Skip to content

Commit 80d1966

Browse files
anambiarindavem330
authored andcommitted
net: Refactor XPS for CPUs and Rx queues
Refactor XPS code to support Tx queue selection based on CPU(s) map or Rx queue(s) map. Signed-off-by: Amritha Nambiar <amritha.nambiar@intel.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 1a84d7f commit 80d1966

4 files changed

Lines changed: 244 additions & 80 deletions

File tree

‎include/linux/cpumask.h‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,17 @@ extern struct cpumask __cpu_active_mask;
115115
#define cpu_active(cpu) ((cpu) == 0)
116116
#endif
117117

118-
/* verify cpu argument to cpumask_* operators */
119-
static inline unsigned int cpumask_check(unsigned int cpu)
118+
static inline void cpu_max_bits_warn(unsigned int cpu, unsigned int bits)
120119
{
121120
#ifdef CONFIG_DEBUG_PER_CPU_MAPS
122-
WARN_ON_ONCE(cpu >= nr_cpumask_bits);
121+
WARN_ON_ONCE(cpu >= bits);
123122
#endif /* CONFIG_DEBUG_PER_CPU_MAPS */
123+
}
124+
125+
/* verify cpu argument to cpumask_* operators */
126+
static inline unsigned int cpumask_check(unsigned int cpu)
127+
{
128+
cpu_max_bits_warn(cpu, nr_cpumask_bits);
124129
return cpu;
125130
}
126131

‎include/linux/netdevice.h‎

Lines changed: 95 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -731,10 +731,15 @@ struct xps_map {
731731
*/
732732
struct xps_dev_maps {
733733
struct rcu_head rcu;
734-
struct xps_map __rcu *cpu_map[0];
734+
struct xps_map __rcu *attr_map[0]; /* Either CPUs map or RXQs map */
735735
};
736-
#define XPS_DEV_MAPS_SIZE(_tcs) (sizeof(struct xps_dev_maps) + \
736+
737+
#define XPS_CPU_DEV_MAPS_SIZE(_tcs) (sizeof(struct xps_dev_maps) + \
737738
(nr_cpu_ids * (_tcs) * sizeof(struct xps_map *)))
739+
740+
#define XPS_RXQ_DEV_MAPS_SIZE(_tcs, _rxqs) (sizeof(struct xps_dev_maps) +\
741+
(_rxqs * (_tcs) * sizeof(struct xps_map *)))
742+
738743
#endif /* CONFIG_XPS */
739744

740745
#define TC_MAX_QUEUE 16
@@ -1910,7 +1915,8 @@ struct net_device {
19101915
int watchdog_timeo;
19111916

19121917
#ifdef CONFIG_XPS
1913-
struct xps_dev_maps __rcu *xps_maps;
1918+
struct xps_dev_maps __rcu *xps_cpus_map;
1919+
struct xps_dev_maps __rcu *xps_rxqs_map;
19141920
#endif
19151921
#ifdef CONFIG_NET_CLS_ACT
19161922
struct mini_Qdisc __rcu *miniq_egress;
@@ -3259,6 +3265,92 @@ static inline void netif_wake_subqueue(struct net_device *dev, u16 queue_index)
32593265
#ifdef CONFIG_XPS
32603266
int netif_set_xps_queue(struct net_device *dev, const struct cpumask *mask,
32613267
u16 index);
3268+
int __netif_set_xps_queue(struct net_device *dev, const unsigned long *mask,
3269+
u16 index, bool is_rxqs_map);
3270+
3271+
/**
3272+
* netif_attr_test_mask - Test a CPU or Rx queue set in a mask
3273+
* @j: CPU/Rx queue index
3274+
* @mask: bitmask of all cpus/rx queues
3275+
* @nr_bits: number of bits in the bitmask
3276+
*
3277+
* Test if a CPU or Rx queue index is set in a mask of all CPU/Rx queues.
3278+
*/
3279+
static inline bool netif_attr_test_mask(unsigned long j,
3280+
const unsigned long *mask,
3281+
unsigned int nr_bits)
3282+
{
3283+
cpu_max_bits_warn(j, nr_bits);
3284+
return test_bit(j, mask);
3285+
}
3286+
3287+
/**
3288+
* netif_attr_test_online - Test for online CPU/Rx queue
3289+
* @j: CPU/Rx queue index
3290+
* @online_mask: bitmask for CPUs/Rx queues that are online
3291+
* @nr_bits: number of bits in the bitmask
3292+
*
3293+
* Returns true if a CPU/Rx queue is online.
3294+
*/
3295+
static inline bool netif_attr_test_online(unsigned long j,
3296+
const unsigned long *online_mask,
3297+
unsigned int nr_bits)
3298+
{
3299+
cpu_max_bits_warn(j, nr_bits);
3300+
3301+
if (online_mask)
3302+
return test_bit(j, online_mask);
3303+
3304+
return (j < nr_bits);
3305+
}
3306+
3307+
/**
3308+
* netif_attrmask_next - get the next CPU/Rx queue in a cpu/Rx queues mask
3309+
* @n: CPU/Rx queue index
3310+
* @srcp: the cpumask/Rx queue mask pointer
3311+
* @nr_bits: number of bits in the bitmask
3312+
*
3313+
* Returns >= nr_bits if no further CPUs/Rx queues set.
3314+
*/
3315+
static inline unsigned int netif_attrmask_next(int n, const unsigned long *srcp,
3316+
unsigned int nr_bits)
3317+
{
3318+
/* -1 is a legal arg here. */
3319+
if (n != -1)
3320+
cpu_max_bits_warn(n, nr_bits);
3321+
3322+
if (srcp)
3323+
return find_next_bit(srcp, nr_bits, n + 1);
3324+
3325+
return n + 1;
3326+
}
3327+
3328+
/**
3329+
* netif_attrmask_next_and - get the next CPU/Rx queue in *src1p & *src2p
3330+
* @n: CPU/Rx queue index
3331+
* @src1p: the first CPUs/Rx queues mask pointer
3332+
* @src2p: the second CPUs/Rx queues mask pointer
3333+
* @nr_bits: number of bits in the bitmask
3334+
*
3335+
* Returns >= nr_bits if no further CPUs/Rx queues set in both.
3336+
*/
3337+
static inline int netif_attrmask_next_and(int n, const unsigned long *src1p,
3338+
const unsigned long *src2p,
3339+
unsigned int nr_bits)
3340+
{
3341+
/* -1 is a legal arg here. */
3342+
if (n != -1)
3343+
cpu_max_bits_warn(n, nr_bits);
3344+
3345+
if (src1p && src2p)
3346+
return find_next_and_bit(src1p, src2p, nr_bits, n + 1);
3347+
else if (src1p)
3348+
return find_next_bit(src1p, nr_bits, n + 1);
3349+
else if (src2p)
3350+
return find_next_bit(src2p, nr_bits, n + 1);
3351+
3352+
return n + 1;
3353+
}
32623354
#else
32633355
static inline int netif_set_xps_queue(struct net_device *dev,
32643356
const struct cpumask *mask,

0 commit comments

Comments
 (0)