sched/topology: Make compiler happy about unused constant definitions
PATCH 1/1 sched/topology: Make compiler happy about unused constant definitions
Compilation of almost each file ends up with
In file included from .../include/linux/energy_model.h:10,
from .../include/linux/device.h:16, from .../drivers/spi/spi.c:8:
.../include/linux/sched/topology.h:30:27: warning: ‘SD_DEGENERATE_GROUPS_MASK’ defined but not used [-Wunused-const-variable=]
30 | static const unsigned int SD_DEGENERATE_GROUPS_MASK =
| ^~~~~~~~~~~~~~~~~~~~~~~~~
...
Make compiler happy by annotating the static constants with __maybwe_unused.
--- include/linux/sched/topology.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
include/linux/sched/topology.h +2 -2
@@ -27,14 +27,14 @@ enum {/* Generate a mask of SD flags with the SDF_NEEDS_GROUPS metaflag */ #define SD_FLAG (name, mflags) (name * !!((mflags) & SDF_NEEDS_GROUPS)) | -static const unsigned int SD_DEGENERATE_GROUPS_MASK = +static __maybe_unused const unsigned int SD_DEGENERATE_GROUPS_MASK = #include <linux/sched/sd_flags.h>0 ;#undef SD_FLAG#ifdef CONFIG_SCHED_DEBUG #define SD_FLAG (_name, mflags) [__##_name] = { .meta_flags = mflags, .name = #_name }, -static const struct { +static __maybe_unused const struct {unsigned int meta_flags;char *name; } sd_flag_debug[] = {
Signature · 1 line
2.28.0
Hi,
Quoted 12 lines · Andy Shevchenko
Compilation of almost each file ends up with
In file included from
.../include/linux/energy_model.h:10,from .../include/linux/device.h:16, from .../drivers/spi/spi.c:8:
.../include/linux/sched/topology.h:30:27: warning: ‘SD_DEGENERATE_GROUPS_MASK’ defined but not used [-Wunused-const-variable=]
30 | static const unsigned intSD_DEGENERATE_GROUPS_MASK=
| ^~~~~~~~~~~~~~~~~~~~~~~~~
...Make compiler happy by annotating the static constants with
__maybwe_unused.
That should see some use as long as the build is for SMP. This whole region is guarded by #ifdef CONFIG_SMP, so an !SMP build shouldn't trigger this.
With what config/kernel are you getting this?
Quoted 11 lines · Valentin Schneider
Quoted 10 lines · Andy Shevchenko
Compilation of almost each file ends up with
In file included from
.../include/linux/energy_model.h:10,from .../include/linux/device.h:16, from .../drivers/spi/spi.c:8:
.../include/linux/sched/topology.h:30:27: warning: ‘SD_DEGENERATE_GROUPS_MASK’ defined but not used [-Wunused-const-variable=]
30 | static const unsigned intSD_DEGENERATE_GROUPS_MASK=
| ^~~~~~~~~~~~~~~~~~~~~~~~~
...
Quoted 5 lines
Quoted 2 lines
Make compiler happy by annotating the static constants with
__maybwe_unused.That should see some use as long as the build is for SMP. This whole region is guarded by #ifdef
CONFIG_SMP, so an !SMP build shouldn't trigger this.
Isn't SMP is default for most of the kernel builds? And honestly I didn't get the purpose of this comment.
Quoted 1 line
With what config/kernel are you getting this?
x86_64_defconfig from the kernel sources with some drivers added (SMP or so has not been touched, DEBUG_SHED was enabled once to confirm that another static const has same issue).
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 12 lines · Andy Shevchenko
Quoted 11 lines · Valentin Schneider
Quoted 10 lines · Andy Shevchenko
Compilation of almost each file ends up with
In file included from
.../include/linux/energy_model.h:10,from .../include/linux/device.h:16, from .../drivers/spi/spi.c:8:
.../include/linux/sched/topology.h:30:27: warning: ‘SD_DEGENERATE_GROUPS_MASK’ defined but not used [-Wunused-const-variable=]
30 | static const unsigned intSD_DEGENERATE_GROUPS_MASK=
| ^~~~~~~~~~~~~~~~~~~~~~~~~
...
Quoted 9 lines
Quoted 5 lines
Quoted 2 lines
Make compiler happy by annotating the static constants with
__maybwe_unused.That should see some use as long as the build is for SMP. This whole region is guarded by #ifdef
CONFIG_SMP, so an !SMP build shouldn't trigger this.Isn't SMP is default for most of the kernel builds? And honestly I didn't get the purpose of this comment.
Sorry, that's what I get for trying to be too succinct; what I tried to say was that SD_DEGENERATE_GROUPS_MASK should very much be used for SMP. If the build is !SMP, it shouldn't even be defined, IOW I'm perplexed as to where this is coming from.
Quoted 5 lines
Quoted 1 line
With what config/kernel are you getting this?
x86_64_defconfigfrom the kernel sources with some drivers added (SMP or so has not been touched,DEBUG_SHEDwas enabled once to confirm that another static const has same issue).
Thanks, I'll poke around this.
Quoted 13 lines · Valentin Schneider
Quoted 12 lines · Andy Shevchenko
Quoted 11 lines · Valentin Schneider
Quoted 10 lines · Andy Shevchenko
Compilation of almost each file ends up with
In file included from
.../include/linux/energy_model.h:10,from .../include/linux/device.h:16, from .../drivers/spi/spi.c:8:
.../include/linux/sched/topology.h:30:27: warning: ‘SD_DEGENERATE_GROUPS_MASK’ defined but not used [-Wunused-const-variable=]
30 | static const unsigned intSD_DEGENERATE_GROUPS_MASK=
| ^~~~~~~~~~~~~~~~~~~~~~~~~
...
Quoted 6 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Make compiler happy by annotating the static constants with
__maybwe_unused.Sorry, that's what I get for trying to be too succinct; what I tried to say was that
SD_DEGENERATE_GROUPS_MASKshould very much be used for SMP. If the build is !SMP, it shouldn't even be defined, IOW I'm perplexed as to where this is coming from.
So I see how having this as a constvar rather than a constexpr is somewhat daft (we get an instance per compilation unit), but none of my compilers seem to complain (even with W=1). AFAIA the kernelbot didn't catch any of it either.
Out of curiosity, what's your compiler & compiler version?
Alternatively we can make this a "proper" constant expression with the below.
---
include/linux/sched/topology.h +4 -2
@@ -27,9 +27,11 @@ enum {/* Generate a mask of SD flags with the SDF_NEEDS_GROUPS metaflag */ #define SD_FLAG (name, mflags) (name * !!((mflags) & SDF_NEEDS_GROUPS)) | -static const unsigned int SD_DEGENERATE_GROUPS_MASK = +enum { +SD_DEGENERATE_GROUPS_MASK = #include <linux/sched/sd_flags.h> -0 ; +0 +};#undef SD_FLAG#ifdef CONFIG_SCHED_DEBUG
Quoted 21 lines · Valentin Schneider
Quoted 13 lines · Valentin Schneider
Quoted 12 lines · Andy Shevchenko
Quoted 11 lines · Valentin Schneider
Quoted 10 lines · Andy Shevchenko
Compilation of almost each file ends up with
In file included from
.../include/linux/energy_model.h:10,from .../include/linux/device.h:16, from .../drivers/spi/spi.c:8:
.../include/linux/sched/topology.h:30:27: warning: ‘SD_DEGENERATE_GROUPS_MASK’ defined but not used [-Wunused-const-variable=]
30 | static const unsigned intSD_DEGENERATE_GROUPS_MASK=
| ^~~~~~~~~~~~~~~~~~~~~~~~~
...Quoted 6 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Make compiler happy by annotating the static constants with
__maybwe_unused.Sorry, that's what I get for trying to be too succinct; what I tried to say was that
SD_DEGENERATE_GROUPS_MASKshould very much be used for SMP. If the build is !SMP, it shouldn't even be defined, IOW I'm perplexed as to where this is coming from.
Quoted 6 lines
So I see how having this as a constvar rather than a constexpr is somewhat daft (we get an instance per compilation unit), but none of my compilers seem to complain (even with W=1). AFAIA the kernelbot didn't catch any of it either.
Out of curiosity, what's your compiler & compiler version?
% gcc --version
gcc (Debian 10.2.0-5) 10.2.0
% make O=... W=1 C=1 CF=-D__CHECK_ENDIAN__ -j64
Quoted 2 lines
Alternatively we can make this a "proper" constant expression with the below.
It doesn't fix another static const in the same file, though that one requires DEBUG_SCHED to be enabled.
Do you want me to split this fix and fix only the other case?
Quoted 20 lines
---
include/linux/sched/topology.h +4
-2@@ -27,9 +27,11 @@ enum {/* Generate a mask of SD flags with the SDF_NEEDS_GROUPS metaflag */ #define SD_FLAG (name, mflags) (name * !!((mflags) & SDF_NEEDS_GROUPS)) | -static const unsigned int SD_DEGENERATE_GROUPS_MASK = +enum { +SD_DEGENERATE_GROUPS_MASK = #include <linux/sched/sd_flags.h> -0 ; +0 +};#undef SD_FLAG#ifdef CONFIG_SCHED_DEBUG
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 34 lines · Andy Shevchenko
Quoted 21 lines · Valentin Schneider
Quoted 13 lines · Valentin Schneider
Quoted 12 lines · Andy Shevchenko
Quoted 11 lines · Valentin Schneider
Quoted 10 lines · Andy Shevchenko
Compilation of almost each file ends up with
In file included from
.../include/linux/energy_model.h:10,from .../include/linux/device.h:16, from .../drivers/spi/spi.c:8:
.../include/linux/sched/topology.h:30:27: warning: ‘SD_DEGENERATE_GROUPS_MASK’ defined but not used [-Wunused-const-variable=]
30 | static const unsigned intSD_DEGENERATE_GROUPS_MASK=
| ^~~~~~~~~~~~~~~~~~~~~~~~~
...Quoted 6 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Make compiler happy by annotating the static constants with
__maybwe_unused.Sorry, that's what I get for trying to be too succinct; what I tried to say was that
SD_DEGENERATE_GROUPS_MASKshould very much be used for SMP. If the build is !SMP, it shouldn't even be defined, IOW I'm perplexed as to where this is coming from.Quoted 6 lines
So I see how having this as a constvar rather than a constexpr is somewhat daft (we get an instance per compilation unit), but none of my compilers seem to complain (even with W=1). AFAIA the kernelbot didn't catch any of it either.
Out of curiosity, what's your compiler & compiler version?
% gcc --version
gcc (Debian 10.2.0-5) 10.2.0% make O=... W=1 C=1 CF=-D__CHECK_ENDIAN__ -j64
Quoted 7 lines
Quoted 2 lines
Alternatively we can make this a "proper" constant expression with the below.
It doesn't fix another static const in the same file, though that one requires
DEBUG_SCHEDto be enabled.Do you want me to split this fix and fix only the other case?
Just checked and the other case has been brought by
b6e862f38672 ("sched/topology: Define and assign sched_domain flag metadata")
with your authorship.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 23 lines · Andy Shevchenko
Quoted 22 lines · Andy Shevchenko
Quoted 21 lines · Valentin Schneider
Quoted 19 lines · Valentin Schneider
Quoted 12 lines · Andy Shevchenko
Quoted 11 lines · Valentin Schneider
Quoted 10 lines · Andy Shevchenko
Compilation of almost each file ends up with
In file included from
.../include/linux/energy_model.h:10,from .../include/linux/device.h:16, from .../drivers/spi/spi.c:8:
.../include/linux/sched/topology.h:30:27: warning: ‘SD_DEGENERATE_GROUPS_MASK’ defined but not used [-Wunused-const-variable=]
30 | static const unsigned intSD_DEGENERATE_GROUPS_MASK=
| ^~~~~~~~~~~~~~~~~~~~~~~~~
...Quoted 1 line
Quoted 1 line
Quoted 1 line
Make compiler happy by annotating the static constants with
__maybwe_unused.Sorry, that's what I get for trying to be too succinct; what I tried to say was that
SD_DEGENERATE_GROUPS_MASKshould very much be used for SMP. If the build is !SMP, it shouldn't even be defined, IOW I'm perplexed as to where this is coming from.
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
So I see how having this as a constvar rather than a constexpr is somewhat daft (we get an instance per compilation unit), but none of my compilers seem to complain (even with W=1). AFAIA the kernelbot didn't catch any of it either.
And even without compiler or any other analyzer / bot I can 100% sure tell that spi.c does *not* use that symbol.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 24 lines · Andy Shevchenko
Quoted 23 lines · Andy Shevchenko
Quoted 22 lines · Andy Shevchenko
Quoted 21 lines · Valentin Schneider
Quoted 19 lines · Valentin Schneider
Quoted 12 lines · Andy Shevchenko
Quoted 11 lines · Valentin Schneider
Quoted 10 lines · Andy Shevchenko
Compilation of almost each file ends up with
In file included from
.../include/linux/energy_model.h:10,from .../include/linux/device.h:16, from .../drivers/spi/spi.c:8:
.../include/linux/sched/topology.h:30:27: warning: ‘SD_DEGENERATE_GROUPS_MASK’ defined but not used [-Wunused-const-variable=]
30 | static const unsigned intSD_DEGENERATE_GROUPS_MASK=
| ^~~~~~~~~~~~~~~~~~~~~~~~~
...Quoted 1 line
Quoted 1 line
Quoted 1 line
Make compiler happy by annotating the static constants with
__maybwe_unused.Sorry, that's what I get for trying to be too succinct; what I tried to say was that
SD_DEGENERATE_GROUPS_MASKshould very much be used for SMP. If the build is !SMP, it shouldn't even be defined, IOW I'm perplexed as to where this is coming from.
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
So I see how having this as a constvar rather than a constexpr is somewhat daft (we get an instance per compilation unit), but none of my compilers seem to complain (even with W=1). AFAIA the kernelbot didn't catch any of it either.
And even without compiler or any other analyzer / bot I can 100% sure tell that
spi.cdoes *not* use that symbol.
Aye aye, this is a daft constvar placement from my end, apologies.
For the SD_DEGENERATE_GROUPS_MASK, that one could directly be shoved into kernel/sched/topology.c (or done via an enum, I don't care too much).
I suppose the other one causing you grief is sd_flag_debug[]; that one too really shouldn't be in a header. I need to access that in two separate files, so I guess I'll have to cook up some wrappers.
Let me take a jab at it, it's my own mess after all...
Quoted 35 lines · Valentin Schneider
Quoted 24 lines · Andy Shevchenko
Quoted 23 lines · Andy Shevchenko
Quoted 22 lines · Andy Shevchenko
Quoted 21 lines · Valentin Schneider
Quoted 19 lines · Valentin Schneider
Quoted 12 lines · Andy Shevchenko
Quoted 11 lines · Valentin Schneider
Quoted 10 lines · Andy Shevchenko
Compilation of almost each file ends up with
In file included from
.../include/linux/energy_model.h:10,from .../include/linux/device.h:16, from .../drivers/spi/spi.c:8:
.../include/linux/sched/topology.h:30:27: warning: ‘SD_DEGENERATE_GROUPS_MASK’ defined but not used [-Wunused-const-variable=]
30 | static const unsigned intSD_DEGENERATE_GROUPS_MASK=
| ^~~~~~~~~~~~~~~~~~~~~~~~~
...Quoted 1 line
Quoted 1 line
Quoted 1 line
Make compiler happy by annotating the static constants with
__maybwe_unused.Sorry, that's what I get for trying to be too succinct; what I tried to say was that
SD_DEGENERATE_GROUPS_MASKshould very much be used for SMP. If the build is !SMP, it shouldn't even be defined, IOW I'm perplexed as to where this is coming from.Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
So I see how having this as a constvar rather than a constexpr is somewhat daft (we get an instance per compilation unit), but none of my compilers seem to complain (even with W=1). AFAIA the kernelbot didn't catch any of it either.
And even without compiler or any other analyzer / bot I can 100% sure tell that
spi.cdoes *not* use that symbol.Aye aye, this is a daft constvar placement from my end, apologies.
Quoted 8 lines
For the
SD_DEGENERATE_GROUPS_MASK, that one could directly be shoved intokernel/sched/topology.c(or done via an enum, I don't care too much).I suppose the other one causing you grief is sd_flag_debug[]; that one too really shouldn't be in a header. I need to access that in two separate files, so I guess I'll have to cook up some wrappers.
Let me take a jab at it, it's my own mess after all...
Thank you!
Ping me if you would need to test a patch or so.
Signature · 2 lines
With Best Regards, Andy Shevchenko
From: Andy Shevchenko
Quoted 15 lines
Sent: 25 August 2020 09:27
Quoted 7 lines · Valentin Schneider
Quoted 6 lines · Andy Shevchenko
Compilation of almost each file ends up with
In file included from
.../include/linux/energy_model.h:10,from .../include/linux/device.h:16, from .../drivers/spi/spi.c:8:
.../include/linux/sched/topology.h:30:27: warning: ‘SD_DEGENERATE_GROUPS_MASK’ defined but notused [-Wunused-const-variable=]
Quoted 4 lines
Quoted 4 lines
30 | static const unsigned int
SD_DEGENERATE_GROUPS_MASK=
| ^~~~~~~~~~~~~~~~~~~~~~~~~
...
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Make compiler happy by annotating the static constants with
__maybwe_unused.That should see some use as long as the build is for SMP. This whole region is guarded by #ifdef
CONFIG_SMP, so an !SMP build shouldn't trigger this.Isn't SMP is default for most of the kernel builds? And honestly I didn't get the purpose of this comment.
The real fix is to not use 'static const' in C. IIRC it is still a memory location (that can be patched) not a compile time constant.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
Quoted 21 lines · David Laight
From: Andy Shevchenko
Quoted 20 lines
Sent: 25 August 2020 09:27
Quoted 7 lines · Valentin Schneider
Quoted 6 lines · Andy Shevchenko
Compilation of almost each file ends up with
In file included from
.../include/linux/energy_model.h:10,from .../include/linux/device.h:16, from .../drivers/spi/spi.c:8:
.../include/linux/sched/topology.h:30:27: warning: ‘SD_DEGENERATE_GROUPS_MASK’ defined but notused [-Wunused-const-variable=]
Quoted 9 lines
Quoted 6 lines
30 | static const unsigned int
SD_DEGENERATE_GROUPS_MASK=
| ^~~~~~~~~~~~~~~~~~~~~~~~~
...Make compiler happy by annotating the static constants with
__maybwe_unused.That should see some use as long as the build is for SMP. This whole region is guarded by #ifdef
CONFIG_SMP, so an !SMP build shouldn't trigger this.
Quoted 6 lines
Quoted 2 lines
Isn't SMP is default for most of the kernel builds? And honestly I didn't get the purpose of this comment.
The real fix is to not use 'static const' in C. IIRC it is still a memory location (that can be patched) not a compile time constant.
Yep. The topology.h can be rather split to topology.c with exported symbols (exported or just visible for linker, depends on the case).
Signature · 2 lines
With Best Regards, Andy Shevchenko