From owner-freebsd-current@FreeBSD.ORG Fri Jun 5 17:30:48 2015 Return-Path: Delivered-To: freebsd-current@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 901C5C9A; Fri, 5 Jun 2015 17:30:48 +0000 (UTC) (envelope-from jenkins-admin@freebsd.org) Received: from jenkins-9.freebsd.org (jenkins-9.freebsd.org [8.8.178.209]) by mx1.freebsd.org (Postfix) with ESMTP id 801FD1BA6; Fri, 5 Jun 2015 17:30:48 +0000 (UTC) (envelope-from jenkins-admin@freebsd.org) Received: from jenkins-9.freebsd.org (localhost [127.0.0.1]) by jenkins-9.freebsd.org (Postfix) with ESMTP id A36A315EB; Fri, 5 Jun 2015 17:30:46 +0000 (UTC) Date: Fri, 5 Jun 2015 17:30:43 +0000 (GMT) From: jenkins-admin@freebsd.org To: avg@FreeBSD.org, jenkins-admin@FreeBSD.org, freebsd-current@FreeBSD.org, freebsd-i386@FreeBSD.org Message-ID: <798928401.54.1433525444293.JavaMail.jenkins@jenkins-9.freebsd.org> Subject: FreeBSD_HEAD_i386 - Build #243 - Failure MIME-Version: 1.0 X-Jenkins-Job: FreeBSD_HEAD_i386 X-Jenkins-Result: FAILURE Precedence: bulk Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Content-Filtered-By: Mailman/MimeDel 2.1.20 X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.20 List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 05 Jun 2015 17:30:48 -0000 FreeBSD_HEAD_i386 - Build #243 - Failure: Check console output at https://jenkins.freebsd.org/job/FreeBSD_HEAD_i386/243/ to view the results. From owner-freebsd-current@FreeBSD.ORG Fri Jun 5 18:19:25 2015 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 048C5CF9; Fri, 5 Jun 2015 18:19:25 +0000 (UTC) (envelope-from jenkins-admin@freebsd.org) Received: from jenkins-9.freebsd.org (jenkins-9.freebsd.org [8.8.178.209]) by mx1.freebsd.org (Postfix) with ESMTP id E63921796; Fri, 5 Jun 2015 18:19:24 +0000 (UTC) (envelope-from jenkins-admin@freebsd.org) Received: from jenkins-9.freebsd.org (localhost [127.0.0.1]) by jenkins-9.freebsd.org (Postfix) with ESMTP id 0098A1604; Fri, 5 Jun 2015 18:19:24 +0000 (UTC) Date: Fri, 5 Jun 2015 18:19:23 +0000 (GMT) From: jenkins-admin@freebsd.org To: achim@FreeBSD.org, avg@FreeBSD.org, sbruno@FreeBSD.org, jenkins-admin@FreeBSD.org, freebsd-current@freebsd.org Message-ID: <727275265.56.1433528364928.JavaMail.jenkins@jenkins-9.freebsd.org> Subject: FreeBSD_HEAD - Build #2830 - Failure MIME-Version: 1.0 X-Jenkins-Job: FreeBSD_HEAD X-Jenkins-Result: FAILURE Precedence: bulk Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Content-Filtered-By: Mailman/MimeDel 2.1.20 X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.20 List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 05 Jun 2015 18:19:25 -0000 FreeBSD_HEAD - Build #2830 - Failure: Check console output at https://jenkins.freebsd.org/job/FreeBSD_HEAD/2830/ to view the results. From owner-freebsd-current@FreeBSD.ORG Fri Jun 5 18:31:17 2015 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id A22E923A for ; Fri, 5 Jun 2015 18:31:17 +0000 (UTC) (envelope-from neelnatu@gmail.com) Received: from mail-wg0-x22a.google.com (mail-wg0-x22a.google.com [IPv6:2a00:1450:400c:c00::22a]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 3BD001B98 for ; Fri, 5 Jun 2015 18:31:17 +0000 (UTC) (envelope-from neelnatu@gmail.com) Received: by wgbgq6 with SMTP id gq6so62991648wgb.3 for ; Fri, 05 Jun 2015 11:31:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=0zrJcotXc3KSsoJ6FI4rAE1DzExxeIN4WKRBl+TtZ5g=; b=JH5cvnMMXdiKHqGpTw/8xn2YYAaRsgVigky4JSkSnvQ8xIaLeQPzFfPZF1XLuTLH+d i0MFa6foeYBxe9Zf8JHIzzrOVzeDc/k81L3283i4OuJ8xGC0iZvBey/vKTfrVSXB+Mmb jZ6+GXgJJQoISLjU7AaeWg+4QIn4TDiiPpOcLy/6H3jmPtXOaHM1FuCQ1xzzagu9nQ63 Fv1NTQ6nPzxwRGTi2ULwRM4ufD3+Zk8DEpACSQcQNwWMCGhRRj06j1ea+eqXoD9gV+5U zMiluy6y3Ok3cUA1z3cavkbhjv2JXxAncPOZGQyU5U86ZE7xRhGc7g6LnBowRnL4x3xH HrXw== MIME-Version: 1.0 X-Received: by 10.194.62.201 with SMTP id a9mr8594728wjs.63.1433529074637; Fri, 05 Jun 2015 11:31:14 -0700 (PDT) Received: by 10.27.52.18 with HTTP; Fri, 5 Jun 2015 11:31:14 -0700 (PDT) In-Reply-To: <55714B26.6060802@selasky.org> References: <55714B26.6060802@selasky.org> Date: Fri, 5 Jun 2015 11:31:14 -0700 Message-ID: Subject: Re: [CFR] Replacing while loops with proper division and multiplication From: Neel Natu To: Hans Petter Selasky Cc: FreeBSD Current Content-Type: text/plain; charset=UTF-8 X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 05 Jun 2015 18:31:17 -0000 Hi Hans, On Fri, Jun 5, 2015 at 12:09 AM, Hans Petter Selasky wrote: > Hi, > > I was going through some timer code and found some unnecessary while loops > in kern/kern_clocksource.c . > > I added some prints and found that during boot, "runs" can exceed 2000, > while during regular usage runs is typically 1. Do you think it is worth to > convert these loops into division and multiplications? It might make the CPU > pipeline a tiny bit faster, having to skip some conditionals? And also > possibly improve readability? > > What do you think? > > --HPS > >> Index: kern/kern_clocksource.c >> =================================================================== >> --- kern/kern_clocksource.c (revision 283606) >> +++ kern/kern_clocksource.c (working copy) >> @@ -155,10 +155,11 @@ >> handleevents(sbintime_t now, int fake) >> { >> sbintime_t t, *hct; >> + sbintime_t runs; >> struct trapframe *frame; >> struct pcpu_state *state; >> int usermode; >> - int done, runs; >> + int done; >> >> CTR3(KTR_SPARE2, "handle at %d: now %d.%08x", >> curcpu, (int)(now >> 32), (u_int)(now & 0xffffffff)); >> @@ -173,12 +174,10 @@ >> >> state = DPCPU_PTR(timerstate); >> >> - runs = 0; >> - while (now >= state->nexthard) { >> - state->nexthard += tick_sbt; >> - runs++; >> - } >> - if (runs) { >> + runs = (now - state->nexthard) / tick_sbt; >> + if (runs > 0) { >> + printf("R%d ", (int)runs); >> + state->nexthard += tick_sbt * runs; >> hct = DPCPU_PTR(hardclocktime); >> *hct = state->nexthard - tick_sbt; >> if (fake < 2) { There is a difference in behavior in the two implementations when 'now == state->nexthard'. In the loop-based implementation this would end up with 'runs = 1' whereas in the division-based implementation it would end up with 'runs = 0'. I am not sure if this is intentional or just an oversight. best Neel >> @@ -186,25 +185,25 @@ >> done = 1; >> } >> } >> - runs = 0; >> - while (now >= state->nextstat) { >> - state->nextstat += statperiod; >> - runs++; >> + runs = (now - state->nextstat) / statperiod; >> + if (runs > 0) { >> + printf("S%d ", (int)runs); >> + state->nextstat += statperiod * runs; >> + if (fake < 2) { >> + statclock_cnt(runs, usermode); >> + done = 1; >> + } >> } >> - if (runs && fake < 2) { >> - statclock_cnt(runs, usermode); >> - done = 1; >> - } >> if (profiling) { >> - runs = 0; >> - while (now >= state->nextprof) { >> - state->nextprof += profperiod; >> - runs++; >> + runs = (now - state->nextprof) / profperiod; >> + if (runs > 0) { >> + printf("T%d ", (int)runs); >> + state->nextprof += profperiod * runs; >> + if (!fake) { >> + profclock_cnt(runs, usermode, >> TRAPF_PC(frame)); >> + done = 1; >> + } >> } >> - if (runs && !fake) { >> - profclock_cnt(runs, usermode, TRAPF_PC(frame)); >> - done = 1; >> - } >> } else >> state->nextprof = state->nextstat; >> if (now >= state->nextcallopt) { > > _______________________________________________ > freebsd-current@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-current > To unsubscribe, send any mail to "freebsd-current-unsubscribe@freebsd.org"