smp.c 18 KB

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