netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Using rates in bits when limits are specified in %
@ 2019-02-06 17:14 Marcos Antonio Moraes
  0 siblings, 0 replies; 4+ messages in thread
From: Marcos Antonio Moraes @ 2019-02-06 17:14 UTC (permalink / raw)
  To: netdev; +Cc: Marcos Antonio Moraes

As /sys/class/net/<iface>/speed indicates a value in Mbits/sec, the
transformation is necessary to create the correct limitations.
---
 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 ab717890..b82142ab 100644
--- a/tc/tc_util.c
+++ b/tc/tc_util.c
@@ -194,7 +194,7 @@ static int parse_percent_rate(char *rate, const char *str, const char *dev)
 {
 	long dev_mbit;
 	int ret;
-	double perc, rate_mbit;
+	double perc, rate_bit;
 	char *str_perc;
 
 	if (!dev[0]) {
@@ -219,9 +219,9 @@ static int parse_percent_rate(char *rate, const char *str, const char *dev)
 		return -1;
 	}
 
-	rate_mbit = perc * dev_mbit;
+	rate_bit = perc * dev_mbit * 1000 * 1000;
 
-	ret = snprintf(rate, 20, "%lf", rate_mbit);
+	ret = snprintf(rate, 20, "%lf", rate_bit);
 	if (ret <= 0 || ret >= 20) {
 		fprintf(stderr, "Unable to parse calculated rate\n");
 		return -1;
-- 
2.17.1


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

* Re: [PATCH] Using rates in bits when limits are specified in %
  2019-02-06 18:51 ` Stephen Hemminger
@ 2019-02-07 12:46   ` Marcos Antonio
  0 siblings, 0 replies; 4+ messages in thread
From: Marcos Antonio @ 2019-02-07 12:46 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: netdev


Em 06/02/2019 16:51, Stephen Hemminger escreveu:
> On Wed,  6 Feb 2019 16:09:13 -0200
> Marcos Antonio Moraes <marcos.antonio@digirati.com.br> wrote:
>
>> As /sys/class/net/<iface>/speed indicates a value in Mbits/sec, the
>> transformation is necessary to create the correct limitations.
> Not sure, if this is correct or not could you give an example?

Sure.

With an interface with 1000 Mbits/sec speed, the following commands are 
expected to create the same result:

`tc class add dev enp0s3 parent 1:0 classid 1:1 htb rate 500Mbit`

`tc class add dev enp0s3 parent 1:0 classid 1:1 htb rate 50%`

The first command creates the correct class:

     class htb 1:1 root prio 0 rate 500Mbit ceil 500Mbit burst 1500b 
cburst 1500b

The second one should do the same, instead of creating a class like this:

     class htb 1:1 root prio 0 rate 496bit ceil 496bit burst 1599b 
cburst 1599b

This happens because after parse_percent_rate(), get_rate() (or 
get_rate64()) is called, and it expects to treat the value with the unit 
suffix. And the value read from /sys/class/net/<iface>/speed is in 
Mbit/sec but does not include the unit. Converting the unity from mbit 
to bit would solve the problem.

>
> This patch needs a signed-off-by and a a Fixes tag.
>
> Also please put iproute2 in subject line:
>
> [PATCH iproute2] tc: use bits not mbits/sec in rate percent.
>
> Also, please rebase since I just found a memory leak in this function.
I'll provide a patch with this adjustments.
>
> 	

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

* Re: [PATCH] Using rates in bits when limits are specified in %
  2019-02-06 18:09 Marcos Antonio Moraes
@ 2019-02-06 18:51 ` Stephen Hemminger
  2019-02-07 12:46   ` Marcos Antonio
  0 siblings, 1 reply; 4+ messages in thread
From: Stephen Hemminger @ 2019-02-06 18:51 UTC (permalink / raw)
  To: Marcos Antonio Moraes; +Cc: netdev

On Wed,  6 Feb 2019 16:09:13 -0200
Marcos Antonio Moraes <marcos.antonio@digirati.com.br> wrote:

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

Not sure, if this is correct or not could you give an example?

This patch needs a signed-off-by and a a Fixes tag.

Also please put iproute2 in subject line:

[PATCH iproute2] tc: use bits not mbits/sec in rate percent.

Also, please rebase since I just found a memory leak in this function.

	

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

* [PATCH] Using rates in bits when limits are specified in %
@ 2019-02-06 18:09 Marcos Antonio Moraes
  2019-02-06 18:51 ` Stephen Hemminger
  0 siblings, 1 reply; 4+ messages in thread
From: Marcos Antonio Moraes @ 2019-02-06 18:09 UTC (permalink / raw)
  To: netdev; +Cc: Marcos Antonio Moraes

As /sys/class/net/<iface>/speed indicates a value in Mbits/sec, the
transformation is necessary to create the correct limitations.
---
 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 ab717890..b82142ab 100644
--- a/tc/tc_util.c
+++ b/tc/tc_util.c
@@ -194,7 +194,7 @@ static int parse_percent_rate(char *rate, const char *str, const char *dev)
 {
 	long dev_mbit;
 	int ret;
-	double perc, rate_mbit;
+	double perc, rate_bit;
 	char *str_perc;
 
 	if (!dev[0]) {
@@ -219,9 +219,9 @@ static int parse_percent_rate(char *rate, const char *str, const char *dev)
 		return -1;
 	}
 
-	rate_mbit = perc * dev_mbit;
+	rate_bit = perc * dev_mbit * 1000 * 1000;
 
-	ret = snprintf(rate, 20, "%lf", rate_mbit);
+	ret = snprintf(rate, 20, "%lf", rate_bit);
 	if (ret <= 0 || ret >= 20) {
 		fprintf(stderr, "Unable to parse calculated rate\n");
 		return -1;
-- 
2.17.1


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

end of thread, other threads:[~2019-02-07 12:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-06 17:14 [PATCH] Using rates in bits when limits are specified in % Marcos Antonio Moraes
2019-02-06 18:09 Marcos Antonio Moraes
2019-02-06 18:51 ` Stephen Hemminger
2019-02-07 12:46   ` Marcos Antonio

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).