Add smp support for Allwinner A20 and phy arch count timer
Subsystems (6)
cover Add smp support for Allwinner A20 and phy arch count timer
The patchs add smp support for Allwinner A20. It add cpuregister node in dts forsmp configure. The patchs also add a options for phy count timer to replace vir count timer as ARM arch timer clocksource. About ARM arch timer: 1. Current kernel use vir count timer, vir count timer can be accessed in any cpu mode for kernel, but it need bootloader set vir count offset rigister zero at first. 2. Phy count timer can be accessed in most cpu mode for kernel except NS-PL1 mode when register CNTHCTL.PL1PCTEN is set to zero. To ensure to use phy count timer, bootloader should set register CNTHCTL.PL1PCTEN is 1 at first. At all, to ensure kernel can use arch timer, bootload should set some generic timer register(cntvoff or cnthctl) at first. the kernel should select which count timer by reading current kernel running mode.
Fan Rong (4):
Add smp support for Allwinner A20(sunxi 7i).
Add cpuconfig nodes in dts for smp configure.
Add physical count arch timer support for clocksource in ARMv7. Add arch count timer node in dts for Allwinner A20(sunxi 7i).
arch/arm/boot/dts/sun7i-a20.dtsi | 18 +- arch/arm/include/asm/arch_timer.h | 11 ++ arch/arm/mach-sunxi/Makefile | 2 + arch/arm/mach-sunxi/headsmp.S | 12 ++ arch/arm/mach-sunxi/platform.h | 346 ++++++++++++++++++++++++++++++++++ arch/arm/mach-sunxi/platsmp.c | 166 ++++++++++++++++ arch/arm/mach-sunxi/sunxi.c | 4 + drivers/clocksource/Kconfig | 8 + drivers/clocksource/arm_arch_timer.c | 10 +- 9 files changed, 574 insertions(+), 3 deletions(-) create mode 100644 arch/arm/mach-sunxi/headsmp.S create mode 100644 arch/arm/mach-sunxi/platform.h create mode 100644 arch/arm/mach-sunxi/platsmp.c
Signature · 1 line
1.7.9.5
PATCH 1/4 Add smp support for Allwinner A20(sunxi 7i).
--- arch/arm/mach-sunxi/Makefile | 2 + arch/arm/mach-sunxi/headsmp.S | 12 ++ arch/arm/mach-sunxi/platform.h | 346 ++++++++++++++++++++++++++++++++++++++++ arch/arm/mach-sunxi/platsmp.c | 166 +++++++++++++++++++ arch/arm/mach-sunxi/sunxi.c | 4 + 5 files changed, 530 insertions(+) create mode 100644 arch/arm/mach-sunxi/headsmp.S create mode 100644 arch/arm/mach-sunxi/platform.h create mode 100644 arch/arm/mach-sunxi/platsmp.c
arch/arm/mach-sunxi/Makefile +2 -0
@@ -1 +1,3 @@ obj-$(CONFIG_ARCH_SUNXI) += sunxi.o +obj-$(CONFIG_ARCH_SUNXI) += platsmp.o +obj-$(CONFIG_ARCH_SUNXI) += headsmp.o
arch/arm/mach-sunxi/headsmp.S new file +12 -0
@@ -0,0 +1,12 @@ +#include <linux/linkage.h> +#include <linux/init.h> + + .section ".text.head", "ax" + __CPUINIT + +ENTRY(sun7i_secondary_startup) + msr cpsr_fsxc, #0xd3 + mov r0, #0 + ldr r1, =0xffffffff + b secondary_startup +ENDPROC(sun7i_secondary_startup)
arch/arm/mach-sunxi/platform.h new file +346 -0
346 lines not on this page · raw message
arch/arm/mach-sunxi/platsmp.c new file +166 -0
166 lines not on this page · raw message
arch/arm/mach-sunxi/sunxi.c +4 -0
@@ -26,6 +26,9 @@#include <asm/mach/map.h> #include <asm/system_misc.h> +#include "platform.h" + +#define SUN4I_WATCHDOG_CTRL_REG 0x00#define SUN4I_WATCHDOG_CTRL_RESTART BIT(0)#define SUN4I_WATCHDOG_MODE_REG 0x04
@@ -139,6 +142,7 @@ static const char * const sunxi_board_dt_compat[] = { };DT_MACHINE_START (SUNXI_DT ,"Allwinner A1X (Device Tree)" ) + .smp = smp_ops(sunxi7i_smp_ops), .init_machine = sunxi_dt_init, .init_time = sunxi_timer_init, .dt_compat = sunxi_board_dt_compat,
Signature · 1 line
1.7.9.5
PATCH 2/4 Add cpuconfig nodes in dts for smp configure.
In reply to Fan Rong--- arch/arm/boot/dts/sun7i-a20.dtsi | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
arch/arm/boot/dts/sun7i-a20.dtsi +7 -2
@@ -20,13 +20,13 @@ #address-cells = <1>; #size-cells = <0>; - cpu at 0 { + cpu0: cpu at 0 { compatible = "arm,cortex-a7"; device_type = "cpu"; reg = <0>; }; - cpu at 1 { + cpu1: cpu at 1 { compatible = "arm,cortex-a7"; device_type = "cpu"; reg = <1>;
@@ -167,6 +167,11 @@ #size-cells = <1>; ranges; + cc: cpuconfig at 01c25c00 { + compatible = "allwinner,sun7i-cc"; + reg = <0x01c25c00 0x400>; + }; + pio: pinctrl at 01c20800 { compatible = "allwinner,sun7i-a20-pinctrl"; reg = <0x01c20800 0x400>;
Signature · 1 line
1.7.9.5
PATCH 3/4 Add physical count arch timer support for clocksource in ARMv7.
In reply to Fan Rong--- arch/arm/include/asm/arch_timer.h | 11 +++++++++++ drivers/clocksource/Kconfig | 8 ++++++++ drivers/clocksource/arm_arch_timer.c | 10 +++++++++- 3 files changed, 28 insertions(+), 1 deletion(-)
arch/arm/include/asm/arch_timer.h +11 -0
@@ -87,6 +87,17 @@ static inline u64 arch_counter_get_cntvct(void)return cval; } +static inline u64 arch_counter_get_cntpct (void ) +{ +u64 cval; + +isb (); + asmvolatile ("mrrc p15, 0, %Q0, %R0, c14" :"=r" (cval)); +return cval; +} + + +static inline void arch_counter_set_user_access (void ) {u32 cntkctl;
drivers/clocksource/Kconfig +8 -0
@@ -109,3 +109,11 @@ config VF_PIT_TIMER bool help Support for Period Interrupt Timer on Freescale Vybrid Family SoCs. +menu "Clock Source" + +config ARM_ARCH_TIMER_USE_PHYCNT + bool "Use Physical Count Timer" + depends on ARM_ARCH_TIMER + help + If bootloader dont set Virtual Offset register,Physical Count Timer is needed to replace Virtual Count Timer. +endmenu
drivers/clocksource/arm_arch_timer.c +9 -1
@@ -372,7 +372,11 @@ static u64 arch_counter_get_cntvct_mem(void)* to exist on arm64. arm doesn't use this before DT is probed so even * if we don't have the cp15 accessors we won't have a problem. */ -u64 (*arch_timer_read_counter)(void) = arch_counter_get_cntvct; +#ifdef CONFIG_ARM_ARCH_TIMER_USE_PHYCNT +u64 (*arch_timer_read_counter)(void) = arch_counter_get_cntpct; +#else +u64 (*arch_timer_read_counter)(void) = arch_counter_get_cntvct; +#endif static cycle_t arch_counter_read (struct clocksource *cs) {
@@ -410,7 +414,11 @@ static void __init arch_counter_register(unsigned type)/* Register the CP15 based counter if we have one */ if (type & ARCH_CP15_TIMER) +#ifdef CONFIG_ARM_ARCH_TIMER_USE_PHYCNT + arch_timer_read_counter = arch_counter_get_cntpct; +#else arch_timer_read_counter = arch_counter_get_cntvct; +#endif else arch_timer_read_counter = arch_counter_get_cntvct_mem;
Signature · 1 line
1.7.9.5
PATCH 4/4 Add arch count timer node in dts for Allwinner A20(sunxi 7i).
In reply to Fan Rong--- arch/arm/boot/dts/sun7i-a20.dtsi | 9 +++++++++ 1 file changed, 9 insertions(+)
arch/arm/boot/dts/sun7i-a20.dtsi +9 -0
@@ -312,5 +312,14 @@ #interrupt-cells = <3>; interrupts = <1 9 0xf04>; }; + + timer { + compatible ="arm,armv7-timer"; + interrupts = <1 13 0x308>, + <1 14 0x308>, + <1 11 0x308>, + <1 10 0x308>; + clock-frequency = <24000000>; + }; }; };
Signature · 1 line
1.7.9.5
Mark Rutland
maintainerRe: [PATCH 3/4] Add physical count arch timer support for clocksource in ARMv7.
In reply to Fan RongQuoted 35 lines · Fan Rong
Signed-off-by Fan Rong <[email protected]>--- arch/arm/include/asm/arch_timer.h | 11 +++++++++++ drivers/clocksource/Kconfig | 8 ++++++++ drivers/clocksource/arm_arch_timer.c | 10 +++++++++- 3 files changed, 28 insertions(+), 1 deletion(-)arch/arm/include/asm/arch_timer.h +11
-0@@ -87,6 +87,17 @@ static inline u64 arch_counter_get_cntvct(void)return cval; } +static inline u64 arch_counter_get_cntpct (void ) +{ +u64 cval; + +isb (); + asmvolatile ("mrrc p15, 0, %Q0, %R0, c14" :"=r" (cval)); +return cval; +} + + +static inline void arch_counter_set_user_access (void ) {u32 cntkctl;drivers/clocksource/Kconfig +0
-0@@ -109,3 +109,11 @@ config VF_PIT_TIMER bool
drivers/clocksource/Kconfig config VF_PIT_TIMER · line 119
Quoted 10 lines
drivers/clocksource/Kconfig +8
-0help Support for Period Interrupt Timer on Freescale Vybrid Family SoCs. +menu "Clock Source" + +config ARM_ARCH_TIMER_USE_PHYCNT + bool "Use Physical Count Timer" + depends on ARM_ARCH_TIMER + help + If bootloader dont set Virtual Offset register,Physical Count Timer is needed to replace Virtual Count Timer. +endmenu
This cannot be a compile-time option as above in a multiplatform build. Other paltforms (e.g. KVM guests) *must* use the virtual counters to get any semblance of a consistent view of time.
Why can the bootloader not be fixed to set CNTVOFF (or to boot the kernel in Hyp mode)?
Thanks,
Mark.
Quoted 33 lines
drivers/clocksource/arm_arch_timer.c +9
-1@@ -372,7 +372,11 @@ static u64 arch_counter_get_cntvct_mem(void)* to exist on arm64. arm doesn't use this before DT is probed so even * if we don't have the cp15 accessors we won't have a problem. */ -u64 (*arch_timer_read_counter)(void) = arch_counter_get_cntvct; +#ifdef CONFIG_ARM_ARCH_TIMER_USE_PHYCNT +u64 (*arch_timer_read_counter)(void) = arch_counter_get_cntpct; +#else +u64 (*arch_timer_read_counter)(void) = arch_counter_get_cntvct; +#endif static cycle_t arch_counter_read (struct clocksource *cs) {@@ -410,7 +414,11 @@ static void __init arch_counter_register(unsigned type)/* Register the CP15 based counter if we have one */ if (type & ARCH_CP15_TIMER) +#ifdef CONFIG_ARM_ARCH_TIMER_USE_PHYCNT + arch_timer_read_counter = arch_counter_get_cntpct; +#else arch_timer_read_counter = arch_counter_get_cntvct; +#endif else arch_timer_read_counter = arch_counter_get_cntvct_mem;Signature · 1 line
1.7.9.5
Re: [PATCH 1/4] Add smp support for Allwinner A20(sunxi 7i).
In reply to Fan RongQuoted 12 lines · Fan Rong
Signed-off-by Fan Rong <[email protected]>--- arch/arm/mach-sunxi/Makefile | 2 + arch/arm/mach-sunxi/headsmp.S | 12 ++ arch/arm/mach-sunxi/platform.h | 346 ++++++++++++++++++++++++++++++++++++++++ arch/arm/mach-sunxi/platsmp.c | 166 +++++++++++++++++++ arch/arm/mach-sunxi/sunxi.c | 4 + 5 files changed, 530 insertions(+) create mode 100644 arch/arm/mach-sunxi/headsmp.S create mode 100644 arch/arm/mach-sunxi/platform.h create mode 100644 arch/arm/mach-sunxi/platsmp.c
[...]
arch/arm/mach-sunxi/platsmp.c line 46
Quoted 4 lines
arch/arm/mach-sunxi/platsmp.c new file +4
-0+static struct of_device_id sunxi_cc_ids[] = { + { .compatible ="allwinner,sun7i-cc" }, + {/*sentinel*/ } +};
NAK - There's no binding document for this in mainline or this series.
arch/arm/mach-sunxi/platsmp.c line 56
Quoted 10 lines
arch/arm/mach-sunxi/platsmp.c new file +10
-0+ + +static void enable_aw_cpu (int cpu) +{ +long paddr; +u32 pwr_reg; + +struct device_node *np; + np =of_find_matching_node (NULL , sunxi_cc_ids); + cc_base =of_iomap (np,0 );
This seems to get called repeatedly in sunxi7i_boot_secondary, so you're repeatedly trying to find the cc node and mapping it, but never unmapping it. That's both a waste of time and a waste of address space.
It would be nicer to map this once at the start. That seems simpler than stashing the physical address and mapping/unmapping it repeatedly. smp_boot_secondary.
arch/arm/mach-sunxi/platsmp.c line 58
Quoted 2 lines
arch/arm/mach-sunxi/platsmp.c new file +2
-0+pr_debug ("cc_base is %x\n" , (unsigned int )cc_base); +if (!cc_base) {
You can use %p to print pointers, without casting to an integer type.
arch/arm/mach-sunxi/platsmp.c line 60
Quoted 2 lines
arch/arm/mach-sunxi/platsmp.c new file +2
-0+pr_debug ("error map cc configure\n" ); +return ;
As this may be called repeatedly, from a function that can return errors, it would be nice to propagate an error code if there's a failure.
Quoted 48 lines
arch/arm/mach-sunxi/platsmp.c new file +48
-0+ } + + paddr =virt_to_phys (sun7i_secondary_startup); +writel (paddr, cc_base +AW_CPUCFG_P_REG0 ); +/* step1: Assert nCOREPORESET LOW and hold L1RSTDISABLE LOW. +Ensure DBGPWRDUP is held LOW to prevent any external +debug access to the processor. +*/ +/* assert cpu core reset */ +writel (0 , cc_base +CPUX_RESET_CTL (cpu)); +/* L1RSTDISABLE hold low */ + pwr_reg =readl (cc_base +AW_CPUCFG_GENCTL ); + pwr_reg &= ~(1 <<cpu); +writel (pwr_reg, cc_base +AW_CPUCFG_GENCTL ); +/* DBGPWRDUP hold low */ + pwr_reg =readl (cc_base +AW_CPUCFG_DBGCTL1 ); + pwr_reg &= ~(1 <<cpu); +writel (pwr_reg, cc_base +AW_CPUCFG_DBGCTL1 ); + +/* step2: release power clamp */ +writel (0xff , cc_base +AW_CPU1_PWR_CLAMP ); +writel (0x7f , cc_base +AW_CPU1_PWR_CLAMP ); +writel (0x3f , cc_base +AW_CPU1_PWR_CLAMP ); +writel (0x1f , cc_base +AW_CPU1_PWR_CLAMP ); +writel (0x0f , cc_base +AW_CPU1_PWR_CLAMP ); +writel (0x07 , cc_base +AW_CPU1_PWR_CLAMP ); +writel (0x03 , cc_base +AW_CPU1_PWR_CLAMP ); +writel (0x01 , cc_base +AW_CPU1_PWR_CLAMP ); +writel (0x00 , cc_base +AW_CPU1_PWR_CLAMP ); +mdelay (10 ); + +/* step3: clear power-off gating */ + pwr_reg =readl (cc_base +AW_CPU1_PWROFF_REG ); + pwr_reg &= ~(1 ); +writel (pwr_reg, cc_base +AW_CPU1_PWROFF_REG ); +mdelay (1 ); + +/* step4: de-assert core reset */ +writel (3 , cc_base +CPUX_RESET_CTL (cpu)); + +/* step5: assert DBGPWRDUP signal */ + pwr_reg =readl (cc_base +AW_CPUCFG_DBGCTL1 ); + pwr_reg |= (1 <<cpu); +writel (pwr_reg, cc_base +AW_CPUCFG_DBGCTL1 ); + +} + +
arch/arm/mach-sunxi/platsmp.c line 118
Quoted 10 lines
arch/arm/mach-sunxi/platsmp.c new file +10
-0+ +static void sunxi7i_smp_init_cpus (void ) +{ +unsigned int i, ncores; + + +/* HDG: we do not use scu_get_core_count() here as that does not +work on the A20 ? */ + +/* Read current CP15 Cache Size ID Register */
Invalid comment. Judging by the encoding, this is the L2CTLR, not the CCSIDR.
arch/arm/mach-sunxi/platsmp.c line 127
Quoted 9 lines
arch/arm/mach-sunxi/platsmp.c new file +9
-0+ asmvolatile ("mrc p15, 1, %0, c9, c0, 2" :"=r" (ncores)); + ncores = ((ncores >>24 ) &0x3 ) +1 ; + +pr_debug ("[%s] ncores=%d\n" , __func__, ncores); + +for (i =0 ; i < ncores; i++) +set_cpu_possible (i, true); + +}
Even ignoring the above, as long as your dt is correct arm_dt_init_cpu_maps (called from stup_arch) will set the cpus as possible (and handles arbitrary MPIDR values as may be the case in multi-cluster).
You don't need this function -- please remove it.
arch/arm/mach-sunxi/platsmp.c line 138
Quoted 11 lines
arch/arm/mach-sunxi/platsmp.c new file +11
-0+ +/* +* for arch/arm/kernel/smp.c:smp_prepare_cpus(unsigned int max_cpus) +*/ +static void sunxi7i_smp_prepare_cpus (unsigned int max_cpus) +{ +/* +* HDG: we do not call scu_enable() here as the sun6i source dump has +* a modified arch/arm/kernel/smp_scu.c, where scu_enable() is a nop. +*/ +}
A look in smp.c shows smp_prepare_cpus is perfectly happy to not have a smp_prepare_cpus callback. You don't need this function -- please remove it.
arch/arm/mach-sunxi/platform.h line 36
Quoted 6 lines
arch/arm/mach-sunxi/platform.h new file +6
-0+ + + + + +
Why so much space here (and elsewhere)?
arch/arm/mach-sunxi/platsmp.c line 152
Quoted 8 lines
arch/arm/mach-sunxi/platsmp.c new file +8
-0+/* +* for linux/arch/arm/kernel/smp.c:__cpu_up(..) +*/ +static int sunxi7i_boot_secondary (unsigned int cpu,struct task_struct *idle) +{ +pr_debug ("[%s] enter cpu %d\n" , __func__, cpu); +spin_lock (&boot_lock); +enable_aw_cpu (cpu);
This can fail. You should propagate the error when it does.
arch/arm/mach-sunxi/platsmp.c line 164
Quoted 12 lines
arch/arm/mach-sunxi/platsmp.c new file +12
-0+spin_unlock (&boot_lock); +return 0 ; +} + + + + +struct smp_operations sunxi7i_smp_ops__initdata = { + .smp_init_cpus = sunxi7i_smp_init_cpus, + .smp_prepare_cpus = sunxi7i_smp_prepare_cpus, + .smp_boot_secondary = sunxi7i_boot_secondary, +};
I believe only smp_boot_secondary is necessary here.
Thanks,
Mark.
Quoted 28 lines
(quoted diff) +2
-0+ +arch/arm/mach-sunxi/sunxi.c +4
-1@@ -26,6 +26,9 @@#include <asm/mach/map.h> #include <asm/system_misc.h> +#include "platform.h" + +#define SUN4I_WATCHDOG_CTRL_REG 0x00#define SUN4I_WATCHDOG_CTRL_RESTART BIT(0)#define SUN4I_WATCHDOG_MODE_REG 0x04@@ -139,6 +142,7 @@ static const char * const sunxi_board_dt_compat[] = { };DT_MACHINE_START (SUNXI_DT ,"Allwinner A1X (Device Tree)" ) + .smp = smp_ops(sunxi7i_smp_ops), .init_machine = sunxi_dt_init, .init_time = sunxi_timer_init, .dt_compat = sunxi_board_dt_compat, --1.7.9.5
Re: [PATCH 3/4] Add physical count arch timer support for clocksource in ARMv7.
In reply to Mark RutlandQuoted 13 lines · Mark Rutland
Quoted 12 lines · Fan Rong
drivers/clocksource/Kconfig +4
-0@@ -109,3 +109,11 @@ config VF_PIT_TIMER bool help Support for Period Interrupt Timer on Freescale Vybrid Family SoCs. +menu "Clock Source" + +config ARM_ARCH_TIMER_USE_PHYCNT + bool "Use Physical Count Timer"
Quoted 8 lines
drivers/clocksource/Kconfig config VF_PIT_TIMER · line 119
Quoted 4 lines
drivers/clocksource/Kconfig +4
-0+ depends on ARM_ARCH_TIMER + help + If bootloader dont set Virtual Offset register,Physical Count Timer is needed to replace Virtual Count Timer. +endmenuThis cannot be a compile-time option as above in a multiplatform build. Other paltforms (e.g. KVM guests) *must* use the virtual counters to get any semblance of a consistent view of time.
Also, for future reference:
1. Use a single blank lines to separate thing like 'menu' and 'endmenu'.
2. Wrap your the help sensibly, don't put it all on one line.
3. It's conventional to use tabs up to below "help" and then two spaces to indent the help text.
4. "," always has one space after it.
Thanks.
Mark Rutland
maintainerQuoted 4 lines · Fan Rong
The patchs add smp support for Allwinner A20. It add cpuregister node in dts forsmp configure. The patchs also add a options for phy count timer to replace vir count timer as ARM arch timer clocksource. About ARM arch timer: 1. Current kernel use vir count timer, vir count timer
Quoted 8 lines
can be accessed in any cpu mode for kernel, but it need bootloader set vir count offset rigister zero at first. 2. Phy count timer can be accessed in most cpu mode for kernel except NS-PL1 mode when register CNTHCTL.PL1PCTEN is set to zero. To ensure to use phy count timer, bootloader should set register CNTHCTL.PL1PCTEN is 1 at first. At all, to ensure kernel can use arch timer, bootload should set some generic timer register(cntvoff or cnthctl) at first. the kernel should select which count timer by reading current kernel running mode.
Sorry, but I find the above text difficult to understand. It jumps between several issues and isn't well formatted.
You seem to be suggesting a kernel change (using CNTPCT), but also bootloader changes (setting CNTHCTL.PL1PCTEN) to make this possible at all. If the bootloader needs to be modified, why can it not be modified to set CNTVOFF (or to boot the kernel in Hyp where it can set it itself)?
I'm not sure what you mean by selecting which timer to use be reading the current running mode. We currently decide to use CNTVCT if booted in PL1, or CNTPCT if booted in Hyp. I assume this isn't the mode you're referring to?
Thanks,
Mark.
Quoted 25 lines
Fan Rong (4):
Add smp support for Allwinner A20(sunxi 7i).
Add cpuconfig nodes in dts for smp configure.
Add physical count arch timer support for clocksource in ARMv7. Add arch count timer node in dts for Allwinner A20(sunxi 7i).arch/arm/boot/dts/sun7i-a20.dtsi | 18 +- arch/arm/include/asm/arch_timer.h | 11 ++ arch/arm/mach-sunxi/Makefile | 2 + arch/arm/mach-sunxi/headsmp.S | 12 ++ arch/arm/mach-sunxi/platform.h | 346 ++++++++++++++++++++++++++++++++++ arch/arm/mach-sunxi/platsmp.c | 166 ++++++++++++++++ arch/arm/mach-sunxi/sunxi.c | 4 + drivers/clocksource/Kconfig | 8 + drivers/clocksource/arm_arch_timer.c | 10 +- 9 files changed, 574 insertions(+), 3 deletions(-) create mode 100644 arch/arm/mach-sunxi/headsmp.S create mode 100644 arch/arm/mach-sunxi/platform.h create mode 100644 arch/arm/mach-sunxi/platsmp.cSignature · 1 line
1.7.9.5
Re: [PATCH 1/4] Add smp support for Allwinner A20(sunxi 7i).
In reply to Fan RongSome other comments:
arch/arm/mach-sunxi/platsmp.c line 73
Quoted 3 lines · Fan Rong
arch/arm/mach-sunxi/platsmp.c new file +3
-0+/* L1RSTDISABLE hold low */ + pwr_reg =readl (cc_base +AW_CPUCFG_GENCTL ); + pwr_reg &= ~(1 <<cpu);
If you pass your patch through checkpatch.pl, it will warn about some of this. You should have one space each side of <<.
arch/arm/mach-sunxi/platsmp.c line 94
Quoted 3 lines
arch/arm/mach-sunxi/platsmp.c new file +3
-0+/* step3: clear power-off gating */ + pwr_reg =readl (cc_base +AW_CPU1_PWROFF_REG ); + pwr_reg &= ~(1 );
You don't need the parens here.
Review
Quoted 2 lines
(quoted diff) +2
-0+ pwr_reg = readl(cc_base + AW_CPUCFG_DBGCTL1); + pwr_reg |= (1<<cpu);
Nor here.
arch/arm/mach-sunxi/platsmp.c line 153
Quoted 6 lines
arch/arm/mach-sunxi/platsmp.c new file +6
-0+static int sunxi7i_boot_secondary (unsigned int cpu,struct task_struct *idle) +{ +pr_debug ("[%s] enter cpu %d\n" , __func__, cpu); +spin_lock (&boot_lock); +enable_aw_cpu (cpu); +spin_unlock (&boot_lock);
What exactly does this spinlock protect? The core code already provides the guarantee that only one CPU will be brought online or taken offline at a time.
Mark Rutland
maintainerRe: [PATCH 4/4] Add arch count timer node in dts for Allwinner A20(sunxi 7i).
In reply to Fan RongQuoted 10 lines · Fan Rong
Signed-off-by Fan Rong <[email protected]>--- arch/arm/boot/dts/sun7i-a20.dtsi | 9 +++++++++ 1 file changed, 9 insertions(+)arch/arm/boot/dts/sun7i-a20.dtsi +0
-0
arch/arm/boot/dts/sun7i-a20.dtsi line 317
Quoted 6 lines
arch/arm/boot/dts/sun7i-a20.dtsi +3
-0@@ -312,5 +312,14 @@ #interrupt-cells = <3>; interrupts = <1 9 0xf04>; }; + + timer { + compatible ="arm,armv7-timer";
Space after the '=' please.
arch/arm/boot/dts/sun7i-a20.dtsi line 322
Quoted 5 lines
arch/arm/boot/dts/sun7i-a20.dtsi +5
-0+ interrupts = <1 13 0x308>, + <1 14 0x308>, + <1 11 0x308>, + <1 10 0x308>; + clock-frequency = <24000000>;
If at all possible, your bootloader should set CNTFREQ, and clock-frequency should only be used as a last resort when it's impossible to get it to set CNTFREQ. It's not possible to set CNTFREQ from the non-secure side, so guests (which might not be Linux, and might not handle DT in the same way) may see a completely wrong frequency value.
Thanks,
Mark.
Quoted 7 lines
arch/arm/boot/dts/sun7i-a20.dtsi +1
-0+ }; }; };Signature · 1 line
1.7.9.5
Re: [linux-sunxi] Re: [PATCH 3/4] Add physical count arch timer support for clocksource in ARMv7.
In reply to Mark RutlandQuoted 3 lines · Mark Rutland
Why can the bootloader not be fixed to set CNTVOFF (or to boot the kernel in Hyp mode)?
It can:
http://lists.xen.org/archives/html/xen-devel/2013-09/msg00880.html
I was waiting for Andre's hyp mode u-boot patches to land before posting the sunxi bits on top. I'm not sure what the status of that is.
Ian.
Re: [linux-sunxi] Re: [PATCH 4/4] Add arch count timer node in dts for Allwinner A20(sunxi 7i).
In reply to Mark RutlandQuoted 4 lines · Mark Rutland
Quoted 4 lines
arch/arm/boot/dts/sun7i-a20.dtsi +4
-0+ interrupts = <1 13 0x308>, + <1 14 0x308>, + <1 11 0x308>, + <1 10 0x308>;
Quoted 8 lines
arch/arm/boot/dts/sun7i-a20.dtsi line 322
Quoted 1 line
arch/arm/boot/dts/sun7i-a20.dtsi +1
-0+ clock-frequency = <24000000>;If at all possible, your bootloader should set CNTFREQ, and clock-frequency should only be used as a last resort when it's impossible to get it to set CNTFREQ. It's not possible to set CNTFREQ from the non-secure side, so guests (which might not be Linux, and might not handle DT in the same way) may see a completely wrong frequency value.
https://groups.google.com/forum/#!topic/linux-sunxi/56Wj1IT-pKU
Ian.
Quoted 5 lines
You seem to be suggesting a kernel change (using CNTPCT), but also bootloader changes (setting CNTHCTL.PL1PCTEN) to make this possible at all. If the bootloader needs to be modified, why can it not be modified to set CNTVOFF (or to boot the kernel in Hyp where it can set it itself)?
I think kernel should can support both CNTVCT and CNTPCT. Yes, if bootloader have set CNTVOFF to zero, then CNTVCT is OK, kvm guest using CNTVCT can run more efficient then that using CNTPCT. but if bootloader dont set it, how about kernel booting? I think kernel should try it's best to boot and run ok even bootload dont set any generic timer register including CNTVOFF and CNTHCTL. So i gave a compile options using CNTPCT. That is only options, If CNTVCT can not working, you have others choice.
Of cause, It is best that kerne can select which timer count is used in running time,
Quoted 4 lines
I'm not sure what you mean by selecting which timer to use be reading the current running mode. We currently decide to use CNTVCT if booted in PL1, or CNTPCT if booted in Hyp. I assume this isn't the mode you're referring to?
Yep, kernel can run PL1 NS=1, PL1 NS=0, PL2. If kernel can know current running Mode.then kernel can chose which timer is OK in running time. 1: If kernel is runing at PL2 and PL1 NS=0, then CNTPCT is OK in any case even CNTVOFF is not zero and CNTHCTL.PL1PCTEN is zero. 2: if kernel is running at PL1 NS=1,then kernel maybe should select CNTVCT. But it has risk to using CNTVCT when CNTVOFF is not zero.
How to deal with the case CNTHCTL.PL1PCTEN is zero and CNTVOFF is not
zero? current kernel cant using any arch timer incluing CNTVCT and
CNTPCT. with this case, I think kernel should use CNTVCT by other
ways: Kernel runing CPUn read CNTVCT and save it to local variable for example InitVctVALUEn in initialization, then kernel running CPUn read timer later return a value as ReadTIMERn=CNTVCTn-InitVctVALUEn, This way can run in any generic timer registe set and in any kernel runing mode. I try to write this patch for new way. But the new way should need more time than old in read timer funcation because it need more calculate.
.
Thanks for your question.
Quoted 56 lines · Mark Rutland
Quoted 4 lines · Fan Rong
The patchs add smp support for Allwinner A20. It add cpuregister node in dts forsmp configure. The patchs also add a options for phy count timer to replace vir count timer as ARM arch timer clocksource. About ARM arch timer: 1. Current kernel use vir count timer, vir count timer
Quoted 8 lines
can be accessed in any cpu mode for kernel, but it need bootloader set vir count offset rigister zero at first. 2. Phy count timer can be accessed in most cpu mode for kernel except NS-PL1 mode when register CNTHCTL.PL1PCTEN is set to zero. To ensure to use phy count timer, bootloader should set register CNTHCTL.PL1PCTEN is 1 at first. At all, to ensure kernel can use arch timer, bootload should set some generic timer register(cntvoff or cnthctl) at first. the kernel should select which count timer by reading current kernel running mode.
Sorry, but I find the above text difficult to understand. It jumps between several issues and isn't well formatted.
You seem to be suggesting a kernel change (using CNTPCT), but also bootloader changes (setting CNTHCTL.PL1PCTEN) to make this possible at all. If the bootloader needs to be modified, why can it not be modified to set CNTVOFF (or to boot the kernel in Hyp where it can set it itself)?
I'm not sure what you mean by selecting which timer to use be reading the current running mode. We currently decide to use CNTVCT if booted in PL1, or CNTPCT if booted in Hyp. I assume this isn't the mode you're referring to?
Thanks,
Mark.Quoted 25 lines
Fan Rong (4):
Add smp support for Allwinner A20(sunxi 7i).
Add cpuconfig nodes in dts for smp configure.
Add physical count arch timer support for clocksource in ARMv7. Add arch count timer node in dts for Allwinner A20(sunxi 7i).arch/arm/boot/dts/sun7i-a20.dtsi | 18 +- arch/arm/include/asm/arch_timer.h | 11 ++ arch/arm/mach-sunxi/Makefile | 2 + arch/arm/mach-sunxi/headsmp.S | 12 ++ arch/arm/mach-sunxi/platform.h | 346 ++++++++++++++++++++++++++++++++++ arch/arm/mach-sunxi/platsmp.c | 166 ++++++++++++++++ arch/arm/mach-sunxi/sunxi.c | 4 + drivers/clocksource/Kconfig | 8 + drivers/clocksource/arm_arch_timer.c | 10 +- 9 files changed, 574 insertions(+), 3 deletions(-) create mode 100644 arch/arm/mach-sunxi/headsmp.S create mode 100644 arch/arm/mach-sunxi/platform.h create mode 100644 arch/arm/mach-sunxi/platsmp.c--
1.7.9.5
Re: [PATCH 1/4] Add smp support for Allwinner A20(sunxi 7i).
In reply to Mark RutlandThanks for you advice, you are right, I will reupdate the patch. :)
Quoted 215 lines · Mark Rutland
Quoted 12 lines · Fan Rong
Signed-off-by Fan Rong <[email protected]>--- arch/arm/mach-sunxi/Makefile | 2 + arch/arm/mach-sunxi/headsmp.S | 12 ++ arch/arm/mach-sunxi/platform.h | 346 ++++++++++++++++++++++++++++++++++++++++ arch/arm/mach-sunxi/platsmp.c | 166 +++++++++++++++++++ arch/arm/mach-sunxi/sunxi.c | 4 + 5 files changed, 530 insertions(+) create mode 100644 arch/arm/mach-sunxi/headsmp.S create mode 100644 arch/arm/mach-sunxi/platform.h create mode 100644 arch/arm/mach-sunxi/platsmp.c[...]
arch/arm/mach-sunxi/platsmp.c line 46
Quoted 4 lines
arch/arm/mach-sunxi/platsmp.c new file +4
-0+static struct of_device_id sunxi_cc_ids[] = { + { .compatible ="allwinner,sun7i-cc" }, + {/*sentinel*/ } +};NAK - There's no binding document for this in mainline or this series.
arch/arm/mach-sunxi/platsmp.c line 56
Quoted 10 lines
arch/arm/mach-sunxi/platsmp.c new file +10
-0+ + +static void enable_aw_cpu (int cpu) +{ +long paddr; +u32 pwr_reg; + +struct device_node *np; + np =of_find_matching_node (NULL , sunxi_cc_ids); + cc_base =of_iomap (np,0 );This seems to get called repeatedly in
sunxi7i_boot_secondary, so you're repeatedly trying to find the cc node and mapping it, but never unmapping it. That's both a waste of time and a waste of address space.It would be nicer to map this once at the start. That seems simpler than stashing the physical address and mapping/unmapping it repeatedly.
smp_boot_secondary.arch/arm/mach-sunxi/platsmp.c line 58
Quoted 2 lines
arch/arm/mach-sunxi/platsmp.c new file +2
-0+pr_debug ("cc_base is %x\n" , (unsigned int )cc_base); +if (!cc_base) {You can use %p to print pointers, without casting to an integer type.
arch/arm/mach-sunxi/platsmp.c line 60
Quoted 2 lines
arch/arm/mach-sunxi/platsmp.c new file +2
-0+pr_debug ("error map cc configure\n" ); +return ;As this may be called repeatedly, from a function that can return errors, it would be nice to propagate an error code if there's a failure.
Quoted 48 lines
arch/arm/mach-sunxi/platsmp.c new file +48
-0+ } + + paddr =virt_to_phys (sun7i_secondary_startup); +writel (paddr, cc_base +AW_CPUCFG_P_REG0 ); +/* step1: Assert nCOREPORESET LOW and hold L1RSTDISABLE LOW. +Ensure DBGPWRDUP is held LOW to prevent any external +debug access to the processor. +*/ +/* assert cpu core reset */ +writel (0 , cc_base +CPUX_RESET_CTL (cpu)); +/* L1RSTDISABLE hold low */ + pwr_reg =readl (cc_base +AW_CPUCFG_GENCTL ); + pwr_reg &= ~(1 <<cpu); +writel (pwr_reg, cc_base +AW_CPUCFG_GENCTL ); +/* DBGPWRDUP hold low */ + pwr_reg =readl (cc_base +AW_CPUCFG_DBGCTL1 ); + pwr_reg &= ~(1 <<cpu); +writel (pwr_reg, cc_base +AW_CPUCFG_DBGCTL1 ); + +/* step2: release power clamp */ +writel (0xff , cc_base +AW_CPU1_PWR_CLAMP ); +writel (0x7f , cc_base +AW_CPU1_PWR_CLAMP ); +writel (0x3f , cc_base +AW_CPU1_PWR_CLAMP ); +writel (0x1f , cc_base +AW_CPU1_PWR_CLAMP ); +writel (0x0f , cc_base +AW_CPU1_PWR_CLAMP ); +writel (0x07 , cc_base +AW_CPU1_PWR_CLAMP ); +writel (0x03 , cc_base +AW_CPU1_PWR_CLAMP ); +writel (0x01 , cc_base +AW_CPU1_PWR_CLAMP ); +writel (0x00 , cc_base +AW_CPU1_PWR_CLAMP ); +mdelay (10 ); + +/* step3: clear power-off gating */ + pwr_reg =readl (cc_base +AW_CPU1_PWROFF_REG ); + pwr_reg &= ~(1 ); +writel (pwr_reg, cc_base +AW_CPU1_PWROFF_REG ); +mdelay (1 ); + +/* step4: de-assert core reset */ +writel (3 , cc_base +CPUX_RESET_CTL (cpu)); + +/* step5: assert DBGPWRDUP signal */ + pwr_reg =readl (cc_base +AW_CPUCFG_DBGCTL1 ); + pwr_reg |= (1 <<cpu); +writel (pwr_reg, cc_base +AW_CPUCFG_DBGCTL1 ); + +} + +arch/arm/mach-sunxi/platsmp.c line 118
Quoted 10 lines
arch/arm/mach-sunxi/platsmp.c new file +10
-0+ +static void sunxi7i_smp_init_cpus (void ) +{ +unsigned int i, ncores; + + +/* HDG: we do not use scu_get_core_count() here as that does not +work on the A20 ? */ + +/* Read current CP15 Cache Size ID Register */ Invalid comment. Judging by the encoding, this is the L2CTLR, not the CCSIDR.
arch/arm/mach-sunxi/platsmp.c line 127
Quoted 9 lines
arch/arm/mach-sunxi/platsmp.c new file +9
-0+ asmvolatile ("mrc p15, 1, %0, c9, c0, 2" :"=r" (ncores)); + ncores = ((ncores >>24 ) &0x3 ) +1 ; + +pr_debug ("[%s] ncores=%d\n" , __func__, ncores); + +for (i =0 ; i < ncores; i++) +set_cpu_possible (i, true); + +}Even ignoring the above, as long as your dt is correct
arm_dt_init_cpu_maps(called fromstup_arch) will set the cpus as possible (and handles arbitrary MPIDR values as may be the case in multi-cluster).You don't need this function -- please remove it.
arch/arm/mach-sunxi/platsmp.c line 138
Quoted 11 lines
arch/arm/mach-sunxi/platsmp.c new file +11
-0+ +/* +* for arch/arm/kernel/smp.c:smp_prepare_cpus(unsigned int max_cpus) +*/ +static void sunxi7i_smp_prepare_cpus (unsigned int max_cpus) +{ +/* +* HDG: we do not call scu_enable() here as the sun6i source dump has +* a modified arch/arm/kernel/smp_scu.c, where scu_enable() is a nop. +*/ +}A look in
smp.cshowssmp_prepare_cpusis perfectly happy to not have asmp_prepare_cpuscallback. You don't need this function -- please remove it.arch/arm/mach-sunxi/platform.h line 36
Quoted 6 lines
arch/arm/mach-sunxi/platform.h new file +6
-0+ + + + + +Why so much space here (and elsewhere)?
arch/arm/mach-sunxi/platsmp.c line 152
Quoted 8 lines
arch/arm/mach-sunxi/platsmp.c new file +8
-0+/* +* for linux/arch/arm/kernel/smp.c:__cpu_up(..) +*/ +static int sunxi7i_boot_secondary (unsigned int cpu,struct task_struct *idle) +{ +pr_debug ("[%s] enter cpu %d\n" , __func__, cpu); +spin_lock (&boot_lock); +enable_aw_cpu (cpu);This can fail. You should propagate the error when it does.
arch/arm/mach-sunxi/platsmp.c line 164
Quoted 12 lines
arch/arm/mach-sunxi/platsmp.c new file +12
-0+spin_unlock (&boot_lock); +return 0 ; +} + + + + +struct smp_operations sunxi7i_smp_ops__initdata = { + .smp_init_cpus = sunxi7i_smp_init_cpus, + .smp_prepare_cpus = sunxi7i_smp_prepare_cpus, + .smp_boot_secondary = sunxi7i_boot_secondary, +};I believe only
smp_boot_secondaryis necessary here.Thanks,
Mark.Quoted 28 lines
(quoted diff) +2
-0+ +arch/arm/mach-sunxi/sunxi.c +4
-1@@ -26,6 +26,9 @@#include <asm/mach/map.h> #include <asm/system_misc.h> +#include "platform.h" + +#define SUN4I_WATCHDOG_CTRL_REG 0x00#define SUN4I_WATCHDOG_CTRL_RESTART BIT(0)#define SUN4I_WATCHDOG_MODE_REG 0x04@@ -139,6 +142,7 @@ static const char * const sunxi_board_dt_compat[] = { };DT_MACHINE_START (SUNXI_DT ,"Allwinner A1X (Device Tree)" ) + .smp = smp_ops(sunxi7i_smp_ops), .init_machine = sunxi_dt_init, .init_time = sunxi_timer_init, .dt_compat = sunxi_board_dt_compat, --1.7.9.5
Re: [PATCH 3/4] Add physical count arch timer support for clocksource in ARMv7.
In reply to Mark RutlandQuoted 3 lines
This cannot be a compile-time option as above in a multiplatform build. Other paltforms (e.g. KVM guests) *must* use the virtual counters to get any semblance of a consistent view of time.
Yes I accept compile-time option is not perfect in my pre email, But,Why Ohter paltforms *must* use the virtual counters? I think KVM should not limit how to use arch timer in its guest OS. Of cause, if KVM guest use vct can be more efficiency then that use pct. but KVM should and must support guest OS to access pct.
Quoted 2 lines
Why can the bootloader not be fixed to set CNTVOFF (or to boot the kernel in Hyp mode)?
I want kernel should try its best to boot and run with the bootloader not be fixed.
BTW, I also hope all bootloader fix the problem.
Re: [PATCH 3/4] Add physical count arch timer support for clocksource in ARMv7.
In reply to Russell King - ARM LinuxThanks, but I am tring a solution in running time.
Quoted 32 lines · Russell King - ARM Linux
Quoted 13 lines · Mark Rutland
Quoted 12 lines · Fan Rong
drivers/clocksource/Kconfig +4
-0@@ -109,3 +109,11 @@ config VF_PIT_TIMER bool help Support for Period Interrupt Timer on Freescale Vybrid Family SoCs. +menu "Clock Source" + +config ARM_ARCH_TIMER_USE_PHYCNT + bool "Use Physical Count Timer"Quoted 8 lines
drivers/clocksource/Kconfig config VF_PIT_TIMER · line 119
Quoted 4 lines
drivers/clocksource/Kconfig +4
-0+ depends on ARM_ARCH_TIMER + help + If bootloader dont set Virtual Offset register,Physical Count Timer is needed to replace Virtual Count Timer. +endmenuThis cannot be a compile-time option as above in a multiplatform build. Other paltforms (e.g. KVM guests) *must* use the virtual counters to get any semblance of a consistent view of time.
Also, for future reference:
1. Use a single blank lines to separate thing like 'menu' and 'endmenu'.
2. Wrap your the help sensibly, don't put it all on one line.
3. It's conventional to use tabs up to below "help" and then two spaces to indent the help text.
4. "," always has one space after it.Thanks.
Re: [linux-sunxi] Re: [PATCH 4/4] Add arch count timer node in dts for Allwinner A20(sunxi 7i).
In reply to Ian CampbellQuoted 8 lines · Ian Campbell
Quoted 6 lines · Mark Rutland
Quoted 5 lines
arch/arm/boot/dts/sun7i-a20.dtsi +5
-0+ interrupts = <1 13 0x308>, + <1 14 0x308>, + <1 11 0x308>, + <1 10 0x308>; + clock-frequency = <24000000>;
Quoted 6 lines
Quoted 6 lines
If at all possible, your bootloader should set CNTFREQ, and clock-frequency should only be used as a last resort when it's impossible to get it to set CNTFREQ. It's not possible to set CNTFREQ from the non-secure side, so guests (which might not be Linux, and might not handle DT in the same way) may see a completely wrong frequency value.
Yes, My bootloader dont set it, and I have to set it at dtsi fot boot, I found <clock-frequency> is be set in dtsi file for ohters cups.
Re: [PATCH 3/4] Add physical count arch timer support for clocksource in ARMv7.
In reply to cinifrQuoted 8 lines · cinifr
Quoted 3 lines
This cannot be a compile-time option as above in a multiplatform build. Other paltforms (e.g. KVM guests) *must* use the virtual counters to get any semblance of a consistent view of time.
Yes I accept compile-time option is not perfect in my pre email, But,Why Ohter paltforms *must* use the virtual counters? I think KVM should not limit how to use arch timer in its guest OS. Of cause, if KVM guest use vct can be more efficiency then that use pct. but KVM should and must support guest OS to access pct.
The virtual counter is there for a good reason: it allows a virtual machine to:
- see its time starting at zero
- be migrated to another host without seeing time shifting one way or another.
So using the physical counter in a VM is a recipe for disaster if you're doing any kind of time tracking. The counter being used for sched_clock(), we cannot afford to see it being shifted one way or another.
If you have issues with the use of the virtual counter, I suggest you fix your firmware to have a consistent CNTVOFF across CPUs. And/or even better, boot your kernel in HYP mode, as it will take care of setting CNTVOFF to zero.
Cheers,
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
Re: [linux-sunxi] Re: [PATCH 4/4] Add arch count timer node in dts for Allwinner A20(sunxi 7i).
In reply to cinifrfre 2013-09-13 klockan 00:23 +0800 skrev cinifr:
Quoted 3 lines
Yes, My bootloader dont set it, and I have to set it at dtsi fot boot, I found <clock-frequency> is be set in dtsi file for ohters cups.
The patch from Ian is now in sunxi u-boot.
Regards
Henrik
Re: [PATCH 3/4] Add physical count arch timer support for clocksource in ARMv7.
In reply to Marc ZyngierQuoted 16 lines · Marc Zyngier
Quoted 8 lines · cinifr
Quoted 3 lines
This cannot be a compile-time option as above in a multiplatform build. Other paltforms (e.g. KVM guests) *must* use the virtual counters to get any semblance of a consistent view of time.
Yes I accept compile-time option is not perfect in my pre email, But,Why Ohter paltforms *must* use the virtual counters? I think KVM should not limit how to use arch timer in its guest OS. Of cause, if KVM guest use vct can be more efficiency then that use pct. but KVM should and must support guest OS to access pct.
The virtual counter is there for a good reason: it allows a virtual machine to:
- see its time starting at zero
- be migrated to another host without seeing time shifting one way or another.
Quoted 3 lines
So using the physical counter in a VM is a recipe for disaster if you're doing any kind of time tracking. The counter being used for
sched_clock(), we cannot afford to see it being shifted one way or another.
I accept that virtual count is better in VM than physical counter
because hypversion can modify VM timer by set CNTVOFF. But I think
hypversior should support that VM should can access physical counter, When VM use physical count. hypversior could trap accessing physical count from guest OS, and return a value that guest OS want liking hypervisor set CNTVOFF for virtual counter. On this way, VM could too see its timer at zero and VM could too be migrated to another host without seeing time shifting.
Quoted 5 lines
If you have issues with the use of the virtual counter, I suggest you fix your firmware to have a consistent CNTVOFF across CPUs. And/or even better, boot your kernel in HYP mode, as it will take care of setting CNTVOFF to zero.
I am wondering what is the principle between kernel and bootload?
What should be done in bootloader and what should be done in kernel? As you said, If kernel boot from hyp, Kernel can set CNTVOFF to zero directly, does we add the code to set CNTVOFF in kernel? But, if kernel boot from PL1 NS=0, Does kernel need to switch hyp mode to set CNTVOFF and return PL1 NS=0 mode? Or,kernel dont care it because
kernel believe bootloader have set CNTVOFF before?
Thanks,
Fan.
Re: [PATCH 3/4] Add physical count arch timer support for clocksource in ARMv7.
Quoted 20 lines · cinifr
Quoted 16 lines · Marc Zyngier
Quoted 8 lines · cinifr
Quoted 3 lines
This cannot be a compile-time option as above in a multiplatform build. Other paltforms (e.g. KVM guests) *must* use the virtual counters to get any semblance of a consistent view of time.
Yes I accept compile-time option is not perfect in my pre email, But,Why Ohter paltforms *must* use the virtual counters? I think KVM should not limit how to use arch timer in its guest OS. Of cause, if KVM guest use vct can be more efficiency then that use pct. but KVM should and must support guest OS to access pct.
The virtual counter is there for a good reason: it allows a virtual machine to:
- see its time starting at zero
- be migrated to another host without seeing time shifting one way or another.Quoted 3 lines
So using the physical counter in a VM is a recipe for disaster if you're doing any kind of time tracking. The counter being used for
sched_clock(), we cannot afford to see it being shifted one way or another.
Quoted 8 lines
I accept that virtual count is better in VM than physical counter
because hypversion can modify VM timer by set CNTVOFF. But I think
hypversior should support that VM should can access physical counter, When VM use physical count. hypversior could trap accessing physical count from guest OS, and return a value that guest OS want liking hypervisor set CNTVOFF for virtual counter. On this way, VM could too see its timer at zero and VM could too be migrated to another host without seeing time shifting.
I urge you to read the ARM ARM, and specifically the section dedicated to trapping access to CP15 operations. If you do, you'll quickly notice that you *cannot* trap accesses to the timer subsystem.
All you can do is disable access to the physical timer/counter, resulting in an UNDEF in the *guest*.
Additionally, please realise the overhead of trapping is enormous, and that we do try very hard to minimise it. Why do you think we went out of our way to ensure that host and guest would use different timers, always?
Quoted 5 lines
Quoted 5 lines
If you have issues with the use of the virtual counter, I suggest you fix your firmware to have a consistent CNTVOFF across CPUs. And/or even better, boot your kernel in HYP mode, as it will take care of setting CNTVOFF to zero.
Quoted 7 lines
I am wondering what is the principle between kernel and bootload?
What should be done in bootloader and what should be done in kernel? As you said, If kernel boot from hyp, Kernel can set CNTVOFF to zero directly, does we add the code to set CNTVOFF in kernel? But, if kernel boot from PL1 NS=0, Does kernel need to switch hyp mode to set CNTVOFF and return PL1 NS=0 mode? Or,kernel dont care it because
kernel believe bootloader have set CNTVOFF before?
In an ideal world, the bootloader should set CNTVOFF to zero. The fact that the kernel does it too when booted in HYP mode is to preserve itself from from broken bootloaders.
CNTVOFF can only be setup from either HYP or Secure Monitor mode with SCR.NS == 1, so if you run your kernel in secure mode, it is always best to do it in the bootloader.
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
Mark Rutland
maintainerQuoted 6 lines · cinifr
Quoted 5 lines
You seem to be suggesting a kernel change (using CNTPCT), but also bootloader changes (setting CNTHCTL.PL1PCTEN) to make this possible at all. If the bootloader needs to be modified, why can it not be modified to set CNTVOFF (or to boot the kernel in Hyp where it can set it itself)?
Quoted 10 lines
I think kernel should can support both CNTVCT and CNTPCT. Yes, if bootloader have set CNTVOFF to zero, then CNTVCT is OK, kvm guest using CNTVCT can run more efficient then that using CNTPCT. but if bootloader dont set it, how about kernel booting? I think kernel should try it's best to boot and run ok even bootload dont set any generic timer register including CNTVOFF and CNTHCTL. So i gave a compile options using CNTPCT. That is only options, If CNTVCT can not working, you have others choice.
Of cause, It is best that kerne can select which timer count is used in running time,
CNTVOFF doesn't need to be zero -- when a guest runs under a hypervisor, CNTVOFF may change across a suspend/resume of a VM (to give the guest the illusion that time wasn't ticking when it wasn't running). All that's required is that all the CPUs have the same CNTVOFF value, and this has been valid for all platforms so far.
Does CNTVOFF vary between your CPUs, or are they a consistent value (event if it's not zero)?
For ARMv8 systems, CNTVOFF and CNTHCTL reset to an UNDEFINED value, so we cannot rely on the physical timers and counters being available -- the firmware and/or hypervisor must set at least one of them for an OS to be able to use the system. The virtual timers and counters are *always* available to PL1/EL1, so our best bet is to use them.
I'd prefer not to have to have a run-time solution to a problem that can be avoided entirely with a simple modification to the bootloader now.
Quoted 14 lines
Quoted 5 lines
I'm not sure what you mean by selecting which timer to use be reading the current running mode. We currently decide to use CNTVCT if booted in PL1, or CNTPCT if booted in Hyp. I assume this isn't the mode you're referring to?
Yep, kernel can run PL1 NS=1, PL1 NS=0, PL2. If kernel can know current running Mode.then kernel can chose which timer is OK in running time. 1: If kernel is runing at PL2 and PL1 NS=0, then CNTPCT is OK in any case even CNTVOFF is not zero and CNTHCTL.PL1PCTEN is zero. 2: if kernel is running at PL1 NS=1,then kernel maybe should select CNTVCT. But it has risk to using CNTVCT when CNTVOFF is not zero.
How to deal with the case CNTHCTL.PL1PCTEN is zero and CNTVOFF is not
zero? current kernel cant using any arch timer incluing CNTVCT and
Quoted 8 lines
CNTPCT. with this case, I think kernel should use CNTVCT by other
ways: Kernel runing CPUn read CNTVCT and save it to local variable for example InitVctVALUEn in initialization, then kernel running CPUn read timer later return a value as ReadTIMERn=CNTVCTn-InitVctVALUEn, This way can run in any generic timer registe set and in any kernel runing mode. I try to write this patch for new way. But the new way should need more time than old in read timer funcation because it need more calculate.
I don't think that would work. You have no way of ensuring that all CPUs read CNTVCT at the same time, so they may record offsets that give them different views of time. Consider the case that CNTVOFF was zero on all CPUs. CPU0 and CPU1 might read CNTVCT at different instants, and CPU1 could record its offset as 100 while CPU1 could record its offset as 2000. That would leave CPU1 thinking it's further ahead in time than CPU0, which could break all sorts of things. AFAICS there's no way of telling this apart from each CPU booting with a different CNTVOFF.
As SMP support for this platform is not yet in mainline, and the bootloader can be fixed to set CNTVOFF (as KVM and Xen do for guests), we should get the bootloader to set CNTVOFF to a consistent value across all CPUs.
Thanks,
Mark.
Quoted 62 lines
.
Thanks for your question.Quoted 56 lines · Mark Rutland
Quoted 4 lines · Fan Rong
The patchs add smp support for Allwinner A20. It add cpuregister node in dts forsmp configure. The patchs also add a options for phy count timer to replace vir count timer as ARM arch timer clocksource. About ARM arch timer: 1. Current kernel use vir count timer, vir count timer
Quoted 8 lines
can be accessed in any cpu mode for kernel, but it need bootloader set vir count offset rigister zero at first. 2. Phy count timer can be accessed in most cpu mode for kernel except NS-PL1 mode when register CNTHCTL.PL1PCTEN is set to zero. To ensure to use phy count timer, bootloader should set register CNTHCTL.PL1PCTEN is 1 at first. At all, to ensure kernel can use arch timer, bootload should set some generic timer register(cntvoff or cnthctl) at first. the kernel should select which count timer by reading current kernel running mode.
Sorry, but I find the above text difficult to understand. It jumps between several issues and isn't well formatted.
You seem to be suggesting a kernel change (using CNTPCT), but also bootloader changes (setting CNTHCTL.PL1PCTEN) to make this possible at all. If the bootloader needs to be modified, why can it not be modified to set CNTVOFF (or to boot the kernel in Hyp where it can set it itself)?
I'm not sure what you mean by selecting which timer to use be reading the current running mode. We currently decide to use CNTVCT if booted in PL1, or CNTPCT if booted in Hyp. I assume this isn't the mode you're referring to?
Thanks,
Mark.Quoted 25 lines
Fan Rong (4):
Add smp support for Allwinner A20(sunxi 7i).
Add cpuconfig nodes in dts for smp configure.
Add physical count arch timer support for clocksource in ARMv7. Add arch count timer node in dts for Allwinner A20(sunxi 7i).arch/arm/boot/dts/sun7i-a20.dtsi | 18 +- arch/arm/include/asm/arch_timer.h | 11 ++ arch/arm/mach-sunxi/Makefile | 2 + arch/arm/mach-sunxi/headsmp.S | 12 ++ arch/arm/mach-sunxi/platform.h | 346 ++++++++++++++++++++++++++++++++++ arch/arm/mach-sunxi/platsmp.c | 166 ++++++++++++++++ arch/arm/mach-sunxi/sunxi.c | 4 + drivers/clocksource/Kconfig | 8 + drivers/clocksource/arm_arch_timer.c | 10 +- 9 files changed, 574 insertions(+), 3 deletions(-) create mode 100644 arch/arm/mach-sunxi/headsmp.S create mode 100644 arch/arm/mach-sunxi/platform.h create mode 100644 arch/arm/mach-sunxi/platsmp.c--
1.7.9.5
Re: [PATCH 3/4] Add physical count arch timer support for clocksource in ARMv7.
In reply to Marc ZyngierQuoted 4 lines
I urge you to read the ARM ARM, and specifically the section dedicated to trapping access to CP15 operations. If you do, you'll quickly notice that you *cannot* trap accesses to the timer subsystem.
I read it again. The ARMv7 manual said "Is accessible from Non-secure PL1 modes only when CNTHCTL.PL1PCTEN is set to 1. When CNTHCTL.PL1PCTEN is set to 0, any attempt to access CNTPCT from a Non-secure PL1 mode ***generates a Hyp Trap exception***, see Hyp Trap exception on page B1-1206" in B8.1.2. but I dont find a special hyp trap control for accessing CNTPCT in manual. As you said HSTR cannot trap accessing of CP15 c14. What happer when OS access CNTPCT from PL1 NS=1 mode with CNTHCTL.PL1PCTEN=0 ??? AmI wrong for understanding the manual?
Thanks.
BTW: And I fond xen have support to trap accessing CNTPCT by this
patch on http://lists.xen.org/archives/html/xen-devel/2012-08/msg00452.html.
Quoted 11 lines
All you can do is disable access to the physical timer/counter, resulting in an UNDEF in the *guest*.
Additionally, please realise the overhead of trapping is enormous, and that we do try very hard to minimise it. Why do you think we went out of our way to ensure that host and guest would use different timers, always?
CNTVOFF can only be setup from either HYP or Secure Monitor mode with SCR.NS == 1, so if you run your kernel in secure mode, it is always best to do it in the bootloader.
I agree it, Bootloader do it better.
Fan
Quoted 18 lines · Mark Rutland
Quoted 6 lines · cinifr
Quoted 5 lines
You seem to be suggesting a kernel change (using CNTPCT), but also bootloader changes (setting CNTHCTL.PL1PCTEN) to make this possible at all. If the bootloader needs to be modified, why can it not be modified to set CNTVOFF (or to boot the kernel in Hyp where it can set it itself)?
Quoted 10 lines
I think kernel should can support both CNTVCT and CNTPCT. Yes, if bootloader have set CNTVOFF to zero, then CNTVCT is OK, kvm guest using CNTVCT can run more efficient then that using CNTPCT. but if bootloader dont set it, how about kernel booting? I think kernel should try it's best to boot and run ok even bootload dont set any generic timer register including CNTVOFF and CNTHCTL. So i gave a compile options using CNTPCT. That is only options, If CNTVCT can not working, you have others choice.
Of cause, It is best that kerne can select which timer count is used in running time,
Quoted 8 lines
CNTVOFF doesn't need to be zero -- when a guest runs under a hypervisor, CNTVOFF may change across a suspend/resume of a VM (to give the guest the illusion that time wasn't ticking when it wasn't running). All that's required is that all the CPUs have the same CNTVOFF value, and this has been valid for all platforms so far.
Does CNTVOFF vary between your CPUs, or are they a consistent value (event if it's not zero)?
Yes, It is vary in A20 CPUS,
Quoted 8 lines
For ARMv8 systems, CNTVOFF and CNTHCTL reset to an UNDEFINED value, so we cannot rely on the physical timers and counters being available -- the firmware and/or hypervisor must set at least one of them for an OS to be able to use the system. The virtual timers and counters are *always* available to PL1/EL1, so our best bet is to use them.
I'd prefer not to have to have a run-time solution to a problem that can be avoided entirely with a simple modification to the bootloader now.
I agree it now,
Quoted 32 lines
Quoted 14 lines
Quoted 5 lines
I'm not sure what you mean by selecting which timer to use be reading the current running mode. We currently decide to use CNTVCT if booted in PL1, or CNTPCT if booted in Hyp. I assume this isn't the mode you're referring to?
Yep, kernel can run PL1 NS=1, PL1 NS=0, PL2. If kernel can know current running Mode.then kernel can chose which timer is OK in running time. 1: If kernel is runing at PL2 and PL1 NS=0, then CNTPCT is OK in any case even CNTVOFF is not zero and CNTHCTL.PL1PCTEN is zero. 2: if kernel is running at PL1 NS=1,then kernel maybe should select CNTVCT. But it has risk to using CNTVCT when CNTVOFF is not zero.
How to deal with the case CNTHCTL.PL1PCTEN is zero and CNTVOFF is not
zero? current kernel cant using any arch timer incluing CNTVCT andQuoted 8 lines
CNTPCT. with this case, I think kernel should use CNTVCT by other
ways: Kernel runing CPUn read CNTVCT and save it to local variable for example InitVctVALUEn in initialization, then kernel running CPUn read timer later return a value as ReadTIMERn=CNTVCTn-InitVctVALUEn, This way can run in any generic timer registe set and in any kernel runing mode. I try to write this patch for new way. But the new way should need more time than old in read timer funcation because it need more calculate.I don't think that would work. You have no way of ensuring that all CPUs read CNTVCT at the same time, so they may record offsets that give them different views of time. Consider the case that CNTVOFF was zero on all CPUs. CPU0 and CPU1 might read CNTVCT at different instants, and CPU1 could record its offset as 100 while CPU1 could record its offset as 2000. That would leave CPU1 thinking it's further ahead in time than CPU0, which could break all sorts of things. AFAICS there's no way of telling this apart from each CPU booting with a different CNTVOFF.
Quoted 4 lines
As SMP support for this platform is not yet in mainline, and the bootloader can be fixed to set CNTVOFF (as KVM and Xen do for guests), we should get the bootloader to set CNTVOFF to a consistent value across all CPUs.
Yes, you are right, I will remove phy count timer support patch.and try to modify bootloader for fix the problem. Bootloader do it better, more simple and more efficiency.
Thanks
Fan.
Re: [PATCH 3/4] Add physical count arch timer support for clocksource in ARMv7.
In reply to cinifrQuoted 4 lines · cinifr
Quoted 4 lines
I urge you to read the ARM ARM, and specifically the section dedicated to trapping access to CP15 operations. If you do, you'll quickly notice that you *cannot* trap accesses to the timer subsystem.
Quoted 9 lines
I read it again. The ARMv7 manual said "Is accessible from Non-secure PL1 modes only when CNTHCTL.PL1PCTEN is set to 1. When CNTHCTL.PL1PCTEN is set to 0, any attempt to access CNTPCT from a Non-secure PL1 mode ***generates a Hyp Trap exception***, see Hyp Trap exception on page B1-1206" in B8.1.2. but I dont find a special hyp trap control for accessing CNTPCT in manual. As you said HSTR cannot trap accessing of CP15 c14. What happer when OS access CNTPCT from PL1 NS=1 mode with CNTHCTL.PL1PCTEN=0 ??? AmI wrong for understanding the manual?
That's interesting, as I never noticed this particular line in the ARM ARM. I'll investigate this, thanks for bringing it up.
This doesn't change the fact that using the physical timer/counter in a VM is (or can be) horribly expensive, and should be avoided at all cost.
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
Re: [PATCH 3/4] Add physical count arch timer support for clocksource in ARMv7.
Quoted 4 lines
This doesn't change the fact that using the physical timer/counter in a VM is (or can be) horribly expensive, and should be avoided at all cost.
I will remove suport phy timer counter patch and try to fix it in bootloader. I agree that is elegant only vct is be used.in kernel now.
Re: [PATCH 2/4] Add cpuconfig nodes in dts for smp configure.
In reply to Fan RongHi Fan,
Quoted 12 lines · Fan Rong
Signed-off-by Fan Rong <[email protected]>--- arch/arm/boot/dts/sun7i-a20.dtsi | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)arch/arm/boot/dts/sun7i-a20.dtsi +0
-0@@ -20,13 +20,13 @@ #address-cells = <1>; #size-cells = <0>;
arch/arm/boot/dts/sun7i-a20.dtsi line 29
Quoted 10 lines
arch/arm/boot/dts/sun7i-a20.dtsi +2
-2- cpu at 0 { + cpu0: cpu at 0 { compatible = "arm,cortex-a7"; device_type = "cpu"; reg = <0>; }; - cpu at 1 { + cpu1: cpu at 1 {
Both these changes don't seem really needed, are they?
arch/arm/boot/dts/sun7i-a20.dtsi line 171
Quoted 9 lines
arch/arm/boot/dts/sun7i-a20.dtsi +2
-0compatible = "arm,cortex-a7"; device_type = "cpu"; reg = <1>;@@ -167,6 +167,11 @@ #size-cells = <1>; ranges; + cc: cpuconfig at 01c25c00 { + compatible = "allwinner,sun7i-cc";
Please use the sun7i-a20 prefix, and I'd prefer cpu-config instead of "cc".
Thanks for working on this!
Maxime
Signature · 10 lines
Maxime Ripard, Free Electrons Embedded Linux, Kernel and Android engineering http://free-electrons.com -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130914/4cf66fd8/attachment.sig>
Re: [PATCH 3/4] Add physical count arch timer support for clocksource in ARMv7.
In reply to Marc ZyngierHi Marc, Fan,
Quoted 10 lines · Marc Zyngier
Quoted 8 lines · cinifr
On 13 September 2013 00:39, Marc Zyngier <[email protected]> wrote:
I am wondering what is the principle between kernel and bootload?
What should be done in bootloader and what should be done in kernel? As you said, If kernel boot from hyp, Kernel can set CNTVOFF to zero directly, does we add the code to set CNTVOFF in kernel? But, if kernel boot from PL1 NS=0, Does kernel need to switch hyp mode to set CNTVOFF and return PL1 NS=0 mode? Or,kernel dont care it because
kernel believe bootloader have set CNTVOFF before?
Quoted 7 lines
In an ideal world, the bootloader should set CNTVOFF to zero. The fact that the kernel does it too when booted in HYP mode is to preserve itself from from broken bootloaders.
CNTVOFF can only be setup from either HYP or Secure Monitor mode with SCR.NS == 1, so if you run your kernel in secure mode, it is always best to do it in the bootloader.
What would happen exactly if a kernel expects CNTVOFF to be set to 0, and that your bootloader don't set it?
Quoted 1 line
From what you're saying, it's will be set by the kernel if it's booted
in hypervisor mode, but what if it's not?
The ARM documentation says that the CNTVOFF register will hold an undefined value, how would that affect the kernel?
Thanks,
Maxime
Signature · 10 lines
Maxime Ripard, Free Electrons Embedded Linux, Kernel and Android engineering http://free-electrons.com -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130914/6c9e137f/attachment.sig>
Re: [PATCH 3/4] Add physical count arch timer support for clocksource in ARMv7.
Hi Maxime,
Quoted 18 lines · maxime.ripard at free-electrons.com
Hi Marc, Fan,
Quoted 15 lines · Marc Zyngier
Quoted 9 lines · cinifr
On 13 September 2013 00:39, Marc Zyngier <[email protected]>
wrote: I am wondering what is the principle between kernel
and bootload? What should be done in bootloader and what should be done in kernel? As you said, If kernel boot from hyp, Kernel can set CNTVOFF to zero directly, does we add the code to set CNTVOFF in kernel? But, if kernel boot from PL1 NS=0, Does kernel need to switch hyp mode to set CNTVOFF and return
PL1 NS=0 mode? Or,kernel dont care it because kernel believe
bootloader have set CNTVOFF before?In an ideal world, the bootloader should set CNTVOFF to zero. The fact that the kernel does it too when booted in HYP mode is to preserve itself from from broken bootloaders.
Quoted 6 lines
Quoted 3 lines
CNTVOFF can only be setup from either HYP or Secure Monitor mode with SCR.NS == 1, so if you run your kernel in secure mode, it is always best to do it in the bootloader.
What would happen exactly if a kernel expects CNTVOFF to be set to 0, and that your bootloader don't set it?
It doesn't really matter if it is set to 0. What actually matters is that all the CPUs have the same value. Otherwise, you will have time reported differently depending on the CPU you're looking from.
Quoted 5 lines
From what you're saying, it's will be set by the kernel if it's booted in hypervisor mode, but what if it's not?
The ARM documentation says that the CNTVOFF register will hold an undefined value, how would that affect the kernel?
See above. Without a consistent view of time across CPUs, you're in deep trouble.
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
Re: [PATCH 3/4] Add physical count arch timer support for clocksource in ARMv7.
In reply to Marc ZyngierHI all,
I have modified uboot code to switch monitor mode and to set
cntvoff for all smp cpus for allwinner a20 cpu. It works, kernel can run ok without using cntpct. I will commit the path for uboot after reviewing the code.
Rong
Quoted 27 lines · Marc Zyngier
Quoted 4 lines · cinifr
Quoted 4 lines
I urge you to read the ARM ARM, and specifically the section dedicated to trapping access to CP15 operations. If you do, you'll quickly notice that you *cannot* trap accesses to the timer subsystem.
Quoted 9 lines
I read it again. The ARMv7 manual said "Is accessible from Non-secure PL1 modes only when CNTHCTL.PL1PCTEN is set to 1. When CNTHCTL.PL1PCTEN is set to 0, any attempt to access CNTPCT from a Non-secure PL1 mode ***generates a Hyp Trap exception***, see Hyp Trap exception on page B1-1206" in B8.1.2. but I dont find a special hyp trap control for accessing CNTPCT in manual. As you said HSTR cannot trap accessing of CP15 c14. What happer when OS access CNTPCT from PL1 NS=1 mode with CNTHCTL.PL1PCTEN=0 ??? AmI wrong for understanding the manual?
That's interesting, as I never noticed this particular line in the ARM ARM. I'll investigate this, thanks for bringing it up.
This doesn't change the fact that using the physical timer/counter in a VM is (or can be) horribly expensive, and should be avoided at all cost.
Thanks,
M.--
Jazz is not dead. It just smells funny...