* [PATCH net-next] ibmvnic: Defer tx completion processing using a wait queue
@ 2016-04-12 19:38 John Allen
2016-04-12 20:12 ` Eric Dumazet
0 siblings, 1 reply; 4+ messages in thread
From: John Allen @ 2016-04-12 19:38 UTC (permalink / raw)
To: Thomas Falcon; +Cc: netdev, linuxppc-dev
Moves tx completion processing out of interrupt context, deferring work
using a wait queue. With this work now deferred, we must account for the
possibility that skbs can be sent faster than we can process completion
requests in which case the tx buffer will overflow. If the tx buffer is
full, ibmvnic_xmit will return NETDEV_TX_BUSY and stop the current tx
queue. Subsequently, the queue will be restarted in ibmvnic_complete_tx
when all pending tx completion requests have been cleared.
Signed-off-by: John Allen <jallen@linux.vnet.ibm.com>
---
diff --git a/drivers/net/ethernet/ibm/ibmvnic.c b/drivers/net/ethernet/ibm/ibmvnic.c
index 864cb21..641e340 100644
--- a/drivers/net/ethernet/ibm/ibmvnic.c
+++ b/drivers/net/ethernet/ibm/ibmvnic.c
@@ -105,6 +105,7 @@ static int pending_scrq(struct ibmvnic_adapter *,
struct ibmvnic_sub_crq_queue *);
static union sub_crq *ibmvnic_next_scrq(struct ibmvnic_adapter *,
struct ibmvnic_sub_crq_queue *);
+static int ibmvnic_tx_work(void *data);
static int ibmvnic_poll(struct napi_struct *napi, int data);
static void send_map_query(struct ibmvnic_adapter *adapter);
static void send_request_map(struct ibmvnic_adapter *, dma_addr_t, __be32, u8);
@@ -437,6 +438,17 @@ static int ibmvnic_open(struct net_device *netdev)
tx_pool->consumer_index = 0;
tx_pool->producer_index = 0;
+
+ init_waitqueue_head(&tx_pool->ibmvnic_tx_comp_q);
+ tx_pool->work_thread =
+ kthread_run(ibmvnic_tx_work, adapter->tx_scrq[i],
+ "%s_%s_%d",
+ IBMVNIC_NAME, adapter->netdev->name, i);
+ if (IS_ERR(tx_pool->work_thread)) {
+ dev_err(dev, "Couldn't create kernel thread: %ld\n",
+ PTR_ERR(tx_pool->work_thread));
+ goto thread_failed;
+ }
}
adapter->bounce_buffer_size =
(netdev->mtu + ETH_HLEN - 1) / PAGE_SIZE + 1;
@@ -477,6 +489,9 @@ bounce_map_failed:
bounce_alloc_failed:
i = tx_subcrqs - 1;
kfree(adapter->tx_pool[i].free_map);
+thread_failed:
+ for (j = 0; j < i; j++)
+ kthread_stop(adapter->tx_pool[j].work_thread);
tx_fm_alloc_failed:
free_long_term_buff(adapter, &adapter->tx_pool[i].long_term_buff);
tx_ltb_alloc_failed:
@@ -731,6 +746,16 @@ static int ibmvnic_xmit(struct sk_buff *skb, struct net_device *netdev)
}
index = tx_pool->free_map[tx_pool->consumer_index];
+ /* tx queue full */
+ if ((index + 1) % adapter->max_tx_entries_per_subcrq ==
+ tx_pool->free_map[tx_pool->producer_index]) {
+ netif_tx_stop_queue(netdev_get_tx_queue(netdev, queue_num));
+ tx_send_failed++;
+ tx_dropped++;
+ ret = NETDEV_TX_BUSY;
+ goto out;
+ }
+
offset = index * adapter->req_mtu;
dst = tx_pool->long_term_buff.buff + offset;
memset(dst, 0, adapter->req_mtu);
@@ -1314,6 +1339,7 @@ static int ibmvnic_complete_tx(struct ibmvnic_adapter *adapter,
{
struct device *dev = &adapter->vdev->dev;
struct ibmvnic_tx_buff *txbuff;
+ struct netdev_queue *txq;
union sub_crq *next;
int index;
int i, j;
@@ -1361,6 +1387,10 @@ restart_loop:
next->tx_comp.first = 0;
}
+ txq = netdev_get_tx_queue(adapter->netdev, scrq->pool_index);
+ if (netif_tx_queue_stopped(txq))
+ netif_tx_wake_queue(txq);
+
enable_scrq_irq(adapter, scrq);
if (pending_scrq(adapter, scrq)) {
@@ -1371,13 +1401,35 @@ restart_loop:
return 0;
}
+static int ibmvnic_tx_work(void *data)
+{
+ int rc;
+ struct ibmvnic_sub_crq_queue *scrq = data;
+ struct ibmvnic_adapter *adapter = scrq->adapter;
+
+ while (1) {
+ rc = wait_event_interruptible(adapter->
+ tx_pool[scrq->pool_index].
+ ibmvnic_tx_comp_q,
+ pending_scrq(adapter, scrq));
+ BUG_ON(rc);
+
+ if (kthread_should_stop())
+ break;
+
+ disable_scrq_irq(adapter, scrq);
+
+ ibmvnic_complete_tx(adapter, scrq);
+ }
+ return 0;
+}
+
static irqreturn_t ibmvnic_interrupt_tx(int irq, void *instance)
{
struct ibmvnic_sub_crq_queue *scrq = instance;
struct ibmvnic_adapter *adapter = scrq->adapter;
- disable_scrq_irq(adapter, scrq);
- ibmvnic_complete_tx(adapter, scrq);
+ wake_up(&adapter->tx_pool[scrq->pool_index].ibmvnic_tx_comp_q);
return IRQ_HANDLED;
}
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH net-next] ibmvnic: Defer tx completion processing using a wait queue
2016-04-12 19:38 [PATCH net-next] ibmvnic: Defer tx completion processing using a wait queue John Allen
@ 2016-04-12 20:12 ` Eric Dumazet
2016-04-12 21:00 ` John Allen
0 siblings, 1 reply; 4+ messages in thread
From: Eric Dumazet @ 2016-04-12 20:12 UTC (permalink / raw)
To: John Allen; +Cc: Thomas Falcon, netdev, linuxppc-dev
On Tue, 2016-04-12 at 14:38 -0500, John Allen wrote:
> Moves tx completion processing out of interrupt context, deferring work
> using a wait queue. With this work now deferred, we must account for the
> possibility that skbs can be sent faster than we can process completion
> requests in which case the tx buffer will overflow. If the tx buffer is
> full, ibmvnic_xmit will return NETDEV_TX_BUSY and stop the current tx
> queue. Subsequently, the queue will be restarted in ibmvnic_complete_tx
> when all pending tx completion requests have been cleared.
1) Why is this needed ?
2) If it is needed, why is this not done in a generic way, so that other
drivers can use this ?
Thanks.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net-next] ibmvnic: Defer tx completion processing using a wait queue
2016-04-12 20:12 ` Eric Dumazet
@ 2016-04-12 21:00 ` John Allen
2016-04-13 1:12 ` David Miller
0 siblings, 1 reply; 4+ messages in thread
From: John Allen @ 2016-04-12 21:00 UTC (permalink / raw)
To: Eric Dumazet; +Cc: Thomas Falcon, netdev, linuxppc-dev
On 04/12/2016 03:12 PM, Eric Dumazet wrote:
> On Tue, 2016-04-12 at 14:38 -0500, John Allen wrote:
>> Moves tx completion processing out of interrupt context, deferring work
>> using a wait queue. With this work now deferred, we must account for the
>> possibility that skbs can be sent faster than we can process completion
>> requests in which case the tx buffer will overflow. If the tx buffer is
>> full, ibmvnic_xmit will return NETDEV_TX_BUSY and stop the current tx
>> queue. Subsequently, the queue will be restarted in ibmvnic_complete_tx
>> when all pending tx completion requests have been cleared.
>
> 1) Why is this needed ?
In the current ibmvnic implementation, tx completion processing is done in
interrupt context. Depending on the load, this can block further
interrupts for a long time. This patch just creates a bottom half so that
when a tx completion interrupt comes in, we can defer the majority of the
work and exit interrupt context quickly.
>
> 2) If it is needed, why is this not done in a generic way, so that other
> drivers can use this ?
I'm still fairly new to network driver development so I'm not in tune with
the needs of other drivers. My assumption was that the wait queue data
structure was a reasonably generic way to handle something like this. Is
there a more appropriate/generic way of implementing a bottom half for
this purpose?
-John
>
> Thanks.
>
>
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net-next] ibmvnic: Defer tx completion processing using a wait queue
2016-04-12 21:00 ` John Allen
@ 2016-04-13 1:12 ` David Miller
0 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2016-04-13 1:12 UTC (permalink / raw)
To: jallen; +Cc: eric.dumazet, tlfalcon, netdev, linuxppc-dev
From: John Allen <jallen@linux.vnet.ibm.com>
Date: Tue, 12 Apr 2016 16:00:23 -0500
> On 04/12/2016 03:12 PM, Eric Dumazet wrote:
>> On Tue, 2016-04-12 at 14:38 -0500, John Allen wrote:
>>> Moves tx completion processing out of interrupt context, deferring work
>>> using a wait queue. With this work now deferred, we must account for the
>>> possibility that skbs can be sent faster than we can process completion
>>> requests in which case the tx buffer will overflow. If the tx buffer is
>>> full, ibmvnic_xmit will return NETDEV_TX_BUSY and stop the current tx
>>> queue. Subsequently, the queue will be restarted in ibmvnic_complete_tx
>>> when all pending tx completion requests have been cleared.
>>
>> 1) Why is this needed ?
>
> In the current ibmvnic implementation, tx completion processing is done in
> interrupt context. Depending on the load, this can block further
> interrupts for a long time. This patch just creates a bottom half so that
> when a tx completion interrupt comes in, we can defer the majority of the
> work and exit interrupt context quickly.
You should use NAPI polling for this, not your own invented
mechanism.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-04-13 1:12 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-04-12 19:38 [PATCH net-next] ibmvnic: Defer tx completion processing using a wait queue John Allen
2016-04-12 20:12 ` Eric Dumazet
2016-04-12 21:00 ` John Allen
2016-04-13 1:12 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).