xref: /openbmc/linux/arch/arm/kernel/smp.c (revision 82df5b73)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  *  linux/arch/arm/kernel/smp.c
4  *
5  *  Copyright (C) 2002 ARM Limited, All Rights Reserved.
6  */
7 #include <linux/module.h>
8 #include <linux/delay.h>
9 #include <linux/init.h>
10 #include <linux/spinlock.h>
11 #include <linux/sched/mm.h>
12 #include <linux/sched/hotplug.h>
13 #include <linux/sched/task_stack.h>
14 #include <linux/interrupt.h>
15 #include <linux/cache.h>
16 #include <linux/profile.h>
17 #include <linux/errno.h>
18 #include <linux/mm.h>
19 #include <linux/err.h>
20 #include <linux/cpu.h>
21 #include <linux/seq_file.h>
22 #include <linux/irq.h>
23 #include <linux/nmi.h>
24 #include <linux/percpu.h>
25 #include <linux/clockchips.h>
26 #include <linux/completion.h>
27 #include <linux/cpufreq.h>
28 #include <linux/irq_work.h>
29 
30 #include <linux/atomic.h>
31 #include <asm/bugs.h>
32 #include <asm/smp.h>
33 #include <asm/cacheflush.h>
34 #include <asm/cpu.h>
35 #include <asm/cputype.h>
36 #include <asm/exception.h>
37 #include <asm/idmap.h>
38 #include <asm/topology.h>
39 #include <asm/mmu_context.h>
40 #include <asm/pgalloc.h>
41 #include <asm/procinfo.h>
42 #include <asm/processor.h>
43 #include <asm/sections.h>
44 #include <asm/tlbflush.h>
45 #include <asm/ptrace.h>
46 #include <asm/smp_plat.h>
47 #include <asm/virt.h>
48 #include <asm/mach/arch.h>
49 #include <asm/mpu.h>
50 
51 #define CREATE_TRACE_POINTS
52 #include <trace/events/ipi.h>
53 
54 /*
55  * as from 2.5, kernels no longer have an init_tasks structure
56  * so we need some other way of telling a new secondary core
57  * where to place its SVC stack
58  */
59 struct secondary_data secondary_data;
60 
61 enum ipi_msg_type {
62 	IPI_WAKEUP,
63 	IPI_TIMER,
64 	IPI_RESCHEDULE,
65 	IPI_CALL_FUNC,
66 	IPI_CPU_STOP,
67 	IPI_IRQ_WORK,
68 	IPI_COMPLETION,
69 	/*
70 	 * CPU_BACKTRACE is special and not included in NR_IPI
71 	 * or tracable with trace_ipi_*
72 	 */
73 	IPI_CPU_BACKTRACE,
74 	/*
75 	 * SGI8-15 can be reserved by secure firmware, and thus may
76 	 * not be usable by the kernel. Please keep the above limited
77 	 * to at most 8 entries.
78 	 */
79 };
80 
81 static DECLARE_COMPLETION(cpu_running);
82 
83 static struct smp_operations smp_ops __ro_after_init;
84 
85 void __init smp_set_ops(const struct smp_operations *ops)
86 {
87 	if (ops)
88 		smp_ops = *ops;
89 };
90 
91 static unsigned long get_arch_pgd(pgd_t *pgd)
92 {
93 #ifdef CONFIG_ARM_LPAE
94 	return __phys_to_pfn(virt_to_phys(pgd));
95 #else
96 	return virt_to_phys(pgd);
97 #endif
98 }
99 
100 #if defined(CONFIG_BIG_LITTLE) && defined(CONFIG_HARDEN_BRANCH_PREDICTOR)
101 static int secondary_biglittle_prepare(unsigned int cpu)
102 {
103 	if (!cpu_vtable[cpu])
104 		cpu_vtable[cpu] = kzalloc(sizeof(*cpu_vtable[cpu]), GFP_KERNEL);
105 
106 	return cpu_vtable[cpu] ? 0 : -ENOMEM;
107 }
108 
109 static void secondary_biglittle_init(void)
110 {
111 	init_proc_vtable(lookup_processor(read_cpuid_id())->proc);
112 }
113 #else
114 static int secondary_biglittle_prepare(unsigned int cpu)
115 {
116 	return 0;
117 }
118 
119 static void secondary_biglittle_init(void)
120 {
121 }
122 #endif
123 
124 int __cpu_up(unsigned int cpu, struct task_struct *idle)
125 {
126 	int ret;
127 
128 	if (!smp_ops.smp_boot_secondary)
129 		return -ENOSYS;
130 
131 	ret = secondary_biglittle_prepare(cpu);
132 	if (ret)
133 		return ret;
134 
135 	/*
136 	 * We need to tell the secondary core where to find
137 	 * its stack and the page tables.
138 	 */
139 	secondary_data.stack = task_stack_page(idle) + THREAD_START_SP;
140 #ifdef CONFIG_ARM_MPU
141 	secondary_data.mpu_rgn_info = &mpu_rgn_info;
142 #endif
143 
144 #ifdef CONFIG_MMU
145 	secondary_data.pgdir = virt_to_phys(idmap_pgd);
146 	secondary_data.swapper_pg_dir = get_arch_pgd(swapper_pg_dir);
147 #endif
148 	sync_cache_w(&secondary_data);
149 
150 	/*
151 	 * Now bring the CPU into our world.
152 	 */
153 	ret = smp_ops.smp_boot_secondary(cpu, idle);
154 	if (ret == 0) {
155 		/*
156 		 * CPU was successfully started, wait for it
157 		 * to come online or time out.
158 		 */
159 		wait_for_completion_timeout(&cpu_running,
160 						 msecs_to_jiffies(1000));
161 
162 		if (!cpu_online(cpu)) {
163 			pr_crit("CPU%u: failed to come online\n", cpu);
164 			ret = -EIO;
165 		}
166 	} else {
167 		pr_err("CPU%u: failed to boot: %d\n", cpu, ret);
168 	}
169 
170 
171 	memset(&secondary_data, 0, sizeof(secondary_data));
172 	return ret;
173 }
174 
175 /* platform specific SMP operations */
176 void __init smp_init_cpus(void)
177 {
178 	if (smp_ops.smp_init_cpus)
179 		smp_ops.smp_init_cpus();
180 }
181 
182 int platform_can_secondary_boot(void)
183 {
184 	return !!smp_ops.smp_boot_secondary;
185 }
186 
187 int platform_can_cpu_hotplug(void)
188 {
189 #ifdef CONFIG_HOTPLUG_CPU
190 	if (smp_ops.cpu_kill)
191 		return 1;
192 #endif
193 
194 	return 0;
195 }
196 
197 #ifdef CONFIG_HOTPLUG_CPU
198 static int platform_cpu_kill(unsigned int cpu)
199 {
200 	if (smp_ops.cpu_kill)
201 		return smp_ops.cpu_kill(cpu);
202 	return 1;
203 }
204 
205 static int platform_cpu_disable(unsigned int cpu)
206 {
207 	if (smp_ops.cpu_disable)
208 		return smp_ops.cpu_disable(cpu);
209 
210 	return 0;
211 }
212 
213 int platform_can_hotplug_cpu(unsigned int cpu)
214 {
215 	/* cpu_die must be specified to support hotplug */
216 	if (!smp_ops.cpu_die)
217 		return 0;
218 
219 	if (smp_ops.cpu_can_disable)
220 		return smp_ops.cpu_can_disable(cpu);
221 
222 	/*
223 	 * By default, allow disabling all CPUs except the first one,
224 	 * since this is special on a lot of platforms, e.g. because
225 	 * of clock tick interrupts.
226 	 */
227 	return cpu != 0;
228 }
229 
230 /*
231  * __cpu_disable runs on the processor to be shutdown.
232  */
233 int __cpu_disable(void)
234 {
235 	unsigned int cpu = smp_processor_id();
236 	int ret;
237 
238 	ret = platform_cpu_disable(cpu);
239 	if (ret)
240 		return ret;
241 
242 #ifdef CONFIG_GENERIC_ARCH_TOPOLOGY
243 	remove_cpu_topology(cpu);
244 #endif
245 
246 	/*
247 	 * Take this CPU offline.  Once we clear this, we can't return,
248 	 * and we must not schedule until we're ready to give up the cpu.
249 	 */
250 	set_cpu_online(cpu, false);
251 
252 	/*
253 	 * OK - migrate IRQs away from this CPU
254 	 */
255 	irq_migrate_all_off_this_cpu();
256 
257 	/*
258 	 * Flush user cache and TLB mappings, and then remove this CPU
259 	 * from the vm mask set of all processes.
260 	 *
261 	 * Caches are flushed to the Level of Unification Inner Shareable
262 	 * to write-back dirty lines to unified caches shared by all CPUs.
263 	 */
264 	flush_cache_louis();
265 	local_flush_tlb_all();
266 
267 	return 0;
268 }
269 
270 /*
271  * called on the thread which is asking for a CPU to be shutdown -
272  * waits until shutdown has completed, or it is timed out.
273  */
274 void __cpu_die(unsigned int cpu)
275 {
276 	if (!cpu_wait_death(cpu, 5)) {
277 		pr_err("CPU%u: cpu didn't die\n", cpu);
278 		return;
279 	}
280 	pr_debug("CPU%u: shutdown\n", cpu);
281 
282 	clear_tasks_mm_cpumask(cpu);
283 	/*
284 	 * platform_cpu_kill() is generally expected to do the powering off
285 	 * and/or cutting of clocks to the dying CPU.  Optionally, this may
286 	 * be done by the CPU which is dying in preference to supporting
287 	 * this call, but that means there is _no_ synchronisation between
288 	 * the requesting CPU and the dying CPU actually losing power.
289 	 */
290 	if (!platform_cpu_kill(cpu))
291 		pr_err("CPU%u: unable to kill\n", cpu);
292 }
293 
294 /*
295  * Called from the idle thread for the CPU which has been shutdown.
296  *
297  * Note that we disable IRQs here, but do not re-enable them
298  * before returning to the caller. This is also the behaviour
299  * of the other hotplug-cpu capable cores, so presumably coming
300  * out of idle fixes this.
301  */
302 void arch_cpu_idle_dead(void)
303 {
304 	unsigned int cpu = smp_processor_id();
305 
306 	idle_task_exit();
307 
308 	local_irq_disable();
309 
310 	/*
311 	 * Flush the data out of the L1 cache for this CPU.  This must be
312 	 * before the completion to ensure that data is safely written out
313 	 * before platform_cpu_kill() gets called - which may disable
314 	 * *this* CPU and power down its cache.
315 	 */
316 	flush_cache_louis();
317 
318 	/*
319 	 * Tell __cpu_die() that this CPU is now safe to dispose of.  Once
320 	 * this returns, power and/or clocks can be removed at any point
321 	 * from this CPU and its cache by platform_cpu_kill().
322 	 */
323 	(void)cpu_report_death();
324 
325 	/*
326 	 * Ensure that the cache lines associated with that completion are
327 	 * written out.  This covers the case where _this_ CPU is doing the
328 	 * powering down, to ensure that the completion is visible to the
329 	 * CPU waiting for this one.
330 	 */
331 	flush_cache_louis();
332 
333 	/*
334 	 * The actual CPU shutdown procedure is at least platform (if not
335 	 * CPU) specific.  This may remove power, or it may simply spin.
336 	 *
337 	 * Platforms are generally expected *NOT* to return from this call,
338 	 * although there are some which do because they have no way to
339 	 * power down the CPU.  These platforms are the _only_ reason we
340 	 * have a return path which uses the fragment of assembly below.
341 	 *
342 	 * The return path should not be used for platforms which can
343 	 * power off the CPU.
344 	 */
345 	if (smp_ops.cpu_die)
346 		smp_ops.cpu_die(cpu);
347 
348 	pr_warn("CPU%u: smp_ops.cpu_die() returned, trying to resuscitate\n",
349 		cpu);
350 
351 	/*
352 	 * Do not return to the idle loop - jump back to the secondary
353 	 * cpu initialisation.  There's some initialisation which needs
354 	 * to be repeated to undo the effects of taking the CPU offline.
355 	 */
356 	__asm__("mov	sp, %0\n"
357 	"	mov	fp, #0\n"
358 	"	b	secondary_start_kernel"
359 		:
360 		: "r" (task_stack_page(current) + THREAD_SIZE - 8));
361 }
362 #endif /* CONFIG_HOTPLUG_CPU */
363 
364 /*
365  * Called by both boot and secondaries to move global data into
366  * per-processor storage.
367  */
368 static void smp_store_cpu_info(unsigned int cpuid)
369 {
370 	struct cpuinfo_arm *cpu_info = &per_cpu(cpu_data, cpuid);
371 
372 	cpu_info->loops_per_jiffy = loops_per_jiffy;
373 	cpu_info->cpuid = read_cpuid_id();
374 
375 	store_cpu_topology(cpuid);
376 	check_cpu_icache_size(cpuid);
377 }
378 
379 /*
380  * This is the secondary CPU boot entry.  We're using this CPUs
381  * idle thread stack, but a set of temporary page tables.
382  */
383 asmlinkage void secondary_start_kernel(void)
384 {
385 	struct mm_struct *mm = &init_mm;
386 	unsigned int cpu;
387 
388 	secondary_biglittle_init();
389 
390 	/*
391 	 * The identity mapping is uncached (strongly ordered), so
392 	 * switch away from it before attempting any exclusive accesses.
393 	 */
394 	cpu_switch_mm(mm->pgd, mm);
395 	local_flush_bp_all();
396 	enter_lazy_tlb(mm, current);
397 	local_flush_tlb_all();
398 
399 	/*
400 	 * All kernel threads share the same mm context; grab a
401 	 * reference and switch to it.
402 	 */
403 	cpu = smp_processor_id();
404 	mmgrab(mm);
405 	current->active_mm = mm;
406 	cpumask_set_cpu(cpu, mm_cpumask(mm));
407 
408 	cpu_init();
409 
410 #ifndef CONFIG_MMU
411 	setup_vectors_base();
412 #endif
413 	pr_debug("CPU%u: Booted secondary processor\n", cpu);
414 
415 	preempt_disable();
416 	trace_hardirqs_off();
417 
418 	/*
419 	 * Give the platform a chance to do its own initialisation.
420 	 */
421 	if (smp_ops.smp_secondary_init)
422 		smp_ops.smp_secondary_init(cpu);
423 
424 	notify_cpu_starting(cpu);
425 
426 	calibrate_delay();
427 
428 	smp_store_cpu_info(cpu);
429 
430 	/*
431 	 * OK, now it's safe to let the boot CPU continue.  Wait for
432 	 * the CPU migration code to notice that the CPU is online
433 	 * before we continue - which happens after __cpu_up returns.
434 	 */
435 	set_cpu_online(cpu, true);
436 
437 	check_other_bugs();
438 
439 	complete(&cpu_running);
440 
441 	local_irq_enable();
442 	local_fiq_enable();
443 	local_abt_enable();
444 
445 	/*
446 	 * OK, it's off to the idle thread for us
447 	 */
448 	cpu_startup_entry(CPUHP_AP_ONLINE_IDLE);
449 }
450 
451 void __init smp_cpus_done(unsigned int max_cpus)
452 {
453 	int cpu;
454 	unsigned long bogosum = 0;
455 
456 	for_each_online_cpu(cpu)
457 		bogosum += per_cpu(cpu_data, cpu).loops_per_jiffy;
458 
459 	printk(KERN_INFO "SMP: Total of %d processors activated "
460 	       "(%lu.%02lu BogoMIPS).\n",
461 	       num_online_cpus(),
462 	       bogosum / (500000/HZ),
463 	       (bogosum / (5000/HZ)) % 100);
464 
465 	hyp_mode_check();
466 }
467 
468 void __init smp_prepare_boot_cpu(void)
469 {
470 	set_my_cpu_offset(per_cpu_offset(smp_processor_id()));
471 }
472 
473 void __init smp_prepare_cpus(unsigned int max_cpus)
474 {
475 	unsigned int ncores = num_possible_cpus();
476 
477 	init_cpu_topology();
478 
479 	smp_store_cpu_info(smp_processor_id());
480 
481 	/*
482 	 * are we trying to boot more cores than exist?
483 	 */
484 	if (max_cpus > ncores)
485 		max_cpus = ncores;
486 	if (ncores > 1 && max_cpus) {
487 		/*
488 		 * Initialise the present map, which describes the set of CPUs
489 		 * actually populated at the present time. A platform should
490 		 * re-initialize the map in the platforms smp_prepare_cpus()
491 		 * if present != possible (e.g. physical hotplug).
492 		 */
493 		init_cpu_present(cpu_possible_mask);
494 
495 		/*
496 		 * Initialise the SCU if there are more than one CPU
497 		 * and let them know where to start.
498 		 */
499 		if (smp_ops.smp_prepare_cpus)
500 			smp_ops.smp_prepare_cpus(max_cpus);
501 	}
502 }
503 
504 static void (*__smp_cross_call)(const struct cpumask *, unsigned int);
505 
506 void __init set_smp_cross_call(void (*fn)(const struct cpumask *, unsigned int))
507 {
508 	if (!__smp_cross_call)
509 		__smp_cross_call = fn;
510 }
511 
512 static const char *ipi_types[NR_IPI] __tracepoint_string = {
513 #define S(x,s)	[x] = s
514 	S(IPI_WAKEUP, "CPU wakeup interrupts"),
515 	S(IPI_TIMER, "Timer broadcast interrupts"),
516 	S(IPI_RESCHEDULE, "Rescheduling interrupts"),
517 	S(IPI_CALL_FUNC, "Function call interrupts"),
518 	S(IPI_CPU_STOP, "CPU stop interrupts"),
519 	S(IPI_IRQ_WORK, "IRQ work interrupts"),
520 	S(IPI_COMPLETION, "completion interrupts"),
521 };
522 
523 static void smp_cross_call(const struct cpumask *target, unsigned int ipinr)
524 {
525 	trace_ipi_raise_rcuidle(target, ipi_types[ipinr]);
526 	__smp_cross_call(target, ipinr);
527 }
528 
529 void show_ipi_list(struct seq_file *p, int prec)
530 {
531 	unsigned int cpu, i;
532 
533 	for (i = 0; i < NR_IPI; i++) {
534 		seq_printf(p, "%*s%u: ", prec - 1, "IPI", i);
535 
536 		for_each_online_cpu(cpu)
537 			seq_printf(p, "%10u ",
538 				   __get_irq_stat(cpu, ipi_irqs[i]));
539 
540 		seq_printf(p, " %s\n", ipi_types[i]);
541 	}
542 }
543 
544 u64 smp_irq_stat_cpu(unsigned int cpu)
545 {
546 	u64 sum = 0;
547 	int i;
548 
549 	for (i = 0; i < NR_IPI; i++)
550 		sum += __get_irq_stat(cpu, ipi_irqs[i]);
551 
552 	return sum;
553 }
554 
555 void arch_send_call_function_ipi_mask(const struct cpumask *mask)
556 {
557 	smp_cross_call(mask, IPI_CALL_FUNC);
558 }
559 
560 void arch_send_wakeup_ipi_mask(const struct cpumask *mask)
561 {
562 	smp_cross_call(mask, IPI_WAKEUP);
563 }
564 
565 void arch_send_call_function_single_ipi(int cpu)
566 {
567 	smp_cross_call(cpumask_of(cpu), IPI_CALL_FUNC);
568 }
569 
570 #ifdef CONFIG_IRQ_WORK
571 void arch_irq_work_raise(void)
572 {
573 	if (arch_irq_work_has_interrupt())
574 		smp_cross_call(cpumask_of(smp_processor_id()), IPI_IRQ_WORK);
575 }
576 #endif
577 
578 #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
579 void tick_broadcast(const struct cpumask *mask)
580 {
581 	smp_cross_call(mask, IPI_TIMER);
582 }
583 #endif
584 
585 static DEFINE_RAW_SPINLOCK(stop_lock);
586 
587 /*
588  * ipi_cpu_stop - handle IPI from smp_send_stop()
589  */
590 static void ipi_cpu_stop(unsigned int cpu)
591 {
592 	if (system_state <= SYSTEM_RUNNING) {
593 		raw_spin_lock(&stop_lock);
594 		pr_crit("CPU%u: stopping\n", cpu);
595 		dump_stack();
596 		raw_spin_unlock(&stop_lock);
597 	}
598 
599 	set_cpu_online(cpu, false);
600 
601 	local_fiq_disable();
602 	local_irq_disable();
603 
604 	while (1) {
605 		cpu_relax();
606 		wfe();
607 	}
608 }
609 
610 static DEFINE_PER_CPU(struct completion *, cpu_completion);
611 
612 int register_ipi_completion(struct completion *completion, int cpu)
613 {
614 	per_cpu(cpu_completion, cpu) = completion;
615 	return IPI_COMPLETION;
616 }
617 
618 static void ipi_complete(unsigned int cpu)
619 {
620 	complete(per_cpu(cpu_completion, cpu));
621 }
622 
623 /*
624  * Main handler for inter-processor interrupts
625  */
626 asmlinkage void __exception_irq_entry do_IPI(int ipinr, struct pt_regs *regs)
627 {
628 	handle_IPI(ipinr, regs);
629 }
630 
631 void handle_IPI(int ipinr, struct pt_regs *regs)
632 {
633 	unsigned int cpu = smp_processor_id();
634 	struct pt_regs *old_regs = set_irq_regs(regs);
635 
636 	if ((unsigned)ipinr < NR_IPI) {
637 		trace_ipi_entry_rcuidle(ipi_types[ipinr]);
638 		__inc_irq_stat(cpu, ipi_irqs[ipinr]);
639 	}
640 
641 	switch (ipinr) {
642 	case IPI_WAKEUP:
643 		break;
644 
645 #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
646 	case IPI_TIMER:
647 		irq_enter();
648 		tick_receive_broadcast();
649 		irq_exit();
650 		break;
651 #endif
652 
653 	case IPI_RESCHEDULE:
654 		scheduler_ipi();
655 		break;
656 
657 	case IPI_CALL_FUNC:
658 		irq_enter();
659 		generic_smp_call_function_interrupt();
660 		irq_exit();
661 		break;
662 
663 	case IPI_CPU_STOP:
664 		irq_enter();
665 		ipi_cpu_stop(cpu);
666 		irq_exit();
667 		break;
668 
669 #ifdef CONFIG_IRQ_WORK
670 	case IPI_IRQ_WORK:
671 		irq_enter();
672 		irq_work_run();
673 		irq_exit();
674 		break;
675 #endif
676 
677 	case IPI_COMPLETION:
678 		irq_enter();
679 		ipi_complete(cpu);
680 		irq_exit();
681 		break;
682 
683 	case IPI_CPU_BACKTRACE:
684 		printk_nmi_enter();
685 		irq_enter();
686 		nmi_cpu_backtrace(regs);
687 		irq_exit();
688 		printk_nmi_exit();
689 		break;
690 
691 	default:
692 		pr_crit("CPU%u: Unknown IPI message 0x%x\n",
693 		        cpu, ipinr);
694 		break;
695 	}
696 
697 	if ((unsigned)ipinr < NR_IPI)
698 		trace_ipi_exit_rcuidle(ipi_types[ipinr]);
699 	set_irq_regs(old_regs);
700 }
701 
702 void smp_send_reschedule(int cpu)
703 {
704 	smp_cross_call(cpumask_of(cpu), IPI_RESCHEDULE);
705 }
706 
707 void smp_send_stop(void)
708 {
709 	unsigned long timeout;
710 	struct cpumask mask;
711 
712 	cpumask_copy(&mask, cpu_online_mask);
713 	cpumask_clear_cpu(smp_processor_id(), &mask);
714 	if (!cpumask_empty(&mask))
715 		smp_cross_call(&mask, IPI_CPU_STOP);
716 
717 	/* Wait up to one second for other CPUs to stop */
718 	timeout = USEC_PER_SEC;
719 	while (num_online_cpus() > 1 && timeout--)
720 		udelay(1);
721 
722 	if (num_online_cpus() > 1)
723 		pr_warn("SMP: failed to stop secondary CPUs\n");
724 }
725 
726 /* In case panic() and panic() called at the same time on CPU1 and CPU2,
727  * and CPU 1 calls panic_smp_self_stop() before crash_smp_send_stop()
728  * CPU1 can't receive the ipi irqs from CPU2, CPU1 will be always online,
729  * kdump fails. So split out the panic_smp_self_stop() and add
730  * set_cpu_online(smp_processor_id(), false).
731  */
732 void panic_smp_self_stop(void)
733 {
734 	pr_debug("CPU %u will stop doing anything useful since another CPU has paniced\n",
735 	         smp_processor_id());
736 	set_cpu_online(smp_processor_id(), false);
737 	while (1)
738 		cpu_relax();
739 }
740 
741 /*
742  * not supported here
743  */
744 int setup_profiling_timer(unsigned int multiplier)
745 {
746 	return -EINVAL;
747 }
748 
749 #ifdef CONFIG_CPU_FREQ
750 
751 static DEFINE_PER_CPU(unsigned long, l_p_j_ref);
752 static DEFINE_PER_CPU(unsigned long, l_p_j_ref_freq);
753 static unsigned long global_l_p_j_ref;
754 static unsigned long global_l_p_j_ref_freq;
755 
756 static int cpufreq_callback(struct notifier_block *nb,
757 					unsigned long val, void *data)
758 {
759 	struct cpufreq_freqs *freq = data;
760 	struct cpumask *cpus = freq->policy->cpus;
761 	int cpu, first = cpumask_first(cpus);
762 	unsigned int lpj;
763 
764 	if (freq->flags & CPUFREQ_CONST_LOOPS)
765 		return NOTIFY_OK;
766 
767 	if (!per_cpu(l_p_j_ref, first)) {
768 		for_each_cpu(cpu, cpus) {
769 			per_cpu(l_p_j_ref, cpu) =
770 				per_cpu(cpu_data, cpu).loops_per_jiffy;
771 			per_cpu(l_p_j_ref_freq, cpu) = freq->old;
772 		}
773 
774 		if (!global_l_p_j_ref) {
775 			global_l_p_j_ref = loops_per_jiffy;
776 			global_l_p_j_ref_freq = freq->old;
777 		}
778 	}
779 
780 	if ((val == CPUFREQ_PRECHANGE  && freq->old < freq->new) ||
781 	    (val == CPUFREQ_POSTCHANGE && freq->old > freq->new)) {
782 		loops_per_jiffy = cpufreq_scale(global_l_p_j_ref,
783 						global_l_p_j_ref_freq,
784 						freq->new);
785 
786 		lpj = cpufreq_scale(per_cpu(l_p_j_ref, first),
787 				    per_cpu(l_p_j_ref_freq, first), freq->new);
788 		for_each_cpu(cpu, cpus)
789 			per_cpu(cpu_data, cpu).loops_per_jiffy = lpj;
790 	}
791 	return NOTIFY_OK;
792 }
793 
794 static struct notifier_block cpufreq_notifier = {
795 	.notifier_call  = cpufreq_callback,
796 };
797 
798 static int __init register_cpufreq_notifier(void)
799 {
800 	return cpufreq_register_notifier(&cpufreq_notifier,
801 						CPUFREQ_TRANSITION_NOTIFIER);
802 }
803 core_initcall(register_cpufreq_notifier);
804 
805 #endif
806 
807 static void raise_nmi(cpumask_t *mask)
808 {
809 	__smp_cross_call(mask, IPI_CPU_BACKTRACE);
810 }
811 
812 void arch_trigger_cpumask_backtrace(const cpumask_t *mask, bool exclude_self)
813 {
814 	nmi_trigger_cpumask_backtrace(mask, exclude_self, raise_nmi);
815 }
816