|
|
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: * writeq.c - Write to 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 "defaults.h" ! 35: #import "buflib.h" ! 36: #import <bsd/sys/signal.h> ! 37: #import <mach/mach_error.h> ! 38: ! 39: void usage(char **argv); ! 40: void exit(int exitcode); ! 41: void fill_buf(u_char *p, int size, char d); ! 42: void sigint(int foo); ! 43: ! 44: int write_requests = 0; ! 45: int write_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 *wbuf; /* write buffer */ ! 54: char *wwbuf; /* working wrtite buffer */ ! 55: kern_return_t krtn; ! 56: u_int bytes_xfr; ! 57: int io_num; ! 58: IOErrorString outstr; ! 59: ! 60: /* ! 61: * user-spec'd variables ! 62: */ ! 63: u_int byte_count=BYTE_COUNT_DEFAULT; /* bytes to write */ ! 64: u_int block_num=0; ! 65: char *hostname=HOST_DEFAULT; ! 66: char *devname=DEVICE_DEFAULT; ! 67: char data_patt = 'z'; ! 68: int num_ios; ! 69: int loop = 0; ! 70: int loop_num = 0; ! 71: ! 72: if(argc < 2) ! 73: usage(argv); ! 74: num_ios = atoi(argv[1]); ! 75: ! 76: /* ! 77: * Get standard defaults from environment of 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: data_patt = argv[arg][2]; ! 100: break; ! 101: case 'l': ! 102: loop++; ! 103: break; ! 104: default: ! 105: usage(argv); ! 106: } ! 107: } ! 108: signal(SIGINT, sigint); ! 109: rtn = [IOClient clientOpen:devname ! 110: hostName:hostname ! 111: intentions:IO_INT_WRITE ! 112: idp:&idClient]; ! 113: if(rtn) { ! 114: [IOClient ioError:rtn ! 115: logString:"clientOpen" ! 116: outString:outstr]; ! 117: printf(outstr); ! 118: exit(1); ! 119: } ! 120: krtn = vm_allocate(task_self(), ! 121: (vm_address_t *)&wbuf, ! 122: byte_count * num_ios, ! 123: TRUE); ! 124: if(krtn) { ! 125: mach_error("vm_allocate", krtn); ! 126: exit(1); ! 127: } ! 128: fill_buf((u_char *)wbuf, (int)byte_count * num_ios, data_patt); ! 129: ! 130: do { ! 131: ! 132: /* ! 133: * fire off num_ios queued write requests ! 134: */ ! 135: wwbuf = wbuf; ! 136: for(io_num=1; io_num<=num_ios; io_num++) { ! 137: ! 138: rtn = [idClient ioWriteAsync:block_num+io_num ! 139: bytesReq:byte_count ! 140: buf:wwbuf ! 141: queueId:io_num]; ! 142: if(rtn != IO_R_SUCCESS) { ! 143: [IOClient ioError:rtn ! 144: logString:"ioWriteAsync" ! 145: outString:outstr]; ! 146: printf(outstr); ! 147: exit(1); ! 148: } ! 149: write_requests++; ! 150: wwbuf += byte_count; ! 151: } ! 152: ! 153: /* ! 154: * now wait for the I/O completes, in reverse order ! 155: */ ! 156: ! 157: for(io_num=num_ios; io_num; io_num--) { ! 158: rtn = [idClient ioWriteWait:io_num ! 159: bytesXfr:&bytes_xfr]; ! 160: if(rtn != IO_R_SUCCESS) { ! 161: [IOClient ioError:rtn ! 162: logString:"ioWriteWait" ! 163: outString:outstr]; ! 164: printf(outstr); ! 165: exit(1); ! 166: } ! 167: write_replies++; ! 168: if(bytes_xfr != byte_count) { ! 169: printf("bytes_xfr = %d; expected %d\n", ! 170: bytes_xfr, byte_count); ! 171: } ! 172: } ! 173: if(++loop_num % 100 == 0) { ! 174: printf("."); ! 175: fflush(stdout); ! 176: } ! 177: } while(loop); ! 178: ! 179: rtn = [idClient ioClose]; ! 180: if(rtn) { ! 181: [IOClient ioError:rtn ! 182: logString:"ioClose" ! 183: outString:outstr]; ! 184: printf(outstr); ! 185: exit(1); ! 186: } ! 187: else ! 188: printf("...ok\n"); ! 189: exit(0); ! 190: ! 191: } /* main() */ ! 192: ! 193: void usage(char **argv) { ! 194: printf("usage: %s num_ios [l(oop] [y=byte_count] [b=block_num] [p={z,1,i,d}] [h=hostname] [d=devname]\n", argv[0]); ! 195: exit(1); ! 196: } ! 197: ! 198: void fill_buf(u_char *buf, int size, char data_patt) { ! 199: ! 200: int i; ! 201: ! 202: printf("\n"); ! 203: for(i=0; i<size; i++) { ! 204: switch(data_patt) { ! 205: case 'z': ! 206: *buf++ = 0; ! 207: break; ! 208: case '1': ! 209: *buf++ = 0xff; ! 210: break; ! 211: case 'i': ! 212: *buf++ = (u_char)i; ! 213: break; ! 214: case 'd': ! 215: *buf++ = 0xff - (u_char)i; ! 216: break; ! 217: default: ! 218: printf("bogus data_patt (%c) in fill_buf()\n", ! 219: data_patt); ! 220: exit(1); ! 221: } ! 222: } ! 223: } /* fill_buf() */ ! 224: ! 225: void sigint(int foo) ! 226: { ! 227: printf("\nAborting.\n"); ! 228: printf("%d write requests\n", write_requests); ! 229: printf("%d write replies\n", write_replies); ! 230: exit(1); ! 231: } ! 232: ! 233:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.