Skip to content

Commit 1dc3e8d

Browse files
msanallayishaih
authored andcommitted
mlx5: Add support for bulk flow counters in mlx5dv_create_flow
Extend the mlx5dv_create_flow API to support bulk counter operations by introducing a new action type MLX5DV_FLOW_ACTION_COUNTERS_DEVX_WITH_OFFSET. This allows users to specify an offset within DEVX counter objects for more granular bulk counter object management. The implementation removes the previous auxiliary array approach (_mlx5dv_create_flow with actions_attr_aux parameter) in favor of a cleaner design that embeds offset information directly within the flow action structure. The mlx5dv_flow_action_attr union is extended with a bulk_obj member containing both the DEVX object and an offset, allowing also external rdma-core applications to use DEVX bulk counter via the offset. Existing applications using MLX5DV_FLOW_ACTION_COUNTERS_DEVX continue to work unchanged, while new applications can use the enhanced MLX5DV_FLOW_ACTION_COUNTERS_DEVX_WITH_OFFSET for bulk counter scenarios. Note that no kernel changes needed, since DEVX bulk counter object with offset is already supported. Signed-off-by: Maher Sanalla <msanalla@nvidia.com> Signed-off-by: Alex Vesker <valex@nvidia.com> Signed-off-by: Yishai Hadas <yishaih@nvidia.com>
1 parent 091ddb5 commit 1dc3e8d

File tree

7 files changed

+49
-42
lines changed

7 files changed

+49
-42
lines changed

