All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jaegeuk Kim <jaegeuk@kernel.org>
To: linux-f2fs-devel@lists.sourceforge.net
Cc: Wei Wang <wvw@google.com>, Jaegeuk Kim <jaegeuk@kernel.org>
Subject: [f2fs-dev] [PATCH] fsck.f2fs: report real wall time
Date: Mon,  9 Mar 2020 14:19:18 -0700	[thread overview]
Message-ID: <20200309211918.159991-1-jaegeuk@kernel.org> (raw)

From: Wei Wang <wvw@google.com>

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>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
---
 fsck/main.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/fsck/main.c b/fsck/main.c
index a6fd970..c481ce4 100644
--- a/fsck/main.c
+++ b/fsck/main.c
@@ -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:
-- 
2.25.1.481.gfbce0eb801-goog



_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

             reply	other threads:[~2020-03-09 21:19 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-09 21:19 Jaegeuk Kim [this message]
2020-03-16  6:17 ` [f2fs-dev] [PATCH] fsck.f2fs: report real wall time Chao Yu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200309211918.159991-1-jaegeuk@kernel.org \
    --to=jaegeuk@kernel.org \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    --cc=wvw@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.