sysfs.c (7483d45f0aee3afc0646d185cabd4af9f6cab58c) | sysfs.c (3a53396b0381ec9d5180fd8fe7a681c8ce95fd9a) |
---|---|
1/* 2 * sysfs.c - sysfs support 3 * 4 * (C) 2006-2007 Shaohua Li <shaohua.li@intel.com> 5 * 6 * This code is licenced under the GPL. 7 */ 8 9#include <linux/kernel.h> 10#include <linux/cpuidle.h> 11#include <linux/sysfs.h> 12#include <linux/slab.h> 13#include <linux/cpu.h> | 1/* 2 * sysfs.c - sysfs support 3 * 4 * (C) 2006-2007 Shaohua Li <shaohua.li@intel.com> 5 * 6 * This code is licenced under the GPL. 7 */ 8 9#include <linux/kernel.h> 10#include <linux/cpuidle.h> 11#include <linux/sysfs.h> 12#include <linux/slab.h> 13#include <linux/cpu.h> |
14#include <linux/capability.h> |
|
14 15#include "cpuidle.h" 16 17static unsigned int sysfs_switch; 18static int __init cpuidle_sysfs_setup(char *unused) 19{ 20 sysfs_switch = 1; 21 return 1; --- 195 unchanged lines hidden (view full) --- 217 ssize_t (*show)(struct cpuidle_state *, \ 218 struct cpuidle_state_usage *, char *); 219 ssize_t (*store)(struct cpuidle_state *, const char *, size_t); 220}; 221 222#define define_one_state_ro(_name, show) \ 223static struct cpuidle_state_attr attr_##_name = __ATTR(_name, 0444, show, NULL) 224 | 15 16#include "cpuidle.h" 17 18static unsigned int sysfs_switch; 19static int __init cpuidle_sysfs_setup(char *unused) 20{ 21 sysfs_switch = 1; 22 return 1; --- 195 unchanged lines hidden (view full) --- 218 ssize_t (*show)(struct cpuidle_state *, \ 219 struct cpuidle_state_usage *, char *); 220 ssize_t (*store)(struct cpuidle_state *, const char *, size_t); 221}; 222 223#define define_one_state_ro(_name, show) \ 224static struct cpuidle_state_attr attr_##_name = __ATTR(_name, 0444, show, NULL) 225 |
226#define define_one_state_rw(_name, show, store) \ 227static struct cpuidle_state_attr attr_##_name = __ATTR(_name, 0644, show, store) 228 |
|
225#define define_show_state_function(_name) \ 226static ssize_t show_state_##_name(struct cpuidle_state *state, \ 227 struct cpuidle_state_usage *state_usage, char *buf) \ 228{ \ 229 return sprintf(buf, "%u\n", state->_name);\ 230} 231 | 229#define define_show_state_function(_name) \ 230static ssize_t show_state_##_name(struct cpuidle_state *state, \ 231 struct cpuidle_state_usage *state_usage, char *buf) \ 232{ \ 233 return sprintf(buf, "%u\n", state->_name);\ 234} 235 |
236#define define_store_state_function(_name) \ 237static ssize_t store_state_##_name(struct cpuidle_state *state, \ 238 const char *buf, size_t size) \ 239{ \ 240 long value; \ 241 int err; \ 242 if (!capable(CAP_SYS_ADMIN)) \ 243 return -EPERM; \ 244 err = kstrtol(buf, 0, &value); \ 245 if (err) \ 246 return err; \ 247 if (value) \ 248 state->disable = 1; \ 249 else \ 250 state->disable = 0; \ 251 return size; \ 252} 253 |
|
232#define define_show_state_ull_function(_name) \ 233static ssize_t show_state_##_name(struct cpuidle_state *state, \ 234 struct cpuidle_state_usage *state_usage, char *buf) \ 235{ \ 236 return sprintf(buf, "%llu\n", state_usage->_name);\ 237} 238 239#define define_show_state_str_function(_name) \ --- 6 unchanged lines hidden (view full) --- 246} 247 248define_show_state_function(exit_latency) 249define_show_state_function(power_usage) 250define_show_state_ull_function(usage) 251define_show_state_ull_function(time) 252define_show_state_str_function(name) 253define_show_state_str_function(desc) | 254#define define_show_state_ull_function(_name) \ 255static ssize_t show_state_##_name(struct cpuidle_state *state, \ 256 struct cpuidle_state_usage *state_usage, char *buf) \ 257{ \ 258 return sprintf(buf, "%llu\n", state_usage->_name);\ 259} 260 261#define define_show_state_str_function(_name) \ --- 6 unchanged lines hidden (view full) --- 268} 269 270define_show_state_function(exit_latency) 271define_show_state_function(power_usage) 272define_show_state_ull_function(usage) 273define_show_state_ull_function(time) 274define_show_state_str_function(name) 275define_show_state_str_function(desc) |
276define_show_state_function(disable) 277define_store_state_function(disable) |
|
254 255define_one_state_ro(name, show_state_name); 256define_one_state_ro(desc, show_state_desc); 257define_one_state_ro(latency, show_state_exit_latency); 258define_one_state_ro(power, show_state_power_usage); 259define_one_state_ro(usage, show_state_usage); 260define_one_state_ro(time, show_state_time); | 278 279define_one_state_ro(name, show_state_name); 280define_one_state_ro(desc, show_state_desc); 281define_one_state_ro(latency, show_state_exit_latency); 282define_one_state_ro(power, show_state_power_usage); 283define_one_state_ro(usage, show_state_usage); 284define_one_state_ro(time, show_state_time); |
285define_one_state_rw(disable, show_state_disable, store_state_disable); |
|
261 262static struct attribute *cpuidle_state_default_attrs[] = { 263 &attr_name.attr, 264 &attr_desc.attr, 265 &attr_latency.attr, 266 &attr_power.attr, 267 &attr_usage.attr, 268 &attr_time.attr, | 286 287static struct attribute *cpuidle_state_default_attrs[] = { 288 &attr_name.attr, 289 &attr_desc.attr, 290 &attr_latency.attr, 291 &attr_power.attr, 292 &attr_usage.attr, 293 &attr_time.attr, |
294 &attr_disable.attr, |
|
269 NULL 270}; 271 272#define kobj_to_state_obj(k) container_of(k, struct cpuidle_state_kobj, kobj) 273#define kobj_to_state(k) (kobj_to_state_obj(k)->state) 274#define kobj_to_state_usage(k) (kobj_to_state_obj(k)->state_usage) 275#define attr_to_stateattr(a) container_of(a, struct cpuidle_state_attr, attr) 276static ssize_t cpuidle_state_show(struct kobject * kobj, --- 5 unchanged lines hidden (view full) --- 282 struct cpuidle_state_attr * cattr = attr_to_stateattr(attr); 283 284 if (cattr->show) 285 ret = cattr->show(state, state_usage, buf); 286 287 return ret; 288} 289 | 295 NULL 296}; 297 298#define kobj_to_state_obj(k) container_of(k, struct cpuidle_state_kobj, kobj) 299#define kobj_to_state(k) (kobj_to_state_obj(k)->state) 300#define kobj_to_state_usage(k) (kobj_to_state_obj(k)->state_usage) 301#define attr_to_stateattr(a) container_of(a, struct cpuidle_state_attr, attr) 302static ssize_t cpuidle_state_show(struct kobject * kobj, --- 5 unchanged lines hidden (view full) --- 308 struct cpuidle_state_attr * cattr = attr_to_stateattr(attr); 309 310 if (cattr->show) 311 ret = cattr->show(state, state_usage, buf); 312 313 return ret; 314} 315 |
316static ssize_t cpuidle_state_store(struct kobject *kobj, 317 struct attribute *attr, const char *buf, size_t size) 318{ 319 int ret = -EIO; 320 struct cpuidle_state *state = kobj_to_state(kobj); 321 struct cpuidle_state_attr *cattr = attr_to_stateattr(attr); 322 323 if (cattr->store) 324 ret = cattr->store(state, buf, size); 325 326 return ret; 327} 328 |
|
290static const struct sysfs_ops cpuidle_state_sysfs_ops = { 291 .show = cpuidle_state_show, | 329static const struct sysfs_ops cpuidle_state_sysfs_ops = { 330 .show = cpuidle_state_show, |
331 .store = cpuidle_state_store, |
|
292}; 293 294static void cpuidle_state_sysfs_release(struct kobject *kobj) 295{ 296 struct cpuidle_state_kobj *state_obj = kobj_to_state_obj(kobj); 297 298 complete(&state_obj->kobj_unregister); 299} --- 94 unchanged lines hidden --- | 332}; 333 334static void cpuidle_state_sysfs_release(struct kobject *kobj) 335{ 336 struct cpuidle_state_kobj *state_obj = kobj_to_state_obj(kobj); 337 338 complete(&state_obj->kobj_unregister); 339} --- 94 unchanged lines hidden --- |