MIPS: Loongson: Make CPUFreq usable for Loongson-3
Subsystems (3)
PATCH v2 12/12 MIPS: Loongson: Make CPUFreq usable for Loongson-3
Loongson-3A/3B support frequency scaling. But due to hardware limitation, Loongson-3A's frequency scaling is not independent for each core, we suggest enable Loongson-3A's CPUFreq only when there is one core online. Loongson-3B can adjust frequency independently for each core, so it can be always enabled.
Each package has only one register (ChipConfig or FreqCtrl) to control frequency, so we need spinlocks to protect register access for multi- cores. However, we cannot use spinlock when a core becomes into "wait" status (frequency = 0), so we only enable "wait" when there is one core in a package online.
arch/mips/kernel/smp.c is modified to guarantee udelay_val has the correct value while both CPU hotplug and CPUFreq are enabled.
--- arch/mips/include/asm/mach-loongson/loongson.h | 1 + arch/mips/kernel/smp.c | 3 +- arch/mips/loongson/Kconfig | 1 + arch/mips/loongson/common/platform.c | 13 +- arch/mips/loongson/loongson-3/Makefile | 2 +- arch/mips/loongson/loongson-3/clock.c | 191 +++++++++++++++++++ drivers/cpufreq/Kconfig | 14 ++ drivers/cpufreq/Makefile | 1 + drivers/cpufreq/loongson3_cpufreq.c | 240 ++++++++++++++++++++++++ 9 files changed, 461 insertions(+), 5 deletions(-) create mode 100644 arch/mips/loongson/loongson-3/clock.c create mode 100644 drivers/cpufreq/loongson3_cpufreq.c
arch/mips/include/asm/mach-loongson/loongson.h +1 -0
@@ -278,6 +278,7 @@ extern u64 loongson_freqctrl[MAX_PACKAGES];#ifdef CONFIG_CPU_SUPPORTS_CPUFREQ #include <linux/cpufreq.h> extern struct cpufreq_frequency_table loongson2_clockmod_table[]; +extern struct cpufreq_frequency_table loongson3_clockmod_table[];#endif /*
arch/mips/kernel/smp.c +2 -1
@@ -136,7 +136,8 @@ asmlinkage void start_secondary(void)calibrate_delay ();preempt_disable (); cpu =smp_processor_id (); - cpu_data[cpu].udelay_val = loops_per_jiffy; +if (!cpu_data[cpu].udelay_val) + cpu_data[cpu].udelay_val = loops_per_jiffy;cpu_set (cpu, cpu_coherent_mask);notify_cpu_starting (cpu);
arch/mips/loongson/Kconfig +1 -0
@@ -69,6 +69,7 @@ config LOONGSON_MACH3X select CSRC_R4K select CEVT_R4K select CPU_HAS_WB + select HAVE_CLK select HW_HAS_PCI select ISA select HT_PCI
arch/mips/loongson/common/platform.c +10 -3
@@ -17,15 +17,22 @@ static struct platform_device loongson2_cpufreq_device = { .id = -1, }; -static int __init loongson2_cpufreq_init (void ) +static struct platform_device loongson3_cpufreq_device = { + .name ="loongson3_cpufreq" , + .id =-1 , +}; + +static int __init loongson_cpufreq_init (void ) {struct cpuinfo_mips *c = ¤t_cpu_data;/* Only 2F revision and it's successors support CPUFreq */ -if ((c->processor_id &PRID_REV_MASK ) >=PRID_REV_LOONGSON2F ) +if ((c->processor_id &PRID_REV_MASK ) ==PRID_REV_LOONGSON2F )return platform_device_register (&loongson2_cpufreq_device); +if ((c->processor_id &PRID_REV_MASK ) >=PRID_REV_LOONGSON3A ) +return platform_device_register (&loongson3_cpufreq_device);return -ENODEV ; } -arch_initcall (loongson2_cpufreq_init); +arch_initcall (loongson_cpufreq_init);
arch/mips/loongson/loongson-3/Makefile +1 -1
@@ -1,7 +1,7 @@ # # Makefile for Loongson-3 family machines # -obj-y += irq.o cop2-ex.o platform.o +obj-y += irq.o cop2-ex.o platform.o clock.o obj-$(CONFIG_SMP) += smp.o
arch/mips/loongson/loongson-3/clock.c new file +191 -0
191 lines not on this page · raw message
drivers/cpufreq/Kconfig +14 -0
@@ -240,6 +240,7 @@ depends on MIPS config LOONGSON2_CPUFREQ tristate "Loongson2 CPUFreq Driver" + depends on CPU_LOONGSON2 help This option adds a CPUFreq driver for loongson processors which support software configurable cpu frequency.
@@ -250,6 +251,19 @@ config LOONGSON2_CPUFREQ If in doubt, say N. +config LOONGSON3_CPUFREQ + tristate "Loongson3 CPUFreq Driver" + depends on CPU_LOONGSON3 + help + This option adds a CPUFreq driver for loongson processors which + support software configurable cpu frequency. + + Loongson-3A and it's successors support this feature. + + For details, take a look at <file:Documentation/cpu-freq/>. + + If in doubt, say N. + endmenu menu "PowerPC CPU frequency scaling drivers"
drivers/cpufreq/Makefile +1 -0
@@ -98,6 +98,7 @@ obj-$(CONFIG_CRIS_MACH_ARTPEC3) += cris-artpec3-cpufreq.o obj-$(CONFIG_ETRAXFS) += cris-etraxfs-cpufreq.o obj-$(CONFIG_IA64_ACPI_CPUFREQ) += ia64-acpi-cpufreq.o obj-$(CONFIG_LOONGSON2_CPUFREQ) += loongson2_cpufreq.o +obj-$(CONFIG_LOONGSON3_CPUFREQ) += loongson3_cpufreq.o obj-$(CONFIG_SH_CPU_FREQ) += sh-cpufreq.o obj-$(CONFIG_SPARC_US2E_CPUFREQ) += sparc-us2e-cpufreq.o obj-$(CONFIG_SPARC_US3_CPUFREQ) += sparc-us3-cpufreq.o
drivers/cpufreq/loongson3_cpufreq.c new file +240 -0
240 lines not on this page · raw message
Signature · 1 line
1.7.7.3
arch/mips/kernel/smp.c asmlinkage void start_secondary(void) · line 140
Quoted 11 lines · Huacai Chen
arch/mips/kernel/smp.c +2
-1@@ -136,7 +136,8 @@ asmlinkage void start_secondary(void)calibrate_delay ();preempt_disable (); cpu =smp_processor_id (); - cpu_data[cpu].udelay_val = loops_per_jiffy; +if (!cpu_data[cpu].udelay_val) + cpu_data[cpu].udelay_val = loops_per_jiffy;
Why this? Is the idea that the value of loops_per_jiffy which was set on bootup may no longer match the actual clock frequency?
Ralf
Hi, Ralf,
Loops_per_jiffy is set on startup and doesn't change later. It reflect the maximum value frequency, but for CPU hotplug, a new online CPU may not run at the maximum frequency (remain the old value before it is offline).
Huacai
Quoted 19 lines · Ralf Baechle
arch/mips/kernel/smp.c asmlinkage void start_secondary(void) · line 140
Quoted 11 lines · Huacai Chen
arch/mips/kernel/smp.c +2
-1@@ -136,7 +136,8 @@ asmlinkage void start_secondary(void)calibrate_delay ();preempt_disable (); cpu =smp_processor_id (); - cpu_data[cpu].udelay_val = loops_per_jiffy; +if (!cpu_data[cpu].udelay_val) + cpu_data[cpu].udelay_val = loops_per_jiffy;Why this? Is the idea that the value of
loops_per_jiffywhich was set on bootup may no longer match the actual clock frequency?Ralf
Quoted 4 lines · Huacai Chen
Loops_per_jiffyis set on startup and doesn't change later. It reflect the maximum value frequency, but for CPU hotplug, a new online CPU may not run at the maximum frequency (remain the old value before it is offline).
As suspected. But what if a CPU is hotunplugged, then the clockrate for all the CPUs changes and then the gets re-hotplugged into the system. Wouldn't in that case the udelay_val be used?
Ralf
Hi, Ralf,
I hope I didn't misunderstand your meaning...
If all cores share the same clockrate (like Loongson-3A), then CPUFreq driver should update all core's udelay_val (include the offline core's udelay_val) at frequency changing. If each core has its own clockrate (like Loongson-3B), the new online core can use its old udelay_val when online. In any case, we don't use loops_per_jiffy for CPU hotplug. Maybe you need to see set_shared_udelay_val() in my patch.
Huacai
Quoted 13 lines · Ralf Baechle
Quoted 4 lines · Huacai Chen
Loops_per_jiffyis set on startup and doesn't change later. It reflect the maximum value frequency, but for CPU hotplug, a new online CPU may not run at the maximum frequency (remain the old value before it is offline).As suspected. But what if a CPU is hotunplugged, then the clockrate for all the CPUs changes and then the gets re-hotplugged into the system. Wouldn't in that case the
udelay_valbe used?Ralf