netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] dcb: fix tc-maxrate unit conversions
@ 2025-10-08  3:16 Yijing Zeng
  2025-10-09 16:01 ` Petr Machata
  2025-10-11 22:25 ` [PATCH v2] " Yijing Zeng
  0 siblings, 2 replies; 4+ messages in thread
From: Yijing Zeng @ 2025-10-08  3:16 UTC (permalink / raw)
  To: netdev; +Cc: stephen, me, kuba, yijingzeng

From: Yijing Zeng <yijingzeng@meta.com>

The ieee_maxrate UAPI is defined as kbps, but dcb_maxrate uses Bps.
This fix patch converts Bps to kbps for parse, and convert kbps to Bps for print_rate().

Fixes: 117939d9 ("dcb: Add a subtool for the DCB maxrate object")
Signed-off-by: Yijing Zeng <yijingzeng@meta.com>
---
 dcb/dcb_maxrate.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/dcb/dcb_maxrate.c b/dcb/dcb_maxrate.c
index 1538c6d7..af012dba 100644
--- a/dcb/dcb_maxrate.c
+++ b/dcb/dcb_maxrate.c
@@ -42,13 +42,16 @@ static void dcb_maxrate_help(void)
 
 static int dcb_maxrate_parse_mapping_tc_maxrate(__u32 key, char *value, void *data)
 {
-	__u64 rate;
+	__u64 rate_Bps;
 
-	if (get_rate64(&rate, value))
+	if (get_rate64(&rate_Bps, value))
 		return -EINVAL;
 
+	/* get_rate64() returns Bps. ieee_maxrate UAPI expects kbps. */
+	__u64 rate_kbps = (rate_Bps * 8) / 1000;
+
 	return dcb_parse_mapping("TC", key, IEEE_8021QAZ_MAX_TCS - 1,
-				 "RATE", rate, -1,
+				 "RATE", rate_kbps, -1,
 				 dcb_set_u64, data);
 }
 
