Skip to content

Commit df38daf

Browse files
jpirkodavem330
authored andcommitted
devlink: implement shared buffer occupancy monitoring interface
User needs to monitor shared buffer occupancy. For that, he issues a snapshot command in order to instruct hardware to catch current and maximal occupancy values, and clear command in order to clear the historical maximal values. Also port-pool and tc-pool-bind command response messages are extended to carry occupancy values. Signed-off-by: Jiri Pirko <jiri@mellanox.com> Reviewed-by: Ido Schimmel <idosch@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent bf79747 commit df38daf

3 files changed

Lines changed: 110 additions & 6 deletions

File tree

‎include/net/devlink.h‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,18 @@ struct devlink_ops {
7878
u16 tc_index,
7979
enum devlink_sb_pool_type pool_type,
8080
u16 pool_index, u32 threshold);
81+
int (*sb_occ_snapshot)(struct devlink *devlink,
82+
unsigned int sb_index);
83+
int (*sb_occ_max_clear)(struct devlink *devlink,
84+
unsigned int sb_index);
85+
int (*sb_occ_port_pool_get)(struct devlink_port *devlink_port,
86+
unsigned int sb_index, u16 pool_index,
87+
u32 *p_cur, u32 *p_max);
88+
int (*sb_occ_tc_port_bind_get)(struct devlink_port *devlink_port,
89+
unsigned int sb_index,
90+
u16 tc_index,
91+
enum devlink_sb_pool_type pool_type,
92+
u32 *p_cur, u32 *p_max);
8193
};
8294

8395
static inline void *devlink_priv(struct devlink *devlink)

