Annotation of driverkit/tests/readq.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:  * readq.m - Read using queued I/O
                     26:  */
                     27: 
                     28: #import <bsd/sys/types.h> 
                     29: #import <driverkit/IOClient.h>
                     30: #import <ansi/stdio.h>
                     31: #import <mach/kern_return.h>
                     32: #import <mach/mach.h>
                     33: #import <ansi/stdlib.h>
                     34: #import <bsd/libc.h>
                     35: #import "buflib.h"
                     36: #import "defaults.h"
                     37: #import <bsd/sys/signal.h>
                     38: #import <mach/mach_error.h>
                     39: 
                     40: void usage(char **argv);
                     41: void exit(int exitcode);
                     42: void sigint(int foo);
                     43: 
                     44: int read_requests = 0;
                     45: int read_replies = 0;
                     46: 
                     47: int main(int argc, char **argv) {
                     48: 
                     49:        int             arg;
                     50:        char            c;
                     51:        id              idClient;
                     52:        IOReturn        rtn;
                     53:        char            *rbuf, *rrbuf;
                     54:        kern_return_t   krtn;
                     55:        u_int           bytes_xfr;
                     56:        int             i;
                     57:        int             io_num;
                     58:        IOErrorString   outstr;
                     59:        int             loop_num = 0;
                     60:        
                     61:        /*
                     62:         * user-spec'd variables 
                     63:         */
                     64:        u_char          dump_data = 0;          /* dump read data to stdout */
                     65:        u_int           byte_count=BYTE_COUNT_DEFAULT;  /* bytes to read */
                     66:        u_int           block_num=0;            
                     67:        char            *hostname=HOST_DEFAULT;
                     68:        char            *devname=DEVICE_DEFAULT;
                     69:        int             num_ios;
                     70:        int             loop = 0;
                     71:        
                     72:        if(argc < 2)
                     73:                usage(argv);
                     74:        num_ios = atoi(argv[1]);
                     75: 
                     76:        /*
                     77:         * Get standard defaults from environment or defaults.h
                     78:         */
                     79:        get_default("byte_count", &byte_count, BYTE_COUNT_DEFAULT);
                     80:        get_default_t("hostname", &hostname, HOST_DEFAULT);
                     81:        get_default_t("devname", &devname, DEVICE_DEFAULT);
                     82: 
                     83:        for(arg=2; arg<argc; arg++) {
                     84:                c = argv[arg][0];
                     85:                switch(c) {
                     86:                    case 'y':
                     87:                        byte_count = atoi(&argv[arg][2]);
                     88:                        break;
                     89:                    case 'h':
                     90:                        hostname = &argv[arg][2];
                     91:                        break;
                     92:                    case 'd':
                     93:                        devname = &argv[arg][2];
                     94:                        break;
                     95:                    case 'b':
                     96:                        block_num = atoi(&argv[arg][2]);
                     97:                        break;
                     98:                    case 'p':
                     99:                        dump_data++;
                    100:                        break;
                    101:                    case 'l':
                    102:                        loop++;
                    103:                        break;
                    104:                    default:
                    105:                        usage(argv);
                    106:                }
                    107:        }
                    108:        signal(SIGINT, sigint);
                    109:        
                    110:        rtn = [IOClient clientOpen:devname 
                    111:                hostName:hostname
                    112:                intentions:IO_INT_READ
                    113:                idp:&idClient];
                    114:        if(rtn) {
                    115:                [IOClient ioError:rtn 
                    116:                          logString:"clientOpen"
                    117:                          outString:outstr];
                    118:                printf(outstr);
                    119:                exit(1);
                    120:        }
                    121:        krtn = vm_allocate(task_self(), 
                    122:                (vm_address_t *)&rbuf, 
                    123:                byte_count * num_ios,
                    124:                TRUE);
                    125:        if(krtn) {
                    126:                mach_error("vm_allocate", krtn);
                    127:                exit(1);
                    128:        }
                    129:        for(i=0; i<byte_count * num_ios; i++)
                    130:                rbuf[i] = 0x5a;
                    131:                
                    132:        do {
                    133:        
                    134:                /* 
                    135:                 * fire off num_ios queued read requests.
                    136:                 */
                    137:                for(io_num=1; io_num<=num_ios; io_num++) {
                    138:                
                    139:                        rtn = [idClient ioReadAsync:block_num+io_num
                    140:                                        bytesReq:byte_count
                    141:                                        queueId:io_num];
                    142:                        if(rtn != IO_R_SUCCESS) {
                    143:                                [IOClient ioError:rtn 
                    144:                                            logString:"ioReadAsync"
                    145:                                            outString:outstr];
                    146:                                printf(outstr);
                    147:                                exit(1);
                    148:                        }
                    149:                        read_requests++;
                    150:                }
                    151:                
                    152:                /* 
                    153:                 * now wait for the data, in reverse order. 
                    154:                 */
                    155:                rrbuf = rbuf + num_ios * byte_count;
                    156:                for(io_num=num_ios; io_num; io_num--) {
                    157:                        rrbuf -= byte_count;
                    158:                        rtn = [idClient ioReadWait:io_num
                    159:                                        buf:rrbuf
                    160:                                        bytesXfr:&bytes_xfr];
                    161:                        if(rtn != IO_R_SUCCESS) {
                    162:                                [IOClient ioError:rtn 
                    163:                                            logString:"ioReadWait"
                    164:                                            outString:outstr];
                    165:                                printf(outstr);
                    166:                                exit(1);
                    167:                        }
                    168:                        read_replies++;
                    169:                        if(bytes_xfr != byte_count) {
                    170:                                printf("bytes_xfr = %d; expected %d\n", 
                    171:                                        bytes_xfr, byte_count);
                    172:                        }       
                    173:                        if(dump_data) {
                    174:                                printf("Read data, block %d\n", 
                    175:                                        block_num+io_num);
                    176:                                dump_buf((u_char *)rrbuf, bytes_xfr);
                    177:                                printf("\n");
                    178:                        }
                    179:                }
                    180:                if(++loop_num % 100 == 0) {
                    181:                        printf(".");
                    182:                        fflush(stdout);
                    183:                }
                    184:        } while(loop);
                    185:        rtn = [idClient ioClose];
                    186:        if(rtn) {
                    187:                [IOClient ioError:rtn 
                    188:                          logString:"ioClose"
                    189:                          outString:outstr];
                    190:                printf(outstr);
                    191:                exit(1);
                    192:        }
                    193:        else if(!dump_data)
                    194:                printf("...ok\n");
                    195:        exit(0);
                    196: 
                    197: } /* main() */
                    198: 
                    199: void usage(char **argv) {
                    200:        printf("usage: %s num_ios [l(oop)] [y=byte_count] [p (dump data)] [b=block_num] [h=hostname] [d=devname]\n", argv[0]);
                    201:        exit(1);
                    202: }
                    203: 
                    204: void sigint(int foo)
                    205: {
                    206:        printf("\nAborting.\n");
                    207:        printf("%d read requests\n", read_requests);
                    208:        printf("%d read replies\n", read_replies);
                    209:        exit(1);
                    210: }

unix.superglobalmegacorp.com

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