1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms 5 * of the Common Development and Distribution License 6 * (the "License"). You may not use this file except 7 * in compliance with the License. 8 * 9 * You can obtain a copy of the license at 10 * src/OPENSOLARIS.LICENSE 11 * or http://www.opensolaris.org/os/licensing. 12 * See the License for the specific language governing 13 * permissions and limitations under the License. 14 * 15 * When distributing Covered Code, include this CDDL 16 * HEADER in each file and include the License file at 17 * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 * add the following below this CDDL HEADER, with the 19 * fields enclosed by brackets "[]" replaced with your 20 * own identifying information: Portions Copyright [yyyy] 21 * [name of copyright owner] 22 * 23 * CDDL HEADER END 24 */ 25 26/* 27 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 * Use is subject to license terms. 29 */ 30 31 32#ifdef linux 33#define _XOPEN_SOURCE 500 34#endif 35 36#include <unistd.h> 37#include <stdlib.h> 38#include <stdio.h> 39#include <fcntl.h> 40 41#include "libmicro.h" 42 43typedef struct { 44 char *ts_buf; 45 int ts_fd; 46} tsd_t; 47 48#define DEFF "/dev/zero" 49#define DEFS 1024 50 51static char *optf = DEFF; 52static long long opts = DEFS; 53int optw = 0; 54 55int 56benchmark_init() 57{ 58 lm_tsdsize = sizeof (tsd_t); 59 60 (void) sprintf(lm_optstr, "f:s:w"); 61 62 (void) sprintf(lm_usage, 63 " [-f file-to-read (default %s)]\n" 64 " [-s buffer-size (default %d)]\n" 65 " [-w (store a byte to each page after read)]\n" 66 "notes: measures read()\n", 67 DEFF, DEFS); 68 69 (void) sprintf(lm_header, "%8s", "size"); 70 71 lm_defB = 1; 72 73 return (0); 74} 75 76int 77benchmark_optswitch(int opt, char *optarg) 78{ 79 switch (opt) { 80 case 'w': 81 optw = getpagesize(); 82 break; 83 case 'f': 84 optf = optarg; 85 break; 86 case 's': 87 opts = sizetoll(optarg); 88 break; 89 default: 90 return (-1); 91 } 92 return (0); 93} 94 95int 96benchmark_initrun() 97{ 98 return (0); 99} 100 101int 102benchmark_initbatch(void *tsd) 103{ 104 tsd_t *ts = (tsd_t *)tsd; 105 106 if (ts->ts_buf == NULL) { 107 ts->ts_buf = malloc(opts); 108 ts->ts_fd = open(optf, O_RDONLY); 109 } 110 111 (void) lseek(ts->ts_fd, 0, SEEK_SET); 112 113 return (0); 114} 115 116int 117benchmark(void *tsd, result_t *res) 118{ 119 tsd_t *ts = (tsd_t *)tsd; 120 int i; 121 int j; 122 for (i = 0; i < lm_optB; i++) { 123 if (read(ts->ts_fd, ts->ts_buf, opts) != opts) { 124 res->re_errors++; 125 } 126 if (optw) 127 for (j = 0; j < opts; j += optw) 128 ts->ts_buf[j] = 0; 129 } 130 res->re_count = i; 131 132 return (0); 133} 134 135char * 136benchmark_result() 137{ 138 static char result[256]; 139 140 (void) sprintf(result, "%8lld", opts); 141 142 return (result); 143} 144