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 11A42A10DA for ; Fri, 2 Aug 2019 04:58:54 +0200 (CEST) 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 Content-Transfer-Encoding: 8bit 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"); -- 2.20.1