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 <p...@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();
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to