mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-08-26 19:00:25 +00:00
net: add an helper to copy xps maps to the new dev_maps
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> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
044ab86d43
commit
402fbb992e
1 changed files with 25 additions and 20 deletions
|
@ -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 cpus_read_lock */
|
||||
int __netif_set_xps_queue(struct net_device *dev, const unsigned long *mask,
|
||||
u16 index, enum xps_map_type type)
|
||||
|
@ -2694,23 +2713,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++;
|
||||
|
@ -2725,18 +2737,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);
|
||||
|
|
Loading…
Reference in a new issue