Annotation of kernel/kern/ns_timer.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
        !             3:  *
        !             4:  * @APPLE_LICENSE_HEADER_START@
        !             5:  * 
        !             6:  * Portions Copyright (c) 1999 Apple Computer, Inc.  All Rights
        !             7:  * Reserved.  This file contains Original Code and/or Modifications of
        !             8:  * Original Code as defined in and that are subject to the Apple Public
        !             9:  * Source License Version 1.1 (the "License").  You may not use this file
        !            10:  * except in compliance with the License.  Please obtain a copy of the
        !            11:  * License at http://www.apple.com/publicsource and read it before using
        !            12:  * this file.
        !            13:  * 
        !            14:  * The Original Code and all software distributed under the License are
        !            15:  * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
        !            16:  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
        !            17:  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
        !            18:  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
        !            19:  * License for the specific language governing rights and limitations
        !            20:  * under the License.
        !            21:  * 
        !            22:  * @APPLE_LICENSE_HEADER_END@
        !            23:  */
        !            24: 
        !            25: /*     @(#)ns_timer.c  1.0     12/8/87         (c) 1987 NeXT   */
        !            26: 
        !            27: /* 
        !            28:  * Copyright (c) 1992 NeXT, Inc.
        !            29:  */ 
        !            30: 
        !            31: #import <sys/param.h>
        !            32: #import <sys/kernel.h>
        !            33: #import <bsd/sys/callout.h>
        !            34: #import <kernserv/ns_timer.h>
        !            35: #import <kernserv/clock_timer.h>
        !            36: #import <bsd/machine/spl.h>
        !            37: #import <kern/thread_call.h>
        !            38: 
        !            39: #if defined (__ppc__)
        !            40: #import "machdep/ppc/longlong.h"
        !            41: #elif defined (__i386__)
        !            42: #import "machdep/i386/longlong.h"
        !            43: #else
        !            44: #error architecture not supported
        !            45: #endif
        !            46: 
        !            47: /*
        !            48:  * Micro-second Timer.
        !            49:  */
        !            50: 
        !            51: /*
        !            52:  *  Arrange that the function "proc" gets called in "time" nanoseconds.
        !            53:  */
        !            54: void ns_timeout(func proc, void *arg, ns_time_t time, int pri)
        !            55: {
        !            56:        int             s;
        !            57:        tvalspec_t      deadline;
        !            58:        extern
        !            59:            tvalspec_t  tick_stamp;
        !            60: 
        !            61:        s = splhigh();
        !            62:        llp_div_l(&time, NSEC_PER_SEC, &deadline.tv_nsec);
        !            63:        deadline.tv_sec = (unsigned int)time;
        !            64:        ADD_TVALSPEC(&deadline, &tick_stamp);
        !            65: 
        !            66:        thread_call_func_delayed(
        !            67:                        (thread_call_func_t)proc,
        !            68:                        (thread_call_spec_t)arg, deadline);
        !            69:        splx(s);
        !            70: }
        !            71: 
        !            72: /*
        !            73:  *  Arrange that the function "proc" gets called at "deadline" nanoseconds
        !            74:  *  from boot.
        !            75:  */
        !            76: void ns_abstimeout(func proc, void *arg, ns_time_t time, int pri)
        !            77: {
        !            78:        int             s;
        !            79:        tvalspec_t      deadline;
        !            80: 
        !            81:        s = splhigh();
        !            82:        llp_div_l(&time, NSEC_PER_SEC, &deadline.tv_nsec);
        !            83:        deadline.tv_sec = (unsigned int)time;
        !            84: 
        !            85:        thread_call_func_delayed(
        !            86:                        (thread_call_func_t)proc,
        !            87:                        (thread_call_spec_t)arg, deadline);
        !            88:        splx(s);
        !            89: }
        !            90: 
        !            91: /*
        !            92:  * Remove something scheduled via ns_timeout or ns_abstimeout.
        !            93:  */
        !            94: boolean_t ns_untimeout(func proc, void *arg)
        !            95: {
        !            96:        thread_call_func_cancel(
        !            97:                        (thread_call_func_t)proc,
        !            98:                        (thread_call_spec_t)arg, FALSE);
        !            99:                    
        !           100:        return (TRUE);  /* XXX cheat */
        !           101: }
        !           102: 
        !           103: void
        !           104: ns_sleep(ns_time_t delay)
        !           105: {
        !           106:        int             s;
        !           107:        extern void     wakeup(caddr_t chan);
        !           108: 
        !           109:        s = splhigh();
        !           110:        ns_timeout((func)wakeup, &delay, delay, CALLOUT_PRI_SOFTINT1);
        !           111:        /* make this uninterruptable */
        !           112:        sleep((caddr_t)&delay, PZERO - 1);
        !           113:        splx(s);
        !           114: }
        !           115: 
        !           116: /*
        !           117:  *  Conversion functions.  Loads o' fun.
        !           118:  */
        !           119: void
        !           120: ns_time_to_timeval(ns_time_t nano_time, struct timeval *tvp)
        !           121: {
        !           122:        llp_div_l(&nano_time, 1000000000, (unsigned int *)&tvp->tv_usec);
        !           123:        
        !           124:        tvp->tv_sec = (unsigned long) nano_time;
        !           125:        tvp->tv_usec /= 1000;
        !           126: }
        !           127: 
        !           128: ns_time_t
        !           129: timeval_to_ns_time(struct timeval *tvp)
        !           130: {
        !           131:        ns_time_t       a_time;
        !           132: 
        !           133:        a_time = (ns_time_t) tvp->tv_sec * 1000000ULL + tvp->tv_usec;
        !           134:        a_time *= 1000ULL;
        !           135: 
        !           136:        return a_time;
        !           137: }
        !           138: 
        !           139: /*
        !           140:  * Return the best possible estimate of the time in the timeval
        !           141:  * to which tvp points.
        !           142:  */
        !           143: void
        !           144: microtime(struct timeval * tvp)
        !           145: {
        !           146:        tvalspec_t      now = clock_get_counter(Calendar);
        !           147: 
        !           148:        tvp->tv_sec = now.tv_sec;
        !           149:        tvp->tv_usec = now.tv_nsec / NSEC_PER_USEC;
        !           150: }
        !           151: 
        !           152: /*
        !           153:  * microboot returns the number of microseconds since boot.
        !           154:  */
        !           155: void microboot(struct timeval *tvp)
        !           156: {
        !           157:        tvalspec_t      now = clock_get_counter(System);
        !           158: 
        !           159:        tvp->tv_sec = now.tv_sec;
        !           160:        tvp->tv_usec = now.tv_nsec / NSEC_PER_USEC;
        !           161: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.