Annotation of driverkit/tests/timertest.m, revision 1.1.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:  * User-level libIO timer test.
                     26:  */
                     27:  
                     28: #import <objc/Object.h>
                     29: #import <driverkit/generalFuncs.h>
                     30: #import <libc.h>
                     31: #import <driverkit/Device_ddm.h>
                     32: 
                     33: #define DO_DDM_DEBUG 1
                     34: 
                     35: static void usage(char **argv);
                     36: 
                     37: ns_time_t last_time = 0;
                     38: int callout_interval = 10;
                     39: 
                     40: static void callFcn()
                     41: {
                     42:        printf("Callout\n");
                     43:        IOScheduleFunc((IOThreadFunc)callFcn, NULL, callout_interval);
                     44: }
                     45: 
                     46: int main(int argc, char **argv)
                     47: {
                     48:        int loop;
                     49:        ns_time_t current_time;
                     50:        unsigned delta;
                     51:        unsigned long long delta_l;
                     52:        int arg;
                     53:        struct tsval ts;
                     54:        
                     55:        if(argc > 2)
                     56:                usage(argv);
                     57:        for(arg=1; arg<argc; arg++) {
                     58:                switch(argv[arg][0]) {
                     59:                    case 'c':
                     60:                        callout_interval = atoi(&argv[arg][2]);
                     61:                        break;
                     62:                    default:
                     63:                        usage(argv);
                     64:                }
                     65:        }
                     66:        IOInitGeneralFuncs();
                     67: #ifdef DO_DDM_DEBUG
                     68:        IOInitDDM(1000, "libIOxpr");
                     69:        IOSetDDMMask(XPR_IODEVICE_INDEX, XPR_LIBIO);
                     70: #endif DO_DDM_DEBUG
                     71:        printf("Should see one loop every second, and a callout every %d "
                     72:                "loops\n\n", callout_interval);
                     73:        IOScheduleFunc((IOThreadFunc)callFcn, NULL, callout_interval);
                     74:        for(loop=0; ; loop++) {
                     75:                IOGetTimestamp(&current_time);
                     76:                delta_l = current_time - last_time;
                     77:                delta = delta_l;
                     78:                kern_timestamp(&ts);
                     79:                printf("...loop %d delta %u ns tsval %u:%u\n", 
                     80:                        loop, (unsigned)delta_l, ts.high_val, ts.low_val);
                     81:                /*
                     82:                 * eliminate printf latency...
                     83:                 */
                     84:                IOGetTimestamp(&last_time);
                     85:                
                     86:                /*
                     87:                 * alternate between IODelay and IOSleep...
                     88:                 */
                     89:                if(loop & 1) {
                     90:                        IOSleep(1000);
                     91:                }
                     92:                else {
                     93:                        IODelay(1000000);
                     94:                }
                     95:        }       
                     96: }
                     97: 
                     98: static void usage(char **argv)
                     99: {
                    100:        printf("usage: %s [c=c(allout interval)]\n");
                    101:        exit(1);
                    102: }

unix.superglobalmegacorp.com

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