[PATCH 4/7] nvme-tcp: receive data in softirq

Hannes Reinecke
2024-06-26T12:14:14Z

From: Sagi Grimberg <sagi@grimberg.me>

Network interrupts are already delivered in softirq, so there is
no need to punt things over to a workqueue. This patch adds a
module parameter 'softirq_rx' to process rx packets directly
from the softirq context.

Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
Signed-off-by: Hannes Reinecke <hare@kernel.org>
---
drivers/nvme/host/tcp.c | 52 ++++++++++++++++++++++++++++-------------
1 file changed, 36 insertions(+), 16 deletions(-)

diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c
index faab55ff86fe..599d4ebf888f 100644
--- a/drivers/nvme/host/tcp.c
+++ b/drivers/nvme/host/tcp.c
@@ -46,6 +46,13 @@ static bool wq_unbound;
module_param(wq_unbound, bool, 0644);
MODULE_PARM_DESC(wq_unbound, "Use unbound workqueue for nvme-tcp IO context (default false)");

+/*
+ * RX context runs in softirq
+ */
+static bool softirq_rx;
+module_param(softirq_rx, bool, 0644);
+MODULE_PARM_DESC(softirq_rx, "nvme-tcp RX context in softirq");
+
/*
* TLS handshake timeout
*/
@@ -957,6 +964,20 @@ static int nvme_tcp_recv_skb(read_descriptor_t *desc, struct sk_buff *skb,
return consumed;
}

+static int nvme_tcp_try_recv_locked(struct nvme_tcp_queue *queue)
+{
+ struct socket *sock = queue->sock;
+ struct sock *sk = sock->sk;
+ read_descriptor_t rd_desc;
+ int consumed;
+
+ rd_desc.arg.data = queue;
+ rd_desc.count = 1;
+ queue->nr_cqe = 0;
+ consumed = sock->ops->read_sock(sk, &rd_desc, nvme_tcp_recv_skb);
+ return consumed;
+}
+
static void nvme_tcp_data_ready(struct sock *sk)
{
struct nvme_tcp_queue *queue;
@@ -966,8 +987,12 @@ static void nvme_tcp_data_ready(struct sock *sk)
read_lock_bh(&sk->sk_callback_lock);
queue = sk->sk_user_data;
if (likely(queue && queue->rd_enabled) &&
- !test_bit(NVME_TCP_Q_POLLING, &queue->flags))
- queue_work_on(queue->io_cpu, nvme_tcp_wq, &queue->io_work);
+ !test_bit(NVME_TCP_Q_POLLING, &queue->flags)) {
+ if (softirq_rx)
+ nvme_tcp_try_recv_locked(queue);
+ else
+ queue_work_on(queue->io_cpu, nvme_tcp_wq, &queue->io_work);
+ }
read_unlock_bh(&sk->sk_callback_lock);
}

@@ -1253,16 +1278,11 @@ static int nvme_tcp_try_send(struct nvme_tcp_queue *queue)

static int nvme_tcp_try_recv(struct nvme_tcp_queue *queue)
{
- struct socket *sock = queue->sock;
- struct sock *sk = sock->sk;
- read_descriptor_t rd_desc;
+ struct sock *sk = queue->sock->sk;
int consumed;

- rd_desc.arg.data = queue;
- rd_desc.count = 1;
lock_sock(sk);
- queue->nr_cqe = 0;
- consumed = sock->ops->read_sock(sk, &rd_desc, nvme_tcp_recv_skb);
+ consumed = nvme_tcp_try_recv_locked(queue);
release_sock(sk);
return consumed;
}
@@ -1285,13 +1305,13 @@ static void nvme_tcp_io_work(struct work_struct *w)
else if (unlikely(result < 0))
break;
}
-
- result = nvme_tcp_try_recv(queue);
- if (result > 0)
- pending = true;
- else if (unlikely(result < 0))
- return;
-
+ if (!softirq_rx) {
+ result = nvme_tcp_try_recv(queue);
+ if (result > 0)
+ pending = true;
+ else if (unlikely(result < 0))
+ return;
+ }
if (!pending || !queue->rd_enabled)
return;

--
2.35.3