From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id E37D6A04DB; Tue, 1 Dec 2020 08:56:32 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 2E404C982; Tue, 1 Dec 2020 08:56:31 +0100 (CET) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by dpdk.org (Postfix) with ESMTP id 2DF114C7B for ; Tue, 1 Dec 2020 08:56:30 +0100 (CET) Received: by linux.microsoft.com (Postfix, from userid 1004) id 641B320B717A; Mon, 30 Nov 2020 23:56:28 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 641B320B717A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxonhyperv.com; s=default; t=1606809388; bh=AWYDJYtQS6vWwkZX558SqBZwOJKgUraPVg3IBVyZ/2M=; h=From:To:Cc:Subject:Date:From; b=lpI6HV0eZ8SC0BJqpHNL/KcMzLB9YnL0KbHuxzT2on8g2k7kCH/eSQUPjVArGmbnb m+im/zVMil758Y5ipqJ5QF+zaHfWLr37kwInHkCnw+YPcP193/cUDwR+tbbqkSJ6EZ VBPWGGU7mJMfOns/PuW0Y0qll7yrbWQCq3WXqvQo= From: Long Li To: Stephen Hemminger Cc: dev@dpdk.org, Stephen Hemminger , Long Li Date: Mon, 30 Nov 2020 23:56:22 -0800 Message-Id: <1606809383-26660-1-git-send-email-longli@linuxonhyperv.com> X-Mailer: git-send-email 1.8.3.1 Subject: [dpdk-dev] [PATCH 1/2] eal/hotplug: allow monitor to be setup by multiple places 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Stephen Hemminger 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: Stephen Hemminger Signed-off-by: Long Li --- lib/librte_eal/linux/eal_dev.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/librte_eal/linux/eal_dev.c b/lib/librte_eal/linux/eal_dev.c index 5c0e752b2d..5fa679989e 100644 --- a/lib/librte_eal/linux/eal_dev.c +++ b/lib/librte_eal/linux/eal_dev.c @@ -23,8 +23,11 @@ #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 uint32_t monitor_refcount; static bool hotplug_handle; #define EAL_UEV_MSG_LEN 4096 @@ -300,7 +303,7 @@ rte_dev_event_monitor_start(void) { int ret; - if (monitor_started) + if (__atomic_fetch_add(&monitor_refcount, 1, __ATOMIC_RELAXED)) return 0; ret = dev_uev_socket_fd_create(); @@ -309,7 +312,6 @@ rte_dev_event_monitor_start(void) return -1; } - intr_handle.type = RTE_INTR_HANDLE_DEV_EVENT; ret = rte_intr_callback_register(&intr_handle, dev_uev_handler, NULL); if (ret) { @@ -317,8 +319,6 @@ rte_dev_event_monitor_start(void) return -1; } - monitor_started = true; - return 0; } @@ -327,7 +327,7 @@ rte_dev_event_monitor_stop(void) { int ret; - if (!monitor_started) + if (__atomic_sub_fetch(&monitor_refcount, 1, __ATOMIC_RELAXED)) return 0; ret = rte_intr_callback_unregister(&intr_handle, dev_uev_handler, @@ -339,7 +339,6 @@ rte_dev_event_monitor_stop(void) close(intr_handle.fd); intr_handle.fd = -1; - monitor_started = false; return 0; } -- 2.25.1