core: Factor out flow calculation from get_rps_cpu
Subsystems (2)
PATCH v2 1/2 core: Factor out flow calculation from get_rps_cpu
From: Krishna Kumar <[email protected]>
Factor out flow calculation code from get_rps_cpu, since macvtap driver can use the same code.
--- net/core/dev.c | 94 +++++++++++++++++++++++++++++------------------ 1 file changed, 58 insertions(+), 36 deletions(-)
net/core/dev.c +58 -36
@@ -2263,51 +2263,24 @@ static inline void ____napi_schedule(str__raise_softirq_irqoff (NET_RX_SOFTIRQ ); } -#ifdef CONFIG_RPS - -/* One global table that all flow-based protocols share. */ -struct rps_sock_flow_table *rps_sock_flow_table__read_mostly ; -EXPORT_SYMBOL (rps_sock_flow_table); -/* -* get_rps_cpu is called from netif_receive_skb and returns the target -* CPU from the RPS map of the receiving queue for a given skb. -* rcu_read_lock must be held on entry. +* skb_calculate_flow: calculate a flow hash based on src/dst addresses +* and src/dst port numbers. On success, returns a hash number (> 0), +* otherwise -1. */ -static int get_rps_cpu (struct net_device *dev,struct sk_buff *skb, -struct rps_dev_flow **rflowp) +int skb_calculate_flow (struct net_device *dev,struct sk_buff *skb) { +int hash = skb->rxhash;struct ipv6hdr *ip6;struct iphdr *ip; -struct netdev_rx_queue *rxqueue; -struct rps_map *map; -struct rps_dev_flow_table *flow_table; -struct rps_sock_flow_table *sock_flow_table; -int cpu =-1 ;u8 ip_proto; -u16 tcpu;u32 addr1, addr2, ihl;union {u32 v32;u16 v16[2 ]; } ports; -if (skb_rx_queue_recorded (skb)) { -u16 index =skb_get_rx_queue (skb); -if (unlikely (index >= dev->num_rx_queues)) { -WARN_ONCE (dev->num_rx_queues >1 ,"%s received packet " -"on queue %u, but number of RX queues is %u\n" , - dev->name, index, dev->num_rx_queues); - goto done; - } - rxqueue = dev->_rx + index; - }else - rxqueue = dev->_rx; - -if (!rxqueue->rps_map && !rxqueue->rps_flow_table) - goto done; - -if (skb->rxhash) +if (hash) goto got_hash;/* Skip hash computation on packet header */ switch (skb->protocol) {
@@ -2334,6 +2307,7 @@ static int get_rps_cpu(struct net_devicedefault : goto done; } +switch (ip_proto) {case IPPROTO_TCP :case IPPROTO_UDP :
@@ -2356,11 +2330,59 @@ static int get_rps_cpu(struct net_device/* get a consistent hash (same value on both flow directions) */ if (addr2 < addr1)swap (addr1, addr2); - skb->rxhash =jhash_3words (addr1, addr2, ports.v32, hashrnd); -if (!skb->rxhash) - skb->rxhash =1 ; + + hash =jhash_3words (addr1, addr2, ports.v32, hashrnd); +if (!hash) + hash =1 ; got_hash: +return hash; + +done: +return -1 ; +} +EXPORT_SYMBOL (skb_calculate_flow); + +#ifdef CONFIG_RPS + +/* One global table that all flow-based protocols share. */ +struct rps_sock_flow_table *rps_sock_flow_table__read_mostly ; +EXPORT_SYMBOL (rps_sock_flow_table); + +/* +* get_rps_cpu is called from netif_receive_skb and returns the target +* CPU from the RPS map of the receiving queue for a given skb. +* rcu_read_lock must be held on entry. +*/ +static int get_rps_cpu (struct net_device *dev,struct sk_buff *skb, +struct rps_dev_flow **rflowp) +{ +struct netdev_rx_queue *rxqueue; +struct rps_map *map; +struct rps_dev_flow_table *flow_table; +struct rps_sock_flow_table *sock_flow_table; +int cpu =-1 ; +u16 tcpu; + +if (skb_rx_queue_recorded (skb)) { +u16 index =skb_get_rx_queue (skb); +if (unlikely (index >= dev->num_rx_queues)) { +WARN_ONCE (dev->num_rx_queues >1 ,"%s received packet " +"on queue %u, but number of RX queues is %u\n" , + dev->name, index, dev->num_rx_queues); + goto done; + } + rxqueue = dev->_rx + index; + }else + rxqueue = dev->_rx; + +if (!rxqueue->rps_map && !rxqueue->rps_flow_table) + goto done; + + skb->rxhash =skb_calculate_flow (dev, skb); +if (skb->rxhash <0 ) + goto done; + flow_table =rcu_dereference (rxqueue->rps_flow_table); sock_flow_table =rcu_dereference (rps_sock_flow_table);if (flow_table && sock_flow_table) {
PATCH v2 2/2 macvtap: Implement multiqueue macvtap driver
From: Krishna Kumar <[email protected]>
Implement multiqueue facility for macvtap driver. The idea is that a macvtap device can be opened multiple times and the fd's can be used to register eg, as backend for vhost.
Please review.
--- drivers/net/macvtap.c | 89 ++++++++++++++++++++++++++++------- include/linux/if_macvlan.h | 11 +++- include/linux/netdevice.h | 1 3 files changed, 83 insertions(+), 18 deletions(-)
include/linux/netdevice.h +1 -0
@@ -2253,6 +2253,7 @@ static inline const char *netdev_name(coreturn dev->name; } +extern int skb_calculate_flow (struct net_device *dev,struct sk_buff *skb);extern int netdev_printk (const char *level,const struct net_device *dev,const char *format, ...) __attribute__ ((format (printf,3 ,4 )));
include/linux/if_macvlan.h +10 -1
@@ -40,6 +40,14 @@ struct macvlan_rx_stats {unsigned long rx_errors; }; +#define MIN (x, y) (((x) < (y)) ? (x) : (y)) + +/* +* Maximum times a macvtap device can be opened. This can be used to +* configure the number of receive queue, e.g. for multiqueue virtio. +*/ +#define MAX_MACVTAP_QUEUES MIN(16, NR_CPUS) +struct macvlan_dev {struct net_device *dev;struct list_head list;
@@ -50,7 +58,8 @@ struct macvlan_dev {enum macvlan_mode mode;int (*receive)(struct sk_buff *skb);int (*forward)(struct net_device *dev,struct sk_buff *skb); -struct macvtap_queue *tap; +struct macvtap_queue *taps[MAX_MACVTAP_QUEUES ]; +int numvtaps; }; static inline void macvlan_count_rx(const struct macvlan_dev *vlan,
drivers/net/macvtap.c +72 -17
146 lines not on this page · raw message
Re: [PATCH v2 2/2] macvtap: Implement multiqueue macvtap driver
Quoted 5 lines · Krishna Kumar
Implement multiqueue facility for macvtap driver. The idea is that a macvtap device can be opened multiple times and the fd's can be used to register eg, as backend for vhost.
Please review.
Only two very minor points from my side:
include/linux/netdevice.h static inline const char *netdev_name(co · line 2259
Quoted 11 lines
diff -ruNp
org/include/linux/netdevice.hnew/include/linux/netdevice.hinclude/linux/netdevice.h +1
-0@@ -2253,6 +2253,7 @@ static inline const char *netdev_name(coreturn dev->name; } +extern int skb_calculate_flow (struct net_device *dev,struct sk_buff *skb);extern int netdev_printk (const char *level,const struct net_device *dev,const char *format, ...) __attribute__ ((format (printf,3 ,4 )));
This logically belongs into the first patch.
Quoted 5 lines
diff -ruNp
org/include/linux/if_macvlan.hnew/include/linux/if_macvlan.hinclude/linux/if_macvlan.h +0
-0@@ -40,6 +40,14 @@ struct macvlan_rx_stats {unsigned long rx_errors;
include/linux/if_macvlan.h struct macvlan_rx_stats { · line 50
Quoted 10 lines
include/linux/if_macvlan.h +8
-0}; +#define MIN (x, y) (((x) < (y)) ? (x) : (y)) + +/* +* Maximum times a macvtap device can be opened. This can be used to +* configure the number of receive queue, e.g. for multiqueue virtio. +*/ +#define MAX_MACVTAP_QUEUES MIN(16, NR_CPUS) +
Please use the existing min() or min_t() macro instead of providing your own.
Arnd
Re: [PATCH v2 2/2] macvtap: Implement multiqueue macvtap driver
Hi Arnd,
Thanks for your comments. The declaration was in the 2nd patch since the function was not used outside net/core/dev.c after the 1st patch is applied, but now I think you are right.
Regarding min/min_t, I had tried both and got this error:
"include/linux/if_macvlan.h:57: error: braced-group within expression
allowed only inside a function"
Please let me know if there is any alternative (curly braces cannot be used outside of functions). Otherwise one change required is to add:
#ifndef MIN
#endif
I will wait for a few hours and resubmit the patches.
thanks,
- KK
Arnd Bergmann <[email protected]> wrote on 08/02/2010 09:22:28 PM:
Quoted 25 lines
Arnd Bergmann <[email protected]>
08/02/2010 09:22 PMTo
Krishna Kumar2/India/IBM@IBMIN
cc
[email protected], [email protected], [email protected], [email protected], [email protected]
Subject
Re: [PATCH v2 2/2] macvtap: Implement multiqueue macvtap driver
Quoted 5 lines · Krishna Kumar
Implement multiqueue facility for macvtap driver. The idea is that a macvtap device can be opened multiple times and the fd's can be used to register eg, as backend for vhost.
Please review.
Only two very minor points from my side:
Quoted 8 lines
include/linux/netdevice.h 2010-08-02 16:05:57.000000000 +0530 static inline const char *netdev_name(co · line 2256
Quoted 8 lines
diff -ruNp
org/include/linux/netdevice.hnew/include/linux/netdevice.hinclude/linux/netdevice.h 2010-08-02 16:05:57.000000000 +0530 renamed from include/linux/netdevice.h 2010-07-25 16:57:07.000000000 +0530 +1
-0@@ -2253,6 +2253,7 @@ static inline const char *netdev_name(co return dev->name; } +extern int skb_calculate_flow(struct net_device *dev, struct sk_buff
*skb);
Quoted 1 line
include/linux/netdevice.h 2010-08-02 16:05:57.000000000 +0530 static inline const char *netdev_name(co · line 2257
Quoted 1 line
include/linux/netdevice.h 2010-08-02 16:05:57.000000000 +0530 renamed from include/linux/netdevice.h 2010-07-25 16:57:07.000000000 +0530 +0
-0extern int netdev_printk(const char *level, const struct net_device
*dev,
Quoted 6 lines
include/linux/netdevice.h 2010-08-02 16:05:57.000000000 +0530 static inline const char *netdev_name(co · line 2259
Quoted 2 lines
include/linux/netdevice.h 2010-08-02 16:05:57.000000000 +0530 renamed from include/linux/netdevice.h 2010-07-25 16:57:07.000000000 +0530 +0
-0const char *format, ...) __attribute__ ((format (printf, 3, 4)));This logically belongs into the first patch.
Quoted 1 line
diff -ruNp
org/include/linux/if_macvlan.h
new/include/linux/if_macvlan.h
Quoted 1 line
Quoted 1 line
---
org/include/linux/if_macvlan.h2010-08-02 15:32:33.000000000
+0530
Quoted 1 line
Quoted 1 line
+++
new/include/linux/if_macvlan.h2010-08-02 15:32:33.000000000
+0530
Quoted 4 lines
Quoted 4 lines
include/linux/netdevice.h 2010-08-02 16:05:57.000000000 +0530 renamed from include/linux/netdevice.h 2010-07-25 16:57:07.000000000 +0530 +0
-0@@ -40,6 +40,14 @@ struct macvlan_rx_stats { unsigned long rx_errors; };
Quoted 10 lines
include/linux/netdevice.h 2010-08-02 16:05:57.000000000 +0530 struct macvlan_rx_stats { · line 50
Quoted 8 lines
include/linux/netdevice.h 2010-08-02 16:05:57.000000000 +0530 renamed from include/linux/netdevice.h 2010-07-25 16:57:07.000000000 +0530 +8
-0+#define MIN(x, y) (((x) < (y)) ? (x) : (y)) + +/* + * Maximum times a macvtap device can be opened. This can be used to + * configure the number of receive queue, e.g. for multiqueue virtio. + */ +#define MAX_MACVTAP_QUEUES MIN(16, NR_CPUS) +Please use the existing
min()ormin_t()macro instead of providing your
own.
Quoted 2 lines
Arnd
Re: [PATCH v2 2/2] macvtap: Implement multiqueue macvtap driver
Quoted 9 lines · On Monday 02 August 2010, Krishna Kumar2 wrote:
"
include/linux/if_macvlan.h:57: error: braced-group within expression
allowed only inside a function"
Please let me know if there is any alternative (curly braces cannot be used outside of functions). Otherwise one change required is to add:#ifndef MIN
#endifI will wait for a few hours and resubmit the patches.
Maybe just open-code the minimum computation:
#define MAX_MACVTAP_QUEUES (NR_CPUS < 16 ? NR_CPUS : 16)
ARnd