New Xen netback implementation
Subsystems (3)
RFC PATCH v2 1/1 New Xen netback implementation
A new netback implementation which includes three major features:
- Global page pool support
- NAPI + kthread 1:1 model
- Netback internal name changes
Changes in V2:
- Fix minor bugs in V1
- Embed pending_tx_info into page pool
- Per-cpu scratch space
- Notification code path clean up
This patch series is the foundation of furture work. So it is better to get it right first. Patch 1 and 3 have the real meat.
The first benifit of 1:1 model will be scheduling fairness.
The rational behind a global page pool is that we need to limit overall memory consumed by all vifs.
Utilization of NAPI enables the possibility to mitigate interrupts/events, the code path is cleaned up in a separated patch.
Netback internal changes cleans up the code structure after switching to 1:1 model. It also prepares netback for further code layout changes.
--- drivers/net/xen-netback/Makefile | 2 +- drivers/net/xen-netback/common.h | 78 ++-- drivers/net/xen-netback/interface.c | 117 ++++-- drivers/net/xen-netback/netback.c | 836 ++++++++++++++--------------------- drivers/net/xen-netback/page_pool.c | 185 ++++++++ drivers/net/xen-netback/page_pool.h | 66 +++ drivers/net/xen-netback/xenbus.c | 6 +- 7 files changed, 704 insertions(+), 586 deletions(-)
RFC PATCH v2 1/8 netback: page pool version 1
A global page pool. Since we are moving to 1:1 model netback, it is better to limit total RAM consumed by all the vifs.
With this patch, each vif gets page from the pool and puts the page back when it is finished with the page.
This pool is only meant to access via exported interfaces. Internals are subject to change when we discover new requirements for the pool.
Current exported interfaces include:
page_pool_init: pool initpage_pool_destroy: pool destructionpage_pool_get: get a page from poolpage_pool_put: put page back to poolis_in_pool: tell whether a page belongs to the pool
Current implementation has following defects:
- Global locking
- No starve prevention mechanism / reservation logic
Global locking tends to cause contention on the pool. No reservation logic may cause vif to starve. A possible solution to these two problems will be each vif maintains its local cache and claims a portion of the pool. However the implementation will be tricky when coming to pool management, so let's worry about that later.
--- drivers/net/xen-netback/Makefile | 2 +- drivers/net/xen-netback/common.h | 6 + drivers/net/xen-netback/netback.c | 158 ++++++++++++------------------ drivers/net/xen-netback/page_pool.c | 185 +++++++++++++++++++++++++++++++++++ drivers/net/xen-netback/page_pool.h | 63 ++++++++++++ 5 files changed, 317 insertions(+), 97 deletions(-) create mode 100644 drivers/net/xen-netback/page_pool.c create mode 100644 drivers/net/xen-netback/page_pool.h
drivers/net/xen-netback/Makefile +1 -1
@@ -1,3 +1,3 @@ obj-$(CONFIG_XEN_NETDEV_BACKEND) := xen-netback.o -xen-netback-y := netback.o xenbus.o interface.o +xen-netback-y := netback.o xenbus.o interface.o page_pool.o
drivers/net/xen-netback/common.h +6 -0
@@ -45,6 +45,12 @@#include <xen/grant_table.h> #include <xen/xenbus.h> +struct pending_tx_info { +struct xen_netif_tx_request req; +struct xenvif *vif; +}; +typedef unsigned int pending_ring_idx_t ; +struct xen_netbk ;struct xenvif {
drivers/net/xen-netback/netback.c +62 -96
323 lines not on this page · raw message
drivers/net/xen-netback/page_pool.c new file +185 -0
185 lines not on this page · raw message
drivers/net/xen-netback/page_pool.h new file +63 -0
63 lines not on this page · raw message
Signature · 1 line
1.7.2.5
RFC PATCH v2 2/8 netback: add module unload function.
In reply to Wei LiuEnables users to unload netback module.
--- drivers/net/xen-netback/common.h | 1 + drivers/net/xen-netback/netback.c | 14 ++++++++++++++ drivers/net/xen-netback/xenbus.c | 5 +++++ 3 files changed, 20 insertions(+), 0 deletions(-)
drivers/net/xen-netback/common.h +1 -0
@@ -126,6 +126,7 @@ void xenvif_get(struct xenvif *vif);void xenvif_put (struct xenvif *vif);int xenvif_xenbus_init (void ); +void xenvif_xenbus_exit (void );int xenvif_schedulable (struct xenvif *vif);
drivers/net/xen-netback/netback.c +14 -0
@@ -1670,5 +1670,19 @@ failed_init:module_init (netback_init); +static void __exit netback_exit(void) +{ +int i; +xenvif_xenbus_exit (); +for (i =0 ; i < xen_netbk_group_nr; i++) { +struct xen_netbk *netbk = &xen_netbk[i]; +del_timer_sync (&netbk->net_timer); +kthread_stop (netbk->task); + } +vfree (xen_netbk); +page_pool_destroy (); +} +module_exit (netback_exit); +MODULE_LICENSE ("Dual BSD/GPL" );MODULE_ALIAS ("xen-backend:vif" );
drivers/net/xen-netback/xenbus.c +5 -0
@@ -485,3 +485,8 @@ int xenvif_xenbus_init(void) {return xenbus_register_backend (&netback_driver); } + +void xenvif_xenbus_exit (void ) +{ +return xenbus_unregister_driver (&netback_driver); +}
Signature · 1 line
1.7.2.5
RFC PATCH v2 3/8 netback: switch to NAPI + kthread model
In reply to Wei LiuThis patch implements 1:1 model netback. We utilizes NAPI and kthread to do the weight-lifting job:
- NAPI is used for guest side TX (host side RX)
- kthread is used for guest side RX (host side TX)
This model provides better scheduling fairness among vifs. It also lays the foundation for future work.
The major defect for the current implementation is that in the NAPI poll handler we don't actually disable interrupt. Xen stuff is different from real hardware, it requires some other tuning of ring macros.
--- drivers/net/xen-netback/common.h | 34 ++-- drivers/net/xen-netback/interface.c | 92 ++++++--- drivers/net/xen-netback/netback.c | 366 ++++++++++------------------------- drivers/net/xen-netback/xenbus.c | 1 - 4 files changed, 185 insertions(+), 308 deletions(-)
drivers/net/xen-netback/common.h +15 -19
@@ -47,7 +47,6 @@struct pending_tx_info {struct xen_netif_tx_request req; -struct xenvif *vif; };typedef unsigned int pending_ring_idx_t ;
@@ -61,14 +60,17 @@ struct xenvif {/* Reference to netback processing backend. */ struct xen_netbk *netbk; +/* Use NAPI for guest TX */ +struct napi_struct napi; +/* Use kthread for guest RX */ +struct task_struct *task; +wait_queue_head_t wq; +u8 fe_dev_addr[6 ];/* Physical parameters of the comms window. */ unsigned int irq; -/* List of frontends to notify after a batch of frames sent. */ -struct list_head notify_list; -/* The shared rings and indexes. */ struct xen_netif_tx_back_ring tx;struct xen_netif_rx_back_ring rx;
@@ -99,11 +101,7 @@ struct xenvif {unsigned long rx_gso_checksum_fixup;/* Miscellaneous private stuff. */ -struct list_head schedule_list; -atomic_t refcnt;struct net_device *dev; - -wait_queue_head_t waiting_to_free; };static inline struct xenbus_device *xenvif_to_xenbus_device (struct xenvif *vif)
@@ -122,9 +120,6 @@ int xenvif_connect(struct xenvif *vif, unsigned long tx_ring_ref, unsigned long rx_ring_ref, unsigned int evtchn);void xenvif_disconnect (struct xenvif *vif); -void xenvif_get (struct xenvif *vif); -void xenvif_put (struct xenvif *vif); -int xenvif_xenbus_init (void );void xenvif_xenbus_exit (void );
@@ -140,14 +135,6 @@ int xen_netbk_map_frontend_rings(struct xenvif *vif,grant_ref_t tx_ring_ref, grant_ref_t rx_ring_ref); -/* (De)Register a xenvif with the netback backend. */ -void xen_netbk_add_xenvif (struct xenvif *vif); -void xen_netbk_remove_xenvif (struct xenvif *vif); - -/* (De)Schedule backend processing for a xenvif */ -void xen_netbk_schedule_xenvif (struct xenvif *vif); -void xen_netbk_deschedule_xenvif (struct xenvif *vif); -/* Check for SKBs from frontend and schedule backend processing */ void xen_netbk_check_rx_xenvif (struct xenvif *vif);/* Receive an SKB from the frontend */
@@ -161,4 +148,13 @@ void xenvif_notify_tx_completion(struct xenvif *vif);/* Returns number of ring slots required to send an skb to the frontend */ unsigned int xen_netbk_count_skb_slots (struct xenvif *vif,struct sk_buff *skb); +/* Allocate and free xen_netbk structure */ +struct xen_netbk *xen_netbk_alloc_netbk (struct xenvif *vif); +void xen_netbk_free_netbk (struct xen_netbk *netbk); + +void xen_netbk_tx_action (struct xen_netbk *netbk,int *work_done,int budget); +void xen_netbk_rx_action (struct xen_netbk *netbk); + +int xen_netbk_kthread (void *data); +#endif /* __XEN_NETBACK__COMMON_H__ */
drivers/net/xen-netback/interface.c +65 -27
183 lines not on this page · raw message
drivers/net/xen-netback/netback.c +105 -261
646 lines not on this page · raw message
drivers/net/xen-netback/xenbus.c +0 -1
@@ -387,7 +387,6 @@ static void connect(struct backend_info *be)netif_wake_queue (be->vif->dev); } -static int connect_rings (struct backend_info *be) {struct xenvif *vif = be->vif;
Signature · 1 line
1.7.2.5
RFC PATCH v2 4/8 netback: switch to per-cpu scratch space.
In reply to Wei LiuIn the 1:1 model, given that there are maximum nr_online_cpus netbacks running, we can use per-cpu scratch space, thus shrinking size of struct xen_netbk.
--- drivers/net/xen-netback/common.h | 13 ++++ drivers/net/xen-netback/netback.c | 134 ++++++++++++++++++++++++------------- 2 files changed, 100 insertions(+), 47 deletions(-)
drivers/net/xen-netback/common.h +13 -0
@@ -45,6 +45,19 @@#include <xen/grant_table.h> #include <xen/xenbus.h> +struct netbk_rx_meta { +int id; +int size; +int gso_size; +}; + +#define MAX_PENDING_REQS 256 + +/* Discriminate from any valid pending_idx value. */ +#define INVALID_PENDING_IDX 0xFFFF + +#define MAX_BUFFER_OFFSET PAGE_SIZE +struct pending_tx_info {struct xen_netif_tx_request req; };
drivers/net/xen-netback/netback.c +87 -47
261 lines not on this page · raw message
Signature · 1 line
1.7.2.5
RFC PATCH v2 5/8 netback: add module get/put operations along with vif connect/disconnect.
In reply to Wei LiuIf there is vif running and user unloads netback, it will certainly cause problems -- guest's network interface just mysteriously stops working.
--- drivers/net/xen-netback/interface.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
drivers/net/xen-netback/interface.c +4 -0
@@ -323,6 +323,8 @@ int xenvif_connect(struct xenvif *vif, unsigned long tx_ring_ref,if (vif->irq)return 0 ; +__module_get (THIS_MODULE ); + err =xen_netbk_map_frontend_rings (vif, tx_ring_ref, rx_ring_ref);if (err <0 ) goto err;
@@ -405,4 +407,6 @@ void xenvif_disconnect(struct xenvif *vif)xen_netbk_unmap_frontend_rings (vif);free_netdev (vif->dev); + +module_put (THIS_MODULE ); }
Signature · 1 line
1.7.2.5
RFC PATCH v2 6/8 netback: melt xen_netbk into xenvif
In reply to Wei LiuIn the 1:1 model, there is no need to keep xen_netbk and xenvif separated.
--- drivers/net/xen-netback/common.h | 36 +++--- drivers/net/xen-netback/interface.c | 36 +++---- drivers/net/xen-netback/netback.c | 207 +++++++++++++---------------------- drivers/net/xen-netback/page_pool.c | 10 +- drivers/net/xen-netback/page_pool.h | 13 ++- 5 files changed, 120 insertions(+), 182 deletions(-)
drivers/net/xen-netback/common.h +17 -19
@@ -45,34 +45,29 @@#include <xen/grant_table.h> #include <xen/xenbus.h> +#include "page_pool.h" +struct netbk_rx_meta {int id;int size;int gso_size; }; -#define MAX_PENDING_REQS 256 -/* Discriminate from any valid pending_idx value. */ #define INVALID_PENDING_IDX 0xFFFF#define MAX_BUFFER_OFFSET PAGE_SIZE -struct pending_tx_info { -struct xen_netif_tx_request req; -}; -typedef unsigned int pending_ring_idx_t ; +#define XEN_NETIF_TX_RING_SIZE __CONST_RING_SIZE(xen_netif_tx, PAGE_SIZE) +#define XEN_NETIF_RX_RING_SIZE __CONST_RING_SIZE(xen_netif_rx, PAGE_SIZE) -struct xen_netbk ; +#define MAX_PENDING_REQS 256struct xenvif {/* Unique identifier for this interface. */ domid_t domid;unsigned int handle; -/* Reference to netback processing backend. */ -struct xen_netbk *netbk; -/* Use NAPI for guest TX */ struct napi_struct napi;/* Use kthread for guest RX */
@@ -115,6 +110,16 @@ struct xenvif {/* Miscellaneous private stuff. */ struct net_device *dev; + +struct sk_buff_head rx_queue; +struct sk_buff_head tx_queue; + +idx_t mmap_pages[MAX_PENDING_REQS ]; + +pending_ring_idx_t pending_prod; +pending_ring_idx_t pending_cons; + +u16 pending_ring[MAX_PENDING_REQS ]; };static inline struct xenbus_device *xenvif_to_xenbus_device (struct xenvif *vif)
@@ -122,9 +127,6 @@ static inline struct xenbus_device *xenvif_to_xenbus_device(struct xenvif *vif)return to_xenbus_device (vif->dev->dev.parent); } -#define XEN_NETIF_TX_RING_SIZE __CONST_RING_SIZE(xen_netif_tx, PAGE_SIZE) -#define XEN_NETIF_RX_RING_SIZE __CONST_RING_SIZE(xen_netif_rx, PAGE_SIZE) -struct xenvif *xenvif_alloc (struct device *parent,domid_t domid,unsigned int handle);
@@ -161,12 +163,8 @@ void xenvif_notify_tx_completion(struct xenvif *vif);/* Returns number of ring slots required to send an skb to the frontend */ unsigned int xen_netbk_count_skb_slots (struct xenvif *vif,struct sk_buff *skb); -/* Allocate and free xen_netbk structure */ -struct xen_netbk *xen_netbk_alloc_netbk (struct xenvif *vif); -void xen_netbk_free_netbk (struct xen_netbk *netbk); - -void xen_netbk_tx_action (struct xen_netbk *netbk,int *work_done,int budget); -void xen_netbk_rx_action (struct xen_netbk *netbk); +void xen_netbk_tx_action (struct xenvif *vif,int *work_done,int budget); +void xen_netbk_rx_action (struct xenvif *vif);int xen_netbk_kthread (void *data);
drivers/net/xen-netback/interface.c +16 -20
@@ -55,9 +55,6 @@ static irqreturn_t xenvif_interrupt(int irq, void *dev_id) {struct xenvif *vif = dev_id; -if (vif->netbk ==NULL ) -return IRQ_NONE ; -if (xenvif_rx_schedulable (vif))netif_wake_queue (vif->dev);
@@ -72,7 +69,7 @@ static int xenvif_poll(struct napi_struct *napi, int budget) struct xenvif *vif = container_of(napi, struct xenvif, napi);int work_done =0 ; -xen_netbk_tx_action (vif->netbk, &work_done, budget); +xen_netbk_tx_action (vif, &work_done, budget);if (work_done < budget) {int more_to_do =0 ;
@@ -95,7 +92,8 @@ static int xenvif_start_xmit(struct sk_buff *skb, struct net_device *dev)BUG_ON (skb->dev != dev); -if (vif->netbk ==NULL ) +/* Drop the packet if vif is not ready */ +if (vif->task ==NULL ) goto drop;/* Drop the packet if the target domain has no receive buffers. */
@@ -257,6 +255,7 @@ struct xenvif *xenvif_alloc(struct device *parent, domid_t domid,int err;struct net_device *dev;struct xenvif *vif; +int i;char name[IFNAMSIZ ] = {};snprintf (name,IFNAMSIZ -1 ,"vif%u.%u" , domid, handle);
@@ -271,7 +270,6 @@ struct xenvif *xenvif_alloc(struct device *parent, domid_t domid, vif =netdev_priv (dev); vif->domid = domid; vif->handle = handle; - vif->netbk =NULL ; vif->can_sg =1 ; vif->csum =1 ;
@@ -290,6 +288,17 @@ struct xenvif *xenvif_alloc(struct device *parent, domid_t domid, dev->tx_queue_len =XENVIF_QUEUE_LENGTH ; +skb_queue_head_init (&vif->rx_queue); +skb_queue_head_init (&vif->tx_queue); + + vif->pending_cons =0 ; + vif->pending_prod =MAX_PENDING_REQS ; +for (i =0 ; i <MAX_PENDING_REQS ; i++) + vif->pending_ring[i] = i; + +for (i =0 ; i <MAX_PENDING_REQS ; i++) + vif->mmap_pages[i] =INVALID_ENTRY ; +/* * Initialise a dummy MAC address. We choose the numerically * largest non-broadcast address to prevent the address getting
@@ -337,14 +346,6 @@ int xenvif_connect(struct xenvif *vif, unsigned long tx_ring_ref, vif->irq = err;disable_irq (vif->irq); - vif->netbk =xen_netbk_alloc_netbk (vif); -if (!vif->netbk) { -pr_warn ("Could not allocate xen_netbk\n" ); - err = -ENOMEM ; - goto err_unbind; - } - -init_waitqueue_head (&vif->wq); vif->task = kthread_create(xen_netbk_kthread, (void *)vif,
@@ -352,7 +353,7 @@ int xenvif_connect(struct xenvif *vif, unsigned long tx_ring_ref,if (IS_ERR (vif->task)) {pr_warn ("Could not create kthread\n" ); err =PTR_ERR (vif->task); - goto err_free_netbk; + goto err_unbind; }rtnl_lock ();
@@ -367,8 +368,6 @@ int xenvif_connect(struct xenvif *vif, unsigned long tx_ring_ref,wake_up_process (vif->task);return 0 ; -err_free_netbk: -xen_netbk_free_netbk (vif->netbk); err_unbind:unbind_from_irqhandler (vif->irq, vif); err_unmap:
@@ -392,9 +391,6 @@ void xenvif_disconnect(struct xenvif *vif)if (vif->task)kthread_stop (vif->task); -if (vif->netbk) -xen_netbk_free_netbk (vif->netbk); -netif_napi_del (&vif->napi);del_timer_sync (&vif->credit_timeout);
drivers/net/xen-netback/netback.c +74 -133
506 lines not on this page · raw message
drivers/net/xen-netback/page_pool.c +5 -5
@@ -102,7 +102,7 @@ int is_in_pool(struct page *page, int *pidx)return get_page_ext (page, pidx); } -struct page *page_pool_get (struct xen_netbk *netbk,int *pidx) +struct page *page_pool_get (struct xenvif *vif,int *pidx) {int idx;struct page *page;
@@ -118,7 +118,7 @@ struct page *page_pool_get(struct xen_netbk *netbk, int *pidx) }set_page_ext (page, idx); - pool[idx].u.netbk = netbk; + pool[idx].u.vif = vif; pool[idx].page = page; *pidx = idx;
@@ -131,7 +131,7 @@ void page_pool_put(int idx)struct page *page = pool[idx].page; pool[idx].page =NULL ; - pool[idx].u.netbk =NULL ; + pool[idx].u.vif =NULL ; page->mapping =0 ;put_page (page);put_free_entry (idx);
@@ -174,9 +174,9 @@ struct page *to_page(int idx)return pool[idx].page; } -struct xen_netbk *to_netbk (int idx) +struct xenvif *to_vif (int idx) { -return pool[idx].u.netbk; +return pool[idx].u.vif; }struct pending_tx_info *to_txinfo (int idx)
drivers/net/xen-netback/page_pool.h +8 -5
@@ -27,7 +27,10 @@#ifndef __PAGE_POOL_H__#define __PAGE_POOL_H__ -#include "common.h" +struct pending_tx_info { +struct xen_netif_tx_request req; +}; +typedef unsigned int pending_ring_idx_t ;typedef uint32_t idx_t ;
@@ -38,8 +41,8 @@ struct page_pool_entry {struct page *page;struct pending_tx_info tx_info;union { -struct xen_netbk *netbk; -idx_t fl; +struct xenvif *vif; +idx_t fl; } u; };
@@ -52,12 +55,12 @@ int page_pool_init(void);void page_pool_destroy (void ); -struct page *page_pool_get (struct xen_netbk *netbk,int *pidx); +struct page *page_pool_get (struct xenvif *vif,int *pidx);void page_pool_put (int idx);int is_in_pool (struct page *page,int *pidx);struct page *to_page (int idx); -struct xen_netbk *to_netbk (int idx); +struct xenvif *to_vif (int idx);struct pending_tx_info *to_txinfo (int idx);#endif /* __PAGE_POOL_H__ */
Signature · 1 line
1.7.2.5
RFC PATCH v2 7/8 netback: alter internal function/structure names.
In reply to Wei LiuSince we've melted xen_netbk into xenvif, so it is better to give functions clearer names.
Also alter napi poll handler function prototypes a bit.
--- drivers/net/xen-netback/common.h | 26 ++-- drivers/net/xen-netback/interface.c | 20 ++-- drivers/net/xen-netback/netback.c | 229 ++++++++++++++++++----------------- 3 files changed, 141 insertions(+), 134 deletions(-)
drivers/net/xen-netback/common.h +13 -13
@@ -47,7 +47,7 @@#include "page_pool.h" -struct netbk_rx_meta { +struct xenvif_rx_meta {int id;int size;int gso_size;
@@ -140,32 +140,32 @@ void xenvif_xenbus_exit(void);int xenvif_schedulable (struct xenvif *vif); -int xen_netbk_rx_ring_full (struct xenvif *vif); +int xenvif_rx_ring_full (struct xenvif *vif); -int xen_netbk_must_stop_queue (struct xenvif *vif); +int xenvif_must_stop_queue (struct xenvif *vif);/* (Un)Map communication rings. */ -void xen_netbk_unmap_frontend_rings (struct xenvif *vif); -int xen_netbk_map_frontend_rings (struct xenvif *vif, -grant_ref_t tx_ring_ref, -grant_ref_t rx_ring_ref); +void xenvif_unmap_frontend_rings (struct xenvif *vif); +int xenvif_map_frontend_rings (struct xenvif *vif, +grant_ref_t tx_ring_ref, +grant_ref_t rx_ring_ref);/* Check for SKBs from frontend and schedule backend processing */ -void xen_netbk_check_rx_xenvif (struct xenvif *vif); +void xenvif_check_rx_xenvif (struct xenvif *vif);/* Receive an SKB from the frontend */ void xenvif_receive_skb (struct xenvif *vif,struct sk_buff *skb);/* Queue an SKB for transmission to the frontend */ -void xen_netbk_queue_tx_skb (struct xenvif *vif,struct sk_buff *skb); +void xenvif_queue_tx_skb (struct xenvif *vif,struct sk_buff *skb);/* Notify xenvif that ring now has space to send an skb to the frontend */ void xenvif_notify_tx_completion (struct xenvif *vif);/* Returns number of ring slots required to send an skb to the frontend */ -unsigned int xen_netbk_count_skb_slots (struct xenvif *vif,struct sk_buff *skb); +unsigned int xenvif_count_skb_slots (struct xenvif *vif,struct sk_buff *skb); -void xen_netbk_tx_action (struct xenvif *vif,int *work_done,int budget); -void xen_netbk_rx_action (struct xenvif *vif); +int xenvif_tx_action (struct xenvif *vif,int budget); +void xenvif_rx_action (struct xenvif *vif); -int xen_netbk_kthread (void *data); +int xenvif_kthread (void *data);#endif /* __XEN_NETBACK__COMMON_H__ */
drivers/net/xen-netback/interface.c +10 -10
@@ -48,7 +48,7 @@ int xenvif_schedulable(struct xenvif *vif)static int xenvif_rx_schedulable (struct xenvif *vif) { -return xenvif_schedulable (vif) && !xen_netbk_rx_ring_full (vif); +return xenvif_schedulable (vif) && !xenvif_rx_ring_full (vif); }static irqreturn_t xenvif_interrupt (int irq,void *dev_id)
@@ -69,7 +69,7 @@ static int xenvif_poll(struct napi_struct *napi, int budget) struct xenvif *vif = container_of(napi, struct xenvif, napi);int work_done =0 ; -xen_netbk_tx_action (vif, &work_done, budget); + work_done =xenvif_tx_action (vif, budget);if (work_done < budget) {int more_to_do =0 ;
@@ -101,12 +101,12 @@ static int xenvif_start_xmit(struct sk_buff *skb, struct net_device *dev) goto drop;/* Reserve ring slots for the worst-case number of fragments. */ - vif->rx_req_cons_peek +=xen_netbk_count_skb_slots (vif, skb); + vif->rx_req_cons_peek +=xenvif_count_skb_slots (vif, skb); -if (vif->can_queue &&xen_netbk_must_stop_queue (vif)) +if (vif->can_queue &&xenvif_must_stop_queue (vif))netif_stop_queue (dev); -xen_netbk_queue_tx_skb (vif, skb); +xenvif_queue_tx_skb (vif, skb);return NETDEV_TX_OK ;
@@ -137,7 +137,7 @@ static void xenvif_up(struct xenvif *vif) {napi_enable (&vif->napi);enable_irq (vif->irq); -xen_netbk_check_rx_xenvif (vif); +xenvif_check_rx_xenvif (vif); }static void xenvif_down (struct xenvif *vif)
@@ -334,7 +334,7 @@ int xenvif_connect(struct xenvif *vif, unsigned long tx_ring_ref,__module_get (THIS_MODULE ); - err =xen_netbk_map_frontend_rings (vif, tx_ring_ref, rx_ring_ref); + err =xenvif_map_frontend_rings (vif, tx_ring_ref, rx_ring_ref);if (err <0 ) goto err;
@@ -347,7 +347,7 @@ int xenvif_connect(struct xenvif *vif, unsigned long tx_ring_ref,disable_irq (vif->irq);init_waitqueue_head (&vif->wq); - vif->task =kthread_create (xen_netbk_kthread, + vif->task =kthread_create (xenvif_kthread, (void *)vif,"vif%d.%d" , vif->domid, vif->handle);if (IS_ERR (vif->task)) {
@@ -371,7 +371,7 @@ int xenvif_connect(struct xenvif *vif, unsigned long tx_ring_ref, err_unbind:unbind_from_irqhandler (vif->irq, vif); err_unmap: -xen_netbk_unmap_frontend_rings (vif); +xenvif_unmap_frontend_rings (vif); err:return err; }
@@ -400,7 +400,7 @@ void xenvif_disconnect(struct xenvif *vif)unregister_netdev (vif->dev); -xen_netbk_unmap_frontend_rings (vif); +xenvif_unmap_frontend_rings (vif);free_netdev (vif->dev);
drivers/net/xen-netback/netback.c +118 -111
602 lines not on this page · raw message
Signature · 1 line
1.7.2.5
RFC PATCH v2 8/8 netback: remove unwanted notification generation during NAPI processing.
In reply to Wei LiuIn original implementation, tx_build_gops tends to update req_event pointer every time it sees tx error or finish one batch. Remove those code to only update req_event pointer when we really want to shut down NAPI.
--- drivers/net/xen-netback/interface.c | 5 +++-- drivers/net/xen-netback/netback.c | 4 +--- 2 files changed, 4 insertions(+), 5 deletions(-)
drivers/net/xen-netback/interface.c +3 -2
@@ -58,8 +58,8 @@ static irqreturn_t xenvif_interrupt(int irq, void *dev_id)if (xenvif_rx_schedulable (vif))netif_wake_queue (vif->dev); -if (likely (napi_schedule_prep (&vif->napi))) -__napi_schedule (&vif->napi); +if (RING_HAS_UNCONSUMED_REQUESTS (&vif->tx)) +napi_schedule (&vif->napi);return IRQ_HANDLED ; }
@@ -74,6 +74,7 @@ static int xenvif_poll(struct napi_struct *napi, int budget)if (work_done < budget) {int more_to_do =0 ;unsigned long flag; +local_irq_save (flag);RING_FINAL_CHECK_FOR_REQUESTS (&vif->tx, more_to_do);
drivers/net/xen-netback/netback.c +1 -3
@@ -663,7 +663,6 @@ static void xenvif_tx_err(struct xenvif *vif, txp =RING_GET_REQUEST (&vif->tx, cons++); }while (1 ); vif->tx.req_cons = cons; -xenvif_check_rx_xenvif (vif); } static int xenvif_count_requests(struct xenvif *vif,
@@ -1048,7 +1047,7 @@ static unsigned xenvif_tx_build_gops(struct xenvif *vif,int pool_idx;struct pending_tx_info *pending_tx_info; -RING_FINAL_CHECK_FOR_REQUESTS (&vif->tx, work_to_do); + work_to_do =RING_HAS_UNCONSUMED_REQUESTS (&vif->tx);if (!work_to_do) {break ; }
@@ -1188,7 +1187,6 @@ static unsigned xenvif_tx_build_gops(struct xenvif *vif, gop = request_gop; vif->tx.req_cons = idx; -xenvif_check_rx_xenvif (vif);if ((gop - tco) >=MAX_PENDING_REQS )break ;
Signature · 1 line
1.7.2.5
Re: [RFC PATCH V2 3/8] netback: switch to NAPI + kthread model
In reply to Wei LiuQuoted 9 lines · On Tue, 17 Jan 2012 13:46:59 +0000 Wei Liu <[email protected]> wrote:
This patch implements 1:1 model netback. We utilizes NAPI and kthread to do the weight-lifting job:
- NAPI is used for guest side TX (host side RX)
- kthread is used for guest side RX (host side TX)This model provides better scheduling fairness among vifs. It also lays the foundation for future work.
Quoted 6 lines
The major defect for the current implementation is that in the NAPI poll handler we don't actually disable interrupt. Xen stuff is different from real hardware, it requires some other tuning of ring macros.
Signed-off-by Wei Liu <[email protected]>
The network receive processing is sensitive to the context it is run in. Normally it is run in softirq with interrupts enabled. With your code, the poll routine disables IRQ's which shouldn't be necessary.
Why does xenvif_receive_skb() need to still exist? Couldn't it just be replaced with call to netif_receive_skb() in one place it is called.
Re: [RFC PATCH V2 3/8] netback: switch to NAPI + kthread model
Quoted 17 lines · Stephen Hemminger
Quoted 14 lines · On Tue, 17 Jan 2012 13:46:59 +0000 Wei Liu <[email protected]> wrote:
This patch implements 1:1 model netback. We utilizes NAPI and kthread to do the weight-lifting job:
- NAPI is used for guest side TX (host side RX)
- kthread is used for guest side RX (host side TX)This model provides better scheduling fairness among vifs. It also lays the foundation for future work.
The major defect for the current implementation is that in the NAPI poll handler we don't actually disable interrupt. Xen stuff is different from real hardware, it requires some other tuning of ring macros.
Quoted 6 lines
Quoted 1 line
Signed-off-by Wei Liu <[email protected]>The network receive processing is sensitive to the context it is run in. Normally it is run in softirq with interrupts enabled. With your code, the poll routine disables IRQ's which shouldn't be necessary.
Misunderstanding here. I should rewrite my commit message.
By "disabling interrupt" I mean stop the other end from generating events, not system wide disabling interrupt.
Quoted 2 lines
Why does
xenvif_receive_skb()need to still exist? Couldn't it just be replaced with call tonetif_receive_skb()in one place it is called.
Sure.
Wei.
Quoted 6 lines · Wei Liu
A new netback implementation which includes three major features:
- Global page pool support
- NAPI + kthread 1:1 model
- Netback internal name changes
Quoted 8 lines
Changes in V2:
- Fix minor bugs in V1
- Embedpending_tx_infointo page pool
- Per-cpu scratch space
- Notification code path clean upThis patch series is the foundation of furture work. So it is better to get it right first. Patch 1 and 3 have the real meat.
I've been playing with these patches and couple of things came to my mind:
- would it make sense to also register to the shrinker API? This way if the host is running low on memory it can squeeze it out of the pool code. Perhaps a future TODO..
- I like the pool code. I was thinking that perhaps (in the future) it could be used by blkback as well, as it runs into "not enought request structure" with the default setting. And making this dynamic would be pretty sweet.
- This patch set solves the CPU banding problem I've seen with the older netback. The older one I could see X netback threads eating 80% of CPU. With this one, the number is down to 13-14%.
So you can definitly stick 'Tested-by: Konrad.." on them. And definitly Reviewed-by on the first two - hadn't had a chance to look at the rest.
Quoted 23 lines
The first benifit of 1:1 model will be scheduling fairness.
The rational behind a global page pool is that we need to limit overall memory consumed by all vifs.
Utilization of NAPI enables the possibility to mitigate interrupts/events, the code path is cleaned up in a separated patch.
Netback internal changes cleans up the code structure after switching to 1:1 model. It also prepares netback for further code layout changes.
--- drivers/net/xen-netback/Makefile | 2 +- drivers/net/xen-netback/common.h | 78 ++-- drivers/net/xen-netback/interface.c | 117 ++++-- drivers/net/xen-netback/netback.c | 836 ++++++++++++++--------------------- drivers/net/xen-netback/page_pool.c | 185 ++++++++ drivers/net/xen-netback/page_pool.h | 66 +++ drivers/net/xen-netback/xenbus.c | 6 +- 7 files changed, 704 insertions(+), 586 deletions(-)
Quoted 16 lines · Konrad Rzeszutek Wilk
Quoted 6 lines · Wei Liu
A new netback implementation which includes three major features:
- Global page pool support
- NAPI + kthread 1:1 model
- Netback internal name changesQuoted 8 lines
Changes in V2:
- Fix minor bugs in V1
- Embedpending_tx_infointo page pool
- Per-cpu scratch space
- Notification code path clean upThis patch series is the foundation of furture work. So it is better to get it right first. Patch 1 and 3 have the real meat.
Quoted 9 lines
I've been playing with these patches and couple of things came to my mind:
- would it make sense to also register to the shrinker API? This way if the host is running low on memory it can squeeze it out of the pool code. Perhaps a future TODO..
- I like the pool code. I was thinking that perhaps (in the future) it could be used by blkback as well, as it runs into "not enought request structure" with the default setting. And making this dynamic would be pretty sweet.
Interesting thoughts worth adding to TODO list. But I'm focusing on multi-page ring support and split event channel at the moment, which should help improve performance on 10G network. Hopefully I can submit RFC patch V3 in a few days. ;-)
Quoted 7 lines
- This patch set solves the CPU banding problem I've seen with the older netback. The older one I could see X netback threads eating 80% of CPU. With this one, the number is down to 13-14%.
So you can definitly stick 'Tested-by: Konrad.." on them. And definitly Reviewed-by on the first two - hadn't had a chance to look at the rest.
Thanks for your extensive test and review.
Wei.
Quoted 36 lines · Wei Liu
Quoted 16 lines · Konrad Rzeszutek Wilk
Quoted 6 lines · Wei Liu
A new netback implementation which includes three major features:
- Global page pool support
- NAPI + kthread 1:1 model
- Netback internal name changesQuoted 8 lines
Changes in V2:
- Fix minor bugs in V1
- Embedpending_tx_infointo page pool
- Per-cpu scratch space
- Notification code path clean upThis patch series is the foundation of furture work. So it is better to get it right first. Patch 1 and 3 have the real meat.
Quoted 9 lines
I've been playing with these patches and couple of things came to my mind:
- would it make sense to also register to the shrinker API? This way if the host is running low on memory it can squeeze it out of the pool code. Perhaps a future TODO..
- I like the pool code. I was thinking that perhaps (in the future) it could be used by blkback as well, as it runs into "not enought request structure" with the default setting. And making this dynamic would be pretty sweet.Interesting thoughts worth adding to TODO list. But I'm focusing on multi-page ring support and split event channel at the moment, which should help improve performance on 10G network. Hopefully I can submit RFC patch V3 in a few days. ;-)
Quoted 4 lines
- This patch set solves the CPU banding problem I've seen with the older netback. The older one I could see X netback threads eating 80% of CPU. With this one, the number is down to 13-14%.
Quoted 5 lines
Quoted 3 lines
So you can definitly stick 'Tested-by: Konrad.." on them. And definitly Reviewed-by on the first two - hadn't had a chance to look at the rest.
Thanks for your extensive test and review.
Sure. I also did some testing with limiting the amount of CPUs and found that 'xl vcpu-set 0 N' make netback not work anymore :-(
Quoted 3 lines
Wei.
Quoted 3 lines · Konrad Rzeszutek Wilk
Sure. I also did some testing with limiting the amount of CPUs and found that 'xl vcpu-set 0 N' make netback not work anymore :-(
Quoted 1 line
Any stack trace? Oops message? Did you increase the number of CPUs or decrease the number?
I didn't pay much attention on the CPU hotplug path TBH. And the V3 series, which I just posted, has a completed different per-cpu scratch space implementation, which takes care of CPU hotplug events.
Wei.
Quoted 5 lines · Konrad Rzeszutek Wilk
- This patch set solves the CPU banding problem I've seen with the older netback. The older one I could see X netback threads eating
80%
of CPU. With this one, the number is down to 13-14%.
"CPU banding problem"?
If you had X threads using 80% before do you now see Y threads using 13-14% where Y is bigger or smaller than X? Is 80*X ~= 13*Y?
Ian.
Quoted 11 lines · Ian Campbell
Quoted 5 lines · Konrad Rzeszutek Wilk
- This patch set solves the CPU banding problem I've seen with the older netback. The older one I could see X netback threads eating
80%
of CPU. With this one, the number is down to 13-14%."CPU banding problem"?
If you had X threads using 80% before do you now see Y threads using 13-14% where Y is bigger or smaller than X? Is 80*X ~= 13*Y?
Yes. ~=. The count looked to be the same.
Quoted 2 lines
Ian.
Quoted 8 lines · Konrad Rzeszutek Wilk
Quoted 7 lines · Ian Campbell
Quoted 5 lines · Konrad Rzeszutek Wilk
- This patch set solves the CPU banding problem I've seen with the older netback. The older one I could see X netback threads eating
80%
of CPU. With this one, the number is down to 13-14%.
Quoted 6 lines
Quoted 4 lines
"CPU banding problem"?
If you had X threads using 80% before do you now see Y threads using 13-14% where Y is bigger or smaller than X? Is 80*X ~= 13*Y?
Yes. ~=. The count looked to be the same.
Great, that's as expected, the same work is more fairly distributed -- I thought you might be suggesting the total had gone down from X*80%->X*13% which is not what I thought this series would be doing!
Ian.
Quoted 5 lines · Konrad Rzeszutek Wilk
Sure. I also did some testing with limiting the amount of CPUs and found that 'xl vcpu-set 0 N' make netback not work anymore :-(
Quoted 2 lines
I just played with vcpu-set a bit, and I can reproduced this problem. That's a race condition.
One possible fix is remove cond_resched() in the kernel thread. After removing that, it fixes the problem (at least for me).
Wei.
drivers/net/xen-netback/netback.c +1 -1
@@ -994,7 +994,7 @@ int xenvif_kthread(void *data)wait_event_interruptible (vif->wq,rx_work_todo (vif) ||kthread_should_stop ()); -cond_resched (); +/* cond_resched(); */ if (kthread_should_stop ())break ;
Quoted 21 lines · Wei Liu (Intern)
Quoted 5 lines · Konrad Rzeszutek Wilk
Sure. I also did some testing with limiting the amount of CPUs and found that 'xl vcpu-set 0 N' make netback not work anymore :-(
Quoted 2 lines
I just played with vcpu-set a bit, and I can reproduced this problem. That's a race condition.
One possible fix is remove
cond_resched()in the kernel thread. After removing that, it fixes the problem (at least for me).Wei.
drivers/net/xen-netback/netback.c int xenvif_kthread(void *data) · line 1000
Quoted 8 lines
drivers/net/xen-netback/netback.c +1
-1@@ -994,7 +994,7 @@ int xenvif_kthread(void *data)wait_event_interruptible (vif->wq,rx_work_todo (vif) ||kthread_should_stop ()); -cond_resched (); +/* cond_resched(); */ if (kthread_should_stop ())break ;
Hmm... Here it comes again. Ignore this fix. It's more complicated than I thought.
Wei.
Quoted 3 lines · Konrad Rzeszutek Wilk
Sure. I also did some testing with limiting the amount of CPUs and found that 'xl vcpu-set 0 N' make netback not work anymore :-(
Quoted 1 line
I think I find a way to work around this problem. In fact, it is my fault -- I was not guarding memory safe enough.
I'm torturing my box at the moment, will see if it can survive the night. :-)
Wei.