]>
Commit | Line | Data |
---|---|---|
1 | From eee289fa5e07e0be94dfad2b17de823945329f4c Mon Sep 17 00:00:00 2001 | |
2 | From: Sasha Levin <sashal@kernel.org> | |
3 | Date: Thu, 29 Feb 2024 13:42:07 +0530 | |
4 | Subject: cpufreq: Don't unregister cpufreq cooling on CPU hotplug | |
5 | ||
6 | From: Viresh Kumar <viresh.kumar@linaro.org> | |
7 | ||
8 | [ Upstream commit c4d61a529db788d2e52654f5b02c8d1de4952c5b ] | |
9 | ||
10 | Offlining a CPU and bringing it back online is a common operation and it | |
11 | happens frequently during system suspend/resume, where the non-boot CPUs | |
12 | are hotplugged out during suspend and brought back at resume. | |
13 | ||
14 | The cpufreq core already tries to make this path as fast as possible as | |
15 | the changes are only temporary in nature and full cleanup of resources | |
16 | isn't required in this case. For example the drivers can implement | |
17 | online()/offline() callbacks to avoid a lot of tear down of resources. | |
18 | ||
19 | On similar lines, there is no need to unregister the cpufreq cooling | |
20 | device during suspend / resume, but only while the policy is getting | |
21 | removed. | |
22 | ||
23 | Moreover, unregistering the cpufreq cooling device is resulting in an | |
24 | unwanted outcome, where the system suspend is eventually aborted in the | |
25 | process. Currently, during system suspend the cpufreq core unregisters | |
26 | the cooling device, which in turn removes a kobject using device_del() | |
27 | and that generates a notification to the userspace via uevent broadcast. | |
28 | This causes system suspend to abort in some setups. | |
29 | ||
30 | This was also earlier reported (indirectly) by Roman [1]. Maybe there is | |
31 | another way around to fixing that problem properly, but this change | |
32 | makes sense anyways. | |
33 | ||
34 | Move the registering and unregistering of the cooling device to policy | |
35 | creation and removal times onlyy. | |
36 | ||
37 | Closes: https://bugzilla.kernel.org/show_bug.cgi?id=218521 | |
38 | Reported-by: Manaf Meethalavalappu Pallikunhi <quic_manafm@quicinc.com> | |
39 | Reported-by: Roman Stratiienko <r.stratiienko@gmail.com> | |
40 | Link: https://patchwork.kernel.org/project/linux-pm/patch/20220710164026.541466-1-r.stratiienko@gmail.com/ [1] | |
41 | Tested-by: Manaf Meethalavalappu Pallikunhi <quic_manafm@quicinc.com> | |
42 | Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org> | |
43 | Reviewed-by: Dhruva Gole <d-gole@ti.com> | |
44 | Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> | |
45 | Signed-off-by: Sasha Levin <sashal@kernel.org> | |
46 | --- | |
47 | drivers/cpufreq/cpufreq.c | 17 +++++++++++------ | |
48 | 1 file changed, 11 insertions(+), 6 deletions(-) | |
49 | ||
50 | diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c | |
51 | index 7d570b44777ac..3c2c955fbbbd6 100644 | |
52 | --- a/drivers/cpufreq/cpufreq.c | |
53 | +++ b/drivers/cpufreq/cpufreq.c | |
54 | @@ -1576,7 +1576,8 @@ static int cpufreq_online(unsigned int cpu) | |
55 | if (cpufreq_driver->ready) | |
56 | cpufreq_driver->ready(policy); | |
57 | ||
58 | - if (cpufreq_thermal_control_enabled(cpufreq_driver)) | |
59 | + /* Register cpufreq cooling only for a new policy */ | |
60 | + if (new_policy && cpufreq_thermal_control_enabled(cpufreq_driver)) | |
61 | policy->cdev = of_cpufreq_cooling_register(policy); | |
62 | ||
63 | pr_debug("initialization complete\n"); | |
64 | @@ -1660,11 +1661,6 @@ static void __cpufreq_offline(unsigned int cpu, struct cpufreq_policy *policy) | |
65 | else | |
66 | policy->last_policy = policy->policy; | |
67 | ||
68 | - if (cpufreq_thermal_control_enabled(cpufreq_driver)) { | |
69 | - cpufreq_cooling_unregister(policy->cdev); | |
70 | - policy->cdev = NULL; | |
71 | - } | |
72 | - | |
73 | if (has_target()) | |
74 | cpufreq_exit_governor(policy); | |
75 | ||
76 | @@ -1725,6 +1721,15 @@ static void cpufreq_remove_dev(struct device *dev, struct subsys_interface *sif) | |
77 | return; | |
78 | } | |
79 | ||
80 | + /* | |
81 | + * Unregister cpufreq cooling once all the CPUs of the policy are | |
82 | + * removed. | |
83 | + */ | |
84 | + if (cpufreq_thermal_control_enabled(cpufreq_driver)) { | |
85 | + cpufreq_cooling_unregister(policy->cdev); | |
86 | + policy->cdev = NULL; | |
87 | + } | |
88 | + | |
89 | /* We did light-weight exit earlier, do full tear down now */ | |
90 | if (cpufreq_driver->offline) | |
91 | cpufreq_driver->exit(policy); | |
92 | -- | |
93 | 2.43.0 | |
94 |