Skip to contentSkip to conversation

Initialise thermal framework and cpufreq earlier during boot

PATCH Superseded Amit Kucheria 5 participants 13 messages Oct 18, 2019 – Nov 13, 2019

Subsystems (7)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v4 cover Initialise thermal framework and cpufreq earlier during boot

Changes since v3:
- Init schedutil governor earlier too
- Simplified changes to thermal_init() error path
- Collects Acks

Changes since v2:
- Missed one patch when posting v2. Respinning.

Changes since v1:
- Completely get rid of netlink support in the thermal framework.
- This changes the early init patch to a single line - change to core_initcall. Changed authorship of patch since it is nothing like the original. Lina, let me know if you feel otherwise.
- I've tested to make sure that the qcom-cpufreq-hw driver continues to work correctly as a module so this won't impact Android's GKI plans.
- Collected Acks

Device boot needs to be as fast as possible while keeping under the thermal envelope. Now that thermal framework is built-in to the kernel, we can initialize it earlier to enable thermal mitigation during boot.

We also need the cpufreq HW drivers to be initialised earlier to act as the cooling devices. This series only converts over the qcom-hw driver to initialize earlier but can be extended to other platforms as well.

Amit Kucheria (6):
thermal: Remove netlink support
thermal: Initialize thermal subsystem earlier
cpufreq: Initialise the governors in core_initcall
cpufreq: Initialize cpufreq-dt driver earlier
clk: qcom: Initialise clock drivers earlier
cpufreq: qcom-hw: Move driver initialisation earlier

 .../driver-api/thermal/sysfs-api.rst          |  26 +----
 drivers/clk/qcom/clk-rpmh.c                   |   2 +-
 drivers/clk/qcom/gcc-qcs404.c                 |   2 +-
 drivers/clk/qcom/gcc-sdm845.c                 |   2 +-
 drivers/cpufreq/cpufreq-dt-platdev.c          |   2 +-
 drivers/cpufreq/cpufreq_conservative.c        |   2 +-
 drivers/cpufreq/cpufreq_ondemand.c            |   2 +-
 drivers/cpufreq/cpufreq_performance.c         |   2 +-
 drivers/cpufreq/cpufreq_powersave.c           |   2 +-
 drivers/cpufreq/cpufreq_userspace.c           |   2 +-
 drivers/cpufreq/qcom-cpufreq-hw.c             |   2 +-
 drivers/thermal/thermal_core.c                | 103 +-----------------
 include/linux/thermal.h                       |  11 --
 kernel/sched/cpufreq_schedutil.c              |   2 +-
 14 files changed, 19 insertions(+), 143 deletions(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH v4 1/6 thermal: Remove netlink support

There are no users of netlink messages for thermal inside the kernel. Remove the code and adjust the documentation.

---
 .../driver-api/thermal/sysfs-api.rst          |  26 ++---
 drivers/thermal/thermal_core.c                | 101 +-----------------
 include/linux/thermal.h                       |  11 --
 3 files changed, 7 insertions(+), 131 deletions(-)
Documentation/driver-api/thermal/sysfs-api.rst +6 -20
index fab2c9b36d084..b40b1f8391481 100644
@@ -725,24 +725,10 @@ method, the sys I/F structure will be built like this::
     |---temp1_input:		37000
     |---temp1_crit:		100000
 
-4. Event Notification
+4. Export Symbol APIs
 =====================
 
-The framework includes a simple notification mechanism, in the form of a
-netlink event. Netlink socket initialization is done during the _init_
-of the framework. Drivers which intend to use the notification mechanism
-just need to call thermal_generate_netlink_event() with two arguments viz
-(originator, event). The originator is a pointer to struct thermal_zone_device
-from where the event has been originated. An integer which represents the
-thermal zone device will be used in the message to identify the zone. The
-event will be one of:{THERMAL_AUX0, THERMAL_AUX1, THERMAL_CRITICAL,
-THERMAL_DEV_FAULT}. Notification can be sent when the current temperature
-crosses any of the configured thresholds.
-
-5. Export Symbol APIs
-=====================
-
-5.1. get_tz_trend
+4.1. get_tz_trend
 -----------------
 
 This function returns the trend of a thermal zone, i.e the rate of change
@@ -751,14 +737,14 @@ are supposed to implement the callback. If they don't, the thermal
 framework calculated the trend by comparing the previous and the current
 temperature values.
 
-5.2. get_thermal_instance
+4.2. get_thermal_instance
 -------------------------
 
 This function returns the thermal_instance corresponding to a given
 {thermal_zone, cooling_device, trip_point} combination. Returns NULL
 if such an instance does not exist.
 
-5.3. thermal_notify_framework
+4.3. thermal_notify_framework
 -----------------------------
 
 This function handles the trip events from sensor drivers. It starts
@@ -768,14 +754,14 @@ and does actual throttling for other trip points i.e ACTIVE and PASSIVE.
 The throttling policy is based on the configured platform data; if no
 platform data is provided, this uses the step_wise throttling policy.
 
-5.4. thermal_cdev_update
+4.4. thermal_cdev_update
 ------------------------
 
 This function serves as an arbitrator to set the state of a cooling
 device. It sets the cooling device to the deepest cooling state if
 possible.
 
-6. thermal_emergency_poweroff
+5. thermal_emergency_poweroff
 =============================
 
 On an event of critical trip temperature crossing. Thermal framework
drivers/thermal/thermal_core.c +1 -100

127 lines not on this page · raw message

include/linux/thermal.h +0 -11
index e45659c759209..d9111aebb97d6 100644
@@ -544,15 +544,4 @@ static inline void thermal_notify_framework(struct thermal_zone_device *tz,
 { }
 #endif /* CONFIG_THERMAL */
 
-#if defined(CONFIG_NET) && IS_ENABLED(CONFIG_THERMAL)
-extern int thermal_generate_netlink_event(struct thermal_zone_device *tz,
-						enum events event);
-#else
-static inline int thermal_generate_netlink_event(struct thermal_zone_device *tz,
-						enum events event)
-{
-	return 0;
-}
-#endif
-
 #endif /* __THERMAL_H__ */
Signature · 1 line
2.17.1
#2 lore raw

PATCH v4 2/6 thermal: Initialize thermal subsystem earlier

In reply to Amit Kucheria

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.

---
 drivers/thermal/thermal_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/thermal/thermal_core.c +1 -1
index cced0638b686f..69fcd54f8a83e 100644
@@ -1537,4 +1537,4 @@ static int __init thermal_init(void)
 	mutex_destroy(&poweroff_lock);
 	return result;
 }
-fs_initcall(thermal_init);
+core_initcall(thermal_init);
Signature · 1 line
2.17.1
#3 lore raw

PATCH v4 3/6 cpufreq: Initialise the governors in core_initcall

In reply to Amit Kucheria

Initialise the cpufreq governors earlier to allow for earlier performance control during the boot process.

---
 drivers/cpufreq/cpufreq_conservative.c | 2 +-
 drivers/cpufreq/cpufreq_ondemand.c     | 2 +-
 drivers/cpufreq/cpufreq_performance.c  | 2 +-
 drivers/cpufreq/cpufreq_powersave.c    | 2 +-
 drivers/cpufreq/cpufreq_userspace.c    | 2 +-
 kernel/sched/cpufreq_schedutil.c       | 2 +-
 6 files changed, 6 insertions(+), 6 deletions(-)
drivers/cpufreq/cpufreq_conservative.c +1 -1
index b66e81c06a575..737ff3b9c2c09 100644
@@ -346,7 +346,7 @@ struct cpufreq_governor *cpufreq_default_governor(void)
 	return CPU_FREQ_GOV_CONSERVATIVE;
 }
 
