All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH iproute2-net 0/3] devlink: Add devlink reload action limit and stats
@ 2020-11-26 11:14 Moshe Shemesh
  2020-11-26 11:14 ` [PATCH iproute2-net 1/3] devlink: Add devlink reload action and limit options Moshe Shemesh
                   ` (3 more replies)
  0 siblings, 4 replies; 12+ messages in thread
From: Moshe Shemesh @ 2020-11-26 11:14 UTC (permalink / raw)
  To: Stephen Hemminger, David Ahern, Jakub Kicinski, Jiri Pirko, netdev
  Cc: Moshe Shemesh

Introduce new options on devlink reload API to enable the user to select
the reload action required and constrains limits on these actions that he
may want to ensure.

Add reload stats to show the history per reload action per limit.

Patch 1 adds the new API reload action and reload limit options to
        devlink reload command.
Patch 2 adds pr_out_dev() helper function and modify monitor function to
        use it.
Patch 3 adds reload stats and remote reload stats to devlink dev show.


Moshe Shemesh (3):
  devlink: Add devlink reload action and limit options
  devlink: Add pr_out_dev() helper function
  devlink: Add reload stats to dev show

 devlink/devlink.c            | 260 +++++++++++++++++++++++++++++++++--
 include/uapi/linux/devlink.h |   2 +
 2 files changed, 249 insertions(+), 13 deletions(-)

-- 
2.18.2


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH iproute2-net 1/3] devlink: Add devlink reload action and limit options
  2020-11-26 11:14 [PATCH iproute2-net 0/3] devlink: Add devlink reload action limit and stats Moshe Shemesh
