sparc32: generic clockevent support
PATCH v2 2/2 sparc32: generic clockevent support
From aa76a8eb7aa0e5747adccaa8b8ba11a461a9baab Mon Sep 17 00:00:00 2001
From: Tkhai Kirill <[email protected]>
Date: Wed, 4 Apr 2012 21:49:26 +0200
Subject: [PATCH 2/2] sparc32: generic clockevent support
The kernel uses l14 timers as clockevents. l10 timer is used as clocksource if platform master_l10_counter isn't constantly zero. The clocksource is continuous, so it's possible to use high resolution timers. l10 timer is also used as clockevent on UP configurations.
This realization is for sun4m, sun4d, sun4c, microsparc-IIep and LEON platforms. The appropriate LEON changes was made by Konrad Eisele.
In case of sun4m's oneshot mode, profile irq is zeroed in smp4m_percpu_timer_interrupt(). It is maybe needless (double, triple etc overflow does nothing).
sun4d is able to have oneshot mode too, but I haven't any way to test it. So code of its percpu timer handler is made as much equal to the current code as possible.
The patch is tested on sun4m box in SMP mode by me, and tested by Konrad on leon in up mode (leon smp is broken atm - due to other reasons).
---
Fixed "From:" line - as Tkhai is the author of this.
Sam
arch/sparc/Kconfig | 7 +- arch/sparc/include/asm/cpudata_32.h | 1 - arch/sparc/include/asm/leon.h | 2 +- arch/sparc/include/asm/timer_32.h | 29 +++++ arch/sparc/include/asm/timex_32.h | 1 - arch/sparc/kernel/irq.h | 19 +++- arch/sparc/kernel/kernel.h | 2 - arch/sparc/kernel/leon_kernel.c | 49 +++++++- arch/sparc/kernel/leon_smp.c | 34 +----- arch/sparc/kernel/pcic.c | 48 ++++---- arch/sparc/kernel/smp_32.c | 21 +---- arch/sparc/kernel/sun4c_irq.c | 11 ++- arch/sparc/kernel/sun4d_irq.c | 18 +++- arch/sparc/kernel/sun4d_smp.c | 34 ++---- arch/sparc/kernel/sun4m_irq.c | 22 +++- arch/sparc/kernel/sun4m_smp.c | 38 ++---- arch/sparc/kernel/time_32.c | 215 ++++++++++++++++++++++++++++------- 17 files changed, 362 insertions(+), 189 deletions(-)
arch/sparc/Kconfig +1 -6
@@ -73,17 +73,12 @@ config BITS default 32 if SPARC32 default 64 if SPARC64 -config ARCH_USES_GETTIMEOFFSET - bool - default y if SPARC32 - config GENERIC_CMOS_UPDATE bool default y config GENERIC_CLOCKEVENTS - bool - default y if SPARC64 + def_bool y config IOMMU_HELPER bool
arch/sparc/include/asm/cpudata_32.h +0 -1
@@ -14,7 +14,6 @@ typedef struct { unsigned long udelay_val; unsigned long clock_tick; - unsigned int multiplier; unsigned int counter; #ifdef CONFIG_SMP unsigned int irq_resched_count;
arch/sparc/include/asm/leon.h +1 -1
@@ -323,7 +323,7 @@ extern void leon_update_virq_handling(unsigned int virq, const char *name, int do_ack);extern void leon_clear_clock_irq (void );extern void leon_load_profile_irq (int cpu,unsigned int limit); -extern void leon_init_timers (irq_handler_t counter_fn); +extern void leon_init_timers (void );extern void leon_clear_clock_irq (void );extern void leon_load_profile_irq (int cpu,unsigned int limit);extern void leon_trans_init (struct device_node *dp);
arch/sparc/include/asm/timer_32.h +29 -0
@@ -8,11 +8,40 @@#ifndef _SPARC_TIMER_H#define _SPARC_TIMER_H +#include <linux/clocksource.h> +#include <linux/irqreturn.h> + +#include <asm-generic/percpu.h> +#include <asm/cpu_type.h> /* For SUN4M_NCPUS */ #include <asm/btfixup.h> +#define SBUS_CLOCK_RATE 2000000/* 2MHz */ +#define TIMER_VALUE_SHIFT 9 +#define TIMER_VALUE_MASK 0x3fffff +#define TIMER_LIMIT_BIT (1 << 31)/* Bit 31 in Counter-Timer register */ + +/* The counter timer register has the value offset by 9 bits. +* From sun4m manual: +* When a counter reaches the value in the corresponding limit register, +* the Limit bit is set and the counter is set to 500 nS (i.e. 0x00000200). +* +* To compensate for this add one to the value. +*/ +static inline unsigned int timer_value (unsigned int value) +{ +return (value +1 ) <<TIMER_VALUE_SHIFT ; +} + extern __volatile__ unsigned int *master_l10_counter; +extern irqreturn_t notrace timer_interrupt(int dummy, void *dev_id); + +#ifdef CONFIG_SMP +DECLARE_PER_CPU(struct clock_event_device, sparc32_clockevent); +extern void register_percpu_ce (int cpu); +#endif +/* FIXME: Make do_[gs]ettimeofday btfixup calls */ struct timespec ; BTFIXUPDEF_CALL(int, bus_do_settimeofday, struct timespec *tv)
arch/sparc/include/asm/timex_32.h +0 -1
@@ -12,5 +12,4 @@typedef unsigned long cycles_t ;#define get_cycles () (0) -extern u32 (*do_arch_gettimeoffset)(void );#endif
arch/sparc/kernel/irq.h +18 -1
@@ -41,15 +41,32 @@ struct sun4m_irq_global {extern struct sun4m_irq_percpu __iomem *sun4m_irq_percpu[SUN4M_NCPUS ];extern struct sun4m_irq_global __iomem *sun4m_irq_global; +/* The following definitions describe the individual platform features: */ +#define FEAT_L10_CLOCKSOURCE (1 << 0)/* L10 timer is used as a clocksource */ +#define FEAT_L10_CLOCKEVENT (1 << 1)/* L10 timer is used as a clockevent */ +#define FEAT_L14_ONESHOT (1 << 2)/* L14 timer clockevent can oneshot */ +/* * Platform specific configuration * The individual platforms assign their platform * specifics in their init functions. */ struct sparc_config { -void (*init_timers)(irq_handler_t ); +void (*init_timers)(void );unsigned int (*build_device_irq)(struct platform_device *op,unsigned int real_irq); + +/* generic clockevent features - see FEAT_* above */ +int features; + +/* clock rate used for clock event timer */ +int clock_rate; + +/* one period for clock source timer */ +unsigned int cs_period; + +/* function to obtain offsett for cs period */ +unsigned int (*get_cycles_offset)(void ); };extern struct sparc_config sparc_config;
arch/sparc/kernel/kernel.h +0 -2
@@ -47,8 +47,6 @@ extern void init_IRQ(void);extern void sun4c_init_IRQ (void );/* sun4m_irq.c */ -extern unsigned int lvl14_resolution; -extern void sun4m_init_IRQ (void );extern void sun4m_unmask_profile_irq (void );extern void sun4m_clear_profile_irq (int cpu);
arch/sparc/kernel/leon_kernel.c +45 -4
91 lines not on this page · raw message
arch/sparc/kernel/leon_smp.c +4 -30
@@ -23,6 +23,8 @@#include <linux/pm.h> #include <linux/delay.h> #include <linux/gfp.h> +#include <linux/cpu.h> +#include <linux/clockchips.h> #include <asm/cacheflush.h> #include <asm/tlbflush.h>
@@ -42,6 +44,7 @@#include <asm/asi.h> #include <asm/leon.h> #include <asm/leon_amba.h> +#include <asm/timer.h> #include "kernel.h"
@@ -68,8 +71,6 @@ static inline unsigned long do_swap(volatile unsigned long *ptr,return val; } -static void smp_setup_percpu_timer (void ); -void __cpuinit leon_callin (void ) {int cpuid =hard_smpleon_processor_id ();
@@ -79,7 +80,7 @@ void __cpuinit leon_callin(void)leon_configure_cache_smp ();/* Get our local ticker going. */ -smp_setup_percpu_timer (); +register_percpu_ce (cpuid);calibrate_delay ();smp_store_cpu_info (cpuid);
@@ -196,7 +197,6 @@ void __init leon_boot_cpus(void)leon_smp_setbroadcast (1 <<LEON3_IRQ_TICKER );leon_configure_cache_smp (); -smp_setup_percpu_timer ();local_flush_cache_all (); }
@@ -489,32 +489,6 @@ void leon_cross_call_irq(void) ccall_info.processors_out[i] =1 ; } -irqreturn_t leon_percpu_timer_interrupt (int irq,void *unused) -{ -int cpu =smp_processor_id (); - -leon_clear_profile_irq (cpu); - -profile_tick (CPU_PROFILING ); - -if (!--prof_counter (cpu)) { -int user =user_mode (get_irq_regs ()); - -update_process_times (user); - -prof_counter (cpu) =prof_multiplier (cpu); - } - -return IRQ_HANDLED ; -} - -static void __init smp_setup_percpu_timer (void ) -{ -int cpu =smp_processor_id (); - -prof_counter (cpu) =prof_multiplier (cpu) =1 ; -} -void __init leon_blackbox_id (unsigned *addr) {int rd = *addr &0x3e000000 ;
arch/sparc/kernel/pcic.c +26 -21
72 lines not on this page · raw message
arch/sparc/kernel/smp_32.c +1 -20
@@ -301,28 +301,9 @@ void smp_flush_sig_insns(struct mm_struct *mm, unsigned long insn_addr)local_flush_sig_insns (mm, insn_addr); } -extern unsigned int lvl14_resolution; - -/* /proc/profile writes can call this, don't __init it please. */ -static DEFINE_SPINLOCK (prof_setup_lock); -int setup_profiling_timer (unsigned int multiplier) { -int i; -unsigned long flags; - -/* Prevent level14 ticker IRQ flooding. */ -if ((!multiplier) || (lvl14_resolution / multiplier) <500 ) -return -EINVAL ; - -spin_lock_irqsave (&prof_setup_lock, flags); -for_each_possible_cpu (i) { -load_profile_irq (i, lvl14_resolution / multiplier); -prof_multiplier (i) = multiplier; - } -spin_unlock_irqrestore (&prof_setup_lock, flags); - -return 0 ; +return -EINVAL ; }void __init smp_prepare_cpus (unsigned int max_cpus)
arch/sparc/kernel/sun4c_irq.c +7 -3
@@ -174,7 +174,7 @@ static void sun4c_load_profile_irq(int cpu, unsigned int limit)/* Errm.. not sure how to do this.. */ } -static void __init sun4c_init_timers (irq_handler_t counter_fn) +static void __init sun4c_init_timers (void ) {const struct linux_prom_irqs *prom_irqs;struct device_node *dp;
@@ -207,12 +207,16 @@ static void __init sun4c_init_timers(irq_handler_t counter_fn)* level 14 timer limit since we are letting the prom handle * them until we have a real console driver so L1-A works. */ -sbus_writel ((((1000000 /HZ ) +1 ) <<10 ), &sun4c_timers->l10_limit); + sparc_config.cs_period =SBUS_CLOCK_RATE /HZ ; + sparc_config.features |+FEAT_L10_CLOCKSOURCE |FEAT_L10_CLOCKEVENT ; +sbus_writel (timer_value (sparc_config.cs_period), + &sun4c_timers->l10_limit); master_l10_counter = &sun4c_timers->l10_count; irq =sun4c_build_device_irq (NULL , prom_irqs[0 ].pri); - err =request_irq (irq, counter_fn,IRQF_TIMER ,"timer" ,NULL ); + err =request_irq (irq, timer_interrupt,IRQF_TIMER ,"timer" ,NULL );if (err) {prom_printf ("sun4c_init_timers: request_irq() fails with %d\n" , err);prom_halt ();
@@ -253,6 +257,7 @@ void __init sun4c_init_IRQ(void) sparc_config.init_timers = sun4c_init_timers; sparc_config.build_device_irq = sun4c_build_device_irq; + sparc_config.clock_rate =SBUS_CLOCK_RATE ;#ifdef CONFIG_SMP BTFIXUPSET_CALL (set_cpu_int, sun4c_nop,BTFIXUPCALL_NOP );
arch/sparc/kernel/sun4d_irq.c +14 -4
@@ -282,7 +282,8 @@ static void sun4d_clear_clock_irq(void)static void sun4d_load_profile_irq (int cpu,unsigned int limit) { -bw_set_prof_limit (cpu, limit); +unsigned int value = limit ?timer_value (limit) :0 ; +bw_set_prof_limit (cpu, value); }static void __init sun4d_load_profile_irqs (void )
@@ -423,7 +424,7 @@ static void __init sun4d_fixup_trap_table(void)#endif } -static void __init sun4d_init_timers (irq_handler_t counter_fn) +static void __init sun4d_init_timers (void ) {struct device_node *dp;struct resource res;
@@ -466,12 +467,20 @@ static void __init sun4d_init_timers(irq_handler_t counter_fn)prom_halt (); } -sbus_writel ((((1000000 /HZ ) +1 ) <<10 ), &sun4d_timers->l10_timer_limit); +#ifdef CONFIG_SMP + sparc_config.cs_period =SBUS_CLOCK_RATE *2 ;/* 2 seconds */ +#else + sparc_config.cs_period =SBUS_CLOCK_RATE /HZ ;/* 1/HZ sec */ + sparc_config.features |=FEAT_L10_CLOCKEVENT ; +#endif + sparc_config.features |=FEAT_L10_CLOCKSOURCE ; +sbus_writel (timer_value (sparc_config.cs_period), + &sun4d_timers->l10_timer_limit); master_l10_counter = &sun4d_timers->l10_cur_count; irq =sun4d_build_timer_irq (board,SUN4D_TIMER_IRQ ); - err =request_irq (irq, counter_fn,IRQF_TIMER ,"timer" ,NULL ); + err =request_irq (irq, timer_interrupt,IRQF_TIMER ,"timer" ,NULL );if (err) {prom_printf ("sun4d_init_timers: request_irq() failed with %d\n" , err);
@@ -514,6 +523,7 @@ void __init sun4d_init_IRQ(void) sparc_config.init_timers = sun4d_init_timers; sparc_config.build_device_irq = sun4d_build_device_irq; + sparc_config.clock_rate =SBUS_CLOCK_RATE ;#ifdef CONFIG_SMP BTFIXUPSET_CALL (set_cpu_int, sun4d_set_cpu_int,BTFIXUPCALL_NORM );
arch/sparc/kernel/sun4d_smp.c +11 -23
@@ -6,16 +6,18 @@* Copyright (C) 1996 David S. Miller ([email protected]) */ +#include <linux/clockchips.h> #include <linux/interrupt.h> #include <linux/profile.h> #include <linux/delay.h> #include <linux/cpu.h> +#include <asm/cacheflush.h> +#include <asm/switch_to.h> +#include <asm/tlbflush.h> +#include <asm/timer.h> #include <asm/sbi.h> #include <asm/mmu.h> -#include <asm/tlbflush.h> -#include <asm/switch_to.h> -#include <asm/cacheflush.h> #include "kernel.h" #include "irq.h"
@@ -34,7 +36,6 @@ static inline unsigned long sun4d_swap(volatile unsigned long *ptr, unsigned lon }static void smp4d_ipi_init (void ); -static void smp_setup_percpu_timer (void );static unsigned char cpu_leds[32 ];
@@ -70,7 +71,7 @@ void __cpuinit smp4d_callin(void)* to call the scheduler code. */ /* Get our local ticker going. */ -smp_setup_percpu_timer (); +register_percpu_ce (cpuid);calibrate_delay ();smp_store_cpu_info (cpuid);
@@ -123,7 +124,6 @@ void __init smp4d_boot_cpus(void)smp4d_ipi_init ();if (boot_cpu_id) current_set[0 ] =NULL ; -smp_setup_percpu_timer ();local_flush_cache_all (); }
@@ -364,6 +364,7 @@ void smp4d_percpu_timer_interrupt(struct pt_regs *regs) {struct pt_regs *old_regs;int cpu =hard_smp4d_processor_id (); +struct clock_event_device *ce;static int cpu_tick[NR_CPUS ];static char led_mask[] = {0xe ,0xd ,0xb ,0x7 ,0xb ,0xd };
@@ -379,28 +380,15 @@ void smp4d_percpu_timer_interrupt(struct pt_regs *regs)show_leds (cpu); } -profile_tick (CPU_PROFILING ); - -if (!--prof_counter (cpu)) { -int user =user_mode (regs); + ce = &per_cpu (sparc32_clockevent, cpu); -irq_enter (); -update_process_times (user); -irq_exit (); +irq_enter (); + ce->event_handler (ce); +irq_exit (); -prof_counter (cpu) =prof_multiplier (cpu); - }set_irq_regs (old_regs); } -static void __cpuinit smp_setup_percpu_timer (void ) -{ -int cpu =hard_smp4d_processor_id (); - -prof_counter (cpu) =prof_multiplier (cpu) =1 ; -load_profile_irq (cpu, lvl14_resolution); -} -void __init smp4d_blackbox_id (unsigned *addr) {int rd = *addr &0x3e000000 ;
arch/sparc/kernel/sun4m_irq.c +15 -7
@@ -318,9 +318,6 @@ struct sun4m_timer_global {static struct sun4m_timer_global __iomem *timers_global; - -unsigned int lvl14_resolution = (((1000000 /HZ ) +1 ) <<10 ); -static void sun4m_clear_clock_irq (void ) {sbus_readl (&timers_global->l10_limit);
@@ -369,10 +366,11 @@ void sun4m_clear_profile_irq(int cpu)static void sun4m_load_profile_irq (int cpu,unsigned int limit) { -sbus_writel (limit, &timers_percpu[cpu]->l14_limit); +unsigned int value = limit ?timer_value (limit) :0 ; +sbus_writel (value, &timers_percpu[cpu]->l14_limit); } -static void __init sun4m_init_timers (irq_handler_t counter_fn) +static void __init sun4m_init_timers (void ) {struct device_node *dp =of_find_node_by_name (NULL ,"counter" );int i, err, len, num_cpu_timers;
@@ -402,13 +400,22 @@ static void __init sun4m_init_timers(irq_handler_t counter_fn)/* Every per-cpu timer works in timer mode */ sbus_writel (0x00000000 , &timers_global->timer_config); -sbus_writel ((((1000000 /HZ ) +1 ) <<10 ), &timers_global->l10_limit); +#ifdef CONFIG_SMP + sparc_config.cs_period =SBUS_CLOCK_RATE *2 ;/* 2 seconds */ + sparc_config.features |=FEAT_L14_ONESHOT ; +#else + sparc_config.cs_period =SBUS_CLOCK_RATE /HZ ;/* 1/HZ sec */ + sparc_config.features |=FEAT_L10_CLOCKEVENT ; +#endif + sparc_config.features |=FEAT_L10_CLOCKSOURCE ; +sbus_writel (timer_value (sparc_config.cs_period), + &timers_global->l10_limit); master_l10_counter = &timers_global->l10_count; irq =sun4m_build_device_irq (NULL ,SUN4M_TIMER_IRQ ); - err =request_irq (irq, counter_fn,IRQF_TIMER ,"timer" ,NULL ); + err =request_irq (irq, timer_interrupt,IRQF_TIMER ,"timer" ,NULL );if (err) {printk (KERN_ERR "sun4m_init_timers: Register IRQ error %d.\n" , err);
@@ -480,6 +487,7 @@ void __init sun4m_init_IRQ(void) sparc_config.init_timers = sun4m_init_timers; sparc_config.build_device_irq = sun4m_build_device_irq; + sparc_config.clock_rate =SBUS_CLOCK_RATE ;#ifdef CONFIG_SMP BTFIXUPSET_CALL (set_cpu_int, sun4m_send_ipi,BTFIXUPCALL_NORM );
arch/sparc/kernel/sun4m_smp.c +13 -25
@@ -4,6 +4,7 @@* Copyright (C) 1996 David S. Miller ([email protected]) */ +#include <linux/clockchips.h> #include <linux/interrupt.h> #include <linux/profile.h> #include <linux/delay.h>
@@ -12,6 +13,7 @@#include <asm/cacheflush.h> #include <asm/switch_to.h> #include <asm/tlbflush.h> +#include <asm/timer.h> #include "irq.h" #include "kernel.h"
@@ -31,7 +33,6 @@ swap_ulong(volatile unsigned long *ptr, unsigned long val) }static void smp4m_ipi_init (void ); -static void smp_setup_percpu_timer (void );void __cpuinit smp4m_callin (void ) {
@@ -42,8 +43,7 @@ void __cpuinit smp4m_callin(void)notify_cpu_starting (cpuid); -/* Get our local ticker going. */ -smp_setup_percpu_timer (); +register_percpu_ce (cpuid);calibrate_delay ();smp_store_cpu_info (cpuid);
@@ -87,7 +87,7 @@ void __cpuinit smp4m_callin(void)void __init smp4m_boot_cpus (void ) {smp4m_ipi_init (); -smp_setup_percpu_timer (); +sun4m_unmask_profile_irq ();local_flush_cache_all (); }
@@ -260,37 +260,25 @@ void smp4m_cross_call_irq(void)void smp4m_percpu_timer_interrupt (struct pt_regs *regs) {struct pt_regs *old_regs; +struct clock_event_device *ce;int cpu =smp_processor_id (); old_regs =set_irq_regs (regs); -sun4m_clear_profile_irq (cpu); + ce = &per_cpu (sparc32_clockevent, cpu); -profile_tick (CPU_PROFILING ); +if (ce->mode &CLOCK_EVT_MODE_PERIODIC ) +sun4m_clear_profile_irq (cpu); +else +load_profile_irq (cpu,0 );/* Is this needless? */ -if (!--prof_counter (cpu)) { -int user =user_mode (regs); +irq_enter (); + ce->event_handler (ce); +irq_exit (); -irq_enter (); -update_process_times (user); -irq_exit (); - -prof_counter (cpu) =prof_multiplier (cpu); - }set_irq_regs (old_regs); } -static void __cpuinit smp_setup_percpu_timer (void ) -{ -int cpu =smp_processor_id (); - -prof_counter (cpu) =prof_multiplier (cpu) =1 ; -load_profile_irq (cpu, lvl14_resolution); - -if (cpu = boot_cpu_id) -sun4m_unmask_profile_irq (); -} -static void __init smp4m_blackbox_id (unsigned *addr) {int rd = *addr &0x3e000000 ;
arch/sparc/kernel/time_32.c +176 -39
265 lines not on this page · raw message
Signature · 1 line
1.6.0.6
From: Sam Ravnborg <[email protected]>
Date: Fri, 6 Apr 2012 18:14:07 +0200
Quoted 23 lines
Quoted 1 line
From
aa76a8eb7aa0e5747adccaa8b8ba11a461a9baabMon Sep 17 00:00:00 2001From: Tkhai Kirill <[email protected]>
Date: Wed, 4 Apr 2012 21:49:26 +0200
Subject: [PATCH 2/2] sparc32: generic clockevent supportThe kernel uses l14 timers as clockevents. l10 timer is used as clocksource if platform
master_l10_counterisn't constantly zero. The clocksource is continuous, so it's possible to use high resolution timers. l10 timer is also used as clockevent on UP configurations.This realization is for sun4m, sun4d, sun4c, microsparc-IIep and LEON platforms. The appropriate LEON changes was made by Konrad Eisele.
In case of sun4m's oneshot mode, profile irq is zeroed in
smp4m_percpu_timer_interrupt(). It is maybe needless (double, triple etc overflow does nothing).sun4d is able to have oneshot mode too, but I haven't any way to test it. So code of its percpu timer handler is made as much equal to the current code as possible.
Quoted 8 lines
The patch is tested on sun4m box in SMP mode by me, and tested by Konrad on leon in up mode (leon smp is broken atm - due to other reasons).
Signed-off-by Tkhai Kirill <[email protected]>[sam: revised patch to provide generic support for leon]Signed-off-by Sam Ravnborg <[email protected]>
Applied.