diff options
Diffstat (limited to 'drivers/net')
-rw-r--r-- | drivers/net/xen-netback/common.h | 29 | ||||
-rw-r--r-- | drivers/net/xen-netback/interface.c | 59 | ||||
-rw-r--r-- | drivers/net/xen-netback/netback.c | 243 | ||||
-rw-r--r-- | drivers/net/xen-netback/xenbus.c | 8 |
4 files changed, 161 insertions, 178 deletions
diff --git a/drivers/net/xen-netback/common.h b/drivers/net/xen-netback/common.h index 93ca77c129c3..c2642402b7a1 100644 --- a/drivers/net/xen-netback/common.h +++ b/drivers/net/xen-netback/common.h | |||
@@ -176,10 +176,9 @@ struct xenvif_queue { /* Per-queue data for xenvif */ | |||
176 | char rx_irq_name[IRQ_NAME_SIZE]; /* DEVNAME-qN-rx */ | 176 | char rx_irq_name[IRQ_NAME_SIZE]; /* DEVNAME-qN-rx */ |
177 | struct xen_netif_rx_back_ring rx; | 177 | struct xen_netif_rx_back_ring rx; |
178 | struct sk_buff_head rx_queue; | 178 | struct sk_buff_head rx_queue; |
179 | RING_IDX rx_last_skb_slots; | ||
180 | unsigned long status; | ||
181 | 179 | ||
182 | struct timer_list rx_stalled; | 180 | unsigned int rx_queue_max; |
181 | unsigned int rx_queue_len; | ||
183 | 182 | ||
184 | struct gnttab_copy grant_copy_op[MAX_GRANT_COPY_OPS]; | 183 | struct gnttab_copy grant_copy_op[MAX_GRANT_COPY_OPS]; |
185 | 184 | ||
@@ -199,18 +198,14 @@ struct xenvif_queue { /* Per-queue data for xenvif */ | |||
199 | struct xenvif_stats stats; | 198 | struct xenvif_stats stats; |
200 | }; | 199 | }; |
201 | 200 | ||
201 | /* Maximum number of Rx slots a to-guest packet may use, including the | ||
202 | * slot needed for GSO meta-data. | ||
203 | */ | ||
204 | #define XEN_NETBK_RX_SLOTS_MAX (MAX_SKB_FRAGS + 1) | ||
205 | |||
202 | enum state_bit_shift { | 206 | enum state_bit_shift { |
203 | /* This bit marks that the vif is connected */ | 207 | /* This bit marks that the vif is connected */ |
204 | VIF_STATUS_CONNECTED, | 208 | VIF_STATUS_CONNECTED, |
205 | /* This bit signals the RX thread that queuing was stopped (in | ||
206 | * start_xmit), and either the timer fired or an RX interrupt came | ||
207 | */ | ||
208 | QUEUE_STATUS_RX_PURGE_EVENT, | ||
209 | /* This bit tells the interrupt handler that this queue was the reason | ||
210 | * for the carrier off, so it should kick the thread. Only queues which | ||
211 | * brought it down can turn on the carrier. | ||
212 | */ | ||
213 | QUEUE_STATUS_RX_STALLED | ||
214 | }; | 209 | }; |
215 | 210 | ||
216 | struct xenvif { | 211 | struct xenvif { |
@@ -246,6 +241,14 @@ struct xenvif { | |||
246 | struct net_device *dev; | 241 | struct net_device *dev; |
247 | }; | 242 | }; |
248 | 243 | ||
244 | struct xenvif_rx_cb { | ||
245 | unsigned long expires; | ||
246 | int meta_slots_used; | ||
247 | bool full_coalesce; | ||
248 | }; | ||
249 | |||
250 | #define XENVIF_RX_CB(skb) ((struct xenvif_rx_cb *)(skb)->cb) | ||
251 | |||
249 | static inline struct xenbus_device *xenvif_to_xenbus_device(struct xenvif *vif) | 252 | static inline struct xenbus_device *xenvif_to_xenbus_device(struct xenvif *vif) |
250 | { | 253 | { |
251 | return to_xenbus_device(vif->dev->dev.parent); | 254 | return to_xenbus_device(vif->dev->dev.parent); |
@@ -291,6 +294,8 @@ void xenvif_kick_thread(struct xenvif_queue *queue); | |||
291 | 294 | ||
292 | int xenvif_dealloc_kthread(void *data); | 295 | int xenvif_dealloc_kthread(void *data); |
293 | 296 | ||
297 | void xenvif_rx_queue_tail(struct xenvif_queue *queue, struct sk_buff *skb); | ||
298 | |||
294 | /* Determine whether the needed number of slots (req) are available, | 299 | /* Determine whether the needed number of slots (req) are available, |
295 | * and set req_event if not. | 300 | * and set req_event if not. |
296 | */ | 301 | */ |
diff --git a/drivers/net/xen-netback/interface.c b/drivers/net/xen-netback/interface.c index c6759b1ec18d..a134d52f55b4 100644 --- a/drivers/net/xen-netback/interface.c +++ b/drivers/net/xen-netback/interface.c | |||
@@ -43,6 +43,9 @@ | |||
43 | #define XENVIF_QUEUE_LENGTH 32 | 43 | #define XENVIF_QUEUE_LENGTH 32 |
44 | #define XENVIF_NAPI_WEIGHT 64 | 44 | #define XENVIF_NAPI_WEIGHT 64 |
45 | 45 | ||
46 | /* Number of bytes allowed on the internal guest Rx queue. */ | ||
47 | #define XENVIF_RX_QUEUE_BYTES (XEN_NETIF_RX_RING_SIZE/2 * PAGE_SIZE) | ||
48 | |||
46 | /* This function is used to set SKBTX_DEV_ZEROCOPY as well as | 49 | /* This function is used to set SKBTX_DEV_ZEROCOPY as well as |
47 | * increasing the inflight counter. We need to increase the inflight | 50 | * increasing the inflight counter. We need to increase the inflight |
48 | * counter because core driver calls into xenvif_zerocopy_callback | 51 | * counter because core driver calls into xenvif_zerocopy_callback |
@@ -63,7 +66,8 @@ void xenvif_skb_zerocopy_complete(struct xenvif_queue *queue) | |||
63 | int xenvif_schedulable(struct xenvif *vif) | 66 | int xenvif_schedulable(struct xenvif *vif) |
64 | { | 67 | { |
65 | return netif_running(vif->dev) && | 68 | return netif_running(vif->dev) && |
66 | test_bit(VIF_STATUS_CONNECTED, &vif->status); | 69 | test_bit(VIF_STATUS_CONNECTED, &vif->status) && |
70 | !vif->disabled; | ||
67 | } | 71 | } |
68 | 72 | ||
69 | static irqreturn_t xenvif_tx_interrupt(int irq, void *dev_id) | 73 | static irqreturn_t xenvif_tx_interrupt(int irq, void *dev_id) |
@@ -104,16 +108,7 @@ int xenvif_poll(struct napi_struct *napi, int budget) | |||
104 | static irqreturn_t xenvif_rx_interrupt(int irq, void *dev_id) | 108 | static irqreturn_t xenvif_rx_interrupt(int irq, void *dev_id) |
105 | { | 109 | { |
106 | struct xenvif_queue *queue = dev_id; | 110 | struct xenvif_queue *queue = dev_id; |
107 | struct netdev_queue *net_queue = | ||
108 | netdev_get_tx_queue(queue->vif->dev, queue->id); | ||
109 | 111 | ||
110 | /* QUEUE_STATUS_RX_PURGE_EVENT is only set if either QDisc was off OR | ||
111 | * the carrier went down and this queue was previously blocked | ||
112 | */ | ||
113 | if (unlikely(netif_tx_queue_stopped(net_queue) || | ||
114 | (!netif_carrier_ok(queue->vif->dev) && | ||
115 | test_bit(QUEUE_STATUS_RX_STALLED, &queue->status)))) | ||
116 | set_bit(QUEUE_STATUS_RX_PURGE_EVENT, &queue->status); | ||
117 | xenvif_kick_thread(queue); | 112 | xenvif_kick_thread(queue); |
118 | 113 | ||
119 | return IRQ_HANDLED; | 114 | return IRQ_HANDLED; |
@@ -141,24 +136,13 @@ void xenvif_wake_queue(struct xenvif_queue *queue) | |||
141 | netif_tx_wake_queue(netdev_get_tx_queue(dev, id)); | 136 | netif_tx_wake_queue(netdev_get_tx_queue(dev, id)); |
142 | } | 137 | } |
143 | 138 | ||
144 | /* Callback to wake the queue's thread and turn the carrier off on timeout */ | ||
145 | static void xenvif_rx_stalled(unsigned long data) | ||
146 | { | ||
147 | struct xenvif_queue *queue = (struct xenvif_queue *)data; | ||
148 | |||
149 | if (xenvif_queue_stopped(queue)) { | ||
150 | set_bit(QUEUE_STATUS_RX_PURGE_EVENT, &queue->status); | ||
151 | xenvif_kick_thread(queue); | ||
152 | } | ||
153 | } | ||
154 | |||
155 | static int xenvif_start_xmit(struct sk_buff *skb, struct net_device *dev) | 139 | static int xenvif_start_xmit(struct sk_buff *skb, struct net_device *dev) |
156 | { | 140 | { |
157 | struct xenvif *vif = netdev_priv(dev); | 141 | struct xenvif *vif = netdev_priv(dev); |
158 | struct xenvif_queue *queue = NULL; | 142 | struct xenvif_queue *queue = NULL; |
159 | unsigned int num_queues = vif->num_queues; | 143 | unsigned int num_queues = vif->num_queues; |
160 | u16 index; | 144 | u16 index; |
161 | int min_slots_needed; | 145 | struct xenvif_rx_cb *cb; |
162 | 146 | ||
163 | BUG_ON(skb->dev != dev); | 147 | BUG_ON(skb->dev != dev); |
164 | 148 | ||
@@ -181,30 +165,10 @@ static int xenvif_start_xmit(struct sk_buff *skb, struct net_device *dev) | |||
181 | !xenvif_schedulable(vif)) | 165 | !xenvif_schedulable(vif)) |
182 | goto drop; | 166 | goto drop; |
183 | 167 | ||
184 | /* At best we'll need one slot for the header and one for each | 168 | cb = XENVIF_RX_CB(skb); |
185 | * frag. | 169 | cb->expires = jiffies + rx_drain_timeout_jiffies; |
186 | */ | ||
187 | min_slots_needed = 1 + skb_shinfo(skb)->nr_frags; | ||
188 | 170 | ||
189 | /* If the skb is GSO then we'll also need an extra slot for the | 171 | xenvif_rx_queue_tail(queue, skb); |
190 | * metadata. | ||
191 | */ | ||
192 | if (skb_is_gso(skb)) | ||
193 | min_slots_needed++; | ||
194 | |||
195 | /* If the skb can't possibly fit in the remaining slots | ||
196 | * then turn off the queue to give the ring a chance to | ||
197 | * drain. | ||
198 | */ | ||
199 | if (!xenvif_rx_ring_slots_available(queue, min_slots_needed)) { | ||
200 | queue->rx_stalled.function = xenvif_rx_stalled; | ||
201 | queue->rx_stalled.data = (unsigned long)queue; | ||
202 | netif_tx_stop_queue(netdev_get_tx_queue(dev, queue->id)); | ||
203 | mod_timer(&queue->rx_stalled, | ||
204 | jiffies + rx_drain_timeout_jiffies); | ||
205 | } | ||
206 | |||
207 | skb_queue_tail(&queue->rx_queue, skb); | ||
208 | xenvif_kick_thread(queue); | 172 | xenvif_kick_thread(queue); |
209 | 173 | ||
210 | return NETDEV_TX_OK; | 174 | return NETDEV_TX_OK; |
@@ -498,6 +462,8 @@ int xenvif_init_queue(struct xenvif_queue *queue) | |||
498 | init_timer(&queue->credit_timeout); | 462 | init_timer(&queue->credit_timeout); |
499 | queue->credit_window_start = get_jiffies_64(); | 463 | queue->credit_window_start = get_jiffies_64(); |
500 | 464 | ||
465 | queue->rx_queue_max = XENVIF_RX_QUEUE_BYTES; | ||
466 | |||
501 | skb_queue_head_init(&queue->rx_queue); | 467 | skb_queue_head_init(&queue->rx_queue); |
502 | skb_queue_head_init(&queue->tx_queue); | 468 | skb_queue_head_init(&queue->tx_queue); |
503 | 469 | ||
@@ -529,8 +495,6 @@ int xenvif_init_queue(struct xenvif_queue *queue) | |||
529 | queue->grant_tx_handle[i] = NETBACK_INVALID_HANDLE; | 495 | queue->grant_tx_handle[i] = NETBACK_INVALID_HANDLE; |
530 | } | 496 | } |
531 | 497 | ||
532 | init_timer(&queue->rx_stalled); | ||
533 | |||
534 | return 0; | 498 | return 0; |
535 | } | 499 | } |
536 | 500 | ||
@@ -664,7 +628,6 @@ void xenvif_disconnect(struct xenvif *vif) | |||
664 | netif_napi_del(&queue->napi); | 628 | netif_napi_del(&queue->napi); |
665 | 629 | ||
666 | if (queue->task) { | 630 | if (queue->task) { |
667 | del_timer_sync(&queue->rx_stalled); | ||
668 | kthread_stop(queue->task); | 631 | kthread_stop(queue->task); |
669 | queue->task = NULL; | 632 | queue->task = NULL; |
670 | } | 633 | } |
diff --git a/drivers/net/xen-netback/netback.c b/drivers/net/xen-netback/netback.c index 08f65996534c..57aa3b507d32 100644 --- a/drivers/net/xen-netback/netback.c +++ b/drivers/net/xen-netback/netback.c | |||
@@ -55,8 +55,8 @@ | |||
55 | bool separate_tx_rx_irq = 1; | 55 | bool separate_tx_rx_irq = 1; |
56 | module_param(separate_tx_rx_irq, bool, 0644); | 56 | module_param(separate_tx_rx_irq, bool, 0644); |
57 | 57 | ||
58 | /* When guest ring is filled up, qdisc queues the packets for us, but we have | 58 | /* The time that packets can stay on the guest Rx internal queue |
59 | * to timeout them, otherwise other guests' packets can get stuck there | 59 | * before they are dropped. |
60 | */ | 60 | */ |
61 | unsigned int rx_drain_timeout_msecs = 10000; | 61 | unsigned int rx_drain_timeout_msecs = 10000; |
62 | module_param(rx_drain_timeout_msecs, uint, 0444); | 62 | module_param(rx_drain_timeout_msecs, uint, 0444); |
@@ -83,7 +83,6 @@ static void make_tx_response(struct xenvif_queue *queue, | |||
83 | s8 st); | 83 | s8 st); |
84 | 84 | ||
85 | static inline int tx_work_todo(struct xenvif_queue *queue); | 85 | static inline int tx_work_todo(struct xenvif_queue *queue); |
86 | static inline int rx_work_todo(struct xenvif_queue *queue); | ||
87 | 86 | ||
88 | static struct xen_netif_rx_response *make_rx_response(struct xenvif_queue *queue, | 87 | static struct xen_netif_rx_response *make_rx_response(struct xenvif_queue *queue, |
89 | u16 id, | 88 | u16 id, |
@@ -163,6 +162,69 @@ bool xenvif_rx_ring_slots_available(struct xenvif_queue *queue, int needed) | |||
163 | return false; | 162 | return false; |
164 | } | 163 | } |
165 | 164 | ||
165 | void xenvif_rx_queue_tail(struct xenvif_queue *queue, struct sk_buff *skb) | ||
166 | { | ||
167 | unsigned long flags; | ||
168 | |||
169 | spin_lock_irqsave(&queue->rx_queue.lock, flags); | ||
170 | |||
171 | __skb_queue_tail(&queue->rx_queue, skb); | ||
172 | |||
173 | queue->rx_queue_len += skb->len; | ||
174 | if (queue->rx_queue_len > queue->rx_queue_max) | ||
175 | netif_tx_stop_queue(netdev_get_tx_queue(queue->vif->dev, queue->id)); | ||
176 | |||
177 | spin_unlock_irqrestore(&queue->rx_queue.lock, flags); | ||
178 | } | ||
179 | |||
180 | static struct sk_buff *xenvif_rx_dequeue(struct xenvif_queue *queue) | ||
181 | { | ||
182 | struct sk_buff *skb; | ||
183 | |||
184 | spin_lock_irq(&queue->rx_queue.lock); | ||
185 | |||
186 | skb = __skb_dequeue(&queue->rx_queue); | ||
187 | if (skb) | ||
188 | queue->rx_queue_len -= skb->len; | ||
189 | |||
190 | spin_unlock_irq(&queue->rx_queue.lock); | ||
191 | |||
192 | return skb; | ||
193 | } | ||
194 | |||
195 | static void xenvif_rx_queue_maybe_wake(struct xenvif_queue *queue) | ||
196 | { | ||
197 | spin_lock_irq(&queue->rx_queue.lock); | ||
198 | |||
199 | if (queue->rx_queue_len < queue->rx_queue_max) | ||
200 | netif_tx_wake_queue(netdev_get_tx_queue(queue->vif->dev, queue->id)); | ||
201 | |||
202 | spin_unlock_irq(&queue->rx_queue.lock); | ||
203 | } | ||
204 | |||
205 | |||
206 | static void xenvif_rx_queue_purge(struct xenvif_queue *queue) | ||
207 | { | ||
208 | struct sk_buff *skb; | ||
209 | while ((skb = xenvif_rx_dequeue(queue)) != NULL) | ||
210 | kfree_skb(skb); | ||
211 | } | ||
212 | |||
213 | static void xenvif_rx_queue_drop_expired(struct xenvif_queue *queue) | ||
214 | { | ||
215 | struct sk_buff *skb; | ||
216 | |||
217 | for(;;) { | ||
218 | skb = skb_peek(&queue->rx_queue); | ||
219 | if (!skb) | ||
220 | break; | ||
221 | if (time_before(jiffies, XENVIF_RX_CB(skb)->expires)) | ||
222 | break; | ||
223 | xenvif_rx_dequeue(queue); | ||
224 | kfree_skb(skb); | ||
225 | } | ||
226 | } | ||
227 | |||
166 | /* | 228 | /* |
167 | * Returns true if we should start a new receive buffer instead of | 229 | * Returns true if we should start a new receive buffer instead of |
168 | * adding 'size' bytes to a buffer which currently contains 'offset' | 230 | * adding 'size' bytes to a buffer which currently contains 'offset' |
@@ -237,13 +299,6 @@ static struct xenvif_rx_meta *get_next_rx_buffer(struct xenvif_queue *queue, | |||
237 | return meta; | 299 | return meta; |
238 | } | 300 | } |
239 | 301 | ||
240 | struct xenvif_rx_cb { | ||
241 | int meta_slots_used; | ||
242 | bool full_coalesce; | ||
243 | }; | ||
244 | |||
245 | #define XENVIF_RX_CB(skb) ((struct xenvif_rx_cb *)(skb)->cb) | ||
246 | |||
247 | /* | 302 | /* |
248 | * Set up the grant operations for this fragment. If it's a flipping | 303 | * Set up the grant operations for this fragment. If it's a flipping |
249 | * interface, we also set up the unmap request from here. | 304 | * interface, we also set up the unmap request from here. |
@@ -587,7 +642,8 @@ static void xenvif_rx_action(struct xenvif_queue *queue) | |||
587 | 642 | ||
588 | skb_queue_head_init(&rxq); | 643 | skb_queue_head_init(&rxq); |
589 | 644 | ||
590 | while ((skb = skb_dequeue(&queue->rx_queue)) != NULL) { | 645 | while (xenvif_rx_ring_slots_available(queue, XEN_NETBK_RX_SLOTS_MAX) |
646 | && (skb = xenvif_rx_dequeue(queue)) != NULL) { | ||
591 | RING_IDX max_slots_needed; | 647 | RING_IDX max_slots_needed; |
592 | RING_IDX old_req_cons; | 648 | RING_IDX old_req_cons; |
593 | RING_IDX ring_slots_used; | 649 | RING_IDX ring_slots_used; |
@@ -634,15 +690,6 @@ static void xenvif_rx_action(struct xenvif_queue *queue) | |||
634 | skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6)) | 690 | skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6)) |
635 | max_slots_needed++; | 691 | max_slots_needed++; |
636 | 692 | ||
637 | /* If the skb may not fit then bail out now */ | ||
638 | if (!xenvif_rx_ring_slots_available(queue, max_slots_needed)) { | ||
639 | skb_queue_head(&queue->rx_queue, skb); | ||
640 | need_to_notify = true; | ||
641 | queue->rx_last_skb_slots = max_slots_needed; | ||
642 | break; | ||
643 | } else | ||
644 | queue->rx_last_skb_slots = 0; | ||
645 | |||
646 | old_req_cons = queue->rx.req_cons; | 693 | old_req_cons = queue->rx.req_cons; |
647 | XENVIF_RX_CB(skb)->meta_slots_used = xenvif_gop_skb(skb, &npo, queue); | 694 | XENVIF_RX_CB(skb)->meta_slots_used = xenvif_gop_skb(skb, &npo, queue); |
648 | ring_slots_used = queue->rx.req_cons - old_req_cons; | 695 | ring_slots_used = queue->rx.req_cons - old_req_cons; |
@@ -1869,12 +1916,6 @@ void xenvif_idx_unmap(struct xenvif_queue *queue, u16 pending_idx) | |||
1869 | } | 1916 | } |
1870 | } | 1917 | } |
1871 | 1918 | ||
1872 | static inline int rx_work_todo(struct xenvif_queue *queue) | ||
1873 | { | ||
1874 | return (!skb_queue_empty(&queue->rx_queue) && | ||
1875 | xenvif_rx_ring_slots_available(queue, queue->rx_last_skb_slots)); | ||
1876 | } | ||
1877 | |||
1878 | static inline int tx_work_todo(struct xenvif_queue *queue) | 1919 | static inline int tx_work_todo(struct xenvif_queue *queue) |
1879 | { | 1920 | { |
1880 | if (likely(RING_HAS_UNCONSUMED_REQUESTS(&queue->tx))) | 1921 | if (likely(RING_HAS_UNCONSUMED_REQUESTS(&queue->tx))) |
@@ -1931,92 +1972,64 @@ err: | |||
1931 | return err; | 1972 | return err; |
1932 | } | 1973 | } |
1933 | 1974 | ||
1934 | static void xenvif_start_queue(struct xenvif_queue *queue) | 1975 | static bool xenvif_have_rx_work(struct xenvif_queue *queue) |
1935 | { | 1976 | { |
1936 | if (xenvif_schedulable(queue->vif)) | 1977 | return (!skb_queue_empty(&queue->rx_queue) |
1937 | xenvif_wake_queue(queue); | 1978 | && xenvif_rx_ring_slots_available(queue, XEN_NETBK_RX_SLOTS_MAX)) |
1979 | || kthread_should_stop() | ||
1980 | || queue->vif->disabled; | ||
1938 | } | 1981 | } |
1939 | 1982 | ||
1940 | /* Only called from the queue's thread, it handles the situation when the guest | 1983 | static long xenvif_rx_queue_timeout(struct xenvif_queue *queue) |
1941 | * doesn't post enough requests on the receiving ring. | ||
1942 | * First xenvif_start_xmit disables QDisc and start a timer, and then either the | ||
1943 | * timer fires, or the guest send an interrupt after posting new request. If it | ||
1944 | * is the timer, the carrier is turned off here. | ||
1945 | * */ | ||
1946 | static void xenvif_rx_purge_event(struct xenvif_queue *queue) | ||
1947 | { | 1984 | { |
1948 | /* Either the last unsuccesful skb or at least 1 slot should fit */ | 1985 | struct sk_buff *skb; |
1949 | int needed = queue->rx_last_skb_slots ? | 1986 | long timeout; |
1950 | queue->rx_last_skb_slots : 1; | ||
1951 | 1987 | ||
1952 | /* It is assumed that if the guest post new slots after this, the RX | 1988 | skb = skb_peek(&queue->rx_queue); |
1953 | * interrupt will set the QUEUE_STATUS_RX_PURGE_EVENT bit and wake up | 1989 | if (!skb) |
1954 | * the thread again | 1990 | return MAX_SCHEDULE_TIMEOUT; |
1955 | */ | ||
1956 | set_bit(QUEUE_STATUS_RX_STALLED, &queue->status); | ||
1957 | if (!xenvif_rx_ring_slots_available(queue, needed)) { | ||
1958 | rtnl_lock(); | ||
1959 | if (netif_carrier_ok(queue->vif->dev)) { | ||
1960 | /* Timer fired and there are still no slots. Turn off | ||
1961 | * everything except the interrupts | ||
1962 | */ | ||
1963 | netif_carrier_off(queue->vif->dev); | ||
1964 | skb_queue_purge(&queue->rx_queue); | ||
1965 | queue->rx_last_skb_slots = 0; | ||
1966 | if (net_ratelimit()) | ||
1967 | netdev_err(queue->vif->dev, "Carrier off due to lack of guest response on queue %d\n", queue->id); | ||
1968 | } else { | ||
1969 | /* Probably an another queue already turned the carrier | ||
1970 | * off, make sure nothing is stucked in the internal | ||
1971 | * queue of this queue | ||
1972 | */ | ||
1973 | skb_queue_purge(&queue->rx_queue); | ||
1974 | queue->rx_last_skb_slots = 0; | ||
1975 | } | ||
1976 | rtnl_unlock(); | ||
1977 | } else if (!netif_carrier_ok(queue->vif->dev)) { | ||
1978 | unsigned int num_queues = queue->vif->num_queues; | ||
1979 | unsigned int i; | ||
1980 | /* The carrier was down, but an interrupt kicked | ||
1981 | * the thread again after new requests were | ||
1982 | * posted | ||
1983 | */ | ||
1984 | clear_bit(QUEUE_STATUS_RX_STALLED, | ||
1985 | &queue->status); | ||
1986 | rtnl_lock(); | ||
1987 | netif_carrier_on(queue->vif->dev); | ||
1988 | netif_tx_wake_all_queues(queue->vif->dev); | ||
1989 | rtnl_unlock(); | ||
1990 | 1991 | ||
1991 | for (i = 0; i < num_queues; i++) { | 1992 | timeout = XENVIF_RX_CB(skb)->expires - jiffies; |
1992 | struct xenvif_queue *temp = &queue->vif->queues[i]; | 1993 | return timeout < 0 ? 0 : timeout; |
1994 | } | ||
1993 | 1995 | ||
1994 | xenvif_napi_schedule_or_enable_events(temp); | 1996 | /* Wait until the guest Rx thread has work. |
1995 | } | 1997 | * |
1996 | if (net_ratelimit()) | 1998 | * The timeout needs to be adjusted based on the current head of the |
1997 | netdev_err(queue->vif->dev, "Carrier on again\n"); | 1999 | * queue (and not just the head at the beginning). In particular, if |
1998 | } else { | 2000 | * the queue is initially empty an infinite timeout is used and this |
1999 | /* Queuing were stopped, but the guest posted | 2001 | * needs to be reduced when a skb is queued. |
2000 | * new requests and sent an interrupt | 2002 | * |
2001 | */ | 2003 | * This cannot be done with wait_event_timeout() because it only |
2002 | clear_bit(QUEUE_STATUS_RX_STALLED, | 2004 | * calculates the timeout once. |
2003 | &queue->status); | 2005 | */ |
2004 | del_timer_sync(&queue->rx_stalled); | 2006 | static void xenvif_wait_for_rx_work(struct xenvif_queue *queue) |
2005 | xenvif_start_queue(queue); | 2007 | { |
2008 | DEFINE_WAIT(wait); | ||
2009 | |||
2010 | if (xenvif_have_rx_work(queue)) | ||
2011 | return; | ||
2012 | |||
2013 | for (;;) { | ||
2014 | long ret; | ||
2015 | |||
2016 | prepare_to_wait(&queue->wq, &wait, TASK_INTERRUPTIBLE); | ||
2017 | if (xenvif_have_rx_work(queue)) | ||
2018 | break; | ||
2019 | ret = schedule_timeout(xenvif_rx_queue_timeout(queue)); | ||
2020 | if (!ret) | ||
2021 | break; | ||
2006 | } | 2022 | } |
2023 | finish_wait(&queue->wq, &wait); | ||
2007 | } | 2024 | } |
2008 | 2025 | ||
2009 | int xenvif_kthread_guest_rx(void *data) | 2026 | int xenvif_kthread_guest_rx(void *data) |
2010 | { | 2027 | { |
2011 | struct xenvif_queue *queue = data; | 2028 | struct xenvif_queue *queue = data; |
2012 | struct sk_buff *skb; | 2029 | struct xenvif *vif = queue->vif; |
2013 | 2030 | ||
2014 | while (!kthread_should_stop()) { | 2031 | for (;;) { |
2015 | wait_event_interruptible(queue->wq, | 2032 | xenvif_wait_for_rx_work(queue); |
2016 | rx_work_todo(queue) || | ||
2017 | queue->vif->disabled || | ||
2018 | test_bit(QUEUE_STATUS_RX_PURGE_EVENT, &queue->status) || | ||
2019 | kthread_should_stop()); | ||
2020 | 2033 | ||
2021 | if (kthread_should_stop()) | 2034 | if (kthread_should_stop()) |
2022 | break; | 2035 | break; |
@@ -2028,35 +2041,29 @@ int xenvif_kthread_guest_rx(void *data) | |||
2028 | * context so we defer it here, if this thread is | 2041 | * context so we defer it here, if this thread is |
2029 | * associated with queue 0. | 2042 | * associated with queue 0. |
2030 | */ | 2043 | */ |
2031 | if (unlikely(queue->vif->disabled && queue->id == 0)) { | 2044 | if (unlikely(vif->disabled && queue->id == 0)) { |
2032 | xenvif_carrier_off(queue->vif); | 2045 | xenvif_carrier_off(vif); |
2033 | } else if (unlikely(queue->vif->disabled)) { | 2046 | xenvif_rx_queue_purge(queue); |
2034 | /* kthread_stop() would be called upon this thread soon, | 2047 | continue; |
2035 | * be a bit proactive | ||
2036 | */ | ||
2037 | skb_queue_purge(&queue->rx_queue); | ||
2038 | queue->rx_last_skb_slots = 0; | ||
2039 | } else if (unlikely(test_and_clear_bit(QUEUE_STATUS_RX_PURGE_EVENT, | ||
2040 | &queue->status))) { | ||
2041 | xenvif_rx_purge_event(queue); | ||
2042 | } else if (!netif_carrier_ok(queue->vif->dev)) { | ||
2043 | /* Another queue stalled and turned the carrier off, so | ||
2044 | * purge the internal queue of queues which were not | ||
2045 | * blocked | ||
2046 | */ | ||
2047 | skb_queue_purge(&queue->rx_queue); | ||
2048 | queue->rx_last_skb_slots = 0; | ||
2049 | } | 2048 | } |
2050 | 2049 | ||
2051 | if (!skb_queue_empty(&queue->rx_queue)) | 2050 | if (!skb_queue_empty(&queue->rx_queue)) |
2052 | xenvif_rx_action(queue); | 2051 | xenvif_rx_action(queue); |
2053 | 2052 | ||
2053 | /* Queued packets may have foreign pages from other | ||
2054 | * domains. These cannot be queued indefinitely as | ||
2055 | * this would starve guests of grant refs and transmit | ||
2056 | * slots. | ||
2057 | */ | ||
2058 | xenvif_rx_queue_drop_expired(queue); | ||
2059 | |||
2060 | xenvif_rx_queue_maybe_wake(queue); | ||
2061 | |||
2054 | cond_resched(); | 2062 | cond_resched(); |
2055 | } | 2063 | } |
2056 | 2064 | ||
2057 | /* Bin any remaining skbs */ | 2065 | /* Bin any remaining skbs */ |
2058 | while ((skb = skb_dequeue(&queue->rx_queue)) != NULL) | 2066 | xenvif_rx_queue_purge(queue); |
2059 | dev_kfree_skb(skb); | ||
2060 | 2067 | ||
2061 | return 0; | 2068 | return 0; |
2062 | } | 2069 | } |
diff --git a/drivers/net/xen-netback/xenbus.c b/drivers/net/xen-netback/xenbus.c index 9060857c9022..96a754d8e517 100644 --- a/drivers/net/xen-netback/xenbus.c +++ b/drivers/net/xen-netback/xenbus.c | |||
@@ -52,6 +52,7 @@ static int xenvif_read_io_ring(struct seq_file *m, void *v) | |||
52 | struct xenvif_queue *queue = m->private; | 52 | struct xenvif_queue *queue = m->private; |
53 | struct xen_netif_tx_back_ring *tx_ring = &queue->tx; | 53 | struct xen_netif_tx_back_ring *tx_ring = &queue->tx; |
54 | struct xen_netif_rx_back_ring *rx_ring = &queue->rx; | 54 | struct xen_netif_rx_back_ring *rx_ring = &queue->rx; |
55 | struct netdev_queue *dev_queue; | ||
55 | 56 | ||
56 | if (tx_ring->sring) { | 57 | if (tx_ring->sring) { |
57 | struct xen_netif_tx_sring *sring = tx_ring->sring; | 58 | struct xen_netif_tx_sring *sring = tx_ring->sring; |
@@ -112,6 +113,13 @@ static int xenvif_read_io_ring(struct seq_file *m, void *v) | |||
112 | queue->credit_timeout.expires, | 113 | queue->credit_timeout.expires, |
113 | jiffies); | 114 | jiffies); |
114 | 115 | ||
116 | dev_queue = netdev_get_tx_queue(queue->vif->dev, queue->id); | ||
117 | |||
118 | seq_printf(m, "\nRx internal queue: len %u max %u pkts %u %s\n", | ||
119 | queue->rx_queue_len, queue->rx_queue_max, | ||
120 | skb_queue_len(&queue->rx_queue), | ||
121 | netif_tx_queue_stopped(dev_queue) ? "stopped" : "running"); | ||
122 | |||
115 | return 0; | 123 | return 0; |
116 | } | 124 | } |
117 | 125 | ||