From owner-svn-src-all@FreeBSD.ORG Fri Aug 3 09:08:21 2012 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3F273106566B; Fri, 3 Aug 2012 09:08:21 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 109288FC17; Fri, 3 Aug 2012 09:08:21 +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 q7398K3g093087; Fri, 3 Aug 2012 09:08:20 GMT (envelope-from mav@svn.freebsd.org) Received: (from mav@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q7398Kbf093085; Fri, 3 Aug 2012 09:08:20 GMT (envelope-from mav@svn.freebsd.org) Message-Id: <201208030908.q7398Kbf093085@svn.freebsd.org> From: Alexander Motin Date: Fri, 3 Aug 2012 09:08:20 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r239005 - head/sys/kern X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 03 Aug 2012 09:08:21 -0000 Author: mav Date: Fri Aug 3 09:08:20 2012 New Revision: 239005 URL: http://svn.freebsd.org/changeset/base/239005 Log: Microoptimize time math. As soon as our event periods are always below ome second we may not add intereger parts by using bintime_addx() instead of bintime_add(). Profiling shows handleevents() time redction by 15%. Modified: head/sys/kern/kern_clocksource.c Modified: head/sys/kern/kern_clocksource.c ============================================================================== --- head/sys/kern/kern_clocksource.c Fri Aug 3 05:39:32 2012 (r239004) +++ head/sys/kern/kern_clocksource.c Fri Aug 3 09:08:20 2012 (r239005) @@ -205,19 +205,21 @@ handleevents(struct bintime *now, int fa runs = 0; while (bintime_cmp(now, &state->nexthard, >=)) { - bintime_add(&state->nexthard, &hardperiod); + bintime_addx(&state->nexthard, hardperiod.frac); runs++; } - if ((timer->et_flags & ET_FLAGS_PERCPU) == 0 && - bintime_cmp(&state->nexthard, &nexthard, >)) - nexthard = state->nexthard; - if (runs && fake < 2) { - hardclock_cnt(runs, usermode); - done = 1; + if (runs) { + if ((timer->et_flags & ET_FLAGS_PERCPU) == 0 && + bintime_cmp(&state->nexthard, &nexthard, >)) + nexthard = state->nexthard; + if (fake < 2) { + hardclock_cnt(runs, usermode); + done = 1; + } } runs = 0; while (bintime_cmp(now, &state->nextstat, >=)) { - bintime_add(&state->nextstat, &statperiod); + bintime_addx(&state->nextstat, statperiod.frac); runs++; } if (runs && fake < 2) { @@ -227,7 +229,7 @@ handleevents(struct bintime *now, int fa if (profiling) { runs = 0; while (bintime_cmp(now, &state->nextprof, >=)) { - bintime_add(&state->nextprof, &profperiod); + bintime_addx(&state->nextprof, profperiod.frac); runs++; } if (runs && !fake) { @@ -356,7 +358,7 @@ timercb(struct eventtimer *et, void *arg next = &nexttick; if (periodic) { now = *next; /* Ex-next tick time becomes present time. */ - bintime_add(next, &timerperiod); /* Next tick in 1 period. */ + bintime_addx(next, timerperiod.frac); /* Next tick in 1 period. */ } else { binuptime(&now); /* Get present time from hardware. */ next->sec = -1; /* Next tick is not scheduled yet. */ @@ -433,7 +435,7 @@ loadtimer(struct bintime *now, int start new.sec = 0; new.frac = timerperiod.frac - tmp; if (new.frac < tmp) /* Left less then passed. */ - bintime_add(&new, &timerperiod); + bintime_addx(&new, timerperiod.frac); CTR5(KTR_SPARE2, "load p at %d: now %d.%08x first in %d.%08x", curcpu, now->sec, (unsigned int)(now->frac >> 32), new.sec, (unsigned int)(new.frac >> 32)); @@ -531,7 +533,7 @@ configtimer(int start) if (start) { /* Initialize time machine parameters. */ next = now; - bintime_add(&next, &timerperiod); + bintime_addx(&next, timerperiod.frac); if (periodic) nexttick = next; else