From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id DA543A046B for ; Fri, 26 Jul 2019 18:51:32 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 19E771C51D; Fri, 26 Jul 2019 18:51:19 +0200 (CEST) Received: from mail-pl1-f193.google.com (mail-pl1-f193.google.com [209.85.214.193]) by dpdk.org (Postfix) with ESMTP id 2E62C1C504 for ; Fri, 26 Jul 2019 18:51:07 +0200 (CEST) Received: by mail-pl1-f193.google.com with SMTP id 4so17978762pld.10 for ; Fri, 26 Jul 2019 09:51:07 -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=A5i/wMMYD/NDjvQ76cpx2QG8xWB7hvVmCM8nmfWvIKY=; b=Ju1tcU04mZ+UbLghaRxp9CWQuIq+WOD+B9kKSMQrLPSLHKi0JjVeTulcVptQ8DM1M/ pCamDXxA5i93cRkljBqTujUTzjc9yvxer1gT7viROuSICvreKxBlScKwu4hRQR9UkxL+ 1IUzrj51UHIiw88j1BCZUMf4UZGwDZrWgGjzRfVhj4UsO4iEEB/0gLy/Vl7zjyzzXAz1 vJsY4pXWssFQ94KhGj/yr0f4flf02ExA1tsfNIzNnCbiKSPBrlLKk9DyEhwixKl07tL3 0uM8/fxlej9z6lz32S27GJhwjVdVHun8Lbrwi34it3qS7e1QZC8b84IXYzh5c7sOgQ78 Eb9g== 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=A5i/wMMYD/NDjvQ76cpx2QG8xWB7hvVmCM8nmfWvIKY=; b=E7KtKFrF9rMidAhm0BwWm7CFuaqUU4uvGQVdR68GT9IlVSNVmMzJChplItq8BUZ6Ae YsRK1qBTnjZ1VIzYZyYBxArwV8Q1xls8wRfayHLQGBVSpgF+Unc8wsH9xyr3nXGSi2Vh p9dXrSaiCH6SnKNJHObEEz1BpqQrxhgOKmv3wgQti5nLc7lcgXCPK47O3KcAqotMZKeO ya2g0t26JPrkO11ej0FioXqC/JPxClUYcq72NfFYUJaquoMlCil5Qe3dGobfFSC1b3ez eeVRjfcjGm6++hGrL9kstDdHTsju4+IWq814n75MMKzfkLCWl4MmbtRLxlR6cCfTySgH KJgA== X-Gm-Message-State: APjAAAX7Uu7b7fIbAuIA5m4pC12CWCWlveRSBBZ2XdehH8igwI40C23/ zAHvb9+pek5DxSs+WGD1XBHdGTtJ X-Google-Smtp-Source: APXvYqw1cXNGQZc78x5+eFdPJBivNNiiSsC6/qyBtSwAs5tYLDG7/HGjNGlmurZZLjvAcI4WxcyF0g== X-Received: by 2002:a17:902:4283:: with SMTP id h3mr94483516pld.15.1564159865826; Fri, 26 Jul 2019 09:51:05 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id s3sm14747747pgq.17.2019.07.26.09.51.04 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 26 Jul 2019 09:51:04 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Fri, 26 Jul 2019 09:50:53 -0700 Message-Id: <20190726165054.24078-4-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190726165054.24078-1-stephen@networkplumber.org> References: <20190709150939.31338-1-stephen@networkplumber.org> <20190726165054.24078-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v4 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 | 58 +++++++++++-------- .../client_server_mp/mp_server/main.c | 44 +++++++------- 3 files changed, 76 insertions(+), 63 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 c1ab12ad00d1..f8c501a13d5e 100644 --- a/examples/multi_process/client_server_mp/mp_server/args.c +++ b/examples/multi_process/client_server_mp/mp_server/args.c @@ -127,33 +127,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..26416f42cf03 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,9 +172,10 @@ 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; } @@ -195,11 +202,11 @@ check_all_ports_link_status(uint16_t port_num, uint32_t port_mask) /* 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")); + printf("Port %d Link Up - speed %u Mbps - %s-duplex\n", + ports->id[portid], + link.link_speed, + (link.link_duplex == ETH_LINK_FULL_DUPLEX) ? + "full" : "half"); else printf("Port %d Link Down\n", (uint8_t)ports->id[portid]); @@ -251,7 +258,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 +277,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"); -- 2.20.1