From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from rcdn-iport-1.cisco.com (rcdn-iport-1.cisco.com [173.37.86.72]) by dpdk.org (Postfix) with ESMTP id C95781B4ED for ; Thu, 29 Nov 2018 16:50:28 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=cisco.com; i=@cisco.com; l=6104; q=dns/txt; s=iport; t=1543506628; x=1544716228; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=RNPWY/pNtwSuuS05esfY++wchkUIlGW6ltTrnEypSHY=; b=J5GEeujbx5ed2lYoYiDDLhdiVE1x3kERjBiAMp5ry+6C7ENS06GcMqCB GkXr3Jmuzn/HIoItoN4iUEY0o6E6Q55ZIkruFqfqjmEc0pOAeHgvXVUK4 JP7AH6tGZy76T8DCh80c+dWQY2/5pP9Z1pLD1wZa1WV0sopRYhjdbB76c 4=; X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0ADAAD5CQBc/40NJK1kGQEBAQEBAQE?= =?us-ascii?q?BAQEBAQcBAQEBAQGBUQQBAQEBAQsBggOBaCcKjAeMCIsrjiYUgWYLAQGEbIM?= =?us-ascii?q?0IjQJDQEDAQECAQECbSiFagsBRoE+DgWDIYF1DacuM4VAhGqHa0WDZheBQD+?= =?us-ascii?q?BEYRTAYMnhXMCiSeWfAmRJwsYkRsBIwmXewIRFIFGOIFVTSMVO4JsgicMC44?= =?us-ascii?q?ePgEBMY0iAYEeAQE?= X-IronPort-AV: E=Sophos;i="5.56,295,1539648000"; d="scan'208";a="489434400" Received: from alln-core-8.cisco.com ([173.36.13.141]) by rcdn-iport-1.cisco.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Nov 2018 15:50:25 +0000 Received: from XCH-RCD-017.cisco.com (xch-rcd-017.cisco.com [173.37.102.27]) by alln-core-8.cisco.com (8.15.2/8.15.2) with ESMTPS id wATFoOUF019174 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=FAIL) for ; Thu, 29 Nov 2018 15:50:24 GMT Received: from JGRAJCIA-DUK21.cisco.com (10.61.208.251) by XCH-RCD-017.cisco.com (173.37.102.27) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Thu, 29 Nov 2018 09:50:23 -0600 From: Jakub Grajciar To: CC: Jakub Grajciar Date: Thu, 29 Nov 2018 16:50:11 +0100 Message-ID: <20181129155011.2408-1-jgrajcia@cisco.com> X-Mailer: git-send-email 2.19.2.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.61.208.251] X-ClientProxiedBy: xch-rcd-007.cisco.com (173.37.102.17) To XCH-RCD-017.cisco.com (173.37.102.27) X-Outbound-SMTP-Client: 173.37.102.27, xch-rcd-017.cisco.com X-Outbound-Node: alln-core-8.cisco.com Subject: [dpdk-dev] [PATCH] eal_interrupts: add option for pending callback unregister X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 29 Nov 2018 15:50:29 -0000 use case: if callback is used to receive message form socket, and the message received is disconnect/error, this callback needs to be unregistered, but cannot because it is still active. With this patch it is possible to mark the callback to be unregistered once the interrupt process is done with this interrupt source. Signed-off-by: Jakub Grajciar --- .../common/include/rte_interrupts.h | 29 +++++++ lib/librte_eal/linuxapp/eal/eal_interrupts.c | 84 ++++++++++++++++++- 2 files changed, 111 insertions(+), 2 deletions(-) diff --git a/lib/librte_eal/common/include/rte_interrupts.h b/lib/librte_eal/common/include/rte_interrupts.h index d751a6378..d03db4c85 100644 --- a/lib/librte_eal/common/include/rte_interrupts.h +++ b/lib/librte_eal/common/include/rte_interrupts.h @@ -24,6 +24,12 @@ struct rte_intr_handle; /** Function to be registered for the specific interrupt */ typedef void (*rte_intr_callback_fn)(void *cb_arg); +/** + * Function to call after a callback is unregistered. + * Can be used to close fd and free cb_arg. + */ +typedef void (*rte_intr_unregister_callback_fn)(struct rte_intr_handle *intr_handle, void *cb_arg); + #include "rte_eal_interrupts.h" /** @@ -61,6 +67,29 @@ int rte_intr_callback_register(const struct rte_intr_handle *intr_handle, int rte_intr_callback_unregister(const struct rte_intr_handle *intr_handle, rte_intr_callback_fn cb, void *cb_arg); +/** + * It unregisters the callback according to the specified interrupt handle, + * after it's no longer acive. Failes if source is not active. + * + * @param intr_handle + * pointer to the interrupt handle. + * @param cb + * callback address. + * @param cb_arg + * address of parameter for callback, (void *)-1 means to remove all + * registered which has the same callback address. + * @param ucb_fn + * callback to call before cb is unregistered (optional). + * can be used to close fd and free cb_arg. + * + * @return + * - On success, return the number of callback entities marked for remove. + * - On failure, a negative value. + */ +int rte_intr_callback_unregister_pending(const struct rte_intr_handle *intr_handle, + rte_intr_callback_fn cb_fn, void *cb_arg, + rte_intr_unregister_callback_fn ucb_fn); + /** * It enables the interrupt for the specified handle. * diff --git a/lib/librte_eal/linuxapp/eal/eal_interrupts.c b/lib/librte_eal/linuxapp/eal/eal_interrupts.c index cbac451e1..41b575e07 100644 --- a/lib/librte_eal/linuxapp/eal/eal_interrupts.c +++ b/lib/librte_eal/linuxapp/eal/eal_interrupts.c @@ -76,6 +76,8 @@ struct rte_intr_callback { TAILQ_ENTRY(rte_intr_callback) next; rte_intr_callback_fn cb_fn; /**< callback address */ void *cb_arg; /**< parameter for callback */ + uint8_t pending_delete; /**< delete after callback is called */ + rte_intr_unregister_callback_fn ucb_fn; /**< function to call before callback is deleted */ }; struct rte_intr_source { @@ -472,6 +474,8 @@ rte_intr_callback_register(const struct rte_intr_handle *intr_handle, } callback->cb_fn = cb; callback->cb_arg = cb_arg; + callback->pending_delete = 0; + callback->ucb_fn = NULL; rte_spinlock_lock(&intr_lock); @@ -518,6 +522,57 @@ rte_intr_callback_register(const struct rte_intr_handle *intr_handle, return ret; } +int +rte_intr_callback_unregister_pending(const struct rte_intr_handle *intr_handle, + rte_intr_callback_fn cb_fn, void *cb_arg, + rte_intr_unregister_callback_fn ucb_fn) +{ + int ret; + struct rte_intr_source *src; + struct rte_intr_callback *cb, *next; + + /* do parameter checking first */ + if (intr_handle == NULL || intr_handle->fd < 0) { + RTE_LOG(ERR, EAL, + "Unregistering with invalid input parameter\n"); + return -EINVAL; + } + + rte_spinlock_lock(&intr_lock); + + /* check if the insterrupt source for the fd is existent */ + TAILQ_FOREACH(src, &intr_sources, next) + if (src->intr_handle.fd == intr_handle->fd) + break; + + /* No interrupt source registered for the fd */ + if (src == NULL) { + ret = -ENOENT; + + /* only usable if the source is active */ + } else if (src->active == 0) { + return -EAGAIN; + + } else { + ret = 0; + + /* walk through the callbacks and mark all that match. */ + for (cb = TAILQ_FIRST(&src->callbacks); cb != NULL; cb = next) { + next = TAILQ_NEXT(cb, next); + if (cb->cb_fn == cb_fn && (cb_arg == (void *)-1 || + cb->cb_arg == cb_arg)) { + cb->pending_delete = 1; + cb->ucb_fn = ucb_fn; + ret++; + } + } + } + + rte_spinlock_unlock(&intr_lock); + + return ret; +} + int rte_intr_callback_unregister(const struct rte_intr_handle *intr_handle, rte_intr_callback_fn cb_fn, void *cb_arg) @@ -698,7 +753,7 @@ static int eal_intr_process_interrupts(struct epoll_event *events, int nfds) { bool call = false; - int n, bytes_read; + int n, bytes_read, rv; struct rte_intr_source *src; struct rte_intr_callback *cb, *next; union rte_intr_read_buffer buf; @@ -823,9 +878,34 @@ eal_intr_process_interrupts(struct epoll_event *events, int nfds) rte_spinlock_lock(&intr_lock); } } - /* we done with that interrupt source, release it. */ src->active = 0; + + rv = 0; + + /* check if any callback are supposed to be removed */ + for (cb = TAILQ_FIRST(&src->callbacks); cb != NULL; cb = next) { + next = TAILQ_NEXT(cb, next); + if (cb->pending_delete) { + TAILQ_REMOVE(&src->callbacks, cb, next); + if (cb->ucb_fn) + cb->ucb_fn(&src->intr_handle, cb->cb_arg); + free(cb); + rv++; + } + } + + /* all callbacks for that source are removed. */ + if (TAILQ_EMPTY(&src->callbacks)) { + TAILQ_REMOVE(&intr_sources, src, next); + free(src); + } + + /* notify the pipe fd waited by epoll_wait to rebuild the wait list */ + if (rv >= 0 && write(intr_pipe.writefd, "1", 1) < 0) { + return -EPIPE; + } + rte_spinlock_unlock(&intr_lock); } -- 2.17.1