netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [patch iproute2-main] devlink: load port-ifname map on demand
@ 2022-08-18  8:28 Jiri Pirko
  2022-08-18  9:40 ` Jiri Pirko
  0 siblings, 1 reply; 3+ messages in thread
From: Jiri Pirko @ 2022-08-18  8:28 UTC (permalink / raw)
  To: netdev; +Cc: sthemmin, dsahern, moshe

From: Jiri Pirko <jiri@nvidia.com>

So far, the port-ifname map was loaded during devlink init
no matter if actually needed or not. Port dump cmd which is utilized
for this in kernel takes lock for every devlink instance.
That may lead to unnecessary blockage of command.

Load the map only in time it is needed to lookup ifname.

Signed-off-by: Jiri Pirko <jiri@nvidia.com>
---
 devlink/devlink.c | 31 ++++++++++++++++++-------------
 1 file changed, 18 insertions(+), 13 deletions(-)

diff --git a/devlink/devlink.c b/devlink/devlink.c
index 21f26246f91b..4ef5dc4a5600 100644
--- a/devlink/devlink.c
+++ b/devlink/devlink.c
@@ -374,6 +374,7 @@ struct dl {
 	bool verbose;
 	bool stats;
 	bool hex;
+	bool map_loaded;
 	struct {
 		bool present;
 		char *bus_name;
@@ -816,13 +817,15 @@ static void ifname_map_fini(struct dl *dl)
 	}
 }
 
-static int ifname_map_init(struct dl *dl)
+static void ifname_map_init(struct dl *dl)
 {
-	struct nlmsghdr *nlh;
-	int err;
-
 	INIT_LIST_HEAD(&dl->ifname_map_list);
+}
 
+static int ifname_map_load(struct dl *dl)
+{
+	struct nlmsghdr *nlh;
+	int err;
 
 	nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_PORT_GET,
 			       NLM_F_REQUEST | NLM_F_ACK | NLM_F_DUMP);
@@ -840,7 +843,16 @@ static int ifname_map_lookup(struct dl *dl, const char *ifname,
 			     uint32_t *p_port_index)
 {
 	struct ifname_map *ifname_map;
+	int err;
 
+	if (!dl->map_loaded) {
+		err = ifname_map_load(dl);
+		if (err) {
+			pr_err("Failed to create index map\n");
+			return err;
+		}
+		dl->map_loaded = true;
+	}
 	list_for_each_entry(ifname_map, &dl->ifname_map_list, list) {
 		if (strcmp(ifname, ifname_map->ifname) == 0) {
 			*p_bus_name = ifname_map->bus_name;
@@ -9528,17 +9540,10 @@ static int dl_init(struct dl *dl)
 		return -errno;
 	}
 
-	err = ifname_map_init(dl);
-	if (err) {
-		pr_err("Failed to create index map\n");
-		goto err_ifname_map_create;
-	}
+	ifname_map_init(dl);
+
 	new_json_obj_plain(dl->json_output);
 	return 0;
-
-err_ifname_map_create:
-	mnlu_gen_socket_close(&dl->nlg);
-	return err;
 }
 
 static void dl_fini(struct dl *dl)
-- 
2.37.1


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

* Re: [patch iproute2-main] devlink: load port-ifname map on demand
  2022-08-18  8:28 [patch iproute2-main] devlink: load port-ifname map on demand Jiri Pirko
@ 2022-08-18  9:40 ` Jiri Pirko
  2022-08-18 21:02   ` Keller, Jacob E
  0 siblings, 1 reply; 3+ messages in thread
From: Jiri Pirko @ 2022-08-18  9:40 UTC (permalink / raw)
  To: netdev; +Cc: sthemmin, dsahern, moshe, jacob.e.keller

Actually, please scratch this for now. Depends on Jacob's "devlink:
remove dl_argv_parse_put" patch. Somehow I got the impression it is
already merged.

Sorry for the fuzz.


Thu, Aug 18, 2022 at 10:28:56AM CEST, jiri@resnulli.us wrote:
>From: Jiri Pirko <jiri@nvidia.com>
>
>So far, the port-ifname map was loaded during devlink init
>no matter if actually needed or not. Port dump cmd which is utilized
>for this in kernel takes lock for every devlink instance.
>That may lead to unnecessary blockage of command.
>
>Load the map only in time it is needed to lookup ifname.
>
>Signed-off-by: Jiri Pirko <jiri@nvidia.com>
>---
> devlink/devlink.c | 31 ++++++++++++++++++-------------
> 1 file changed, 18 insertions(+), 13 deletions(-)
>
>diff --git a/devlink/devlink.c b/devlink/devlink.c
>index 21f26246f91b..4ef5dc4a5600 100644
>--- a/devlink/devlink.c
>+++ b/devlink/devlink.c
>@@ -374,6 +374,7 @@ struct dl {
> 	bool verbose;
> 	bool stats;
> 	bool hex;
>+	bool map_loaded;
> 	struct {
> 		bool present;
> 		char *bus_name;
>@@ -816,13 +817,15 @@ static void ifname_map_fini(struct dl *dl)
> 	}
> }
> 
>-static int ifname_map_init(struct dl *dl)
>+static void ifname_map_init(struct dl *dl)
> {
>-	struct nlmsghdr *nlh;
>-	int err;
>-
> 	INIT_LIST_HEAD(&dl->ifname_map_list);
>+}
> 
>+static int ifname_map_load(struct dl *dl)
>+{
>+	struct nlmsghdr *nlh;
>+	int err;
> 
> 	nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_PORT_GET,
> 			       NLM_F_REQUEST | NLM_F_ACK | NLM_F_DUMP);
>@@ -840,7 +843,16 @@ static int ifname_map_lookup(struct dl *dl, const char *ifname,
> 			     uint32_t *p_port_index)
> {
> 	struct ifname_map *ifname_map;
>+	int err;
> 
>+	if (!dl->map_loaded) {
>+		err = ifname_map_load(dl);
>+		if (err) {
>+			pr_err("Failed to create index map\n");
>+			return err;
>+		}
>+		dl->map_loaded = true;
>+	}
> 	list_for_each_entry(ifname_map, &dl->ifname_map_list, list) {
> 		if (strcmp(ifname, ifname_map->ifname) == 0) {
> 			*p_bus_name = ifname_map->bus_name;
>@@ -9528,17 +9540,10 @@ static int dl_init(struct dl *dl)
> 		return -errno;
> 	}
> 
>-	err = ifname_map_init(dl);
>-	if (err) {
>-		pr_err("Failed to create index map\n");
>-		goto err_ifname_map_create;
>-	}
>+	ifname_map_init(dl);
>+
> 	new_json_obj_plain(dl->json_output);
> 	return 0;
>-
>-err_ifname_map_create:
>-	mnlu_gen_socket_close(&dl->nlg);
>-	return err;
> }
> 
> static void dl_fini(struct dl *dl)
>-- 
>2.37.1
>

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

* RE: [patch iproute2-main] devlink: load port-ifname map on demand
  2022-08-18  9:40 ` Jiri Pirko
