drivers/thermal/thermal_thresholds.c
Source file repositories/reference/linux-study-clean/drivers/thermal/thermal_thresholds.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/thermal/thermal_thresholds.c- Extension
.c- Size
- 5758 bytes
- Lines
- 245
- 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/list.hlinux/list_sort.hlinux/slab.hthermal_core.hthermal_thresholds.h
Detected Declarations
function thermal_thresholds_initfunction __thermal_thresholds_flushfunction list_for_each_entry_safefunction thermal_thresholds_flushfunction thermal_thresholds_exitfunction __thermal_thresholds_cmpfunction thermal_thresholds_handle_raisingfunction list_for_each_entryfunction thermal_thresholds_handle_droppingfunction list_for_each_entry_reversefunction thermal_threshold_find_boundariesfunction list_for_each_entryfunction list_for_each_entry_reversefunction thermal_thresholds_handlefunction thermal_thresholds_addfunction thermal_thresholds_deletefunction thermal_thresholds_for_eachfunction list_for_each_entry
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright 2024 Linaro Limited
*
* Author: Daniel Lezcano <daniel.lezcano@linaro.org>
*
* Thermal thresholds
*/
#include <linux/list.h>
#include <linux/list_sort.h>
#include <linux/slab.h>
#include "thermal_core.h"
#include "thermal_thresholds.h"
int thermal_thresholds_init(struct thermal_zone_device *tz)
{
INIT_LIST_HEAD(&tz->user_thresholds);
return 0;
}
static void __thermal_thresholds_flush(struct thermal_zone_device *tz)
{
struct list_head *thresholds = &tz->user_thresholds;
struct user_threshold *entry, *tmp;
list_for_each_entry_safe(entry, tmp, thresholds, list_node) {
list_del(&entry->list_node);
kfree(entry);
}
}
void thermal_thresholds_flush(struct thermal_zone_device *tz)
{
lockdep_assert_held(&tz->lock);
__thermal_thresholds_flush(tz);
thermal_notify_threshold_flush(tz);
__thermal_zone_device_update(tz, THERMAL_TZ_FLUSH_THRESHOLDS);
}
void thermal_thresholds_exit(struct thermal_zone_device *tz)
{
__thermal_thresholds_flush(tz);
}
static int __thermal_thresholds_cmp(void *data,
const struct list_head *l1,
const struct list_head *l2)
{
struct user_threshold *t1 = container_of(l1, struct user_threshold, list_node);
struct user_threshold *t2 = container_of(l2, struct user_threshold, list_node);
return t1->temperature - t2->temperature;
}
static struct user_threshold *__thermal_thresholds_find(const struct list_head *thresholds,
int temperature)
{
struct user_threshold *t;
list_for_each_entry(t, thresholds, list_node)
if (t->temperature == temperature)
return t;
return NULL;
}
static bool thermal_thresholds_handle_raising(struct list_head *thresholds, int temperature,
int last_temperature)
{
struct user_threshold *t;
list_for_each_entry(t, thresholds, list_node) {
if (!(t->direction & THERMAL_THRESHOLD_WAY_UP))
continue;
if (temperature >= t->temperature &&
last_temperature < t->temperature)
return true;
}
return false;
}
static bool thermal_thresholds_handle_dropping(struct list_head *thresholds, int temperature,
Annotation
- Immediate include surface: `linux/list.h`, `linux/list_sort.h`, `linux/slab.h`, `thermal_core.h`, `thermal_thresholds.h`.
- Detected declarations: `function thermal_thresholds_init`, `function __thermal_thresholds_flush`, `function list_for_each_entry_safe`, `function thermal_thresholds_flush`, `function thermal_thresholds_exit`, `function __thermal_thresholds_cmp`, `function thermal_thresholds_handle_raising`, `function list_for_each_entry`, `function thermal_thresholds_handle_dropping`, `function list_for_each_entry_reverse`.
- 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.