Re: [net-next PATCH v2 1/4] net: Refactor XPS for CPUs and Rx queues

2018-05-23 Thread Nambiar, Amritha
On 5/17/2018 9:08 PM, Tom Herbert wrote:
> On Tue, May 15, 2018 at 6:26 PM, Amritha Nambiar
>  wrote:
>> Refactor XPS code to support Tx queue selection based on
>> CPU map or Rx queue map.
>>
>> Signed-off-by: Amritha Nambiar 
>> ---
>>  include/linux/cpumask.h   |   11 ++
>>  include/linux/netdevice.h |   72 +++-
>>  net/core/dev.c|  208 
>> +
>>  net/core/net-sysfs.c  |4 -
>>  4 files changed, 215 insertions(+), 80 deletions(-)
>>
>> diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
>> index bf53d89..57f20a0 100644
>> --- a/include/linux/cpumask.h
>> +++ b/include/linux/cpumask.h
>> @@ -115,12 +115,17 @@ extern struct cpumask __cpu_active_mask;
>>  #define cpu_active(cpu)((cpu) == 0)
>>  #endif
>>
>> -/* verify cpu argument to cpumask_* operators */
>> -static inline unsigned int cpumask_check(unsigned int cpu)
>> +static inline void cpu_max_bits_warn(unsigned int cpu, unsigned int bits)
>>  {
>>  #ifdef CONFIG_DEBUG_PER_CPU_MAPS
>> -   WARN_ON_ONCE(cpu >= nr_cpumask_bits);
>> +   WARN_ON_ONCE(cpu >= bits);
>>  #endif /* CONFIG_DEBUG_PER_CPU_MAPS */
>> +}
>> +
>> +/* verify cpu argument to cpumask_* operators */
>> +static inline unsigned int cpumask_check(unsigned int cpu)
>> +{
>> +   cpu_max_bits_warn(cpu, nr_cpumask_bits);
>> return cpu;
>>  }
>>
>> diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
>> index 03ed492..c2eeb36 100644
>> --- a/include/linux/netdevice.h
>> +++ b/include/linux/netdevice.h
>> @@ -730,10 +730,21 @@ struct xps_map {
>>   */
>>  struct xps_dev_maps {
>> struct rcu_head rcu;
>> -   struct xps_map __rcu *cpu_map[0];
>> +   struct xps_map __rcu *attr_map[0];
>>  };
>> -#define XPS_DEV_MAPS_SIZE(_tcs) (sizeof(struct xps_dev_maps) + \
>> +
>> +#define XPS_CPU_DEV_MAPS_SIZE(_tcs) (sizeof(struct xps_dev_maps) + \
>> (nr_cpu_ids * (_tcs) * sizeof(struct xps_map *)))
>> +
>> +#define XPS_RXQ_DEV_MAPS_SIZE(_tcs, _rxqs) (sizeof(struct xps_dev_maps) +\
>> +   (_rxqs * (_tcs) * sizeof(struct xps_map *)))
>> +
>> +enum xps_map_type {
>> +   XPS_MAP_RXQS,
>> +   XPS_MAP_CPUS,
>> +   __XPS_MAP_MAX
>> +};
>> +
>>  #endif /* CONFIG_XPS */
>>
>>  #define TC_MAX_QUEUE   16
>> @@ -1891,7 +1902,7 @@ struct net_device {
>> int watchdog_timeo;
>>
>>  #ifdef CONFIG_XPS
>> -   struct xps_dev_maps __rcu *xps_maps;
>> +   struct xps_dev_maps __rcu *xps_maps[__XPS_MAP_MAX];
>>  #endif
>>  #ifdef CONFIG_NET_CLS_ACT
>> struct mini_Qdisc __rcu *miniq_egress;
>> @@ -3229,6 +3240,61 @@ static inline void netif_wake_subqueue(struct 
>> net_device *dev, u16 queue_index)
>>  #ifdef CONFIG_XPS
>>  int netif_set_xps_queue(struct net_device *dev, const struct cpumask *mask,
>> u16 index);
>> +int __netif_set_xps_queue(struct net_device *dev, const unsigned long *mask,
>> + u16 index, enum xps_map_type type);
>> +
>> +static inline bool attr_test_mask(unsigned long j, const unsigned long 
>> *mask,
>> + unsigned int nr_bits)
>> +{
>> +   cpu_max_bits_warn(j, nr_bits);
>> +   return test_bit(j, mask);
>> +}
>> +
>> +static inline bool attr_test_online(unsigned long j,
>> +   const unsigned long *online_mask,
>> +   unsigned int nr_bits)
>> +{
>> +   cpu_max_bits_warn(j, nr_bits);
>> +
>> +   if (online_mask)
>> +   return test_bit(j, online_mask);
>> +
>> +   if (j >= 0 && j < nr_bits)
>> +   return true;
>> +
>> +   return false;
>> +}
>> +
>> +static inline unsigned int attrmask_next(int n, const unsigned long *srcp,
>> +unsigned int nr_bits)
>> +{
>> +   /* -1 is a legal arg here. */
>> +   if (n != -1)
>> +   cpu_max_bits_warn(n, nr_bits);
>> +
>> +   if (srcp)
>> +   return find_next_bit(srcp, nr_bits, n + 1);
>> +
>> +   return n + 1;
>> +}
>> +
>> +static inline int attrmask_next_and(int n, const unsigned long *src1p,
>> +   const unsigned long *src2p,
>> +   unsigned int nr_bits)
>> +{
>> +   /* -1 is a legal arg here. */
>> +   if (n != -1)
>> +   cpu_max_bits_warn(n, nr_bits);
>> +
>> +   if (src1p && src2p)
>> +   return find_next_and_bit(src1p, src2p, nr_bits, n + 1);
>> +   else if (src1p)
>> +   return find_next_bit(src1p, nr_bits, n + 1);
>> +   else if (src2p)
>> +   return find_next_bit(src2p, nr_bits, n + 1);
>> +
>> +   return n + 1;
>> +}
>>  #else
>>  static inline int netif_set_xps_queue(struct net_device *dev,
>>   const struct cpumask *mask,
>> diff --git 

Re: [net-next PATCH v2 1/4] net: Refactor XPS for CPUs and Rx queues

2018-05-17 Thread Tom Herbert
On Tue, May 15, 2018 at 6:26 PM, Amritha Nambiar
 wrote:
> Refactor XPS code to support Tx queue selection based on
> CPU map or Rx queue map.
>
> Signed-off-by: Amritha Nambiar 
> ---
>  include/linux/cpumask.h   |   11 ++
>  include/linux/netdevice.h |   72 +++-
>  net/core/dev.c|  208 
> +
>  net/core/net-sysfs.c  |4 -
>  4 files changed, 215 insertions(+), 80 deletions(-)
>
> diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
> index bf53d89..57f20a0 100644
> --- a/include/linux/cpumask.h
> +++ b/include/linux/cpumask.h
> @@ -115,12 +115,17 @@ extern struct cpumask __cpu_active_mask;
>  #define cpu_active(cpu)((cpu) == 0)
>  #endif
>
> -/* verify cpu argument to cpumask_* operators */
> -static inline unsigned int cpumask_check(unsigned int cpu)
> +static inline void cpu_max_bits_warn(unsigned int cpu, unsigned int bits)
>  {
>  #ifdef CONFIG_DEBUG_PER_CPU_MAPS
> -   WARN_ON_ONCE(cpu >= nr_cpumask_bits);
> +   WARN_ON_ONCE(cpu >= bits);
>  #endif /* CONFIG_DEBUG_PER_CPU_MAPS */
> +}
> +
> +/* verify cpu argument to cpumask_* operators */
> +static inline unsigned int cpumask_check(unsigned int cpu)
> +{
> +   cpu_max_bits_warn(cpu, nr_cpumask_bits);
> return cpu;
>  }
>
> diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
> index 03ed492..c2eeb36 100644
> --- a/include/linux/netdevice.h
> +++ b/include/linux/netdevice.h
> @@ -730,10 +730,21 @@ struct xps_map {
>   */
>  struct xps_dev_maps {
> struct rcu_head rcu;
> -   struct xps_map __rcu *cpu_map[0];
> +   struct xps_map __rcu *attr_map[0];
>  };
> -#define XPS_DEV_MAPS_SIZE(_tcs) (sizeof(struct xps_dev_maps) + \
> +
> +#define XPS_CPU_DEV_MAPS_SIZE(_tcs) (sizeof(struct xps_dev_maps) + \
> (nr_cpu_ids * (_tcs) * sizeof(struct xps_map *)))
> +
> +#define XPS_RXQ_DEV_MAPS_SIZE(_tcs, _rxqs) (sizeof(struct xps_dev_maps) +\
> +   (_rxqs * (_tcs) * sizeof(struct xps_map *)))
> +
> +enum xps_map_type {
> +   XPS_MAP_RXQS,
> +   XPS_MAP_CPUS,
> +   __XPS_MAP_MAX
> +};
> +
>  #endif /* CONFIG_XPS */
>
>  #define TC_MAX_QUEUE   16
> @@ -1891,7 +1902,7 @@ struct net_device {
> int watchdog_timeo;
>
>  #ifdef CONFIG_XPS
> -   struct xps_dev_maps __rcu *xps_maps;
> +   struct xps_dev_maps __rcu *xps_maps[__XPS_MAP_MAX];
>  #endif
>  #ifdef CONFIG_NET_CLS_ACT
> struct mini_Qdisc __rcu *miniq_egress;
> @@ -3229,6 +3240,61 @@ static inline void netif_wake_subqueue(struct 
> net_device *dev, u16 queue_index)
>  #ifdef CONFIG_XPS
>  int netif_set_xps_queue(struct net_device *dev, const struct cpumask *mask,
> u16 index);
> +int __netif_set_xps_queue(struct net_device *dev, const unsigned long *mask,
> + u16 index, enum xps_map_type type);
> +
> +static inline bool attr_test_mask(unsigned long j, const unsigned long *mask,
> + unsigned int nr_bits)
> +{
> +   cpu_max_bits_warn(j, nr_bits);
> +   return test_bit(j, mask);
> +}
> +
> +static inline bool attr_test_online(unsigned long j,
> +   const unsigned long *online_mask,
> +   unsigned int nr_bits)
> +{
> +   cpu_max_bits_warn(j, nr_bits);
> +
> +   if (online_mask)
> +   return test_bit(j, online_mask);
> +
> +   if (j >= 0 && j < nr_bits)
> +   return true;
> +
> +   return false;
> +}
> +
> +static inline unsigned int attrmask_next(int n, const unsigned long *srcp,
> +unsigned int nr_bits)
> +{
> +   /* -1 is a legal arg here. */
> +   if (n != -1)
> +   cpu_max_bits_warn(n, nr_bits);
> +
> +   if (srcp)
> +   return find_next_bit(srcp, nr_bits, n + 1);
> +
> +   return n + 1;
> +}
> +
> +static inline int attrmask_next_and(int n, const unsigned long *src1p,
> +   const unsigned long *src2p,
> +   unsigned int nr_bits)
> +{
> +   /* -1 is a legal arg here. */
> +   if (n != -1)
> +   cpu_max_bits_warn(n, nr_bits);
> +
> +   if (src1p && src2p)
> +   return find_next_and_bit(src1p, src2p, nr_bits, n + 1);
> +   else if (src1p)
> +   return find_next_bit(src1p, nr_bits, n + 1);
> +   else if (src2p)
> +   return find_next_bit(src2p, nr_bits, n + 1);
> +
> +   return n + 1;
> +}
>  #else
>  static inline int netif_set_xps_queue(struct net_device *dev,
>   const struct cpumask *mask,
> diff --git a/net/core/dev.c b/net/core/dev.c
> index 9f43901..7e5dfdb 100644
> --- a/net/core/dev.c
> +++ b/net/core/dev.c
> @@ -2092,7 +2092,7 @@ static bool remove_xps_queue(struct xps_dev_maps 
> *dev_maps,
>   

Re: [net-next PATCH v2 1/4] net: Refactor XPS for CPUs and Rx queues

2018-05-17 Thread Nambiar, Amritha
On 5/17/2018 11:38 AM, David Miller wrote:
> From: Amritha Nambiar 
> Date: Tue, 15 May 2018 18:26:43 -0700
> 
>> @@ -2125,7 +2125,7 @@ static bool remove_xps_queue_cpu(struct net_device 
>> *dev,
>>  int i, j;
>>  
>>  for (i = count, j = offset; i--; j++) {
>> -if (!remove_xps_queue(dev_maps, cpu, j))
>> +if (!remove_xps_queue(dev_maps, tci, j))
>>  break;
>>  }
>>  
> 
> This looks like a bug fix, completely unrelated to the feature being added
> by this patch set.
> 
> Please submit this targetting the 'net' tree, then when that fix propagates
> into 'net-next' you can rebase this series on top of that.
> 
> Thank you.
> 

Sure, will do that.
Thanks.


Re: [net-next PATCH v2 1/4] net: Refactor XPS for CPUs and Rx queues

2018-05-17 Thread David Miller
From: Amritha Nambiar 
Date: Tue, 15 May 2018 18:26:43 -0700

> @@ -2125,7 +2125,7 @@ static bool remove_xps_queue_cpu(struct net_device *dev,
>   int i, j;
>  
>   for (i = count, j = offset; i--; j++) {
> - if (!remove_xps_queue(dev_maps, cpu, j))
> + if (!remove_xps_queue(dev_maps, tci, j))
>   break;
>   }
>  

This looks like a bug fix, completely unrelated to the feature being added
by this patch set.

Please submit this targetting the 'net' tree, then when that fix propagates
into 'net-next' you can rebase this series on top of that.

Thank you.


[net-next PATCH v2 1/4] net: Refactor XPS for CPUs and Rx queues

2018-05-15 Thread Amritha Nambiar
Refactor XPS code to support Tx queue selection based on
CPU map or Rx queue map.

Signed-off-by: Amritha Nambiar 
---
 include/linux/cpumask.h   |   11 ++
 include/linux/netdevice.h |   72 +++-
 net/core/dev.c|  208 +
 net/core/net-sysfs.c  |4 -
 4 files changed, 215 insertions(+), 80 deletions(-)

diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
index bf53d89..57f20a0 100644
--- a/include/linux/cpumask.h
+++ b/include/linux/cpumask.h
@@ -115,12 +115,17 @@ extern struct cpumask __cpu_active_mask;
 #define cpu_active(cpu)((cpu) == 0)
 #endif
 
-/* verify cpu argument to cpumask_* operators */
-static inline unsigned int cpumask_check(unsigned int cpu)
+static inline void cpu_max_bits_warn(unsigned int cpu, unsigned int bits)
 {
 #ifdef CONFIG_DEBUG_PER_CPU_MAPS
-   WARN_ON_ONCE(cpu >= nr_cpumask_bits);
+   WARN_ON_ONCE(cpu >= bits);
 #endif /* CONFIG_DEBUG_PER_CPU_MAPS */
+}
+
+/* verify cpu argument to cpumask_* operators */
+static inline unsigned int cpumask_check(unsigned int cpu)
+{
+   cpu_max_bits_warn(cpu, nr_cpumask_bits);
return cpu;
 }
 
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 03ed492..c2eeb36 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -730,10 +730,21 @@ struct xps_map {
  */
 struct xps_dev_maps {
struct rcu_head rcu;
-   struct xps_map __rcu *cpu_map[0];
+   struct xps_map __rcu *attr_map[0];
 };
-#define XPS_DEV_MAPS_SIZE(_tcs) (sizeof(struct xps_dev_maps) + \
+
+#define XPS_CPU_DEV_MAPS_SIZE(_tcs) (sizeof(struct xps_dev_maps) + \
(nr_cpu_ids * (_tcs) * sizeof(struct xps_map *)))
+
+#define XPS_RXQ_DEV_MAPS_SIZE(_tcs, _rxqs) (sizeof(struct xps_dev_maps) +\
+   (_rxqs * (_tcs) * sizeof(struct xps_map *)))
+
+enum xps_map_type {
+   XPS_MAP_RXQS,
+   XPS_MAP_CPUS,
+   __XPS_MAP_MAX
+};
+
 #endif /* CONFIG_XPS */
 
 #define TC_MAX_QUEUE   16
@@ -1891,7 +1902,7 @@ struct net_device {
int watchdog_timeo;
 
 #ifdef CONFIG_XPS
-   struct xps_dev_maps __rcu *xps_maps;
+   struct xps_dev_maps __rcu *xps_maps[__XPS_MAP_MAX];
 #endif
 #ifdef CONFIG_NET_CLS_ACT
struct mini_Qdisc __rcu *miniq_egress;
@@ -3229,6 +3240,61 @@ static inline void netif_wake_subqueue(struct net_device 
*dev, u16 queue_index)
 #ifdef CONFIG_XPS
 int netif_set_xps_queue(struct net_device *dev, const struct cpumask *mask,
u16 index);
+int __netif_set_xps_queue(struct net_device *dev, const unsigned long *mask,
+ u16 index, enum xps_map_type type);
+
+static inline bool attr_test_mask(unsigned long j, const unsigned long *mask,
+ unsigned int nr_bits)
+{
+   cpu_max_bits_warn(j, nr_bits);
+   return test_bit(j, mask);
+}
+
+static inline bool attr_test_online(unsigned long j,
+   const unsigned long *online_mask,
+   unsigned int nr_bits)
+{
+   cpu_max_bits_warn(j, nr_bits);
+
+   if (online_mask)
+   return test_bit(j, online_mask);
+
+   if (j >= 0 && j < nr_bits)
+   return true;
+
+   return false;
+}
+
+static inline unsigned int attrmask_next(int n, const unsigned long *srcp,
+unsigned int nr_bits)
+{
+   /* -1 is a legal arg here. */
+   if (n != -1)
+   cpu_max_bits_warn(n, nr_bits);
+
+   if (srcp)
+   return find_next_bit(srcp, nr_bits, n + 1);
+
+   return n + 1;
+}
+
+static inline int attrmask_next_and(int n, const unsigned long *src1p,
+   const unsigned long *src2p,
+   unsigned int nr_bits)
+{
+   /* -1 is a legal arg here. */
+   if (n != -1)
+   cpu_max_bits_warn(n, nr_bits);
+
+   if (src1p && src2p)
+   return find_next_and_bit(src1p, src2p, nr_bits, n + 1);
+   else if (src1p)
+   return find_next_bit(src1p, nr_bits, n + 1);
+   else if (src2p)
+   return find_next_bit(src2p, nr_bits, n + 1);
+
+   return n + 1;
+}
 #else
 static inline int netif_set_xps_queue(struct net_device *dev,
  const struct cpumask *mask,
diff --git a/net/core/dev.c b/net/core/dev.c
index 9f43901..7e5dfdb 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -2092,7 +2092,7 @@ static bool remove_xps_queue(struct xps_dev_maps 
*dev_maps,
int pos;
 
if (dev_maps)
-   map = xmap_dereference(dev_maps->cpu_map[tci]);
+   map = xmap_dereference(dev_maps->attr_map[tci]);
if (!map)
return false;
 
@@ -2105,7 +2105,7 @@ static bool remove_xps_queue(struct xps_dev_maps 
*dev_maps,
break;
}
 
-