aboutsummaryrefslogtreecommitdiffstats
path: root/arch/powerpc/kernel/smp.c
diff options
context:
space:
mode:
authorMilton Miller <miltonm@bga.com>2011-05-10 15:29:39 -0400
committerBenjamin Herrenschmidt <benh@kernel.crashing.org>2011-05-19 01:31:03 -0400
commit23d72bfd8f9f24aa9efafed3586a99f5669c23d7 (patch)
treef8fbd87c64de43c1d85a830f1f3342818414764a /arch/powerpc/kernel/smp.c
parent17f9c8a73bac2c7dfe28a520516ea6b8bbbe977e (diff)
powerpc: Consolidate ipi message mux and demux
Consolidate the mux and demux of ipi messages into smp.c and call a new smp_ops callback to actually trigger the ipi. The powerpc architecture code is optimised for having 4 distinct ipi triggers, which are mapped to 4 distinct messages (ipi many, ipi single, scheduler ipi, and enter debugger). However, several interrupt controllers only provide a single software triggered interrupt that can be delivered to each cpu. To resolve this limitation, each smp_ops implementation created a per-cpu variable that is manipulated with atomic bitops. Since these lines will be contended they are optimialy marked as shared_aligned and take a full cache line for each cpu. Distro kernels may have 2 or 3 of these in their config, each taking per-cpu space even though at most one will be in use. This consolidation removes smp_message_recv and replaces the single call actions cases with direct calls from the common message recognition loop. The complicated debugger ipi case with its muxed crash handling code is moved to debug_ipi_action which is now called from the demux code (instead of the multi-message action calling smp_message_recv). I put a call to reschedule_action to increase the likelyhood of correctly merging the anticipated scheduler_ipi() hook coming from the scheduler tree; that single required call can be inlined later. The actual message decode is a copy of the old pseries xics code with its memory barriers and cache line spacing, augmented with a per-cpu unsigned long based on the book-e doorbell code. The optional data is set via a callback from the implementation and is passed to the new cause-ipi hook along with the logical cpu number. While currently only the doorbell implemntation uses this data it should be almost zero cost to retrieve and pass it -- it adds a single register load for the argument from the same cache line to which we just completed a store and the register is dead on return from the call. I extended the data element from unsigned int to unsigned long in case some other code wanted to associate a pointer. The doorbell check_self is replaced by a call to smp_muxed_ipi_resend, conditioned on the CPU_DBELL feature. The ifdef guard could be relaxed to CONFIG_SMP but I left it with BOOKE for now. Also, the doorbell interrupt vector for book-e was not calling irq_enter and irq_exit, which throws off cpu accounting and causes code to not realize it is running in interrupt context. Add the missing calls. Signed-off-by: Milton Miller <miltonm@bga.com> Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Diffstat (limited to 'arch/powerpc/kernel/smp.c')
-rw-r--r--arch/powerpc/kernel/smp.c94
1 files changed, 63 insertions, 31 deletions
diff --git a/arch/powerpc/kernel/smp.c b/arch/powerpc/kernel/smp.c
index b74411446922..fa8e8700064b 100644
--- a/arch/powerpc/kernel/smp.c
+++ b/arch/powerpc/kernel/smp.c
@@ -111,35 +111,6 @@ int __devinit smp_generic_kick_cpu(int nr)
111} 111}
112#endif 112#endif
113 113
114void smp_message_recv(int msg)
115{
116 switch(msg) {
117 case PPC_MSG_CALL_FUNCTION:
118 generic_smp_call_function_interrupt();
119 break;
120 case PPC_MSG_RESCHEDULE:
121 /* we notice need_resched on exit */
122 break;
123 case PPC_MSG_CALL_FUNC_SINGLE:
124 generic_smp_call_function_single_interrupt();
125 break;
126 case PPC_MSG_DEBUGGER_BREAK:
127 if (crash_ipi_function_ptr) {
128 crash_ipi_function_ptr(get_irq_regs());
129 break;
130 }
131#ifdef CONFIG_DEBUGGER
132 debugger_ipi(get_irq_regs());
133 break;
134#endif /* CONFIG_DEBUGGER */
135 /* FALLTHROUGH */
136 default:
137 printk("SMP %d: smp_message_recv(): unknown msg %d\n",
138 smp_processor_id(), msg);
139 break;
140 }
141}
142
143static irqreturn_t call_function_action(int irq, void *data) 114static irqreturn_t call_function_action(int irq, void *data)
144{ 115{
145 generic_smp_call_function_interrupt(); 116 generic_smp_call_function_interrupt();
@@ -158,9 +129,17 @@ static irqreturn_t call_function_single_action(int irq, void *data)
158 return IRQ_HANDLED; 129 return IRQ_HANDLED;
159} 130}
160 131
161static irqreturn_t debug_ipi_action(int irq, void *data) 132irqreturn_t debug_ipi_action(int irq, void *data)
162{ 133{
163 smp_message_recv(PPC_MSG_DEBUGGER_BREAK); 134 if (crash_ipi_function_ptr) {
135 crash_ipi_function_ptr(get_irq_regs());
136 return IRQ_HANDLED;
137 }
138
139#ifdef CONFIG_DEBUGGER
140 debugger_ipi(get_irq_regs());
141#endif /* CONFIG_DEBUGGER */
142
164 return IRQ_HANDLED; 143 return IRQ_HANDLED;
165} 144}
166 145
@@ -199,6 +178,59 @@ int smp_request_message_ipi(int virq, int msg)
199 return err; 178 return err;
200} 179}
201 180
181struct cpu_messages {
182 unsigned long messages; /* current messages bits */
183 unsigned long data; /* data for cause ipi */
184};
185static DEFINE_PER_CPU_SHARED_ALIGNED(struct cpu_messages, ipi_message);
186
187void smp_muxed_ipi_set_data(int cpu, unsigned long data)
188{
189 struct cpu_messages *info = &per_cpu(ipi_message, cpu);
190
191 info->data = data;
192}
193
194void smp_muxed_ipi_message_pass(int cpu, int msg)
195{
196 struct cpu_messages *info = &per_cpu(ipi_message, cpu);
197 unsigned long *tgt = &info->messages;
198
199 set_bit(msg, tgt);
200 mb();
201 smp_ops->cause_ipi(cpu, info->data);
202}
203
204void smp_muxed_ipi_resend(void)
205{
206 struct cpu_messages *info = &__get_cpu_var(ipi_message);
207 unsigned long *tgt = &info->messages;
208
209 if (*tgt)
210 smp_ops->cause_ipi(smp_processor_id(), info->data);
211}
212
213irqreturn_t smp_ipi_demux(void)
214{
215 struct cpu_messages *info = &__get_cpu_var(ipi_message);
216 unsigned long *tgt = &info->messages;
217
218 mb(); /* order any irq clear */
219 while (*tgt) {
220 if (test_and_clear_bit(PPC_MSG_CALL_FUNCTION, tgt))
221 generic_smp_call_function_interrupt();
222 if (test_and_clear_bit(PPC_MSG_RESCHEDULE, tgt))
223 reschedule_action(0, NULL); /* upcoming sched hook */
224 if (test_and_clear_bit(PPC_MSG_CALL_FUNC_SINGLE, tgt))
225 generic_smp_call_function_single_interrupt();
226#if defined(CONFIG_DEBUGGER) || defined(CONFIG_KEXEC)
227 if (test_and_clear_bit(PPC_MSG_DEBUGGER_BREAK, tgt))
228 debug_ipi_action(0, NULL);
229#endif
230 }
231 return IRQ_HANDLED;
232}
233
202void smp_send_reschedule(int cpu) 234void smp_send_reschedule(int cpu)
203{ 235{
204 if (likely(smp_ops)) 236 if (likely(smp_ops))