drivers/thermal/thermal_sysfs.c
Source file repositories/reference/linux-study-clean/drivers/thermal/thermal_sysfs.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/thermal/thermal_sysfs.c- Extension
.c- Size
- 21540 bytes
- Lines
- 881
- 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.
- 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/container_of.hlinux/sysfs.hlinux/device.hlinux/err.hlinux/slab.hlinux/string.hlinux/string_choices.hlinux/jiffies.hthermal_core.h
Detected Declarations
struct cooling_dev_statsfunction Copyrightfunction temp_showfunction mode_showfunction mode_storefunction trip_point_type_showfunction trip_point_temp_storefunction trip_point_temp_showfunction trip_point_hyst_storefunction trip_point_hyst_showfunction policy_storefunction policy_showfunction available_policies_showfunction emul_temp_storefunction sustainable_power_showfunction sustainable_power_storefunction create_trip_attrsfunction destroy_trip_attrsfunction thermal_zone_create_device_groupsfunction thermal_zone_destroy_device_groupsfunction cdev_type_showfunction max_state_showfunction cur_state_showfunction cur_state_storefunction update_time_in_statefunction thermal_cooling_device_stats_updatefunction total_trans_showfunction time_in_state_ms_showfunction reset_storefunction trans_table_showfunction cooling_device_stats_setupfunction cooling_device_stats_destroyfunction cooling_device_stats_setupfunction thermal_cooling_device_destroy_sysfsfunction thermal_cooling_device_stats_reinitfunction trip_point_showfunction weight_showfunction weight_store
Annotated Snippet
struct cooling_dev_stats {
spinlock_t lock;
unsigned int total_trans;
unsigned long state;
ktime_t last_time;
ktime_t *time_in_state;
unsigned int *trans_table;
};
static void update_time_in_state(struct cooling_dev_stats *stats)
{
ktime_t now = ktime_get(), delta;
delta = ktime_sub(now, stats->last_time);
stats->time_in_state[stats->state] =
ktime_add(stats->time_in_state[stats->state], delta);
stats->last_time = now;
}
void thermal_cooling_device_stats_update(struct thermal_cooling_device *cdev,
unsigned long new_state)
{
struct cooling_dev_stats *stats = cdev->stats;
lockdep_assert_held(&cdev->lock);
if (!stats)
return;
spin_lock(&stats->lock);
if (stats->state == new_state)
goto unlock;
update_time_in_state(stats);
stats->trans_table[stats->state * (cdev->max_state + 1) + new_state]++;
stats->state = new_state;
stats->total_trans++;
unlock:
spin_unlock(&stats->lock);
}
static ssize_t total_trans_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct thermal_cooling_device *cdev = to_cooling_device(dev);
struct cooling_dev_stats *stats;
int ret;
guard(cooling_dev)(cdev);
stats = cdev->stats;
if (!stats)
return 0;
spin_lock(&stats->lock);
ret = sysfs_emit(buf, "%u\n", stats->total_trans);
spin_unlock(&stats->lock);
return ret;
}
static ssize_t
time_in_state_ms_show(struct device *dev, struct device_attribute *attr,
char *buf)
{
struct thermal_cooling_device *cdev = to_cooling_device(dev);
struct cooling_dev_stats *stats;
ssize_t len = 0;
int i;
guard(cooling_dev)(cdev);
stats = cdev->stats;
if (!stats)
return 0;
spin_lock(&stats->lock);
update_time_in_state(stats);
for (i = 0; i <= cdev->max_state; i++) {
len += sysfs_emit_at(buf, len, "state%u\t%llu\n", i,
ktime_to_ms(stats->time_in_state[i]));
}
spin_unlock(&stats->lock);
return len;
}
Annotation
- Immediate include surface: `linux/container_of.h`, `linux/sysfs.h`, `linux/device.h`, `linux/err.h`, `linux/slab.h`, `linux/string.h`, `linux/string_choices.h`, `linux/jiffies.h`.
- Detected declarations: `struct cooling_dev_stats`, `function Copyright`, `function temp_show`, `function mode_show`, `function mode_store`, `function trip_point_type_show`, `function trip_point_temp_store`, `function trip_point_temp_show`, `function trip_point_hyst_store`, `function trip_point_hyst_show`.
- Atlas domain: Driver Families / drivers/thermal.
- 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.