[BACK]Return to clock.c CVS log [TXT][DIR] Up to [local] / sys / arch / solbourne / solbourne

Annotation of sys/arch/solbourne/solbourne/clock.c, Revision 1.1

1.1     ! nbrk        1: /*     $OpenBSD: clock.c,v 1.1 2005/04/19 21:30:18 miod Exp $  */
        !             2: /*     OpenBSD: clock.c,v 1.19 2004/04/08 01:11:21 deraadt Exp         */
        !             3:
        !             4: /*
        !             5:  * Copyright (c) 1992, 1993
        !             6:  *     The Regents of the University of California.  All rights reserved.
        !             7:  * Copyright (c) 1994 Gordon W. Ross
        !             8:  * Copyright (c) 1993 Adam Glass
        !             9:  * Copyright (c) 1996 Paul Kranenburg
        !            10:  * Copyright (c) 1996
        !            11:  *     The President and Fellows of Harvard College. All rights reserved.
        !            12:  *
        !            13:  * This software was developed by the Computer Systems Engineering group
        !            14:  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
        !            15:  * contributed to Berkeley.
        !            16:  *
        !            17:  * All advertising materials mentioning features or use of this software
        !            18:  * must display the following acknowledgement:
        !            19:  *     This product includes software developed by Harvard University.
        !            20:  *     This product includes software developed by the University of
        !            21:  *     California, Lawrence Berkeley Laboratory.
        !            22:  *
        !            23:  * Redistribution and use in source and binary forms, with or without
        !            24:  * modification, are permitted provided that the following conditions
        !            25:  * are met:
        !            26:  *
        !            27:  * 1. Redistributions of source code must retain the above copyright
        !            28:  *    notice, this list of conditions and the following disclaimer.
        !            29:  * 2. Redistributions in binary form must reproduce the above copyright
        !            30:  *    notice, this list of conditions and the following disclaimer in the
        !            31:  *    documentation and/or other materials provided with the distribution.
        !            32:  * 3. All advertising materials mentioning features or use of this software
        !            33:  *    must display the following acknowledgement:
        !            34:  *     This product includes software developed by the University of
        !            35:  *     California, Berkeley and its contributors.
        !            36:  *     This product includes software developed by Paul Kranenburg.
        !            37:  *     This product includes software developed by Harvard University.
        !            38:  * 4. Neither the name of the University nor the names of its contributors
        !            39:  *    may be used to endorse or promote products derived from this software
        !            40:  *    without specific prior written permission.
        !            41:  *
        !            42:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
        !            43:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
        !            44:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
        !            45:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
        !            46:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
        !            47:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
        !            48:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
        !            49:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
        !            50:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
        !            51:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
        !            52:  * SUCH DAMAGE.
        !            53:  *
        !            54:  *     @(#)clock.c     8.1 (Berkeley) 6/11/93
        !            55:  *
        !            56:  */
        !            57:
        !            58: /*
        !            59:  * Clock driver.  This is the id prom and eeprom driver as well
        !            60:  * and includes the timer register functions too.
        !            61:  */
        !            62:
        !            63: #include <sys/param.h>
        !            64: #include <sys/kernel.h>
        !            65: #include <sys/device.h>
        !            66: #include <sys/systm.h>
        !            67:
        !            68: #include <uvm/uvm_extern.h>
        !            69:
        !            70: #include <machine/autoconf.h>
        !            71: #include <machine/cpu.h>
        !            72:
        !            73: #include <sparc/sparc/asm.h>
        !            74: #include <machine/idt.h>
        !            75: #include <machine/kap.h>
        !            76:
        !            77: /*
        !            78:  * Statistics clock interval and variance, in usec.  Variance must be a
        !            79:  * power of two.  Since this gives us an even number, not an odd number,
        !            80:  * we discard one case and compensate.  That is, a variance of 1024 would
        !            81:  * give us offsets in [0..1023].  Instead, we take offsets in [1..1023].
        !            82:  * This is symmetric about the point 512, or statvar/2, and thus averages
        !            83:  * to that value (assuming uniform random numbers).
        !            84:  */
        !            85: /* XXX fix comment to match value */
        !            86: int statvar = 8192;
        !            87: int statmin;                   /* statclock interval - 1/2*variance */
        !            88:
        !            89: int timerblurb = 10; /* Guess a value; used before clock is attached */
        !            90:
        !            91: /*
        !            92:  * Set up the real-time and statistics clocks.  Leave stathz 0 only if
        !            93:  * no alternative timer is available.
        !            94:  *
        !            95:  * The frequencies of these clocks must be an even number of microseconds.
        !            96:  */
        !            97: void
        !            98: cpu_initclocks()
        !            99: {
        !           100:        profhz = hz;
        !           101:        tick = 1000000 / hz;
        !           102: }
        !           103:
        !           104: /*
        !           105:  * Dummy setstatclockrate(), since we know profhz==hz.
        !           106:  */
        !           107: /* ARGSUSED */
        !           108: void
        !           109: setstatclockrate(newhz)
        !           110:        int newhz;
        !           111: {
        !           112:        /* nothing */
        !           113: }
        !           114:
        !           115: /*
        !           116:  * Level 10 (clock) interrupts.
        !           117:  */
        !           118: int
        !           119: clockintr(cap)
        !           120:        void *cap;
        !           121: {
        !           122:        hardclock((struct clockframe *)cap);
        !           123:
        !           124:        return (1);
        !           125: }
        !           126:
        !           127: /*
        !           128:  * Level 14 (stat clock) interrupt handler.
        !           129:  */
        !           130: int
        !           131: statintr(cap)
        !           132:        void *cap;
        !           133: {
        !           134: #if 1
        !           135:        panic("level 14 interrupt");
        !           136: #else
        !           137:        statclock((struct clockframe *)cap);
        !           138: #endif
        !           139:
        !           140:        return (1);
        !           141: }
        !           142:
        !           143: /*
        !           144:  * Return the best possible estimate of the time in the timeval
        !           145:  * to which tvp points.  We do this by returning the current time
        !           146:  * plus the amount of time since the last clock interrupt.
        !           147:  *
        !           148:  * Check that this time is no less than any previously-reported time,
        !           149:  * which could happen around the time of a clock adjustment.  Just for
        !           150:  * fun, we guarantee that the time will be greater than the value
        !           151:  * obtained by a previous call.
        !           152:  */
        !           153: void
        !           154: microtime(tvp)
        !           155:        struct timeval *tvp;
        !           156: {
        !           157:        int s;
        !           158:        static struct timeval lasttime;
        !           159:        static struct timeval oneusec = {0, 1};
        !           160:
        !           161:        s = splhigh();
        !           162:        *tvp = time;
        !           163:        splx(s);
        !           164:
        !           165:        if (timercmp(tvp, &lasttime, <=))
        !           166:                timeradd(&lasttime, &oneusec, tvp);
        !           167:
        !           168:        lasttime = *tvp;
        !           169: }

CVSweb