mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] blk-iocost: don't make all constants unsigned long long
@ 2022-12-20 20:18 Yann Droneaud
  2022-12-22 13:58 ` Michal Koutný
  2023-01-04 22:16 ` Tejun Heo
  0 siblings, 2 replies; 5+ messages in thread
From: Yann Droneaud @ 2022-12-20 20:18 UTC (permalink / raw)
  To: Tejun Heo, Josef Bacik, Jens Axboe
  Cc: cgroups, linux-block, linux-kernel, Yann Droneaud

My shiny new compiler (GCC 13) is reporting the following
warnings:

  ../block/blk-iocost.c: In function 'ioc_weight_prfill':
  ../block/blk-iocost.c:3035:37: warning: format '%u' expects argument of type 'unsigned int', but argument 4 has type 'long unsigned int' [-Wformat=]
   3035 |                 seq_printf(sf, "%s %u\n", dname, iocg->cfg_weight / WEIGHT_ONE);
        |                                    ~^            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        |                                     |                             |
        |                                     unsigned int                  long unsigned int
        |                                    %lu
  ../block/blk-iocost.c: In function 'ioc_weight_show':
  ../block/blk-iocost.c:3045:34: warning: format '%u' expects argument of type 'unsigned int', but argument 3 has type 'long unsigned int' [-Wformat=]
   3045 |         seq_printf(sf, "default %u\n", iocc->dfl_weight / WEIGHT_ONE);
        |                                 ~^     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        |                                  |                      |
        |                                  unsigned int           long unsigned int
        |                                 %lu

It appears WEIGHT_ONE enum is unnecessarly unsigned long
(or unsigned long long on 32bit) because of VTIME_PER_SEC
and/or AUTOP_CYCLE_NSEC need the enum to be that large.

Addressed by lazy splitting the "catch all" anonymous
enum and placing the unsigned long long constants in
their own anonymous enums.

Signed-off-by: Yann Droneaud <ydroneaud@opteya.com>
---
 block/blk-iocost.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/block/blk-iocost.c b/block/blk-iocost.c
index 495396425bad..bb1f8522c0f1 100644
--- a/block/blk-iocost.c
+++ b/block/blk-iocost.c
@@ -232,7 +232,9 @@ enum {
 
 	/* 1/64k is granular enough and can easily be handled w/ u32 */
 	WEIGHT_ONE		= 1 << 16,
+};
 
