dovecot-2.2: lib: Added io_loop_get_wait_usecs()

dovecot at dovecot.org dovecot at dovecot.org
Mon Sep 21 11:04:08 UTC 2015


details:   http://hg.dovecot.org/dovecot-2.2/rev/1076679adf9f
changeset: 19160:1076679adf9f
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Sep 21 13:59:41 2015 +0300
description:
lib: Added io_loop_get_wait_usecs()

diffstat:

 src/lib/ioloop-private.h |   1 +
 src/lib/ioloop.c         |  31 +++++++++++++++++++++++--------
 src/lib/ioloop.h         |   2 ++
 3 files changed, 26 insertions(+), 8 deletions(-)

diffs (81 lines):

diff -r c607ef95a785 -r 1076679adf9f src/lib/ioloop-private.h
--- a/src/lib/ioloop-private.h	Mon Sep 21 13:59:22 2015 +0300
+++ b/src/lib/ioloop-private.h	Mon Sep 21 13:59:41 2015 +0300
@@ -25,6 +25,7 @@
 
 	io_loop_time_moved_callback_t *time_moved_callback;
 	time_t next_max_time;
+	uint64_t ioloop_wait_usecs;
 
 	unsigned int io_pending_count;
 
diff -r c607ef95a785 -r 1076679adf9f src/lib/ioloop.c
--- a/src/lib/ioloop.c	Mon Sep 21 13:59:22 2015 +0300
+++ b/src/lib/ioloop.c	Mon Sep 21 13:59:41 2015 +0300
@@ -402,6 +402,12 @@
 	tv_now.tv_sec = 0;
 	msecs = timeout_get_wait_time(timeout, tv_r, &tv_now);
 	ioloop->next_max_time = (tv_now.tv_sec + msecs/1000) + 1;
+
+	/* update ioloop_timeval - this is meant for io_loop_handle_timeouts()'s
+	   ioloop_wait_usecs calculation. normally after this we go to the
+	   ioloop and after that we update ioloop_timeval immediately again. */
+	ioloop_timeval = tv_now;
+	ioloop_time = tv_now.tv_sec;
 	return msecs;
 }
 
@@ -466,7 +472,7 @@
 static void io_loop_handle_timeouts_real(struct ioloop *ioloop)
 {
 	struct priorityq_item *item;
-	struct timeval tv, tv_call;
+	struct timeval tv, tv_call, prev_ioloop_timeval = ioloop_timeval;
 	unsigned int t_id;
 
 	if (gettimeofday(&ioloop_timeval, NULL) < 0)
@@ -482,13 +488,17 @@
 		/* the callback may have slept, so check the time again. */
 		if (gettimeofday(&ioloop_timeval, NULL) < 0)
 			i_fatal("gettimeofday(): %m");
-	} else if (unlikely(ioloop_timeval.tv_sec >
-			    ioloop->next_max_time)) {
-		io_loops_timeouts_update(ioloop_timeval.tv_sec -
-					ioloop->next_max_time);
-		/* time moved forwards */
-		ioloop->time_moved_callback(ioloop->next_max_time,
-					    ioloop_timeval.tv_sec);
+	} else {
+		if (unlikely(ioloop_timeval.tv_sec >
+			     ioloop->next_max_time)) {
+			io_loops_timeouts_update(ioloop_timeval.tv_sec -
+						 ioloop->next_max_time);
+			/* time moved forwards */
+			ioloop->time_moved_callback(ioloop->next_max_time,
+						    ioloop_timeval.tv_sec);
+		}
+		ioloop->ioloop_wait_usecs +=
+			timeval_diff_usecs(&ioloop_timeval, &prev_ioloop_timeval);
 	}
 
 	ioloop_time = ioloop_timeval.tv_sec;
@@ -933,3 +943,8 @@
 
 	return io_loop_get_wait_time(ioloop, &tv) == 0;
 }
+
+uint64_t io_loop_get_wait_usecs(struct ioloop *ioloop)
+{
+	return ioloop->ioloop_wait_usecs;
+}
diff -r c607ef95a785 -r 1076679adf9f src/lib/ioloop.h
--- a/src/lib/ioloop.h	Mon Sep 21 13:59:22 2015 +0300
+++ b/src/lib/ioloop.h	Mon Sep 21 13:59:41 2015 +0300
@@ -185,5 +185,7 @@
 /* Returns TRUE if there is a pending timeout that is going to be run
    immediately. */
 bool io_loop_have_immediate_timeouts(struct ioloop *ioloop);
+/* Returns number of microseconds spent on the ioloop waiting itself. */
+uint64_t io_loop_get_wait_usecs(struct ioloop *ioloop);
 
 #endif


More information about the dovecot-cvs mailing list