drivers/base/power/qos.c
Source file repositories/reference/linux-study-clean/drivers/base/power/qos.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/base/power/qos.c- Extension
.c- Size
- 26300 bytes
- Lines
- 984
- 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.
- 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/pm_qos.hlinux/spinlock.hlinux/slab.hlinux/device.hlinux/mutex.hlinux/export.hlinux/pm_runtime.hlinux/err.htrace/events/power.hpower.h
Detected Declarations
function __dev_pm_qos_flagsfunction dev_pm_qos_flagsfunction __dev_pm_qos_resume_latencyfunction dev_pm_qos_read_valuefunction apply_constraintfunction dev_pm_qos_constraints_allocatefunction device_pm_lockfunction dev_pm_qos_invalid_req_typefunction __dev_pm_qos_add_requestfunction dev_pm_qos_add_requestfunction __dev_pm_qos_update_requestfunction dev_pm_qos_update_requestfunction __dev_pm_qos_remove_requestfunction dev_pm_qos_remove_requestfunction createdfunction dev_pm_qos_remove_notifierfunction dev_pm_qos_add_ancestor_requestfunction __dev_pm_qos_drop_user_requestfunction dev_pm_qos_drop_user_requestfunction dev_pm_qos_expose_latency_limitfunction __dev_pm_qos_hide_latency_limitfunction dev_pm_qos_hide_latency_limitfunction dev_pm_qos_expose_flagsfunction __dev_pm_qos_hide_flagsfunction dev_pm_qos_hide_flagsfunction dev_pm_qos_update_flagsfunction dev_pm_qos_get_user_latency_tolerancefunction dev_pm_qos_update_user_latency_tolerancefunction dev_pm_qos_expose_latency_tolerancefunction dev_pm_qos_hide_latency_toleranceexport dev_pm_qos_flagsexport dev_pm_qos_read_valueexport dev_pm_qos_add_requestexport dev_pm_qos_update_requestexport dev_pm_qos_remove_requestexport dev_pm_qos_add_notifierexport dev_pm_qos_remove_notifierexport dev_pm_qos_add_ancestor_requestexport dev_pm_qos_expose_latency_limitexport dev_pm_qos_hide_latency_limitexport dev_pm_qos_expose_flagsexport dev_pm_qos_hide_flagsexport dev_pm_qos_update_user_latency_toleranceexport dev_pm_qos_expose_latency_toleranceexport dev_pm_qos_hide_latency_tolerance
Annotated Snippet
if (ret) {
value = pm_qos_read_value(&qos->latency_tolerance);
req->dev->power.set_latency_tolerance(req->dev, value);
}
break;
case DEV_PM_QOS_MIN_FREQUENCY:
case DEV_PM_QOS_MAX_FREQUENCY:
ret = freq_qos_apply(&req->data.freq, action, value);
break;
case DEV_PM_QOS_FLAGS:
ret = pm_qos_update_flags(&qos->flags, &req->data.flr,
action, value);
break;
default:
ret = -EINVAL;
}
return ret;
}
/*
* dev_pm_qos_constraints_allocate
* @dev: device to allocate data for
*
* Called at the first call to add_request, for constraint data allocation
* Must be called with the dev_pm_qos_mtx mutex held
*/
static int dev_pm_qos_constraints_allocate(struct device *dev)
{
struct dev_pm_qos *qos;
struct pm_qos_constraints *c;
struct blocking_notifier_head *n;
qos = kzalloc_obj(*qos);
if (!qos)
return -ENOMEM;
n = kzalloc_objs(*n, 3);
if (!n) {
kfree(qos);
return -ENOMEM;
}
c = &qos->resume_latency;
plist_head_init(&c->list);
c->target_value = PM_QOS_RESUME_LATENCY_DEFAULT_VALUE;
c->default_value = PM_QOS_RESUME_LATENCY_DEFAULT_VALUE;
c->no_constraint_value = PM_QOS_RESUME_LATENCY_NO_CONSTRAINT;
c->type = PM_QOS_MIN;
c->notifiers = n;
BLOCKING_INIT_NOTIFIER_HEAD(n);
c = &qos->latency_tolerance;
plist_head_init(&c->list);
c->target_value = PM_QOS_LATENCY_TOLERANCE_DEFAULT_VALUE;
c->default_value = PM_QOS_LATENCY_TOLERANCE_DEFAULT_VALUE;
c->no_constraint_value = PM_QOS_LATENCY_TOLERANCE_NO_CONSTRAINT;
c->type = PM_QOS_MIN;
freq_constraints_init(&qos->freq);
INIT_LIST_HEAD(&qos->flags.list);
spin_lock_irq(&dev->power.lock);
dev->power.qos = qos;
spin_unlock_irq(&dev->power.lock);
return 0;
}
static void __dev_pm_qos_hide_latency_limit(struct device *dev);
static void __dev_pm_qos_hide_flags(struct device *dev);
/**
* dev_pm_qos_constraints_destroy
* @dev: target device
*
* Called from the device PM subsystem on device removal under device_pm_lock().
*/
void dev_pm_qos_constraints_destroy(struct device *dev)
{
struct dev_pm_qos *qos;
struct dev_pm_qos_request *req, *tmp;
struct pm_qos_constraints *c;
struct pm_qos_flags *f;
mutex_lock(&dev_pm_qos_sysfs_mtx);
/*
* If the device's PM QoS resume latency limit or PM QoS flags have been
Annotation
- Immediate include surface: `linux/pm_qos.h`, `linux/spinlock.h`, `linux/slab.h`, `linux/device.h`, `linux/mutex.h`, `linux/export.h`, `linux/pm_runtime.h`, `linux/err.h`.
- Detected declarations: `function __dev_pm_qos_flags`, `function dev_pm_qos_flags`, `function __dev_pm_qos_resume_latency`, `function dev_pm_qos_read_value`, `function apply_constraint`, `function dev_pm_qos_constraints_allocate`, `function device_pm_lock`, `function dev_pm_qos_invalid_req_type`, `function __dev_pm_qos_add_request`, `function dev_pm_qos_add_request`.
- 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.