drivers/powercap/intel_rapl_common.c
Source file repositories/reference/linux-study-clean/drivers/powercap/intel_rapl_common.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/powercap/intel_rapl_common.c- Extension
.c- Size
- 49491 bytes
- Lines
- 1894
- Domain
- Driver Families
- Bucket
- drivers/powercap
- 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.
- 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/bitmap.hlinux/cleanup.hlinux/cpu.hlinux/delay.hlinux/device.hlinux/intel_rapl.hlinux/kernel.hlinux/list.hlinux/log2.hlinux/module.hlinux/nospec.hlinux/perf_event.hlinux/platform_device.hlinux/powercap.hlinux/processor.hlinux/slab.hlinux/suspend.hlinux/sysfs.hlinux/types.hlinux/units.hasm/cpu_device_id.hasm/intel-family.hasm/msr.h
Detected Declarations
struct rapl_pmuenum pl_primsenum perf_rapl_eventsfunction is_pl_validfunction get_pl_lock_primfunction get_pl_primfunction get_energy_counterfunction get_max_energy_counterfunction release_zonefunction find_nr_power_limitfunction set_domain_enablefunction get_domain_enablefunction limitfunction set_power_limitfunction get_current_power_limitfunction set_time_windowfunction get_time_windowfunction get_max_powerfunction get_ridfunction rapl_init_domainsfunction rapl_unit_xlatefunction rapl_configfunction prim_fixupsfunction rapl_read_data_rawfunction rapl_write_data_rawfunction rapl_read_pl_datafunction rapl_write_pl_datafunction rapl_default_check_unitfunction power_limit_irq_save_cpufunction package_power_limit_irq_savefunction package_power_limit_irq_restorefunction rapl_default_set_floor_freqfunction rapl_default_compute_time_windowfunction rapl_update_domain_datafunction rapl_package_register_powercapfunction rapl_check_domainfunction rapl_get_domain_unitfunction rapl_detect_powerlimitfunction rapl_detect_domainsfunction set_pmu_cpumaskfunction is_rp_pmu_cpufunction event_read_counterfunction __rapl_pmu_event_startfunction rapl_pmu_event_startfunction rapl_event_updatefunction rapl_pmu_event_stopfunction rapl_pmu_event_addfunction rapl_pmu_event_del
Annotated Snippet
struct rapl_pmu {
struct pmu pmu; /* Perf PMU structure */
u64 timer_ms; /* Maximum expiration time to avoid counter overflow */
unsigned long domain_map; /* Events supported by current registered PMU */
bool registered; /* Whether the PMU has been registered or not */
};
static struct rapl_pmu rapl_pmu;
/* PMU helpers */
static void set_pmu_cpumask(struct rapl_package *rp, cpumask_var_t mask)
{
int cpu;
if (!rp->has_pmu)
return;
/* Only TPMI & MSR RAPL are supported for now */
if (rp->priv->type != RAPL_IF_TPMI && rp->priv->type != RAPL_IF_MSR)
return;
/* TPMI/MSR RAPL uses any CPU in the package for PMU */
for_each_online_cpu(cpu)
if (topology_physical_package_id(cpu) == rp->id)
cpumask_set_cpu(cpu, mask);
}
static bool is_rp_pmu_cpu(struct rapl_package *rp, int cpu)
{
if (!rp->has_pmu)
return false;
/* Only TPMI & MSR RAPL are supported for now */
if (rp->priv->type != RAPL_IF_TPMI && rp->priv->type != RAPL_IF_MSR)
return false;
/* TPMI/MSR RAPL uses any CPU in the package for PMU */
return topology_physical_package_id(cpu) == rp->id;
}
static struct rapl_package_pmu_data *event_to_pmu_data(struct perf_event *event)
{
struct rapl_package *rp = event->pmu_private;
return &rp->pmu_data;
}
/* PMU event callbacks */
static u64 event_read_counter(struct perf_event *event)
{
struct rapl_package *rp = event->pmu_private;
u64 val;
int ret;
/* Return 0 for unsupported events */
if (event->hw.idx < 0)
return 0;
ret = rapl_read_data_raw(&rp->domains[event->hw.idx], ENERGY_COUNTER, false, &val, true);
/* Return 0 for failed read */
if (ret)
return 0;
return val;
}
static void __rapl_pmu_event_start(struct perf_event *event)
{
struct rapl_package_pmu_data *data = event_to_pmu_data(event);
if (WARN_ON_ONCE(!(event->hw.state & PERF_HES_STOPPED)))
return;
event->hw.state = 0;
list_add_tail(&event->active_entry, &data->active_list);
local64_set(&event->hw.prev_count, event_read_counter(event));
if (++data->n_active == 1)
hrtimer_start(&data->hrtimer, data->timer_interval,
HRTIMER_MODE_REL_PINNED);
}
static void rapl_pmu_event_start(struct perf_event *event, int mode)
{
struct rapl_package_pmu_data *data = event_to_pmu_data(event);
unsigned long flags;
Annotation
- Immediate include surface: `linux/bitmap.h`, `linux/cleanup.h`, `linux/cpu.h`, `linux/delay.h`, `linux/device.h`, `linux/intel_rapl.h`, `linux/kernel.h`, `linux/list.h`.
- Detected declarations: `struct rapl_pmu`, `enum pl_prims`, `enum perf_rapl_events`, `function is_pl_valid`, `function get_pl_lock_prim`, `function get_pl_prim`, `function get_energy_counter`, `function get_max_energy_counter`, `function release_zone`, `function find_nr_power_limit`.
- Atlas domain: Driver Families / drivers/powercap.
- Implementation status: integration 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.