From patchwork Thu Sep 27 00:32:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Gora X-Patchwork-Id: 45466 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id B2DC81B272; Thu, 27 Sep 2018 02:34:14 +0200 (CEST) Received: from mail-qk1-f176.google.com (mail-qk1-f176.google.com [209.85.222.176]) by dpdk.org (Postfix) with ESMTP id 5D1FE1B213 for ; Thu, 27 Sep 2018 02:34:04 +0200 (CEST) Received: by mail-qk1-f176.google.com with SMTP id q12-v6so522666qkl.13 for ; Wed, 26 Sep 2018 17:34:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PlH/VAfIrUGq17Kvr2neDS51vqfEwcHSM70/Jy2B3NE=; b=jH4xuT7IpWHZwgFkuw8NrXmt35YOBwN+qeJQRmr33xHlEXsGXdzxC5ngywB9DOHlB/ uib0BCQCamSlXWMroSjdpRWillX6P40LtFL2lcth8s/SB4bukAtgZH6+rmJStOOTIWnI axB6ZVDbDS3iprkOalQTbW/Pk8s9cMgaIuB0znlAsB6a3gdMhQMerOprsMkpolryWLOB 4gFDoZ+FP4aMIf+eMk+vUB/ocQZkjbaFe/xDujmXOYHBinBIo3xmVjKgTMUNeFJIAZzT bUlQJCMAmpxE5+NiK4TCncEGPq2NRwSotb133aTd9bHL4bkhcT1vsaGaRVWMNlI/ol20 RTFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=PlH/VAfIrUGq17Kvr2neDS51vqfEwcHSM70/Jy2B3NE=; b=m8RyVtNY8lJGaWngsM98WyT1JZKuCHzrCJTfQWhhYK9dccYJJktkfGx1nX3Ygsw+WK zY3avaFOAngn9bOCpPu6NMPjFYz5Ul82HyVpplpuXcT1G8nfd2w77oeW/6liCBq0C6St i427BKU72exWHcSGrlL0pyCpwDtrpp5YRInwExdZZuLhvYjXPk9/Ttd8V1yrziopzkw7 r+eTjGKM2Ks17LaKfpZKfJn2mz47iW4724TiybpbdF7FxoKBE7fRoIWoAoTfWhrQtiF5 YaHzkWGCL+aV5+OpPP82kaHBLkwSNJjfo+50CdpXyuWmj8s5Dmu8ETzajFh32O+AWCwT h4GQ== X-Gm-Message-State: ABuFfoiZZg46FJDtpvkbcwPi6ytFnAYy9GHjauGupGKzNE9y2h7w2bv0 wC8HZDXTFKKmIaKxFS0AuU+H2AsA X-Google-Smtp-Source: ACcGV60F5ANhfU20GVWeRpk05nnP23KTpJ2P8dr1eHYjdMod+oGkM3f4IfRqW0/yuzOJqb7oVZb9FA== X-Received: by 2002:a37:30d4:: with SMTP id w203-v6mr2829130qkw.106.1538008443306; Wed, 26 Sep 2018 17:34:03 -0700 (PDT) Received: from snappy.local.lan (189-46-124-178.dsl.telesp.net.br. [189.46.124.178]) by smtp.gmail.com with ESMTPSA id x26-v6sm463053qth.15.2018.09.26.17.34.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 26 Sep 2018 17:34:02 -0700 (PDT) From: Dan Gora To: dev@dpdk.org Cc: Igor Ryzhov , Stephen Hemminger , Ferruh Yigit , Dan Gora Date: Wed, 26 Sep 2018 21:32:51 -0300 Message-Id: <20180927003256.6901-2-dg@adax.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180927003256.6901-1-dg@adax.com> References: <20180911232906.18352-1-dg@adax.com> <20180927003256.6901-1-dg@adax.com> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v3 1/6] kni: add API to set link status on kernel interface 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" Add a new API function to KNI, rte_kni_update_link() to allow DPDK applications to update the link status for KNI network interfaces in the linux kernel. Signed-off-by: Dan Gora --- lib/librte_kni/rte_kni.c | 57 ++++++++++++++++++++++++++++++ lib/librte_kni/rte_kni.h | 18 ++++++++++ lib/librte_kni/rte_kni_version.map | 6 ++++ 3 files changed, 81 insertions(+) diff --git a/lib/librte_kni/rte_kni.c b/lib/librte_kni/rte_kni.c index 65f6a2b03..0c3e17dbb 100644 --- a/lib/librte_kni/rte_kni.c +++ b/lib/librte_kni/rte_kni.c @@ -790,6 +790,63 @@ rte_kni_unregister_handlers(struct rte_kni *kni) return 0; } + +int __rte_experimental +rte_kni_update_link(struct rte_kni *kni, struct rte_eth_link *link) +{ + char path[64]; + char carrier[2]; + const char *new_carrier; + int fd, ret; + + if (kni == NULL || link == NULL) + return -1; + + snprintf(path, sizeof(path), "/sys/devices/virtual/net/%s/carrier", + kni->name); + + fd = open(path, O_RDWR); + if (fd == -1) { + RTE_LOG(ERR, KNI, "Failed to open file: %s.\n", path); + return -1; + } + + ret = read(fd, carrier, 2); + if (ret < 1) { + /* Cannot read carrier until interface is marked + * 'up', so don't log an error. + */ + close(fd); + return -1; + } + + new_carrier = (link->link_status == ETH_LINK_UP) ? "1" : "0"; + ret = write(fd, new_carrier, 1); + if (ret < 1) { + RTE_LOG(ERR, KNI, "Failed to write file: %s.\n", path); + close(fd); + return -1; + } + + if (strncmp(carrier, new_carrier, 1)) { + if (link->link_status == ETH_LINK_UP) { + RTE_LOG(INFO, KNI, "%s NIC Link is Up %d Mbps %s %s.\n", + kni->name, + link->link_speed, + link->link_autoneg ? "(AutoNeg)" : "(Fixed)", + link->link_duplex ? + "Full Duplex" : "Half Duplex"); + } else { + RTE_LOG(INFO, KNI, "%s NIC Link is Down.\n", + kni->name); + } + } + + close(fd); + + return 0; +} + void rte_kni_close(void) { diff --git a/lib/librte_kni/rte_kni.h b/lib/librte_kni/rte_kni.h index 99055e2c2..4118ae97a 100644 --- a/lib/librte_kni/rte_kni.h +++ b/lib/librte_kni/rte_kni.h @@ -21,6 +21,7 @@ #include #include #include +#include #include @@ -228,6 +229,23 @@ int rte_kni_register_handlers(struct rte_kni *kni, struct rte_kni_ops *ops); */ int rte_kni_unregister_handlers(struct rte_kni *kni); +/** + * Update link status info for KNI port. + * + * Update the linkup/linkdown status of a KNI interface in the kernel. + * + * @param kni + * pointer to struct rte_kni. + * @param link + * pointer to struct rte_eth_link containing new interface status. + * + * @return + * On success: 0 + * On failure: -1 + */ +int __rte_experimental +rte_kni_update_link(struct rte_kni *kni, struct rte_eth_link *link); + /** * Close KNI device. */ diff --git a/lib/librte_kni/rte_kni_version.map b/lib/librte_kni/rte_kni_version.map index acd515eb0..c877dc6aa 100644 --- a/lib/librte_kni/rte_kni_version.map +++ b/lib/librte_kni/rte_kni_version.map @@ -15,3 +15,9 @@ DPDK_2.0 { local: *; }; + +EXPERIMENTAL { + global: + + rte_kni_update_link; +}; From patchwork Thu Sep 27 00:32:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Gora X-Patchwork-Id: 45467 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 5C0561B295; Thu, 27 Sep 2018 02:34:16 +0200 (CEST) Received: from mail-qt1-f174.google.com (mail-qt1-f174.google.com [209.85.160.174]) by dpdk.org (Postfix) with ESMTP id 9423C1B213 for ; Thu, 27 Sep 2018 02:34:07 +0200 (CEST) Received: by mail-qt1-f174.google.com with SMTP id z8-v6so937035qto.9 for ; Wed, 26 Sep 2018 17:34:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/JQjpf7+nI3prxOCKS0ftKi19F7w8+VllABK5QE4//0=; b=UUQfCeTuVD72wcVIgPpGwfx9Z5eqPXNrXENStjDXk5yv025jwbGZL1hNL2eRJBBtsZ k0+jQk+y9rcCnYySwpCAYiS79p2gLhJ40PE/Jqp/bvakFjC/0DPG5wBnrLxDUTuO/58/ a70vUctOpKbRo/wO2EULp5ateHXBgy8TFLvURk8cu+3DWttfYQ5QNHDrUZezJHETUs+P wIh4fZy+GiPwF20Y65mW8/rzK91WJUnVs7dutq2ZkLx7NUcE4L2fdi4pzaO//VhItzk1 IQoBumhumHWnUYgg00S2DiARAwO/TgEYNACe1YCrljvd5b8BCGR0EuU3Gfe+quNS+ZDl AMkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=/JQjpf7+nI3prxOCKS0ftKi19F7w8+VllABK5QE4//0=; b=NLvfYB6/C+NfIF9cI3fOiOFIbPutEXzrtSEXFq0i5Cu6qf8nsKWkBEMirbUGRb3n5b NJVxwKY/LpEe/qQpQP1kyRPiFdm/8jz5egp1GmlzyH3QhUV0em/8wpq1vZTtLvvFS/GN Sk9W5yzJiuzVpEi8lqV4YVYkEoVg1WnYM2bKc7wqfllJkHIBzvu5L/sUnANx8JEIrsDZ MIT88NSS5UWEbPJAK5gduuw6LJjYzpr6znXT57bQn/Mq35sOmyf+Pg9UzrgAsMsN3Yto DRM3x0wr5us5NBdwwlMf0CAL4lvUuIsgitRCTQxxCLDLlZKzxkpLQ2SPsc/Ou2MXohXE D9zw== X-Gm-Message-State: ABuFfohcFplE26b8w3/P1BVPjI7wRoY3KloMCqS7fCYno20Tu/MPiFld iFOYqw5RpS86e7E2aXIqF6cm1NkI X-Google-Smtp-Source: ACcGV6178JNQWlbc1kTtB+uz623lyqn9qiBNWnlZ0ACbu9qgIO/CMy8MAOq0ljOXAMr3GnfI85CBrw== X-Received: by 2002:a0c:d032:: with SMTP id u47-v6mr2555537qvg.245.1538008446670; Wed, 26 Sep 2018 17:34:06 -0700 (PDT) Received: from snappy.local.lan (189-46-124-178.dsl.telesp.net.br. [189.46.124.178]) by smtp.gmail.com with ESMTPSA id x26-v6sm463053qth.15.2018.09.26.17.34.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 26 Sep 2018 17:34:05 -0700 (PDT) From: Dan Gora To: dev@dpdk.org Cc: Igor Ryzhov , Stephen Hemminger , Ferruh Yigit , Dan Gora Date: Wed, 26 Sep 2018 21:32:52 -0300 Message-Id: <20180927003256.6901-3-dg@adax.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180927003256.6901-1-dg@adax.com> References: <20180911232906.18352-1-dg@adax.com> <20180927003256.6901-1-dg@adax.com> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v3 2/6] kni: add link status test 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" Test changing the link, speed, duplex, etc. status of the KNI interface with rte_kni_update_link(). Signed-off-by: Dan Gora --- test/test/test_kni.c | 131 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) diff --git a/test/test/test_kni.c b/test/test/test_kni.c index 3dcadcebd..138bc9686 100644 --- a/test/test/test_kni.c +++ b/test/test/test_kni.c @@ -118,6 +118,133 @@ kni_change_mtu(uint16_t port_id, unsigned int new_mtu) port_id, kni_pkt_mtu); return 0; } + +static int +test_kni_link_change(void) +{ + struct rte_eth_link link; + int ret; + int pid; + + pid = fork(); + if (pid < 0) { + printf("Error: Failed to fork a process\n"); + return -1; + } + + if (pid == 0) { + printf("Starting KNI Link status change tests.\n"); + if (system(IFCONFIG TEST_KNI_PORT" up") == -1) { + ret = -1; + goto error; + } + + link.link_speed = 10; + link.link_status = ETH_LINK_UP; + link.link_autoneg = ETH_LINK_AUTONEG; + link.link_duplex = ETH_LINK_FULL_DUPLEX; + ret = rte_kni_update_link(test_kni_ctx, &link); + if (ret != 0) { + printf("Failed to change link state to " + "Up/10Mbps/AutoNeg/Full ret=%d.\n", ret); + goto error; + } + rte_delay_ms(1000); + + link.link_speed = 0; + link.link_status = ETH_LINK_DOWN; + link.link_autoneg = ETH_LINK_FIXED; + link.link_duplex = ETH_LINK_FULL_DUPLEX; + ret = rte_kni_update_link(test_kni_ctx, &link); + if (ret != 0) { + printf("Failed to change link state to Down ret=%d.\n", + ret); + goto error; + } + rte_delay_ms(1000); + + link.link_speed = 1000; + link.link_status = ETH_LINK_UP; + link.link_autoneg = ETH_LINK_AUTONEG; + link.link_duplex = ETH_LINK_HALF_DUPLEX; + ret = rte_kni_update_link(test_kni_ctx, &link); + if (ret != 0) { + printf("Failed to change link state to " + "Up/1Gbps/AutoNeg/Half ret=%d.\n", ret); + goto error; + } + rte_delay_ms(1000); + + link.link_speed = 0; + link.link_status = ETH_LINK_DOWN; + link.link_autoneg = ETH_LINK_FIXED; + link.link_duplex = ETH_LINK_FULL_DUPLEX; + ret = rte_kni_update_link(test_kni_ctx, &link); + if (ret != 0) { + printf("Failed to change link state to Down ret=%d.\n", + ret); + goto error; + } + rte_delay_ms(1000); + + link.link_speed = 40000; + link.link_status = ETH_LINK_UP; + link.link_autoneg = ETH_LINK_FIXED; + link.link_duplex = ETH_LINK_FULL_DUPLEX; + ret = rte_kni_update_link(test_kni_ctx, &link); + if (ret != 0) { + printf("Failed to change link state to " + "Up/40Gbps/Fixed/Full ret=%d.\n", ret); + goto error; + } + rte_delay_ms(1000); + + link.link_speed = 0; + link.link_status = ETH_LINK_DOWN; + link.link_autoneg = ETH_LINK_FIXED; + link.link_duplex = ETH_LINK_FULL_DUPLEX; + ret = rte_kni_update_link(test_kni_ctx, &link); + if (ret != 0) { + printf("Failed to change link state to Down ret=%d.\n", + ret); + goto error; + } + rte_delay_ms(1000); + + link.link_speed = 100000; + link.link_status = ETH_LINK_UP; + link.link_autoneg = ETH_LINK_FIXED; + link.link_duplex = ETH_LINK_FULL_DUPLEX; + ret = rte_kni_update_link(test_kni_ctx, &link); + if (ret != 0) { + printf("Failed to change link state to " + "Up/100Gbps/Fixed/Full ret=%d.\n", ret); + goto error; + } + rte_delay_ms(1000); + +error: + if (system(IFCONFIG TEST_KNI_PORT" down") == -1) + ret = -1; + + printf("KNI Link status change tests: %s.\n", + (ret == 0) ? "Passed" : "Failed"); + exit(ret); + } else { + int p_ret, status; + + while (1) { + p_ret = waitpid(pid, &status, WNOHANG); + if (p_ret != 0) { + if (WIFEXITED(status)) + return WEXITSTATUS(status); + return -1; + } + rte_delay_ms(10); + rte_kni_handle_request(test_kni_ctx); + } + } +} /** * This loop fully tests the basic functions of KNI. e.g. transmitting, * receiving to, from kernel space, and kernel requests. @@ -401,6 +528,10 @@ test_kni_processing(uint16_t port_id, struct rte_mempool *mp) goto fail_kni; } + ret = test_kni_link_change(); + if (ret != 0) + goto fail_kni; + rte_eal_mp_remote_launch(test_kni_loop, NULL, CALL_MASTER); RTE_LCORE_FOREACH_SLAVE(i) { if (rte_eal_wait_lcore(i) < 0) { From patchwork Thu Sep 27 00:32:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Gora X-Patchwork-Id: 45468 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 869341B2B3; Thu, 27 Sep 2018 02:34:18 +0200 (CEST) Received: from mail-qt1-f196.google.com (mail-qt1-f196.google.com [209.85.160.196]) by dpdk.org (Postfix) with ESMTP id 56D9F1B1C1 for ; Thu, 27 Sep 2018 02:34:10 +0200 (CEST) Received: by mail-qt1-f196.google.com with SMTP id n6-v6so973116qtl.4 for ; Wed, 26 Sep 2018 17:34:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xX5BCN1EA1YvdGifpFtBi3+Bd3fV7UXIa4dFxGhfigs=; b=jIg7umEQ3J9mRhgEb92YgwdoXyr1NQ1SIQPLZwwzNZBjxTmOzc5J4blE5+o0m/vNId e55RdL9iXoDtqok1BJl61LUk4vYQ0R5sfZhBDJf5XNdbN053E1/hDR/inJDRAxYCmqRo ZmocoZtJl7svpj+EI6Pxd8GiJ6Rbr4uvUXBYt2QMQO1BVAC/X79sjO2HuMIOr9p8nI+5 mX6EJxpWcurwAA5r+Z5SxjqoMe14GOSdKjFUu67TTgapVAzD/isA6N3Y5HLTpHe3wYvI NWS5CJ15MUMzgMfU8rg6DeQzQ9H1+NC22SEFdm9mr49ZPw+0EWIhScpo1BtCARGvhzVh 2/vQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=xX5BCN1EA1YvdGifpFtBi3+Bd3fV7UXIa4dFxGhfigs=; b=DxpBq6A+YXD4ldJCCjd/oKrqtvGkIIKAEFd8/CXVQ+qZZkwi0iZTThP2vSpkcXzJHg 2QKN/ZxV8lArRj4U/gwHlthF62DFtrtXBEB8UdpRFfr52QkWBSxp//HGIyVwQwViBZ6i sKSnHYH2D7cYOg5eL5mkA7zqEjcC4JL+eeGDBpjKasXq2Q0a7IxR6UptZz4AeZVH2iVP +5iciUeR+QQhjW6dXGPGo8J/+gArf/usI0bMgJcFdh/9sdprQd7+n2Xr9OTf1MXU/Pji Ghmy2NeRRVdkf4Bd4I+Arr9fZQw+Oe+cLbiAWBPZnwyRTisZ5rniU9R1vNT3Ayj76zRm /lNQ== X-Gm-Message-State: ABuFfohFVNlFOX/FfThEOpQ8NG2bzOE+fT7lKusYXk9rr754iDNqfCgz VL2k3cZa0rfw3ahulH2WDzCyBgUX X-Google-Smtp-Source: ACcGV63sJn60EtcVezgRpeeHChDEzM3iKwmbWD0OF/ti1pzC/31jcfRJTzLSJ8/4yEl9ZfiS0l44fg== X-Received: by 2002:a05:6214:114b:: with SMTP id b11mr6266277qvt.168.1538008449406; Wed, 26 Sep 2018 17:34:09 -0700 (PDT) Received: from snappy.local.lan (189-46-124-178.dsl.telesp.net.br. [189.46.124.178]) by smtp.gmail.com with ESMTPSA id x26-v6sm463053qth.15.2018.09.26.17.34.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 26 Sep 2018 17:34:08 -0700 (PDT) From: Dan Gora To: dev@dpdk.org Cc: Igor Ryzhov , Stephen Hemminger , Ferruh Yigit , Dan Gora Date: Wed, 26 Sep 2018 21:32:53 -0300 Message-Id: <20180927003256.6901-4-dg@adax.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180927003256.6901-1-dg@adax.com> References: <20180911232906.18352-1-dg@adax.com> <20180927003256.6901-1-dg@adax.com> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v3 3/6] kni: set default carrier state to 'off' 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" Set the carrier state to 'off' when the interface is instantiated or when it is marked 'up' or 'down'. This is necessary to set the interface to a known operational state until the carrier state is changed with rte_kni_update_link(). Signed-off-by: Dan Gora --- kernel/linux/kni/kni_misc.c | 2 ++ kernel/linux/kni/kni_net.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/kernel/linux/kni/kni_misc.c b/kernel/linux/kni/kni_misc.c index fa69f8e63..45649499d 100644 --- a/kernel/linux/kni/kni_misc.c +++ b/kernel/linux/kni/kni_misc.c @@ -466,6 +466,8 @@ kni_ioctl_create(struct net *net, uint32_t ioctl_num, return -ENODEV; } + netif_carrier_off(net_dev); + ret = kni_run_thread(knet, kni, dev_info.force_bind); if (ret != 0) return ret; diff --git a/kernel/linux/kni/kni_net.c b/kernel/linux/kni/kni_net.c index 7fcfa106c..1f8ba0700 100644 --- a/kernel/linux/kni/kni_net.c +++ b/kernel/linux/kni/kni_net.c @@ -133,6 +133,7 @@ kni_net_open(struct net_device *dev) struct kni_dev *kni = netdev_priv(dev); netif_start_queue(dev); + netif_carrier_off(dev); memset(&req, 0, sizeof(req)); req.req_id = RTE_KNI_REQ_CFG_NETWORK_IF; @@ -152,6 +153,7 @@ kni_net_release(struct net_device *dev) struct kni_dev *kni = netdev_priv(dev); netif_stop_queue(dev); /* can't transmit any more */ + netif_carrier_off(dev); memset(&req, 0, sizeof(req)); req.req_id = RTE_KNI_REQ_CFG_NETWORK_IF; From patchwork Thu Sep 27 00:32:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Gora X-Patchwork-Id: 45469 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id C46981B39B; Thu, 27 Sep 2018 02:34:20 +0200 (CEST) Received: from mail-qt1-f181.google.com (mail-qt1-f181.google.com [209.85.160.181]) by dpdk.org (Postfix) with ESMTP id 3AB521B1C1 for ; Thu, 27 Sep 2018 02:34:13 +0200 (CEST) Received: by mail-qt1-f181.google.com with SMTP id z14-v6so993249qtn.2 for ; Wed, 26 Sep 2018 17:34:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=pLLLNP8XDuEHY0ULln1BKY4tSmTgFpDovLSjwzzDUAk=; b=LlaCbo7rYsD/8kM1wwqYExhzMzd9F67Z9Tbtv058GLS5VL41FyvyC7DDskLxWWvRgV egEjixqAUymsfrVyclqBZHPr5qtCdJGhQ6u8V0AN8U6xukWdwebjYhGBgt6zOU6ZbgjK 3eJGn6YY1UYfr3LoqbD0eaMnlFCcnvuEZhyLT/9CZqMs5sG77RulNwaWqE03SiqjSK2T JvnBBLmvvFhJlJOOM0cOXVtb9zRnaM12zvTt4jjdrcQKIlJeJOvPf3S9qyTSf9vuC8cC ECu/CKwaTRRdzwK4NUOLJBtQFosq/mLUShL8ImA+iRCvwgK2g1K2PhNiTDGQ6t8iluAR BkOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=pLLLNP8XDuEHY0ULln1BKY4tSmTgFpDovLSjwzzDUAk=; b=FhvUZ+OmhjZLifR1M1rauTtOgisXGl6LEZ1x+RGQAqEO/VOZ8P/Ob4JRas9snqS3yT p1/ob5OvC5yq9yyuqtFqG9zdEllonbYi0VnXlhJhb6nuQU7dadz8jK0hER1uXPm6SUk1 NL+LjzYPQQ87oRdt/Dh2uNXza226HEUoF6+0E135/8NIWLDEcByn4dZ3Flsp/oM/M6SP 8kWMjWSEYmCL0rs4eTO5IKrSfj4BpptFaelQkIzBNTNCkSAsTtKVXjaQn5PxgzIkvEAh LPXjR3GJBMVt1InqFRi9g5WVd3Tp6KyXegR6sqLm3P56fGybOAxy7Xh4bWXZKvvKANIG medw== X-Gm-Message-State: ABuFfoi24UipoBYfIzrgI33vlHQNLSMv7zylVDfZh0gUJxORSg+NuPoo GxifwcUeT1QZS11C8Sr0gr68pIde X-Google-Smtp-Source: ACcGV6341WjEpt1F6u3a9Jtnp9Vf5dV4QaRC/qb5mc578RLX5pRRFAvK5gwPFC9yYW5jnsBNn5vqDg== X-Received: by 2002:ac8:29ef:: with SMTP id 44-v6mr6338172qtt.174.1538008452235; Wed, 26 Sep 2018 17:34:12 -0700 (PDT) Received: from snappy.local.lan (189-46-124-178.dsl.telesp.net.br. [189.46.124.178]) by smtp.gmail.com with ESMTPSA id x26-v6sm463053qth.15.2018.09.26.17.34.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 26 Sep 2018 17:34:11 -0700 (PDT) From: Dan Gora To: dev@dpdk.org Cc: Igor Ryzhov , Stephen Hemminger , Ferruh Yigit , Dan Gora Date: Wed, 26 Sep 2018 21:32:54 -0300 Message-Id: <20180927003256.6901-5-dg@adax.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180927003256.6901-1-dg@adax.com> References: <20180911232906.18352-1-dg@adax.com> <20180927003256.6901-1-dg@adax.com> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v3 4/6] examples/kni: monitor and update link status continually 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" Update KNI example to continuously monitor the Ethernet link status of the physical link and update the link status of the corresponding interfaces with rte_kni_update_link(). Signed-off-by: Dan Gora --- examples/kni/Makefile | 2 ++ examples/kni/main.c | 73 +++++++++++++++++-------------------------- 2 files changed, 31 insertions(+), 44 deletions(-) diff --git a/examples/kni/Makefile b/examples/kni/Makefile index 7e19d2e2a..dd90d7d73 100644 --- a/examples/kni/Makefile +++ b/examples/kni/Makefile @@ -20,6 +20,7 @@ static: build/$(APP)-static PC_FILE := $(shell pkg-config --path libdpdk) CFLAGS += -O3 $(shell pkg-config --cflags libdpdk) +CFLAGS += -DALLOW_EXPERIMENTAL_API LDFLAGS_SHARED = $(shell pkg-config --libs libdpdk) LDFLAGS_STATIC = -Wl,-Bstatic $(shell pkg-config --static --libs libdpdk) @@ -54,6 +55,7 @@ please change the definition of the RTE_TARGET environment variable) endif CFLAGS += -O3 +CFLAGS += -DALLOW_EXPERIMENTAL_API CFLAGS += $(WERROR_FLAGS) include $(RTE_SDK)/mk/rte.extapp.mk diff --git a/examples/kni/main.c b/examples/kni/main.c index 80c401c51..be721b9cc 100644 --- a/examples/kni/main.c +++ b/examples/kni/main.c @@ -107,6 +107,8 @@ static uint32_t ports_mask = 0; /* Ports set in promiscuous mode off by default. */ static int promiscuous_on = 0; +static int kni_running; + /* Structure type for recording kni interface specific stats */ struct kni_interface_stats { /* number of pkts received from NIC, and sent to KNI */ @@ -619,59 +621,31 @@ init_port(uint16_t port) rte_eth_promiscuous_enable(port); } -/* Check the link status of all ports in up to 9s, and print them finally */ -static void -check_all_ports_link_status(uint32_t port_mask) +/* + * Monitor the link status of all ports and update the + * corresponding KNI interface(s) + */ +static void * +check_all_ports_link_status(void *arg) { -#define CHECK_INTERVAL 100 /* 100ms */ -#define MAX_CHECK_TIME 90 /* 9s (90 * 100ms) in total */ uint16_t portid; - uint8_t count, all_ports_up, print_flag = 0; struct rte_eth_link link; + unsigned int i; + struct kni_port_params **p = kni_port_params_array; + (void) arg; - printf("\nChecking link status\n"); - fflush(stdout); - for (count = 0; count <= MAX_CHECK_TIME; count++) { - all_ports_up = 1; + while (kni_running) { + rte_delay_ms(100); RTE_ETH_FOREACH_DEV(portid) { - if ((port_mask & (1 << portid)) == 0) + if ((ports_mask & (1 << portid)) == 0) continue; memset(&link, 0, sizeof(link)); rte_eth_link_get_nowait(portid, &link); - /* print link status if flag set */ - if (print_flag == 1) { - if (link.link_status) - printf( - "Port%d Link Up - speed %uMbps - %s\n", - portid, link.link_speed, - (link.link_duplex == ETH_LINK_FULL_DUPLEX) ? - ("full-duplex") : ("half-duplex\n")); - else - printf("Port %d Link Down\n", portid); - continue; - } - /* clear all_ports_up flag if any link down */ - if (link.link_status == ETH_LINK_DOWN) { - all_ports_up = 0; - break; - } - } - /* after finally printing all link status, get out */ - if (print_flag == 1) - break; - - if (all_ports_up == 0) { - printf("."); - fflush(stdout); - rte_delay_ms(CHECK_INTERVAL); - } - - /* set the print_flag if all ports up or timeout */ - if (all_ports_up == 1 || count == (MAX_CHECK_TIME - 1)) { - print_flag = 1; - printf("done\n"); + for (i = 0; i < p[portid]->nb_kni; i++) + rte_kni_update_link(p[portid]->kni[i], &link); } } + return NULL; } /* Callback for request of changing MTU */ @@ -893,6 +867,8 @@ main(int argc, char** argv) int ret; uint16_t nb_sys_ports, port; unsigned i; + void *retval; + pthread_t kni_link_tid; /* Associate signal_hanlder function with USR signals */ signal(SIGUSR1, signal_handler); @@ -947,7 +923,14 @@ main(int argc, char** argv) kni_alloc(port); } - check_all_ports_link_status(ports_mask); + + kni_running = 1; + ret = rte_ctrl_thread_create(&kni_link_tid, + "KNI link status check", NULL, + check_all_ports_link_status, NULL); + if (ret < 0) + rte_exit(EXIT_FAILURE, + "Could not create link status thread!\n"); /* Launch per-lcore function on every lcore */ rte_eal_mp_remote_launch(main_loop, NULL, CALL_MASTER); @@ -955,6 +938,8 @@ main(int argc, char** argv) if (rte_eal_wait_lcore(i) < 0) return -1; } + kni_running = 0; + pthread_join(kni_link_tid, &retval); /* Release resources */ RTE_ETH_FOREACH_DEV(port) { From patchwork Thu Sep 27 00:32:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Gora X-Patchwork-Id: 45470 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id DF56D1B3A1; Thu, 27 Sep 2018 02:34:27 +0200 (CEST) Received: from mail-qt1-f194.google.com (mail-qt1-f194.google.com [209.85.160.194]) by dpdk.org (Postfix) with ESMTP id E28281B277 for ; Thu, 27 Sep 2018 02:34:15 +0200 (CEST) Received: by mail-qt1-f194.google.com with SMTP id c25-v6so959080qtp.6 for ; Wed, 26 Sep 2018 17:34:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=W69kTPPQZsG3Xfc6I/641TiWiA+zDnC2Z/KCUco6T/E=; b=bJ17VFUeURhw3R3L2uEkJQ2YBJGSeQh/9/vpXHYURy522YPXHrnA9dIuHi2PcLKf1K izSSyUSThJ5Yh73O58243mp4yjjgYUnrVq9+QaL5zcD3KMT2w/+K4nP6wzDHu7PKo/vr 6JPxacbNx4jkxpTqYHcT10f/XQ/w/y442+O+ivX3O4K065xYFSbc2rdkUj9FUXQKR4nM +phYjwpe61WQJU1YHW9zdBuxPPQ3VY0U5YE1MAxjCMSfmgd2AoqPmOafhz6HQJolkpWJ DLLjou3i1YUm2YAtAPAamVp5u9J4EtPutAhOkjvpy/jXBEZ671qzd7M0T48ApUPARHPo /moA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=W69kTPPQZsG3Xfc6I/641TiWiA+zDnC2Z/KCUco6T/E=; b=if7MuTT2Uu0rJqHepIWz9ynCOrb3akyFAc9WvN4wX4GsS8NcsFmcSg4uZqIX4TcYnp 9I8zjt6TqvE+SLMOiOIWg7CNAbRnolHYn84S6BpKDsxsC14jWO+t9cvBlxgpXpmmJBKe QMgDuAugnlrkprM8gUArKxgpSGAesTAIBtvWOcIlQ5oEYK/p+WzUNugJJqYvRnRXIwmq jkqwOqizUfNSrF53FwOTZZwcG+SbXzpycSVMyQ33Frb6752WvAyuoAD/S0ieT24xpykd ZFSA/wjVoWyg11iFNwUOrQwtpuZYs0Lwb8sR24CU6WmvymriJ3jMlhRCir3W6nAUzQr/ rByg== X-Gm-Message-State: ABuFfojSn4WMH19OA+SRCyWQqdRx9PVadbIWXQ4HlT8478pPwZe31JUN dNN6nvYVDvhGoL4bb0bFbZMyW/3q X-Google-Smtp-Source: ACcGV627LDqVtBZbLTNvmkBSYnMdPw0Q+j4qgibFE5Hlh/OkPZsb5eOE163vUP95ETbidcHuRH/8aQ== X-Received: by 2002:a0c:bf49:: with SMTP id b9-v6mr6253808qvj.65.1538008454969; Wed, 26 Sep 2018 17:34:14 -0700 (PDT) Received: from snappy.local.lan (189-46-124-178.dsl.telesp.net.br. [189.46.124.178]) by smtp.gmail.com with ESMTPSA id x26-v6sm463053qth.15.2018.09.26.17.34.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 26 Sep 2018 17:34:14 -0700 (PDT) From: Dan Gora To: dev@dpdk.org Cc: Igor Ryzhov , Stephen Hemminger , Ferruh Yigit , Dan Gora Date: Wed, 26 Sep 2018 21:32:55 -0300 Message-Id: <20180927003256.6901-6-dg@adax.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180927003256.6901-1-dg@adax.com> References: <20180911232906.18352-1-dg@adax.com> <20180927003256.6901-1-dg@adax.com> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v3 5/6] examples/kni: add log msgs to show and clear stats 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" Add logging messages showing the commands necessary for the user to have the application display and zero the statistics. Signed-off-by: Dan Gora --- examples/kni/main.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/examples/kni/main.c b/examples/kni/main.c index be721b9cc..357cfd6fc 100644 --- a/examples/kni/main.c +++ b/examples/kni/main.c @@ -171,14 +171,13 @@ signal_handler(int signum) /* When we receive a USR2 signal, reset stats */ if (signum == SIGUSR2) { memset(&kni_stats, 0, sizeof(kni_stats)); - printf("\n**Statistics have been reset**\n"); + printf("\n** Statistics have been reset **\n"); return; } /* When we receive a RTMIN or SIGINT signal, stop kni processing */ if (signum == SIGRTMIN || signum == SIGINT){ - printf("SIGRTMIN is received, and the KNI processing is " - "going to stop\n"); + printf("\nSIGRTMIN/SIGINT received. KNI processing stopping.\n"); rte_atomic32_inc(&kni_stop); return; } @@ -869,6 +868,7 @@ main(int argc, char** argv) unsigned i; void *retval; pthread_t kni_link_tid; + int pid; /* Associate signal_hanlder function with USR signals */ signal(SIGUSR1, signal_handler); @@ -924,6 +924,16 @@ main(int argc, char** argv) kni_alloc(port); } + pid = getpid(); + RTE_LOG(INFO, APP, "========================\n"); + RTE_LOG(INFO, APP, "KNI Running\n"); + RTE_LOG(INFO, APP, "kill -SIGUSR1 %d\n", pid); + RTE_LOG(INFO, APP, " Show KNI Statistics.\n"); + RTE_LOG(INFO, APP, "kill -SIGUSR2 %d\n", pid); + RTE_LOG(INFO, APP, " Zero KNI Statistics.\n"); + RTE_LOG(INFO, APP, "========================\n"); + fflush(stdout); + kni_running = 1; ret = rte_ctrl_thread_create(&kni_link_tid, "KNI link status check", NULL, From patchwork Thu Sep 27 00:32:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Gora X-Patchwork-Id: 45471 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id B1E431B3B0; Thu, 27 Sep 2018 02:34:29 +0200 (CEST) Received: from mail-qt1-f194.google.com (mail-qt1-f194.google.com [209.85.160.194]) by dpdk.org (Postfix) with ESMTP id 961EF1B396 for ; Thu, 27 Sep 2018 02:34:18 +0200 (CEST) Received: by mail-qt1-f194.google.com with SMTP id l16-v6so934783qtq.10 for ; Wed, 26 Sep 2018 17:34:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XajtgKiqjzZQSpraVqsSiDSw1ckFngYhJNl+DiOidKw=; b=dXg14jedQ2/tM4nWsxX9jhcRBPrv8s4a0zKVp+Y0MCqYVjKqT1fKpy4xsojPv8Ybz2 x3VV+k9NUnOpYRcAucuLN/9kqQnVGS5dHt7Fe5ga5cEZ9/nbJ8akEvGY0RErUj5TcEJY +/Fv1d7fnBya1Cc2tUtgurJ9Ru3WOajrhV23yOHrJN5GquVpru8hZjCDplxA4YFFPFgk QigPLJ0EF3Z5+AmEQiGwsUkx5wjQdfRYL2rvTXCuAtibLc4XR02c29Yl8ugddGV8P95p 3sdTHuetb8udvsCkKzDySE6qngWvWljMcXCNmQGKAsIHu6v1SwmgHTjQ3EG6PfWUtxpn HilQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=XajtgKiqjzZQSpraVqsSiDSw1ckFngYhJNl+DiOidKw=; b=h2Mvg3EYmZdHqbU48ouwRZJhkDG3iG4ytgTneOFClaecd12ZVT1QWKaQAmx1ouk8b+ hsCqw6Zz4mjqvNs3YRJQKj3qldNtiqKOELDWC/KJMP8uBVOCfHsJMPz7+5sb+iBUPQlD EzQjVKUXihjpDVrY2ARZOzmvsinIDjR7cQJVMuxktqF5SmvIgLXdbEApBQAedHaRKyhl 7q7Cv8rg15gx8Ii1+FbnhspGk/1SgP9aoLb1jYzETHWpRVd5D6E4s5C2SGML5S/AhFTj 76mosY1hawO5QFsaWSBYAonmlXxMigw5e0X3iieDV8AFwBcJWR8a+ORSaY/aKVibnjjn 6FPw== X-Gm-Message-State: ABuFfoiFP4y87X+IQcEo2KqopKoFgozqJvsYRRrG/6TFFMvBMdsqLLRA Xzf+QsYBrxY4uryOD1xCD4adfpNd X-Google-Smtp-Source: ACcGV63NfvTmfZUIyVUx2UgdJ6Vzg9ghcUUdETJkEVqjvjNhKFoqV/TQWeK5ZesG4w7f7tc0tz9+ig== X-Received: by 2002:ac8:34bc:: with SMTP id w57-v6mr6507747qtb.239.1538008457662; Wed, 26 Sep 2018 17:34:17 -0700 (PDT) Received: from snappy.local.lan (189-46-124-178.dsl.telesp.net.br. [189.46.124.178]) by smtp.gmail.com with ESMTPSA id x26-v6sm463053qth.15.2018.09.26.17.34.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 26 Sep 2018 17:34:16 -0700 (PDT) From: Dan Gora To: dev@dpdk.org Cc: Igor Ryzhov , Stephen Hemminger , Ferruh Yigit , Dan Gora Date: Wed, 26 Sep 2018 21:32:56 -0300 Message-Id: <20180927003256.6901-7-dg@adax.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180927003256.6901-1-dg@adax.com> References: <20180911232906.18352-1-dg@adax.com> <20180927003256.6901-1-dg@adax.com> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v3 6/6] examples/kni: improve zeroing statistics 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 worker threads incrementing the rx/tx_packets race with the signal handler from the main thread zeroing the entire statistics structure. This can cause the statistics to fail to be zeroed, even when there is no traffic on those interfaces. Improve zeroing the statistics by only incrementing rx/tx_packets in worker threads by a non-zero amount. This limits the race to the periods in which traffic is actually being received or transmitted. Signed-off-by: Dan Gora --- examples/kni/main.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/kni/main.c b/examples/kni/main.c index 357cfd6fc..cda23b028 100644 --- a/examples/kni/main.c +++ b/examples/kni/main.c @@ -223,7 +223,8 @@ kni_ingress(struct kni_port_params *p) } /* Burst tx to kni */ num = rte_kni_tx_burst(p->kni[i], pkts_burst, nb_rx); - kni_stats[port_id].rx_packets += num; + if (num) + kni_stats[port_id].rx_packets += num; rte_kni_handle_request(p->kni[i]); if (unlikely(num < nb_rx)) { @@ -260,7 +261,8 @@ kni_egress(struct kni_port_params *p) } /* Burst tx to eth */ nb_tx = rte_eth_tx_burst(port_id, 0, pkts_burst, (uint16_t)num); - kni_stats[port_id].tx_packets += nb_tx; + if (nb_tx) + kni_stats[port_id].tx_packets += nb_tx; if (unlikely(nb_tx < num)) { /* Free mbufs not tx to NIC */ kni_burst_free_mbufs(&pkts_burst[nb_tx], num - nb_tx);