Skip to contentSkip to conversation

fsck: use monotonic time to fsck run time measurement

PATCH Applied Sami Kerola 2 participants 2 messages Feb 3, 2015 – Feb 10, 2015 Util-Linux package

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fsck: use monotonic time to fsck run time measurement

Earlier use of gettimeofday() resulted to wrong measurement if system administrator did manual time changes, or NTP or adjtime(3) adjusment happen during fsck run.

---
 disk-utils/Makemodule.am |  4 ++--
 disk-utils/fsck.c        | 14 +++++++-------
 2 files changed, 9 insertions(+), 9 deletions(-)
disk-utils/Makemodule.am +2 -2
index 2280b9d..b4606a1 100644
@@ -83,8 +83,8 @@ endif #BUILD_SWAPLABEL
 if BUILD_FSCK
 sbin_PROGRAMS += fsck
 dist_man_MANS += disk-utils/fsck.8
-fsck_SOURCES = disk-utils/fsck.c
-fsck_LDADD = $(LDADD) libmount.la libblkid.la libcommon.la
+fsck_SOURCES = disk-utils/fsck.c lib/monotonic.c
+fsck_LDADD = $(LDADD) libmount.la libblkid.la libcommon.la $(CLOCKGETTIME_LIBS)
 fsck_CFLAGS = $(AM_CFLAGS) -I$(ul_libmount_incdir) -I$(ul_libblkid_incdir)
 endif
 
disk-utils/fsck.c +7 -7
index 277d041..78ad43e 100644
@@ -54,6 +54,7 @@
 #include "c.h"
 #include "closestream.h"
 #include "fileutils.h"
+#include "monotonic.h"
 
 #define XALLOC_EXIT_CODE	FSCK_EX_ERROR
 #include "xalloc.h"
@@ -577,20 +578,19 @@ static int progress_active(void)
  */
 static void print_stats(struct fsck_instance *inst)
 {
-	double time_diff;
+	struct timeval delta;
 
 	if (!inst || !report_stats || noexecute)
 		return;
 
-	time_diff = (inst->end_time.tv_sec  - inst->start_time.tv_sec)
-		  + (inst->end_time.tv_usec - inst->start_time.tv_usec) / 1E6;
+	timersub(&inst->end_time, &inst->start_time, &delta);
 
 	fprintf(stdout, "%s: status %d, rss %ld, "
-			"real %f, user %d.%06d, sys %d.%06d\n",
+			"real %ld.%06ld, user %d.%06d, sys %d.%06d\n",
 		fs_get_device(inst->fs),
 		inst->exit_status,
 		inst->rusage.ru_maxrss,
-		time_diff,
+		delta.tv_sec, delta.tv_usec,
 		(int)inst->rusage.ru_utime.tv_sec,
 		(int)inst->rusage.ru_utime.tv_usec,
 		(int)inst->rusage.ru_stime.tv_sec,
@@ -676,7 +676,7 @@ static int execute(const char *progname, const char *progpath,
 	inst->pid = pid;
 	inst->prog = xstrdup(progname);
 	inst->type = xstrdup(type);
-	gettimeofday(&inst->start_time, NULL);
+	gettime_monotonic(&inst->start_time);
 	inst->next = NULL;
 
 	/*
@@ -789,7 +789,7 @@ static struct fsck_instance *wait_one(int flags)
 
 	inst->exit_status = status;
 	inst->flags |= FLAG_DONE;
-	gettimeofday(&inst->end_time, NULL);
+	gettime_monotonic(&inst->end_time);
 	memcpy(&inst->rusage, &rusage, sizeof(struct rusage));
 
 	if (progress && (inst->flags & FLAG_PROGRESS) &&
Signature · 1 line
2.2.2
maintainer Applied
#1 lore raw
Quoted 3 lines · Sami Kerola
 disk-utils/Makemodule.am |  4 ++--
 disk-utils/fsck.c        | 14 +++++++-------
 2 files changed, 9 insertions(+), 9 deletions(-)

Applied, thanks.

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com