All of lore.kernel.org
 help / color / mirror / Atom feed
From: Antoine Tenart <atenart@kernel.org>
To: davem@davemloft.net, kuba@kernel.org, alexander.duyck@gmail.com
Cc: Antoine Tenart <atenart@kernel.org>, netdev@vger.kernel.org
Subject: [PATCH net-next v3 09/16] net: add an helper to copy xps maps to the new dev_maps
Date: Fri, 12 Mar 2021 16:04:37 +0100	[thread overview]
Message-ID: <20210312150444.355207-10-atenart@kernel.org> (raw)
In-Reply-To: <20210312150444.355207-1-atenart@kernel.org>

This patch adds an helper, xps_copy_dev_maps, to copy maps from dev_maps
to new_dev_maps at a given index. The logic should be the same, with an
improved code readability and maintenance.

Signed-off-by: Antoine Tenart <atenart@kernel.org>
---
 net/core/dev.c | 45 +++++++++++++++++++++++++--------------------
 1 file changed, 25 insertions(+), 20 deletions(-)

diff --git a/net/core/dev.c b/net/core/dev.c
index dfdd476a6d67..4d39938417c4 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -2608,6 +2608,25 @@ static struct xps_map *expand_xps_map(struct xps_map *map, int attr_index,
 	return new_map;
 }
 
+/* Copy xps maps at a given index */
+static void xps_copy_dev_maps(struct xps_dev_maps *dev_maps,
+			      struct xps_dev_maps *new_dev_maps, int index,
+			      int tc, bool skip_tc)
+{
+	int i, tci = index * dev_maps->num_tc;
+	struct xps_map *map;
+
+	/* copy maps belonging to foreign traffic classes */
+	for (i = 0; i < dev_maps->num_tc; i++, tci++) {
+		if (i == tc && skip_tc)
+			continue;
+
+		/* fill in the new device map from the old device map */
+		map = xmap_dereference(dev_maps->attr_map[tci]);
+		RCU_INIT_POINTER(new_dev_maps->attr_map[tci], map);
+	}
+}
+
 /* Must be called under rtnl_lock and cpus_read_lock */
 int __netif_set_xps_queue(struct net_device *dev, const unsigned long *mask,
 			  u16 index, enum xps_map_type type)
@@ -2696,23 +2715,16 @@ int __netif_set_xps_queue(struct net_device *dev, const unsigned long *mask,
 	}
 
 	for (j = 0; j < nr_ids; j++) {
-		/* copy maps belonging to foreign traffic classes */
-		for (i = tc, tci = j * num_tc; copy && i--; tci++) {
-			/* fill in the new device map from the old device map */
-			map = xmap_dereference(dev_maps->attr_map[tci]);
-			RCU_INIT_POINTER(new_dev_maps->attr_map[tci], map);
-		}
+		bool skip_tc = false;
 
-		/* We need to explicitly update tci as prevous loop
-		 * could break out early if dev_maps is NULL.
-		 */
 		tci = j * num_tc + tc;
-
 		if (netif_attr_test_mask(j, mask, nr_ids) &&
 		    netif_attr_test_online(j, online_mask, nr_ids)) {
 			/* add tx-queue to CPU/rx-queue maps */
 			int pos = 0;
 
+			skip_tc = true;
+
 			map = xmap_dereference(new_dev_maps->attr_map[tci]);
 			while ((pos < map->len) && (map->queues[pos] != index))
 				pos++;
@@ -2727,18 +2739,11 @@ int __netif_set_xps_queue(struct net_device *dev, const unsigned long *mask,
 					numa_node_id = -1;
 			}
 #endif
-		} else if (copy) {
-			/* fill in the new device map from the old device map */
-			map = xmap_dereference(dev_maps->attr_map[tci]);
-			RCU_INIT_POINTER(new_dev_maps->attr_map[tci], map);
 		}
 
-		/* copy maps belonging to foreign traffic classes */
-		for (i = num_tc - tc, tci++; copy && --i; tci++) {
-			/* fill in the new device map from the old device map */
-			map = xmap_dereference(dev_maps->attr_map[tci]);
-			RCU_INIT_POINTER(new_dev_maps->attr_map[tci], map);
-		}
+		if (copy)
+			xps_copy_dev_maps(dev_maps, new_dev_maps, j, tc,
+					  skip_tc);
 	}
 
 	rcu_assign_pointer(dev->xps_maps[type], new_dev_maps);
-- 
2.29.2


  parent reply	other threads:[~2021-03-12 15:06 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-12 15:04 [PATCH net-next v3 00/16] net: xps: improve the xps maps handling Antoine Tenart
2021-03-12 15:04 ` [PATCH net-next v3 01/16] net-sysfs: convert xps_cpus_show to bitmap_zalloc Antoine Tenart
2021-03-12 15:04 ` [PATCH net-next v3 02/16] net-sysfs: store the return of get_netdev_queue_index in an unsigned int Antoine Tenart
2021-03-12 15:04 ` [PATCH net-next v3 03/16] net-sysfs: make xps_cpus_show and xps_rxqs_show consistent Antoine Tenart
2021-03-12 15:04 ` [PATCH net-next v3 04/16] net: embed num_tc in the xps maps Antoine Tenart
2021-03-12 15:04 ` [PATCH net-next v3 05/16] net: embed nr_ids " Antoine Tenart
2021-03-12 15:04 ` [PATCH net-next v3 06/16] net: assert the rtnl lock is held when calling __netif_set_xps_queue Antoine Tenart
2021-03-12 15:04 ` [PATCH net-next v3 07/16] net: remove the xps possible_mask Antoine Tenart
2021-03-12 15:04 ` [PATCH net-next v3 08/16] net: move the xps maps to an array Antoine Tenart
2021-03-12 15:04 ` Antoine Tenart [this message]
2021-03-12 15:04 ` [PATCH net-next v3 10/16] net: improve queue removal readability in __netif_set_xps_queue Antoine Tenart
2021-03-12 15:04 ` [PATCH net-next v3 11/16] net-sysfs: move the rtnl unlock up in the xps show helpers Antoine Tenart
2021-03-12 15:04 ` [PATCH net-next v3 12/16] net-sysfs: move the xps cpus/rxqs retrieval in a common function Antoine Tenart
2021-03-12 15:04 ` [PATCH net-next v3 13/16] net: fix use after free in xps Antoine Tenart
2021-03-12 15:04 ` [PATCH net-next v3 14/16] net: NULL the old xps map entries when freeing them Antoine Tenart
2021-03-12 15:04 ` [PATCH net-next v3 15/16] net/mlx5e: take the rtnl lock when calling netif_set_xps_queue Antoine Tenart
2021-03-12 20:54   ` Saeed Mahameed
2021-03-15  8:38     ` Antoine Tenart
2021-03-15 14:53       ` Maxim Mikityanskiy
2021-03-15 15:13         ` Antoine Tenart
2021-03-17  8:55     ` Antoine Tenart
2021-03-12 15:04 ` [PATCH net-next v3 16/16] virtio_net: take the rtnl lock when calling virtnet_set_affinity Antoine Tenart

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210312150444.355207-10-atenart@kernel.org \
    --to=atenart@kernel.org \
    --cc=alexander.duyck@gmail.com \
    --cc=davem@davemloft.net \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.