Re: [PATCH 1/2] thermal/drivers/core: Add init section table for self-encapsulation

From: Zhang Rui
Date: Thu Jun 27 2019 - 09:21:38 EST


On ä, 2019-06-24 at 09:32 +0200, Daniel Lezcano wrote:
> Any chance this patch gets merged for v5.4?
>
> Thanks
> Â -- Daniel
>

have you run compile test for the patch?
I got the following errors when compiling.

In file included from drivers/thermal/fair_share.c:16:0:
drivers/thermal/thermal_core.h:23:3: error: expected identifier or â(â
before âstaticâ
 (static typeof(name) *__thermal_table_entry_##name \
ÂÂÂ^
drivers/thermal/thermal_core.h:26:40: note: in expansion of macro
âTHERMAL_TABLE_ENTRYâ
Â#define THERMAL_GOVERNOR_DECLARE(name) THERMAL_TABLE_ENTRY(governor,
name)
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ^
drivers/thermal/fair_share.c:120:1: note: in expansion of macro
âTHERMAL_GOVERNOR_DECLAREâ
ÂTHERMAL_GOVERNOR_DECLARE(thermal_gov_fair_share);
Â^
drivers/thermal/fair_share.c:116:32: warning: âthermal_gov_fair_shareâ
defined but not used [-Wunused-variable]
Âstatic struct thermal_governor thermal_gov_fair_share = {
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ^
make[2]: *** [drivers/thermal/fair_share.o] Error 1
make[2]: *** Waiting for unfinished jobs....
In file included from drivers/thermal/gov_bang_bang.c:14:0:
drivers/thermal/thermal_core.h:23:3: error: expected identifier or â(â
before âstaticâ
 (static typeof(name) *__thermal_table_entry_##name \
ÂÂÂ^
drivers/thermal/thermal_core.h:26:40: note: in expansion of macro
âTHERMAL_TABLE_ENTRYâ
Â#define THERMAL_GOVERNOR_DECLARE(name) THERMAL_TABLE_ENTRY(governor,
name)
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ^
drivers/thermal/gov_bang_bang.c:119:1: note: in expansion of macro
âTHERMAL_GOVERNOR_DECLAREâ
ÂTHERMAL_GOVERNOR_DECLARE(thermal_gov_bang_bang);
Â^
drivers/thermal/gov_bang_bang.c:115:32: warning:
âthermal_gov_bang_bangâ defined but not used [-Wunused-variable]
Âstatic struct thermal_governor thermal_gov_bang_bang = {
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ^
make[2]: *** [drivers/thermal/gov_bang_bang.o] Error 1
make[1]: *** [drivers/thermal] Error 2
make[1]: *** Waiting for unfinished jobs....
make: *** [drivers] Error 2

Fix the problem by removing theÂround brackets
ofÂTHERMAL_TABLE_ENTRY(), and applied.

thanks,
rui
> On 12/06/2019 22:13, Daniel Lezcano wrote:
> >
> > Currently the governors are declared in their respective files but
> > they
> > export their [un]register functions which in turn call the
> > [un]register
> > governors core's functions. That implies a cyclic dependency which
> > is
> > not desirable. There is a way to self-encapsulate the governors by
> > letting
> > them to declare themselves in a __init section table.
> >
> > Define the table in the asm generic linker description like the
> > other
> > tables and provide the specific macros to deal with.
> >
> > Reviewed-by: Amit Kucheria <amit.kucheria@xxxxxxxxxx>
> > Signed-off-by: Daniel Lezcano <daniel.lezcano@xxxxxxxxxx>
> > ---
> > Âdrivers/thermal/thermal_core.hÂÂÂÂ| 15 +++++++++++++++
> > Âinclude/asm-generic/vmlinux.lds.h | 11 +++++++++++
> > Â2 files changed, 26 insertions(+)
> >
> > diff --git a/drivers/thermal/thermal_core.h
> > b/drivers/thermal/thermal_core.h
> > index 0df190ed82a7..be901e84aa65 100644
> > --- a/drivers/thermal/thermal_core.h
> > +++ b/drivers/thermal/thermal_core.h
> > @@ -15,6 +15,21 @@
> > Â/* Initial state of a cooling device during binding */
> > Â#define THERMAL_NO_TARGET -1UL
> > Â
> > +/* Init section thermal table */
> > +extern struct thermal_governor *__governor_thermal_table[];
> > +extern struct thermal_governor *__governor_thermal_table_end[];
> > +
> > +#define THERMAL_TABLE_ENTRY(table, name) \
> > + (static typeof(name) *__thermal_table_entry_##name
> > \
> > + __used __section(__##table##_thermal_table) = &name)
> > +
> > +#define THERMAL_GOVERNOR_DECLARE(name) THERMAL_TABLE_ENTRY(
> > governor, name)
> > +
> > +#define for_each_governor_table(__governor) \
> > + for (__governor = __governor_thermal_table; \
> > + ÂÂÂÂÂ__governor < __governor_thermal_table_end; \
> > + ÂÂÂÂÂ__governor++)
> > +
> > Â/*
> > Â * This structure is used to describe the behavior of
> > Â * a certain cooling device on a certain trip point
> > diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-
> > generic/vmlinux.lds.h
> > index f8f6f04c4453..8312fdc2b2fa 100644
> > --- a/include/asm-generic/vmlinux.lds.h
> > +++ b/include/asm-generic/vmlinux.lds.h
> > @@ -239,6 +239,16 @@
> > Â#define ACPI_PROBE_TABLE(name)
> > Â#endif
> > Â
> > +#ifdef CONFIG_THERMAL
> > +#define THERMAL_TABLE(name)
> > \
> > + . = ALIGN(8);
> > \
> > + __##name##_thermal_table = .;
> > \
> > + KEEP(*(__##name##_thermal_table))
> > \
> > + __##name##_thermal_table_end = .;
> > +#else
> > +#define THERMAL_TABLE(name)
> > +#endif
> > +
> > Â#define KERNEL_DTB()
> > \
> > Â STRUCT_ALIGN();
> > \
> > Â __dtb_start = .;
> > \
> > @@ -609,6 +619,7 @@
> > Â IRQCHIP_OF_MATCH_TABLE()
> > \
> > Â ACPI_PROBE_TABLE(irqchip)
> > \
> > Â ACPI_PROBE_TABLE(timer)
> > \
> > + THERMAL_TABLE(governor)
> > \
> > Â EARLYCON_TABLE()
> > \
> > Â LSM_TABLE()
> > Â
> >
>