aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Travis <travis@sgi.com>2008-04-08 14:43:04 -0400
committerIngo Molnar <mingo@elte.hu>2008-04-19 13:44:59 -0400
commit9d1fe3236a1d64ab687e16b4cbbaa1383352a2c1 (patch)
tree059cd312cbc2253fd1e00809a5a937ba45120b99
parent39106dcf85285e78f3b290022122c76f851379b8 (diff)
cpumask: add show cpu map functions
* Add cpu_sysdev_class functions to display the following maps with cpulist_scnprintf(). cpu_online_map cpu_present_map cpu_possible_map * Small change to include/linux/sysdev.h to allow the attribute name and label to be different (to avoid collision with the "attr_online" entry for bringing cpus on- and off-line.) Cc: H. Peter Anvin <hpa@zytor.com> Signed-off-by: Mike Travis <travis@sgi.com> Signed-off-by: Ingo Molnar <mingo@elte.hu>
-rw-r--r--drivers/base/cpu.c48
-rw-r--r--include/linux/sysdev.h17
2 files changed, 59 insertions, 6 deletions
diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c
index 499b003f9278..2c76afff3b15 100644
--- a/drivers/base/cpu.c
+++ b/drivers/base/cpu.c
@@ -103,6 +103,51 @@ static SYSDEV_ATTR(crash_notes, 0400, show_crash_notes, NULL);
103#endif 103#endif
104 104
105/* 105/*
106 * Print cpu online, possible, present, and system maps
107 */
108static ssize_t print_cpus_map(char *buf, cpumask_t *map)
109{
110 int n = cpulist_scnprintf(buf, PAGE_SIZE-2, *map);
111
112 buf[n++] = '\n';
113 buf[n] = '\0';
114 return n;
115}
116
117#define print_cpus_func(type) \
118static ssize_t print_cpus_##type(struct sysdev_class *class, char *buf) \
119{ \
120 return print_cpus_map(buf, &cpu_##type##_map); \
121} \
122struct sysdev_class_attribute attr_##type##_map = \
123 _SYSDEV_CLASS_ATTR(type, 0444, print_cpus_##type, NULL)
124
125print_cpus_func(online);
126print_cpus_func(possible);
127print_cpus_func(present);
128
129struct sysdev_class_attribute *cpu_state_attr[] = {
130 &attr_online_map,
131 &attr_possible_map,
132 &attr_present_map,
133};
134
135static int cpu_states_init(void)
136{
137 int i;
138 int err = 0;
139
140 for (i = 0; i < ARRAY_SIZE(cpu_state_attr); i++) {
141 int ret;
142 ret = sysdev_class_create_file(&cpu_sysdev_class,
143 cpu_state_attr[i]);
144 if (!err)
145 err = ret;
146 }
147 return err;
148}
149
150/*
106 * register_cpu - Setup a sysfs device for a CPU. 151 * register_cpu - Setup a sysfs device for a CPU.
107 * @cpu - cpu->hotpluggable field set to 1 will generate a control file in 152 * @cpu - cpu->hotpluggable field set to 1 will generate a control file in
108 * sysfs for this CPU. 153 * sysfs for this CPU.
@@ -147,6 +192,9 @@ int __init cpu_dev_init(void)
147 int err; 192 int err;
148 193
149 err = sysdev_class_register(&cpu_sysdev_class); 194 err = sysdev_class_register(&cpu_sysdev_class);
195 if (!err)
196 err = cpu_states_init();
197
150#if defined(CONFIG_SCHED_MC) || defined(CONFIG_SCHED_SMT) 198#if defined(CONFIG_SCHED_MC) || defined(CONFIG_SCHED_SMT)
151 if (!err) 199 if (!err)
152 err = sched_create_sysfs_power_savings_entries(&cpu_sysdev_class); 200 err = sched_create_sysfs_power_savings_entries(&cpu_sysdev_class);
diff --git a/include/linux/sysdev.h b/include/linux/sysdev.h
index f752e73bf977..f2767bc6b735 100644
--- a/include/linux/sysdev.h
+++ b/include/linux/sysdev.h
@@ -45,12 +45,16 @@ struct sysdev_class_attribute {
45 ssize_t (*store)(struct sysdev_class *, const char *, size_t); 45 ssize_t (*store)(struct sysdev_class *, const char *, size_t);
46}; 46};
47 47
48#define SYSDEV_CLASS_ATTR(_name,_mode,_show,_store) \ 48#define _SYSDEV_CLASS_ATTR(_name,_mode,_show,_store) \
49struct sysdev_class_attribute attr_##_name = { \ 49{ \
50 .attr = {.name = __stringify(_name), .mode = _mode }, \ 50 .attr = {.name = __stringify(_name), .mode = _mode }, \
51 .show = _show, \ 51 .show = _show, \
52 .store = _store, \ 52 .store = _store, \
53}; 53}
54
55#define SYSDEV_CLASS_ATTR(_name,_mode,_show,_store) \
56 struct sysdev_class_attribute attr_##_name = \
57 _SYSDEV_CLASS_ATTR(_name,_mode,_show,_store)
54 58
55 59
56extern int sysdev_class_register(struct sysdev_class *); 60extern int sysdev_class_register(struct sysdev_class *);
@@ -100,15 +104,16 @@ struct sysdev_attribute {
100}; 104};
101 105
102 106
103#define _SYSDEV_ATTR(_name,_mode,_show,_store) \ 107#define _SYSDEV_ATTR(_name, _mode, _show, _store) \
104{ \ 108{ \
105 .attr = { .name = __stringify(_name), .mode = _mode }, \ 109 .attr = { .name = __stringify(_name), .mode = _mode }, \
106 .show = _show, \ 110 .show = _show, \
107 .store = _store, \ 111 .store = _store, \
108} 112}
109 113
110#define SYSDEV_ATTR(_name,_mode,_show,_store) \ 114#define SYSDEV_ATTR(_name, _mode, _show, _store) \
111struct sysdev_attribute attr_##_name = _SYSDEV_ATTR(_name,_mode,_show,_store); 115 struct sysdev_attribute attr_##_name = \
116 _SYSDEV_ATTR(_name, _mode, _show, _store);
112 117
113extern int sysdev_create_file(struct sys_device *, struct sysdev_attribute *); 118extern int sysdev_create_file(struct sys_device *, struct sysdev_attribute *);
114extern void sysdev_remove_file(struct sys_device *, struct sysdev_attribute *); 119extern void sysdev_remove_file(struct sys_device *, struct sysdev_attribute *);