lmbench_lat_sig_prot.c [plain text]
#ifdef __sun
#pragma ident "@(#)lmbench_lat_sig_prot.c 1.0 08/16/06 Apple Inc."
#endif
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <setjmp.h>
#include <string.h>
#include <stdint.h>
#include <fcntl.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <errno.h>
#include "../libmicro.h"
static int optp = 1;
static int optw = 0;
static int optn = -1;
static char *optf = "/Volumes/data/darbench/bin-i386/lmbench_lat_sig_prot";
static int *mappedfile;
jmp_buf jumper;
u_int64_t caught, n;
double adj;
void handler(int s) { }
jmp_buf prot_env;
typedef struct {
char* fname;
char* where;
} tsd_t;
void
prot(int s)
{
_longjmp(jumper, s);
}
int
benchmark_initbatch(void *tsd)
{
(void) fprintf(stderr, "benchmark_initbatch: entry\n");
return (0);
}
int
benchmark_finirun()
{
return (0);
}
int
benchmark_init()
{
(void) sprintf(lm_optstr, "p:w:n:f");
lm_tsdsize = sizeof (tsd_t);
(void) sprintf(lm_usage,
" [-p <parallelism>]\n"
" [-w <warmup>]\n"
" [-n <repetitions>]\n"
" [-f <filename>]\n"
"notes: measures lmbench lat_sig prot\n");
(void) fprintf(stderr, "benchmark_init: entry\n");
lm_defB = 1;
return (0);
}
int
benchmark_fini()
{
return (0);
}
int
benchmark_finibatch(void *tsd)
{
return (0);
}
char *
benchmark_result()
{
static char result = '\0';
(void) fprintf(stderr, "benchmark_result\n");
return (&result);
}
int
benchmark_finiworker(void *tsd)
{
return (0);
}
int
benchmark_optswitch(int opt, char *optarg)
{
(void) fprintf(stderr, "benchmark_optswitch: entry\n");
switch (opt) {
case 'w':
optw = sizetoint(optarg);
break;
case 'n':
optn = sizetoint(optarg);
break;
case 'p':
optp = sizetoint(optarg);
break;
case 'f':
(void) fprintf(stderr, "benchmark_optswitch: FILENAME entry = %s\n",optf);
(void) fprintf(stderr, "benchmark_optswitch: FILENAME exit\n");
break;
default:
return (-1);
}
(void) fprintf(stderr, "benchmark_optswitch: exit\n");
return (0);
}
int
benchmark_initworker(void *tsd)
{
tsd_t* ts = (tsd_t*)tsd;
int fd;
struct sigaction sa;
(void) fprintf(stderr, "benchmark_initworker: entry = %s\n",optf);
ts->fname = optf;
fd = open(ts->fname, 0);
(void) fprintf(stderr, "benchmark_initworker: open result is %i\n",fd);
(void) fprintf(stderr, "benchmark_initworker: errno result is %d - \"%s\"\n",errno, strerror(errno));
ts->where = mmap(0,4096, PROT_READ, MAP_SHARED, fd, 0);
(void) fprintf(stderr, "benchmark_initworker: mmap result is %i\n",ts->where);
*mappedfile = (int) ts->where;
(void) fprintf(stderr, "benchmark_initworker: mappedfile result is %i\n",*mappedfile);
if ((long)ts->where == -1) {
perror("mmap");
exit(1);
}
sa.sa_handler = prot;
sigemptyset(&sa.sa_mask);
sa.sa_flags = 0;
sigaction(SIGSEGV, &sa, 0);
sigaction(SIGBUS, &sa, 0);
caught = 0;
n = lm_optB;
return (0);
}
int
benchmark_initrun()
{
(void) fprintf(stderr, "benchmark_initrun: entry\n");
return (0);
}
int
benchmark(void *tsd, result_t *res)
{
int i;
(void) fprintf(stderr, "benchmark: lm_optB = %i\n",lm_optB);
for (i = 0; i < lm_optB; i++) {
if (_setjmp(jumper) == 0) {
*mappedfile= 1;
}
}
res->re_count = i;
return (0);
}