Merge pull request #6176 from poettering/timer-boottime-monotonic
WakeSystem= and other timer fixes.
This commit is contained in:
+25
-6
@@ -107,7 +107,7 @@ dual_timestamp* dual_timestamp_from_realtime(dual_timestamp *ts, usec_t u) {
|
||||
ts->realtime = u;
|
||||
|
||||
delta = (int64_t) now(CLOCK_REALTIME) - (int64_t) u;
|
||||
ts->monotonic = usec_sub(now(CLOCK_MONOTONIC), delta);
|
||||
ts->monotonic = usec_sub_signed(now(CLOCK_MONOTONIC), delta);
|
||||
|
||||
return ts;
|
||||
}
|
||||
@@ -124,8 +124,8 @@ triple_timestamp* triple_timestamp_from_realtime(triple_timestamp *ts, usec_t u)
|
||||
|
||||
ts->realtime = u;
|
||||
delta = (int64_t) now(CLOCK_REALTIME) - (int64_t) u;
|
||||
ts->monotonic = usec_sub(now(CLOCK_MONOTONIC), delta);
|
||||
ts->boottime = clock_boottime_supported() ? usec_sub(now(CLOCK_BOOTTIME), delta) : USEC_INFINITY;
|
||||
ts->monotonic = usec_sub_signed(now(CLOCK_MONOTONIC), delta);
|
||||
ts->boottime = clock_boottime_supported() ? usec_sub_signed(now(CLOCK_BOOTTIME), delta) : USEC_INFINITY;
|
||||
|
||||
return ts;
|
||||
}
|
||||
@@ -141,7 +141,7 @@ dual_timestamp* dual_timestamp_from_monotonic(dual_timestamp *ts, usec_t u) {
|
||||
|
||||
ts->monotonic = u;
|
||||
delta = (int64_t) now(CLOCK_MONOTONIC) - (int64_t) u;
|
||||
ts->realtime = usec_sub(now(CLOCK_REALTIME), delta);
|
||||
ts->realtime = usec_sub_signed(now(CLOCK_REALTIME), delta);
|
||||
|
||||
return ts;
|
||||
}
|
||||
@@ -156,8 +156,8 @@ dual_timestamp* dual_timestamp_from_boottime_or_monotonic(dual_timestamp *ts, us
|
||||
|
||||
dual_timestamp_get(ts);
|
||||
delta = (int64_t) now(clock_boottime_or_monotonic()) - (int64_t) u;
|
||||
ts->realtime = usec_sub(ts->realtime, delta);
|
||||
ts->monotonic = usec_sub(ts->monotonic, delta);
|
||||
ts->realtime = usec_sub_signed(ts->realtime, delta);
|
||||
ts->monotonic = usec_sub_signed(ts->monotonic, delta);
|
||||
|
||||
return ts;
|
||||
}
|
||||
@@ -1351,3 +1351,22 @@ unsigned long usec_to_jiffies(usec_t u) {
|
||||
|
||||
return DIV_ROUND_UP(u , USEC_PER_SEC / hz);
|
||||
}
|
||||
|
||||
usec_t usec_shift_clock(usec_t x, clockid_t from, clockid_t to) {
|
||||
usec_t a, b;
|
||||
|
||||
if (x == USEC_INFINITY)
|
||||
return USEC_INFINITY;
|
||||
if (map_clock_id(from) == map_clock_id(to))
|
||||
return x;
|
||||
|
||||
a = now(from);
|
||||
b = now(to);
|
||||
|
||||
if (x > a)
|
||||
/* x lies in the future */
|
||||
return usec_add(b, usec_sub_unsigned(x, a));
|
||||
else
|
||||
/* x lies in the past */
|
||||
return usec_sub_unsigned(b, usec_sub_unsigned(a, x));
|
||||
}
|
||||
|
||||
+11
-5
@@ -145,6 +145,8 @@ bool clock_boottime_supported(void);
|
||||
bool clock_supported(clockid_t clock);
|
||||
clockid_t clock_boottime_or_monotonic(void);
|
||||
|
||||
usec_t usec_shift_clock(usec_t, clockid_t from, clockid_t to);
|
||||
|
||||
#define xstrftime(buf, fmt, tm) \
|
||||
assert_message_se(strftime(buf, ELEMENTSOF(buf), fmt, tm) > 0, \
|
||||
"xstrftime: " #buf "[] must be big enough")
|
||||
@@ -169,19 +171,23 @@ static inline usec_t usec_add(usec_t a, usec_t b) {
|
||||
return c;
|
||||
}
|
||||
|
||||
static inline usec_t usec_sub(usec_t timestamp, int64_t delta) {
|
||||
if (delta < 0)
|
||||
return usec_add(timestamp, (usec_t) (-delta));
|
||||
static inline usec_t usec_sub_unsigned(usec_t timestamp, usec_t delta) {
|
||||
|
||||
if (timestamp == USEC_INFINITY) /* Make sure infinity doesn't degrade */
|
||||
return USEC_INFINITY;
|
||||
|
||||
if (timestamp < (usec_t) delta)
|
||||
if (timestamp < delta)
|
||||
return 0;
|
||||
|
||||
return timestamp - delta;
|
||||
}
|
||||
|
||||
static inline usec_t usec_sub_signed(usec_t timestamp, int64_t delta) {
|
||||
if (delta < 0)
|
||||
return usec_add(timestamp, (usec_t) (-delta));
|
||||
else
|
||||
return usec_sub_unsigned(timestamp, (usec_t) delta);
|
||||
}
|
||||
|
||||
#if SIZEOF_TIME_T == 8
|
||||
/* The last second we can format is 31. Dec 9999, 1s before midnight, because otherwise we'd enter 5 digit year
|
||||
* territory. However, since we want to stay away from this in all timezones we take one day off. */
|
||||
|
||||
Reference in New Issue
Block a user