-fs_initcall(cpufreq_gov_dbs_init);
+core_initcall(cpufreq_gov_dbs_init);
 #else
 module_init(cpufreq_gov_dbs_init);
 #endif
drivers/cpufreq/cpufreq_ondemand.c +1 -1
index dced033875bf8..82a4d37ddecb3 100644
@@ -483,7 +483,7 @@ struct cpufreq_governor *cpufreq_default_governor(void)
 	return CPU_FREQ_GOV_ONDEMAND;
 }
 
-fs_initcall(cpufreq_gov_dbs_init);
+core_initcall(cpufreq_gov_dbs_init);
 #else
 module_init(cpufreq_gov_dbs_init);
 #endif
drivers/cpufreq/cpufreq_performance.c +1 -1
index aaa04dfcacd9d..def9afe0f5b86 100644
@@ -50,5 +50,5 @@ MODULE_AUTHOR("Dominik Brodowski <[email protected]>");
 MODULE_DESCRIPTION("CPUfreq policy governor 'performance'");
 MODULE_LICENSE("GPL");
 
-fs_initcall(cpufreq_gov_performance_init);
+core_initcall(cpufreq_gov_performance_init);
 module_exit(cpufreq_gov_performance_exit);
drivers/cpufreq/cpufreq_powersave.c +1 -1
index c143dc237d878..1ae66019eb835 100644
@@ -43,7 +43,7 @@ struct cpufreq_governor *cpufreq_default_governor(void)
 	return &cpufreq_gov_powersave;
 }
 
