loongarch: time: Derive max_delta from prcfg1 tmrbits
PATCH 1/1 loongarch: time: Derive max_delta from prcfg1 tmrbits
As per arch spec, maximum timer bits is configurable and should not be hardcoded in any way.
Use prcfg1 tmrbits to determine clockevent's max_delta to be conformance.
---
LA32R doesn't have prcfg, maybe we should handle this during cpu-probe and save it in cpuinfo_loongarch,
What's your opinion, Huacai?
--- arch/loongarch/include/asm/loongarch.h | 1 - arch/loongarch/kernel/time.c | 7 ++++++- 2 files changed, 6 insertions(+), 2 deletions(-)
arch/loongarch/include/asm/loongarch.h +0 -1
@@ -466,7 +466,6 @@#define LOONGARCH_CSR_TCFG 0x41/* Timer config */ #define CSR_TCFG_VAL_SHIFT 2 -#define CSR_TCFG_VAL_WIDTH 48#define CSR_TCFG_VAL (_ULCAST_(0x3fffffffffff) << CSR_TCFG_VAL_SHIFT)#define CSR_TCFG_PERIOD_SHIFT 1#define CSR_TCFG_PERIOD (_ULCAST_(0x1) << CSR_TCFG_PERIOD_SHIFT)
arch/loongarch/kernel/time.c +6 -1
@@ -126,16 +126,21 @@ void sync_counter(void)int constant_clockevent_init (void ) { +uint32_t tmrbits;unsigned int cpu =smp_processor_id ();#ifdef CONFIG_PREEMPT_RT unsigned long min_delta =100 ;#else unsigned long min_delta =1000 ;#endif -unsigned long max_delta = (1UL <<48 ) -1 ; +unsigned long max_delta;struct clock_event_device *cd;static int irq =0 , timer_irq_installed =0 ; + tmrbits =read_csr_prcfg1 () &CSR_CONF1_TMRBITS ; + tmrbits = tmrbits >>CSR_CONF1_TMRBITS_SHIFT ; + max_delta =CLOCKSOURCE_MASK (tmrbits +1 ); +if (!timer_irq_installed) { irq =get_percpu_irq (INT_TI );if (irq <0 )
---
base-commit: 8155b4ef3466f0e289e8fcc9e6e62f3f4dceeac2
change-id: 20241223-la-misc-d610d14f947e
Best regards,
Signature · 1 line
Jiaxun Yang <[email protected]>
Huacai Chen
maintainerHi, Jiaxun,
Quoted 35 lines · Jiaxun Yang
As per arch spec, maximum timer bits is configurable and should not be hardcoded in any way.
Use prcfg1 tmrbits to determine clockevent's
max_deltato be conformance.Signed-off-by Jiaxun Yang <[email protected]>---
LA32R doesn't have prcfg, maybe we should handle this during cpu-probe and save it incpuinfo_loongarch,What's your opinion, Huacai?
--- arch/loongarch/include/asm/loongarch.h | 1 - arch/loongarch/kernel/time.c | 7 ++++++- 2 files changed, 6 insertions(+), 2 deletions(-)arch/loongarch/include/asm/loongarch.h +0
-1@@ -466,7 +466,6 @@#define LOONGARCH_CSR_TCFG 0x41/* Timer config */ #define CSR_TCFG_VAL_SHIFT 2 -#define CSR_TCFG_VAL_WIDTH 48#define CSR_TCFG_VAL (_ULCAST_(0x3fffffffffff) << CSR_TCFG_VAL_SHIFT)#define CSR_TCFG_PERIOD_SHIFT 1#define CSR_TCFG_PERIOD (_ULCAST_(0x1) << CSR_TCFG_PERIOD_SHIFT)arch/loongarch/kernel/time.c +0
-0
arch/loongarch/kernel/time.c void sync_counter(void) · line 129
Quoted 4 lines
arch/loongarch/kernel/time.c +1
-0@@ -126,16 +126,21 @@ void sync_counter(void)int constant_clockevent_init (void ) { +uint32_t tmrbits;
tmr is a strange short name, you can use timer_bits or tbits for short.
Quoted 4 lines
arch/loongarch/kernel/time.c +0
-0unsigned int cpu =smp_processor_id ();#ifdef CONFIG_PREEMPT_RT unsigned long min_delta =100 ;#else
arch/loongarch/kernel/time.c void sync_counter(void) · line 142
Quoted 10 lines
arch/loongarch/kernel/time.c +4
-1unsigned long min_delta =1000 ;#endif -unsigned long max_delta = (1UL <<48 ) -1 ; +unsigned long max_delta;struct clock_event_device *cd;static int irq =0 , timer_irq_installed =0 ; + tmrbits =read_csr_prcfg1 () &CSR_CONF1_TMRBITS ; + tmrbits = tmrbits >>CSR_CONF1_TMRBITS_SHIFT ; + max_delta =CLOCKSOURCE_MASK (tmrbits +1 );
I prefer to evaluate the tbits and max_delta directly when declaring them.
Huacai
Quoted 13 lines
arch/loongarch/kernel/time.c +1
-1+if (!timer_irq_installed) { irq =get_percpu_irq (INT_TI );if (irq <0 ) ---base-commit:
8155b4ef3466f0e289e8fcc9e6e62f3f4dceeac2
change-id: 20241223-la-misc-d610d14f947eBest regards,
--
Jiaxun Yang <[email protected]>
Quoted 39 lines · 在2025年1月3日一月 上午2:36,Huacai Chen写道:
Hi, Jiaxun,
Quoted 36 lines · Jiaxun Yang
As per arch spec, maximum timer bits is configurable and should not be hardcoded in any way.
Use prcfg1 tmrbits to determine clockevent's
max_deltato be conformance.Signed-off-by Jiaxun Yang <[email protected]>---
LA32R doesn't have prcfg, maybe we should handle this during cpu-probe and save it incpuinfo_loongarch,What's your opinion, Huacai?
--- arch/loongarch/include/asm/loongarch.h | 1 - arch/loongarch/kernel/time.c | 7 ++++++- 2 files changed, 6 insertions(+), 2 deletions(-)arch/loongarch/include/asm/loongarch.h +0
-1@@ -466,7 +466,6 @@#define LOONGARCH_CSR_TCFG 0x41/* Timer config */ #define CSR_TCFG_VAL_SHIFT 2 -#define CSR_TCFG_VAL_WIDTH 48#define CSR_TCFG_VAL (_ULCAST_(0x3fffffffffff) << CSR_TCFG_VAL_SHIFT)#define CSR_TCFG_PERIOD_SHIFT 1#define CSR_TCFG_PERIOD (_ULCAST_(0x1) << CSR_TCFG_PERIOD_SHIFT)arch/loongarch/kernel/time.c +0
-0@@ -126,16 +126,21 @@ void sync_counter(void)
Quoted 4 lines
arch/loongarch/kernel/time.c void sync_counter(void) · line 129
Quoted 3 lines
arch/loongarch/kernel/time.c +1
-0int constant_clockevent_init (void ) { +uint32_t tmrbits;tmr is a strange short name, you can use
timer_bitsor tbits for short.
That’s the one from the manual :-( I’d agree with you though.
Quoted 12 lines
Quoted 12 lines
arch/loongarch/kernel/time.c +1
-1unsigned int cpu =smp_processor_id ();#ifdef CONFIG_PREEMPT_RT unsigned long min_delta =100 ;#else unsigned long min_delta =1000 ;#endif -unsigned long max_delta = (1UL <<48 ) -1 ; +unsigned long max_delta;struct clock_event_device *cd;static int irq =0 , timer_irq_installed =0 ;
Quoted 4 lines
arch/loongarch/kernel/time.c void sync_counter(void) · line 142
Quoted 3 lines
arch/loongarch/kernel/time.c +3
-0+ tmrbits =read_csr_prcfg1 () &CSR_CONF1_TMRBITS ; + tmrbits = tmrbits >>CSR_CONF1_TMRBITS_SHIFT ; + max_delta =CLOCKSOURCE_MASK (tmrbits +1 );I prefer to evaluate the tbits and
max_deltadirectly when declaring them.
Will do in v2.
Thanks
Quoted 16 lines
Huacai
Quoted 13 lines
arch/loongarch/kernel/time.c +1
-1+if (!timer_irq_installed) { irq =get_percpu_irq (INT_TI );if (irq <0 ) ---base-commit:
8155b4ef3466f0e289e8fcc9e6e62f3f4dceeac2
change-id: 20241223-la-misc-d610d14f947eBest regards,
--
Jiaxun Yang <[email protected]>
Signature · 1 line
- Jiaxun