Commit a59d2e4e authored by Rusty Russell's avatar Rusty Russell Committed by Linus Torvalds

[PATCH] minor cleanups for hotplug CPUs

Note that without CONFIG_HOTPLUG_CPU, online cpus == possible cpus, so
substitutions are a noop.

- Changes show_stat to print out stats for every possible cpu, not
  just online CPUs.

- Allocate mem in stat_open on possible, not online_cpus.

- Add conventient macros to cpu.h: especially cpu_is_offline() for
  testing if a cpu is still online.

- Add a num_possible_cpus() similar to num_online_cpus(), and define
  cpu_possible_mask for UP.

- Allow printk on down cpus once system is running.

- Mask cpumask with possible, not online cpus, for sys_getaffinity().
parent 33a7ddaa
...@@ -389,7 +389,7 @@ int show_stat(struct seq_file *p, void *v) ...@@ -389,7 +389,7 @@ int show_stat(struct seq_file *p, void *v)
jiffies_to_clock_t(iowait), jiffies_to_clock_t(iowait),
jiffies_to_clock_t(irq), jiffies_to_clock_t(irq),
jiffies_to_clock_t(softirq)); jiffies_to_clock_t(softirq));
for_each_online_cpu(i) { for_each_cpu(i) {
seq_printf(p, "cpu%d %u %u %u %u %u %u %u\n", seq_printf(p, "cpu%d %u %u %u %u %u %u %u\n",
i, i,
jiffies_to_clock_t(kstat_cpu(i).cpustat.user), jiffies_to_clock_t(kstat_cpu(i).cpustat.user),
...@@ -424,7 +424,7 @@ int show_stat(struct seq_file *p, void *v) ...@@ -424,7 +424,7 @@ int show_stat(struct seq_file *p, void *v)
static int stat_open(struct inode *inode, struct file *file) static int stat_open(struct inode *inode, struct file *file)
{ {
unsigned size = 4096 * (1 + num_online_cpus() / 32); unsigned size = 4096 * (1 + num_possible_cpus() / 32);
char *buf; char *buf;
struct seq_file *m; struct seq_file *m;
int res; int res;
......
...@@ -21,6 +21,8 @@ ...@@ -21,6 +21,8 @@
#include <linux/sysdev.h> #include <linux/sysdev.h>
#include <linux/node.h> #include <linux/node.h>
#include <linux/compiler.h>
#include <linux/cpumask.h>
#include <asm/semaphore.h> #include <asm/semaphore.h>
struct cpu { struct cpu {
...@@ -56,9 +58,20 @@ extern struct sysdev_class cpu_sysdev_class; ...@@ -56,9 +58,20 @@ extern struct sysdev_class cpu_sysdev_class;
extern struct semaphore cpucontrol; extern struct semaphore cpucontrol;
#define lock_cpu_hotplug() down(&cpucontrol) #define lock_cpu_hotplug() down(&cpucontrol)
#define unlock_cpu_hotplug() up(&cpucontrol) #define unlock_cpu_hotplug() up(&cpucontrol)
#define lock_cpu_hotplug_interruptible() down_interruptible(&cpucontrol)
#define hotcpu_notifier(fn, pri) { \
static struct notifier_block fn##_nb = { fn, pri }; \
register_cpu_notifier(&fn##_nb); \
}
#define cpu_is_offline(cpu) unlikely(!cpu_online(cpu))
#else #else
#define lock_cpu_hotplug() do { } while (0) #define lock_cpu_hotplug() do { } while (0)
#define unlock_cpu_hotplug() do { } while (0) #define unlock_cpu_hotplug() do { } while (0)
#define lock_cpu_hotplug_interruptible() 0
#define hotcpu_notifier(fn, pri)
/* CPUs don't go offline once they're online w/o CONFIG_HOTPLUG_CPU */
#define cpu_is_offline(cpu) 0
#endif #endif
#endif /* _LINUX_CPU_H_ */ #endif /* _LINUX_CPU_H_ */
...@@ -12,6 +12,7 @@ extern cpumask_t cpu_online_map; ...@@ -12,6 +12,7 @@ extern cpumask_t cpu_online_map;
extern cpumask_t cpu_possible_map; extern cpumask_t cpu_possible_map;
#define num_online_cpus() cpus_weight(cpu_online_map) #define num_online_cpus() cpus_weight(cpu_online_map)
#define num_possible_cpus() cpus_weight(cpu_possible_map)
#define cpu_online(cpu) cpu_isset(cpu, cpu_online_map) #define cpu_online(cpu) cpu_isset(cpu, cpu_online_map)
#define cpu_possible(cpu) cpu_isset(cpu, cpu_possible_map) #define cpu_possible(cpu) cpu_isset(cpu, cpu_possible_map)
...@@ -24,7 +25,9 @@ extern cpumask_t cpu_possible_map; ...@@ -24,7 +25,9 @@ extern cpumask_t cpu_possible_map;
#define for_each_online_cpu(cpu) for_each_cpu_mask(cpu, cpu_online_map) #define for_each_online_cpu(cpu) for_each_cpu_mask(cpu, cpu_online_map)
#else #else
#define cpu_online_map cpumask_of_cpu(0) #define cpu_online_map cpumask_of_cpu(0)
#define cpu_possible_map cpumask_of_cpu(0)
#define num_online_cpus() 1 #define num_online_cpus() 1
#define num_possible_cpus() 1
#define cpu_online(cpu) ({ BUG_ON((cpu) != 0); 1; }) #define cpu_online(cpu) ({ BUG_ON((cpu) != 0); 1; })
#define cpu_possible(cpu) ({ BUG_ON((cpu) != 0); 1; }) #define cpu_possible(cpu) ({ BUG_ON((cpu) != 0); 1; })
......
...@@ -522,7 +522,7 @@ asmlinkage int printk(const char *fmt, ...) ...@@ -522,7 +522,7 @@ asmlinkage int printk(const char *fmt, ...)
log_level_unknown = 1; log_level_unknown = 1;
} }
if (!cpu_online(smp_processor_id())) { if (!cpu_online(smp_processor_id()) && !system_running) {
/* /*
* Some console drivers may assume that per-cpu resources have * Some console drivers may assume that per-cpu resources have
* been allocated. So don't allow them to be called by this * been allocated. So don't allow them to be called by this
......
...@@ -2366,7 +2366,7 @@ asmlinkage long sys_sched_getaffinity(pid_t pid, unsigned int len, ...@@ -2366,7 +2366,7 @@ asmlinkage long sys_sched_getaffinity(pid_t pid, unsigned int len,
goto out_unlock; goto out_unlock;
retval = 0; retval = 0;
cpus_and(mask, p->cpus_allowed, cpu_online_map); cpus_and(mask, p->cpus_allowed, cpu_possible_map);
out_unlock: out_unlock:
read_unlock(&tasklist_lock); read_unlock(&tasklist_lock);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment