diff options
author | Zoltan Kiss <zoltan.kiss@citrix.com> | 2014-03-06 16:48:24 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2014-03-07 15:56:34 -0500 |
commit | 121fa4b77775549c3c5eb41eb335d7dcbb801f90 (patch) | |
tree | cac1ae8a3d4ac72411312d27090e0a9106b6586c | |
parent | 8f13dd9612286cc0d38d32ff9543763b7c74f6a5 (diff) |
xen-netback: Minor refactoring of netback code
This patch contains a few bits of refactoring before introducing the grant
mapping changes:
- introducing xenvif_tx_pending_slots_available(), as this is used several
times, and will be used more often
- rename the thread to vifX.Y-guest-rx, to signify it does RX work from the
guest point of view
Signed-off-by: Zoltan Kiss <zoltan.kiss@citrix.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | drivers/net/xen-netback/common.h | 23 | ||||
-rw-r--r-- | drivers/net/xen-netback/interface.c | 4 | ||||
-rw-r--r-- | drivers/net/xen-netback/netback.c | 22 |
3 files changed, 27 insertions, 22 deletions
diff --git a/drivers/net/xen-netback/common.h b/drivers/net/xen-netback/common.h index ae413a2cbee7..9d3584545e5d 100644 --- a/drivers/net/xen-netback/common.h +++ b/drivers/net/xen-netback/common.h | |||
@@ -108,6 +108,15 @@ struct xenvif_rx_meta { | |||
108 | */ | 108 | */ |
109 | #define MAX_GRANT_COPY_OPS (MAX_SKB_FRAGS * XEN_NETIF_RX_RING_SIZE) | 109 | #define MAX_GRANT_COPY_OPS (MAX_SKB_FRAGS * XEN_NETIF_RX_RING_SIZE) |
110 | 110 | ||
111 | #define NETBACK_INVALID_HANDLE -1 | ||
112 | |||
113 | /* To avoid confusion, we define XEN_NETBK_LEGACY_SLOTS_MAX indicating | ||
114 | * the maximum slots a valid packet can use. Now this value is defined | ||
115 | * to be XEN_NETIF_NR_SLOTS_MIN, which is supposed to be supported by | ||
116 | * all backend. | ||
117 | */ | ||
118 | #define XEN_NETBK_LEGACY_SLOTS_MAX XEN_NETIF_NR_SLOTS_MIN | ||
119 | |||
111 | struct xenvif { | 120 | struct xenvif { |
112 | /* Unique identifier for this interface. */ | 121 | /* Unique identifier for this interface. */ |
113 | domid_t domid; | 122 | domid_t domid; |
@@ -216,7 +225,7 @@ void xenvif_carrier_off(struct xenvif *vif); | |||
216 | 225 | ||
217 | int xenvif_tx_action(struct xenvif *vif, int budget); | 226 | int xenvif_tx_action(struct xenvif *vif, int budget); |
218 | 227 | ||
219 | int xenvif_kthread(void *data); | 228 | int xenvif_kthread_guest_rx(void *data); |
220 | void xenvif_kick_thread(struct xenvif *vif); | 229 | void xenvif_kick_thread(struct xenvif *vif); |
221 | 230 | ||
222 | /* Determine whether the needed number of slots (req) are available, | 231 | /* Determine whether the needed number of slots (req) are available, |
@@ -226,6 +235,18 @@ bool xenvif_rx_ring_slots_available(struct xenvif *vif, int needed); | |||
226 | 235 | ||
227 | void xenvif_stop_queue(struct xenvif *vif); | 236 | void xenvif_stop_queue(struct xenvif *vif); |
228 | 237 | ||
238 | static inline pending_ring_idx_t nr_pending_reqs(struct xenvif *vif) | ||
239 | { | ||
240 | return MAX_PENDING_REQS - | ||
241 | vif->pending_prod + vif->pending_cons; | ||
242 | } | ||
243 | |||
244 | static inline bool xenvif_tx_pending_slots_available(struct xenvif *vif) | ||
245 | { | ||
246 | return nr_pending_reqs(vif) + XEN_NETBK_LEGACY_SLOTS_MAX | ||
247 | < MAX_PENDING_REQS; | ||
248 | } | ||
249 | |||
229 | extern bool separate_tx_rx_irq; | 250 | extern bool separate_tx_rx_irq; |
230 | 251 | ||
231 | #endif /* __XEN_NETBACK__COMMON_H__ */ | 252 | #endif /* __XEN_NETBACK__COMMON_H__ */ |
diff --git a/drivers/net/xen-netback/interface.c b/drivers/net/xen-netback/interface.c index 7669d49a67e2..bc32627a22cb 100644 --- a/drivers/net/xen-netback/interface.c +++ b/drivers/net/xen-netback/interface.c | |||
@@ -421,8 +421,8 @@ int xenvif_connect(struct xenvif *vif, unsigned long tx_ring_ref, | |||
421 | disable_irq(vif->rx_irq); | 421 | disable_irq(vif->rx_irq); |
422 | } | 422 | } |
423 | 423 | ||
424 | task = kthread_create(xenvif_kthread, | 424 | task = kthread_create(xenvif_kthread_guest_rx, |
425 | (void *)vif, "%s", vif->dev->name); | 425 | (void *)vif, "%s-guest-rx", vif->dev->name); |
426 | if (IS_ERR(task)) { | 426 | if (IS_ERR(task)) { |
427 | pr_warn("Could not allocate kthread for %s\n", vif->dev->name); | 427 | pr_warn("Could not allocate kthread for %s\n", vif->dev->name); |
428 | err = PTR_ERR(task); | 428 | err = PTR_ERR(task); |
diff --git a/drivers/net/xen-netback/netback.c b/drivers/net/xen-netback/netback.c index 43ae4bad50c4..715d810124eb 100644 --- a/drivers/net/xen-netback/netback.c +++ b/drivers/net/xen-netback/netback.c | |||
@@ -63,14 +63,6 @@ static unsigned int fatal_skb_slots = FATAL_SKB_SLOTS_DEFAULT; | |||
63 | module_param(fatal_skb_slots, uint, 0444); | 63 | module_param(fatal_skb_slots, uint, 0444); |
64 | 64 | ||
65 | /* | 65 | /* |
66 | * To avoid confusion, we define XEN_NETBK_LEGACY_SLOTS_MAX indicating | ||
67 | * the maximum slots a valid packet can use. Now this value is defined | ||
68 | * to be XEN_NETIF_NR_SLOTS_MIN, which is supposed to be supported by | ||
69 | * all backend. | ||
70 | */ | ||
71 | #define XEN_NETBK_LEGACY_SLOTS_MAX XEN_NETIF_NR_SLOTS_MIN | ||
72 | |||
73 | /* | ||
74 | * If head != INVALID_PENDING_RING_IDX, it means this tx request is head of | 66 | * If head != INVALID_PENDING_RING_IDX, it means this tx request is head of |
75 | * one or more merged tx requests, otherwise it is the continuation of | 67 | * one or more merged tx requests, otherwise it is the continuation of |
76 | * previous tx request. | 68 | * previous tx request. |
@@ -131,12 +123,6 @@ static inline pending_ring_idx_t pending_index(unsigned i) | |||
131 | return i & (MAX_PENDING_REQS-1); | 123 | return i & (MAX_PENDING_REQS-1); |
132 | } | 124 | } |
133 | 125 | ||
134 | static inline pending_ring_idx_t nr_pending_reqs(struct xenvif *vif) | ||
135 | { | ||
136 | return MAX_PENDING_REQS - | ||
137 | vif->pending_prod + vif->pending_cons; | ||
138 | } | ||
139 | |||
140 | bool xenvif_rx_ring_slots_available(struct xenvif *vif, int needed) | 126 | bool xenvif_rx_ring_slots_available(struct xenvif *vif, int needed) |
141 | { | 127 | { |
142 | RING_IDX prod, cons; | 128 | RING_IDX prod, cons; |
@@ -1116,8 +1102,7 @@ static unsigned xenvif_tx_build_gops(struct xenvif *vif, int budget) | |||
1116 | struct sk_buff *skb; | 1102 | struct sk_buff *skb; |
1117 | int ret; | 1103 | int ret; |
1118 | 1104 | ||
1119 | while ((nr_pending_reqs(vif) + XEN_NETBK_LEGACY_SLOTS_MAX | 1105 | while (xenvif_tx_pending_slots_available(vif) && |
1120 | < MAX_PENDING_REQS) && | ||
1121 | (skb_queue_len(&vif->tx_queue) < budget)) { | 1106 | (skb_queue_len(&vif->tx_queue) < budget)) { |
1122 | struct xen_netif_tx_request txreq; | 1107 | struct xen_netif_tx_request txreq; |
1123 | struct xen_netif_tx_request txfrags[XEN_NETBK_LEGACY_SLOTS_MAX]; | 1108 | struct xen_netif_tx_request txfrags[XEN_NETBK_LEGACY_SLOTS_MAX]; |
@@ -1487,8 +1472,7 @@ static inline int tx_work_todo(struct xenvif *vif) | |||
1487 | { | 1472 | { |
1488 | 1473 | ||
1489 | if (likely(RING_HAS_UNCONSUMED_REQUESTS(&vif->tx)) && | 1474 | if (likely(RING_HAS_UNCONSUMED_REQUESTS(&vif->tx)) && |
1490 | (nr_pending_reqs(vif) + XEN_NETBK_LEGACY_SLOTS_MAX | 1475 | xenvif_tx_pending_slots_available(vif)) |
1491 | < MAX_PENDING_REQS)) | ||
1492 | return 1; | 1476 | return 1; |
1493 | 1477 | ||
1494 | return 0; | 1478 | return 0; |
@@ -1551,7 +1535,7 @@ static void xenvif_start_queue(struct xenvif *vif) | |||
1551 | netif_wake_queue(vif->dev); | 1535 | netif_wake_queue(vif->dev); |
1552 | } | 1536 | } |
1553 | 1537 | ||
1554 | int xenvif_kthread(void *data) | 1538 | int xenvif_kthread_guest_rx(void *data) |
1555 | { | 1539 | { |
1556 | struct xenvif *vif = data; | 1540 | struct xenvif *vif = data; |
1557 | struct sk_buff *skb; | 1541 | struct sk_buff *skb; |