]> git.saurik.com Git - apple/xnu.git/blob - tools/tests/libMicro/apple/lmbench_lat_sig_install.c
ee1acd697523ce13c0aec681ee3e6788a875700b
[apple/xnu.git] / tools / tests / libMicro / apple / lmbench_lat_sig_install.c
1 /*
2 * Copyright (c) 2006 Apple Inc. All Rights Reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
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.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
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.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28
29
30 /*
31 * Order of Execution
32 *
33 * benchmark_init
34 *
35 * benchmark_optswitch
36 *
37 * benchmark_initrun
38 *
39 * benchmark_initworker
40 * benchmark_initbatch
41 * benchmark
42 * benchmark_finibatch
43 * benchmark_initbatch
44 * benchmark
45 * benchmark_finibatch, etc.
46 * benchmark_finiworker
47 *
48 * benchmark_result
49 *
50 * benchmark_finirun
51 *
52 * benchmark_fini
53 */
54
55
56
57 #ifdef __sun
58 #pragma ident "@(#)lmbench_lat_sig_install.c 1.0 08/16/06 Apple Inc."
59 #endif
60
61
62
63 #include <unistd.h>
64 #include <stdlib.h>
65 #include <stdio.h>
66 #include <setjmp.h>
67 #include <signal.h>
68
69 #include "../libmicro.h"
70
71 /*
72 * Your state variables should live in the tsd_t struct below
73 */
74
75 static int optp = 1;
76 static int optw = 0;
77 static int optn = -1;
78
79 u_int64_t caught, n;
80 double adj;
81 void handler(int s) { }
82 jmp_buf prot_env;
83
84 typedef struct {
85 int ts_once;
86 } tsd_t;
87
88 /*ARGSUSED*/
89 int
90 benchmark_initbatch(void *tsd)
91 {
92 /*
93 * initialize your state variables here second
94 */
95 return (0);
96 }
97
98 int
99 benchmark_finirun()
100 {
101 return (0);
102 }
103
104 int
105 benchmark_init()
106 {
107 /*
108 * the lm_optstr must be defined here or no options for you
109 *
110 * ...and the framework will throw an error
111 *
112 */
113 (void) sprintf(lm_optstr, "t:");
114 /*
115 * working hypothesis:
116 *
117 * tsd_t is the struct that we can pass around our
118 * state info in
119 *
120 * lm_tsdsize will allocate the space we need for this
121 * structure throughout the rest of the framework
122 */
123 lm_tsdsize = sizeof (tsd_t);
124
125 (void) sprintf(lm_usage,
126 " [-p <parallelism>]\n"
127 " [-w <warmup>]\n"
128 " [-n <repetitions>]\n"
129 "notes: measures lmbench lat_sig install\n");
130 lm_defB = 1;
131 return (0);
132 }
133
134 int
135 benchmark_fini()
136 {
137 return (0);
138 }
139
140 int
141 benchmark_finibatch(void *tsd)
142 {
143 /*
144 * more proof of state passing
145 */
146 return (0);
147 }
148
149 char *
150 benchmark_result()
151 {
152 static char result = '\0';
153 (void) fprintf(stderr, "benchmark_result\n");
154 return (&result);
155 }
156
157 int
158 benchmark_finiworker(void *tsd)
159 {
160 return (0);
161 }
162
163 int
164 benchmark_optswitch(int opt, char *optarg)
165 {
166
167 switch (opt) {
168 case 'w':
169 optw = sizetoint(optarg);
170 break;
171 case 'n':
172 optn = sizetoint(optarg);
173 break;
174 case 'p':
175 optp = sizetoint(optarg);
176 break;
177 default:
178 return (-1);
179 }
180 return (0);
181 }
182
183 int
184 benchmark_initworker(void *tsd)
185 {
186 /*
187 * initialize your state variables here first
188 */
189
190
191 return (0);
192 }
193
194 int
195 benchmark_initrun()
196 {
197 return (0);
198 }
199
200 int
201 benchmark(void *tsd, result_t *res)
202 {
203 /*
204 * initialize your state variables here last
205 *
206 * and realize that you are paying for your initialization here
207 * and it is really a bad idea
208 */
209 struct sigaction sa, old;
210 int i;
211
212 for (i = 0; i < lm_optB; i++) {
213 sa.sa_handler = handler;
214 sigemptyset(&sa.sa_mask);
215 sa.sa_flags = 0;
216 sigaction(SIGUSR1, &sa, &old);
217 }
218 res->re_count = i;
219
220 return (0);
221 }