@ 2022-08-18 21:02   ` Keller, Jacob E
  0 siblings, 0 replies; 3+ messages in thread
From: Keller, Jacob E @ 2022-08-18 21:02 UTC (permalink / raw)
  To: Jiri Pirko, netdev@vger.kernel.org
  Cc: sthemmin@microsoft.com, dsahern@gmail.com, moshe@nvidia.com



> -----Original Message-----
> From: Jiri Pirko <jiri@resnulli.us>
> Sent: Thursday, August 18, 2022 2:41 AM
> To: netdev@vger.kernel.org
> Cc: sthemmin@microsoft.com; dsahern@gmail.com; moshe@nvidia.com; Keller,
> Jacob E <jacob.e.keller@intel.com>
> Subject: Re: [patch iproute2-main] devlink: load port-ifname map on demand
> 
> Actually, please scratch this for now. Depends on Jacob's "devlink:
> remove dl_argv_parse_put" patch. Somehow I got the impression it is
> already merged.
> 
> Sorry for the fuzz.


I'm about to send this series. Sorry for the delay, I got a bad cold earlier this week which knocked me out for a couple days.

Thanks,
Jake


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

end of thread, other threads:[~2022-08-18 21:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-08-18  8:28 [patch iproute2-main] devlink: load port-ifname map on demand Jiri Pirko
2022-08-18  9:40 ` Jiri Pirko
2022-08-18 21:02   ` Keller, Jacob E

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).