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_common.h>
46 #include <rte_debug.h>
47 #include <rte_ethdev.h>
48 #include <rte_malloc.h>
49 #include <rte_memory.h>
50 #include <rte_memzone.h>
51 #include <rte_launch.h>
52 #include <rte_tailq.h>
53 #include <rte_per_lcore.h>
54 #include <rte_lcore.h>
55 #include <rte_debug.h>
57 #include <rte_atomic.h>
58 #include <rte_branch_prediction.h>
59 #include <rte_string_fns.h>
61 /* Maximum long option length for option parsing. */
62 #define MAX_LONG_OPT_SZ 64
63 #define RTE_LOGTYPE_APP RTE_LOGTYPE_USER1
65 /**< mask of enabled ports */
66 static uint32_t enabled_port_mask;
68 static uint32_t enable_stats;
69 /**< Enable xstats. */
70 static uint32_t enable_xstats;
71 /**< Enable stats reset. */
72 static uint32_t reset_stats;
73 /**< Enable xstats reset. */
74 static uint32_t reset_xstats;
75 /**< Enable memory info. */
76 static uint32_t mem_info;
80 proc_info_usage(const char *prgname)
82 printf("%s [EAL options] -- -p PORTMASK\n"
83 " -m to display DPDK memory zones, segments and TAILQ information\n"
84 " -p PORTMASK: hexadecimal bitmask of ports to retrieve stats for\n"
85 " --stats: to display port statistics, enabled by default\n"
86 " --xstats: to display extended port statistics, disabled by "
88 " --stats-reset: to reset port statistics\n"
89 " --xstats-reset: to reset port extended statistics\n",
94 * Parse the portmask provided at run time.
97 parse_portmask(const char *portmask)
104 /* parse hexadecimal string */
105 pm = strtoul(portmask, &end, 16);
106 if ((portmask[0] == '\0') || (end == NULL) || (*end != '\0') ||
108 printf("%s ERROR parsing the port mask\n", __func__);
119 /* Parse the argument given in the command line of the application */
121 proc_info_parse_args(int argc, char **argv)
125 char *prgname = argv[0];
126 static struct option long_option[] = {
127 {"stats", 0, NULL, 0},
128 {"stats-reset", 0, NULL, 0},
129 {"xstats", 0, NULL, 0},
130 {"xstats-reset", 0, NULL, 0},
135 proc_info_usage(prgname);
137 /* Parse command line */
138 while ((opt = getopt_long(argc, argv, "p:m",
139 long_option, &option_index)) != EOF) {
143 enabled_port_mask = parse_portmask(optarg);
144 if (enabled_port_mask == 0) {
145 printf("invalid portmask\n");
146 proc_info_usage(prgname);
155 if (!strncmp(long_option[option_index].name, "stats",
159 else if (!strncmp(long_option[option_index].name, "xstats",
163 if (!strncmp(long_option[option_index].name, "stats-reset",
167 else if (!strncmp(long_option[option_index].name, "xstats-reset",
173 proc_info_usage(prgname);
181 meminfo_display(void)
183 printf("----------- MEMORY_SEGMENTS -----------\n");
184 rte_dump_physmem_layout(stdout);
185 printf("--------- END_MEMORY_SEGMENTS ---------\n");
187 printf("------------ MEMORY_ZONES -------------\n");
188 rte_memzone_dump(stdout);
189 printf("---------- END_MEMORY_ZONES -----------\n");
191 printf("------------- TAIL_QUEUES -------------\n");
192 rte_dump_tailq(stdout);
193 printf("---------- END_TAIL_QUEUES ------------\n");
197 nic_stats_display(uint8_t port_id)
199 struct rte_eth_stats stats;
202 static const char *nic_stats_border = "########################";
204 rte_eth_stats_get(port_id, &stats);
205 printf("\n %s NIC statistics for port %-2d %s\n",
206 nic_stats_border, port_id, nic_stats_border);
208 printf(" RX-packets: %-10"PRIu64" RX-errors: %-10"PRIu64
209 " RX-bytes: %-10"PRIu64"\n", stats.ipackets, stats.ierrors,
211 printf(" RX-nombuf: %-10"PRIu64"\n", stats.rx_nombuf);
212 printf(" TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64
213 " TX-bytes: %-10"PRIu64"\n", stats.opackets, stats.oerrors,
217 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
218 printf(" Stats reg %2d RX-packets: %-10"PRIu64
219 " RX-errors: %-10"PRIu64
220 " RX-bytes: %-10"PRIu64"\n",
221 i, stats.q_ipackets[i], stats.q_errors[i], stats.q_ibytes[i]);
225 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
226 printf(" Stats reg %2d TX-packets: %-10"PRIu64
227 " TX-bytes: %-10"PRIu64"\n",
228 i, stats.q_opackets[i], stats.q_obytes[i]);
231 printf(" %s############################%s\n",
232 nic_stats_border, nic_stats_border);
236 nic_stats_clear(uint8_t port_id)
238 printf("\n Clearing NIC stats for port %d\n", port_id);
239 rte_eth_stats_reset(port_id);
240 printf("\n NIC statistics for port %d cleared\n", port_id);
244 nic_xstats_display(uint8_t port_id)
246 struct rte_eth_xstats *xstats;
248 static const char *nic_stats_border = "########################";
250 len = rte_eth_xstats_get(port_id, NULL, 0);
252 printf("Cannot get xstats count\n");
255 xstats = malloc(sizeof(xstats[0]) * len);
256 if (xstats == NULL) {
257 printf("Cannot allocate memory for xstats\n");
261 printf("###### NIC extended statistics for port %-2d #########\n",
263 printf("%s############################\n",
265 ret = rte_eth_xstats_get(port_id, xstats, len);
266 if (ret < 0 || ret > len) {
267 printf("Cannot get xstats\n");
272 for (i = 0; i < len; i++)
273 printf("%s: %"PRIu64"\n", xstats[i].name, xstats[i].value);
275 printf("%s############################\n",
281 nic_xstats_clear(uint8_t port_id)
283 printf("\n Clearing NIC xstats for port %d\n", port_id);
284 rte_eth_xstats_reset(port_id);
285 printf("\n NIC extended statistics for port %d cleared\n", port_id);
289 main(int argc, char **argv)
293 char c_flag[] = "-c1";
294 char n_flag[] = "-n4";
295 char mp_flag[] = "--proc-type=secondary";
296 char *argp[argc + 3];
304 for (i = 1; i < argc; i++)
305 argp[i + 3] = argv[i];
309 ret = rte_eal_init(argc, argp);
311 rte_panic("Cannot init EAL\n");
316 /* parse app arguments */
317 ret = proc_info_parse_args(argc, argv);
319 rte_exit(EXIT_FAILURE, "Invalid argument\n");
326 nb_ports = rte_eth_dev_count();
328 rte_exit(EXIT_FAILURE, "No Ethernet ports - bye\n");
330 /* If no port mask was specified*/
331 if (enabled_port_mask == 0)
332 enabled_port_mask = 0xffff;
334 for (i = 0; i < nb_ports; i++) {
335 if (enabled_port_mask & (1 << i)) {
337 nic_stats_display(i);
338 else if (enable_xstats)
339 nic_xstats_display(i);
340 else if (reset_stats)
342 else if (reset_xstats)