‎include/uapi/linux/devlink.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ enum devlink_command {
5353
DEVLINK_CMD_SB_TC_POOL_BIND_NEW,
5454
DEVLINK_CMD_SB_TC_POOL_BIND_DEL,
5555

56+
/* Shared buffer occupancy monitoring commands */
57+
DEVLINK_CMD_SB_OCC_SNAPSHOT,
58+
DEVLINK_CMD_SB_OCC_MAX_CLEAR,
59+
5660
/* add new commands above here */
5761

5862
__DEVLINK_CMD_MAX,
@@ -119,6 +123,8 @@ enum devlink_attr {
119123
DEVLINK_ATTR_SB_POOL_THRESHOLD_TYPE, /* u8 */
120124
DEVLINK_ATTR_SB_THRESHOLD, /* u32 */
121125
DEVLINK_ATTR_SB_TC_INDEX, /* u16 */
126+
DEVLINK_ATTR_SB_OCC_CUR, /* u32 */
127+
DEVLINK_ATTR_SB_OCC_MAX, /* u32 */
122128

123129
/* add new attributes above here, update the policy in devlink.c */
124130

‎net/core/devlink.c‎

Lines changed: 92 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,10 @@ devlink_sb_tc_index_get_from_info(struct devlink_sb *devlink_sb,
280280
#define DEVLINK_NL_FLAG_NEED_DEVLINK BIT(0)
281281
#define DEVLINK_NL_FLAG_NEED_PORT BIT(1)
282282
#define DEVLINK_NL_FLAG_NEED_SB BIT(2)
283+
#define DEVLINK_NL_FLAG_LOCK_PORTS BIT(3)
284+
/* port is not needed but we need to ensure they don't
285+
* change in the middle of command
286+
*/
283287

284288
static int devlink_nl_pre_doit(const struct genl_ops *ops,
285289
struct sk_buff *skb, struct genl_info *info)
@@ -306,6 +310,9 @@ static int devlink_nl_pre_doit(const struct genl_ops *ops,
306310
}
307311
info->user_ptr[0] = devlink_port;
308312
}
313+
if (ops->internal_flags & DEVLINK_NL_FLAG_LOCK_PORTS) {
314+
mutex_lock(&devlink_port_mutex);
315+
}
309316
if (ops->internal_flags & DEVLINK_NL_FLAG_NEED_SB) {
310317
struct devlink_sb *devlink_sb;
311318

@@ -324,7 +331,8 @@ static int devlink_nl_pre_doit(const struct genl_ops *ops,
324331
static void devlink_nl_post_doit(const struct genl_ops *ops,
325332
struct sk_buff *skb, struct genl_info *info)
326333
{
327-
if (ops->internal_flags & DEVLINK_NL_FLAG_NEED_PORT)
334+
if (ops->internal_flags & DEVLINK_NL_FLAG_NEED_PORT ||
335+
ops->internal_flags & DEVLINK_NL_FLAG_LOCK_PORTS)
328336
mutex_unlock(&devlink_port_mutex);
329337
mutex_unlock(&devlink_mutex);
330338
}
@@ -942,12 +950,13 @@ static int devlink_nl_sb_port_pool_fill(struct sk_buff *msg,
942950
enum devlink_command cmd,
943951
u32 portid, u32 seq, int flags)
944952
{
953+
const struct devlink_ops *ops = devlink->ops;
945954
u32 threshold;
946955
void *hdr;
947956
int err;
948957

949-
err = devlink->ops->sb_port_pool_get(devlink_port, devlink_sb->index,
950-
pool_index, &threshold);
958+
err = ops->sb_port_pool_get(devlink_port, devlink_sb->index,
959+
pool_index, &threshold);
951960
if (err)
952961
return err;
953962

@@ -966,6 +975,22 @@ static int devlink_nl_sb_port_pool_fill(struct sk_buff *msg,
966975
if (nla_put_u32(msg, DEVLINK_ATTR_SB_THRESHOLD, threshold))
967976
goto nla_put_failure;
968977

978+
if (ops->sb_occ_port_pool_get) {
979+
u32 cur;
980+
u32 max;
981+
982+
err = ops->sb_occ_port_pool_get(devlink_port, devlink_sb->index,
983+
pool_index, &cur, &max);
984+
if (err && err != -EOPNOTSUPP)
985+
return err;
986+
if (!err) {
987+
if (nla_put_u32(msg, DEVLINK_ATTR_SB_OCC_CUR, cur))
988+
goto nla_put_failure;
989+
if (nla_put_u32(msg, DEVLINK_ATTR_SB_OCC_MAX, max))
990+
goto nla_put_failure;
991+
}
992+
}
993+
969994
genlmsg_end(msg, hdr);
970995
return 0;
971996

@@ -1114,14 +1139,15 @@ devlink_nl_sb_tc_pool_bind_fill(struct sk_buff *msg, struct devlink *devlink,
11141139
enum devlink_command cmd,
11151140
u32 portid, u32 seq, int flags)
11161141
{
1142+
const struct devlink_ops *ops = devlink->ops;
11171143
u16 pool_index;
11181144
u32 threshold;
11191145
void *hdr;
11201146
int err;
11211147

1122-
err = devlink->ops->sb_tc_pool_bind_get(devlink_port, devlink_sb->index,
1123-
tc_index, pool_type,
1124-
&pool_index, &threshold);
1148+
err = ops->sb_tc_pool_bind_get(devlink_port, devlink_sb->index,
1149+
tc_index, pool_type,
1150+
&pool_index, &threshold);
11251151
if (err)
11261152
return err;
11271153

@@ -1144,6 +1170,24 @@ devlink_nl_sb_tc_pool_bind_fill(struct sk_buff *msg, struct devlink *devlink,
11441170
if (nla_put_u32(msg, DEVLINK_ATTR_SB_THRESHOLD, threshold))
11451171
goto nla_put_failure;
11461172

1173+
if (ops->sb_occ_tc_port_bind_get) {
1174+
u32 cur;
1175+
u32 max;
1176+
1177+
err = ops->sb_occ_tc_port_bind_get(devlink_port,
1178+
devlink_sb->index,
1179+
tc_index, pool_type,
1180+
&cur, &max);
1181+
if (err && err != -EOPNOTSUPP)
1182+
return err;
1183+
if (!err) {
1184+
if (nla_put_u32(msg, DEVLINK_ATTR_SB_OCC_CUR, cur))
1185+
goto nla_put_failure;
1186+
if (nla_put_u32(msg, DEVLINK_ATTR_SB_OCC_MAX, max))
1187+
goto nla_put_failure;
1188+
}
1189+
}
1190+
11471191
genlmsg_end(msg, hdr);
11481192
return 0;
11491193

@@ -1326,6 +1370,30 @@ static int devlink_nl_cmd_sb_tc_pool_bind_set_doit(struct sk_buff *skb,
13261370
pool_index, threshold);
13271371
}
13281372

1373+
static int devlink_nl_cmd_sb_occ_snapshot_doit(struct sk_buff *skb,
1374+
struct genl_info *info)
1375+
{
1376+
struct devlink *devlink = info->user_ptr[0];
1377+
struct devlink_sb *devlink_sb = info->user_ptr[1];
1378+
const struct devlink_ops *ops = devlink->ops;
1379+
1380+
if (ops && ops->sb_occ_snapshot)
1381+
return ops->sb_occ_snapshot(devlink, devlink_sb->index);
1382+
return -EOPNOTSUPP;
1383+
}
1384+
1385+
static int devlink_nl_cmd_sb_occ_max_clear_doit(struct sk_buff *skb,
1386+
struct genl_info *info)
1387+
{
1388+
struct devlink *devlink = info->user_ptr[0];
1389+
struct devlink_sb *devlink_sb = info->user_ptr[1];
1390+
const struct devlink_ops *ops = devlink->ops;
1391+
1392+
if (ops && ops->sb_occ_max_clear)
1393+
return ops->sb_occ_max_clear(devlink, devlink_sb->index);
1394+
return -EOPNOTSUPP;
1395+
}
1396+
13291397
static const struct nla_policy devlink_nl_policy[DEVLINK_ATTR_MAX + 1] = {
13301398
[DEVLINK_ATTR_BUS_NAME] = { .type = NLA_NUL_STRING },
13311399
[DEVLINK_ATTR_DEV_NAME] = { .type = NLA_NUL_STRING },
@@ -1439,6 +1507,24 @@ static const struct genl_ops devlink_nl_ops[] = {
14391507
.internal_flags = DEVLINK_NL_FLAG_NEED_PORT |
14401508
DEVLINK_NL_FLAG_NEED_SB,
14411509
},
1510+
{
1511+
.cmd = DEVLINK_CMD_SB_OCC_SNAPSHOT,
1512+
.doit = devlink_nl_cmd_sb_occ_snapshot_doit,
1513+
.policy = devlink_nl_policy,
1514+
.flags = GENL_ADMIN_PERM,
1515+
.internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK |
1516+
DEVLINK_NL_FLAG_NEED_SB |
1517+
DEVLINK_NL_FLAG_LOCK_PORTS,
1518+
},
1519+
{
1520+
.cmd = DEVLINK_CMD_SB_OCC_MAX_CLEAR,
1521+
.doit = devlink_nl_cmd_sb_occ_max_clear_doit,
1522+
.policy = devlink_nl_policy,
1523+
.flags = GENL_ADMIN_PERM,
1524+
.internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK |
1525+
DEVLINK_NL_FLAG_NEED_SB |
1526+
DEVLINK_NL_FLAG_LOCK_PORTS,
1527+
},
14421528
};
14431529

14441530
/**

0 commit comments

Comments
 (0)