Commit 9d1fe3236a1d64ab687e16b4cbbaa1383352a2c1
Committed by
Ingo Molnar
1 parent
39106dcf85
Exists in
master
and in
7 other branches
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>
Showing 2 changed files with 59 additions and 6 deletions Side-by-side Diff
drivers/base/cpu.c
... | ... | @@ -103,6 +103,51 @@ |
103 | 103 | #endif |
104 | 104 | |
105 | 105 | /* |
106 | + * Print cpu online, possible, present, and system maps | |
107 | + */ | |
108 | +static 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) \ | |
118 | +static ssize_t print_cpus_##type(struct sysdev_class *class, char *buf) \ | |
119 | +{ \ | |
120 | + return print_cpus_map(buf, &cpu_##type##_map); \ | |
121 | +} \ | |
122 | +struct sysdev_class_attribute attr_##type##_map = \ | |
123 | + _SYSDEV_CLASS_ATTR(type, 0444, print_cpus_##type, NULL) | |
124 | + | |
125 | +print_cpus_func(online); | |
126 | +print_cpus_func(possible); | |
127 | +print_cpus_func(present); | |
128 | + | |
129 | +struct sysdev_class_attribute *cpu_state_attr[] = { | |
130 | + &attr_online_map, | |
131 | + &attr_possible_map, | |
132 | + &attr_present_map, | |
133 | +}; | |
134 | + | |
135 | +static 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 | 151 | * register_cpu - Setup a sysfs device for a CPU. |
107 | 152 | * @cpu - cpu->hotpluggable field set to 1 will generate a control file in |
108 | 153 | * sysfs for this CPU. |
... | ... | @@ -147,6 +192,9 @@ |
147 | 192 | int err; |
148 | 193 | |
149 | 194 | err = sysdev_class_register(&cpu_sysdev_class); |
195 | + if (!err) | |
196 | + err = cpu_states_init(); | |
197 | + | |
150 | 198 | #if defined(CONFIG_SCHED_MC) || defined(CONFIG_SCHED_SMT) |
151 | 199 | if (!err) |
152 | 200 | err = sched_create_sysfs_power_savings_entries(&cpu_sysdev_class); |
include/linux/sysdev.h
... | ... | @@ -45,14 +45,18 @@ |
45 | 45 | ssize_t (*store)(struct sysdev_class *, const char *, size_t); |
46 | 46 | }; |
47 | 47 | |
48 | -#define SYSDEV_CLASS_ATTR(_name,_mode,_show,_store) \ | |
49 | -struct sysdev_class_attribute attr_##_name = { \ | |
48 | +#define _SYSDEV_CLASS_ATTR(_name,_mode,_show,_store) \ | |
49 | +{ \ | |
50 | 50 | .attr = {.name = __stringify(_name), .mode = _mode }, \ |
51 | 51 | .show = _show, \ |
52 | 52 | .store = _store, \ |
53 | -}; | |
53 | +} | |
54 | 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) | |
55 | 58 | |
59 | + | |
56 | 60 | extern int sysdev_class_register(struct sysdev_class *); |
57 | 61 | extern void sysdev_class_unregister(struct sysdev_class *); |
58 | 62 | |
59 | 63 | |
... | ... | @@ -100,15 +104,16 @@ |
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 | 109 | .attr = { .name = __stringify(_name), .mode = _mode }, \ |
106 | 110 | .show = _show, \ |
107 | 111 | .store = _store, \ |
108 | 112 | } |
109 | 113 | |
110 | -#define SYSDEV_ATTR(_name,_mode,_show,_store) \ | |
111 | -struct sysdev_attribute attr_##_name = _SYSDEV_ATTR(_name,_mode,_show,_store); | |
114 | +#define SYSDEV_ATTR(_name, _mode, _show, _store) \ | |
115 | + struct sysdev_attribute attr_##_name = \ | |
116 | + _SYSDEV_ATTR(_name, _mode, _show, _store); | |
112 | 117 | |
113 | 118 | extern int sysdev_create_file(struct sys_device *, struct sysdev_attribute *); |
114 | 119 | extern void sysdev_remove_file(struct sys_device *, struct sysdev_attribute *); |