From patchwork Thu Aug 26 14:57:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harman Kalra X-Patchwork-Id: 97373 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 3B07AA0547; Thu, 26 Aug 2021 16:58:44 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C94D241241; Thu, 26 Aug 2021 16:58:37 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by mails.dpdk.org (Postfix) with ESMTP id 2E90141228 for ; Thu, 26 Aug 2021 16:58:36 +0200 (CEST) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.16.1.2/8.16.0.43) with SMTP id 17QC3QhG017023; Thu, 26 Aug 2021 07:58:35 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=pfpt0220; bh=WTy2g6lFBlDf+sSqQCPb6RWNqRKGjZHBvm1qnkaxrzU=; b=O92zB56ZRPgBuo+LYBhdGGd7heQq45aCuu+rSQOumGtlvPyQ4bpmfD2GcrruDy0k3hYM lxYivQqEkpQtn3g+cNoIx99Rw4KJtjMohzd2JTTS/Egy3gzvtsih4Gza//mZ+tVZLZm8 lxzX+YNlR4uJzUQWX101fIg8u1QU/qLXySsO+O+qjcHvHL7PRM+LHtNFeqbu2h1FgKul i8vs2QyLkcGSY3GVCcbc6FaOi6kY+lxba/1obccyXPwO+BMpeX60NtzvRBBjMjJ2iAWE qYRlLyOk1p3GxQ6vyocGe70WGFMAcgidGf5uSydrEeLRVPqzjGvvnl4mM55ax0Hh7xRo bA== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0a-0016f401.pphosted.com with ESMTP id 3apamh0nfa-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Thu, 26 Aug 2021 07:58:35 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Thu, 26 Aug 2021 07:58:33 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Thu, 26 Aug 2021 07:58:33 -0700 Received: from localhost.localdomain (unknown [10.29.52.211]) by maili.marvell.com (Postfix) with ESMTP id 986573F705F; Thu, 26 Aug 2021 07:58:32 -0700 (PDT) From: Harman Kalra To: , Bruce Richardson CC: Harman Kalra Date: Thu, 26 Aug 2021 20:27:26 +0530 Message-ID: <20210826145726.102081-8-hkalra@marvell.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20210826145726.102081-1-hkalra@marvell.com> References: <20210826145726.102081-1-hkalra@marvell.com> MIME-Version: 1.0 X-Proofpoint-GUID: BB4PSbSDQ9XRz6pijVncc5R_E2pTG_pz X-Proofpoint-ORIG-GUID: BB4PSbSDQ9XRz6pijVncc5R_E2pTG_pz X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.182.1,Aquarius:18.0.790,Hydra:6.0.391,FMLib:17.0.607.475 definitions=2021-08-26_04,2021-08-26_02,2020-04-07_01 Subject: [dpdk-dev] [RFC 7/7] eal/alarm: introduce alarm fini routine X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Implementing alarm cleanup routine, where the memory allocated for interrupt instance can be freed. Signed-off-by: Harman Kalra --- lib/eal/common/eal_private.h | 11 ++++++++ lib/eal/freebsd/eal.c | 1 + lib/eal/freebsd/eal_alarm.c | 50 +++++++++++++++++++++++++++++++----- lib/eal/linux/eal.c | 1 + lib/eal/linux/eal_alarm.c | 10 +++++++- 5 files changed, 66 insertions(+), 7 deletions(-) diff --git a/lib/eal/common/eal_private.h b/lib/eal/common/eal_private.h index 64cf4e81c8..ed429dec9d 100644 --- a/lib/eal/common/eal_private.h +++ b/lib/eal/common/eal_private.h @@ -162,6 +162,17 @@ int rte_eal_intr_init(void); */ int rte_eal_alarm_init(void); +/** + * Init alarm mechanism. This is to allow a callback be called after + * specific time. + * + * This function is private to EAL. + * + * @return + * 0 on success, negative on error + */ +void rte_eal_alarm_fini(void); + /** * Function is to check if the kernel module(like, vfio, vfio_iommu_type1, * etc.) loaded. diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c index 6cee5ae369..7efead4f48 100644 --- a/lib/eal/freebsd/eal.c +++ b/lib/eal/freebsd/eal.c @@ -973,6 +973,7 @@ rte_eal_cleanup(void) rte_eal_memory_detach(); rte_trace_save(); eal_trace_fini(); + rte_eal_alarm_fini(); eal_cleanup_config(internal_conf); return 0; } diff --git a/lib/eal/freebsd/eal_alarm.c b/lib/eal/freebsd/eal_alarm.c index 07baecd64f..33855393a6 100644 --- a/lib/eal/freebsd/eal_alarm.c +++ b/lib/eal/freebsd/eal_alarm.c @@ -32,7 +32,7 @@ struct alarm_entry { LIST_ENTRY(alarm_entry) next; - struct rte_intr_handle handle; + struct rte_intr_handle *handle; struct timespec time; rte_eal_alarm_callback cb_fn; void *cb_arg; @@ -43,7 +43,7 @@ struct alarm_entry { static LIST_HEAD(alarm_list, alarm_entry) alarm_list = LIST_HEAD_INITIALIZER(); static rte_spinlock_t alarm_list_lk = RTE_SPINLOCK_INITIALIZER; -static struct rte_intr_handle intr_handle = {.fd = -1 }; +static struct rte_intr_handle *intr_handle; static void eal_alarm_callback(void *arg); void @@ -56,16 +56,40 @@ rte_eal_alarm_fini(void) int rte_eal_alarm_init(void) { - intr_handle.type = RTE_INTR_HANDLE_ALARM; + int fd; + + intr_handle = + rte_intr_handle_instance_alloc(RTE_INTR_HANDLE_DEFAULT_SIZE, + false); + if (!intr_handle) { + RTE_LOG(ERR, EAL, "Fail to allocate intr_handle\n"); + goto error; + } + + if (rte_intr_handle_type_set(intr_handle, RTE_INTR_HANDLE_ALARM)) + goto error; + + if (rte_intr_handle_fd_set(intr_handle, -1)) + goto error; /* on FreeBSD, timers don't use fd's, and their identifiers are stored * in separate namespace from fd's, so using any value is OK. however, * EAL interrupts handler expects fd's to be unique, so use an actual fd * to guarantee unique timer identifier. */ - intr_handle.fd = open("/dev/zero", O_RDONLY); + fd = open("/dev/zero", O_RDONLY); + if (rte_intr_handle_fd_set(intr_handle, fd)) + goto fail; return 0; +fail: + close(fd); +error: + if (intr_handle) + rte_intr_handle_instance_free(intr_handle); + + rte_intr_handle_fd_set(intr_handle, -1); + return -1; } static inline int @@ -125,7 +149,7 @@ unregister_current_callback(void) ap = LIST_FIRST(&alarm_list); do { - ret = rte_intr_callback_unregister(&intr_handle, + ret = rte_intr_callback_unregister(intr_handle, eal_alarm_callback, &ap->time); } while (ret == -EAGAIN); } @@ -143,7 +167,7 @@ register_first_callback(void) ap = LIST_FIRST(&alarm_list); /* register a new callback */ - ret = rte_intr_callback_register(&intr_handle, + ret = rte_intr_callback_register(intr_handle, eal_alarm_callback, &ap->time); } return ret; @@ -171,6 +195,8 @@ eal_alarm_callback(void *arg __rte_unused) rte_spinlock_lock(&alarm_list_lk); LIST_REMOVE(ap, next); + if (ap->handle) + rte_intr_handle_instance_free(ap->handle); free(ap); ap = LIST_FIRST(&alarm_list); @@ -209,6 +235,12 @@ rte_eal_alarm_set(uint64_t us, rte_eal_alarm_callback cb_fn, void *cb_arg) new_alarm->time.tv_nsec = (now.tv_nsec + ns) % NS_PER_S; new_alarm->time.tv_sec = now.tv_sec + ((now.tv_nsec + ns) / NS_PER_S); + new_alarm->handle = + rte_intr_handle_instance_alloc(RTE_INTR_HANDLE_DEFAULT_SIZE, + false); + if (new_alarm->handle == NULL) + return -ENOMEM; + rte_spinlock_lock(&alarm_list_lk); if (LIST_EMPTY(&alarm_list)) @@ -263,6 +295,9 @@ rte_eal_alarm_cancel(rte_eal_alarm_callback cb_fn, void *cb_arg) if (ap->executing == 0) { LIST_REMOVE(ap, next); free(ap); + if (ap->handle) + rte_intr_handle_instance_free( + ap->handle); count++; } else { /* If calling from other context, mark that @@ -289,6 +324,9 @@ rte_eal_alarm_cancel(rte_eal_alarm_callback cb_fn, void *cb_arg) cb_arg == ap->cb_arg)) { if (ap->executing == 0) { LIST_REMOVE(ap, next); + if (ap->handle) + rte_intr_handle_instance_free( + ap->handle); free(ap); count++; ap = ap_prev; diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c index 3577eaeaa4..5c8af85ad5 100644 --- a/lib/eal/linux/eal.c +++ b/lib/eal/linux/eal.c @@ -1370,6 +1370,7 @@ rte_eal_cleanup(void) rte_eal_memory_detach(); rte_trace_save(); eal_trace_fini(); + rte_eal_alarm_fini(); eal_cleanup_config(internal_conf); return 0; } diff --git a/lib/eal/linux/eal_alarm.c b/lib/eal/linux/eal_alarm.c index e959fba27b..5dd804f83c 100644 --- a/lib/eal/linux/eal_alarm.c +++ b/lib/eal/linux/eal_alarm.c @@ -58,6 +58,13 @@ static struct rte_intr_handle *intr_handle; static int handler_registered = 0; static void eal_alarm_callback(void *arg); +void +rte_eal_alarm_fini(void) +{ + if (intr_handle) + rte_intr_handle_instance_free(intr_handle); +} + int rte_eal_alarm_init(void) { @@ -70,7 +77,8 @@ rte_eal_alarm_init(void) goto error; } - rte_intr_handle_type_set(intr_handle, RTE_INTR_HANDLE_ALARM); + if (rte_intr_handle_type_set(intr_handle, RTE_INTR_HANDLE_ALARM)) + goto error; /* create a timerfd file descriptor */ if (rte_intr_handle_fd_set(intr_handle,