@@ -62,8 +65,11 @@ static void dcb_maxrate_print_tc_maxrate(struct dcb *dcb, const struct ieee_maxr
 	print_string(PRINT_FP, NULL, "tc-maxrate ", NULL);
 
 	for (i = 0; i < size; i++) {
+		/* ieee_maxrate UAPI returns kbps. print_rate() expects Bps for display */
+		__u64 rate_Bps  = maxrate->tc_maxrate[i] * 1000 / 8;
+
 		snprintf(b, sizeof(b), "%zd:%%s ", i);
-		print_rate(dcb->use_iec, PRINT_ANY, NULL, b, maxrate->tc_maxrate[i]);
+		print_rate(dcb->use_iec, PRINT_ANY, NULL, b, rate_Bps);
 	}
 
 	close_json_array(PRINT_JSON, "tc_maxrate");
-- 
2.50.1


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

* Re: [PATCH] dcb: fix tc-maxrate unit conversions
  2025-10-08  3:16 [PATCH] dcb: fix tc-maxrate unit conversions Yijing Zeng
@ 2025-10-09 16:01 ` Petr Machata
  2025-10-11 22:25 ` [PATCH v2] " Yijing Zeng
  1 sibling, 0 replies; 4+ messages in thread
From: Petr Machata @ 2025-10-09 16:01 UTC (permalink / raw)
  To: Yijing Zeng; +Cc: netdev, stephen, me, kuba, yijingzeng


Yijing Zeng <zengyijing19900106@gmail.com> writes:

> From: Yijing Zeng <yijingzeng@meta.com>
>
> The ieee_maxrate UAPI is defined as kbps, but dcb_maxrate uses Bps.

Hmm, indeed, "values are 64 bits long and specified in Kbps to enable
usage over both slow and very fast networks". Good catch.

I think that if anyone actually tried to use this in the wild, the issue
would have been discovered and reported already, so this might be
actually safe to fix without breaking the world.

Thanks for the patch. I have a number of relatively minor coding style
points. Please correct them and send v2. You may want to pass the
candidate patch through checkpatch:

 # ../linux-source/scripts/checkpatch.pl --max-line-length=80 the.patch

> This fix patch converts Bps to kbps for parse, and convert kbps to Bps for print_rate().

Please wrap this line to 75 characters.

> Fixes: 117939d9 ("dcb: Add a subtool for the DCB maxrate object")

This should show 12 characters of the hash.

> Signed-off-by: Yijing Zeng <yijingzeng@meta.com>
> ---
>  dcb/dcb_maxrate.c | 14 ++++++++++----
>  1 file changed, 10 insertions(+), 4 deletions(-)
>
> diff --git a/dcb/dcb_maxrate.c b/dcb/dcb_maxrate.c
> index 1538c6d7..af012dba 100644
> --- a/dcb/dcb_maxrate.c
> +++ b/dcb/dcb_maxrate.c
> @@ -42,13 +42,16 @@ static void dcb_maxrate_help(void)
>  
>  static int dcb_maxrate_parse_mapping_tc_maxrate(__u32 key, char *value, void *data)
>  {
> -	__u64 rate;
> +	__u64 rate_Bps;

Lowercase this, please.

>  
> -	if (get_rate64(&rate, value))
> +	if (get_rate64(&rate_Bps, value))
>  		return -EINVAL;
>  
> +	/* get_rate64() returns Bps. ieee_maxrate UAPI expects kbps. */
> +	__u64 rate_kbps = (rate_Bps * 8) / 1000;

Keep all the declarations at the top of the function, please.
Make sure they are ordered longest line to shortest (RXT, reverse xmass tree).

There's a small concern regarding the * 8 overflowing (likewise * 1000
below). But it's u64, I don't feel like we need to really worry about it.

> +
>  	return dcb_parse_mapping("TC", key, IEEE_8021QAZ_MAX_TCS - 1,
> -				 "RATE", rate, -1,
> +				 "RATE", rate_kbps, -1,
>  				 dcb_set_u64, data);
>  }
>  
> @@ -62,8 +65,11 @@ static void dcb_maxrate_print_tc_maxrate(struct dcb *dcb, const struct ieee_maxr
>  	print_string(PRINT_FP, NULL, "tc-maxrate ", NULL);
>  
>  	for (i = 0; i < size; i++) {
> +		/* ieee_maxrate UAPI returns kbps. print_rate() expects Bps for display */

This line is too long.

> +		__u64 rate_Bps  = maxrate->tc_maxrate[i] * 1000 / 8;

This variable can stay here, it's start of the block, but it should be
lowercased.

>  		snprintf(b, sizeof(b), "%zd:%%s ", i);
> -		print_rate(dcb->use_iec, PRINT_ANY, NULL, b, maxrate->tc_maxrate[i]);
> +		print_rate(dcb->use_iec, PRINT_ANY, NULL, b, rate_Bps);
>  	}
>  
>  	close_json_array(PRINT_JSON, "tc_maxrate");

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

* [PATCH v2] dcb: fix tc-maxrate unit conversions
  2025-10-08  3:16 [PATCH] dcb: fix tc-maxrate unit conversions Yijing Zeng
  2025-10-09 16:01 ` Petr Machata
@ 2025-10-11 22:25 ` Yijing Zeng
  2025-10-16 22:10   ` patchwork-bot+netdevbpf
  1 sibling, 1 reply; 4+ messages in thread
From: Yijing Zeng @ 2025-10-11 22:25 UTC (permalink / raw)
  To: netdev; +Cc: stephen, me, kuba, yijingzeng

From: Yijing Zeng <yijingzeng@meta.com>

The ieee_maxrate UAPI is defined as kbps, but dcb_maxrate uses Bps.
This fix patch converts Bps to kbps for parse by dividing 125,
and convert kbps to Bps for print_rate() by multiplying 125.

Fixes: 117939d9bd89 ("dcb: Add a subtool for the DCB maxrate object")
Signed-off-by: Yijing Zeng <yijingzeng@meta.com>
---
v2:
  - Address style comments
  - Avoid potential overflow

 dcb/dcb_maxrate.c | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/dcb/dcb_maxrate.c b/dcb/dcb_maxrate.c
index 1538c6d7..8c5a7e55 100644
--- a/dcb/dcb_maxrate.c
+++ b/dcb/dcb_maxrate.c
@@ -42,13 +42,20 @@ static void dcb_maxrate_help(void)
 
 static int dcb_maxrate_parse_mapping_tc_maxrate(__u32 key, char *value, void *data)
 {
-	__u64 rate;
+	__u64 rate_bytes_per_sec;
+	__u64 rate_kbits_per_sec;
 
-	if (get_rate64(&rate, value))
+	if (get_rate64(&rate_bytes_per_sec, value))
 		return -EINVAL;
 
+	/* get_rate64() returns Bps.
+	 * ieee_maxrate UAPI expects kbps.
+	 * convert Bps to kbps by dividing 125.
+	 */
+	rate_kbits_per_sec = rate_bytes_per_sec / 125;
+
 	return dcb_parse_mapping("TC", key, IEEE_8021QAZ_MAX_TCS - 1,
-				 "RATE", rate, -1,
+				 "RATE", rate_kbits_per_sec, -1,
 				 dcb_set_u64, data);
 }
 
@@ -62,8 +69,14 @@ static void dcb_maxrate_print_tc_maxrate(struct dcb *dcb, const struct ieee_maxr
 	print_string(PRINT_FP, NULL, "tc-maxrate ", NULL);
 
 	for (i = 0; i < size; i++) {
+		/* ieee_maxrate UAPI returns kbps.
+		 * print_rate() expects Bps for display.
+		 * convert kbps to Bps by multiplying 125.
+		 */
+		__u64 rate_bytes_per_sec  = maxrate->tc_maxrate[i] * 125;
+
 		snprintf(b, sizeof(b), "%zd:%%s ", i);
-		print_rate(dcb->use_iec, PRINT_ANY, NULL, b, maxrate->tc_maxrate[i]);
+		print_rate(dcb->use_iec, PRINT_ANY, NULL, b, rate_bytes_per_sec);
 	}
 
 	close_json_array(PRINT_JSON, "tc_maxrate");
-- 
2.50.1


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

* Re: [PATCH v2] dcb: fix tc-maxrate unit conversions
  2025-10-11 22:25 ` [PATCH v2] " Yijing Zeng
@ 2025-10-16 22:10   ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-10-16 22:10 UTC (permalink / raw)
  To: Yijing Zeng; +Cc: netdev, stephen, me, kuba, yijingzeng

Hello:

This patch was applied to iproute2/iproute2.git (main)
by Stephen Hemminger <stephen@networkplumber.org>:

On Sat, 11 Oct 2025 15:25:24 -0700 you wrote:
> From: Yijing Zeng <yijingzeng@meta.com>
> 
> The ieee_maxrate UAPI is defined as kbps, but dcb_maxrate uses Bps.
> This fix patch converts Bps to kbps for parse by dividing 125,
> and convert kbps to Bps for print_rate() by multiplying 125.
> 
> Fixes: 117939d9bd89 ("dcb: Add a subtool for the DCB maxrate object")
> Signed-off-by: Yijing Zeng <yijingzeng@meta.com>
> 
> [...]

Here is the summary with links:
  - [v2] dcb: fix tc-maxrate unit conversions
    https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=af33b4800265

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2025-10-16 22:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-08  3:16 [PATCH] dcb: fix tc-maxrate unit conversions Yijing Zeng
2025-10-09 16:01 ` Petr Machata
2025-10-11 22:25 ` [PATCH v2] " Yijing Zeng
2025-10-16 22:10   ` patchwork-bot+netdevbpf

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