[Ocfs2-commits] mfasheh commits r2537 - trunk/fs/ocfs2/cluster

svn-commits at oss.oracle.com svn-commits at oss.oracle.com
Fri Aug 19 18:05:27 CDT 2005


Author: mfasheh
Signed-off-by: manish
Date: 2005-08-19 18:05:25 -0500 (Fri, 19 Aug 2005)
New Revision: 2537

Modified:
   trunk/fs/ocfs2/cluster/heartbeat.c
Log:
* Have heartbeat sleep only as much as is required based on how long
  it spent doing it's work. This should help on busy systems.

Signed-off-by: manish



Modified: trunk/fs/ocfs2/cluster/heartbeat.c
===================================================================
--- trunk/fs/ocfs2/cluster/heartbeat.c	2005-08-19 21:39:50 UTC (rev 2536)
+++ trunk/fs/ocfs2/cluster/heartbeat.c	2005-08-19 23:05:25 UTC (rev 2537)
@@ -851,6 +851,32 @@
 	}
 }
 
+/* Subtract b from a, storing the result in a. a *must* have a larger
+ * value than b. */
+static void o2hb_tv_subtract(struct timeval *a,
+			     struct timeval *b)
+{
+	BUG_ON(a->tv_sec < b->tv_sec);
+	BUG_ON(a->tv_sec == b->tv_sec && a->tv_usec < b->tv_usec);
+
+        a->tv_sec -= b->tv_sec;
+        a->tv_usec -= b->tv_usec;
+        while ( a->tv_usec < 0 ) {
+                a->tv_sec--;
+                a->tv_usec += 1000000;
+        }
+}
+
+static unsigned int o2hb_elapsed_msecs(struct timeval *start,
+				       struct timeval *end)
+{
+	struct timeval res = *end;
+
+	o2hb_tv_subtract(&res, start);
+
+	return res.tv_sec * 1000 + res.tv_usec / 1000;
+}
+
 /*
  * we ride the region ref that the region dir holds.  before the region
  * dir is removed and drops it ref it will wait to tear down this
@@ -862,17 +888,35 @@
 	struct o2hb_region *reg = data;
 	struct bio *write_bio;
 	struct o2hb_bio_wait_ctxt write_wc;
+	struct timeval before_hb, after_hb;
+	unsigned int elapsed_msec;
 
 	mlog(ML_HEARTBEAT|ML_KTHREAD, "hb thread running\n");
 
 	set_user_nice(current, -20);
 
 	while (!kthread_should_stop() && !reg->hr_unclean_stop) {
+		/* We track the time spent inside
+		 * o2hb_do_disk_heartbeat so that we avoid more then
+		 * hr_timeout_ms between disk writes. On busy systems
+		 * this should result in a heartbeat which is less
+		 * likely to time itself out. */
+		do_gettimeofday(&before_hb);
+
 		o2hb_do_disk_heartbeat(reg);
 
-		/* the kthread api has blocked signals for us so no
-		 * need to record the return value. */
-		msleep_interruptible(reg->hr_timeout_ms);
+		do_gettimeofday(&after_hb);
+		elapsed_msec = o2hb_elapsed_msecs(&before_hb, &after_hb);
+
+		mlog(0, "start = %lu.%lu, end = %lu.%lu, msec = %u\n",
+		     before_hb.tv_sec, before_hb.tv_usec,
+		     after_hb.tv_sec, after_hb.tv_usec, elapsed_msec);
+
+		if (elapsed_msec < reg->hr_timeout_ms) {
+			/* the kthread api has blocked signals for us so no
+			 * need to record the return value. */
+			msleep_interruptible(reg->hr_timeout_ms - elapsed_msec);
+		}
 	}
 
 	o2hb_disarm_write_timeout(reg);



More information about the Ocfs2-commits mailing list