drivers/thermal/gov_power_allocator.c
Source file repositories/reference/linux-study-clean/drivers/thermal/gov_power_allocator.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/thermal/gov_power_allocator.c- Extension
.c- Size
- 22682 bytes
- Lines
- 801
- Domain
- Driver Families
- Bucket
- drivers/thermal
- 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.
- 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/slab.hlinux/thermal.hthermal_trace_ipa.hthermal_core.h
Detected Declarations
struct power_actorstruct power_allocator_paramsfunction Copyrightfunction div_fracfunction power_actor_is_validfunction estimate_sustainable_powerfunction list_for_each_entryfunction estimate_pid_constantsfunction get_sustainable_powerfunction pid_controllerfunction power_actor_set_powerfunction divvy_up_powerfunction allocate_powerfunction list_for_each_entryfunction get_governor_tripsfunction for_each_trip_descfunction reset_pid_controllerfunction allow_maximum_powerfunction list_for_each_entryfunction scoped_guardfunction check_power_actorsfunction list_for_each_entryfunction allocate_actors_bufferfunction power_allocator_update_weightfunction power_allocator_update_tzfunction power_allocator_bindfunction power_allocator_unbindfunction power_allocator_manage
Annotated Snippet
struct power_actor {
u32 req_power;
u32 max_power;
u32 granted_power;
u32 extra_actor_power;
u32 weighted_req_power;
};
/**
* struct power_allocator_params - parameters for the power allocator governor
* @allocated_tzp: whether we have allocated tzp for this thermal zone and
* it needs to be freed on unbind
* @update_cdevs: whether or not update cdevs on the next run
* @err_integral: accumulated error in the PID controller.
* @prev_err: error in the previous iteration of the PID controller.
* Used to calculate the derivative term.
* @sustainable_power: Sustainable power (heat) that this thermal zone can
* dissipate
* @trip_switch_on: first passive trip point of the thermal zone. The
* governor switches on when this trip point is crossed.
* If the thermal zone only has one passive trip point,
* @trip_switch_on should be NULL.
* @trip_max: last passive trip point of the thermal zone. The
* temperature we are controlling for.
* @total_weight: Sum of all thermal instances weights
* @num_actors: number of cooling devices supporting IPA callbacks
* @buffer_size: internal buffer size, to avoid runtime re-calculation
* @power: buffer for all power actors internal power information
*/
struct power_allocator_params {
bool allocated_tzp;
bool update_cdevs;
s64 err_integral;
s32 prev_err;
u32 sustainable_power;
const struct thermal_trip *trip_switch_on;
const struct thermal_trip *trip_max;
int total_weight;
unsigned int num_actors;
unsigned int buffer_size;
struct power_actor *power;
};
static bool power_actor_is_valid(struct thermal_instance *instance)
{
return cdev_is_power_actor(instance->cdev);
}
/**
* estimate_sustainable_power() - Estimate the sustainable power of a thermal zone
* @tz: thermal zone we are operating in
*
* For thermal zones that don't provide a sustainable_power in their
* thermal_zone_params, estimate one. Calculate it using the minimum
* power of all the cooling devices as that gives a valid value that
* can give some degree of functionality. For optimal performance of
* this governor, provide a sustainable_power in the thermal zone's
* thermal_zone_params.
*/
static u32 estimate_sustainable_power(struct thermal_zone_device *tz)
{
struct power_allocator_params *params = tz->governor_data;
const struct thermal_trip_desc *td = trip_to_trip_desc(params->trip_max);
struct thermal_cooling_device *cdev;
struct thermal_instance *instance;
u32 sustainable_power = 0;
u32 min_power;
list_for_each_entry(instance, &td->thermal_instances, trip_node) {
if (!power_actor_is_valid(instance))
continue;
cdev = instance->cdev;
if (cdev->ops->state2power(cdev, instance->upper, &min_power))
continue;
sustainable_power += min_power;
}
return sustainable_power;
}
/**
* estimate_pid_constants() - Estimate the constants for the PID controller
* @tz: thermal zone for which to estimate the constants
* @sustainable_power: sustainable power for the thermal zone
* @trip_switch_on: trip point for the switch on temperature
* @control_temp: target temperature for the power allocator governor
*
* This function is used to update the estimation of the PID
Annotation
- Immediate include surface: `linux/slab.h`, `linux/thermal.h`, `thermal_trace_ipa.h`, `thermal_core.h`.
- Detected declarations: `struct power_actor`, `struct power_allocator_params`, `function Copyright`, `function div_frac`, `function power_actor_is_valid`, `function estimate_sustainable_power`, `function list_for_each_entry`, `function estimate_pid_constants`, `function get_sustainable_power`, `function pid_controller`.
- Atlas domain: Driver Families / drivers/thermal.
- Implementation status: source implementation candidate.
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.