From patchwork Fri May 8 03:59:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 69969 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id D8010A00C5; Fri, 8 May 2020 05:59:23 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 14CCC1DC19; Fri, 8 May 2020 05:59:21 +0200 (CEST) Received: from mail-pg1-f195.google.com (mail-pg1-f195.google.com [209.85.215.195]) by dpdk.org (Postfix) with ESMTP id 8AF7F1DC11 for ; Fri, 8 May 2020 05:59:19 +0200 (CEST) Received: by mail-pg1-f195.google.com with SMTP id d22so264185pgk.3 for ; Thu, 07 May 2020 20:59:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6KpId3oyoj9E0BT2NM7FCzfwA99QZCH5r3w7pJfi4Tg=; b=JIU65oAxvhx56QfOz8Cb5ldA3FRLqskQW7RYeSvSt+R5Ox/TZpKzTFF7YAEiXxYZUt QIcjByOdRaobWMyR5vU/keCHLWmBntvLbxSfgumiRJonY4zck/CHp6cqik3vRM2lx/qg PS0C4NKiyRi1rb5hBfH5b2ABSVCQf1PynuYApmP+dWToa6/EVwyN6lJb8K16y5Z4HdZT wRm8bK1OqnDveHpXoVlWiVFyOwpUa80aMxPsrTdFDkqhzlrG4fehQttpsJWIEmgeSP0x b5MU/g8KJ0C2hL6ArP67vqUCjQukc9/poqWRh3S86eYGHq3kMoQdqnWq2tnKq+XYNGOt Pl/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6KpId3oyoj9E0BT2NM7FCzfwA99QZCH5r3w7pJfi4Tg=; b=bf9PTAYKho5qkpCLe27Kz0olLMrAKBjejnc5cFV+gzjkLMCsMWPKBCX/YMWJnGYrsP tIwFyDrfeYAhKPSPvw/gQQ7it9SR9QPHO2Y/AUS5/JDTf3ev3QNPiREesddAaLiT7QfC nlidadis6UK+xu3Gdb5c5QaWgCsSAUK4OvM0BZJivcTl4Vydx678IoHBj2wyAvgNaWwA AUcE04Gg2sqQuJhRHIKu35m4X19CPb0en4Cox33VfcB5x+drxnKlHwlgsTP1x63yI/+U CF6GCpNFr2R6JnyDmPvU57GguLlSJ+5gYvvQhdMvcwm+vIxhGqs3fR0i4uL50aVbSfd1 ogNw== X-Gm-Message-State: AGi0PuaAqdQqDhBAGuWOiSSXrGh3CVnAPXEFqGg1b2pMJJOrSfbK93le ByyYjiK6Uji6ImL+uFaNHoMZ7eAbCPBBXw== X-Google-Smtp-Source: APiQypKzVWB2muUB2pksNwddXeGfe3hedVsExHpEGkl64YbE2h8tE6YmHscReUcAVMTGgFk4mjEmsw== X-Received: by 2002:a62:844c:: with SMTP id k73mr678272pfd.235.1588910357989; Thu, 07 May 2020 20:59:17 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id fv14sm1130694pjb.47.2020.05.07.20.59.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 May 2020 20:59:14 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Thu, 7 May 2020 20:59:04 -0700 Message-Id: <20200508035906.18359-2-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200508035906.18359-1-stephen@networkplumber.org> References: <20200508035906.18359-1-stephen@networkplumber.org> MIME-Version: 1.0 Subject: [dpdk-dev] [RFC 1/3] 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" 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 --- 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 83c9cd660754..4d1c08f4c258 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 @@ -290,7 +293,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(); @@ -299,7 +302,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) { @@ -307,8 +309,6 @@ rte_dev_event_monitor_start(void) return -1; } - monitor_started = true; - return 0; } @@ -317,7 +317,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, @@ -329,7 +329,6 @@ rte_dev_event_monitor_stop(void) close(intr_handle.fd); intr_handle.fd = -1; - monitor_started = false; return 0; }