-fs_initcall(cpufreq_gov_powersave_init);
+core_initcall(cpufreq_gov_powersave_init);
 #else
 module_init(cpufreq_gov_powersave_init);
 #endif
drivers/cpufreq/cpufreq_userspace.c +1 -1
index cbd81c58cb8f0..b43e7cd502c58 100644
@@ -147,7 +147,7 @@ struct cpufreq_governor *cpufreq_default_governor(void)
 	return &cpufreq_gov_userspace;
 }
 
-fs_initcall(cpufreq_gov_userspace_init);
+core_initcall(cpufreq_gov_userspace_init);
 #else
 module_init(cpufreq_gov_userspace_init);
 #endif
kernel/sched/cpufreq_schedutil.c +1 -1
index 86800b4d5453f..322ca8860f548 100644
@@ -915,7 +915,7 @@ static int __init sugov_register(void)
 {
 	return cpufreq_register_governor(&schedutil_gov);
 }
-fs_initcall(sugov_register);
+core_initcall(sugov_register);
 
 #ifdef CONFIG_ENERGY_MODEL
 extern bool sched_energy_update;
Signature · 1 line
2.17.1
Reviewed-by on v4 3/6
#4 lore raw

Re: [PATCH v4 3/6] cpufreq: Initialise the governors in core_initcall

Quoted 5 lines · CEST Amit Kucheria

Initialise the cpufreq governors earlier to allow for earlier performance control during the boot process.

No more issues found, so

Quoted 86 lines
---
 drivers/cpufreq/cpufreq_conservative.c | 2 +-
 drivers/cpufreq/cpufreq_ondemand.c     | 2 +-
 drivers/cpufreq/cpufreq_performance.c  | 2 +-
 drivers/cpufreq/cpufreq_powersave.c    | 2 +-
 drivers/cpufreq/cpufreq_userspace.c    | 2 +-
 kernel/sched/cpufreq_schedutil.c       | 2 +-
 6 files changed, 6 insertions(+), 6 deletions(-)
drivers/cpufreq/cpufreq_conservative.c +1 -1
index b66e81c06a575..737ff3b9c2c09 100644
@@ -346,7 +346,7 @@ struct cpufreq_governor *cpufreq_default_governor(void)
 	return CPU_FREQ_GOV_CONSERVATIVE;
 }
 
-fs_initcall(cpufreq_gov_dbs_init);
+core_initcall(cpufreq_gov_dbs_init);
 #else
 module_init(cpufreq_gov_dbs_init);
 #endif
drivers/cpufreq/cpufreq_ondemand.c +1 -1
index dced033875bf8..82a4d37ddecb3 100644
@@ -483,7 +483,7 @@ struct cpufreq_governor *cpufreq_default_governor(void)
 	return CPU_FREQ_GOV_ONDEMAND;
 }
 
-fs_initcall(cpufreq_gov_dbs_init);
+core_initcall(cpufreq_gov_dbs_init);
 #else
 module_init(cpufreq_gov_dbs_init);
 #endif
drivers/cpufreq/cpufreq_performance.c +1 -1
index aaa04dfcacd9d..def9afe0f5b86 100644
@@ -50,5 +50,5 @@ MODULE_AUTHOR("Dominik Brodowski <[email protected]>");
 MODULE_DESCRIPTION("CPUfreq policy governor 'performance'");
 MODULE_LICENSE("GPL");
 
-fs_initcall(cpufreq_gov_performance_init);
+core_initcall(cpufreq_gov_performance_init);
 module_exit(cpufreq_gov_performance_exit);
drivers/cpufreq/cpufreq_powersave.c +1 -1
index c143dc237d878..1ae66019eb835 100644
@@ -43,7 +43,7 @@ struct cpufreq_governor *cpufreq_default_governor(void)
 	return &cpufreq_gov_powersave;
 }
 
