From: Lennart Poettering Date: Tue, 21 Jul 2020 15:33:19 +0000 (+0200) Subject: core: don't acquire dual timestamp needlessly if we don't need it in .timer handling X-Git-Tag: v246-rc2~18^2 X-Git-Url: http://git.ipfire.org/?p=thirdparty%2Fsystemd.git;a=commitdiff_plain;h=58afc4f8e41176c890b171f422b988fd83887605 core: don't acquire dual timestamp needlessly if we don't need it in .timer handling Follow-up for: 26698337f3842842af51cd007485f1dcd7c43cf2 --- diff --git a/src/core/timer.c b/src/core/timer.c index 75f1dc1f8be..03a9c14f766 100644 --- a/src/core/timer.c +++ b/src/core/timer.c @@ -346,7 +346,6 @@ static void timer_enter_waiting(Timer *t, bool time_change) { bool found_monotonic = false, found_realtime = false; bool leave_around = false; triple_timestamp ts; - dual_timestamp dts; TimerValue *v; Unit *trigger; int r; @@ -368,7 +367,7 @@ static void timer_enter_waiting(Timer *t, bool time_change) { continue; if (v->base == TIMER_CALENDAR) { - usec_t b; + usec_t b, rebased; /* If we know the last time this was * triggered, schedule the job based relative @@ -388,12 +387,14 @@ static void timer_enter_waiting(Timer *t, bool time_change) { if (r < 0) continue; - /* To make the delay due to RandomizedDelaySec= work even at boot, - * if the scheduled time has already passed, set the time when systemd - * first started as the scheduled time. */ - dual_timestamp_from_monotonic(&dts, UNIT(t)->manager->timestamps[MANAGER_TIMESTAMP_USERSPACE].monotonic); - if (v->next_elapse < dts.realtime) - v->next_elapse = dts.realtime; + /* To make the delay due to RandomizedDelaySec= work even at boot, if the scheduled + * time has already passed, set the time when systemd first started as the scheduled + * time. Note that we base this on the monotonic timestamp of the boot, not the + * realtime one, since the wallclock might have been off during boot. */ + rebased = map_clock_usec(UNIT(t)->manager->timestamps[MANAGER_TIMESTAMP_USERSPACE].monotonic, + CLOCK_MONOTONIC, CLOCK_REALTIME); + if (v->next_elapse < rebased) + v->next_elapse = rebased; if (!found_realtime) t->next_elapse_realtime = v->next_elapse;