]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: don't acquire dual timestamp needlessly if we don't need it in .timer handling 16536/head
authorLennart Poettering <lennart@poettering.net>
Tue, 21 Jul 2020 15:33:19 +0000 (17:33 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 21 Jul 2020 15:33:47 +0000 (17:33 +0200)
Follow-up for: 26698337f3842842af51cd007485f1dcd7c43cf2

src/core/timer.c

index 75f1dc1f8beb3f11bcd530af5598778535b4d9a1..03a9c14f766a8e72035de2dcaf8e518a4a55b6e4 100644 (file)
@@ -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;