@ 2020-11-26 11:14 ` Moshe Shemesh
  2020-11-29 21:12   ` David Ahern
  2020-11-26 11:14 ` [PATCH iproute2-net 2/3] devlink: Add pr_out_dev() helper function Moshe Shemesh
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 12+ messages in thread
From: Moshe Shemesh @ 2020-11-26 11:14 UTC (permalink / raw)
  To: Stephen Hemminger, David Ahern, Jakub Kicinski, Jiri Pirko, netdev
  Cc: Moshe Shemesh

Add reload action and reload limit to devlink reload command to enable
the user to select the reload action required and constrains limits on
these actions that he may want to ensure.
The following reload actions are supported:
  driver_reinit: driver entities re-initialization, applying
                 devlink-param and devlink-resource values.
  fw_activate: firmware activate.

The uAPI is backward compatible, if the reload action option is omitted
from the reload command, the driver reinit action will be used.
Note that when required to do firmware activation some drivers may need
to reload the driver. On the other hand some drivers may need to reset
the firmware to reinitialize the driver entities. Therefore, the devlink
reload command returns the actions which were actually performed.

By default reload actions are not limited and driver implementation may
include reset or downtime as needed to perform the actions.
However, if reload limit is selected, the driver should perform only if
it can do it while keeping the limit constraints.
Reload limit added:
  no_reset: No reset allowed, no down time allowed, no link flap and no
            configuration is lost.

Command examples:
$devlink dev reload pci/0000:82:00.0 action driver_reinit
reload_actions_performed:
  driver_reinit

$devlink dev reload pci/0000:82:00.0 action fw_activate
reload_actions_performed:
  driver_reinit fw_activate

devlink dev reload pci/0000:82:00.1 action driver_reinit -jp
{
    "reload": {
        "reload_actions_performed": [ "driver_reinit" ]
    }
}

devlink dev reload pci/0000:82:00.0 action fw_activate -jp
{
    "reload": {
        "reload_actions_performed": [ "driver_reinit","fw_activate" ]
    }
}

Signed-off-by: Moshe Shemesh <moshe@mellanox.com>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
---
 devlink/devlink.c | 136 +++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 133 insertions(+), 3 deletions(-)

diff --git a/devlink/devlink.c b/devlink/devlink.c
index 1ff865bc..a9ba0072 100644
--- a/devlink/devlink.c
+++ b/devlink/devlink.c
@@ -304,6 +304,8 @@ static void ifname_map_free(struct ifname_map *ifname_map)
 #define DL_OPT_HEALTH_REPORTER_AUTO_DUMP     BIT(37)
 #define DL_OPT_PORT_FUNCTION_HW_ADDR BIT(38)
 #define DL_OPT_FLASH_OVERWRITE		BIT(39)
+#define DL_OPT_RELOAD_ACTION		BIT(40)
+#define DL_OPT_RELOAD_LIMIT	BIT(41)
 
 struct dl_opts {
 	uint64_t present; /* flags of present items */
@@ -352,6 +354,8 @@ struct dl_opts {
 	char port_function_hw_addr[MAX_ADDR_LEN];
 	uint32_t port_function_hw_addr_len;
 	uint32_t overwrite_mask;
+	enum devlink_reload_action reload_action;
+	enum devlink_reload_limit reload_limit;
 };
 
 struct dl {
@@ -1344,6 +1348,32 @@ static int hw_addr_parse(const char *addrstr, char *hw_addr, uint32_t *len)
 	return 0;
 }
 
+static int reload_action_get(struct dl *dl, const char *actionstr,
+			     enum devlink_reload_action *action)
+{
+	if (strcmp(actionstr, "driver_reinit") == 0) {
+		*action = DEVLINK_RELOAD_ACTION_DRIVER_REINIT;
+	} else if (strcmp(actionstr, "fw_activate") == 0) {
+		*action = DEVLINK_RELOAD_ACTION_FW_ACTIVATE;
+	} else {
+		pr_err("Unknown reload action \"%s\"\n", actionstr);
+		return -EINVAL;
+	}
+	return 0;
+}
+
+static int reload_limit_get(struct dl *dl, const char *limitstr,
+			     enum devlink_reload_limit *limit)
+{
+	if (strcmp(limitstr, "no_reset") == 0) {
+		*limit = DEVLINK_RELOAD_LIMIT_NO_RESET;
+	} else {
+		pr_err("Unknown reload limit \"%s\"\n", limitstr);
+		return -EINVAL;
+	}
+	return 0;
+}
+
 struct dl_args_metadata {
 	uint64_t o_flag;
 	char err_msg[DL_ARGS_REQUIRED_MAX_ERR_LEN];
@@ -1730,6 +1760,30 @@ static int dl_argv_parse(struct dl *dl, uint64_t o_required,
 				opts->netns_is_pid = true;
 			}
 			o_found |= DL_OPT_NETNS;
+		} else if (dl_argv_match(dl, "action") &&
+			   (o_all & DL_OPT_RELOAD_ACTION)) {
+			const char *actionstr;
+
+			dl_arg_inc(dl);
+			err = dl_argv_str(dl, &actionstr);
+			if (err)
+				return err;
+			err = reload_action_get(dl, actionstr, &opts->reload_action);
+			if (err)
+				return err;
+			o_found |= DL_OPT_RELOAD_ACTION;
+		} else if (dl_argv_match(dl, "limit") &&
+			   (o_all & DL_OPT_RELOAD_LIMIT)) {
+			const char *limitstr;
+
+			dl_arg_inc(dl);
+			err = dl_argv_str(dl, &limitstr);
+			if (err)
+				return err;
+			err = reload_limit_get(dl, limitstr, &opts->reload_limit);
+			if (err)
+				return err;
+			o_found |= DL_OPT_RELOAD_LIMIT;
 		} else if (dl_argv_match(dl, "policer") &&
 			   (o_all & DL_OPT_TRAP_POLICER_ID)) {
 			dl_arg_inc(dl);
@@ -1810,6 +1864,16 @@ dl_flash_update_overwrite_put(struct nlmsghdr *nlh, const struct dl_opts *opts)
 		     sizeof(overwrite_mask), &overwrite_mask);
 }
 
+static void
+dl_reload_limits_put(struct nlmsghdr *nlh, const struct dl_opts *opts)
+{
+	struct nla_bitfield32 limits;
+
+	limits.selector = DEVLINK_RELOAD_LIMITS_VALID_MASK;
+	limits.value = BIT(opts->reload_limit);
+	mnl_attr_put(nlh, DEVLINK_ATTR_RELOAD_LIMITS, sizeof(limits), &limits);
+}
+
 static void dl_opts_put(struct nlmsghdr *nlh, struct dl *dl)
 {
 	struct dl_opts *opts = &dl->opts;
@@ -1926,6 +1990,11 @@ static void dl_opts_put(struct nlmsghdr *nlh, struct dl *dl)
 				 opts->netns_is_pid ? DEVLINK_ATTR_NETNS_PID :
 						      DEVLINK_ATTR_NETNS_FD,
 				 opts->netns);
+	if (opts->present & DL_OPT_RELOAD_ACTION)
+		mnl_attr_put_u8(nlh, DEVLINK_ATTR_RELOAD_ACTION,
+				opts->reload_action);
+	if (opts->present & DL_OPT_RELOAD_LIMIT)
+		dl_reload_limits_put(nlh, opts);
 	if (opts->present & DL_OPT_TRAP_POLICER_ID)
 		mnl_attr_put_u32(nlh, DEVLINK_ATTR_TRAP_POLICER_ID,
 				 opts->trap_policer_id);
@@ -1997,7 +2066,7 @@ static void cmd_dev_help(void)
 	pr_err("       devlink dev eswitch show DEV\n");
 	pr_err("       devlink dev param set DEV name PARAMETER value VALUE cmode { permanent | driverinit | runtime }\n");
 	pr_err("       devlink dev param show [DEV name PARAMETER]\n");
-	pr_err("       devlink dev reload DEV [ netns { PID | NAME | ID } ]\n");
+	pr_err("       devlink dev reload DEV [ netns { PID | NAME | ID } ] [ action { driver_reinit | fw_activate } ] [ limit no_reset ]\n");
 	pr_err("       devlink dev info [ DEV ]\n");
 	pr_err("       devlink dev flash DEV file PATH [ component NAME ] [ overwrite SECTION ]\n");
 }
@@ -2289,6 +2358,18 @@ static const char *param_cmode_name(uint8_t cmode)
 	}
 }
 
+static const char *reload_action_name(uint8_t reload_action)
+{
+	switch (reload_action) {
+	case DEVLINK_RELOAD_ACTION_DRIVER_REINIT:
+		return "driver_reinit";
+	case DEVLINK_RELOAD_ACTION_FW_ACTIVATE:
+		return "fw_activate";
+	default:
+		return "<unknown reload action>";
+	}
+}
+
 static const char *eswitch_mode_name(uint32_t mode)
 {
 	switch (mode) {
@@ -2942,6 +3023,54 @@ static int cmd_dev_show(struct dl *dl)
 	return err;
 }
 
+static void pr_out_reload_actions_performed(struct dl *dl, struct nlattr **tb)
+{
+	struct nla_bitfield32 *actions;
+	uint32_t actions_performed;
+	uint16_t len;
+	int action;
+
+	if (!tb[DEVLINK_ATTR_RELOAD_ACTIONS_PERFORMED])
+		return;
+
+	len = mnl_attr_get_payload_len(tb[DEVLINK_ATTR_RELOAD_ACTIONS_PERFORMED]);
+	if (len != sizeof(*actions))
+		return;
+	actions = mnl_attr_get_payload(tb[DEVLINK_ATTR_RELOAD_ACTIONS_PERFORMED]);
+	if (!actions)
+		return;
+	g_new_line_count = 1; /* Avoid extra new line in non-json print */
+	pr_out_array_start(dl, "reload_actions_performed");
+	actions_performed = actions->value & actions->selector;
+	for (action = 0; action <= DEVLINK_RELOAD_ACTION_MAX; action++) {
+		if (BIT(action) & actions_performed) {
+			check_indent_newline(dl);
+			print_string(PRINT_ANY, NULL, "%s", reload_action_name(action));
+		}
+	}
+	pr_out_array_end(dl);
+	if (!dl->json_output)
+		__pr_out_newline();
+}
+
+static int cmd_dev_reload_cb(const struct nlmsghdr *nlh, void *data)
+{
+	struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
+	struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {};
+	struct dl *dl = data;
+
+	mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
+	if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME] ||
+	    !tb[DEVLINK_ATTR_RELOAD_ACTIONS_PERFORMED])
+		return MNL_CB_ERROR;
+
+	pr_out_section_start(dl, "reload");
+	pr_out_reload_actions_performed(dl, tb);
+	pr_out_section_end(dl);
+
+	return MNL_CB_OK;
+}
+
 static int cmd_dev_reload(struct dl *dl)
 {
 	struct nlmsghdr *nlh;
@@ -2955,11 +3084,12 @@ static int cmd_dev_reload(struct dl *dl)
 	nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_RELOAD,
 			       NLM_F_REQUEST | NLM_F_ACK);
 
-	err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE, DL_OPT_NETNS);
+	err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE,
+				DL_OPT_NETNS | DL_OPT_RELOAD_ACTION | DL_OPT_RELOAD_LIMIT);
 	if (err)
 		return err;
 
-	return _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL);
+	return _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_dev_reload_cb, dl);
 }
 
 static void pr_out_versions_single(struct dl *dl, const struct nlmsghdr *nlh,
-- 
2.18.2


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH iproute2-net 2/3] devlink: Add pr_out_dev() helper function
  2020-11-26 11:14 [PATCH iproute2-net 0/3] devlink: Add devlink reload action limit and stats Moshe Shemesh
  2020-11-26 11:14 ` [PATCH iproute2-net 1/3] devlink: Add devlink reload action and limit options Moshe Shemesh
