smp.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757
  1. /*
  2. * SMP support for ppc.
  3. *
  4. * Written by Cort Dougan (cort@cs.nmt.edu) borrowing a great
  5. * deal of code from the sparc and intel versions.
  6. *
  7. * Copyright (C) 1999 Cort Dougan <cort@cs.nmt.edu>
  8. *
  9. * PowerPC-64 Support added by Dave Engebretsen, Peter Bergner, and
  10. * Mike Corrigan {engebret|bergner|mikec}@us.ibm.com
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License
  14. * as published by the Free Software Foundation; either version
  15. * 2 of the License, or (at your option) any later version.
  16. */
  17. #undef DEBUG
  18. #include <linux/kernel.h>
  19. #include <linux/module.h>
  20. #include <linux/sched.h>
  21. #include <linux/smp.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/delay.h>
  24. #include <linux/init.h>
  25. #include <linux/spinlock.h>
  26. #include <linux/cache.h>
  27. #include <linux/err.h>
  28. #include <linux/sysdev.h>
  29. #include <linux/cpu.h>
  30. #include <linux/notifier.h>
  31. #include <linux/topology.h>
  32. #include <asm/ptrace.h>
  33. #include <asm/atomic.h>
  34. #include <asm/irq.h>
  35. #include <asm/page.h>
  36. #include <asm/pgtable.h>
  37. #include <asm/prom.h>
  38. #include <asm/smp.h>
  39. #include <asm/time.h>
  40. #include <asm/machdep.h>
  41. #include <asm/cputhreads.h>
  42. #include <asm/cputable.h>
  43. #include <asm/system.h>
  44. #include <asm/mpic.h>
  45. #include <asm/vdso_datapage.h>
  46. #ifdef CONFIG_PPC64
  47. #include <asm/paca.h>
  48. #endif
  49. #ifdef DEBUG
  50. #include <asm/udbg.h>
  51. #define DBG(fmt...) udbg_printf(fmt)
  52. #else
  53. #define DBG(fmt...)
  54. #endif
  55. /* Store all idle threads, this can be reused instead of creating
  56. * a new thread. Also avoids complicated thread destroy functionality
  57. * for idle threads.
  58. */
  59. #ifdef CONFIG_HOTPLUG_CPU
  60. /*
  61. * Needed only for CONFIG_HOTPLUG_CPU because __cpuinitdata is
  62. * removed after init for !CONFIG_HOTPLUG_CPU.
  63. */
  64. static DEFINE_PER_CPU(struct task_struct *, idle_thread_array);
  65. #define get_idle_for_cpu(x) (per_cpu(idle_thread_array, x))
  66. #define set_idle_for_cpu(x, p) (per_cpu(idle_thread_array, x) = (p))
  67. #else
  68. static struct task_struct *idle_thread_array[NR_CPUS] __cpuinitdata ;
  69. #define get_idle_for_cpu(x) (idle_thread_array[(x)])
  70. #define set_idle_for_cpu(x, p) (idle_thread_array[(x)] = (p))
  71. #endif
  72. struct thread_info *secondary_ti;
  73. DEFINE_PER_CPU(cpumask_var_t, cpu_sibling_map);
  74. DEFINE_PER_CPU(cpumask_var_t, cpu_core_map);
  75. EXPORT_PER_CPU_SYMBOL(cpu_sibling_map);
  76. EXPORT_PER_CPU_SYMBOL(cpu_core_map);
  77. /* SMP operations for this machine */
  78. struct smp_ops_t *smp_ops;
  79. /* Can't be static due to PowerMac hackery */
  80. volatile unsigned int cpu_callin_map[NR_CPUS];
  81. int smt_enabled_at_boot = 1;
  82. static void (*crash_ipi_function_ptr)(struct pt_regs *) = NULL;
  83. #ifdef CONFIG_PPC64
  84. int __devinit smp_generic_kick_cpu(int nr)
  85. {
  86. BUG_ON(nr < 0 || nr >= NR_CPUS);
  87. /*
  88. * The processor is currently spinning, waiting for the
  89. * cpu_start field to become non-zero After we set cpu_start,
  90. * the processor will continue on to secondary_start
  91. */
  92. paca[nr].cpu_start = 1;
  93. smp_mb();
  94. return 0;
  95. }
  96. #endif
  97. static irqreturn_t call_function_action(int irq, void *data)
  98. {
  99. generic_smp_call_function_interrupt();
  100. return IRQ_HANDLED;
  101. }
  102. static irqreturn_t reschedule_action(int irq, void *data)
  103. {
  104. scheduler_ipi();
  105. return IRQ_HANDLED;
  106. }
  107. static irqreturn_t call_function_single_action(int irq, void *data)
  108. {
  109. generic_smp_call_function_single_interrupt();
  110. return IRQ_HANDLED;
  111. }
  112. irqreturn_t debug_ipi_action(int irq, void *data)
  113. {
  114. if (crash_ipi_function_ptr) {
  115. crash_ipi_function_ptr(get_irq_regs());
  116. return IRQ_HANDLED;
  117. }
  118. #ifdef CONFIG_DEBUGGER
  119. debugger_ipi(get_irq_regs());
  120. #endif /* CONFIG_DEBUGGER */
  121. return IRQ_HANDLED;
  122. }
  123. static irq_handler_t smp_ipi_action[] = {
  124. [PPC_MSG_CALL_FUNCTION] = call_function_action,
  125. [PPC_MSG_RESCHEDULE] = reschedule_action,
  126. [PPC_MSG_CALL_FUNC_SINGLE] = call_function_single_action,
  127. [PPC_MSG_DEBUGGER_BREAK] = debug_ipi_action,
  128. };
  129. const char *smp_ipi_name[] = {
  130. [PPC_MSG_CALL_FUNCTION] = "ipi call function",
  131. [PPC_MSG_RESCHEDULE] = "ipi reschedule",
  132. [PPC_MSG_CALL_FUNC_SINGLE] = "ipi call function single",
  133. [PPC_MSG_DEBUGGER_BREAK] = "ipi debugger",
  134. };
  135. /* optional function to request ipi, for controllers with >= 4 ipis */
  136. int smp_request_message_ipi(int virq, int msg)
  137. {
  138. int err;
  139. if (msg < 0 || msg > PPC_MSG_DEBUGGER_BREAK) {
  140. return -EINVAL;
  141. }
  142. #if !defined(CONFIG_DEBUGGER) && !defined(CONFIG_KEXEC)
  143. if (msg == PPC_MSG_DEBUGGER_BREAK) {
  144. return 1;
  145. }
  146. #endif
  147. err = request_irq(virq, smp_ipi_action[msg], IRQF_DISABLED|IRQF_PERCPU,
  148. smp_ipi_name[msg], 0);
  149. WARN(err < 0, "unable to request_irq %d for %s (rc %d)\n",
  150. virq, smp_ipi_name[msg], err);
  151. return err;
  152. }
  153. #ifdef CONFIG_PPC_SMP_MUXED_IPI
  154. struct cpu_messages {
  155. int messages; /* current messages */
  156. unsigned long data; /* data for cause ipi */
  157. };
  158. static DEFINE_PER_CPU_SHARED_ALIGNED(struct cpu_messages, ipi_message);
  159. void smp_muxed_ipi_set_data(int cpu, unsigned long data)
  160. {
  161. struct cpu_messages *info = &per_cpu(ipi_message, cpu);
  162. info->data = data;
  163. }
  164. void smp_muxed_ipi_message_pass(int cpu, int msg)
  165. {
  166. struct cpu_messages *info = &per_cpu(ipi_message, cpu);
  167. char *message = (char *)&info->messages;
  168. message[msg] = 1;
  169. mb();
  170. smp_ops->cause_ipi(cpu, info->data);
  171. }
  172. void smp_muxed_ipi_resend(void)
  173. {
  174. struct cpu_messages *info = &__get_cpu_var(ipi_message);
  175. if (info->messages)
  176. smp_ops->cause_ipi(smp_processor_id(), info->data);
  177. }
  178. irqreturn_t smp_ipi_demux(void)
  179. {
  180. struct cpu_messages *info = &__get_cpu_var(ipi_message);
  181. unsigned int all;
  182. mb(); /* order any irq clear */
  183. do {
  184. all = xchg_local(&info->messages, 0);
  185. #ifdef __BIG_ENDIAN
  186. if (all & (1 << (24 - 8 * PPC_MSG_CALL_FUNCTION)))
  187. generic_smp_call_function_interrupt();
  188. if (all & (1 << (24 - 8 * PPC_MSG_RESCHEDULE)))
  189. scheduler_ipi();
  190. if (all & (1 << (24 - 8 * PPC_MSG_CALL_FUNC_SINGLE)))
  191. generic_smp_call_function_single_interrupt();
  192. if (all & (1 << (24 - 8 * PPC_MSG_DEBUGGER_BREAK)))
  193. debug_ipi_action(0, NULL);
  194. #else
  195. #error Unsupported ENDIAN
  196. #endif
  197. } while (info->messages);
  198. return IRQ_HANDLED;
  199. }
  200. #endif /* CONFIG_PPC_SMP_MUXED_IPI */
  201. void smp_send_reschedule(int cpu)
  202. {
  203. if (likely(smp_ops))
  204. smp_ops->message_pass(cpu, PPC_MSG_RESCHEDULE);
  205. }
  206. void arch_send_call_function_single_ipi(int cpu)
  207. {
  208. smp_ops->message_pass(cpu, PPC_MSG_CALL_FUNC_SINGLE);
  209. }
  210. void arch_send_call_function_ipi_mask(const struct cpumask *mask)
  211. {
  212. unsigned int cpu;
  213. for_each_cpu(cpu, mask)
  214. smp_ops->message_pass(cpu, PPC_MSG_CALL_FUNCTION);
  215. }
  216. #if defined(CONFIG_DEBUGGER) || defined(CONFIG_KEXEC)
  217. void smp_send_debugger_break(void)
  218. {
  219. int cpu;
  220. int me = raw_smp_processor_id();
  221. if (unlikely(!smp_ops))
  222. return;
  223. for_each_online_cpu(cpu)
  224. if (cpu != me)
  225. smp_ops->message_pass(cpu, PPC_MSG_DEBUGGER_BREAK);
  226. }
  227. #endif
  228. #ifdef CONFIG_KEXEC
  229. void crash_send_ipi(void (*crash_ipi_callback)(struct pt_regs *))
  230. {
  231. crash_ipi_function_ptr = crash_ipi_callback;
  232. if (crash_ipi_callback) {
  233. mb();
  234. smp_send_debugger_break();
  235. }
  236. }
  237. #endif
  238. static void stop_this_cpu(void *dummy)
  239. {
  240. /* Remove this CPU */
  241. set_cpu_online(smp_processor_id(), false);
  242. local_irq_disable();
  243. while (1)
  244. ;
  245. }
  246. void smp_send_stop(void)
  247. {
  248. smp_call_function(stop_this_cpu, NULL, 0);
  249. }
  250. struct thread_info *current_set[NR_CPUS];
  251. static void __devinit smp_store_cpu_info(int id)
  252. {
  253. per_cpu(cpu_pvr, id) = mfspr(SPRN_PVR);
  254. }
  255. void __init smp_prepare_cpus(unsigned int max_cpus)
  256. {
  257. unsigned int cpu;
  258. DBG("smp_prepare_cpus\n");
  259. /*
  260. * setup_cpu may need to be called on the boot cpu. We havent
  261. * spun any cpus up but lets be paranoid.
  262. */
  263. BUG_ON(boot_cpuid != smp_processor_id());
  264. /* Fixup boot cpu */
  265. smp_store_cpu_info(boot_cpuid);
  266. cpu_callin_map[boot_cpuid] = 1;
  267. for_each_possible_cpu(cpu) {
  268. zalloc_cpumask_var_node(&per_cpu(cpu_sibling_map, cpu),
  269. GFP_KERNEL, cpu_to_node(cpu));
  270. zalloc_cpumask_var_node(&per_cpu(cpu_core_map, cpu),
  271. GFP_KERNEL, cpu_to_node(cpu));
  272. }
  273. cpumask_set_cpu(boot_cpuid, cpu_sibling_mask(boot_cpuid));
  274. cpumask_set_cpu(boot_cpuid, cpu_core_mask(boot_cpuid));
  275. if (smp_ops)
  276. if (smp_ops->probe)
  277. max_cpus = smp_ops->probe();
  278. else
  279. max_cpus = NR_CPUS;
  280. else
  281. max_cpus = 1;
  282. }
  283. void __devinit smp_prepare_boot_cpu(void)
  284. {
  285. BUG_ON(smp_processor_id() != boot_cpuid);
  286. #ifdef CONFIG_PPC64
  287. paca[boot_cpuid].__current = current;
  288. #endif
  289. current_set[boot_cpuid] = task_thread_info(current);
  290. }
  291. #ifdef CONFIG_HOTPLUG_CPU
  292. /* State of each CPU during hotplug phases */
  293. static DEFINE_PER_CPU(int, cpu_state) = { 0 };
  294. int generic_cpu_disable(void)
  295. {
  296. unsigned int cpu = smp_processor_id();
  297. if (cpu == boot_cpuid)
  298. return -EBUSY;
  299. set_cpu_online(cpu, false);
  300. #ifdef CONFIG_PPC64
  301. vdso_data->processorCount--;
  302. #endif
  303. migrate_irqs();
  304. return 0;
  305. }
  306. void generic_cpu_die(unsigned int cpu)
  307. {
  308. int i;
  309. for (i = 0; i < 100; i++) {
  310. smp_rmb();
  311. if (per_cpu(cpu_state, cpu) == CPU_DEAD)
  312. return;
  313. msleep(100);
  314. }
  315. printk(KERN_ERR "CPU%d didn't die...\n", cpu);
  316. }
  317. void generic_mach_cpu_die(void)
  318. {
  319. unsigned int cpu;
  320. local_irq_disable();
  321. idle_task_exit();
  322. cpu = smp_processor_id();
  323. printk(KERN_DEBUG "CPU%d offline\n", cpu);
  324. __get_cpu_var(cpu_state) = CPU_DEAD;
  325. smp_wmb();
  326. while (__get_cpu_var(cpu_state) != CPU_UP_PREPARE)
  327. cpu_relax();
  328. }
  329. void generic_set_cpu_dead(unsigned int cpu)
  330. {
  331. per_cpu(cpu_state, cpu) = CPU_DEAD;
  332. }
  333. #endif
  334. struct create_idle {
  335. struct work_struct work;
  336. struct task_struct *idle;
  337. struct completion done;
  338. int cpu;
  339. };
  340. static void __cpuinit do_fork_idle(struct work_struct *work)
  341. {
  342. struct create_idle *c_idle =
  343. container_of(work, struct create_idle, work);
  344. c_idle->idle = fork_idle(c_idle->cpu);
  345. complete(&c_idle->done);
  346. }
  347. static int __cpuinit create_idle(unsigned int cpu)
  348. {
  349. struct thread_info *ti;
  350. struct create_idle c_idle = {
  351. .cpu = cpu,
  352. .done = COMPLETION_INITIALIZER_ONSTACK(c_idle.done),
  353. };
  354. INIT_WORK_ONSTACK(&c_idle.work, do_fork_idle);
  355. c_idle.idle = get_idle_for_cpu(cpu);
  356. /* We can't use kernel_thread since we must avoid to
  357. * reschedule the child. We use a workqueue because
  358. * we want to fork from a kernel thread, not whatever
  359. * userspace process happens to be trying to online us.
  360. */
  361. if (!c_idle.idle) {
  362. schedule_work(&c_idle.work);
  363. wait_for_completion(&c_idle.done);
  364. } else
  365. init_idle(c_idle.idle, cpu);
  366. if (IS_ERR(c_idle.idle)) {
  367. pr_err("Failed fork for CPU %u: %li", cpu, PTR_ERR(c_idle.idle));
  368. return PTR_ERR(c_idle.idle);
  369. }
  370. ti = task_thread_info(c_idle.idle);
  371. #ifdef CONFIG_PPC64
  372. paca[cpu].__current = c_idle.idle;
  373. paca[cpu].kstack = (unsigned long)ti + THREAD_SIZE - STACK_FRAME_OVERHEAD;
  374. #endif
  375. ti->cpu = cpu;
  376. current_set[cpu] = ti;
  377. return 0;
  378. }
  379. int __cpuinit __cpu_up(unsigned int cpu)
  380. {
  381. int rc, c;
  382. if (smp_ops == NULL ||
  383. (smp_ops->cpu_bootable && !smp_ops->cpu_bootable(cpu)))
  384. return -EINVAL;
  385. /* Make sure we have an idle thread */
  386. rc = create_idle(cpu);
  387. if (rc)
  388. return rc;
  389. secondary_ti = current_set[cpu];
  390. /* Make sure callin-map entry is 0 (can be leftover a CPU
  391. * hotplug
  392. */
  393. cpu_callin_map[cpu] = 0;
  394. /* The information for processor bringup must
  395. * be written out to main store before we release
  396. * the processor.
  397. */
  398. smp_mb();
  399. /* wake up cpus */
  400. DBG("smp: kicking cpu %d\n", cpu);
  401. rc = smp_ops->kick_cpu(cpu);
  402. if (rc) {
  403. pr_err("smp: failed starting cpu %d (rc %d)\n", cpu, rc);
  404. return rc;
  405. }
  406. /*
  407. * wait to see if the cpu made a callin (is actually up).
  408. * use this value that I found through experimentation.
  409. * -- Cort
  410. */
  411. if (system_state < SYSTEM_RUNNING)
  412. for (c = 50000; c && !cpu_callin_map[cpu]; c--)
  413. udelay(100);
  414. #ifdef CONFIG_HOTPLUG_CPU
  415. else
  416. /*
  417. * CPUs can take much longer to come up in the
  418. * hotplug case. Wait five seconds.
  419. */
  420. for (c = 5000; c && !cpu_callin_map[cpu]; c--)
  421. msleep(1);
  422. #endif
  423. if (!cpu_callin_map[cpu]) {
  424. printk(KERN_ERR "Processor %u is stuck.\n", cpu);
  425. return -ENOENT;
  426. }
  427. DBG("Processor %u found.\n", cpu);
  428. if (smp_ops->give_timebase)
  429. smp_ops->give_timebase();
  430. /* Wait until cpu puts itself in the online map */
  431. while (!cpu_online(cpu))
  432. cpu_relax();
  433. return 0;
  434. }
  435. /* Return the value of the reg property corresponding to the given
  436. * logical cpu.
  437. */
  438. int cpu_to_core_id(int cpu)
  439. {
  440. struct device_node *np;
  441. const int *reg;
  442. int id = -1;
  443. np = of_get_cpu_node(cpu, NULL);
  444. if (!np)
  445. goto out;
  446. reg = of_get_property(np, "reg", NULL);
  447. if (!reg)
  448. goto out;
  449. id = *reg;
  450. out:
  451. of_node_put(np);
  452. return id;
  453. }
  454. /* Helper routines for cpu to core mapping */
  455. int cpu_core_index_of_thread(int cpu)
  456. {
  457. return cpu >> threads_shift;
  458. }
  459. EXPORT_SYMBOL_GPL(cpu_core_index_of_thread);
  460. int cpu_first_thread_of_core(int core)
  461. {
  462. return core << threads_shift;
  463. }
  464. EXPORT_SYMBOL_GPL(cpu_first_thread_of_core);
  465. /* Must be called when no change can occur to cpu_present_mask,
  466. * i.e. during cpu online or offline.
  467. */
  468. static struct device_node *cpu_to_l2cache(int cpu)
  469. {
  470. struct device_node *np;
  471. struct device_node *cache;
  472. if (!cpu_present(cpu))
  473. return NULL;
  474. np = of_get_cpu_node(cpu, NULL);
  475. if (np == NULL)
  476. return NULL;
  477. cache = of_find_next_cache_node(np);
  478. of_node_put(np);
  479. return cache;
  480. }
  481. /* Activate a secondary processor. */
  482. void __devinit start_secondary(void *unused)
  483. {
  484. unsigned int cpu = smp_processor_id();
  485. struct device_node *l2_cache;
  486. int i, base;
  487. atomic_inc(&init_mm.mm_count);
  488. current->active_mm = &init_mm;
  489. smp_store_cpu_info(cpu);
  490. set_dec(tb_ticks_per_jiffy);
  491. preempt_disable();
  492. cpu_callin_map[cpu] = 1;
  493. if (smp_ops->setup_cpu)
  494. smp_ops->setup_cpu(cpu);
  495. if (smp_ops->take_timebase)
  496. smp_ops->take_timebase();
  497. secondary_cpu_time_init();
  498. #ifdef CONFIG_PPC64
  499. if (system_state == SYSTEM_RUNNING)
  500. vdso_data->processorCount++;
  501. #endif
  502. ipi_call_lock();
  503. notify_cpu_starting(cpu);
  504. set_cpu_online(cpu, true);
  505. /* Update sibling maps */
  506. base = cpu_first_thread_sibling(cpu);
  507. for (i = 0; i < threads_per_core; i++) {
  508. if (cpu_is_offline(base + i))
  509. continue;
  510. cpumask_set_cpu(cpu, cpu_sibling_mask(base + i));
  511. cpumask_set_cpu(base + i, cpu_sibling_mask(cpu));
  512. /* cpu_core_map should be a superset of
  513. * cpu_sibling_map even if we don't have cache
  514. * information, so update the former here, too.
  515. */
  516. cpumask_set_cpu(cpu, cpu_core_mask(base + i));
  517. cpumask_set_cpu(base + i, cpu_core_mask(cpu));
  518. }
  519. l2_cache = cpu_to_l2cache(cpu);
  520. for_each_online_cpu(i) {
  521. struct device_node *np = cpu_to_l2cache(i);
  522. if (!np)
  523. continue;
  524. if (np == l2_cache) {
  525. cpumask_set_cpu(cpu, cpu_core_mask(i));
  526. cpumask_set_cpu(i, cpu_core_mask(cpu));
  527. }
  528. of_node_put(np);
  529. }
  530. of_node_put(l2_cache);
  531. ipi_call_unlock();
  532. local_irq_enable();
  533. cpu_idle();
  534. BUG();
  535. }
  536. int setup_profiling_timer(unsigned int multiplier)
  537. {
  538. return 0;
  539. }
  540. void __init smp_cpus_done(unsigned int max_cpus)
  541. {
  542. cpumask_var_t old_mask;
  543. /* We want the setup_cpu() here to be called from CPU 0, but our
  544. * init thread may have been "borrowed" by another CPU in the meantime
  545. * se we pin us down to CPU 0 for a short while
  546. */
  547. alloc_cpumask_var(&old_mask, GFP_NOWAIT);
  548. cpumask_copy(old_mask, tsk_cpus_allowed(current));
  549. set_cpus_allowed_ptr(current, cpumask_of(boot_cpuid));
  550. if (smp_ops && smp_ops->setup_cpu)
  551. smp_ops->setup_cpu(boot_cpuid);
  552. set_cpus_allowed_ptr(current, old_mask);
  553. free_cpumask_var(old_mask);
  554. if (smp_ops && smp_ops->bringup_done)
  555. smp_ops->bringup_done();
  556. dump_numa_cpu_topology();
  557. }
  558. int arch_sd_sibling_asym_packing(void)
  559. {
  560. if (cpu_has_feature(CPU_FTR_ASYM_SMT)) {
  561. printk_once(KERN_INFO "Enabling Asymmetric SMT scheduling\n");
  562. return SD_ASYM_PACKING;
  563. }
  564. return 0;
  565. }
  566. #ifdef CONFIG_HOTPLUG_CPU
  567. int __cpu_disable(void)
  568. {
  569. struct device_node *l2_cache;
  570. int cpu = smp_processor_id();
  571. int base, i;
  572. int err;
  573. if (!smp_ops->cpu_disable)
  574. return -ENOSYS;
  575. err = smp_ops->cpu_disable();
  576. if (err)
  577. return err;
  578. /* Update sibling maps */
  579. base = cpu_first_thread_sibling(cpu);
  580. for (i = 0; i < threads_per_core; i++) {
  581. cpumask_clear_cpu(cpu, cpu_sibling_mask(base + i));
  582. cpumask_clear_cpu(base + i, cpu_sibling_mask(cpu));
  583. cpumask_clear_cpu(cpu, cpu_core_mask(base + i));
  584. cpumask_clear_cpu(base + i, cpu_core_mask(cpu));
  585. }
  586. l2_cache = cpu_to_l2cache(cpu);
  587. for_each_present_cpu(i) {
  588. struct device_node *np = cpu_to_l2cache(i);
  589. if (!np)
  590. continue;
  591. if (np == l2_cache) {
  592. cpumask_clear_cpu(cpu, cpu_core_mask(i));
  593. cpumask_clear_cpu(i, cpu_core_mask(cpu));
  594. }
  595. of_node_put(np);
  596. }
  597. of_node_put(l2_cache);
  598. return 0;
  599. }
  600. void __cpu_die(unsigned int cpu)
  601. {
  602. if (smp_ops->cpu_die)
  603. smp_ops->cpu_die(cpu);
  604. }
  605. static DEFINE_MUTEX(powerpc_cpu_hotplug_driver_mutex);
  606. void cpu_hotplug_driver_lock()
  607. {
  608. mutex_lock(&powerpc_cpu_hotplug_driver_mutex);
  609. }
  610. void cpu_hotplug_driver_unlock()
  611. {
  612. mutex_unlock(&powerpc_cpu_hotplug_driver_mutex);
  613. }
  614. void cpu_die(void)
  615. {
  616. if (ppc_md.cpu_die)
  617. ppc_md.cpu_die();
  618. /* If we return, we re-enter start_secondary */
  619. start_secondary_resume();
  620. }
  621. #endif