From patchwork Fri Aug 2 02:58:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 57376 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 9C4751C203; Fri, 2 Aug 2019 04:58:33 +0200 (CEST) Received: from mail-pg1-f196.google.com (mail-pg1-f196.google.com [209.85.215.196]) by dpdk.org (Postfix) with ESMTP id AF7A61C1F1 for ; Fri, 2 Aug 2019 04:58:30 +0200 (CEST) Received: by mail-pg1-f196.google.com with SMTP id f5so26463451pgu.5 for ; Thu, 01 Aug 2019 19:58:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zc5wLVYzGdBzMnqa1CvBFKrqffPTJWatPwgXmOWAuj4=; b=zL6Quq7+CyS1AGwVYUCnS6LOjTsCa0FwNcoe1p34uKrMYfGxDCjDYWhznK9gbVucDW rOA7Z97fxtWX6UPiHxRXzgUXQClwKn7+wkdyraFKt+3YE+9XtbiUtbe0x0xqkXz/vqdo RDtVD2p9roFBqnLJZuBKGx/mGFHPKN8ZE6s1LN8B+GBiFrZOEBF1zffDNLCkXoW9I0EU NJK5on+/VuyCReJ85DOOzOM2/Ots4qiIP72l04vowfgM76WGIluNGiXTeQvihe1zl/Sx uvI0Ytjhbn+zDce71FjV77akgz4jYLQaBPcniKTvl7pYg/WFHZVevkhWGIK7Y/DfJnIa wiRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zc5wLVYzGdBzMnqa1CvBFKrqffPTJWatPwgXmOWAuj4=; b=BXzhWh/9skUmvJE1frsoyUslxXIXeLQ//EV2RMbkJXy1ArdKMCSm1L2Z3G1RGL/YRz qAFwxBpuVggQkgrmfrbpIsbg8ud3yH8oEF7K45wg7dDw+TxSYGTr/c++nIDOzwYyjUkN wfDuJCGtboctRMV5aSY+AyRUEIumHuaaz3MoID5OpAEsvT7Jiy5oByOPnnwykQPHtb1j GbV6eNcTxYbXg2j4MfIi+YKpnUOeKEePPn2FhwPgGgwh7U8WZWiLVSwBz0ncnji/I3BE P8vf8+4JhZZM6UsoXVn/lTwRrvC2pOh9KyP3TcWuVv9FF71ndmZiifI82y0xHY04lP/C H68Q== X-Gm-Message-State: APjAAAXPTZe8tlZGDL8M4Teu8oxWY+J7EeCLWBDEPJP577pm6BOtmtwP wlqhxOxbuudI8gd5nU0PXaTDnOM6 X-Google-Smtp-Source: APXvYqzdvvvOR5Prqc6TblvlYVFc9WxltU5/EShM+daoh51zGz7lLYQ+db+d7sWFupvL+3lYAwA8Dg== X-Received: by 2002:a17:90a:9bc5:: with SMTP id b5mr1993643pjw.109.1564714709545; Thu, 01 Aug 2019 19:58:29 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id a20sm5788738pjo.0.2019.08.01.19.58.28 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 01 Aug 2019 19:58:28 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Thu, 1 Aug 2019 19:58:23 -0700 Message-Id: <20190802025826.1174-2-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190802025826.1174-1-stephen@networkplumber.org> References: <20190726165054.24078-1-stephen@networkplumber.org> <20190802025826.1174-1-stephen@networkplumber.org> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v5 1/4] examples/multi_process/client_server_mp: check port validity 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" From: Stephen Hemminger The mp_server incorrectly allows a port mask that included hidden ports and which later caused either lost packets or failed initialization. This fixes explicitly checking that each bit in portmask is a valid port before using it. Fixes: 5b7ba31148a8 ("ethdev: add port ownership") Signed-off-by: Stephen Hemminger --- .../client_server_mp/mp_server/args.c | 35 ++++++++++--------- .../client_server_mp/mp_server/args.h | 2 +- .../client_server_mp/mp_server/init.c | 7 ++-- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/examples/multi_process/client_server_mp/mp_server/args.c b/examples/multi_process/client_server_mp/mp_server/args.c index b0d8d7665c85..fdc008b3d677 100644 --- a/examples/multi_process/client_server_mp/mp_server/args.c +++ b/examples/multi_process/client_server_mp/mp_server/args.c @@ -10,6 +10,7 @@ #include #include +#include #include #include "common.h" @@ -41,31 +42,33 @@ usage(void) * array variable */ static int -parse_portmask(uint8_t max_ports, const char *portmask) +parse_portmask(const char *portmask) { char *end = NULL; unsigned long pm; - uint16_t count = 0; + uint16_t id; if (portmask == NULL || *portmask == '\0') return -1; /* convert parameter to a number and verify */ pm = strtoul(portmask, &end, 16); - if (end == NULL || *end != '\0' || pm == 0) + if (end == NULL || *end != '\0' || pm > UINT16_MAX || pm == 0) return -1; - /* loop through bits of the mask and mark ports */ - while (pm != 0){ - if (pm & 0x01){ /* bit is set in mask, use port */ - if (count >= max_ports) - printf("WARNING: requested port %u not present" - " - ignoring\n", (unsigned)count); - else - ports->id[ports->num_ports++] = count; - } - pm = (pm >> 1); - count++; + RTE_ETH_FOREACH_DEV(id) { + unsigned long msk = 1u << id; + + if ((pm & msk) == 0) + continue; + + pm &= ~msk; + ports->id[ports->num_ports++] = id; + } + + if (pm != 0) { + printf("WARNING: leftover ports in mask %#lx - ignoring\n", + pm); } return 0; @@ -99,7 +102,7 @@ parse_num_clients(const char *clients) * on error. */ int -parse_app_args(uint16_t max_ports, int argc, char *argv[]) +parse_app_args(int argc, char *argv[]) { int option_index, opt; char **argvopt = argv; @@ -112,7 +115,7 @@ parse_app_args(uint16_t max_ports, int argc, char *argv[]) &option_index)) != EOF){ switch (opt){ case 'p': - if (parse_portmask(max_ports, optarg) != 0){ + if (parse_portmask(optarg) != 0) { usage(); return -1; } diff --git a/examples/multi_process/client_server_mp/mp_server/args.h b/examples/multi_process/client_server_mp/mp_server/args.h index 79c190a33a37..52c8cc86e6f0 100644 --- a/examples/multi_process/client_server_mp/mp_server/args.h +++ b/examples/multi_process/client_server_mp/mp_server/args.h @@ -5,6 +5,6 @@ #ifndef _ARGS_H_ #define _ARGS_H_ -int parse_app_args(uint16_t max_ports, int argc, char *argv[]); +int parse_app_args(int argc, char *argv[]); #endif /* ifndef _ARGS_H_ */ diff --git a/examples/multi_process/client_server_mp/mp_server/init.c b/examples/multi_process/client_server_mp/mp_server/init.c index 3af5dc6994bf..1b0569937b51 100644 --- a/examples/multi_process/client_server_mp/mp_server/init.c +++ b/examples/multi_process/client_server_mp/mp_server/init.c @@ -238,7 +238,7 @@ init(int argc, char *argv[]) { int retval; const struct rte_memzone *mz; - uint16_t i, total_ports; + uint16_t i; /* init EAL, parsing EAL args */ retval = rte_eal_init(argc, argv); @@ -247,9 +247,6 @@ init(int argc, char *argv[]) argc -= retval; argv += retval; - /* get total number of ports */ - total_ports = rte_eth_dev_count_total(); - /* set up array for port data */ mz = rte_memzone_reserve(MZ_PORT_INFO, sizeof(*ports), rte_socket_id(), NO_FLAGS); @@ -259,7 +256,7 @@ init(int argc, char *argv[]) ports = mz->addr; /* parse additional, application arguments */ - retval = parse_app_args(total_ports, argc, argv); + retval = parse_app_args(argc, argv); if (retval != 0) return -1; From patchwork Fri Aug 2 02:58:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 57377 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 26EE81C211; Fri, 2 Aug 2019 04:58:36 +0200 (CEST) Received: from mail-pf1-f195.google.com (mail-pf1-f195.google.com [209.85.210.195]) by dpdk.org (Postfix) with ESMTP id 1FB0B1C200 for ; Fri, 2 Aug 2019 04:58:32 +0200 (CEST) Received: by mail-pf1-f195.google.com with SMTP id q10so35189118pff.9 for ; Thu, 01 Aug 2019 19:58:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8v7OSOzARnVHBELM/KAu2BccRvpC7XvWrmT3Mxp8KjI=; b=lRD/1cKG90stvWMjNP7XOcA3QfA52V30HzlhbXI7h8c3t8Hc+ZGxygzpCnTpIX3gu7 fgd+B/Qxei4KktqRCyvI1lAhK29xyX//RDO/MHt5bTcN9YBZbVNbYInrgLlooM3sKZ7R iXSSR/vnjKZo22bnLxAZjlqcF0unD5ITpBSjxwTivj2oxHO46XsLS+cZwa3kQts+FMyq Cz5Itvf5o1ekvK2gFdn8ll41KJDpI7qJi5T0iI82kJOccCJMXGlopq9ikfHpyhf/8Eff nqHJN4C2dc8W31Q7oZAHjHoR5sRsxsAHQBoj8JCJ0cbbYlN6ujc40u3IFnPhMsLAdhX9 /Kdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8v7OSOzARnVHBELM/KAu2BccRvpC7XvWrmT3Mxp8KjI=; b=uWNzbwV0s5U1BxmXp6g0Xhy5S1/Hl9RWROEFtOpm6HzjV6gAtULKKCpA+mCnHokcj+ eml1QyOFlzhjklxeHEk0/X5bLFc3Gd7D3EfKult0sWHbqK/uWAfMIwBldBEBMmFrOMxe s7StHjv/Fv9GN+JVD/kyjm9OUyAzvUqOmsNBpkDqsGIeu/vGg+cPaFC6pG1DXfNH8Qj7 QTkJB05mC+a8j/Sp81sBSdjEKxNAhSBVdzspKt8fzyPz8KIx/ojP9pixVyvWB1IqJ6WB SjbPrYezcbJsMWCdcTk5TUdwz3vSraLJ47hlEc+u8vywbExnM4gdru3D2GPSJykqfhQ5 fseA== X-Gm-Message-State: APjAAAULfFosN7exIyM0eTevVFRG8fyUrhmAwKFA6tiimAZpk6MrqS5X 8x7L/PEMP83KxDc89mdUIDTiRrbcDLI= X-Google-Smtp-Source: APXvYqwKBSH7s6R2R1fqifrtdbRAwGCGrLooq7xHk9y4bdZ5BFGBmGeU9L6n52DPfZGKjnW7oNwCmg== X-Received: by 2002:a17:90a:d817:: with SMTP id a23mr1979559pjv.54.1564714710773; Thu, 01 Aug 2019 19:58:30 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id a20sm5788738pjo.0.2019.08.01.19.58.29 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 01 Aug 2019 19:58:29 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Thu, 1 Aug 2019 19:58:24 -0700 Message-Id: <20190802025826.1174-3-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190802025826.1174-1-stephen@networkplumber.org> References: <20190726165054.24078-1-stephen@networkplumber.org> <20190802025826.1174-1-stephen@networkplumber.org> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v5 2/4] examples/multi_process/client_server_mp - fix crash in mp_client with sparse ports 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" From: Stephen Hemminger The mp_client crashes if run on Azure or any system where ethdev ports are owned. In that case, the tx_buffer and tx_stats for the real port were initialized correctly, but the wrong port was used. For example if the server has Ports 3 and 5. Then calling rte_eth_tx_buffer_flush on any other buffer will dereference null because the tx buffer for that port was not allocated. Also: - the flush code is common enough that it should not be marked unlikely - combine conditions to reduce indentation - avoid unnecessary if() if sent is zero. Fixes: e2366e74e029 ("examples: use buffered Tx") Signed-off-by: Stephen Hemminger --- .../client_server_mp/mp_client/client.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/examples/multi_process/client_server_mp/mp_client/client.c b/examples/multi_process/client_server_mp/mp_client/client.c index c23dd3f378f7..361d90b54b2d 100644 --- a/examples/multi_process/client_server_mp/mp_client/client.c +++ b/examples/multi_process/client_server_mp/mp_client/client.c @@ -246,19 +246,19 @@ main(int argc, char *argv[]) for (;;) { uint16_t i, rx_pkts; - uint16_t port; rx_pkts = rte_ring_dequeue_burst(rx_ring, pkts, PKT_READ_SIZE, NULL); - if (unlikely(rx_pkts == 0)){ - if (need_flush) - for (port = 0; port < ports->num_ports; port++) { - sent = rte_eth_tx_buffer_flush(ports->id[port], client_id, - tx_buffer[port]); - if (unlikely(sent)) - tx_stats->tx[port] += sent; - } + if (rx_pkts == 0 && need_flush) { + for (i = 0; i < ports->num_ports; i++) { + uint16_t port = ports->id[i]; + + sent = rte_eth_tx_buffer_flush(port, + client_id, + tx_buffer[port]); + tx_stats->tx[port] += sent; + } need_flush = 0; continue; } From patchwork Fri Aug 2 02:58:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 57378 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 479091C220; Fri, 2 Aug 2019 04:58:38 +0200 (CEST) Received: from mail-pf1-f193.google.com (mail-pf1-f193.google.com [209.85.210.193]) by dpdk.org (Postfix) with ESMTP id 8405A1C208 for ; Fri, 2 Aug 2019 04:58:33 +0200 (CEST) Received: by mail-pf1-f193.google.com with SMTP id f17so31212970pfn.6 for ; Thu, 01 Aug 2019 19:58:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=id3prtgZ4g29GHDINT1hbmHslO10slBJO8OwDHigAZ8=; b=dNpLeUO4hm2F3BMi1EUCvJRHP3h8AmlTHKI4npPB/3fhHszzhlnTElJJ5MadNXxQ8a AfjcJIeQyvf1FmXT8b1s3pCS+9x2X9FEzwucNjCKgBGZbPQoh+WreIAITig0TZy4i10x 82i2AahSky+z9DZcMQDo2JbLq61OGPZ5Dz2J8HK1SxCf7tacqLvWLbNVQZlIzO9SXOy/ p4YaO13BG6RH8bvwjV+0M60TfR5K9/L5zOXsdE6wYFEeSKkZ1iYfmbDICVxLeEi2s/b8 x1A1GBdjj+yX9rImPALB4xt5VejzmBZpDgyV3NsF5I/hhWe5oZiM03s7gGt9ugZoX4/v IWwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=id3prtgZ4g29GHDINT1hbmHslO10slBJO8OwDHigAZ8=; b=Lyu9cO8vc9W1JzMUJ13yaGomYtMjdzRmUM5lKnKr4n2LvsqH4Ls64PC0vzvydNAFkK 8W9IU/zrJt83426Gz/po/Rvfu0Fof2cR8JLG53sm/42ZyXA5Mm6up45leh1hnjsmHAfQ 39QaeX0zm3mSSHgStss9f4IlTK03mugh2nEHPaQqJ9MAeXnO6edMavh9puBhdYmKToUQ GGH1Ly1Z3TpOyWEn3XLG4BQeIUNoVQ9pmkB4EXYP97lCDqPLHOtIrxKnndZtMaKPBid7 e4auVcKw7tZv3pRHc+vQ2EDBhYSfAmgBj9M8dFtAas1lU2u6zOnjcyKIYk/og1y+qofT W9kw== X-Gm-Message-State: APjAAAVEhAX3C+dU/iar2GT0dc2wR8fUEUnV8jaQLd1z12YdNgunRDZ0 yzePoA053iTluR3SLAA/E2urzRLE X-Google-Smtp-Source: APXvYqz6cKvR1IDBSky2eYp29iO9pu5IWx3nK68FjBrDrgfYxXXambSZkla2LZT7SfQ5TajUW9Seog== X-Received: by 2002:a17:90a:24ac:: with SMTP id i41mr1994747pje.124.1564714712132; Thu, 01 Aug 2019 19:58:32 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id a20sm5788738pjo.0.2019.08.01.19.58.30 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 01 Aug 2019 19:58:31 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Thu, 1 Aug 2019 19:58:25 -0700 Message-Id: <20190802025826.1174-4-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190802025826.1174-1-stephen@networkplumber.org> References: <20190726165054.24078-1-stephen@networkplumber.org> <20190802025826.1174-1-stephen@networkplumber.org> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v5 3/4] examples/multi_process/client_server_mp/mp_server: fix style 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" Lots of little style complaints from checkpatch. Signed-off-by: Stephen Hemminger --- .../client_server_mp/mp_server/args.c | 37 ++++----- .../client_server_mp/mp_server/init.c | 79 +++++++++++-------- .../client_server_mp/mp_server/main.c | 44 ++++++----- 3 files changed, 88 insertions(+), 72 deletions(-) diff --git a/examples/multi_process/client_server_mp/mp_server/args.c b/examples/multi_process/client_server_mp/mp_server/args.c index fdc008b3d677..91c823856a72 100644 --- a/examples/multi_process/client_server_mp/mp_server/args.c +++ b/examples/multi_process/client_server_mp/mp_server/args.c @@ -112,33 +112,34 @@ parse_app_args(int argc, char *argv[]) progname = argv[0]; while ((opt = getopt_long(argc, argvopt, "n:p:", lgopts, - &option_index)) != EOF){ - switch (opt){ - case 'p': - if (parse_portmask(optarg) != 0) { - usage(); - return -1; - } - break; - case 'n': - if (parse_num_clients(optarg) != 0){ - usage(); - return -1; - } - break; - default: - printf("ERROR: Unknown option '%c'\n", opt); + &option_index)) != EOF) { + + switch (opt) { + case 'p': + if (parse_portmask(optarg) != 0) { + usage(); + return -1; + } + break; + case 'n': + if (parse_num_clients(optarg) != 0) { usage(); return -1; + } + break; + default: + printf("ERROR: Unknown option '%c'\n", opt); + usage(); + return -1; } } - if (ports->num_ports == 0 || num_clients == 0){ + if (ports->num_ports == 0 || num_clients == 0) { usage(); return -1; } - if (ports->num_ports % 2 != 0){ + if (ports->num_ports % 2 != 0) { printf("ERROR: application requires an even number of ports to use\n"); return -1; } diff --git a/examples/multi_process/client_server_mp/mp_server/init.c b/examples/multi_process/client_server_mp/mp_server/init.c index 1b0569937b51..96c35f220a7d 100644 --- a/examples/multi_process/client_server_mp/mp_server/init.c +++ b/examples/multi_process/client_server_mp/mp_server/init.c @@ -49,7 +49,7 @@ struct rte_mempool *pktmbuf_pool; /* array of info/queues for clients */ -struct client *clients = NULL; +struct client *clients; /* the port details */ struct port_info *ports; @@ -72,7 +72,8 @@ init_mbuf_pools(void) num_mbufs_server + num_mbufs_client + num_mbufs_mp_cache; /* don't pass single-producer/single-consumer flags to mbuf create as it - * seems faster to use a cache instead */ + * seems faster to use a cache instead + */ printf("Creating mbuf pool '%s' [%u mbufs] ...\n", PKTMBUF_POOL_NAME, num_mbufs); pktmbuf_pool = rte_pktmbuf_pool_create(PKTMBUF_POOL_NAME, num_mbufs, @@ -108,9 +109,11 @@ init_port(uint16_t port_num) fflush(stdout); /* Standard DPDK port initialisation - config port, then set up - * rx and tx rings */ - if ((retval = rte_eth_dev_configure(port_num, rx_rings, tx_rings, - &port_conf)) != 0) + * rx and tx rings + */ + retval = rte_eth_dev_configure(port_num, rx_rings, tx_rings, + &port_conf); + if (retval != 0) return retval; retval = rte_eth_dev_adjust_nb_rx_tx_desc(port_num, &rx_ring_size, @@ -122,22 +125,25 @@ init_port(uint16_t port_num) retval = rte_eth_rx_queue_setup(port_num, q, rx_ring_size, rte_eth_dev_socket_id(port_num), NULL, pktmbuf_pool); - if (retval < 0) return retval; + if (retval < 0) + return retval; } - for ( q = 0; q < tx_rings; q ++ ) { + for (q = 0; q < tx_rings; q++) { retval = rte_eth_tx_queue_setup(port_num, q, tx_ring_size, rte_eth_dev_socket_id(port_num), NULL); - if (retval < 0) return retval; + if (retval < 0) + return retval; } rte_eth_promiscuous_enable(port_num); retval = rte_eth_dev_start(port_num); - if (retval < 0) return retval; + if (retval < 0) + return retval; - printf( "done: \n"); + printf("done:\n"); return 0; } @@ -150,15 +156,15 @@ init_port(uint16_t port_num) static int init_shm_rings(void) { - unsigned i; - unsigned socket_id; - const char * q_name; - const unsigned ringsize = CLIENT_QUEUE_RINGSIZE; + unsigned int i, socket_id; + const char *q_name; + const unsigned int ringsize = CLIENT_QUEUE_RINGSIZE; clients = rte_malloc("client details", sizeof(*clients) * num_clients, 0); if (clients == NULL) - rte_exit(EXIT_FAILURE, "Cannot allocate memory for client program details\n"); + rte_exit(EXIT_FAILURE, + "Cannot allocate memory for client program details\n"); for (i = 0; i < num_clients; i++) { /* Create an RX queue for each client */ @@ -166,13 +172,27 @@ init_shm_rings(void) q_name = get_rx_queue_name(i); clients[i].rx_q = rte_ring_create(q_name, ringsize, socket_id, - RING_F_SP_ENQ | RING_F_SC_DEQ ); /* single prod, single cons */ + RING_F_SP_ENQ | RING_F_SC_DEQ); if (clients[i].rx_q == NULL) - rte_exit(EXIT_FAILURE, "Cannot create rx ring queue for client %u\n", i); + rte_exit(EXIT_FAILURE, + "Cannot create rx ring queue for client %u\n", + i); } return 0; } +static void +print_link_status(uint16 id, const struct rte_eth_link *link) +{ + if (link->link_status) + printf("Port %d Link Up - speed %u Mbps - %s-duplex\n", + id, link->link_speed, + (link->link_duplex == ETH_LINK_FULL_DUPLEX) ? + "full" : "half"); + else + printf("Port %d Link Down\n", id); +} + /* Check the link status of all ports in up to 9s, and print them finally */ static void check_all_ports_link_status(uint16_t port_num, uint32_t port_mask) @@ -192,21 +212,11 @@ check_all_ports_link_status(uint16_t port_num, uint32_t port_mask) continue; memset(&link, 0, sizeof(link)); rte_eth_link_get_nowait(ports->id[portid], &link); + /* print link status if flag set */ - if (print_flag == 1) { - if (link.link_status) - printf("Port %d Link Up - speed %u " - "Mbps - %s\n", ports->id[portid], - (unsigned)link.link_speed, - (link.link_duplex == ETH_LINK_FULL_DUPLEX) ? - ("full-duplex") : ("half-duplex\n")); - else - printf("Port %d Link Down\n", - (uint8_t)ports->id[portid]); - continue; - } - /* clear all_ports_up flag if any link down */ - if (link.link_status == ETH_LINK_DOWN) { + if (print_flag == 1) + print_link_status(&link); + else if (link.link_status == ETH_LINK_DOWN) { all_ports_up = 0; break; } @@ -251,7 +261,8 @@ init(int argc, char *argv[]) mz = rte_memzone_reserve(MZ_PORT_INFO, sizeof(*ports), rte_socket_id(), NO_FLAGS); if (mz == NULL) - rte_exit(EXIT_FAILURE, "Cannot reserve memory zone for port information\n"); + rte_exit(EXIT_FAILURE, + "Cannot reserve memory zone for port information\n"); memset(mz->addr, 0, sizeof(*ports)); ports = mz->addr; @@ -269,8 +280,8 @@ init(int argc, char *argv[]) for (i = 0; i < ports->num_ports; i++) { retval = init_port(ports->id[i]); if (retval != 0) - rte_exit(EXIT_FAILURE, "Cannot initialise port %u\n", - (unsigned)i); + rte_exit(EXIT_FAILURE, + "Cannot initialise port %u\n", i); } check_all_ports_link_status(ports->num_ports, (~0x0)); diff --git a/examples/multi_process/client_server_mp/mp_server/main.c b/examples/multi_process/client_server_mp/mp_server/main.c index 0150533700f0..bfec0bef3a71 100644 --- a/examples/multi_process/client_server_mp/mp_server/main.c +++ b/examples/multi_process/client_server_mp/mp_server/main.c @@ -64,8 +64,9 @@ get_printable_mac_addr(uint16_t port) if (unlikely(port >= RTE_MAX_ETHPORTS)) return err_address; - if (unlikely(addresses[port][0]=='\0')){ + if (unlikely(addresses[port][0] == '\0')) { struct rte_ether_addr mac; + rte_eth_macaddr_get(port, &mac); snprintf(addresses[port], sizeof(addresses[port]), "%02x:%02x:%02x:%02x:%02x:%02x\n", @@ -85,9 +86,9 @@ get_printable_mac_addr(uint16_t port) static void do_stats_display(void) { - unsigned i, j; + unsigned int i, j; const char clr[] = { 27, '[', '2', 'J', '\0' }; - const char topLeft[] = { 27, '[', '1', ';', '1', 'H','\0' }; + const char topLeft[] = { 27, '[', '1', ';', '1', 'H', '\0' }; uint64_t port_tx[RTE_MAX_ETHPORTS], port_tx_drop[RTE_MAX_ETHPORTS]; uint64_t client_tx[MAX_CLIENTS], client_tx_drop[MAX_CLIENTS]; @@ -97,12 +98,14 @@ do_stats_display(void) memset(client_tx, 0, sizeof(client_tx)); memset(client_tx_drop, 0, sizeof(client_tx_drop)); - for (i = 0; i < num_clients; i++){ + for (i = 0; i < num_clients; i++) { const volatile struct tx_stats *tx = &ports->tx_stats[i]; - for (j = 0; j < ports->num_ports; j++){ + + for (j = 0; j < ports->num_ports; j++) { /* assign to local variables here, save re-reading volatile vars */ const uint64_t tx_val = tx->tx[ports->id[j]]; const uint64_t drop_val = tx->tx_drop[ports->id[j]]; + port_tx[j] += tx_val; port_tx_drop[j] += drop_val; client_tx[i] += tx_val; @@ -116,21 +119,21 @@ do_stats_display(void) printf("PORTS\n"); printf("-----\n"); for (i = 0; i < ports->num_ports; i++) - printf("Port %u: '%s'\t", (unsigned)ports->id[i], - get_printable_mac_addr(ports->id[i])); + printf("Port %u: '%s'\t", ports->id[i], + get_printable_mac_addr(ports->id[i])); printf("\n\n"); - for (i = 0; i < ports->num_ports; i++){ - printf("Port %u - rx: %9"PRIu64"\t" - "tx: %9"PRIu64"\n", - (unsigned)ports->id[i], ports->rx_stats.rx[i], + for (i = 0; i < ports->num_ports; i++) { + printf("Port %u - rx: %9"PRIu64"\ttx: %9"PRIu64"\n", + ports->id[i], ports->rx_stats.rx[i], port_tx[i]); } printf("\nCLIENTS\n"); printf("-------\n"); - for (i = 0; i < num_clients; i++){ + for (i = 0; i < num_clients; i++) { const unsigned long long rx = clients[i].stats.rx; const unsigned long long rx_drop = clients[i].stats.rx_drop; + printf("Client %2u - rx: %9llu, rx_drop: %9llu\n" " tx: %9"PRIu64", tx_drop: %9"PRIu64"\n", i, rx, rx_drop, client_tx[i], client_tx_drop[i]); @@ -153,7 +156,8 @@ sleep_lcore(__attribute__((unused)) void *dummy) /* Only one core should display stats */ if (rte_atomic32_test_and_set(&display_stats)) { - const unsigned sleeptime = 1; + const unsigned int sleeptime = 1; + printf("Core %u displaying statistics\n", rte_lcore_id()); /* Longer initial pause so above printf is seen */ @@ -173,7 +177,7 @@ sleep_lcore(__attribute__((unused)) void *dummy) static void clear_stats(void) { - unsigned i; + unsigned int i; for (i = 0; i < num_clients; i++) clients[i].stats.rx = clients[i].stats.rx_drop = 0; @@ -194,12 +198,11 @@ flush_rx_queue(uint16_t client) cl = &clients[client]; if (rte_ring_enqueue_bulk(cl->rx_q, (void **)cl_rx_buf[client].buffer, - cl_rx_buf[client].count, NULL) == 0){ + cl_rx_buf[client].count, NULL) == 0) { for (j = 0; j < cl_rx_buf[client].count; j++) rte_pktmbuf_free(cl_rx_buf[client].buffer[j]); cl->stats.rx_drop += cl_rx_buf[client].count; - } - else + } else cl->stats.rx += cl_rx_buf[client].count; cl_rx_buf[client].count = 0; @@ -243,14 +246,14 @@ process_packets(uint32_t port_num __rte_unused, static void do_packet_forwarding(void) { - unsigned port_num = 0; /* indexes the port[] array */ + unsigned int port_num = 0; /* indexes the port[] array */ for (;;) { struct rte_mbuf *buf[PACKET_READ_SIZE]; uint16_t rx_count; /* read a port */ - rx_count = rte_eth_rx_burst(ports->id[port_num], 0, \ + rx_count = rte_eth_rx_burst(ports->id[port_num], 0, buf, PACKET_READ_SIZE); ports->rx_stats.rx[port_num] += rx_count; @@ -281,8 +284,9 @@ int main(int argc, char *argv[]) { signal(SIGINT, signal_handler); + /* initialise the system */ - if (init(argc, argv) < 0 ) + if (init(argc, argv) < 0) return -1; RTE_LOG(INFO, APP, "Finished Process Init.\n"); From patchwork Fri Aug 2 02:58:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 57379 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 C18C91C227; Fri, 2 Aug 2019 04:58:39 +0200 (CEST) Received: from mail-pg1-f194.google.com (mail-pg1-f194.google.com [209.85.215.194]) by dpdk.org (Postfix) with ESMTP id 2E1701C20F for ; Fri, 2 Aug 2019 04:58:34 +0200 (CEST) Received: by mail-pg1-f194.google.com with SMTP id n4so10602pgv.2 for ; Thu, 01 Aug 2019 19:58:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GRL9o22FsqlZS1KIBKGsZH8PR5E+wVCUALAgsRD4EO0=; b=VRrPHxAqwsVlETKaJ2uQ8Fy/NmgObWFUBWp5PwaFjx79w+O/tF4ZoWff8Vf3Im7Rny 0vcb6JzZTuOXrxlpvcvVMu3CDhfHzDFb6vn2MhAQJpbgmMKfVkoVqjuZWDZ6VlFef9m1 aq/UAliHZ/NTCeLeDCoOZlXcHK6pQSmuDUYVYVwkBldOXz/1sE39fNyBAP8vXZ+o4CJZ A6BHJWraj+Dx5kWu8AJzoU51gG2sNiE1qX1PC6/P5KR35qD1RMEiU4YRUk6jdO1S+bqp u4GZGY05VGsXp99yszcHiELQwgzjSFPockUiT3VAtfEfaLujcXlGoClHLLFKV7pxZVfM FF0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=GRL9o22FsqlZS1KIBKGsZH8PR5E+wVCUALAgsRD4EO0=; b=gjgW93ts8Tc16RjUQovkeFmhH/5CjCvqNs7+Nltp5W4kfkv9cDB11Z72I+FgbnFi9D wZE6aW5zPoT+kpE8Mwp4/4nXly2d61JY3tOigpD/6kZ8NDSbaUhUmYiJJSgne/hm+JjC kj8ZoNpAv2lS34YIG6dO1nMen73uApzA2x3pyJ1KuIIV+hHEusmZUQp1MmX+cUuZ9Vt9 E2kElCMmjHigipruTaWewNsBZA7cXKrhMADlKF3Q9ab/KDDqTGzroSQRAV70C1DAC+hl +wRUVwbyrL4IXaEycrLF0UJNqA25/r8e70t2AWMi/N42T7gyPLi6vrr5uij1IWWA/E7q Mr0A== X-Gm-Message-State: APjAAAVGpJSlbAAQK2B+Do7Yzh6So4LlmrdsKp/r6VL4P7gqeFPFqzk8 TYbanavBDD/AQbGAz+RpDuync3c7 X-Google-Smtp-Source: APXvYqygpfqT/ZZE7sHvUncnu4jY6QV/6Y3WNMd3uW4aEy+8n+5gA3Gl4IbhZNmYOeyLBSRChqyJkA== X-Received: by 2002:aa7:9531:: with SMTP id c17mr59086508pfp.130.1564714712941; Thu, 01 Aug 2019 19:58:32 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id a20sm5788738pjo.0.2019.08.01.19.58.32 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 01 Aug 2019 19:58:32 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Thu, 1 Aug 2019 19:58:26 -0700 Message-Id: <20190802025826.1174-5-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190802025826.1174-1-stephen@networkplumber.org> References: <20190726165054.24078-1-stephen@networkplumber.org> <20190802025826.1174-1-stephen@networkplumber.org> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v5 4/4] examples/multi_process/client_server_mp/mp_server: use ether format address 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" No need to use snprintf to print ethernet address. Signed-off-by: Stephen Hemminger --- .../client_server_mp/mp_server/main.c | 32 ++++++------------- 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/examples/multi_process/client_server_mp/mp_server/main.c b/examples/multi_process/client_server_mp/mp_server/main.c index bfec0bef3a71..d1339d4be64c 100644 --- a/examples/multi_process/client_server_mp/mp_server/main.c +++ b/examples/multi_process/client_server_mp/mp_server/main.c @@ -56,26 +56,6 @@ struct client_rx_buf { /* One buffer per client rx queue - dynamically allocate array */ static struct client_rx_buf *cl_rx_buf; -static const char * -get_printable_mac_addr(uint16_t port) -{ - static const char err_address[] = "00:00:00:00:00:00"; - static char addresses[RTE_MAX_ETHPORTS][sizeof(err_address)]; - - if (unlikely(port >= RTE_MAX_ETHPORTS)) - return err_address; - if (unlikely(addresses[port][0] == '\0')) { - struct rte_ether_addr mac; - - rte_eth_macaddr_get(port, &mac); - snprintf(addresses[port], sizeof(addresses[port]), - "%02x:%02x:%02x:%02x:%02x:%02x\n", - mac.addr_bytes[0], mac.addr_bytes[1], mac.addr_bytes[2], - mac.addr_bytes[3], mac.addr_bytes[4], mac.addr_bytes[5]); - } - return addresses[port]; -} - /* * This function displays the recorded statistics for each port * and for each client. It uses ANSI terminal codes to clear @@ -118,9 +98,15 @@ do_stats_display(void) printf("PORTS\n"); printf("-----\n"); - for (i = 0; i < ports->num_ports; i++) - printf("Port %u: '%s'\t", ports->id[i], - get_printable_mac_addr(ports->id[i])); + for (i = 0; i < ports->num_ports; i++) { + struct rte_ether_addr mac = { }; + char buf[32]; + + rte_eth_macaddr_get(ports->id[i], &mac); + rte_ether_format_addr(buf, sizeof(buf), &mac); + printf("Port %u: '%s'\t", ports->id[i], buf); + } + printf("\n\n"); for (i = 0; i < ports->num_ports; i++) { printf("Port %u - rx: %9"PRIu64"\ttx: %9"PRIu64"\n",