powerpc: Free up an IPI message slot for tick broadcast IPIs
Subsystems (3)
cover powerpc: Free up an IPI message slot for tick broadcast IPIs
This patchset is a precursor for enabling deep idle states on powerpc, when the local CPU timers stop. The tick broadcast framework in the Linux Kernel today handles wakeup of such CPUs at their next timer event by using an external clock device. At the expiry of this clock device, IPIs are sent to the CPUs in deep idle states so that they wakeup to handle their respective timers. This patchset frees up one of the IPI slots on powerpc so as to be used to handle the tick broadcast IPI.
On certain implementations of powerpc, such an external clock device is absent. The support in the tick broadcast framework to handle wakeup of CPUs from deep idle states on such implementations is currently in the tip tree.
https://lkml.org/lkml/2014/2/7/906
https://lkml.org/lkml/2014/2/7/876
https://lkml.org/lkml/2014/2/7/608
With the above support in place, this patchset is next in line to enable deep idle states on powerpc.
The patchset has been appended by a RESEND tag since nothing has changed from the previous post except for an added config condition around tick_broadcast() which handles sending broadcast IPIs, and the update in the cover letter.
---
Preeti U Murthy (1):
cpuidle/ppc: Split timer_interrupt() into timer handling and interrupt handling routines
Srivatsa S. Bhat (2):
powerpc: Free up the slot of PPC_MSG_CALL_FUNC_SINGLE IPI message
powerpc: Implement tick broadcast IPI as a fixed IPI message
arch/powerpc/include/asm/smp.h | 2 - arch/powerpc/include/asm/time.h | 1 arch/powerpc/kernel/smp.c | 25 ++++++--- arch/powerpc/kernel/time.c | 86 ++++++++++++++++++------------- arch/powerpc/platforms/cell/interrupt.c | 2 - arch/powerpc/platforms/ps3/smp.c | 2 - 6 files changed, 73 insertions(+), 45 deletions(-)
PATCH RESEND 1/3 powerpc: Free up the slot of PPC_MSG_CALL_FUNC_SINGLE IPI message
From: Srivatsa S. Bhat <[email protected]>
The IPI handlers for both PPC_MSG_CALL_FUNC and PPC_MSG_CALL_FUNC_SINGLE map to a common implementation - generic_smp_call_function_single_interrupt(). So, we can consolidate them and save one of the IPI message slots, (which are precious on powerpc, since only 4 of those slots are available).
So, implement the functionality of PPC_MSG_CALL_FUNC_SINGLE using PPC_MSG_CALL_FUNC itself and release its IPI message slot, so that it can be used for something else in the future, if desired.
---
arch/powerpc/include/asm/smp.h | 2 +- arch/powerpc/kernel/smp.c | 12 +++++------- arch/powerpc/platforms/cell/interrupt.c | 2 +- arch/powerpc/platforms/ps3/smp.c | 2 +- 4 files changed, 8 insertions(+), 10 deletions(-)
arch/powerpc/include/asm/smp.h +1 -1
@@ -120,7 +120,7 @@ extern int cpu_to_core_id(int cpu);* in /proc/interrupts will be wrong!!! --Troy */ #define PPC_MSG_CALL_FUNCTION 0#define PPC_MSG_RESCHEDULE 1 -#define PPC_MSG_CALL_FUNC_SINGLE 2 +#define PPC_MSG_UNUSED 2#define PPC_MSG_DEBUGGER_BREAK 3/* for irq controllers that have dedicated ipis per message (4) */
arch/powerpc/kernel/smp.c +5 -7
@@ -145,9 +145,9 @@ static irqreturn_t reschedule_action(int irq, void *data)return IRQ_HANDLED ; } -static irqreturn_t call_function_single_action (int irq,void *data) +static irqreturn_t unused_action (int irq,void *data) { -generic_smp_call_function_single_interrupt (); +/* This slot is unused and hence available for use, if needed */ return IRQ_HANDLED ; }
@@ -168,14 +168,14 @@ static irqreturn_t debug_ipi_action(int irq, void *data)static irq_handler_t smp_ipi_action[] = { [PPC_MSG_CALL_FUNCTION ] = call_function_action, [PPC_MSG_RESCHEDULE ] = reschedule_action, - [PPC_MSG_CALL_FUNC_SINGLE ] = call_function_single_action, + [PPC_MSG_UNUSED ] = unused_action, [PPC_MSG_DEBUGGER_BREAK ] = debug_ipi_action, };const char *smp_ipi_name[] = { [PPC_MSG_CALL_FUNCTION ] ="ipi call function" , [PPC_MSG_RESCHEDULE ] ="ipi reschedule" , - [PPC_MSG_CALL_FUNC_SINGLE ] ="ipi call function single" , + [PPC_MSG_UNUSED ] ="ipi unused" , [PPC_MSG_DEBUGGER_BREAK ] ="ipi debugger" , };
@@ -251,8 +251,6 @@ irqreturn_t smp_ipi_demux(void)generic_smp_call_function_interrupt ();if (all &IPI_MESSAGE (PPC_MSG_RESCHEDULE ))scheduler_ipi (); -if (all &IPI_MESSAGE (PPC_MSG_CALL_FUNC_SINGLE )) -generic_smp_call_function_single_interrupt ();if (all &IPI_MESSAGE (PPC_MSG_DEBUGGER_BREAK ))debug_ipi_action (0 ,NULL ); }while (info->messages);
@@ -280,7 +278,7 @@ EXPORT_SYMBOL_GPL(smp_send_reschedule);void arch_send_call_function_single_ipi (int cpu) { -do_message_pass (cpu,PPC_MSG_CALL_FUNC_SINGLE ); +do_message_pass (cpu,PPC_MSG_CALL_FUNCTION ); }void arch_send_call_function_ipi_mask (const struct cpumask *mask)
arch/powerpc/platforms/cell/interrupt.c +1 -1
@@ -215,7 +215,7 @@ void iic_request_IPIs(void) {iic_request_ipi (PPC_MSG_CALL_FUNCTION );iic_request_ipi (PPC_MSG_RESCHEDULE ); -iic_request_ipi (PPC_MSG_CALL_FUNC_SINGLE ); +iic_request_ipi (PPC_MSG_UNUSED );iic_request_ipi (PPC_MSG_DEBUGGER_BREAK ); }
arch/powerpc/platforms/ps3/smp.c +1 -1
@@ -76,7 +76,7 @@ static int __init ps3_smp_probe(void)BUILD_BUG_ON (PPC_MSG_CALL_FUNCTION !=0 );BUILD_BUG_ON (PPC_MSG_RESCHEDULE !=1 ); -BUILD_BUG_ON (PPC_MSG_CALL_FUNC_SINGLE !=2 ); +BUILD_BUG_ON (PPC_MSG_UNUSED !=2 );BUILD_BUG_ON (PPC_MSG_DEBUGGER_BREAK !=3 );for (i =0 ; i <MSG_COUNT ; i++) {
PATCH RESEND 2/3 powerpc: Implement tick broadcast IPI as a fixed IPI message
In reply to Preeti U MurthyFrom: Srivatsa S. Bhat <[email protected]>
For scalability and performance reasons, we want the tick broadcast IPIs to be handled as efficiently as possible. Fixed IPI messages
are one of the most efficient mechanisms available - they are faster than the smp_call_function mechanism because the IPI handlers are fixed and hence they don't involve costly operations such as adding IPI handlers to the target CPU's function queue, acquiring locks for synchronization etc.
Luckily we have an unused IPI message slot, so use that to implement tick broadcast IPIs efficiently.
[Functions renamed to tick_broadcast* and Changelog modified by
Preeti U. Murthy<[email protected]>]
---
arch/powerpc/include/asm/smp.h | 2 +- arch/powerpc/include/asm/time.h | 1 + arch/powerpc/kernel/smp.c | 21 +++++++++++++++++---- arch/powerpc/kernel/time.c | 5 +++++ arch/powerpc/platforms/cell/interrupt.c | 2 +- arch/powerpc/platforms/ps3/smp.c | 2 +- 6 files changed, 26 insertions(+), 7 deletions(-)
arch/powerpc/include/asm/smp.h +1 -1
@@ -120,7 +120,7 @@ extern int cpu_to_core_id(int cpu);* in /proc/interrupts will be wrong!!! --Troy */ #define PPC_MSG_CALL_FUNCTION 0#define PPC_MSG_RESCHEDULE 1 -#define PPC_MSG_UNUSED 2 +#define PPC_MSG_TICK_BROADCAST 2#define PPC_MSG_DEBUGGER_BREAK 3/* for irq controllers that have dedicated ipis per message (4) */
arch/powerpc/include/asm/time.h +1 -0
@@ -28,6 +28,7 @@ extern struct clock_event_device decrementer_clockevent;struct rtc_time ;extern void to_tm (int tim,struct rtc_time * tm);extern void GregorianDay (struct rtc_time *tm); +extern void tick_broadcast_ipi_handler (void );extern void generic_calibrate_decr (void );
arch/powerpc/kernel/smp.c +17 -4
@@ -35,6 +35,7 @@#include <asm/ptrace.h> #include <linux/atomic.h> #include <asm/irq.h> +#include <asm/hw_irq.h> #include <asm/page.h> #include <asm/pgtable.h> #include <asm/prom.h>
@@ -145,9 +146,9 @@ static irqreturn_t reschedule_action(int irq, void *data)return IRQ_HANDLED ; } -static irqreturn_t unused_action (int irq,void *data) +static irqreturn_t tick_broadcast_ipi_action (int irq,void *data) { -/* This slot is unused and hence available for use, if needed */ +tick_broadcast_ipi_handler ();return IRQ_HANDLED ; }
@@ -168,14 +169,14 @@ static irqreturn_t debug_ipi_action(int irq, void *data)static irq_handler_t smp_ipi_action[] = { [PPC_MSG_CALL_FUNCTION ] = call_function_action, [PPC_MSG_RESCHEDULE ] = reschedule_action, - [PPC_MSG_UNUSED ] = unused_action, + [PPC_MSG_TICK_BROADCAST ] = tick_broadcast_ipi_action, [PPC_MSG_DEBUGGER_BREAK ] = debug_ipi_action, };const char *smp_ipi_name[] = { [PPC_MSG_CALL_FUNCTION ] ="ipi call function" , [PPC_MSG_RESCHEDULE ] ="ipi reschedule" , - [PPC_MSG_UNUSED ] ="ipi unused" , + [PPC_MSG_TICK_BROADCAST ] ="ipi tick-broadcast" , [PPC_MSG_DEBUGGER_BREAK ] ="ipi debugger" , };
@@ -251,6 +252,8 @@ irqreturn_t smp_ipi_demux(void)generic_smp_call_function_interrupt ();if (all &IPI_MESSAGE (PPC_MSG_RESCHEDULE ))scheduler_ipi (); +if (all &IPI_MESSAGE (PPC_MSG_TICK_BROADCAST )) +tick_broadcast_ipi_handler ();if (all &IPI_MESSAGE (PPC_MSG_DEBUGGER_BREAK ))debug_ipi_action (0 ,NULL ); }while (info->messages);
@@ -289,6 +292,16 @@ void arch_send_call_function_ipi_mask(const struct cpumask *mask)do_message_pass (cpu,PPC_MSG_CALL_FUNCTION ); } +#ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST +void tick_broadcast (const struct cpumask *mask) +{ +unsigned int cpu; + +for_each_cpu (cpu, mask) +do_message_pass (cpu,PPC_MSG_TICK_BROADCAST ); +} +#endif +#if defined(CONFIG_DEBUGGER ) || defined(CONFIG_KEXEC )void smp_send_debugger_break (void ) {
arch/powerpc/kernel/time.c +5 -0
@@ -825,6 +825,11 @@ static void decrementer_set_mode(enum clock_event_mode mode,decrementer_set_next_event (DECREMENTER_MAX , dev); } +/* Interrupt handler for the timer broadcast IPI */ +void tick_broadcast_ipi_handler (void ) +{ +} +static void register_decrementer_clockevent (int cpu) {struct clock_event_device *dec = &per_cpu (decrementers, cpu);
arch/powerpc/platforms/cell/interrupt.c +1 -1
@@ -215,7 +215,7 @@ void iic_request_IPIs(void) {iic_request_ipi (PPC_MSG_CALL_FUNCTION );iic_request_ipi (PPC_MSG_RESCHEDULE ); -iic_request_ipi (PPC_MSG_UNUSED ); +iic_request_ipi (PPC_MSG_TICK_BROADCAST );iic_request_ipi (PPC_MSG_DEBUGGER_BREAK ); }
arch/powerpc/platforms/ps3/smp.c +1 -1
@@ -76,7 +76,7 @@ static int __init ps3_smp_probe(void)BUILD_BUG_ON (PPC_MSG_CALL_FUNCTION !=0 );BUILD_BUG_ON (PPC_MSG_RESCHEDULE !=1 ); -BUILD_BUG_ON (PPC_MSG_UNUSED !=2 ); +BUILD_BUG_ON (PPC_MSG_TICK_BROADCAST !=2 );BUILD_BUG_ON (PPC_MSG_DEBUGGER_BREAK !=3 );for (i =0 ; i <MSG_COUNT ; i++) {
PATCH RESEND 3/3 cpuidle/ppc: Split timer_interrupt() into timer handling and interrupt handling routines
In reply to Preeti U MurthyFrom: Preeti U Murthy <[email protected]>
Split timer_interrupt(), which is the local timer interrupt handler on ppc into routines called during regular interrupt handling and __timer_interrupt(), which takes care of running local timers and collecting time related stats.
This will enable callers interested only in running expired local timers to directly call into __timer_interupt(). One of the use cases of this is the tick broadcast IPI handling in which the sleeping CPUs need to handle the local timers that have expired.
---
arch/powerpc/kernel/time.c | 81 +++++++++++++++++++++++++------------------- 1 file changed, 46 insertions(+), 35 deletions(-)
arch/powerpc/kernel/time.c +46 -35
@@ -478,6 +478,47 @@ void arch_irq_work_raise(void)#endif /* CONFIG_IRQ_WORK */ +void __timer_interrupt (void ) +{ +struct pt_regs *regs =get_irq_regs (); +u64 *next_tb = &__get_cpu_var (decrementers_next_tb); +struct clock_event_device *evt = &__get_cpu_var (decrementers); +u64 now; + +trace_timer_interrupt_entry (regs); + +if (test_irq_work_pending ()) { +clear_irq_work_pending (); +irq_work_run (); + } + + now =get_tb_or_rtc (); +if (now >= *next_tb) { + *next_tb = ~(u64 )0 ; +if (evt->event_handler) + evt->event_handler (evt); +__get_cpu_var (irq_stat).timer_irqs_event++; + }else { + now = *next_tb - now; +if (now <=DECREMENTER_MAX ) +set_dec ((int )now); +/* We may have raced with new irq work */ +if (test_irq_work_pending ()) +set_dec (1 ); +__get_cpu_var (irq_stat).timer_irqs_others++; + } + +#ifdef CONFIG_PPC64 +/* collect purr register values often, for accurate calculations */ +if (firmware_has_feature (FW_FEATURE_SPLPAR )) { +struct cpu_usage *cu = &__get_cpu_var (cpu_usage_array); + cu->current_tb =mfspr (SPRN_PURR ); + } +#endif + +trace_timer_interrupt_exit (regs); +} +/* * timer_interrupt - gets called when the decrementer overflows, * with interrupts disabled.
@@ -486,8 +527,6 @@ void timer_interrupt(struct pt_regs * regs) {struct pt_regs *old_regs;u64 *next_tb = &__get_cpu_var (decrementers_next_tb); -struct clock_event_device *evt = &__get_cpu_var (decrementers); -u64 now;/* Ensure a positive value is written to the decrementer, or else * some CPUs will continue to take decrementer exceptions.
@@ -519,39 +558,7 @@ void timer_interrupt(struct pt_regs * regs) old_regs =set_irq_regs (regs);irq_enter (); -trace_timer_interrupt_entry (regs); - -if (test_irq_work_pending ()) { -clear_irq_work_pending (); -irq_work_run (); - } - - now =get_tb_or_rtc (); -if (now >= *next_tb) { - *next_tb = ~(u64 )0 ; -if (evt->event_handler) - evt->event_handler (evt); -__get_cpu_var (irq_stat).timer_irqs_event++; - }else { - now = *next_tb - now; -if (now <=DECREMENTER_MAX ) -set_dec ((int )now); -/* We may have raced with new irq work */ -if (test_irq_work_pending ()) -set_dec (1 ); -__get_cpu_var (irq_stat).timer_irqs_others++; - } - -#ifdef CONFIG_PPC64 -/* collect purr register values often, for accurate calculations */ -if (firmware_has_feature (FW_FEATURE_SPLPAR )) { -struct cpu_usage *cu = &__get_cpu_var (cpu_usage_array); - cu->current_tb =mfspr (SPRN_PURR ); - } -#endif - -trace_timer_interrupt_exit (regs); - +__timer_interrupt ();irq_exit ();set_irq_regs (old_regs); }
@@ -828,6 +835,10 @@ static void decrementer_set_mode(enum clock_event_mode mode,/* Interrupt handler for the timer broadcast IPI */ void tick_broadcast_ipi_handler (void ) { +u64 *next_tb = &__get_cpu_var (decrementers_next_tb); + + *next_tb =get_tb_or_rtc (); +__timer_interrupt (); }static void register_decrementer_clockevent (int cpu)