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

From: Zhang Rui
Date: Mon Apr 22 2019 - 04:48:23 EST


Hi, Daniel,

Thanks for the patches, it looks good to me except this one and patch
4/7.

First, I don't think this is a cyclic dependency issue as they are in
the same module.
Second, I have not read include/asm-generic/vmlinux.lds.h before, it
seems that it is used forÂarchitecture specific stuff. Fix a thermal
issue in this way seems overkill to me.

IMO, to make the code clean, we can build the governors as separate
modules just like we do for cpu governors.
This brings to the old commit 80a26a5c22b9("Thermal: build thermal
governors into thermal_sys module"), and that was introduced to fix a
problem when CONFIG_THERMAL is set to 'm'. So I think we can switch
back to the old way as the problem is gone now.

what do you think?

Patch 1,2,5,6,7 applied first.

thanks,
rui

On ä, 2019-04-02 at 18:12 +0200, 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
> the 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.
>
> Signed-off-by: Daniel Lezcano <daniel.lezcano@xxxxxxxxxx>
> ---
> Âdrivers/thermal/thermal_core.hÂÂÂÂ| 16 ++++++++++++++++
> Âinclude/asm-generic/vmlinux.lds.h | 11 +++++++++++
> Â2 files changed, 27 insertions(+)
>
> diff --git a/drivers/thermal/thermal_core.h
> b/drivers/thermal/thermal_core.h
> index 0df190ed82a7..28d18083e969 100644
> --- a/drivers/thermal/thermal_core.h
> +++ b/drivers/thermal/thermal_core.h
> @@ -15,6 +15,22 @@
> Â/* 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(go
> vernor, 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..9893a3ed242a 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()
> Â