Skip to content

Commit 053819e

Browse files
shilpasrirafaeljw
authored andcommitted
cpufreq: powernv: Handle throttling due to Pmax capping at chip level
The On-Chip-Controller(OCC) can throttle cpu frequency by reducing the max allowed frequency for that chip if the chip exceeds its power or temperature limits. As Pmax capping is a chip level condition report this throttling behavior at chip level and also do not set the global 'throttled' on Pmax capping instead set the per-chip throttled variable. Report unthrottling if Pmax is restored after throttling. This patch adds a structure to store chip id and throttled state of the chip. Signed-off-by: Shilpasri G Bhat <shilpa.bhat@linux.vnet.ibm.com> Reviewed-by: Preeti U Murthy <preeti@linux.vnet.ibm.com> Acked-by: Viresh Kumar <viresh.kumar@linaro.org> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent a34e63b commit 053819e

File tree

1 file changed

+55
-4
lines changed

1 file changed

+55
-4
lines changed

drivers/cpufreq/powernv-cpufreq.c

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <linux/smp.h>
2828
#include <linux/of.h>
2929
#include <linux/reboot.h>
30+
#include <linux/slab.h>
3031

3132
#include <asm/cputhreads.h>
3233
#include <asm/firmware.h>
@@ -42,6 +43,13 @@
4243
static struct cpufreq_frequency_table powernv_freqs[POWERNV_MAX_PSTATES+1];
4344
static bool rebooting, throttled;
4445

46+
static struct chip {
47+
unsigned int id;
48+
bool throttled;
49+
} *chips;
50+
51+
static int nr_chips;
52+
4553
/*
4654
* Note: The set of pstates consists of contiguous integers, the
4755
* smallest of which is indicated by powernv_pstate_info.min, the
@@ -301,22 +309,33 @@ static inline unsigned int get_nominal_index(void)
301309
static void powernv_cpufreq_throttle_check(unsigned int cpu)
302310
{
303311
unsigned long pmsr;
304-
int pmsr_pmax, pmsr_lp;
312+
int pmsr_pmax, pmsr_lp, i;
305313

306314
pmsr = get_pmspr(SPRN_PMSR);
307315

316+
for (i = 0; i < nr_chips; i++)
317+
if (chips[i].id == cpu_to_chip_id(cpu))
318+
break;
319+
308320
/* Check for Pmax Capping */
309321
pmsr_pmax = (s8)PMSR_MAX(pmsr);
310322
if (pmsr_pmax != powernv_pstate_info.max) {
311-
throttled = true;
312-
pr_info("CPU %d Pmax is reduced to %d\n", cpu, pmsr_pmax);
313-
pr_info("Max allowed Pstate is capped\n");
323+
if (chips[i].throttled)
324+
goto next;
325+
chips[i].throttled = true;
326+
pr_info("CPU %d on Chip %u has Pmax reduced to %d\n", cpu,
327+
chips[i].id, pmsr_pmax);
328+
} else if (chips[i].throttled) {
329+
chips[i].throttled = false;
330+
pr_info("CPU %d on Chip %u has Pmax restored to %d\n", cpu,
331+
chips[i].id, pmsr_pmax);
314332
}
315333

316334
/*
317335
* Check for Psafe by reading LocalPstate
318336
* or check if Psafe_mode_active is set in PMSR.
319337
*/
338+
next:
320339
pmsr_lp = (s8)PMSR_LP(pmsr);
321340
if ((pmsr_lp < powernv_pstate_info.min) ||
322341
(pmsr & PMSR_PSAFE_ENABLE)) {
@@ -414,6 +433,33 @@ static struct cpufreq_driver powernv_cpufreq_driver = {
414433
.attr = powernv_cpu_freq_attr,
415434
};
416435

436+
static int init_chip_info(void)
437+
{
438+
unsigned int chip[256];
439+
unsigned int cpu, i;
440+
unsigned int prev_chip_id = UINT_MAX;
441+
442+
for_each_possible_cpu(cpu) {
443+
unsigned int id = cpu_to_chip_id(cpu);
444+
445+
if (prev_chip_id != id) {
446+
prev_chip_id = id;
447+
chip[nr_chips++] = id;
448+
}
449+
}
450+
451+
chips = kmalloc_array(nr_chips, sizeof(struct chip), GFP_KERNEL);
452+
if (!chips)
453+
return -ENOMEM;
454+
455+
for (i = 0; i < nr_chips; i++) {
456+
chips[i].id = chip[i];
457+
chips[i].throttled = false;
458+
}
459+
460+
return 0;
461+
}
462+
417463
static int __init powernv_cpufreq_init(void)
418464
{
419465
int rc = 0;
@@ -429,6 +475,11 @@ static int __init powernv_cpufreq_init(void)
429475
return rc;
430476
}
431477

478+
/* Populate chip info */
479+
rc = init_chip_info();
480+
if (rc)
481+
return rc;
482+
432483
register_reboot_notifier(&powernv_cpufreq_reboot_nb);
433484
return cpufreq_register_driver(&powernv_cpufreq_driver);
434485
}

0 commit comments

Comments
 (0)