From owner-svn-src-projects@FreeBSD.ORG Mon Jun 18 18:25:58 2012 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 984531065675; Mon, 18 Jun 2012 18:25:58 +0000 (UTC) (envelope-from davide@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 79A498FC08; Mon, 18 Jun 2012 18:25:58 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q5IIPwG2093882; Mon, 18 Jun 2012 18:25:58 GMT (envelope-from davide@svn.freebsd.org) Received: (from davide@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q5IIPw1S093880; Mon, 18 Jun 2012 18:25:58 GMT (envelope-from davide@svn.freebsd.org) Message-Id: <201206181825.q5IIPw1S093880@svn.freebsd.org> From: Davide Italiano Date: Mon, 18 Jun 2012 18:25:58 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r237233 - projects/calloutng/sys/kern X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 18 Jun 2012 18:25:58 -0000 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);