int main(int ac, char **av) { int parallel = 1; int warmup = 0; int repetitions = -1; int c; char* usage = "[-P <parallelism>] [-W <warmup>] [-N <repetitions>] procedure|fork|exec|shell\n"; while (( c = getopt(ac, av, "P:W:N:")) != EOF) { switch(c) { case 'P': parallel = atoi(optarg); if (parallel <= 0) lmbench_usage(ac, av, usage); break; case 'W': warmup = atoi(optarg); break; case 'N': repetitions = atoi(optarg); break; default: lmbench_usage(ac, av, usage); break; } } if (optind + 1 != ac) { /* should have one argument left */ lmbench_usage(ac, av, usage); } if (!strcmp("procedure", av[optind])) { benchmp(NULL, do_procedure, cleanup, 0, parallel, warmup, repetitions, &ac); micro("Procedure call", get_n()); } else if (!strcmp("fork", av[optind])) { benchmp(NULL, do_fork, cleanup, 0, parallel, warmup, repetitions, NULL); micro(STATIC_PREFIX "Process fork+exit", get_n()); } else if (!strcmp("exec", av[optind])) { benchmp(NULL, do_forkexec, cleanup, 0, parallel, warmup, repetitions, NULL); micro(STATIC_PREFIX "Process fork+execve", get_n()); } else if (!strcmp("shell", av[optind])) { benchmp(NULL, do_shell, cleanup, 0, parallel, warmup, repetitions, NULL); micro(STATIC_PREFIX "Process fork+/bin/sh -c", get_n()); } else { lmbench_usage(ac, av, usage); } return(0); }
int main(int ac, char **av) { int parallel = 1; int warmup = 0; int repetitions = TRIES; int c; char* usage = "[-P <parallelism>] [-W <warmup>] [-N <repetitions>]\n"; while (( c = getopt(ac, av, "P:W:N:")) != EOF) { switch(c) { case 'P': parallel = atoi(optarg); if (parallel <= 0) lmbench_usage(ac, av, usage); break; case 'W': warmup = atoi(optarg); break; case 'N': repetitions = atoi(optarg); break; default: lmbench_usage(ac, av, usage); break; } } if (optind < ac) { lmbench_usage(ac, av, usage); } #ifdef HAVE_DRAND48 benchmp(NULL, bench_drand48, NULL, 0, parallel, warmup, repetitions, NULL); nano("drand48 latency", get_n()); benchmp(NULL, bench_lrand48, NULL, 0, parallel, warmup, repetitions, NULL); nano("lrand48 latency", get_n()); #endif #ifdef HAVE_RAND benchmp(NULL, bench_rand, NULL, 0, parallel, warmup, repetitions, NULL); nano("rand latency", get_n()); #endif #ifdef HAVE_RANDOM benchmp(NULL, bench_random, NULL, 0, parallel, warmup, repetitions, NULL); nano("random latency", get_n()); #endif return (0); }
int main(int ac, char **av) { state_t state; int parallel = 1; int warmup = 0; int repetitions = -1; int c; double time; uint64 usecs; char buf[1024]; char* usage = "[-P <parallelism>] [-W <warmup>] [-N <repetitions>] Njobs usecs...\n"; while (( c = getopt(ac, av, "P:W:N:")) != EOF) { switch(c) { case 'P': parallel = atoi(optarg); if (parallel <= 0) lmbench_usage(ac, av, usage); break; case 'W': warmup = atoi(optarg); break; case 'N': repetitions = atoi(optarg); break; default: lmbench_usage(ac, av, usage); break; } } if (ac < optind + 2) { lmbench_usage(ac, av, usage); } state.jobs = atoi(av[optind]); state.pids = NULL; fprintf(stderr, "\"pmake jobs=%d\n", state.jobs); while (++optind < ac) { usecs = bytes(av[optind]); benchmp(setup, work, NULL, 0, 1, 0, TRIES, &state); if (gettime() == 0) exit(1); state.iterations = (iter_t)((usecs * get_n()) / gettime()); benchmp(setup, bench, NULL, 0, parallel, warmup, repetitions, &state); time = gettime(); time /= get_n(); if (time > 0.0) fprintf(stderr, "%llu %.2f\n", usecs, time); } return (0); }
double loads(benchmp_f initialize, int len, int warmup, int repetitions, void* cookie) { double result; int count; int parallel = 1; struct mem_state* state = (struct mem_state*)cookie; state->len = len; state->maxlen = len; count = 100 * (state->len / (state->line * 100) + 1); /* * Now walk them and time it. */ benchmp(initialize, benchmark_loads, mem_cleanup, 0, parallel, warmup, repetitions, cookie); /* We want to get to nanoseconds / load. */ result = (1000. * (double)gettime()) / (double)(count * get_n()); /* fprintf(stderr, "%.5f %.3f\n", len / (1024. * 1024.), result); /**/ return result; }
double max_parallelism(benchmp_f* benchmarks, int warmup, int repetitions, void* cookie) { int i, j, k; double baseline, max_load_parallelism, load_parallelism; result_t *results, *r_save; max_load_parallelism = 1.; for (i = 0; i < MAX_LOAD_PARALLELISM; ++i) { benchmp(initialize, benchmarks[i], cleanup, 0, 1, warmup, repetitions, cookie); save_minimum(); if (gettime() == 0) return -1.; if (i == 0) { baseline = (double)gettime() / (double)get_n(); } else { load_parallelism = baseline; load_parallelism /= (double)gettime(); load_parallelism *= (double)((i + 1) * get_n()); if (load_parallelism > max_load_parallelism) { max_load_parallelism = load_parallelism; } } } return max_load_parallelism; }
int main(int ac, char **av) { int parallel = 1; int warmup = 0; int repetitions = TRIES; char *usage = "-s\n OR [-P <parallelism>] [-W <warmup>] [-N <repetitions>]\n OR -S\n"; int c; /* Start the server "-s" or Shut down the server "-S" */ if (ac == 2) { if (!strcmp(av[1], "-s")) { #ifdef CONFIG_NOMMU if (fork() == 0) { server_main(); _exit(0); } #else if (fork() == 0) { server_main(); } #endif exit(0); } if (!strcmp(av[1], "-S")) { int sock = unix_connect(CONNAME); write(sock, "0", 1); close(sock); exit(0); } } /* * Rest is client */ while (( c = getopt(ac, av, "P:W:N:")) != EOF) { switch(c) { case 'P': parallel = atoi(optarg); if (parallel <= 0) lmbench_usage(ac, av, usage); break; case 'W': warmup = atoi(optarg); break; case 'N': repetitions = atoi(optarg); break; default: lmbench_usage(ac, av, usage); break; } } if (optind != ac) { lmbench_usage(ac, av, usage); } benchmp(NULL, benchmark, NULL, 0, parallel, warmup, repetitions, NULL); micro("UNIX connection cost", get_n()); }
int main(int argc, char *argv[]) { struct _state state; int parallel = 1; int warmup = 0; int repetitions = TRIES; int c; char* usage = "[-m <message size>] [-M <total bytes>] [-P <parallelism>] [-W <warmup>] [-N <repetitions>]\n"; state.xfer = XFERSIZE; /* per-packet size */ state.bytes = XFER; /* total bytes per call */ while (( c = getopt(argc,argv,"m:M:P:W:N:")) != EOF) { switch(c) { case 'm': state.xfer = bytes(optarg); break; case 'M': state.bytes = bytes(optarg); break; case 'P': parallel = atoi(optarg); if (parallel <= 0) lmbench_usage(argc, argv, usage); break; case 'W': warmup = atoi(optarg); break; case 'N': repetitions = atoi(optarg); break; default: lmbench_usage(argc, argv); break; } } if (optind == argc - 1) { state.bytes = bytes(argv[optind]); } else if (optind < argc - 1) { lmbench_usage(argc, argv); } state.pid = 0; /* round up total byte count to a multiple of xfer */ if (state.bytes % state.xfer) { state.bytes += state.bytes - state.bytes % state.xfer; } benchmp(initialize, reader, cleanup, MEDIUM, parallel, warmup, repetitions, &state); if (gettime() > 0) { fprintf(stderr, "AF_UNIX sock stream bandwidth: "); mb(get_n() * parallel * XFER); } return(0); }
/* * Cost of catching the signal less the cost of sending it */ void bench_catch(int parallel, int warmup, int repetitions) { uint64 t, send_usecs, send_n; /* measure cost of sending signal */ benchmp(NULL, do_send, NULL, 0, parallel, warmup, repetitions, NULL); send_usecs = gettime(); send_n = get_n(); /* measure cost of sending & catching signal */ benchmp(NULL, do_catch, NULL, 0, parallel, warmup, repetitions, NULL); /* subtract cost of sending signal */ if (gettime() > (send_usecs * get_n()) / send_n) { settime(gettime() - (send_usecs * get_n()) / send_n); } else { settime(0); } }
int main(int ac, char **av) { state_t state; int rc, c, repetitions = -1, warmup = 0; char buf[256]; char *usage = "-s\n OR [-S] [-W <warmup>] [-N <repetitions>] server\n"; while (( c = getopt(ac, av, "sSP:W:N:")) != EOF) { switch(c) { case 's': /* Server */ if (fork() == 0) { server_main(); } exit(0); case 'S': /* shutdown serverhost */ { int sock = tcp_connect(av[optind], TCP_CONNECT, SOCKOPT_NONE); rc = write(sock, "0", 1); if (rc < 0) DIE_PERROR("write failed"); close(sock); exit(0); } case 'W': warmup = atoi(optarg); break; case 'N': repetitions = atoi(optarg); break; default: lmbench_usage(ac, av, usage); break; } } if (optind + 1 != ac) { lmbench_usage(ac, av, usage); } handle_scheduler(benchmp_childid(), 0, 0); state.server = av[optind]; benchmp(NULL, doclient, NULL, 0, 1, warmup, repetitions, &state); sprintf(buf, "TCP/IP connection cost to %s", state.server); micro(buf, get_n()); exit(0); }
int main(int ac, char **av) { int parallel = 1; int warmup = 0; int repetitions = TRIES; int c; char* usage = "[-P <parallelism>] [-W <warmup>] [-N <repetitions>] install|catch|prot [file]\n"; while (( c = getopt(ac, av, "P:W:N:")) != EOF) { switch(c) { case 'P': parallel = atoi(optarg); if (parallel <= 0) lmbench_usage(ac, av, usage); break; case 'W': warmup = atoi(optarg); break; case 'N': repetitions = atoi(optarg); break; default: lmbench_usage(ac, av, usage); break; } } if (optind != ac - 1 && optind != ac - 2) { lmbench_usage(ac, av, usage); } if (!strcmp("install", av[optind])) { benchmp(NULL, do_install, NULL, 0, parallel, warmup, repetitions, NULL); micro("Signal handler installation", get_n()); } else if (!strcmp("catch", av[optind])) { bench_catch(parallel, warmup, repetitions); micro("Signal handler overhead", get_n()); } else if (!strcmp("prot", av[optind]) && optind == ac - 2) { bench_prot(av[optind+1], parallel, warmup, repetitions); micro("Protection fault", get_n()); } else { lmbench_usage(ac, av, usage); } return(0); }
int main(int ac, char **av) { int parallel = 1; int warmup = 0; int repetitions = -1; struct _state state; int c; char* usage = "[-m <message size>] [-P <parallelism>] [-W <warmup>] [-N <repetitions>]\n"; state.msize = 1; state.pid = 0; while (( c = getopt(ac, av, "m:P:W:N:")) != EOF) { switch(c) { case 'm': state.msize = atoi(optarg); break; case 'P': parallel = atoi(optarg); if (parallel <= 0) lmbench_usage(ac, av, usage); break; case 'W': warmup = atoi(optarg); break; case 'N': repetitions = atoi(optarg); break; default: lmbench_usage(ac, av, usage); break; } } if (optind < ac) { lmbench_usage(ac, av, usage); } benchmp(initialize, benchmark, cleanup, 0, parallel, warmup, repetitions, &state); micro("AF_UNIX sock stream latency", get_n()); return(0); }
int main(int ac, char **av) { int c; int i; int parallel = 1; int warmup = 0; int repetitions = TRIES; char buf[1024]; state_t state; char* usage = "[-P <parallelism>] [-W <warmup>] [-N <repetitions>] cmdline...\n"; while (( c = getopt(ac, av, "P:W:N:")) != EOF) { switch(c) { case 'P': parallel = atoi(optarg); if (parallel <= 0) lmbench_usage(ac, av, usage); break; case 'W': warmup = atoi(optarg); break; case 'N': repetitions = atoi(optarg); break; default: lmbench_usage(ac, av, usage); break; } } if (optind >= ac) { lmbench_usage(ac, av, usage); } state.argv = (char**)malloc((ac - optind + 1) * sizeof(char*)); state.pid = 0; for (i = 0; i < ac - optind; ++i) { state.argv[i] = av[optind + i]; } state.argv[i] = NULL; benchmp(NULL, bench, NULL, 0, parallel, warmup, repetitions, &state); micro("lat_cmd", get_n()); return (0); }
void loads(size_t len, size_t range, size_t stride, int parallel, int warmup, int repetitions) { double result; size_t count; struct mem_state state; if (range < stride) return; state.width = 1; state.len = range; state.maxlen = len; state.line = stride; state.pagesize = getpagesize(); count = 100 * (state.len / (state.line * 100) + 1); #if 0 (*fpInit)(0, &state); fprintf(stderr, "loads: after init\n"); (*benchmark_loads)(2, &state); fprintf(stderr, "loads: after benchmark\n"); mem_cleanup(0, &state); fprintf(stderr, "loads: after cleanup\n"); settime(1); save_n(1); #else /* * Now walk them and time it. */ benchmp(fpInit, benchmark_loads, mem_cleanup, 100000, parallel, warmup, repetitions, &state); #endif /* We want to get to nanoseconds / load. */ save_minimum(); result = (1000. * (double)gettime()) / (double)(count * get_n()); fprintf(stderr, "%.5f %.3f\n", range / (1024. * 1024.), result); }
int main(int ac, char **av) { state_t state; int parallel = 1; int warmup = 0; int repetitions = TRIES; int c; char* usage = "[-P <parallelism>] [-W <warmup>] [-N <repetitions>]\n"; while (( c = getopt(ac, av, "P:W:N:")) != EOF) { switch(c) { case 'P': parallel = atoi(optarg); if (parallel <= 0) lmbench_usage(ac, av, usage); break; case 'W': warmup = atoi(optarg); break; case 'N': repetitions = atoi(optarg); break; default: lmbench_usage(ac, av, usage); break; } } if (optind < ac) { lmbench_usage(ac, av, usage); } state.pid = 0; benchmp(initialize, doit, cleanup, SHORT, parallel, warmup, repetitions, &state); micro("Pipe latency", get_n()); return (0); }
void bench_prot(char* fname, int parallel, int warmup, int repetitions) { uint64 catch_usecs, catch_n; struct _state state; state.fname = fname; /* * Catch protection faults. * Assume that they will cost the same as a normal catch. */ bench_catch(parallel, warmup, repetitions); catch_usecs = gettime(); catch_n = get_n(); benchmp(initialize, do_prot, NULL, 0, parallel, warmup, repetitions, &state); if (gettime() > (catch_usecs * get_n()) / catch_n) { settime(gettime() - (catch_usecs * get_n()) / catch_n); } else { settime(0); } }
int main(int ac, char **av) { int c; int parallel = 1; int warmup = 0; int repetitions = -1; state_t state; CLIENT *cl; char buf[1024]; char *protocol = NULL; char *usage = "-s\n OR [-p <tcp|udp>] [-P parallel] [-W <warmup>] [-N <repetitions>] serverhost\n OR -S serverhost\n"; state.msize = 1; state.server = NULL; while (( c = getopt(ac, av, "sS:m:p:P:W:N:")) != EOF) { switch(c) { case 's': /* Server */ if (fork() == 0) { server_main(); } exit(0); case 'S': /* shutdown serverhost */ { cl = clnt_create(optarg, XACT_PROG, XACT_VERS, "udp"); if (!cl) { clnt_pcreateerror(state.server); exit(1); } clnt_call(cl, RPC_EXIT, (xdrproc_t)xdr_void, 0, (xdrproc_t)xdr_void, 0, TIMEOUT); exit(0); } case 'm': state.msize = atoi(optarg); break; case 'p': protocol = optarg; break; case 'P': parallel = atoi(optarg); if (parallel <= 0) lmbench_usage(ac, av, usage); break; case 'W': warmup = atoi(optarg); break; case 'N': repetitions = atoi(optarg); break; default: lmbench_usage(ac, av, usage); break; } } if (optind != ac - 1) { lmbench_usage(ac, av, usage); } state.server = av[optind++]; if (protocol == NULL || !strcasecmp(protocol, proto[0])) { state.protocol = proto[0]; benchmp(initialize, benchmark, NULL, MEDIUM, parallel, warmup, repetitions, &state); sprintf(buf, "RPC/%s latency using %s", proto[0], state.server); micro(buf, get_n()); } if (protocol == NULL || !strcasecmp(protocol, proto[1])) { state.protocol = proto[1]; benchmp(initialize, benchmark, NULL, MEDIUM, parallel, warmup, repetitions, &state); sprintf(buf, "RPC/%s latency using %s", proto[1], state.server); micro(buf, get_n()); } exit(0); }
int main(int ac, char **av) { int i, maxprocs; int c; int parallel = 1; int warmup = 0; int repetitions = -1; struct _state state; char *usage = "[-P <parallelism>] [-W <warmup>] [-N <repetitions>] [-s kbytes] processes [processes ...]\n"; double time; /* * Need 4 byte ints. */ if (sizeof(int) != 4) { fprintf(stderr, "Fix sumit() in ctx.c.\n"); exit(1); } state.process_size = 0; state.overhead = 0.0; state.pids = NULL; /* * If they specified a context size, or parallelism level, get them. */ while (( c = getopt(ac, av, "s:P:W:N:")) != EOF) { switch(c) { case 'P': parallel = atoi(optarg); if (parallel <= 0) lmbench_usage(ac, av, usage); break; case 'W': warmup = atoi(optarg); break; case 'N': repetitions = atoi(optarg); break; case 's': state.process_size = atoi(optarg) * 1024; break; default: lmbench_usage(ac, av, usage); break; } } if (optind > ac - 1) lmbench_usage(ac, av, usage); /* compute pipe + sumit overhead */ maxprocs = atoi(av[optind]); for (i = optind; i < ac; ++i) { state.procs = atoi(av[i]); if (state.procs > maxprocs) maxprocs = state.procs; } state.procs = maxprocs; benchmp(initialize_overhead, benchmark_overhead, cleanup_overhead, 0, 1, warmup, repetitions, &state); if (gettime() == 0) return(0); state.overhead = gettime(); state.overhead /= get_n(); fprintf(stderr, "\n\"size=%dk ovr=%.2f\n", state.process_size/1024, state.overhead); /* compute the context switch cost for N processes */ for (i = optind; i < ac; ++i) { state.procs = atoi(av[i]); benchmp(initialize, benchmark, cleanup, 0, parallel, warmup, repetitions, &state); time = gettime(); time /= get_n(); time /= state.procs; time -= state.overhead; if (time > 0.0) fprintf(stderr, "%d %.2f\n", state.procs, time); } return (0); }
int main(int ac, char **av) { int parallel = 1; int warmup = LONGER; int repetitions = -1; int shutdown = 0; state_t state; char *usage = "-s\n OR [-m <message size>] [-M <bytes to move>] [-P <parallelism>] [-W <warmup>] [-N <repetitions>] server\n OR -S serverhost\n"; int c; state.msize = 0; state.move = 0; /* Rest is client argument processing */ while (( c = getopt(ac, av, "sS:m:M:P:W:N:")) != EOF) { switch(c) { case 's': /* Server */ if (fork() == 0) { server_main(); } exit(0); break; case 'S': /* shutdown serverhost */ { int conn; conn = tcp_connect(optarg, TCP_DATA, SOCKOPT_NONE); write(conn, "0", 1); exit(0); } case 'm': state.msize = bytes(optarg); break; case 'M': state.move = bytes(optarg); break; case 'P': parallel = atoi(optarg); if (parallel <= 0) lmbench_usage(ac, av, usage); break; case 'W': warmup = atoi(optarg); break; case 'N': repetitions = atoi(optarg); break; default: lmbench_usage(ac, av, usage); break; } } if (optind < ac - 2 || optind >= ac) { lmbench_usage(ac, av, usage); } state.server = av[optind++]; if (state.msize == 0 && state.move == 0) { state.msize = state.move = XFERSIZE; } else if (state.msize == 0) { state.msize = state.move; } else if (state.move == 0) { state.move = state.msize; } /* make the number of bytes to move a multiple of the message size */ if (state.move % state.msize) { state.move += state.msize - state.move % state.msize; } /* * Default is to warmup the connection for seven seconds, * then measure performance over each timing interval. * This minimizes the effect of opening and initializing TCP * connections. */ benchmp(initialize, loop_transfer, cleanup, 0, parallel, warmup, repetitions, &state); if (gettime() > 0) { fprintf(stderr, "%.6f ", state.msize / (1000. * 1000.)); mb(state.move * get_n() * parallel); } return(0); }
int main(int ac, char **av) { state_t state; int parallel = 1; int warmup = 0; int repetitions = -1; int c; char* usage = "[-n <#descriptors>] [-P <parallelism>] [-W <warmup>] [-N <repetitions>] file|tcp\n"; char buf[256]; morefds(); /* bump fd_cur to fd_max */ state.num = 200; while (( c = getopt(ac, av, "P:W:N:n:")) != EOF) { switch(c) { case 'P': parallel = atoi(optarg); if (parallel <= 0) lmbench_usage(ac, av, usage); break; case 'W': warmup = atoi(optarg); break; case 'N': repetitions = atoi(optarg); break; case 'n': state.num = bytes(optarg); break; default: lmbench_usage(ac, av, usage); break; } } if (optind + 1 != ac) { lmbench_usage(ac, av, usage); } if (streq("tcp", av[optind])) { state.fid_f = open_socket; server(&state); benchmp(initialize, doit, cleanup, 0, parallel, warmup, repetitions, &state); sprintf(buf, "Select on %d tcp fd's", state.num); kill(state.pid, SIGKILL); waitpid(state.pid, NULL, 0); micro(buf, get_n()); } else if (streq("file", av[optind])) { state.fid_f = open_file; server(&state); benchmp(initialize, doit, cleanup, 0, parallel, warmup, repetitions, &state); unlink(state.fname); sprintf(buf, "Select on %d fd's", state.num); micro(buf, get_n()); } else { lmbench_usage(ac, av, usage); } exit(0); }
int main(int ac, char **av) { state_t state; int parallel = 1; int warmup = 0; int repetitions = TRIES; int c; char buf[256]; char *usage = "-s\n OR [-m <message size>] [-P <parallelism>] [-W <warmup>] [-N <repetitions>] server\n OR -S server\n"; state.msize = 1; while (( c = getopt(ac, av, "sS:m:P:W:N:")) != EOF) { switch(c) { case 's': /* Server */ #ifdef CONFIG_NOMMU server_main(); #else if (fork() == 0) { server_main(); } #endif exit(0); case 'S': /* shutdown serverhost */ state.sock = tcp_connect(optarg, TCP_XACT, SOCKOPT_NONE); close(state.sock); exit(0); case 'm': state.msize = atoi(optarg); break; case 'P': parallel = atoi(optarg); if (parallel <= 0) lmbench_usage(ac, av, usage); break; case 'W': warmup = atoi(optarg); break; case 'N': repetitions = atoi(optarg); break; default: lmbench_usage(ac, av, usage); break; } } if (optind != ac - 1) { lmbench_usage(ac, av, usage); } state.server = av[optind]; benchmp(init, doclient, cleanup, MEDIUM, parallel, warmup, repetitions, &state); sprintf(buf, "TCP latency using %s", state.server); micro(buf, get_n()); exit(0); }
int main(int ac, char **av) { int parallel = 1; int warmup = 0; int repetitions = -1; int server = 0; state_t state; char *usage = "-s\n OR [-m <message size>] [-W <warmup>] [-N <repetitions>] server [size]\n OR -S serverhost\n"; int c; uint64 usecs; state.msize = 0; state.move = 10*1024*1024; /* Rest is client argument processing */ while (( c = getopt(ac, av, "sS:m:W:N:")) != EOF) { switch(c) { case 's': /* Server */ #ifdef CONFIG_NOMMU if (vfork() == 0) { server_main(); _exit(0); } #else if (fork() == 0) { server_main(); } #endif exit(0); case 'S': /* shutdown serverhost */ { int seq, n; int sock = udp_connect(optarg, UDP_XACT, SOCKOPT_NONE); for (n = -1; n > -5; --n) { seq = htonl(n); (void) send(sock, &seq, sizeof(int), 0); } close(sock); exit (0); } case 'm': state.msize = atoi(optarg); break; case 'W': warmup = atoi(optarg); break; case 'N': repetitions = atoi(optarg); break; default: lmbench_usage(ac, av, usage); break; } } if (optind < ac - 2 || optind >= ac) { lmbench_usage(ac, av, usage); } state.server = av[optind++]; if (optind < ac) { state.move = bytes(av[optind]); } if (state.msize == 0) { state.msize = state.move; } /* make the number of bytes to move a multiple of the message size */ if (state.move % state.msize) { state.move += state.move - state.move % state.msize; } state.buf = valloc(state.msize); if (!state.buf) { perror("valloc"); exit(1); } touch(state.buf, state.msize); /* * Make one run take at least 5 seconds. * This minimizes the effect of connect & reopening TCP windows. */ benchmp(init, loop_transfer, cleanup, LONGER, parallel, warmup, repetitions, &state ); out: (void)fprintf(stderr, "socket UDP bandwidth using %s: ", state.server); mb(state.move * get_n() * parallel); }
int main(int ac, char **av) { state_t state; int c; int parallel = 1; int warmup = 0; int repetitions = TRIES; int msize = 4; char buf[256]; char *usage = "-s\n OR [-S] [-m <message size>] [-P <parallelism>] [-W <warmup>] [-N <repetitions>] server\n NOTE: message size must be >= 4\n"; if (sizeof(int) != 4) { fprintf(stderr, "lat_udp: Wrong sequence size\n"); return(1); } while (( c = getopt(ac, av, "sS:m:P:W:N:")) != EOF) { switch(c) { case 's': /* Server */ if (fork() == 0) { server_main(); } exit(0); case 'S': /* shutdown serverhost */ { int seq, n; int sock = udp_connect(optarg, UDP_XACT, SOCKOPT_NONE); for (n = -1; n > -5; --n) { seq = htonl(n); (void) send(sock, &seq, sizeof(int), 0); } close(sock); exit (0); } case 'm': msize = atoi(optarg); if (msize < sizeof(int)) { lmbench_usage(ac, av, usage); msize = 4; } if (msize > MAX_MSIZE) { lmbench_usage(ac, av, usage); msize = MAX_MSIZE; } break; case 'P': parallel = atoi(optarg); if (parallel <= 0) lmbench_usage(ac, av, usage); break; case 'W': warmup = atoi(optarg); break; case 'N': repetitions = atoi(optarg); break; default: lmbench_usage(ac, av, usage); break; } } if (optind + 1 != ac) { lmbench_usage(ac, av, usage); } state.server = av[optind]; state.msize = msize; benchmp(init, doit, cleanup, SHORT, parallel, warmup, repetitions, &state); sprintf(buf, "UDP latency using %s", state.server); micro(buf, get_n()); exit(0); }
int main(int ac, char **av) { int realtime = 0; int parallel = 1; int warmup = 0; int repetitions = -1; int c; char buf[512]; timer_e what = USLEEP; state_t state; char *scheduler = ""; char *mechanism = "usleep"; char *usage = "[-r] [-u <method>] [-P <parallelism>] [-W <warmup>] [-N <repetitions>] usecs\nmethod=usleep|nanosleep|select|pselect|itimer\n"; realtime = 0; while ((c = getopt(ac, av, "ru:W:N:")) != EOF) { switch (c) { case 'r': realtime = 1; break; case 'u': if (strcmp(optarg, "usleep") == 0) { what = USLEEP; mechanism = "usleep"; } else if (strcmp(optarg, "nanosleep") == 0) { what = NANOSLEEP; mechanism = "nanosleep"; } else if (strcmp(optarg, "select") == 0) { what = SELECT; mechanism = "select"; #ifdef _POSIX_SELECT } else if (strcmp(optarg, "pselect") == 0) { what = PSELECT; mechanism = "pselect"; #endif /* _POSIX_SELECT */ } else if (strcmp(optarg, "itimer") == 0) { what = ITIMER; mechanism = "itimer"; } else { lmbench_usage(ac, av, usage); } break; case 'P': parallel = atoi(optarg); if (parallel <= 0) lmbench_usage(ac, av, usage); break; case 'W': warmup = atoi(optarg); break; case 'N': repetitions = atoi(optarg); break; default: lmbench_usage(ac, av, usage); break; } } if (optind != ac - 1) { lmbench_usage(ac, av, usage); } state.usecs = bytes(av[optind]); if (realtime && set_realtime()) scheduler = "realtime "; switch (what) { case USLEEP: benchmp(NULL, bench_usleep, NULL, 0, parallel, warmup, repetitions, &state); break; case NANOSLEEP: benchmp(NULL, bench_nanosleep, NULL, 0, parallel, warmup, repetitions, &state); break; case SELECT: benchmp(NULL, bench_select, NULL, 0, parallel, warmup, repetitions, &state); break; #ifdef _POSIX_SELECT case PSELECT: benchmp(NULL, bench_pselect, NULL, 0, parallel, warmup, repetitions, &state); break; #endif /* _POSIX_SELECT */ case ITIMER: benchmp(initialize, bench_itimer, NULL, 0, parallel, warmup, repetitions, &state); break; default: lmbench_usage(ac, av, usage); break; } sprintf(buf, "%s%s %lu microseconds", scheduler, mechanism, state.usecs); micro(buf, get_n()); return (0); }
void benchmp(benchmp_f initialize, benchmp_f benchmark, benchmp_f cleanup, int enough, int parallel, int warmup, int repetitions, void* cookie) { iter_t iterations = 1; long i; pid_t *pids = NULL; int response[2]; int start_signal[2]; int result_signal[2]; int exit_signal[2]; #ifdef _DEBUG fprintf(stderr, "benchmp(%p, %p, %p, %d, %d, %d, %d, %p): entering\n", initialize, benchmark, cleanup, enough, parallel, warmup, repetitions, cookie); #endif enough = get_enough(enough); #ifdef _DEBUG fprintf(stderr, "\tenough=%d\n", enough); #endif if (repetitions < 0) repetitions = (1 < parallel || 1000000 <= enough ? 1 : TRIES); /* initialize results */ settime(0); save_n(1); if (parallel > 1) { /* Compute the baseline performance */ benchmp(initialize, benchmark, cleanup, enough, 1, warmup, repetitions, cookie); /* if we can't even do a single job, then give up */ if (gettime() == 0) return; /* calculate iterations for 1sec runtime */ iterations = get_n(); if (enough < SHORT) { double tmp = (double)SHORT * (double)get_n(); tmp /= (double)gettime(); iterations = (iter_t)tmp + 1; } settime(0); save_n(1); } /* Create the necessary pipes for control */ if (pipe(response) < 0 || pipe(start_signal) < 0 || pipe(result_signal) < 0 || pipe(exit_signal) < 0) { #ifdef _DEBUG fprintf(stderr, "BENCHMP: Could not create control pipes\n"); #endif /* _DEBUG */ return; } /* fork the necessary children */ benchmp_sigchld_received = 0; benchmp_sigterm_received = 0; benchmp_sigterm_handler = signal(SIGTERM, benchmp_sigterm); benchmp_sigchld_handler = signal(SIGCHLD, benchmp_sigchld); pids = (pid_t*)malloc(parallel * sizeof(pid_t)); if (!pids) return; bzero((void*)pids, parallel * sizeof(pid_t)); for (i = 0; i < parallel; ++i) { if (benchmp_sigterm_received) goto error_exit; #ifdef _DEBUG fprintf(stderr, "benchmp(%p, %p, %p, %d, %d, %d, %d, %p): creating child %d\n", initialize, benchmark, cleanup, enough, parallel, warmup, repetitions, cookie, i); #endif switch(pids[i] = fork()) { case -1: /* could not open enough children! */ #ifdef _DEBUG fprintf(stderr, "BENCHMP: fork() failed!\n"); #endif /* _DEBUG */ goto error_exit; case 0: /* If child */ close(response[0]); close(start_signal[1]); close(result_signal[1]); close(exit_signal[1]); handle_scheduler(i, 0, 0); benchmp_child(initialize, benchmark, cleanup, i, response[1], start_signal[0], result_signal[0], exit_signal[0], enough, iterations, parallel, repetitions, cookie ); exit(0); default: break; } } close(response[1]); close(start_signal[0]); close(result_signal[0]); close(exit_signal[0]); benchmp_parent(response[0], start_signal[1], result_signal[1], exit_signal[1], pids, parallel, iterations, warmup, repetitions, enough ); goto cleanup_exit; error_exit: /* give the children a chance to clean up gracefully */ signal(SIGCHLD, SIG_DFL); while (--i >= 0) { kill(pids[i], SIGTERM); waitpid(pids[i], NULL, 0); } cleanup_exit: /* * Clean up and kill all children * * NOTE: the children themselves SHOULD exit, and * Killing them could prevent them from * cleanup up subprocesses, etc... So, we only * want to kill child processes when it appears * that they will not die of their own accord. * We wait twice the timing interval plus two seconds * for children to die. If they haven't died by * that time, then we start killing them. */ benchmp_sigalrm_timeout = (int)((2 * enough)/1000000) + 2; if (benchmp_sigalrm_timeout < 5) benchmp_sigalrm_timeout = 5; signal(SIGCHLD, SIG_DFL); while (i-- > 0) { /* wait timeout seconds for child to die, then kill it */ benchmp_sigalrm_pid = pids[i]; benchmp_sigalrm_handler = signal(SIGALRM, benchmp_sigalrm); alarm(benchmp_sigalrm_timeout); waitpid(pids[i], NULL, 0); alarm(0); signal(SIGALRM, benchmp_sigalrm_handler); } if (pids) free(pids); #ifdef _DEBUG fprintf(stderr, "benchmp(0x%x, 0x%x, 0x%x, %d, %d, 0x%x): exiting\n", (unsigned int)initialize, (unsigned int)benchmark, (unsigned int)cleanup, enough, parallel, (unsigned int)cookie); #endif }
int main(int ac, char **av) { int fd; struct stat sbuf; void *buf; int parallel = 1; int warmup = 0; int repetitions = TRIES; size_t nbytes; state_t state; int c; char *usage = "[-C] [-P <parallelism>] [-W <warmup>] [-N <repetitions>] <size> open2close|mmap_only <filename>"; state.clone = 0; while (( c = getopt(ac, av, "P:W:N:C")) != EOF) { switch(c) { case 'P': parallel = atoi(optarg); if (parallel <= 0) lmbench_usage(ac, av, usage); break; case 'W': warmup = atoi(optarg); break; case 'N': repetitions = atoi(optarg); break; case 'C': state.clone = 1; break; default: lmbench_usage(ac, av, usage); break; } } /* should have three arguments left (bytes type filename) */ if (optind + 3 != ac) { lmbench_usage(ac, av, usage); } nbytes = state.nbytes = bytes(av[optind]); strcpy(state.filename,av[optind+2]); CHK(stat(state.filename, &sbuf)); if ((S_ISREG(sbuf.st_mode) && nbytes > sbuf.st_size) || (nbytes < MINSZ)) { fprintf(stderr,"<size> out of range!\n"); exit(1); } if (!strcmp("open2close", av[optind+1])) { benchmp(initialize, time_with_open, cleanup, 0, parallel, warmup, repetitions, &state); } else if (!strcmp("mmap_only", av[optind+1])) { benchmp(init_open, time_no_open, cleanup, 0, parallel, warmup, repetitions, &state); } else { lmbench_usage(ac, av, usage); } bandwidth(nbytes, get_n() * parallel, 0); return (0); }
int main(int ac, char **av) { int parallel = 1; int warmup = 0; int repetitions = TRIES; int c; struct _state state; char* usage = "[-P <parallelism>] [-W <warmup>] [-N <repetitions>] null|read|write|stat|fstat|open [file]\n"; while (( c = getopt(ac, av, "P:W:N:")) != EOF) { switch(c) { case 'P': parallel = atoi(optarg); if (parallel <= 0) lmbench_usage(ac, av, usage); break; case 'W': warmup = atoi(optarg); break; case 'N': repetitions = atoi(optarg); break; default: lmbench_usage(ac, av, usage); break; } } if (optind != ac - 1 && optind != ac - 2 ) { lmbench_usage(ac, av, usage); } state.file = FNAME; if (optind == ac - 2) state.file = av[optind + 1]; if (!strcmp("null", av[optind])) { benchmp(NULL, do_getppid, NULL, 0, parallel, warmup, repetitions, &state); micro("Simple syscall", get_n()); } else if (!strcmp("write", av[optind])) { state.fd = open("/dev/null", 1); benchmp(NULL, do_write, NULL, 0, parallel, warmup, repetitions, &state); micro("Simple write", get_n()); close(state.fd); } else if (!strcmp("read", av[optind])) { state.fd = open("/dev/zero", 0); if (state.fd == -1) { fprintf(stderr, "Simple read: -1\n"); return(1); } benchmp(NULL, do_read, NULL, 0, parallel, warmup, repetitions, &state); micro("Simple read", get_n()); close(state.fd); } else if (!strcmp("stat", av[optind])) { benchmp(NULL, do_stat, NULL, 0, parallel, warmup, repetitions, &state); micro("Simple stat", get_n()); } else if (!strcmp("fstat", av[optind])) { state.fd = open(state.file, 0); benchmp(NULL, do_fstat, NULL, 0, parallel, warmup, repetitions, &state); micro("Simple fstat", get_n()); close(state.fd); } else if (!strcmp("open", av[optind])) { benchmp(NULL, do_openclose, NULL, 0, parallel, warmup, repetitions, &state); micro("Simple open/close", get_n()); } else { lmbench_usage(ac, av, usage); } return(0); }
int main(int ac, char **av) { int fd; state_t state; int parallel = 1; int warmup = 0; int repetitions = -1; int c; char usage[1024]; sprintf(usage,"[-C] [-P <parallelism>] [-W <warmup>] [-N <repetitions>]" " [-D <path>] [-I isolate_paths ] [-U uid/gid] \n" " [-L <lock_uid>] [-w <open for write>] <filename>\n"); state.clone = 0; state.write = 1; state.lock_uid = 0; while (( c = getopt(ac, av, "P:W:N:L:D:CIUw")) != EOF) { switch(c) { case 'P': parallel = atoi(optarg); if (parallel <= 0) lmbench_usage(ac, av, usage); break; case 'W': warmup = atoi(optarg); break; case 'N': repetitions = atoi(optarg); break; case 'L': state.lock_uid = atoi(optarg); break; case 'D': strcpy(state.path, optarg); break; case 'C': state.clone = 1; break; case 'I': state.isolate = 1; break; case 'U': state.use_uid = 1; break; case 'w': state.write = 1; break; default: lmbench_usage(ac, av, usage); break; } } if (optind + 1 != ac) { /* should have three arguments left */ lmbench_usage(ac, av, usage); } strcpy(state.filename,av[optind]); benchmp(initialize, time_with_loop, cleanup, 0, parallel, warmup, repetitions, &state); mili_op("res ", get_n(), parallel); return (0); }