The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/mtx/clock.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 #include        "u.h"
    2 #include        "../port/lib.h"
    3 #include        "mem.h"
    4 #include        "dat.h"
    5 #include        "fns.h"
    6 #include        "io.h"
    7 #include        "ureg.h"
    8 
    9 static  ulong   clkreload;
   10 
   11 void
   12 delayloopinit(void)
   13 {
   14         ulong v;
   15         uvlong x;
   16 
   17         m->loopconst = 5000;
   18         v = getdec();
   19         delay(1000);
   20         v -= getdec();
   21 
   22         x = m->loopconst;
   23         x *= m->dechz;
   24         x /= v;
   25         m->loopconst = x;
   26 }
   27 
   28 void
   29 clockinit(void)
   30 {
   31         /* XXX this should not be hard coded! */
   32         m->cpuhz = 300000000;
   33         m->bushz = 66666666;
   34 
   35         m->dechz = m->bushz/4;                  /* true for all 604e */
   36         m->tbhz = m->dechz;                             /* conjecture; manual doesn't say */
   37 
   38         delayloopinit();
   39 
   40         clkreload = m->dechz/HZ-1;
   41         putdec(clkreload);
   42 }
   43 
   44 void
   45 clockintr(Ureg *ureg)
   46 {
   47         long v;
   48 
   49         v = -getdec();
   50         if(v > clkreload/2){
   51                 if(v > clkreload)
   52                         m->ticks += v/clkreload;
   53                 v = 0;
   54         }
   55         putdec(clkreload-v);
   56 
   57         timerintr(ureg, 0);
   58 }
   59 
   60 void
   61 timerset(Tval)
   62 {
   63 }
   64 
   65 void
   66 delay(int l)
   67 {
   68         ulong i, j;
   69 
   70         j = m->loopconst;
   71         while(l-- > 0)
   72                 for(i=0; i < j; i++)
   73                         ;
   74 }
   75 
   76 void
   77 microdelay(int l)
   78 {
   79         ulong i;
   80 
   81         l *= m->loopconst;
   82         l += 500;
   83         l /= 1000;
   84         if(l <= 0)
   85                 l = 1;
   86         for(i = 0; i < l; i++)
   87                 ;
   88 }
   89 
   90 uvlong
   91 fastticks(uvlong *hz)
   92 {
   93         if(hz)
   94                 *hz = HZ;
   95         return m->ticks;
   96 }
   97 
   98 ulong
   99 ยตs(void)
  100 {
  101         return fastticks2us(m->ticks);
  102 }
  103 
  104 /*  
  105  *  performance measurement ticks.  must be low overhead.
  106  *  doesn't have to count over a second.
  107  */
  108 ulong
  109 perfticks(void)
  110 {
  111         return m->ticks;
  112 }

Cache object: 60e64304f6b1d081f2d4dc266799263a


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.