From 31710bc1f3aa902c17620a4ae4035cd2ba21b076 Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Mon, 7 Sep 2026 11:38:49 +0200 Subject: [PATCH] Distinguish system temperature sensor from thermal model ambient reference --- cmdline/state.c | 1 + cmdline/state.h | 3 ++- cmdline/thermal.c | 31 +++++++++++++++++-------------- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/cmdline/state.c b/cmdline/state.c index 5cee2246..9f02beda 100644 --- a/cmdline/state.c +++ b/cmdline/state.c @@ -179,6 +179,7 @@ void state_init(struct snapraid_state* state) state->unsynced_blocks = 0; state->unscrubbed_blocks = 0; state->thermal_stop_gathering = 0; + state->thermal_system_temperature = 0; state->thermal_ambient_temperature = 0; state->thermal_highest_temperature = 0; state->thermal_first = 0; diff --git a/cmdline/state.h b/cmdline/state.h index c97b304d..d4d0c060 100644 --- a/cmdline/state.h +++ b/cmdline/state.h @@ -159,7 +159,8 @@ struct snapraid_state { /* Thermal */ tommy_list thermallist; /**< List of all thermal state */ int thermal_stop_gathering; /**< If thermal data gathering is stopped */ - int thermal_ambient_temperature; /**< Ambient themperature. 0 if not available */ + int thermal_system_temperature; /**< System temperature. 0 if not available */ + int thermal_ambient_temperature; /**< Ambient temperature used as thermal model reference. 0 if not available */ int thermal_highest_temperature; /**< Current highest temperature */ uint64_t thermal_first; /**< Monotonic time of the first measure */ uint64_t thermal_latest; /**< Monotonic time of latest measure */ diff --git a/cmdline/thermal.c b/cmdline/thermal.c index 2f9ff17f..1f4ec419 100644 --- a/cmdline/thermal.c +++ b/cmdline/thermal.c @@ -196,21 +196,24 @@ int state_thermal(struct snapraid_state* state, time_t now) /* report new attribute */ state_attr(state, &low); - /* if ambient temperature is not set, set it now with the lowest HD temperature */ + /* if ambient temperature is not set, get the system temperature or fallback to the lowest HD temperature */ if (state->thermal_ambient_temperature == 0) { - state->thermal_ambient_temperature = ambient_temperature(); + state->thermal_system_temperature = ambient_temperature(); + state->thermal_ambient_temperature = state->thermal_system_temperature; - for (i = tommy_list_head(&low); i != 0; i = i->next) { - devinfo_t* devinfo = i->data; + if (state->thermal_ambient_temperature == 0) { + for (i = tommy_list_head(&low); i != 0; i = i->next) { + devinfo_t* devinfo = i->data; - int temp = smart_temp(devinfo); - if (temp < 0) - continue; + int temp = smart_temp(devinfo); + if (temp < 0) + continue; - log_tag("thermal:system:candidate:%d\n", temp); + log_tag("thermal:system:candidate:%d\n", temp); - if (state->thermal_ambient_temperature == 0 || state->thermal_ambient_temperature > temp) - state->thermal_ambient_temperature = temp; + if (state->thermal_ambient_temperature == 0 || state->thermal_ambient_temperature > temp) + state->thermal_ambient_temperature = temp; + } } log_tag("thermal:system:final:%d\n", state->thermal_ambient_temperature); @@ -404,12 +407,12 @@ int state_thermal_begin(struct snapraid_state* state, time_t now) state->thermal_latest = state->thermal_first; state_thermal(state, now); - if (state->thermal_ambient_temperature != 0) { - printf("System temperature is %u degrees\n", state->thermal_ambient_temperature); + if (state->thermal_system_temperature != 0) { + printf("System temperature is %u degrees\n", state->thermal_system_temperature); - if (state->thermal_temperature_limit != 0 && state->thermal_temperature_limit <= state->thermal_ambient_temperature) { + if (state->thermal_temperature_limit != 0 && state->thermal_temperature_limit <= state->thermal_system_temperature) { /* LCOV_EXCL_START */ - log_fatal(EENVIRONMENT, "DANGER! System temperature of %d degrees is higher than the temperature limit of %d degrees. Unable to proceed!\n", state->thermal_ambient_temperature, state->thermal_temperature_limit); + log_fatal(EENVIRONMENT, "DANGER! System temperature of %d degrees is higher than the temperature limit of %d degrees. Unable to proceed!\n", state->thermal_system_temperature, state->thermal_temperature_limit); log_flush(); return 0; /* LCOV_EXCL_STOP */