Skip to content

Commit 96c4726

Browse files
shilpasrirafaeljw
authored andcommitted
cpufreq: powernv: Remove cpu_to_chip_id() from hot-path
cpu_to_chip_id() does a DT walk through to find out the chip id by taking a contended device tree lock. This adds an unnecessary overhead in a hot path. So instead of calling cpu_to_chip_id() everytime cache the chip ids for all cores in the array 'core_to_chip_map' and use it in the hotpath. Reported-by: Anton Blanchard <anton@samba.org> Signed-off-by: Shilpasri G Bhat <shilpa.bhat@linux.vnet.ibm.com> Reviewed-by: Gautham R. Shenoy <ego@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 6d167a4 commit 96c4726

1 file changed

Lines changed: 20 additions & 3 deletions

File tree

‎drivers/cpufreq/powernv-cpufreq.c‎

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343

4444
static struct cpufreq_frequency_table powernv_freqs[POWERNV_MAX_PSTATES+1];
4545
static bool rebooting, throttled, occ_reset;
46+
static unsigned int *core_to_chip_map;
4647

4748
static struct chip {
4849
unsigned int id;
@@ -313,13 +314,14 @@ static inline unsigned int get_nominal_index(void)
313314
static void powernv_cpufreq_throttle_check(void *data)
314315
{
315316
unsigned int cpu = smp_processor_id();
317+
unsigned int chip_id = core_to_chip_map[cpu_core_index_of_thread(cpu)];
316318
unsigned long pmsr;
317319
int pmsr_pmax, i;
318320

319321
pmsr = get_pmspr(SPRN_PMSR);
320322

321323
for (i = 0; i < nr_chips; i++)
322-
if (chips[i].id == cpu_to_chip_id(cpu))
324+
if (chips[i].id == chip_id)
323325
break;
324326

325327
/* Check for Pmax Capping */
@@ -559,19 +561,29 @@ static int init_chip_info(void)
559561
unsigned int chip[256];
560562
unsigned int cpu, i;
561563
unsigned int prev_chip_id = UINT_MAX;
564+
cpumask_t cpu_mask;
565+
int ret = -ENOMEM;
562566

563-
for_each_possible_cpu(cpu) {
567+
core_to_chip_map = kcalloc(cpu_nr_cores(), sizeof(unsigned int),
568+
GFP_KERNEL);
569+
if (!core_to_chip_map)
570+
goto out;
571+
572+
cpumask_copy(&cpu_mask, cpu_possible_mask);
573+
for_each_cpu(cpu, &cpu_mask) {
564574
unsigned int id = cpu_to_chip_id(cpu);
565575

566576
if (prev_chip_id != id) {
567577
prev_chip_id = id;
568578
chip[nr_chips++] = id;
569579
}
580+
core_to_chip_map[cpu_core_index_of_thread(cpu)] = id;
581+
cpumask_andnot(&cpu_mask, &cpu_mask, cpu_sibling_mask(cpu));
570582
}
571583

572584
chips = kmalloc_array(nr_chips, sizeof(struct chip), GFP_KERNEL);
573585
if (!chips)
574-
return -ENOMEM;
586+
goto free_chip_map;
575587

576588
for (i = 0; i < nr_chips; i++) {
577589
chips[i].id = chip[i];
@@ -582,6 +594,10 @@ static int init_chip_info(void)
582594
}
583595

584596
return 0;
597+
free_chip_map:
598+
kfree(core_to_chip_map);
599+
out:
600+
return ret;
585601
}
586602

587603
static int __init powernv_cpufreq_init(void)
@@ -616,6 +632,7 @@ static void __exit powernv_cpufreq_exit(void)
616632
opal_message_notifier_unregister(OPAL_MSG_OCC,
617633
&powernv_cpufreq_opal_nb);
618634
kfree(chips);
635+
kfree(core_to_chip_map);
619636
cpufreq_unregister_driver(&powernv_cpufreq_driver);
620637
}
621638
module_exit(powernv_cpufreq_exit);

0 commit comments

Comments
 (0)