tools/thermal/thermal-engine/thermal-engine.c

Source file repositories/reference/linux-study-clean/tools/thermal/thermal-engine/thermal-engine.c

File Facts

System
Linux kernel
Corpus path
tools/thermal/thermal-engine/thermal-engine.c
Extension
.c
Size
9728 bytes
Lines
421
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.

Dependency Surface

Detected Declarations

Annotated Snippet

struct options {
	int loglevel;
	int logopt;
	int interactive;
	int daemonize;
};

struct thermal_data {
	struct thermal_zone *tz;
	struct thermal_handler *th;
};

static int show_threshold(struct thermal_threshold *th, __maybe_unused void *arg)
{
	INFO("threshold temp=%d, direction=%d\n",
	     th->temperature, th->direction);

	return 0;
}

static int show_trip(struct thermal_trip *tt, __maybe_unused void *arg)
{
	INFO("trip id=%d, type=%d, temp=%d, hyst=%d\n",
	     tt->id, tt->type, tt->temp, tt->hyst);

	return 0;
}

static int show_temp(struct thermal_zone *tz, __maybe_unused void *arg)
{
	thermal_cmd_get_temp(arg, tz);

	INFO("temperature: %d\n", tz->temp);

	return 0;
}

static int show_governor(struct thermal_zone *tz, __maybe_unused void *arg)
{
	thermal_cmd_get_governor(arg, tz);

	INFO("governor: '%s'\n", tz->governor);

	return 0;
}

static int show_tz(struct thermal_zone *tz, __maybe_unused void *arg)
{
	INFO("thermal zone '%s', id=%d\n", tz->name, tz->id);

	for_each_thermal_trip(tz->trip, show_trip, NULL);

	for_each_thermal_threshold(tz->thresholds, show_threshold, NULL);

	show_temp(tz, arg);

	show_governor(tz, arg);

	return 0;
}

static int set_threshold(struct thermal_zone *tz, __maybe_unused void *arg)
{
	struct thermal_handler *th = arg;
	int thresholds[] = { 43000, 65000, 49000, 55000, 57000 };
	size_t i;

	INFO("Setting threshold for thermal zone '%s', id=%d\n", tz->name, tz->id);

	if (thermal_cmd_threshold_flush(th, tz)) {
		ERROR("Failed to flush all previous thresholds\n");
		return -1;
	}

	for (i = 0; i < sizeof(thresholds) / sizeof(thresholds[0]); i++)
		if (thermal_cmd_threshold_add(th, tz, thresholds[i],
					      THERMAL_THRESHOLD_WAY_UP |
					      THERMAL_THRESHOLD_WAY_DOWN)) {
			ERROR("Failed to set threshold\n");
			return -1;
		}

	return 0;
}

static int tz_create(const char *name, int tz_id, __maybe_unused void *arg)
{
	INFO("Thermal zone '%s'/%d created\n", name, tz_id);

	return 0;

Annotation

Implementation Notes