@ 2020-11-26 11:14 ` Moshe Shemesh
  2020-11-29 21:15   ` David Ahern
  2020-11-26 11:14 ` [PATCH iproute2-net 3/3] devlink: Add reload stats to dev show Moshe Shemesh
  2020-12-01 11:25 ` [PATCH iproute2-net 0/3] devlink: Add devlink reload action limit and stats Vasundhara Volam
  3 siblings, 1 reply; 12+ messages in thread
From: Moshe Shemesh @ 2020-11-26 11:14 UTC (permalink / raw)
  To: Stephen Hemminger, David Ahern, Jakub Kicinski, Jiri Pirko, netdev
  Cc: Moshe Shemesh

Add pr_out_dev() helper function and use it both by cmd_dev_show_cb()
and by cmd_mon_show_cb().

Dev stats will be added on the next patch to dev context, so
cmd_mon_show_cb() should print the whole dev context and not just dev
handle.

Signed-off-by: Moshe Shemesh <moshe@mellanox.com>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
---
 devlink/devlink.c | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/devlink/devlink.c b/devlink/devlink.c
index a9ba0072..bd588869 100644
--- a/devlink/devlink.c
+++ b/devlink/devlink.c
@@ -2974,17 +2974,11 @@ static int cmd_dev_param(struct dl *dl)
 	pr_err("Command \"%s\" not found\n", dl_argv(dl));
 	return -ENOENT;
 }
-static int cmd_dev_show_cb(const struct nlmsghdr *nlh, void *data)
+
+static void pr_out_dev(struct dl *dl, struct nlattr **tb)
 {
-	struct dl *dl = data;
-	struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {};
-	struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
 	uint8_t reload_failed = 0;
 
-	mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
-	if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME])
-		return MNL_CB_ERROR;
-
 	if (tb[DEVLINK_ATTR_RELOAD_FAILED])
 		reload_failed = mnl_attr_get_u8(tb[DEVLINK_ATTR_RELOAD_FAILED]);
 
@@ -2996,7 +2990,19 @@ static int cmd_dev_show_cb(const struct nlmsghdr *nlh, void *data)
 	} else {
 		pr_out_handle(dl, tb);
 	}
+}
 
+static int cmd_dev_show_cb(const struct nlmsghdr *nlh, void *data)
+{
+	struct dl *dl = data;
+	struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {};
+	struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
+
+	mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
+	if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME])
+		return MNL_CB_ERROR;
+
+	pr_out_dev(dl, tb);
 	return MNL_CB_OK;
 }
 
@@ -4838,7 +4844,7 @@ static int cmd_mon_show_cb(const struct nlmsghdr *nlh, void *data)
 		if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME])
 			return MNL_CB_ERROR;
 		pr_out_mon_header(genl->cmd);
-		pr_out_handle(dl, tb);
+		pr_out_dev(dl, tb);
 		pr_out_mon_footer();
 		break;
 	case DEVLINK_CMD_PORT_GET: /* fall through */
