From e7e10859d317085fd880f410ae07c601c3a27e39 Mon Sep 17 00:00:00 2001 From: Maciej Szwed Date: Wed, 10 Jun 2020 12:11:16 +0200 Subject: [PATCH] nvmf: Make spdk_nvmf_tgt_accept return the number of events accepted This will be usefull for pollers/threads stats. Signed-off-by: Maciej Szwed Change-Id: I4d1651f3ff6410c258c8bc75c2a68640b67d2ed9 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/2849 Community-CI: Broadcom CI Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris Reviewed-by: Anil Veerabhadrappa Reviewed-by: Aleksey Marchuk Reviewed-by: Shuhei Matsumoto --- include/spdk/nvmf.h | 2 +- include/spdk/nvmf_transport.h | 2 +- lib/nvmf/fc.c | 7 +++++-- lib/nvmf/nvmf.c | 7 +++++-- lib/nvmf/rdma.c | 11 +++++++---- lib/nvmf/tcp.c | 13 ++++++++++--- lib/nvmf/transport.c | 4 ++-- lib/nvmf/transport.h | 4 ++-- module/event/subsystems/nvmf/nvmf_tgt.c | 5 +++-- 9 files changed, 36 insertions(+), 19 deletions(-) diff --git a/include/spdk/nvmf.h b/include/spdk/nvmf.h index 1aad01e44..7d5a41392 100644 --- a/include/spdk/nvmf.h +++ b/include/spdk/nvmf.h @@ -241,7 +241,7 @@ int spdk_nvmf_tgt_stop_listen(struct spdk_nvmf_tgt *tgt, * \param cb_fn Called for each newly discovered qpair. * \param cb_arg A context argument passed to cb_fn. */ -void spdk_nvmf_tgt_accept(struct spdk_nvmf_tgt *tgt, new_qpair_fn cb_fn, void *cb_arg); +uint32_t spdk_nvmf_tgt_accept(struct spdk_nvmf_tgt *tgt, new_qpair_fn cb_fn, void *cb_arg); /** * Create a poll group. diff --git a/include/spdk/nvmf_transport.h b/include/spdk/nvmf_transport.h index a15b3c501..68abc6b88 100644 --- a/include/spdk/nvmf_transport.h +++ b/include/spdk/nvmf_transport.h @@ -252,7 +252,7 @@ struct spdk_nvmf_transport_ops { /** * Check for new connections on the transport. */ - void (*accept)(struct spdk_nvmf_transport *transport, new_qpair_fn cb_fn, void *cb_arg); + uint32_t (*accept)(struct spdk_nvmf_transport *transport, new_qpair_fn cb_fn, void *cb_arg); /** * Initialize subset of identify controller data. diff --git a/lib/nvmf/fc.c b/lib/nvmf/fc.c index aef9f2174..b375ed343 100644 --- a/lib/nvmf/fc.c +++ b/lib/nvmf/fc.c @@ -1908,10 +1908,11 @@ nvmf_fc_stop_listen(struct spdk_nvmf_transport *transport, { } -static void +static uint32_t nvmf_fc_accept(struct spdk_nvmf_transport *transport, new_qpair_fn cb_fn, void *cb_arg) { struct spdk_nvmf_fc_port *fc_port = NULL; + uint32_t count = 0; static bool start_lld = false; if (spdk_unlikely(!start_lld)) { @@ -1923,9 +1924,11 @@ nvmf_fc_accept(struct spdk_nvmf_transport *transport, new_qpair_fn cb_fn, void * TAILQ_FOREACH(fc_port, &g_spdk_nvmf_fc_port_list, link) { if (fc_port->hw_port_status == SPDK_FC_PORT_ONLINE) { fc_port->new_qp_cb = cb_fn; - nvmf_fc_process_queue(&fc_port->ls_queue); + count += nvmf_fc_process_queue(&fc_port->ls_queue); } } + + return count; } static void diff --git a/lib/nvmf/nvmf.c b/lib/nvmf/nvmf.c index e2f6afcfb..f31f8efc3 100644 --- a/lib/nvmf/nvmf.c +++ b/lib/nvmf/nvmf.c @@ -720,14 +720,17 @@ spdk_nvmf_tgt_get_transport(struct spdk_nvmf_tgt *tgt, const char *transport_nam return NULL; } -void +uint32_t spdk_nvmf_tgt_accept(struct spdk_nvmf_tgt *tgt, new_qpair_fn cb_fn, void *cb_arg) { struct spdk_nvmf_transport *transport, *tmp; + uint32_t count = 0; TAILQ_FOREACH_SAFE(transport, &tgt->transports, link, tmp) { - nvmf_transport_accept(transport, cb_fn, cb_arg); + count += nvmf_transport_accept(transport, cb_fn, cb_arg); } + + return count; } struct spdk_nvmf_poll_group * diff --git a/lib/nvmf/rdma.c b/lib/nvmf/rdma.c index be83b67b6..b845d6b9e 100644 --- a/lib/nvmf/rdma.c +++ b/lib/nvmf/rdma.c @@ -3157,18 +3157,19 @@ nvmf_process_ib_event(struct spdk_nvmf_rdma_device *device) ibv_ack_async_event(&event); } -static void +static uint32_t nvmf_rdma_accept(struct spdk_nvmf_transport *transport, new_qpair_fn cb_fn, void *cb_arg) { int nfds, i = 0; struct spdk_nvmf_rdma_transport *rtransport; struct spdk_nvmf_rdma_device *device, *tmp; + uint32_t count; rtransport = SPDK_CONTAINEROF(transport, struct spdk_nvmf_rdma_transport, transport); - nfds = poll(rtransport->poll_fds, rtransport->npoll_fds, 0); + count = nfds = poll(rtransport->poll_fds, rtransport->npoll_fds, 0); if (nfds <= 0) { - return; + return 0; } /* The first poll descriptor is RDMA CM event */ @@ -3178,7 +3179,7 @@ nvmf_rdma_accept(struct spdk_nvmf_transport *transport, new_qpair_fn cb_fn, void } if (nfds == 0) { - return; + return count; } /* Second and subsequent poll descriptors are IB async events */ @@ -3190,6 +3191,8 @@ nvmf_rdma_accept(struct spdk_nvmf_transport *transport, new_qpair_fn cb_fn, void } /* check all flagged fd's have been served */ assert(nfds == 0); + + return count; } static void diff --git a/lib/nvmf/tcp.c b/lib/nvmf/tcp.c index 338102909..78098cbf4 100644 --- a/lib/nvmf/tcp.c +++ b/lib/nvmf/tcp.c @@ -905,11 +905,12 @@ nvmf_tcp_handle_connect(struct spdk_nvmf_transport *transport, cb_fn(&tqpair->qpair, cb_arg); } -static void +static uint32_t nvmf_tcp_port_accept(struct spdk_nvmf_transport *transport, struct spdk_nvmf_tcp_port *port, new_qpair_fn cb_fn, void *cb_arg) { struct spdk_sock *sock; + uint32_t count = 0; int i; for (i = 0; i < NVMF_TCP_MAX_ACCEPT_SOCK_ONE_TIME; i++) { @@ -917,21 +918,27 @@ nvmf_tcp_port_accept(struct spdk_nvmf_transport *transport, struct spdk_nvmf_tcp if (sock == NULL) { break; } + count++; nvmf_tcp_handle_connect(transport, port, sock, cb_fn, cb_arg); } + + return count; } -static void +static uint32_t nvmf_tcp_accept(struct spdk_nvmf_transport *transport, new_qpair_fn cb_fn, void *cb_arg) { struct spdk_nvmf_tcp_transport *ttransport; struct spdk_nvmf_tcp_port *port; + uint32_t count = 0; ttransport = SPDK_CONTAINEROF(transport, struct spdk_nvmf_tcp_transport, transport); TAILQ_FOREACH(port, &ttransport->ports, link) { - nvmf_tcp_port_accept(transport, port, cb_fn, cb_arg); + count += nvmf_tcp_port_accept(transport, port, cb_fn, cb_arg); } + + return count; } static void diff --git a/lib/nvmf/transport.c b/lib/nvmf/transport.c index add9e52dc..da2c810c0 100644 --- a/lib/nvmf/transport.c +++ b/lib/nvmf/transport.c @@ -254,10 +254,10 @@ spdk_nvmf_transport_stop_listen(struct spdk_nvmf_transport *transport, return 0; } -void +uint32_t nvmf_transport_accept(struct spdk_nvmf_transport *transport, new_qpair_fn cb_fn, void *cb_arg) { - transport->ops->accept(transport, cb_fn, cb_arg); + return transport->ops->accept(transport, cb_fn, cb_arg); } void diff --git a/lib/nvmf/transport.h b/lib/nvmf/transport.h index 30427fb8d..0f5e9f6d8 100644 --- a/lib/nvmf/transport.h +++ b/lib/nvmf/transport.h @@ -40,8 +40,8 @@ #include "spdk/nvmf.h" #include "spdk/nvmf_transport.h" -void nvmf_transport_accept(struct spdk_nvmf_transport *transport, new_qpair_fn cb_fn, - void *cb_arg); +uint32_t nvmf_transport_accept(struct spdk_nvmf_transport *transport, new_qpair_fn cb_fn, + void *cb_arg); void nvmf_transport_listener_discover(struct spdk_nvmf_transport *transport, struct spdk_nvme_transport_id *trid, diff --git a/module/event/subsystems/nvmf/nvmf_tgt.c b/module/event/subsystems/nvmf/nvmf_tgt.c index 144f30fd6..9e3f26972 100644 --- a/module/event/subsystems/nvmf/nvmf_tgt.c +++ b/module/event/subsystems/nvmf/nvmf_tgt.c @@ -302,10 +302,11 @@ static int acceptor_poll(void *arg) { struct spdk_nvmf_tgt *tgt = arg; + uint32_t count; - spdk_nvmf_tgt_accept(tgt, new_qpair, NULL); + count = spdk_nvmf_tgt_accept(tgt, new_qpair, NULL); - return -1; + return count; } static void