Lines Matching full:cpu
29 #include <linux/cpu.h>
72 /* State of each CPU during hotplug phases */
122 * On big-cores system, thread_group_l1_cache_map for each CPU corresponds to
128 * On some big-cores system, thread_group_l2_cache_map for each CPU
135 * On P10, thread_group_l3_cache_map for each CPU is equal to the
149 * Returns 1 if the specified cpu should be brought up during boot.
283 void smp_muxed_ipi_set_message(int cpu, int msg) in smp_muxed_ipi_set_message() argument
285 struct cpu_messages *info = &per_cpu(ipi_message, cpu); in smp_muxed_ipi_set_message()
295 void smp_muxed_ipi_message_pass(int cpu, int msg) in smp_muxed_ipi_message_pass() argument
297 smp_muxed_ipi_set_message(cpu, msg); in smp_muxed_ipi_message_pass()
303 smp_ops->cause_ipi(cpu); in smp_muxed_ipi_message_pass()
357 static inline void do_message_pass(int cpu, int msg) in do_message_pass() argument
360 smp_ops->message_pass(cpu, msg); in do_message_pass()
363 smp_muxed_ipi_message_pass(cpu, msg); in do_message_pass()
367 void smp_send_reschedule(int cpu) in smp_send_reschedule() argument
370 do_message_pass(cpu, PPC_MSG_RESCHEDULE); in smp_send_reschedule()
374 void arch_send_call_function_single_ipi(int cpu) in arch_send_call_function_single_ipi() argument
376 do_message_pass(cpu, PPC_MSG_CALL_FUNCTION); in arch_send_call_function_single_ipi()
381 unsigned int cpu; in arch_send_call_function_ipi_mask() local
383 for_each_cpu(cpu, mask) in arch_send_call_function_ipi_mask()
384 do_message_pass(cpu, PPC_MSG_CALL_FUNCTION); in arch_send_call_function_ipi_mask()
475 static void do_smp_send_nmi_ipi(int cpu, bool safe) in do_smp_send_nmi_ipi() argument
477 if (!safe && smp_ops->cause_nmi_ipi && smp_ops->cause_nmi_ipi(cpu)) in do_smp_send_nmi_ipi()
480 if (cpu >= 0) { in do_smp_send_nmi_ipi()
481 do_message_pass(cpu, PPC_MSG_NMI_IPI); in do_smp_send_nmi_ipi()
494 * - cpu is the target CPU (must not be this CPU), or NMI_IPI_ALL_OTHERS.
499 static int __smp_send_nmi_ipi(int cpu, void (*fn)(struct pt_regs *), in __smp_send_nmi_ipi() argument
506 BUG_ON(cpu == me); in __smp_send_nmi_ipi()
507 BUG_ON(cpu < 0 && cpu != NMI_IPI_ALL_OTHERS); in __smp_send_nmi_ipi()
523 if (cpu < 0) { in __smp_send_nmi_ipi()
528 cpumask_set_cpu(cpu, &nmi_ipi_pending_mask); in __smp_send_nmi_ipi()
535 do_smp_send_nmi_ipi(cpu, safe); in __smp_send_nmi_ipi()
564 int smp_send_nmi_ipi(int cpu, void (*fn)(struct pt_regs *), u64 delay_us) in smp_send_nmi_ipi() argument
566 return __smp_send_nmi_ipi(cpu, fn, delay_us, false); in smp_send_nmi_ipi()
569 int smp_send_safe_nmi_ipi(int cpu, void (*fn)(struct pt_regs *), u64 delay_us) in smp_send_safe_nmi_ipi() argument
571 return __smp_send_nmi_ipi(cpu, fn, delay_us, true); in smp_send_safe_nmi_ipi()
578 unsigned int cpu; in tick_broadcast() local
580 for_each_cpu(cpu, mask) in tick_broadcast()
581 do_message_pass(cpu, PPC_MSG_TICK_BROADCAST); in tick_broadcast()
600 int cpu; in crash_send_ipi() local
604 for_each_present_cpu(cpu) { in crash_send_ipi()
605 if (cpu_online(cpu)) in crash_send_ipi()
616 do_smp_send_nmi_ipi(cpu, false); in crash_send_ipi()
718 * Relationships between CPUs are maintained in a set of per-cpu cpumasks so
720 * returns the that cpumask for the given CPU.
738 * Extends set_cpus_related. Instead of setting one CPU at a time in
761 * property for the CPU device node @dn and stores
765 * @dn: The device node of the CPU device.
770 * the CPU-device node can be grouped together based on the property.
860 * that @cpu belongs to.
862 * @cpu : The logical CPU whose thread group is being searched.
863 * @tg : The thread-group structure of the CPU node which @cpu belongs
867 * of the thread_group that @cpu belongs to.
869 * Returns -1 if cpu doesn't belong to any of the groups pointed to by
872 static int get_cpu_thread_group_start(int cpu, struct thread_groups *tg) in get_cpu_thread_group_start() argument
874 int hw_cpu_id = get_hard_smp_processor_id(cpu); in get_cpu_thread_group_start()
891 static struct thread_groups *__init get_thread_groups(int cpu, in get_thread_groups() argument
895 struct device_node *dn = of_get_cpu_node(cpu, NULL); in get_thread_groups()
896 struct thread_groups_list *cpu_tgl = &tgl[cpu]; in get_thread_groups()
927 int cpu, int cpu_group_start) in update_mask_from_threadgroup() argument
929 int first_thread = cpu_first_thread_sibling(cpu); in update_mask_from_threadgroup()
932 zalloc_cpumask_var_node(mask, GFP_KERNEL, cpu_to_node(cpu)); in update_mask_from_threadgroup()
949 static int __init init_thread_group_cache_map(int cpu, int cache_property) in init_thread_group_cache_map() argument
960 tg = get_thread_groups(cpu, cache_property, &err); in init_thread_group_cache_map()
965 cpu_group_start = get_cpu_thread_group_start(cpu, tg); in init_thread_group_cache_map()
973 mask = &per_cpu(thread_group_l1_cache_map, cpu); in init_thread_group_cache_map()
974 update_mask_from_threadgroup(mask, tg, cpu, cpu_group_start); in init_thread_group_cache_map()
977 mask = &per_cpu(thread_group_l2_cache_map, cpu); in init_thread_group_cache_map()
978 update_mask_from_threadgroup(mask, tg, cpu, cpu_group_start); in init_thread_group_cache_map()
979 mask = &per_cpu(thread_group_l3_cache_map, cpu); in init_thread_group_cache_map()
980 update_mask_from_threadgroup(mask, tg, cpu, cpu_group_start); in init_thread_group_cache_map()
1018 static const struct cpumask *shared_cache_mask(int cpu) in shared_cache_mask() argument
1020 return per_cpu(cpu_l2_cache_map, cpu); in shared_cache_mask()
1024 static const struct cpumask *smallcore_smt_mask(int cpu) in smallcore_smt_mask() argument
1026 return cpu_smallcore_mask(cpu); in smallcore_smt_mask()
1030 static struct cpumask *cpu_coregroup_mask(int cpu) in cpu_coregroup_mask() argument
1032 return per_cpu(cpu_coregroup_map, cpu); in cpu_coregroup_mask()
1040 static const struct cpumask *cpu_mc_mask(int cpu) in cpu_mc_mask() argument
1042 return cpu_coregroup_mask(cpu); in cpu_mc_mask()
1057 int cpu; in init_big_cores() local
1059 for_each_possible_cpu(cpu) { in init_big_cores()
1060 int err = init_thread_group_cache_map(cpu, THREAD_GROUP_SHARE_L1); in init_big_cores()
1065 zalloc_cpumask_var_node(&per_cpu(cpu_smallcore_map, cpu), in init_big_cores()
1067 cpu_to_node(cpu)); in init_big_cores()
1072 for_each_possible_cpu(cpu) { in init_big_cores()
1073 int err = init_thread_group_cache_map(cpu, THREAD_GROUP_SHARE_L2_L3); in init_big_cores()
1088 unsigned int cpu; in smp_prepare_cpus() local
1093 * setup_cpu may need to be called on the boot cpu. We haven't in smp_prepare_cpus()
1098 /* Fixup boot cpu */ in smp_prepare_cpus()
1102 for_each_possible_cpu(cpu) { in smp_prepare_cpus()
1103 zalloc_cpumask_var_node(&per_cpu(cpu_sibling_map, cpu), in smp_prepare_cpus()
1104 GFP_KERNEL, cpu_to_node(cpu)); in smp_prepare_cpus()
1105 zalloc_cpumask_var_node(&per_cpu(cpu_l2_cache_map, cpu), in smp_prepare_cpus()
1106 GFP_KERNEL, cpu_to_node(cpu)); in smp_prepare_cpus()
1107 zalloc_cpumask_var_node(&per_cpu(cpu_core_map, cpu), in smp_prepare_cpus()
1108 GFP_KERNEL, cpu_to_node(cpu)); in smp_prepare_cpus()
1110 zalloc_cpumask_var_node(&per_cpu(cpu_coregroup_map, cpu), in smp_prepare_cpus()
1111 GFP_KERNEL, cpu_to_node(cpu)); in smp_prepare_cpus()
1117 if (cpu_present(cpu)) { in smp_prepare_cpus()
1118 set_cpu_numa_node(cpu, numa_cpu_lookup_table[cpu]); in smp_prepare_cpus()
1119 set_cpu_numa_mem(cpu, in smp_prepare_cpus()
1120 local_memory_node(numa_cpu_lookup_table[cpu])); in smp_prepare_cpus()
1125 /* Init the cpumasks so the boot CPU is related to itself */ in smp_prepare_cpus()
1171 unsigned int cpu = smp_processor_id(); in generic_cpu_disable() local
1173 if (cpu == boot_cpuid) in generic_cpu_disable()
1176 set_cpu_online(cpu, false); in generic_cpu_disable()
1180 /* Update affinity of all IRQs previously aimed at this CPU */ in generic_cpu_disable()
1185 * that one of the interrupts we just migrated away from this CPU is in generic_cpu_disable()
1186 * actually already pending on this CPU. If we leave it in that state in generic_cpu_disable()
1189 * be received (and EOI'ed), before we take this CPU offline. in generic_cpu_disable()
1198 void generic_cpu_die(unsigned int cpu) in generic_cpu_die() argument
1204 if (is_cpu_dead(cpu)) in generic_cpu_die()
1208 printk(KERN_ERR "CPU%d didn't die...\n", cpu); in generic_cpu_die()
1211 void generic_set_cpu_dead(unsigned int cpu) in generic_set_cpu_dead() argument
1213 per_cpu(cpu_state, cpu) = CPU_DEAD; in generic_set_cpu_dead()
1221 void generic_set_cpu_up(unsigned int cpu) in generic_set_cpu_up() argument
1223 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE; in generic_set_cpu_up()
1226 int generic_check_cpu_restart(unsigned int cpu) in generic_check_cpu_restart() argument
1228 return per_cpu(cpu_state, cpu) == CPU_UP_PREPARE; in generic_check_cpu_restart()
1231 int is_cpu_dead(unsigned int cpu) in is_cpu_dead() argument
1233 return per_cpu(cpu_state, cpu) == CPU_DEAD; in is_cpu_dead()
1247 static void cpu_idle_thread_init(unsigned int cpu, struct task_struct *idle) in cpu_idle_thread_init() argument
1250 paca_ptrs[cpu]->__current = idle; in cpu_idle_thread_init()
1251 paca_ptrs[cpu]->kstack = (unsigned long)task_stack_page(idle) + in cpu_idle_thread_init()
1254 task_thread_info(idle)->cpu = cpu; in cpu_idle_thread_init()
1255 secondary_current = current_set[cpu] = idle; in cpu_idle_thread_init()
1258 int __cpu_up(unsigned int cpu, struct task_struct *tidle) in __cpu_up() argument
1271 cpu_thread_in_subcore(cpu)) in __cpu_up()
1275 (smp_ops->cpu_bootable && !smp_ops->cpu_bootable(cpu))) in __cpu_up()
1278 cpu_idle_thread_init(cpu, tidle); in __cpu_up()
1282 * up the CPU in __cpu_up()
1285 rc = smp_ops->prepare_cpu(cpu); in __cpu_up()
1290 /* Make sure callin-map entry is 0 (can be leftover a CPU in __cpu_up()
1293 cpu_callin_map[cpu] = 0; in __cpu_up()
1302 DBG("smp: kicking cpu %d\n", cpu); in __cpu_up()
1303 rc = smp_ops->kick_cpu(cpu); in __cpu_up()
1305 pr_err("smp: failed starting cpu %d (rc %d)\n", cpu, rc); in __cpu_up()
1317 spin_until_cond(cpu_callin_map[cpu] || time_is_before_jiffies(deadline)); in __cpu_up()
1319 if (!cpu_callin_map[cpu] && system_state >= SYSTEM_RUNNING) { in __cpu_up()
1324 while (!cpu_callin_map[cpu] && time_is_after_jiffies(deadline)) in __cpu_up()
1328 if (!cpu_callin_map[cpu]) { in __cpu_up()
1329 printk(KERN_ERR "Processor %u is stuck.\n", cpu); in __cpu_up()
1333 DBG("Processor %u found.\n", cpu); in __cpu_up()
1338 /* Wait until cpu puts itself in the online & active maps */ in __cpu_up()
1339 spin_until_cond(cpu_online(cpu)); in __cpu_up()
1345 * logical cpu.
1347 int cpu_to_core_id(int cpu) in cpu_to_core_id() argument
1352 np = of_get_cpu_node(cpu, NULL); in cpu_to_core_id()
1363 /* Helper routines for cpu to core mapping */
1364 int cpu_core_index_of_thread(int cpu) in cpu_core_index_of_thread() argument
1366 return cpu >> threads_shift; in cpu_core_index_of_thread()
1377 * i.e. during cpu online or offline.
1379 static struct device_node *cpu_to_l2cache(int cpu) in cpu_to_l2cache() argument
1384 if (!cpu_present(cpu)) in cpu_to_l2cache()
1387 np = of_get_cpu_node(cpu, NULL); in cpu_to_l2cache()
1398 static bool update_mask_by_l2(int cpu, cpumask_var_t *mask) in update_mask_by_l2() argument
1412 cpumask_set_cpu(cpu, cpu_l2_cache_mask(cpu)); in update_mask_by_l2()
1414 for_each_cpu(i, per_cpu(thread_group_l2_cache_map, cpu)) { in update_mask_by_l2()
1416 set_cpus_related(i, cpu, cpu_l2_cache_mask); in update_mask_by_l2()
1420 if (!cpumask_equal(submask_fn(cpu), cpu_l2_cache_mask(cpu)) && in update_mask_by_l2()
1421 !cpumask_subset(submask_fn(cpu), cpu_l2_cache_mask(cpu))) { in update_mask_by_l2()
1422 pr_warn_once("CPU %d : Inconsistent L1 and L2 cache siblings\n", in update_mask_by_l2()
1423 cpu); in update_mask_by_l2()
1429 l2_cache = cpu_to_l2cache(cpu); in update_mask_by_l2()
1431 /* Assume only core siblings share cache with this CPU */ in update_mask_by_l2()
1432 for_each_cpu(i, cpu_sibling_mask(cpu)) in update_mask_by_l2()
1433 set_cpus_related(cpu, i, cpu_l2_cache_mask); in update_mask_by_l2()
1438 cpumask_and(*mask, cpu_online_mask, cpu_cpu_mask(cpu)); in update_mask_by_l2()
1441 or_cpumasks_related(cpu, cpu, submask_fn, cpu_l2_cache_mask); in update_mask_by_l2()
1443 /* Skip all CPUs already part of current CPU l2-cache mask */ in update_mask_by_l2()
1444 cpumask_andnot(*mask, *mask, cpu_l2_cache_mask(cpu)); in update_mask_by_l2()
1448 * when updating the marks the current CPU has not been marked in update_mask_by_l2()
1453 /* Skip all CPUs already part of current CPU l2-cache */ in update_mask_by_l2()
1455 or_cpumasks_related(cpu, i, submask_fn, cpu_l2_cache_mask); in update_mask_by_l2()
1469 static void remove_cpu_from_masks(int cpu) in remove_cpu_from_masks() argument
1474 unmap_cpu_from_node(cpu); in remove_cpu_from_masks()
1479 for_each_cpu(i, mask_fn(cpu)) { in remove_cpu_from_masks()
1480 set_cpus_unrelated(cpu, i, cpu_l2_cache_mask); in remove_cpu_from_masks()
1481 set_cpus_unrelated(cpu, i, cpu_sibling_mask); in remove_cpu_from_masks()
1483 set_cpus_unrelated(cpu, i, cpu_smallcore_mask); in remove_cpu_from_masks()
1486 for_each_cpu(i, cpu_core_mask(cpu)) in remove_cpu_from_masks()
1487 set_cpus_unrelated(cpu, i, cpu_core_mask); in remove_cpu_from_masks()
1490 for_each_cpu(i, cpu_coregroup_mask(cpu)) in remove_cpu_from_masks()
1491 set_cpus_unrelated(cpu, i, cpu_coregroup_mask); in remove_cpu_from_masks()
1496 static inline void add_cpu_to_smallcore_masks(int cpu) in add_cpu_to_smallcore_masks() argument
1503 cpumask_set_cpu(cpu, cpu_smallcore_mask(cpu)); in add_cpu_to_smallcore_masks()
1505 for_each_cpu(i, per_cpu(thread_group_l1_cache_map, cpu)) { in add_cpu_to_smallcore_masks()
1507 set_cpus_related(i, cpu, cpu_smallcore_mask); in add_cpu_to_smallcore_masks()
1511 static void update_coregroup_mask(int cpu, cpumask_var_t *mask) in update_coregroup_mask() argument
1514 int coregroup_id = cpu_to_coregroup_id(cpu); in update_coregroup_mask()
1521 /* Assume only siblings are part of this CPU's coregroup */ in update_coregroup_mask()
1522 for_each_cpu(i, submask_fn(cpu)) in update_coregroup_mask()
1523 set_cpus_related(cpu, i, cpu_coregroup_mask); in update_coregroup_mask()
1528 cpumask_and(*mask, cpu_online_mask, cpu_cpu_mask(cpu)); in update_coregroup_mask()
1531 or_cpumasks_related(cpu, cpu, submask_fn, cpu_coregroup_mask); in update_coregroup_mask()
1534 cpumask_andnot(*mask, *mask, cpu_coregroup_mask(cpu)); in update_coregroup_mask()
1539 or_cpumasks_related(cpu, i, submask_fn, cpu_coregroup_mask); in update_coregroup_mask()
1547 static void add_cpu_to_masks(int cpu) in add_cpu_to_masks() argument
1550 int first_thread = cpu_first_thread_sibling(cpu); in add_cpu_to_masks()
1557 * This CPU will not be in the online mask yet so we need to manually in add_cpu_to_masks()
1560 map_cpu_to_node(cpu, cpu_to_node(cpu)); in add_cpu_to_masks()
1561 cpumask_set_cpu(cpu, cpu_sibling_mask(cpu)); in add_cpu_to_masks()
1562 cpumask_set_cpu(cpu, cpu_core_mask(cpu)); in add_cpu_to_masks()
1566 set_cpus_related(i, cpu, cpu_sibling_mask); in add_cpu_to_masks()
1568 add_cpu_to_smallcore_masks(cpu); in add_cpu_to_masks()
1570 /* In CPU-hotplug path, hence use GFP_ATOMIC */ in add_cpu_to_masks()
1571 ret = alloc_cpumask_var_node(&mask, GFP_ATOMIC, cpu_to_node(cpu)); in add_cpu_to_masks()
1572 update_mask_by_l2(cpu, &mask); in add_cpu_to_masks()
1575 update_coregroup_mask(cpu, &mask); in add_cpu_to_masks()
1578 chip_id = cpu_to_chip_id(cpu); in add_cpu_to_masks()
1584 or_cpumasks_related(cpu, cpu, submask_fn, cpu_core_mask); in add_cpu_to_masks()
1586 /* Skip all CPUs already part of current CPU core mask */ in add_cpu_to_masks()
1587 cpumask_andnot(mask, cpu_online_mask, cpu_core_mask(cpu)); in add_cpu_to_masks()
1591 cpumask_and(mask, mask, cpu_cpu_mask(cpu)); in add_cpu_to_masks()
1595 or_cpumasks_related(cpu, i, submask_fn, cpu_core_mask); in add_cpu_to_masks()
1608 unsigned int cpu = raw_smp_processor_id(); in start_secondary() local
1617 smp_store_cpu_info(cpu); in start_secondary()
1619 rcu_cpu_starting(cpu); in start_secondary()
1620 cpu_callin_map[cpu] = 1; in start_secondary()
1623 smp_ops->setup_cpu(cpu); in start_secondary()
1635 set_numa_node(numa_cpu_lookup_table[cpu]); in start_secondary()
1636 set_numa_mem(local_memory_node(numa_cpu_lookup_table[cpu])); in start_secondary()
1638 /* Update topology CPU masks */ in start_secondary()
1639 add_cpu_to_masks(cpu); in start_secondary()
1647 struct cpumask *mask = cpu_l2_cache_mask(cpu); in start_secondary()
1652 if (cpumask_weight(mask) > cpumask_weight(sibling_mask(cpu))) in start_secondary()
1657 notify_cpu_starting(cpu); in start_secondary()
1658 set_cpu_online(cpu, true); in start_secondary()
1714 * We are running pinned to the boot CPU, see rest_init(). in smp_cpus_done()
1731 int cpu = smp_processor_id(); in __cpu_disable() local
1744 remove_cpu_from_masks(cpu); in __cpu_disable()
1749 void __cpu_die(unsigned int cpu) in __cpu_die() argument
1752 smp_ops->cpu_die(cpu); in __cpu_die()