-- 
2.18.2


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH iproute2-net 3/3] devlink: Add reload stats to dev show
  2020-11-26 11:14 [PATCH iproute2-net 0/3] devlink: Add devlink reload action limit and stats Moshe Shemesh
  2020-11-26 11:14 ` [PATCH iproute2-net 1/3] devlink: Add devlink reload action and limit options Moshe Shemesh
  2020-11-26 11:14 ` [PATCH iproute2-net 2/3] devlink: Add pr_out_dev() helper function Moshe Shemesh
@ 2020-11-26 11:14 ` Moshe Shemesh
  2020-11-29 21:22   ` David Ahern
  2020-12-01 11:25 ` [PATCH iproute2-net 0/3] devlink: Add devlink reload action limit and stats Vasundhara Volam
  3 siblings, 1 reply; 12+ messages in thread
From: Moshe Shemesh @ 2020-11-26 11:14 UTC (permalink / raw)
  To: Stephen Hemminger, David Ahern, Jakub Kicinski, Jiri Pirko, netdev
  Cc: Moshe Shemesh

Show reload statistics through devlink dev show using devlink stats
flag. The reload statistics show the history per reload action type and
limit. Add remote reload statistics to show the history of actions
performed due devlink reload commands initiated by remote host.

Output examples:
$ devlink dev show -s
pci/0000:82:00.0:
  stats:
      reload:
          driver_reinit:
            unspecified 2
          fw_activate:
            unspecified 1 no_reset 0
      remote_reload:
          driver_reinit:
            unspecified 0
          fw_activate:
            unspecified 0 no_reset 0
pci/0000:82:00.1:
  stats:
      reload:
          driver_reinit:
            unspecified 0
          fw_activate:
            unspecified 0 no_reset 0
      remote_reload:
          driver_reinit:
            unspecified 1
          fw_activate:
            unspecified 1 no_reset 0

$ devlink dev show -s -jp
{
    "dev": {
        "pci/0000:82:00.0": {
            "stats": {
                "reload": {
                    "driver_reinit": {
                        "unspecified": 2
                    },
                    "fw_activate": {
                        "unspecified": 1,
                        "no_reset": 0
                    }
                },
                "remote_reload": {
                    "driver_reinit": {
                        "unspecified": 0
                    },
                    "fw_activate": {
                        "unspecified": 0,
                        "no_reset": 0
                    }
                }
            }
        },
        "pci/0000:82:00.1": {
            "stats": {
                "reload": {
                    "driver_reinit": {
                        "unspecified": 0
                    },
                    "fw_activate": {
                        "unspecified": 0,
                        "no_reset": 0
                    }
                },
                "remote_reload": {
                    "driver_reinit": {
                        "unspecified": 1
                    },
                    "fw_activate": {
                        "unspecified": 1,
                        "no_reset": 0
                    }
                }
            }
        }
    }
}

Signed-off-by: Moshe Shemesh <moshe@mellanox.com>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
---
 devlink/devlink.c            | 102 ++++++++++++++++++++++++++++++++++-
 include/uapi/linux/devlink.h |   2 +
 2 files changed, 102 insertions(+), 2 deletions(-)

diff --git a/devlink/devlink.c b/devlink/devlink.c
index bd588869..b588ba98 100644
--- a/devlink/devlink.c
+++ b/devlink/devlink.c
@@ -682,6 +682,15 @@ static const enum mnl_attr_data_type devlink_policy[DEVLINK_ATTR_MAX + 1] = {
 	[DEVLINK_ATTR_TRAP_METADATA] = MNL_TYPE_NESTED,
 	[DEVLINK_ATTR_TRAP_GROUP_NAME] = MNL_TYPE_STRING,
 	[DEVLINK_ATTR_RELOAD_FAILED] = MNL_TYPE_U8,
+	[DEVLINK_ATTR_DEV_STATS] = MNL_TYPE_NESTED,
+	[DEVLINK_ATTR_RELOAD_STATS] = MNL_TYPE_NESTED,
+	[DEVLINK_ATTR_RELOAD_STATS_ENTRY] = MNL_TYPE_NESTED,
+	[DEVLINK_ATTR_RELOAD_ACTION] = MNL_TYPE_U8,
+	[DEVLINK_ATTR_RELOAD_STATS_LIMIT] = MNL_TYPE_U8,
+	[DEVLINK_ATTR_RELOAD_STATS_VALUE] = MNL_TYPE_U32,
+	[DEVLINK_ATTR_REMOTE_RELOAD_STATS] = MNL_TYPE_NESTED,
+	[DEVLINK_ATTR_RELOAD_ACTION_INFO] = MNL_TYPE_NESTED,
+	[DEVLINK_ATTR_RELOAD_ACTION_STATS] = MNL_TYPE_NESTED,
 	[DEVLINK_ATTR_TRAP_POLICER_ID] = MNL_TYPE_U32,
 	[DEVLINK_ATTR_TRAP_POLICER_RATE] = MNL_TYPE_U64,
 	[DEVLINK_ATTR_TRAP_POLICER_BURST] = MNL_TYPE_U64,
@@ -2370,6 +2379,18 @@ static const char *reload_action_name(uint8_t reload_action)
 	}
 }
 
+static const char *reload_limit_name(uint8_t reload_limit)
+{
+	switch (reload_limit) {
+	case DEVLINK_RELOAD_LIMIT_UNSPEC:
+		return "unspecified";
+	case DEVLINK_RELOAD_LIMIT_NO_RESET:
+		return "no_reset";
+	default:
+		return "<unknown reload action>";
+	}
+}
+
 static const char *eswitch_mode_name(uint32_t mode)
 {
 	switch (mode) {
@@ -2975,17 +2996,93 @@ static int cmd_dev_param(struct dl *dl)
 	return -ENOENT;
 }
 
-static void pr_out_dev(struct dl *dl, struct nlattr **tb)
+static void pr_out_action_stats(struct dl *dl, struct nlattr *action_stats)
+{
+	struct nlattr *tb_stats_entry[DEVLINK_ATTR_MAX + 1] = {};
+	struct nlattr *reload_stats_entry;
+	enum devlink_reload_limit limit;
+	uint32_t value;
+	int err;
+
+	mnl_attr_for_each_nested(reload_stats_entry, action_stats) {
+		err = mnl_attr_parse_nested(reload_stats_entry, attr_cb, tb_stats_entry);
+		if (err != MNL_CB_OK)
+			return;
+		if (!tb_stats_entry[DEVLINK_ATTR_RELOAD_STATS_LIMIT] ||
+		    !tb_stats_entry[DEVLINK_ATTR_RELOAD_STATS_VALUE])
+			return;
+
+		check_indent_newline(dl);
+		limit = mnl_attr_get_u8(tb_stats_entry[DEVLINK_ATTR_RELOAD_STATS_LIMIT]);
+		value = mnl_attr_get_u32(tb_stats_entry[DEVLINK_ATTR_RELOAD_STATS_VALUE]);
+		print_uint_name_value(reload_limit_name(limit), value);
+	}
+}
+
+static void pr_out_reload_stats(struct dl *dl, struct nlattr *reload_stats)
+{
+	struct nlattr *tb_action_info[DEVLINK_ATTR_MAX + 1] = {};
+	enum devlink_reload_action action;
+	struct nlattr *action_info;
+	int err;
+
+	mnl_attr_for_each_nested(action_info, reload_stats) {
+		err = mnl_attr_parse_nested(action_info, attr_cb, tb_action_info);
+		if (err != MNL_CB_OK)
+			return;
+		if (!tb_action_info[DEVLINK_ATTR_RELOAD_ACTION] ||
+		    !tb_action_info[DEVLINK_ATTR_RELOAD_ACTION_STATS])
+			return;
+
+		action = mnl_attr_get_u8(tb_action_info[DEVLINK_ATTR_RELOAD_ACTION]);
+		pr_out_object_start(dl, reload_action_name(action));
+		pr_out_action_stats(dl, tb_action_info[DEVLINK_ATTR_RELOAD_ACTION_STATS]);
+		pr_out_object_end(dl);
+	}
+}
+
+static void pr_out_reload_data(struct dl *dl, struct nlattr **tb)
 {
+	struct nlattr *tb_stats[DEVLINK_ATTR_MAX + 1] = {};
 	uint8_t reload_failed = 0;
+	int err;
 
 	if (tb[DEVLINK_ATTR_RELOAD_FAILED])
 		reload_failed = mnl_attr_get_u8(tb[DEVLINK_ATTR_RELOAD_FAILED]);
 
 	if (reload_failed) {
-		__pr_out_handle_start(dl, tb, true, false);
 		check_indent_newline(dl);
 		print_bool(PRINT_ANY, "reload_failed", "reload_failed %s", true);
+	}
+	if (!tb[DEVLINK_ATTR_DEV_STATS] || !dl->stats)
+		return;
+	err = mnl_attr_parse_nested(tb[DEVLINK_ATTR_DEV_STATS], attr_cb, tb_stats);
+	if (err != MNL_CB_OK)
+		return;
+
+	pr_out_object_start(dl, "stats");
+
+	if (tb_stats[DEVLINK_ATTR_RELOAD_STATS]) {
+		pr_out_object_start(dl, "reload");
+		pr_out_reload_stats(dl, tb_stats[DEVLINK_ATTR_RELOAD_STATS]);
+		pr_out_object_end(dl);
+	}
+	if (tb_stats[DEVLINK_ATTR_REMOTE_RELOAD_STATS]) {
+		pr_out_object_start(dl, "remote_reload");
+		pr_out_reload_stats(dl, tb_stats[DEVLINK_ATTR_REMOTE_RELOAD_STATS]);
+		pr_out_object_end(dl);
+	}
+
+	pr_out_object_end(dl);
+}
+
+
+static void pr_out_dev(struct dl *dl, struct nlattr **tb)
+{
+	if ((tb[DEVLINK_ATTR_RELOAD_FAILED] && mnl_attr_get_u8(tb[DEVLINK_ATTR_RELOAD_FAILED])) ||
+	    (tb[DEVLINK_ATTR_DEV_STATS] && dl->stats)) {
+		__pr_out_handle_start(dl, tb, true, false);
+		pr_out_reload_data(dl, tb);
 		pr_out_handle_end(dl);
 	} else {
 		pr_out_handle(dl, tb);
@@ -4844,6 +4941,7 @@ static int cmd_mon_show_cb(const struct nlmsghdr *nlh, void *data)
 		if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME])
 			return MNL_CB_ERROR;
 		pr_out_mon_header(genl->cmd);
+		dl->stats = true;
 		pr_out_dev(dl, tb);
 		pr_out_mon_footer();
 		break;
diff --git a/include/uapi/linux/devlink.h b/include/uapi/linux/devlink.h
index e639a4e5..6ffa0121 100644
--- a/include/uapi/linux/devlink.h
+++ b/include/uapi/linux/devlink.h
@@ -526,6 +526,8 @@ enum devlink_attr {
 	DEVLINK_ATTR_RELOAD_STATS_LIMIT,	/* u8 */
 	DEVLINK_ATTR_RELOAD_STATS_VALUE,	/* u32 */
 	DEVLINK_ATTR_REMOTE_RELOAD_STATS,	/* nested */
+	DEVLINK_ATTR_RELOAD_ACTION_INFO,	/* nested */
+	DEVLINK_ATTR_RELOAD_ACTION_STATS,	/* nested */
 
 	/* add new attributes above here, update the policy in devlink.c */
 
-- 
2.18.2


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH iproute2-net 1/3] devlink: Add devlink reload action and limit options
  2020-11-26 11:14 ` [PATCH iproute2-net 1/3] devlink: Add devlink reload action and limit options Moshe Shemesh
