tools/thermal/tmon/sysfs.c
Source file repositories/reference/linux-study-clean/tools/thermal/tmon/sysfs.c
File Facts
- System
- Linux kernel
- Corpus path
tools/thermal/tmon/sysfs.c- Extension
.c- Size
- 14816 bytes
- Lines
- 592
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
unistd.hstdio.hstdlib.hstring.hstdint.hdirent.hlibintl.hlimits.hctype.htime.hsyslog.hsys/time.herrno.htmon.h
Detected Declarations
function sysfs_set_ulongfunction sysfs_get_ulongfunction sysfs_get_stringfunction probe_cdevfunction str_to_trip_typefunction get_trip_point_datafunction get_instance_idfunction find_tzone_tpfunction find_tzone_cdevfunction scan_tzonesfunction scan_cdevsfunction probe_thermal_sysfsfunction zone_instance_to_indexfunction update_thermal_datafunction set_ctrl_statefunction get_ctrl_statefunction free_thermal_data
Annotated Snippet
strstr(d_name, "temp")) {
/* check if trip point temp is non-zero
* ignore 0/invalid trip points
*/
sysfs_get_ulong(tz_name, d_name, &temp_ulong);
if (temp_ulong < MAX_TEMP_KC) {
tzi->nr_trip_pts++;
/* found a valid trip point */
tp_id = get_instance_id(d_name, 2, 0);
syslog(LOG_DEBUG, "tzone %s trip %d temp %lu tpnode %s",
tz_name, tp_id, temp_ulong, d_name);
if (tp_id < 0 || tp_id >= MAX_NR_TRIP) {
syslog(LOG_ERR, "Failed to find TP inst %s\n",
d_name);
return -1;
}
get_trip_point_data(tz_name, tz_id, tp_id);
tzi->tp[tp_id].temp = temp_ulong;
}
}
return 0;
}
/* check cooling devices for binding info. */
static int find_tzone_cdev(struct dirent *nl, char *tz_name,
struct tz_info *tzi, int tz_id, int cid)
{
unsigned long trip_instance = 0;
char cdev_name_linked[256];
char cdev_name[PATH_MAX];
char cdev_trip_name[PATH_MAX];
int cdev_id;
if (nl->d_type == DT_LNK) {
syslog(LOG_DEBUG, "TZ%d: cdev: %s cid %d\n", tz_id, nl->d_name,
cid);
tzi->nr_cdev++;
if (tzi->nr_cdev > ptdata.nr_cooling_dev) {
syslog(LOG_ERR, "Err: Too many cdev? %d\n",
tzi->nr_cdev);
return -EINVAL;
}
/* find the link to real cooling device record binding */
snprintf(cdev_name, sizeof(cdev_name) - 2, "%s/%s",
tz_name, nl->d_name);
memset(cdev_name_linked, 0, sizeof(cdev_name_linked));
if (readlink(cdev_name, cdev_name_linked,
sizeof(cdev_name_linked) - 1) != -1) {
cdev_id = get_instance_id(cdev_name_linked, 1,
sizeof("device") - 1);
syslog(LOG_DEBUG, "cdev %s linked to %s : %d\n",
cdev_name, cdev_name_linked, cdev_id);
tzi->cdev_binding |= (1 << cdev_id);
/* find the trip point in which the cdev is binded to
* in this tzone
*/
snprintf(cdev_trip_name, sizeof(cdev_trip_name) - 1,
"%s%s", nl->d_name, "_trip_point");
sysfs_get_ulong(tz_name, cdev_trip_name,
&trip_instance);
/* validate trip point range, e.g. trip could return -1
* when passive is enabled
*/
if (trip_instance > MAX_NR_TRIP)
trip_instance = 0;
tzi->trip_binding[cdev_id] |= 1 << trip_instance;
syslog(LOG_DEBUG, "cdev %s -> trip:%lu: 0x%lx %d\n",
cdev_name, trip_instance,
tzi->trip_binding[cdev_id],
cdev_id);
}
return 0;
}
return -ENODEV;
}
/*****************************************************************************
* Before calling scan_tzones, thermal sysfs must be probed to determine
* the number of thermal zones and cooling devices.
* We loop through each thermal zone and fill in tz_info struct, i.e.
* ptdata.tzi[]
root@jacob-chiefriver:~# tree -d /sys/class/thermal/thermal_zone0
/sys/class/thermal/thermal_zone0
Annotation
- Immediate include surface: `unistd.h`, `stdio.h`, `stdlib.h`, `string.h`, `stdint.h`, `dirent.h`, `libintl.h`, `limits.h`.
- Detected declarations: `function sysfs_set_ulong`, `function sysfs_get_ulong`, `function sysfs_get_string`, `function probe_cdev`, `function str_to_trip_type`, `function get_trip_point_data`, `function get_instance_id`, `function find_tzone_tp`, `function find_tzone_cdev`, `function scan_tzones`.
- Atlas domain: Support Tooling And Documentation / tools.
- 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.