drivers/powercap/dtpm_devfreq.c
Source file repositories/reference/linux-study-clean/drivers/powercap/dtpm_devfreq.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/powercap/dtpm_devfreq.c- Extension
.c- Size
- 4862 bytes
- Lines
- 211
- Domain
- Driver Families
- Bucket
- drivers/powercap
- 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/cpumask.hlinux/devfreq.hlinux/dtpm.hlinux/energy_model.hlinux/of.hlinux/pm_qos.hlinux/slab.hlinux/units.h
Detected Declarations
struct dtpm_devfreqfunction update_pd_power_uwfunction set_pd_power_limitfunction _normalize_loadfunction get_pd_power_uwfunction pd_releasefunction __dtpm_devfreq_setupfunction dtpm_devfreq_setup
Annotated Snippet
struct dtpm_devfreq {
struct dtpm dtpm;
struct dev_pm_qos_request qos_req;
struct devfreq *devfreq;
};
static struct dtpm_devfreq *to_dtpm_devfreq(struct dtpm *dtpm)
{
return container_of(dtpm, struct dtpm_devfreq, dtpm);
}
static int update_pd_power_uw(struct dtpm *dtpm)
{
struct dtpm_devfreq *dtpm_devfreq = to_dtpm_devfreq(dtpm);
struct devfreq *devfreq = dtpm_devfreq->devfreq;
struct device *dev = devfreq->dev.parent;
struct em_perf_domain *pd = em_pd_get(dev);
struct em_perf_state *table;
rcu_read_lock();
table = em_perf_state_from_pd(pd);
dtpm->power_min = table[0].power;
dtpm->power_max = table[pd->nr_perf_states - 1].power;
rcu_read_unlock();
return 0;
}
static u64 set_pd_power_limit(struct dtpm *dtpm, u64 power_limit)
{
struct dtpm_devfreq *dtpm_devfreq = to_dtpm_devfreq(dtpm);
struct devfreq *devfreq = dtpm_devfreq->devfreq;
struct device *dev = devfreq->dev.parent;
struct em_perf_domain *pd = em_pd_get(dev);
struct em_perf_state *table;
unsigned long freq;
int i;
rcu_read_lock();
table = em_perf_state_from_pd(pd);
for (i = 0; i < pd->nr_perf_states; i++) {
if (table[i].power > power_limit)
break;
}
freq = table[i - 1].frequency;
power_limit = table[i - 1].power;
rcu_read_unlock();
dev_pm_qos_update_request(&dtpm_devfreq->qos_req, freq);
return power_limit;
}
static void _normalize_load(struct devfreq_dev_status *status)
{
if (status->total_time > 0xfffff) {
status->total_time >>= 10;
status->busy_time >>= 10;
}
status->busy_time <<= 10;
status->busy_time /= status->total_time ? : 1;
status->busy_time = status->busy_time ? : 1;
status->total_time = 1024;
}
static u64 get_pd_power_uw(struct dtpm *dtpm)
{
struct dtpm_devfreq *dtpm_devfreq = to_dtpm_devfreq(dtpm);
struct devfreq *devfreq = dtpm_devfreq->devfreq;
struct device *dev = devfreq->dev.parent;
struct em_perf_domain *pd = em_pd_get(dev);
struct devfreq_dev_status status;
struct em_perf_state *table;
unsigned long freq;
u64 power = 0;
int i;
mutex_lock(&devfreq->lock);
status = devfreq->last_status;
mutex_unlock(&devfreq->lock);
freq = DIV_ROUND_UP(status.current_frequency, HZ_PER_KHZ);
_normalize_load(&status);
rcu_read_lock();
Annotation
- Immediate include surface: `linux/cpumask.h`, `linux/devfreq.h`, `linux/dtpm.h`, `linux/energy_model.h`, `linux/of.h`, `linux/pm_qos.h`, `linux/slab.h`, `linux/units.h`.
- Detected declarations: `struct dtpm_devfreq`, `function update_pd_power_uw`, `function set_pd_power_limit`, `function _normalize_load`, `function get_pd_power_uw`, `function pd_release`, `function __dtpm_devfreq_setup`, `function dtpm_devfreq_setup`.
- Atlas domain: Driver Families / drivers/powercap.
- 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.