|
| 1 | +ACPI: processor: reduce CPUFREQ thermal reduction pctg for Tegra241 |
| 2 | + |
| 3 | +jira LE-1907 |
| 4 | +Rebuild_History Non-Buildable kernel-5.14.0-427.35.1.el9_4 |
| 5 | +commit-author Srikar Srimath Tirumala <srikars@nvidia.com> |
| 6 | +commit 310293a2b94197f3d75e65ab22672287a7938a00 |
| 7 | +Empty-Commit: Cherry-Pick Conflicts during history rebuild. |
| 8 | +Will be included in final tarball splat. Ref for failed cherry-pick at: |
| 9 | +ciq/ciq_backports/kernel-5.14.0-427.35.1.el9_4/310293a2.failed |
| 10 | + |
| 11 | +Current implementation of processor_thermal performs software throttling |
| 12 | +in fixed steps of "20%" which can be too coarse for some platforms. |
| 13 | +We observed some performance gain after reducing the throttle percentage. |
| 14 | +Change the CPUFREQ thermal reduction percentage and maximum thermal steps |
| 15 | +to be configurable. Also, update the default values of both for Nvidia |
| 16 | +Tegra241 (Grace) SoC. The thermal reduction percentage is reduced to "5%" |
| 17 | +and accordingly the maximum number of thermal steps are increased as they |
| 18 | +are derived from the reduction percentage. |
| 19 | + |
| 20 | + Signed-off-by: Srikar Srimath Tirumala <srikars@nvidia.com> |
| 21 | +Co-developed-by: Sumit Gupta <sumitg@nvidia.com> |
| 22 | + Signed-off-by: Sumit Gupta <sumitg@nvidia.com> |
| 23 | + Acked-by: Sudeep Holla <sudeep.holla@arm.com> |
| 24 | + Acked-by: Hanjun Guo <guohanjun@huawei.com> |
| 25 | + Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> |
| 26 | +(cherry picked from commit 310293a2b94197f3d75e65ab22672287a7938a00) |
| 27 | + Signed-off-by: Jonathan Maple <jmaple@ciq.com> |
| 28 | + |
| 29 | +# Conflicts: |
| 30 | +# drivers/acpi/arm64/Makefile |
| 31 | +diff --cc drivers/acpi/arm64/Makefile |
| 32 | +index e21a9e84e394,726944648c9b..000000000000 |
| 33 | +--- a/drivers/acpi/arm64/Makefile |
| 34 | ++++ b/drivers/acpi/arm64/Makefile |
| 35 | +@@@ -3,4 -3,6 +3,10 @@@ obj-$(CONFIG_ACPI_AGDI) += agdi. |
| 36 | + obj-$(CONFIG_ACPI_IORT) += iort.o |
| 37 | + obj-$(CONFIG_ACPI_GTDT) += gtdt.o |
| 38 | + obj-$(CONFIG_ACPI_APMT) += apmt.o |
| 39 | +++<<<<<<< HEAD |
| 40 | + +obj-y += dma.o |
| 41 | +++======= |
| 42 | ++ obj-$(CONFIG_ARM_AMBA) += amba.o |
| 43 | ++ obj-y += dma.o init.o |
| 44 | ++ obj-y += thermal_cpufreq.o |
| 45 | +++>>>>>>> 310293a2b941 (ACPI: processor: reduce CPUFREQ thermal reduction pctg for Tegra241) |
| 46 | +* Unmerged path drivers/acpi/arm64/Makefile |
| 47 | +diff --git a/drivers/acpi/arm64/thermal_cpufreq.c b/drivers/acpi/arm64/thermal_cpufreq.c |
| 48 | +new file mode 100644 |
| 49 | +index 000000000000..d524f2cd6044 |
| 50 | +--- /dev/null |
| 51 | ++++ b/drivers/acpi/arm64/thermal_cpufreq.c |
| 52 | +@@ -0,0 +1,20 @@ |
| 53 | ++// SPDX-License-Identifier: GPL-2.0-only |
| 54 | ++#include <linux/acpi.h> |
| 55 | ++ |
| 56 | ++#include "../internal.h" |
| 57 | ++ |
| 58 | ++#define SMCCC_SOC_ID_T241 0x036b0241 |
| 59 | ++ |
| 60 | ++int acpi_arch_thermal_cpufreq_pctg(void) |
| 61 | ++{ |
| 62 | ++ s32 soc_id = arm_smccc_get_soc_id_version(); |
| 63 | ++ |
| 64 | ++ /* |
| 65 | ++ * Check JEP106 code for NVIDIA Tegra241 chip (036b:0241) and |
| 66 | ++ * reduce the CPUFREQ Thermal reduction percentage to 5%. |
| 67 | ++ */ |
| 68 | ++ if (soc_id == SMCCC_SOC_ID_T241) |
| 69 | ++ return 5; |
| 70 | ++ |
| 71 | ++ return 0; |
| 72 | ++} |
| 73 | +diff --git a/drivers/acpi/internal.h b/drivers/acpi/internal.h |
| 74 | +index 06ad497067ac..215f80de9996 100644 |
| 75 | +--- a/drivers/acpi/internal.h |
| 76 | ++++ b/drivers/acpi/internal.h |
| 77 | +@@ -88,6 +88,15 @@ bool acpi_scan_is_offline(struct acpi_device *adev, bool uevent); |
| 78 | + acpi_status acpi_sysfs_table_handler(u32 event, void *table, void *context); |
| 79 | + void acpi_scan_table_notify(void); |
| 80 | + |
| 81 | ++#ifdef CONFIG_ARM64 |
| 82 | ++int acpi_arch_thermal_cpufreq_pctg(void); |
| 83 | ++#else |
| 84 | ++static inline int acpi_arch_thermal_cpufreq_pctg(void) |
| 85 | ++{ |
| 86 | ++ return 0; |
| 87 | ++} |
| 88 | ++#endif |
| 89 | ++ |
| 90 | + /* -------------------------------------------------------------------------- |
| 91 | + Device Node Initialization / Removal |
| 92 | + -------------------------------------------------------------------------- */ |
| 93 | +diff --git a/drivers/acpi/processor_thermal.c b/drivers/acpi/processor_thermal.c |
| 94 | +index b7c6287eccca..1219adb11ab9 100644 |
| 95 | +--- a/drivers/acpi/processor_thermal.c |
| 96 | ++++ b/drivers/acpi/processor_thermal.c |
| 97 | +@@ -17,6 +17,8 @@ |
| 98 | + #include <acpi/processor.h> |
| 99 | + #include <linux/uaccess.h> |
| 100 | + |
| 101 | ++#include "internal.h" |
| 102 | ++ |
| 103 | + #ifdef CONFIG_CPU_FREQ |
| 104 | + |
| 105 | + /* If a passive cooling situation is detected, primarily CPUfreq is used, as it |
| 106 | +@@ -26,12 +28,21 @@ |
| 107 | + */ |
| 108 | + |
| 109 | + #define CPUFREQ_THERMAL_MIN_STEP 0 |
| 110 | +-#define CPUFREQ_THERMAL_MAX_STEP 3 |
| 111 | + |
| 112 | +-static DEFINE_PER_CPU(unsigned int, cpufreq_thermal_reduction_pctg); |
| 113 | ++static int cpufreq_thermal_max_step __read_mostly = 3; |
| 114 | ++ |
| 115 | ++/* |
| 116 | ++ * Minimum throttle percentage for processor_thermal cooling device. |
| 117 | ++ * The processor_thermal driver uses it to calculate the percentage amount by |
| 118 | ++ * which cpu frequency must be reduced for each cooling state. This is also used |
| 119 | ++ * to calculate the maximum number of throttling steps or cooling states. |
| 120 | ++ */ |
| 121 | ++static int cpufreq_thermal_reduction_pctg __read_mostly = 20; |
| 122 | + |
| 123 | +-#define reduction_pctg(cpu) \ |
| 124 | +- per_cpu(cpufreq_thermal_reduction_pctg, phys_package_first_cpu(cpu)) |
| 125 | ++static DEFINE_PER_CPU(unsigned int, cpufreq_thermal_reduction_step); |
| 126 | ++ |
| 127 | ++#define reduction_step(cpu) \ |
| 128 | ++ per_cpu(cpufreq_thermal_reduction_step, phys_package_first_cpu(cpu)) |
| 129 | + |
| 130 | + /* |
| 131 | + * Emulate "per package data" using per cpu data (which should really be |
| 132 | +@@ -71,7 +82,7 @@ static int cpufreq_get_max_state(unsigned int cpu) |
| 133 | + if (!cpu_has_cpufreq(cpu)) |
| 134 | + return 0; |
| 135 | + |
| 136 | +- return CPUFREQ_THERMAL_MAX_STEP; |
| 137 | ++ return cpufreq_thermal_max_step; |
| 138 | + } |
| 139 | + |
| 140 | + static int cpufreq_get_cur_state(unsigned int cpu) |
| 141 | +@@ -79,7 +90,7 @@ static int cpufreq_get_cur_state(unsigned int cpu) |
| 142 | + if (!cpu_has_cpufreq(cpu)) |
| 143 | + return 0; |
| 144 | + |
| 145 | +- return reduction_pctg(cpu); |
| 146 | ++ return reduction_step(cpu); |
| 147 | + } |
| 148 | + |
| 149 | + static int cpufreq_set_cur_state(unsigned int cpu, int state) |
| 150 | +@@ -92,7 +103,7 @@ static int cpufreq_set_cur_state(unsigned int cpu, int state) |
| 151 | + if (!cpu_has_cpufreq(cpu)) |
| 152 | + return 0; |
| 153 | + |
| 154 | +- reduction_pctg(cpu) = state; |
| 155 | ++ reduction_step(cpu) = state; |
| 156 | + |
| 157 | + /* |
| 158 | + * Update all the CPUs in the same package because they all |
| 159 | +@@ -113,7 +124,8 @@ static int cpufreq_set_cur_state(unsigned int cpu, int state) |
| 160 | + if (!policy) |
| 161 | + return -EINVAL; |
| 162 | + |
| 163 | +- max_freq = (policy->cpuinfo.max_freq * (100 - reduction_pctg(i) * 20)) / 100; |
| 164 | ++ max_freq = (policy->cpuinfo.max_freq * |
| 165 | ++ (100 - reduction_step(i) * cpufreq_thermal_reduction_pctg)) / 100; |
| 166 | + |
| 167 | + cpufreq_cpu_put(policy); |
| 168 | + |
| 169 | +@@ -126,10 +138,29 @@ static int cpufreq_set_cur_state(unsigned int cpu, int state) |
| 170 | + return 0; |
| 171 | + } |
| 172 | + |
| 173 | ++static void acpi_thermal_cpufreq_config(void) |
| 174 | ++{ |
| 175 | ++ int cpufreq_pctg = acpi_arch_thermal_cpufreq_pctg(); |
| 176 | ++ |
| 177 | ++ if (!cpufreq_pctg) |
| 178 | ++ return; |
| 179 | ++ |
| 180 | ++ cpufreq_thermal_reduction_pctg = cpufreq_pctg; |
| 181 | ++ |
| 182 | ++ /* |
| 183 | ++ * Derive the MAX_STEP from minimum throttle percentage so that the reduction |
| 184 | ++ * percentage doesn't end up becoming negative. Also, cap the MAX_STEP so that |
| 185 | ++ * the CPU performance doesn't become 0. |
| 186 | ++ */ |
| 187 | ++ cpufreq_thermal_max_step = (100 / cpufreq_pctg) - 2; |
| 188 | ++} |
| 189 | ++ |
| 190 | + void acpi_thermal_cpufreq_init(struct cpufreq_policy *policy) |
| 191 | + { |
| 192 | + unsigned int cpu; |
| 193 | + |
| 194 | ++ acpi_thermal_cpufreq_config(); |
| 195 | ++ |
| 196 | + for_each_cpu(cpu, policy->related_cpus) { |
| 197 | + struct acpi_processor *pr = per_cpu(processors, cpu); |
| 198 | + int ret; |
| 199 | +@@ -190,7 +221,7 @@ static int acpi_processor_max_state(struct acpi_processor *pr) |
| 200 | + |
| 201 | + /* |
| 202 | + * There exists four states according to |
| 203 | +- * cpufreq_thermal_reduction_pctg. 0, 1, 2, 3 |
| 204 | ++ * cpufreq_thermal_reduction_step. 0, 1, 2, 3 |
| 205 | + */ |
| 206 | + max_state += cpufreq_get_max_state(pr->id); |
| 207 | + if (pr->flags.throttling) |
0 commit comments