From: Long Li <longli@linuxonhyperv.com>
To: Stephen Hemminger <sthemmin@microsoft.com>
Cc: dev@dpdk.org, Long Li <longli@microsoft.com>
Subject: [dpdk-dev] [PATCH v2 1/2] eal/hotplug: allow monitor to be setup by multiple places
Date: Mon, 21 Dec 2020 13:32:36 -0800 [thread overview]
Message-ID: <1608586356-20046-1-git-send-email-longli@linuxonhyperv.com> (raw)
In-Reply-To: <1606809383-26660-1-git-send-email-longli@linuxonhyperv.com>
From: Long Li <longli@microsoft.com>
In some cases, a device or infrastructure may want to enable hotplug
but application may also try and start hotplug as well. Therefore
change the monitor_started from a boolean into a reference count.
Signed-off-by: Long Li <longli@microsoft.com>
---
lib/librte_eal/linux/eal_dev.c | 56 ++++++++++++++++++++++++----------
1 file changed, 40 insertions(+), 16 deletions(-)
diff --git a/lib/librte_eal/linux/eal_dev.c b/lib/librte_eal/linux/eal_dev.c
index 5c0e752b2d..3b905e18f5 100644
--- a/lib/librte_eal/linux/eal_dev.c
+++ b/lib/librte_eal/linux/eal_dev.c
@@ -23,8 +23,12 @@
#include "eal_private.h"
-static struct rte_intr_handle intr_handle = {.fd = -1 };
-static bool monitor_started;
+static struct rte_intr_handle intr_handle = {
+ .type = RTE_INTR_HANDLE_DEV_EVENT,
+ .fd = -1,
+};
+static rte_rwlock_t monitor_lock = RTE_RWLOCK_INITIALIZER;
+static uint32_t monitor_refcount;
static bool hotplug_handle;
#define EAL_UEV_MSG_LEN 4096
@@ -298,50 +302,70 @@ dev_uev_handler(__rte_unused void *param)
int
rte_dev_event_monitor_start(void)
{
- int ret;
+ int ret = 0;
- if (monitor_started)
- return 0;
+ rte_rwlock_write_lock(&monitor_lock);
+
+ if (monitor_refcount) {
+ monitor_refcount++;
+ goto exit;
+ }
ret = dev_uev_socket_fd_create();
if (ret) {
RTE_LOG(ERR, EAL, "error create device event fd.\n");
- return -1;
+ goto exit;
}
- intr_handle.type = RTE_INTR_HANDLE_DEV_EVENT;
ret = rte_intr_callback_register(&intr_handle, dev_uev_handler, NULL);
if (ret) {
RTE_LOG(ERR, EAL, "fail to register uevent callback.\n");
- return -1;
+ close(intr_handle.fd);
+ intr_handle.fd = -1;
+ goto exit;
}
- monitor_started = true;
+ monitor_refcount++;
- return 0;
+exit:
+ rte_rwlock_write_unlock(&monitor_lock);
+ return ret;
}
int
rte_dev_event_monitor_stop(void)
{
- int ret;
+ int ret = 0;
- if (!monitor_started)
- return 0;
+ rte_rwlock_write_lock(&monitor_lock);
+
+ if (!monitor_refcount) {
+ RTE_LOG(ERR, EAL, "device event monitor already stopped\n");
+ goto exit;
+ }
+
+ if (monitor_refcount > 1) {
+ monitor_refcount--;
+ goto exit;
+ }
ret = rte_intr_callback_unregister(&intr_handle, dev_uev_handler,
(void *)-1);
if (ret < 0) {
RTE_LOG(ERR, EAL, "fail to unregister uevent callback.\n");
- return ret;
+ goto exit;
}
close(intr_handle.fd);
intr_handle.fd = -1;
- monitor_started = false;
- return 0;
+ monitor_refcount--;
+
+exit:
+ rte_rwlock_write_unlock(&monitor_lock);
+
+ return ret;
}
int
--
2.25.1
next prev parent reply other threads:[~2020-12-21 21:32 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-01 7:56 [dpdk-dev] [PATCH " Long Li
2020-12-01 7:56 ` [dpdk-dev] [PATCH 2/2] net/netvsc: support VF device hot add/remove Long Li
2020-12-21 21:33 ` [dpdk-dev] [PATCH v2 " Long Li
2020-12-21 23:51 ` Stephen Hemminger
2021-01-06 2:50 ` Long Li
2020-12-17 15:08 ` [dpdk-dev] [PATCH 1/2] eal/hotplug: allow monitor to be setup by multiple places Luca Boccassi
2020-12-17 22:37 ` Long Li
2020-12-21 21:32 ` Long Li [this message]
2021-01-17 21:26 ` [dpdk-dev] [PATCH v2 " Thomas Monjalon
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=1608586356-20046-1-git-send-email-longli@linuxonhyperv.com \
--to=longli@linuxonhyperv.com \
--cc=dev@dpdk.org \
--cc=longli@microsoft.com \
--cc=sthemmin@microsoft.com \
/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).