Skip to contentSkip to conversation

fsck.f2fs: report real wall time

PATCH In review Jaegeuk Kim 2 participants 2 messages Mar 9, 2020 – Mar 16, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fsck.f2fs: report real wall time

From: Wei Wang <[email protected]>

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)

---
 fsck/main.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
fsck/main.c +9 -2
index a6fd970..c481ce4 100644
@@ -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:
Signature · 8 lines
2.25.1.481.gfbce0eb801-goog



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Jaegeuk Kim

From: Wei Wang <[email protected]>

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.

Quoted 4 lines

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

Thanks,

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel