From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 3DF58A0C47; Tue, 14 Sep 2021 08:59:07 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A55A94068F; Tue, 14 Sep 2021 08:59:06 +0200 (CEST) Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) by mails.dpdk.org (Postfix) with ESMTP id 31D1C4003C for ; Tue, 14 Sep 2021 08:59:05 +0200 (CEST) Received: by mail-pj1-f41.google.com with SMTP id k23so8202587pji.0 for ; Mon, 13 Sep 2021 23:59:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uQR2ToEoifB+DPYCKZ48up1gp84AJNLvK1hJieuQtJg=; b=JGeW3iA745WO/LT7kcev0pAgw71NoWAeNUuZrTZFTtpsRiBazy4BCEwlRahHL5ICgZ kQn93QoTSkVl2MAwkUR8PfAdsiJFrtsDHqBqxDswwk7i4Wy3goLCaosWH0Ht4rlWbALE 2N44Cds6wWtHLborUOtsJTNiSHx+Hryaq9WYv8BjL569XFKD3Fif309AvfylLwBeLAYB SgJja9Z/Ivw+Dw/7UyfI+TtmmJvNtwHEST6uWSNTmawxYUkZulL3PPugehTUo7Q8f+GS pMVttskY9GZzA5VDRj6kq6cSycCqUkhOBVrlq7pidnEOOzytD+tchbejjix19RrgHvec DvXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uQR2ToEoifB+DPYCKZ48up1gp84AJNLvK1hJieuQtJg=; b=WF0LcBVBQBzz7qN+dV3OiRktBwv699PjmPATglXrt1c/RypAQFuCHUglpYZVCK3GSf /UC5UVOdHaptwL32XV4wP/hdBqK+vchwJLbs2iHuJsGfuF/PIugD0aNuLc1QKcgxEKcy NLhtQrfIG8HYzPYJm1ntQvi9y1l2qQ1C96t915+6daTrEc/EKiRQT0SRdGX2IeP0mUS8 H9HbspR5rSUY8nAPpBwxpNaEIX99OESSwGXOrOtnzna2sWVldS/a1p0V6hkMIX+wgyej kbKixdi5oUsS2HQlsPBfv5emmfAnk34kuwnz3DsQddAJENe5J/Nf3mrVREbKdEyGzojN 0VwA== X-Gm-Message-State: AOAM532QKolABqP7FB4Wsi/UqaZ4KAc5uow0qeaMuC01V/IuYgI3WBJf b+FjsrbeQc2/3CMOb6yv6APPtA== X-Google-Smtp-Source: ABdhPJz4VjcrrX6eJ/k3r/++7pgPvlpJSfpISgt5reNGHcdzQTnH02rpWeHK6HRJmTzEVm6zRHmBaQ== X-Received: by 2002:a17:90b:3b84:: with SMTP id pc4mr400697pjb.220.1631602744111; Mon, 13 Sep 2021 23:59:04 -0700 (PDT) Received: from hermes.local (204-195-33-123.wavecable.com. [204.195.33.123]) by smtp.gmail.com with ESMTPSA id h24sm9419487pfn.180.2021.09.13.23.59.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Sep 2021 23:59:03 -0700 (PDT) Date: Mon, 13 Sep 2021 23:59:01 -0700 From: Stephen Hemminger To: "Min Hu (Connor)" Cc: Thomas Monjalon , "dev@dpdk.org" , Ferruh Yigit , Declan Doherty , Keith Wiles Message-ID: <20210913235901.25eb6df3@hermes.local> In-Reply-To: <89fa6c37-3ad0-f454-6ab3-cc47592ebba7@huawei.com> References: <29b75903-d212-c6e6-eedf-e3bc92ab816a@huawei.com> <3787620.G55ntfxAi9@thomas> <89fa6c37-3ad0-f454-6ab3-cc47592ebba7@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [dpdk-dev] Questions about rte_eth_link_speed_to_str API X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" On Tue, 14 Sep 2021 11:25:44 +0800 "Min Hu (Connor)" wrote: > Thanks Thomas, > I am not sure if we need to print combined slaves speed. > How about others' opinion ? @all >=20 > 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 =3D=3D ETH_SPEED_NUM_NONE) > + return "None"; > + if (link_speed =3D=3D 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; > +} >=20 > But the float value is difficult to handle, like 2.5 Gbps for show. Any=20 > advices? >=20 > =E5=9C=A8 2021/9/13 18:26, Thomas Monjalon =E5=86=99=E9=81=93: > > 13/09/2021 10:45, Min Hu (Connor): =20 > >> 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=EF=BC=9F any comments will be welcome. =20 > >=20 > > 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. > >=20 > >=20 > > . > > =20 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 c= olor, const char *key, const char *fmt, unsigned long long r= ate) { unsigned long kilo =3D use_iec ? 1024 : 1000; const char *str =3D use_iec ? "i" : ""; static char *units[5] =3D {"", "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 <<=3D 3; /* bytes/sec -> bits/sec */ for (i =3D 0; i < ARRAY_SIZE(units) - 1; i++) { if (rate < kilo) break; if (((rate % kilo) !=3D 0) && rate < 1000*kilo) break; rate /=3D kilo; } rc =3D asprintf(&buf, "%.0f%s%sbit", (double)rate, units[i], i > 0 ? str : ""); if (rc < 0) return -1; rc =3D print_color_string(type, color, key, fmt, buf); free(buf); } =20