Skip to contentSkip to conversation

Questions about rte_eth_link_speed_to_str API

dpdk-dev NAK Min Hu (Connor) 6 participants 16 messages Sep 13, 2021 – Mar 23, 2023

lore
Share & tools
lore
#0 lore raw

Hi all,
I have questions about rte_eth_link_speed_to_str API. The API converts link speed to string for display, But it only
supports the following speeds, like that:

	case ETH_SPEED_NUM_NONE: return "None";
	case ETH_SPEED_NUM_10M:  return "10 Mbps";
	case ETH_SPEED_NUM_100M: return "100 Mbps";
	case ETH_SPEED_NUM_1G:   return "1 Gbps";
	case ETH_SPEED_NUM_2_5G: return "2.5 Gbps";
	case ETH_SPEED_NUM_5G:   return "5 Gbps";
	case ETH_SPEED_NUM_10G:  return "10 Gbps";
	case ETH_SPEED_NUM_20G:  return "20 Gbps";
	case ETH_SPEED_NUM_25G:  return "25 Gbps";
	case ETH_SPEED_NUM_40G:  return "40 Gbps";
	case ETH_SPEED_NUM_50G:  return "50 Gbps";
	case ETH_SPEED_NUM_56G:  return "56 Gbps";
	case ETH_SPEED_NUM_100G: return "100 Gbps";
	case ETH_SPEED_NUM_200G: return "200 Gbps";
	case ETH_SPEED_NUM_UNKNOWN: return "Unknown";
	default: return "Invalid";

	In some cases, like bonding, for example, three slaves which
	link speed are 10Gbps, so link speed of bonding port will be
	30Gbps, but it shows "Invalid".

	Is this reasonable? any comments will be welcome.

		Best wishes
#1 lore raw

13/09/2021 10:45, Min Hu (Connor):

Quoted 18 lines

Hi all,
I have questions about rte_eth_link_speed_to_str API. The API converts link speed to string for display, But it only
supports the following speeds, like that:

	case ETH_SPEED_NUM_NONE: return "None";
	case ETH_SPEED_NUM_10M:  return "10 Mbps";
	case ETH_SPEED_NUM_100M: return "100 Mbps";
	case ETH_SPEED_NUM_1G:   return "1 Gbps";
	case ETH_SPEED_NUM_2_5G: return "2.5 Gbps";
	case ETH_SPEED_NUM_5G:   return "5 Gbps";
	case ETH_SPEED_NUM_10G:  return "10 Gbps";
	case ETH_SPEED_NUM_20G:  return "20 Gbps";
	case ETH_SPEED_NUM_25G:  return "25 Gbps";
	case ETH_SPEED_NUM_40G:  return "40 Gbps";
	case ETH_SPEED_NUM_50G:  return "50 Gbps";
	case ETH_SPEED_NUM_56G:  return "56 Gbps";
	case ETH_SPEED_NUM_100G: return "100 Gbps";
	case ETH_SPEED_NUM_200G: return "200 Gbps";
Quoted 8 lines
	case ETH_SPEED_NUM_UNKNOWN: return "Unknown";
	default: return "Invalid";

	In some cases, like bonding, for example, three slaves which
	link speed are 10Gbps, so link speed of bonding port will be
	30Gbps, but it shows "Invalid".

	Is this reasonable? any comments will be welcome.

Is it meaningful to print combined slaves speed?
If yes, we can do better then this fixed switch/case logic, it shouldn't be too hard given it is a standard uint32_t value.

#2 lore raw

Thanks Thomas,
I am not sure if we need to print combined slaves speed. How about others' opinion ? @all

BTW, If yes, one possible option may be like that:
+const char *
+rte_eth_link_speed_to_str(uint32_t link_speed) +{
+ char name[16];
+
+ if (link_speed == ETH_SPEED_NUM_NONE)
+ return "None";
+ if (link_speed == ETH_SPEED_NUM_NONE)
+ return "Unknown";
+ if (link_speed < ETH_SPEED_NUM_1G) {
+ snprintf(name, sizeof(name), "%u Mbps", link_speed);
+ } else {
+ snprintf(name, sizeof(name), "%u Mbps",
+ link_speed / ETH_SPEED_NUM_1G);
+ }
+
+ return name;
+}

But the float value is difficult to handle, like 2.5 Gbps for show. Any advices?

Quoted 35 lines · Thomas Monjalon

13/09/2021 10:45, Min Hu (Connor):

Quoted 18 lines

Hi all,
I have questions about rte_eth_link_speed_to_str API. The API converts link speed to string for display, But it only
supports the following speeds, like that:

	case ETH_SPEED_NUM_NONE: return "None";
	case ETH_SPEED_NUM_10M:  return "10 Mbps";
	case ETH_SPEED_NUM_100M: return "100 Mbps";
	case ETH_SPEED_NUM_1G:   return "1 Gbps";
	case ETH_SPEED_NUM_2_5G: return "2.5 Gbps";
	case ETH_SPEED_NUM_5G:   return "5 Gbps";
	case ETH_SPEED_NUM_10G:  return "10 Gbps";
	case ETH_SPEED_NUM_20G:  return "20 Gbps";
	case ETH_SPEED_NUM_25G:  return "25 Gbps";
	case ETH_SPEED_NUM_40G:  return "40 Gbps";
	case ETH_SPEED_NUM_50G:  return "50 Gbps";
	case ETH_SPEED_NUM_56G:  return "56 Gbps";
	case ETH_SPEED_NUM_100G: return "100 Gbps";
	case ETH_SPEED_NUM_200G: return "200 Gbps";
