Lines Matching +full:1 +full:- +full:cpu

1 // SPDX-License-Identifier: GPL-2.0-or-later
10 * PowerPC-64 Support added by Dave Engebretsen, Peter Bergner, and
29 #include <linux/cpu.h>
76 /* State of each CPU during hotplug phases */
98 #define THREAD_GROUP_SHARE_L1 1
117 * On big-cores system, thread_group_l1_cache_map for each CPU corresponds to
118 * the set its siblings that share the L1-cache.
123 * On some big-cores system, thread_group_l2_cache_map for each CPU
125 * L2-cache.
130 * On P10, thread_group_l3_cache_map for each CPU is equal to the
141 int smt_enabled_at_boot = 1;
144 * Returns 1 if the specified cpu should be brought up during boot.
150 /* Special case - we inhibit secondary thread startup in smp_generic_cpu_bootable()
161 return 1; in smp_generic_cpu_bootable()
169 return -EINVAL; in smp_generic_kick_cpu()
173 * cpu_start field to become non-zero After we set cpu_start, in smp_generic_kick_cpu()
176 if (!paca_ptrs[nr]->cpu_start) { in smp_generic_kick_cpu()
177 paca_ptrs[nr]->cpu_start = 1; in smp_generic_kick_cpu()
184 * Ok it's not there, so it might be soft-unplugged, let's in smp_generic_kick_cpu()
236 * The NMI IPI is a fallback and not truly non-maskable. It is simpler
244 [PPC_MSG_TICK_BROADCAST] = "ipi tick-broadcast",
257 return -EINVAL; in smp_request_message_ipi()
260 return 1; in smp_request_message_ipi()
278 void smp_muxed_ipi_set_message(int cpu, int msg) in smp_muxed_ipi_set_message() argument
280 struct cpu_messages *info = &per_cpu(ipi_message, cpu); in smp_muxed_ipi_set_message()
281 char *message = (char *)&info->messages; in smp_muxed_ipi_set_message()
287 WRITE_ONCE(message[msg], 1); in smp_muxed_ipi_set_message()
290 void smp_muxed_ipi_message_pass(int cpu, int msg) in smp_muxed_ipi_message_pass() argument
292 smp_muxed_ipi_set_message(cpu, msg); in smp_muxed_ipi_message_pass()
298 smp_ops->cause_ipi(cpu); in smp_muxed_ipi_message_pass()
302 #define IPI_MESSAGE(A) (1uL << ((BITS_PER_LONG - 8) - 8 * (A)))
304 #define IPI_MESSAGE(A) (1uL << (8 * (A)))
314 /* sync-free variant. Callers should ensure synchronization */
322 all = xchg(&info->messages, 0); in smp_ipi_demux_relaxed()
346 } while (READ_ONCE(info->messages)); in smp_ipi_demux_relaxed()
352 static inline void do_message_pass(int cpu, int msg) in do_message_pass() argument
354 if (smp_ops->message_pass) in do_message_pass()
355 smp_ops->message_pass(cpu, msg); in do_message_pass()
358 smp_muxed_ipi_message_pass(cpu, msg); in do_message_pass()
362 void arch_smp_send_reschedule(int cpu) in arch_smp_send_reschedule() argument
365 do_message_pass(cpu, PPC_MSG_RESCHEDULE); in arch_smp_send_reschedule()
369 void arch_send_call_function_single_ipi(int cpu) in arch_send_call_function_single_ipi() argument
371 do_message_pass(cpu, PPC_MSG_CALL_FUNCTION); in arch_send_call_function_single_ipi()
376 unsigned int cpu; in arch_send_call_function_ipi_mask() local
378 for_each_cpu(cpu, mask) in arch_send_call_function_ipi_mask()
379 do_message_pass(cpu, PPC_MSG_CALL_FUNCTION); in arch_send_call_function_ipi_mask()
393 * concurrency or re-entrancy.
413 while (raw_atomic_cmpxchg(&__nmi_ipi_lock, 0, 1) == 1) { in nmi_ipi_lock_start()
423 while (raw_atomic_cmpxchg(&__nmi_ipi_lock, 0, 1) == 1) in nmi_ipi_lock()
430 WARN_ON(raw_atomic_read(&__nmi_ipi_lock) != 1); in nmi_ipi_unlock()
460 ret = 1; in smp_handle_nmi_ipi()
470 static void do_smp_send_nmi_ipi(int cpu, bool safe) in do_smp_send_nmi_ipi() argument
472 if (!safe && smp_ops->cause_nmi_ipi && smp_ops->cause_nmi_ipi(cpu)) in do_smp_send_nmi_ipi()
475 if (cpu >= 0) { in do_smp_send_nmi_ipi()
476 do_message_pass(cpu, PPC_MSG_NMI_IPI); in do_smp_send_nmi_ipi()
489 * - cpu is the target CPU (must not be this CPU), or NMI_IPI_ALL_OTHERS.
490 * - fn is the target callback function.
491 * - delay_us > 0 is the delay before giving up waiting for targets to
494 static int __smp_send_nmi_ipi(int cpu, void (*fn)(struct pt_regs *), in __smp_send_nmi_ipi() argument
499 int ret = 1; in __smp_send_nmi_ipi()
501 BUG_ON(cpu == me); in __smp_send_nmi_ipi()
502 BUG_ON(cpu < 0 && cpu != NMI_IPI_ALL_OTHERS); in __smp_send_nmi_ipi()
518 if (cpu < 0) { in __smp_send_nmi_ipi()
523 cpumask_set_cpu(cpu, &nmi_ipi_pending_mask); in __smp_send_nmi_ipi()
530 do_smp_send_nmi_ipi(cpu, safe); in __smp_send_nmi_ipi()
536 udelay(1); in __smp_send_nmi_ipi()
539 delay_us--; in __smp_send_nmi_ipi()
559 int smp_send_nmi_ipi(int cpu, void (*fn)(struct pt_regs *), u64 delay_us) in smp_send_nmi_ipi() argument
561 return __smp_send_nmi_ipi(cpu, fn, delay_us, false); in smp_send_nmi_ipi()
564 int smp_send_safe_nmi_ipi(int cpu, void (*fn)(struct pt_regs *), u64 delay_us) in smp_send_safe_nmi_ipi() argument
566 return __smp_send_nmi_ipi(cpu, fn, delay_us, true); in smp_send_safe_nmi_ipi()
573 unsigned int cpu; in tick_broadcast() local
575 for_each_cpu(cpu, mask) in tick_broadcast()
576 do_message_pass(cpu, PPC_MSG_TICK_BROADCAST); in tick_broadcast()
595 int cpu; in crash_send_ipi() local
599 for_each_present_cpu(cpu) { in crash_send_ipi()
600 if (cpu_online(cpu)) in crash_send_ipi()
611 do_smp_send_nmi_ipi(cpu, false); in crash_send_ipi()
623 * on ibm,os-term rtas call. Skip IPI callbacks to other CPUs before in crash_smp_send_stop()
654 while (1) in nmi_stop_this_cpu()
678 while (1) in stop_this_cpu()
708 = (mfspr(SPRN_TLB1CFG) & TLBnCFG_N_ENTRY) - 1; in smp_store_cpu_info()
713 * Relationships between CPUs are maintained in a set of per-cpu cpumasks so
715 * returns the that cpumask for the given CPU.
733 * Extends set_cpus_related. Instead of setting one CPU at a time in
755 * parse_thread_groups: Parses the "ibm,thread-groups" device tree
756 * property for the CPU device node @dn and stores
760 * @dn: The device node of the CPU device.
762 * output of "ibm,thread-groups" is stored.
764 * ibm,thread-groups[0..N-1] array defines which group of threads in
765 * the CPU-device node can be grouped together based on the property.
769 * ibm,thread-groups[i + 0] tells us the property based on which the
770 * threads are being grouped together. If this value is 1, it implies
775 * ibm,thread-groups[i+1] tells us how many such thread groups exist for the
776 * property ibm,thread-groups[i]
778 * ibm,thread-groups[i+2] tells us the number of threads in each such
780 * Suppose k = (ibm,thread-groups[i+1] * ibm,thread-groups[i+2]), then,
782 * ibm,thread-groups[i+3..i+k+2] (is the list of threads identified by
783 * "ibm,ppc-interrupt-server#s" arranged as per their membership in
787 * If "ibm,thread-groups" = [1,2,4,8,10,12,14,9,11,13,15,2,2,4,8,10,12,14,9,11,13,15]
789 * a) [1,2,4,8,10,12,14,9,11,13,15]
794 * a) provides information of Property "1" being shared by "2" groups,
795 * each with "4" threads each. The "ibm,ppc-interrupt-server#s" of
797 * "ibm,ppc-interrupt-server#s" of the second group is
798 * {9,11,13,15}. Property "1" is indicative of the thread in the
803 * each group with "4" threads. The "ibm,ppc-interrupt-server#s" of
805 * "ibm,ppc-interrupt-server#s" of the second group is
807 * group share the L2-cache.
809 * Returns 0 on success, -EINVAL if the property does not exist,
810 * -ENODATA if property does not have a value, and -EOVERFLOW if the
823 count = of_property_count_u32_elems(dn, "ibm,thread-groups"); in parse_thread_groups()
825 ret = of_property_read_u32_array(dn, "ibm,thread-groups", in parse_thread_groups()
832 struct thread_groups *tg = &tglp->property_tgs[property_idx++]; in parse_thread_groups()
834 tg->property = thread_group_array[i]; in parse_thread_groups()
835 tg->nr_groups = thread_group_array[i + 1]; in parse_thread_groups()
836 tg->threads_per_group = thread_group_array[i + 2]; in parse_thread_groups()
837 total_threads = tg->nr_groups * tg->threads_per_group; in parse_thread_groups()
842 tg->thread_list[j] = thread_list[j]; in parse_thread_groups()
846 tglp->nr_properties = property_idx; in parse_thread_groups()
854 * get_cpu_thread_group_start : Searches the thread group in tg->thread_list
855 * that @cpu belongs to.
857 * @cpu : The logical CPU whose thread group is being searched.
858 * @tg : The thread-group structure of the CPU node which @cpu belongs
861 * Returns the index to tg->thread_list that points to the start
862 * of the thread_group that @cpu belongs to.
864 * Returns -1 if cpu doesn't belong to any of the groups pointed to by
865 * tg->thread_list.
867 static int get_cpu_thread_group_start(int cpu, struct thread_groups *tg) in get_cpu_thread_group_start() argument
869 int hw_cpu_id = get_hard_smp_processor_id(cpu); in get_cpu_thread_group_start()
872 for (i = 0; i < tg->nr_groups; i++) { in get_cpu_thread_group_start()
873 int group_start = i * tg->threads_per_group; in get_cpu_thread_group_start()
875 for (j = 0; j < tg->threads_per_group; j++) { in get_cpu_thread_group_start()
878 if (tg->thread_list[idx] == hw_cpu_id) in get_cpu_thread_group_start()
883 return -1; in get_cpu_thread_group_start()
886 static struct thread_groups *__init get_thread_groups(int cpu, in get_thread_groups() argument
890 struct device_node *dn = of_get_cpu_node(cpu, NULL); in get_thread_groups()
891 struct thread_groups_list *cpu_tgl = &tgl[cpu]; in get_thread_groups()
897 *err = -ENODATA; in get_thread_groups()
901 if (!cpu_tgl->nr_properties) { in get_thread_groups()
907 for (i = 0; i < cpu_tgl->nr_properties; i++) { in get_thread_groups()
908 if (cpu_tgl->property_tgs[i].property == group_property) { in get_thread_groups()
909 tg = &cpu_tgl->property_tgs[i]; in get_thread_groups()
915 *err = -EINVAL; in get_thread_groups()
922 int cpu, int cpu_group_start) in update_mask_from_threadgroup() argument
924 int first_thread = cpu_first_thread_sibling(cpu); in update_mask_from_threadgroup()
927 zalloc_cpumask_var_node(mask, GFP_KERNEL, cpu_to_node(cpu)); in update_mask_from_threadgroup()
932 if (unlikely(i_group_start == -1)) { in update_mask_from_threadgroup()
933 WARN_ON_ONCE(1); in update_mask_from_threadgroup()
934 return -ENODATA; in update_mask_from_threadgroup()
944 static int __init init_thread_group_cache_map(int cpu, int cache_property) in init_thread_group_cache_map() argument
947 int cpu_group_start = -1, err = 0; in init_thread_group_cache_map()
953 return -EINVAL; in init_thread_group_cache_map()
955 tg = get_thread_groups(cpu, cache_property, &err); in init_thread_group_cache_map()
960 cpu_group_start = get_cpu_thread_group_start(cpu, tg); in init_thread_group_cache_map()
962 if (unlikely(cpu_group_start == -1)) { in init_thread_group_cache_map()
963 WARN_ON_ONCE(1); in init_thread_group_cache_map()
964 return -ENODATA; in init_thread_group_cache_map()
968 mask = &per_cpu(thread_group_l1_cache_map, cpu); in init_thread_group_cache_map()
969 update_mask_from_threadgroup(mask, tg, cpu, cpu_group_start); in init_thread_group_cache_map()
972 mask = &per_cpu(thread_group_l2_cache_map, cpu); in init_thread_group_cache_map()
973 update_mask_from_threadgroup(mask, tg, cpu, cpu_group_start); in init_thread_group_cache_map()
974 mask = &per_cpu(thread_group_l3_cache_map, cpu); in init_thread_group_cache_map()
975 update_mask_from_threadgroup(mask, tg, cpu, cpu_group_start); in init_thread_group_cache_map()
1029 * returns a non-const pointer and the compiler barfs on that.
1031 static const struct cpumask *shared_cache_mask(int cpu) in shared_cache_mask() argument
1033 return per_cpu(cpu_l2_cache_map, cpu); in shared_cache_mask()
1037 static const struct cpumask *smallcore_smt_mask(int cpu) in smallcore_smt_mask() argument
1039 return cpu_smallcore_mask(cpu); in smallcore_smt_mask()
1043 static struct cpumask *cpu_coregroup_mask(int cpu) in cpu_coregroup_mask() argument
1045 return per_cpu(cpu_coregroup_map, cpu); in cpu_coregroup_mask()
1057 static const struct cpumask *cpu_mc_mask(int cpu) in cpu_mc_mask() argument
1059 return cpu_coregroup_mask(cpu); in cpu_mc_mask()
1064 int cpu; in init_big_cores() local
1066 for_each_possible_cpu(cpu) { in init_big_cores()
1067 int err = init_thread_group_cache_map(cpu, THREAD_GROUP_SHARE_L1); in init_big_cores()
1072 zalloc_cpumask_var_node(&per_cpu(cpu_smallcore_map, cpu), in init_big_cores()
1074 cpu_to_node(cpu)); in init_big_cores()
1079 for_each_possible_cpu(cpu) { in init_big_cores()
1080 int err = init_thread_group_cache_map(cpu, THREAD_GROUP_SHARE_L2_L3); in init_big_cores()
1095 unsigned int cpu, num_threads; in smp_prepare_cpus() local
1100 * setup_cpu may need to be called on the boot cpu. We haven't in smp_prepare_cpus()
1105 /* Fixup boot cpu */ in smp_prepare_cpus()
1107 cpu_callin_map[boot_cpuid] = 1; in smp_prepare_cpus()
1109 for_each_possible_cpu(cpu) { in smp_prepare_cpus()
1110 zalloc_cpumask_var_node(&per_cpu(cpu_sibling_map, cpu), in smp_prepare_cpus()
1111 GFP_KERNEL, cpu_to_node(cpu)); in smp_prepare_cpus()
1112 zalloc_cpumask_var_node(&per_cpu(cpu_l2_cache_map, cpu), in smp_prepare_cpus()
1113 GFP_KERNEL, cpu_to_node(cpu)); in smp_prepare_cpus()
1114 zalloc_cpumask_var_node(&per_cpu(cpu_core_map, cpu), in smp_prepare_cpus()
1115 GFP_KERNEL, cpu_to_node(cpu)); in smp_prepare_cpus()
1117 zalloc_cpumask_var_node(&per_cpu(cpu_coregroup_map, cpu), in smp_prepare_cpus()
1118 GFP_KERNEL, cpu_to_node(cpu)); in smp_prepare_cpus()
1124 if (cpu_present(cpu)) { in smp_prepare_cpus()
1125 set_cpu_numa_node(cpu, numa_cpu_lookup_table[cpu]); in smp_prepare_cpus()
1126 set_cpu_numa_mem(cpu, in smp_prepare_cpus()
1127 local_memory_node(numa_cpu_lookup_table[cpu])); in smp_prepare_cpus()
1132 /* Init the cpumasks so the boot CPU is related to itself */ in smp_prepare_cpus()
1146 if (cpu_to_chip_id(boot_cpuid) != -1) { in smp_prepare_cpus()
1152 * Assumption: if boot_cpuid doesn't have a chip-id, then no in smp_prepare_cpus()
1153 * other CPUs, will also not have chip-id. in smp_prepare_cpus()
1157 memset(chip_id_lookup_table, -1, sizeof(int) * idx); in smp_prepare_cpus()
1160 if (smp_ops && smp_ops->probe) in smp_prepare_cpus()
1161 smp_ops->probe(); in smp_prepare_cpus()
1164 num_threads = 1; in smp_prepare_cpus()
1174 paca_ptrs[boot_cpuid]->__current = current; in smp_prepare_boot_cpu()
1184 unsigned int cpu = smp_processor_id(); in generic_cpu_disable() local
1186 if (cpu == boot_cpuid) in generic_cpu_disable()
1187 return -EBUSY; in generic_cpu_disable()
1189 set_cpu_online(cpu, false); in generic_cpu_disable()
1191 systemcfg->processorCount--; in generic_cpu_disable()
1193 /* Update affinity of all IRQs previously aimed at this CPU */ in generic_cpu_disable()
1198 * that one of the interrupts we just migrated away from this CPU is in generic_cpu_disable()
1199 * actually already pending on this CPU. If we leave it in that state in generic_cpu_disable()
1202 * be received (and EOI'ed), before we take this CPU offline. in generic_cpu_disable()
1205 mdelay(1); in generic_cpu_disable()
1211 void generic_cpu_die(unsigned int cpu) in generic_cpu_die() argument
1217 if (is_cpu_dead(cpu)) in generic_cpu_die()
1221 printk(KERN_ERR "CPU%d didn't die...\n", cpu); in generic_cpu_die()
1224 void generic_set_cpu_dead(unsigned int cpu) in generic_set_cpu_dead() argument
1226 per_cpu(cpu_state, cpu) = CPU_DEAD; in generic_set_cpu_dead()
1234 void generic_set_cpu_up(unsigned int cpu) in generic_set_cpu_up() argument
1236 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE; in generic_set_cpu_up()
1239 int generic_check_cpu_restart(unsigned int cpu) in generic_check_cpu_restart() argument
1241 return per_cpu(cpu_state, cpu) == CPU_UP_PREPARE; in generic_check_cpu_restart()
1244 int is_cpu_dead(unsigned int cpu) in is_cpu_dead() argument
1246 return per_cpu(cpu_state, cpu) == CPU_DEAD; in is_cpu_dead()
1260 static void cpu_idle_thread_init(unsigned int cpu, struct task_struct *idle) in cpu_idle_thread_init() argument
1263 paca_ptrs[cpu]->__current = idle; in cpu_idle_thread_init()
1264 paca_ptrs[cpu]->kstack = (unsigned long)task_stack_page(idle) + in cpu_idle_thread_init()
1265 THREAD_SIZE - STACK_FRAME_MIN_SIZE; in cpu_idle_thread_init()
1267 task_thread_info(idle)->cpu = cpu; in cpu_idle_thread_init()
1268 secondary_current = current_set[cpu] = idle; in cpu_idle_thread_init()
1271 int __cpu_up(unsigned int cpu, struct task_struct *tidle) in __cpu_up() argument
1275 const unsigned long hp_spin_ms = 1; in __cpu_up()
1283 if (threads_per_core > 1 && secondaries_inhibited() && in __cpu_up()
1284 cpu_thread_in_subcore(cpu)) in __cpu_up()
1285 return -EBUSY; in __cpu_up()
1288 (smp_ops->cpu_bootable && !smp_ops->cpu_bootable(cpu))) in __cpu_up()
1289 return -EINVAL; in __cpu_up()
1291 cpu_idle_thread_init(cpu, tidle); in __cpu_up()
1295 * up the CPU in __cpu_up()
1297 if (smp_ops->prepare_cpu) { in __cpu_up()
1298 rc = smp_ops->prepare_cpu(cpu); in __cpu_up()
1303 /* Make sure callin-map entry is 0 (can be leftover a CPU in __cpu_up()
1306 cpu_callin_map[cpu] = 0; in __cpu_up()
1315 DBG("smp: kicking cpu %d\n", cpu); in __cpu_up()
1316 rc = smp_ops->kick_cpu(cpu); in __cpu_up()
1318 pr_err("smp: failed starting cpu %d (rc %d)\n", cpu, rc); in __cpu_up()
1330 spin_until_cond(cpu_callin_map[cpu] || time_is_before_jiffies(deadline)); in __cpu_up()
1332 if (!cpu_callin_map[cpu] && system_state >= SYSTEM_RUNNING) { in __cpu_up()
1337 while (!cpu_callin_map[cpu] && time_is_after_jiffies(deadline)) in __cpu_up()
1341 if (!cpu_callin_map[cpu]) { in __cpu_up()
1342 printk(KERN_ERR "Processor %u is stuck.\n", cpu); in __cpu_up()
1343 return -ENOENT; in __cpu_up()
1346 DBG("Processor %u found.\n", cpu); in __cpu_up()
1348 if (smp_ops->give_timebase) in __cpu_up()
1349 smp_ops->give_timebase(); in __cpu_up()
1351 /* Wait until cpu puts itself in the online & active maps */ in __cpu_up()
1352 spin_until_cond(cpu_online(cpu)); in __cpu_up()
1358 * logical cpu.
1360 int cpu_to_core_id(int cpu) in cpu_to_core_id() argument
1363 int id = -1; in cpu_to_core_id()
1365 np = of_get_cpu_node(cpu, NULL); in cpu_to_core_id()
1376 /* Helper routines for cpu to core mapping */
1377 int cpu_core_index_of_thread(int cpu) in cpu_core_index_of_thread() argument
1379 return cpu >> threads_shift; in cpu_core_index_of_thread()
1390 * i.e. during cpu online or offline.
1392 static struct device_node *cpu_to_l2cache(int cpu) in cpu_to_l2cache() argument
1397 if (!cpu_present(cpu)) in cpu_to_l2cache()
1400 np = of_get_cpu_node(cpu, NULL); in cpu_to_l2cache()
1411 static bool update_mask_by_l2(int cpu, cpumask_var_t *mask) in update_mask_by_l2() argument
1421 * If the threads in a thread-group share L2 cache, then the in update_mask_by_l2()
1422 * L2-mask can be obtained from thread_group_l2_cache_map. in update_mask_by_l2()
1425 cpumask_set_cpu(cpu, cpu_l2_cache_mask(cpu)); in update_mask_by_l2()
1427 for_each_cpu(i, per_cpu(thread_group_l2_cache_map, cpu)) { in update_mask_by_l2()
1429 set_cpus_related(i, cpu, cpu_l2_cache_mask); in update_mask_by_l2()
1432 /* Verify that L1-cache siblings are a subset of L2 cache-siblings */ in update_mask_by_l2()
1433 if (!cpumask_equal(submask_fn(cpu), cpu_l2_cache_mask(cpu)) && in update_mask_by_l2()
1434 !cpumask_subset(submask_fn(cpu), cpu_l2_cache_mask(cpu))) { in update_mask_by_l2()
1435 pr_warn_once("CPU %d : Inconsistent L1 and L2 cache siblings\n", in update_mask_by_l2()
1436 cpu); in update_mask_by_l2()
1442 l2_cache = cpu_to_l2cache(cpu); in update_mask_by_l2()
1444 /* Assume only core siblings share cache with this CPU */ in update_mask_by_l2()
1445 for_each_cpu(i, cpu_sibling_mask(cpu)) in update_mask_by_l2()
1446 set_cpus_related(cpu, i, cpu_l2_cache_mask); in update_mask_by_l2()
1451 cpumask_and(*mask, cpu_online_mask, cpu_cpu_mask(cpu)); in update_mask_by_l2()
1453 /* Update l2-cache mask with all the CPUs that are part of submask */ in update_mask_by_l2()
1454 or_cpumasks_related(cpu, cpu, submask_fn, cpu_l2_cache_mask); in update_mask_by_l2()
1456 /* Skip all CPUs already part of current CPU l2-cache mask */ in update_mask_by_l2()
1457 cpumask_andnot(*mask, *mask, cpu_l2_cache_mask(cpu)); in update_mask_by_l2()
1461 * when updating the marks the current CPU has not been marked in update_mask_by_l2()
1466 /* Skip all CPUs already part of current CPU l2-cache */ in update_mask_by_l2()
1468 or_cpumasks_related(cpu, i, submask_fn, cpu_l2_cache_mask); in update_mask_by_l2()
1482 static void remove_cpu_from_masks(int cpu) in remove_cpu_from_masks() argument
1487 unmap_cpu_from_node(cpu); in remove_cpu_from_masks()
1492 for_each_cpu(i, mask_fn(cpu)) { in remove_cpu_from_masks()
1493 set_cpus_unrelated(cpu, i, cpu_l2_cache_mask); in remove_cpu_from_masks()
1494 set_cpus_unrelated(cpu, i, cpu_sibling_mask); in remove_cpu_from_masks()
1496 set_cpus_unrelated(cpu, i, cpu_smallcore_mask); in remove_cpu_from_masks()
1499 for_each_cpu(i, cpu_core_mask(cpu)) in remove_cpu_from_masks()
1500 set_cpus_unrelated(cpu, i, cpu_core_mask); in remove_cpu_from_masks()
1503 for_each_cpu(i, cpu_coregroup_mask(cpu)) in remove_cpu_from_masks()
1504 set_cpus_unrelated(cpu, i, cpu_coregroup_mask); in remove_cpu_from_masks()
1509 static inline void add_cpu_to_smallcore_masks(int cpu) in add_cpu_to_smallcore_masks() argument
1516 cpumask_set_cpu(cpu, cpu_smallcore_mask(cpu)); in add_cpu_to_smallcore_masks()
1518 for_each_cpu(i, per_cpu(thread_group_l1_cache_map, cpu)) { in add_cpu_to_smallcore_masks()
1520 set_cpus_related(i, cpu, cpu_smallcore_mask); in add_cpu_to_smallcore_masks()
1524 static void update_coregroup_mask(int cpu, cpumask_var_t *mask) in update_coregroup_mask() argument
1527 int coregroup_id = cpu_to_coregroup_id(cpu); in update_coregroup_mask()
1534 /* Assume only siblings are part of this CPU's coregroup */ in update_coregroup_mask()
1535 for_each_cpu(i, submask_fn(cpu)) in update_coregroup_mask()
1536 set_cpus_related(cpu, i, cpu_coregroup_mask); in update_coregroup_mask()
1541 cpumask_and(*mask, cpu_online_mask, cpu_cpu_mask(cpu)); in update_coregroup_mask()
1544 or_cpumasks_related(cpu, cpu, submask_fn, cpu_coregroup_mask); in update_coregroup_mask()
1547 cpumask_andnot(*mask, *mask, cpu_coregroup_mask(cpu)); in update_coregroup_mask()
1552 or_cpumasks_related(cpu, i, submask_fn, cpu_coregroup_mask); in update_coregroup_mask()
1560 static void add_cpu_to_masks(int cpu) in add_cpu_to_masks() argument
1563 int first_thread = cpu_first_thread_sibling(cpu); in add_cpu_to_masks()
1565 int chip_id = -1; in add_cpu_to_masks()
1570 * This CPU will not be in the online mask yet so we need to manually in add_cpu_to_masks()
1573 map_cpu_to_node(cpu, cpu_to_node(cpu)); in add_cpu_to_masks()
1574 cpumask_set_cpu(cpu, cpu_sibling_mask(cpu)); in add_cpu_to_masks()
1575 cpumask_set_cpu(cpu, cpu_core_mask(cpu)); in add_cpu_to_masks()
1579 set_cpus_related(i, cpu, cpu_sibling_mask); in add_cpu_to_masks()
1581 add_cpu_to_smallcore_masks(cpu); in add_cpu_to_masks()
1583 /* In CPU-hotplug path, hence use GFP_ATOMIC */ in add_cpu_to_masks()
1584 ret = alloc_cpumask_var_node(&mask, GFP_ATOMIC, cpu_to_node(cpu)); in add_cpu_to_masks()
1585 update_mask_by_l2(cpu, &mask); in add_cpu_to_masks()
1588 update_coregroup_mask(cpu, &mask); in add_cpu_to_masks()
1591 chip_id = cpu_to_chip_id(cpu); in add_cpu_to_masks()
1597 or_cpumasks_related(cpu, cpu, submask_fn, cpu_core_mask); in add_cpu_to_masks()
1599 /* Skip all CPUs already part of current CPU core mask */ in add_cpu_to_masks()
1600 cpumask_andnot(mask, cpu_online_mask, cpu_core_mask(cpu)); in add_cpu_to_masks()
1602 /* If chip_id is -1; limit the cpu_core_mask to within PKG */ in add_cpu_to_masks()
1603 if (chip_id == -1) in add_cpu_to_masks()
1604 cpumask_and(mask, mask, cpu_cpu_mask(cpu)); in add_cpu_to_masks()
1608 or_cpumasks_related(cpu, i, submask_fn, cpu_core_mask); in add_cpu_to_masks()
1622 unsigned int cpu = raw_smp_processor_id(); in start_secondary() local
1629 current->active_mm = &init_mm; in start_secondary()
1631 cpumask_set_cpu(cpu, mm_cpumask(&init_mm)); in start_secondary()
1634 smp_store_cpu_info(cpu); in start_secondary()
1636 rcutree_report_cpu_starting(cpu); in start_secondary()
1637 cpu_callin_map[cpu] = 1; in start_secondary()
1639 if (smp_ops->setup_cpu) in start_secondary()
1640 smp_ops->setup_cpu(cpu); in start_secondary()
1641 if (smp_ops->take_timebase) in start_secondary()
1642 smp_ops->take_timebase(); in start_secondary()
1648 systemcfg->processorCount++; in start_secondary()
1654 set_numa_node(numa_cpu_lookup_table[cpu]); in start_secondary()
1655 set_numa_mem(local_memory_node(numa_cpu_lookup_table[cpu])); in start_secondary()
1657 /* Update topology CPU masks */ in start_secondary()
1658 add_cpu_to_masks(cpu); in start_secondary()
1662 * per-core basis because one core in the pair might be disabled. in start_secondary()
1666 struct cpumask *mask = cpu_l2_cache_mask(cpu); in start_secondary()
1671 if (cpumask_weight(mask) > cpumask_weight(sibling_mask(cpu))) in start_secondary()
1676 notify_cpu_starting(cpu); in start_secondary()
1677 set_cpu_online(cpu, true); in start_secondary()
1727 BUG_ON(i >= ARRAY_SIZE(powerpc_topology) - 1); in build_sched_topology()
1735 * We are running pinned to the boot CPU, see rest_init(). in smp_cpus_done()
1737 if (smp_ops && smp_ops->setup_cpu) in smp_cpus_done()
1738 smp_ops->setup_cpu(boot_cpuid); in smp_cpus_done()
1740 if (smp_ops && smp_ops->bringup_done) in smp_cpus_done()
1741 smp_ops->bringup_done(); in smp_cpus_done()
1748 * For asym packing, by default lower numbered CPU has higher priority.
1752 int arch_asym_cpu_priority(int cpu) in arch_asym_cpu_priority() argument
1755 return -cpu / threads_per_core; in arch_asym_cpu_priority()
1757 return -cpu; in arch_asym_cpu_priority()
1763 int cpu = smp_processor_id(); in __cpu_disable() local
1766 if (!smp_ops->cpu_disable) in __cpu_disable()
1767 return -ENOSYS; in __cpu_disable()
1771 err = smp_ops->cpu_disable(); in __cpu_disable()
1776 remove_cpu_from_masks(cpu); in __cpu_disable()
1781 void __cpu_die(unsigned int cpu) in __cpu_die() argument
1787 VM_WARN_ON_ONCE(!cpumask_test_cpu(cpu, mm_cpumask(&init_mm))); in __cpu_die()
1789 cpumask_clear_cpu(cpu, mm_cpumask(&init_mm)); in __cpu_die()
1791 if (smp_ops->cpu_die) in __cpu_die()
1792 smp_ops->cpu_die(cpu); in __cpu_die()
1798 * Disable on the down path. This will be re-enabled by in arch_cpu_idle_dead()
1803 if (smp_ops->cpu_offline_self) in arch_cpu_idle_dead()
1804 smp_ops->cpu_offline_self(); in arch_cpu_idle_dead()
1806 /* If we return, we re-enter start_secondary */ in arch_cpu_idle_dead()