drivers/base/power/sysfs.c
Source file repositories/reference/linux-study-clean/drivers/base/power/sysfs.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/base/power/sysfs.c- Extension
.c- Size
- 21634 bytes
- Lines
- 836
- Domain
- Driver Families
- Bucket
- drivers/base
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/device.hlinux/kobject.hlinux/string.hlinux/export.hlinux/pm_qos.hlinux/pm_runtime.hlinux/atomic.hlinux/jiffies.hpower.h
Detected Declarations
function control_showfunction control_storefunction runtime_active_time_showfunction runtime_suspended_time_showfunction runtime_status_showfunction autosuspend_delay_ms_showfunction autosuspend_delay_ms_storefunction pm_qos_resume_latency_us_showfunction pm_qos_resume_latency_us_storefunction pm_qos_latency_tolerance_us_showfunction pm_qos_latency_tolerance_us_storefunction pm_qos_no_power_off_showfunction pm_qos_no_power_off_storefunction wakeup_showfunction wakeup_storefunction wakeup_count_showfunction wakeup_active_count_showfunction wakeup_abort_count_showfunction wakeup_expire_count_showfunction wakeup_active_showfunction wakeup_total_time_ms_showfunction wakeup_max_time_ms_showfunction wakeup_last_time_ms_showfunction wakeup_prevent_sleep_time_ms_showfunction dpm_sysfs_wakeup_change_ownerfunction dpm_sysfs_wakeup_change_ownerfunction runtime_usage_showfunction runtime_active_kids_showfunction runtime_enabled_showfunction async_showfunction async_storefunction dpm_sysfs_addfunction dpm_sysfs_change_ownerfunction wakeup_sysfs_addfunction wakeup_sysfs_removefunction pm_qos_sysfs_add_resume_latencyfunction pm_qos_sysfs_remove_resume_latencyfunction pm_qos_sysfs_add_flagsfunction pm_qos_sysfs_remove_flagsfunction pm_qos_sysfs_add_latency_tolerancefunction pm_qos_sysfs_remove_latency_tolerancefunction rpm_sysfs_removefunction dpm_sysfs_removeexport power_group_name
Annotated Snippet
switch (dev->power.runtime_status) {
case RPM_SUSPENDED:
output = "suspended";
break;
case RPM_SUSPENDING:
output = "suspending";
break;
case RPM_RESUMING:
output = "resuming";
break;
case RPM_ACTIVE:
output = "active";
break;
default:
return -EIO;
}
}
return sysfs_emit(buf, "%s\n", output);
}
static DEVICE_ATTR_RO(runtime_status);
static ssize_t autosuspend_delay_ms_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
if (!dev->power.use_autosuspend)
return -EIO;
return sysfs_emit(buf, "%d\n", dev->power.autosuspend_delay);
}
static ssize_t autosuspend_delay_ms_store(struct device *dev,
struct device_attribute *attr, const char *buf, size_t n)
{
long delay;
if (!dev->power.use_autosuspend)
return -EIO;
if (kstrtol(buf, 10, &delay) != 0 || delay != (int) delay)
return -EINVAL;
device_lock(dev);
pm_runtime_set_autosuspend_delay(dev, delay);
device_unlock(dev);
return n;
}
static DEVICE_ATTR_RW(autosuspend_delay_ms);
static ssize_t pm_qos_resume_latency_us_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
s32 value = dev_pm_qos_requested_resume_latency(dev);
if (value == 0)
return sysfs_emit(buf, "n/a\n");
if (value == PM_QOS_RESUME_LATENCY_NO_CONSTRAINT)
value = 0;
return sysfs_emit(buf, "%d\n", value);
}
static ssize_t pm_qos_resume_latency_us_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t n)
{
s32 value;
int ret;
if (!kstrtos32(buf, 0, &value)) {
/*
* Prevent users from writing negative or "no constraint" values
* directly.
*/
if (value < 0 || value == PM_QOS_RESUME_LATENCY_NO_CONSTRAINT)
return -EINVAL;
if (value == 0)
value = PM_QOS_RESUME_LATENCY_NO_CONSTRAINT;
} else if (sysfs_streq(buf, "n/a")) {
value = 0;
} else {
return -EINVAL;
}
ret = dev_pm_qos_update_request(dev->power.qos->resume_latency_req,
value);
Annotation
- Immediate include surface: `linux/device.h`, `linux/kobject.h`, `linux/string.h`, `linux/export.h`, `linux/pm_qos.h`, `linux/pm_runtime.h`, `linux/atomic.h`, `linux/jiffies.h`.
- Detected declarations: `function control_show`, `function control_store`, `function runtime_active_time_show`, `function runtime_suspended_time_show`, `function runtime_status_show`, `function autosuspend_delay_ms_show`, `function autosuspend_delay_ms_store`, `function pm_qos_resume_latency_us_show`, `function pm_qos_resume_latency_us_store`, `function pm_qos_latency_tolerance_us_show`.
- Atlas domain: Driver Families / drivers/base.
- Implementation status: integration implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- 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.