From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f43.google.com (mail-wm0-f43.google.com [74.125.82.43]) by dpdk.org (Postfix) with ESMTP id AF93CA10 for ; Tue, 14 Mar 2017 13:52:09 +0100 (CET) Received: by mail-wm0-f43.google.com with SMTP id v186so63165512wmd.0 for ; Tue, 14 Mar 2017 05:52:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=wAG/S9FhMuABC1tiCAMoblqCFKYCVOuhFsn5TT4CaEY=; b=vp9eFWg+0H8oDnnBZakXu6ipJecH0w9nYfnxgGu2qmhteYYyNdwacOYI1oXDZs9yPu E57/T0pOS3n68tFJea3tQ0ivMoxOt7H18WI8O4lGyn0JPYtLdfNOrqPEhaVCntLw6hev qu3mKtrsXW+yoiNDsuhLWT8cLsXZ2KLO+TIgSwRMjEy69KNx3Hw7RUTv1sGmh3VEe4zO ROZYfzHYqEllooO5B+kz11e8jXeyKWxzyWU90Ok22NKRh/pHTWcy8pdpSOjbFLx0P++m lUVPqEFJZQd5A8Zoek+l1b6cLqKPpg9uQWStHZspCSAzL/CWDv5rCvm3J6T6xxIRXUeK JZ8g== 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; bh=wAG/S9FhMuABC1tiCAMoblqCFKYCVOuhFsn5TT4CaEY=; b=aScM62mUzXJOymz427nBMY9CiCVUYLca4zdgo4XeLwDTZ4bl5CY1NHCojh0QYh8efE oiEhzf3U/pgdsYguJxQsxBfR1o2hXrsGKS83ZNfPB+/PynX9KEX7PGmveNHAsIXocyem daDswROgm8BenDJpVukEh8//wdAwRIRAyG6aSD4rZJz5y2LpE1Vrr0sM3yH2SN2mBl4y ISJm/AwCRhffz1FguG2JBLWxx+6BZ3UJZJpJ5j+kps3R+Xu3+xU16lg3dO2L2v98EzN8 IPt7dM4I8XiV5877hcVPw8RROwV4kSfCTItt6UwwFFi35AQDl4Tz2/wQ1kIATE7dpZEE ppOw== X-Gm-Message-State: AFeK/H3y213FlkvNzSyVV4AuGwVq842PILNCRt8/oZhhL5DkVqxeQYFuhJRacMpR3geOs+7E X-Received: by 10.28.144.14 with SMTP id s14mr12585336wmd.22.1489495929438; Tue, 14 Mar 2017 05:52:09 -0700 (PDT) Received: from 6wind.com (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id b13sm15435951wmf.6.2017.03.14.05.52.08 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Tue, 14 Mar 2017 05:52:08 -0700 (PDT) From: Adrien Mazarguil To: Keith Wiles Cc: dev@dpdk.org Date: Tue, 14 Mar 2017 13:51:58 +0100 Message-Id: <2f12b366764d27eb3938781e97bdd42c9f1b7e3a.1489495663.git.adrien.mazarguil@6wind.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: References: Subject: [dpdk-dev] [PATCH 2/2] net/tap: add Rx trigger 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: , X-List-Received-Date: Tue, 14 Mar 2017 12:52:09 -0000 This commit adds a signal-based trigger to the Rx burst function in order to avoid unnecessary system calls while Rx queues are empty. Triggered Rx bursts put less pressure on the kernel, free up CPU resources for applications and result in a noticeable performance improvement when sharing CPU threads with other PMDs. Measuring the traffic forwarding rate between two physical devices in testpmd (IO mode, single thread, 64B packets) before and after adding two tap PMD instances (4 ports total) that do not process any traffic and comparing results yields: Without Rx trigger: -15% (--burst=32) -62% (--burst=1) With Rx trigger: -0.3% (--burst=32) -6% (--burst=1) Signed-off-by: Adrien Mazarguil Acked-by: Pascal Mazon --- drivers/net/tap/rte_eth_tap.c | 59 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c index c757a7c..d5d467a 100644 --- a/drivers/net/tap/rte_eth_tap.c +++ b/drivers/net/tap/rte_eth_tap.c @@ -31,6 +31,8 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include +#include #include #include #include @@ -42,6 +44,9 @@ #include #include #include +#include +#include +#include #include #include #include @@ -72,6 +77,8 @@ static const char *valid_arguments[] = { static int tap_unit; +static volatile uint32_t tap_trigger; /* Rx trigger */ + static struct rte_eth_link pmd_link = { .link_speed = ETH_SPEED_NUM_10G, .link_duplex = ETH_LINK_FULL_DUPLEX, @@ -89,6 +96,7 @@ struct pkt_stats { struct rx_queue { struct rte_mempool *mp; /* Mempool for RX packets */ + uint32_t trigger_seen; /* Last seen Rx trigger value */ uint16_t in_port; /* Port ID */ int fd; @@ -111,6 +119,13 @@ struct pmd_internals { struct tx_queue txq[RTE_PMD_TAP_MAX_QUEUES]; /* List of TX queues */ }; +static void +tap_trigger_cb(int sig __rte_unused) +{ + /* Valid trigger values are nonzero */ + tap_trigger = (tap_trigger + 1) | 0x80000000; +} + /* Tun/Tap allocation routine * * name is the number of the interface to use, unless NULL to take the host @@ -175,6 +190,43 @@ tun_alloc(struct pmd_internals *pmd, uint16_t qid) goto error; } + /* Set up trigger to optimize empty Rx bursts */ + errno = 0; + do { + struct sigaction sa; + int flags = fcntl(fd, F_GETFL); + + if (flags == -1 || sigaction(SIGIO, NULL, &sa) == -1) + 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; + } + /* Enable SIGIO on file descriptor */ + fcntl(fd, F_SETFL, flags | O_ASYNC); + fcntl(fd, F_SETOWN, getpid()); + } while (0); + if (errno) { + /* Disable trigger globally in case of error */ + tap_trigger = 0; + RTE_LOG(WARNING, PMD, "Rx trigger disabled: %s\n", + strerror(errno)); + } + if (qid == 0) { if (ioctl(fd, SIOCGIFHWADDR, &ifr) == -1) { RTE_LOG(ERR, PMD, "ioctl failed (SIOCGIFHWADDR) (%s)\n", @@ -204,7 +256,13 @@ pmd_rx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) struct rx_queue *rxq = queue; uint16_t num_rx; unsigned long num_rx_bytes = 0; + uint32_t trigger = tap_trigger; + if (trigger == rxq->trigger_seen) + return 0; + if (trigger) + rxq->trigger_seen = trigger; + rte_compiler_barrier(); for (num_rx = 0; num_rx < nb_pkts; ) { /* allocate the next mbuf */ mbuf = rte_pktmbuf_alloc(rxq->mp); @@ -563,6 +621,7 @@ tap_rx_queue_setup(struct rte_eth_dev *dev, } internals->rxq[rx_queue_id].mp = mp; + internals->rxq[rx_queue_id].trigger_seen = 1; /* force initial burst */ internals->rxq[rx_queue_id].in_port = dev->data->port_id; /* Now get the space available for data in the mbuf */ -- 2.1.4