From patchwork Tue Sep 11 23:29:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Gora X-Patchwork-Id: 44603 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 82DAD4C95; Wed, 12 Sep 2018 01:29:26 +0200 (CEST) Received: from mail-qk1-f195.google.com (mail-qk1-f195.google.com [209.85.222.195]) by dpdk.org (Postfix) with ESMTP id D69CB4C94 for ; Wed, 12 Sep 2018 01:29:25 +0200 (CEST) Received: by mail-qk1-f195.google.com with SMTP id f17-v6so32608qkh.4 for ; Tue, 11 Sep 2018 16:29:25 -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=brKgXRmAdYdNeL3uqBo0I3ImwvPWLgFWozo5r8fr8WE=; b=KJlNr9W+jF7TRpZem/EbIKwgveOlC4PL2Zd13KCpNi7odfYYHKpvtMjVYGm6Y/jfv8 KCbukPkFLJFYqx5kwE4FZRF2cr1/Y3E+lPLVE9mVYjObleJnkWjNADeUcwhJZXRQyfon IUWWsiogbcQTzSNnOBiQ/PIEP4Ec75OQu4qtW+6LEJ5Yc5nPsDkBR5V07wgt7hjRqG21 GIZC4BmYxvCSvxtCLIxsJYN79O97EEcDC33P7x0fKh1L+xnXmdFiLRF4DMYs3AuDQd3x ek4YfHxw4XdKZkA0m1Kn1B7LnH4zzHP2Ap+RRSjioAIqJE6fYOdXSYRHbjtaOfX/y/EM HXqA== 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=brKgXRmAdYdNeL3uqBo0I3ImwvPWLgFWozo5r8fr8WE=; b=LScDXJTP/jGo+IA+xonP8eGpsZPhLZ/beOEbeVH/jtQwGJX+mcEZXnQOErEfMwwJhK 5cKWOmEZOIO2lO7JAiO1Ww2Yjb8XhWHcR8oAp61pWoZutIvZ/A6eAeUlVC3p2z7CcZSL Ftf+QAaxKM4rKj5dMviVJ/YtOmLewbVhwxY9C6RoGOrdA3tmwXMFK88ZVlWRrMdAVq6o rmF19xfdLpjfi46zuV8UEKGF0ATW9DLzDcLtDJ7a+FRM15CyKMcW8xzETVJqRMDQH/XW JcVlH3s32Mrc6nt3WcmMJzEM6eWdEEBstvKK4aCn/my7r23v8CfExoH/Cam7blvet3az J7mw== X-Gm-Message-State: APzg51DTsCf3syC/4GrqZSav3svLhuE9nUMxe4IG1yuBTbj2Wcv+jsMf 88eCjMXNJDEBbnY05w/lJGjd22fz X-Google-Smtp-Source: ANB0VdZSMqU3g7agqrJwRA750traNHslUqwZJ0vL+3BISYnDbqaa82gN1kdCR9W19cjH0EWvK26qSQ== X-Received: by 2002:a37:cc9a:: with SMTP id n26-v6mr20947097qkl.112.1536708564872; Tue, 11 Sep 2018 16:29:24 -0700 (PDT) Received: from snappy.local.lan (189-46-164-241.dsl.telesp.net.br. [189.46.164.241]) by smtp.gmail.com with ESMTPSA id p30-v6sm12767814qta.4.2018.09.11.16.29.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 11 Sep 2018 16:29:24 -0700 (PDT) From: Dan Gora To: dev@dpdk.org Cc: Igor Ryzhov , Stephen Hemminger , Ferruh Yigit , Dan Gora Date: Tue, 11 Sep 2018 20:29:05 -0300 Message-Id: <20180911232906.18352-2-dg@adax.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180911232906.18352-1-dg@adax.com> References: <20180911232906.18352-1-dg@adax.com> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH 1/2] 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 +++++++++++++ 2 files changed, 75 insertions(+) diff --git a/lib/librte_kni/rte_kni.c b/lib/librte_kni/rte_kni.c index 65f6a2b03..afe1d7410 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_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 ? "(Fixed)" : "(AutoNeg)", + 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. */ From patchwork Tue Sep 11 23:29:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Gora X-Patchwork-Id: 44604 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 75A464C94; Wed, 12 Sep 2018 01:29:35 +0200 (CEST) Received: from mail-qt0-f196.google.com (mail-qt0-f196.google.com [209.85.216.196]) by dpdk.org (Postfix) with ESMTP id 0D94E4C74 for ; Wed, 12 Sep 2018 01:29:34 +0200 (CEST) Received: by mail-qt0-f196.google.com with SMTP id g53-v6so26417qtg.10 for ; Tue, 11 Sep 2018 16:29:33 -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=lDrW5xwn5txmyUMWCyqYldoDx8rKm+fnxw+vUUIMejQnodaWavIkRDCytwtOfioLOJ /zcd8pl2f8GQiPfwz91eY/ntH1+DKfrGe8QuGPlElCVSibfoCtoWPzHhOtd7mkENwFnx 0U2JnJH4W4/5LpKYrFT/cEtfGI/G8hjgVGuo3Ywxic+G4g8PkB9J1PdJ3B15hKa5C6uj pctz6zTYufWw4g9bsuWtPwQGpIzd7OosvgWyeKKd3iqy24QYH7qGE40Enhn2vyDHCYzo 5rbKIOwhGz3RW7NkfZAb/aPsxK0zL5FRCeu3C/GK9VEoultqUmVPIMQoNo48SK042xqW IIFQ== 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=gzWle38a5ZO2KXQuHWujfdr1Mhh7hM6yZfW1YTBY1iXHNPzVC04jc3ytSvh/cqZq1C XQ44ioNsE6zgrnJnGvKFWvxDcwGFEbKNp/URbnTVwDqLkZ2BUF6+lKFBw0YOmMdcTmk9 M3dgY5N4j/u4Fqa5l4jhO7wmMxYx3OZFPIOoUWPCu0HFR4t5r9Y+lsvcMVcDksUgyfXV QdEDs/EPlWe+i4KbscljSIiX/jEzfvndvOtIov9nSjeS7NAR+3abVbUvi/fp6IOx2ILy XHTCbcUYLz4n/HS4xcXAI+toh692BIaSttLlRO3lDalcDYBwH/27LmFXkZroEOezBKaA 3d4Q== X-Gm-Message-State: APzg51D9mk19Q04mFvpvtZoRUbeLsB05FXXuZzXKdhWhapggfkNTN+kt Gk/K2I8Igp+un8BWCpZMM1fEdTZc X-Google-Smtp-Source: ANB0Vda7hH9Io1AYjU/lkBnhKDoCYz8OxkrJhgV8o60uM8EguNyit13hJdGx2EQp0X4VaUQefrnHdg== X-Received: by 2002:aed:3ceb:: with SMTP id e40-v6mr22251160qtf.157.1536708568925; Tue, 11 Sep 2018 16:29:28 -0700 (PDT) Received: from snappy.local.lan (189-46-164-241.dsl.telesp.net.br. [189.46.164.241]) by smtp.gmail.com with ESMTPSA id p30-v6sm12767814qta.4.2018.09.11.16.29.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 11 Sep 2018 16:29:28 -0700 (PDT) From: Dan Gora To: dev@dpdk.org Cc: Igor Ryzhov , Stephen Hemminger , Ferruh Yigit , Dan Gora Date: Tue, 11 Sep 2018 20:29:06 -0300 Message-Id: <20180911232906.18352-3-dg@adax.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180911232906.18352-1-dg@adax.com> References: <20180911232906.18352-1-dg@adax.com> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH 2/2] 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 Wed Oct 17 01:04:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Gora X-Patchwork-Id: 46925 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 ADC7C5B16; Wed, 17 Oct 2018 03:04:46 +0200 (CEST) Received: from mail-qk1-f195.google.com (mail-qk1-f195.google.com [209.85.222.195]) by dpdk.org (Postfix) with ESMTP id 6F0A258FE for ; Wed, 17 Oct 2018 03:04:44 +0200 (CEST) Received: by mail-qk1-f195.google.com with SMTP id v68-v6so15445245qka.2 for ; Tue, 16 Oct 2018 18:04:44 -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=2UELdy0yPdq1PAyRC8o+AggKNGplVW0JzBg4affyT1Q=; b=Kr+T7o7PqJx3Emf8GieLU68vAu16yT46bC/YisB4OOxNCfcA7zXy2T54lgdTD5BPuY M1uMv10db92NXr3mDCb6VVUiY3sdcVhmjNK565+oYmx/RzKz+aQi3wCBXxomFgf7xbD9 9iIXK8DAmIdYoNfQIvbBpVOeUKL/HRbp7ZxSWYCn1g74vSqwM3N2ZZrGoJEZA/GN8vVm MhkTiS8T9o5hnhQegYM4Yvnj0b6BDfG3ybLKY8wQ5meBmhwPDHGd3Bb22Ebk4w7TLqKF SKYJ6S9Ooan7ad2N4/9EfL2OgoapsY8O76C6IiqqkzrlOJfkM85PP3LIcmiTWUCVlo5S UMRQ== 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=2UELdy0yPdq1PAyRC8o+AggKNGplVW0JzBg4affyT1Q=; b=AYRgeyzb0dG47TtWOfEgmgbgl+Nc+EEDqHQy5ogz+VwQS1evuP9AQava4+Z6eibVXV B79GeCpy/Ls5JOxFrTQ2M8vZ8JniAJ1Dyz4eDHcgHBF1/KLFtHWsw2FWBHbtIuzXvrm+ w6MvbGybg7C7lsBnOmOZ6HE+FjGaKLKUEth3WtmASprETyqLc5Vya0EhPCyk4GgqmNtN 26+XcCfRdvIWvGj1RVcAAnvUckP4JEOQRUYfqarh6Hzbd5AiJW/UAHtk6HHuZuTpDU/b K3zr9t05sDUcdMNuEpuTYFf0opqsNlmZ0bkEqctkLI7dAJ98IDS/E+lFI7g9sZ9Vn31m 2Kyg== X-Gm-Message-State: ABuFfohnisgepgBd1vH1QNTSl8LRqFNKY6GG3nMkmehE+n/GhGAp3oiJ lJxTXs98J8ZFuSwWoztDBLLu/DHfG+0= X-Google-Smtp-Source: ACcGV62YrZhTpUOfwOQzzAV73D9NO7uJ1YmzQEyVES/w3BYUn2+/Cm51T326gGcOj89b6T8FrLAF1w== X-Received: by 2002:a37:a512:: with SMTP id o18-v6mr21643861qke.232.1539738283508; Tue, 16 Oct 2018 18:04:43 -0700 (PDT) Received: from snappy.local.lan ([187.74.142.5]) by smtp.gmail.com with ESMTPSA id v54-v6sm19547508qtc.81.2018.10.16.18.04.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 16 Oct 2018 18:04:42 -0700 (PDT) From: Dan Gora To: dev@dpdk.org Cc: Igor Ryzhov , Stephen Hemminger , Ferruh Yigit , Dan Gora Date: Tue, 16 Oct 2018 22:04:10 -0300 Message-Id: <20181017010412.23141-4-dg@adax.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180911232906.18352-1-dg@adax.com> References: <20180911232906.18352-1-dg@adax.com> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v4 3/6] kni: set default carrier state of 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 module parameter 'carrier='on|off' to set the default carrier state for linux network interfaces created by the KNI module. The default carrier state is 'off'. For KNI interfaces which need to reflect the carrier state of a physical Ethernet port controlled by the DPDK application, the default carrier state should be left set to 'off'. The application can set the carrier state of the KNI interface to reflect the state of the physical Ethernet port using rte_kni_update_link(). For KNI interfaces which are purely virtual, the default carrier state can be set to 'on'. This enables the KNI interface to be used without having to explicity set the carrier state to 'on' using rte_kni_update_link(). Signed-off-by: Dan Gora --- kernel/linux/kni/kni_dev.h | 3 +++ kernel/linux/kni/kni_misc.c | 40 +++++++++++++++++++++++++++++++++++++ kernel/linux/kni/kni_net.c | 5 +++++ 3 files changed, 48 insertions(+) diff --git a/kernel/linux/kni/kni_dev.h b/kernel/linux/kni/kni_dev.h index 6275ef27f..688f574a4 100644 --- a/kernel/linux/kni/kni_dev.h +++ b/kernel/linux/kni/kni_dev.h @@ -29,6 +29,9 @@ #define MBUF_BURST_SZ 32 +/* Default carrier state for created KNI network interfaces */ +extern uint32_t dflt_carrier; + /** * A structure describing the private information for a kni device. */ diff --git a/kernel/linux/kni/kni_misc.c b/kernel/linux/kni/kni_misc.c index fa69f8e63..a5e7af2a6 100644 --- a/kernel/linux/kni/kni_misc.c +++ b/kernel/linux/kni/kni_misc.c @@ -39,6 +39,10 @@ static char *lo_mode; static char *kthread_mode; static uint32_t multiple_kthread_on; +/* Default carrier state for created KNI network interfaces */ +static char *carrier; +uint32_t dflt_carrier; + #define KNI_DEV_IN_USE_BIT_NUM 0 /* Bit number for device in use */ static int kni_net_id; @@ -466,6 +470,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; @@ -590,6 +596,22 @@ kni_parse_kthread_mode(void) return 0; } +static int __init +kni_parse_carrier_state(void) +{ + if (!carrier) + dflt_carrier = 0; + + if (strcmp(carrier, "off") == 0) + dflt_carrier = 0; + else if (strcmp(carrier, "on") == 0) + dflt_carrier = 1; + else + return -1; + + return 0; +} + static int __init kni_init(void) { @@ -605,6 +627,16 @@ kni_init(void) else pr_debug("Multiple kernel thread mode enabled\n"); + if (kni_parse_carrier_state() < 0) { + pr_err("Invalid parameter for carrier\n"); + return -EINVAL; + } + + if (dflt_carrier == 0) + pr_debug("Default carrier state set to off.\n"); + else + pr_debug("Default carrier state set to on.\n"); + #ifdef HAVE_SIMPLIFIED_PERNET_OPERATIONS rc = register_pernet_subsys(&kni_net_ops); #else @@ -663,3 +695,11 @@ MODULE_PARM_DESC(kthread_mode, " multiple Multiple kernel thread mode enabled.\n" "\n" ); + +module_param(carrier, charp, S_IRUGO); +MODULE_PARM_DESC(carrier, +"Defaul carrier state for KNI interface (default=off):\n" +" off Interfaces will be created with carrier state set to off.\n" +" on Interfaces will be created with carrier state set to on.\n" +"\n" +); diff --git a/kernel/linux/kni/kni_net.c b/kernel/linux/kni/kni_net.c index 3a542d737..7371b6d58 100644 --- a/kernel/linux/kni/kni_net.c +++ b/kernel/linux/kni/kni_net.c @@ -133,6 +133,10 @@ kni_net_open(struct net_device *dev) struct kni_dev *kni = netdev_priv(dev); netif_start_queue(dev); + if (dflt_carrier == 1) + netif_carrier_on(dev); + else + netif_carrier_off(dev); memset(&req, 0, sizeof(req)); req.req_id = RTE_KNI_REQ_CFG_NETWORK_IF; @@ -152,6 +156,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 Wed Oct 17 01:04:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Gora X-Patchwork-Id: 46926 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 6BB5158FE; Wed, 17 Oct 2018 03:04:50 +0200 (CEST) Received: from mail-qk1-f180.google.com (mail-qk1-f180.google.com [209.85.222.180]) by dpdk.org (Postfix) with ESMTP id 4F6CD58FE for ; Wed, 17 Oct 2018 03:04:47 +0200 (CEST) Received: by mail-qk1-f180.google.com with SMTP id a85-v6so15445165qkg.3 for ; Tue, 16 Oct 2018 18:04:47 -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=YXXVpyDrx8IPADtT5NX3LbPOsIXnyqYD0/EQ9rmANjE=; b=SLrYZrYzCRG4SOAJ2JeVDRqyLCNuphimsB02impl361f8do15TF2vQvKOExQoxcEdg MSGm18e4r7rnh3JSLCEUXLY2J6ADiPkgLMKpO5WpT20PHkqiozwp5lSiCFncRmDTl+2/ zgpWC0NuXvyTKW5xP0U8M3YwehTMcNTIQtgQIaB2sUDfw081+nKmuCJ55W90qxgHZEcL IQhcdkEDRZgPdivNjS3VIPJEz8NUqqOAwUuKJgF3XiWolfJCAhykZ94dyny/aEFNi2Wp JbIzIIce60MQuUvJphAaTktctHchUu4RJ79Ys50T7hbZMPu43VxmoKdOiQ2Em5jORpcE y2mQ== 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=YXXVpyDrx8IPADtT5NX3LbPOsIXnyqYD0/EQ9rmANjE=; b=XuZV2bah1PWlde60LrVWoVxe+QY29EPspHm8Mp8eRBvfFBje/NGNc73b8VMcb93QUL REpOqU5bnEYza9V6frRnQEllpCBud18zMN0WmtF71JVWNkWK5zf3O6AJUxPMz7oiKYmv jvh/6m3Oa1r7Osi2YVtlBN3ONFZVkWwusYViYX4sdT3G8Qo4GwQ4qjPN71o4uUB8dOgs 9fAokQCDLeM0oad3EfjxdU8Ex2Q4QOLv2SYe+TlbgCq6fr2b8+d3pENETxZfDlRq8q3r lsDVtreETSDerVf907y8gvylBMLa+U9hNmlgLgbaHvIGlItRdsHxVT/mPR5ONZRE5s1q XZEg== X-Gm-Message-State: ABuFfogfofkpI/+apEWAOk4FzEHDlBwee1GQHWMP9ZJh8c0M6KfyEa+A JWOoIA2tUwE2w6qYK/TybvHjMURFM/c= X-Google-Smtp-Source: ACcGV60+RonaETbFFesXB59+ey1w8tkmqDeC/EG4+kUikzlHsGGgVlctCdLHwWeNxVup9V8HooCKJg== X-Received: by 2002:a37:8d83:: with SMTP id p125-v6mr22568123qkd.97.1539738286309; Tue, 16 Oct 2018 18:04:46 -0700 (PDT) Received: from snappy.local.lan ([187.74.142.5]) by smtp.gmail.com with ESMTPSA id v54-v6sm19547508qtc.81.2018.10.16.18.04.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 16 Oct 2018 18:04:45 -0700 (PDT) From: Dan Gora To: dev@dpdk.org Cc: Igor Ryzhov , Stephen Hemminger , Ferruh Yigit , Dan Gora Date: Tue, 16 Oct 2018 22:04:11 -0300 Message-Id: <20181017010412.23141-5-dg@adax.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180911232906.18352-1-dg@adax.com> References: <20180911232906.18352-1-dg@adax.com> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v4 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 add the command line flag '-m' to enable a function 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 | 70 +++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 70 insertions(+), 2 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..634024960 100644 --- a/examples/kni/main.c +++ b/examples/kni/main.c @@ -106,6 +106,8 @@ static struct rte_mempool * pktmbuf_pool = NULL; static uint32_t ports_mask = 0; /* Ports set in promiscuous mode off by default. */ static int promiscuous_on = 0; +/* Monitor link status continually. off by default. */ +static int monitor_links; /* Structure type for recording kni interface specific stats */ struct kni_interface_stats { @@ -325,11 +327,12 @@ main_loop(__rte_unused void *arg) static void print_usage(const char *prgname) { - RTE_LOG(INFO, APP, "\nUsage: %s [EAL options] -- -p PORTMASK -P " + RTE_LOG(INFO, APP, "\nUsage: %s [EAL options] -- -p PORTMASK -P -m " "[--config (port,lcore_rx,lcore_tx,lcore_kthread...)" "[,(port,lcore_rx,lcore_tx,lcore_kthread...)]]\n" " -p PORTMASK: hex bitmask of ports to use\n" " -P : enable promiscuous mode\n" + " -m : enable monitoring of port carrier state\n" " --config (port,lcore_rx,lcore_tx,lcore_kthread...): " "port and lcore configurations\n", prgname); @@ -510,7 +513,7 @@ parse_args(int argc, char **argv) opterr = 0; /* Parse command line */ - while ((opt = getopt_long(argc, argv, "p:P", longopts, + while ((opt = getopt_long(argc, argv, "p:Pm", longopts, &longindex)) != EOF) { switch (opt) { case 'p': @@ -519,6 +522,9 @@ parse_args(int argc, char **argv) case 'P': promiscuous_on = 1; break; + case 'm': + monitor_links = 1; + break; case 0: if (!strncmp(longopts[longindex].name, CMDLINE_OPT_CONFIG, @@ -674,6 +680,55 @@ check_all_ports_link_status(uint32_t port_mask) } } +static void +log_link_state(struct rte_kni *kni, int prev, struct rte_eth_link *link) +{ + if (kni == NULL || link == NULL) + return; + + if (prev == ETH_LINK_DOWN && link->link_status == ETH_LINK_UP) { + RTE_LOG(INFO, APP, "%s NIC Link is Up %d Mbps %s %s.\n", + rte_kni_get_name(kni), + link->link_speed, + link->link_autoneg ? "(AutoNeg)" : "(Fixed)", + link->link_duplex ? "Full Duplex" : "Half Duplex"); + } else if (prev == ETH_LINK_UP && link->link_status == ETH_LINK_DOWN) { + RTE_LOG(INFO, APP, "%s NIC Link is Down.\n", + rte_kni_get_name(kni)); + } +} + +/* + * Monitor the link status of all ports and update the + * corresponding KNI interface(s) + */ +static void * +monitor_all_ports_link_status(void *arg) +{ + uint16_t portid; + struct rte_eth_link link; + unsigned int i; + struct kni_port_params **p = kni_port_params_array; + int prev; + (void) arg; + + while (monitor_links) { + rte_delay_ms(100); + RTE_ETH_FOREACH_DEV(portid) { + if ((ports_mask & (1 << portid)) == 0) + continue; + memset(&link, 0, sizeof(link)); + rte_eth_link_get_nowait(portid, &link); + for (i = 0; i < p[portid]->nb_kni; i++) { + prev = rte_kni_update_link(p[portid]->kni[i], + link.link_status); + log_link_state(p[portid]->kni[i], prev, &link); + } + } + } + return NULL; +} + /* Callback for request of changing MTU */ static int kni_change_mtu(uint16_t port_id, unsigned int new_mtu) @@ -893,6 +948,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); @@ -949,12 +1006,21 @@ main(int argc, char** argv) } check_all_ports_link_status(ports_mask); + ret = rte_ctrl_thread_create(&kni_link_tid, + "KNI link status check", NULL, + monitor_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); RTE_LCORE_FOREACH_SLAVE(i) { if (rte_eal_wait_lcore(i) < 0) return -1; } + monitor_links = 0; + pthread_join(kni_link_tid, &retval); /* Release resources */ RTE_ETH_FOREACH_DEV(port) { From patchwork Wed Oct 17 01:04:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Gora X-Patchwork-Id: 46927 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 88AAC5B38; Wed, 17 Oct 2018 03:04:53 +0200 (CEST) Received: from mail-qk1-f177.google.com (mail-qk1-f177.google.com [209.85.222.177]) by dpdk.org (Postfix) with ESMTP id 1E6EA58EC for ; Wed, 17 Oct 2018 03:04:50 +0200 (CEST) Received: by mail-qk1-f177.google.com with SMTP id 204-v6so15432836qkd.5 for ; Tue, 16 Oct 2018 18:04:50 -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=tO8aIB+Hw72z5n3ko5IxaglmkWXugqm628TkFFBTpDs=; b=Dsa0qBT4RMNS1Pu4OeF2W7qTQol5M686dFIy15DBx+Xg/3UE5QQ+WT3cC6AnqTWtab 4YiWi2uBzCu4UJfr9eGQzDa9zxxNF2/FjaD27MxbILlmkGITtPRt12hUlfyIxelVXDjs EbcfbJSvIqpdGYF6gJc9CUqvH2mNRhbGzTiqDTB5aBN5VKS2atDgu5xhMY5oGy3CQta/ lmyfl9qn3QooV+JcVFbPjljsYzoW3iZyzl2MWLwTVzlOv20p8UBxCXddKz1I2fEhYCPH HKWbwq1kcv7gzlZ9N5Ct0ku/MJKKglsig5I5QVhQvt/TpjhPSTEtSkzz+B5DAdlP2fl6 1/Dw== 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=tO8aIB+Hw72z5n3ko5IxaglmkWXugqm628TkFFBTpDs=; b=mfyBSInFWjWUsQeYxneSR3U0paLKMr1Dw2zq8n8+3O6zZyQSnt/VkyKvGMi2CTDxCm oyyi7ZyxMh2eo6joklefTASDp9xIaOXUiPRyjBdSqFOr/TaAD9z3powGa4/VwxADvrnb SKp5RquxkgIzZa3B8mGhN+y1Ke42EepEZnwfR7SM+8oG2JBgJtpdgbzIgUtvGRVJS46U PDASYNyykIB8hUGW7PNGTzfumALgRxVs2+jKQlHX/DjaT0L7LfAxZWX+OOaJMMx7wQIn PsVoK85rDXP0GB2Mkpnt9//j9UETM6ngPjRHNY/9TKGActshKBYIJyEsHxKTGoo4lf8b 1UNg== X-Gm-Message-State: ABuFfoiAMRcQdD1crwOt1vBTYkXOkma2rnIf7LVDGMyCW7l5SYTuYaw4 jzECRb6lHbEJ/nuvJWjZ8Zen+BYliPc= X-Google-Smtp-Source: ACcGV60WfrRPVjs57D6g/J9d8Wuqcft5yaNg0FysuqWG4b9faaC4bcvVNHjKpgFr/8nl1S/D3NJBiw== X-Received: by 2002:a37:72c1:: with SMTP id n184-v6mr22854092qkc.133.1539738289173; Tue, 16 Oct 2018 18:04:49 -0700 (PDT) Received: from snappy.local.lan ([187.74.142.5]) by smtp.gmail.com with ESMTPSA id v54-v6sm19547508qtc.81.2018.10.16.18.04.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 16 Oct 2018 18:04:48 -0700 (PDT) From: Dan Gora To: dev@dpdk.org Cc: Igor Ryzhov , Stephen Hemminger , Ferruh Yigit , Dan Gora Date: Tue, 16 Oct 2018 22:04:12 -0300 Message-Id: <20181017010412.23141-6-dg@adax.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180911232906.18352-1-dg@adax.com> References: <20180911232906.18352-1-dg@adax.com> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v4 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 634024960..314e19c68 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; } @@ -950,6 +949,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); @@ -1006,6 +1006,16 @@ main(int argc, char** argv) } check_all_ports_link_status(ports_mask); + 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); + ret = rte_ctrl_thread_create(&kni_link_tid, "KNI link status check", NULL, monitor_all_ports_link_status, NULL); From patchwork Wed Oct 17 01:04:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Gora X-Patchwork-Id: 46928 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 E19785B36; Wed, 17 Oct 2018 03:04:57 +0200 (CEST) Received: from mail-qk1-f196.google.com (mail-qk1-f196.google.com [209.85.222.196]) by dpdk.org (Postfix) with ESMTP id D2C175B12 for ; Wed, 17 Oct 2018 03:04:52 +0200 (CEST) Received: by mail-qk1-f196.google.com with SMTP id 84-v6so15464382qkf.0 for ; Tue, 16 Oct 2018 18:04:52 -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=hJm2Nz7jWrFJUyXegi5KeKO7sLlN5Uz928Q+fW2s80k=; b=E9MFnC5yAJoLkVipzMVUF82P5VsPiOFz4KHQq+eLv6eVMV021ZahTDZfTpOYs5QMr2 5io2dYWc6nXxnBH/CtApLicHFy1sZdofc2LoDlR7toLAtXipbApVhV1kG9uqnG9kI8+P HlNbdG7658gw4DKdulJA+qCuxvTj7vyur6rKTx98GCJdldDVQ3z27DzaAwmRqe78KuXb X3qbJQhF1fAtDqetRun9nju1nnm+4RkDz6axQHflUqTaCKweZdmK5t8eQMV+RHRQ3Shs hztjzY7ryPgGgG6V4oz/35wtyBXKw1lFJOlRc3CquRBYKN1ICcgOKHTzq2rpid4Iuaaa 2AvA== 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=hJm2Nz7jWrFJUyXegi5KeKO7sLlN5Uz928Q+fW2s80k=; b=INzfkKAPsZECptQceoS741yKfp9FVmDGUyV/k5BZNBdNhBhCQiIdMEl+I2L1BtPgPt v+BGY/OPCnZ1udgRG+S1snE+4Vx3/m54sKYQTyBSO+dsTSihnbwpbNuvHSDynp+jIuFh GJOf6zpMdCaGzFzSNRWgAD+VLgGWERNhK7N+DIWbFkTomShEmNYsbIql3Lt/lCeFvScO y+SC33W270wpPzS+MMlp6O5aWfBAC+qEdcAB/nidRu8hzn9P4aXAT94DDb4fqVtxOleO pAQSHMEOu/+U62+FDtKTHXwBVDMOKp4bdzQeo3KnTDjsSzZ4F381g3H0IWktwhaYQj0I kYTg== X-Gm-Message-State: ABuFfojNS6p31IeSJ4nviouT8WaEMLsADvJuxZsFqnyTaamckeqgRAfo T1z/dJVkwUWmhMN6nnj69Jw4C9Wd5+4= X-Google-Smtp-Source: ACcGV61vDquaGJXIXgw5hJnxNVcJzSdsPd1DQ37A7smWLjS7vEbzqbEz4RmLa1KvmhLPR/oHEAZSIg== X-Received: by 2002:a37:634e:: with SMTP id x75-v6mr4041099qkb.122.1539738291885; Tue, 16 Oct 2018 18:04:51 -0700 (PDT) Received: from snappy.local.lan ([187.74.142.5]) by smtp.gmail.com with ESMTPSA id v54-v6sm19547508qtc.81.2018.10.16.18.04.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 16 Oct 2018 18:04:51 -0700 (PDT) From: Dan Gora To: dev@dpdk.org Cc: Igor Ryzhov , Stephen Hemminger , Ferruh Yigit , Dan Gora Date: Tue, 16 Oct 2018 22:04:13 -0300 Message-Id: <20181017010412.23141-7-dg@adax.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180911232906.18352-1-dg@adax.com> References: <20180911232906.18352-1-dg@adax.com> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v4 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 314e19c68..3ae4c13a2 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);