All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH iproute2] tc: use bits not mbits/sec in rate percent
@ 2019-02-07 15:29 Marcos Antonio Moraes
  2019-02-08 18:01 ` Stephen Hemminger
  0 siblings, 1 reply; 2+ messages in thread
From: Marcos Antonio Moraes @ 2019-02-07 15:29 UTC (permalink / raw)
  To: netdev; +Cc: Marcos Antonio Moraes

As /sys/class/net/<iface>/speed indicates a value in Mbits/sec, the
conversion is necessary to create the correct limits.

This guarantees the same result for the following commands in an
1000Mbit/sec device:

tc class add ... htb rate 500Mbit
tc class add ... htb rate 50%

Fixes: 927e3cfb52b5 ("tc: B.W limits can now be specified in %.")
Signed-off-by: Marcos Antonio Moraes <marcos.antonio@digirati.com.br>
---
 tc/tc_util.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tc/tc_util.c b/tc/tc_util.c
index 4e289ae9..07216fba 100644
--- a/tc/tc_util.c
+++ b/tc/tc_util.c
@@ -195,7 +195,7 @@ static int parse_percent_rate(char *rate, size_t len,
 {
 	long dev_mbit;
 	int ret;
-	double perc, rate_mbit;
+	double perc, rate_bit;
 	char *str_perc = NULL;
 
 	if (!dev[0]) {
@@ -220,9 +220,9 @@ static int parse_percent_rate(char *rate, size_t len,
 		return -1;
 	}
 
-	rate_mbit = perc * dev_mbit;
+	rate_bit = perc * dev_mbit * 1000 * 1000;
 
-	ret = snprintf(rate, len, "%lf", rate_mbit);
+	ret = snprintf(rate, len, "%lf", rate_bit);
 	if (ret <= 0 || ret >= len) {
 		fprintf(stderr, "Unable to parse calculated rate\n");
 		return -1;
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH iproute2] tc: use bits not mbits/sec in rate percent
  2019-02-07 15:29 [PATCH iproute2] tc: use bits not mbits/sec in rate percent Marcos Antonio Moraes
@ 2019-02-08 18:01 ` Stephen Hemminger
  0 siblings, 0 replies; 2+ messages in thread
From: Stephen Hemminger @ 2019-02-08 18:01 UTC (permalink / raw)
  To: Marcos Antonio Moraes; +Cc: netdev

On Thu,  7 Feb 2019 13:29:54 -0200
Marcos Antonio Moraes <marcos.antonio@digirati.com.br> wrote:

> As /sys/class/net/<iface>/speed indicates a value in Mbits/sec, the
> conversion is necessary to create the correct limits.
> 
> This guarantees the same result for the following commands in an
> 1000Mbit/sec device:
> 
> tc class add ... htb rate 500Mbit
> tc class add ... htb rate 50%
> 
> Fixes: 927e3cfb52b5 ("tc: B.W limits can now be specified in %.")
> Signed-off-by: Marcos Antonio Moraes <marcos.antonio@digirati.com.br>

Sure applied.



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-02-08 18:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-07 15:29 [PATCH iproute2] tc: use bits not mbits/sec in rate percent Marcos Antonio Moraes
2019-02-08 18:01 ` Stephen Hemminger

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.