[dpdk-dev] [PATCH v7 08/25] examples: new link status print format
Ivan Dyukov
i.dyukov at samsung.com
Fri Jul 10 09:02:06 CEST 2020
Add usage of rte_eth_link_strf function to example
applications:
* ipv4_multicast
* l2fwd-jobstats
* l2fwd-keepalive
* l3fwd
* link_status_interrupt
Signed-off-by: Ivan Dyukov <i.dyukov at samsung.com>
---
examples/ipv4_multicast/main.c | 12 ++++-------
examples/l2fwd-jobstats/main.c | 12 ++++-------
examples/l2fwd-keepalive/main.c | 12 ++++-------
examples/l3fwd/main.c | 12 ++++-------
examples/link_status_interrupt/main.c | 30 +++++++++++----------------
5 files changed, 28 insertions(+), 50 deletions(-)
diff --git a/examples/ipv4_multicast/main.c b/examples/ipv4_multicast/main.c
index 7e255c35a..0d4957658 100644
--- a/examples/ipv4_multicast/main.c
+++ b/examples/ipv4_multicast/main.c
@@ -572,6 +572,7 @@ check_all_ports_link_status(uint32_t port_mask)
uint8_t count, all_ports_up, print_flag = 0;
struct rte_eth_link link;
int ret;
+ char link_status_text[60];
printf("\nChecking link status");
fflush(stdout);
@@ -591,14 +592,9 @@ check_all_ports_link_status(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",
- portid, link.link_speed,
- (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
- ("full-duplex") : ("half-duplex"));
- else
- printf("Port %d Link Down\n", portid);
+ rte_eth_link_strf(link_status_text, 60, NULL,
+ &link);
+ printf("Port %d %s", portid, link_status_text);
continue;
}
/* clear all_ports_up flag if any link down */
diff --git a/examples/l2fwd-jobstats/main.c b/examples/l2fwd-jobstats/main.c
index 47a3b0976..740f1c80f 100644
--- a/examples/l2fwd-jobstats/main.c
+++ b/examples/l2fwd-jobstats/main.c
@@ -689,6 +689,7 @@ check_all_ports_link_status(uint32_t port_mask)
uint8_t count, all_ports_up, print_flag = 0;
struct rte_eth_link link;
int ret;
+ char link_status_text[60];
printf("\nChecking link status");
fflush(stdout);
@@ -708,14 +709,9 @@ check_all_ports_link_status(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",
- portid, link.link_speed,
- (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
- ("full-duplex") : ("half-duplex"));
- else
- printf("Port %d Link Down\n", portid);
+ rte_eth_link_strf(link_status_text, 60, NULL,
+ &link);
+ printf("Port %d %s", portid, link_status_text);
continue;
}
/* clear all_ports_up flag if any link down */
diff --git a/examples/l2fwd-keepalive/main.c b/examples/l2fwd-keepalive/main.c
index b2742633b..d8be0a727 100644
--- a/examples/l2fwd-keepalive/main.c
+++ b/examples/l2fwd-keepalive/main.c
@@ -453,6 +453,7 @@ check_all_ports_link_status(uint32_t port_mask)
uint8_t count, all_ports_up, print_flag = 0;
struct rte_eth_link link;
int ret;
+ char link_status_text[60];
printf("\nChecking link status");
fflush(stdout);
@@ -472,14 +473,9 @@ check_all_ports_link_status(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",
- portid, link.link_speed,
- (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
- ("full-duplex") : ("half-duplex"));
- else
- printf("Port %d Link Down\n", portid);
+ rte_eth_link_strf(link_status_text, 60, NULL,
+ &link);
+ printf("Port %d %s", portid, link_status_text);
continue;
}
/* clear all_ports_up flag if any link down */
diff --git a/examples/l3fwd/main.c b/examples/l3fwd/main.c
index 24ede4290..ef0f19a39 100644
--- a/examples/l3fwd/main.c
+++ b/examples/l3fwd/main.c
@@ -810,6 +810,7 @@ check_all_ports_link_status(uint32_t port_mask)
uint8_t count, all_ports_up, print_flag = 0;
struct rte_eth_link link;
int ret;
+ char link_status_text[60];
printf("\nChecking link status");
fflush(stdout);
@@ -833,14 +834,9 @@ check_all_ports_link_status(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",
- portid, link.link_speed,
- (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
- ("full-duplex") : ("half-duplex"));
- else
- printf("Port %d Link Down\n", portid);
+ rte_eth_link_strf(link_status_text, 60, NULL,
+ &link);
+ printf("Port %d %s", portid, link_status_text);
continue;
}
/* clear all_ports_up flag if any link down */
diff --git a/examples/link_status_interrupt/main.c b/examples/link_status_interrupt/main.c
index 9bbcadfcf..5e286060d 100644
--- a/examples/link_status_interrupt/main.c
+++ b/examples/link_status_interrupt/main.c
@@ -118,6 +118,7 @@ print_stats(void)
const char clr[] = { 27, '[', '2', 'J', '\0' };
const char topLeft[] = { 27, '[', '1', ';', '1', 'H','\0' };
int link_get_err;
+ char link_speed_text[16];
/* Clear screen and move to top left */
printf("%s%s", clr, topLeft);
@@ -131,9 +132,10 @@ print_stats(void)
memset(&link, 0, sizeof(link));
link_get_err = rte_eth_link_get_nowait(portid, &link);
+ rte_eth_link_strf(link_speed_text, 16, "%M", &link);
printf("\nStatistics for port %u ------------------------------"
"\nLink status: %25s"
- "\nLink speed: %26u"
+ "\nLink speed: %26s"
"\nLink duplex: %25s"
"\nPackets sent: %24"PRIu64
"\nPackets received: %20"PRIu64
@@ -141,8 +143,7 @@ print_stats(void)
portid,
link_get_err < 0 ? "Link get failed" :
(link.link_status ? "Link up" : "Link down"),
- link_get_err < 0 ? 0 :
- (unsigned int)link.link_speed,
+ link_get_err < 0 ? "0" : link_speed_text,
link_get_err < 0 ? "Link get failed" :
(link.link_duplex == ETH_LINK_FULL_DUPLEX ? \
"full-duplex" : "half-duplex"),
@@ -445,6 +446,7 @@ lsi_event_callback(uint16_t port_id, enum rte_eth_event_type type, void *param,
{
struct rte_eth_link link;
int ret;
+ char link_status_text[60];
RTE_SET_USED(param);
RTE_SET_USED(ret_param);
@@ -457,13 +459,8 @@ lsi_event_callback(uint16_t port_id, enum rte_eth_event_type type, void *param,
port_id, rte_strerror(-ret));
return ret;
}
- if (link.link_status) {
- printf("Port %d Link Up - speed %u Mbps - %s\n\n",
- port_id, (unsigned)link.link_speed,
- (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
- ("full-duplex") : ("half-duplex"));
- } else
- printf("Port %d Link Down\n\n", port_id);
+ rte_eth_link_strf(link_status_text, 60, NULL, &link);
+ printf("Port %d %s\n", port_id, link_status_text);
return 0;
}
@@ -478,6 +475,7 @@ check_all_ports_link_status(uint16_t port_num, uint32_t port_mask)
uint16_t portid;
struct rte_eth_link link;
int ret;
+ char link_status_text[60];
printf("\nChecking link status");
fflush(stdout);
@@ -497,14 +495,10 @@ 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",
- portid, link.link_speed,
- (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
- ("full-duplex") : ("half-duplex"));
- else
- printf("Port %d Link Down\n", portid);
+ rte_eth_link_strf(link_status_text, 60, NULL,
+ &link);
+ printf("Port %d %s", portid,
+ link_status_text);
continue;
}
/* clear all_ports_up flag if any link down */
--
2.17.1
More information about the dev
mailing list