diff options
-rw-r--r-- | drivers/base/cpu.c | 48 | ||||
-rw-r--r-- | include/linux/sysdev.h | 17 |
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 | */ | ||
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 | * 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) \ |
49 | struct 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 | ||
56 | extern int sysdev_class_register(struct sysdev_class *); | 60 | extern 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) \ |
111 | struct 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 | ||
113 | extern int sysdev_create_file(struct sys_device *, struct sysdev_attribute *); | 118 | extern int sysdev_create_file(struct sys_device *, struct sysdev_attribute *); |
114 | extern void sysdev_remove_file(struct sys_device *, struct sysdev_attribute *); | 119 | extern void sysdev_remove_file(struct sys_device *, struct sysdev_attribute *); |