4 * Written by Cort Dougan (cort@cs.nmt.edu) borrowing a great
5 * deal of code from the sparc and intel versions.
7 * Copyright (C) 1999 Cort Dougan <cort@cs.nmt.edu>
9 * PowerPC-64 Support added by Dave Engebretsen, Peter Bergner, and
10 * Mike Corrigan {engebret|bergner|mikec}@us.ibm.com
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.
20 #include <linux/kernel.h>
21 #include <linux/export.h>
22 #include <linux/sched/mm.h>
23 #include <linux/sched/topology.h>
24 #include <linux/smp.h>
25 #include <linux/interrupt.h>
26 #include <linux/delay.h>
27 #include <linux/init.h>
28 #include <linux/spinlock.h>
29 #include <linux/cache.h>
30 #include <linux/err.h>
31 #include <linux/device.h>
32 #include <linux/cpu.h>
33 #include <linux/notifier.h>
34 #include <linux/topology.h>
35 #include <linux/profile.h>
36 #include <linux/processor.h>
38 #include <asm/ptrace.h>
39 #include <linux/atomic.h>
41 #include <asm/hw_irq.h>
42 #include <asm/kvm_ppc.h>
43 #include <asm/dbell.h>
45 #include <asm/pgtable.h>
49 #include <asm/machdep.h>
50 #include <asm/cputhreads.h>
51 #include <asm/cputable.h>
53 #include <asm/vdso_datapage.h>
58 #include <asm/debug.h>
59 #include <asm/kexec.h>
60 #include <asm/asm-prototypes.h>
61 #include <asm/cpu_has_feature.h>
65 #define DBG(fmt...) udbg_printf(fmt)
70 #ifdef CONFIG_HOTPLUG_CPU
71 /* State of each CPU during hotplug phases */
72 static DEFINE_PER_CPU(int, cpu_state) = { 0 };
75 struct thread_info *secondary_ti;
77 DEFINE_PER_CPU(cpumask_var_t, cpu_sibling_map);
78 DEFINE_PER_CPU(cpumask_var_t, cpu_core_map);
80 EXPORT_PER_CPU_SYMBOL(cpu_sibling_map);
81 EXPORT_PER_CPU_SYMBOL(cpu_core_map);
83 /* SMP operations for this machine */
84 struct smp_ops_t *smp_ops;
86 /* Can't be static due to PowerMac hackery */
87 volatile unsigned int cpu_callin_map[NR_CPUS];
89 int smt_enabled_at_boot = 1;
92 * Returns 1 if the specified cpu should be brought up during boot.
93 * Used to inhibit booting threads if they've been disabled or
94 * limited on the command line
96 int smp_generic_cpu_bootable(unsigned int nr)
98 /* Special case - we inhibit secondary thread startup
99 * during boot if the user requests it.
101 if (system_state < SYSTEM_RUNNING && cpu_has_feature(CPU_FTR_SMT)) {
102 if (!smt_enabled_at_boot && cpu_thread_in_core(nr) != 0)
104 if (smt_enabled_at_boot
105 && cpu_thread_in_core(nr) >= smt_enabled_at_boot)
114 int smp_generic_kick_cpu(int nr)
116 if (nr < 0 || nr >= nr_cpu_ids)
120 * The processor is currently spinning, waiting for the
121 * cpu_start field to become non-zero After we set cpu_start,
122 * the processor will continue on to secondary_start
124 if (!paca[nr].cpu_start) {
125 paca[nr].cpu_start = 1;
130 #ifdef CONFIG_HOTPLUG_CPU
132 * Ok it's not there, so it might be soft-unplugged, let's
133 * try to bring it back
135 generic_set_cpu_up(nr);
137 smp_send_reschedule(nr);
138 #endif /* CONFIG_HOTPLUG_CPU */
142 #endif /* CONFIG_PPC64 */
144 static irqreturn_t call_function_action(int irq, void *data)
146 generic_smp_call_function_interrupt();
150 static irqreturn_t reschedule_action(int irq, void *data)
156 static irqreturn_t tick_broadcast_ipi_action(int irq, void *data)
158 tick_broadcast_ipi_handler();
162 #ifdef CONFIG_NMI_IPI
163 static irqreturn_t nmi_ipi_action(int irq, void *data)
165 smp_handle_nmi_ipi(get_irq_regs());
170 static irq_handler_t smp_ipi_action[] = {
171 [PPC_MSG_CALL_FUNCTION] = call_function_action,
172 [PPC_MSG_RESCHEDULE] = reschedule_action,
173 [PPC_MSG_TICK_BROADCAST] = tick_broadcast_ipi_action,
174 #ifdef CONFIG_NMI_IPI
175 [PPC_MSG_NMI_IPI] = nmi_ipi_action,
180 * The NMI IPI is a fallback and not truly non-maskable. It is simpler
181 * than going through the call function infrastructure, and strongly
182 * serialized, so it is more appropriate for debugging.
184 const char *smp_ipi_name[] = {
185 [PPC_MSG_CALL_FUNCTION] = "ipi call function",
186 [PPC_MSG_RESCHEDULE] = "ipi reschedule",
187 [PPC_MSG_TICK_BROADCAST] = "ipi tick-broadcast",
188 [PPC_MSG_NMI_IPI] = "nmi ipi",
191 /* optional function to request ipi, for controllers with >= 4 ipis */
192 int smp_request_message_ipi(int virq, int msg)
196 if (msg < 0 || msg > PPC_MSG_NMI_IPI)
198 #ifndef CONFIG_NMI_IPI
199 if (msg == PPC_MSG_NMI_IPI)
203 err = request_irq(virq, smp_ipi_action[msg],
204 IRQF_PERCPU | IRQF_NO_THREAD | IRQF_NO_SUSPEND,
205 smp_ipi_name[msg], NULL);
206 WARN(err < 0, "unable to request_irq %d for %s (rc %d)\n",
207 virq, smp_ipi_name[msg], err);
212 #ifdef CONFIG_PPC_SMP_MUXED_IPI
213 struct cpu_messages {
214 long messages; /* current messages */
216 static DEFINE_PER_CPU_SHARED_ALIGNED(struct cpu_messages, ipi_message);
218 void smp_muxed_ipi_set_message(int cpu, int msg)
220 struct cpu_messages *info = &per_cpu(ipi_message, cpu);
221 char *message = (char *)&info->messages;
224 * Order previous accesses before accesses in the IPI handler.
230 void smp_muxed_ipi_message_pass(int cpu, int msg)
232 smp_muxed_ipi_set_message(cpu, msg);
235 * cause_ipi functions are required to include a full barrier
236 * before doing whatever causes the IPI.
238 smp_ops->cause_ipi(cpu);
241 #ifdef __BIG_ENDIAN__
242 #define IPI_MESSAGE(A) (1uL << ((BITS_PER_LONG - 8) - 8 * (A)))
244 #define IPI_MESSAGE(A) (1uL << (8 * (A)))
247 irqreturn_t smp_ipi_demux(void)
249 mb(); /* order any irq clear */
251 return smp_ipi_demux_relaxed();
254 /* sync-free variant. Callers should ensure synchronization */
255 irqreturn_t smp_ipi_demux_relaxed(void)
257 struct cpu_messages *info;
260 info = this_cpu_ptr(&ipi_message);
262 all = xchg(&info->messages, 0);
263 #if defined(CONFIG_KVM_XICS) && defined(CONFIG_KVM_BOOK3S_HV_POSSIBLE)
265 * Must check for PPC_MSG_RM_HOST_ACTION messages
266 * before PPC_MSG_CALL_FUNCTION messages because when
267 * a VM is destroyed, we call kick_all_cpus_sync()
268 * to ensure that any pending PPC_MSG_RM_HOST_ACTION
269 * messages have completed before we free any VCPUs.
271 if (all & IPI_MESSAGE(PPC_MSG_RM_HOST_ACTION))
272 kvmppc_xics_ipi_action();
274 if (all & IPI_MESSAGE(PPC_MSG_CALL_FUNCTION))
275 generic_smp_call_function_interrupt();
276 if (all & IPI_MESSAGE(PPC_MSG_RESCHEDULE))
278 if (all & IPI_MESSAGE(PPC_MSG_TICK_BROADCAST))
279 tick_broadcast_ipi_handler();
280 #ifdef CONFIG_NMI_IPI
281 if (all & IPI_MESSAGE(PPC_MSG_NMI_IPI))
282 nmi_ipi_action(0, NULL);
284 } while (info->messages);
288 #endif /* CONFIG_PPC_SMP_MUXED_IPI */
290 static inline void do_message_pass(int cpu, int msg)
292 if (smp_ops->message_pass)
293 smp_ops->message_pass(cpu, msg);
294 #ifdef CONFIG_PPC_SMP_MUXED_IPI
296 smp_muxed_ipi_message_pass(cpu, msg);
300 void smp_send_reschedule(int cpu)
303 do_message_pass(cpu, PPC_MSG_RESCHEDULE);
305 EXPORT_SYMBOL_GPL(smp_send_reschedule);
307 void arch_send_call_function_single_ipi(int cpu)
309 do_message_pass(cpu, PPC_MSG_CALL_FUNCTION);
312 void arch_send_call_function_ipi_mask(const struct cpumask *mask)
316 for_each_cpu(cpu, mask)
317 do_message_pass(cpu, PPC_MSG_CALL_FUNCTION);
320 #ifdef CONFIG_NMI_IPI
325 * NMI IPIs may not be recoverable, so should not be used as ongoing part of
326 * a running system. They can be used for crash, debug, halt/reboot, etc.
328 * NMI IPIs are globally single threaded. No more than one in progress at
331 * The IPI call waits with interrupts disabled until all targets enter the
332 * NMI handler, then the call returns.
334 * No new NMI can be initiated until targets exit the handler.
336 * The IPI call may time out without all targets entering the NMI handler.
337 * In that case, there is some logic to recover (and ignore subsequent
338 * NMI interrupts that may eventually be raised), but the platform interrupt
339 * handler may not be able to distinguish this from other exception causes,
340 * which may cause a crash.
343 static atomic_t __nmi_ipi_lock = ATOMIC_INIT(0);
344 static struct cpumask nmi_ipi_pending_mask;
345 static int nmi_ipi_busy_count = 0;
346 static void (*nmi_ipi_function)(struct pt_regs *) = NULL;
348 static void nmi_ipi_lock_start(unsigned long *flags)
350 raw_local_irq_save(*flags);
352 while (atomic_cmpxchg(&__nmi_ipi_lock, 0, 1) == 1) {
353 raw_local_irq_restore(*flags);
355 raw_local_irq_save(*flags);
360 static void nmi_ipi_lock(void)
362 while (atomic_cmpxchg(&__nmi_ipi_lock, 0, 1) == 1)
366 static void nmi_ipi_unlock(void)
369 WARN_ON(atomic_read(&__nmi_ipi_lock) != 1);
370 atomic_set(&__nmi_ipi_lock, 0);
373 static void nmi_ipi_unlock_end(unsigned long *flags)
376 raw_local_irq_restore(*flags);
380 * Platform NMI handler calls this to ack
382 int smp_handle_nmi_ipi(struct pt_regs *regs)
384 void (*fn)(struct pt_regs *);
386 int me = raw_smp_processor_id();
390 * Unexpected NMIs are possible here because the interrupt may not
391 * be able to distinguish NMI IPIs from other types of NMIs, or
392 * because the caller may have timed out.
394 nmi_ipi_lock_start(&flags);
395 if (!nmi_ipi_busy_count)
397 if (!cpumask_test_cpu(me, &nmi_ipi_pending_mask))
400 fn = nmi_ipi_function;
404 cpumask_clear_cpu(me, &nmi_ipi_pending_mask);
405 nmi_ipi_busy_count++;
413 nmi_ipi_busy_count--;
415 nmi_ipi_unlock_end(&flags);
420 static void do_smp_send_nmi_ipi(int cpu)
422 if (smp_ops->cause_nmi_ipi && smp_ops->cause_nmi_ipi(cpu))
426 do_message_pass(cpu, PPC_MSG_NMI_IPI);
430 for_each_online_cpu(c) {
431 if (c == raw_smp_processor_id())
433 do_message_pass(c, PPC_MSG_NMI_IPI);
438 void smp_flush_nmi_ipi(u64 delay_us)
442 nmi_ipi_lock_start(&flags);
443 while (nmi_ipi_busy_count) {
444 nmi_ipi_unlock_end(&flags);
451 nmi_ipi_lock_start(&flags);
453 nmi_ipi_unlock_end(&flags);
457 * - cpu is the target CPU (must not be this CPU), or NMI_IPI_ALL_OTHERS.
458 * - fn is the target callback function.
459 * - delay_us > 0 is the delay before giving up waiting for targets to
460 * enter the handler, == 0 specifies indefinite delay.
462 int smp_send_nmi_ipi(int cpu, void (*fn)(struct pt_regs *), u64 delay_us)
465 int me = raw_smp_processor_id();
469 BUG_ON(cpu < 0 && cpu != NMI_IPI_ALL_OTHERS);
471 if (unlikely(!smp_ops))
474 /* Take the nmi_ipi_busy count/lock with interrupts hard disabled */
475 nmi_ipi_lock_start(&flags);
476 while (nmi_ipi_busy_count) {
477 nmi_ipi_unlock_end(&flags);
479 nmi_ipi_lock_start(&flags);
482 nmi_ipi_function = fn;
486 cpumask_copy(&nmi_ipi_pending_mask, cpu_online_mask);
487 cpumask_clear_cpu(me, &nmi_ipi_pending_mask);
489 /* cpumask starts clear */
490 cpumask_set_cpu(cpu, &nmi_ipi_pending_mask);
492 nmi_ipi_busy_count++;
495 do_smp_send_nmi_ipi(cpu);
497 while (!cpumask_empty(&nmi_ipi_pending_mask)) {
507 if (!cpumask_empty(&nmi_ipi_pending_mask)) {
508 /* Could not gather all CPUs */
510 cpumask_clear(&nmi_ipi_pending_mask);
512 nmi_ipi_busy_count--;
513 nmi_ipi_unlock_end(&flags);
517 #endif /* CONFIG_NMI_IPI */
519 #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
520 void tick_broadcast(const struct cpumask *mask)
524 for_each_cpu(cpu, mask)
525 do_message_pass(cpu, PPC_MSG_TICK_BROADCAST);
529 #ifdef CONFIG_DEBUGGER
530 void debugger_ipi_callback(struct pt_regs *regs)
535 void smp_send_debugger_break(void)
537 smp_send_nmi_ipi(NMI_IPI_ALL_OTHERS, debugger_ipi_callback, 1000000);
541 #ifdef CONFIG_KEXEC_CORE
542 void crash_send_ipi(void (*crash_ipi_callback)(struct pt_regs *))
544 smp_send_nmi_ipi(NMI_IPI_ALL_OTHERS, crash_ipi_callback, 1000000);
548 static void stop_this_cpu(void *dummy)
550 /* Remove this CPU */
551 set_cpu_online(smp_processor_id(), false);
558 void smp_send_stop(void)
560 smp_call_function(stop_this_cpu, NULL, 0);
563 struct thread_info *current_set[NR_CPUS];
565 static void smp_store_cpu_info(int id)
567 per_cpu(cpu_pvr, id) = mfspr(SPRN_PVR);
568 #ifdef CONFIG_PPC_FSL_BOOK3E
569 per_cpu(next_tlbcam_idx, id)
570 = (mfspr(SPRN_TLB1CFG) & TLBnCFG_N_ENTRY) - 1;
574 void __init smp_prepare_cpus(unsigned int max_cpus)
578 DBG("smp_prepare_cpus\n");
581 * setup_cpu may need to be called on the boot cpu. We havent
582 * spun any cpus up but lets be paranoid.
584 BUG_ON(boot_cpuid != smp_processor_id());
587 smp_store_cpu_info(boot_cpuid);
588 cpu_callin_map[boot_cpuid] = 1;
590 for_each_possible_cpu(cpu) {
591 zalloc_cpumask_var_node(&per_cpu(cpu_sibling_map, cpu),
592 GFP_KERNEL, cpu_to_node(cpu));
593 zalloc_cpumask_var_node(&per_cpu(cpu_core_map, cpu),
594 GFP_KERNEL, cpu_to_node(cpu));
596 * numa_node_id() works after this.
598 if (cpu_present(cpu)) {
599 set_cpu_numa_node(cpu, numa_cpu_lookup_table[cpu]);
600 set_cpu_numa_mem(cpu,
601 local_memory_node(numa_cpu_lookup_table[cpu]));
605 cpumask_set_cpu(boot_cpuid, cpu_sibling_mask(boot_cpuid));
606 cpumask_set_cpu(boot_cpuid, cpu_core_mask(boot_cpuid));
608 if (smp_ops && smp_ops->probe)
612 void smp_prepare_boot_cpu(void)
614 BUG_ON(smp_processor_id() != boot_cpuid);
616 paca[boot_cpuid].__current = current;
618 set_numa_node(numa_cpu_lookup_table[boot_cpuid]);
619 current_set[boot_cpuid] = task_thread_info(current);
622 #ifdef CONFIG_HOTPLUG_CPU
624 int generic_cpu_disable(void)
626 unsigned int cpu = smp_processor_id();
628 if (cpu == boot_cpuid)
631 set_cpu_online(cpu, false);
633 vdso_data->processorCount--;
635 /* Update affinity of all IRQs previously aimed at this CPU */
636 irq_migrate_all_off_this_cpu();
639 * Depending on the details of the interrupt controller, it's possible
640 * that one of the interrupts we just migrated away from this CPU is
641 * actually already pending on this CPU. If we leave it in that state
642 * the interrupt will never be EOI'ed, and will never fire again. So
643 * temporarily enable interrupts here, to allow any pending interrupt to
644 * be received (and EOI'ed), before we take this CPU offline.
653 void generic_cpu_die(unsigned int cpu)
657 for (i = 0; i < 100; i++) {
659 if (is_cpu_dead(cpu))
663 printk(KERN_ERR "CPU%d didn't die...\n", cpu);
666 void generic_set_cpu_dead(unsigned int cpu)
668 per_cpu(cpu_state, cpu) = CPU_DEAD;
672 * The cpu_state should be set to CPU_UP_PREPARE in kick_cpu(), otherwise
673 * the cpu_state is always CPU_DEAD after calling generic_set_cpu_dead(),
674 * which makes the delay in generic_cpu_die() not happen.
676 void generic_set_cpu_up(unsigned int cpu)
678 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
681 int generic_check_cpu_restart(unsigned int cpu)
683 return per_cpu(cpu_state, cpu) == CPU_UP_PREPARE;
686 int is_cpu_dead(unsigned int cpu)
688 return per_cpu(cpu_state, cpu) == CPU_DEAD;
691 static bool secondaries_inhibited(void)
693 return kvm_hv_mode_active();
696 #else /* HOTPLUG_CPU */
698 #define secondaries_inhibited() 0
702 static void cpu_idle_thread_init(unsigned int cpu, struct task_struct *idle)
704 struct thread_info *ti = task_thread_info(idle);
707 paca[cpu].__current = idle;
708 paca[cpu].kstack = (unsigned long)ti + THREAD_SIZE - STACK_FRAME_OVERHEAD;
711 secondary_ti = current_set[cpu] = ti;
714 int __cpu_up(unsigned int cpu, struct task_struct *tidle)
719 * Don't allow secondary threads to come online if inhibited
721 if (threads_per_core > 1 && secondaries_inhibited() &&
722 cpu_thread_in_subcore(cpu))
725 if (smp_ops == NULL ||
726 (smp_ops->cpu_bootable && !smp_ops->cpu_bootable(cpu)))
729 cpu_idle_thread_init(cpu, tidle);
732 * The platform might need to allocate resources prior to bringing
735 if (smp_ops->prepare_cpu) {
736 rc = smp_ops->prepare_cpu(cpu);
741 /* Make sure callin-map entry is 0 (can be leftover a CPU
744 cpu_callin_map[cpu] = 0;
746 /* The information for processor bringup must
747 * be written out to main store before we release
753 DBG("smp: kicking cpu %d\n", cpu);
754 rc = smp_ops->kick_cpu(cpu);
756 pr_err("smp: failed starting cpu %d (rc %d)\n", cpu, rc);
761 * wait to see if the cpu made a callin (is actually up).
762 * use this value that I found through experimentation.
765 if (system_state < SYSTEM_RUNNING)
766 for (c = 50000; c && !cpu_callin_map[cpu]; c--)
768 #ifdef CONFIG_HOTPLUG_CPU
771 * CPUs can take much longer to come up in the
772 * hotplug case. Wait five seconds.
774 for (c = 5000; c && !cpu_callin_map[cpu]; c--)
778 if (!cpu_callin_map[cpu]) {
779 printk(KERN_ERR "Processor %u is stuck.\n", cpu);
783 DBG("Processor %u found.\n", cpu);
785 if (smp_ops->give_timebase)
786 smp_ops->give_timebase();
788 /* Wait until cpu puts itself in the online & active maps */
789 spin_until_cond(cpu_online(cpu));
794 /* Return the value of the reg property corresponding to the given
797 int cpu_to_core_id(int cpu)
799 struct device_node *np;
803 np = of_get_cpu_node(cpu, NULL);
807 reg = of_get_property(np, "reg", NULL);
811 id = be32_to_cpup(reg);
816 EXPORT_SYMBOL_GPL(cpu_to_core_id);
818 /* Helper routines for cpu to core mapping */
819 int cpu_core_index_of_thread(int cpu)
821 return cpu >> threads_shift;
823 EXPORT_SYMBOL_GPL(cpu_core_index_of_thread);
825 int cpu_first_thread_of_core(int core)
827 return core << threads_shift;
829 EXPORT_SYMBOL_GPL(cpu_first_thread_of_core);
831 static void traverse_siblings_chip_id(int cpu, bool add, int chipid)
833 const struct cpumask *mask;
834 struct device_node *np;
838 mask = add ? cpu_online_mask : cpu_present_mask;
839 for_each_cpu(i, mask) {
840 np = of_get_cpu_node(i, NULL);
843 prop = of_get_property(np, "ibm,chip-id", &plen);
844 if (prop && plen == sizeof(int) &&
845 of_read_number(prop, 1) == chipid) {
847 cpumask_set_cpu(cpu, cpu_core_mask(i));
848 cpumask_set_cpu(i, cpu_core_mask(cpu));
850 cpumask_clear_cpu(cpu, cpu_core_mask(i));
851 cpumask_clear_cpu(i, cpu_core_mask(cpu));
858 /* Must be called when no change can occur to cpu_present_mask,
859 * i.e. during cpu online or offline.
861 static struct device_node *cpu_to_l2cache(int cpu)
863 struct device_node *np;
864 struct device_node *cache;
866 if (!cpu_present(cpu))
869 np = of_get_cpu_node(cpu, NULL);
873 cache = of_find_next_cache_node(np);
880 static void traverse_core_siblings(int cpu, bool add)
882 struct device_node *l2_cache, *np;
883 const struct cpumask *mask;
887 /* First see if we have ibm,chip-id properties in cpu nodes */
888 np = of_get_cpu_node(cpu, NULL);
891 prop = of_get_property(np, "ibm,chip-id", &plen);
892 if (prop && plen == sizeof(int))
893 chip = of_read_number(prop, 1);
896 traverse_siblings_chip_id(cpu, add, chip);
901 l2_cache = cpu_to_l2cache(cpu);
902 mask = add ? cpu_online_mask : cpu_present_mask;
903 for_each_cpu(i, mask) {
904 np = cpu_to_l2cache(i);
907 if (np == l2_cache) {
909 cpumask_set_cpu(cpu, cpu_core_mask(i));
910 cpumask_set_cpu(i, cpu_core_mask(cpu));
912 cpumask_clear_cpu(cpu, cpu_core_mask(i));
913 cpumask_clear_cpu(i, cpu_core_mask(cpu));
918 of_node_put(l2_cache);
921 /* Activate a secondary processor. */
922 void start_secondary(void *unused)
924 unsigned int cpu = smp_processor_id();
928 current->active_mm = &init_mm;
930 smp_store_cpu_info(cpu);
931 set_dec(tb_ticks_per_jiffy);
933 cpu_callin_map[cpu] = 1;
935 if (smp_ops->setup_cpu)
936 smp_ops->setup_cpu(cpu);
937 if (smp_ops->take_timebase)
938 smp_ops->take_timebase();
940 secondary_cpu_time_init();
943 if (system_state == SYSTEM_RUNNING)
944 vdso_data->processorCount++;
948 /* Update sibling maps */
949 base = cpu_first_thread_sibling(cpu);
950 for (i = 0; i < threads_per_core; i++) {
951 if (cpu_is_offline(base + i) && (cpu != base + i))
953 cpumask_set_cpu(cpu, cpu_sibling_mask(base + i));
954 cpumask_set_cpu(base + i, cpu_sibling_mask(cpu));
956 /* cpu_core_map should be a superset of
957 * cpu_sibling_map even if we don't have cache
958 * information, so update the former here, too.
960 cpumask_set_cpu(cpu, cpu_core_mask(base + i));
961 cpumask_set_cpu(base + i, cpu_core_mask(cpu));
963 traverse_core_siblings(cpu, true);
965 set_numa_node(numa_cpu_lookup_table[cpu]);
966 set_numa_mem(local_memory_node(numa_cpu_lookup_table[cpu]));
969 notify_cpu_starting(cpu);
970 set_cpu_online(cpu, true);
974 cpu_startup_entry(CPUHP_AP_ONLINE_IDLE);
979 int setup_profiling_timer(unsigned int multiplier)
984 #ifdef CONFIG_SCHED_SMT
985 /* cpumask of CPUs with asymetric SMT dependancy */
986 static int powerpc_smt_flags(void)
988 int flags = SD_SHARE_CPUCAPACITY | SD_SHARE_PKG_RESOURCES;
990 if (cpu_has_feature(CPU_FTR_ASYM_SMT)) {
991 printk_once(KERN_INFO "Enabling Asymmetric SMT scheduling\n");
992 flags |= SD_ASYM_PACKING;
998 static struct sched_domain_topology_level powerpc_topology[] = {
999 #ifdef CONFIG_SCHED_SMT
1000 { cpu_smt_mask, powerpc_smt_flags, SD_INIT_NAME(SMT) },
1002 { cpu_cpu_mask, SD_INIT_NAME(DIE) },
1006 void __init smp_cpus_done(unsigned int max_cpus)
1009 * We are running pinned to the boot CPU, see rest_init().
1011 if (smp_ops && smp_ops->setup_cpu)
1012 smp_ops->setup_cpu(boot_cpuid);
1014 if (smp_ops && smp_ops->bringup_done)
1015 smp_ops->bringup_done();
1017 dump_numa_cpu_topology();
1019 set_sched_topology(powerpc_topology);
1022 #ifdef CONFIG_HOTPLUG_CPU
1023 int __cpu_disable(void)
1025 int cpu = smp_processor_id();
1029 if (!smp_ops->cpu_disable)
1032 err = smp_ops->cpu_disable();
1036 /* Update sibling maps */
1037 base = cpu_first_thread_sibling(cpu);
1038 for (i = 0; i < threads_per_core && base + i < nr_cpu_ids; i++) {
1039 cpumask_clear_cpu(cpu, cpu_sibling_mask(base + i));
1040 cpumask_clear_cpu(base + i, cpu_sibling_mask(cpu));
1041 cpumask_clear_cpu(cpu, cpu_core_mask(base + i));
1042 cpumask_clear_cpu(base + i, cpu_core_mask(cpu));
1044 traverse_core_siblings(cpu, false);
1049 void __cpu_die(unsigned int cpu)
1051 if (smp_ops->cpu_die)
1052 smp_ops->cpu_die(cpu);
1060 /* If we return, we re-enter start_secondary */
1061 start_secondary_resume();