]>
git.saurik.com Git - apple/xnu.git/blob - tools/tests/libMicro/apple/lmbench_select_file.c
2 * Copyright (c) 2006 Apple Inc. All Rights Reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
39 * benchmark_initworker
45 * benchmark_finibatch, etc.
46 * benchmark_finiworker
58 #pragma ident "@(#)socket.c 1.3 05/08/04 Apple Inc."
70 #include "../libmicro.h"
73 * lmbench routines, etc. brought over for this benchmark
75 int open_file(void* tsd
);
76 void server(void* tsd
);
79 typedef int (*open_f
)(void* tsd
);
81 * end of lmbench support routines
85 * Your state variables should live in the tsd_t struct below
104 * lmbench routines, etc. brought over for this benchmark
113 getrlimit(RLIMIT_NOFILE
, &r
);
114 r
.rlim_cur
= r
.rlim_max
;
115 setrlimit(RLIMIT_NOFILE
, &r
);
122 tsd_t
* ts
= (tsd_t
*)tsd
;
123 //(void) fprintf(stderr, "open_file: ts->fname = %s\n",ts->fname);
124 return (int) open(ts
->fname
, O_RDONLY
);
131 tsd_t
* ts
= (tsd_t
*)tsd
;
135 //(void) fprintf(stderr, "server: state->fid_f = %i\n",ts->fid_f);
137 if (ts
->fid_f
== open_file
) {
138 /* Create a temporary file for clients to open */
139 sprintf(ts
->fname
, "/tmp/lat_selectXXXXXX");
140 //(void) fprintf(stderr, "server: ts->fname = %s\n",ts->fname);
141 ts
->fid
= mkstemp(ts
->fname
);
142 //(void) fprintf(stderr, "server: ts->fname = %s: ts->fid = %d\n",ts->fname, ts->fid);
145 char buf
[L_tmpnam
+128];
146 sprintf(buf
, "lat_select: Could not create temp file %s", ts
->fname
);
154 // this is all for the tcp version of this test only
156 // /* Create a socket for clients to connect to */
157 // state->sock = tcp_server(TCP_SELECT, SOCKOPT_REUSE);
158 // if (state->sock <= 0) {
159 // perror("lat_select: Could not open tcp server socket");
163 /* Start a server process to accept client connections */
164 // switch(state->pid = fork()) {
166 // /* child server process */
167 // while (pid == getppid()) {
168 // int newsock = tcp_accept(state->sock, SOCKOPT_NONE);
169 // read(newsock, &state->fid, 1);
175 // perror("lat_select::server(): fork() failed");
184 * end of lmbench support routines
189 benchmark_initbatch(void *tsd
)
192 * initialize your state variables here second
200 //(void) fprintf(stderr, "benchmark_finirun\n");
207 //(void) fprintf(stderr, "benchmark_init\n");
209 * the lm_optstr must be defined here or no options for you
211 * ...and the framework will throw an error
214 (void) sprintf(lm_optstr
, "p:w:n:t:");
216 * working hypothesis:
218 * tsd_t is the struct that we can pass around our
221 * lm_tsdsize will allocate the space we need for this
222 * structure throughout the rest of the framework
224 lm_tsdsize
= sizeof (tsd_t
);
226 (void) sprintf(lm_usage
,
227 " [-p parallelism (default 1)]\n"
228 " [-w warmup (default 0)]\n"
229 " [-n number of descriptors (default 1)]\n"
230 " [-t int (default 1)]\n"
231 "notes: measures lmbench_select_file\n");
239 //(void) fprintf(stderr, "benchmark_fini\n");
244 benchmark_finibatch(void *tsd
)
252 static char result
= '\0';
253 //(void) fprintf(stderr, "benchmark_result\n");
258 benchmark_finiworker(void *tsd
)
260 tsd_t
*ts
= (tsd_t
*)tsd
;
262 // pulls in the lmbench cleanup code
263 //(void) fprintf(stderr, "benchmark_finiworker\n");
264 for (i
= 0; i
<= ts
->max
; ++i
) {
265 if (FD_ISSET(i
, &(ts
->set
)))
274 benchmark_optswitch(int opt
, char *optarg
)
276 //(void) fprintf(stderr, "benchmark_optswitch\n");
280 optt
= sizetoint(optarg
);
283 optn
= sizetoint(optarg
);
286 optp
= sizetoint(optarg
);
289 optw
= sizetoint(optarg
);
298 benchmark_initworker(void *tsd
)
300 // pulls in code from lmbench main and initialize
303 * initialize your state variables here first
305 tsd_t
*ts
= (tsd_t
*)tsd
;
309 * default number of file descriptors
311 //(void) fprintf(stderr, "benchmark_initworker\n");
317 //(void) fprintf(stderr, "benchmark_initworker ts->num is %i\n",ts->num);
320 * grab more file descriptors
325 ts
->fid_f
= open_file
;
327 //(void) fprintf(stderr, "benchmark_initworker: returned from server call\n");
329 * Initialize function from lmbench
332 fid
= (*ts
->fid_f
)(ts
);
333 //(void) fprintf(stderr, "initworker: fid is %i\n",fid);
335 perror("Could not open device");
340 //(void) fprintf(stderr, "initworker FD_ZERO: ts->set result is %i\n",ts->set);
341 //(void) fprintf(stderr, "initworker: N is %i\n",N);
342 for (n
= 0; n
< N
; n
++) {
343 //(void) fprintf(stderr, "benchmark_initworker: in the loop - N is %i: n is %i\n",N, n);
345 //(void) fprintf(stderr, "benchmark_initworker: dup result is %i\n",fd);
346 //(void) fprintf(stderr, "benchmark_initworker: errno result is %d - \"%s\"\n",errno, strerror(errno));
351 FD_SET(fd
, &(ts
->set
));
352 //(void) fprintf(stderr, "initworker FD_SET: ts->set result is %i\n",ts->set);
355 //(void) fprintf(stderr, "benchmark_initworker: after second macro/loop\n");
359 //(void) fprintf(stderr, "benchmark_initworker: N is %i: n is %i\n",N, n);
362 /* end of initialize function */
363 //(void) fprintf(stderr, "benchmark_initworker: about to exit\n");
370 //(void) fprintf(stderr, "benchmark_initrun\n");
375 benchmark(void *tsd
, result_t
*res
)
378 * initialize your state variables here last
380 * and realize that you are paying for your initialization here
381 * and it is really a bad idea
383 tsd_t
*ts
= (tsd_t
*)tsd
;
385 static struct timeval tv
;
387 //(void) fprintf(stderr, "benchmark\n");
395 for (i
= 0; i
< lm_optB
; i
++) {
397 //(void) fprintf(stderr, "benchmark: nosave is %i\n", nosave);
399 select(ts
->num
, 0, &nosave
, 0, &tv
);
400 //(void) fprintf(stderr, "benchmark: select result is %i\n",sel_res);
401 //(void) fprintf(stderr, "benchmark: errno result is %d - \"%s\"\n",errno, strerror(errno));