Quoted 8 lines
	case ETH_SPEED_NUM_UNKNOWN: return "Unknown";
	default: return "Invalid";

	In some cases, like bonding, for example, three slaves which
	link speed are 10Gbps, so link speed of bonding port will be
	30Gbps, but it shows "Invalid".

	Is this reasonable? any comments will be welcome.

Is it meaningful to print combined slaves speed?
If yes, we can do better then this fixed switch/case logic, it shouldn't be too hard given it is a standard uint32_t value.

.

#3 lore raw
Quoted 24 lines · On Tue, 14 Sep 2021 11:25:44 +0800 "Min Hu (Connor)" <[email protected]> wrote:

Thanks Thomas,
I am not sure if we need to print combined slaves speed. How about others' opinion ? @all

BTW, If yes, one possible option may be like that:

(quoted diff) +18 -0
+const char *
+rte_eth_link_speed_to_str(uint32_t link_speed)
+{
+	char name[16];
+
+	if (link_speed == ETH_SPEED_NUM_NONE)
+		return "None";
+	if (link_speed == ETH_SPEED_NUM_NONE)
+		return "Unknown";
+	if (link_speed < ETH_SPEED_NUM_1G) {
+		snprintf(name, sizeof(name), "%u Mbps", link_speed);
+	} else {
+		snprintf(name, sizeof(name), "%u Mbps",
+			link_speed / ETH_SPEED_NUM_1G);
+	}
+
+	return name;
+}
Quoted 39 lines

But the float value is difficult to handle, like 2.5 Gbps for show. Any advices?

Quoted 35 lines · Thomas Monjalon

13/09/2021 10:45, Min Hu (Connor):

Quoted 18 lines

Hi all,
I have questions about rte_eth_link_speed_to_str API. The API converts link speed to string for display, But it only
supports the following speeds, like that:

	case ETH_SPEED_NUM_NONE: return "None";
	case ETH_SPEED_NUM_10M:  return "10 Mbps";
	case ETH_SPEED_NUM_100M: return "100 Mbps";
	case ETH_SPEED_NUM_1G:   return "1 Gbps";
	case ETH_SPEED_NUM_2_5G: return "2.5 Gbps";
	case ETH_SPEED_NUM_5G:   return "5 Gbps";
	case ETH_SPEED_NUM_10G:  return "10 Gbps";
	case ETH_SPEED_NUM_20G:  return "20 Gbps";
	case ETH_SPEED_NUM_25G:  return "25 Gbps";
	case ETH_SPEED_NUM_40G:  return "40 Gbps";
	case ETH_SPEED_NUM_50G:  return "50 Gbps";
	case ETH_SPEED_NUM_56G:  return "56 Gbps";
	case ETH_SPEED_NUM_100G: return "100 Gbps";
	case ETH_SPEED_NUM_200G: return "200 Gbps";
Quoted 8 lines
	case ETH_SPEED_NUM_UNKNOWN: return "Unknown";
	default: return "Invalid";

	In some cases, like bonding, for example, three slaves which
	link speed are 10Gbps, so link speed of bonding port will be
	30Gbps, but it shows "Invalid".

	Is this reasonable? any comments will be welcome.  

Is it meaningful to print combined slaves speed?
If yes, we can do better then this fixed switch/case logic, it shouldn't be too hard given it is a standard uint32_t value.

.

Since all the values are encoded numerically do some math. This is what iproute2 has evolved to doing..

int print_color_rate(bool use_iec, enum output_type type, enum color_attr color,
const char *key, const char *fmt, unsigned long long rate)

{
        unsigned long kilo = use_iec ? 1024 : 1000;
        const char *str = use_iec ? "i" : "";
        static char *units[5] = {"", "K", "M", "G", "T"};
        char *buf;
        int rc;
        int i;

        if (_IS_JSON_CONTEXT(type))
                return print_color_lluint(type, color, key, "%llu", rate);

        rate <<= 3; /* bytes/sec -> bits/sec */

        for (i = 0; i < ARRAY_SIZE(units) - 1; i++)  {
                if (rate < kilo)
                        break;
                if (((rate % kilo) != 0) && rate < 1000*kilo)
                        break;
                rate /= kilo;
        }

        rc = asprintf(&buf, "%.0f%s%sbit", (double)rate, units[i],
                      i > 0 ? str : "");
        if (rc < 0)
                return -1;

        rc = print_color_string(type, color, key, fmt, buf);
        free(buf);
}
#4 lore raw

Thanks Stephen,
While I think this option is more clear and simple:
+const char * +rte_eth_link_speed_to_str(uint32_t link_speed) +{
+#define SPEED_STRING_LEN 16
+ static char name[SPEED_STRING_LEN];
+
+ if (link_speed == ETH_SPEED_NUM_NONE)
+ return "None";
+ if (link_speed == ETH_SPEED_NUM_UNKNOWN)
+ return "Unknown";
+ if (link_speed < ETH_SPEED_NUM_1G) {
+ snprintf(name, sizeof(name), "%u Mbps", link_speed);
+ } else if (link_speed % ETH_SPEED_NUM_1G != 0){
+ snprintf(name, sizeof(name), "%.1f Gbps",
+ (double)link_speed / ETH_SPEED_NUM_1G);
+ } else {
+ snprintf(name, sizeof(name), "%u Gbps",
+ link_speed / ETH_SPEED_NUM_1G);
+ }
+
+ return (const char *)name;
+}