+enum {
 	/*
 	 * As vtime is used to calculate the cost of each IO, it needs to
 	 * be fairly high precision.  For example, it should be able to
@@ -255,7 +257,9 @@ enum {
 
 	VRATE_MIN		= VTIME_PER_USEC * VRATE_MIN_PPM / MILLION,
 	VRATE_CLAMP_ADJ_PCT	= 4,
+};
 
+enum {
 	/* if IOs end up waiting for requests, issue less */
 	RQ_WAIT_BUSY_PCT	= 5,
 
@@ -293,10 +297,14 @@ enum {
 
 	/* don't let cmds which take a very long time pin lagging for too long */
 	MAX_LAGGING_PERIODS	= 10,
+};
 
+enum {
 	/* switch iff the conditions are met for longer than this */
 	AUTOP_CYCLE_NSEC	= 10LLU * NSEC_PER_SEC,
+};
 
+enum {
 	/*
 	 * Count IO size in 4k pages.  The 12bit shift helps keeping
 	 * size-proportional components of cost calculation in closer
-- 
2.37.2


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

* Re: [PATCH] blk-iocost: don't make all constants unsigned long long
  2022-12-20 20:18 [PATCH] blk-iocost: don't make all constants unsigned long long Yann Droneaud
@ 2022-12-22 13:58 ` Michal Koutný
  2023-01-04 22:15   ` Tejun Heo
  2023-01-04 22:16 ` Tejun Heo
  1 sibling, 1 reply; 5+ messages in thread
From: Michal Koutný @ 2022-12-22 13:58 UTC (permalink / raw)
  To: Yann Droneaud
  Cc: Tejun Heo, Josef Bacik, Jens Axboe, cgroups, linux-block, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 338 bytes --]

On Tue, Dec 20, 2022 at 09:18:19PM +0100, Yann Droneaud <ydroneaud@opteya.com> wrote:
> +enum {
>  	/* switch iff the conditions are met for longer than this */
>  	AUTOP_CYCLE_NSEC	= 10LLU * NSEC_PER_SEC,
> +};

This looks gratuitous.

What about indivudial #defines with typed literals instead of the "lazy
splitting"?

Regards,
Michal

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

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

* Re: [PATCH] blk-iocost: don't make all constants unsigned long long
  2022-12-22 13:58 ` Michal Koutný
@ 2023-01-04 22:15   ` Tejun Heo
  2023-01-04 22:17     ` Tejun Heo
  0 siblings, 1 reply; 5+ messages in thread
From: Tejun Heo @ 2023-01-04 22:15 UTC (permalink / raw)
  To: Michal Koutný
  Cc: Yann Droneaud, Josef Bacik, Jens Axboe, cgroups, linux-block,
	linux-kernel

On Thu, Dec 22, 2022 at 02:58:55PM +0100, Michal Koutný wrote:
> On Tue, Dec 20, 2022 at 09:18:19PM +0100, Yann Droneaud <ydroneaud@opteya.com> wrote:
> > +enum {
> >  	/* switch iff the conditions are met for longer than this */
> >  	AUTOP_CYCLE_NSEC	= 10LLU * NSEC_PER_SEC,
> > +};
> 
> This looks gratuitous.
> 
> What about indivudial #defines with typed literals instead of the "lazy
> splitting"?

enums are so much better for debugging and tracing. This is a gcc caused
problem where there's no other way to generate the same code between two gcc
versions without splitting the enum definitions. I'm kinda baffled that this
is what they chose to do but can't think of a better way to work around it.

Thanks.

-- 
tejun

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

* Re: [PATCH] blk-iocost: don't make all constants unsigned long long
  2022-12-20 20:18 [PATCH] blk-iocost: don't make all constants unsigned long long Yann Droneaud
  2022-12-22 13:58 ` Michal Koutný
@ 2023-01-04 22:16 ` Tejun Heo
  1 sibling, 0 replies; 5+ messages in thread
From: Tejun Heo @ 2023-01-04 22:16 UTC (permalink / raw)
  To: Yann Droneaud; +Cc: Josef Bacik, Jens Axboe, cgroups, linux-block, linux-kernel

On Tue, Dec 20, 2022 at 09:18:19PM +0100, Yann Droneaud wrote:
> My shiny new compiler (GCC 13) is reporting the following
> warnings:
> 
>   ../block/blk-iocost.c: In function 'ioc_weight_prfill':
>   ../block/blk-iocost.c:3035:37: warning: format '%u' expects argument of type 'unsigned int', but argument 4 has type 'long unsigned int' [-Wformat=]
>    3035 |                 seq_printf(sf, "%s %u\n", dname, iocg->cfg_weight / WEIGHT_ONE);
>         |                                    ~^            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>         |                                     |                             |
>         |                                     unsigned int                  long unsigned int
>         |                                    %lu
>   ../block/blk-iocost.c: In function 'ioc_weight_show':
>   ../block/blk-iocost.c:3045:34: warning: format '%u' expects argument of type 'unsigned int', but argument 3 has type 'long unsigned int' [-Wformat=]
>    3045 |         seq_printf(sf, "default %u\n", iocc->dfl_weight / WEIGHT_ONE);
>         |                                 ~^     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>         |                                  |                      |
>         |                                  unsigned int           long unsigned int
>         |                                 %lu
> 
> It appears WEIGHT_ONE enum is unnecessarly unsigned long
> (or unsigned long long on 32bit) because of VTIME_PER_SEC
> and/or AUTOP_CYCLE_NSEC need the enum to be that large.
> 
> Addressed by lazy splitting the "catch all" anonymous
> enum and placing the unsigned long long constants in
> their own anonymous enums.
> 
> Signed-off-by: Yann Droneaud <ydroneaud@opteya.com>

There's a better patch doing this which groups the enums into two groups.
Let's do that instead.

Thanks.

-- 
tejun

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

* Re: [PATCH] blk-iocost: don't make all constants unsigned long long
  2023-01-04 22:15   ` Tejun Heo
@ 2023-01-04 22:17     ` Tejun Heo
  0 siblings, 0 replies; 5+ messages in thread
From: Tejun Heo @ 2023-01-04 22:17 UTC (permalink / raw)
  To: Michal Koutný
  Cc: Yann Droneaud, Josef Bacik, Jens Axboe, cgroups, linux-block,
	linux-kernel

On Wed, Jan 04, 2023 at 12:15:06PM -1000, Tejun Heo wrote:
> On Thu, Dec 22, 2022 at 02:58:55PM +0100, Michal Koutný wrote:
> > On Tue, Dec 20, 2022 at 09:18:19PM +0100, Yann Droneaud <ydroneaud@opteya.com> wrote:
> > > +enum {
> > >  	/* switch iff the conditions are met for longer than this */
> > >  	AUTOP_CYCLE_NSEC	= 10LLU * NSEC_PER_SEC,
> > > +};
> > 
> > This looks gratuitous.
> > 
> > What about indivudial #defines with typed literals instead of the "lazy
> > splitting"?
> 
> enums are so much better for debugging and tracing. This is a gcc caused
> problem where there's no other way to generate the same code between two gcc
> versions without splitting the enum definitions. I'm kinda baffled that this
> is what they chose to do but can't think of a better way to work around it.

I thought this was the other patch addressing this issue. The proposed patch
is rather painful to look at. The other one splits it into two groups.

Thanks.

-- 
tejun

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

end of thread, other threads:[~2023-01-04 22:17 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-20 20:18 [PATCH] blk-iocost: don't make all constants unsigned long long Yann Droneaud
2022-12-22 13:58 ` Michal Koutný
2023-01-04 22:15   ` Tejun Heo
2023-01-04 22:17     ` Tejun Heo
2023-01-04 22:16 ` Tejun Heo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®