fsck.f2fs: report real wall time
authorWei Wang <wvw@google.com>
Mon, 9 Mar 2020 19:54:27 +0000 (12:54 -0700)
committerJaegeuk Kim <jaegeuk@kernel.org>
Thu, 19 Mar 2020 01:07:13 +0000 (18:07 -0700)
clock_t time is per-process time, which is not wall time. For example,
if the CPU is shared by other processes, clock_t time may advance slower
than wall clock. On the other hand, if the current process is
multithreaded and more than one execution core is available, clock_t
time may advance faster than wall clock.

this CL changes it to use CLOCK_BOOTTIME (Linux-specific)

Signed-off-by: Wei Wang <wvw@google.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fsck/main.c

index a6fd970..c481ce4 100644 (file)
@@ -801,11 +801,18 @@ static int do_sload(struct f2fs_sb_info *sbi)
        return f2fs_sload(sbi);
 }
 
+static u64 get_boottime_ns() {
+       struct timespec t;
+       t.tv_sec = t.tv_nsec = 0;
+       clock_gettime(CLOCK_BOOTTIME, &t);
+       return (u64)t.tv_sec * 1000000000LL + t.tv_nsec;
+}
+
 int main(int argc, char **argv)
 {
        struct f2fs_sb_info *sbi;
        int ret = 0;
-       clock_t start = clock();
+       u64 start = get_boottime_ns();
 
        f2fs_init_configuration();
 
@@ -919,7 +926,7 @@ retry:
        if (ret < 0)
                return ret;
 
-       printf("\nDone: %lf secs\n", (clock() - start) / (double)CLOCKS_PER_SEC);
+       printf("\nDone: %lf secs\n", (get_boottime_ns() - start) / 1000000000.0);
        return 0;
 
 out_err: