Message ID | 1598801254-27764-4-git-send-email-moshe@mellanox.com |
---|---|
State | RFC |
Delegated to: | David Miller |
Headers | show |
Series | Add devlink reload action option | expand |
Sun, Aug 30, 2020 at 05:27:23PM CEST, moshe@mellanox.com wrote: >Expose devlink reload actions counters to the user through devlink dev >get command. > >Examples: >$ devlink dev show >pci/0000:82:00.0: > reload_actions_stats: > driver_reinit 2 > fw_activate 1 > fw_activate_no_reset 0 >pci/0000:82:00.1: > reload_actions_stats: > driver_reinit 1 > fw_activate 1 > fw_activate_no_reset 0 > >$ devlink dev show -jp >{ > "dev": { > "pci/0000:82:00.0": { > "reload_actions_stats": [ { Perhaps "reload_action_stats" would be better. > "driver_reinit": 2 > },{ > "fw_activate": 1 > },{ > "fw_activate_no_reset": 0 > } ] > }, > "pci/0000:82:00.1": { > "reload_actions_stats": [ { > "driver_reinit": 1 > },{ > "fw_activate": 1 > },{ > "fw_activate_no_reset": 0 > } ] > } > } >} > >Signed-off-by: Moshe Shemesh <moshe@mellanox.com> >--- >v2 -> v3: >- Add reload actions counters instead of supported reload actions > (reload actions counters are only for supported action so no need for > both) >v1 -> v2: >- Removed DEVLINK_ATTR_RELOAD_DEFAULT_LEVEL >- Removed DEVLINK_ATTR_RELOAD_LEVELS_INFO >- Have actions instead of levels >--- > include/uapi/linux/devlink.h | 3 +++ > net/core/devlink.c | 37 +++++++++++++++++++++++++++++++----- > 2 files changed, 35 insertions(+), 5 deletions(-) > >diff --git a/include/uapi/linux/devlink.h b/include/uapi/linux/devlink.h >index 0a438135c3cf..fd7667c78417 100644 >--- a/include/uapi/linux/devlink.h >+++ b/include/uapi/linux/devlink.h >@@ -478,6 +478,9 @@ enum devlink_attr { > > DEVLINK_ATTR_RELOAD_ACTION, /* u8 */ > DEVLINK_ATTR_RELOAD_ACTIONS_DONE, /* nested */ >+ DEVLINK_ATTR_RELOAD_ACTION_CNT_VALUE, /* u32 */ >+ DEVLINK_ATTR_RELOAD_ACTION_CNT, /* nested */ >+ DEVLINK_ATTR_RELOAD_ACTIONS_CNTS, /* nested */ Be in-sync with the user outputs. Perhaps something like: DEVLINK_ATTR_RELOAD_ACTION_STATS DEVLINK_ATTR_RELOAD_ACTION_STAT DEVLINK_ATTR_RELOAD_ACTION_STAT_VALUE ? > > /* add new attributes above here, update the policy in devlink.c */ > [..]
On 8/31/2020 1:44 PM, Jiri Pirko wrote: > Sun, Aug 30, 2020 at 05:27:23PM CEST, moshe@mellanox.com wrote: >> Expose devlink reload actions counters to the user through devlink dev >> get command. >> >> Examples: >> $ devlink dev show >> pci/0000:82:00.0: >> reload_actions_stats: >> driver_reinit 2 >> fw_activate 1 >> fw_activate_no_reset 0 >> pci/0000:82:00.1: >> reload_actions_stats: >> driver_reinit 1 >> fw_activate 1 >> fw_activate_no_reset 0 >> >> $ devlink dev show -jp >> { >> "dev": { >> "pci/0000:82:00.0": { >> "reload_actions_stats": [ { > Perhaps "reload_action_stats" would be better. OK. > >> "driver_reinit": 2 >> },{ >> "fw_activate": 1 >> },{ >> "fw_activate_no_reset": 0 >> } ] >> }, >> "pci/0000:82:00.1": { >> "reload_actions_stats": [ { >> "driver_reinit": 1 >> },{ >> "fw_activate": 1 >> },{ >> "fw_activate_no_reset": 0 >> } ] >> } >> } >> } >> >> Signed-off-by: Moshe Shemesh <moshe@mellanox.com> >> --- >> v2 -> v3: >> - Add reload actions counters instead of supported reload actions >> (reload actions counters are only for supported action so no need for >> both) >> v1 -> v2: >> - Removed DEVLINK_ATTR_RELOAD_DEFAULT_LEVEL >> - Removed DEVLINK_ATTR_RELOAD_LEVELS_INFO >> - Have actions instead of levels >> --- >> include/uapi/linux/devlink.h | 3 +++ >> net/core/devlink.c | 37 +++++++++++++++++++++++++++++++----- >> 2 files changed, 35 insertions(+), 5 deletions(-) >> >> diff --git a/include/uapi/linux/devlink.h b/include/uapi/linux/devlink.h >> index 0a438135c3cf..fd7667c78417 100644 >> --- a/include/uapi/linux/devlink.h >> +++ b/include/uapi/linux/devlink.h >> @@ -478,6 +478,9 @@ enum devlink_attr { >> >> DEVLINK_ATTR_RELOAD_ACTION, /* u8 */ >> DEVLINK_ATTR_RELOAD_ACTIONS_DONE, /* nested */ >> + DEVLINK_ATTR_RELOAD_ACTION_CNT_VALUE, /* u32 */ >> + DEVLINK_ATTR_RELOAD_ACTION_CNT, /* nested */ >> + DEVLINK_ATTR_RELOAD_ACTIONS_CNTS, /* nested */ > Be in-sync with the user outputs. Perhaps something like: > DEVLINK_ATTR_RELOAD_ACTION_STATS > DEVLINK_ATTR_RELOAD_ACTION_STAT > DEVLINK_ATTR_RELOAD_ACTION_STAT_VALUE > ? I actually see it as counters of number of times action done, but generally counters and stats are the same, so I am fine with that too. >> /* add new attributes above here, update the policy in devlink.c */ >> > [..]
diff --git a/include/uapi/linux/devlink.h b/include/uapi/linux/devlink.h index 0a438135c3cf..fd7667c78417 100644 --- a/include/uapi/linux/devlink.h +++ b/include/uapi/linux/devlink.h @@ -478,6 +478,9 @@ enum devlink_attr { DEVLINK_ATTR_RELOAD_ACTION, /* u8 */ DEVLINK_ATTR_RELOAD_ACTIONS_DONE, /* nested */ + DEVLINK_ATTR_RELOAD_ACTION_CNT_VALUE, /* u32 */ + DEVLINK_ATTR_RELOAD_ACTION_CNT, /* nested */ + DEVLINK_ATTR_RELOAD_ACTIONS_CNTS, /* nested */ /* add new attributes above here, update the policy in devlink.c */ diff --git a/net/core/devlink.c b/net/core/devlink.c index 20a29c34ff71..962b14295380 100644 --- a/net/core/devlink.c +++ b/net/core/devlink.c @@ -462,6 +462,11 @@ static int devlink_nl_put_handle(struct sk_buff *msg, struct devlink *devlink) return 0; } +static bool devlink_reload_supported(struct devlink *devlink) +{ + return devlink->ops->reload_down && devlink->ops->reload_up; +} + static bool devlink_reload_action_is_supported(struct devlink *devlink, enum devlink_reload_action action) { @@ -472,7 +477,9 @@ static int devlink_nl_fill(struct sk_buff *msg, struct devlink *devlink, enum devlink_command cmd, u32 portid, u32 seq, int flags) { + struct nlattr *reload_actions_cnts, *reload_action_cnt; void *hdr; + int i; hdr = genlmsg_put(msg, portid, seq, &devlink_nl_family, flags, cmd); if (!hdr) @@ -483,9 +490,34 @@ static int devlink_nl_fill(struct sk_buff *msg, struct devlink *devlink, if (nla_put_u8(msg, DEVLINK_ATTR_RELOAD_FAILED, devlink->reload_failed)) goto nla_put_failure; + if (devlink_reload_supported(devlink)) { + reload_actions_cnts = nla_nest_start(msg, DEVLINK_ATTR_RELOAD_ACTIONS_CNTS); + if (!reload_actions_cnts) + goto nla_put_failure; + + for (i = 0; i <= DEVLINK_RELOAD_ACTION_MAX; i++) { + if (!devlink_reload_action_is_supported(devlink, i)) + continue; + reload_action_cnt = nla_nest_start(msg, DEVLINK_ATTR_RELOAD_ACTION_CNT); + if (!reload_action_cnt) + goto reload_actions_cnts_nest_cancel; + if (nla_put_u8(msg, DEVLINK_ATTR_RELOAD_ACTION, i)) + goto reload_action_cnt_nest_cancel; + if (nla_put_u8(msg, DEVLINK_ATTR_RELOAD_ACTION_CNT_VALUE, + devlink->reload_actions_cnts[i])) + goto reload_action_cnt_nest_cancel; + nla_nest_end(msg, reload_action_cnt); + } + nla_nest_end(msg, reload_actions_cnts); + } + genlmsg_end(msg, hdr); return 0; +reload_action_cnt_nest_cancel: + nla_nest_cancel(msg, reload_action_cnt); +reload_actions_cnts_nest_cancel: + nla_nest_cancel(msg, reload_actions_cnts); nla_put_failure: genlmsg_cancel(msg, hdr); return -EMSGSIZE; @@ -2949,11 +2981,6 @@ static void devlink_reload_netns_change(struct devlink *devlink, DEVLINK_CMD_PARAM_NEW); } -static bool devlink_reload_supported(const struct devlink *devlink) -{ - return devlink->ops->reload_down && devlink->ops->reload_up; -} - static void devlink_reload_failed_set(struct devlink *devlink, bool reload_failed) {
Expose devlink reload actions counters to the user through devlink dev get command. Examples: $ devlink dev show pci/0000:82:00.0: reload_actions_stats: driver_reinit 2 fw_activate 1 fw_activate_no_reset 0 pci/0000:82:00.1: reload_actions_stats: driver_reinit 1 fw_activate 1 fw_activate_no_reset 0 $ devlink dev show -jp { "dev": { "pci/0000:82:00.0": { "reload_actions_stats": [ { "driver_reinit": 2 },{ "fw_activate": 1 },{ "fw_activate_no_reset": 0 } ] }, "pci/0000:82:00.1": { "reload_actions_stats": [ { "driver_reinit": 1 },{ "fw_activate": 1 },{ "fw_activate_no_reset": 0 } ] } } } Signed-off-by: Moshe Shemesh <moshe@mellanox.com> --- v2 -> v3: - Add reload actions counters instead of supported reload actions (reload actions counters are only for supported action so no need for both) v1 -> v2: - Removed DEVLINK_ATTR_RELOAD_DEFAULT_LEVEL - Removed DEVLINK_ATTR_RELOAD_LEVELS_INFO - Have actions instead of levels --- include/uapi/linux/devlink.h | 3 +++ net/core/devlink.c | 37 +++++++++++++++++++++++++++++++----- 2 files changed, 35 insertions(+), 5 deletions(-)