-fs_initcall(cpufreq_gov_powersave_init);
+core_initcall(cpufreq_gov_powersave_init);
 #else
 module_init(cpufreq_gov_powersave_init);
 #endif
drivers/cpufreq/cpufreq_userspace.c +1 -1
index cbd81c58cb8f0..b43e7cd502c58 100644
@@ -147,7 +147,7 @@ struct cpufreq_governor *cpufreq_default_governor(void)
 	return &cpufreq_gov_userspace;
 }
 
-fs_initcall(cpufreq_gov_userspace_init);
+core_initcall(cpufreq_gov_userspace_init);
 #else
 module_init(cpufreq_gov_userspace_init);
 #endif
kernel/sched/cpufreq_schedutil.c +1 -1
index 86800b4d5453f..322ca8860f548 100644
@@ -915,7 +915,7 @@ static int __init sugov_register(void)
 {
 	return cpufreq_register_governor(&schedutil_gov);
 }
-fs_initcall(sugov_register);
+core_initcall(sugov_register);
 
 #ifdef CONFIG_ENERGY_MODEL
 extern bool sched_energy_update;
#5 lore raw

PATCH v4 4/6 cpufreq: Initialize cpufreq-dt driver earlier

In reply to Amit Kucheria

This allows HW drivers that depend on cpufreq-dt to initialise earlier.

---
 drivers/cpufreq/cpufreq-dt-platdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cpufreq/cpufreq-dt-platdev.c +1 -1
index bca8d1f47fd2c..3282defe14d41 100644
@@ -180,4 +180,4 @@ static int __init cpufreq_dt_platdev_init(void)
 			       -1, data,
 			       sizeof(struct cpufreq_dt_platform_data)));
 }
-device_initcall(cpufreq_dt_platdev_init);
+core_initcall(cpufreq_dt_platdev_init);
Signature · 1 line
2.17.1
#6 lore raw

Re: [PATCH v4 4/6] cpufreq: Initialize cpufreq-dt driver earlier

Quoted 1 line · Amit Kucheria

This allows HW drivers that depend on cpufreq-dt to initialise earlier.

My obsessive-compulsive in-brain spellchecker noticed that the title says 'initialize' (US spelling), while the comment uses 'initialise' (UK spelling). Just in case this is not some post-Brexit expression of cross-Atlantic friendliness you might want to fix it. :)

Thanks,

Ingo

#7 lore raw

Re: [PATCH v4 4/6] cpufreq: Initialize cpufreq-dt driver earlier

Quoted 10 lines · Ingo Molnar
Quoted 1 line · Amit Kucheria

This allows HW drivers that depend on cpufreq-dt to initialise earlier.

My obsessive-compulsive in-brain spellchecker noticed that the title says 'initialize' (US spelling), while the comment uses 'initialise' (UK spelling). Just in case this is not some post-Brexit expression of cross-Atlantic friendliness you might want to fix it. :)

Naah, its just my confused brain that grew up learning British English, then spent enough time in US to pick up some of that too. I think it is a form of selective spelling blindness :-)

Will fix.

#8 lore raw

PATCH v4 5/6 clk: qcom: Initialise clock drivers earlier

In reply to Amit Kucheria

Initialise the clock drivers on sdm845 and qcs404 in core_initcall so we can have earlier access to cpufreq during booting.

---
 drivers/clk/qcom/clk-rpmh.c   | 2 +-
 drivers/clk/qcom/gcc-qcs404.c | 2 +-
 drivers/clk/qcom/gcc-sdm845.c | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
drivers/clk/qcom/clk-rpmh.c +1 -1
index 96a36f6ff667d..20d4258f125b9 100644
@@ -487,7 +487,7 @@ static int __init clk_rpmh_init(void)
 {
 	return platform_driver_register(&clk_rpmh_driver);
 }
