Skip to content

Commit 310293a

Browse files
Srikar Srimath Tirumalarafaeljw
authored andcommitted
ACPI: processor: reduce CPUFREQ thermal reduction pctg for Tegra241
Current implementation of processor_thermal performs software throttling in fixed steps of "20%" which can be too coarse for some platforms. We observed some performance gain after reducing the throttle percentage. Change the CPUFREQ thermal reduction percentage and maximum thermal steps to be configurable. Also, update the default values of both for Nvidia Tegra241 (Grace) SoC. The thermal reduction percentage is reduced to "5%" and accordingly the maximum number of thermal steps are increased as they are derived from the reduction percentage. Signed-off-by: Srikar Srimath Tirumala <srikars@nvidia.com> Co-developed-by: Sumit Gupta <sumitg@nvidia.com> Signed-off-by: Sumit Gupta <sumitg@nvidia.com> Acked-by: Sudeep Holla <sudeep.holla@arm.com> Acked-by: Hanjun Guo <guohanjun@huawei.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 4c2ba6a commit 310293a

File tree

4 files changed

+70
-9
lines changed

4 files changed

+70
-9
lines changed

drivers/acpi/arm64/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ obj-$(CONFIG_ACPI_GTDT) += gtdt.o
55
obj-$(CONFIG_ACPI_APMT) += apmt.o
66
obj-$(CONFIG_ARM_AMBA) += amba.o
77
obj-y += dma.o init.o
8+
obj-y += thermal_cpufreq.o

drivers/acpi/arm64/thermal_cpufreq.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// SPDX-License-Identifier: GPL-2.0-only
2+
#include <linux/acpi.h>
3+
4+
#include "../internal.h"
5+
6+
#define SMCCC_SOC_ID_T241 0x036b0241
7+
8+
int acpi_arch_thermal_cpufreq_pctg(void)
9+
{
10+
s32 soc_id = arm_smccc_get_soc_id_version();
11+
12+
/*
13+
* Check JEP106 code for NVIDIA Tegra241 chip (036b:0241) and
14+
* reduce the CPUFREQ Thermal reduction percentage to 5%.
15+
*/
16+
if (soc_id == SMCCC_SOC_ID_T241)
17+
return 5;
18+
19+
return 0;
20+
}

drivers/acpi/internal.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,15 @@ bool acpi_scan_is_offline(struct acpi_device *adev, bool uevent);
8585
acpi_status acpi_sysfs_table_handler(u32 event, void *table, void *context);
8686
void acpi_scan_table_notify(void);
8787

88+
#ifdef CONFIG_ARM64
89+
int acpi_arch_thermal_cpufreq_pctg(void);
90+
#else
91+
static inline int acpi_arch_thermal_cpufreq_pctg(void)
92+
{
93+
return 0;
94+
}
95+
#endif
96+
8897
/* --------------------------------------------------------------------------
8998
Device Node Initialization / Removal
9099
-------------------------------------------------------------------------- */

drivers/acpi/processor_thermal.c

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#include <acpi/processor.h>
1818
#include <linux/uaccess.h>
1919

20+
#include "internal.h"
21+
2022
#ifdef CONFIG_CPU_FREQ
2123

2224
/* If a passive cooling situation is detected, primarily CPUfreq is used, as it
@@ -26,12 +28,21 @@
2628
*/
2729

2830
#define CPUFREQ_THERMAL_MIN_STEP 0
29-
#define CPUFREQ_THERMAL_MAX_STEP 3
3031

31-
static DEFINE_PER_CPU(unsigned int, cpufreq_thermal_reduction_pctg);
32+
static int cpufreq_thermal_max_step __read_mostly = 3;
33+
34+
/*
35+
* Minimum throttle percentage for processor_thermal cooling device.
36+
* The processor_thermal driver uses it to calculate the percentage amount by
37+
* which cpu frequency must be reduced for each cooling state. This is also used
38+
* to calculate the maximum number of throttling steps or cooling states.
39+
*/
40+
static int cpufreq_thermal_reduction_pctg __read_mostly = 20;
3241

