Message ID | 97b6f861e6e6a2ac7b50efb7211f3c8e7fe872b0.1568240476.git.amit.kucheria@linaro.org |
---|---|
State | New |
Headers | show |
Series | Initialise thermal framework earlier during boot | expand |
On 12/09/2019 00:32, Amit Kucheria wrote: > From: Lina Iyer <ilina@codeaurora.org> > > Now that the thermal framework is built-in, in order to facilitate > thermal mitigation as early as possible in the boot cycle, move the > thermal framework initialization to core_initcall. > > However, netlink initialization happens only as part of subsys_initcall. > At this time in the boot process, the userspace is not available yet. So > initialize the netlink events later in fs_initcall. Why not kill directly the netlink part, no one is using it in the kernel? > Signed-off-by: Lina Iyer <ilina@codeaurora.org> > [Rebased, refactored and moved to core_initcall] > Signed-off-by: Amit Kucheria <amit.kucheria@linaro.org> > --- > drivers/thermal/thermal_core.c | 41 ++++++++++++++++++++-------------- > 1 file changed, 24 insertions(+), 17 deletions(-) > > diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c > index 6bab66e84eb5..b13e8a9298cc 100644 > --- a/drivers/thermal/thermal_core.c > +++ b/drivers/thermal/thermal_core.c > @@ -1468,6 +1468,8 @@ static struct genl_family thermal_event_genl_family __ro_after_init = { > .n_mcgrps = ARRAY_SIZE(thermal_event_mcgrps), > }; > > +static bool allow_netlink_events; > + > int thermal_generate_netlink_event(struct thermal_zone_device *tz, > enum events event) > { > @@ -1482,6 +1484,9 @@ int thermal_generate_netlink_event(struct thermal_zone_device *tz, > if (!tz) > return -EINVAL; > > + if (!allow_netlink_events) > + return -ENODEV; > + > /* allocate memory */ > size = nla_total_size(sizeof(struct thermal_genl_event)) + > nla_total_size(0); > @@ -1533,16 +1538,18 @@ EXPORT_SYMBOL_GPL(thermal_generate_netlink_event); > > static int __init genetlink_init(void) > { > - return genl_register_family(&thermal_event_genl_family); > -} > + int ret; > > -static void genetlink_exit(void) > -{ > - genl_unregister_family(&thermal_event_genl_family); > + ret = genl_register_family(&thermal_event_genl_family); > + if (!ret) > + allow_netlink_events = true; > + return ret; > } > + > #else /* !CONFIG_NET */ > static inline int genetlink_init(void) { return 0; } > -static inline void genetlink_exit(void) {} > +static inline int thermal_generate_netlink_event(struct thermal_zone_device *tz, > + enum events event) { return -ENODEV; } > #endif /* !CONFIG_NET */ > > static int thermal_pm_notify(struct notifier_block *nb, > @@ -1591,19 +1598,15 @@ static int __init thermal_init(void) > mutex_init(&poweroff_lock); > result = thermal_register_governors(); > if (result) > - goto error; > + goto init_exit; > > result = class_register(&thermal_class); > if (result) > goto unregister_governors; > > - result = genetlink_init(); > - if (result) > - goto unregister_class; > - > result = of_parse_thermal_zones(); > if (result) > - goto exit_netlink; > + goto exit_zone_parse; > > result = register_pm_notifier(&thermal_pm_nb); > if (result) > @@ -1612,13 +1615,11 @@ static int __init thermal_init(void) > > return 0; > > -exit_netlink: > - genetlink_exit(); > -unregister_class: > +exit_zone_parse: > class_unregister(&thermal_class); > unregister_governors: > thermal_unregister_governors(); > -error: > +init_exit: > ida_destroy(&thermal_tz_ida); > ida_destroy(&thermal_cdev_ida); > mutex_destroy(&thermal_list_lock); > @@ -1626,4 +1627,10 @@ static int __init thermal_init(void) > mutex_destroy(&poweroff_lock); > return result; > } > -fs_initcall(thermal_init); > + > +static int __init thermal_netlink_init(void) > +{ > + return genetlink_init(); > +} > +core_initcall(thermal_init); > +fs_initcall(thermal_netlink_init); > -- <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook | <http://twitter.com/#!/linaroorg> Twitter | <http://www.linaro.org/linaro-blog/> Blog
On Tue, Sep 17, 2019 at 1:30 AM Daniel Lezcano <daniel.lezcano@linaro.org> wrote: > > On 12/09/2019 00:32, Amit Kucheria wrote: > > From: Lina Iyer <ilina@codeaurora.org> > > > > Now that the thermal framework is built-in, in order to facilitate > > thermal mitigation as early as possible in the boot cycle, move the > > thermal framework initialization to core_initcall. > > > > However, netlink initialization happens only as part of subsys_initcall. > > At this time in the boot process, the userspace is not available yet. So > > initialize the netlink events later in fs_initcall. > > Why not kill directly the netlink part, no one is using it in the kernel? That's a good point. I wasn't sure if anybody was using it, but I can remove it completely since no driver seems to be using the thermal_generate_netlink_event() api. Regards, Amit $ git grep thermal_generate_netlink_event Documentation/thermal/sysfs-api.rst:just need to call thermal_generate_netlink_event() with two arguments viz drivers/thermal/thermal_core.c:int thermal_generate_netlink_event(struct thermal_zone_device *tz, drivers/thermal/thermal_core.c:EXPORT_SYMBOL_GPL(thermal_generate_netlink_event); include/linux/thermal.h:extern int thermal_generate_netlink_event(struct thermal_zone_device *tz, include/linux/thermal.h:static inline int thermal_generate_netlink_event(struct thermal_zone_device *tz,
On Tue, 2019-09-17 at 14:48 +0530, Amit Kucheria wrote: > On Tue, Sep 17, 2019 at 1:30 AM Daniel Lezcano > <daniel.lezcano@linaro.org> wrote: > > > > On 12/09/2019 00:32, Amit Kucheria wrote: > > > From: Lina Iyer <ilina@codeaurora.org> > > > > > > Now that the thermal framework is built-in, in order to > > > facilitate > > > thermal mitigation as early as possible in the boot cycle, move > > > the > > > thermal framework initialization to core_initcall. > > > > > > However, netlink initialization happens only as part of > > > subsys_initcall. > > > At this time in the boot process, the userspace is not available > > > yet. So > > > initialize the netlink events later in fs_initcall. > > > > Why not kill directly the netlink part, no one is using it in the > > kernel? > > That's a good point. I wasn't sure if anybody was using it, but I can > remove it completely since no driver seems to be using the > thermal_generate_netlink_event() api. Interesting, I recalled that thermal_generate_netlink_event() is indeed used by some thermal driver, but it's true that no one is using it now. let's remove it and see if we get any complains. thanks, rui > > Regards, > Amit > > $ git grep thermal_generate_netlink_event > Documentation/thermal/sysfs-api.rst:just need to call > thermal_generate_netlink_event() with two arguments viz > drivers/thermal/thermal_core.c:int > thermal_generate_netlink_event(struct thermal_zone_device *tz, > drivers/thermal/thermal_core.c:EXPORT_SYMBOL_GPL(thermal_generate_net > link_event); > include/linux/thermal.h:extern int > thermal_generate_netlink_event(struct thermal_zone_device *tz, > include/linux/thermal.h:static inline int > thermal_generate_netlink_event(struct thermal_zone_device *tz,
diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index 6bab66e84eb5..b13e8a9298cc 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -1468,6 +1468,8 @@ static struct genl_family thermal_event_genl_family __ro_after_init = { .n_mcgrps = ARRAY_SIZE(thermal_event_mcgrps), }; +static bool allow_netlink_events; + int thermal_generate_netlink_event(struct thermal_zone_device *tz, enum events event) { @@ -1482,6 +1484,9 @@ int thermal_generate_netlink_event(struct thermal_zone_device *tz, if (!tz) return -EINVAL; + if (!allow_netlink_events) + return -ENODEV; + /* allocate memory */ size = nla_total_size(sizeof(struct thermal_genl_event)) + nla_total_size(0); @@ -1533,16 +1538,18 @@ EXPORT_SYMBOL_GPL(thermal_generate_netlink_event); static int __init genetlink_init(void) { - return genl_register_family(&thermal_event_genl_family); -} + int ret; -static void genetlink_exit(void) -{ - genl_unregister_family(&thermal_event_genl_family); + ret = genl_register_family(&thermal_event_genl_family); + if (!ret) + allow_netlink_events = true; + return ret; } + #else /* !CONFIG_NET */ static inline int genetlink_init(void) { return 0; } -static inline void genetlink_exit(void) {} +static inline int thermal_generate_netlink_event(struct thermal_zone_device *tz, + enum events event) { return -ENODEV; } #endif /* !CONFIG_NET */ static int thermal_pm_notify(struct notifier_block *nb, @@ -1591,19 +1598,15 @@ static int __init thermal_init(void) mutex_init(&poweroff_lock); result = thermal_register_governors(); if (result) - goto error; + goto init_exit; result = class_register(&thermal_class); if (result) goto unregister_governors; - result = genetlink_init(); - if (result) - goto unregister_class; - result = of_parse_thermal_zones(); if (result) - goto exit_netlink; + goto exit_zone_parse; result = register_pm_notifier(&thermal_pm_nb); if (result) @@ -1612,13 +1615,11 @@ static int __init thermal_init(void) return 0; -exit_netlink: - genetlink_exit(); -unregister_class: +exit_zone_parse: class_unregister(&thermal_class); unregister_governors: thermal_unregister_governors(); -error: +init_exit: ida_destroy(&thermal_tz_ida); ida_destroy(&thermal_cdev_ida); mutex_destroy(&thermal_list_lock); @@ -1626,4 +1627,10 @@ static int __init thermal_init(void) mutex_destroy(&poweroff_lock); return result; } -fs_initcall(thermal_init); + +static int __init thermal_netlink_init(void) +{ + return genetlink_init(); +} +core_initcall(thermal_init); +fs_initcall(thermal_netlink_init);