@ 2020-11-29 21:12   ` David Ahern
  2020-12-02  6:57     ` Moshe Shemesh
  0 siblings, 1 reply; 12+ messages in thread
From: David Ahern @ 2020-11-29 21:12 UTC (permalink / raw)
  To: Moshe Shemesh, Stephen Hemminger, Jakub Kicinski, Jiri Pirko, netdev

On 11/26/20 4:14 AM, Moshe Shemesh wrote:
> @@ -1997,7 +2066,7 @@ static void cmd_dev_help(void)
>  	pr_err("       devlink dev eswitch show DEV\n");
>  	pr_err("       devlink dev param set DEV name PARAMETER value VALUE cmode { permanent | driverinit | runtime }\n");
>  	pr_err("       devlink dev param show [DEV name PARAMETER]\n");
> -	pr_err("       devlink dev reload DEV [ netns { PID | NAME | ID } ]\n");
> +	pr_err("       devlink dev reload DEV [ netns { PID | NAME | ID } ] [ action { driver_reinit | fw_activate } ] [ limit no_reset ]\n");

line length is unreasonable; add new options on the next line.

>  	pr_err("       devlink dev info [ DEV ]\n");
>  	pr_err("       devlink dev flash DEV file PATH [ component NAME ] [ overwrite SECTION ]\n");
>  }


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH iproute2-net 2/3] devlink: Add pr_out_dev() helper function
  2020-11-26 11:14 ` [PATCH iproute2-net 2/3] devlink: Add pr_out_dev() helper function Moshe Shemesh
@ 2020-11-29 21:15   ` David Ahern
  2020-12-02  7:00     ` Moshe Shemesh
  0 siblings, 1 reply; 12+ messages in thread
From: David Ahern @ 2020-11-29 21:15 UTC (permalink / raw)
  To: Moshe Shemesh, Stephen Hemminger, Jakub Kicinski, Jiri Pirko, netdev

On 11/26/20 4:14 AM, Moshe Shemesh wrote:
> diff --git a/devlink/devlink.c b/devlink/devlink.c
> index a9ba0072..bd588869 100644
> --- a/devlink/devlink.c
> +++ b/devlink/devlink.c
> @@ -2974,17 +2974,11 @@ static int cmd_dev_param(struct dl *dl)
>  	pr_err("Command \"%s\" not found\n", dl_argv(dl));
>  	return -ENOENT;
>  }
> -static int cmd_dev_show_cb(const struct nlmsghdr *nlh, void *data)
> +
> +static void pr_out_dev(struct dl *dl, struct nlattr **tb)

why 'pr_out_dev'? there is no 'dev' argument.

>  {
> -	struct dl *dl = data;
> -	struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {};
> -	struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
>  	uint8_t reload_failed = 0;
>  
> -	mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
> -	if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME])
> -		return MNL_CB_ERROR;
> -
>  	if (tb[DEVLINK_ATTR_RELOAD_FAILED])
>  		reload_failed = mnl_attr_get_u8(tb[DEVLINK_ATTR_RELOAD_FAILED]);
>  

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH iproute2-net 3/3] devlink: Add reload stats to dev show
  2020-11-26 11:14 ` [PATCH iproute2-net 3/3] devlink: Add reload stats to dev show Moshe Shemesh
