Xen netback / netfront improvement
RFC PATCH v3 1/1 Xen netback / netfront improvement
Since this series includes both netback and netfront changes, the whole series is named as "Xen netback / netfront improvement".
Changes in V3:
- Rework of per-cpu scratch space
- Multi page ring support
- Split event channels
- Rx protocol stub
- Fix a minor bug in module_put path
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 version has been tested by
Konrad Rzeszutek Wilk <[email protected]>
V1:
A new netback implementation which includes three major features:
- Global page pool support
- NAPI + kthread 1:1 model
- Netback internal name changes
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 | 149 ++- drivers/net/xen-netback/interface.c | 256 ++++-- drivers/net/xen-netback/netback.c | 1344 +++++++------------------ drivers/net/xen-netback/page_pool.c | 185 ++++ drivers/net/xen-netback/page_pool.h | 66 ++ drivers/net/xen-netback/xenbus.c | 185 ++++- drivers/net/xen-netback/xenvif_rx_protocol0.c | 616 +++++++++++ drivers/net/xen-netback/xenvif_rx_protocol0.h | 53 + drivers/net/xen-netfront.c | 399 ++++++-- 10 files changed, 2062 insertions(+), 1193 deletions(-)
RFC PATCH v3 1/16 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 v3 2/16 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 v3 3/16 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 frontend from generating interrupt. Any tuning with ring pointers will come in as separated commit.
--- drivers/net/xen-netback/common.h | 34 ++-- drivers/net/xen-netback/interface.c | 92 ++++++--- drivers/net/xen-netback/netback.c | 367 ++++++++++------------------------- drivers/net/xen-netback/xenbus.c | 1 - 4 files changed, 186 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 +106 -261
648 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 v3 4/16 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
Re: [RFC PATCH V3 04/16] netback: switch to per-cpu scratch space.
Hi,
drivers/net/xen-netback/netback.c void xen_netbk_rx_action(struct xen_netbk *netbk) · line 530
Quoted 8 lines · Wei Liu
skb_queue_head_init(&rxq);
drivers/net/xen-netback/netback.c +1
-1@@ -534,13 +527,16 @@ void xen_netbk_rx_action(struct xen_netbk *netbk) break; } - BUG_ON(npo.meta_prod > ARRAY_SIZE(netbk->meta)); + BUG_ON(npo.meta_prod > MAX_PENDING_REQS);
While you are already here,
how about having WARN_ON() ?
drivers/net/xen-netback/netback.c void xen_netbk_rx_action(struct xen_netbk *netbk) · line 538
Quoted 11 lines
drivers/net/xen-netback/netback.c +5
-3- if (!npo.copy_prod) + if (!npo.copy_prod) { + put_cpu_ptr(gco); + put_cpu_ptr(m); return; + } - BUG_ON(npo.copy_prod > ARRAY_SIZE(netbk->grant_copy_op)); - ret = HYPERVISOR_grant_table_op(GNTTABOP_copy, &netbk->grant_copy_op, + BUG_ON(npo.copy_prod > (2 * XEN_NETIF_RX_RING_SIZE));
And may be here, too...
If there is serious bug, may be system will crash at a later point But, IMHO, WARN_ON() is the correct function for drivers at least.
Quoted 4 lines
drivers/net/xen-netback/netback.c +1
-0+ ret = HYPERVISOR_grant_table_op(GNTTABOP_copy, gco, npo.copy_prod); BUG_ON(ret != 0);
Signature · 2 lines
Thanks, Viral Mehta
Re: [RFC PATCH V3 04/16] netback: switch to per-cpu scratch space.
Quoted 23 lines · Viral Mehta
Hi,
drivers/net/xen-netback/netback.c void xen_netbk_rx_action(struct xen_netbk *netbk) · line 530
Quoted 8 lines · Wei Liu
skb_queue_head_init(&rxq);drivers/net/xen-netback/netback.c +1
-1@@ -534,13 +527,16 @@ void xen_netbk_rx_action(struct xen_netbk *netbk)break ; } -BUG_ON (npo.meta_prod >ARRAY_SIZE (netbk->meta)); +BUG_ON (npo.meta_prod >MAX_PENDING_REQS );While you are already here,
how about havingWARN_ON()?Quoted 8 lines
drivers/net/xen-netback/netback.c +4
-1-if (!npo.copy_prod) +if (!npo.copy_prod) { +put_cpu_ptr (gco); +put_cpu_ptr (m);return ; + }
Quoted 9 lines
drivers/net/xen-netback/netback.c void xen_netbk_rx_action(struct xen_netbk *netbk) · line 538
Quoted 3 lines
drivers/net/xen-netback/netback.c +1
-2-BUG_ON (npo.copy_prod >ARRAY_SIZE (netbk->grant_copy_op)); - ret = HYPERVISOR_grant_table_op(GNTTABOP_copy, &netbk->grant_copy_op, +BUG_ON (npo.copy_prod > (2 *XEN_NETIF_RX_RING_SIZE ));And may be here, too...
If there is serious bug, may be system will crash at a later point But, IMHO,
WARN_ON()is the correct function for drivers at least.
I don't agree. Here BUG_ON means code logic has defects that we haven't discovered. I won't take the risk of any undefined behavior.
Further more, there are a bunch of drivers use BUG_ON. A simple grep will show you hundreds (even thousands?) of results.
Wei.
RFC PATCH v3 5/16 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.
v2: fix module_put path
disconnect function may get called by the generic framework even before vif connects.
--- drivers/net/xen-netback/interface.c | 11 ++++++++++- 1 files changed, 10 insertions(+), 1 deletions(-)
drivers/net/xen-netback/interface.c +10 -1
@@ -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;
@@ -372,12 +374,14 @@ err_unbind: err_unmap:xen_netbk_unmap_frontend_rings (vif); err: +module_put (THIS_MODULE );return err; }void xenvif_disconnect (struct xenvif *vif) {struct net_device *dev = vif->dev; +int need_module_put =0 ;if (netif_carrier_ok (dev)) {rtnl_lock ();
@@ -397,12 +401,17 @@ void xenvif_disconnect(struct xenvif *vif)del_timer_sync (&vif->credit_timeout); -if (vif->irq) +if (vif->irq) {unbind_from_irqhandler (vif->irq, vif); + need_module_put =1 ; + }unregister_netdev (vif->dev);xen_netbk_unmap_frontend_rings (vif);free_netdev (vif->dev); + +if (need_module_put) +module_put (THIS_MODULE ); }
Signature · 1 line
1.7.2.5
Re: [RFC PATCH V3 05/16] netback: add module get/put operations along with vif connect/disconnect.
Quoted 3 lines · Wei Liu
If there is vif running and user unloads netback, it will certainly cause problems -- guest's network interface just mysteriously stops working.
This seems like a bug fix for 02/16 "netback: add module unload function". Please could you fold back such fixes where appropriate? I think there's a handful of these sorts of patches in the series.
Quoted 40 lines
v2: fix
module_putpathdisconnect function may get called by the generic framework even before vif connects.
Signed-off-by Wei Liu <[email protected]>--- drivers/net/xen-netback/interface.c | 11 ++++++++++- 1 files changed, 10 insertions(+), 1 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;@@ -372,12 +374,14 @@ err_unbind: err_unmap:xen_netbk_unmap_frontend_rings (vif); err: +module_put (THIS_MODULE );return err; }void xenvif_disconnect (struct xenvif *vif) {struct net_device *dev = vif->dev; +int need_module_put =0 ;if (netif_carrier_ok (dev)) {rtnl_lock ();
drivers/net/xen-netback/interface.c void xenvif_disconnect(struct xenvif *vif) · line 406
Quoted 7 lines
drivers/net/xen-netback/interface.c +2
-1@@ -397,12 +401,17 @@ void xenvif_disconnect(struct xenvif *vif)del_timer_sync (&vif->credit_timeout); -if (vif->irq) +if (vif->irq) {unbind_from_irqhandler (vif->irq, vif); + need_module_put =1 ;
This seems like a slightly odd condition. Why is the put not unconditional?
Quoted 11 lines
drivers/net/xen-netback/interface.c +4
-0+ }unregister_netdev (vif->dev);xen_netbk_unmap_frontend_rings (vif);free_netdev (vif->dev); + +if (need_module_put) +module_put (THIS_MODULE ); }
Re: [RFC PATCH V3 05/16] netback: add module get/put operations along with vif connect/disconnect.
Quoted 9 lines · Ian Campbell
Quoted 3 lines · Wei Liu
If there is vif running and user unloads netback, it will certainly cause problems -- guest's network interface just mysteriously stops working.
This seems like a bug fix for 02/16 "netback: add module unload function". Please could you fold back such fixes where appropriate? I think there's a handful of these sorts of patches in the series.
Sure.
Quoted 43 lines
Quoted 43 lines
v2: fix
module_putpathdisconnect function may get called by the generic framework even before vif connects.
Signed-off-by Wei Liu <[email protected]>--- drivers/net/xen-netback/interface.c | 11 ++++++++++- 1 files changed, 10 insertions(+), 1 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;@@ -372,12 +374,14 @@ err_unbind: err_unmap:xen_netbk_unmap_frontend_rings (vif); err: +module_put (THIS_MODULE );return err; }void xenvif_disconnect (struct xenvif *vif) {struct net_device *dev = vif->dev; +int need_module_put =0 ;if (netif_carrier_ok (dev)) {rtnl_lock ();@@ -397,12 +401,17 @@ void xenvif_disconnect(struct xenvif *vif)del_timer_sync (&vif->credit_timeout);
Quoted 8 lines
drivers/net/xen-netback/interface.c void xenvif_disconnect(struct xenvif *vif) · line 406
Quoted 4 lines
drivers/net/xen-netback/interface.c +2
-1-if (vif->irq) +if (vif->irq) {unbind_from_irqhandler (vif->irq, vif); + need_module_put =1 ;This seems like a slightly odd condition. Why is the put not unconditional?
This is what I observed. The framework will call disconnect unconditionally in the cleanup phase. If the frontend fails to initialize, the connect function will not get called, so there lacks a corresponding module_get().
Wei.
Quoted 14 lines
Quoted 12 lines
drivers/net/xen-netback/interface.c +4
-0+ }unregister_netdev (vif->dev);xen_netbk_unmap_frontend_rings (vif);free_netdev (vif->dev); + +if (need_module_put) +module_put (THIS_MODULE ); }
RFC PATCH v3 6/16 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 | 213 +++++++++++++---------------------- drivers/net/xen-netback/page_pool.c | 10 +- drivers/net/xen-netback/page_pool.h | 13 ++- 5 files changed, 122 insertions(+), 186 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:
@@ -394,9 +393,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 +76 -137
521 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 v3 7/16 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 | 231 ++++++++++++++++++----------------- 3 files changed, 142 insertions(+), 135 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:module_put (THIS_MODULE );return err;
@@ -404,7 +404,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 +119 -112
606 lines not on this page · raw message
Signature · 1 line
1.7.2.5
RFC PATCH v3 8/16 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
@@ -662,7 +662,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,
@@ -1047,7 +1046,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 ; }
@@ -1187,7 +1186,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
RFC PATCH v3 9/16 netback: nuke xenvif_receive_skb
In reply to Wei LiuReplace it with direct call to netif_receive_skb.
--- drivers/net/xen-netback/common.h | 2 -- drivers/net/xen-netback/interface.c | 5 ----- drivers/net/xen-netback/netback.c | 2 +- 3 files changed, 1 insertions(+), 8 deletions(-)
drivers/net/xen-netback/common.h +0 -2
@@ -152,8 +152,6 @@ int xenvif_map_frontend_rings(struct xenvif *vif,/* Check for SKBs from frontend and schedule backend processing */ 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 xenvif_queue_tx_skb (struct xenvif *vif,struct sk_buff *skb);
drivers/net/xen-netback/interface.c +0 -5
@@ -117,11 +117,6 @@ static int xenvif_start_xmit(struct sk_buff *skb, struct net_device *dev)return NETDEV_TX_OK ; } -void xenvif_receive_skb (struct xenvif *vif,struct sk_buff *skb) -{ -netif_receive_skb (skb); -} -void xenvif_notify_tx_completion (struct xenvif *vif) {if (netif_queue_stopped (vif->dev) &&xenvif_rx_schedulable (vif))
drivers/net/xen-netback/netback.c +1 -1
@@ -1270,7 +1270,7 @@ static int xenvif_tx_submit(struct xenvif *vif, work_done++; -xenvif_receive_skb (vif, skb); +netif_receive_skb (skb); }return work_done;
Signature · 1 line
1.7.2.5
RFC PATCH v3 10/16 netback: rework of per-cpu scratch space.
In reply to Wei LiuIf we allocate large arrays in per-cpu section, multi-page ring feature is likely to blow up the per-cpu section. So avoid allocating large arrays, instead we only store pointers to scratch spaces in per-cpu section.
CPU hotplug event is also taken care of.
--- drivers/net/xen-netback/netback.c | 140 +++++++++++++++++++++++++++---------- 1 files changed, 104 insertions(+), 36 deletions(-)
drivers/net/xen-netback/netback.c +104 -36
@@ -39,6 +39,7 @@#include <linux/kthread.h> #include <linux/if_vlan.h> #include <linux/udp.h> +#include <linux/cpu.h> #include <net/tcp.h>
@@ -49,15 +50,15 @@#include <asm/xen/page.h> -struct gnttab_copy *tx_copy_ops; +DEFINE_PER_CPU(struct gnttab_copy *, tx_copy_ops);/* * 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; -struct xenvif_rx_meta *meta; +DEFINE_PER_CPU(struct gnttab_copy *, grant_copy_op); +DEFINE_PER_CPU(struct xenvif_rx_meta *, meta);static void xenvif_idx_release (struct xenvif *vif,u16 pending_idx); static void make_tx_response(struct xenvif *vif,
@@ -481,8 +482,8 @@ void xenvif_rx_action(struct xenvif *vif)struct skb_cb_overlay *sco;int need_to_notify =0 ; -struct gnttab_copy *gco =get_cpu_ptr (grant_copy_op); -struct xenvif_rx_meta *m =get_cpu_ptr (meta); +struct gnttab_copy *gco =get_cpu_var (grant_copy_op); +struct xenvif_rx_meta *m =get_cpu_var (meta);struct netrx_pending_operations npo = { .copy = gco,
@@ -512,8 +513,8 @@ void xenvif_rx_action(struct xenvif *vif)BUG_ON (npo.meta_prod >MAX_PENDING_REQS );if (!npo.copy_prod) { -put_cpu_ptr (gco); -put_cpu_ptr (m); +put_cpu_var (grant_copy_op); +put_cpu_var (meta);return ; }
@@ -599,8 +600,8 @@ void xenvif_rx_action(struct xenvif *vif)if (!skb_queue_empty (&vif->rx_queue))xenvif_kick_thread (vif); -put_cpu_ptr (gco); -put_cpu_ptr (m); +put_cpu_var (grant_copy_op); +put_cpu_var (meta); }void xenvif_queue_tx_skb (struct xenvif *vif,struct sk_buff *skb)
@@ -1287,12 +1288,12 @@ int xenvif_tx_action(struct xenvif *vif, int budget)if (unlikely (!tx_work_todo (vif)))return 0 ; - tco =get_cpu_ptr (tx_copy_ops); + tco =get_cpu_var (tx_copy_ops); nr_gops =xenvif_tx_build_gops (vif, tco);if (nr_gops ==0 ) { -put_cpu_ptr (tco); +put_cpu_var (tx_copy_ops);return 0 ; }
@@ -1301,7 +1302,7 @@ int xenvif_tx_action(struct xenvif *vif, int budget) work_done =xenvif_tx_submit (vif, tco, budget); -put_cpu_ptr (tco); +put_cpu_var (tx_copy_ops);return work_done; }
@@ -1452,31 +1453,97 @@ int xenvif_kthread(void *data)return 0 ; } +static int __create_percpu_scratch_space (unsigned int cpu) +{ +per_cpu (tx_copy_ops, cpu) = +vzalloc (sizeof (struct gnttab_copy ) *MAX_PENDING_REQS ); + +per_cpu (grant_copy_op, cpu) = +vzalloc (sizeof (struct gnttab_copy ) + *2 *XEN_NETIF_RX_RING_SIZE ); + +per_cpu (meta, cpu) =vzalloc (sizeof (struct xenvif_rx_meta ) + *2 *XEN_NETIF_RX_RING_SIZE ); + +if (!per_cpu (tx_copy_ops, cpu) || + !per_cpu (grant_copy_op, cpu) || + !per_cpu (meta, cpu)) +return -ENOMEM ; + +return 0 ; +} + +static void __free_percpu_scratch_space (unsigned int cpu) +{ +/* freeing NULL pointer is legit */ +vfree (per_cpu (tx_copy_ops, cpu)); +vfree (per_cpu (grant_copy_op, cpu)); +vfree (per_cpu (meta, cpu)); +} + +static int __netback_percpu_callback (struct notifier_block *nfb, +unsigned long action,void *hcpu) +{ +unsigned int cpu = (unsigned long )hcpu; +int rc =NOTIFY_DONE ; + +switch (action) { +case CPU_ONLINE : +case CPU_ONLINE_FROZEN : +printk (KERN_INFO +"netback: CPU %x online, creating scratch space\n" , cpu); + rc =__create_percpu_scratch_space (cpu); +if (rc) { +printk (KERN_ALERT +"netback: failed to create scratch space for CPU" +" %x\n" , cpu); +/* FIXME: nothing more we can do here, we will +* print out warning message when thread or +* NAPI runs on this cpu. Also stop getting +* called in the future. +*/ +__free_percpu_scratch_space (cpu); + rc =NOTIFY_BAD ; + }else { + rc =NOTIFY_OK ; + } +break ; +case CPU_DEAD : +case CPU_DEAD_FROZEN : +printk ("netback: CPU %x offline, destroying scratch space\n" , + cpu); +__free_percpu_scratch_space (cpu); + rc =NOTIFY_OK ; +break ; +default : +break ; + } + +return rc; +} + +static struct notifier_block netback_notifier_block = { + .notifier_call = __netback_percpu_callback, +};static int __init netback_init (void ) {int rc = -ENOMEM ; +int cpu;if (!xen_domain ())return -ENODEV ; - tx_copy_ops =__alloc_percpu (sizeof (struct gnttab_copy ) - *MAX_PENDING_REQS , - __alignof__(struct gnttab_copy )); -if (!tx_copy_ops) - goto failed_init; +/* Don't need to disable preempt here, since nobody else will +* touch these percpu areas during start up. */ +for_each_online_cpu (cpu) { + rc =__create_percpu_scratch_space (cpu); - grant_copy_op =__alloc_percpu (sizeof (struct gnttab_copy ) - *2 *XEN_NETIF_RX_RING_SIZE , - __alignof__(struct gnttab_copy )); -if (!grant_copy_op) - goto failed_init_gco; +if (rc) + goto failed_init; + } - meta =__alloc_percpu (sizeof (struct xenvif_rx_meta ) - *2 *XEN_NETIF_RX_RING_SIZE , - __alignof__(struct xenvif_rx_meta )); -if (!meta) - goto failed_init_meta; +register_hotcpu_notifier (&netback_notifier_block); rc =page_pool_init ();if (rc)
@@ -1491,25 +1558,26 @@ static int __init netback_init(void) failed_init_xenbus:page_pool_destroy (); failed_init_pool: -free_percpu (meta); -failed_init_meta: -free_percpu (grant_copy_op); -failed_init_gco: -free_percpu (tx_copy_ops); +for_each_online_cpu (cpu) +__free_percpu_scratch_space (cpu); failed_init:return rc; - }module_init (netback_init); static void __exit netback_exit(void) { +int cpu; +xenvif_xenbus_exit ();page_pool_destroy (); -free_percpu (meta); -free_percpu (grant_copy_op); -free_percpu (tx_copy_ops); + +unregister_hotcpu_notifier (&netback_notifier_block); + +/* Since we're here, nobody else will touch per-cpu area. */ +for_each_online_cpu (cpu) +__free_percpu_scratch_space (cpu); }module_exit (netback_exit);
Signature · 1 line
1.7.2.5
Re: [RFC PATCH V3 10/16] netback: rework of per-cpu scratch space.
Quoted 109 lines · Wei Liu
If we allocate large arrays in per-cpu section, multi-page ring feature is likely to blow up the per-cpu section. So avoid allocating large arrays, instead we only store pointers to scratch spaces in per-cpu section.
CPU hotplug event is also taken care of.
Signed-off-by Wei Liu <[email protected]>--- drivers/net/xen-netback/netback.c | 140 +++++++++++++++++++++++++++---------- 1 files changed, 104 insertions(+), 36 deletions(-)drivers/net/xen-netback/netback.c +18
-12@@ -39,6 +39,7 @@#include <linux/kthread.h> #include <linux/if_vlan.h> #include <linux/udp.h> +#include <linux/cpu.h> #include <net/tcp.h> @@ -49,15 +50,15 @@#include <asm/xen/page.h> -struct gnttab_copy *tx_copy_ops; +DEFINE_PER_CPU(struct gnttab_copy *, tx_copy_ops);/* * 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; -struct xenvif_rx_meta *meta; +DEFINE_PER_CPU(struct gnttab_copy *, grant_copy_op); +DEFINE_PER_CPU(struct xenvif_rx_meta *, meta);static void xenvif_idx_release (struct xenvif *vif,u16 pending_idx); static void make_tx_response(struct xenvif *vif,@@ -481,8 +482,8 @@ void xenvif_rx_action(struct xenvif *vif)struct skb_cb_overlay *sco;int need_to_notify =0 ; -struct gnttab_copy *gco =get_cpu_ptr (grant_copy_op); -struct xenvif_rx_meta *m =get_cpu_ptr (meta); +struct gnttab_copy *gco =get_cpu_var (grant_copy_op); +struct xenvif_rx_meta *m =get_cpu_var (meta);struct netrx_pending_operations npo = { .copy = gco,@@ -512,8 +513,8 @@ void xenvif_rx_action(struct xenvif *vif)BUG_ON (npo.meta_prod >MAX_PENDING_REQS );if (!npo.copy_prod) { -put_cpu_ptr (gco); -put_cpu_ptr (m); +put_cpu_var (grant_copy_op); +put_cpu_var (meta);return ; }@@ -599,8 +600,8 @@ void xenvif_rx_action(struct xenvif *vif)if (!skb_queue_empty (&vif->rx_queue))xenvif_kick_thread (vif); -put_cpu_ptr (gco); -put_cpu_ptr (m); +put_cpu_var (grant_copy_op); +put_cpu_var (meta); }void xenvif_queue_tx_skb (struct xenvif *vif,struct sk_buff *skb)@@ -1287,12 +1288,12 @@ int xenvif_tx_action(struct xenvif *vif, int budget)if (unlikely (!tx_work_todo (vif)))return 0 ; - tco =get_cpu_ptr (tx_copy_ops); + tco =get_cpu_var (tx_copy_ops); nr_gops =xenvif_tx_build_gops (vif, tco);if (nr_gops ==0 ) { -put_cpu_ptr (tco); +put_cpu_var (tx_copy_ops);return 0 ; }@@ -1301,7 +1302,7 @@ int xenvif_tx_action(struct xenvif *vif, int budget) work_done =xenvif_tx_submit (vif, tco, budget); -put_cpu_ptr (tco); +put_cpu_var (tx_copy_ops);return work_done; }@@ -1452,31 +1453,97 @@ int xenvif_kthread(void *data)return 0 ; } +static int __create_percpu_scratch_space (unsigned int cpu) +{ +per_cpu (tx_copy_ops, cpu) = +vzalloc (sizeof (struct gnttab_copy ) *MAX_PENDING_REQS ); +
drivers/net/xen-netback/netback.c int xenvif_kthread(void *data) · line 1470
Quoted 10 lines
drivers/net/xen-netback/netback.c +10
-0+per_cpu (grant_copy_op, cpu) = +vzalloc (sizeof (struct gnttab_copy ) + *2 *XEN_NETIF_RX_RING_SIZE ); + +per_cpu (meta, cpu) =vzalloc (sizeof (struct xenvif_rx_meta ) + *2 *XEN_NETIF_RX_RING_SIZE ); + +if (!per_cpu (tx_copy_ops, cpu) || + !per_cpu (grant_copy_op, cpu) || + !per_cpu (meta, cpu))
Hm, shouldn't you vfree one at least them? It might be that just one of them failed.
Quoted 14 lines
drivers/net/xen-netback/netback.c +14
-0+return -ENOMEM ; + +return 0 ; +} + +static void __free_percpu_scratch_space (unsigned int cpu) +{ +/* freeing NULL pointer is legit */ +vfree (per_cpu (tx_copy_ops, cpu)); +vfree (per_cpu (grant_copy_op, cpu)); +vfree (per_cpu (meta, cpu)); +} + +static int __netback_percpu_callback(struct notifier_block *nfb,
drivers/net/xen-netback/netback.c int xenvif_kthread(void *data) · line 1494
Quoted 10 lines
drivers/net/xen-netback/netback.c +10
-0+ unsigned long action, void *hcpu) +{ +unsigned int cpu = (unsigned long )hcpu; +int rc =NOTIFY_DONE ; + +switch (action) { +case CPU_ONLINE : +case CPU_ONLINE_FROZEN : +printk (KERN_INFO +"netback: CPU %x online, creating scratch space\n" , cpu);
Is there any way to use 'pr_info(DRV_NAME' for these printk's? It might require another patch, but it would make it nicer.
Quoted 10 lines
drivers/net/xen-netback/netback.c +10
-0+ rc =__create_percpu_scratch_space (cpu); +if (rc) { +printk (KERN_ALERT +"netback: failed to create scratch space for CPU" +" %x\n" , cpu); +/* FIXME: nothing more we can do here, we will +* print out warning message when thread or +* NAPI runs on this cpu. Also stop getting +* called in the future. +*/
drivers/net/xen-netback/netback.c int xenvif_kthread(void *data) · line 1514
Quoted 10 lines
drivers/net/xen-netback/netback.c +10
-0+__free_percpu_scratch_space (cpu); + rc =NOTIFY_BAD ; + }else { + rc =NOTIFY_OK ; + } +break ; +case CPU_DEAD : +case CPU_DEAD_FROZEN : +printk ("netback: CPU %x offline, destroying scratch space\n" , + cpu);
pr_debug?
Quoted 53 lines
drivers/net/xen-netback/netback.c +22
-15+__free_percpu_scratch_space (cpu); + rc =NOTIFY_OK ; +break ; +default : +break ; + } + +return rc; +} + +static struct notifier_block netback_notifier_block = { + .notifier_call = __netback_percpu_callback, +};static int __init netback_init (void ) {int rc = -ENOMEM ; +int cpu;if (!xen_domain ())return -ENODEV ; - tx_copy_ops =__alloc_percpu (sizeof (struct gnttab_copy ) - *MAX_PENDING_REQS , - __alignof__(struct gnttab_copy )); -if (!tx_copy_ops) - goto failed_init; +/* Don't need to disable preempt here, since nobody else will +* touch these percpu areas during start up. */ +for_each_online_cpu (cpu) { + rc =__create_percpu_scratch_space (cpu); - grant_copy_op =__alloc_percpu (sizeof (struct gnttab_copy ) - *2 *XEN_NETIF_RX_RING_SIZE , - __alignof__(struct gnttab_copy )); -if (!grant_copy_op) - goto failed_init_gco; +if (rc) + goto failed_init; + } - meta =__alloc_percpu (sizeof (struct xenvif_rx_meta ) - *2 *XEN_NETIF_RX_RING_SIZE , - __alignof__(struct xenvif_rx_meta )); -if (!meta) - goto failed_init_meta; +register_hotcpu_notifier (&netback_notifier_block); rc =page_pool_init ();if (rc)@@ -1491,25 +1558,26 @@ static int __init netback_init(void) failed_init_xenbus:page_pool_destroy ();
drivers/net/xen-netback/netback.c static int __init netback_init(void) · line 1564
Quoted 10 lines
drivers/net/xen-netback/netback.c +2
-5failed_init_pool: -free_percpu (meta); -failed_init_meta: -free_percpu (grant_copy_op); -failed_init_gco: -free_percpu (tx_copy_ops); +for_each_online_cpu (cpu) +__free_percpu_scratch_space (cpu); failed_init:return rc;
We don't want to try to clean up the per_cpu_spaces that might have gotten allocated in the loop?
Quoted 25 lines
drivers/net/xen-netback/netback.c +8
-4- }module_init (netback_init); static void __exit netback_exit(void) { +int cpu; +xenvif_xenbus_exit ();page_pool_destroy (); -free_percpu (meta); -free_percpu (grant_copy_op); -free_percpu (tx_copy_ops); + +unregister_hotcpu_notifier (&netback_notifier_block); + +/* Since we're here, nobody else will touch per-cpu area. */ +for_each_online_cpu (cpu) +__free_percpu_scratch_space (cpu); }module_exit (netback_exit);Signature · 1 line
1.7.2.5
Re: [RFC PATCH V3 10/16] netback: rework of per-cpu scratch space.
Quoted 115 lines · Konrad Rzeszutek Wilk
Quoted 114 lines · Wei Liu
If we allocate large arrays in per-cpu section, multi-page ring feature is likely to blow up the per-cpu section. So avoid allocating large arrays, instead we only store pointers to scratch spaces in per-cpu section.
CPU hotplug event is also taken care of.
Signed-off-by Wei Liu <[email protected]>--- drivers/net/xen-netback/netback.c | 140 +++++++++++++++++++++++++++---------- 1 files changed, 104 insertions(+), 36 deletions(-)drivers/net/xen-netback/netback.c +23
-12@@ -39,6 +39,7 @@#include <linux/kthread.h> #include <linux/if_vlan.h> #include <linux/udp.h> +#include <linux/cpu.h> #include <net/tcp.h> @@ -49,15 +50,15 @@#include <asm/xen/page.h> -struct gnttab_copy *tx_copy_ops; +DEFINE_PER_CPU(struct gnttab_copy *, tx_copy_ops);/* * 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; -struct xenvif_rx_meta *meta; +DEFINE_PER_CPU(struct gnttab_copy *, grant_copy_op); +DEFINE_PER_CPU(struct xenvif_rx_meta *, meta);static void xenvif_idx_release (struct xenvif *vif,u16 pending_idx); static void make_tx_response(struct xenvif *vif,@@ -481,8 +482,8 @@ void xenvif_rx_action(struct xenvif *vif)struct skb_cb_overlay *sco;int need_to_notify =0 ; -struct gnttab_copy *gco =get_cpu_ptr (grant_copy_op); -struct xenvif_rx_meta *m =get_cpu_ptr (meta); +struct gnttab_copy *gco =get_cpu_var (grant_copy_op); +struct xenvif_rx_meta *m =get_cpu_var (meta);struct netrx_pending_operations npo = { .copy = gco,@@ -512,8 +513,8 @@ void xenvif_rx_action(struct xenvif *vif)BUG_ON (npo.meta_prod >MAX_PENDING_REQS );if (!npo.copy_prod) { -put_cpu_ptr (gco); -put_cpu_ptr (m); +put_cpu_var (grant_copy_op); +put_cpu_var (meta);return ; }@@ -599,8 +600,8 @@ void xenvif_rx_action(struct xenvif *vif)if (!skb_queue_empty (&vif->rx_queue))xenvif_kick_thread (vif); -put_cpu_ptr (gco); -put_cpu_ptr (m); +put_cpu_var (grant_copy_op); +put_cpu_var (meta); }void xenvif_queue_tx_skb (struct xenvif *vif,struct sk_buff *skb)@@ -1287,12 +1288,12 @@ int xenvif_tx_action(struct xenvif *vif, int budget)if (unlikely (!tx_work_todo (vif)))return 0 ; - tco =get_cpu_ptr (tx_copy_ops); + tco =get_cpu_var (tx_copy_ops); nr_gops =xenvif_tx_build_gops (vif, tco);if (nr_gops ==0 ) { -put_cpu_ptr (tco); +put_cpu_var (tx_copy_ops);return 0 ; }@@ -1301,7 +1302,7 @@ int xenvif_tx_action(struct xenvif *vif, int budget) work_done =xenvif_tx_submit (vif, tco, budget); -put_cpu_ptr (tco); +put_cpu_var (tx_copy_ops);return work_done; }@@ -1452,31 +1453,97 @@ int xenvif_kthread(void *data)return 0 ; } +static int __create_percpu_scratch_space (unsigned int cpu) +{ +per_cpu (tx_copy_ops, cpu) = +vzalloc (sizeof (struct gnttab_copy ) *MAX_PENDING_REQS ); + +per_cpu (grant_copy_op, cpu) = +vzalloc (sizeof (struct gnttab_copy ) + *2 *XEN_NETIF_RX_RING_SIZE ); + + per_cpu(meta, cpu) = vzalloc(sizeof(struct xenvif_rx_meta)
Quoted 9 lines
drivers/net/xen-netback/netback.c int xenvif_kthread(void *data) · line 1470
Quoted 5 lines
drivers/net/xen-netback/netback.c +5
-0+ * 2 * XEN_NETIF_RX_RING_SIZE); + +if (!per_cpu (tx_copy_ops, cpu) || + !per_cpu (grant_copy_op, cpu) || + !per_cpu (meta, cpu))Hm, shouldn't you vfree one at least them? It might be that just one of them failed.
The caller will clean up.
Quoted 19 lines
Quoted 19 lines
drivers/net/xen-netback/netback.c +19
-0+return -ENOMEM ; + +return 0 ; +} + +static void __free_percpu_scratch_space (unsigned int cpu) +{ +/* freeing NULL pointer is legit */ +vfree (per_cpu (tx_copy_ops, cpu)); +vfree (per_cpu (grant_copy_op, cpu)); +vfree (per_cpu (meta, cpu)); +} + +static int __netback_percpu_callback (struct notifier_block *nfb, +unsigned long action,void *hcpu) +{ +unsigned int cpu = (unsigned long )hcpu; +int rc =NOTIFY_DONE ; +
Quoted 9 lines
drivers/net/xen-netback/netback.c int xenvif_kthread(void *data) · line 1494
Quoted 5 lines
drivers/net/xen-netback/netback.c +5
-0+switch (action) { +case CPU_ONLINE : +case CPU_ONLINE_FROZEN : +printk (KERN_INFO +"netback: CPU %x online, creating scratch space\n" , cpu);Is there any way to use 'pr_info(DRV_NAME' for these printk's? It might require another patch, but it would make it nicer.
Hmm... will look into that.
Quoted 81 lines
Quoted 10 lines
drivers/net/xen-netback/netback.c +10
-0+ rc =__create_percpu_scratch_space (cpu); +if (rc) { +printk (KERN_ALERT +"netback: failed to create scratch space for CPU" +" %x\n" , cpu); +/* FIXME: nothing more we can do here, we will +* print out warning message when thread or +* NAPI runs on this cpu. Also stop getting +* called in the future. +*/ drivers/net/xen-netback/netback.c int xenvif_kthread(void *data) · line 1514
Quoted 10 lines
drivers/net/xen-netback/netback.c +10
-0+__free_percpu_scratch_space (cpu); + rc =NOTIFY_BAD ; + }else { + rc =NOTIFY_OK ; + } +break ; +case CPU_DEAD : +case CPU_DEAD_FROZEN : +printk ("netback: CPU %x offline, destroying scratch space\n" , + cpu);
pr_debug?Quoted 58 lines
drivers/net/xen-netback/netback.c +22
-19+__free_percpu_scratch_space (cpu); + rc =NOTIFY_OK ; +break ; +default : +break ; + } + +return rc; +} + +static struct notifier_block netback_notifier_block = { + .notifier_call = __netback_percpu_callback, +};static int __init netback_init (void ) {int rc = -ENOMEM ; +int cpu;if (!xen_domain ())return -ENODEV ; - tx_copy_ops =__alloc_percpu (sizeof (struct gnttab_copy ) - *MAX_PENDING_REQS , - __alignof__(struct gnttab_copy )); -if (!tx_copy_ops) - goto failed_init; +/* Don't need to disable preempt here, since nobody else will +* touch these percpu areas during start up. */ +for_each_online_cpu (cpu) { + rc =__create_percpu_scratch_space (cpu); - grant_copy_op =__alloc_percpu (sizeof (struct gnttab_copy ) - *2 *XEN_NETIF_RX_RING_SIZE , - __alignof__(struct gnttab_copy )); -if (!grant_copy_op) - goto failed_init_gco; +if (rc) + goto failed_init; + } - meta =__alloc_percpu (sizeof (struct xenvif_rx_meta ) - *2 *XEN_NETIF_RX_RING_SIZE , - __alignof__(struct xenvif_rx_meta )); -if (!meta) - goto failed_init_meta; +register_hotcpu_notifier (&netback_notifier_block); rc =page_pool_init ();if (rc)@@ -1491,25 +1558,26 @@ static int __init netback_init(void) failed_init_xenbus:page_pool_destroy (); failed_init_pool: -free_percpu (meta); -failed_init_meta: -free_percpu (grant_copy_op); -failed_init_gco:
Quoted 9 lines
drivers/net/xen-netback/netback.c static int __init netback_init(void) · line 1564
Quoted 5 lines
drivers/net/xen-netback/netback.c +2
-1-free_percpu (tx_copy_ops); +for_each_online_cpu (cpu) +__free_percpu_scratch_space (cpu); failed_init:return rc;We don't want to try to clean up the
per_cpu_spacesthat might have gotten allocated in the loop?
Good catch, thanks.
Wei.
Quoted 25 lines
Quoted 25 lines
drivers/net/xen-netback/netback.c +8
-4- }module_init (netback_init); static void __exit netback_exit(void) { +int cpu; +xenvif_xenbus_exit ();page_pool_destroy (); -free_percpu (meta); -free_percpu (grant_copy_op); -free_percpu (tx_copy_ops); + +unregister_hotcpu_notifier (&netback_notifier_block); + +/* Since we're here, nobody else will touch per-cpu area. */ +for_each_online_cpu (cpu) +__free_percpu_scratch_space (cpu); }module_exit (netback_exit);Signature · 1 line
1.7.2.5
Re: [RFC PATCH V3 10/16] netback: rework of per-cpu scratch space.
In reply to Wei LiuQuoted 20 lines · Wei Liu
If we allocate large arrays in per-cpu section, multi-page ring feature is likely to blow up the per-cpu section. So avoid allocating large arrays, instead we only store pointers to scratch spaces in per-cpu section.
CPU hotplug event is also taken care of.
}
drivers/net/xen-netback/netback.c +10
-0+static int __create_percpu_scratch_space (unsigned int cpu) +{ + per_cpu(tx_copy_ops, cpu) = + vzalloc(sizeof(struct gnttab_copy) * MAX_PENDING_REQS); + + per_cpu(grant_copy_op, cpu) = + vzalloc(sizeof(struct gnttab_copy) + * 2 * XEN_NETIF_RX_RING_SIZE); + + per_cpu(meta, cpu) = vzalloc(sizeof(struct xenvif_rx_meta)
drivers/net/xen-netback/netback.c int xenvif_kthread(void *data) · line 1475
Quoted 10 lines
drivers/net/xen-netback/netback.c +10
-0+ * 2 * XEN_NETIF_RX_RING_SIZE); + + if (!per_cpu(tx_copy_ops, cpu) || + !per_cpu(grant_copy_op, cpu) || + !per_cpu(meta, cpu)) + return -ENOMEM; + + return 0; +} +
Problem is you lost NUMA awareness here.
Please check vzalloc_node()
Re: [RFC PATCH V3 10/16] netback: rework of per-cpu scratch space.
Quoted 4 lines · Eric Dumazet
Problem is you lost NUMA awareness here.
Please check
vzalloc_node()
Good point, thanks.
Wei.
RFC PATCH v3 11/16 netback: print alert and bail when scratch space is not available.
In reply to Wei LiuCPU online event causes our callback to allocate scratch space for this CPU, which may fail. The simplest and best action when NAPI or kthread is scheduled on that CPU is to bail.
--- drivers/net/xen-netback/interface.c | 5 ++++- drivers/net/xen-netback/netback.c | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletions(-)
drivers/net/xen-netback/interface.c +4 -1
@@ -69,6 +69,9 @@ static int xenvif_poll(struct napi_struct *napi, int budget) struct xenvif *vif = container_of(napi, struct xenvif, napi);int work_done =0 ; +/* N.B.: work_done may be -ENOMEM, indicating scratch space on +* this CPU is not usable. In this situation, we shutdown +* NAPI. See __napi_complete check below.*/ work_done =xenvif_tx_action (vif, budget);if (work_done < budget) {
@@ -78,7 +81,7 @@ static int xenvif_poll(struct napi_struct *napi, int budget)local_irq_save (flag);RING_FINAL_CHECK_FOR_REQUESTS (&vif->tx, more_to_do); -if (!more_to_do) +if (!more_to_do || work_done <0 )__napi_complete (napi);local_irq_restore (flag);
drivers/net/xen-netback/netback.c +17 -0
@@ -490,6 +490,15 @@ void xenvif_rx_action(struct xenvif *vif) .meta = m, }; +if (gco ==NULL || m ==NULL ) { +put_cpu_var (grant_copy_op); +put_cpu_var (meta); +printk (KERN_ALERT "netback: CPU %x scratch space is not usable," +" not doing any TX work for vif%u.%u\n" , +smp_processor_id (), vif->domid, vif->handle); +return ; + } +skb_queue_head_init (&rxq); count =0 ;
@@ -1290,6 +1299,14 @@ int xenvif_tx_action(struct xenvif *vif, int budget) tco =get_cpu_var (tx_copy_ops); +if (tco ==NULL ) { +put_cpu_var (tx_copy_ops); +printk (KERN_ALERT "netback: CPU %x scratch space is not usable," +" not doing any RX work for vif%u.%u\n" , +smp_processor_id (), vif->domid, vif->handle); +return -ENOMEM ; + } + nr_gops =xenvif_tx_build_gops (vif, tco);if (nr_gops ==0 ) {
Signature · 1 line
1.7.2.5
RFC PATCH v3 12/16 netback: multi-page ring support
In reply to Wei LiuExtend netback to support multi-page ring.
--- drivers/net/xen-netback/common.h | 44 ++++++++++--- drivers/net/xen-netback/interface.c | 33 +++++++-- drivers/net/xen-netback/netback.c | 116 +++++++++++++++++++++---------- drivers/net/xen-netback/xenbus.c | 129 +++++++++++++++++++++++++++++++++-- 4 files changed, 262 insertions(+), 60 deletions(-)
drivers/net/xen-netback/common.h +35 -9
@@ -58,16 +58,36 @@ struct xenvif_rx_meta {#define MAX_BUFFER_OFFSET PAGE_SIZE -#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) +#define NETBK_TX_RING_SIZE (_nr_pages) \ + (__CONST_RING_SIZE(xen_netif_tx, PAGE_SIZE * (_nr_pages))) +#define NETBK_RX_RING_SIZE (_nr_pages) \ + (__CONST_RING_SIZE(xen_netif_rx, PAGE_SIZE * (_nr_pages))) -#define MAX_PENDING_REQS 256 +#define NETBK_MAX_RING_PAGE_ORDER 2 +#define NETBK_MAX_RING_PAGES (1U << NETBK_MAX_RING_PAGE_ORDER) + +#define NETBK_MAX_TX_RING_SIZE NETBK_TX_RING_SIZE(NETBK_MAX_RING_PAGES) +#define NETBK_MAX_RX_RING_SIZE NETBK_RX_RING_SIZE(NETBK_MAX_RING_PAGES) + +#define INVALID_GRANT_HANDLE ((grant_handle_t)~0U) + +#define MAX_PENDING_REQS NETBK_MAX_TX_RING_SIZE + +struct xen_comms { +struct vm_struct *ring_area; +grant_handle_t shmem_handle[NETBK_MAX_RING_PAGES ]; +unsigned int nr_handles; +};struct xenvif {/* Unique identifier for this interface. */ domid_t domid;unsigned int handle; +/* Multi-page ring support */ +struct xen_comms tx_comms; +struct xen_comms rx_comms; +/* Use NAPI for guest TX */ struct napi_struct napi;/* Use kthread for guest RX */
@@ -131,8 +151,10 @@ struct xenvif *xenvif_alloc(struct device *parent,domid_t domid, unsigned int handle); -int xenvif_connect (struct xenvif *vif,unsigned long tx_ring_ref, -unsigned long rx_ring_ref,unsigned int evtchn); +int xenvif_connect (struct xenvif *vif, +unsigned long tx_ring_ref[],unsigned int tx_ring_order, +unsigned long rx_ring_ref[],unsigned int rx_ring_order, +unsigned int evtchn);void xenvif_disconnect (struct xenvif *vif);int xenvif_xenbus_init (void );
@@ -145,10 +167,11 @@ int xenvif_rx_ring_full(struct xenvif *vif);int xenvif_must_stop_queue (struct xenvif *vif);/* (Un)Map communication rings. */ -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); +void xenvif_unmap_frontend_rings (struct xen_comms *comms); +int xenvif_map_frontend_rings (struct xen_comms *comms, +int domid, +unsigned long ring_ref[], +unsigned int ring_ref_count);/* Check for SKBs from frontend and schedule backend processing */ void xenvif_check_rx_xenvif (struct xenvif *vif);
@@ -166,4 +189,7 @@ void xenvif_rx_action(struct xenvif *vif);int xenvif_kthread (void *data); +extern unsigned int MODPARM_netback_max_tx_ring_page_order; +extern unsigned int MODPARM_netback_max_rx_ring_page_order; +#endif /* __XEN_NETBACK__COMMON_H__ */
drivers/net/xen-netback/interface.c +25 -8
@@ -322,10 +322,14 @@ struct xenvif *xenvif_alloc(struct device *parent, domid_t domid,return vif; } -int xenvif_connect (struct xenvif *vif,unsigned long tx_ring_ref, -unsigned long rx_ring_ref,unsigned int evtchn) +int xenvif_connect (struct xenvif *vif, +unsigned long tx_ring_ref[],unsigned int tx_ring_ref_count, +unsigned long rx_ring_ref[],unsigned int rx_ring_ref_count, +unsigned int evtchn) {int err = -ENOMEM ; +struct xen_netif_tx_sring *txs; +struct xen_netif_rx_sring *rxs;/* Already connected through? */ if (vif->irq)
@@ -333,15 +337,25 @@ int xenvif_connect(struct xenvif *vif, unsigned long tx_ring_ref,__module_get (THIS_MODULE ); - err =xenvif_map_frontend_rings (vif, tx_ring_ref, rx_ring_ref); -if (err <0 ) + err =xenvif_map_frontend_rings (&vif->tx_comms, vif->domid, + tx_ring_ref, tx_ring_ref_count); +if (err) goto err; + txs = (struct xen_netif_tx_sring *)vif->tx_comms.ring_area->addr; +BACK_RING_INIT (&vif->tx, txs,PAGE_SIZE * tx_ring_ref_count); + + err =xenvif_map_frontend_rings (&vif->rx_comms, vif->domid, + rx_ring_ref, rx_ring_ref_count); +if (err) + goto err_tx_unmap; + rxs = (struct xen_netif_rx_sring *)vif->rx_comms.ring_area->addr; +BACK_RING_INIT (&vif->rx, rxs,PAGE_SIZE * rx_ring_ref_count); err =bind_interdomain_evtchn_to_irqhandler ( vif->domid, evtchn, xenvif_interrupt,0 , vif->dev->name, vif);if (err <0 ) - goto err_unmap; + goto err_rx_unmap; vif->irq = err;disable_irq (vif->irq);
@@ -369,8 +383,10 @@ int xenvif_connect(struct xenvif *vif, unsigned long tx_ring_ref,return 0 ; err_unbind:unbind_from_irqhandler (vif->irq, vif); -err_unmap: -xenvif_unmap_frontend_rings (vif); +err_rx_unmap: +xenvif_unmap_frontend_rings (&vif->rx_comms); +err_tx_unmap: +xenvif_unmap_frontend_rings (&vif->tx_comms); err:module_put (THIS_MODULE );return err;
@@ -403,7 +419,8 @@ void xenvif_disconnect(struct xenvif *vif)unregister_netdev (vif->dev); -xenvif_unmap_frontend_rings (vif); +xenvif_unmap_frontend_rings (&vif->tx_comms); +xenvif_unmap_frontend_rings (&vif->rx_comms);free_netdev (vif->dev);
drivers/net/xen-netback/netback.c +80 -36
173 lines not on this page · raw message
drivers/net/xen-netback/xenbus.c +122 -7
161 lines not on this page · raw message
Signature · 1 line
1.7.2.5
Re: [Xen-devel] [RFC PATCH V3 12/16] netback: multi-page ring support
Quoted 10 lines
Quoted 1 line
Quoted 1 line · Wei Liu
drivers/net/xen-netback/netback.c +4
-4-int xenvif_map_frontend_rings (struct xenvif *vif, -grant_ref_t tx_ring_ref, -grant_ref_t rx_ring_ref) +int xenvif_map_frontend_rings (struct xen_comms *comms, +int domid, +unsigned long ring_ref[], +unsigned int ring_ref_count) { -void *addr;
drivers/net/xen-netback/netback.c static inline int tx_work_todo(struct xenvif *vif) · line 1429
Quoted 10 lines
drivers/net/xen-netback/netback.c +3
-6-struct xen_netif_tx_sring *txs; -struct xen_netif_rx_sring *rxs; - -int err = -ENOMEM ; +struct gnttab_map_grant_ref op[NETBK_MAX_RING_PAGES ]; +unsigned int i; +int err =0 ; - err =xenbus_map_ring_valloc (xenvif_to_xenbus_device (vif), - tx_ring_ref, &addr);
Any reason why you don't just extend this function (in a prerequisite patch) rather than open coding a common utility function (twice) here, so that other backends (blkback!) can benefit later as well.
Jan
Quoted 46 lines
drivers/net/xen-netback/netback.c +23
-14-if (err) - goto err; + comms->ring_area =alloc_vm_area (PAGE_SIZE * ring_ref_count,NULL ); +if (comms->ring_area ==NULL ) +return -ENOMEM ; - txs = (struct xen_netif_tx_sring *)addr; -BACK_RING_INIT (&vif->tx, txs,PAGE_SIZE ); +for (i =0 ; i < ring_ref_count; i++) { +unsigned long addr = (unsigned long )comms->ring_area->addr + + (i *PAGE_SIZE ); +gnttab_set_map_op (&op[i], addr, GNTMAP_host_map, + ring_ref[i], domid); + } - err =xenbus_map_ring_valloc (xenvif_to_xenbus_device (vif), - rx_ring_ref, &addr); -if (err) - goto err; +if (HYPERVISOR_grant_table_op (GNTTABOP_map_grant_ref, + &op, ring_ref_count)) +BUG (); - rxs = (struct xen_netif_rx_sring *)addr; -BACK_RING_INIT (&vif->rx, rxs,PAGE_SIZE ); + comms->nr_handles = ring_ref_count; - vif->rx_req_cons_peek =0 ; +for (i =0 ; i < ring_ref_count; i++) { +if (op[i].status !=0 ) { + err = op[i].status; + comms->shmem_handle[i] =INVALID_GRANT_HANDLE ; +continue ; + } + comms->shmem_handle[i] = op[i].handle; + } -return 0 ; +if (err !=0 ) +xenvif_unmap_frontend_rings (comms); -err: -xenvif_unmap_frontend_rings (vif);return err; }
Re: [Xen-devel] [RFC PATCH V3 12/16] netback: multi-page ring support
Quoted 18 lines · Jan Beulich
Quoted 18 lines
Quoted 1 line
Quoted 1 line · Wei Liu
drivers/net/xen-netback/netback.c +7
-8-int xenvif_map_frontend_rings (struct xenvif *vif, -grant_ref_t tx_ring_ref, -grant_ref_t rx_ring_ref) +int xenvif_map_frontend_rings (struct xen_comms *comms, +int domid, +unsigned long ring_ref[], +unsigned int ring_ref_count) { -void *addr; -struct xen_netif_tx_sring *txs; -struct xen_netif_rx_sring *rxs; - -int err = -ENOMEM ; +struct gnttab_map_grant_ref op[NETBK_MAX_RING_PAGES ]; +unsigned int i; +int err =0 ;
Quoted 9 lines
drivers/net/xen-netback/netback.c static inline int tx_work_todo(struct xenvif *vif) · line 1429
Quoted 2 lines
drivers/net/xen-netback/netback.c +0
-2- err =xenbus_map_ring_valloc (xenvif_to_xenbus_device (vif), - tx_ring_ref, &addr);Any reason why you don't just extend this function (in a prerequisite patch) rather than open coding a common utility function (twice) here, so that other backends (blkback!) can benefit later as well.
Jan
I'm mainly focusing on netback stuffs, so the code is slightly coupled with netback -- NETBK_MAX_RING_PAGES.
To extend xenbus_map_ring_valloc and make more generic, it requires setting a global maximum page number limits on rings, I think it will require further investigation and code refactor -- which I have no time to attend to at the moment. :-/
Wei.
Re: [Xen-devel] [RFC PATCH V3 12/16] netback: multi-page ring support
Quoted 30 lines
Quoted 1 line
Quoted 1 line · Wei Liu
Quoted 18 lines · Jan Beulich
Quoted 18 lines
Quoted 1 line
Quoted 1 line · Wei Liu
drivers/net/xen-netback/netback.c +7
-8-int xenvif_map_frontend_rings (struct xenvif *vif, -grant_ref_t tx_ring_ref, -grant_ref_t rx_ring_ref) +int xenvif_map_frontend_rings (struct xen_comms *comms, +int domid, +unsigned long ring_ref[], +unsigned int ring_ref_count) { -void *addr; -struct xen_netif_tx_sring *txs; -struct xen_netif_rx_sring *rxs; - -int err = -ENOMEM ; +struct gnttab_map_grant_ref op[NETBK_MAX_RING_PAGES ]; +unsigned int i; +int err =0 ;Quoted 9 lines
drivers/net/xen-netback/netback.c static inline int tx_work_todo(struct xenvif *vif) · line 1429
Quoted 2 lines
drivers/net/xen-netback/netback.c +0
-2- err =xenbus_map_ring_valloc (xenvif_to_xenbus_device (vif), - tx_ring_ref, &addr);Any reason why you don't just extend this function (in a prerequisite patch) rather than open coding a common utility function (twice) here, so that other backends (blkback!) can benefit later as well.
Jan
Quoted 7 lines
I'm mainly focusing on netback stuffs, so the code is slightly coupled with netback --
NETBK_MAX_RING_PAGES.To extend
xenbus_map_ring_vallocand make more generic, it requires setting a global maximum page number limits on rings, I think it will require further investigation and code refactor -- which I have no time to attend to at the moment. :-/
Why? You can simply pass in the number of pages, there's no need for a global maximum.
Jan
Re: [Xen-devel] [RFC PATCH V3 12/16] netback: multi-page ring support
Quoted 33 lines · Jan Beulich
Quoted 33 lines
Quoted 1 line
Quoted 1 line · Wei Liu
Quoted 18 lines · Jan Beulich
Quoted 18 lines
Quoted 1 line
Quoted 1 line · Wei Liu
drivers/net/xen-netback/netback.c +7
-8-int xenvif_map_frontend_rings (struct xenvif *vif, -grant_ref_t tx_ring_ref, -grant_ref_t rx_ring_ref) +int xenvif_map_frontend_rings (struct xen_comms *comms, +int domid, +unsigned long ring_ref[], +unsigned int ring_ref_count) { -void *addr; -struct xen_netif_tx_sring *txs; -struct xen_netif_rx_sring *rxs; - -int err = -ENOMEM ; +struct gnttab_map_grant_ref op[NETBK_MAX_RING_PAGES ]; +unsigned int i; +int err =0 ;Quoted 9 lines
drivers/net/xen-netback/netback.c static inline int tx_work_todo(struct xenvif *vif) · line 1429
Quoted 2 lines
drivers/net/xen-netback/netback.c +0
-2- err =xenbus_map_ring_valloc (xenvif_to_xenbus_device (vif), - tx_ring_ref, &addr);Any reason why you don't just extend this function (in a prerequisite patch) rather than open coding a common utility function (twice) here, so that other backends (blkback!) can benefit later as well.
Jan
I'm mainly focusing on netback stuffs, so the code is slightly coupled with netback --
NETBK_MAX_RING_PAGES.
Quoted 8 lines
Quoted 4 lines
To extend
xenbus_map_ring_vallocand make more generic, it requires setting a global maximum page number limits on rings, I think it will require further investigation and code refactor -- which I have no time to attend to at the moment. :-/Why? You can simply pass in the number of pages, there's no need for a global maximum.
I mean the gnttab_map_gran_ref array, it is statically allocated at the moment. Of course we can make it dynamically allocated, but why bother taking the risk of allocation failure.
Wei.
Quoted 2 lines
Jan
Re: [Xen-devel] [RFC PATCH V3 12/16] netback: multi-page ring support
Quoted 39 lines · Wei Liu (Intern)
Quoted 38 lines · Jan Beulich
Quoted 37 lines
Quoted 1 line
Quoted 1 line · Wei Liu
Quoted 18 lines · Jan Beulich
Quoted 18 lines
Quoted 1 line
Quoted 1 line · Wei Liu
drivers/net/xen-netback/netback.c +7
-8-int xenvif_map_frontend_rings (struct xenvif *vif, -grant_ref_t tx_ring_ref, -grant_ref_t rx_ring_ref) +int xenvif_map_frontend_rings (struct xen_comms *comms, +int domid, +unsigned long ring_ref[], +unsigned int ring_ref_count) { -void *addr; -struct xen_netif_tx_sring *txs; -struct xen_netif_rx_sring *rxs; - -int err = -ENOMEM ; +struct gnttab_map_grant_ref op[NETBK_MAX_RING_PAGES ]; +unsigned int i; +int err =0 ;Quoted 9 lines
drivers/net/xen-netback/netback.c static inline int tx_work_todo(struct xenvif *vif) · line 1429
Quoted 2 lines
drivers/net/xen-netback/netback.c +0
-2- err =xenbus_map_ring_valloc (xenvif_to_xenbus_device (vif), - tx_ring_ref, &addr);Any reason why you don't just extend this function (in a prerequisite patch) rather than open coding a common utility function (twice) here, so that other backends (blkback!) can benefit later as well.
Jan
I'm mainly focusing on netback stuffs, so the code is slightly coupled with netback --
NETBK_MAX_RING_PAGES.To extend
xenbus_map_ring_vallocand make more generic, it requires setting a global maximum page number limits on rings, I think it will require further investigation and code refactor -- which I have no time to attend to at the moment. :-/
Quoted 7 lines
Quoted 3 lines
Why? You can simply pass in the number of pages, there's no need for a global maximum.
I mean the
gnttab_map_gran_refarray, it is statically allocated at the moment. Of course we can make it dynamically allocated, but why bother taking the risk of allocation failure.
You can do
struct gnttab_map_grant_ref op[nr_pages];
and the compiler will do the right thing with the on-stack data structure. In the kernel you'd need to be a bit careful about the size of pages first but that should be all.
Ian.
Re: [Xen-devel] [RFC PATCH V3 12/16] netback: multi-page ring support
In reply to Wei LiuQuoted 40 lines
Quoted 1 line
Quoted 1 line · Wei Liu
Quoted 38 lines · Jan Beulich
Quoted 37 lines
Quoted 1 line
Quoted 1 line · Wei Liu
Quoted 18 lines · Jan Beulich
Quoted 18 lines
Quoted 1 line
Quoted 1 line · Wei Liu
drivers/net/xen-netback/netback.c +7
-8-int xenvif_map_frontend_rings (struct xenvif *vif, -grant_ref_t tx_ring_ref, -grant_ref_t rx_ring_ref) +int xenvif_map_frontend_rings (struct xen_comms *comms, +int domid, +unsigned long ring_ref[], +unsigned int ring_ref_count) { -void *addr; -struct xen_netif_tx_sring *txs; -struct xen_netif_rx_sring *rxs; - -int err = -ENOMEM ; +struct gnttab_map_grant_ref op[NETBK_MAX_RING_PAGES ]; +unsigned int i; +int err =0 ;Quoted 9 lines
drivers/net/xen-netback/netback.c static inline int tx_work_todo(struct xenvif *vif) · line 1429
Quoted 2 lines
drivers/net/xen-netback/netback.c +0
-2- err =xenbus_map_ring_valloc (xenvif_to_xenbus_device (vif), - tx_ring_ref, &addr);Any reason why you don't just extend this function (in a prerequisite patch) rather than open coding a common utility function (twice) here, so that other backends (blkback!) can benefit later as well.
Jan
I'm mainly focusing on netback stuffs, so the code is slightly coupled with netback --
NETBK_MAX_RING_PAGES.To extend
xenbus_map_ring_vallocand make more generic, it requires setting a global maximum page number limits on rings, I think it will require further investigation and code refactor -- which I have no time to attend to at the moment. :-/
Quoted 7 lines
Quoted 3 lines
Why? You can simply pass in the number of pages, there's no need for a global maximum.
I mean the
gnttab_map_gran_refarray, it is statically allocated at the moment. Of course we can make it dynamically allocated, but why bother taking the risk of allocation failure.
There's so many other allocations, why would you worry about this one.
But of course you can undo what a recent change did, and then subsequently someone else will have to clean up again after you. I'm just asking to follow good programming practices and write re-usable code where potential for re-use is obvious (after all, multi-page block interface patches have been floating around for much longer than yours for the net interface).
Jan
Re: [Xen-devel] [RFC PATCH V3 12/16] netback: multi-page ring support
Quoted 44 lines · Jan Beulich
Quoted 44 lines
Quoted 1 line
Quoted 1 line · Wei Liu
Quoted 41 lines · Jan Beulich
Quoted 30 lines
Quoted 1 line
Quoted 1 line · Wei Liu
Quoted 18 lines · Jan Beulich
Quoted 18 lines
Quoted 1 line
Quoted 1 line · Wei Liu
drivers/net/xen-netback/netback.c +7
-8-int xenvif_map_frontend_rings (struct xenvif *vif, -grant_ref_t tx_ring_ref, -grant_ref_t rx_ring_ref) +int xenvif_map_frontend_rings (struct xen_comms *comms, +int domid, +unsigned long ring_ref[], +unsigned int ring_ref_count) { -void *addr; -struct xen_netif_tx_sring *txs; -struct xen_netif_rx_sring *rxs; - -int err = -ENOMEM ; +struct gnttab_map_grant_ref op[NETBK_MAX_RING_PAGES ]; +unsigned int i; +int err =0 ;Quoted 9 lines
drivers/net/xen-netback/netback.c static inline int tx_work_todo(struct xenvif *vif) · line 1429
Quoted 2 lines
drivers/net/xen-netback/netback.c +0
-2- err =xenbus_map_ring_valloc (xenvif_to_xenbus_device (vif), - tx_ring_ref, &addr);Any reason why you don't just extend this function (in a prerequisite patch) rather than open coding a common utility function (twice) here, so that other backends (blkback!) can benefit later as well.
Jan
Quoted 7 lines
I'm mainly focusing on netback stuffs, so the code is slightly coupled with netback --
NETBK_MAX_RING_PAGES.To extend
xenbus_map_ring_vallocand make more generic, it requires setting a global maximum page number limits on rings, I think it will require further investigation and code refactor -- which I have no time to attend to at the moment. :-/Why? You can simply pass in the number of pages, there's no need for a global maximum.
Quoted 7 lines
Quoted 3 lines
I mean the
gnttab_map_gran_refarray, it is statically allocated at the moment. Of course we can make it dynamically allocated, but why bother taking the risk of allocation failure.There's so many other allocations, why would you worry about this one.
IMHO, this is not a critical part of the code, so failing this one thus making all other pieces not workable is very strange.
Quoted 7 lines
But of course you can undo what a recent change did, and then subsequently someone else will have to clean up again after you. I'm just asking to follow good programming practices and write re-usable code where potential for re-use is obvious (after all, multi-page block interface patches have been floating around for much longer than yours for the net interface).
I understand your concern. If the changes required will not make this series longer and involves major changes in block interface, I'm happy to refactor the xenbus interface.
Wei.
Quoted 2 lines
Jan
Re: [Xen-devel] [RFC PATCH V3 12/16] netback: multi-page ring support
Quoted 64 lines · Wei Liu
Quoted 44 lines · Jan Beulich
Quoted 44 lines
Quoted 1 line
Quoted 1 line · Wei Liu
Quoted 41 lines · Jan Beulich
Quoted 30 lines
Quoted 1 line
Quoted 1 line · Wei Liu
Quoted 18 lines · Jan Beulich
Quoted 18 lines
Quoted 1 line
Quoted 1 line · Wei Liu
(quoted diff) +7
-8-int xenvif_map_frontend_rings(struct xenvif *vif, - grant_ref_t tx_ring_ref, - grant_ref_t rx_ring_ref) +int xenvif_map_frontend_rings(struct xen_comms *comms, + int domid, + unsigned long ring_ref[], + unsigned int ring_ref_count) { - void *addr; - struct xen_netif_tx_sring *txs; - struct xen_netif_rx_sring *rxs; - - int err = -ENOMEM; + struct gnttab_map_grant_ref op[NETBK_MAX_RING_PAGES]; + unsigned int i; + int err = 0;Quoted 9 lines
Review
Quoted 2 lines
(quoted diff) +0
-2- err = xenbus_map_ring_valloc(xenvif_to_xenbus_device(vif), - tx_ring_ref, &addr);Any reason why you don't just extend this function (in a prerequisite patch) rather than open coding a common utility function (twice) here, so that other backends (blkback!) can benefit later as well.
Jan
Quoted 7 lines
I'm mainly focusing on netback stuffs, so the code is slightly coupled with netback --
NETBK_MAX_RING_PAGES.To extend
xenbus_map_ring_vallocand make more generic, it requires setting a global maximum page number limits on rings, I think it will require further investigation and code refactor -- which I have no time to attend to at the moment. :-/Why? You can simply pass in the number of pages, there's no need for a global maximum.
Quoted 7 lines
Quoted 3 lines
I mean the
gnttab_map_gran_refarray, it is statically allocated at the moment. Of course we can make it dynamically allocated, but why bother taking the risk of allocation failure.There's so many other allocations, why would you worry about this one.
IMHO, this is not a critical part of the code, so failing this one thus making all other pieces not workable is very strange.
Quoted 7 lines
But of course you can undo what a recent change did, and then subsequently someone else will have to clean up again after you. I'm just asking to follow good programming practices and write re-usable code where potential for re-use is obvious (after all, multi-page block interface patches have been floating around for much longer than yours for the net interface).
Quoted 3 lines
I understand your concern. If the changes required will not make this series longer and involves major changes in block interface, I'm happy to refactor the xenbus interface.
Please do. Patches are more than welcome to make it be more versatile.
RFC PATCH v3 13/16 netback: stub for multi receive protocol support.
In reply to Wei LiuRefactor netback, make stub for mutli receive protocols. Also stub existing code as protocol 0.
Now the file layout becomes:
- interface.c: xenvif interfaces
- xenbus.c: xenbus related functions
- netback.c: common functions for various protocols
For different protocols:
- xenvif_rx_protocolX.h: header file for the protocol, including protocol structures and functions
- xenvif_rx_protocolX.c: implementations
To add a new protocol:
- include protocol header in common.h
- modify XENVIF_MAX_RX_PROTOCOL in common.h
- add protocol structure in xenvif.rx union
- stub in xenbus.c
- modify Makefile
A protocol should define five functions:
- setup: setup frontend / backend ring connections
- teardown: teardown frontend / backend ring connections
- start_xmit: host start xmit (i.e. guest need to do rx)
- event: rx completion event
- action: prepare host side data for guest rx
--- drivers/net/xen-netback/Makefile | 2 +- drivers/net/xen-netback/common.h | 34 +- drivers/net/xen-netback/interface.c | 49 +- drivers/net/xen-netback/netback.c | 528 +--------------------- drivers/net/xen-netback/xenbus.c | 8 +- drivers/net/xen-netback/xenvif_rx_protocol0.c | 616 +++++++++++++++++++++++++ drivers/net/xen-netback/xenvif_rx_protocol0.h | 53 +++ 7 files changed, 732 insertions(+), 558 deletions(-) create mode 100644 drivers/net/xen-netback/xenvif_rx_protocol0.c create mode 100644 drivers/net/xen-netback/xenvif_rx_protocol0.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 page_pool.o +xen-netback-y := netback.o xenbus.o interface.o page_pool.o xenvif_rx_protocol0.o
drivers/net/xen-netback/common.h +22 -12
@@ -46,6 +46,7 @@#include <xen/xenbus.h> #include "page_pool.h" +#include "xenvif_rx_protocol0.h" struct xenvif_rx_meta {int id;
@@ -79,6 +80,9 @@ struct xen_comms {unsigned int nr_handles; }; +#define XENVIF_MIN_RX_PROTOCOL 0 +#define XENVIF_MAX_RX_PROTOCOL 0 +struct xenvif {/* Unique identifier for this interface. */ domid_t domid;
@@ -99,9 +103,13 @@ struct xenvif {/* Physical parameters of the comms window. */ unsigned int irq; -/* The shared rings and indexes. */ +/* The shared tx ring and index. */ struct xen_netif_tx_back_ring tx; -struct xen_netif_rx_back_ring rx; + +/* Multi receive protocol support */ +union { +struct xenvif_rx_protocol0 p0; + } rx;/* Frontend feature information. */ u8 can_sg:1;
@@ -112,13 +120,6 @@ struct xenvif {/* Internal feature information. */ u8 can_queue:1; /* can queue packets for receiver? */ -/* -* Allow xenvif_start_xmit() to peek ahead in the rx request -* ring. This is a prediction of what rx_req_cons will be -* once all queued skbs are put on the ring. -*/ -RING_IDX rx_req_cons_peek; -/* Transmit shaping: allow 'credit_bytes' every 'credit_usec'. */ unsigned long credit_bytes;unsigned long credit_usec;
@@ -128,6 +129,13 @@ struct xenvif {/* Statistics */ unsigned long rx_gso_checksum_fixup; +/* Hooks for multi receive protocol support */ +int (*setup)(struct xenvif *); +void (*start_xmit)(struct xenvif *,struct sk_buff *); +void (*teardown)(struct xenvif *); +void (*event)(struct xenvif *); +void (*action)(struct xenvif *); +/* Miscellaneous private stuff. */ struct net_device *dev;
@@ -154,7 +162,7 @@ struct xenvif *xenvif_alloc(struct device *parent,int xenvif_connect (struct xenvif *vif,unsigned long tx_ring_ref[],unsigned int tx_ring_order,unsigned long rx_ring_ref[],unsigned int rx_ring_order, -unsigned int evtchn); +unsigned int evtchn,unsigned int rx_protocol);void xenvif_disconnect (struct xenvif *vif);int xenvif_xenbus_init (void );
@@ -178,8 +186,6 @@ void xenvif_check_rx_xenvif(struct xenvif *vif);/* Queue an SKB for transmission to the frontend */ 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 xenvif_count_skb_slots (struct xenvif *vif,struct sk_buff *skb);
@@ -188,7 +194,11 @@ int xenvif_tx_action(struct xenvif *vif, int budget);void xenvif_rx_action (struct xenvif *vif);int xenvif_kthread (void *data); +void xenvif_kick_thread (struct xenvif *vif); + +int xenvif_max_required_rx_slots (struct xenvif *vif); +extern unsigned int MODPARM_netback_max_rx_protocol;extern unsigned int MODPARM_netback_max_tx_ring_page_order;extern unsigned int MODPARM_netback_max_rx_ring_page_order;
drivers/net/xen-netback/interface.c +23 -26
94 lines not on this page · raw message
drivers/net/xen-netback/netback.c +10 -518
568 lines not on this page · raw message
drivers/net/xen-netback/xenbus.c +7 -1
@@ -415,6 +415,7 @@ static int connect_rings(struct backend_info *be)unsigned long rx_ring_ref[NETBK_MAX_RING_PAGES ];unsigned int tx_ring_order;unsigned int rx_ring_order; +unsigned int rx_protocol; err =xenbus_gather (XBT_NIL , dev->otherend,"event-channel" ,"%u" , &evtchn,NULL );
@@ -510,6 +511,11 @@ static int connect_rings(struct backend_info *be) } } + err =xenbus_scanf (XBT_NIL , dev->otherend,"rx-protocol" , +"%u" , &rx_protocol); +if (err <0 ) + rx_protocol =XENVIF_MIN_RX_PROTOCOL ; + err =xenbus_scanf (XBT_NIL , dev->otherend,"request-rx-copy" ,"%u" , &rx_copy);if (err == -ENOENT ) {
@@ -559,7 +565,7 @@ static int connect_rings(struct backend_info *be) err =xenvif_connect (vif, tx_ring_ref, (1U << tx_ring_order), rx_ring_ref, (1U << rx_ring_order), - evtchn); + evtchn, rx_protocol);if (err) {int i; xenbus_dev_fatal(dev, err,
drivers/net/xen-netback/xenvif_rx_protocol0.c new file +616 -0
616 lines not on this page · raw message
drivers/net/xen-netback/xenvif_rx_protocol0.h new file +53 -0
53 lines not on this page · raw message
Signature · 1 line
1.7.2.5
Re: [Xen-devel] [RFC PATCH V3 13/16] netback: stub for multi receive protocol support.
Quoted 1 line · Wei Liu
Refactor netback, make stub for mutli receive protocols. Also stub
multi.
Quoted 1 line
existing code as protocol 0.
Why not 1?
Why do we need a new rework without anything using it besides the existing framework? OR if you are, you should say which patch is doing it...
Quoted 29 lines
Now the file layout becomes:
-
interface.c: xenvif interfaces
-xenbus.c: xenbus related functions
-netback.c: common functions for various protocolsFor different protocols:
-
xenvif_rx_protocolX.h: header file for the protocol, including protocol structures and functions
-xenvif_rx_protocolX.c: implementationsTo add a new protocol:
- include protocol header in
common.h
- modifyXENVIF_MAX_RX_PROTOCOLincommon.h
- add protocol structure in xenvif.rx union
- stub inxenbus.c
- modifyMakefileA protocol should define five functions:
- setup: setup frontend / backend ring connections
- teardown: teardown frontend / backend ring connections
-start_xmit: host start xmit (i.e. guest need to do rx)
- event: rx completion event
- action: prepare host side data for guest rx
.. snip..
Quoted 31 lines
drivers/net/xen-netback/netback.c +2
-6- -return resp; -} -static inline int rx_work_todo (struct xenvif *vif) {return !skb_queue_empty (&vif->rx_queue);@@ -1507,8 +999,8 @@ int xenvif_kthread(void *data)if (kthread_should_stop ())break ; -if (rx_work_todo (vif)) -xenvif_rx_action (vif); +if (rx_work_todo (vif) && vif->action) + vif->action (vif); }return 0 ;drivers/net/xen-netback/xenbus.c +1
-0@@ -415,6 +415,7 @@ static int connect_rings(struct backend_info *be)unsigned long rx_ring_ref[NETBK_MAX_RING_PAGES ];unsigned int tx_ring_order;unsigned int rx_ring_order; +unsigned int rx_protocol; err =xenbus_gather (XBT_NIL , dev->otherend,"event-channel" ,"%u" , &evtchn,NULL );
drivers/net/xen-netback/xenbus.c static int connect_rings(struct backend_info *be) · line 514
Quoted 4 lines
drivers/net/xen-netback/xenbus.c +1
-0@@ -510,6 +511,11 @@ static int connect_rings(struct backend_info *be) } } + err = xenbus_scanf(XBT_NIL, dev->otherend, "rx-protocol",
feature-rx-protocol?
drivers/net/xen-netback/xenbus.c static int connect_rings(struct backend_info *be) · line 518
Quoted 4 lines
drivers/net/xen-netback/xenbus.c +4
-0+ "%u", &rx_protocol); +if (err <0 ) + rx_protocol =XENVIF_MIN_RX_PROTOCOL ; +
You should check to see if the protocol is higher than what we can support. The guest could be playing funny games and putting in 39432...
Quoted 12 lines
drivers/net/xen-netback/xenbus.c +1
-1err =xenbus_scanf (XBT_NIL , dev->otherend,"request-rx-copy" ,"%u" , &rx_copy);if (err == -ENOENT ) {@@ -559,7 +565,7 @@ static int connect_rings(struct backend_info *be) err =xenvif_connect (vif, tx_ring_ref, (1U << tx_ring_order), rx_ring_ref, (1U << rx_ring_order), - evtchn); + evtchn, rx_protocol);if (err) {int i; xenbus_dev_fatal(dev, err,
Re: [Xen-devel] [RFC PATCH V3 13/16] netback: stub for multi receive protocol support.
Quoted 5 lines · Konrad Rzeszutek Wilk
Quoted 1 line · Wei Liu
Refactor netback, make stub for mutli receive protocols. Also stub
multi.
Good catch, thanks.
Quoted 4 lines
Quoted 1 line
existing code as protocol 0.
Why not 1?
We have some existing xenolinux code which has not been upstreamed calls this protocol 0, just try to be compatible.
Quoted 4 lines
Why do we need a new rework without anything using it besides the existing framework? OR if you are, you should say which patch is doing it...
It is not in use at the moment, and will be in use in the future.
Quoted 65 lines
Quoted 29 lines
Now the file layout becomes:
-
interface.c: xenvif interfaces
-xenbus.c: xenbus related functions
-netback.c: common functions for various protocolsFor different protocols:
-
xenvif_rx_protocolX.h: header file for the protocol, including protocol structures and functions
-xenvif_rx_protocolX.c: implementationsTo add a new protocol:
- include protocol header in
common.h
- modifyXENVIF_MAX_RX_PROTOCOLincommon.h
- add protocol structure in xenvif.rx union
- stub inxenbus.c
- modifyMakefileA protocol should define five functions:
- setup: setup frontend / backend ring connections
- teardown: teardown frontend / backend ring connections
-start_xmit: host start xmit (i.e. guest need to do rx)
- event: rx completion event
- action: prepare host side data for guest rx.. snip..
Quoted 34 lines
drivers/net/xen-netback/netback.c +2
-6- -return resp; -} -static inline int rx_work_todo (struct xenvif *vif) {return !skb_queue_empty (&vif->rx_queue);@@ -1507,8 +999,8 @@ int xenvif_kthread(void *data)if (kthread_should_stop ())break ; -if (rx_work_todo (vif)) -xenvif_rx_action (vif); +if (rx_work_todo (vif) && vif->action) + vif->action (vif); }return 0 ;drivers/net/xen-netback/xenbus.c +1
-0@@ -415,6 +415,7 @@ static int connect_rings(struct backend_info *be)unsigned long rx_ring_ref[NETBK_MAX_RING_PAGES ];unsigned int tx_ring_order;unsigned int rx_ring_order; +unsigned int rx_protocol; err =xenbus_gather (XBT_NIL , dev->otherend,"event-channel" ,"%u" , &evtchn,NULL );@@ -510,6 +511,11 @@ static int connect_rings(struct backend_info *be) } }
Quoted 4 lines
drivers/net/xen-netback/xenbus.c static int connect_rings(struct backend_info *be) · line 514
Quoted 1 line
drivers/net/xen-netback/xenbus.c +1
-0+ err = xenbus_scanf(XBT_NIL, dev->otherend, "rx-protocol",feature-rx-protocol?
This is not a feature switch. Does it make sense to add "feature-" prefix?
Quoted 9 lines
drivers/net/xen-netback/xenbus.c static int connect_rings(struct backend_info *be) · line 518
Quoted 4 lines
drivers/net/xen-netback/xenbus.c +4
-0+ "%u", &rx_protocol); +if (err <0 ) + rx_protocol =XENVIF_MIN_RX_PROTOCOL ; +You should check to see if the protocol is higher than what we can support. The guest could be playing funny games and putting in 39432...
Good point.
Wei.
Re: [Xen-devel] [RFC PATCH V3 13/16] netback: stub for multi receive protocol support.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
existing code as protocol 0.
Why not 1?
We have some existing xenolinux code which has not been upstreamed calls this protocol 0, just try to be compatible.
Ah. Please do mention that in the description.
Quoted 7 lines
Quoted 5 lines
Why do we need a new rework without anything using it besides the existing framework? OR if you are, you should say which patch is doing it...
It is not in use at the moment, and will be in use in the future.
Ok, should it be part of the "in the future" patchset then?
Quoted 66 lines
Quoted 66 lines
Quoted 30 lines
Now the file layout becomes:
-
interface.c: xenvif interfaces
-xenbus.c: xenbus related functions
-netback.c: common functions for various protocolsFor different protocols:
-
xenvif_rx_protocolX.h: header file for the protocol, including protocol structures and functions
-xenvif_rx_protocolX.c: implementationsTo add a new protocol:
- include protocol header in
common.h
- modifyXENVIF_MAX_RX_PROTOCOLincommon.h
- add protocol structure in xenvif.rx union
- stub inxenbus.c
- modifyMakefileA protocol should define five functions:
- setup: setup frontend / backend ring connections
- teardown: teardown frontend / backend ring connections
-start_xmit: host start xmit (i.e. guest need to do rx)
- event: rx completion event
- action: prepare host side data for guest rx.. snip..
Quoted 34 lines
drivers/net/xen-netback/netback.c +2
-6- -return resp; -} -static inline int rx_work_todo (struct xenvif *vif) {return !skb_queue_empty (&vif->rx_queue);@@ -1507,8 +999,8 @@ int xenvif_kthread(void *data)if (kthread_should_stop ())break ; -if (rx_work_todo (vif)) -xenvif_rx_action (vif); +if (rx_work_todo (vif) && vif->action) + vif->action (vif); }return 0 ;drivers/net/xen-netback/xenbus.c +1
-0@@ -415,6 +415,7 @@ static int connect_rings(struct backend_info *be)unsigned long rx_ring_ref[NETBK_MAX_RING_PAGES ];unsigned int tx_ring_order;unsigned int rx_ring_order; +unsigned int rx_protocol; err =xenbus_gather (XBT_NIL , dev->otherend,"event-channel" ,"%u" , &evtchn,NULL );@@ -510,6 +511,11 @@ static int connect_rings(struct backend_info *be) } }
Quoted 6 lines
Quoted 4 lines
drivers/net/xen-netback/xenbus.c static int connect_rings(struct backend_info *be) · line 514
Quoted 1 line
drivers/net/xen-netback/xenbus.c +1
-0+ err = xenbus_scanf(XBT_NIL, dev->otherend, "rx-protocol",feature-rx-protocol?
This is not a feature switch. Does it make sense to add "feature-"
Good point.
Quoted 1 line
prefix?
It is negotiating a new protocol. Hm, perhaps 'protocol-rx-version' instead? Or just 'protocol-version'?
RFC PATCH v3 14/16 netback: split event channels support
In reply to Wei LiuOriginally, netback and netfront only use one event channel to do tx / rx notification. This may cause unnecessary wake-up of NAPI / kthread.
When guest tx is completed, netback will only notify tx_irq.
Also modify xenvif_protocol0 to reflect this change. Rx protocol only notifies rx_irq.
If split-event-channels feature is not activated, rx_irq = tx_irq, so RX protocol will just work as expected.
--- drivers/net/xen-netback/common.h | 9 ++- drivers/net/xen-netback/interface.c | 90 ++++++++++++++++++++----- drivers/net/xen-netback/netback.c | 2 +- drivers/net/xen-netback/xenbus.c | 52 ++++++++++++--- drivers/net/xen-netback/xenvif_rx_protocol0.c | 2 +- 5 files changed, 123 insertions(+), 32 deletions(-)
drivers/net/xen-netback/common.h +6 -3
@@ -100,8 +100,10 @@ struct xenvif {u8 fe_dev_addr[6 ]; -/* Physical parameters of the comms window. */ -unsigned int irq; +/* when split_irq == 0, only use tx_irq */ +int split_irq; +unsigned int tx_irq; +unsigned int rx_irq;/* The shared tx ring and index. */ struct xen_netif_tx_back_ring tx;
@@ -162,7 +164,8 @@ struct xenvif *xenvif_alloc(struct device *parent,int xenvif_connect (struct xenvif *vif,unsigned long tx_ring_ref[],unsigned int tx_ring_order,unsigned long rx_ring_ref[],unsigned int rx_ring_order, -unsigned int evtchn,unsigned int rx_protocol); +unsigned int evtchn[],int split_evtchn, +unsigned int rx_protocol);void xenvif_disconnect (struct xenvif *vif);int xenvif_xenbus_init (void );
drivers/net/xen-netback/interface.c +73 -17
145 lines not on this page · raw message
drivers/net/xen-netback/netback.c +1 -1
@@ -895,7 +895,7 @@ static void make_tx_response(struct xenvif *vif, vif->tx.rsp_prod_pvt = ++i;RING_PUSH_RESPONSES_AND_CHECK_NOTIFY (&vif->tx, notify);if (notify) -notify_remote_via_irq (vif->irq); +notify_remote_via_irq (vif->tx_irq); }static inline int rx_work_todo (struct xenvif *vif)
drivers/net/xen-netback/xenbus.c +42 -10
79 lines not on this page · raw message
drivers/net/xen-netback/xenvif_rx_protocol0.c +1 -1
@@ -550,7 +550,7 @@ void xenvif_rx_action(struct xenvif *vif) }if (need_to_notify) -notify_remote_via_irq (vif->irq); +notify_remote_via_irq (vif->rx_irq);if (!skb_queue_empty (&vif->rx_queue))xenvif_kick_thread (vif);
Signature · 1 line
1.7.2.5
Re: [RFC PATCH V3 14/16] netback: split event channels support
Quoted 25 lines · Wei Liu
Originally, netback and netfront only use one event channel to do tx / rx notification. This may cause unnecessary wake-up of NAPI / kthread.
When guest tx is completed, netback will only notify
tx_irq.Also modify
xenvif_protocol0to reflect this change. Rx protocol only notifiesrx_irq.If split-event-channels feature is not activated,
rx_irq=tx_irq, so RX protocol will just work as expected.Signed-off-by Wei Liu <[email protected]>--- drivers/net/xen-netback/common.h | 9 ++- drivers/net/xen-netback/interface.c | 90 ++++++++++++++++++++----- drivers/net/xen-netback/netback.c | 2 +- drivers/net/xen-netback/xenbus.c | 52 ++++++++++++--- drivers/net/xen-netback/xenvif_rx_protocol0.c | 2 +- 5 files changed, 123 insertions(+), 32 deletions(-)drivers/net/xen-netback/common.h +0
-0
drivers/net/xen-netback/common.h struct xenvif { · line 106
Quoted 9 lines
drivers/net/xen-netback/common.h +4
-2@@ -100,8 +100,10 @@ struct xenvif {u8 fe_dev_addr[6 ]; -/* Physical parameters of the comms window. */ -unsigned int irq; +/* when split_irq == 0, only use tx_irq */ +int split_irq; +unsigned int tx_irq; +unsigned int rx_irq;
Can you get rid of split_irq by setting tx_irq == rx_irq in that case and simplify the code by doing so?
I think this should work even for places like:
if (!vif->split_irq)
enable_irq(vif->tx_irq);
else {
enable_irq(vif->tx_irq);
enable_irq(vif->rx_irq);
}Just by doing
enable_irq(vif->tx_irq); enable_irq(vif->rx_irq);
Since enable/disable_irq maintain a count and so it will do the right thing if they happen to be the same.
Quoted 36 lines
drivers/net/xen-netback/common.h +2
-1/* The shared tx ring and index. */ struct xen_netif_tx_back_ring tx;@@ -162,7 +164,8 @@ struct xenvif *xenvif_alloc(struct device *parent,int xenvif_connect (struct xenvif *vif,unsigned long tx_ring_ref[],unsigned int tx_ring_order,unsigned long rx_ring_ref[],unsigned int rx_ring_order, -unsigned int evtchn,unsigned int rx_protocol); +unsigned int evtchn[],int split_evtchn, +unsigned int rx_protocol);void xenvif_disconnect (struct xenvif *vif);int xenvif_xenbus_init (void );drivers/net/xen-netback/interface.c +11
-1@@ -46,15 +46,31 @@ int xenvif_schedulable(struct xenvif *vif)return netif_running (vif->dev) &&netif_carrier_ok (vif->dev); } -static irqreturn_t xenvif_interrupt (int irq,void *dev_id) +static irqreturn_t xenvif_tx_interrupt (int irq,void *dev_id) +{ +struct xenvif *vif = dev_id; + +if (RING_HAS_UNCONSUMED_REQUESTS (&vif->tx)) +napi_schedule (&vif->napi); + +return IRQ_HANDLED ; +} + +static irqreturn_t xenvif_rx_interrupt (int irq,void *dev_id) {struct xenvif *vif = dev_id;if (xenvif_schedulable (vif) && vif->event !=NULL )
drivers/net/xen-netback/interface.c int xenvif_schedulable(struct xenvif *vif) · line 71
Quoted 10 lines
drivers/net/xen-netback/interface.c +6
-2vif->event (vif); -if (RING_HAS_UNCONSUMED_REQUESTS (&vif->tx)) -napi_schedule (&vif->napi); +return IRQ_HANDLED ; +} + +static irqreturn_t xenvif_interrupt (int irq,void *dev_id) +{ +xenvif_tx_interrupt (0 , dev_id);
Might as well pass irq down.
[...]
drivers/net/xen-netback/interface.c struct xenvif *xenvif_alloc(struct device *parent, domid_t domid, · line 337
Quoted 6 lines
drivers/net/xen-netback/interface.c +1
-1@@ -308,13 +334,14 @@ struct xenvif *xenvif_alloc(struct device *parent, domid_t domid, int xenvif_connect(struct xenvif *vif, unsigned long tx_ring_ref[], unsigned int tx_ring_ref_count, unsigned long rx_ring_ref[], unsigned int rx_ring_ref_count, -unsigned int evtchn,unsigned int rx_protocol) + unsigned int evtchn[], int split_evtchn,
Explicitly tx_evtchn and rx_evtchn would be clearer than remembering that [0]==tx and [1]==rx I think.
Quoted 13 lines
drivers/net/xen-netback/interface.c +2
-1+ unsigned int rx_protocol) {int err = -ENOMEM ;struct xen_netif_tx_sring *txs;/* Already connected through? */ -if (vif->irq) +if (vif->tx_irq)return 0 ;__module_get (THIS_MODULE );@@ -345,13 +372,35 @@ int xenvif_connect(struct xenvif *vif,if (vif->setup (vif))
drivers/net/xen-netback/interface.c int xenvif_connect(struct xenvif *vif, · line 375
Quoted 10 lines
drivers/net/xen-netback/interface.c +1
-7goto err_rx_unmap; - err =bind_interdomain_evtchn_to_irqhandler ( - vif->domid, evtchn, xenvif_interrupt,0 , - vif->dev->name, vif); -if (err <0 ) - goto err_rx_unmap; - vif->irq = err; -disable_irq (vif->irq); +if (!split_evtchn) {
Presumably this is one of the places where you do have to care about split vs non. I did consider whether simply registering two handlers for the interrupt in a shared-interrupt style would work, but I think that way lies madness and confusion...
Quoted 36 lines
drivers/net/xen-netback/interface.c +28
-0+ err =bind_interdomain_evtchn_to_irqhandler ( + vif->domid, evtchn[0 ], xenvif_interrupt,0 , + vif->dev->name, vif); +if (err <0 ) + goto err_rx_unmap; + vif->tx_irq = vif->rx_irq = err; +disable_irq (vif->tx_irq); + vif->split_irq =0 ; + }else { + err =bind_interdomain_evtchn_to_irqhandler ( + vif->domid, evtchn[0 ], xenvif_tx_interrupt, +0 , vif->dev->name, vif); +if (err <0 ) + goto err_rx_unmap; + vif->tx_irq = err; +disable_irq (vif->tx_irq); + + err =bind_interdomain_evtchn_to_irqhandler ( + vif->domid, evtchn[1 ], xenvif_rx_interrupt, +0 , vif->dev->name, vif); +if (err <0 ) { +unbind_from_irqhandler (vif->tx_irq, vif); + goto err_rx_unmap; + } + vif->rx_irq = err; +disable_irq (vif->rx_irq); + vif->split_irq =1 ; + }init_waitqueue_head (&vif->wq); vif->task = kthread_create(xenvif_kthread,drivers/net/xen-netback/xenbus.c +0
-0
drivers/net/xen-netback/xenbus.c static int netback_probe(struct xenbus_device *dev, · line 135
Quoted 5 lines
drivers/net/xen-netback/xenbus.c +2
-0@@ -131,6 +131,14 @@ static int netback_probe(struct xenbus_device *dev, goto abort_transaction; } + err = xenbus_printf(xbt, dev->nodename, + "split-event-channels",
Usually we use "feature-FOO" as the names for these sorts of nodes.
Quoted 10 lines
drivers/net/xen-netback/xenbus.c +6
-0+ "%u", 1); +if (err) { + message ="writing split-event-channels" ; + goto abort_transaction; + } + err =xenbus_transaction_end (xbt,0 ); }while (err == -EAGAIN );
drivers/net/xen-netback/xenbus.c static int connect_rings(struct backend_info *be) · line 419
Quoted 5 lines
drivers/net/xen-netback/xenbus.c +1
-1@@ -408,7 +416,7 @@ static int connect_rings(struct backend_info *be) {struct xenvif *vif = be->vif;struct xenbus_device *dev = be->dev; -unsigned int evtchn, rx_copy; +unsigned int evtchn[2 ], split_evtchn, rx_copy;
Another case where I think two vars is better than a small array.
drivers/net/xen-netback/xenbus.c static int connect_rings(struct backend_info *be) · line 422
Quoted 3 lines
drivers/net/xen-netback/xenbus.c +0
-0int err;int val;unsigned long tx_ring_ref[NETBK_MAX_RING_PAGES ];
Ian.
Re: [RFC PATCH V3 14/16] netback: split event channels support
Quoted 14 lines · Ian Campbell
O
Can you get rid of
split_irqby settingtx_irq==rx_irqin that case and simplify the code by doing so?I think this should work even for places like:
if (!vif->split_irq) enable_irq(vif->tx_irq); else { enable_irq(vif->tx_irq); enable_irq(vif->rx_irq); }
Quoted 7 lines
Just by doing
enable_irq(vif->tx_irq); enable_irq(vif->rx_irq);Since enable/disable_irq maintain a count and so it will do the right thing if they happen to be the same.
Hmm... OK.
Quoted 38 lines
Quoted 38 lines
drivers/net/xen-netback/common.h +2
-1/* The shared tx ring and index. */ struct xen_netif_tx_back_ring tx;@@ -162,7 +164,8 @@ struct xenvif *xenvif_alloc(struct device *parent,int xenvif_connect (struct xenvif *vif,unsigned long tx_ring_ref[],unsigned int tx_ring_order,unsigned long rx_ring_ref[],unsigned int rx_ring_order, -unsigned int evtchn,unsigned int rx_protocol); +unsigned int evtchn[],int split_evtchn, +unsigned int rx_protocol);void xenvif_disconnect (struct xenvif *vif);int xenvif_xenbus_init (void );drivers/net/xen-netback/interface.c +11
-1@@ -46,15 +46,31 @@ int xenvif_schedulable(struct xenvif *vif)return netif_running (vif->dev) &&netif_carrier_ok (vif->dev); } -static irqreturn_t xenvif_interrupt (int irq,void *dev_id) +static irqreturn_t xenvif_tx_interrupt (int irq,void *dev_id) +{ +struct xenvif *vif = dev_id; + +if (RING_HAS_UNCONSUMED_REQUESTS (&vif->tx)) +napi_schedule (&vif->napi); + +return IRQ_HANDLED ; +} + +static irqreturn_t xenvif_rx_interrupt (int irq,void *dev_id) {struct xenvif *vif = dev_id;if (xenvif_schedulable (vif) && vif->event !=NULL ) vif->event (vif);
Quoted 10 lines
drivers/net/xen-netback/interface.c int xenvif_schedulable(struct xenvif *vif) · line 71
Quoted 8 lines
drivers/net/xen-netback/interface.c +6
-2-if (RING_HAS_UNCONSUMED_REQUESTS (&vif->tx)) -napi_schedule (&vif->napi); +return IRQ_HANDLED ; +} + +static irqreturn_t xenvif_interrupt (int irq,void *dev_id) +{ +xenvif_tx_interrupt (0 , dev_id);Might as well pass irq down.
Sure.
Quoted 79 lines
[...]
drivers/net/xen-netback/interface.c struct xenvif *xenvif_alloc(struct device *parent, domid_t domid, · line 337
Quoted 6 lines
drivers/net/xen-netback/interface.c +1
-1@@ -308,13 +334,14 @@ struct xenvif *xenvif_alloc(struct device *parent, domid_t domid, int xenvif_connect(struct xenvif *vif, unsigned long tx_ring_ref[], unsigned int tx_ring_ref_count, unsigned long rx_ring_ref[], unsigned int rx_ring_ref_count, -unsigned int evtchn,unsigned int rx_protocol) + unsigned int evtchn[], int split_evtchn,Explicitly
tx_evtchnandrx_evtchnwould be clearer than remembering that [0]==tx and [1]==rx I think.Quoted 13 lines
drivers/net/xen-netback/interface.c +2
-1+ unsigned int rx_protocol) {int err = -ENOMEM ;struct xen_netif_tx_sring *txs;/* Already connected through? */ -if (vif->irq) +if (vif->tx_irq)return 0 ;__module_get (THIS_MODULE );@@ -345,13 +372,35 @@ int xenvif_connect(struct xenvif *vif,if (vif->setup (vif))drivers/net/xen-netback/interface.c int xenvif_connect(struct xenvif *vif, · line 375
Quoted 10 lines
drivers/net/xen-netback/interface.c +1
-7goto err_rx_unmap; - err =bind_interdomain_evtchn_to_irqhandler ( - vif->domid, evtchn, xenvif_interrupt,0 , - vif->dev->name, vif); -if (err <0 ) - goto err_rx_unmap; - vif->irq = err; -disable_irq (vif->irq); +if (!split_evtchn) {Presumably this is one of the places where you do have to care about split vs non. I did consider whether simply registering two handlers for the interrupt in a shared-interrupt style would work, but I think that way lies madness and confusion...
Quoted 39 lines
drivers/net/xen-netback/interface.c +28
-0+ err =bind_interdomain_evtchn_to_irqhandler ( + vif->domid, evtchn[0 ], xenvif_interrupt,0 , + vif->dev->name, vif); +if (err <0 ) + goto err_rx_unmap; + vif->tx_irq = vif->rx_irq = err; +disable_irq (vif->tx_irq); + vif->split_irq =0 ; + }else { + err =bind_interdomain_evtchn_to_irqhandler ( + vif->domid, evtchn[0 ], xenvif_tx_interrupt, +0 , vif->dev->name, vif); +if (err <0 ) + goto err_rx_unmap; + vif->tx_irq = err; +disable_irq (vif->tx_irq); + + err =bind_interdomain_evtchn_to_irqhandler ( + vif->domid, evtchn[1 ], xenvif_rx_interrupt, +0 , vif->dev->name, vif); +if (err <0 ) { +unbind_from_irqhandler (vif->tx_irq, vif); + goto err_rx_unmap; + } + vif->rx_irq = err; +disable_irq (vif->rx_irq); + vif->split_irq =1 ; + }init_waitqueue_head (&vif->wq); vif->task = kthread_create(xenvif_kthread,drivers/net/xen-netback/xenbus.c +0
-0@@ -131,6 +131,14 @@ static int netback_probe(struct xenbus_device *dev, goto abort_transaction; }
Quoted 5 lines
drivers/net/xen-netback/xenbus.c static int netback_probe(struct xenbus_device *dev, · line 135
Quoted 2 lines
drivers/net/xen-netback/xenbus.c +2
-0+ err = xenbus_printf(xbt, dev->nodename, + "split-event-channels",Usually we use "feature-FOO" as the names for these sorts of nodes.
Got it.
Quoted 9 lines
Quoted 9 lines
drivers/net/xen-netback/xenbus.c +6
-0+ "%u", 1); +if (err) { + message ="writing split-event-channels" ; + goto abort_transaction; + } + err =xenbus_transaction_end (xbt,0 ); }while (err == -EAGAIN );
Quoted 13 lines
drivers/net/xen-netback/xenbus.c static int connect_rings(struct backend_info *be) · line 419
Quoted 6 lines
drivers/net/xen-netback/xenbus.c +1
-1@@ -408,7 +416,7 @@ static int connect_rings(struct backend_info *be) {struct xenvif *vif = be->vif;struct xenbus_device *dev = be->dev; -unsigned int evtchn, rx_copy; +unsigned int evtchn[2 ], split_evtchn, rx_copy;Another case where I think two vars is better than a small array.
Quoted 3 lines
drivers/net/xen-netback/xenbus.c +0
-0int err;int val;unsigned long tx_ring_ref[NETBK_MAX_RING_PAGES ];
Reasonable change.
Wei.
RFC PATCH v3 15/16 netfront: multi page ring support.
In reply to Wei LiuUse DMA API to allocate ring pages, because we need to get machine contiginous memory.
--- drivers/net/xen-netfront.c | 258 ++++++++++++++++++++++++++++++++------------ 1 files changed, 187 insertions(+), 71 deletions(-)
drivers/net/xen-netfront.c +187 -71
@@ -66,9 +66,18 @@ struct netfront_cb {#define GRANT_INVALID_REF 0 -#define NET_TX_RING_SIZE __CONST_RING_SIZE(xen_netif_tx, PAGE_SIZE) -#define NET_RX_RING_SIZE __CONST_RING_SIZE(xen_netif_rx, PAGE_SIZE) -#define TX_MAX_TARGET min_t(int, NET_TX_RING_SIZE, 256) +#define XENNET_MAX_RING_PAGE_ORDER 2 +#define XENNET_MAX_RING_PAGES (1U << XENNET_MAX_RING_PAGE_ORDER) + +#define NET_TX_RING_SIZE (_nr_pages) \ + __CONST_RING_SIZE(xen_netif_tx, PAGE_SIZE * (_nr_pages)) +#define NET_RX_RING_SIZE (_nr_pages) \ + __CONST_RING_SIZE(xen_netif_rx, PAGE_SIZE * (_nr_pages)) + +#define XENNET_MAX_TX_RING_SIZE NET_TX_RING_SIZE(XENNET_MAX_RING_PAGES) +#define XENNET_MAX_RX_RING_SIZE NET_RX_RING_SIZE(XENNET_MAX_RING_PAGES) + +#define TX_MAX_TARGET XENNET_MAX_TX_RING_SIZEstruct netfront_stats {u64 rx_packets;
@@ -84,12 +93,20 @@ struct netfront_info {struct napi_struct napi; +/* Statistics */ +struct netfront_stats __percpu *stats; + +unsigned long rx_gso_checksum_fixup; +unsigned int evtchn;struct xenbus_device *xbdev;spinlock_t tx_lock;struct xen_netif_tx_front_ring tx; -int tx_ring_ref; +dma_addr_t tx_ring_dma_handle; +int tx_ring_ref[XENNET_MAX_RING_PAGES ]; +int tx_ring_page_order; +int tx_ring_pages;/* * {tx,rx}_skbs store outstanding skbuffs. Free tx_skb entries
@@ -103,36 +120,34 @@ struct netfront_info {union skb_entry {struct sk_buff *skb;unsigned long link; - } tx_skbs[NET_TX_RING_SIZE ]; + } tx_skbs[XENNET_MAX_TX_RING_SIZE ];grant_ref_t gref_tx_head; -grant_ref_t grant_tx_ref[NET_TX_RING_SIZE ]; +grant_ref_t grant_tx_ref[XENNET_MAX_TX_RING_SIZE ];unsigned tx_skb_freelist;spinlock_t rx_lock____cacheline_aligned_in_smp ;struct xen_netif_rx_front_ring rx; -int rx_ring_ref; +dma_addr_t rx_ring_dma_handle; +int rx_ring_ref[XENNET_MAX_RING_PAGES ]; +int rx_ring_page_order; +int rx_ring_pages;/* Receive-ring batched refills. */ #define RX_MIN_TARGET 8#define RX_DFL_MIN_TARGET 64 -#define RX_MAX_TARGET min_t(int, NET_RX_RING_SIZE, 256) +#define RX_MAX_TARGET XENNET_MAX_RX_RING_SIZEunsigned rx_min_target, rx_max_target, rx_target;struct sk_buff_head rx_batch;struct timer_list rx_refill_timer; -struct sk_buff *rx_skbs[NET_RX_RING_SIZE ]; +struct sk_buff *rx_skbs[XENNET_MAX_RX_RING_SIZE ];grant_ref_t gref_rx_head; -grant_ref_t grant_rx_ref[NET_RX_RING_SIZE ]; - -unsigned long rx_pfn_array[NET_RX_RING_SIZE ]; -struct multicall_entry rx_mcl[NET_RX_RING_SIZE +1 ]; -struct mmu_update rx_mmu[NET_RX_RING_SIZE ]; - -/* Statistics */ -struct netfront_stats __percpu *stats; +grant_ref_t grant_rx_ref[XENNET_MAX_RX_RING_SIZE ]; -unsigned long rx_gso_checksum_fixup; +unsigned long rx_pfn_array[XENNET_MAX_RX_RING_SIZE ]; +struct multicall_entry rx_mcl[XENNET_MAX_RX_RING_SIZE +1 ]; +struct mmu_update rx_mmu[XENNET_MAX_RX_RING_SIZE ]; };struct netfront_rx_info {
@@ -170,15 +185,15 @@ static unsigned short get_id_from_freelist(unsigned *head,return id; } -static int xennet_rxidx (RING_IDX idx) +static int xennet_rxidx (RING_IDX idx,struct netfront_info *info) { -return idx & (NET_RX_RING_SIZE -1 ); +return idx & (NET_RX_RING_SIZE (info->rx_ring_pages) -1 ); }static struct sk_buff *xennet_get_rx_skb (struct netfront_info *np,RING_IDX ri) { -int i =xennet_rxidx (ri); +int i =xennet_rxidx (ri, np);struct sk_buff *skb = np->rx_skbs[i]; np->rx_skbs[i] =NULL ;return skb;
@@ -187,7 +202,7 @@ static struct sk_buff *xennet_get_rx_skb(struct netfront_info *np,static grant_ref_t xennet_get_rx_ref (struct netfront_info *np,RING_IDX ri) { -int i =xennet_rxidx (ri); +int i =xennet_rxidx (ri, np);grant_ref_t ref = np->grant_rx_ref[i]; np->grant_rx_ref[i] =GRANT_INVALID_REF ;return ref;
@@ -300,7 +315,7 @@ no_skb: skb->dev = dev; - id =xennet_rxidx (req_prod + i); + id =xennet_rxidx (req_prod + i, np);BUG_ON (np->rx_skbs[id]); np->rx_skbs[id] = skb;
@@ -596,7 +611,7 @@ static int xennet_close(struct net_device *dev)static void xennet_move_rx_slot (struct netfront_info *np,struct sk_buff *skb,grant_ref_t ref) { -int new =xennet_rxidx (np->rx.req_prod_pvt); +int new =xennet_rxidx (np->rx.req_prod_pvt, np);BUG_ON (np->rx_skbs[new]); np->rx_skbs[new] = skb;
@@ -1089,7 +1104,7 @@ static void xennet_release_tx_bufs(struct netfront_info *np)struct sk_buff *skb;int i; -for (i =0 ; i <NET_TX_RING_SIZE ; i++) { +for (i =0 ; i <NET_TX_RING_SIZE (np->tx_ring_pages); i++) {/* Skip over entries which are actually freelist references */ if (skb_entry_is_link (&np->tx_skbs[i]))continue ;
@@ -1123,7 +1138,7 @@ static void xennet_release_rx_bufs(struct netfront_info *np)spin_lock_bh (&np->rx_lock); -for (id =0 ; id <NET_RX_RING_SIZE ; id++) { +for (id =0 ; id <NET_RX_RING_SIZE (np->rx_ring_pages); id++) { ref = np->grant_rx_ref[id];if (ref ==GRANT_INVALID_REF ) { unused++;
@@ -1305,13 +1320,13 @@ static struct net_device * __devinit xennet_create_dev(struct xenbus_device *dev/* Initialise tx_skbs as a free chain containing every entry. */ np->tx_skb_freelist =0 ; -for (i =0 ; i <NET_TX_RING_SIZE ; i++) { +for (i =0 ; i <XENNET_MAX_TX_RING_SIZE ; i++) {skb_entry_set_link (&np->tx_skbs[i], i+1 ); np->grant_tx_ref[i] =GRANT_INVALID_REF ; }/* Clear out rx_skbs */ -for (i =0 ; i <NET_RX_RING_SIZE ; i++) { +for (i =0 ; i <XENNET_MAX_RX_RING_SIZE ; i++) { np->rx_skbs[i] =NULL ; np->grant_rx_ref[i] =GRANT_INVALID_REF ; }
@@ -1409,15 +1424,11 @@ static int __devinit netfront_probe(struct xenbus_device *dev,return err; } -static void xennet_end_access (int ref,void *page) -{ -/* This frees the page as a side-effect */ -if (ref !=GRANT_INVALID_REF ) -gnttab_end_foreign_access (ref,0 , (unsigned long )page); -} -static void xennet_disconnect_backend (struct netfront_info *info) { +int i; +struct xenbus_device *dev = info->xbdev; +/* Stop old i/f to prevent errors whilst we rebuild the state. */ spin_lock_bh (&info->rx_lock);spin_lock_irq (&info->tx_lock);
@@ -1429,12 +1440,24 @@ static void xennet_disconnect_backend(struct netfront_info *info)unbind_from_irqhandler (info->netdev->irq, info->netdev); info->evtchn = info->netdev->irq =0 ; -/* End access and free the pages */ -xennet_end_access (info->tx_ring_ref, info->tx.sring); -xennet_end_access (info->rx_ring_ref, info->rx.sring); +for (i =0 ; i < info->tx_ring_pages; i++) { +int ref = info->tx_ring_ref[i]; +gnttab_end_foreign_access_ref (ref,0 ); + info->tx_ring_ref[i] =GRANT_INVALID_REF ; + } +dma_free_coherent (NULL ,PAGE_SIZE * info->tx_ring_pages, + (void *)info->tx.sring, + info->tx_ring_dma_handle); + +for (i =0 ; i < info->rx_ring_pages; i++) { +int ref = info->rx_ring_ref[i]; +gnttab_end_foreign_access_ref (ref,0 ); + info->rx_ring_ref[i] =GRANT_INVALID_REF ; + } +dma_free_coherent (NULL ,PAGE_SIZE * info->rx_ring_pages, + (void *)info->rx.sring, + info->rx_ring_dma_handle); - info->tx_ring_ref =GRANT_INVALID_REF ; - info->rx_ring_ref =GRANT_INVALID_REF ; info->tx.sring =NULL ; info->rx.sring =NULL ; }
@@ -1483,9 +1506,13 @@ static int setup_netfront(struct xenbus_device *dev, struct netfront_info *info)struct xen_netif_rx_sring *rxs;int err;struct net_device *netdev = info->netdev; +unsigned int max_tx_ring_page_order, max_rx_ring_page_order; +int i, j; - info->tx_ring_ref =GRANT_INVALID_REF ; - info->rx_ring_ref =GRANT_INVALID_REF ; +for (i =0 ; i <XENNET_MAX_RING_PAGES ; i++) { + info->tx_ring_ref[i] =GRANT_INVALID_REF ; + info->rx_ring_ref[i] =GRANT_INVALID_REF ; + } info->rx.sring =NULL ; info->tx.sring =NULL ; netdev->irq =0 ;
@@ -1496,50 +1523,105 @@ static int setup_netfront(struct xenbus_device *dev, struct netfront_info *info) goto fail; } - txs = (struct xen_netif_tx_sring *)get_zeroed_page (GFP_NOIO | __GFP_HIGH); + err =xenbus_scanf (XBT_NIL , info->xbdev->otherend, +"max-tx-ring-page-order" ,"%u" , + &max_tx_ring_page_order); +if (err <0 ) { + info->tx_ring_page_order =0 ; +dev_info (&dev->dev,"single tx ring\n" ); + }else { + info->tx_ring_page_order = max_tx_ring_page_order; +dev_info (&dev->dev,"multi page tx ring, order = %d\n" , + max_tx_ring_page_order); + } + info->tx_ring_pages = (1U << info->tx_ring_page_order); + + txs = (struct xen_netif_tx_sring *) +dma_alloc_coherent (NULL ,PAGE_SIZE * info->tx_ring_pages, + &info->tx_ring_dma_handle, + __GFP_ZERO |GFP_NOIO | __GFP_HIGH);if (!txs) { err = -ENOMEM ;xenbus_dev_fatal (dev, err,"allocating tx ring page" ); goto fail; }SHARED_RING_INIT (txs); -FRONT_RING_INIT (&info->tx, txs,PAGE_SIZE ); +FRONT_RING_INIT (&info->tx, txs,PAGE_SIZE * info->tx_ring_pages); + +for (i =0 ; i < info->tx_ring_pages; i++) { +void *addr = (void *)((unsigned long )txs +PAGE_SIZE * i); + err =xenbus_grant_ring (dev,virt_to_mfn (addr)); +if (err <0 ) + goto grant_tx_ring_fail; + info->tx_ring_ref[i] = err; + } - err =xenbus_grant_ring (dev,virt_to_mfn (txs)); + err =xenbus_scanf (XBT_NIL , info->xbdev->otherend, +"max-rx-ring-page-order" ,"%u" , + &max_rx_ring_page_order);if (err <0 ) { -free_page ((unsigned long )txs); - goto fail; + info->rx_ring_page_order =0 ; +dev_info (&dev->dev,"single rx ring\n" ); + }else { + info->rx_ring_page_order = max_rx_ring_page_order; +dev_info (&dev->dev,"multi page rx ring, order = %d\n" , + max_rx_ring_page_order); } + info->rx_ring_pages = (1U << info->rx_ring_page_order); - info->tx_ring_ref = err; - rxs = (struct xen_netif_rx_sring *)get_zeroed_page (GFP_NOIO | __GFP_HIGH); + rxs = (struct xen_netif_rx_sring *) +dma_alloc_coherent (NULL ,PAGE_SIZE * info->rx_ring_pages, + &info->rx_ring_dma_handle, + __GFP_ZERO |GFP_NOIO | __GFP_HIGH);if (!rxs) { err = -ENOMEM ;xenbus_dev_fatal (dev, err,"allocating rx ring page" ); - goto fail; + goto alloc_rx_ring_fail; }SHARED_RING_INIT (rxs); -FRONT_RING_INIT (&info->rx, rxs,PAGE_SIZE ); - - err =xenbus_grant_ring (dev,virt_to_mfn (rxs)); -if (err <0 ) { -free_page ((unsigned long )rxs); - goto fail; +FRONT_RING_INIT (&info->rx, rxs,PAGE_SIZE * info->rx_ring_pages); + +for (j =0 ; j < info->rx_ring_pages; j++) { +void *addr = (void *)((unsigned long )rxs +PAGE_SIZE * j); + err =xenbus_grant_ring (dev,virt_to_mfn (addr)); +if (err <0 ) + goto grant_rx_ring_fail; + info->rx_ring_ref[j] = err; } - info->rx_ring_ref = err; err =xenbus_alloc_evtchn (dev, &info->evtchn);if (err) - goto fail; + goto alloc_evtchn_fail; err =bind_evtchn_to_irqhandler (info->evtchn, xennet_interrupt,0 , netdev->name, netdev);if (err <0 ) - goto fail; + goto bind_fail; netdev->irq = err; +return 0 ; - fail: +bind_fail: +xenbus_free_evtchn (dev, info->evtchn); +alloc_evtchn_fail: +for (; j >=0 ; j--) { +int ref = info->rx_ring_ref[j]; +gnttab_end_foreign_access_ref (ref,0 ); + info->rx_ring_ref[j] =GRANT_INVALID_REF ; + } +grant_rx_ring_fail: +dma_free_coherent (NULL ,PAGE_SIZE * info->rx_ring_pages, + (void *)rxs, info->rx_ring_dma_handle); +alloc_rx_ring_fail: +for (; i >=0 ; i--) { +int ref = info->tx_ring_ref[i]; +gnttab_end_foreign_access_ref (ref,0 ); + info->tx_ring_ref[i] =GRANT_INVALID_REF ; + } +grant_tx_ring_fail: +dma_free_coherent (NULL ,PAGE_SIZE * info->tx_ring_pages, + (void *)txs, info->tx_ring_dma_handle); +fail:return err; }
@@ -1550,6 +1632,7 @@ static int talk_to_netback(struct xenbus_device *dev,const char *message;struct xenbus_transaction xbt;int err; +int i;/* Create shared ring, alloc event channel. */ err =setup_netfront (dev, info);
@@ -1563,18 +1646,50 @@ again: goto destroy_ring; } - err =xenbus_printf (xbt, dev->nodename,"tx-ring-ref" ,"%u" , - info->tx_ring_ref); -if (err) { - message ="writing tx ring-ref" ; - goto abort_transaction; +if (info->tx_ring_page_order ==0 ) + err =xenbus_printf (xbt, dev->nodename,"tx-ring-ref" ,"%u" , + info->tx_ring_ref[0 ]); +else { + err =xenbus_printf (xbt, dev->nodename,"tx-ring-order" ,"%u" , + info->tx_ring_page_order); +if (err) { + message ="writing tx ring-ref" ; + goto abort_transaction; + } +for (i =0 ; i < info->tx_ring_pages; i++) { +char name[sizeof ("tx-ring-ref" )+2 ]; +snprintf (name,sizeof (name),"tx-ring-ref%u" , i); + err =xenbus_printf (xbt, dev->nodename, name,"%u" , + info->tx_ring_ref[i]); +if (err) { + message ="writing tx ring-ref" ; + goto abort_transaction; + } + } } - err =xenbus_printf (xbt, dev->nodename,"rx-ring-ref" ,"%u" , - info->rx_ring_ref); -if (err) { - message ="writing rx ring-ref" ; - goto abort_transaction; + +if (info->rx_ring_page_order ==0 ) + err =xenbus_printf (xbt, dev->nodename,"rx-ring-ref" ,"%u" , + info->rx_ring_ref[0 ]); +else { + err =xenbus_printf (xbt, dev->nodename,"rx-ring-order" ,"%u" , + info->rx_ring_page_order); +if (err) { + message ="writing tx ring-ref" ; + goto abort_transaction; + } +for (i =0 ; i < info->rx_ring_pages; i++) { +char name[sizeof ("rx-ring-ref" )+2 ]; +snprintf (name,sizeof (name),"rx-ring-ref%u" , i); + err =xenbus_printf (xbt, dev->nodename, name,"%u" , + info->rx_ring_ref[i]); +if (err) { + message ="writing rx ring-ref" ; + goto abort_transaction; + } + } } + err =xenbus_printf (xbt, dev->nodename,"event-channel" ,"%u" , info->evtchn);if (err) {
@@ -1661,7 +1776,8 @@ static int xennet_connect(struct net_device *dev)xennet_release_tx_bufs (np);/* Step 2: Rebuild the RX buffer freelist and the RX ring itself. */ -for (requeue_idx =0 , i =0 ; i <NET_RX_RING_SIZE ; i++) { +for (requeue_idx =0 , i =0 ; i <NET_RX_RING_SIZE (np->rx_ring_pages); + i++) {skb_frag_t *frag;const struct page *page;if (!np->rx_skbs[i])
Signature · 1 line
1.7.2.5
Re: [Xen-devel] [RFC PATCH V3 15/16] netfront: multi page ring support.
Quoted 263 lines · Wei Liu
Use DMA API to allocate ring pages, because we need to get machine contiginous memory.
Signed-off-by Wei Liu <[email protected]>--- drivers/net/xen-netfront.c | 258 ++++++++++++++++++++++++++++++++------------ 1 files changed, 187 insertions(+), 71 deletions(-)drivers/net/xen-netfront.c +76
-43@@ -66,9 +66,18 @@ struct netfront_cb {#define GRANT_INVALID_REF 0 -#define NET_TX_RING_SIZE __CONST_RING_SIZE(xen_netif_tx, PAGE_SIZE) -#define NET_RX_RING_SIZE __CONST_RING_SIZE(xen_netif_rx, PAGE_SIZE) -#define TX_MAX_TARGET min_t(int, NET_TX_RING_SIZE, 256) +#define XENNET_MAX_RING_PAGE_ORDER 2 +#define XENNET_MAX_RING_PAGES (1U << XENNET_MAX_RING_PAGE_ORDER) + +#define NET_TX_RING_SIZE (_nr_pages) \ + __CONST_RING_SIZE(xen_netif_tx, PAGE_SIZE * (_nr_pages)) +#define NET_RX_RING_SIZE (_nr_pages) \ + __CONST_RING_SIZE(xen_netif_rx, PAGE_SIZE * (_nr_pages)) + +#define XENNET_MAX_TX_RING_SIZE NET_TX_RING_SIZE(XENNET_MAX_RING_PAGES) +#define XENNET_MAX_RX_RING_SIZE NET_RX_RING_SIZE(XENNET_MAX_RING_PAGES) + +#define TX_MAX_TARGET XENNET_MAX_TX_RING_SIZEstruct netfront_stats {u64 rx_packets;@@ -84,12 +93,20 @@ struct netfront_info {struct napi_struct napi; +/* Statistics */ +struct netfront_stats __percpu *stats; + +unsigned long rx_gso_checksum_fixup; +unsigned int evtchn;struct xenbus_device *xbdev;spinlock_t tx_lock;struct xen_netif_tx_front_ring tx; -int tx_ring_ref; +dma_addr_t tx_ring_dma_handle; +int tx_ring_ref[XENNET_MAX_RING_PAGES ]; +int tx_ring_page_order; +int tx_ring_pages;/* * {tx,rx}_skbs store outstanding skbuffs. Free tx_skb entries @@ -103,36 +120,34 @@ struct netfront_info {union skb_entry {struct sk_buff *skb;unsigned long link; - } tx_skbs[NET_TX_RING_SIZE ]; + } tx_skbs[XENNET_MAX_TX_RING_SIZE ];grant_ref_t gref_tx_head; -grant_ref_t grant_tx_ref[NET_TX_RING_SIZE ]; +grant_ref_t grant_tx_ref[XENNET_MAX_TX_RING_SIZE ];unsigned tx_skb_freelist;spinlock_t rx_lock____cacheline_aligned_in_smp ;struct xen_netif_rx_front_ring rx; -int rx_ring_ref; +dma_addr_t rx_ring_dma_handle; +int rx_ring_ref[XENNET_MAX_RING_PAGES ]; +int rx_ring_page_order; +int rx_ring_pages;/* Receive-ring batched refills. */ #define RX_MIN_TARGET 8#define RX_DFL_MIN_TARGET 64 -#define RX_MAX_TARGET min_t(int, NET_RX_RING_SIZE, 256) +#define RX_MAX_TARGET XENNET_MAX_RX_RING_SIZEunsigned rx_min_target, rx_max_target, rx_target;struct sk_buff_head rx_batch;struct timer_list rx_refill_timer; -struct sk_buff *rx_skbs[NET_RX_RING_SIZE ]; +struct sk_buff *rx_skbs[XENNET_MAX_RX_RING_SIZE ];grant_ref_t gref_rx_head; -grant_ref_t grant_rx_ref[NET_RX_RING_SIZE ]; - -unsigned long rx_pfn_array[NET_RX_RING_SIZE ]; -struct multicall_entry rx_mcl[NET_RX_RING_SIZE +1 ]; -struct mmu_update rx_mmu[NET_RX_RING_SIZE ]; - -/* Statistics */ -struct netfront_stats __percpu *stats; +grant_ref_t grant_rx_ref[XENNET_MAX_RX_RING_SIZE ]; -unsigned long rx_gso_checksum_fixup; +unsigned long rx_pfn_array[XENNET_MAX_RX_RING_SIZE ]; +struct multicall_entry rx_mcl[XENNET_MAX_RX_RING_SIZE +1 ]; +struct mmu_update rx_mmu[XENNET_MAX_RX_RING_SIZE ]; };struct netfront_rx_info {@@ -170,15 +185,15 @@ static unsigned short get_id_from_freelist(unsigned *head,return id; } -static int xennet_rxidx (RING_IDX idx) +static int xennet_rxidx (RING_IDX idx,struct netfront_info *info) { -return idx & (NET_RX_RING_SIZE -1 ); +return idx & (NET_RX_RING_SIZE (info->rx_ring_pages) -1 ); }static struct sk_buff *xennet_get_rx_skb (struct netfront_info *np,RING_IDX ri) { -int i =xennet_rxidx (ri); +int i =xennet_rxidx (ri, np);struct sk_buff *skb = np->rx_skbs[i]; np->rx_skbs[i] =NULL ;return skb;@@ -187,7 +202,7 @@ static struct sk_buff *xennet_get_rx_skb(struct netfront_info *np,static grant_ref_t xennet_get_rx_ref (struct netfront_info *np,RING_IDX ri) { -int i =xennet_rxidx (ri); +int i =xennet_rxidx (ri, np);grant_ref_t ref = np->grant_rx_ref[i]; np->grant_rx_ref[i] =GRANT_INVALID_REF ;return ref;@@ -300,7 +315,7 @@ no_skb: skb->dev = dev; - id =xennet_rxidx (req_prod + i); + id =xennet_rxidx (req_prod + i, np);BUG_ON (np->rx_skbs[id]); np->rx_skbs[id] = skb;@@ -596,7 +611,7 @@ static int xennet_close(struct net_device *dev)static void xennet_move_rx_slot (struct netfront_info *np,struct sk_buff *skb,grant_ref_t ref) { -int new =xennet_rxidx (np->rx.req_prod_pvt); +int new =xennet_rxidx (np->rx.req_prod_pvt, np);BUG_ON (np->rx_skbs[new]); np->rx_skbs[new] = skb;@@ -1089,7 +1104,7 @@ static void xennet_release_tx_bufs(struct netfront_info *np)struct sk_buff *skb;int i; -for (i =0 ; i <NET_TX_RING_SIZE ; i++) { +for (i =0 ; i <NET_TX_RING_SIZE (np->tx_ring_pages); i++) {/* Skip over entries which are actually freelist references */ if (skb_entry_is_link (&np->tx_skbs[i]))continue ;@@ -1123,7 +1138,7 @@ static void xennet_release_rx_bufs(struct netfront_info *np)spin_lock_bh (&np->rx_lock); -for (id =0 ; id <NET_RX_RING_SIZE ; id++) { +for (id =0 ; id <NET_RX_RING_SIZE (np->rx_ring_pages); id++) { ref = np->grant_rx_ref[id];if (ref ==GRANT_INVALID_REF ) { unused++;@@ -1305,13 +1320,13 @@ static struct net_device * __devinit xennet_create_dev(struct xenbus_device *dev/* Initialise tx_skbs as a free chain containing every entry. */ np->tx_skb_freelist =0 ; -for (i =0 ; i <NET_TX_RING_SIZE ; i++) { +for (i =0 ; i <XENNET_MAX_TX_RING_SIZE ; i++) {skb_entry_set_link (&np->tx_skbs[i], i+1 ); np->grant_tx_ref[i] =GRANT_INVALID_REF ; }/* Clear out rx_skbs */ -for (i =0 ; i <NET_RX_RING_SIZE ; i++) { +for (i =0 ; i <XENNET_MAX_RX_RING_SIZE ; i++) { np->rx_skbs[i] =NULL ; np->grant_rx_ref[i] =GRANT_INVALID_REF ; }@@ -1409,15 +1424,11 @@ static int __devinit netfront_probe(struct xenbus_device *dev,return err; } -static void xennet_end_access (int ref,void *page) -{ -/* This frees the page as a side-effect */ -if (ref !=GRANT_INVALID_REF ) -gnttab_end_foreign_access (ref,0 , (unsigned long )page); -} -static void xennet_disconnect_backend (struct netfront_info *info) { +int i; +struct xenbus_device *dev = info->xbdev; +/* Stop old i/f to prevent errors whilst we rebuild the state. */ spin_lock_bh (&info->rx_lock);spin_lock_irq (&info->tx_lock);@@ -1429,12 +1440,24 @@ static void xennet_disconnect_backend(struct netfront_info *info)unbind_from_irqhandler (info->netdev->irq, info->netdev); info->evtchn = info->netdev->irq =0 ; -/* End access and free the pages */ -xennet_end_access (info->tx_ring_ref, info->tx.sring); -xennet_end_access (info->rx_ring_ref, info->rx.sring); +for (i =0 ; i < info->tx_ring_pages; i++) { +int ref = info->tx_ring_ref[i]; +gnttab_end_foreign_access_ref (ref,0 ); + info->tx_ring_ref[i] =GRANT_INVALID_REF ; + } +dma_free_coherent (NULL ,PAGE_SIZE * info->tx_ring_pages, + (void *)info->tx.sring, + info->tx_ring_dma_handle); + +for (i =0 ; i < info->rx_ring_pages; i++) { +int ref = info->rx_ring_ref[i]; +gnttab_end_foreign_access_ref (ref,0 ); + info->rx_ring_ref[i] =GRANT_INVALID_REF ; + } +dma_free_coherent (NULL ,PAGE_SIZE * info->rx_ring_pages, + (void *)info->rx.sring, + info->rx_ring_dma_handle); - info->tx_ring_ref =GRANT_INVALID_REF ; - info->rx_ring_ref =GRANT_INVALID_REF ; info->tx.sring =NULL ; info->rx.sring =NULL ; }@@ -1483,9 +1506,13 @@ static int setup_netfront(struct xenbus_device *dev, struct netfront_info *info)struct xen_netif_rx_sring *rxs;int err;struct net_device *netdev = info->netdev; +unsigned int max_tx_ring_page_order, max_rx_ring_page_order; +int i, j; - info->tx_ring_ref =GRANT_INVALID_REF ; - info->rx_ring_ref =GRANT_INVALID_REF ; +for (i =0 ; i <XENNET_MAX_RING_PAGES ; i++) { + info->tx_ring_ref[i] =GRANT_INVALID_REF ; + info->rx_ring_ref[i] =GRANT_INVALID_REF ; + } info->rx.sring =NULL ; info->tx.sring =NULL ; netdev->irq =0 ;@@ -1496,50 +1523,105 @@ static int setup_netfront(struct xenbus_device *dev, struct netfront_info *info) goto fail; } - txs = (struct xen_netif_tx_sring *)get_zeroed_page (GFP_NOIO | __GFP_HIGH); + err =xenbus_scanf (XBT_NIL , info->xbdev->otherend, +"max-tx-ring-page-order" ,"%u" , + &max_tx_ring_page_order); +if (err <0 ) { + info->tx_ring_page_order =0 ; +dev_info (&dev->dev,"single tx ring\n" ); + }else {
drivers/net/xen-netfront.c static int setup_netfront(struct xenbus_device *dev, struct netfront_info *info) · line 1542
Quoted 10 lines
drivers/net/xen-netfront.c +10
-0+ info->tx_ring_page_order = max_tx_ring_page_order; +dev_info (&dev->dev,"multi page tx ring, order = %d\n" , + max_tx_ring_page_order); + } + info->tx_ring_pages = (1U << info->tx_ring_page_order); + + txs = (struct xen_netif_tx_sring *) +dma_alloc_coherent (NULL ,PAGE_SIZE * info->tx_ring_pages, + &info->tx_ring_dma_handle, + __GFP_ZERO |GFP_NOIO | __GFP_HIGH);
Hm, so I see you are using 'NULL' which is a big nono (the API docs say that). But the other reason why it is a no-no, is b/c this way the generic DMA engine has no clue whether you are OK getting pages under 4GB or above it (so 64-bit support).
If you don't supply a 'dev' it will assume 4GB. But when you are run this as a pure PV guest that won't matter the slighest b/I there are no DMA code in action (well, there is dma_alloc_coherent - which looking at the code would NULL it seems).
Anyhow, if you get to have more than 4GB in the guest or do PCI passthrough and use 'iommu=soft'- at which point the Xen SWIOTLB will kick and you will end up 'swizzling' the pages to be under 4GB. That can be fixed if you declerae a 'fake' device where you set the coherent_dma_mask to DMA_BIT_MASK(64).
But if you boot the guest under HVM, then it will use the generic SWIOTLB code, which won't guaranteeing the pages to be "machine" contingous but will be "guest machine" contingous. Is that sufficient for this?
How did you test this? Did you supply iommu=soft to your guest or booted it with more than 4GB?
Quoted 189 lines
drivers/net/xen-netfront.c +101
-28if (!txs) { err = -ENOMEM ;xenbus_dev_fatal (dev, err,"allocating tx ring page" ); goto fail; }SHARED_RING_INIT (txs); -FRONT_RING_INIT (&info->tx, txs,PAGE_SIZE ); +FRONT_RING_INIT (&info->tx, txs,PAGE_SIZE * info->tx_ring_pages); + +for (i =0 ; i < info->tx_ring_pages; i++) { +void *addr = (void *)((unsigned long )txs +PAGE_SIZE * i); + err =xenbus_grant_ring (dev,virt_to_mfn (addr)); +if (err <0 ) + goto grant_tx_ring_fail; + info->tx_ring_ref[i] = err; + } - err =xenbus_grant_ring (dev,virt_to_mfn (txs)); + err =xenbus_scanf (XBT_NIL , info->xbdev->otherend, +"max-rx-ring-page-order" ,"%u" , + &max_rx_ring_page_order);if (err <0 ) { -free_page ((unsigned long )txs); - goto fail; + info->rx_ring_page_order =0 ; +dev_info (&dev->dev,"single rx ring\n" ); + }else { + info->rx_ring_page_order = max_rx_ring_page_order; +dev_info (&dev->dev,"multi page rx ring, order = %d\n" , + max_rx_ring_page_order); } + info->rx_ring_pages = (1U << info->rx_ring_page_order); - info->tx_ring_ref = err; - rxs = (struct xen_netif_rx_sring *)get_zeroed_page (GFP_NOIO | __GFP_HIGH); + rxs = (struct xen_netif_rx_sring *) +dma_alloc_coherent (NULL ,PAGE_SIZE * info->rx_ring_pages, + &info->rx_ring_dma_handle, + __GFP_ZERO |GFP_NOIO | __GFP_HIGH);if (!rxs) { err = -ENOMEM ;xenbus_dev_fatal (dev, err,"allocating rx ring page" ); - goto fail; + goto alloc_rx_ring_fail; }SHARED_RING_INIT (rxs); -FRONT_RING_INIT (&info->rx, rxs,PAGE_SIZE ); - - err =xenbus_grant_ring (dev,virt_to_mfn (rxs)); -if (err <0 ) { -free_page ((unsigned long )rxs); - goto fail; +FRONT_RING_INIT (&info->rx, rxs,PAGE_SIZE * info->rx_ring_pages); + +for (j =0 ; j < info->rx_ring_pages; j++) { +void *addr = (void *)((unsigned long )rxs +PAGE_SIZE * j); + err =xenbus_grant_ring (dev,virt_to_mfn (addr)); +if (err <0 ) + goto grant_rx_ring_fail; + info->rx_ring_ref[j] = err; } - info->rx_ring_ref = err; err =xenbus_alloc_evtchn (dev, &info->evtchn);if (err) - goto fail; + goto alloc_evtchn_fail; err =bind_evtchn_to_irqhandler (info->evtchn, xennet_interrupt,0 , netdev->name, netdev);if (err <0 ) - goto fail; + goto bind_fail; netdev->irq = err; +return 0 ; - fail: +bind_fail: +xenbus_free_evtchn (dev, info->evtchn); +alloc_evtchn_fail: +for (; j >=0 ; j--) { +int ref = info->rx_ring_ref[j]; +gnttab_end_foreign_access_ref (ref,0 ); + info->rx_ring_ref[j] =GRANT_INVALID_REF ; + } +grant_rx_ring_fail: +dma_free_coherent (NULL ,PAGE_SIZE * info->rx_ring_pages, + (void *)rxs, info->rx_ring_dma_handle); +alloc_rx_ring_fail: +for (; i >=0 ; i--) { +int ref = info->tx_ring_ref[i]; +gnttab_end_foreign_access_ref (ref,0 ); + info->tx_ring_ref[i] =GRANT_INVALID_REF ; + } +grant_tx_ring_fail: +dma_free_coherent (NULL ,PAGE_SIZE * info->tx_ring_pages, + (void *)txs, info->tx_ring_dma_handle); +fail:return err; }@@ -1550,6 +1632,7 @@ static int talk_to_netback(struct xenbus_device *dev,const char *message;struct xenbus_transaction xbt;int err; +int i;/* Create shared ring, alloc event channel. */ err =setup_netfront (dev, info);@@ -1563,18 +1646,50 @@ again: goto destroy_ring; } - err =xenbus_printf (xbt, dev->nodename,"tx-ring-ref" ,"%u" , - info->tx_ring_ref); -if (err) { - message ="writing tx ring-ref" ; - goto abort_transaction; +if (info->tx_ring_page_order ==0 ) + err =xenbus_printf (xbt, dev->nodename,"tx-ring-ref" ,"%u" , + info->tx_ring_ref[0 ]); +else { + err =xenbus_printf (xbt, dev->nodename,"tx-ring-order" ,"%u" , + info->tx_ring_page_order); +if (err) { + message ="writing tx ring-ref" ; + goto abort_transaction; + } +for (i =0 ; i < info->tx_ring_pages; i++) { +char name[sizeof ("tx-ring-ref" )+2 ]; +snprintf (name,sizeof (name),"tx-ring-ref%u" , i); + err =xenbus_printf (xbt, dev->nodename, name,"%u" , + info->tx_ring_ref[i]); +if (err) { + message ="writing tx ring-ref" ; + goto abort_transaction; + } + } } - err =xenbus_printf (xbt, dev->nodename,"rx-ring-ref" ,"%u" , - info->rx_ring_ref); -if (err) { - message ="writing rx ring-ref" ; - goto abort_transaction; + +if (info->rx_ring_page_order ==0 ) + err =xenbus_printf (xbt, dev->nodename,"rx-ring-ref" ,"%u" , + info->rx_ring_ref[0 ]); +else { + err =xenbus_printf (xbt, dev->nodename,"rx-ring-order" ,"%u" , + info->rx_ring_page_order); +if (err) { + message ="writing tx ring-ref" ; + goto abort_transaction; + } +for (i =0 ; i < info->rx_ring_pages; i++) { +char name[sizeof ("rx-ring-ref" )+2 ]; +snprintf (name,sizeof (name),"rx-ring-ref%u" , i); + err =xenbus_printf (xbt, dev->nodename, name,"%u" , + info->rx_ring_ref[i]); +if (err) { + message ="writing rx ring-ref" ; + goto abort_transaction; + } + } } + err =xenbus_printf (xbt, dev->nodename,"event-channel" ,"%u" , info->evtchn);if (err) {@@ -1661,7 +1776,8 @@ static int xennet_connect(struct net_device *dev)xennet_release_tx_bufs (np);/* Step 2: Rebuild the RX buffer freelist and the RX ring itself. */ -for (requeue_idx =0 , i =0 ; i <NET_RX_RING_SIZE ; i++) { +for (requeue_idx =0 , i =0 ; i <NET_RX_RING_SIZE (np->rx_ring_pages); + i++) {skb_frag_t *frag;const struct page *page;if (!np->rx_skbs[i])Signature · 7 lines
1.7.2.5 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xensource.com/xen-devel
Re: [Xen-devel] [RFC PATCH V3 15/16] netfront: multi page ring support.
On Mon, 2012-01-30 at 21:39 +0000, Konrad Rzeszutek Wilk wrote:
[...snip... please do consider trimming unnecessary quotes]
Quoted 18 lines
Quoted 18 lines
drivers/net/xen-netfront.c +13
-1@@ -1496,50 +1523,105 @@ static int setup_netfront(struct xenbus_device *dev, struct netfront_info *info) goto fail; } - txs = (struct xen_netif_tx_sring *)get_zeroed_page (GFP_NOIO | __GFP_HIGH); + err =xenbus_scanf (XBT_NIL , info->xbdev->otherend, +"max-tx-ring-page-order" ,"%u" , + &max_tx_ring_page_order); +if (err <0 ) { + info->tx_ring_page_order =0 ; +dev_info (&dev->dev,"single tx ring\n" ); + }else { + info->tx_ring_page_order = max_tx_ring_page_order; +dev_info (&dev->dev,"multi page tx ring, order = %d\n" , + max_tx_ring_page_order); + } + info->tx_ring_pages = (1U << info->tx_ring_page_order); +
Quoted 8 lines
drivers/net/xen-netfront.c static int setup_netfront(struct xenbus_device *dev, struct netfront_info *info) · line 1542
Quoted 4 lines
drivers/net/xen-netfront.c +4
-0+ txs = (struct xen_netif_tx_sring *) +dma_alloc_coherent (NULL ,PAGE_SIZE * info->tx_ring_pages, + &info->tx_ring_dma_handle, + __GFP_ZERO |GFP_NOIO | __GFP_HIGH);Hm, so I see you are using 'NULL' which is a big nono (the API docs say that). But the other reason why it is a no-no, is b/c this way the generic DMA engine has no clue whether you are OK getting pages under 4GB or above it (so 64-bit support).
Does this allocation even need to be physically contiguous? I'd have thought that virtually contiguous would be sufficient, and even then only as a convenience at either end to avoid the need for more complicated ring macros.
Ian.
Re: [Xen-devel] [RFC PATCH V3 15/16] netfront: multi page ring support.
Quoted 31 lines · Ian Campbell
On Mon, 2012-01-30 at 21:39 +0000, Konrad Rzeszutek Wilk wrote:
[...snip... please do consider trimming unnecessary quotes]
Quoted 18 lines
Quoted 18 lines
drivers/net/xen-netfront.c +13
-1@@ -1496,50 +1523,105 @@ static int setup_netfront(struct xenbus_device *dev, struct netfront_info *info) goto fail; } - txs = (struct xen_netif_tx_sring *)get_zeroed_page (GFP_NOIO | __GFP_HIGH); + err =xenbus_scanf (XBT_NIL , info->xbdev->otherend, +"max-tx-ring-page-order" ,"%u" , + &max_tx_ring_page_order); +if (err <0 ) { + info->tx_ring_page_order =0 ; +dev_info (&dev->dev,"single tx ring\n" ); + }else { + info->tx_ring_page_order = max_tx_ring_page_order; +dev_info (&dev->dev,"multi page tx ring, order = %d\n" , + max_tx_ring_page_order); + } + info->tx_ring_pages = (1U << info->tx_ring_page_order); +Quoted 8 lines
drivers/net/xen-netfront.c static int setup_netfront(struct xenbus_device *dev, struct netfront_info *info) · line 1542
Quoted 4 lines
drivers/net/xen-netfront.c +4
-0+ txs = (struct xen_netif_tx_sring *) +dma_alloc_coherent (NULL ,PAGE_SIZE * info->tx_ring_pages, + &info->tx_ring_dma_handle, + __GFP_ZERO |GFP_NOIO | __GFP_HIGH);Hm, so I see you are using 'NULL' which is a big nono (the API docs say that). But the other reason why it is a no-no, is b/c this way the generic DMA engine has no clue whether you are OK getting pages under 4GB or above it (so 64-bit support).
Quoted 5 lines
Does this allocation even need to be physically contiguous? I'd have thought that virtually contiguous would be sufficient, and even then only as a convenience at either end to avoid the need for more complicated ring macros.
I had a second thought about this, you're right. I just need to make sure it is virtually contiguous in both frontend and backend, that's sufficient.
Wei.
Quoted 3 lines
Ian.
Re: [Xen-devel] [RFC PATCH V3 15/16] netfront: multi page ring support.
In reply to Konrad Rzeszutek WilkQuoted 48 lines
Quoted 1 line
Quoted 1 line · Konrad Rzeszutek Wilk
Review static int setup_netfront(struct xenbus_device *dev,
Quoted 1 line · Wei Liu
(quoted diff) +0
-0@@ -1496,50 +1523,105 @@ static int setup_netfront(struct xenbus_device *dev,struct
netfront_info*info)Quoted 11 lines
drivers/net/xen-netfront.c +7
-1goto fail; } - txs = (struct xen_netif_tx_sring *)get_zeroed_page (GFP_NOIO | __GFP_HIGH); + err =xenbus_scanf (XBT_NIL , info->xbdev->otherend, +"max-tx-ring-page-order" ,"%u" , + &max_tx_ring_page_order); +if (err <0 ) { + info->tx_ring_page_order =0 ; +dev_info (&dev->dev,"single tx ring\n" ); + }else {drivers/net/xen-netfront.c static int setup_netfront(struct xenbus_device *dev, struct netfront_info *info) · line 1542
Quoted 10 lines
drivers/net/xen-netfront.c +10
-0+ info->tx_ring_page_order = max_tx_ring_page_order; +dev_info (&dev->dev,"multi page tx ring, order = %d\n" , + max_tx_ring_page_order); + } + info->tx_ring_pages = (1U << info->tx_ring_page_order); + + txs = (struct xen_netif_tx_sring *) +dma_alloc_coherent (NULL ,PAGE_SIZE * info->tx_ring_pages, + &info->tx_ring_dma_handle, + __GFP_ZERO |GFP_NOIO | __GFP_HIGH);Hm, so I see you are using 'NULL' which is a big nono (the API docs say that).
But the other reason why it is a no-no, is b/c this way the generic DMA engine has no
clue whether you are OK getting pages under 4GB or above it (so 64-bit support).If you don't supply a 'dev' it will assume 4GB. But when you are run this as a
pure PV guest that won't matter the slighest b/I there are no DMA code in action
(well, there isdma_alloc_coherent- which looking at the code would NULL it seems).Anyhow, if you get to have more than 4GB in the guest or do PCI passthrough and use
'iommu=soft'- at which point the Xen SWIOTLB will kick and you will end up 'swizzling'
the pages to be under 4GB. That can be fixed if you declerae a 'fake' device where you set
thecoherent_dma_masktoDMA_BIT_MASK(64).
Quoted 8 lines
But if you boot the guest under HVM, then it will use the generic SWIOTLB code, which
won't guaranteeing the pages to be "machine" contingous but will be "guest machine"
contingous. Is that sufficient for this?How did you test this? Did you supply iommu=soft to your guest or booted it with more than 4GB?
Imo the use of the DMA API is a mistake here anyway. There's no need for anything to be contiguous in a PV frontend/backend handshake protocol, or if one finds there is it's very likely just because of trying to avoid doing something properly.
Jan
Re: [Xen-devel] [RFC PATCH V3 15/16] netfront: multi page ring support.
Quoted 7 lines · Jan Beulich
Quoted 1 line
with more than 4GB?
Imo the use of the DMA API is a mistake here anyway. There's no need for anything to be contiguous in a PV frontend/backend handshake protocol, or if one finds there is it's very likely just because of trying to avoid doing something properly.
Seems you're right. I look at the backend code again, I make use of vm_struct to create a contiguous area in backend kernel. In fact I can avoid DMA API completely. ;-)
Wei.
Quoted 2 lines
Jan
Re: [Xen-devel] [RFC PATCH V3 15/16] netfront: multi page ring support.
In reply to Konrad Rzeszutek WilkQuoted 279 lines · Konrad Rzeszutek Wilk
Quoted 263 lines · Wei Liu
Use DMA API to allocate ring pages, because we need to get machine contiginous memory.
Signed-off-by Wei Liu <[email protected]>--- drivers/net/xen-netfront.c | 258 ++++++++++++++++++++++++++++++++------------ 1 files changed, 187 insertions(+), 71 deletions(-)drivers/net/xen-netfront.c +76
-43@@ -66,9 +66,18 @@ struct netfront_cb {#define GRANT_INVALID_REF 0 -#define NET_TX_RING_SIZE __CONST_RING_SIZE(xen_netif_tx, PAGE_SIZE) -#define NET_RX_RING_SIZE __CONST_RING_SIZE(xen_netif_rx, PAGE_SIZE) -#define TX_MAX_TARGET min_t(int, NET_TX_RING_SIZE, 256) +#define XENNET_MAX_RING_PAGE_ORDER 2 +#define XENNET_MAX_RING_PAGES (1U << XENNET_MAX_RING_PAGE_ORDER) + +#define NET_TX_RING_SIZE (_nr_pages) \ + __CONST_RING_SIZE(xen_netif_tx, PAGE_SIZE * (_nr_pages)) +#define NET_RX_RING_SIZE (_nr_pages) \ + __CONST_RING_SIZE(xen_netif_rx, PAGE_SIZE * (_nr_pages)) + +#define XENNET_MAX_TX_RING_SIZE NET_TX_RING_SIZE(XENNET_MAX_RING_PAGES) +#define XENNET_MAX_RX_RING_SIZE NET_RX_RING_SIZE(XENNET_MAX_RING_PAGES) + +#define TX_MAX_TARGET XENNET_MAX_TX_RING_SIZEstruct netfront_stats {u64 rx_packets;@@ -84,12 +93,20 @@ struct netfront_info {struct napi_struct napi; +/* Statistics */ +struct netfront_stats __percpu *stats; + +unsigned long rx_gso_checksum_fixup; +unsigned int evtchn;struct xenbus_device *xbdev;spinlock_t tx_lock;struct xen_netif_tx_front_ring tx; -int tx_ring_ref; +dma_addr_t tx_ring_dma_handle; +int tx_ring_ref[XENNET_MAX_RING_PAGES ]; +int tx_ring_page_order; +int tx_ring_pages;/* * {tx,rx}_skbs store outstanding skbuffs. Free tx_skb entries @@ -103,36 +120,34 @@ struct netfront_info {union skb_entry {struct sk_buff *skb;unsigned long link; - } tx_skbs[NET_TX_RING_SIZE ]; + } tx_skbs[XENNET_MAX_TX_RING_SIZE ];grant_ref_t gref_tx_head; -grant_ref_t grant_tx_ref[NET_TX_RING_SIZE ]; +grant_ref_t grant_tx_ref[XENNET_MAX_TX_RING_SIZE ];unsigned tx_skb_freelist;spinlock_t rx_lock____cacheline_aligned_in_smp ;struct xen_netif_rx_front_ring rx; -int rx_ring_ref; +dma_addr_t rx_ring_dma_handle; +int rx_ring_ref[XENNET_MAX_RING_PAGES ]; +int rx_ring_page_order; +int rx_ring_pages;/* Receive-ring batched refills. */ #define RX_MIN_TARGET 8#define RX_DFL_MIN_TARGET 64 -#define RX_MAX_TARGET min_t(int, NET_RX_RING_SIZE, 256) +#define RX_MAX_TARGET XENNET_MAX_RX_RING_SIZEunsigned rx_min_target, rx_max_target, rx_target;struct sk_buff_head rx_batch;struct timer_list rx_refill_timer; -struct sk_buff *rx_skbs[NET_RX_RING_SIZE ]; +struct sk_buff *rx_skbs[XENNET_MAX_RX_RING_SIZE ];grant_ref_t gref_rx_head; -grant_ref_t grant_rx_ref[NET_RX_RING_SIZE ]; - -unsigned long rx_pfn_array[NET_RX_RING_SIZE ]; -struct multicall_entry rx_mcl[NET_RX_RING_SIZE +1 ]; -struct mmu_update rx_mmu[NET_RX_RING_SIZE ]; - -/* Statistics */ -struct netfront_stats __percpu *stats; +grant_ref_t grant_rx_ref[XENNET_MAX_RX_RING_SIZE ]; -unsigned long rx_gso_checksum_fixup; +unsigned long rx_pfn_array[XENNET_MAX_RX_RING_SIZE ]; +struct multicall_entry rx_mcl[XENNET_MAX_RX_RING_SIZE +1 ]; +struct mmu_update rx_mmu[XENNET_MAX_RX_RING_SIZE ]; };struct netfront_rx_info {@@ -170,15 +185,15 @@ static unsigned short get_id_from_freelist(unsigned *head,return id; } -static int xennet_rxidx (RING_IDX idx) +static int xennet_rxidx (RING_IDX idx,struct netfront_info *info) { -return idx & (NET_RX_RING_SIZE -1 ); +return idx & (NET_RX_RING_SIZE (info->rx_ring_pages) -1 ); }static struct sk_buff *xennet_get_rx_skb (struct netfront_info *np,RING_IDX ri) { -int i =xennet_rxidx (ri); +int i =xennet_rxidx (ri, np);struct sk_buff *skb = np->rx_skbs[i]; np->rx_skbs[i] =NULL ;return skb;@@ -187,7 +202,7 @@ static struct sk_buff *xennet_get_rx_skb(struct netfront_info *np,static grant_ref_t xennet_get_rx_ref (struct netfront_info *np,RING_IDX ri) { -int i =xennet_rxidx (ri); +int i =xennet_rxidx (ri, np);grant_ref_t ref = np->grant_rx_ref[i]; np->grant_rx_ref[i] =GRANT_INVALID_REF ;return ref;@@ -300,7 +315,7 @@ no_skb: skb->dev = dev; - id =xennet_rxidx (req_prod + i); + id =xennet_rxidx (req_prod + i, np);BUG_ON (np->rx_skbs[id]); np->rx_skbs[id] = skb;@@ -596,7 +611,7 @@ static int xennet_close(struct net_device *dev)static void xennet_move_rx_slot (struct netfront_info *np,struct sk_buff *skb,grant_ref_t ref) { -int new =xennet_rxidx (np->rx.req_prod_pvt); +int new =xennet_rxidx (np->rx.req_prod_pvt, np);BUG_ON (np->rx_skbs[new]); np->rx_skbs[new] = skb;@@ -1089,7 +1104,7 @@ static void xennet_release_tx_bufs(struct netfront_info *np)struct sk_buff *skb;int i; -for (i =0 ; i <NET_TX_RING_SIZE ; i++) { +for (i =0 ; i <NET_TX_RING_SIZE (np->tx_ring_pages); i++) {/* Skip over entries which are actually freelist references */ if (skb_entry_is_link (&np->tx_skbs[i]))continue ;@@ -1123,7 +1138,7 @@ static void xennet_release_rx_bufs(struct netfront_info *np)spin_lock_bh (&np->rx_lock); -for (id =0 ; id <NET_RX_RING_SIZE ; id++) { +for (id =0 ; id <NET_RX_RING_SIZE (np->rx_ring_pages); id++) { ref = np->grant_rx_ref[id];if (ref ==GRANT_INVALID_REF ) { unused++;@@ -1305,13 +1320,13 @@ static struct net_device * __devinit xennet_create_dev(struct xenbus_device *dev/* Initialise tx_skbs as a free chain containing every entry. */ np->tx_skb_freelist =0 ; -for (i =0 ; i <NET_TX_RING_SIZE ; i++) { +for (i =0 ; i <XENNET_MAX_TX_RING_SIZE ; i++) {skb_entry_set_link (&np->tx_skbs[i], i+1 ); np->grant_tx_ref[i] =GRANT_INVALID_REF ; }/* Clear out rx_skbs */ -for (i =0 ; i <NET_RX_RING_SIZE ; i++) { +for (i =0 ; i <XENNET_MAX_RX_RING_SIZE ; i++) { np->rx_skbs[i] =NULL ; np->grant_rx_ref[i] =GRANT_INVALID_REF ; }@@ -1409,15 +1424,11 @@ static int __devinit netfront_probe(struct xenbus_device *dev,return err; } -static void xennet_end_access (int ref,void *page) -{ -/* This frees the page as a side-effect */ -if (ref !=GRANT_INVALID_REF ) -gnttab_end_foreign_access (ref,0 , (unsigned long )page); -} -static void xennet_disconnect_backend (struct netfront_info *info) { +int i; +struct xenbus_device *dev = info->xbdev; +/* Stop old i/f to prevent errors whilst we rebuild the state. */ spin_lock_bh (&info->rx_lock);spin_lock_irq (&info->tx_lock);@@ -1429,12 +1440,24 @@ static void xennet_disconnect_backend(struct netfront_info *info)unbind_from_irqhandler (info->netdev->irq, info->netdev); info->evtchn = info->netdev->irq =0 ; -/* End access and free the pages */ -xennet_end_access (info->tx_ring_ref, info->tx.sring); -xennet_end_access (info->rx_ring_ref, info->rx.sring); +for (i =0 ; i < info->tx_ring_pages; i++) { +int ref = info->tx_ring_ref[i]; +gnttab_end_foreign_access_ref (ref,0 ); + info->tx_ring_ref[i] =GRANT_INVALID_REF ; + } +dma_free_coherent (NULL ,PAGE_SIZE * info->tx_ring_pages, + (void *)info->tx.sring, + info->tx_ring_dma_handle); + +for (i =0 ; i < info->rx_ring_pages; i++) { +int ref = info->rx_ring_ref[i]; +gnttab_end_foreign_access_ref (ref,0 ); + info->rx_ring_ref[i] =GRANT_INVALID_REF ; + } +dma_free_coherent (NULL ,PAGE_SIZE * info->rx_ring_pages, + (void *)info->rx.sring, + info->rx_ring_dma_handle); - info->tx_ring_ref =GRANT_INVALID_REF ; - info->rx_ring_ref =GRANT_INVALID_REF ; info->tx.sring =NULL ; info->rx.sring =NULL ; }@@ -1483,9 +1506,13 @@ static int setup_netfront(struct xenbus_device *dev, struct netfront_info *info)struct xen_netif_rx_sring *rxs;int err;struct net_device *netdev = info->netdev; +unsigned int max_tx_ring_page_order, max_rx_ring_page_order; +int i, j; - info->tx_ring_ref =GRANT_INVALID_REF ; - info->rx_ring_ref =GRANT_INVALID_REF ; +for (i =0 ; i <XENNET_MAX_RING_PAGES ; i++) { + info->tx_ring_ref[i] =GRANT_INVALID_REF ; + info->rx_ring_ref[i] =GRANT_INVALID_REF ; + } info->rx.sring =NULL ; info->tx.sring =NULL ; netdev->irq =0 ;@@ -1496,50 +1523,105 @@ static int setup_netfront(struct xenbus_device *dev, struct netfront_info *info) goto fail; } - txs = (struct xen_netif_tx_sring *)get_zeroed_page (GFP_NOIO | __GFP_HIGH); + err =xenbus_scanf (XBT_NIL , info->xbdev->otherend, +"max-tx-ring-page-order" ,"%u" , + &max_tx_ring_page_order); +if (err <0 ) { + info->tx_ring_page_order =0 ; +dev_info (&dev->dev,"single tx ring\n" ); + }else {drivers/net/xen-netfront.c static int setup_netfront(struct xenbus_device *dev, struct netfront_info *info) · line 1542
Quoted 10 lines
drivers/net/xen-netfront.c +10
-0+ info->tx_ring_page_order = max_tx_ring_page_order; +dev_info (&dev->dev,"multi page tx ring, order = %d\n" , + max_tx_ring_page_order); + } + info->tx_ring_pages = (1U << info->tx_ring_page_order); + + txs = (struct xen_netif_tx_sring *) +dma_alloc_coherent (NULL ,PAGE_SIZE * info->tx_ring_pages, + &info->tx_ring_dma_handle, + __GFP_ZERO |GFP_NOIO | __GFP_HIGH);Hm, so I see you are using 'NULL' which is a big nono (the API docs say that). But the other reason why it is a no-no, is b/c this way the generic DMA engine has no clue whether you are OK getting pages under 4GB or above it (so 64-bit support).
Quoted 9 lines
If you don't supply a 'dev' it will assume 4GB. But when you are run this as a pure PV guest that won't matter the slighest b/I there are no DMA code in action (well, there is
dma_alloc_coherent- which looking at the code would NULL it seems).Anyhow, if you get to have more than 4GB in the guest or do PCI passthrough and use 'iommu=soft'- at which point the Xen SWIOTLB will kick and you will end up 'swizzling' the pages to be under 4GB. That can be fixed if you declerae a 'fake' device where you set the
coherent_dma_masktoDMA_BIT_MASK(64).
This seems to be a reasonable solution. I could not set netfront's DMA mask, that's why I used NULL device. And, how do I create a 'fake' device?
Quoted 4 lines
But if you boot the guest under HVM, then it will use the generic SWIOTLB code, which won't guaranteeing the pages to be "machine" contingous but will be "guest machine" contingous. Is that sufficient for this?
For HVM, this is sufficient.
Quoted 3 lines
How did you test this? Did you supply iommu=soft to your guest or booted it with more than 4GB?
I haven't tested guest with more than 4GB RAM.
Wei.
RFC PATCH v3 16/16 netfront: split event channels support.
In reply to Wei LiuIf this feature is not activated, rx_irq = tx_irq. See corresponding netback change log for details.
--- drivers/net/xen-netfront.c | 147 ++++++++++++++++++++++++++++++++++---------- 1 files changed, 115 insertions(+), 32 deletions(-)
drivers/net/xen-netfront.c +115 -32
@@ -98,7 +98,9 @@ struct netfront_info {unsigned long rx_gso_checksum_fixup; -unsigned int evtchn; +unsigned int split_evtchn; +unsigned int tx_evtchn, rx_evtchn; +unsigned int tx_irq, rx_irq;struct xenbus_device *xbdev;spinlock_t tx_lock;
@@ -344,7 +346,7 @@ no_skb: push:RING_PUSH_REQUESTS_AND_CHECK_NOTIFY (&np->rx, notify);if (notify) -notify_remote_via_irq (np->netdev->irq); +notify_remote_via_irq (np->rx_irq); }static int xennet_open (struct net_device *dev)
@@ -577,7 +579,7 @@ static int xennet_start_xmit(struct sk_buff *skb, struct net_device *dev)RING_PUSH_REQUESTS_AND_CHECK_NOTIFY (&np->tx, notify);if (notify) -notify_remote_via_irq (np->netdev->irq); +notify_remote_via_irq (np->tx_irq);u64_stats_update_begin (&stats->syncp); stats->tx_bytes += skb->len;
@@ -1242,22 +1244,35 @@ static int xennet_set_features(struct net_device *dev, u32 features)return 0 ; } -static irqreturn_t xennet_interrupt (int irq,void *dev_id) +static irqreturn_t xennet_tx_interrupt (int irq,void *dev_id) { -struct net_device *dev = dev_id; -struct netfront_info *np =netdev_priv (dev); +struct netfront_info *np = dev_id; +struct net_device *dev = np->netdev;unsigned long flags;spin_lock_irqsave (&np->tx_lock, flags); +xennet_tx_buf_gc (dev); +spin_unlock_irqrestore (&np->tx_lock, flags); -if (likely (netif_carrier_ok (dev))) { -xennet_tx_buf_gc (dev); -/* Under tx_lock: protects access to rx shared-ring indexes. */ -if (RING_HAS_UNCONSUMED_RESPONSES (&np->rx)) -napi_schedule (&np->napi); - } +return IRQ_HANDLED ; +} -spin_unlock_irqrestore (&np->tx_lock, flags); +static irqreturn_t xennet_rx_interrupt (int irq,void *dev_id) +{ +struct netfront_info *np = dev_id; +struct net_device *dev = np->netdev; + +if (likely (netif_carrier_ok (dev)) && +RING_HAS_UNCONSUMED_RESPONSES (&np->rx)) +napi_schedule (&np->napi); + +return IRQ_HANDLED ; +} +static irqreturn_t xennet_interrupt (int irq,void *dev_id) +{ +xennet_tx_interrupt (0 , dev_id); + +xennet_rx_interrupt (0 , dev_id);return IRQ_HANDLED ; }
@@ -1436,9 +1451,14 @@ static void xennet_disconnect_backend(struct netfront_info *info)spin_unlock_irq (&info->tx_lock);spin_unlock_bh (&info->rx_lock); -if (info->netdev->irq) -unbind_from_irqhandler (info->netdev->irq, info->netdev); - info->evtchn = info->netdev->irq =0 ; +if (info->tx_irq && (info->tx_irq == info->rx_irq)) +unbind_from_irqhandler (info->tx_irq, info); +if (info->tx_irq && (info->tx_irq != info->rx_irq)) { +unbind_from_irqhandler (info->tx_irq, info); +unbind_from_irqhandler (info->rx_irq, info); + } + info->tx_evtchn = info->tx_irq =0 ; + info->rx_evtchn = info->rx_irq =0 ;for (i =0 ; i < info->tx_ring_pages; i++) {int ref = info->tx_ring_ref[i];
@@ -1507,6 +1527,7 @@ static int setup_netfront(struct xenbus_device *dev, struct netfront_info *info)int err;struct net_device *netdev = info->netdev;unsigned int max_tx_ring_page_order, max_rx_ring_page_order; +unsigned int split_evtchn;int i, j;for (i =0 ; i <XENNET_MAX_RING_PAGES ; i++) {
@@ -1515,7 +1536,6 @@ static int setup_netfront(struct xenbus_device *dev, struct netfront_info *info) } info->rx.sring =NULL ; info->tx.sring =NULL ; - netdev->irq =0 ; err =xen_net_read_mac (dev, netdev->dev_addr);if (err) {
@@ -1524,6 +1544,12 @@ static int setup_netfront(struct xenbus_device *dev, struct netfront_info *info) } err =xenbus_scanf (XBT_NIL , info->xbdev->otherend, +"split-event-channels" ,"%u" , + &split_evtchn); +if (err <0 ) + split_evtchn =0 ; + + err =xenbus_scanf (XBT_NIL , info->xbdev->otherend,"max-tx-ring-page-order" ,"%u" , &max_tx_ring_page_order);if (err <0 ) {
@@ -1589,20 +1615,59 @@ static int setup_netfront(struct xenbus_device *dev, struct netfront_info *info) info->rx_ring_ref[j] = err; } - err =xenbus_alloc_evtchn (dev, &info->evtchn); -if (err) - goto alloc_evtchn_fail; +if (!split_evtchn) { + err =xenbus_alloc_evtchn (dev, &info->tx_evtchn); +if (err) + goto alloc_evtchn_fail; - err =bind_evtchn_to_irqhandler (info->evtchn, xennet_interrupt, -0 , netdev->name, netdev); -if (err <0 ) - goto bind_fail; - netdev->irq = err; + err =bind_evtchn_to_irqhandler (info->tx_evtchn, + xennet_interrupt, +0 , netdev->name, info); +if (err <0 ) + goto bind_fail; + info->rx_evtchn = info->tx_evtchn; + info->tx_irq = info->rx_irq = err; + info->split_evtchn =0 ; +dev_info (&dev->dev,"single event channel, irq = %d\n" , + info->tx_irq); + }else { + err =xenbus_alloc_evtchn (dev, &info->tx_evtchn); +if (err) + goto alloc_evtchn_fail; + err =xenbus_alloc_evtchn (dev, &info->rx_evtchn); +if (err) { +xenbus_free_evtchn (dev, info->tx_evtchn); + goto alloc_evtchn_fail; + } + err =bind_evtchn_to_irqhandler (info->tx_evtchn, + xennet_tx_interrupt, +0 , netdev->name, info); +if (err <0 ) + goto bind_fail; + info->tx_irq = err; + err =bind_evtchn_to_irqhandler (info->rx_evtchn, + xennet_rx_interrupt, +0 , netdev->name, info); +if (err <0 ) { +unbind_from_irqhandler (info->tx_irq, info); + goto bind_fail; + } + info->rx_irq = err; + info->split_evtchn =1 ; +dev_info (&dev->dev,"split event channels," +" tx_irq = %d, rx_irq = %d\n" , + info->tx_irq, info->rx_irq); + }return 0 ; bind_fail: -xenbus_free_evtchn (dev, info->evtchn); +if (!split_evtchn) +xenbus_free_evtchn (dev, info->tx_evtchn); +else { +xenbus_free_evtchn (dev, info->tx_evtchn); +xenbus_free_evtchn (dev, info->rx_evtchn); + } alloc_evtchn_fail:for (; j >=0 ; j--) {int ref = info->rx_ring_ref[j];
@@ -1690,11 +1755,27 @@ again: } } - err =xenbus_printf (xbt, dev->nodename, -"event-channel" ,"%u" , info->evtchn); -if (err) { - message ="writing event-channel" ; - goto abort_transaction; + +if (!info->split_evtchn) { + err =xenbus_printf (xbt, dev->nodename, +"event-channel" ,"%u" , info->tx_evtchn); +if (err) { + message ="writing event-channel" ; + goto abort_transaction; + } + }else { + err =xenbus_printf (xbt, dev->nodename, +"event-channel-tx" ,"%u" , info->tx_evtchn); +if (err) { + message ="writing event-channel-tx" ; + goto abort_transaction; + } + err =xenbus_printf (xbt, dev->nodename, +"event-channel-rx" ,"%u" , info->rx_evtchn); +if (err) { + message ="writing event-channel-rx" ; + goto abort_transaction; + } } err = xenbus_printf(xbt, dev->nodename, "request-rx-copy", "%u",
@@ -1808,7 +1889,9 @@ static int xennet_connect(struct net_device *dev)* packets. */ netif_carrier_on (np->netdev); -notify_remote_via_irq (np->netdev->irq); +notify_remote_via_irq (np->tx_irq); +if (np->split_evtchn) +notify_remote_via_irq (np->rx_irq);xennet_tx_buf_gc (dev);xennet_alloc_rx_buffers (dev);
Signature · 1 line
1.7.2.5
Re: [Xen-devel] [RFC PATCH V3 16/16] netfront: split event channels support.
Quoted 13 lines · Wei Liu
If this feature is not activated,
rx_irq=tx_irq. See corresponding netback change log for details.Signed-off-by Wei Liu <[email protected]>--- drivers/net/xen-netfront.c | 147 ++++++++++++++++++++++++++++++++++---------- 1 files changed, 115 insertions(+), 32 deletions(-)drivers/net/xen-netfront.c +0
-0
drivers/net/xen-netfront.c struct netfront_info { · line 101
Quoted 5 lines
drivers/net/xen-netfront.c +1
-1@@ -98,7 +98,9 @@ struct netfront_info {unsigned long rx_gso_checksum_fixup; -unsigned int evtchn; +unsigned int split_evtchn;
bool?
Quoted 104 lines
drivers/net/xen-netfront.c +36
-16+unsigned int tx_evtchn, rx_evtchn; +unsigned int tx_irq, rx_irq;struct xenbus_device *xbdev;spinlock_t tx_lock;@@ -344,7 +346,7 @@ no_skb: push:RING_PUSH_REQUESTS_AND_CHECK_NOTIFY (&np->rx, notify);if (notify) -notify_remote_via_irq (np->netdev->irq); +notify_remote_via_irq (np->rx_irq); }static int xennet_open (struct net_device *dev)@@ -577,7 +579,7 @@ static int xennet_start_xmit(struct sk_buff *skb, struct net_device *dev)RING_PUSH_REQUESTS_AND_CHECK_NOTIFY (&np->tx, notify);if (notify) -notify_remote_via_irq (np->netdev->irq); +notify_remote_via_irq (np->tx_irq);u64_stats_update_begin (&stats->syncp); stats->tx_bytes += skb->len;@@ -1242,22 +1244,35 @@ static int xennet_set_features(struct net_device *dev, u32 features)return 0 ; } -static irqreturn_t xennet_interrupt (int irq,void *dev_id) +static irqreturn_t xennet_tx_interrupt (int irq,void *dev_id) { -struct net_device *dev = dev_id; -struct netfront_info *np =netdev_priv (dev); +struct netfront_info *np = dev_id; +struct net_device *dev = np->netdev;unsigned long flags;spin_lock_irqsave (&np->tx_lock, flags); +xennet_tx_buf_gc (dev); +spin_unlock_irqrestore (&np->tx_lock, flags); -if (likely (netif_carrier_ok (dev))) { -xennet_tx_buf_gc (dev); -/* Under tx_lock: protects access to rx shared-ring indexes. */ -if (RING_HAS_UNCONSUMED_RESPONSES (&np->rx)) -napi_schedule (&np->napi); - } +return IRQ_HANDLED ; +} -spin_unlock_irqrestore (&np->tx_lock, flags); +static irqreturn_t xennet_rx_interrupt (int irq,void *dev_id) +{ +struct netfront_info *np = dev_id; +struct net_device *dev = np->netdev; + +if (likely (netif_carrier_ok (dev)) && +RING_HAS_UNCONSUMED_RESPONSES (&np->rx)) +napi_schedule (&np->napi); + +return IRQ_HANDLED ; +} +static irqreturn_t xennet_interrupt (int irq,void *dev_id) +{ +xennet_tx_interrupt (0 , dev_id); + +xennet_rx_interrupt (0 , dev_id);return IRQ_HANDLED ; }@@ -1436,9 +1451,14 @@ static void xennet_disconnect_backend(struct netfront_info *info)spin_unlock_irq (&info->tx_lock);spin_unlock_bh (&info->rx_lock); -if (info->netdev->irq) -unbind_from_irqhandler (info->netdev->irq, info->netdev); - info->evtchn = info->netdev->irq =0 ; +if (info->tx_irq && (info->tx_irq == info->rx_irq)) +unbind_from_irqhandler (info->tx_irq, info); +if (info->tx_irq && (info->tx_irq != info->rx_irq)) { +unbind_from_irqhandler (info->tx_irq, info); +unbind_from_irqhandler (info->rx_irq, info); + } + info->tx_evtchn = info->tx_irq =0 ; + info->rx_evtchn = info->rx_irq =0 ;for (i =0 ; i < info->tx_ring_pages; i++) {int ref = info->tx_ring_ref[i];@@ -1507,6 +1527,7 @@ static int setup_netfront(struct xenbus_device *dev, struct netfront_info *info)int err;struct net_device *netdev = info->netdev;unsigned int max_tx_ring_page_order, max_rx_ring_page_order; +unsigned int split_evtchn;int i, j;for (i =0 ; i <XENNET_MAX_RING_PAGES ; i++) {@@ -1515,7 +1536,6 @@ static int setup_netfront(struct xenbus_device *dev, struct netfront_info *info) } info->rx.sring =NULL ; info->tx.sring =NULL ; - netdev->irq =0 ; err =xen_net_read_mac (dev, netdev->dev_addr);if (err) {
drivers/net/xen-netfront.c static int setup_netfront(struct xenbus_device *dev, struct netfront_info *info) · line 1547
Quoted 4 lines
drivers/net/xen-netfront.c +1
-0@@ -1524,6 +1544,12 @@ static int setup_netfront(struct xenbus_device *dev, struct netfront_info *info) } err = xenbus_scanf(XBT_NIL, info->xbdev->otherend, + "split-event-channels", "%u",
We don't want to call them 'feature-split-event-channels' ?
Quoted 9 lines
drivers/net/xen-netfront.c +5
-0+ &split_evtchn); +if (err <0 ) + split_evtchn =0 ; + + err =xenbus_scanf (XBT_NIL , info->xbdev->otherend,"max-tx-ring-page-order" ,"%u" , &max_tx_ring_page_order);if (err <0 ) {
drivers/net/xen-netfront.c static int setup_netfront(struct xenbus_device *dev, struct netfront_info *info) · line 1618
Quoted 7 lines
drivers/net/xen-netfront.c +1
-3@@ -1589,20 +1615,59 @@ static int setup_netfront(struct xenbus_device *dev, struct netfront_info *info) info->rx_ring_ref[j] = err; } - err =xenbus_alloc_evtchn (dev, &info->evtchn); -if (err) - goto alloc_evtchn_fail; +if (!split_evtchn) {
Why not just move most of the code that deals with this allocation in two seperate functions: setup_netfront_split and setup_netfront_generic ?
Quoted 113 lines
drivers/net/xen-netfront.c +71
-12+ err =xenbus_alloc_evtchn (dev, &info->tx_evtchn); +if (err) + goto alloc_evtchn_fail; - err =bind_evtchn_to_irqhandler (info->evtchn, xennet_interrupt, -0 , netdev->name, netdev); -if (err <0 ) - goto bind_fail; - netdev->irq = err; + err =bind_evtchn_to_irqhandler (info->tx_evtchn, + xennet_interrupt, +0 , netdev->name, info); +if (err <0 ) + goto bind_fail; + info->rx_evtchn = info->tx_evtchn; + info->tx_irq = info->rx_irq = err; + info->split_evtchn =0 ; +dev_info (&dev->dev,"single event channel, irq = %d\n" , + info->tx_irq); + }else { + err =xenbus_alloc_evtchn (dev, &info->tx_evtchn); +if (err) + goto alloc_evtchn_fail; + err =xenbus_alloc_evtchn (dev, &info->rx_evtchn); +if (err) { +xenbus_free_evtchn (dev, info->tx_evtchn); + goto alloc_evtchn_fail; + } + err =bind_evtchn_to_irqhandler (info->tx_evtchn, + xennet_tx_interrupt, +0 , netdev->name, info); +if (err <0 ) + goto bind_fail; + info->tx_irq = err; + err =bind_evtchn_to_irqhandler (info->rx_evtchn, + xennet_rx_interrupt, +0 , netdev->name, info); +if (err <0 ) { +unbind_from_irqhandler (info->tx_irq, info); + goto bind_fail; + } + info->rx_irq = err; + info->split_evtchn =1 ; +dev_info (&dev->dev,"split event channels," +" tx_irq = %d, rx_irq = %d\n" , + info->tx_irq, info->rx_irq); + }return 0 ; bind_fail: -xenbus_free_evtchn (dev, info->evtchn); +if (!split_evtchn) +xenbus_free_evtchn (dev, info->tx_evtchn); +else { +xenbus_free_evtchn (dev, info->tx_evtchn); +xenbus_free_evtchn (dev, info->rx_evtchn); + } alloc_evtchn_fail:for (; j >=0 ; j--) {int ref = info->rx_ring_ref[j];@@ -1690,11 +1755,27 @@ again: } } - err =xenbus_printf (xbt, dev->nodename, -"event-channel" ,"%u" , info->evtchn); -if (err) { - message ="writing event-channel" ; - goto abort_transaction; + +if (!info->split_evtchn) { + err =xenbus_printf (xbt, dev->nodename, +"event-channel" ,"%u" , info->tx_evtchn); +if (err) { + message ="writing event-channel" ; + goto abort_transaction; + } + }else { + err =xenbus_printf (xbt, dev->nodename, +"event-channel-tx" ,"%u" , info->tx_evtchn); +if (err) { + message ="writing event-channel-tx" ; + goto abort_transaction; + } + err =xenbus_printf (xbt, dev->nodename, +"event-channel-rx" ,"%u" , info->rx_evtchn); +if (err) { + message ="writing event-channel-rx" ; + goto abort_transaction; + } } err = xenbus_printf(xbt, dev->nodename, "request-rx-copy", "%u",@@ -1808,7 +1889,9 @@ static int xennet_connect(struct net_device *dev)* packets. */ netif_carrier_on (np->netdev); -notify_remote_via_irq (np->netdev->irq); +notify_remote_via_irq (np->tx_irq); +if (np->split_evtchn) +notify_remote_via_irq (np->rx_irq);xennet_tx_buf_gc (dev);xennet_alloc_rx_buffers (dev);Signature · 7 lines
1.7.2.5 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xensource.com/xen-devel