From: Harman Kalra <hkalra@marvell.com>
To: <dev@dpdk.org>, Bruce Richardson <bruce.richardson@intel.com>
Cc: Harman Kalra <hkalra@marvell.com>
Subject: [dpdk-dev] [RFC 7/7] eal/alarm: introduce alarm fini routine
Date: Thu, 26 Aug 2021 20:27:26 +0530 [thread overview]
Message-ID: <20210826145726.102081-8-hkalra@marvell.com> (raw)
In-Reply-To: <20210826145726.102081-1-hkalra@marvell.com>
Implementing alarm cleanup routine, where the memory allocated
for interrupt instance can be freed.
Signed-off-by: Harman Kalra <hkalra@marvell.com>
---
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,
--
2.18.0
next prev parent reply other threads:[~2021-08-26 14:58 UTC|newest]
Thread overview: 152+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-26 14:57 [dpdk-dev] [RFC 0/7] make rte_intr_handle internal Harman Kalra
2021-08-26 14:57 ` [dpdk-dev] [RFC 1/7] eal: interrupt handle API prototypes Harman Kalra
2021-08-31 15:52 ` Kinsella, Ray
2021-08-26 14:57 ` [dpdk-dev] [RFC 2/7] eal/interrupts: implement get set APIs Harman Kalra
2021-08-31 15:53 ` Kinsella, Ray
2021-08-26 14:57 ` [dpdk-dev] [RFC 3/7] eal/interrupts: avoid direct access to interrupt handle Harman Kalra
2021-08-26 14:57 ` [dpdk-dev] [RFC 4/7] test/interrupt: apply get set interrupt handle APIs Harman Kalra
2021-08-26 14:57 ` [dpdk-dev] [RFC 5/7] drivers: remove direct access to interrupt handle fields Harman Kalra
2021-08-26 14:57 ` [dpdk-dev] [RFC 6/7] eal/interrupts: make interrupt handle structure opaque Harman Kalra
2021-08-26 14:57 ` Harman Kalra [this message]
2021-09-03 12:40 ` [dpdk-dev] [PATCH v1 0/7] make rte_intr_handle internal Harman Kalra
2021-09-03 12:40 ` [dpdk-dev] [PATCH v1 1/7] eal: interrupt handle API prototypes Harman Kalra
2021-09-03 12:40 ` [dpdk-dev] [PATCH v1 2/7] eal/interrupts: implement get set APIs Harman Kalra
2021-09-28 15:46 ` David Marchand
2021-10-04 8:51 ` [dpdk-dev] [EXT] " Harman Kalra
2021-10-04 9:57 ` David Marchand
2021-10-12 15:22 ` Thomas Monjalon
2021-10-13 17:54 ` Harman Kalra
2021-10-13 17:57 ` Harman Kalra
2021-10-13 18:52 ` Thomas Monjalon
2021-10-14 8:22 ` Thomas Monjalon
2021-10-14 9:31 ` Harman Kalra
2021-10-14 9:37 ` David Marchand
2021-10-14 9:41 ` Thomas Monjalon
2021-10-14 10:31 ` Harman Kalra
2021-10-14 10:35 ` Thomas Monjalon
2021-10-14 10:44 ` Harman Kalra
2021-10-14 12:04 ` Thomas Monjalon
2021-10-14 10:25 ` Dmitry Kozlyuk
2021-10-03 18:05 ` [dpdk-dev] " Dmitry Kozlyuk
2021-10-04 10:37 ` [dpdk-dev] [EXT] " Harman Kalra
2021-10-04 11:18 ` Dmitry Kozlyuk
2021-10-04 14:03 ` Harman Kalra
2021-09-03 12:40 ` [dpdk-dev] [PATCH v1 3/7] eal/interrupts: avoid direct access to interrupt handle Harman Kalra
2021-09-03 12:40 ` [dpdk-dev] [PATCH v1 4/7] test/interrupt: apply get set interrupt handle APIs Harman Kalra
2021-09-03 12:41 ` [dpdk-dev] [PATCH v1 5/7] drivers: remove direct access to interrupt handle fields Harman Kalra
2021-09-03 12:41 ` [dpdk-dev] [PATCH v1 6/7] eal/interrupts: make interrupt handle structure opaque Harman Kalra
2021-10-03 18:16 ` Dmitry Kozlyuk
2021-10-04 14:09 ` [dpdk-dev] [EXT] " Harman Kalra
2021-09-03 12:41 ` [dpdk-dev] [PATCH v1 7/7] eal/alarm: introduce alarm fini routine Harman Kalra
2021-09-15 14:13 ` [dpdk-dev] [PATCH v1 0/7] make rte_intr_handle internal Harman Kalra
2021-09-23 8:20 ` David Marchand
2021-10-05 12:14 ` [dpdk-dev] [PATCH v2 0/6] " Harman Kalra
2021-10-05 12:14 ` [dpdk-dev] [PATCH v2 1/6] eal/interrupts: implement get set APIs Harman Kalra
2021-10-14 0:58 ` Dmitry Kozlyuk
2021-10-14 17:15 ` [dpdk-dev] [EXT] " Harman Kalra
2021-10-14 17:53 ` Dmitry Kozlyuk
2021-10-15 7:53 ` Thomas Monjalon
2021-10-14 7:31 ` [dpdk-dev] " David Marchand
2021-10-05 12:14 ` [dpdk-dev] [PATCH v2 2/6] eal/interrupts: avoid direct access to interrupt handle Harman Kalra
2021-10-14 0:59 ` Dmitry Kozlyuk
2021-10-14 17:31 ` [dpdk-dev] [EXT] " Harman Kalra
2021-10-14 17:53 ` Dmitry Kozlyuk
2021-10-05 12:14 ` [dpdk-dev] [PATCH v2 3/6] test/interrupt: apply get set interrupt handle APIs Harman Kalra
2021-10-05 12:15 ` [dpdk-dev] [PATCH v2 4/6] drivers: remove direct access to interrupt handle Harman Kalra
2021-10-05 12:15 ` [dpdk-dev] [PATCH v2 5/6] eal/interrupts: make interrupt handle structure opaque Harman Kalra
2021-10-05 12:15 ` [dpdk-dev] [PATCH v2 6/6] eal/alarm: introduce alarm fini routine Harman Kalra
2021-10-05 16:07 ` [dpdk-dev] [RFC 0/7] make rte_intr_handle internal Stephen Hemminger
2021-10-07 10:57 ` [dpdk-dev] [EXT] " Harman Kalra
2021-10-18 19:37 ` [dpdk-dev] [PATCH v3 " Harman Kalra
2021-10-18 19:37 ` [dpdk-dev] [PATCH v3 1/7] malloc: introduce malloc is ready API Harman Kalra
2021-10-19 15:53 ` Thomas Monjalon
2021-10-18 19:37 ` [dpdk-dev] [PATCH v3 2/7] eal/interrupts: implement get set APIs Harman Kalra
2021-10-18 22:07 ` Dmitry Kozlyuk
2021-10-19 8:50 ` [dpdk-dev] [EXT] " Harman Kalra
2021-10-19 18:44 ` Harman Kalra
2021-10-18 22:56 ` [dpdk-dev] " Stephen Hemminger
2021-10-19 8:32 ` [dpdk-dev] [EXT] " Harman Kalra
2021-10-19 15:58 ` Thomas Monjalon
2021-10-20 15:30 ` Dmitry Kozlyuk
2021-10-21 9:16 ` Harman Kalra
2021-10-21 12:33 ` Dmitry Kozlyuk
2021-10-21 13:32 ` David Marchand
2021-10-21 16:05 ` Harman Kalra
2021-10-18 19:37 ` [dpdk-dev] [PATCH v3 3/7] eal/interrupts: avoid direct access to interrupt handle Harman Kalra
2021-10-18 19:37 ` [dpdk-dev] [PATCH v3 4/7] test/interrupt: apply get set interrupt handle APIs Harman Kalra
2021-10-18 19:37 ` [dpdk-dev] [PATCH v3 5/7] drivers: remove direct access to interrupt handle Harman Kalra
2021-10-18 19:37 ` [dpdk-dev] [PATCH v3 6/7] eal/interrupts: make interrupt handle structure opaque Harman Kalra
2021-10-18 19:37 ` [dpdk-dev] [PATCH v3 7/7] eal/alarm: introduce alarm fini routine Harman Kalra
2021-10-19 18:35 ` [dpdk-dev] [PATCH v4 0/7] make rte_intr_handle internal Harman Kalra
2021-10-19 18:35 ` [dpdk-dev] [PATCH v4 1/7] malloc: introduce malloc is ready API Harman Kalra
2021-10-19 22:01 ` Dmitry Kozlyuk
2021-10-19 22:04 ` Dmitry Kozlyuk
2021-10-20 9:01 ` [dpdk-dev] [EXT] " Harman Kalra
2021-10-19 18:35 ` [dpdk-dev] [PATCH v4 2/7] eal/interrupts: implement get set APIs Harman Kalra
2021-10-20 6:14 ` David Marchand
2021-10-20 14:29 ` Dmitry Kozlyuk
2021-10-20 16:15 ` Dmitry Kozlyuk
2021-10-19 18:35 ` [dpdk-dev] [PATCH v4 3/7] eal/interrupts: avoid direct access to interrupt handle Harman Kalra
2021-10-19 21:27 ` Dmitry Kozlyuk
2021-10-20 9:25 ` [dpdk-dev] [EXT] " Harman Kalra
2021-10-20 9:52 ` Dmitry Kozlyuk
2021-10-19 18:35 ` [dpdk-dev] [PATCH v4 4/7] test/interrupt: apply get set interrupt handle APIs Harman Kalra
2021-10-19 18:35 ` [dpdk-dev] [PATCH v4 5/7] drivers: remove direct access to interrupt handle Harman Kalra
2021-10-20 1:57 ` Hyong Youb Kim (hyonkim)
2021-10-19 18:35 ` [dpdk-dev] [PATCH v4 6/7] eal/interrupts: make interrupt handle structure opaque Harman Kalra
2021-10-19 18:35 ` [dpdk-dev] [PATCH v4 7/7] eal/alarm: introduce alarm fini routine Harman Kalra
2021-10-19 21:39 ` Dmitry Kozlyuk
2021-10-22 20:49 ` [dpdk-dev] [PATCH v5 0/6] make rte_intr_handle internal Harman Kalra
2021-10-22 20:49 ` [dpdk-dev] [PATCH v5 1/6] eal/interrupts: implement get set APIs Harman Kalra
2021-10-22 23:33 ` Dmitry Kozlyuk
2021-10-22 20:49 ` [dpdk-dev] [PATCH v5 2/6] eal/interrupts: avoid direct access to interrupt handle Harman Kalra
2021-10-22 23:33 ` Dmitry Kozlyuk
2021-10-22 20:49 ` [dpdk-dev] [PATCH v5 3/6] test/interrupt: apply get set interrupt handle APIs Harman Kalra
2021-10-22 20:49 ` [dpdk-dev] [PATCH v5 4/6] drivers: remove direct access to interrupt handle Harman Kalra
2021-10-22 20:49 ` [dpdk-dev] [PATCH v5 5/6] eal/interrupts: make interrupt handle structure opaque Harman Kalra
2021-10-22 23:33 ` Dmitry Kozlyuk
2021-10-22 20:49 ` [dpdk-dev] [PATCH v5 6/6] eal/alarm: introduce alarm fini routine Harman Kalra
2021-10-22 23:33 ` Dmitry Kozlyuk
2021-10-22 23:37 ` Dmitry Kozlyuk
2021-10-24 20:04 ` [dpdk-dev] [PATCH v6 0/9] make rte_intr_handle internal David Marchand
2021-10-24 20:04 ` [dpdk-dev] [PATCH v6 1/9] interrupts: add allocator and accessors David Marchand
2021-10-24 20:04 ` [dpdk-dev] [PATCH v6 2/9] interrupts: remove direct access to interrupt handle David Marchand
2021-10-25 6:57 ` David Marchand
2021-10-24 20:04 ` [dpdk-dev] [PATCH v6 3/9] test/interrupts: " David Marchand
2021-10-24 20:04 ` [dpdk-dev] [PATCH v6 4/9] alarm: " David Marchand
2021-10-25 10:49 ` Dmitry Kozlyuk
2021-10-25 11:09 ` David Marchand
2021-10-24 20:04 ` [dpdk-dev] [PATCH v6 5/9] lib: " David Marchand
2021-10-24 20:04 ` [dpdk-dev] [PATCH v6 6/9] drivers: " David Marchand
2021-10-24 20:04 ` [dpdk-dev] [PATCH v6 7/9] interrupts: make interrupt handle structure opaque David Marchand
2021-10-24 20:04 ` [dpdk-dev] [PATCH v6 8/9] interrupts: rename device specific file descriptor David Marchand
2021-10-24 20:04 ` [dpdk-dev] [PATCH v6 9/9] interrupts: extend event list David Marchand
2021-10-25 10:49 ` Dmitry Kozlyuk
2021-10-25 11:11 ` David Marchand
2021-10-25 13:04 ` [dpdk-dev] [PATCH v5 0/6] make rte_intr_handle internal Raslan Darawsheh
2021-10-25 13:09 ` David Marchand
2021-10-25 13:34 ` [dpdk-dev] [PATCH v7 0/9] " David Marchand
2021-10-25 13:34 ` [dpdk-dev] [PATCH v7 1/9] interrupts: add allocator and accessors David Marchand
2021-10-25 13:34 ` [dpdk-dev] [PATCH v7 2/9] interrupts: remove direct access to interrupt handle David Marchand
2021-10-25 13:34 ` [dpdk-dev] [PATCH v7 3/9] test/interrupts: " David Marchand
2021-10-25 13:34 ` [dpdk-dev] [PATCH v7 4/9] alarm: " David Marchand
2021-10-25 13:34 ` [dpdk-dev] [PATCH v7 5/9] lib: " David Marchand
2021-10-28 6:14 ` Jiang, YuX
2021-10-25 13:34 ` [dpdk-dev] [PATCH v7 6/9] drivers: " David Marchand
2021-10-25 13:34 ` [dpdk-dev] [PATCH v7 7/9] interrupts: make interrupt handle structure opaque David Marchand
2021-10-25 13:34 ` [dpdk-dev] [PATCH v7 8/9] interrupts: rename device specific file descriptor David Marchand
2021-10-25 13:34 ` [dpdk-dev] [PATCH v7 9/9] interrupts: extend event list David Marchand
2021-10-25 14:27 ` [dpdk-dev] [PATCH v8 0/9] make rte_intr_handle internal David Marchand
2021-10-25 14:27 ` [dpdk-dev] [PATCH v8 1/9] interrupts: add allocator and accessors David Marchand
2021-10-25 14:27 ` [dpdk-dev] [PATCH v8 2/9] interrupts: remove direct access to interrupt handle David Marchand
2021-10-25 14:27 ` [dpdk-dev] [PATCH v8 3/9] test/interrupts: " David Marchand
2021-10-25 14:27 ` [dpdk-dev] [PATCH v8 4/9] alarm: " David Marchand
2021-10-25 14:27 ` [dpdk-dev] [PATCH v8 5/9] lib: " David Marchand
2021-10-25 14:27 ` [dpdk-dev] [PATCH v8 6/9] drivers: " David Marchand
2021-10-25 14:27 ` [dpdk-dev] [PATCH v8 7/9] interrupts: make interrupt handle structure opaque David Marchand
2021-10-25 14:27 ` [dpdk-dev] [PATCH v8 8/9] interrupts: rename device specific file descriptor David Marchand
2021-10-25 14:27 ` [dpdk-dev] [PATCH v8 9/9] interrupts: extend event list David Marchand
2021-10-28 15:58 ` Ji, Kai
2021-10-28 17:16 ` David Marchand
2021-10-25 14:32 ` [dpdk-dev] [PATCH v8 0/9] make rte_intr_handle internal Raslan Darawsheh
2021-10-25 19:24 ` David Marchand
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210826145726.102081-8-hkalra@marvell.com \
--to=hkalra@marvell.com \
--cc=bruce.richardson@intel.com \
--cc=dev@dpdk.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).