providers/mlx5/dr_action.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -975,8 +975,7 @@ int dr_actions_build_ste_arr(struct mlx5dv_dr_matcher *matcher,
975975
int dr_actions_build_attr(struct mlx5dv_dr_matcher *matcher,
976976
struct mlx5dv_dr_action *actions[],
977977
size_t num_actions,
978-
struct mlx5dv_flow_action_attr *attr,
979-
struct mlx5_flow_action_attr_aux *attr_aux)
978+
struct mlx5dv_flow_action_attr *attr)
980979
{
981980
struct mlx5dv_dr_domain *dmn = matcher->tbl->dmn;
982981
int i;
@@ -1026,8 +1025,8 @@ int dr_actions_build_attr(struct mlx5dv_dr_matcher *matcher,
10261025
attr[i].obj = actions[i]->ctr.devx_obj;
10271026

10281027
if (actions[i]->ctr.offset) {
1029-
attr_aux[i].type = MLX5_FLOW_ACTION_COUNTER_OFFSET;
1030-
attr_aux[i].offset = actions[i]->ctr.offset;
1028+
attr[i].type = MLX5DV_FLOW_ACTION_COUNTERS_DEVX_WITH_OFFSET;
1029+
attr[i].bulk_obj.offset = actions[i]->ctr.offset;
10311030
}
10321031
break;
10331032
case DR_ACTION_TYP_TAG:

providers/mlx5/dr_rule.c

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1552,7 +1552,6 @@ dr_rule_create_rule_root(struct mlx5dv_dr_matcher *matcher,
15521552
struct mlx5dv_dr_action *actions[])
15531553
{
15541554
struct mlx5dv_flow_action_attr *attr;
1555-
struct mlx5_flow_action_attr_aux *attr_aux;
15561555
struct mlx5dv_dr_rule *rule;
15571556
int ret;
15581557

@@ -1570,37 +1569,27 @@ dr_rule_create_rule_root(struct mlx5dv_dr_matcher *matcher,
15701569
goto free_rule;
15711570
}
15721571

1573-
attr_aux = calloc(num_actions, sizeof(*attr_aux));
1574-
if (!attr_aux) {
1575-
errno = ENOMEM;
1576-
goto free_attr;
1577-
}
1578-
1579-
ret = dr_actions_build_attr(matcher, actions, num_actions, attr, attr_aux);
1572+
ret = dr_actions_build_attr(matcher, actions, num_actions, attr);
15801573
if (ret)
1581-
goto free_attr_aux;
1574+
goto free_attr;
15821575

15831576
ret = dr_rule_add_action_members(rule, num_actions, actions);
15841577
if (ret)
1585-
goto free_attr_aux;
1578+
goto free_attr;
15861579

1587-
rule->flow = _mlx5dv_create_flow(matcher->dv_matcher,
1580+
rule->flow = mlx5dv_create_flow(matcher->dv_matcher,
15881581
value,
15891582
num_actions,
1590-
attr,
1591-
attr_aux);
1583+
attr);
15921584
if (!rule->flow)
15931585
goto remove_action_members;
15941586

15951587
free(attr);
1596-
free(attr_aux);
15971588

15981589
return rule;
15991590

16001591
remove_action_members:
16011592
dr_rule_remove_action_members(rule);
1602-
free_attr_aux:
1603-
free(attr_aux);
16041593
free_attr:
16051594
free(attr);
16061595
free_rule:

providers/mlx5/man/mlx5dv_create_flow.3.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ struct mlx5dv_flow_action_attr {
4646
struct ibv_flow_action *action;
4747
uint32_t tag_value;
4848
struct mlx5dv_devx_obj *obj;
49+
struct {
50+
struct mlx5dv_devx_obj *obj;
51+
uint32_t offset;
52+
} bulk_obj;
4953
};
5054
};
5155
```
@@ -65,6 +69,8 @@ struct mlx5dv_flow_action_attr {
6569
Steer the packet to the default miss destination.
6670
MLX5DV_FLOW_ACTION_DROP
6771
Action is dropping the matched packet.
72+
MLX5DV_FLOW_ACTION_COUNTERS_DEVX_WITH_OFFSET
73+
The DEVX bulk counter object and its counter offset for the matched packets.
6874

6975
*qp*
7076
: QP passed, to be used with *type* *MLX5DV_FLOW_ACTION_DEST_IBV_QP*.
@@ -78,7 +84,12 @@ struct mlx5dv_flow_action_attr {
7884
*MLX5DV_FLOW_ACTION_TAG* see *ibv_create_cq_ex(3)*.
7985

8086
*obj*
81-
: DEVX object, to be used with *type* *MLX5DV_FLOW_ACTION_DEST_DEVX* or by *MLX5DV_FLOW_ACTION_COUNTERS_DEVX*.
87+
: DEVX object, to be used with *type* *MLX5DV_FLOW_ACTION_DEST_DEVX* or by *MLX5DV_FLOW_ACTION_COUNTERS_DEVX*
88+
or by *MLX5DV_FLOW_ACTION_COUNTERS_DEVX_WITH_OFFSET*.
89+
90+
*offset*
91+
: offset to the target counter within a bulk DEVX object, to be used with *type*
92+
*MLX5DV_FLOW_ACTION_COUNTERS_DEVX_WITH_OFFSET*
8293

8394
# RETURN VALUE
8495

providers/mlx5/mlx5.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -962,8 +962,7 @@ struct ibv_flow *
962962
_mlx5dv_create_flow(struct mlx5dv_flow_matcher *flow_matcher,
963963
struct mlx5dv_flow_match_parameters *match_value,
964964
size_t num_actions,
965-
struct mlx5dv_flow_action_attr actions_attr[],
966-
struct mlx5_flow_action_attr_aux actions_attr_aux[]);
965+
struct mlx5dv_flow_action_attr actions_attr[]);
967966

968967
extern int mlx5_stall_num_loop;
969968
extern int mlx5_stall_cq_poll_min;
@@ -1586,11 +1585,11 @@ struct mlx5_dv_context_ops {
15861585
struct mlx5dv_flow_matcher *(*create_flow_matcher)(struct ibv_context *context,
15871586
struct mlx5dv_flow_matcher_attr *attr);
15881587
int (*destroy_flow_matcher)(struct mlx5dv_flow_matcher *flow_matcher);
1589-
struct ibv_flow *(*create_flow)(struct mlx5dv_flow_matcher *flow_matcher,
1590-
struct mlx5dv_flow_match_parameters *match_value,
1591-
size_t num_actions,
1592-
struct mlx5dv_flow_action_attr actions_attr[],
1593-
struct mlx5_flow_action_attr_aux actions_attr_aux[]);
1588+
struct ibv_flow *(*create_flow)(
1589+
struct mlx5dv_flow_matcher *flow_matcher,
1590+
struct mlx5dv_flow_match_parameters *match_value,
1591+
size_t num_actions,
1592+
struct mlx5dv_flow_action_attr actions_attr[]);
15941593

15951594
struct mlx5dv_steering_anchor *(*create_steering_anchor)(struct ibv_context *conterxt,
15961595
struct mlx5dv_steering_anchor_attr *attr);

providers/mlx5/mlx5dv.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,7 @@ enum mlx5dv_flow_action_type {
783783
MLX5DV_FLOW_ACTION_DEST_DEVX,
784784
MLX5DV_FLOW_ACTION_COUNTERS_DEVX,
785785
MLX5DV_FLOW_ACTION_DEFAULT_MISS,
786+
MLX5DV_FLOW_ACTION_COUNTERS_DEVX_WITH_OFFSET,
786787
};
787788

788789
struct mlx5dv_flow_action_attr {
@@ -793,6 +794,10 @@ struct mlx5dv_flow_action_attr {
793794
struct ibv_flow_action *action;
794795
uint32_t tag_value;
795796
struct mlx5dv_devx_obj *obj;
797+
struct {
798+
struct mlx5dv_devx_obj *obj;
799+
uint32_t offset;
800+
} bulk_obj;
796801
};
797802
};
798803

providers/mlx5/mlx5dv_dr.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -691,8 +691,7 @@ int dr_actions_build_ste_arr(struct mlx5dv_dr_matcher *matcher,
691691
int dr_actions_build_attr(struct mlx5dv_dr_matcher *matcher,
692692
struct mlx5dv_dr_action *actions[],
693693
size_t num_actions,
694-
struct mlx5dv_flow_action_attr *attr,
695-
struct mlx5_flow_action_attr_aux *attr_aux);
694+
struct mlx5dv_flow_action_attr *attr);
696695

697696
uint32_t dr_actions_reformat_get_id(struct mlx5dv_dr_action *action);
698697

providers/mlx5/verbs.c

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5615,8 +5615,7 @@ struct ibv_flow *
56155615
_mlx5dv_create_flow(struct mlx5dv_flow_matcher *flow_matcher,
56165616
struct mlx5dv_flow_match_parameters *match_value,
56175617
size_t num_actions,
5618-
struct mlx5dv_flow_action_attr actions_attr[],
5619-
struct mlx5_flow_action_attr_aux actions_attr_aux[])
5618+
struct mlx5dv_flow_action_attr actions_attr[])
56205619
{
56215620
uint32_t flow_actions[CREATE_FLOW_MAX_FLOW_ACTIONS_SUPPORTED];
56225621
struct verbs_flow_action *vaction;
@@ -5626,6 +5625,7 @@ _mlx5dv_create_flow(struct mlx5dv_flow_matcher *flow_matcher,
56265625
bool have_dest_devx = false;
56275626
bool have_flow_tag = false;
56285627
bool have_counter = false;
5628+
bool have_bulk_counter = false;
56295629
bool have_default = false;
56305630
bool have_drop = false;
56315631
int ret;
@@ -5695,20 +5695,13 @@ _mlx5dv_create_flow(struct mlx5dv_flow_matcher *flow_matcher,
56955695
have_flow_tag = true;
56965696
break;
56975697
case MLX5DV_FLOW_ACTION_COUNTERS_DEVX:
5698-
if (have_counter) {
5698+
if (have_counter || have_bulk_counter) {
56995699
errno = EOPNOTSUPP;
57005700
goto err;
57015701
}
57025702
fill_attr_in_objs_arr(cmd,
57035703
MLX5_IB_ATTR_CREATE_FLOW_ARR_COUNTERS_DEVX,
57045704
&actions_attr[i].obj->handle, 1);
5705-
5706-
if (actions_attr_aux &&
5707-
actions_attr_aux[i].type == MLX5_FLOW_ACTION_COUNTER_OFFSET)
5708-
fill_attr_in_ptr_array(cmd,
5709-
MLX5_IB_ATTR_CREATE_FLOW_ARR_COUNTERS_DEVX_OFFSET,
5710-
&actions_attr_aux[i].offset, 1);
5711-
57125705
have_counter = true;
57135706
break;
57145707
case MLX5DV_FLOW_ACTION_DEFAULT_MISS:
@@ -5733,6 +5726,19 @@ _mlx5dv_create_flow(struct mlx5dv_flow_matcher *flow_matcher,
57335726
MLX5_IB_ATTR_CREATE_FLOW_FLAGS_DROP);
57345727
have_drop = true;
57355728
break;
5729+
case MLX5DV_FLOW_ACTION_COUNTERS_DEVX_WITH_OFFSET:
5730+
if (have_counter || have_bulk_counter) {
5731+
errno = EOPNOTSUPP;
5732+
goto err;
5733+
}
5734+
fill_attr_in_objs_arr(cmd,
5735+
MLX5_IB_ATTR_CREATE_FLOW_ARR_COUNTERS_DEVX,
5736+
&actions_attr[i].bulk_obj.obj->handle, 1);
5737+
fill_attr_in_ptr_array(cmd,
5738+
MLX5_IB_ATTR_CREATE_FLOW_ARR_COUNTERS_DEVX_OFFSET,
5739+
&actions_attr[i].bulk_obj.offset, 1);
5740+
have_bulk_counter = true;
5741+
break;
57365742
default:
57375743
errno = EOPNOTSUPP;
57385744
goto err;
@@ -5772,8 +5778,7 @@ mlx5dv_create_flow(struct mlx5dv_flow_matcher *flow_matcher,
57725778
return dvops->create_flow(flow_matcher,
57735779
match_value,
57745780
num_actions,
5775-
actions_attr,
5776-
NULL);
5781+
actions_attr);
57775782
}
57785783

57795784
static struct mlx5dv_steering_anchor *

0 commit comments

Comments
 (0)