linux/include/linux/cpu.h
<<
>>
Prefs
   1/*
   2 * include/linux/cpu.h - generic cpu definition
   3 *
   4 * This is mainly for topological representation. We define the 
   5 * basic 'struct cpu' here, which can be embedded in per-arch 
   6 * definitions of processors.
   7 *
   8 * Basic handling of the devices is done in drivers/base/cpu.c
   9 * and system devices are handled in drivers/base/sys.c. 
  10 *
  11 * CPUs are exported via sysfs in the class/cpu/devices/
  12 * directory. 
  13 */
  14#ifndef _LINUX_CPU_H_
  15#define _LINUX_CPU_H_
  16
  17#include <linux/node.h>
  18#include <linux/compiler.h>
  19#include <linux/cpumask.h>
  20
  21struct device;
  22
  23struct cpu {
  24        int node_id;            /* The node which contains the CPU */
  25        int hotpluggable;       /* creates sysfs control file if hotpluggable */
  26        struct device dev;
  27};
  28
  29extern int register_cpu(struct cpu *cpu, int num);
  30extern struct device *get_cpu_device(unsigned cpu);
  31extern bool cpu_is_hotpluggable(unsigned cpu);
  32
  33extern int cpu_add_dev_attr(struct device_attribute *attr);
  34extern void cpu_remove_dev_attr(struct device_attribute *attr);
  35
  36extern int cpu_add_dev_attr_group(struct attribute_group *attrs);
  37extern void cpu_remove_dev_attr_group(struct attribute_group *attrs);
  38
  39extern ssize_t cpu_show_meltdown(struct device *dev,
  40                                 struct device_attribute *attr, char *buf);
  41extern ssize_t cpu_show_spectre_v1(struct device *dev,
  42                                   struct device_attribute *attr, char *buf);
  43extern ssize_t cpu_show_spectre_v2(struct device *dev,
  44                                   struct device_attribute *attr, char *buf);
  45
  46#ifdef CONFIG_HOTPLUG_CPU
  47extern void unregister_cpu(struct cpu *cpu);
  48extern ssize_t arch_cpu_probe(const char *, size_t);
  49extern ssize_t arch_cpu_release(const char *, size_t);
  50#endif
  51struct notifier_block;
  52
  53#ifdef CONFIG_ARCH_HAS_CPU_AUTOPROBE
  54extern int arch_cpu_uevent(struct device *dev, struct kobj_uevent_env *env);
  55extern ssize_t arch_print_cpu_modalias(struct device *dev,
  56                                       struct device_attribute *attr,
  57                                       char *bufptr);
  58#endif
  59
  60/*
  61 * CPU notifier priorities.
  62 */
  63enum {
  64        /*
  65         * SCHED_ACTIVE marks a cpu which is coming up active during
  66         * CPU_ONLINE and CPU_DOWN_FAILED and must be the first
  67         * notifier.  CPUSET_ACTIVE adjusts cpuset according to
  68         * cpu_active mask right after SCHED_ACTIVE.  During
  69         * CPU_DOWN_PREPARE, SCHED_INACTIVE and CPUSET_INACTIVE are
  70         * ordered in the similar way.
  71         *
  72         * This ordering guarantees consistent cpu_active mask and
  73         * migration behavior to all cpu notifiers.
  74         */
  75        CPU_PRI_SCHED_ACTIVE    = INT_MAX,
  76        CPU_PRI_CPUSET_ACTIVE   = INT_MAX - 1,
  77        CPU_PRI_SCHED_INACTIVE  = INT_MIN + 1,
  78        CPU_PRI_CPUSET_INACTIVE = INT_MIN,
  79
  80        /* migration should happen before other stuff but after perf */
  81        CPU_PRI_PERF            = 20,
  82        CPU_PRI_MIGRATION       = 10,
  83        /* bring up workqueues before normal notifiers and down after */
  84        CPU_PRI_WORKQUEUE_UP    = 5,
  85        CPU_PRI_WORKQUEUE_DOWN  = -5,
  86};
  87
  88#define CPU_ONLINE              0x0002 /* CPU (unsigned)v is up */
  89#define CPU_UP_PREPARE          0x0003 /* CPU (unsigned)v coming up */
  90#define CPU_UP_CANCELED         0x0004 /* CPU (unsigned)v NOT coming up */
  91#define CPU_DOWN_PREPARE        0x0005 /* CPU (unsigned)v going down */
  92#define CPU_DOWN_FAILED         0x0006 /* CPU (unsigned)v NOT going down */
  93#define CPU_DEAD                0x0007 /* CPU (unsigned)v dead */
  94#define CPU_DYING               0x0008 /* CPU (unsigned)v not running any task,
  95                                        * not handling interrupts, soon dead.
  96                                        * Called on the dying cpu, interrupts
  97                                        * are already disabled. Must not
  98                                        * sleep, must not fail */
  99#define CPU_POST_DEAD           0x0009 /* CPU (unsigned)v dead, cpu_hotplug
 100                                        * lock is dropped */
 101#define CPU_STARTING            0x000A /* CPU (unsigned)v soon running.
 102                                        * Called on the new cpu, just before
 103                                        * enabling interrupts. Must not sleep,
 104                                        * must not fail */
 105#define CPU_BROKEN              0x000C /* CPU (unsigned)v did not die properly,
 106                                        * perhaps due to preemption. */
 107
 108/* Used for CPU hotplug events occurring while tasks are frozen due to a suspend
 109 * operation in progress
 110 */
 111#define CPU_TASKS_FROZEN        0x0010
 112
 113#define CPU_ONLINE_FROZEN       (CPU_ONLINE | CPU_TASKS_FROZEN)
 114#define CPU_UP_PREPARE_FROZEN   (CPU_UP_PREPARE | CPU_TASKS_FROZEN)
 115#define CPU_UP_CANCELED_FROZEN  (CPU_UP_CANCELED | CPU_TASKS_FROZEN)
 116#define CPU_DOWN_PREPARE_FROZEN (CPU_DOWN_PREPARE | CPU_TASKS_FROZEN)
 117#define CPU_DOWN_FAILED_FROZEN  (CPU_DOWN_FAILED | CPU_TASKS_FROZEN)
 118#define CPU_DEAD_FROZEN         (CPU_DEAD | CPU_TASKS_FROZEN)
 119#define CPU_DYING_FROZEN        (CPU_DYING | CPU_TASKS_FROZEN)
 120#define CPU_STARTING_FROZEN     (CPU_STARTING | CPU_TASKS_FROZEN)
 121
 122
 123#ifdef CONFIG_SMP
 124/* Need to know about CPUs going up/down? */
 125#if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE)
 126#define cpu_notifier(fn, pri) {                                 \
 127        static struct notifier_block fn##_nb =                  \
 128                { .notifier_call = fn, .priority = pri };       \
 129        register_cpu_notifier(&fn##_nb);                        \
 130}
 131
 132#define __cpu_notifier(fn, pri) {                               \
 133        static struct notifier_block fn##_nb =                  \
 134                { .notifier_call = fn, .priority = pri };       \
 135        __register_cpu_notifier(&fn##_nb);                      \
 136}
 137#else /* #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE) */
 138#define cpu_notifier(fn, pri)   do { (void)(fn); } while (0)
 139#define __cpu_notifier(fn, pri) do { (void)(fn); } while (0)
 140#endif /* #else #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE) */
 141
 142#ifdef CONFIG_HOTPLUG_CPU
 143extern int register_cpu_notifier(struct notifier_block *nb);
 144extern int __register_cpu_notifier(struct notifier_block *nb);
 145extern void unregister_cpu_notifier(struct notifier_block *nb);
 146extern void __unregister_cpu_notifier(struct notifier_block *nb);
 147#else
 148
 149#ifndef MODULE
 150extern int register_cpu_notifier(struct notifier_block *nb);
 151extern int __register_cpu_notifier(struct notifier_block *nb);
 152#else
 153static inline int register_cpu_notifier(struct notifier_block *nb)
 154{
 155        return 0;
 156}
 157
 158static inline int __register_cpu_notifier(struct notifier_block *nb)
 159{
 160        return 0;
 161}
 162#endif
 163
 164static inline void unregister_cpu_notifier(struct notifier_block *nb)
 165{
 166}
 167
 168static inline void __unregister_cpu_notifier(struct notifier_block *nb)
 169{
 170}
 171#endif
 172
 173int cpu_up(unsigned int cpu);
 174void notify_cpu_starting(unsigned int cpu);
 175extern void cpu_maps_update_begin(void);
 176extern void cpu_maps_update_done(void);
 177
 178#define cpu_notifier_register_begin     cpu_maps_update_begin
 179#define cpu_notifier_register_done      cpu_maps_update_done
 180
 181#else   /* CONFIG_SMP */
 182
 183#define cpu_notifier(fn, pri)   do { (void)(fn); } while (0)
 184#define __cpu_notifier(fn, pri) do { (void)(fn); } while (0)
 185
 186static inline int register_cpu_notifier(struct notifier_block *nb)
 187{
 188        return 0;
 189}
 190
 191static inline int __register_cpu_notifier(struct notifier_block *nb)
 192{
 193        return 0;
 194}
 195
 196static inline void unregister_cpu_notifier(struct notifier_block *nb)
 197{
 198}
 199
 200static inline void __unregister_cpu_notifier(struct notifier_block *nb)
 201{
 202}
 203
 204static inline void cpu_maps_update_begin(void)
 205{
 206}
 207
 208static inline void cpu_maps_update_done(void)
 209{
 210}
 211
 212static inline void cpu_notifier_register_begin(void)
 213{
 214}
 215
 216static inline void cpu_notifier_register_done(void)
 217{
 218}
 219
 220#endif /* CONFIG_SMP */
 221extern struct bus_type cpu_subsys;
 222
 223#ifdef CONFIG_HOTPLUG_CPU
 224/* Stop CPUs going up and down. */
 225
 226extern void get_online_cpus(void);
 227extern bool try_get_online_cpus(void);
 228extern void put_online_cpus(void);
 229extern void cpu_hotplug_disable(void);
 230extern void cpu_hotplug_enable(void);
 231#define hotcpu_notifier(fn, pri)        cpu_notifier(fn, pri)
 232#define __hotcpu_notifier(fn, pri)      __cpu_notifier(fn, pri)
 233#define register_hotcpu_notifier(nb)    register_cpu_notifier(nb)
 234#define __register_hotcpu_notifier(nb)  __register_cpu_notifier(nb)
 235#define unregister_hotcpu_notifier(nb)  unregister_cpu_notifier(nb)
 236#define __unregister_hotcpu_notifier(nb)        __unregister_cpu_notifier(nb)
 237void clear_tasks_mm_cpumask(int cpu);
 238int cpu_down(unsigned int cpu);
 239
 240#else           /* CONFIG_HOTPLUG_CPU */
 241
 242#define get_online_cpus()       do { } while (0)
 243#define try_get_online_cpus()   true
 244#define put_online_cpus()       do { } while (0)
 245#define cpu_hotplug_disable()   do { } while (0)
 246#define cpu_hotplug_enable()    do { } while (0)
 247#define hotcpu_notifier(fn, pri)        do { (void)(fn); } while (0)
 248#define __hotcpu_notifier(fn, pri)      do { (void)(fn); } while (0)
 249/* These aren't inline functions due to a GCC bug. */
 250#define register_hotcpu_notifier(nb)    ({ (void)(nb); 0; })
 251#define __register_hotcpu_notifier(nb)  ({ (void)(nb); 0; })
 252#define unregister_hotcpu_notifier(nb)  ({ (void)(nb); })
 253#define __unregister_hotcpu_notifier(nb)        ({ (void)(nb); })
 254#endif          /* CONFIG_HOTPLUG_CPU */
 255
 256#ifdef CONFIG_PM_SLEEP_SMP
 257extern int disable_nonboot_cpus(void);
 258extern void enable_nonboot_cpus(void);
 259#else /* !CONFIG_PM_SLEEP_SMP */
 260static inline int disable_nonboot_cpus(void) { return 0; }
 261static inline void enable_nonboot_cpus(void) {}
 262#endif /* !CONFIG_PM_SLEEP_SMP */
 263
 264enum cpuhp_state {
 265        CPUHP_OFFLINE,
 266        CPUHP_ONLINE,
 267};
 268
 269void cpu_startup_entry(enum cpuhp_state state);
 270void cpu_idle(void);
 271
 272void cpu_idle_poll_ctrl(bool enable);
 273
 274/* Attach to any functions which should be considered cpuidle. */
 275#define __cpuidle       __attribute__((__section__(".cpuidle.text")))
 276
 277bool cpu_in_idle(unsigned long pc);
 278
 279void arch_cpu_idle(void);
 280void arch_cpu_idle_prepare(void);
 281void arch_cpu_idle_enter(void);
 282void arch_cpu_idle_exit(void);
 283void arch_cpu_idle_dead(void);
 284
 285DECLARE_PER_CPU(bool, cpu_dead_idle);
 286
 287int cpu_report_state(int cpu);
 288int cpu_check_up_prepare(int cpu);
 289void cpu_set_state_online(int cpu);
 290#ifdef CONFIG_HOTPLUG_CPU
 291bool cpu_wait_death(unsigned int cpu, int seconds);
 292bool cpu_report_death(void);
 293#endif /* #ifdef CONFIG_HOTPLUG_CPU */
 294
 295#endif /* _LINUX_CPU_H_ */
 296