From owner-svn-src-head@freebsd.org  Tue Feb 20 07:30:57 2018
Return-Path: <owner-svn-src-head@freebsd.org>
Delivered-To: svn-src-head@mailman.ysv.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1])
 by mailman.ysv.freebsd.org (Postfix) with ESMTP id D5D32F0B180;
 Tue, 20 Feb 2018 07:30:57 +0000 (UTC) (envelope-from wma@FreeBSD.org)
Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org
 [IPv6:2610:1c1:1:606c::19:3])
 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
 (Client CN "mxrelay.nyi.freebsd.org",
 Issuer "Let's Encrypt Authority X3" (verified OK))
 by mx1.freebsd.org (Postfix) with ESMTPS id 8713087BFD;
 Tue, 20 Feb 2018 07:30:57 +0000 (UTC) (envelope-from wma@FreeBSD.org)
Received: from repo.freebsd.org (repo.freebsd.org
 [IPv6:2610:1c1:1:6068::e6a:0])
 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
 (Client did not present a certificate)
 by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 820F72656D;
 Tue, 20 Feb 2018 07:30:57 +0000 (UTC) (envelope-from wma@FreeBSD.org)
Received: from repo.freebsd.org ([127.0.1.37])
 by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w1K7UvJO056664;
 Tue, 20 Feb 2018 07:30:57 GMT (envelope-from wma@FreeBSD.org)
Received: (from wma@localhost)
 by repo.freebsd.org (8.15.2/8.15.2/Submit) id w1K7Uv7R056663;
 Tue, 20 Feb 2018 07:30:57 GMT (envelope-from wma@FreeBSD.org)
Message-Id: <201802200730.w1K7Uv7R056663@repo.freebsd.org>
X-Authentication-Warning: repo.freebsd.org: wma set sender to wma@FreeBSD.org
 using -f
From: Wojciech Macek <wma@FreeBSD.org>
Date: Tue, 20 Feb 2018 07:30:57 +0000 (UTC)
To: src-committers@freebsd.org, svn-src-all@freebsd.org,
 svn-src-head@freebsd.org
Subject: svn commit: r329635 - head/sys/powerpc/powerpc
X-SVN-Group: head
X-SVN-Commit-Author: wma
X-SVN-Commit-Paths: head/sys/powerpc/powerpc
X-SVN-Commit-Revision: 329635
X-SVN-Commit-Repository: base
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-BeenThere: svn-src-head@freebsd.org
X-Mailman-Version: 2.1.25
Precedence: list
List-Id: SVN commit messages for the src tree for head/-current
 <svn-src-head.freebsd.org>
List-Unsubscribe: <https://lists.freebsd.org/mailman/options/svn-src-head>,
 <mailto:svn-src-head-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/svn-src-head/>
List-Post: <mailto:svn-src-head@freebsd.org>
List-Help: <mailto:svn-src-head-request@freebsd.org?subject=help>
List-Subscribe: <https://lists.freebsd.org/mailman/listinfo/svn-src-head>,
 <mailto:svn-src-head-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Tue, 20 Feb 2018 07:30:58 -0000

Author: wma
Date: Tue Feb 20 07:30:57 2018
New Revision: 329635
URL: https://svnweb.freebsd.org/changeset/base/329635

Log:
  PowerPC: Switch to more accurate unit to avoid division rounding
  
  On POWER8 architecture there is a timer with 512Mhz frequency.
  It has about 1,95ns period, but it is rounded to 1ns which is not accurate.
  
  Submitted by:          Patryk Duda <pdk@semihalf.com>
  Obtained from:         Semihalf
  Reviewed by:           wma
  Sponsored by:          IBM, QCM Technologies
  Differential revision: https://reviews.freebsd.org/D14433

Modified:
  head/sys/powerpc/powerpc/clock.c

Modified: head/sys/powerpc/powerpc/clock.c
==============================================================================
--- head/sys/powerpc/powerpc/clock.c	Tue Feb 20 06:38:55 2018	(r329634)
+++ head/sys/powerpc/powerpc/clock.c	Tue Feb 20 07:30:57 2018	(r329635)
@@ -82,7 +82,7 @@ __FBSDID("$FreeBSD$");
  * Initially we assume a processor with a bus frequency of 12.5 MHz.
  */
 static int		initialized = 0;
-static u_long		ns_per_tick = 80;
+static uint64_t		ps_per_tick = 80000;
 static u_long		ticks_per_sec = 12500000;
 static u_long		*decr_counts[MAXCPU];
 
@@ -178,7 +178,7 @@ decr_init(void)
 	if (platform_smp_get_bsp(&cpu) != 0)
 		platform_smp_first_cpu(&cpu);
 	ticks_per_sec = platform_timebase_freq(&cpu);
-	ns_per_tick = 1000000000 / ticks_per_sec;
+	ps_per_tick = 1000000000000 / ticks_per_sec;
 
 	set_cputicker(mftb, ticks_per_sec, 0);
 	snprintf(buf, sizeof(buf), "cpu%d:decrementer", curcpu);
@@ -307,7 +307,7 @@ DELAY(int n)
 
 	TSENTER();
 	tb = mftb();
-	ttb = tb + howmany(n * 1000, ns_per_tick);
+	ttb = tb + howmany((uint64_t)n * 1000000, ps_per_tick);
 	while (tb < ttb)
 		tb = mftb();
 	TSEXIT();