Re: [PATCH v2] sched/sysctl: Fix attributes of some extern declarations

From: Ingo Molnar
Date: Wed Nov 01 2017 - 04:35:06 EST



* Matthias Kaehlcke <mka@xxxxxxxxxxxx> wrote:

> El Tue, Oct 30, 2017 at 10:57:58AM +0100 Ingo Molnar ha dit:
>
> > * Matthias Kaehlcke <mka@xxxxxxxxxxxx> wrote:
> >
> > > The definition of sysctl_sched_migration_cost, sysctl_sched_nr_migrate
> > > and sysctl_sched_time_avg includes the attribute const_debug. This
> > > attribute is not part of the extern declaration of these variables in
> > > include/linux/sched/sysctl.h, as a result clang generates warnings like
> > > this:
> > >
> > > kernel/sched/sched.h:1618:33: warning: section attribute is specified on
> > > redeclared variable [-Wsection]
> > > extern const_debug unsigned int sysctl_sched_time_avg;
> > > ^
> > > ./include/linux/sched/sysctl.h:42:21: note: previous declaration is here
> > > extern unsigned int sysctl_sched_time_avg;
> > >
> > > The header only declares the variables when CONFIG_SCHED_DEBUG is defined,
> > > therefore it is not necessary to duplicate the definition of const_debug.
> > > Instead we can use the attribute __read_mostly, which is the expansion of
> > > const_debug when CONFIG_SCHED_DEBUG is set.
> > >
> > > Signed-off-by: Matthias Kaehlcke <mka@xxxxxxxxxxxx>
> > > Reviewed-by: Nick Desaulniers <nick.desaulniers@xxxxxxxxx>
> > > ---
> > > Changes in v2:
> > > - removed pointless include of linux/static_key.h
> > > - added Reviewed-by tag
> > >
> > > include/linux/sched/sysctl.h | 6 +++---
> > > 1 file changed, 3 insertions(+), 3 deletions(-)
> > >
> > > diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
> > > index 0f5ecd4d298e..d34c823f3d36 100644
> > > --- a/include/linux/sched/sysctl.h
> > > +++ b/include/linux/sched/sysctl.h
> > > @@ -37,9 +37,9 @@ extern unsigned int sysctl_numa_balancing_scan_period_max;
> > > extern unsigned int sysctl_numa_balancing_scan_size;
> > >
> > > #ifdef CONFIG_SCHED_DEBUG
> > > -extern unsigned int sysctl_sched_migration_cost;
> > > -extern unsigned int sysctl_sched_nr_migrate;
> > > -extern unsigned int sysctl_sched_time_avg;
> > > +extern __read_mostly unsigned int sysctl_sched_migration_cost;
> > > +extern __read_mostly unsigned int sysctl_sched_nr_migrate;
> > > +extern __read_mostly unsigned int sysctl_sched_time_avg;
> >
> > So I hate this change, because it pointlessly duplicates an attribute that should
> > only matter at the definition site.
>
> It's certainly not ideal, and then again essentially the same is done
> in kernel/sched/sched.h, just that here the specific attribute is
> hidden behind const_debug.

Ok - and that indeed is a problem and makes the Clang build warning useful,
as there are two conflicting prototypes and one definition.

I'll apply your fix.

Thanks,

Ingo