@ 2020-11-29 21:22   ` David Ahern
  2020-12-02  7:01     ` Moshe Shemesh
  0 siblings, 1 reply; 12+ messages in thread
From: David Ahern @ 2020-11-29 21:22 UTC (permalink / raw)
  To: Moshe Shemesh, Stephen Hemminger, Jakub Kicinski, Jiri Pirko, netdev

On 11/26/20 4:14 AM, Moshe Shemesh wrote:
> @@ -2975,17 +2996,93 @@ static int cmd_dev_param(struct dl *dl)
>  	return -ENOENT;
>  }
>  
> -static void pr_out_dev(struct dl *dl, struct nlattr **tb)
> +static void pr_out_action_stats(struct dl *dl, struct nlattr *action_stats)
> +{
> +	struct nlattr *tb_stats_entry[DEVLINK_ATTR_MAX + 1] = {};
> +	struct nlattr *reload_stats_entry;
> +	enum devlink_reload_limit limit;
> +	uint32_t value;
> +	int err;
> +
> +	mnl_attr_for_each_nested(reload_stats_entry, action_stats) {
> +		err = mnl_attr_parse_nested(reload_stats_entry, attr_cb, tb_stats_entry);

wrap lines at 80 columns unless it is a print statement.

> +		if (err != MNL_CB_OK)
> +			return;
> +		if (!tb_stats_entry[DEVLINK_ATTR_RELOAD_STATS_LIMIT] ||
> +		    !tb_stats_entry[DEVLINK_ATTR_RELOAD_STATS_VALUE])
> +			return;
> +
> +		check_indent_newline(dl);
> +		limit = mnl_attr_get_u8(tb_stats_entry[DEVLINK_ATTR_RELOAD_STATS_LIMIT]);
> +		value = mnl_attr_get_u32(tb_stats_entry[DEVLINK_ATTR_RELOAD_STATS_VALUE]);

Use temp variables for the attributes to make the code readable.

> +		print_uint_name_value(reload_limit_name(limit), value);
> +	}
> +}
> +

