drivers/cpuidle/sysfs.c
Source file repositories/reference/linux-study-clean/drivers/cpuidle/sysfs.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/cpuidle/sysfs.c- Extension
.c- Size
- 19621 bytes
- Lines
- 748
- Domain
- Driver Families
- Bucket
- drivers/cpuidle
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/cpuidle.hlinux/sysfs.hlinux/slab.hlinux/cpu.hlinux/completion.hlinux/capability.hlinux/device.hlinux/kobject.hcpuidle.h
Detected Declarations
struct cpuidle_attrstruct cpuidle_device_kobjstruct cpuidle_state_attrstruct cpuidle_state_kobjstruct cpuidle_driver_kobjstruct cpuidle_driver_attrfunction show_available_governorsfunction show_current_driverfunction show_current_governorfunction store_current_governorfunction cpuidle_add_interfacefunction cpuidle_remove_interfacefunction cpuidle_showfunction cpuidle_storefunction cpuidle_sysfs_releasefunction show_state_timefunction show_state_disablefunction store_state_disablefunction show_state_default_statusfunction cpuidle_add_s2idle_attr_groupfunction cpuidle_remove_s2idle_attr_groupfunction cpuidle_add_s2idle_attr_groupfunction cpuidle_state_storefunction cpuidle_state_sysfs_releasefunction cpuidle_free_state_kobjfunction cpuidle_add_state_sysfsfunction cpuidle_remove_state_sysfsfunction show_driver_namefunction cpuidle_driver_sysfs_releasefunction cpuidle_driver_showfunction cpuidle_driver_storefunction cpuidle_add_driver_sysfsfunction cpuidle_remove_driver_sysfsfunction cpuidle_add_driver_sysfsfunction cpuidle_remove_driver_sysfsfunction cpuidle_add_device_sysfsfunction cpuidle_remove_device_sysfsfunction cpuidle_add_sysfsfunction cpuidle_remove_sysfs
Annotated Snippet
struct cpuidle_attr {
struct attribute attr;
ssize_t (*show)(struct cpuidle_device *, char *);
ssize_t (*store)(struct cpuidle_device *, const char *, size_t count);
};
#define attr_to_cpuidleattr(a) container_of(a, struct cpuidle_attr, attr)
struct cpuidle_device_kobj {
struct cpuidle_device *dev;
struct completion kobj_unregister;
struct kobject kobj;
};
static inline struct cpuidle_device *to_cpuidle_device(struct kobject *kobj)
{
struct cpuidle_device_kobj *kdev =
container_of(kobj, struct cpuidle_device_kobj, kobj);
return kdev->dev;
}
static ssize_t cpuidle_show(struct kobject *kobj, struct attribute *attr,
char *buf)
{
int ret = -EIO;
struct cpuidle_device *dev = to_cpuidle_device(kobj);
struct cpuidle_attr *cattr = attr_to_cpuidleattr(attr);
if (cattr->show) {
mutex_lock(&cpuidle_lock);
ret = cattr->show(dev, buf);
mutex_unlock(&cpuidle_lock);
}
return ret;
}
static ssize_t cpuidle_store(struct kobject *kobj, struct attribute *attr,
const char *buf, size_t count)
{
int ret = -EIO;
struct cpuidle_device *dev = to_cpuidle_device(kobj);
struct cpuidle_attr *cattr = attr_to_cpuidleattr(attr);
if (cattr->store) {
mutex_lock(&cpuidle_lock);
ret = cattr->store(dev, buf, count);
mutex_unlock(&cpuidle_lock);
}
return ret;
}
static const struct sysfs_ops cpuidle_sysfs_ops = {
.show = cpuidle_show,
.store = cpuidle_store,
};
static void cpuidle_sysfs_release(struct kobject *kobj)
{
struct cpuidle_device_kobj *kdev =
container_of(kobj, struct cpuidle_device_kobj, kobj);
complete(&kdev->kobj_unregister);
}
static const struct kobj_type ktype_cpuidle = {
.sysfs_ops = &cpuidle_sysfs_ops,
.release = cpuidle_sysfs_release,
};
struct cpuidle_state_attr {
struct attribute attr;
ssize_t (*show)(struct cpuidle_state *, \
struct cpuidle_state_usage *, char *);
ssize_t (*store)(struct cpuidle_state *, \
struct cpuidle_state_usage *, const char *, size_t);
};
#define define_one_state_ro(_name, show) \
static struct cpuidle_state_attr attr_##_name = __ATTR(_name, 0444, show, NULL)
#define define_one_state_rw(_name, show, store) \
static struct cpuidle_state_attr attr_##_name = __ATTR(_name, 0644, show, store)
#define define_show_state_function(_name) \
static ssize_t show_state_##_name(struct cpuidle_state *state, \
struct cpuidle_state_usage *state_usage, char *buf) \
{ \
return sysfs_emit(buf, "%u\n", state->_name);\
}
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/cpuidle.h`, `linux/sysfs.h`, `linux/slab.h`, `linux/cpu.h`, `linux/completion.h`, `linux/capability.h`, `linux/device.h`.
- Detected declarations: `struct cpuidle_attr`, `struct cpuidle_device_kobj`, `struct cpuidle_state_attr`, `struct cpuidle_state_kobj`, `struct cpuidle_driver_kobj`, `struct cpuidle_driver_attr`, `function show_available_governors`, `function show_current_driver`, `function show_current_governor`, `function store_current_governor`.
- Atlas domain: Driver Families / drivers/cpuidle.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.