How about any others' opinions, thanks.

Quoted 106 lines · Stephen Hemminger
Quoted 24 lines · On Tue, 14 Sep 2021 11:25:44 +0800 "Min Hu (Connor)" <[email protected]> wrote:

Thanks Thomas,
I am not sure if we need to print combined slaves speed. How about others' opinion ? @all

BTW, If yes, one possible option may be like that:

(quoted diff) +18 -0
+const char *
+rte_eth_link_speed_to_str(uint32_t link_speed)
+{
+	char name[16];
+
+	if (link_speed == ETH_SPEED_NUM_NONE)
+		return "None";
+	if (link_speed == ETH_SPEED_NUM_NONE)
+		return "Unknown";
+	if (link_speed < ETH_SPEED_NUM_1G) {
+		snprintf(name, sizeof(name), "%u Mbps", link_speed);
+	} else {
+		snprintf(name, sizeof(name), "%u Mbps",
+			link_speed / ETH_SPEED_NUM_1G);
+	}
+
+	return name;
+}
Quoted 39 lines

But the float value is difficult to handle, like 2.5 Gbps for show. Any advices?

Quoted 35 lines · Thomas Monjalon

13/09/2021 10:45, Min Hu (Connor):

Quoted 18 lines

Hi all,
I have questions about rte_eth_link_speed_to_str API. The API converts link speed to string for display, But it only
supports the following speeds, like that:

	case ETH_SPEED_NUM_NONE: return "None";
	case ETH_SPEED_NUM_10M:  return "10 Mbps";
	case ETH_SPEED_NUM_100M: return "100 Mbps";
	case ETH_SPEED_NUM_1G:   return "1 Gbps";
	case ETH_SPEED_NUM_2_5G: return "2.5 Gbps";
	case ETH_SPEED_NUM_5G:   return "5 Gbps";
	case ETH_SPEED_NUM_10G:  return "10 Gbps";
	case ETH_SPEED_NUM_20G:  return "20 Gbps";
	case ETH_SPEED_NUM_25G:  return "25 Gbps";
	case ETH_SPEED_NUM_40G:  return "40 Gbps";
	case ETH_SPEED_NUM_50G:  return "50 Gbps";
	case ETH_SPEED_NUM_56G:  return "56 Gbps";
	case ETH_SPEED_NUM_100G: return "100 Gbps";
	case ETH_SPEED_NUM_200G: return "200 Gbps";
Quoted 8 lines
	case ETH_SPEED_NUM_UNKNOWN: return "Unknown";
	default: return "Invalid";

	In some cases, like bonding, for example, three slaves which
	link speed are 10Gbps, so link speed of bonding port will be
	30Gbps, but it shows "Invalid".

	Is this reasonable? any comments will be welcome.

Is it meaningful to print combined slaves speed?
If yes, we can do better then this fixed switch/case logic, it shouldn't be too hard given it is a standard uint32_t value.

.

Since all the values are encoded numerically do some math. This is what iproute2 has evolved to doing..

int print_color_rate(bool use_iec, enum output_type type, enum color_attr color,
const char *key, const char *fmt, unsigned long long rate)

{
         unsigned long kilo = use_iec ? 1024 : 1000;
         const char *str = use_iec ? "i" : "";
         static char *units[5] = {"", "K", "M", "G", "T"};
         char *buf;
         int rc;
         int i;

         if (_IS_JSON_CONTEXT(type))
                 return print_color_lluint(type, color, key, "%llu", rate);

         rate <<= 3; /* bytes/sec -> bits/sec */

         for (i = 0; i < ARRAY_SIZE(units) - 1; i++)  {
                 if (rate < kilo)
                         break;
                 if (((rate % kilo) != 0) && rate < 1000*kilo)
                         break;
                 rate /= kilo;
         }

         rc = asprintf(&buf, "%.0f%s%sbit", (double)rate, units[i],
                       i > 0 ? str : "");
         if (rc < 0)
                 return -1;

         rc = print_color_string(type, color, key, fmt, buf);
         free(buf);
}

.

#5 lore raw

RFC 1/1 ethdev: improve link speed to string

In reply to Min Hu (Connor)

Currently, link speed to string only supports specific speeds, like 10M, 100M, 1G etc.

This patch expands support for any link speed which is over 1M and one decimal place will kept for display at most.

---
 lib/ethdev/rte_ethdev.c | 34 +++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)