that applies to all of the patches.


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH iproute2-net 0/3] devlink: Add devlink reload action limit and stats
  2020-11-26 11:14 [PATCH iproute2-net 0/3] devlink: Add devlink reload action limit and stats Moshe Shemesh
                   ` (2 preceding siblings ...)
  2020-11-26 11:14 ` [PATCH iproute2-net 3/3] devlink: Add reload stats to dev show Moshe Shemesh
@ 2020-12-01 11:25 ` Vasundhara Volam
  2020-12-02  8:44   ` Moshe Shemesh
  3 siblings, 1 reply; 12+ messages in thread
From: Vasundhara Volam @ 2020-12-01 11:25 UTC (permalink / raw)
  To: Moshe Shemesh
  Cc: Stephen Hemminger, David Ahern, Jakub Kicinski, Jiri Pirko, Netdev

[-- Attachment #1: Type: text/plain, Size: 1052 bytes --]

On Thu, Nov 26, 2020 at 4:46 PM Moshe Shemesh <moshe@mellanox.com> wrote:
>
> Introduce new options on devlink reload API to enable the user to select
> the reload action required and constrains limits on these actions that he
> may want to ensure.
>
> Add reload stats to show the history per reload action per limit.
>
> Patch 1 adds the new API reload action and reload limit options to
>         devlink reload command.
> Patch 2 adds pr_out_dev() helper function and modify monitor function to
>         use it.
> Patch 3 adds reload stats and remote reload stats to devlink dev show.
>
>
> Moshe Shemesh (3):
>   devlink: Add devlink reload action and limit options
>   devlink: Add pr_out_dev() helper function
>   devlink: Add reload stats to dev show
>
>  devlink/devlink.c            | 260 +++++++++++++++++++++++++++++++++--
>  include/uapi/linux/devlink.h |   2 +
>  2 files changed, 249 insertions(+), 13 deletions(-)
I see man pages are not updated accordingly in this series. Will it be
updated in the follow-up patch?
>
> --
> 2.18.2
>

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4182 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH iproute2-net 1/3] devlink: Add devlink reload action and limit options
  2020-11-29 21:12   ` David Ahern
@ 2020-12-02  6:57     ` Moshe Shemesh
  0 siblings, 0 replies; 12+ messages in thread
From: Moshe Shemesh @ 2020-12-02  6:57 UTC (permalink / raw)
  To: David Ahern, Moshe Shemesh, Stephen Hemminger, Jakub Kicinski,
	Jiri Pirko, netdev


On 11/29/2020 11:12 PM, David Ahern wrote:
> On 11/26/20 4:14 AM, Moshe Shemesh wrote:
>> @@ -1997,7 +2066,7 @@ static void cmd_dev_help(void)
>>   	pr_err("       devlink dev eswitch show DEV\n");
>>   	pr_err("       devlink dev param set DEV name PARAMETER value VALUE cmode { permanent | driverinit | runtime }\n");
>>   	pr_err("       devlink dev param show [DEV name PARAMETER]\n");
>> -	pr_err("       devlink dev reload DEV [ netns { PID | NAME | ID } ]\n");
>> +	pr_err("       devlink dev reload DEV [ netns { PID | NAME | ID } ] [ action { driver_reinit | fw_activate } ] [ limit no_reset ]\n");
> line length is unreasonable; add new options on the next line.
Ack.
>>   	pr_err("       devlink dev info [ DEV ]\n");
>>   	pr_err("       devlink dev flash DEV file PATH [ component NAME ] [ overwrite SECTION ]\n");
>>   }

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH iproute2-net 2/3] devlink: Add pr_out_dev() helper function
  2020-11-29 21:15   ` David Ahern
@ 2020-12-02  7:00     ` Moshe Shemesh
  0 siblings, 0 replies; 12+ messages in thread
From: Moshe Shemesh @ 2020-12-02  7:00 UTC (permalink / raw)
  To: David Ahern, Moshe Shemesh, Stephen Hemminger, Jakub Kicinski,
	Jiri Pirko, netdev


On 11/29/2020 11:15 PM, David Ahern wrote:
> On 11/26/20 4:14 AM, Moshe Shemesh wrote:
>> diff --git a/devlink/devlink.c b/devlink/devlink.c
>> index a9ba0072..bd588869 100644
>> --- a/devlink/devlink.c
>> +++ b/devlink/devlink.c
>> @@ -2974,17 +2974,11 @@ static int cmd_dev_param(struct dl *dl)
>>   	pr_err("Command \"%s\" not found\n", dl_argv(dl));
>>   	return -ENOENT;
>>   }
>> -static int cmd_dev_show_cb(const struct nlmsghdr *nlh, void *data)
>> +
>> +static void pr_out_dev(struct dl *dl, struct nlattr **tb)
> why 'pr_out_dev'? there is no 'dev' argument.


