From 58411110894c0a9e6a1a1ec9dbdf2fbe2ef3da00 Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Fri, 21 Aug 2009 16:06:08 +0200 Subject: conntrackd: reduce the number of gettimeofday() syscalls This patch reduces the number of gettimeofday syscalls by caching the current time in a variable at the beginning of the main loop. Based on a suggestion from Vincent Jardin. Signed-off-by: Pablo Neira Ayuso --- src/alarm.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/alarm.c') diff --git a/src/alarm.c b/src/alarm.c index fe938a0..006721a 100644 --- a/src/alarm.c +++ b/src/alarm.c @@ -17,6 +17,7 @@ */ #include "alarm.h" +#include "date.h" #include #include @@ -61,7 +62,7 @@ void add_alarm(struct alarm_block *alarm, unsigned long sc, unsigned long usc) del_alarm(alarm); alarm->tv.tv_sec = sc; alarm->tv.tv_usec = usc; - gettimeofday(&tv, NULL); + gettimeofday_cached(&tv); timeradd(&alarm->tv, &tv, &alarm->tv); __add_alarm(alarm); } @@ -107,7 +108,7 @@ get_next_alarm_run(struct timeval *next_run) struct rb_node *node; struct timeval tv; - gettimeofday(&tv, NULL); + gettimeofday_cached(&tv); node = rb_first(&alarm_root); if (node) { @@ -126,7 +127,7 @@ do_alarm_run(struct timeval *next_run) struct alarm_block *this, *tmp; struct timeval tv; - gettimeofday(&tv, NULL); + gettimeofday_cached(&tv); INIT_LIST_HEAD(&alarm_run_queue); for (node = rb_first(&alarm_root); node; node = rb_next(node)) { -- cgit v1.2.3