Skip to content

Commit ec5c8e4

Browse files
Julien Thierrywildea01
authored andcommitted
arm_arch_timer: Expose event stream status
The arch timer configuration for a CPU might get reset after suspending said CPU. In order to reliably use the event stream in the kernel (e.g. for delays), we keep track of the state where we can safely consider the event stream as properly configured. After writing to cntkctl, we issue an ISB to ensure that subsequent delay loops can rely on the event stream being enabled. Signed-off-by: Julien Thierry <julien.thierry@arm.com> Acked-by: Mark Rutland <mark.rutland@arm.com> Cc: Marc Zyngier <marc.zyngier@arm.com> Cc: Russell King <linux@armlinux.org.uk> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Will Deacon <will.deacon@arm.com> Signed-off-by: Will Deacon <will.deacon@arm.com>
1 parent 611a7bc commit ec5c8e4

4 files changed

Lines changed: 30 additions & 3 deletions

File tree

‎arch/arm/include/asm/arch_timer.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ static inline u32 arch_timer_get_cntkctl(void)
106106
static inline void arch_timer_set_cntkctl(u32 cntkctl)
107107
{
108108
asm volatile("mcr p15, 0, %0, c14, c1, 0" : : "r" (cntkctl));
109+
isb();
109110
}
110111

111112
#endif

‎arch/arm64/include/asm/arch_timer.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ static inline u32 arch_timer_get_cntkctl(void)
144144
static inline void arch_timer_set_cntkctl(u32 cntkctl)
145145
{
146146
write_sysreg(cntkctl, cntkctl_el1);
147+
isb();
147148
}
148149

149150
static inline u64 arch_counter_get_cntpct(void)

‎drivers/clocksource/arm_arch_timer.c‎

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ static bool arch_timer_mem_use_virtual;
7777
static bool arch_counter_suspend_stop;
7878
static bool vdso_default = true;
7979

80+
static cpumask_t evtstrm_available = CPU_MASK_NONE;
8081
static bool evtstrm_enable = IS_ENABLED(CONFIG_ARM_ARCH_TIMER_EVTSTREAM);
8182

8283
static int __init early_evtstrm_cfg(char *buf)
@@ -740,6 +741,7 @@ static void arch_timer_evtstrm_enable(int divider)
740741
#ifdef CONFIG_COMPAT
741742
compat_elf_hwcap |= COMPAT_HWCAP_EVTSTRM;
742743
#endif
744+
cpumask_set_cpu(smp_processor_id(), &evtstrm_available);
743745
}
744746

745747
static void arch_timer_configure_evtstream(void)
@@ -864,6 +866,16 @@ u32 arch_timer_get_rate(void)
864866
return arch_timer_rate;
865867
}
866868

869+
bool arch_timer_evtstrm_available(void)
870+
{
871+
/*
872+
* We might get called from a preemptible context. This is fine
873+
* because availability of the event stream should be always the same
874+
* for a preemptible context and context where we might resume a task.
875+
*/
876+
return cpumask_test_cpu(raw_smp_processor_id(), &evtstrm_available);
877+
}
878+
867879
static u64 arch_counter_get_cntvct_mem(void)
868880
{
869881
u32 vct_lo, vct_hi, tmp_hi;
@@ -929,6 +941,8 @@ static int arch_timer_dying_cpu(unsigned int cpu)
929941
{
930942
struct clock_event_device *clk = this_cpu_ptr(arch_timer_evt);
931943

944+
cpumask_clear_cpu(smp_processor_id(), &evtstrm_available);
945+
932946
arch_timer_stop(clk);
933947
return 0;
934948
}
@@ -938,10 +952,16 @@ static DEFINE_PER_CPU(unsigned long, saved_cntkctl);
938952
static int arch_timer_cpu_pm_notify(struct notifier_block *self,
939953
unsigned long action, void *hcpu)
940954
{
941-
if (action == CPU_PM_ENTER)
955+
if (action == CPU_PM_ENTER) {
942956
__this_cpu_write(saved_cntkctl, arch_timer_get_cntkctl());
943-
else if (action == CPU_PM_ENTER_FAILED || action == CPU_PM_EXIT)
957+
958+
cpumask_clear_cpu(smp_processor_id(), &evtstrm_available);
959+
} else if (action == CPU_PM_ENTER_FAILED || action == CPU_PM_EXIT) {
944960
arch_timer_set_cntkctl(__this_cpu_read(saved_cntkctl));
961+
962+
if (elf_hwcap & HWCAP_EVTSTRM)
963+
cpumask_set_cpu(smp_processor_id(), &evtstrm_available);
964+
}
945965
return NOTIFY_OK;
946966
}
947967

@@ -1017,7 +1037,6 @@ static int __init arch_timer_register(void)
10171037
if (err)
10181038
goto out_unreg_notify;
10191039

1020-
10211040
/* Register and immediately configure the timer on the boot CPU */
10221041
err = cpuhp_setup_state(CPUHP_AP_ARM_ARCH_TIMER_STARTING,
10231042
"clockevents/arm/arch_timer:starting",

‎include/clocksource/arm_arch_timer.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ struct arch_timer_mem {
9393
extern u32 arch_timer_get_rate(void);
9494
extern u64 (*arch_timer_read_counter)(void);
9595
extern struct arch_timer_kvm_info *arch_timer_get_kvm_info(void);
96+
extern bool arch_timer_evtstrm_available(void);
9697

9798
#else
9899

@@ -106,6 +107,11 @@ static inline u64 arch_timer_read_counter(void)
106107
return 0;
107108
}
108109

110+
static inline bool arch_timer_evtstrm_available(void)
111+
{
112+
return false;
113+
}
114+
109115
#endif
110116

111117
#endif

0 commit comments

Comments
 (0)