-subsys_initcall(clk_rpmh_init);
+core_initcall(clk_rpmh_init);
 
 static void __exit clk_rpmh_exit(void)
 {
drivers/clk/qcom/gcc-qcs404.c +1 -1
index bd32212f37e64..9b0c4ce2ef4ec 100644
@@ -2855,7 +2855,7 @@ static int __init gcc_qcs404_init(void)
 {
 	return platform_driver_register(&gcc_qcs404_driver);
 }
-subsys_initcall(gcc_qcs404_init);
+core_initcall(gcc_qcs404_init);
 
 static void __exit gcc_qcs404_exit(void)
 {
drivers/clk/qcom/gcc-sdm845.c +1 -1
index 95be125c3bddf..49dcff1af2db1 100644
@@ -3628,7 +3628,7 @@ static int __init gcc_sdm845_init(void)
 {
 	return platform_driver_register(&gcc_sdm845_driver);
 }
-subsys_initcall(gcc_sdm845_init);
+core_initcall(gcc_sdm845_init);
 
 static void __exit gcc_sdm845_exit(void)
 {
Signature · 1 line
2.17.1
maintainer Acked-by on v4 5/6
#9 lore raw

Re: [PATCH v4 5/6] clk: qcom: Initialise clock drivers earlier

Quoted 10 lines · Amit Kucheria

Initialise the clock drivers on sdm845 and qcs404 in core_initcall so we can have earlier access to cpufreq during booting.

---
 drivers/clk/qcom/clk-rpmh.c   | 2 +-
 drivers/clk/qcom/gcc-qcs404.c | 2 +-
 drivers/clk/qcom/gcc-sdm845.c | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
Signature · 1 line
viresh
#10 lore raw

PATCH v4 6/6 cpufreq: qcom-hw: Move driver initialisation earlier

In reply to Amit Kucheria

Allow qcom-hw driver to initialise right after the cpufreq and thermal subsystems are initialised in core_initcall so we get earlier access to thermal mitigation.

---
 drivers/cpufreq/qcom-cpufreq-hw.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cpufreq/qcom-cpufreq-hw.c +1 -1
index a9ae2f84a4efc..fc92a8842e252 100644
@@ -334,7 +334,7 @@ static int __init qcom_cpufreq_hw_init(void)
 {
 	return platform_driver_register(&qcom_cpufreq_hw_driver);
 }
-device_initcall(qcom_cpufreq_hw_init);
+postcore_initcall(qcom_cpufreq_hw_init);
 
 static void __exit qcom_cpufreq_hw_exit(void)
 {
Signature · 1 line
2.17.1
maintainer Acked-by on v4 6/6
#11 lore raw

Re: [PATCH v4 6/6] cpufreq: qcom-hw: Move driver initialisation earlier

Quoted 16 lines · Amit Kucheria

Allow qcom-hw driver to initialise right after the cpufreq and thermal subsystems are initialised in core_initcall so we get earlier access to thermal mitigation.

---
 drivers/cpufreq/qcom-cpufreq-hw.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cpufreq/qcom-cpufreq-hw.c +0 -0
index a9ae2f84a4efc..fc92a8842e252 100644

drivers/cpufreq/qcom-cpufreq-hw.c static int __init qcom_cpufreq_hw_init(void) · line 340

Quoted 8 lines
drivers/cpufreq/qcom-cpufreq-hw.c +1 -1
@@ -334,7 +334,7 @@ static int __init qcom_cpufreq_hw_init(void)
 {
 	return platform_driver_register(&qcom_cpufreq_hw_driver);
 }
-device_initcall(qcom_cpufreq_hw_init);
+postcore_initcall(qcom_cpufreq_hw_init);
 
 static void __exit qcom_cpufreq_hw_exit(void)
 {
Signature · 1 line
viresh
#12 lore raw

Re: [PATCH v4 6/6] cpufreq: qcom-hw: Move driver initialisation earlier

In reply to Amit Kucheria
Quoted 7 lines · Amit Kucheria

Allow qcom-hw driver to initialise right after the cpufreq and thermal subsystems are initialised in core_initcall so we get earlier access to thermal mitigation.

Hi Amit,

Booting linux-next on my db845c (and SDM850 laptop) I can see that the device probes in /sys/bus/platform/drivers/qcom-cpufreq-hw, but /sys/devices/system/cpu/cpufreq is empty.

Reverting this change gives me cpufreq back. Can you please have a look at this?

Regards,
Bjorn

Quoted 20 lines
---
 drivers/cpufreq/qcom-cpufreq-hw.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cpufreq/qcom-cpufreq-hw.c +1 -1
index a9ae2f84a4efc..fc92a8842e252 100644
@@ -334,7 +334,7 @@ static int __init qcom_cpufreq_hw_init(void)
 {
 	return platform_driver_register(&qcom_cpufreq_hw_driver);
 }
-device_initcall(qcom_cpufreq_hw_init);
+postcore_initcall(qcom_cpufreq_hw_init);
 
 static void __exit qcom_cpufreq_hw_exit(void)
 {
Signature · 1 line
2.17.1