33-
#define reduction_pctg(cpu) \
34-
per_cpu(cpufreq_thermal_reduction_pctg, phys_package_first_cpu(cpu))
42+
static DEFINE_PER_CPU(unsigned int, cpufreq_thermal_reduction_step);
43+
44+
#define reduction_step(cpu) \
45+
per_cpu(cpufreq_thermal_reduction_step, phys_package_first_cpu(cpu))
3546

3647
/*
3748
* Emulate "per package data" using per cpu data (which should really be
@@ -71,15 +82,15 @@ static int cpufreq_get_max_state(unsigned int cpu)
7182
if (!cpu_has_cpufreq(cpu))
7283
return 0;
7384

74-
return CPUFREQ_THERMAL_MAX_STEP;
85+
return cpufreq_thermal_max_step;
7586
}
7687

7788
static int cpufreq_get_cur_state(unsigned int cpu)
7889
{
7990
if (!cpu_has_cpufreq(cpu))
8091
return 0;
8192

82-
return reduction_pctg(cpu);
93+
return reduction_step(cpu);
8394
}
8495

8596
static int cpufreq_set_cur_state(unsigned int cpu, int state)
@@ -92,7 +103,7 @@ static int cpufreq_set_cur_state(unsigned int cpu, int state)
92103
if (!cpu_has_cpufreq(cpu))
93104
return 0;
94105

95-
reduction_pctg(cpu) = state;
106+
reduction_step(cpu) = state;
96107

97108
/*
98109
* Update all the CPUs in the same package because they all
@@ -113,7 +124,8 @@ static int cpufreq_set_cur_state(unsigned int cpu, int state)
113124
if (!policy)
114125
return -EINVAL;
115126

116-
max_freq = (policy->cpuinfo.max_freq * (100 - reduction_pctg(i) * 20)) / 100;
127+
max_freq = (policy->cpuinfo.max_freq *
128+
(100 - reduction_step(i) * cpufreq_thermal_reduction_pctg)) / 100;
117129

118130
cpufreq_cpu_put(policy);
119131

@@ -126,10 +138,29 @@ static int cpufreq_set_cur_state(unsigned int cpu, int state)
126138
return 0;
127139
}
128140

141+
static void acpi_thermal_cpufreq_config(void)
142+
{
143+
int cpufreq_pctg = acpi_arch_thermal_cpufreq_pctg();
144+
145+
if (!cpufreq_pctg)
146+
return;
147+
148+
cpufreq_thermal_reduction_pctg = cpufreq_pctg;
149+
150+
/*
151+
* Derive the MAX_STEP from minimum throttle percentage so that the reduction
152+
* percentage doesn't end up becoming negative. Also, cap the MAX_STEP so that
153+
* the CPU performance doesn't become 0.
154+
*/
155+
cpufreq_thermal_max_step = (100 / cpufreq_pctg) - 2;
156+
}
157+
129158
void acpi_thermal_cpufreq_init(struct cpufreq_policy *policy)
130159
{
131160
unsigned int cpu;
132161

162+
acpi_thermal_cpufreq_config();
163+
133164
for_each_cpu(cpu, policy->related_cpus) {
134165
struct acpi_processor *pr = per_cpu(processors, cpu);
135166
int ret;
@@ -190,7 +221,7 @@ static int acpi_processor_max_state(struct acpi_processor *pr)
190221

191222
/*
192223
* There exists four states according to
193-
* cpufreq_thermal_reduction_pctg. 0, 1, 2, 3
224+
* cpufreq_thermal_reduction_step. 0, 1, 2, 3
194225
*/
195226
max_state += cpufreq_get_max_state(pr->id);
196227
if (pr->flags.throttling)

0 commit comments

Comments
 (0)