4 * Copyright(c) 2010-2016 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_xstat_name
*xstats_names
;
247 struct rte_eth_xstat
*xstats
;
249 static const char *nic_stats_border
= "########################";
251 len
= rte_eth_xstats_get_names(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 xstats_names
= malloc(sizeof(struct rte_eth_xstat_name
) * len
);
263 if (xstats_names
== NULL
) {
264 printf("Cannot allocate memory for xstat names\n");
268 if (len
!= rte_eth_xstats_get_names(
269 port_id
, xstats_names
, len
)) {
270 printf("Cannot get xstat names\n");
274 printf("###### NIC extended statistics for port %-2d #########\n",
276 printf("%s############################\n",
278 ret
= rte_eth_xstats_get(port_id
, xstats
, len
);
279 if (ret
< 0 || ret
> len
) {
280 printf("Cannot get xstats\n");
284 for (i
= 0; i
< len
; i
++)
285 printf("%s: %"PRIu64
"\n",
286 xstats_names
[i
].name
,
289 printf("%s############################\n",
297 nic_xstats_clear(uint8_t port_id
)
299 printf("\n Clearing NIC xstats for port %d\n", port_id
);
300 rte_eth_xstats_reset(port_id
);
301 printf("\n NIC extended statistics for port %d cleared\n", port_id
);
305 main(int argc
, char **argv
)
309 char c_flag
[] = "-c1";
310 char n_flag
[] = "-n4";
311 char mp_flag
[] = "--proc-type=secondary";
312 char *argp
[argc
+ 3];
320 for (i
= 1; i
< argc
; i
++)
321 argp
[i
+ 3] = argv
[i
];
325 ret
= rte_eal_init(argc
, argp
);
327 rte_panic("Cannot init EAL\n");
332 if (!rte_eal_primary_proc_alive(NULL
))
333 rte_exit(EXIT_FAILURE
, "No primary DPDK process is running.\n");
335 /* parse app arguments */
336 ret
= proc_info_parse_args(argc
, argv
);
338 rte_exit(EXIT_FAILURE
, "Invalid argument\n");
345 nb_ports
= rte_eth_dev_count();
347 rte_exit(EXIT_FAILURE
, "No Ethernet ports - bye\n");
349 /* If no port mask was specified*/
350 if (enabled_port_mask
== 0)
351 enabled_port_mask
= 0xffff;
353 for (i
= 0; i
< nb_ports
; i
++) {
354 if (enabled_port_mask
& (1 << i
)) {
356 nic_stats_display(i
);
357 else if (enable_xstats
)
358 nic_xstats_display(i
);
359 else if (reset_stats
)
361 else if (reset_xstats
)