smp.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809
  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/export.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/device.h>
  29. #include <linux/cpu.h>
  30. #include <linux/notifier.h>
  31. #include <linux/topology.h>
  32. #include <asm/ptrace.h>
  33. #include <linux/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/mpic.h>
  44. #include <asm/vdso_datapage.h>
  45. #ifdef CONFIG_PPC64
  46. #include <asm/paca.h>
  47. #endif
  48. #include <asm/vdso.h>
  49. #include <asm/debug.h>
  50. #ifdef DEBUG
  51. #include <asm/udbg.h>
  52. #define DBG(fmt...) udbg_printf(fmt)
  53. #else
  54. #define DBG(fmt...)
  55. #endif
  56. #ifdef CONFIG_HOTPLUG_CPU
  57. /* State of each CPU during hotplug phases */
  58. static DEFINE_PER_CPU(int, cpu_state) = { 0 };
  59. #endif
  60. struct thread_info *secondary_ti;
  61. DEFINE_PER_CPU(cpumask_var_t, cpu_sibling_map);
  62. DEFINE_PER_CPU(cpumask_var_t, cpu_core_map);
  63. EXPORT_PER_CPU_SYMBOL(cpu_sibling_map);
  64. EXPORT_PER_CPU_SYMBOL(cpu_core_map);
  65. /* SMP operations for this machine */
  66. struct smp_ops_t *smp_ops;
  67. /* Can't be static due to PowerMac hackery */
  68. volatile unsigned int cpu_callin_map[NR_CPUS];
  69. int smt_enabled_at_boot = 1;
  70. static void (*crash_ipi_function_ptr)(struct pt_regs *) = NULL;
  71. /*
  72. * Returns 1 if the specified cpu should be brought up during boot.
  73. * Used to inhibit booting threads if they've been disabled or
  74. * limited on the command line
  75. */
  76. int smp_generic_cpu_bootable(unsigned int nr)
  77. {
  78. /* Special case - we inhibit secondary thread startup
  79. * during boot if the user requests it.
  80. */
  81. if (system_state == SYSTEM_BOOTING && cpu_has_feature(CPU_FTR_SMT)) {
  82. if (!smt_enabled_at_boot && cpu_thread_in_core(nr) != 0)
  83. return 0;
  84. if (smt_enabled_at_boot
  85. && cpu_thread_in_core(nr) >= smt_enabled_at_boot)
  86. return 0;
  87. }
  88. return 1;
  89. }
  90. #ifdef CONFIG_PPC64
  91. int smp_generic_kick_cpu(int nr)
  92. {
  93. BUG_ON(nr < 0 || nr >= NR_CPUS);
  94. /*
  95. * The processor is currently spinning, waiting for the
  96. * cpu_start field to become non-zero After we set cpu_start,
  97. * the processor will continue on to secondary_start
  98. */
  99. if (!paca[nr].cpu_start) {
  100. paca[nr].cpu_start = 1;
  101. smp_mb();
  102. return 0;
  103. }
  104. #ifdef CONFIG_HOTPLUG_CPU
  105. /*
  106. * Ok it's not there, so it might be soft-unplugged, let's
  107. * try to bring it back
  108. */
  109. generic_set_cpu_up(nr);
  110. smp_wmb();
  111. smp_send_reschedule(nr);
  112. #endif /* CONFIG_HOTPLUG_CPU */
  113. return 0;
  114. }
  115. #endif /* CONFIG_PPC64 */
  116. static irqreturn_t call_function_action(int irq, void *data)
  117. {
  118. generic_smp_call_function_interrupt();
  119. return IRQ_HANDLED;
  120. }
  121. static irqreturn_t reschedule_action(int irq, void *data)
  122. {
  123. scheduler_ipi();
  124. return IRQ_HANDLED;
  125. }
  126. static irqreturn_t call_function_single_action(int irq, void *data)
  127. {
  128. generic_smp_call_function_single_interrupt();
  129. return IRQ_HANDLED;
  130. }
  131. static irqreturn_t debug_ipi_action(int irq, void *data)
  132. {
  133. if (crash_ipi_function_ptr) {
  134. crash_ipi_function_ptr(get_irq_regs());
  135. return IRQ_HANDLED;
  136. }
  137. #ifdef CONFIG_DEBUGGER
  138. debugger_ipi(get_irq_regs());
  139. #endif /* CONFIG_DEBUGGER */
  140. return IRQ_HANDLED;
  141. }
  142. static irq_handler_t smp_ipi_action[] = {
  143. [PPC_MSG_CALL_FUNCTION] = call_function_action,
  144. [PPC_MSG_RESCHEDULE] = reschedule_action,
  145. [PPC_MSG_CALL_FUNC_SINGLE] = call_function_single_action,
  146. [PPC_MSG_DEBUGGER_BREAK] = debug_ipi_action,
  147. };
  148. const char *smp_ipi_name[] = {
  149. [PPC_MSG_CALL_FUNCTION] = "ipi call function",
  150. [PPC_MSG_RESCHEDULE] = "ipi reschedule",
  151. [PPC_MSG_CALL_FUNC_SINGLE] = "ipi call function single",
  152. [PPC_MSG_DEBUGGER_BREAK] = "ipi debugger",
  153. };
  154. /* optional function to request ipi, for controllers with >= 4 ipis */
  155. int smp_request_message_ipi(int virq, int msg)
  156. {
  157. int err;
  158. if (msg < 0 || msg > PPC_MSG_DEBUGGER_BREAK) {
  159. return -EINVAL;
  160. }
  161. #if !defined(CONFIG_DEBUGGER) && !defined(CONFIG_KEXEC)
  162. if (msg == PPC_MSG_DEBUGGER_BREAK) {
  163. return 1;
  164. }
  165. #endif
  166. err = request_irq(virq, smp_ipi_action[msg],
  167. IRQF_PERCPU | IRQF_NO_THREAD | IRQF_NO_SUSPEND,
  168. smp_ipi_name[msg], NULL);
  169. WARN(err < 0, "unable to request_irq %d for %s (rc %d)\n",
  170. virq, smp_ipi_name[msg], err);
  171. return err;
  172. }
  173. #ifdef CONFIG_PPC_SMP_MUXED_IPI
  174. struct cpu_messages {
  175. int messages; /* current messages */
  176. unsigned long data; /* data for cause ipi */
  177. };
  178. static DEFINE_PER_CPU_SHARED_ALIGNED(struct cpu_messages, ipi_message);
  179. void smp_muxed_ipi_set_data(int cpu, unsigned long data)
  180. {
  181. struct cpu_messages *info = &per_cpu(ipi_message, cpu);
  182. info->data = data;
  183. }
  184. void smp_muxed_ipi_message_pass(int cpu, int msg)
  185. {
  186. struct cpu_messages *info = &per_cpu(ipi_message, cpu);
  187. char *message = (char *)&info->messages;
  188. /*
  189. * Order previous accesses before accesses in the IPI handler.
  190. */
  191. smp_mb();
  192. message[msg] = 1;
  193. /*
  194. * cause_ipi functions are required to include a full barrier
  195. * before doing whatever causes the IPI.
  196. */
  197. smp_ops->cause_ipi(cpu, info->data);
  198. }
  199. irqreturn_t smp_ipi_demux(void)
  200. {
  201. struct cpu_messages *info = &__get_cpu_var(ipi_message);
  202. unsigned int all;
  203. mb(); /* order any irq clear */
  204. do {
  205. all = xchg(&info->messages, 0);
  206. #ifdef __BIG_ENDIAN
  207. if (all & (1 << (24 - 8 * PPC_MSG_CALL_FUNCTION)))
  208. generic_smp_call_function_interrupt();
  209. if (all & (1 << (24 - 8 * PPC_MSG_RESCHEDULE)))
  210. scheduler_ipi();
  211. if (all & (1 << (24 - 8 * PPC_MSG_CALL_FUNC_SINGLE)))
  212. generic_smp_call_function_single_interrupt();
  213. if (all & (1 << (24 - 8 * PPC_MSG_DEBUGGER_BREAK)))
  214. debug_ipi_action(0, NULL);
  215. #else
  216. #error Unsupported ENDIAN
  217. #endif
  218. } while (info->messages);
  219. return IRQ_HANDLED;
  220. }
  221. #endif /* CONFIG_PPC_SMP_MUXED_IPI */
  222. static inline void do_message_pass(int cpu, int msg)
  223. {
  224. if (smp_ops->message_pass)
  225. smp_ops->message_pass(cpu, msg);
  226. #ifdef CONFIG_PPC_SMP_MUXED_IPI
  227. else
  228. smp_muxed_ipi_message_pass(cpu, msg);
  229. #endif
  230. }
  231. void smp_send_reschedule(int cpu)
  232. {
  233. if (likely(smp_ops))
  234. do_message_pass(cpu, PPC_MSG_RESCHEDULE);
  235. }
  236. EXPORT_SYMBOL_GPL(smp_send_reschedule);
  237. void arch_send_call_function_single_ipi(int cpu)
  238. {
  239. do_message_pass(cpu, PPC_MSG_CALL_FUNC_SINGLE);
  240. }
  241. void arch_send_call_function_ipi_mask(const struct cpumask *mask)
  242. {
  243. unsigned int cpu;
  244. for_each_cpu(cpu, mask)
  245. do_message_pass(cpu, PPC_MSG_CALL_FUNCTION);
  246. }
  247. #if defined(CONFIG_DEBUGGER) || defined(CONFIG_KEXEC)
  248. void smp_send_debugger_break(void)
  249. {
  250. int cpu;
  251. int me = raw_smp_processor_id();
  252. if (unlikely(!smp_ops))
  253. return;
  254. for_each_online_cpu(cpu)
  255. if (cpu != me)
  256. do_message_pass(cpu, PPC_MSG_DEBUGGER_BREAK);
  257. }
  258. #endif
  259. #ifdef CONFIG_KEXEC
  260. void crash_send_ipi(void (*crash_ipi_callback)(struct pt_regs *))
  261. {
  262. crash_ipi_function_ptr = crash_ipi_callback;
  263. if (crash_ipi_callback) {
  264. mb();
  265. smp_send_debugger_break();
  266. }
  267. }
  268. #endif
  269. static void stop_this_cpu(void *dummy)
  270. {
  271. /* Remove this CPU */
  272. set_cpu_online(smp_processor_id(), false);
  273. local_irq_disable();
  274. while (1)
  275. ;
  276. }
  277. void smp_send_stop(void)
  278. {
  279. smp_call_function(stop_this_cpu, NULL, 0);
  280. }
  281. struct thread_info *current_set[NR_CPUS];
  282. static void smp_store_cpu_info(int id)
  283. {
  284. per_cpu(cpu_pvr, id) = mfspr(SPRN_PVR);
  285. #ifdef CONFIG_PPC_FSL_BOOK3E
  286. per_cpu(next_tlbcam_idx, id)
  287. = (mfspr(SPRN_TLB1CFG) & TLBnCFG_N_ENTRY) - 1;
  288. #endif
  289. }
  290. void __init smp_prepare_cpus(unsigned int max_cpus)
  291. {
  292. unsigned int cpu;
  293. DBG("smp_prepare_cpus\n");
  294. /*
  295. * setup_cpu may need to be called on the boot cpu. We havent
  296. * spun any cpus up but lets be paranoid.
  297. */
  298. BUG_ON(boot_cpuid != smp_processor_id());
  299. /* Fixup boot cpu */
  300. smp_store_cpu_info(boot_cpuid);
  301. cpu_callin_map[boot_cpuid] = 1;
  302. for_each_possible_cpu(cpu) {
  303. zalloc_cpumask_var_node(&per_cpu(cpu_sibling_map, cpu),
  304. GFP_KERNEL, cpu_to_node(cpu));
  305. zalloc_cpumask_var_node(&per_cpu(cpu_core_map, cpu),
  306. GFP_KERNEL, cpu_to_node(cpu));
  307. }
  308. cpumask_set_cpu(boot_cpuid, cpu_sibling_mask(boot_cpuid));
  309. cpumask_set_cpu(boot_cpuid, cpu_core_mask(boot_cpuid));
  310. if (smp_ops)
  311. if (smp_ops->probe)
  312. max_cpus = smp_ops->probe();
  313. else
  314. max_cpus = NR_CPUS;
  315. else
  316. max_cpus = 1;
  317. }
  318. void smp_prepare_boot_cpu(void)
  319. {
  320. BUG_ON(smp_processor_id() != boot_cpuid);
  321. #ifdef CONFIG_PPC64
  322. paca[boot_cpuid].__current = current;
  323. #endif
  324. current_set[boot_cpuid] = task_thread_info(current);
  325. }
  326. #ifdef CONFIG_HOTPLUG_CPU
  327. int generic_cpu_disable(void)
  328. {
  329. unsigned int cpu = smp_processor_id();
  330. if (cpu == boot_cpuid)
  331. return -EBUSY;
  332. set_cpu_online(cpu, false);
  333. #ifdef CONFIG_PPC64
  334. vdso_data->processorCount--;
  335. #endif
  336. migrate_irqs();
  337. return 0;
  338. }
  339. void generic_cpu_die(unsigned int cpu)
  340. {
  341. int i;
  342. for (i = 0; i < 100; i++) {
  343. smp_rmb();
  344. if (per_cpu(cpu_state, cpu) == CPU_DEAD)
  345. return;
  346. msleep(100);
  347. }
  348. printk(KERN_ERR "CPU%d didn't die...\n", cpu);
  349. }
  350. void generic_mach_cpu_die(void)
  351. {
  352. unsigned int cpu;
  353. local_irq_disable();
  354. idle_task_exit();
  355. cpu = smp_processor_id();
  356. printk(KERN_DEBUG "CPU%d offline\n", cpu);
  357. __get_cpu_var(cpu_state) = CPU_DEAD;
  358. smp_wmb();
  359. while (__get_cpu_var(cpu_state) != CPU_UP_PREPARE)
  360. cpu_relax();
  361. }
  362. void generic_set_cpu_dead(unsigned int cpu)
  363. {
  364. per_cpu(cpu_state, cpu) = CPU_DEAD;
  365. }
  366. /*
  367. * The cpu_state should be set to CPU_UP_PREPARE in kick_cpu(), otherwise
  368. * the cpu_state is always CPU_DEAD after calling generic_set_cpu_dead(),
  369. * which makes the delay in generic_cpu_die() not happen.
  370. */
  371. void generic_set_cpu_up(unsigned int cpu)
  372. {
  373. per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
  374. }
  375. int generic_check_cpu_restart(unsigned int cpu)
  376. {
  377. return per_cpu(cpu_state, cpu) == CPU_UP_PREPARE;
  378. }
  379. static atomic_t secondary_inhibit_count;
  380. /*
  381. * Don't allow secondary CPU threads to come online
  382. */
  383. void inhibit_secondary_onlining(void)
  384. {
  385. /*
  386. * This makes secondary_inhibit_count stable during cpu
  387. * online/offline operations.
  388. */
  389. get_online_cpus();
  390. atomic_inc(&secondary_inhibit_count);
  391. put_online_cpus();
  392. }
  393. EXPORT_SYMBOL_GPL(inhibit_secondary_onlining);
  394. /*
  395. * Allow secondary CPU threads to come online again
  396. */
  397. void uninhibit_secondary_onlining(void)
  398. {
  399. get_online_cpus();
  400. atomic_dec(&secondary_inhibit_count);
  401. put_online_cpus();
  402. }
  403. EXPORT_SYMBOL_GPL(uninhibit_secondary_onlining);
  404. static int secondaries_inhibited(void)
  405. {
  406. return atomic_read(&secondary_inhibit_count);
  407. }
  408. #else /* HOTPLUG_CPU */
  409. #define secondaries_inhibited() 0
  410. #endif
  411. static void cpu_idle_thread_init(unsigned int cpu, struct task_struct *idle)
  412. {
  413. struct thread_info *ti = task_thread_info(idle);
  414. #ifdef CONFIG_PPC64
  415. paca[cpu].__current = idle;
  416. paca[cpu].kstack = (unsigned long)ti + THREAD_SIZE - STACK_FRAME_OVERHEAD;
  417. #endif
  418. ti->cpu = cpu;
  419. secondary_ti = current_set[cpu] = ti;
  420. }
  421. int __cpu_up(unsigned int cpu, struct task_struct *tidle)
  422. {
  423. int rc, c;
  424. /*
  425. * Don't allow secondary threads to come online if inhibited
  426. */
  427. if (threads_per_core > 1 && secondaries_inhibited() &&
  428. cpu % threads_per_core != 0)
  429. return -EBUSY;
  430. if (smp_ops == NULL ||
  431. (smp_ops->cpu_bootable && !smp_ops->cpu_bootable(cpu)))
  432. return -EINVAL;
  433. cpu_idle_thread_init(cpu, tidle);
  434. /* Make sure callin-map entry is 0 (can be leftover a CPU
  435. * hotplug
  436. */
  437. cpu_callin_map[cpu] = 0;
  438. /* The information for processor bringup must
  439. * be written out to main store before we release
  440. * the processor.
  441. */
  442. smp_mb();
  443. /* wake up cpus */
  444. DBG("smp: kicking cpu %d\n", cpu);
  445. rc = smp_ops->kick_cpu(cpu);
  446. if (rc) {
  447. pr_err("smp: failed starting cpu %d (rc %d)\n", cpu, rc);
  448. return rc;
  449. }
  450. /*
  451. * wait to see if the cpu made a callin (is actually up).
  452. * use this value that I found through experimentation.
  453. * -- Cort
  454. */
  455. if (system_state < SYSTEM_RUNNING)
  456. for (c = 50000; c && !cpu_callin_map[cpu]; c--)
  457. udelay(100);
  458. #ifdef CONFIG_HOTPLUG_CPU
  459. else
  460. /*
  461. * CPUs can take much longer to come up in the
  462. * hotplug case. Wait five seconds.
  463. */
  464. for (c = 5000; c && !cpu_callin_map[cpu]; c--)
  465. msleep(1);
  466. #endif
  467. if (!cpu_callin_map[cpu]) {
  468. printk(KERN_ERR "Processor %u is stuck.\n", cpu);
  469. return -ENOENT;
  470. }
  471. DBG("Processor %u found.\n", cpu);
  472. if (smp_ops->give_timebase)
  473. smp_ops->give_timebase();
  474. /* Wait until cpu puts itself in the online map */
  475. while (!cpu_online(cpu))
  476. cpu_relax();
  477. return 0;
  478. }
  479. /* Return the value of the reg property corresponding to the given
  480. * logical cpu.
  481. */
  482. int cpu_to_core_id(int cpu)
  483. {
  484. struct device_node *np;
  485. const int *reg;
  486. int id = -1;
  487. np = of_get_cpu_node(cpu, NULL);
  488. if (!np)
  489. goto out;
  490. reg = of_get_property(np, "reg", NULL);
  491. if (!reg)
  492. goto out;
  493. id = *reg;
  494. out:
  495. of_node_put(np);
  496. return id;
  497. }
  498. /* Helper routines for cpu to core mapping */
  499. int cpu_core_index_of_thread(int cpu)
  500. {
  501. return cpu >> threads_shift;
  502. }
  503. EXPORT_SYMBOL_GPL(cpu_core_index_of_thread);
  504. int cpu_first_thread_of_core(int core)
  505. {
  506. return core << threads_shift;
  507. }
  508. EXPORT_SYMBOL_GPL(cpu_first_thread_of_core);
  509. /* Must be called when no change can occur to cpu_present_mask,
  510. * i.e. during cpu online or offline.
  511. */
  512. static struct device_node *cpu_to_l2cache(int cpu)
  513. {
  514. struct device_node *np;
  515. struct device_node *cache;
  516. if (!cpu_present(cpu))
  517. return NULL;
  518. np = of_get_cpu_node(cpu, NULL);
  519. if (np == NULL)
  520. return NULL;
  521. cache = of_find_next_cache_node(np);
  522. of_node_put(np);
  523. return cache;
  524. }
  525. static void traverse_core_siblings(int cpu, bool add)
  526. {
  527. struct device_node *l2_cache;
  528. const struct cpumask *mask;
  529. int i;
  530. l2_cache = cpu_to_l2cache(cpu);
  531. mask = add ? cpu_online_mask : cpu_present_mask;
  532. for_each_cpu(i, mask) {
  533. struct device_node *np = cpu_to_l2cache(i);
  534. if (!np)
  535. continue;
  536. if (np == l2_cache) {
  537. if (add) {
  538. cpumask_set_cpu(cpu, cpu_core_mask(i));
  539. cpumask_set_cpu(i, cpu_core_mask(cpu));
  540. } else {
  541. cpumask_clear_cpu(cpu, cpu_core_mask(i));
  542. cpumask_clear_cpu(i, cpu_core_mask(cpu));
  543. }
  544. }
  545. of_node_put(np);
  546. }
  547. of_node_put(l2_cache);
  548. }
  549. /* Activate a secondary processor. */
  550. void start_secondary(void *unused)
  551. {
  552. unsigned int cpu = smp_processor_id();
  553. int i, base;
  554. atomic_inc(&init_mm.mm_count);
  555. current->active_mm = &init_mm;
  556. smp_store_cpu_info(cpu);
  557. set_dec(tb_ticks_per_jiffy);
  558. preempt_disable();
  559. cpu_callin_map[cpu] = 1;
  560. if (smp_ops->setup_cpu)
  561. smp_ops->setup_cpu(cpu);
  562. if (smp_ops->take_timebase)
  563. smp_ops->take_timebase();
  564. secondary_cpu_time_init();
  565. #ifdef CONFIG_PPC64
  566. if (system_state == SYSTEM_RUNNING)
  567. vdso_data->processorCount++;
  568. vdso_getcpu_init();
  569. #endif
  570. /* Update sibling maps */
  571. base = cpu_first_thread_sibling(cpu);
  572. for (i = 0; i < threads_per_core; i++) {
  573. if (cpu_is_offline(base + i) && (cpu != base + i))
  574. continue;
  575. cpumask_set_cpu(cpu, cpu_sibling_mask(base + i));
  576. cpumask_set_cpu(base + i, cpu_sibling_mask(cpu));
  577. /* cpu_core_map should be a superset of
  578. * cpu_sibling_map even if we don't have cache
  579. * information, so update the former here, too.
  580. */
  581. cpumask_set_cpu(cpu, cpu_core_mask(base + i));
  582. cpumask_set_cpu(base + i, cpu_core_mask(cpu));
  583. }
  584. traverse_core_siblings(cpu, true);
  585. smp_wmb();
  586. notify_cpu_starting(cpu);
  587. set_cpu_online(cpu, true);
  588. local_irq_enable();
  589. cpu_startup_entry(CPUHP_ONLINE);
  590. BUG();
  591. }
  592. int setup_profiling_timer(unsigned int multiplier)
  593. {
  594. return 0;
  595. }
  596. void __init smp_cpus_done(unsigned int max_cpus)
  597. {
  598. cpumask_var_t old_mask;
  599. /* We want the setup_cpu() here to be called from CPU 0, but our
  600. * init thread may have been "borrowed" by another CPU in the meantime
  601. * se we pin us down to CPU 0 for a short while
  602. */
  603. alloc_cpumask_var(&old_mask, GFP_NOWAIT);
  604. cpumask_copy(old_mask, tsk_cpus_allowed(current));
  605. set_cpus_allowed_ptr(current, cpumask_of(boot_cpuid));
  606. if (smp_ops && smp_ops->setup_cpu)
  607. smp_ops->setup_cpu(boot_cpuid);
  608. set_cpus_allowed_ptr(current, old_mask);
  609. free_cpumask_var(old_mask);
  610. if (smp_ops && smp_ops->bringup_done)
  611. smp_ops->bringup_done();
  612. dump_numa_cpu_topology();
  613. }
  614. int arch_sd_sibling_asym_packing(void)
  615. {
  616. if (cpu_has_feature(CPU_FTR_ASYM_SMT)) {
  617. printk_once(KERN_INFO "Enabling Asymmetric SMT scheduling\n");
  618. return SD_ASYM_PACKING;
  619. }
  620. return 0;
  621. }
  622. #ifdef CONFIG_HOTPLUG_CPU
  623. int __cpu_disable(void)
  624. {
  625. int cpu = smp_processor_id();
  626. int base, i;
  627. int err;
  628. if (!smp_ops->cpu_disable)
  629. return -ENOSYS;
  630. err = smp_ops->cpu_disable();
  631. if (err)
  632. return err;
  633. /* Update sibling maps */
  634. base = cpu_first_thread_sibling(cpu);
  635. for (i = 0; i < threads_per_core; i++) {
  636. cpumask_clear_cpu(cpu, cpu_sibling_mask(base + i));
  637. cpumask_clear_cpu(base + i, cpu_sibling_mask(cpu));
  638. cpumask_clear_cpu(cpu, cpu_core_mask(base + i));
  639. cpumask_clear_cpu(base + i, cpu_core_mask(cpu));
  640. }
  641. traverse_core_siblings(cpu, false);
  642. return 0;
  643. }
  644. void __cpu_die(unsigned int cpu)
  645. {
  646. if (smp_ops->cpu_die)
  647. smp_ops->cpu_die(cpu);
  648. }
  649. static DEFINE_MUTEX(powerpc_cpu_hotplug_driver_mutex);
  650. void cpu_hotplug_driver_lock()
  651. {
  652. mutex_lock(&powerpc_cpu_hotplug_driver_mutex);
  653. }
  654. void cpu_hotplug_driver_unlock()
  655. {
  656. mutex_unlock(&powerpc_cpu_hotplug_driver_mutex);
  657. }
  658. void cpu_die(void)
  659. {
  660. if (ppc_md.cpu_die)
  661. ppc_md.cpu_die();
  662. /* If we return, we re-enter start_secondary */
  663. start_secondary_resume();
  664. }
  665. #endif