From patchwork Wed Sep 19 19:55:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Gora X-Patchwork-Id: 44975 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 9F5D51B128; Wed, 19 Sep 2018 21:56:21 +0200 (CEST) Received: from mail-qt0-f193.google.com (mail-qt0-f193.google.com [209.85.216.193]) by dpdk.org (Postfix) with ESMTP id 6F0D11B126 for ; Wed, 19 Sep 2018 21:56:20 +0200 (CEST) Received: by mail-qt0-f193.google.com with SMTP id l42-v6so6285954qtf.13 for ; Wed, 19 Sep 2018 12:56:20 -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=Nz/UmoQLVRgRqvHKfUeCvxAYUgThgWKOV7tL6gEQha0=; b=XzskoyeigMPc/wghr+5Eh2eAbW4mvc3tJHl3lyrnh9iuhEwcsC6BLQjDahTydLf+7g pmwVywxlInZ4TE7Lrl/uP0tCrnSwZ3BrNkHJhMKXsE8PXxYioYcZzs0VdX4q3F3YVWSX xpbWsV2T85J1JsJb/rPiSH/kdyRg5YOcATP2Uevq0lA7UqOx8ebw06yFb/kf1yYeChfm 7IXSjVNtuNTLCVfRh9xwr5AmUwY7vcwDR3ow3c6WGPhMx8l3OOgAq9mFhiSauAu3mse1 c+cphdNdsPM8kPB7eEqPlP8WHY9zj3pfyqzwHWtX4CcvrXpKirMKkrWZdHIU8X1QqOcE Zwsg== 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=Nz/UmoQLVRgRqvHKfUeCvxAYUgThgWKOV7tL6gEQha0=; b=AVvdM6hQJTLtX2LNoJG8kty6GCWBauyLUlH0CGF/FexjBuIjTCc4x3GpqLjywZ+Qna yZqEKyQr3st/SGZ4IcPyiQ8tbDebS9Xz5vo19c263mbf7sB1F2xnDvh4Zgfs6te7NBaX osq3UsvBH1YHDH/09wd18xwQe55a0Pa7TR5qCFrNo9SnfeojZbpsnOiusA+x/i1Hoe8G jlpRbpsEgeUuRSXP4f+M3M/prHkVr64thF2sGHoYp2ENQmMSh9Uv9xYEa4gWrKAB/7UV 13oPYS2VLFsH5ZyOQYo5tLTOkAd4pmCVi/Loi4cRxMz+cW6I8rhbexQGXfK2bEiaEiMo ri6A== X-Gm-Message-State: APzg51Dp9jxMSMfn1f1ixE36ZyIzxYm1NPQjVnMg5K2fNZ2+EKWa7/Sr muYRbzNmFs7pw1YPSlGQchmBUanl X-Google-Smtp-Source: ANB0VdbWlgCbCh+jJZ6jl8Qs3bk594hIM42/tn5gp3In7a00t7hKccSyq3ROFIpAbxxny/giXnP8fQ== X-Received: by 2002:a0c:80a8:: with SMTP id 37-v6mr25651473qvb.13.1537386979348; Wed, 19 Sep 2018 12:56:19 -0700 (PDT) Received: from snappy.local.lan ([187.10.145.241]) by smtp.gmail.com with ESMTPSA id g184-v6sm12431369qkb.15.2018.09.19.12.56.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 19 Sep 2018 12:56:18 -0700 (PDT) From: Dan Gora To: dev@dpdk.org Cc: Igor Ryzhov , Stephen Hemminger , Dan Gora , Ferruh Yigit Date: Wed, 19 Sep 2018 16:55:45 -0300 Message-Id: <20180919195549.5585-2-dg@adax.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180919195549.5585-1-dg@adax.com> References: <20180911232906.18352-1-dg@adax.com> <20180919195549.5585-1-dg@adax.com> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v2 1/5] 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 ++ test/test/test_kni.c | 100 ++++++++++++++++++++++++++++- 4 files changed, 180 insertions(+), 1 deletion(-) 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; +}; diff --git a/test/test/test_kni.c b/test/test/test_kni.c index 3dcadcebd..d450cc342 100644 --- a/test/test/test_kni.c +++ b/test/test/test_kni.c @@ -118,6 +118,97 @@ kni_change_mtu(uint16_t port_id, unsigned int new_mtu) port_id, kni_pkt_mtu); return 0; } + +static int +kni_change_link(void) +{ + struct rte_eth_link link; + int ret; + + 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); + return -1; + } + 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); + return -1; + } + 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); + return -1; + } + 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); + return -1; + } + 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); + return -1; + } + 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); + return -1; + } + 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); + return -1; + } + rte_delay_ms(1000); + + return 0; +} + /** * This loop fully tests the basic functions of KNI. e.g. transmitting, * receiving to, from kernel space, and kernel requests. @@ -148,9 +239,16 @@ test_kni_loop(__rte_unused void *arg) ret = -1; if (system(IFCONFIG TEST_KNI_PORT" mtu 1400") == -1) ret = -1; + + ret = kni_change_link(); + if (ret != 0) { + test_kni_processing_flag = 1; + return ret; + } + rte_delay_ms(KNI_TIMEOUT_MS); if (system(IFCONFIG TEST_KNI_PORT" down") == -1) ret = -1; - rte_delay_ms(KNI_TIMEOUT_MS); + rte_delay_ms(1000); test_kni_processing_flag = 1; } else if (lcore_id == lcore_ingress) { struct rte_mempool *mp = test_kni_lookup_mempool(); From patchwork Wed Sep 19 19:55:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Gora X-Patchwork-Id: 44976 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 9D2651B12E; Wed, 19 Sep 2018 21:56:24 +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 1B2FF1B12C for ; Wed, 19 Sep 2018 21:56:23 +0200 (CEST) Received: by mail-qt0-f196.google.com with SMTP id j7-v6so6337564qtp.2 for ; Wed, 19 Sep 2018 12:56:23 -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=oxilflxMgAVO+MlDkzBPxA1lbAk9vUIhRj5RVOh2Unggc0Zu01vMtvU6D/NPrnYrlH CC5NtmBzy0kebirm3BolqLBnCmIswdxWH2VCQMTrXSRgGzFDEb5vQgABwlG4vh0kfLqp kSBUo6dYyZNalRIWg2usjNPABRV+eL0S/aIUQL3UpUrU5aZJmoBaY7pQTF8vWEKGLqwU ZWSGGh2rWJtwcczHFkdGOLCRq0Z6NMnDHG77NHgPfhirTsUML9nA3QVCHGLxnBhhPkA+ 1Oz2VXtwcRWddzb79q8oQRvuLEmmQUmCpIvTpGnL83jGGskALKDYtMDUqkwkTHAhR3I7 T/uw== 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=gv8XE3zFmM32yT20C+tcIUcXyKXIjIoZx/6kD8kO+AZOM7s0xsDHHZcC1sA055piM2 CaugbShMZ2471TdWgv4yPJyPlPm3IoTZ1anADM/QLyXyRokcnRmUf28P5sYYhjCwhucn 9uudFYFtrFVeEMUIFZ05f90CzQ6yS7IT6C+G+oZqoWJWflQe8Ap3h+U+UALTEyEYo+s4 OEgKwfJc5YTJd0A+ai1f5oI10mdIus87kiU0uJGOCxxmtNEB3IC8nm9XrUQ94VqhprBO Gt1bXuwqPPlRn0xcCL5b8/15fMFhbk5DMj7EtTEcKQEGXUCMOCv4uhFD/KVwmv3HJ3SO xRaA== X-Gm-Message-State: APzg51CcF5Q7FW7iRFPVhups3NZCOxO28uS5K+uhkOvLJ3UD+V1KJ89b x9eGqDpLyJHWRqhKVFcjTYXVV5QB X-Google-Smtp-Source: ANB0VdYlTC9zAwbG6JzHKecb1SShNB+amd17QACrCI1dHpyGvtvyLV+lQdUZRh+I7OzaRYf4ltPHqw== X-Received: by 2002:aed:3584:: with SMTP id c4-v6mr25403664qte.155.1537386982203; Wed, 19 Sep 2018 12:56:22 -0700 (PDT) Received: from snappy.local.lan ([187.10.145.241]) by smtp.gmail.com with ESMTPSA id g184-v6sm12431369qkb.15.2018.09.19.12.56.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 19 Sep 2018 12:56:21 -0700 (PDT) From: Dan Gora To: dev@dpdk.org Cc: Igor Ryzhov , Stephen Hemminger , Dan Gora , Ferruh Yigit Date: Wed, 19 Sep 2018 16:55:46 -0300 Message-Id: <20180919195549.5585-3-dg@adax.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180919195549.5585-1-dg@adax.com> References: <20180911232906.18352-1-dg@adax.com> <20180919195549.5585-1-dg@adax.com> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v2 2/5] 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 Acked-by: Ferruh Yigit --- 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 Sep 19 19:55:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Gora X-Patchwork-Id: 44977 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 3ED7F1B136; Wed, 19 Sep 2018 21:56:27 +0200 (CEST) Received: from mail-qt0-f194.google.com (mail-qt0-f194.google.com [209.85.216.194]) by dpdk.org (Postfix) with ESMTP id 222841B133 for ; Wed, 19 Sep 2018 21:56:26 +0200 (CEST) Received: by mail-qt0-f194.google.com with SMTP id l42-v6so6286236qtf.13 for ; Wed, 19 Sep 2018 12:56:26 -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=Q8m/h6wgMrJg98G+yF7Q37xFrUbI8QZydatcW7/BTNs=; b=rk/rm33JlZTp/fwvmM7hXJ3p+wgyjq95Y/guLZv8nty7533tAuH03RISdyeRTMo8Zp 6ZbeNjL95fRyAIaemdwJsV0Bk6/bH+l1tpVbLE/M7pQTm/hkrXamKO2KrcRuKOcFh2C1 ItZMR4S/61GNQzyd0XX6zAGOe/FlFk0qzBmnZuZ2lnYoks5tLuRnQ/tMd+qOHVHOlyBa ciKFEj2ZUXB2VO8swFQ3HLyNZ5dpbWLzmoMx2yeaeeD20b5TiHaC+SxdioNPEZpPpP88 SQJjhZcCNRDtiYKz8esfp9/HncC7XJ0hHgrZvSncxfwq1iy8j0Zjg5vBMqLB5ubSncn3 BXgQ== 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=Q8m/h6wgMrJg98G+yF7Q37xFrUbI8QZydatcW7/BTNs=; b=p1bujB6lwsAHzIkWer3H5BQUmA+sVWpsr3J4pK/fDCCLXEeF0dfkjG7uFL+f8FRAZ4 f92XnTlpToqbkfiPMu7HLMJTaLeEo7jJg+FyiwcfhBmwmKBqweSMohsDruDCpUaseJOE yVxB2A5luHQSWhfIEVxlf44EkOAKT3ErxEqh1AxBISu8uBbiXnl8I+VLKeMToxCEBdBl m9VQ5rwPGCDjBQtH4hhVkM1VTWkWZzETIzWUC/mhis9QMrxvdnsmMpOlemWQ4+FaiSYz OtSXzpA4fqSIKCb1Xm+gOROqXbm4Ue6hPARy81IBLnp6PC558fcwyKqgqQ5xMlXQ9ofW 0rlw== X-Gm-Message-State: APzg51A2eTyAI+kDJ+szVCp1tkA3AjvdLxfYqlFLJ3/vVAVR0QS0Vs0v 8jKPltqrhhQ9Oeik9KydzyZM78lm X-Google-Smtp-Source: ANB0Vdb0oZ96UV5eFJuWuATJ/Kb1cMSG6b2P/C1b7I1KOywp66WdAJEZhpmfWvnC73FxBU6bINepoQ== X-Received: by 2002:ac8:29ef:: with SMTP id 44-v6mr24961810qtt.174.1537386985156; Wed, 19 Sep 2018 12:56:25 -0700 (PDT) Received: from snappy.local.lan ([187.10.145.241]) by smtp.gmail.com with ESMTPSA id g184-v6sm12431369qkb.15.2018.09.19.12.56.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 19 Sep 2018 12:56:24 -0700 (PDT) From: Dan Gora To: dev@dpdk.org Cc: Igor Ryzhov , Stephen Hemminger , Dan Gora , Ferruh Yigit Date: Wed, 19 Sep 2018 16:55:47 -0300 Message-Id: <20180919195549.5585-4-dg@adax.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180919195549.5585-1-dg@adax.com> References: <20180911232906.18352-1-dg@adax.com> <20180919195549.5585-1-dg@adax.com> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v2 3/5] 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 carrier status of the corresponding interfaces with rte_kni_update_link(). Signed-off-by: Dan Gora --- examples/kni/Makefile | 2 ++ examples/kni/main.c | 82 +++++++++++++++++++++---------------------- 2 files changed, 43 insertions(+), 41 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..8c3d3839e 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 */ @@ -620,58 +622,45 @@ init_port(uint16_t 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) +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; + const char *name; + char cmd[64]; + unsigned int i; + struct kni_port_params **p = kni_port_params_array; + (void) arg; + + RTE_ETH_FOREACH_DEV(portid) { + for (i = 0; i < p[portid]->nb_kni; i++) { + name = rte_kni_get_name(p[portid]->kni[i]); + snprintf(cmd, sizeof(cmd), + "/sbin/ifconfig %s up", name); + RTE_LOG(INFO, APP, + "Marking interface %s 'up'\n", name); + if (system(cmd) == -1) + RTE_LOG(ERR, APP, + "Error: Failed to mark interface %s 'up'\n", + name); + } + } - 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(CHECK_INTERVAL); 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 +882,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 +938,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 +953,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 Wed Sep 19 19:55:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Gora X-Patchwork-Id: 44978 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 AC7D11B141; Wed, 19 Sep 2018 21:56:30 +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 045881B13A for ; Wed, 19 Sep 2018 21:56:28 +0200 (CEST) Received: by mail-qk1-f180.google.com with SMTP id p84-v6so3488460qke.1 for ; Wed, 19 Sep 2018 12:56:28 -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=o4LEoCMqpS+UIuv/HnSs3xUK1rsvdh8y7P5SRBN1XTs=; b=oKUF3QjsJslNXXlT4UeR2+lVA7AsF95x+B2EtnCC2kaTcq59OiN5PUgB/KCBP12Jbk 71K6a74IGPUWICFsr/yxQcQhk2IfnnAJ4etwtdxsfQeGfymP8W4Vs101kMoKEvhLNKJP i91sG6As/PAXYJ7y7JiL17JWPLOYWlTMySgVBUVLHCP0Eb+Lx79sIKv/yh1wiNfOvn1t XOiMR3MwbmhHM9CseLsGzMn5EQEyCpDSEFI5N9WFwmGqViw5+VkEycTYPjcudzkDHs3c Sy0f0loy3YoOH1G9DhC+GtV77PkX45u1E9nhR3SjFGtp+1qNk7lewVdkTKR/t4Kc9vTM qotw== 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=o4LEoCMqpS+UIuv/HnSs3xUK1rsvdh8y7P5SRBN1XTs=; b=Z4hsZTFJ8xMYVMYaLZoYw/+VadRaeBKfM2OJFBQqgKyfAV4RsyIIMbdK0pqtNvgHV5 VSLNZO+c4uUbTEkoQl3FwdNLKHJkX549X5DSRAf5KEc+8k6L86kJb3MIAnm/1tVqvnJy 073QjLxU75Zm1NocioxsI0QhnL5ZAr0CUKQSfFU/9Y7hZ6JjdQIHqOiTbV3DijgXFdYM zcrSGQ66G7ulhlGkcYetLhm+NOttKxejQDYMci3bhT3Q4XBjg25Z93Dp/wtQCRCgoq/U pUXYi1Rb/iBhPM1N3cQjFqwfG01EHPUbtIiadZ/6RyTzFtCDI03M27MmAvEUEqWIYvas mZuA== X-Gm-Message-State: APzg51B33EcBVCKsRstC/uH5x7CJ2YyMulFd7+p6wCud4F0O+HwKSkdR YjuUzcuU4gIEsDpt2fdLxP0VBDQR X-Google-Smtp-Source: ANB0VdaNyHCim4prfmt/ovmOwTAUzZzSmnI24E7zJh7PZhsccd3MZVT5bef70zTfoPgifLT957TZ/w== X-Received: by 2002:a37:72c4:: with SMTP id n187-v6mr18309242qkc.103.1537386987872; Wed, 19 Sep 2018 12:56:27 -0700 (PDT) Received: from snappy.local.lan ([187.10.145.241]) by smtp.gmail.com with ESMTPSA id g184-v6sm12431369qkb.15.2018.09.19.12.56.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 19 Sep 2018 12:56:27 -0700 (PDT) From: Dan Gora To: dev@dpdk.org Cc: Igor Ryzhov , Stephen Hemminger , Dan Gora , Ferruh Yigit Date: Wed, 19 Sep 2018 16:55:48 -0300 Message-Id: <20180919195549.5585-5-dg@adax.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180919195549.5585-1-dg@adax.com> References: <20180911232906.18352-1-dg@adax.com> <20180919195549.5585-1-dg@adax.com> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v2 4/5] 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 Acked-by: Ferruh Yigit --- 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 8c3d3839e..ca45347d8 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; } @@ -884,6 +883,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); @@ -939,6 +939,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 Wed Sep 19 19:55:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Gora X-Patchwork-Id: 44979 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 F18151B144; Wed, 19 Sep 2018 21:56:33 +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 997DB1B139 for ; Wed, 19 Sep 2018 21:56:31 +0200 (CEST) Received: by mail-qt0-f196.google.com with SMTP id t39-v6so6303989qtc.8 for ; Wed, 19 Sep 2018 12:56:31 -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=tB/2EJyp2DqxuqeCx3cu4cWQhnJqCkB6QueQXqBozcE=; b=s8emZmjBni2LSi65F5mKvq5dmtu1pav/SwIgzKL3JFfesHe7Jnpy2UZsH0Dz1Qsz2B k8ETnpVIxL6oibeKexpXs94cAfyV9nxe7DyXWGT/PgPItfJqowX1/0VkVa2CxnBYYQD0 GYTwELoXX05D2nutDCvG2GofuaJlhPtc9om4xWj44dVFDMXqROCHv03MSInyYhLfU18W GsImeDn7PlBg4QQJVNfsy7rQ8uOE18t1+jMrv2IZyfGeUOejOfvF8tjJas9ZSAz/NTdD 1P2wfBxHevWR5VMr0cstpawVGWx4SXVvN65QIkFhCkIPXaxraevT7F608qqT5dcFU399 Z2eQ== 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=tB/2EJyp2DqxuqeCx3cu4cWQhnJqCkB6QueQXqBozcE=; b=BaJCTYmV/QQyQi3tW9E0UkNuIJqD+sP+jKl7acYeAEcp8YDcWbI25+RbstIp8Hr4zn bEO49xfMsT60aVzGlPQQvT6ojy0pUnJpKPgQlp6LwsDFMcs9ktEzmR6soze7pESbOlvh 7PTWUHcPfiWLOZZStk5ywiGCKfikOmikXp3OtXkQDyzk3DgW9BBXtdL5G+knUk2ju3De o1CKENTMFHDLWzEFuaE2JAyNzUUm2xk40oL0txBXOoVeTh/qy0NhiEAkJG+96fSn1AuI AtALXDa89ilN1+2kNpBSCf06TKoGjuXOq0R6mLGZm/LiBHz4ZoWrdbQAXsclK4aaylqM jhlg== X-Gm-Message-State: APzg51DjDjdcLXxgjSZYlFEB2QmTq+FGtZqs5v0P+il08EVdbfrxygtm cgvp7T8S7QMNi6sG0tOAmk6KeBMR X-Google-Smtp-Source: ANB0VdafN/pn3aKuIRFqE82uRIPlIUIrTcou844tpOhITIUFjrzZX7503HMuczi245SctV0MfwNUBQ== X-Received: by 2002:ac8:376c:: with SMTP id p41-v6mr25652136qtb.225.1537386990679; Wed, 19 Sep 2018 12:56:30 -0700 (PDT) Received: from snappy.local.lan ([187.10.145.241]) by smtp.gmail.com with ESMTPSA id g184-v6sm12431369qkb.15.2018.09.19.12.56.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 19 Sep 2018 12:56:29 -0700 (PDT) From: Dan Gora To: dev@dpdk.org Cc: Igor Ryzhov , Stephen Hemminger , Dan Gora , Ferruh Yigit Date: Wed, 19 Sep 2018 16:55:49 -0300 Message-Id: <20180919195549.5585-6-dg@adax.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180919195549.5585-1-dg@adax.com> References: <20180911232906.18352-1-dg@adax.com> <20180919195549.5585-1-dg@adax.com> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v2 5/5] 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 ca45347d8..d00569740 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);