xen-netback: switch to NAPI + kthread 1:1 model
Subsystems (2)
v3 cover xen-netback: switch to NAPI + kthread 1:1 model
This series implements NAPI + kthread 1:1 model for Xen netback.
This model
- provides better scheduling fairness among vifs
- is prerequisite for implementing multiqueue for Xen network driver
The first two patches are ground work for the third patch. First one simplifies code in netback, second one can reduce memory footprint if we switch to 1:1 model.
The third patch has the real meat:
- make use of NAPI to mitigate interrupt
- kthreads are not bound to CPUs any more, so that we can take advantage of backend scheduler and trust it to do the right thing
Benchmark done on a Dell T3400 workstation with 4 cores, running 4 DomUs. Netserver running in Dom0. DomUs do netperf to Dom0 with following command: /root/netperf -H Dom0 -fm -l120
IRQs are distributed to 4 cores by hand in the new model, while in the old model vifs are automatically distributed to 4 kthreads.
* New model
%Cpu0 : 0.5 us, 20.3 sy, 0.0 ni, 28.9 id, 0.0 wa, 0.0 hi, 24.4 si, 25.9 st %Cpu1 : 0.5 us, 17.8 sy, 0.0 ni, 28.8 id, 0.0 wa, 0.0 hi, 27.7 si, 25.1 st %Cpu2 : 0.5 us, 18.8 sy, 0.0 ni, 30.7 id, 0.0 wa, 0.0 hi, 22.9 si, 27.1 st %Cpu3 : 0.0 us, 20.1 sy, 0.0 ni, 30.4 id, 0.0 wa, 0.0 hi, 22.7 si, 26.8 st
Throughputs: 2027.89 2025.95 2018.57 2016.23 aggregated: 8088.64
* Old model
%Cpu0 : 0.5 us, 68.8 sy, 0.0 ni, 16.1 id, 0.5 wa, 0.0 hi, 2.8 si, 11.5 st %Cpu1 : 0.4 us, 45.1 sy, 0.0 ni, 31.1 id, 0.4 wa, 0.0 hi, 2.1 si, 20.9 st %Cpu2 : 0.9 us, 44.8 sy, 0.0 ni, 30.9 id, 0.0 wa, 0.0 hi, 1.3 si, 22.2 st %Cpu3 : 0.8 us, 46.4 sy, 0.0 ni, 28.3 id, 1.3 wa, 0.0 hi, 2.1 si, 21.1 st
Throughputs: 1899.14 2280.43 1963.33 1893.47 aggregated: 8036.37
We can see that the impact is mainly on CPU usage. The new model moves processing from kthread to NAPI (software interrupt).
Comments?
----------------------------------------------------
Change since V2:
- Remove per-cpu scratch space.
Change since V1:
- No page pool in this version. Instead page tracking facility is removed.
Wei Liu (2):
xen-netback: remove page tracking facility
xen-netback: switch to NAPI + kthread 1:1 model
drivers/net/xen-netback/common.h | 105 +++-- drivers/net/xen-netback/interface.c | 122 ++++-- drivers/net/xen-netback/netback.c | 817 +++++++++++------------------------ 3 files changed, 390 insertions(+), 654 deletions(-)
Signature · 1 line
1.7.10.4
PATCH v3 1/2 xen-netback: remove page tracking facility
The data flow from DomU to DomU on the same host in current copying scheme with tracking facility:
copy
DomU --------> Dom0 DomU
| ^ |____________________________|
copy
The page in Dom0 is a page with valid MFN. So we can always copy from page Dom0, thus removing the need for a tracking facility.
copy copy
DomU --------> Dom0 -------> DomU
Simple iperf test shows no performance regression (obviously we do two copy's either way):
W/ tracking: ~5.3Gb/s
W/o tracking: ~5.4Gb/s
--- drivers/net/xen-netback/netback.c | 77 +------------------------------------ 1 file changed, 2 insertions(+), 75 deletions(-)
drivers/net/xen-netback/netback.c +2 -75
@@ -95,21 +95,6 @@ struct netbk_rx_meta {#define MAX_BUFFER_OFFSET PAGE_SIZE -/* extra field used in struct page */ -union page_ext { -struct { -#if BITS_PER_LONG <64 -#define IDX_WIDTH 8 -#define GROUP_WIDTH (BITS_PER_LONG - IDX_WIDTH) -unsigned int group:GROUP_WIDTH ; -unsigned int idx:IDX_WIDTH ; -#else -unsigned int group, idx; -#endif - } e; -void *mapping; -}; -struct xen_netbk {wait_queue_head_t wq;struct task_struct *task;
@@ -214,45 +199,6 @@ static inline unsigned long idx_to_kaddr(struct xen_netbk *netbk,return (unsigned long )pfn_to_kaddr (idx_to_pfn (netbk, idx)); } -/* extra field used in struct page */ -static inline void set_page_ext (struct page *pg,struct xen_netbk *netbk, -unsigned int idx) -{ -unsigned int group = netbk - xen_netbk; -union page_ext ext = { .e = { .group = group +1 , .idx = idx } }; - -BUILD_BUG_ON (sizeof (ext) >sizeof (ext.mapping)); - pg->mapping = ext.mapping; -} - -static int get_page_ext (struct page *pg, -unsigned int *pgroup,unsigned int *pidx) -{ -union page_ext ext = { .mapping = pg->mapping }; -struct xen_netbk *netbk; -unsigned int group, idx; - - group = ext.e.group -1 ; - -if (group <0 || group >= xen_netbk_group_nr) -return 0 ; - - netbk = &xen_netbk[group]; - - idx = ext.e.idx; - -if ((idx <0 ) || (idx >=MAX_PENDING_REQS )) -return 0 ; - -if (netbk->mmap_pages[idx] != pg) -return 0 ; - - *pgroup = group; - *pidx = idx; - -return 1 ; -} -/* * This is the amount of packet we copy rather than map, so that the * guest can't fiddle with the contents of the headers while we do
@@ -453,12 +399,6 @@ static void netbk_gop_frag_copy(struct xenvif *vif, struct sk_buff *skb, {struct gnttab_copy *copy_gop;struct netbk_rx_meta *meta; -/* -* These variables are used iff get_page_ext returns true, -* in which case they are guaranteed to be initialized. -*/ -unsigned int uninitialized_var (group ),uninitialized_var (idx ); -int foreign =get_page_ext (page, &group, &idx);unsigned long bytes;/* Data must not cross a page boundary. */
@@ -494,20 +434,9 @@ static void netbk_gop_frag_copy(struct xenvif *vif, struct sk_buff *skb, copy_gop = npo->copy + npo->copy_prod++; copy_gop->flags = GNTCOPY_dest_gref; -if (foreign) { -struct xen_netbk *netbk = &xen_netbk[group]; -struct pending_tx_info *src_pend; + copy_gop->source.domid =DOMID_SELF ; + copy_gop->source.u.gmfn =virt_to_mfn (page_address (page)); - src_pend = &netbk->pending_tx_info[idx]; - - copy_gop->source.domid = src_pend->vif->domid; - copy_gop->source.u.ref = src_pend->req.gref; - copy_gop->flags |= GNTCOPY_source_gref; - }else { -void *vaddr =page_address (page); - copy_gop->source.domid =DOMID_SELF ; - copy_gop->source.u.gmfn =virt_to_mfn (vaddr); - } copy_gop->source.offset = offset; copy_gop->dest.domid = vif->domid;
@@ -1045,7 +974,6 @@ static struct page *xen_netbk_alloc_page(struct xen_netbk *netbk, page =alloc_page (GFP_KERNEL |__GFP_COLD);if (!page)return NULL ; -set_page_ext (page, netbk, pending_idx); netbk->mmap_pages[pending_idx] = page;return page; }
@@ -1153,7 +1081,6 @@ static struct gnttab_copy *xen_netbk_get_requests(struct xen_netbk *netbk, first->req.offset =0 ; first->req.size = dst_offset; first->head = start_idx; -set_page_ext (page, netbk, head_idx); netbk->mmap_pages[head_idx] = page;frag_set_pending_idx (&frags[shinfo->nr_frags], head_idx); }
Signature · 1 line
1.7.10.4
Re: [PATCH 1/2] xen-netback: remove page tracking facility
Quoted 8 lines · Wei Liu
The data flow from DomU to DomU on the same host in current copying scheme with tracking facility:
copy
DomU --------> Dom0 DomU| ^ |____________________________|copy
Um, wow, that was certainly unintentional!
Quoted 5 lines
The page in Dom0 is a page with valid MFN. So we can always copy from page Dom0, thus removing the need for a tracking facility.
copy copy
DomU --------> Dom0 -------> DomU
Much nicer!
Quoted 7 lines
Simple iperf test shows no performance regression (obviously we do two copy's either way):
W/ tracking: ~5.3Gb/s
W/o tracking: ~5.4Gb/sSigned-off-by Wei Liu <[email protected]>
Quoted 128 lines
--- drivers/net/xen-netback/netback.c | 77 +------------------------------------ 1 file changed, 2 insertions(+), 75 deletions(-)drivers/net/xen-netback/netback.c +2
-75@@ -95,21 +95,6 @@ struct netbk_rx_meta {#define MAX_BUFFER_OFFSET PAGE_SIZE -/* extra field used in struct page */ -union page_ext { -struct { -#if BITS_PER_LONG <64 -#define IDX_WIDTH 8 -#define GROUP_WIDTH (BITS_PER_LONG - IDX_WIDTH) -unsigned int group:GROUP_WIDTH ; -unsigned int idx:IDX_WIDTH ; -#else -unsigned int group, idx; -#endif - } e; -void *mapping; -}; -struct xen_netbk {wait_queue_head_t wq;struct task_struct *task;@@ -214,45 +199,6 @@ static inline unsigned long idx_to_kaddr(struct xen_netbk *netbk,return (unsigned long )pfn_to_kaddr (idx_to_pfn (netbk, idx)); } -/* extra field used in struct page */ -static inline void set_page_ext (struct page *pg,struct xen_netbk *netbk, -unsigned int idx) -{ -unsigned int group = netbk - xen_netbk; -union page_ext ext = { .e = { .group = group +1 , .idx = idx } }; - -BUILD_BUG_ON (sizeof (ext) >sizeof (ext.mapping)); - pg->mapping = ext.mapping; -} - -static int get_page_ext (struct page *pg, -unsigned int *pgroup,unsigned int *pidx) -{ -union page_ext ext = { .mapping = pg->mapping }; -struct xen_netbk *netbk; -unsigned int group, idx; - - group = ext.e.group -1 ; - -if (group <0 || group >= xen_netbk_group_nr) -return 0 ; - - netbk = &xen_netbk[group]; - - idx = ext.e.idx; - -if ((idx <0 ) || (idx >=MAX_PENDING_REQS )) -return 0 ; - -if (netbk->mmap_pages[idx] != pg) -return 0 ; - - *pgroup = group; - *pidx = idx; - -return 1 ; -} -/* * This is the amount of packet we copy rather than map, so that the * guest can't fiddle with the contents of the headers while we do @@ -453,12 +399,6 @@ static void netbk_gop_frag_copy(struct xenvif *vif, struct sk_buff *skb, {struct gnttab_copy *copy_gop;struct netbk_rx_meta *meta; -/* -* These variables are used iff get_page_ext returns true, -* in which case they are guaranteed to be initialized. -*/ -unsigned int uninitialized_var (group ),uninitialized_var (idx ); -int foreign =get_page_ext (page, &group, &idx);unsigned long bytes;/* Data must not cross a page boundary. */ @@ -494,20 +434,9 @@ static void netbk_gop_frag_copy(struct xenvif *vif, struct sk_buff *skb, copy_gop = npo->copy + npo->copy_prod++; copy_gop->flags = GNTCOPY_dest_gref; -if (foreign) { -struct xen_netbk *netbk = &xen_netbk[group]; -struct pending_tx_info *src_pend; + copy_gop->source.domid =DOMID_SELF ; + copy_gop->source.u.gmfn =virt_to_mfn (page_address (page)); - src_pend = &netbk->pending_tx_info[idx]; - - copy_gop->source.domid = src_pend->vif->domid; - copy_gop->source.u.ref = src_pend->req.gref; - copy_gop->flags |= GNTCOPY_source_gref; - }else { -void *vaddr =page_address (page); - copy_gop->source.domid =DOMID_SELF ; - copy_gop->source.u.gmfn =virt_to_mfn (vaddr); - } copy_gop->source.offset = offset; copy_gop->dest.domid = vif->domid;@@ -1045,7 +974,6 @@ static struct page *xen_netbk_alloc_page(struct xen_netbk *netbk, page =alloc_page (GFP_KERNEL |__GFP_COLD);if (!page)return NULL ; -set_page_ext (page, netbk, pending_idx); netbk->mmap_pages[pending_idx] = page;return page; }@@ -1153,7 +1081,6 @@ static struct gnttab_copy *xen_netbk_get_requests(struct xen_netbk *netbk, first->req.offset =0 ; first->req.size = dst_offset; first->head = start_idx; -set_page_ext (page, netbk, head_idx); netbk->mmap_pages[head_idx] = page;frag_set_pending_idx (&frags[shinfo->nr_frags], head_idx); }
PATCH v3 2/2 xen-netback: switch to NAPI + kthread 1:1 model
In reply to Wei LiuThis patch implements 1:1 model netback. NAPI and kthread are utilized 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)
Xenvif and xen_netbk are made into one structure to reduce code size.
This model provides better scheduling fairness among vifs. It is also prerequisite for implementing multiqueue for Xen netback.
--- drivers/net/xen-netback/common.h | 105 +++-- drivers/net/xen-netback/interface.c | 122 +++--- drivers/net/xen-netback/netback.c | 742 ++++++++++++----------------------- 3 files changed, 389 insertions(+), 580 deletions(-)
drivers/net/xen-netback/common.h +70 -35
@@ -45,15 +45,43 @@#include <xen/grant_table.h> #include <xen/xenbus.h> -struct xen_netbk ; +typedef unsigned int pending_ring_idx_t ; +#define INVALID_PENDING_RING_IDX (~0U) + +struct pending_tx_info { +struct xen_netif_tx_request req;/* coalesced tx request */ +pending_ring_idx_t head;/* head != INVALID_PENDING_RING_IDX +* if it is head of one or more tx +* reqs +*/ +}; + +#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_rx_meta { +int id; +int size; +int gso_size; +}; + +/* Discriminate from any valid pending_idx value. */ +#define INVALID_PENDING_IDX 0xFFFF + +#define MAX_BUFFER_OFFSET PAGE_SIZE + +#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 */ +struct task_struct *task; +wait_queue_head_t wq;u8 fe_dev_addr[6 ];
@@ -64,9 +92,6 @@ struct xenvif {char tx_irq_name[IFNAMSIZ +4 ];/* DEVNAME-tx */ char rx_irq_name[IFNAMSIZ +4 ];/* DEVNAME-rx */ -/* 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;
@@ -96,12 +121,33 @@ struct xenvif {/* Statistics */ unsigned long rx_gso_checksum_fixup; +struct sk_buff_head rx_queue; +struct sk_buff_head tx_queue; + +struct page *mmap_pages[MAX_PENDING_REQS ]; + +pending_ring_idx_t pending_prod; +pending_ring_idx_t pending_cons; +u16 pending_ring[MAX_PENDING_REQS ]; + +struct pending_tx_info pending_tx_info[MAX_PENDING_REQS ]; + +/* Coalescing tx requests before copying makes number of grant +* copy ops greater or equal to number of slots required. In +* worst case a tx request consumes 2 gnttab_copy. +*/ +struct gnttab_copy tx_copy_ops[2 *MAX_PENDING_REQS ]; + +/* +* Given MAX_BUFFER_OFFSET of 4096 the worst case is that each +* head/fragment page uses 2 copy operations because it +* straddles two buffers in the frontend. +*/ +struct gnttab_copy grant_copy_op[2 *XEN_NETIF_RX_RING_SIZE ]; +struct xenvif_rx_meta meta[2 *XEN_NETIF_RX_RING_SIZE ]; +/* 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)
@@ -109,9 +155,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);
@@ -121,39 +164,26 @@ int xenvif_connect(struct xenvif *vif, unsigned long tx_ring_ref, unsigned int rx_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_fini (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); - -/* (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); +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); -/* Receive an SKB from the frontend */ -void xenvif_receive_skb (struct xenvif *vif,struct sk_buff *skb); +void xenvif_check_rx_xenvif (struct xenvif *vif);/* 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);
@@ -161,7 +191,12 @@ void xenvif_notify_tx_completion(struct xenvif *vif);void xenvif_carrier_off (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); + +int xenvif_tx_action (struct xenvif *vif,int budget); +void xenvif_rx_action (struct xenvif *vif); + +int xenvif_kthread (void *data);extern bool separate_tx_rx_irq;
drivers/net/xen-netback/interface.c +75 -47
266 lines not on this page · raw message
drivers/net/xen-netback/netback.c +244 -498
1,383 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Quoted 10 lines · Wei Liu
This patch implements 1:1 model netback. NAPI and kthread are utilized 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)Xenvif and
xen_netbkare made into one structure to reduce code size.This model provides better scheduling fairness among vifs. It is also prerequisite for implementing multiqueue for Xen netback.
Any interesting numbers from this change?
Quoted 14 lines
Signed-off-by Wei Liu <[email protected]>--- drivers/net/xen-netback/common.h | 105 +++-- drivers/net/xen-netback/interface.c | 122 +++--- drivers/net/xen-netback/netback.c | 742 ++++++++++++----------------------- 3 files changed, 389 insertions(+), 580 deletions(-)drivers/net/xen-netback/common.h +0
-0@@ -45,15 +45,43 @@#include <xen/grant_table.h> #include <xen/xenbus.h>
drivers/net/xen-netback/common.h line 55
Quoted 10 lines
drivers/net/xen-netback/common.h +8
-1-struct xen_netbk ; +typedef unsigned int pending_ring_idx_t ; +#define INVALID_PENDING_RING_IDX (~0U) + +struct pending_tx_info { +struct xen_netif_tx_request req;/* coalesced tx request */ +pending_ring_idx_t head;/* head != INVALID_PENDING_RING_IDX +* if it is head of one or more tx +* reqs
So this sounds like it is only valid for the pending tx corresponding to the first slot in a frame, right?
It does not contain a link from any arbitrary slot to the slot containing the head of that frame, right?
So for the head it is effectively that entries index into the pending_tx array?
Quoted 21 lines
drivers/net/xen-netback/common.h +18
-0+*/ +}; + +#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_rx_meta { +int id; +int size; +int gso_size; +}; + +/* Discriminate from any valid pending_idx value. */ +#define INVALID_PENDING_IDX 0xFFFF + +#define MAX_BUFFER_OFFSET PAGE_SIZE + +#define MAX_PENDING_REQS 256struct xenvif {/* Unique identifier for this interface. */
drivers/net/xen-netback/common.h line 84
Quoted 10 lines
drivers/net/xen-netback/common.h +5
-2domid_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 */ +struct task_struct *task; +wait_queue_head_t wq;
This isn't new with this patch but I wonder if we shouldn't group tx and rx related things into to separate regions of the struct, rather than interleaving them like this. Especially once we start to separate RX and TX processing onto different processes the current layout is going to have pretty horrible cache line bouncing properties.
Quoted 75 lines
drivers/net/xen-netback/common.h +26
-14u8 fe_dev_addr[6 ];@@ -64,9 +92,6 @@ struct xenvif {char tx_irq_name[IFNAMSIZ +4 ];/* DEVNAME-tx */ char rx_irq_name[IFNAMSIZ +4 ];/* DEVNAME-rx */ -/* 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;@@ -96,12 +121,33 @@ struct xenvif {/* Statistics */ unsigned long rx_gso_checksum_fixup; +struct sk_buff_head rx_queue; +struct sk_buff_head tx_queue; + +struct page *mmap_pages[MAX_PENDING_REQS ]; + +pending_ring_idx_t pending_prod; +pending_ring_idx_t pending_cons; +u16 pending_ring[MAX_PENDING_REQS ]; + +struct pending_tx_info pending_tx_info[MAX_PENDING_REQS ]; + +/* Coalescing tx requests before copying makes number of grant +* copy ops greater or equal to number of slots required. In +* worst case a tx request consumes 2 gnttab_copy. +*/ +struct gnttab_copy tx_copy_ops[2 *MAX_PENDING_REQS ]; + +/* +* Given MAX_BUFFER_OFFSET of 4096 the worst case is that each +* head/fragment page uses 2 copy operations because it +* straddles two buffers in the frontend. +*/ +struct gnttab_copy grant_copy_op[2 *XEN_NETIF_RX_RING_SIZE ]; +struct xenvif_rx_meta meta[2 *XEN_NETIF_RX_RING_SIZE ]; +/* 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)@@ -109,9 +155,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);@@ -121,39 +164,26 @@ int xenvif_connect(struct xenvif *vif, unsigned long tx_ring_ref, unsigned int rx_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_fini (void );int xenvif_schedulable (struct xenvif *vif); -int xen_netbk_rx_ring_full (struct xenvif *vif); +int xenvif_rx_ring_full (struct xenvif *vif);
Quoted 1 line
From a review PoV it would have been good to do the bulk rename either
before or after the functional changes. I just skipped over anything which looked to be just renaming at first glance. Hopefully I didn't miss anything ciritical!
drivers/net/xen-netback/common.h
Quoted 12 lines
drivers/net/xen-netback/common.h +12
-0+static int xenvif_poll (struct napi_struct *napi,int budget) +{ + struct xenvif *vif = container_of(napi, struct xenvif, napi); +int work_done; + + work_done =xenvif_tx_action (vif, budget); + +if (work_done < budget) { +int more_to_do =0 ; +unsigned long flags; + +local_irq_save (flags);
What does this protect against? Maybe it's a napi requirement not an Xen netif one?
drivers/net/xen-netback/common.h
Quoted 3 lines
drivers/net/xen-netback/common.h +3
-0+ +RING_FINAL_CHECK_FOR_REQUESTS (&vif->tx, more_to_do); +if (!more_to_do || work_done <0 )
"work_done < 0" is an error condition from xenvif_tx_action? But following the chain down through xenvif_tx_action to xenvif_tx_submit it doesn't look like such a thing is possible?
Perhaps just a BUG_ON(work_done < 0) right after the call to xenvif_tx_action()?
drivers/net/xen-netback/common.h struct xenvif *xenvif_alloc(struct device *parent, domid_t domid, · line 284
Quoted 12 lines
drivers/net/xen-netback/common.h +3
-1@@ -272,11 +275,13 @@ struct xenvif *xenvif_alloc(struct device *parent, domid_t domid,struct net_device *dev;struct xenvif *vif;char name[IFNAMSIZ ] = {}; +int i;snprintf (name,IFNAMSIZ -1 ,"vif%u.%u" , domid, handle); dev =alloc_netdev (sizeof (struct xenvif ), name, ether_setup);if (dev ==NULL ) { -pr_warn ("Could not allocate netdev\n" ); +printk (KERN_WARNING "xen-netback: Could not allocate netdev for vif%d.%d\n" , + domid, handle);
pr_warn can take a fmt string and do the right thing, can't it? Or was there a different reason for this change?
Rather than repeating vif%d.%d why not reuse the result of the previous snprintf -- especially since the fmt codes differ (although probably not in a way which affects the result).
drivers/net/xen-netback/common.h int xenvif_connect(struct xenvif *vif, unsigned long tx_ring_ref, · line 395
Quoted 9 lines
drivers/net/xen-netback/common.h +4
-1@@ -377,7 +389,16 @@ int xenvif_connect(struct xenvif *vif, unsigned long tx_ring_ref,disable_irq (vif->rx_irq); } -xenvif_get (vif); +init_waitqueue_head (&vif->wq); + vif->task =kthread_create (xenvif_kthread, + (void *)vif, +"vif%d.%d" , vif->domid, vif->handle);
%u.%u, or better find a way to reuse the name allocated in xenvif_alloc, which I suppose you can get via vif->dev->name?
drivers/net/xen-netback/common.h int xenvif_connect(struct xenvif *vif, unsigned long tx_ring_ref, · line 398
Quoted 3 lines
drivers/net/xen-netback/common.h +3
-0+if (IS_ERR (vif->task)) { +printk (KERN_WARNING "xen-netback: Could not allocate kthread for vif%d.%d\n" , + vif->domid, vif->handle);
pr_warn if possible please. and %u vs %d again.
drivers/net/xen-netback/common.h static void netbk_gop_frag_copy(struct xenvif *vif, struct sk_buff *skb, · line 439
Quoted 8 lines
drivers/net/xen-netback/common.h +1
-1@@ -434,9 +338,9 @@ static void netbk_gop_frag_copy(struct xenvif *vif, struct sk_buff *skb, copy_gop = npo->copy + npo->copy_prod++; copy_gop->flags = GNTCOPY_dest_gref; + copy_gop->source.domid =DOMID_SELF ; copy_gop->source.u.gmfn =virt_to_mfn (page_address (page)); -
The blank lines in this function seem pretty arbitrary both before and after this change ;-)
Quoted 4 lines
drivers/net/xen-netback/common.h +0
-0copy_gop->source.offset = offset; copy_gop->dest.domid = vif->domid;
drivers/net/xen-netback/common.h static unsigned xen_netbk_tx_build_gops(struct xen_netbk *netbk) · line 1285
Quoted 10 lines
drivers/net/xen-netback/common.h +3
-3@@ -1469,19 +1279,20 @@ static unsigned xen_netbk_tx_build_gops(struct xen_netbk *netbk)struct xen_netif_extra_info *gso; gso = &extras[XEN_NETIF_EXTRA_TYPE_GSO -1 ]; -if (netbk_set_skb_gso (vif, skb, gso)) { -/* Failure in netbk_set_skb_gso is fatal. */ +if (xenvif_set_skb_gso (vif, skb, gso)) { +/* Failure in xenvif_set_skb_gso is fatal. */ kfree_skb (skb); -continue ; +/* XXX ???? break or continue ?*/
I'd been wondering that a bunch in the previous hunks too ;-)
break seems fine here.
drivers/net/xen-netback/common.h static unsigned xen_netbk_tx_build_gops(struct xen_netbk *netbk) · line 1297
Quoted 13 lines
drivers/net/xen-netback/common.h +12
-0+int xenvif_kthread (void *data) +{ +struct xenvif *vif = data; + +while (!kthread_should_stop ()) { +wait_event_interruptible (vif->wq, +rx_work_todo (vif) || +kthread_should_stop ()); +cond_resched (); + +if (kthread_should_stop ()) +break ;
Should this come before the cond resched? Seems odd to potentially wait a bit before just exiting.
Ian.
Quoted 7 lines · Ian Campbell
Quoted 6 lines · Wei Liu
This patch implements 1:1 model netback. NAPI and kthread are utilized 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)
Quoted 7 lines
Quoted 4 lines
Xenvif and
xen_netbkare made into one structure to reduce code size.This model provides better scheduling fairness among vifs. It is also prerequisite for implementing multiqueue for Xen netback.
Any interesting numbers from this change?
[extracted from 0/2 of this series]
IRQs are distributed to 4 cores by hand in the new model, while in the old model vifs are automatically distributed to 4 kthreads.
* New model
%Cpu0 : 0.5 us, 20.3 sy, 0.0 ni, 28.9 id, 0.0 wa, 0.0 hi, 24.4 si, 25.9 st %Cpu1 : 0.5 us, 17.8 sy, 0.0 ni, 28.8 id, 0.0 wa, 0.0 hi, 27.7 si, 25.1 st %Cpu2 : 0.5 us, 18.8 sy, 0.0 ni, 30.7 id, 0.0 wa, 0.0 hi, 22.9 si, 27.1 st %Cpu3 : 0.0 us, 20.1 sy, 0.0 ni, 30.4 id, 0.0 wa, 0.0 hi, 22.7 si, 26.8 st
Throughputs: 2027.89 2025.95 2018.57 2016.23 aggregated: 8088.64
* Old model
%Cpu0 : 0.5 us, 68.8 sy, 0.0 ni, 16.1 id, 0.5 wa, 0.0 hi, 2.8 si, 11.5 st %Cpu1 : 0.4 us, 45.1 sy, 0.0 ni, 31.1 id, 0.4 wa, 0.0 hi, 2.1 si, 20.9 st %Cpu2 : 0.9 us, 44.8 sy, 0.0 ni, 30.9 id, 0.0 wa, 0.0 hi, 1.3 si, 22.2 st %Cpu3 : 0.8 us, 46.4 sy, 0.0 ni, 28.3 id, 1.3 wa, 0.0 hi, 2.1 si, 21.1 st
Throughputs: 1899.14 2280.43 1963.33 1893.47 aggregated: 8036.37
Quoted 15 lines
Quoted 15 lines
Signed-off-by Wei Liu <[email protected]>--- drivers/net/xen-netback/common.h | 105 +++-- drivers/net/xen-netback/interface.c | 122 +++--- drivers/net/xen-netback/netback.c | 742 ++++++++++++----------------------- 3 files changed, 389 insertions(+), 580 deletions(-)drivers/net/xen-netback/common.h +0
-0@@ -45,15 +45,43 @@#include <xen/grant_table.h> #include <xen/xenbus.h>
Quoted 10 lines
drivers/net/xen-netback/common.h line 55
Quoted 9 lines
drivers/net/xen-netback/common.h +8
-1-struct xen_netbk ; +typedef unsigned int pending_ring_idx_t ; +#define INVALID_PENDING_RING_IDX (~0U) + +struct pending_tx_info { +struct xen_netif_tx_request req;/* coalesced tx request */ +pending_ring_idx_t head;/* head != INVALID_PENDING_RING_IDX +* if it is head of one or more tx +* reqs
This is only code movement, no funcational change.
Quoted 3 lines
So this sounds like it is only valid for the pending tx corresponding to the first slot in a frame, right?
No. It can also be interpreted as continuation of several merged tx requests.
Quoted 6 lines
It does not contain a link from any arbitrary slot to the slot containing the head of that frame, right?
So for the head it is effectively that entries index into the
pending_txarray?
No. It's a flag to tell if this pending_tx_info is the head of one or more merged tx requests.
Quoted 24 lines
Quoted 24 lines
drivers/net/xen-netback/common.h +18
-0+*/ +}; + +#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_rx_meta { +int id; +int size; +int gso_size; +}; + +/* Discriminate from any valid pending_idx value. */ +#define INVALID_PENDING_IDX 0xFFFF + +#define MAX_BUFFER_OFFSET PAGE_SIZE + +#define MAX_PENDING_REQS 256struct xenvif {/* Unique identifier for this interface. */ domid_t domid;unsigned int handle;
Quoted 14 lines
drivers/net/xen-netback/common.h line 84
Quoted 7 lines
drivers/net/xen-netback/common.h +5
-2-/* 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;This isn't new with this patch but I wonder if we shouldn't group tx and rx related things into to separate regions of the struct, rather than interleaving them like this. Especially once we start to separate RX and TX processing onto different processes the current layout is going to have pretty horrible cache line bouncing properties.
OK, will group them separately.
Quoted 72 lines
Quoted 72 lines
drivers/net/xen-netback/common.h +25
-13u8 fe_dev_addr[6 ];@@ -64,9 +92,6 @@ struct xenvif {char tx_irq_name[IFNAMSIZ +4 ];/* DEVNAME-tx */ char rx_irq_name[IFNAMSIZ +4 ];/* DEVNAME-rx */ -/* 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;@@ -96,12 +121,33 @@ struct xenvif {/* Statistics */ unsigned long rx_gso_checksum_fixup; +struct sk_buff_head rx_queue; +struct sk_buff_head tx_queue; + +struct page *mmap_pages[MAX_PENDING_REQS ]; + +pending_ring_idx_t pending_prod; +pending_ring_idx_t pending_cons; +u16 pending_ring[MAX_PENDING_REQS ]; + +struct pending_tx_info pending_tx_info[MAX_PENDING_REQS ]; + +/* Coalescing tx requests before copying makes number of grant +* copy ops greater or equal to number of slots required. In +* worst case a tx request consumes 2 gnttab_copy. +*/ +struct gnttab_copy tx_copy_ops[2 *MAX_PENDING_REQS ]; + +/* +* Given MAX_BUFFER_OFFSET of 4096 the worst case is that each +* head/fragment page uses 2 copy operations because it +* straddles two buffers in the frontend. +*/ +struct gnttab_copy grant_copy_op[2 *XEN_NETIF_RX_RING_SIZE ]; +struct xenvif_rx_meta meta[2 *XEN_NETIF_RX_RING_SIZE ]; +/* 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)@@ -109,9 +155,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);@@ -121,39 +164,26 @@ int xenvif_connect(struct xenvif *vif, unsigned long tx_ring_ref, unsigned int rx_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_fini (void );int xenvif_schedulable (struct xenvif *vif);
Quoted 8 lines
Quoted 4 lines
drivers/net/xen-netback/common.h +1
-1-int xen_netbk_rx_ring_full (struct xenvif *vif); +int xenvif_rx_ring_full (struct xenvif *vif);From a review PoV it would have been good to do the bulk rename either
before or after the functional changes. I just skipped over anything which looked to be just renaming at first glance. Hopefully I didn't miss anything ciritical!
No problem, will separate rename and functional changes to two patches.
Quoted 7 lines
Quoted 7 lines
drivers/net/xen-netback/common.h +7
-0+static int xenvif_poll (struct napi_struct *napi,int budget) +{ + struct xenvif *vif = container_of(napi, struct xenvif, napi); +int work_done; + + work_done =xenvif_tx_action (vif, budget); +
Quoted 9 lines
drivers/net/xen-netback/common.h
Quoted 5 lines
drivers/net/xen-netback/common.h +5
-0+if (work_done < budget) { +int more_to_do =0 ; +unsigned long flags; + +local_irq_save (flags);What does this protect against? Maybe it's a napi requirement not an Xen netif one?
This is sort of a NAPI requirement. If we don't do local_irq_save we would lose event.
Quoted 8 lines
drivers/net/xen-netback/common.h
Quoted 3 lines
drivers/net/xen-netback/common.h +3
-0+ +RING_FINAL_CHECK_FOR_REQUESTS (&vif->tx, more_to_do); +if (!more_to_do || work_done <0 )"
work_done< 0" is an error condition fromxenvif_tx_action? But following the chain down throughxenvif_tx_actiontoxenvif_tx_submitit doesn't look like such a thing is possible?
Right, this is not necessary.
Quoted 20 lines
Perhaps just a
BUG_ON(work_done < 0)right after the call toxenvif_tx_action()?drivers/net/xen-netback/common.h struct xenvif *xenvif_alloc(struct device *parent, domid_t domid, · line 284
Quoted 12 lines
drivers/net/xen-netback/common.h +3
-1@@ -272,11 +275,13 @@ struct xenvif *xenvif_alloc(struct device *parent, domid_t domid,struct net_device *dev;struct xenvif *vif;char name[IFNAMSIZ ] = {}; +int i;snprintf (name,IFNAMSIZ -1 ,"vif%u.%u" , domid, handle); dev =alloc_netdev (sizeof (struct xenvif ), name, ether_setup);if (dev ==NULL ) { -pr_warn ("Could not allocate netdev\n" ); +printk (KERN_WARNING "xen-netback: Could not allocate netdev for vif%d.%d\n" , + domid, handle);
pr_warncan take a fmt string and do the right thing, can't it? Or was there a different reason for this change?
Quoted 4 lines
Rather than repeating vif%d.%d why not reuse the result of the previous snprintf -- especially since the fmt codes differ (although probably not in a way which affects the result).
At that time I was trying to unify all output to use printk. But it turned out that we went the other way around -- several weeks ago we changed to pr_*.
This change is not necessary any more.
Quoted 4 lines
Quoted 4 lines
drivers/net/xen-netback/common.h +0
-0@@ -377,7 +389,16 @@ int xenvif_connect(struct xenvif *vif, unsigned long tx_ring_ref,disable_irq (vif->rx_irq); }
Quoted 9 lines
drivers/net/xen-netback/common.h int xenvif_connect(struct xenvif *vif, unsigned long tx_ring_ref, · line 395
Quoted 5 lines
drivers/net/xen-netback/common.h +4
-1-xenvif_get (vif); +init_waitqueue_head (&vif->wq); + vif->task =kthread_create (xenvif_kthread, + (void *)vif, +"vif%d.%d" , vif->domid, vif->handle);%u.%u, or better find a way to reuse the name allocated in
xenvif_alloc, which I suppose you can get viavif->dev->name?
Yes.
Quoted 6 lines
drivers/net/xen-netback/common.h int xenvif_connect(struct xenvif *vif, unsigned long tx_ring_ref, · line 398
Quoted 3 lines
drivers/net/xen-netback/common.h +3
-0+if (IS_ERR (vif->task)) { +printk (KERN_WARNING "xen-netback: Could not allocate kthread for vif%d.%d\n" , + vif->domid, vif->handle);
pr_warnif possible please. and %u vs %d again.
OK.
Quoted 31 lines
drivers/net/xen-netback/common.h static void netbk_gop_frag_copy(struct xenvif *vif, struct sk_buff *skb, · line 439
Quoted 8 lines
drivers/net/xen-netback/common.h +1
-1@@ -434,9 +338,9 @@ static void netbk_gop_frag_copy(struct xenvif *vif, struct sk_buff *skb, copy_gop = npo->copy + npo->copy_prod++; copy_gop->flags = GNTCOPY_dest_gref; + copy_gop->source.domid =DOMID_SELF ; copy_gop->source.u.gmfn =virt_to_mfn (page_address (page)); -The blank lines in this function seem pretty arbitrary both before and after this change ;-)
Quoted 4 lines
drivers/net/xen-netback/common.h +0
-0copy_gop->source.offset = offset; copy_gop->dest.domid = vif->domid;drivers/net/xen-netback/common.h static unsigned xen_netbk_tx_build_gops(struct xen_netbk *netbk) · line 1285
Quoted 10 lines
drivers/net/xen-netback/common.h +3
-3@@ -1469,19 +1279,20 @@ static unsigned xen_netbk_tx_build_gops(struct xen_netbk *netbk)struct xen_netif_extra_info *gso; gso = &extras[XEN_NETIF_EXTRA_TYPE_GSO -1 ]; -if (netbk_set_skb_gso (vif, skb, gso)) { -/* Failure in netbk_set_skb_gso is fatal. */ +if (xenvif_set_skb_gso (vif, skb, gso)) { +/* Failure in xenvif_set_skb_gso is fatal. */ kfree_skb (skb); -continue ; +/* XXX ???? break or continue ?*/ I'd been wondering that a bunch in the previous hunks too ;-)
break seems fine here.
Quoted 1 line
Quoted 16 lines
drivers/net/xen-netback/common.h
Quoted 12 lines
drivers/net/xen-netback/common.h +12
-0+int xenvif_kthread (void *data) +{ +struct xenvif *vif = data; + +while (!kthread_should_stop ()) { +wait_event_interruptible (vif->wq, +rx_work_todo (vif) || +kthread_should_stop ()); +cond_resched (); + +if (kthread_should_stop ()) +break ;Should this come before the cond resched? Seems odd to potentially wait a bit before just exiting.
I didn't think about this. This is just plain copy of existing code. I will swap those two hunks.
Wei.
Quoted 1 line
Ian.
Quoted 10 lines · Wei Liu
Quoted 9 lines · Ian Campbell
Quoted 8 lines · Wei Liu
This patch implements 1:1 model netback. NAPI and kthread are utilized 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)Xenvif and
xen_netbkare made into one structure to reduce code size.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
This model provides better scheduling fairness among vifs. It is also prerequisite for implementing multiqueue for Xen netback.
Any interesting numbers from this change?
[extracted from 0/2 of this series]
Oops, missed that, sorry.
Quoted 9 lines
IRQs are distributed to 4 cores by hand in the new model, while in the old model vifs are automatically distributed to 4 kthreads.
* New model
%Cpu0 : 0.5 us, 20.3 sy, 0.0 ni, 28.9 id, 0.0 wa, 0.0 hi, 24.4 si, 25.9 st %Cpu1 : 0.5 us, 17.8 sy, 0.0 ni, 28.8 id, 0.0 wa, 0.0 hi, 27.7 si, 25.1 st %Cpu2 : 0.5 us, 18.8 sy, 0.0 ni, 30.7 id, 0.0 wa, 0.0 hi, 22.9 si, 27.1 st %Cpu3 : 0.0 us, 20.1 sy, 0.0 ni, 30.4 id, 0.0 wa, 0.0 hi, 22.7 si, 26.8 st
Quoted 8 lines
Throughputs: 2027.89 2025.95 2018.57 2016.23 aggregated: 8088.64
* Old model
%Cpu0 : 0.5 us, 68.8 sy, 0.0 ni, 16.1 id, 0.5 wa, 0.0 hi, 2.8 si, 11.5 st %Cpu1 : 0.4 us, 45.1 sy, 0.0 ni, 31.1 id, 0.4 wa, 0.0 hi, 2.1 si, 20.9 st %Cpu2 : 0.9 us, 44.8 sy, 0.0 ni, 30.9 id, 0.0 wa, 0.0 hi, 1.3 si, 22.2 st %Cpu3 : 0.8 us, 46.4 sy, 0.0 ni, 28.3 id, 1.3 wa, 0.0 hi, 2.1 si, 21.1 stThroughputs: 1899.14 2280.43 1963.33 1893.47 aggregated: 8036.37
The CPU load seems to drop pretty significantly with the new model, nice. I suppose that is the impact of NAPI rather than the 1:1 side of things.
Quoted 39 lines
Quoted 16 lines
Quoted 16 lines
Signed-off-by Wei Liu <[email protected]>--- drivers/net/xen-netback/common.h | 105 +++-- drivers/net/xen-netback/interface.c | 122 +++--- drivers/net/xen-netback/netback.c | 742 ++++++++++++----------------------- 3 files changed, 389 insertions(+), 580 deletions(-)drivers/net/xen-netback/common.h +0
-0@@ -45,15 +45,43 @@#include <xen/grant_table.h> #include <xen/xenbus.h> Quoted 10 lines
drivers/net/xen-netback/common.h line 55
Quoted 9 lines
drivers/net/xen-netback/common.h +8
-1-struct xen_netbk ; +typedef unsigned int pending_ring_idx_t ; +#define INVALID_PENDING_RING_IDX (~0U) + +struct pending_tx_info { +struct xen_netif_tx_request req;/* coalesced tx request */ +pending_ring_idx_t head;/* head != INVALID_PENDING_RING_IDX +* if it is head of one or more tx +* reqs This is only code movement, no funcational change.
Quoted 3 lines
So this sounds like it is only valid for the pending tx corresponding to the first slot in a frame, right?
No. It can also be interpreted as continuation of several merged tx requests.
Quoted 3 lines
It does not contain a link from any arbitrary slot to the slot containing the head of that frame, right?
Quoted 6 lines
Quoted 3 lines
So for the head it is effectively that entries index into the
pending_txarray?No. It's a flag to tell if this
pending_tx_infois the head of one or more merged tx requests.
OK, then I'm totally confused.
I think a comment with an example of the representation of a single multislot frame (2-3 slots if that suffices as an illustration) in a comment would be useful.
Quoted 17 lines
Quoted 7 lines
Quoted 7 lines
drivers/net/xen-netback/common.h +7
-0+static int xenvif_poll (struct napi_struct *napi,int budget) +{ + struct xenvif *vif = container_of(napi, struct xenvif, napi); +int work_done; + + work_done =xenvif_tx_action (vif, budget); +Quoted 9 lines
drivers/net/xen-netback/common.h line 67
Quoted 5 lines
drivers/net/xen-netback/common.h +5
-0+if (work_done < budget) { +int more_to_do =0 ; +unsigned long flags; + +local_irq_save (flags);What does this protect against? Maybe it's a napi requirement not an Xen netif one?
Quoted 2 lines
This is sort of a NAPI requirement. If we don't do
local_irq_savewe would lose event.
How come? This is a race against this code vs. a new event coming in and calling napi_schedule? Do real drivers all disable interrupts in this way too or do they get this for free via some other means?
I think a comment is at least required.
Ian.
Quoted 39 lines · Ian Campbell
Quoted 10 lines · Wei Liu
Quoted 9 lines · Ian Campbell
Quoted 8 lines · Wei Liu
This patch implements 1:1 model netback. NAPI and kthread are utilized 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)Xenvif and
xen_netbkare made into one structure to reduce code size.Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
This model provides better scheduling fairness among vifs. It is also prerequisite for implementing multiqueue for Xen netback.
Any interesting numbers from this change?
[extracted from 0/2 of this series]
Oops, missed that, sorry.
Quoted 9 lines
IRQs are distributed to 4 cores by hand in the new model, while in the old model vifs are automatically distributed to 4 kthreads.
* New model
%Cpu0 : 0.5 us, 20.3 sy, 0.0 ni, 28.9 id, 0.0 wa, 0.0 hi, 24.4 si, 25.9 st %Cpu1 : 0.5 us, 17.8 sy, 0.0 ni, 28.8 id, 0.0 wa, 0.0 hi, 27.7 si, 25.1 st %Cpu2 : 0.5 us, 18.8 sy, 0.0 ni, 30.7 id, 0.0 wa, 0.0 hi, 22.9 si, 27.1 st %Cpu3 : 0.0 us, 20.1 sy, 0.0 ni, 30.4 id, 0.0 wa, 0.0 hi, 22.7 si, 26.8 stQuoted 8 lines
Throughputs: 2027.89 2025.95 2018.57 2016.23 aggregated: 8088.64
* Old model
%Cpu0 : 0.5 us, 68.8 sy, 0.0 ni, 16.1 id, 0.5 wa, 0.0 hi, 2.8 si, 11.5 st %Cpu1 : 0.4 us, 45.1 sy, 0.0 ni, 31.1 id, 0.4 wa, 0.0 hi, 2.1 si, 20.9 st %Cpu2 : 0.9 us, 44.8 sy, 0.0 ni, 30.9 id, 0.0 wa, 0.0 hi, 1.3 si, 22.2 st %Cpu3 : 0.8 us, 46.4 sy, 0.0 ni, 28.3 id, 1.3 wa, 0.0 hi, 2.1 si, 21.1 stThroughputs: 1899.14 2280.43 1963.33 1893.47 aggregated: 8036.37
Quoted 4 lines
The CPU load seems to drop pretty significantly with the new model, nice. I suppose that is the impact of NAPI rather than the 1:1 side of things.
Indeed.
Quoted 43 lines
Quoted 43 lines
Quoted 16 lines
Quoted 16 lines
Signed-off-by Wei Liu <[email protected]>--- drivers/net/xen-netback/common.h | 105 +++-- drivers/net/xen-netback/interface.c | 122 +++--- drivers/net/xen-netback/netback.c | 742 ++++++++++++----------------------- 3 files changed, 389 insertions(+), 580 deletions(-)drivers/net/xen-netback/common.h +0
-0@@ -45,15 +45,43 @@#include <xen/grant_table.h> #include <xen/xenbus.h> Quoted 10 lines
drivers/net/xen-netback/common.h line 55
Quoted 9 lines
drivers/net/xen-netback/common.h +8
-1-struct xen_netbk ; +typedef unsigned int pending_ring_idx_t ; +#define INVALID_PENDING_RING_IDX (~0U) + +struct pending_tx_info { +struct xen_netif_tx_request req;/* coalesced tx request */ +pending_ring_idx_t head;/* head != INVALID_PENDING_RING_IDX +* if it is head of one or more tx +* reqs This is only code movement, no funcational change.
Quoted 3 lines
So this sounds like it is only valid for the pending tx corresponding to the first slot in a frame, right?
No. It can also be interpreted as continuation of several merged tx requests.
Quoted 6 lines
It does not contain a link from any arbitrary slot to the slot containing the head of that frame, right?
So for the head it is effectively that entries index into the
pending_txarray?
Quoted 9 lines
Quoted 2 lines
No. It's a flag to tell if this
pending_tx_infois the head of one or more merged tx requests.OK, then I'm totally confused.
I think a comment with an example of the representation of a single multislot frame (2-3 slots if that suffices as an illustration) in a comment would be useful.
Ok.
Quoted 17 lines
Quoted 17 lines
Quoted 16 lines
drivers/net/xen-netback/common.h line 67
Quoted 12 lines
drivers/net/xen-netback/common.h +12
-0+static int xenvif_poll (struct napi_struct *napi,int budget) +{ + struct xenvif *vif = container_of(napi, struct xenvif, napi); +int work_done; + + work_done =xenvif_tx_action (vif, budget); + +if (work_done < budget) { +int more_to_do =0 ; +unsigned long flags; + +local_irq_save (flags);What does this protect against? Maybe it's a napi requirement not an Xen netif one?
Quoted 5 lines
Quoted 2 lines
This is sort of a NAPI requirement. If we don't do
local_irq_savewe would lose event.How come? This is a race against this code vs. a new event coming in and calling
napi_schedule?
Yes. That's the case. After we manipulate the event pointer the frontend might generate a new event. Our NAPI handler is still scheduled at that time, it won't be scheduled again.
Do real drivers all disable interrupts in this
Quoted 2 lines
way too or do they get this for free via some other means?
Real drivers often use hardware mechanism to prevent generating events.
Quoted 2 lines
I think a comment is at least required.
Sure.
Wei.
Quoted 1 line
Ian.
Quoted 34 lines · Wei Liu
This series implements NAPI + kthread 1:1 model for Xen netback.
This model
- provides better scheduling fairness among vifs
- is prerequisite for implementing multiqueue for Xen network driverThe first two patches are ground work for the third patch. First one simplifies code in netback, second one can reduce memory footprint if we switch to 1:1 model.
The third patch has the real meat:
- make use of NAPI to mitigate interrupt
- kthreads are not bound to CPUs any more, so that we can take advantage of backend scheduler and trust it to do the right thingBenchmark done on a Dell T3400 workstation with 4 cores, running 4 DomUs. Netserver running in Dom0. DomUs do netperf to Dom0 with following command:
/root/netperf-H Dom0 -fm -l120IRQs are distributed to 4 cores by hand in the new model, while in the old model vifs are automatically distributed to 4 kthreads.
* New model
%Cpu0 : 0.5 us, 20.3 sy, 0.0 ni, 28.9 id, 0.0 wa, 0.0 hi, 24.4 si, 25.9 st %Cpu1 : 0.5 us, 17.8 sy, 0.0 ni, 28.8 id, 0.0 wa, 0.0 hi, 27.7 si, 25.1 st %Cpu2 : 0.5 us, 18.8 sy, 0.0 ni, 30.7 id, 0.0 wa, 0.0 hi, 22.9 si, 27.1 st %Cpu3 : 0.0 us, 20.1 sy, 0.0 ni, 30.4 id, 0.0 wa, 0.0 hi, 22.7 si, 26.8 stThroughputs: 2027.89 2025.95 2018.57 2016.23 aggregated: 8088.64
* Old model
%Cpu0 : 0.5 us, 68.8 sy, 0.0 ni, 16.1 id, 0.5 wa, 0.0 hi, 2.8 si, 11.5 st %Cpu1 : 0.4 us, 45.1 sy, 0.0 ni, 31.1 id, 0.4 wa, 0.0 hi, 2.1 si, 20.9 st %Cpu2 : 0.9 us, 44.8 sy, 0.0 ni, 30.9 id, 0.0 wa, 0.0 hi, 1.3 si, 22.2 st %Cpu3 : 0.8 us, 46.4 sy, 0.0 ni, 28.3 id, 1.3 wa, 0.0 hi, 2.1 si, 21.1 st
Quoted 6 lines
Throughputs: 1899.14 2280.43 1963.33 1893.47 aggregated: 8036.37
We can see that the impact is mainly on CPU usage. The new model moves processing from kthread to NAPI (software interrupt).
Comments?
I like it!
Quoted 9 lines
----------------------------------------------------
Change since V2:
- Remove per-cpu scratch space.Change since V1:
- No page pool in this version. Instead page tracking facility is removed.
Quoted 8 lines
Wei Liu (2):
xen-netback: remove page tracking facility
xen-netback: switch to NAPI + kthread 1:1 modeldrivers/net/xen-netback/common.h | 105 +++-- drivers/net/xen-netback/interface.c | 122 ++++-- drivers/net/xen-netback/netback.c | 817 +++++++++++------------------------ 3 files changed, 390 insertions(+), 654 deletions(-)
:-)
Quoted 10 lines
Signature · 8 lines
-- 1.7.10.4 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel