Skip to content

Commit 6234f87

Browse files
Alexander Duyckdavem330
authored andcommitted
net: Refactor removal of queues from XPS map and apply on num_tc changes
This patch updates the code for removing queues from the XPS map and makes it so that we can apply the code any time we change either the number of traffic classes or the mapping of a given block of queues. This way we avoid having queues pulling traffic from a foreign traffic class. Signed-off-by: Alexander Duyck <alexander.h.duyck@intel.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 8d059b0 commit 6234f87

File tree

1 file changed

+50
-23
lines changed

1 file changed

+50
-23
lines changed

net/core/dev.c

Lines changed: 50 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1970,32 +1970,50 @@ static DEFINE_MUTEX(xps_map_mutex);
19701970
#define xmap_dereference(P) \
19711971
rcu_dereference_protected((P), lockdep_is_held(&xps_map_mutex))
19721972

1973-
static struct xps_map *remove_xps_queue(struct xps_dev_maps *dev_maps,
1974-
int cpu, u16 index)
1973+
static bool remove_xps_queue(struct xps_dev_maps *dev_maps,
1974+
int tci, u16 index)
19751975
{
19761976
struct xps_map *map = NULL;
19771977
int pos;
19781978

19791979
if (dev_maps)
1980-
map = xmap_dereference(dev_maps->cpu_map[cpu]);
1980+
map = xmap_dereference(dev_maps->cpu_map[tci]);
1981+
if (!map)
1982+
return false;
19811983

1982-
for (pos = 0; map && pos < map->len; pos++) {
1983-
if (map->queues[pos] == index) {
1984-
if (map->len > 1) {
1985-
map->queues[pos] = map->queues[--map->len];
1986-
} else {
1987-
RCU_INIT_POINTER(dev_maps->cpu_map[cpu], NULL);
1988-
kfree_rcu(map, rcu);
1989-
map = NULL;
1990-
}
1984+
for (pos = map->len; pos--;) {
1985+
if (map->queues[pos] != index)
1986+
continue;
1987+
1988+
if (map->len > 1) {
1989+
map->queues[pos] = map->queues[--map->len];
19911990
break;
19921991
}
1992+
1993+
RCU_INIT_POINTER(dev_maps->cpu_map[tci], NULL);
1994+
kfree_rcu(map, rcu);
1995+
return false;
19931996
}
19941997

1995-
return map;
1998+
return true;
19961999
}
19972000

1998-
static void netif_reset_xps_queues_gt(struct net_device *dev, u16 index)
2001+
static bool remove_xps_queue_cpu(struct net_device *dev,
2002+
struct xps_dev_maps *dev_maps,
2003+
int cpu, u16 offset, u16 count)
2004+
{
2005+
int i, j;
2006+
2007+
for (i = count, j = offset; i--; j++) {
2008+
if (!remove_xps_queue(dev_maps, cpu, j))
2009+
break;
2010+
}
2011+
2012+
return i < 0;
2013+
}
2014+
2015+
static void netif_reset_xps_queues(struct net_device *dev, u16 offset,
2016+
u16 count)
19992017
{
20002018
struct xps_dev_maps *dev_maps;
20012019
int cpu, i;
@@ -2007,28 +2025,28 @@ static void netif_reset_xps_queues_gt(struct net_device *dev, u16 index)
20072025
if (!dev_maps)
20082026
goto out_no_maps;
20092027

2010-
for_each_possible_cpu(cpu) {
2011-
for (i = index; i < dev->num_tx_queues; i++) {
2012-
if (!remove_xps_queue(dev_maps, cpu, i))
2013-
break;
2014-
}
2015-
if (i == dev->num_tx_queues)
2016-
active = true;
2017-
}
2028+
for_each_possible_cpu(cpu)
2029+
active |= remove_xps_queue_cpu(dev, dev_maps, cpu,
2030+
offset, count);
20182031

20192032
if (!active) {
20202033
RCU_INIT_POINTER(dev->xps_maps, NULL);
20212034
kfree_rcu(dev_maps, rcu);
20222035
}
20232036

2024-
for (i = index; i < dev->num_tx_queues; i++)
2037+
for (i = offset + (count - 1); count--; i--)
20252038
netdev_queue_numa_node_write(netdev_get_tx_queue(dev, i),
20262039
NUMA_NO_NODE);
20272040

20282041
out_no_maps:
20292042
mutex_unlock(&xps_map_mutex);
20302043
}
20312044

2045+
static void netif_reset_xps_queues_gt(struct net_device *dev, u16 index)
2046+
{
2047+
netif_reset_xps_queues(dev, index, dev->num_tx_queues - index);
2048+
}
2049+
20322050
static struct xps_map *expand_xps_map(struct xps_map *map,
20332051
int cpu, u16 index)
20342052
{
@@ -2192,6 +2210,9 @@ EXPORT_SYMBOL(netif_set_xps_queue);
21922210
#endif
21932211
void netdev_reset_tc(struct net_device *dev)
21942212
{
2213+
#ifdef CONFIG_XPS
2214+
netif_reset_xps_queues_gt(dev, 0);
2215+
#endif
21952216
dev->num_tc = 0;
21962217
memset(dev->tc_to_txq, 0, sizeof(dev->tc_to_txq));
21972218
memset(dev->prio_tc_map, 0, sizeof(dev->prio_tc_map));
@@ -2203,6 +2224,9 @@ int netdev_set_tc_queue(struct net_device *dev, u8 tc, u16 count, u16 offset)
22032224
if (tc >= dev->num_tc)
22042225
return -EINVAL;
22052226

2227+
#ifdef CONFIG_XPS
2228+
netif_reset_xps_queues(dev, offset, count);
2229+
#endif
22062230
dev->tc_to_txq[tc].count = count;
22072231
dev->tc_to_txq[tc].offset = offset;
22082232
return 0;
@@ -2214,6 +2238,9 @@ int netdev_set_num_tc(struct net_device *dev, u8 num_tc)
22142238
if (num_tc > TC_MAX_QUEUE)
22152239
return -EINVAL;
22162240

2241+
#ifdef CONFIG_XPS
2242+
netif_reset_xps_queues_gt(dev, 0);
2243+
#endif
22172244
dev->num_tc = num_tc;
22182245
return 0;
22192246
}

0 commit comments

Comments
 (0)