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>
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();
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: