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_catch.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 75static int optp = 1; 76static int optw = 0; 77static int optn = -1; 78 79u_int64_t caught, n; 80double adj; 81void handler(int s) { } 82jmp_buf prot_env; 83 84typedef struct { 85 int pid; 86} tsd_t; 87 88/*ARGSUSED*/ 89int 90benchmark_initbatch(void *tsd) 91{ 92 /* 93 * initialize your state variables here second 94 */ 95 return (0); 96} 97 98int 99benchmark_finirun() 100{ 101 return (0); 102} 103 104int 105benchmark_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, "p:w:n"); 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 134int 135benchmark_fini() 136{ 137 return (0); 138} 139 140int 141benchmark_finibatch(void *tsd) 142{ 143 /* 144 * more proof of state passing 145 */ 146 return (0); 147} 148 149char * 150benchmark_result() 151{ 152 static char result = '\0'; 153 (void) fprintf(stderr, "benchmark_result\n"); 154 return (&result); 155} 156 157int 158benchmark_finiworker(void *tsd) 159{ 160 return (0); 161} 162 163int 164benchmark_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 183int 184benchmark_initworker(void *tsd) 185{ 186 /* 187 * initialize your state variables here first 188 */ 189 tsd_t* ts = (tsd_t*)tsd; 190 struct sigaction sa, old; 191 192 sa.sa_handler = handler; 193 (void) sigemptyset(&sa.sa_mask); 194 sa.sa_flags = 0; 195 (void) sigaction(SIGUSR1, &sa, &old); 196 197 ts->pid = getpid(); 198 return (0); 199} 200 201int 202benchmark_initrun() 203{ 204 205 return (0); 206} 207 208int 209benchmark(void *tsd, result_t *res) 210{ 211 /* 212 * initialize your state variables here last 213 * 214 * and realize that you are paying for your initialization here 215 * and it is really a bad idea 216 */ 217 int i; 218 tsd_t* ts = (tsd_t*)tsd; 219 220 for (i = 0; i < lm_optB; i++) { 221 (void) kill(ts->pid, SIGUSR1); 222 } 223 res->re_count = i; 224 225 return (0); 226} 227