Skip to content

Commit 40476b8

Browse files
Tinabr7torvalds
authored andcommitted
ocfs2: use 64bit variables to track heartbeat time
o2hb_elapsed_msecs computes the time taken for a disk heartbeat. 'struct timeval' variables are used to store start and end times. On 32-bit systems, the 'tv_sec' component of 'struct timeval' will overflow in year 2038 and beyond. This patch solves the overflow with the following: 1. Replace o2hb_elapsed_msecs using 'ktime_t' values to measure start and end time, and built-in function 'ktime_ms_delta' to compute the elapsed time. ktime_get_real() is used since the code prints out the wallclock time. 2. Changes format string to print time as a single 64-bit nanoseconds value ("%lld") instead of seconds and microseconds. This simplifies the code since converting ktime_t to that format would need expensive computation. However, the debug log string is less readable than the previous format. Signed-off-by: Tina Ruchandani <[email protected]> Suggested by: Arnd Bergmann <[email protected]> Reviewed-by: Mark Fasheh <[email protected]> Cc: Joel Becker <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent ad69482 commit 40476b8

File tree

1 file changed

+9
-40
lines changed

1 file changed

+9
-40
lines changed

fs/ocfs2/cluster/heartbeat.c

Lines changed: 9 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
#include <linux/debugfs.h>
3737
#include <linux/slab.h>
3838
#include <linux/bitmap.h>
39-
39+
#include <linux/ktime.h>
4040
#include "heartbeat.h"
4141
#include "tcp.h"
4242
#include "nodemanager.h"
@@ -1060,37 +1060,6 @@ static int o2hb_do_disk_heartbeat(struct o2hb_region *reg)
10601060
return ret;
10611061
}
10621062

1063-
/* Subtract b from a, storing the result in a. a *must* have a larger
1064-
* value than b. */
1065-
static void o2hb_tv_subtract(struct timeval *a,
1066-
struct timeval *b)
1067-
{
1068-
/* just return 0 when a is after b */
1069-
if (a->tv_sec < b->tv_sec ||
1070-
(a->tv_sec == b->tv_sec && a->tv_usec < b->tv_usec)) {
1071-
a->tv_sec = 0;
1072-
a->tv_usec = 0;
1073-
return;
1074-
}
1075-
1076-
a->tv_sec -= b->tv_sec;
1077-
a->tv_usec -= b->tv_usec;
1078-
while ( a->tv_usec < 0 ) {
1079-
a->tv_sec--;
1080-
a->tv_usec += 1000000;
1081-
}
1082-
}
1083-
1084-
static unsigned int o2hb_elapsed_msecs(struct timeval *start,
1085-
struct timeval *end)
1086-
{
1087-
struct timeval res = *end;
1088-
1089-
o2hb_tv_subtract(&res, start);
1090-
1091-
return res.tv_sec * 1000 + res.tv_usec / 1000;
1092-
}
1093-
10941063
/*
10951064
* we ride the region ref that the region dir holds. before the region
10961065
* dir is removed and drops it ref it will wait to tear down this
@@ -1101,7 +1070,7 @@ static int o2hb_thread(void *data)
11011070
int i, ret;
11021071
struct o2hb_region *reg = data;
11031072
struct o2hb_bio_wait_ctxt write_wc;
1104-
struct timeval before_hb, after_hb;
1073+
ktime_t before_hb, after_hb;
11051074
unsigned int elapsed_msec;
11061075

11071076
mlog(ML_HEARTBEAT|ML_KTHREAD, "hb thread running\n");
@@ -1118,18 +1087,18 @@ static int o2hb_thread(void *data)
11181087
* hr_timeout_ms between disk writes. On busy systems
11191088
* this should result in a heartbeat which is less
11201089
* likely to time itself out. */
1121-
do_gettimeofday(&before_hb);
1090+
before_hb = ktime_get_real();
11221091

11231092
ret = o2hb_do_disk_heartbeat(reg);
11241093

1125-
do_gettimeofday(&after_hb);
1126-
elapsed_msec = o2hb_elapsed_msecs(&before_hb, &after_hb);
1094+
after_hb = ktime_get_real();
1095+
1096+
elapsed_msec = (unsigned int)
1097+
ktime_ms_delta(after_hb, before_hb);
11271098

11281099
mlog(ML_HEARTBEAT,
1129-
"start = %lu.%lu, end = %lu.%lu, msec = %u, ret = %d\n",
1130-
before_hb.tv_sec, (unsigned long) before_hb.tv_usec,
1131-
after_hb.tv_sec, (unsigned long) after_hb.tv_usec,
1132-
elapsed_msec, ret);
1100+
"start = %lld, end = %lld, msec = %u, ret = %d\n",
1101+
before_hb.tv64, after_hb.tv64, elapsed_msec, ret);
11331102

11341103
if (!kthread_should_stop() &&
11351104
elapsed_msec < reg->hr_timeout_ms) {

0 commit comments

Comments
 (0)