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 95CCAA04C5; Fri, 4 Sep 2020 01:28:29 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id D4282E07; Fri, 4 Sep 2020 01:28:28 +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 9C2C8DE0 for ; Fri, 4 Sep 2020 01:28:27 +0200 (CEST) Received: by mail-pg1-f195.google.com with SMTP id 31so3323098pgy.13 for ; Thu, 03 Sep 2020 16:28:27 -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=tsJmQ6kR+FbLj50EUX/SEd3r7EhtA/5c3McrcYOflL0=; b=iB4btLBxvzwZ1Ab5q3H4xpHZHfY2O/yy355FRB+OcEYk4Vd0gVwEgDf9Q1hozKZJuQ 6FgM9Y8tLkU75TCVMbz9pnaX6hDApaQD5j/YVVjzOUaao1SwyQgl2FGg+KzBA4E6B8yb yVH/4Pj/K6UoRoR5T3CNVzAsJiMBD8AzJEJgP76ls5YVW0es1iSWLNoiUA/x1JLOY2vx ANkQAo3KxDzGuxivK+vXZBwew/4LJGr9M2Ievdzc8PDLcb2/+GWoV13SBUBVYyu6/eD+ YJH3m8NTOGZA487wjllgdVl9WzQ2YLj4gJqhXkyWhsEmeFeqjO3l174jdd4vLCTL50K4 cjDg== 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=tsJmQ6kR+FbLj50EUX/SEd3r7EhtA/5c3McrcYOflL0=; b=XavmJI/uu407T7Y92BZRMfgG9w8DAdy/lvoFq5C9I2AtwcPzJch/RdLEzHa0cD4IfT +aeo0z5YPqwbn1QZ1uLb6wbI8ykVMKchoJXVMXvolv8jfvrpAjbu10/nBTqwLZasNG9t AAoY+yQWO88sxRIg4LgIkBCxsYFiCPs2SlSY0p2pfk1Uj09msgyZF6/ilKFau3c4l3Uu D5KY2hnPSRroA+AyUiT+efR6LtuScVCQnTHTezQlCUaIhAO+ZxI/dQH/8l9rslA9EU2z BykecNugYn0COTLOb8d7tzzb2W1w04NL3nkwQQw+aVJ+bBlvaLOoBPQZXrQXB+nyJDZJ RhYw== X-Gm-Message-State: AOAM530p4hWGIq/lMl/EbIrWK757ZaB2mq3vZhGX1PKENgGAYkN51k1A vUPkrIAwfJCuic3cz+9bgTILkQSVhPJ4Dw== X-Google-Smtp-Source: ABdhPJxJy7xz5JI7Wh5G2jy2V3QuEoZW+OzMdbF9JcJIm7aKUAfa4V7jjMGP2IUXnK2NAzwJhYcmoA== X-Received: by 2002:a62:7616:: with SMTP id r22mr5850443pfc.48.1599175706105; Thu, 03 Sep 2020 16:28:26 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id e127sm4319224pfe.152.2020.09.03.16.28.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Sep 2020 16:28:25 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Harman Kalra Date: Thu, 3 Sep 2020 16:28:22 -0700 Message-Id: <20200903232822.19167-1-stephen@networkplumber.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20190724172037.7776-1-stephen@networkplumber.org> References: <20190724172037.7776-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v2] eal/interrupts: add function to allow interruptible epoll 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" The existing definition of rte_epoll_wait retries if interrupted by a signal. This behavior makes it hard to use rte_epoll_wait for applications that want to use signals do do things like exit polling loop and shutdown. Since changing existing semantic might break applications, add a new rte_epoll_wait_interruptible() function that does the same thing as rte_epoll_wait but will return -1 and errno of EINTR if it receives a signal. Signed-off-by: Stephen Hemminger Reviewed-by: Harman Kalra --- v2 -- rebase onto current code organization simplify logic to make it clear how common the code is Note: the documentation of the new version is intentionally the the same as the original one. lib/librte_eal/freebsd/eal_interrupts.c | 12 +++++++++ lib/librte_eal/include/rte_eal_interrupts.h | 23 +++++++++++++++++ lib/librte_eal/linux/eal_interrupts.c | 28 +++++++++++++++++---- lib/librte_eal/rte_eal_version.map | 3 +++ 4 files changed, 61 insertions(+), 5 deletions(-) diff --git a/lib/librte_eal/freebsd/eal_interrupts.c b/lib/librte_eal/freebsd/eal_interrupts.c index 6d53d33c81a9..b07cff639318 100644 --- a/lib/librte_eal/freebsd/eal_interrupts.c +++ b/lib/librte_eal/freebsd/eal_interrupts.c @@ -684,6 +684,18 @@ rte_epoll_wait(int epfd, struct rte_epoll_event *events, return -ENOTSUP; } +int +rte_epoll_wait_interruptible(int epfd, struct rte_epoll_event *events, + int maxevents, int timeout) +{ + RTE_SET_USED(epfd); + RTE_SET_USED(events); + RTE_SET_USED(maxevents); + RTE_SET_USED(timeout); + + return -ENOTSUP; +} + int rte_epoll_ctl(int epfd, int op, int fd, struct rte_epoll_event *event) { diff --git a/lib/librte_eal/include/rte_eal_interrupts.h b/lib/librte_eal/include/rte_eal_interrupts.h index b1e8a2934e78..7d808a22624a 100644 --- a/lib/librte_eal/include/rte_eal_interrupts.h +++ b/lib/librte_eal/include/rte_eal_interrupts.h @@ -87,6 +87,7 @@ struct rte_intr_handle { /** * It waits for events on the epoll instance. + * Retries if signal received. * * @param epfd * Epoll instance fd on which the caller wait for events. @@ -105,6 +106,28 @@ int rte_epoll_wait(int epfd, struct rte_epoll_event *events, int maxevents, int timeout); +/** + * It waits for events on the epoll instance. + * Does not retry if signal received. + * + * @param epfd + * Epoll instance fd on which the caller wait for events. + * @param events + * Memory area contains the events that will be available for the caller. + * @param maxevents + * Up to maxevents are returned, must greater than zero. + * @param timeout + * Specifying a timeout of -1 causes a block indefinitely. + * Specifying a timeout equal to zero cause to return immediately. + * @return + * - On success, returns the number of available event. + * - On failure, a negative value. + */ +__rte_experimental +int +rte_epoll_wait_interruptible(int epfd, struct rte_epoll_event *events, + int maxevents, int timeout); + /** * It performs control operations on epoll instance referred by the epfd. * It requests that the operation op be performed for the target fd. diff --git a/lib/librte_eal/linux/eal_interrupts.c b/lib/librte_eal/linux/eal_interrupts.c index 13db5c4e8aee..26b5dd4ca86b 100644 --- a/lib/librte_eal/linux/eal_interrupts.c +++ b/lib/librte_eal/linux/eal_interrupts.c @@ -1275,9 +1275,9 @@ rte_intr_tls_epfd(void) return RTE_PER_LCORE(_epfd); } -int -rte_epoll_wait(int epfd, struct rte_epoll_event *events, - int maxevents, int timeout) +static int +eal_epoll_wait(int epfd, struct rte_epoll_event *events, + int maxevents, int timeout, bool interruptible) { struct epoll_event evs[maxevents]; int rc; @@ -1298,8 +1298,12 @@ rte_epoll_wait(int epfd, struct rte_epoll_event *events, rc = eal_epoll_process_event(evs, rc, events); break; } else if (rc < 0) { - if (errno == EINTR) - continue; + if (errno == EINTR) { + if (interruptible) + return -1; + else + continue; + } /* epoll_wait fail */ RTE_LOG(ERR, EAL, "epoll_wait returns with fail %s\n", strerror(errno)); @@ -1314,6 +1318,20 @@ rte_epoll_wait(int epfd, struct rte_epoll_event *events, return rc; } +int +rte_epoll_wait(int epfd, struct rte_epoll_event *events, + int maxevents, int timeout) +{ + return eal_epoll_wait(epfd, events, maxevents, timeout, false); +} + +int +rte_epoll_wait_interruptible(int epfd, struct rte_epoll_event *events, + int maxevents, int timeout) +{ + return eal_epoll_wait(epfd, events, maxevents, timeout, true); +} + static inline void eal_epoll_data_safe_free(struct rte_epoll_event *ev) { diff --git a/lib/librte_eal/rte_eal_version.map b/lib/librte_eal/rte_eal_version.map index 0b18e2ef85f9..a31a7cf5791a 100644 --- a/lib/librte_eal/rte_eal_version.map +++ b/lib/librte_eal/rte_eal_version.map @@ -397,6 +397,9 @@ EXPERIMENTAL { rte_mp_disable; rte_thread_register; rte_thread_unregister; + + # added in 20.11 + rte_epoll_wait_interruptible; }; INTERNAL { -- 2.27.0