From: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
To: "Min Hu (Connor)" <humin29@huawei.com>, dev@dpdk.org
Cc: ferruh.yigit@intel.com, thomas@monjalon.net
Subject: Re: [dpdk-dev] [RFC] ethdev: improve link speed to string
Date: Thu, 16 Sep 2021 09:22:17 +0300 [thread overview]
Message-ID: <080fa0c3-c518-0e7f-f6d5-146dc9430d27@oktetlabs.ru> (raw)
In-Reply-To: <20210916025636.48024-1-humin29@huawei.com>
On 9/16/21 5:56 AM, Min Hu (Connor) wrote:
> 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.
>
> Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
> ---
> lib/ethdev/rte_ethdev.c | 34 +++++++++++++++++-----------------
> 1 file changed, 17 insertions(+), 17 deletions(-)
>
> diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c
> index daf5ca9242..1d3b960305 100644
> --- a/lib/ethdev/rte_ethdev.c
> +++ b/lib/ethdev/rte_ethdev.c
> @@ -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];
NACK
Nothing good will happen if you try to use the function to
print two different link speeds in one log message.
> +
> + 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
>
next prev parent reply other threads:[~2021-09-16 6:22 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-13 8:45 [dpdk-dev] Questions about rte_eth_link_speed_to_str API Min Hu (Connor)
2021-09-13 10:26 ` Thomas Monjalon
2021-09-14 3:25 ` Min Hu (Connor)
2021-09-14 6:59 ` Stephen Hemminger
2021-09-14 13:04 ` Min Hu (Connor)
2021-09-16 2:56 ` [dpdk-dev] [RFC] ethdev: improve link speed to string Min Hu (Connor)
2021-09-16 6:22 ` Andrew Rybchenko [this message]
2021-09-16 8:16 ` Min Hu (Connor)
2021-09-16 8:21 ` Andrew Rybchenko
2021-09-17 0:43 ` Min Hu (Connor)
2021-10-30 9:59 ` Morten Brørup
2021-11-01 0:23 ` Min Hu (Connor)
2023-01-19 11:41 ` Ferruh Yigit
2023-01-19 16:45 ` Stephen Hemminger
2023-02-10 14:41 ` Ferruh Yigit
2023-03-23 14:40 ` Ferruh Yigit
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=080fa0c3-c518-0e7f-f6d5-146dc9430d27@oktetlabs.ru \
--to=andrew.rybchenko@oktetlabs.ru \
--cc=dev@dpdk.org \
--cc=ferruh.yigit@intel.com \
--cc=humin29@huawei.com \
--cc=thomas@monjalon.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).