lib/ethdev/rte_ethdev.c +17 -17
index daf5ca9242..1d3b960305 100644
@@ -2750,24 +2750,24 @@ rte_eth_link_get_nowait(uint16_t port_id, struct rte_eth_link *eth_link)
 const char *
 rte_eth_link_speed_to_str(uint32_t link_speed)
 {
-	switch (link_speed) {
-	case ETH_SPEED_NUM_NONE: return "None";
-	case ETH_SPEED_NUM_10M:  return "10 Mbps";
-	case ETH_SPEED_NUM_100M: return "100 Mbps";
-	case ETH_SPEED_NUM_1G:   return "1 Gbps";
-	case ETH_SPEED_NUM_2_5G: return "2.5 Gbps";
-	case ETH_SPEED_NUM_5G:   return "5 Gbps";
-	case ETH_SPEED_NUM_10G:  return "10 Gbps";
-	case ETH_SPEED_NUM_20G:  return "20 Gbps";
-	case ETH_SPEED_NUM_25G:  return "25 Gbps";
-	case ETH_SPEED_NUM_40G:  return "40 Gbps";
-	case ETH_SPEED_NUM_50G:  return "50 Gbps";
-	case ETH_SPEED_NUM_56G:  return "56 Gbps";
-	case ETH_SPEED_NUM_100G: return "100 Gbps";
-	case ETH_SPEED_NUM_200G: return "200 Gbps";
-	case ETH_SPEED_NUM_UNKNOWN: return "Unknown";
-	default: return "Invalid";
+#define SPEED_STRING_LEN 16
+	static char name[SPEED_STRING_LEN];
+
+	if (link_speed == ETH_SPEED_NUM_NONE)
+		return "None";
+	if (link_speed == ETH_SPEED_NUM_UNKNOWN)
+		return "Unknown";
+	if (link_speed < ETH_SPEED_NUM_1G) {
+		snprintf(name, sizeof(name), "%u Mbps", link_speed);
+	} else if (link_speed % ETH_SPEED_NUM_1G != 0) {
+		snprintf(name, sizeof(name), "%.1f Gbps",
+		(double)link_speed / ETH_SPEED_NUM_1G);
+	} else {
+		snprintf(name, sizeof(name), "%u Gbps",
+		link_speed / ETH_SPEED_NUM_1G);
 	}
+
+	return (const char *)name;
 }
 
 int
Signature · 1 line
2.33.0
#6 lore raw

Re: [dpdk-dev] [RFC] ethdev: improve link speed to string

Quoted 28 lines · Min Hu (Connor)

Currently, link speed to string only supports specific speeds, like 10M, 100M, 1G etc.

This patch expands support for any link speed which is over 1M and one decimal place will kept for display at most.

---
 lib/ethdev/rte_ethdev.c | 34 +++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)
lib/ethdev/rte_ethdev.c +0 -9
index daf5ca9242..1d3b960305 100644
@@ -2750,24 +2750,24 @@ rte_eth_link_get_nowait(uint16_t port_id, struct rte_eth_link *eth_link)
 const char *
 rte_eth_link_speed_to_str(uint32_t link_speed)
 {
-	switch (link_speed) {
-	case ETH_SPEED_NUM_NONE: return "None";
-	case ETH_SPEED_NUM_10M:  return "10 Mbps";
-	case ETH_SPEED_NUM_100M: return "100 Mbps";
-	case ETH_SPEED_NUM_1G:   return "1 Gbps";
-	case ETH_SPEED_NUM_2_5G: return "2.5 Gbps";
-	case ETH_SPEED_NUM_5G:   return "5 Gbps";
-	case ETH_SPEED_NUM_10G:  return "10 Gbps";
-	case ETH_SPEED_NUM_20G:  return "20 Gbps";

lib/ethdev/rte_ethdev.c rte_eth_link_get_nowait(uint16_t port_id, struct rte_eth_link *eth_link) · line 2754

Quoted 10 lines
lib/ethdev/rte_ethdev.c +2 -8
-	case ETH_SPEED_NUM_25G:  return "25 Gbps";
-	case ETH_SPEED_NUM_40G:  return "40 Gbps";
-	case ETH_SPEED_NUM_50G:  return "50 Gbps";
-	case ETH_SPEED_NUM_56G:  return "56 Gbps";
-	case ETH_SPEED_NUM_100G: return "100 Gbps";
-	case ETH_SPEED_NUM_200G: return "200 Gbps";
-	case ETH_SPEED_NUM_UNKNOWN: return "Unknown";
-	default: return "Invalid";
+#define SPEED_STRING_LEN 16
+	static char name[SPEED_STRING_LEN];

NACK

Nothing good will happen if you try to use the function to print two different link speeds in one log message.

Quoted 20 lines
lib/ethdev/rte_ethdev.c +15 -0
+
+	if (link_speed == ETH_SPEED_NUM_NONE)
+		return "None";
+	if (link_speed == ETH_SPEED_NUM_UNKNOWN)
+		return "Unknown";
+	if (link_speed < ETH_SPEED_NUM_1G) {
+		snprintf(name, sizeof(name), "%u Mbps", link_speed);
+	} else if (link_speed % ETH_SPEED_NUM_1G != 0) {
+		snprintf(name, sizeof(name), "%.1f Gbps",
+		(double)link_speed / ETH_SPEED_NUM_1G);
+	} else {
+		snprintf(name, sizeof(name), "%u Gbps",
+		link_speed / ETH_SPEED_NUM_1G);
 	}
+
+	return (const char *)name;
 }
 
 int
#7 lore raw

Re: [dpdk-dev] [RFC] ethdev: improve link speed to string

Hi, Andrew,

Quoted 42 lines · Andrew Rybchenko
Quoted 28 lines · Min Hu (Connor)

Currently, link speed to string only supports specific speeds, like 10M, 100M, 1G etc.

This patch expands support for any link speed which is over 1M and one decimal place will kept for display at most.

---
  lib/ethdev/rte_ethdev.c | 34 +++++++++++++++++-----------------
  1 file changed, 17 insertions(+), 17 deletions(-)
lib/ethdev/rte_ethdev.c +0 -9
index daf5ca9242..1d3b960305 100644
@@ -2750,24 +2750,24 @@ rte_eth_link_get_nowait(uint16_t port_id, struct rte_eth_link *eth_link)
  const char *
  rte_eth_link_speed_to_str(uint32_t link_speed)
  {
-	switch (link_speed) {
-	case ETH_SPEED_NUM_NONE: return "None";
-	case ETH_SPEED_NUM_10M:  return "10 Mbps";
-	case ETH_SPEED_NUM_100M: return "100 Mbps";
-	case ETH_SPEED_NUM_1G:   return "1 Gbps";
-	case ETH_SPEED_NUM_2_5G: return "2.5 Gbps";
-	case ETH_SPEED_NUM_5G:   return "5 Gbps";
-	case ETH_SPEED_NUM_10G:  return "10 Gbps";
-	case ETH_SPEED_NUM_20G:  return "20 Gbps";

lib/ethdev/rte_ethdev.c rte_eth_link_get_nowait(uint16_t port_id, struct rte_eth_link *eth_link) · line 2754

Quoted 10 lines
lib/ethdev/rte_ethdev.c +2 -8
-	case ETH_SPEED_NUM_25G:  return "25 Gbps";
-	case ETH_SPEED_NUM_40G:  return "40 Gbps";
-	case ETH_SPEED_NUM_50G:  return "50 Gbps";
-	case ETH_SPEED_NUM_56G:  return "56 Gbps";
-	case ETH_SPEED_NUM_100G: return "100 Gbps";
-	case ETH_SPEED_NUM_200G: return "200 Gbps";
-	case ETH_SPEED_NUM_UNKNOWN: return "Unknown";
-	default: return "Invalid";
+#define SPEED_STRING_LEN 16
+	static char name[SPEED_STRING_LEN];

NACK

Quoted 2 lines

Nothing good will happen if you try to use the function to print two different link speeds in one log message.

You are right.
And use malloc for "name" will result in memory leakage, which is also not a good option.

BTW, do you think if we need to modify the function "rte_eth_link_speed_to_str"?

Quoted 24 lines
Quoted 11 lines
lib/ethdev/rte_ethdev.c +9 -0
+
+	if (link_speed == ETH_SPEED_NUM_NONE)
+		return "None";
+	if (link_speed == ETH_SPEED_NUM_UNKNOWN)
+		return "Unknown";
+	if (link_speed < ETH_SPEED_NUM_1G) {
+		snprintf(name, sizeof(name), "%u Mbps", link_speed);
+	} else if (link_speed % ETH_SPEED_NUM_1G != 0) {
+		snprintf(name, sizeof(name), "%.1f Gbps",

lib/ethdev/rte_ethdev.c rte_eth_link_get_nowait(uint16_t port_id, struct rte_eth_link *eth_link) · line 2773

Quoted 10 lines
lib/ethdev/rte_ethdev.c +6 -0
+		(double)link_speed / ETH_SPEED_NUM_1G);
+	} else {
+		snprintf(name, sizeof(name), "%u Gbps",
+		link_speed / ETH_SPEED_NUM_1G);
  	}
+
+	return (const char *)name;
  }
 
  int

.

#8 lore raw

Re: [dpdk-dev] [RFC] ethdev: improve link speed to string

Quoted 46 lines · Min Hu (Connor)

Hi, Andrew,

Quoted 43 lines · Andrew Rybchenko
Quoted 31 lines · Min Hu (Connor)

Currently, link speed to string only supports specific speeds, like 10M, 100M, 1G etc.

This patch expands support for any link speed which is over 1M and one decimal place will kept for display at most.

---
  lib/ethdev/rte_ethdev.c | 34 +++++++++++++++++-----------------

  1 file changed, 17 insertions(+), 17 deletions(-)
lib/ethdev/rte_ethdev.c +0 -0
index daf5ca9242..1d3b960305 100644
@@ -2750,24 +2750,24 @@ rte_eth_link_get_nowait(uint16_t port_id,
 struct rte_eth_link *eth_link)

  const char *
  rte_eth_link_speed_to_str(uint32_t link_speed)
  {
-    switch (link_speed) {
-    case ETH_SPEED_NUM_NONE: return "None";
-    case ETH_SPEED_NUM_10M:  return "10 Mbps";
-    case ETH_SPEED_NUM_100M: return "100 Mbps";
-    case ETH_SPEED_NUM_1G:   return "1 Gbps";
-    case ETH_SPEED_NUM_2_5G: return "2.5 Gbps";
-    case ETH_SPEED_NUM_5G:   return "5 Gbps";
-    case ETH_SPEED_NUM_10G:  return "10 Gbps";
-    case ETH_SPEED_NUM_20G:  return "20 Gbps";
-    case ETH_SPEED_NUM_25G:  return "25 Gbps";
-    case ETH_SPEED_NUM_40G:  return "40 Gbps";

Quoted 8 lines

-    case ETH_SPEED_NUM_50G:  return "50 Gbps"; -    case ETH_SPEED_NUM_56G:  return "56 Gbps"; -    case ETH_SPEED_NUM_100G: return "100 Gbps"; -    case ETH_SPEED_NUM_200G: return "200 Gbps"; -    case ETH_SPEED_NUM_UNKNOWN: return "Unknown"; -    default: return "Invalid";
+#define SPEED_STRING_LEN 16
+    static char name[SPEED_STRING_LEN];

NACK

Quoted 8 lines
Quoted 2 lines

Nothing good will happen if you try to use the function to print two different link speeds in one log message.

You are right.
And use malloc for "name" will result in memory leakage, which is also not a good option.

BTW, do you think if we need to modify the function "rte_eth_link_speed_to_str"?

IMHO it would be more pain than gain in this case.

#9 lore raw

Re: [dpdk-dev] [RFC] ethdev: improve link speed to string

Agree with you. Thanks Andrew

Quoted 60 lines · Andrew Rybchenko
Quoted 46 lines · Min Hu (Connor)

Hi, Andrew,

Quoted 43 lines · Andrew Rybchenko
Quoted 29 lines · Min Hu (Connor)

Currently, link speed to string only supports specific speeds, like 10M, 100M, 1G etc.

This patch expands support for any link speed which is over 1M and one decimal place will kept for display at most.

---
   lib/ethdev/rte_ethdev.c | 34 +++++++++++++++++-----------------
   1 file changed, 17 insertions(+), 17 deletions(-)
lib/ethdev/rte_ethdev.c +0 -9
index daf5ca9242..1d3b960305 100644
@@ -2750,24 +2750,24 @@ rte_eth_link_get_nowait(uint16_t port_id,
 struct rte_eth_link *eth_link)
   const char *
   rte_eth_link_speed_to_str(uint32_t link_speed)
   {
-    switch (link_speed) {
-    case ETH_SPEED_NUM_NONE: return "None";
-    case ETH_SPEED_NUM_10M:  return "10 Mbps";
-    case ETH_SPEED_NUM_100M: return "100 Mbps";
-    case ETH_SPEED_NUM_1G:   return "1 Gbps";
-    case ETH_SPEED_NUM_2_5G: return "2.5 Gbps";
-    case ETH_SPEED_NUM_5G:   return "5 Gbps";
-    case ETH_SPEED_NUM_10G:  return "10 Gbps";
-    case ETH_SPEED_NUM_20G:  return "20 Gbps";

lib/ethdev/rte_ethdev.c rte_eth_link_get_nowait(uint16_t port_id, · line 2755

Quoted 10 lines
lib/ethdev/rte_ethdev.c +2 -8
-    case ETH_SPEED_NUM_25G:  return "25 Gbps";
-    case ETH_SPEED_NUM_40G:  return "40 Gbps";
-    case ETH_SPEED_NUM_50G:  return "50 Gbps";
-    case ETH_SPEED_NUM_56G:  return "56 Gbps";
-    case ETH_SPEED_NUM_100G: return "100 Gbps";
-    case ETH_SPEED_NUM_200G: return "200 Gbps";
-    case ETH_SPEED_NUM_UNKNOWN: return "Unknown";
-    default: return "Invalid";
+#define SPEED_STRING_LEN 16
+    static char name[SPEED_STRING_LEN];

NACK

Quoted 8 lines
Quoted 2 lines

Nothing good will happen if you try to use the function to print two different link speeds in one log message.

You are right.
And use malloc for "name" will result in memory leakage, which is also not a good option.

BTW, do you think if we need to modify the function "rte_eth_link_speed_to_str"?

IMHO it would be more pain than gain in this case.

.

#10 lore raw

Re: [dpdk-dev] [RFC] ethdev: improve link speed to string

Quoted 55 lines

From: dev [mailto:[email protected]] On Behalf Of Min Hu (Connor)
Sent: Friday, 17 September 2021 02.44

Agree with you. Thanks Andrew

Quoted 6 lines · Andrew Rybchenko
Quoted 5 lines · Min Hu (Connor)

Hi, Andrew,

Quoted 2 lines · Andrew Rybchenko
Quoted 1 line · Min Hu (Connor)

Currently, link speed to string only supports specific speeds,

like 10M,

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

100M, 1G etc.

This patch expands support for any link speed which is over 1M and

one

Quoted 38 lines
Quoted 38 lines
Quoted 38 lines
Quoted 25 lines

decimal place will kept for display at most.

---
   lib/ethdev/rte_ethdev.c | 34 +++++++++++++++++-----------------
   1 file changed, 17 insertions(+), 17 deletions(-)
lib/ethdev/rte_ethdev.c +0 -9
index daf5ca9242..1d3b960305 100644
@@ -2750,24 +2750,24 @@ rte_eth_link_get_nowait(uint16_t port_id,
 struct rte_eth_link *eth_link)
   const char *
   rte_eth_link_speed_to_str(uint32_t link_speed)
   {
-    switch (link_speed) {
-    case ETH_SPEED_NUM_NONE: return "None";
-    case ETH_SPEED_NUM_10M:  return "10 Mbps";
-    case ETH_SPEED_NUM_100M: return "100 Mbps";
-    case ETH_SPEED_NUM_1G:   return "1 Gbps";
-    case ETH_SPEED_NUM_2_5G: return "2.5 Gbps";
-    case ETH_SPEED_NUM_5G:   return "5 Gbps";
-    case ETH_SPEED_NUM_10G:  return "10 Gbps";
-    case ETH_SPEED_NUM_20G:  return "20 Gbps";

lib/ethdev/rte_ethdev.c rte_eth_link_get_nowait(uint16_t port_id, · line 2755

Quoted 10 lines
lib/ethdev/rte_ethdev.c +2 -8
-    case ETH_SPEED_NUM_25G:  return "25 Gbps";
-    case ETH_SPEED_NUM_40G:  return "40 Gbps";
-    case ETH_SPEED_NUM_50G:  return "50 Gbps";
-    case ETH_SPEED_NUM_56G:  return "56 Gbps";
-    case ETH_SPEED_NUM_100G: return "100 Gbps";
-    case ETH_SPEED_NUM_200G: return "200 Gbps";
-    case ETH_SPEED_NUM_UNKNOWN: return "Unknown";
-    default: return "Invalid";
+#define SPEED_STRING_LEN 16
+    static char name[SPEED_STRING_LEN];

NACK

Quoted 11 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

Nothing good will happen if you try to use the function to print two different link speeds in one log message.

You are right.
And use malloc for "name" will result in memory leakage, which is

also

Quoted 6 lines
Quoted 4 lines

not a good option.

BTW, do you think if we need to modify the function "rte_eth_link_speed_to_str"?

IMHO it would be more pain than gain in this case.

If ETH_SPEED_NUM_xyz values was an enum instead of #define, the default case could be removed from this switch, and the compiler would emit a warning if a new ETH_SPEED_NUM_xyz was introduced without adding a case for it in this function.

-Morten

#11 lore raw

Re: [dpdk-dev] [RFC] ethdev: improve link speed to string

Quoted 60 lines · Morten Brørup
Quoted 60 lines

From: dev [mailto:[email protected]] On Behalf Of Min Hu (Connor)
Sent: Friday, 17 September 2021 02.44

Agree with you. Thanks Andrew

Quoted 6 lines · Andrew Rybchenko
Quoted 5 lines · Min Hu (Connor)

Hi, Andrew,

Quoted 2 lines · Andrew Rybchenko
Quoted 1 line · Min Hu (Connor)

Currently, link speed to string only supports specific speeds,

like 10M,

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

100M, 1G etc.

This patch expands support for any link speed which is over 1M and

one

Quoted 38 lines
Quoted 38 lines
Quoted 38 lines
Quoted 25 lines

decimal place will kept for display at most.

---
    lib/ethdev/rte_ethdev.c | 34 +++++++++++++++++-----------------
    1 file changed, 17 insertions(+), 17 deletions(-)
lib/ethdev/rte_ethdev.c +0 -9
index daf5ca9242..1d3b960305 100644
@@ -2750,24 +2750,24 @@ rte_eth_link_get_nowait(uint16_t port_id,
 struct rte_eth_link *eth_link)
    const char *
    rte_eth_link_speed_to_str(uint32_t link_speed)
    {
-    switch (link_speed) {
-    case ETH_SPEED_NUM_NONE: return "None";
-    case ETH_SPEED_NUM_10M:  return "10 Mbps";
-    case ETH_SPEED_NUM_100M: return "100 Mbps";
-    case ETH_SPEED_NUM_1G:   return "1 Gbps";
-    case ETH_SPEED_NUM_2_5G: return "2.5 Gbps";
-    case ETH_SPEED_NUM_5G:   return "5 Gbps";
-    case ETH_SPEED_NUM_10G:  return "10 Gbps";
-    case ETH_SPEED_NUM_20G:  return "20 Gbps";

lib/ethdev/rte_ethdev.c rte_eth_link_get_nowait(uint16_t port_id, · line 2755

Quoted 10 lines
lib/ethdev/rte_ethdev.c +2 -8
-    case ETH_SPEED_NUM_25G:  return "25 Gbps";
-    case ETH_SPEED_NUM_40G:  return "40 Gbps";
-    case ETH_SPEED_NUM_50G:  return "50 Gbps";
-    case ETH_SPEED_NUM_56G:  return "56 Gbps";
-    case ETH_SPEED_NUM_100G: return "100 Gbps";
-    case ETH_SPEED_NUM_200G: return "200 Gbps";
-    case ETH_SPEED_NUM_UNKNOWN: return "Unknown";
-    default: return "Invalid";
+#define SPEED_STRING_LEN 16
+    static char name[SPEED_STRING_LEN];

NACK

Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

Nothing good will happen if you try to use the function to print two different link speeds in one log message.

You are right.
And use malloc for "name" will result in memory leakage, which is

also

Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines

not a good option.

BTW, do you think if we need to modify the function "rte_eth_link_speed_to_str"?

IMHO it would be more pain than gain in this case.

If ETH_SPEED_NUM_xyz values was an enum instead of #define, the default case could be removed from this switch, and the compiler would emit a warning if a new ETH_SPEED_NUM_xyz was introduced without adding a case for it in this function.

But, according to some coding standard, default case should be added in "switch case" syntax.

Quoted 3 lines

-Morten

#12 lore raw

Re: [dpdk-dev] [RFC] ethdev: improve link speed to string

In reply to Min Hu (Connor)
Quoted 55 lines · Min Hu (Connor)
Quoted 54 lines · Andrew Rybchenko
Quoted 53 lines · Min Hu (Connor)

Hi, Andrew,

Quoted 44 lines · Andrew Rybchenko
Quoted 32 lines · Min Hu (Connor)

Currently, link speed to string only supports specific speeds, like 10M,
100M, 1G etc.

This patch expands support for any link speed which is over 1M and one decimal place will kept for display at most.

---
   lib/ethdev/rte_ethdev.c | 34 +++++++++++++++++-----------------

   1 file changed, 17 insertions(+), 17 deletions(-)
lib/ethdev/rte_ethdev.c +0 -0
index daf5ca9242..1d3b960305 100644
@@ -2750,24 +2750,24 @@ rte_eth_link_get_nowait(uint16_t port_id,
 struct rte_eth_link *eth_link)

   const char *
   rte_eth_link_speed_to_str(uint32_t link_speed)
   {
-    switch (link_speed) {
-    case ETH_SPEED_NUM_NONE: return "None";
-    case ETH_SPEED_NUM_10M:  return "10 Mbps";
-    case ETH_SPEED_NUM_100M: return "100 Mbps";
-    case ETH_SPEED_NUM_1G:   return "1 Gbps";
-    case ETH_SPEED_NUM_2_5G: return "2.5 Gbps";
-    case ETH_SPEED_NUM_5G:   return "5 Gbps";
-    case ETH_SPEED_NUM_10G:  return "10 Gbps";
-    case ETH_SPEED_NUM_20G:  return "20 Gbps";
-    case ETH_SPEED_NUM_25G:  return "25 Gbps";
-    case ETH_SPEED_NUM_40G:  return "40 Gbps";

Quoted 8 lines

-    case ETH_SPEED_NUM_50G:  return "50 Gbps"; -    case ETH_SPEED_NUM_56G:  return "56 Gbps"; -    case ETH_SPEED_NUM_100G: return "100 Gbps"; -    case ETH_SPEED_NUM_200G: return "200 Gbps"; -    case ETH_SPEED_NUM_UNKNOWN: return "Unknown"; -    default: return "Invalid";
+#define SPEED_STRING_LEN 16
+    static char name[SPEED_STRING_LEN];

NACK

Quoted 2 lines

Nothing good will happen if you try to use the function to print two different link speeds in one log message.

You are right.
And use malloc for "name" will result in memory leakage, which is also not a good option.

Quoted 9 lines
Quoted 7 lines
Quoted 2 lines

BTW, do you think if we need to modify the function "rte_eth_link_speed_to_str"?

IMHO it would be more pain than gain in this case.

.

Agree with you. Thanks Andrew

It can be option to update the API as following in next ABI break release:

const char *
rte_eth_link_speed_to_str(uint32_t link_speed, char *buf, size_t buf_size);

For this a deprecation notice needs to be sent and approved, not sure though if it worth.

Meanwhile, what do you think to update string 'Invalid' to something like 'Irregular' or 'Erratic', does this help to convey the right message?

#13 lore raw

Re: [dpdk-dev] [RFC] ethdev: improve link speed to string

Quoted 21 lines · On Thu, 19 Jan 2023 11:41:12 +0000 Ferruh Yigit <[email protected]> wrote:
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

Nothing good will happen if you try to use the function to print two different link speeds in one log message.

You are right.
And use malloc for "name" will result in memory leakage, which is also not a good option.

Quoted 9 lines
Quoted 7 lines
Quoted 2 lines

BTW, do you think if we need to modify the function "rte_eth_link_speed_to_str"?

IMHO it would be more pain than gain in this case.

.

Agree with you. Thanks Andrew

It can be option to update the API as following in next ABI break release:

const char *
rte_eth_link_speed_to_str(uint32_t link_speed, char *buf, size_t buf_size);

Quoted 6 lines

For this a deprecation notice needs to be sent and approved, not sure though if it worth.

Meanwhile, what do you think to update string 'Invalid' to something like 'Irregular' or 'Erratic', does this help to convey the right message?

API versioning is possible here.

#14 lore raw

Re: [dpdk-dev] [RFC] ethdev: improve link speed to string

Quoted 28 lines · Stephen Hemminger
Quoted 25 lines · On Thu, 19 Jan 2023 11:41:12 +0000 Ferruh Yigit <[email protected]> wrote:
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

Nothing good will happen if you try to use the function to print two different link speeds in one log message.

You are right.
And use malloc for "name" will result in memory leakage, which is also not a good option.

Quoted 9 lines
Quoted 7 lines
Quoted 2 lines

BTW, do you think if we need to modify the function "rte_eth_link_speed_to_str"?

IMHO it would be more pain than gain in this case.

.

Agree with you. Thanks Andrew

It can be option to update the API as following in next ABI break release:

const char *
rte_eth_link_speed_to_str(uint32_t link_speed, char *buf, size_t buf_size);

For this a deprecation notice needs to be sent and approved, not sure though if it worth.

Quoted 5 lines
Quoted 2 lines

Meanwhile, what do you think to update string 'Invalid' to something like 'Irregular' or 'Erratic', does this help to convey the right message?

API versioning is possible here.

Agree, ABI versioning can be used here.

@Connor, what do you think?

#15 lore raw

Re: [dpdk-dev] [RFC] ethdev: improve link speed to string

Quoted 33 lines · Ferruh Yigit
Quoted 32 lines · Stephen Hemminger
Quoted 27 lines · On Thu, 19 Jan 2023 11:41:12 +0000 Ferruh Yigit <[email protected]> wrote:
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

Nothing good will happen if you try to use the function to print two different link speeds in one log message.

You are right.
And use malloc for "name" will result in memory leakage, which is also not a good option.

Quoted 9 lines
Quoted 7 lines
Quoted 2 lines

BTW, do you think if we need to modify the function "rte_eth_link_speed_to_str"?

IMHO it would be more pain than gain in this case.

.

Agree with you. Thanks Andrew

It can be option to update the API as following in next ABI break release:

const char *
rte_eth_link_speed_to_str(uint32_t link_speed, char *buf, size_t buf_size);

For this a deprecation notice needs to be sent and approved, not sure though if it worth.

Meanwhile, what do you think to update string 'Invalid' to something like 'Irregular' or 'Erratic', does this help to convey the right message?

Quoted 6 lines
Quoted 1 line

API versioning is possible here.

Agree, ABI versioning can be used here.

@Connor, what do you think?

Updating patch status as rejected, if you still pursue the feature please send a separate patch that updates the API via ABI versioning.

Thanks,
ferruh