4 * Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 #include <sys/queue.h>
45 #include <rte_config.h>
46 #include <rte_common.h>
47 #include <rte_debug.h>
48 #include <rte_ethdev.h>
49 #include <rte_malloc.h>
50 #include <rte_memory.h>
51 #include <rte_memzone.h>
52 #include <rte_launch.h>
53 #include <rte_tailq.h>
54 #include <rte_per_lcore.h>
55 #include <rte_lcore.h>
56 #include <rte_debug.h>
58 #include <rte_atomic.h>
59 #include <rte_branch_prediction.h>
60 #include <rte_string_fns.h>
62 /* Maximum long option length for option parsing. */
63 #define MAX_LONG_OPT_SZ 64
64 #define RTE_LOGTYPE_APP RTE_LOGTYPE_USER1
66 /**< mask of enabled ports */
67 static uint32_t enabled_port_mask;
69 static uint32_t enable_stats;
70 /**< Enable xstats. */
71 static uint32_t enable_xstats;
72 /**< Enable stats reset. */
73 static uint32_t reset_stats;
74 /**< Enable xstats reset. */
75 static uint32_t reset_xstats;
76 /**< Enable memory info. */
77 static uint32_t mem_info;
81 proc_info_usage(const char *prgname)
83 printf("%s [EAL options] -- -p PORTMASK\n"
84 " -m to display DPDK memory zones, segments and TAILQ information\n"
85 " -p PORTMASK: hexadecimal bitmask of ports to retrieve stats for\n"
86 " --stats: to display port statistics, enabled by default\n"
87 " --xstats: to display extended port statistics, disabled by "
89 " --stats-reset: to reset port statistics\n"
90 " --xstats-reset: to reset port extended statistics\n",
95 * Parse the portmask provided at run time.
98 parse_portmask(const char *portmask)
105 /* parse hexadecimal string */
106 pm = strtoul(portmask, &end, 16);
107 if ((portmask[0] == '\0') || (end == NULL) || (*end != '\0') ||
109 printf("%s ERROR parsing the port mask\n", __func__);
120 /* Parse the argument given in the command line of the application */
122 proc_info_parse_args(int argc, char **argv)
126 char *prgname = argv[0];
127 static struct option long_option[] = {
128 {"stats", 0, NULL, 0},
129 {"stats-reset", 0, NULL, 0},
130 {"xstats", 0, NULL, 0},
131 {"xstats-reset", 0, NULL, 0},
136 proc_info_usage(prgname);
138 /* Parse command line */
139 while ((opt = getopt_long(argc, argv, "p:m",
140 long_option, &option_index)) != EOF) {
144 enabled_port_mask = parse_portmask(optarg);
145 if (enabled_port_mask == 0) {
146 printf("invalid portmask\n");
147 proc_info_usage(prgname);
156 if (!strncmp(long_option[option_index].name, "stats",
160 else if (!strncmp(long_option[option_index].name, "xstats",
164 if (!strncmp(long_option[option_index].name, "stats-reset",
168 else if (!strncmp(long_option[option_index].name, "xstats-reset",
174 proc_info_usage(prgname);
182 meminfo_display(void)
184 printf("----------- MEMORY_SEGMENTS -----------\n");
185 rte_dump_physmem_layout(stdout);
186 printf("--------- END_MEMORY_SEGMENTS ---------\n");
188 printf("------------ MEMORY_ZONES -------------\n");
189 rte_memzone_dump(stdout);
190 printf("---------- END_MEMORY_ZONES -----------\n");
192 printf("------------- TAIL_QUEUES -------------\n");
193 rte_dump_tailq(stdout);
194 printf("---------- END_TAIL_QUEUES ------------\n");
198 nic_stats_display(uint8_t port_id)
200 struct rte_eth_stats stats;
203 static const char *nic_stats_border = "########################";
205 rte_eth_stats_get(port_id, &stats);
206 printf("\n %s NIC statistics for port %-2d %s\n",
207 nic_stats_border, port_id, nic_stats_border);
209 printf(" RX-packets: %-10"PRIu64" RX-errors: %-10"PRIu64
210 " RX-bytes: %-10"PRIu64"\n", stats.ipackets, stats.ierrors,
212 printf(" RX-nombuf: %-10"PRIu64"\n", stats.rx_nombuf);
213 printf(" TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64
214 " TX-bytes: %-10"PRIu64"\n", stats.opackets, stats.oerrors,
218 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
219 printf(" Stats reg %2d RX-packets: %-10"PRIu64
220 " RX-errors: %-10"PRIu64
221 " RX-bytes: %-10"PRIu64"\n",
222 i, stats.q_ipackets[i], stats.q_errors[i], stats.q_ibytes[i]);
226 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
227 printf(" Stats reg %2d TX-packets: %-10"PRIu64
228 " TX-bytes: %-10"PRIu64"\n",
229 i, stats.q_opackets[i], stats.q_obytes[i]);
232 printf(" %s############################%s\n",
233 nic_stats_border, nic_stats_border);
237 nic_stats_clear(uint8_t port_id)
239 printf("\n Clearing NIC stats for port %d\n", port_id);
240 rte_eth_stats_reset(port_id);
241 printf("\n NIC statistics for port %d cleared\n", port_id);
245 nic_xstats_display(uint8_t port_id)
247 struct rte_eth_xstats *xstats;
249 static const char *nic_stats_border = "########################";
251 len = rte_eth_xstats_get(port_id, NULL, 0);
253 printf("Cannot get xstats count\n");
256 xstats = malloc(sizeof(xstats[0]) * len);
257 if (xstats == NULL) {
258 printf("Cannot allocate memory for xstats\n");
262 printf("###### NIC extended statistics for port %-2d #########\n",
264 printf("%s############################\n",
266 ret = rte_eth_xstats_get(port_id, xstats, len);
267 if (ret < 0 || ret > len) {
268 printf("Cannot get xstats\n");
273 for (i = 0; i < len; i++)
274 printf("%s: %"PRIu64"\n", xstats[i].name, xstats[i].value);
276 printf("%s############################\n",
282 nic_xstats_clear(uint8_t port_id)
284 printf("\n Clearing NIC xstats for port %d\n", port_id);
285 rte_eth_xstats_reset(port_id);
286 printf("\n NIC extended statistics for port %d cleared\n", port_id);
290 main(int argc, char **argv)
294 char c_flag[] = "-c1";
295 char n_flag[] = "-n4";
296 char mp_flag[] = "--proc-type=secondary";
297 char *argp[argc + 3];
305 for (i = 1; i < argc; i++)
306 argp[i + 3] = argv[i];
310 ret = rte_eal_init(argc, argp);
312 rte_panic("Cannot init EAL\n");
317 /* parse app arguments */
318 ret = proc_info_parse_args(argc, argv);
320 rte_exit(EXIT_FAILURE, "Invalid argument\n");
327 nb_ports = rte_eth_dev_count();
329 rte_exit(EXIT_FAILURE, "No Ethernet ports - bye\n");
332 if (nb_ports > RTE_MAX_ETHPORTS)
333 nb_ports = RTE_MAX_ETHPORTS;
335 /* If no port mask was specified*/
336 if (enabled_port_mask == 0)
337 enabled_port_mask = 0xffff;
339 for (i = 0; i < nb_ports; i++) {
340 if (enabled_port_mask & (1 << i)) {
342 nic_stats_display(i);
343 else if (enable_xstats)
344 nic_xstats_display(i);
345 else if (reset_stats)
347 else if (reset_xstats)