From patchwork Tue Jul 14 23:58:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 74029 X-Patchwork-Delegate: ferruh.yigit@amd.com 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 1A15AA0540; Wed, 15 Jul 2020 01:58:17 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id DDF6D1C21F; Wed, 15 Jul 2020 01:58:15 +0200 (CEST) Received: from mail-pl1-f195.google.com (mail-pl1-f195.google.com [209.85.214.195]) by dpdk.org (Postfix) with ESMTP id 55DA01C20D for ; Wed, 15 Jul 2020 01:58:14 +0200 (CEST) Received: by mail-pl1-f195.google.com with SMTP id b9so234381plx.6 for ; Tue, 14 Jul 2020 16:58:14 -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=KuYj+Mmq6flYrDurxMFwkU005ZegQRAdR1akzTiAfDU=; b=Ul/of6z8klgiIT7+UgKjZ43EBck6hGcZGBcAmS8dShm8VaZRNCWuhKUtSnLXmzzIwc YwQl4Kp2cEcFNdHcCyMyRr5LUiopD4XwPvq9HFUTs93GOH4iXP2Jn51euPuyxmjwTBzw ZkmW5J+OC9CVwmVSS3C3ypNouZzJBh6J1zYf8y/78ze95h0Gd5fWGqpB7CF8YgpCnppc 1rMZPEjnAs1cmNJZsPNrGo5YNrcIRB8uJALmQ0xq73XTrp2AZp2XM9O2S/eq7PzV/Esp ubU3lQceUzqf0kk1a/1Tv1KrLre6h4UT3OTencECJZ4upeG2/uRYtH0OYiX8M+MAyQhF nHig== 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=KuYj+Mmq6flYrDurxMFwkU005ZegQRAdR1akzTiAfDU=; b=r1fKOp7mgnr/3j0OybGHYu2KCuWBfSQ2Rxo2q/x4sT8+zHC7D+OaglqAFiK4mbfETd 3oP7g7v/+iDsefhZJbDOxxakP9cSlgL3fWv6RKh73L//8uTcvI3LUccjKY0PCCETIVus tJjSiyTBireGb7gSGFD8rN0Mmeb+AM97ZK5y82WbCXlpF3/0NpQlC61MFaIhNFPKJNKu /2p9i02faMlqQqtbaj7KE3VBl4HtDewmUm07CZoXElR3u85AfHBxePrUgffbpKGXcwSV DORGi/BgWHy37QAf8RqcpcUqkgPhMuZ12UnRUz14ywdBDMM4xHTsbsBou0OxxcE1pjfF TxSg== X-Gm-Message-State: AOAM530g0RjWtmbsmfZ4gl9ap5NUS/YBMBOUyE7rsSLK/cVYu8+oZR/h wLcCAaMeUv5QZCR+HSngqqabdw== X-Google-Smtp-Source: ABdhPJx3he/Xe/O+6RrWbsqRMpSbA+lfrBbGmN7KGAWGirpw8iGOduk48NTewnnd5/HRKlfxU0Uqwg== X-Received: by 2002:a17:90a:fa09:: with SMTP id cm9mr7156915pjb.146.1594771093360; Tue, 14 Jul 2020 16:58:13 -0700 (PDT) Received: from hermes.corp.microsoft.com (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id j36sm211640pgj.39.2020.07.14.16.58.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jul 2020 16:58:12 -0700 (PDT) From: Stephen Hemminger To: keith.wiles@intel.com Cc: dev@dpdk.org, Stephen Hemminger Date: Tue, 14 Jul 2020 16:58:10 -0700 Message-Id: <20200714235810.5286-1-stephen@networkplumber.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200422010156.1956-1-stephen@networkplumber.org> References: <20200422010156.1956-1-stephen@networkplumber.org> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH] net/tap: avoid using SIGIO 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" SIGIO maybe used by application, instead choose another rt-signal. Linux allows any signal to be used for signal based IO. Search for an unused signal in the available rt-signal range. Add more error checking for fcntl and signal handling. Signed-off-by: Stephen Hemminger Acked-by: Morten Brørup Reviewed-by: Ferruh Yigit --- Resending original version, marked as PATCH now. drivers/net/tap/rte_eth_tap.c | 99 ++++++++++++++++++++++++----------- 1 file changed, 67 insertions(+), 32 deletions(-) diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c index 339f24bf82f3..b19e26ba0e65 100644 --- a/drivers/net/tap/rte_eth_tap.c +++ b/drivers/net/tap/rte_eth_tap.c @@ -134,7 +134,7 @@ tun_alloc(struct pmd_internals *pmd, int is_keepalive) #ifdef IFF_MULTI_QUEUE unsigned int features; #endif - int fd; + int fd, signo, flags; memset(&ifr, 0, sizeof(struct ifreq)); @@ -199,52 +199,87 @@ tun_alloc(struct pmd_internals *pmd, int is_keepalive) } } + flags = fcntl(fd, F_GETFL); + if (flags == -1) { + TAP_LOG(WARNING, + "Unable to get %s current flags\n", + ifr.ifr_name); + goto error; + } + /* Always set the file descriptor to non-blocking */ - if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0) { + flags |= O_NONBLOCK; + if (fcntl(fd, F_SETFL, flags) < 0) { TAP_LOG(WARNING, "Unable to set %s to nonblocking: %s", ifr.ifr_name, strerror(errno)); goto error; } - /* Set up trigger to optimize empty Rx bursts */ - errno = 0; - do { + /* Find a free realtime signal */ + for (signo = SIGRTMIN + 1; signo < SIGRTMAX; signo++) { struct sigaction sa; - int flags = fcntl(fd, F_GETFL); - if (flags == -1 || sigaction(SIGIO, NULL, &sa) == -1) + if (sigaction(signo, NULL, &sa) == -1) { + TAP_LOG(WARNING, + "Unable to get current rt-signal %d handler", + signo); + goto error; + } + + /* Already have the handler we want on this signal */ + if (sa.sa_handler == tap_trigger_cb) break; - if (sa.sa_handler != tap_trigger_cb) { - /* - * Make sure SIGIO is not already taken. This is done - * as late as possible to leave the application a - * chance to set up its own signal handler first. - */ - if (sa.sa_handler != SIG_IGN && - sa.sa_handler != SIG_DFL) { - errno = EBUSY; - break; - } - sa = (struct sigaction){ - .sa_flags = SA_RESTART, - .sa_handler = tap_trigger_cb, - }; - if (sigaction(SIGIO, &sa, NULL) == -1) - break; + + /* Is handler in use by application */ + if (sa.sa_handler != SIG_DFL) { + TAP_LOG(DEBUG, + "Skipping used rt-signal %d", signo); + continue; } - /* Enable SIGIO on file descriptor */ - fcntl(fd, F_SETFL, flags | O_ASYNC); - fcntl(fd, F_SETOWN, getpid()); - } while (0); - if (errno) { + sa = (struct sigaction) { + .sa_flags = SA_RESTART, + .sa_handler = tap_trigger_cb, + }; + + if (sigaction(signo, &sa, NULL) == -1) { + TAP_LOG(WARNING, + "Unable to set rt-signal %d handler\n", signo); + goto error; + } + + /* Found a good signal to use */ + TAP_LOG(DEBUG, + "Using rt-signal %d", signo); + break; + } + + if (signo == SIGRTMAX) { + TAP_LOG(WARNING, "All rt-signals are in use\n"); + /* Disable trigger globally in case of error */ tap_trigger = 0; - TAP_LOG(WARNING, "Rx trigger disabled: %s", - strerror(errno)); - } + TAP_LOG(NOTICE, "No Rx trigger signal available\n"); + } else { + /* Enable signal on file descriptor */ + if (fcntl(fd, F_SETSIG, signo) < 0) { + TAP_LOG(WARNING, "Unable to set signo %d for fd %d: %s", + signo, fd, strerror(errno)); + goto error; + } + if (fcntl(fd, F_SETFL, flags | O_ASYNC) < 0) { + TAP_LOG(WARNING, "Unable to set fcntl flags: %s", + strerror(errno)); + goto error; + } + if (fcntl(fd, F_SETOWN, getpid()) < 0) { + TAP_LOG(WARNING, "Unable to set fcntl owner: %s", + strerror(errno)); + goto error; + } + } return fd; error: