9 #include <linux/kernel.h>
12 #include <linux/slab.h>
14 #include <linux/capability.h>
18 static unsigned int sysfs_switch;
24 __setup(
"cpuidle_sysfs_switch", cpuidle_sysfs_setup);
53 spin_lock(&cpuidle_driver_lock);
58 spin_unlock(&cpuidle_driver_lock);
81 const char *buf,
size_t count)
88 if (!len || len >=
sizeof(gov_name))
91 memcpy(gov_name, buf, len);
93 if (gov_name[len - 1] ==
'\n')
94 gov_name[--len] =
'\0';
114 static DEVICE_ATTR(current_governor_ro, 0444, show_current_governor,
NULL);
116 static struct attribute *cpuidle_default_attrs[] = {
117 &dev_attr_current_driver.attr,
118 &dev_attr_current_governor_ro.attr,
122 static DEVICE_ATTR(available_governors, 0444, show_available_governors,
NULL);
123 static DEVICE_ATTR(current_governor, 0644, show_current_governor,
124 store_current_governor);
126 static struct attribute *cpuidle_switch_attrs[] = {
127 &dev_attr_available_governors.attr,
128 &dev_attr_current_driver.attr,
129 &dev_attr_current_governor.attr,
134 .attrs = cpuidle_default_attrs,
144 cpuidle_attr_group.
attrs = cpuidle_switch_attrs;
163 #define define_one_ro(_name, show) \
164 static struct cpuidle_attr attr_##_name = __ATTR(_name, 0444, show, NULL)
165 #define define_one_rw(_name, show, store) \
166 static struct cpuidle_attr attr_##_name = __ATTR(_name, 0644, show, store)
168 #define kobj_to_cpuidledev(k) container_of(k, struct cpuidle_device, kobj)
169 #define attr_to_cpuidleattr(a) container_of(a, struct cpuidle_attr, attr)
178 ret = cattr->
show(dev, buf);
185 const char * buf,
size_t count)
193 ret = cattr->
store(dev, buf, count);
199 static const struct sysfs_ops cpuidle_sysfs_ops = {
200 .show = cpuidle_show,
201 .store = cpuidle_store,
204 static void cpuidle_sysfs_release(
struct kobject *kobj)
211 static struct kobj_type ktype_cpuidle = {
212 .sysfs_ops = &cpuidle_sysfs_ops,
213 .release = cpuidle_sysfs_release,
224 #define define_one_state_ro(_name, show) \
225 static struct cpuidle_state_attr attr_##_name = __ATTR(_name, 0444, show, NULL)
227 #define define_one_state_rw(_name, show, store) \
228 static struct cpuidle_state_attr attr_##_name = __ATTR(_name, 0644, show, store)
230 #define define_show_state_function(_name) \
231 static ssize_t show_state_##_name(struct cpuidle_state *state, \
232 struct cpuidle_state_usage *state_usage, char *buf) \
234 return sprintf(buf, "%u\n", state->_name);\
237 #define define_store_state_ull_function(_name) \
238 static ssize_t store_state_##_name(struct cpuidle_state *state, \
239 struct cpuidle_state_usage *state_usage, \
240 const char *buf, size_t size) \
242 unsigned long long value; \
244 if (!capable(CAP_SYS_ADMIN)) \
246 err = kstrtoull(buf, 0, &value); \
250 state_usage->_name = 1; \
252 state_usage->_name = 0; \
256 #define define_show_state_ull_function(_name) \
257 static ssize_t show_state_##_name(struct cpuidle_state *state, \
258 struct cpuidle_state_usage *state_usage, char *buf) \
260 return sprintf(buf, "%llu\n", state_usage->_name);\
263 #define define_show_state_str_function(_name) \
264 static ssize_t show_state_##_name(struct cpuidle_state *state, \
265 struct cpuidle_state_usage *state_usage, char *buf) \
267 if (state->_name[0] == '\0')\
268 return sprintf(buf, "<null>\n");\
269 return sprintf(buf, "%s\n", state->_name);\
300 #define kobj_to_state_obj(k) container_of(k, struct cpuidle_state_kobj, kobj)
301 #define kobj_to_state(k) (kobj_to_state_obj(k)->state)
302 #define kobj_to_state_usage(k) (kobj_to_state_obj(k)->state_usage)
303 #define attr_to_stateattr(a) container_of(a, struct cpuidle_state_attr, attr)
313 ret = cattr->
show(state, state_usage, buf);
327 ret = cattr->
store(state, state_usage, buf, size);
332 static const struct sysfs_ops cpuidle_state_sysfs_ops = {
333 .show = cpuidle_state_show,
334 .store = cpuidle_state_store,
337 static void cpuidle_state_sysfs_release(
struct kobject *kobj)
344 static struct kobj_type ktype_state_cpuidle = {
345 .sysfs_ops = &cpuidle_state_sysfs_ops,
346 .default_attrs = cpuidle_state_default_attrs,
347 .release = cpuidle_state_sysfs_release,
390 for (i = i - 1; i >= 0; i--)
391 cpuidle_free_state_kobj(device, i);
404 cpuidle_free_state_kobj(device, i);
413 int cpu = cpu_dev->
id;
417 dev =
per_cpu(cpuidle_devices, cpu);
431 int cpu = cpu_dev->
id;
434 dev =
per_cpu(cpuidle_devices, cpu);