Because it prints command dev show output, the data is in tb argument 
and includes bus name, dev name and dev stats.
>>   {
>> -	struct dl *dl = data;
>> -	struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {};
>> -	struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
>>   	uint8_t reload_failed = 0;
>>   
>> -	mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
>> -	if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME])
>> -		return MNL_CB_ERROR;
>> -
>>   	if (tb[DEVLINK_ATTR_RELOAD_FAILED])
>>   		reload_failed = mnl_attr_get_u8(tb[DEVLINK_ATTR_RELOAD_FAILED]);
>>   

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH iproute2-net 3/3] devlink: Add reload stats to dev show
  2020-11-29 21:22   ` David Ahern
@ 2020-12-02  7:01     ` Moshe Shemesh
  0 siblings, 0 replies; 12+ messages in thread
From: Moshe Shemesh @ 2020-12-02  7:01 UTC (permalink / raw)
  To: David Ahern, Moshe Shemesh, Stephen Hemminger, Jakub Kicinski,
	Jiri Pirko, netdev


On 11/29/2020 11:22 PM, David Ahern wrote:
> On 11/26/20 4:14 AM, Moshe Shemesh wrote:
>> @@ -2975,17 +2996,93 @@ static int cmd_dev_param(struct dl *dl)
>>   	return -ENOENT;
>>   }
>>   
>> -static void pr_out_dev(struct dl *dl, struct nlattr **tb)
>> +static void pr_out_action_stats(struct dl *dl, struct nlattr *action_stats)
>> +{
>> +	struct nlattr *tb_stats_entry[DEVLINK_ATTR_MAX + 1] = {};
>> +	struct nlattr *reload_stats_entry;
>> +	enum devlink_reload_limit limit;
>> +	uint32_t value;
>> +	int err;
>> +
>> +	mnl_attr_for_each_nested(reload_stats_entry, action_stats) {
>> +		err = mnl_attr_parse_nested(reload_stats_entry, attr_cb, tb_stats_entry);
> wrap lines at 80 columns unless it is a print statement.
Ack.
>
>> +		if (err != MNL_CB_OK)
>> +			return;
>> +		if (!tb_stats_entry[DEVLINK_ATTR_RELOAD_STATS_LIMIT] ||
>> +		    !tb_stats_entry[DEVLINK_ATTR_RELOAD_STATS_VALUE])
>> +			return;
>> +
>> +		check_indent_newline(dl);
>> +		limit = mnl_attr_get_u8(tb_stats_entry[DEVLINK_ATTR_RELOAD_STATS_LIMIT]);
>> +		value = mnl_attr_get_u32(tb_stats_entry[DEVLINK_ATTR_RELOAD_STATS_VALUE]);
> Use temp variables for the attributes to make the code readable.
Ack.
>
>> +		print_uint_name_value(reload_limit_name(limit), value);
>> +	}
>> +}
>> +
> that applies to all of the patches.
>

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH iproute2-net 0/3] devlink: Add devlink reload action limit and stats
  2020-12-01 11:25 ` [PATCH iproute2-net 0/3] devlink: Add devlink reload action limit and stats Vasundhara Volam
@ 2020-12-02  8:44   ` Moshe Shemesh
  0 siblings, 0 replies; 12+ messages in thread
From: Moshe Shemesh @ 2020-12-02  8:44 UTC (permalink / raw)
  To: Vasundhara Volam, Moshe Shemesh
  Cc: Stephen Hemminger, David Ahern, Jakub Kicinski, Jiri Pirko, Netdev


On 12/1/2020 1:25 PM, Vasundhara Volam wrote:
> On Thu, Nov 26, 2020 at 4:46 PM Moshe Shemesh <moshe@mellanox.com> wrote:
>> Introduce new options on devlink reload API to enable the user to select
>> the reload action required and constrains limits on these actions that he
>> may want to ensure.
>>
>> Add reload stats to show the history per reload action per limit.
>>
>> Patch 1 adds the new API reload action and reload limit options to
>>          devlink reload command.
>> Patch 2 adds pr_out_dev() helper function and modify monitor function to
>>          use it.
>> Patch 3 adds reload stats and remote reload stats to devlink dev show.
>>
>>
>> Moshe Shemesh (3):
>>    devlink: Add devlink reload action and limit options
>>    devlink: Add pr_out_dev() helper function
>>    devlink: Add reload stats to dev show
>>
>>   devlink/devlink.c            | 260 +++++++++++++++++++++++++++++++++--
>>   include/uapi/linux/devlink.h |   2 +
>>   2 files changed, 249 insertions(+), 13 deletions(-)
> I see man pages are not updated accordingly in this series. Will it be
> updated in the follow-up patch?
Right, I will update man page. Thanks.
>> --
>> 2.18.2
>>

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2020-12-02  8:45 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-26 11:14 [PATCH iproute2-net 0/3] devlink: Add devlink reload action limit and stats Moshe Shemesh
2020-11-26 11:14 ` [PATCH iproute2-net 1/3] devlink: Add devlink reload action and limit options Moshe Shemesh
2020-11-29 21:12   ` David Ahern
2020-12-02  6:57     ` Moshe Shemesh
2020-11-26 11:14 ` [PATCH iproute2-net 2/3] devlink: Add pr_out_dev() helper function Moshe Shemesh
2020-11-29 21:15   ` David Ahern
2020-12-02  7:00     ` Moshe Shemesh
2020-11-26 11:14 ` [PATCH iproute2-net 3/3] devlink: Add reload stats to dev show Moshe Shemesh
2020-11-29 21:22   ` David Ahern
2020-12-02  7:01     ` Moshe Shemesh
2020-12-01 11:25 ` [PATCH iproute2-net 0/3] devlink: Add devlink reload action limit and stats Vasundhara Volam
2020-12-02  8:44   ` Moshe Shemesh

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.