Use monotonic clock for thermal sampling intervals and model time axis

This commit is contained in:
Andrea Mazzoleni 2026-09-07 00:04:49 +02:00
parent 9ec2457147
commit 305d1bce36
3 changed files with 9 additions and 7 deletions

View file

@ -5839,13 +5839,15 @@ static void state_progress_graph(struct snapraid_state* state, struct snapraid_i
int state_progress(struct snapraid_state* state, struct snapraid_io* io, block_off_t blockpos, block_off_t countpos, block_off_t countmax, data_off_t countsize)
{
time_t now;
uint64_t thermal_now;
int pred;
now = time(0);
thermal_now = os_tick_sec();
/* thermal measure */
if (now > state->thermal_latest + THERMAL_PERIOD_SECONDS || state->opt.fake_device) {
state->thermal_latest = now;
if (thermal_now > state->thermal_latest + THERMAL_PERIOD_SECONDS || state->opt.fake_device) {
state->thermal_latest = thermal_now;
state_thermal(state, now);
}

View file

@ -161,8 +161,8 @@ struct snapraid_state {
int thermal_stop_gathering; /**< If thermal data gathering is stopped */
int thermal_ambient_temperature; /**< Ambient themperature. 0 if not available */
int thermal_highest_temperature; /**< Current highest temperature */
time_t thermal_first; /**< Time of the first measure */
time_t thermal_latest; /**< Time of latest measure */
uint64_t thermal_first; /**< Monotonic time of the first measure */
uint64_t thermal_latest; /**< Monotonic time of latest measure */
int thermal_cooldown_time; /**< Cooldown wait time in seconds */
int thermal_temperature_limit; /**< Upper limit temperature of the operating range */

View file

@ -265,7 +265,7 @@ int state_thermal(struct snapraid_state* state, time_t now)
/* insert the new data point */
found->data[found->count].temperature = temperature;
found->data[found->count].time = now - state->thermal_first;
found->data[found->count].time = state->thermal_latest - state->thermal_first;
++found->count;
if (state->opt.fake_device) {
@ -386,8 +386,8 @@ int state_thermal_begin(struct snapraid_state* state, time_t now)
return 1;
/* initial thermal measure */
state->thermal_first = now;
state->thermal_latest = now;
state->thermal_first = os_tick_sec();
state->thermal_latest = state->thermal_first;
state_thermal(state, now);
if (state->thermal_ambient_temperature != 0) {