From: Thomas Weißschuh Date: Sat, 21 Jan 2023 00:21:10 +0000 (+0000) Subject: lib/monotonic: get_suspended_time: use usec_t X-Git-Tag: v2.39-rc1~114^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=02f3ecd680b71019b1242ec7ee0256ad36720094;p=thirdparty%2Futil-linux.git lib/monotonic: get_suspended_time: use usec_t Signed-off-by: Thomas Weißschuh --- diff --git a/include/monotonic.h b/include/monotonic.h index 380e59c379..5c5c2c1c11 100644 --- a/include/monotonic.h +++ b/include/monotonic.h @@ -13,9 +13,11 @@ #include +#include "timeutils.h" + extern int get_boot_time(struct timeval *boot_time); -extern time_t get_suspended_time(void); +extern usec_t get_suspended_time(void); extern int gettime_monotonic(struct timeval *tv); diff --git a/lib/monotonic.c b/lib/monotonic.c index f0aeba6828..cd554dd719 100644 --- a/lib/monotonic.c +++ b/lib/monotonic.c @@ -48,14 +48,14 @@ int get_boot_time(struct timeval *boot_time) #endif } -time_t get_suspended_time(void) +usec_t get_suspended_time(void) { #if defined(CLOCK_BOOTTIME) && defined(CLOCK_MONOTONIC) struct timespec boot, mono; if (clock_gettime(CLOCK_BOOTTIME, &boot) == 0 && clock_gettime(CLOCK_MONOTONIC, &mono) == 0) - return boot.tv_sec - mono.tv_sec; + return timespec_to_usec(&boot) - timespec_to_usec(&mono); #endif return 0; } diff --git a/sys-utils/dmesg.c b/sys-utils/dmesg.c index 42000cb40e..6bd6880adb 100644 --- a/sys-utils/dmesg.c +++ b/sys-utils/dmesg.c @@ -170,7 +170,7 @@ struct dmesg_control { struct timeval lasttime; /* last printed timestamp */ struct tm lasttm; /* last localtime */ struct timeval boot_time; /* system boot time */ - time_t suspended_time; /* time spent in suspended state */ + usec_t suspended_time; /* time spent in suspended state */ int action; /* SYSLOG_ACTION_* */ int method; /* DMESG_METHOD_* */ @@ -786,7 +786,7 @@ static int get_next_syslog_record(struct dmesg_control *ctl, static time_t record_time(struct dmesg_control *ctl, struct dmesg_record *rec) { - return ctl->boot_time.tv_sec + ctl->suspended_time + rec->tv.tv_sec; + return ctl->boot_time.tv_sec + ctl->suspended_time / USEC_PER_SEC + rec->tv.tv_sec; } static int accept_record(struct dmesg_control *ctl, struct dmesg_record *rec) @@ -877,7 +877,7 @@ static char *iso_8601_time(struct dmesg_control *ctl, struct dmesg_record *rec, char *buf, size_t bufsz) { struct timeval tv = { - .tv_sec = ctl->boot_time.tv_sec + ctl->suspended_time + rec->tv.tv_sec, + .tv_sec = ctl->boot_time.tv_sec + ctl->suspended_time / USEC_PER_SEC + rec->tv.tv_sec, .tv_usec = rec->tv.tv_usec }; @@ -1355,7 +1355,7 @@ static inline int dmesg_get_boot_time(struct timeval *tv) return get_boot_time(tv); } -static inline time_t dmesg_get_suspended_time(void) +static inline usec_t dmesg_get_suspended_time(void) { if (getenv("DMESG_TEST_BOOTIME")) return 0;