Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 18 Jun 2012 18:25:58 +0000 (UTC)
From:      Davide Italiano <davide@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-projects@freebsd.org
Subject:   svn commit: r237233 - projects/calloutng/sys/kern
Message-ID:  <201206181825.q5IIPw1S093880@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: davide
Date: Mon Jun 18 18:25:57 2012
New Revision: 237233
URL: http://svn.freebsd.org/changeset/base/237233

Log:
  Don't compute the bucket applying the hash function if there's no need to
  do this. While here, try to simplify the callout_tick() logic and fix
  a couple of style bugs.
  
  Discussed with:		mav

Modified:
  projects/calloutng/sys/kern/kern_timeout.c

Modified: projects/calloutng/sys/kern/kern_timeout.c
==============================================================================
--- projects/calloutng/sys/kern/kern_timeout.c	Mon Jun 18 17:23:24 2012	(r237232)
+++ projects/calloutng/sys/kern/kern_timeout.c	Mon Jun 18 18:25:57 2012	(r237233)
@@ -358,13 +358,11 @@ get_bucket(struct bintime *bt)
 void
 callout_tick(void)
 {
+	struct bintime limit, next, now;
 	struct callout *tmp;
 	struct callout_cpu *cc;
 	struct callout_tailq *sc;
-	struct bintime now;
-	struct bintime limit;
-	struct bintime next;
-	int cpu, first, flag, future, last, need_softclock; 
+	int cpu, first, future, last, need_softclock; 
 
 	/*
 	 * Process callouts at a very low cpu priority, so we don't keep the
@@ -374,8 +372,12 @@ callout_tick(void)
 	cc = CC_SELF();
 	mtx_lock_spin_flags(&cc->cc_lock, MTX_QUIET);
 	binuptime(&now);
+	cpu = curcpu;
 	first = callout_hash(&cc->cc_softticks);
 	last = callout_hash(&now);
+	next.sec = -1;
+	next.frac = -1;
+	future = ((last + hz/4) & callwheelmask); 
 	/* 
 	 * Check if we wrapped around the entire wheel from the last scan.
 	 * In case, we need to scan entirely the wheel for pending callouts.
@@ -388,19 +390,10 @@ callout_tick(void)
 		first &= callwheelmask;
 		last &= callwheelmask;
 	}
-	cpu = curcpu;
-	next.sec = -1;
-	next .frac = -1;
-	limit.sec = 0;
-	limit.frac = 4611686018427250000; /* 1/4 sec */
-	bintime_add(&limit,&now);
-	future = get_bucket(&limit);
-	flag = 0;
 	for (;;) {	
 		sc = &cc->cc_callwheel[first];
 		TAILQ_FOREACH(tmp, sc, c_links.tqe) {
-			if ((!flag || flag == 1) && 
-			    bintime_cmp(&tmp->c_time, &now, <=)) {
+			if (bintime_cmp(&tmp->c_time, &now, <=)) {
 				if (tmp->c_flags & CALLOUT_DIRECT) {
 					tmp->c_func(tmp->c_arg);
 					TAILQ_REMOVE(sc, tmp, c_links.tqe);
@@ -414,8 +407,18 @@ callout_tick(void)
 					need_softclock = 1;
 				}
 			}	
-			if ((flag == 1 || flag == 2)  && 
-			    bintime_cmp(&tmp->c_time, &now, >)) {
+		}	
+		if (first == last)
+			break;
+		first = ((first + 1) & callwheelmask);
+	}
+	limit.sec = 0;
+	limit.frac = (uint64_t)1 << (64 - 2);
+	bintime_add(&limit, &now);		
+	for (;;) {
+		sc = &cc->cc_callwheel[last];
+		TAILQ_FOREACH(tmp, sc, c_links.tqe) {
+			if (bintime_cmp(&tmp->c_time, &limit, <=)) {
 				if (next.sec == -1 ||
 				    bintime_cmp(&tmp->c_time, &next, <)) {
 					next = tmp->c_time;
@@ -423,16 +426,15 @@ callout_tick(void)
 				}
 			}
 		}
-		if (first == ((last - 1) & callwheelmask)) 
-			flag = 1;
-		if (first == last)
-			flag = 2;
-		if (first == future || next.sec != -1)
+		if ((last == future) || (next.sec != -1))
 			break;
-		first = (first + 1) & callwheelmask;
+		last = ((last + 1) & callwheelmask);
+	}	
+	if (next.sec == -1) { 
+		next.sec = 0;	
+		next.frac = (uint64_t)1 << (64 - 2);	
+		bintime_add(&next, &now);
 	}
-	if (next.sec == -1)  
-		next = limit;
 	cc->cc_firsttick = next;
 	if (callout_new_inserted != NULL) 
 		(*callout_new_inserted)(cpu, next);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201206181825.q5IIPw1S093880>