From 3c1f50a75beb85f5e9ad67fc1bde139b53c8e238 Mon Sep 17 00:00:00 2001 From: CSRG Date: Mon, 6 May 1985 03:27:25 -0800 Subject: [PATCH] BSD 4_3_Net_2 development Work on file usr/src/sys/tests/benchmarks/Makefile Work on file usr/src/sys/tests/benchmarks/run Work on file usr/src/sys/tests/benchmarks/gausspage.c Work on file usr/src/sys/tests/benchmarks/pipeback.c Work on file usr/src/sys/tests/benchmarks/randread.c Work on file usr/src/sys/tests/benchmarks/seqread.c Work on file usr/src/sys/tests/benchmarks/inet/inetdgs.c Work on file usr/src/sys/tests/benchmarks/inet/inetdg.c Work on file usr/src/sys/tests/benchmarks/randbread.c Work on file usr/src/sys/tests/benchmarks/bench-4.1/pipeback.c Work on file usr/src/sys/tests/benchmarks/bench-4.1/pipeself.c Work on file usr/src/sys/tests/benchmarks/bench-4.1/gausspage.c Work on file usr/src/sys/tests/benchmarks/bench-4.1/csw.c Work on file usr/src/sys/tests/benchmarks/bench-4.1/pipediscard.c Work on file usr/src/sys/tests/benchmarks/bench-4.1/randbread.c Work on file usr/src/sys/tests/benchmarks/bench-4.1/randread.c Work on file usr/src/sys/tests/benchmarks/bench-4.1/seqread.c Work on file usr/src/sys/tests/benchmarks/bench-4.1/seqpage.c Work on file usr/src/sys/tests/benchmarks/bench-4.1/randpage.c Work on file usr/src/sys/tests/benchmarks/bench-4.1/randwrite.c Work on file usr/src/sys/tests/benchmarks/bench-4.1/randrewrite.c Work on file usr/src/sys/tests/benchmarks/bench-4.1/Makefile Work on file usr/src/sys/tests/benchmarks/bench-4.1/seqrewrite.c Work on file usr/src/sys/tests/benchmarks/bench-4.1/syscall.c Work on file usr/src/sys/tests/benchmarks/bench-4.1/seqwrite.c Work on file usr/src/sys/tests/benchmarks/bench-4.1/run Work on file usr/src/sys/tests/benchmarks/bench-4.1/signocsw.c Work on file usr/src/sys/tests/benchmarks/bench-4.1/getpagesize.c Work on file usr/src/sys/tests/benchmarks/nulljob.c Work on file usr/src/sys/tests/benchmarks/udgself.c Work on file usr/src/sys/tests/benchmarks/pipediscard.c Work on file usr/src/sys/tests/benchmarks/bigjob.c Work on file usr/src/sys/tests/benchmarks/execs.c Work on file usr/src/sys/tests/benchmarks/forks.c Work on file usr/src/sys/tests/benchmarks/udgback.c Work on file usr/src/sys/tests/benchmarks/udgdiscard.c Work on file usr/src/sys/tests/benchmarks/vforks.c Work on file usr/src/sys/tests/benchmarks/pipeself.c Work on file usr/src/sys/tests/benchmarks/countenv.c Work on file usr/src/sys/tests/benchmarks/run+fs Work on file usr/src/sys/tests/benchmarks/seqwrite.c Work on file usr/src/sys/tests/benchmarks/randrewrite.c Work on file usr/src/sys/tests/benchmarks/vexecs.c Work on file usr/src/sys/tests/benchmarks/randwrite.c Work on file usr/src/sys/tests/benchmarks/randpage.c Work on file usr/src/sys/tests/benchmarks/seqpage.c Work on file usr/src/sys/tests/benchmarks/run.awk Work on file usr/src/sys/tests/benchmarks/syscall.c Work on file usr/src/sys/tests/benchmarks/valloc.c Work on file usr/src/sys/tests/benchmarks/seqrewrite.c Work on file usr/src/sys/tests/benchmarks/udgrand.c Synthesized-from: CSRG/cd2/net.2 --- usr/src/sys/tests/benchmarks/Makefile | 95 +++++++++++ .../sys/tests/benchmarks/bench-4.1/Makefile | 59 +++++++ usr/src/sys/tests/benchmarks/bench-4.1/csw.c | 47 ++++++ .../tests/benchmarks/bench-4.1/gausspage.c | 100 +++++++++++ .../tests/benchmarks/bench-4.1/getpagesize.c | 5 + .../sys/tests/benchmarks/bench-4.1/pipeback.c | 46 ++++++ .../tests/benchmarks/bench-4.1/pipediscard.c | 35 ++++ .../sys/tests/benchmarks/bench-4.1/pipeself.c | 33 ++++ .../tests/benchmarks/bench-4.1/randbread.c | 44 +++++ .../sys/tests/benchmarks/bench-4.1/randpage.c | 62 +++++++ .../sys/tests/benchmarks/bench-4.1/randread.c | 49 ++++++ .../tests/benchmarks/bench-4.1/randrewrite.c | 48 ++++++ .../tests/benchmarks/bench-4.1/randwrite.c | 45 +++++ usr/src/sys/tests/benchmarks/bench-4.1/run | 44 +++++ .../sys/tests/benchmarks/bench-4.1/seqpage.c | 55 ++++++ .../sys/tests/benchmarks/bench-4.1/seqread.c | 32 ++++ .../tests/benchmarks/bench-4.1/seqrewrite.c | 35 ++++ .../sys/tests/benchmarks/bench-4.1/seqwrite.c | 34 ++++ .../sys/tests/benchmarks/bench-4.1/signocsw.c | 31 ++++ .../sys/tests/benchmarks/bench-4.1/syscall.c | 16 ++ usr/src/sys/tests/benchmarks/bigjob.c | 12 ++ usr/src/sys/tests/benchmarks/countenv.c | 18 ++ usr/src/sys/tests/benchmarks/execs.c | 54 ++++++ usr/src/sys/tests/benchmarks/forks.c | 49 ++++++ usr/src/sys/tests/benchmarks/gausspage.c | 104 ++++++++++++ usr/src/sys/tests/benchmarks/inet/inetdg.c | 142 ++++++++++++++++ usr/src/sys/tests/benchmarks/inet/inetdgs.c | 128 ++++++++++++++ usr/src/sys/tests/benchmarks/nulljob.c | 10 ++ usr/src/sys/tests/benchmarks/pipeback.c | 46 ++++++ usr/src/sys/tests/benchmarks/pipediscard.c | 35 ++++ usr/src/sys/tests/benchmarks/pipeself.c | 33 ++++ usr/src/sys/tests/benchmarks/randbread.c | 44 +++++ usr/src/sys/tests/benchmarks/randpage.c | 65 ++++++++ usr/src/sys/tests/benchmarks/randread.c | 49 ++++++ usr/src/sys/tests/benchmarks/randrewrite.c | 48 ++++++ usr/src/sys/tests/benchmarks/randwrite.c | 45 +++++ usr/src/sys/tests/benchmarks/run | 78 +++++++++ usr/src/sys/tests/benchmarks/run+fs | 92 +++++++++++ usr/src/sys/tests/benchmarks/run.awk | 3 + usr/src/sys/tests/benchmarks/seqpage.c | 58 +++++++ usr/src/sys/tests/benchmarks/seqread.c | 32 ++++ usr/src/sys/tests/benchmarks/seqrewrite.c | 35 ++++ usr/src/sys/tests/benchmarks/seqwrite.c | 34 ++++ usr/src/sys/tests/benchmarks/syscall.c | 16 ++ usr/src/sys/tests/benchmarks/udgback.c | 85 ++++++++++ usr/src/sys/tests/benchmarks/udgdiscard.c | 78 +++++++++ usr/src/sys/tests/benchmarks/udgrand.c | 156 ++++++++++++++++++ usr/src/sys/tests/benchmarks/udgself.c | 70 ++++++++ usr/src/sys/tests/benchmarks/valloc.c | 18 ++ usr/src/sys/tests/benchmarks/vexecs.c | 54 ++++++ usr/src/sys/tests/benchmarks/vforks.c | 49 ++++++ 51 files changed, 2655 insertions(+) create mode 100644 usr/src/sys/tests/benchmarks/Makefile create mode 100644 usr/src/sys/tests/benchmarks/bench-4.1/Makefile create mode 100644 usr/src/sys/tests/benchmarks/bench-4.1/csw.c create mode 100644 usr/src/sys/tests/benchmarks/bench-4.1/gausspage.c create mode 100644 usr/src/sys/tests/benchmarks/bench-4.1/getpagesize.c create mode 100644 usr/src/sys/tests/benchmarks/bench-4.1/pipeback.c create mode 100644 usr/src/sys/tests/benchmarks/bench-4.1/pipediscard.c create mode 100644 usr/src/sys/tests/benchmarks/bench-4.1/pipeself.c create mode 100644 usr/src/sys/tests/benchmarks/bench-4.1/randbread.c create mode 100644 usr/src/sys/tests/benchmarks/bench-4.1/randpage.c create mode 100644 usr/src/sys/tests/benchmarks/bench-4.1/randread.c create mode 100644 usr/src/sys/tests/benchmarks/bench-4.1/randrewrite.c create mode 100644 usr/src/sys/tests/benchmarks/bench-4.1/randwrite.c create mode 100644 usr/src/sys/tests/benchmarks/bench-4.1/run create mode 100644 usr/src/sys/tests/benchmarks/bench-4.1/seqpage.c create mode 100644 usr/src/sys/tests/benchmarks/bench-4.1/seqread.c create mode 100644 usr/src/sys/tests/benchmarks/bench-4.1/seqrewrite.c create mode 100644 usr/src/sys/tests/benchmarks/bench-4.1/seqwrite.c create mode 100644 usr/src/sys/tests/benchmarks/bench-4.1/signocsw.c create mode 100644 usr/src/sys/tests/benchmarks/bench-4.1/syscall.c create mode 100644 usr/src/sys/tests/benchmarks/bigjob.c create mode 100644 usr/src/sys/tests/benchmarks/countenv.c create mode 100644 usr/src/sys/tests/benchmarks/execs.c create mode 100644 usr/src/sys/tests/benchmarks/forks.c create mode 100644 usr/src/sys/tests/benchmarks/gausspage.c create mode 100644 usr/src/sys/tests/benchmarks/inet/inetdg.c create mode 100644 usr/src/sys/tests/benchmarks/inet/inetdgs.c create mode 100644 usr/src/sys/tests/benchmarks/nulljob.c create mode 100644 usr/src/sys/tests/benchmarks/pipeback.c create mode 100644 usr/src/sys/tests/benchmarks/pipediscard.c create mode 100644 usr/src/sys/tests/benchmarks/pipeself.c create mode 100644 usr/src/sys/tests/benchmarks/randbread.c create mode 100644 usr/src/sys/tests/benchmarks/randpage.c create mode 100644 usr/src/sys/tests/benchmarks/randread.c create mode 100644 usr/src/sys/tests/benchmarks/randrewrite.c create mode 100644 usr/src/sys/tests/benchmarks/randwrite.c create mode 100644 usr/src/sys/tests/benchmarks/run create mode 100644 usr/src/sys/tests/benchmarks/run+fs create mode 100644 usr/src/sys/tests/benchmarks/run.awk create mode 100644 usr/src/sys/tests/benchmarks/seqpage.c create mode 100644 usr/src/sys/tests/benchmarks/seqread.c create mode 100644 usr/src/sys/tests/benchmarks/seqrewrite.c create mode 100644 usr/src/sys/tests/benchmarks/seqwrite.c create mode 100644 usr/src/sys/tests/benchmarks/syscall.c create mode 100644 usr/src/sys/tests/benchmarks/udgback.c create mode 100644 usr/src/sys/tests/benchmarks/udgdiscard.c create mode 100644 usr/src/sys/tests/benchmarks/udgrand.c create mode 100644 usr/src/sys/tests/benchmarks/udgself.c create mode 100644 usr/src/sys/tests/benchmarks/valloc.c create mode 100644 usr/src/sys/tests/benchmarks/vexecs.c create mode 100644 usr/src/sys/tests/benchmarks/vforks.c diff --git a/usr/src/sys/tests/benchmarks/Makefile b/usr/src/sys/tests/benchmarks/Makefile new file mode 100644 index 0000000000..907f3101d2 --- /dev/null +++ b/usr/src/sys/tests/benchmarks/Makefile @@ -0,0 +1,95 @@ +ALL= syscall csw signocsw \ + seqpage randpage gausspage \ + seqread randbread randread randrewrite \ + randwrite seqrewrite seqwrite \ + forks vforks execs vexecs nulljob bigjob \ + pipeback pipediscard pipeself \ + udgback udgself udgrand udgdiscard \ + countenv +CFLAGS=-O + +all: ${ALL} + +syscall: syscall.c + ${CC} -o syscall ${CFLAGS} syscall.c + +csw: csw.c + ${CC} -o csw ${CFLAGS} csw.c + +gausspage: gausspage.c valloc.o + ${CC} -o gausspage ${CFLAGS} gausspage.c valloc.o -lnm + +pipeback: pipeback.c + ${CC} -o pipeback ${CFLAGS} pipeback.c + +pipediscard: pipediscard.c + ${CC} -o pipediscard ${CFLAGS} pipediscard.c + +pipeself: pipeself.c + ${CC} -o pipeself ${CFLAGS} pipeself.c + +udgback: udgback.c + ${CC} -o udgback ${CFLAGS} udgback.c + +udgdiscard: udgdiscard.c + ${CC} -o udgdiscard ${CFLAGS} udgdiscard.c + +udgself: udgself.c + ${CC} -o udgself ${CFLAGS} udgself.c + +udgrand: udgrand.c random.o + ${CC} -o udgrand ${CFLAGS} udgrand.c random.o + +randbread: randbread.c random.o + ${CC} -o randbread ${CFLAGS} randbread.c random.o + +randpage: randpage.c random.o valloc.o + ${CC} -o randpage ${CFLAGS} randpage.c random.o valloc.o + +randread: randread.c random.o + ${CC} -o randread ${CFLAGS} randread.c random.o + +randrewrite: randrewrite.c random.o + ${CC} -o randrewrite ${CFLAGS} randrewrite.c random.o + +randwrite: randwrite.c random.o + ${CC} -o randwrite ${CFLAGS} randwrite.c random.o + +seqpage: seqpage.c valloc.o + ${CC} -o seqpage ${CFLAGS} seqpage.c valloc.o + +seqread: seqread.c + ${CC} -o seqread ${CFLAGS} seqread.c + +seqrewrite: seqrewrite.c + ${CC} -o seqrewrite ${CFLAGS} seqrewrite.c + +seqwrite: seqwrite.c + ${CC} -o seqwrite ${CFLAGS} seqwrite.c + +signocsw: signocsw.c + ${CC} -o signocsw ${CFLAGS} signocsw.c + +forks: forks.c + ${CC} -o forks ${CFLAGS} forks.c + +vforks: vforks.c + ${CC} -o vforks ${CFLAGS} vforks.c + +execs: execs.c + ${CC} -o execs ${CFLAGS} execs.c + +vexecs: vexecs.c + ${CC} -o vexecs ${CFLAGS} vexecs.c + +nulljob: nulljob.c + ${CC} -o nulljob ${CFLAGS} nulljob.c + +bigjob: bigjob.c + ${CC} -o bigjob ${CFLAGS} bigjob.c + +countenv: countenv.c + ${CC} -o countenv ${CFLAGS} countenv.c + +clean: + rm -f ${ALL} *.o core errs diff --git a/usr/src/sys/tests/benchmarks/bench-4.1/Makefile b/usr/src/sys/tests/benchmarks/bench-4.1/Makefile new file mode 100644 index 0000000000..7517f9dd44 --- /dev/null +++ b/usr/src/sys/tests/benchmarks/bench-4.1/Makefile @@ -0,0 +1,59 @@ +ALL= syscall csw signocsw \ + seqpage randpage gausspage \ + seqread randbread randread randrewrite \ + randwrite seqrewrite seqwrite \ + pipeback pipediscard pipeself +CFLAGS=-O + +all: ${ALL} + +syscall: syscall.c + ${CC} -o syscall ${CFLAGS} syscall.c + +csw: csw.c + ${CC} -o csw ${CFLAGS} csw.c + +gausspage: gausspage.c getpagesize.o + ${CC} -o gausspage ${CFLAGS} gausspage.c getpagesize.o -lnm + +pipeback: pipeback.c + ${CC} -o pipeback ${CFLAGS} pipeback.c + +pipediscard: pipediscard.c + ${CC} -o pipediscard ${CFLAGS} pipediscard.c + +pipeself: pipeself.c + ${CC} -o pipeself ${CFLAGS} pipeself.c + +randbread: randbread.c random.o + ${CC} -o randbread ${CFLAGS} randbread.c random.o + +randpage: randpage.c random.o + ${CC} -o randpage ${CFLAGS} randpage.c random.o + +randread: randread.c random.o + ${CC} -o randread ${CFLAGS} randread.c random.o + +randrewrite: randrewrite.c random.o + ${CC} -o randrewrite ${CFLAGS} randrewrite.c random.o + +randwrite: randwrite.c random.o + ${CC} -o randwrite ${CFLAGS} randwrite.c random.o + +seqpage: seqpage.c getpagesize.o + ${CC} -o seqpage ${CFLAGS} seqpage.c getpagesize.o + +seqread: seqread.c + ${CC} -o seqread ${CFLAGS} seqread.c + +seqrewrite: seqrewrite.c + ${CC} -o seqrewrite ${CFLAGS} seqrewrite.c + +seqwrite: seqwrite.c + ${CC} -o seqwrite ${CFLAGS} seqwrite.c + +signocsw: signocsw.c + ${CC} -o signocsw ${CFLAGS} signocsw.c + +clean: + rm -f ${ALL} *.o core errs diff --git a/usr/src/sys/tests/benchmarks/bench-4.1/csw.c b/usr/src/sys/tests/benchmarks/bench-4.1/csw.c new file mode 100644 index 0000000000..973c1f5298 --- /dev/null +++ b/usr/src/sys/tests/benchmarks/bench-4.1/csw.c @@ -0,0 +1,47 @@ +/* + * Context switching benchmark. + * + * Force system to context switch 2*nsigs + * times by forking and exchanging signals. + * To calculate system overhead for a context + * switch, the signocsw program must be run + * with nsigs. Overhead is then estimated by + * t1 = time csw + * t2 = time signocsw + * overhead = t1 - 2 * t2; + */ +#include + +int sigsub(); +int otherpid; +int nsigs; + +main(argc, argv) + char *argv[]; +{ + int pid; + + if (argc < 2) { + printf("usage: %s nsignals\n", argv[0]); + exit(1); + } + nsigs = atoi(argv[1]); + signal(SIGALRM, sigsub); + otherpid = getpid(); + pid = fork(); + if (pid != 0) { + otherpid = pid; + kill(otherpid, SIGALRM); + } + for (;;) + pause(); +} + +sigsub() +{ + + signal(SIGALRM, sigsub); + kill(otherpid, SIGALRM); + if (--nsigs <= 0) + exit(0); +} diff --git a/usr/src/sys/tests/benchmarks/bench-4.1/gausspage.c b/usr/src/sys/tests/benchmarks/bench-4.1/gausspage.c new file mode 100644 index 0000000000..cad1cf570a --- /dev/null +++ b/usr/src/sys/tests/benchmarks/bench-4.1/gausspage.c @@ -0,0 +1,100 @@ +/* + * Random page access with + * a gaussian distribution. + * + * Allocate a large (zero fill on demand) address + * space and fault the pages in a random gaussian + * order. + */ + +float sqrt(), log(), rnd(), cos(), gauss(); +char *valloc(); +int rand(); + +main(argc, argv) + char *argv[]; +{ + register int pn, i, niter, delta; + register char *pages; + float sd = 10.0; + int npages = 4096, pagesize, debug = 0; + char *name; + + name = argv[0]; + argc--, argv++; +again: + if (argc < 1) { +usage: + printf( +"usage: %s [ -d ] [ -p #pages ] [ -s standard-deviation ] iterations\n", name); + exit(1); + } + if (strcmp(*argv, "-s") == 0) { + argc--, argv++; + if (argc < 1) + goto usage; + sscanf(*argv, "%f", &sd); + if (sd <= 0) { + printf("%s: Bad standard deviation.\n", *argv); + exit(2); + } + argc--, argv++; + goto again; + } + if (strcmp(*argv, "-p") == 0) { + argc--, argv++; + if (argc < 1) + goto usage; + npages = atoi(*argv); + if (npages <= 0) { + printf("%s: Bad page count.\n", *argv); + exit(2); + } + argc--, argv++; + goto again; + } + if (strcmp(*argv, "-d") == 0) { + argc--, argv++; + debug++; + goto again; + } + niter = atoi(*argv); + pagesize = getpagesize(); + pages = valloc(npages*pagesize); + if (pages == (char *)0) { + printf("Can't allocate %d pages (%2.1f megabytes).\n", + npages, (npages*pagesize) / (1024. * 1024.)); + exit(3); + } + pn = 0; + for (i = 0; i < niter; i++) { + delta = gauss(sd, 0.0); + while (pn + delta < 0 || pn + delta > npages) + delta = gauss(sd, 0.0); + pn += delta; + if (debug) + printf("touch page %d\n", pn); + else + pages[pn * pagesize] = 1; + } +} + +float +gauss(sd, mean) + float sd, mean; +{ + register float qa, qb; + + qa = sqrt(log(rnd()) * -2.0); + qb = 3.14159 * rnd(); + return (qa * cos(qb) * sd + mean); +} + +float +rnd() +{ + static int seed = 1; + static int biggest = 0x7fffffff; + + return ((float)rand(seed) / (float)biggest); +} diff --git a/usr/src/sys/tests/benchmarks/bench-4.1/getpagesize.c b/usr/src/sys/tests/benchmarks/bench-4.1/getpagesize.c new file mode 100644 index 0000000000..488b639862 --- /dev/null +++ b/usr/src/sys/tests/benchmarks/bench-4.1/getpagesize.c @@ -0,0 +1,5 @@ +getpagesize() +{ + + return (1024); +} diff --git a/usr/src/sys/tests/benchmarks/bench-4.1/pipeback.c b/usr/src/sys/tests/benchmarks/bench-4.1/pipeback.c new file mode 100644 index 0000000000..b76e0401a8 --- /dev/null +++ b/usr/src/sys/tests/benchmarks/bench-4.1/pipeback.c @@ -0,0 +1,46 @@ +/* + * IPC benchmark, + * read and reply using pipes. + * + * Process forks and exchanges messages + * over a pipe in a request-response fashion. + */ + +main(argc, argv) + char *argv[]; +{ + char buf[512]; + int fd[2], fd2[2], msgsize; + register int i, iter; + + if (argc < 3) { + printf("usage: %s iterations message-size\n", argv[0]); + exit(1); + } + argc--, argv++; + iter = atoi(*argv); + argc--, argv++; + msgsize = atoi(*argv); + if (msgsize > sizeof (buf) || msgsize <= 0) { + printf("%s: Bad message size.\n", *argv); + exit(2); + } + if (pipe(fd) < 0) { + perror("pipe"); + exit(3); + } + if (pipe(fd2) < 0) { + perror("pipe"); + exit(3); + } + if (fork() == 0) + for (i = 0; i < iter; i++) { + read(fd[0], buf, msgsize); + write(fd2[1], buf, msgsize); + } + else + for (i = 0; i < iter; i++) { + write(fd[1], buf, msgsize); + read(fd2[0], buf, msgsize); + } +} diff --git a/usr/src/sys/tests/benchmarks/bench-4.1/pipediscard.c b/usr/src/sys/tests/benchmarks/bench-4.1/pipediscard.c new file mode 100644 index 0000000000..cab8df51b2 --- /dev/null +++ b/usr/src/sys/tests/benchmarks/bench-4.1/pipediscard.c @@ -0,0 +1,35 @@ +/* + * IPC benchmarkl, + * write and discard using pipes. + */ + +main(argc, argv) + char *argv[]; +{ + char buf[512]; + int fd[2], msgsize; + register int i, iter; + + if (argc < 3) { + printf("usage: %s iterations message-size\n", argv[0]); + exit(1); + } + argc--, argv++; + iter = atoi(*argv); + argc--, argv++; + msgsize = atoi(*argv); + if (msgsize > sizeof (buf) || msgsize <= 0) { + printf("%s: Bad message size.\n", *argv); + exit(2); + } + if (pipe(fd) < 0) { + perror("pipe"); + exit(3); + } + if (fork() == 0) + for (i = 0; i < iter; i++) + read(fd[0], buf, msgsize); + else + for (i = 0; i < iter; i++) + write(fd[1], buf, msgsize); +} diff --git a/usr/src/sys/tests/benchmarks/bench-4.1/pipeself.c b/usr/src/sys/tests/benchmarks/bench-4.1/pipeself.c new file mode 100644 index 0000000000..114b1d0189 --- /dev/null +++ b/usr/src/sys/tests/benchmarks/bench-4.1/pipeself.c @@ -0,0 +1,33 @@ +/* + * IPC benchmark, + * write to self using pipes. + */ + +main(argc, argv) + char *argv[]; +{ + char buf[512]; + int fd[2], msgsize; + register int i, iter; + + if (argc < 3) { + printf("usage: %s iterations message-size\n", argv[0]); + exit(1); + } + argc--, argv++; + iter = atoi(*argv); + argc--, argv++; + msgsize = atoi(*argv); + if (msgsize > sizeof (buf) || msgsize <= 0) { + printf("%s: Bad message size.\n", *argv); + exit(2); + } + if (pipe(fd) < 0) { + perror("pipe"); + exit(3); + } + for (i = 0; i < iter; i++) { + write(fd[1], buf, msgsize); + read(fd[0], buf, msgsize); + } +} diff --git a/usr/src/sys/tests/benchmarks/bench-4.1/randbread.c b/usr/src/sys/tests/benchmarks/bench-4.1/randbread.c new file mode 100644 index 0000000000..f1d86234c8 --- /dev/null +++ b/usr/src/sys/tests/benchmarks/bench-4.1/randbread.c @@ -0,0 +1,44 @@ +/* + * Random I/O benchmark. + * + * Process reads blocks from a + * file in a random order. + */ +#include +#include +#include + +char *malloc(); + +main(argc, argv) + char *argv[]; +{ + char *buf; + int fd, bn, maxblocks; + struct stat sb; + register int i, niter; + + if (argc < 3) { + printf("usage: %s file #reads\n", argv[0]); + exit(1); + } + fd = open(argv[1], 0); + if (fd < 0) { + perror(argv[1]); + exit(2); + } + buf = malloc(1024); + if (buf == (char *)0) { + printf("Couldn't allocate i/o buffer.\n"); + exit(3); + } + fstat(fd, &sb); + niter = atoi(argv[2]); + printf("%d random block reads, file size %d kb (bsize %d)\n", + niter, sb.st_size / 1024, 1024); + for (i = 0; i < niter; i++) { + bn = (random() % sb.st_size) / sb.st_size; + lseek(fd, bn * 1024, 0); + read(fd, buf, 1024); + } +} diff --git a/usr/src/sys/tests/benchmarks/bench-4.1/randpage.c b/usr/src/sys/tests/benchmarks/bench-4.1/randpage.c new file mode 100644 index 0000000000..8884421f5d --- /dev/null +++ b/usr/src/sys/tests/benchmarks/bench-4.1/randpage.c @@ -0,0 +1,62 @@ +/* + * Random page access benchmark. + */ +#include + +char *valloc(); +int rand(); + +main(argc, argv) + char *argv[]; +{ + register int npages = 4096, pagesize, pn, i, niter; + int vflag = 0, debug = 0; + char *pages, *name; + + name = argv[0]; + argc--, argv++; +again: + if (argc < 1) { +usage: + printf("usage: %s [ -d ] [ -v ] [ -p #pages ] niter\n", name); + exit(1); + } + if (strcmp(*argv, "-p") == 0) { + argc--, argv++; + if (argc < 1) + goto usage; + npages = atoi(*argv); + if (npages <= 0) { + printf("%s: Bad page count.\n", *argv); + exit(2); + } + argc--, argv++; + goto again; + } + if (strcmp(*argv, "-v") == 0) { + argc--, argv++; + vflag++; + goto again; + } + if (strcmp(*argv, "-d") == 0) { + argc--, argv++; + debug++; + goto again; + } + niter = atoi(*argv); + pagesize = getpagesize(); + pages = valloc(npages * pagesize); + if (pages == (char *)0) { + printf("Can't allocate %d pages (%2.1f megabytes).\n", + npages, (npages * pagesize) / (1024. * 1024.)); + exit(3); + } + if (vflag) + vadvise(VA_ANOM); + for (i = 0; i < niter; i++) { + pn = random() % npages; + if (debug) + printf("touch page %d\n", pn); + pages[pagesize * pn] = 1; + } +} diff --git a/usr/src/sys/tests/benchmarks/bench-4.1/randread.c b/usr/src/sys/tests/benchmarks/bench-4.1/randread.c new file mode 100644 index 0000000000..21494f1b1d --- /dev/null +++ b/usr/src/sys/tests/benchmarks/bench-4.1/randread.c @@ -0,0 +1,49 @@ +/* + * Random I/O benchmark. + * + * Process reads blocks from a + * file in a random order. + */ +#include +#include +#include + +char *malloc(); + +main(argc, argv) + char *argv[]; +{ + char *buf; + int size, fd, bn, maxblocks; + struct stat sb; + register int i, niter; + + if (argc < 3) { + printf("usage: %s file read-size #reads\n", argv[0]); + exit(1); + } + fd = open(argv[1], 0); + if (fd < 0) { + perror(argv[1]); + exit(2); + } + fstat(fd, &sb); + buf = malloc(1024); + if (buf == (char *)0) { + printf("Couldn't allocate i/o buffer.\n"); + exit(3); + } + size = atoi(argv[2]); + if (size > 1024) { + printf("Reads must be no larger than block size (%d)\n", + 1024); + exit(4); + } + niter = atoi(argv[3]); + printf("%d random %d byte reads, file size %d kb (bsize %d)\n", + niter, size, sb.st_size / 1024, 1024); + for (i = 0; i < niter; i++) { + lseek(fd, random() % sb.st_size, 0); + read(fd, buf, size); + } +} diff --git a/usr/src/sys/tests/benchmarks/bench-4.1/randrewrite.c b/usr/src/sys/tests/benchmarks/bench-4.1/randrewrite.c new file mode 100644 index 0000000000..ddc9a814de --- /dev/null +++ b/usr/src/sys/tests/benchmarks/bench-4.1/randrewrite.c @@ -0,0 +1,48 @@ +/* + * Random I/O benchmark. + * + * Process writes blocks to a file in a + * random order. Writes are constrained + * to overwrite existing blocks. This + * test should be run after the seqio test + * so that a file is constructed. + */ +#include +#include +#include + +char *malloc(); + +main(argc, argv) + char *argv[]; +{ + char *buf; + int fd, bn, nblocks; + struct stat sb; + register int i, niter; + + if (argc < 3) { + printf("usage: %s file #writes\n", argv[0]); + exit(1); + } + fd = open(argv[1], 1); + if (fd < 0) { + perror(argv[1]); + exit(2); + } + fstat(fd, &sb); + buf = malloc(1024); + if (buf == (char *)0) { + printf("Couldn't allocate i/o buffer.\n"); + exit(3); + } + nblocks = sb.st_size / 1024; + niter = atoi(argv[2]); + printf("%d random writes in %d block file (block size %d)\n", + niter, nblocks, 1024); + for (i = 0; i < niter; i++) { + bn = random() % nblocks; + lseek(fd, bn * 1024, 0); + write(fd, buf, 1024); + } +} diff --git a/usr/src/sys/tests/benchmarks/bench-4.1/randwrite.c b/usr/src/sys/tests/benchmarks/bench-4.1/randwrite.c new file mode 100644 index 0000000000..8841d0c0d9 --- /dev/null +++ b/usr/src/sys/tests/benchmarks/bench-4.1/randwrite.c @@ -0,0 +1,45 @@ +/* + * Random I/O benchmark. + * + * Process writes blocks to a + * file in a random order. + */ +#include +#include +#include + +char *malloc(); + +main(argc, argv) + char *argv[]; +{ + char *buf; + int fd, bn, maxblocks; + struct stat sb; + register int i, niter; + + if (argc < 4) { + printf("usage: %s file max-file-size #writes\n", argv[0]); + exit(1); + } + fd = creat(argv[1], 0644); + if (fd < 0) { + perror(argv[1]); + exit(2); + } + buf = malloc(1024); + if (buf == (char *)0) { + printf("Couldn't allocate i/o buffer.\n"); + exit(3); + } + /* file size is in megabytes */ + fstat(fd, &sb); + maxblocks = atoi(argv[2]) * ((1024 * 1024) / 1024); + niter = atoi(argv[3]); + printf("%d random writes (block size %d)\n", niter, 1024); + for (i = 0; i < niter; i++) { + bn = random() % maxblocks; + lseek(fd, bn * 1024, 0); + write(fd, buf, 1024); + } +} diff --git a/usr/src/sys/tests/benchmarks/bench-4.1/run b/usr/src/sys/tests/benchmarks/bench-4.1/run new file mode 100644 index 0000000000..6016a56fa0 --- /dev/null +++ b/usr/src/sys/tests/benchmarks/bench-4.1/run @@ -0,0 +1,44 @@ +#! /bin/csh -fx +# Script to run benchmark programs. +# +date +time syscall 100000 +onintr cleanup +time seqwrite test 8 # 8 megabyte file +repeat 3 time seqbread test +repeat 3 time seqread test +repeat 3 time randread test 30000 +time seqrewrite test 8 +time randrewrite test 30000 +rm test +time randwrite test 8 30000 # 8 megabyte file +rm test; onintr +time seqpage -p 3750 10 +time seqpage -v -p 3750 10 +time randpage -p 3901 30000 +time randpage -v -p 3901 30000 +time gausspage -p 3901 -s 1 30000 +time gausspage -p 3901 -s 10 30000 +time gausspage -p 3901 -s 30 30000 +time gausspage -p 3901 -s 40 30000 +time gausspage -p 3901 -s 50 30000 +time gausspage -p 3901 -s 60 30000 +time gausspage -p 3901 -s 80 30000 +time gausspage -p 3901 -s 10000 30000 +time csw 10000 +time signocsw 10000 +time pipeself 10000 512 +time pipeself 10000 4 +#time udgcself 10000 512 +#time udgself 10000 4 +time pipediscard 10000 512 +time pipediscard 10000 4 +#time udgdiscard 10000 512 +#time udgdiscard 10000 4 +time pipeback 10000 512 +time pipeback 10000 4 +#time udgback 10000 512 +#time udgback 10000 4 +exit +cleanup: +rm -f test diff --git a/usr/src/sys/tests/benchmarks/bench-4.1/seqpage.c b/usr/src/sys/tests/benchmarks/bench-4.1/seqpage.c new file mode 100644 index 0000000000..542a6a4cad --- /dev/null +++ b/usr/src/sys/tests/benchmarks/bench-4.1/seqpage.c @@ -0,0 +1,55 @@ +/* + * Sequential page access benchmark. + */ +#include + +char *valloc(); + +main(argc, argv) + char *argv[]; +{ + register i, niter; + register char *pf, *lastpage; + int npages = 4096, pagesize, vflag = 0; + char *pages, *name; + + name = argv[0]; + argc--, argv++; +again: + if (argc < 1) { +usage: + printf("usage: %s [ -v ] [ -p #pages ] niter\n", name); + exit(1); + } + if (strcmp(*argv, "-p") == 0) { + argc--, argv++; + if (argc < 1) + goto usage; + npages = atoi(*argv); + if (npages <= 0) { + printf("%s: Bad page count.\n", *argv); + exit(2); + } + argc--, argv++; + goto again; + } + if (strcmp(*argv, "-v") == 0) { + argc--, argv++; + vflag++; + goto again; + } + niter = atoi(*argv); + pagesize = getpagesize(); + pages = valloc(npages * pagesize); + if (pages == (char *)0) { + printf("Can't allocate %d pages (%2.1f megabytes).\n", + npages, (npages * pagesize) / (1024. * 1024.)); + exit(3); + } + lastpage = pages + (npages * pagesize); + if (vflag) + vadvise(VA_SEQL); + for (i = 0; i < niter; i++) + for (pf = pages; pf < lastpage; pf += pagesize) + *pf = 1; +} diff --git a/usr/src/sys/tests/benchmarks/bench-4.1/seqread.c b/usr/src/sys/tests/benchmarks/bench-4.1/seqread.c new file mode 100644 index 0000000000..9289f4638f --- /dev/null +++ b/usr/src/sys/tests/benchmarks/bench-4.1/seqread.c @@ -0,0 +1,32 @@ +/* + * Sequential I/O benchmark. + */ + +#include +#include +#include + +char *malloc(); + +main(argc, argv) + char *argv[]; +{ + register int i, max; + char *buf; + struct stat sb; + int fd; + + if (argc < 2) { + printf("usage: %s file\n", argv[0]); + exit(1); + } + fd = open(argv[1], 0); + if (fd < 0) { + perror(argv[1]); + exit(1); + } + fstat(fd, &sb); + buf = malloc(1024); + while (read(fd, buf, 1024) == 1024) + ; +} diff --git a/usr/src/sys/tests/benchmarks/bench-4.1/seqrewrite.c b/usr/src/sys/tests/benchmarks/bench-4.1/seqrewrite.c new file mode 100644 index 0000000000..86d91596be --- /dev/null +++ b/usr/src/sys/tests/benchmarks/bench-4.1/seqrewrite.c @@ -0,0 +1,35 @@ +/* + * Sequential I/O benchmark. + * + * Overwrites existing data in a file. + */ +#include +#include +#include + +char *malloc(); + +main(argc, argv) + char *argv[]; +{ + register int i, max; + char *buf; + struct stat sb; + int fd; + + if (argc < 2) { + printf("usage: %s file\n", argv[0]); + exit(1); + } + fd = open(argv[1], 1); + if (fd < 0) { + perror(argv[1]); + exit(1); + } + fstat(fd, &sb); + buf = malloc(1024); + max = sb.st_size / 1024; + printf("%d writes of %d kilobytes\n", max, 1024 / 1024); + for (i = 0; i < max; i++) + write(fd, buf, 1024); +} diff --git a/usr/src/sys/tests/benchmarks/bench-4.1/seqwrite.c b/usr/src/sys/tests/benchmarks/bench-4.1/seqwrite.c new file mode 100644 index 0000000000..fc743ae900 --- /dev/null +++ b/usr/src/sys/tests/benchmarks/bench-4.1/seqwrite.c @@ -0,0 +1,34 @@ +/* + * Sequential I/O benchmark. + */ + +#include +#include +#include + +char *malloc(); + +main(argc, argv) + char *argv[]; +{ + register int i, max; + char *buf; + struct stat sb; + int fd; + + if (argc < 3) { + printf("usage: %s file megabytes\n", argv[0]); + exit(1); + } + fd = creat(argv[1], 0644); + if (fd < 0) { + perror(argv[1]); + exit(1); + } + fstat(fd, &sb); + buf = malloc(1024); + max = (atoi(argv[2]) * 1024 * 1024) / 1024; + printf("%d writes of %d kilobytes\n", max, 1024 / 1024); + for (i = 0; i < max; i++) + write(fd, buf, 1024); +} diff --git a/usr/src/sys/tests/benchmarks/bench-4.1/signocsw.c b/usr/src/sys/tests/benchmarks/bench-4.1/signocsw.c new file mode 100644 index 0000000000..98a507e9c0 --- /dev/null +++ b/usr/src/sys/tests/benchmarks/bench-4.1/signocsw.c @@ -0,0 +1,31 @@ +/* + * Signal without context switch benchmark. + */ +#include + +int pid; +int nsigs; +int sigsub(); + +main(argc, argv) + char *argv[]; +{ + + if (argc < 2) { + printf("usage: %s nsignals\n", argv[0]); + exit(1); + } + nsigs = atoi(argv[1]); + signal(SIGALRM, sigsub); + pid = getpid(); + kill(pid, SIGALRM); +} + +sigsub() +{ + static int i = 0; + + signal(SIGALRM, sigsub); + if (i++ < nsigs) + kill(pid, SIGALRM); +} diff --git a/usr/src/sys/tests/benchmarks/bench-4.1/syscall.c b/usr/src/sys/tests/benchmarks/bench-4.1/syscall.c new file mode 100644 index 0000000000..c50103eced --- /dev/null +++ b/usr/src/sys/tests/benchmarks/bench-4.1/syscall.c @@ -0,0 +1,16 @@ +/* + * System call overhead benchmark. + */ +main(argc, argv) + char *argv[]; +{ + register int ncalls; + + if (argc < 2) { + printf("usage: %s #syscalls\n", argv[0]); + exit(1); + } + ncalls = atoi(argv[1]); + while (ncalls-- > 0) + (void) getpid(); +} diff --git a/usr/src/sys/tests/benchmarks/bigjob.c b/usr/src/sys/tests/benchmarks/bigjob.c new file mode 100644 index 0000000000..eb8e4bb8eb --- /dev/null +++ b/usr/src/sys/tests/benchmarks/bigjob.c @@ -0,0 +1,12 @@ +/* + * Benchmark "null big job" program. + */ +/* 250 here is intended to approximate vi's text+data size */ +char space[1024 * 250] = "force into data segment"; + +main(argc, argv) + char *argv[]; +{ + + exit(0); +} diff --git a/usr/src/sys/tests/benchmarks/countenv.c b/usr/src/sys/tests/benchmarks/countenv.c new file mode 100644 index 0000000000..114a81fd12 --- /dev/null +++ b/usr/src/sys/tests/benchmarks/countenv.c @@ -0,0 +1,18 @@ +/* + * Benchmark utility to sum up + * the total number of bytes passed + * in the environment on an exec. + */ + +main(argc, argv, envp) + char *argv[], *envp[]; +{ + register char **p; + register int n; + + n = 0; + for (p = envp; *p && *p != (char *)-1; p++) + n += strlen(*p); + printf("%d bytes\n", n); + exit(0); +} diff --git a/usr/src/sys/tests/benchmarks/execs.c b/usr/src/sys/tests/benchmarks/execs.c new file mode 100644 index 0000000000..6d03974244 --- /dev/null +++ b/usr/src/sys/tests/benchmarks/execs.c @@ -0,0 +1,54 @@ +/* + * Benchmark program to calculate exec + * overhead (approximately). Process + * forks and execs "null" test program. + * The time to run the fork program should + * then be deducted from this one to + * estimate the overhead for the exec. + */ + +main(argc, argv) + char *argv[]; +{ + register int nexecs, i; + char *cp, *sbrk(); + int pid, child, status, brksize; + + if (argc < 3) { + printf("usage: %s number-of-execs sbrk-size job-name\n", + argv[0]); + exit(1); + } + nexecs = atoi(argv[1]); + if (nexecs < 0) { + printf("%s: bad number of execs\n", argv[1]); + exit(2); + } + brksize = atoi(argv[2]); + if (brksize < 0) { + printf("%s: bad size to sbrk\n", argv[2]); + exit(3); + } + cp = sbrk(brksize); + if ((int)cp == -1) { + perror("sbrk"); + exit(4); + } + for (i = 0; i < brksize; i += 1024) + cp[i] = i; + while (nexecs-- > 0) { + child = fork(); + if (child == -1) { + perror("fork"); + exit(-1); + } + if (child == 0) { + execv(argv[3], argv); + perror("execv"); + _exit(-1); + } + while ((pid = wait(&status)) != -1 && pid != child) + ; + } + exit(0); +} diff --git a/usr/src/sys/tests/benchmarks/forks.c b/usr/src/sys/tests/benchmarks/forks.c new file mode 100644 index 0000000000..28803ee4f9 --- /dev/null +++ b/usr/src/sys/tests/benchmarks/forks.c @@ -0,0 +1,49 @@ +/* + * Benchmark program to calculate fork+wait + * overhead (approximately). Process + * forks and exits while parent waits. + * The time to run this program is used + * in calculating exec overhead. + */ + +main(argc, argv) + char *argv[]; +{ + register int nforks, i; + char *cp; + int pid, child, status, brksize; + + if (argc < 2) { + printf("usage: %s number-of-forks sbrk-size\n", argv[0]); + exit(1); + } + nforks = atoi(argv[1]); + if (nforks < 0) { + printf("%s: bad number of forks\n", argv[1]); + exit(2); + } + brksize = atoi(argv[2]); + if (brksize < 0) { + printf("%s: bad size to sbrk\n", argv[2]); + exit(3); + } + cp = (char *)sbrk(brksize); + if ((int)cp == -1) { + perror("sbrk"); + exit(4); + } + for (i = 0; i < brksize; i += 1024) + cp[i] = i; + while (nforks-- > 0) { + child = fork(); + if (child == -1) { + perror("fork"); + exit(-1); + } + if (child == 0) + _exit(-1); + while ((pid = wait(&status)) != -1 && pid != child) + ; + } + exit(0); +} diff --git a/usr/src/sys/tests/benchmarks/gausspage.c b/usr/src/sys/tests/benchmarks/gausspage.c new file mode 100644 index 0000000000..2ccda426f9 --- /dev/null +++ b/usr/src/sys/tests/benchmarks/gausspage.c @@ -0,0 +1,104 @@ +/* + * Random page access with + * a gaussian distribution. + * + * Allocate a large (zero fill on demand) address + * space and fault the pages in a random gaussian + * order. + */ +#include + +float rnd(), gauss(); +char *valloc(); +int rand(); + +main(argc, argv) + char *argv[]; +{ + register int pn, i, niter, delta; + register char *pages; + float sd = 10.0; + int npages = 4096, pagesize, debug = 0; + char *name; + + name = argv[0]; + argc--, argv++; +again: + if (argc < 1) { +usage: + printf( +"usage: %s [ -d ] [ -k #Kb ] [ -s standard-deviation ] iterations\n", name); + exit(1); + } + if (strcmp(*argv, "-s") == 0) { + argc--, argv++; + if (argc < 1) + goto usage; + sscanf(*argv, "%f", &sd); + if (sd <= 0) { + printf("%s: Bad standard deviation.\n", *argv); + exit(2); + } + argc--, argv++; + goto again; + } + if (strcmp(*argv, "-k") == 0) { + argc--, argv++; + if (argc < 1) + goto usage; + npages = atoi(*argv); + if (npages <= 0) { + printf("%s: Bad virtual memory size.\n", *argv); + exit(2); + } + argc--, argv++; + goto again; + } + if (strcmp(*argv, "-d") == 0) { + argc--, argv++; + debug++; + goto again; + } + niter = atoi(*argv); + pagesize = getpagesize(); + npages /= pagesize / 1024; + pages = valloc(npages, pagesize); + if (pages == (char *)0) { + printf("Can't allocate %d pages (%2.1f megabytes).\n", + npages, (npages*pagesize) / (1024. * 1024.)); + exit(3); + } + if (pagesize != 1024) + printf("Pagesize %dKb\n", pagesize / 1024); + pn = 0; + for (i = 0; i < niter; i++) { + delta = gauss(sd, 0.0); + while (pn + delta < 0 || pn + delta > npages) + delta = gauss(sd, 0.0); + pn += delta; + if (debug) + printf("touch page %d\n", pn); + else + pages[pn * pagesize] = 1; + } +} + +float +gauss(sd, mean) + float sd, mean; +{ + register float qa, qb; + + qa = sqrt(log(rnd()) * -2.0); + qb = 3.14159 * rnd(); + return (qa * cos(qb) * sd + mean); +} + +float +rnd() +{ + static int seed = 1; + static int biggest = 0x7fffffff; + + return ((float)rand(seed) / (float)biggest); +} diff --git a/usr/src/sys/tests/benchmarks/inet/inetdg.c b/usr/src/sys/tests/benchmarks/inet/inetdg.c new file mode 100644 index 0000000000..1559fc2670 --- /dev/null +++ b/usr/src/sys/tests/benchmarks/inet/inetdg.c @@ -0,0 +1,142 @@ +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +struct sockaddr_in sin; +char myname[256]; + +#define MAXMSGS (5000 - 1) +#define MAXMSGLEN BUFSIZ + +char *malloc(); + +main(argc, argv) + char *argv[]; +{ + int s, sinlen; + struct hostent *hp; + register char *buf; + register int i, kb, msgs = 0; + int msglen = 0, ms, lens[MAXMSGS]; + struct timeval t1, t2; + struct rusage r1, r2; + + if (argc < 2) { + printf("usage: %s port [ #msgs ] [ max-msg-length ]\n", + argv[0]); + exit(1); + } + s = socket(AF_INET, SOCK_DGRAM, 0); + if (s < 0) { + perror("socket"); + exit(1); + } + sinlen = sizeof (myname); + gethostname(myname, &sinlen); + hp = gethostbyname(myname); + if (hp == 0) { + printf("%s: host unknown\n", myname); + exit(1); + } + sin.sin_family = AF_INET; + bcopy(hp->h_addr, &sin.sin_addr, hp->h_length); + if (bind(s, &sin, sizeof (sin)) < 0) { + perror("inetdg: bind"); + exit(1); + } + sin.sin_port = htons(atoi(argv[1])); + if (argc > 2) + msgs = atoi(argv[2]); + if (msgs <= 0 || msgs > MAXMSGS) + msgs = MAXMSGS; + if (argc > 3) + msglen = atoi(argv[3]); + if (msglen <= 0 || msglen >= MAXMSGLEN) + msglen = MAXMSGLEN; + buf = malloc(msglen); + if (buf == 0) { + printf("couldn't allocate data buffer\n"); + exit(1); + } + for (i = 0; i < msgs; i++) + lens[i] = random() % msglen; + for (i = 0; i < msglen; i++) + buf[i] = random() & 0xff; + printf("%d messages, max message length %d bytes\n", + msgs + 1, msglen); + (void) sendto(s, "begin", 5, 0, &sin, sizeof (sin)); + kb = 0; + getrusage(RUSAGE_SELF, &r1); + gettimeofday(&t1, (struct timezone *)0); + for (i = 0; i < msgs; i++) { + if (sendto(s, buf, lens[i], 0, &sin, sizeof (sin)) < 0) + perror("inetdg: sendto"); + kb += lens[i]; + } + (void) sendto(s, "end", 3, 0, &sin, sizeof (sin)); + gettimeofday(&t2, (struct timezone *)0); + getrusage(RUSAGE_SELF, &r2); + msgs++, kb += 3; + timevalsub(&t2, &t1); + ms = t2.tv_usec / 1000; + printf("%d msgs (%d bytes) in %d.%d secs", msgs, + kb, t2.tv_sec, ms / 100); + printf(", %d bytes/msg, %6.2f kb/s, %4.1f ms/msg\n", + kb / msgs, (8. * kb) / (t2.tv_sec * 1024.), + (1000. * t2.tv_sec + ms) / msgs); + timevalsub(&r2.ru_stime, &r1.ru_stime); + timevalsub(&r2.ru_utime, &r1.ru_utime); + r2.ru_nvcsw -= r1.ru_nvcsw; + r2.ru_nivcsw -= r1.ru_nivcsw; + printf("System %d.%d, user %d.%d, %d vcsw, %d ivcsw\n", + r2.ru_stime.tv_sec, r2.ru_stime.tv_usec / 100000, + r2.ru_utime.tv_sec, r2.ru_utime.tv_usec / 100000, + r2.ru_nvcsw, r2.ru_nivcsw); + pause(); +} + +/* + * Add and subtract routines for timevals. + * N.B.: subtract routine doesn't deal with + * results which are before the beginning, + * it just gets very confused in this case. + * Caveat emptor. + */ +timevaladd(t1, t2) + struct timeval *t1, *t2; +{ + + t1->tv_sec += t2->tv_sec; + t1->tv_usec += t2->tv_usec; + timevalfix(t1); +} + +timevalsub(t1, t2) + struct timeval *t1, *t2; +{ + + t1->tv_sec -= t2->tv_sec; + t1->tv_usec -= t2->tv_usec; + timevalfix(t1); +} + +timevalfix(t1) + struct timeval *t1; +{ + + if (t1->tv_usec < 0) { + t1->tv_sec--; + t1->tv_usec += 1000000; + } + if (t1->tv_usec >= 1000000) { + t1->tv_sec++; + t1->tv_usec -= 1000000; + } +} diff --git a/usr/src/sys/tests/benchmarks/inet/inetdgs.c b/usr/src/sys/tests/benchmarks/inet/inetdgs.c new file mode 100644 index 0000000000..94acf922b2 --- /dev/null +++ b/usr/src/sys/tests/benchmarks/inet/inetdgs.c @@ -0,0 +1,128 @@ +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +struct sockaddr_in sin; +jmp_buf j; +int catchsig(); + +main(argc, argv) + char *argv[]; +{ + int s, n; + char buf[2 * BUFSIZ]; + struct rusage r1, r2; + + if (argc < 2) { + printf("usage: %s port\n", argv[0]); + exit(1); + } + s = socket(AF_INET, SOCK_DGRAM, 0); + if (s < 0) { + perror("inetdgs: socket"); + exit(1); + } + sin.sin_family = AF_INET; + sin.sin_port = htons(atoi(argv[1])); + if (bind(s, &sin, sizeof (sin)) < 0) { + perror("inetdgs: bind"); + exit(1); + } + for (;;) { + int count, ms, kb, fromlen; + struct timeval t1, t2; + struct sockaddr_in from; + extern int errno; + + for (;;) { + fromlen = sizeof (from); + n = recvfrom(s, buf, sizeof (buf), 0, &from, &fromlen); + if (n < 0) { + if (errno != EINTR) + perror("inetdgs: recvfrom"); + continue; + } + if (strncmp(buf, "begin", 5) == 0) + break; + } + count = kb = 0; + getrusage(RUSAGE_SELF, &r1); + gettimeofday(&t1, (struct timezone *)0); + for (;;) { + fromlen = sizeof (from); + n = recvfrom(s, buf, sizeof (buf), 0, &from, &fromlen); + if (n < 0) { + if (errno != EINTR) + perror("inetdgs: recvfrom"); + continue; + } + count++, kb += n; + if (strncmp(buf, "end", 3) == 0) + break; + } + gettimeofday(&t2, (struct timezone *)0); + getrusage(RUSAGE_SELF, &r2); + sleep(2); + timevalsub(&t2, &t1); + ms = t2.tv_usec / 1000; + printf("%d msgs (%d bytes) in %d.%d secs", count, + kb, t2.tv_sec, ms / 100); + printf(", %d bytes/msg, %6.2f kb/s, %4.1f ms/msg\n", + kb / count, (8. * kb) / (t2.tv_sec * 1024.), + (1000. * t2.tv_sec + ms) / count); + timevalsub(&r2.ru_stime, &r1.ru_stime); + timevalsub(&r2.ru_utime, &r1.ru_utime); + r2.ru_nvcsw -= r1.ru_nvcsw; + r2.ru_nivcsw -= r1.ru_nivcsw; + printf("System %d.%d, user %d.%d, %d vcsw, %d ivcsw\n", + r2.ru_stime.tv_sec, r2.ru_stime.tv_usec / 100000, + r2.ru_utime.tv_sec, r2.ru_utime.tv_usec / 100000, + r2.ru_nvcsw, r2.ru_nivcsw); + } +} + +/* + * Add and subtract routines for timevals. + * N.B.: subtract routine doesn't deal with + * results which are before the beginning, + * it just gets very confused in this case. + * Caveat emptor. + */ +timevaladd(t1, t2) + struct timeval *t1, *t2; +{ + + t1->tv_sec += t2->tv_sec; + t1->tv_usec += t2->tv_usec; + timevalfix(t1); +} + +timevalsub(t1, t2) + struct timeval *t1, *t2; +{ + + t1->tv_sec -= t2->tv_sec; + t1->tv_usec -= t2->tv_usec; + timevalfix(t1); +} + +timevalfix(t1) + struct timeval *t1; +{ + + if (t1->tv_usec < 0) { + t1->tv_sec--; + t1->tv_usec += 1000000; + } + if (t1->tv_usec >= 1000000) { + t1->tv_sec++; + t1->tv_usec -= 1000000; + } +} diff --git a/usr/src/sys/tests/benchmarks/nulljob.c b/usr/src/sys/tests/benchmarks/nulljob.c new file mode 100644 index 0000000000..713f9e876f --- /dev/null +++ b/usr/src/sys/tests/benchmarks/nulljob.c @@ -0,0 +1,10 @@ +/* + * Benchmark "null job" program. + */ + +main(argc, argv) + char *argv[]; +{ + + exit(0); +} diff --git a/usr/src/sys/tests/benchmarks/pipeback.c b/usr/src/sys/tests/benchmarks/pipeback.c new file mode 100644 index 0000000000..b76e0401a8 --- /dev/null +++ b/usr/src/sys/tests/benchmarks/pipeback.c @@ -0,0 +1,46 @@ +/* + * IPC benchmark, + * read and reply using pipes. + * + * Process forks and exchanges messages + * over a pipe in a request-response fashion. + */ + +main(argc, argv) + char *argv[]; +{ + char buf[512]; + int fd[2], fd2[2], msgsize; + register int i, iter; + + if (argc < 3) { + printf("usage: %s iterations message-size\n", argv[0]); + exit(1); + } + argc--, argv++; + iter = atoi(*argv); + argc--, argv++; + msgsize = atoi(*argv); + if (msgsize > sizeof (buf) || msgsize <= 0) { + printf("%s: Bad message size.\n", *argv); + exit(2); + } + if (pipe(fd) < 0) { + perror("pipe"); + exit(3); + } + if (pipe(fd2) < 0) { + perror("pipe"); + exit(3); + } + if (fork() == 0) + for (i = 0; i < iter; i++) { + read(fd[0], buf, msgsize); + write(fd2[1], buf, msgsize); + } + else + for (i = 0; i < iter; i++) { + write(fd[1], buf, msgsize); + read(fd2[0], buf, msgsize); + } +} diff --git a/usr/src/sys/tests/benchmarks/pipediscard.c b/usr/src/sys/tests/benchmarks/pipediscard.c new file mode 100644 index 0000000000..cab8df51b2 --- /dev/null +++ b/usr/src/sys/tests/benchmarks/pipediscard.c @@ -0,0 +1,35 @@ +/* + * IPC benchmarkl, + * write and discard using pipes. + */ + +main(argc, argv) + char *argv[]; +{ + char buf[512]; + int fd[2], msgsize; + register int i, iter; + + if (argc < 3) { + printf("usage: %s iterations message-size\n", argv[0]); + exit(1); + } + argc--, argv++; + iter = atoi(*argv); + argc--, argv++; + msgsize = atoi(*argv); + if (msgsize > sizeof (buf) || msgsize <= 0) { + printf("%s: Bad message size.\n", *argv); + exit(2); + } + if (pipe(fd) < 0) { + perror("pipe"); + exit(3); + } + if (fork() == 0) + for (i = 0; i < iter; i++) + read(fd[0], buf, msgsize); + else + for (i = 0; i < iter; i++) + write(fd[1], buf, msgsize); +} diff --git a/usr/src/sys/tests/benchmarks/pipeself.c b/usr/src/sys/tests/benchmarks/pipeself.c new file mode 100644 index 0000000000..114b1d0189 --- /dev/null +++ b/usr/src/sys/tests/benchmarks/pipeself.c @@ -0,0 +1,33 @@ +/* + * IPC benchmark, + * write to self using pipes. + */ + +main(argc, argv) + char *argv[]; +{ + char buf[512]; + int fd[2], msgsize; + register int i, iter; + + if (argc < 3) { + printf("usage: %s iterations message-size\n", argv[0]); + exit(1); + } + argc--, argv++; + iter = atoi(*argv); + argc--, argv++; + msgsize = atoi(*argv); + if (msgsize > sizeof (buf) || msgsize <= 0) { + printf("%s: Bad message size.\n", *argv); + exit(2); + } + if (pipe(fd) < 0) { + perror("pipe"); + exit(3); + } + for (i = 0; i < iter; i++) { + write(fd[1], buf, msgsize); + read(fd[0], buf, msgsize); + } +} diff --git a/usr/src/sys/tests/benchmarks/randbread.c b/usr/src/sys/tests/benchmarks/randbread.c new file mode 100644 index 0000000000..a720361d0f --- /dev/null +++ b/usr/src/sys/tests/benchmarks/randbread.c @@ -0,0 +1,44 @@ +/* + * Random I/O benchmark. + * + * Process reads blocks from a + * file in a random order. + */ +#include +#include +#include + +char *malloc(); + +main(argc, argv) + char *argv[]; +{ + char *buf; + int fd, bn, maxblocks; + struct stat sb; + register int i, niter; + + if (argc < 3) { + printf("usage: %s file #reads\n", argv[0]); + exit(1); + } + fd = open(argv[1], O_RDONLY); + if (fd < 0) { + perror(argv[1]); + exit(2); + } + buf = malloc(sb.st_blksize); + if (buf == (char *)0) { + printf("Couldn't allocate i/o buffer.\n"); + exit(3); + } + fstat(fd, &sb); + niter = atoi(argv[2]); + printf("%d random block reads, file size %d kb (bsize %d)\n", + niter, sb.st_size / 1024, sb.st_blksize); + for (i = 0; i < niter; i++) { + bn = (random() % sb.st_size) / sb.st_size; + lseek(fd, bn * sb.st_blksize, L_SET); + read(fd, buf, sb.st_blksize); + } +} diff --git a/usr/src/sys/tests/benchmarks/randpage.c b/usr/src/sys/tests/benchmarks/randpage.c new file mode 100644 index 0000000000..9626dba585 --- /dev/null +++ b/usr/src/sys/tests/benchmarks/randpage.c @@ -0,0 +1,65 @@ +/* + * Random page access benchmark. + */ +#include + +char *valloc(); +int rand(); + +main(argc, argv) + char *argv[]; +{ + register int npages = 4096, pagesize, pn, i, niter; + int vflag = 0, debug = 0; + char *pages, *name; + + name = argv[0]; + argc--, argv++; +again: + if (argc < 1) { +usage: + printf("usage: %s [ -d ] [ -v ] [ -k #Kb ] niter\n", name); + exit(1); + } + if (strcmp(*argv, "-k") == 0) { + argc--, argv++; + if (argc < 1) + goto usage; + npages = atoi(*argv); + if (npages <= 0) { + printf("%s: Bad virtual memory size.\n", *argv); + exit(2); + } + argc--, argv++; + goto again; + } + if (strcmp(*argv, "-v") == 0) { + argc--, argv++; + vflag++; + goto again; + } + if (strcmp(*argv, "-d") == 0) { + argc--, argv++; + debug++; + goto again; + } + niter = atoi(*argv); + pagesize = getpagesize(); + npages /= pagesize / 1024; + pages = valloc(npages, pagesize); + if (pages == (char *)0) { + printf("Can't allocate %d pages (%2.1f megabytes).\n", + npages, (npages * pagesize) / (1024. * 1024.)); + exit(3); + } + if (pagesize != 1024) + printf("Pagesize %dKb\n", pagesize / 1024); + if (vflag) + vadvise(VA_ANOM); + for (i = 0; i < niter; i++) { + pn = random() % npages; + if (debug) + printf("touch page %d\n", pn); + pages[pagesize * pn] = 1; + } +} diff --git a/usr/src/sys/tests/benchmarks/randread.c b/usr/src/sys/tests/benchmarks/randread.c new file mode 100644 index 0000000000..5f4968ee43 --- /dev/null +++ b/usr/src/sys/tests/benchmarks/randread.c @@ -0,0 +1,49 @@ +/* + * Random I/O benchmark. + * + * Process reads blocks from a + * file in a random order. + */ +#include +#include +#include + +char *malloc(); + +main(argc, argv) + char *argv[]; +{ + char *buf; + int size, fd, bn, maxblocks; + struct stat sb; + register int i, niter; + + if (argc < 3) { + printf("usage: %s file read-size #reads\n", argv[0]); + exit(1); + } + fd = open(argv[1], O_RDONLY); + if (fd < 0) { + perror(argv[1]); + exit(2); + } + fstat(fd, &sb); + buf = malloc(sb.st_blksize); + if (buf == (char *)0) { + printf("Couldn't allocate i/o buffer.\n"); + exit(3); + } + size = atoi(argv[2]); + if (size > sb.st_blksize) { + printf("Reads must be no larger than block size (%d)\n", + sb.st_blksize); + exit(4); + } + niter = atoi(argv[3]); + printf("%d random %d byte reads, file size %d kb (bsize %d)\n", + niter, size, sb.st_size / 1024, sb.st_blksize); + for (i = 0; i < niter; i++) { + lseek(fd, random() % sb.st_size, L_SET); + read(fd, buf, size); + } +} diff --git a/usr/src/sys/tests/benchmarks/randrewrite.c b/usr/src/sys/tests/benchmarks/randrewrite.c new file mode 100644 index 0000000000..cf768e5223 --- /dev/null +++ b/usr/src/sys/tests/benchmarks/randrewrite.c @@ -0,0 +1,48 @@ +/* + * Random I/O benchmark. + * + * Process writes blocks to a file in a + * random order. Writes are constrained + * to overwrite existing blocks. This + * test should be run after the seqio test + * so that a file is constructed. + */ +#include +#include +#include + +char *malloc(); + +main(argc, argv) + char *argv[]; +{ + char *buf; + int fd, bn, nblocks; + struct stat sb; + register int i, niter; + + if (argc < 3) { + printf("usage: %s file #writes\n", argv[0]); + exit(1); + } + fd = open(argv[1], O_WRONLY|O_CREAT, 0644); + if (fd < 0) { + perror(argv[1]); + exit(2); + } + fstat(fd, &sb); + buf = malloc(sb.st_blksize); + if (buf == (char *)0) { + printf("Couldn't allocate i/o buffer.\n"); + exit(3); + } + nblocks = sb.st_size / sb.st_blksize; + niter = atoi(argv[2]); + printf("%d random writes in %d block file (block size %d)\n", + niter, nblocks, sb.st_blksize); + for (i = 0; i < niter; i++) { + bn = random() % nblocks; + lseek(fd, bn * sb.st_blksize, L_SET); + write(fd, buf, sb.st_blksize); + } +} diff --git a/usr/src/sys/tests/benchmarks/randwrite.c b/usr/src/sys/tests/benchmarks/randwrite.c new file mode 100644 index 0000000000..d6e6d48a5a --- /dev/null +++ b/usr/src/sys/tests/benchmarks/randwrite.c @@ -0,0 +1,45 @@ +/* + * Random I/O benchmark. + * + * Process writes blocks to a + * file in a random order. + */ +#include +#include +#include + +char *malloc(); + +main(argc, argv) + char *argv[]; +{ + char *buf; + int fd, bn, maxblocks; + struct stat sb; + register int i, niter; + + if (argc < 4) { + printf("usage: %s file max-file-size #writes\n", argv[0]); + exit(1); + } + fd = open(argv[1], O_WRONLY|O_CREAT|O_TRUNC, 0644); + if (fd < 0) { + perror(argv[1]); + exit(2); + } + buf = malloc(sb.st_blksize); + if (buf == (char *)0) { + printf("Couldn't allocate i/o buffer.\n"); + exit(3); + } + /* file size is in megabytes */ + fstat(fd, &sb); + maxblocks = atoi(argv[2]) * ((1024 * 1024) / sb.st_blksize); + niter = atoi(argv[3]); + printf("%d random writes (block size %d)\n", niter, sb.st_blksize); + for (i = 0; i < niter; i++) { + bn = random() % maxblocks; + lseek(fd, bn * sb.st_blksize, L_SET); + write(fd, buf, sb.st_blksize); + } +} diff --git a/usr/src/sys/tests/benchmarks/run b/usr/src/sys/tests/benchmarks/run new file mode 100644 index 0000000000..4aeb94c5c2 --- /dev/null +++ b/usr/src/sys/tests/benchmarks/run @@ -0,0 +1,78 @@ +#! /bin/csh -fx +# Script to run benchmark programs. +# +date +make clean; time make +time syscall 100000 +time seqpage -p 7500 10 +time seqpage -v -p 7500 10 +time randpage -p 7500 30000 +time randpage -v -p 7500 30000 +time gausspage -p 7500 -s 1 30000 +time gausspage -p 7500 -s 10 30000 +time gausspage -p 7500 -s 30 30000 +time gausspage -p 7500 -s 40 30000 +time gausspage -p 7500 -s 50 30000 +time gausspage -p 7500 -s 60 30000 +time gausspage -p 7500 -s 80 30000 +time gausspage -p 7500 -s 10000 30000 +time csw 10000 +time signocsw 10000 +time pipeself 10000 512 +time pipeself 10000 4 +time udgself 10000 512 +time udgself 10000 4 +time pipediscard 10000 512 +time pipediscard 10000 4 +time udgdiscard 10000 512 +time udgdiscard 10000 4 +time pipeback 10000 512 +time pipeback 10000 4 +time udgback 10000 512 +time udgback 10000 4 +size forks +time forks 1000 0 +time forks 1000 1024 +time forks 1000 102400 +size vforks +time vforks 1000 0 +time vforks 1000 1024 +time vforks 1000 102400 +countenv +size nulljob +time execs 1000 0 nulljob +time execs 1000 1024 nulljob +time execs 1000 102400 nulljob +time vexecs 1000 0 nulljob +time vexecs 1000 1024 nulljob +time vexecs 1000 102400 nulljob +size bigjob +time execs 1000 0 bigjob +time execs 1000 1024 bigjob +time execs 1000 102400 bigjob +time vexecs 1000 0 bigjob +time vexecs 1000 1024 bigjob +time vexecs 1000 102400 bigjob +# fill environment with ~1024 bytes +setenv a 012345678901234567890123456789012345678901234567890123456780123456789 +setenv b 012345678901234567890123456789012345678901234567890123456780123456789 +setenv c 012345678901234567890123456789012345678901234567890123456780123456789 +setenv d 012345678901234567890123456789012345678901234567890123456780123456789 +setenv e 012345678901234567890123456789012345678901234567890123456780123456789 +setenv f 012345678901234567890123456789012345678901234567890123456780123456789 +setenv g 012345678901234567890123456789012345678901234567890123456780123456789 +setenv h 012345678901234567890123456789012345678901234567890123456780123456789 +setenv i 012345678901234567890123456789012345678901234567890123456780123456789 +setenv j 012345678901234567890123456789012345678901234567890123456780123456789 +setenv k 012345678901234567890123456789012345678901234567890123456780123456789 +setenv l 012345678901234567890123456789012345678901234567890123456780123456789 +setenv m 012345678901234567890123456789012345678901234567890123456780123456789 +setenv n 012345678901234567890123456789012345678901234567890123456780123456789 +setenv o 012345678901234567890123456789012345678901234567890123456780123456789 +countenv +time execs 1000 0 nulljob +time execs 1000 1024 nulljob +time execs 1000 102400 nulljob +time execs 1000 0 bigjob +time execs 1000 1024 bigjob +time execs 1000 102400 bigjob diff --git a/usr/src/sys/tests/benchmarks/run+fs b/usr/src/sys/tests/benchmarks/run+fs new file mode 100644 index 0000000000..cec85ae693 --- /dev/null +++ b/usr/src/sys/tests/benchmarks/run+fs @@ -0,0 +1,92 @@ +#! /bin/csh -fx +# Script to run benchmark programs. +# +date +make clean; time make +time syscall 100000 +onintr cleanup +time seqwrite test 8 # 8 megabyte file +time seqread test +time randread test 10 30000 +time randread test 512 30000 +time randread test 1024 30000 +time seqrewrite test 8 +time randrewrite test 30000 +rm test +time randwrite test 8 30000 # 8 megabyte file +rm test; onintr +time seqpage -p 7500 10 +time seqpage -v -p 7500 10 +time randpage -p 7500 30000 +time randpage -v -p 7500 30000 +time gausspage -p 7500 -s 1 30000 +time gausspage -p 7500 -s 10 30000 +time gausspage -p 7500 -s 30 30000 +time gausspage -p 7500 -s 40 30000 +time gausspage -p 7500 -s 50 30000 +time gausspage -p 7500 -s 60 30000 +time gausspage -p 7500 -s 80 30000 +time gausspage -p 7500 -s 10000 30000 +time csw 10000 +time signocsw 10000 +time pipeself 10000 512 +time pipeself 10000 4 +time udgself 10000 512 +time udgself 10000 4 +time pipediscard 10000 512 +time pipediscard 10000 4 +time udgdiscard 10000 512 +time udgdiscard 10000 4 +time pipeback 10000 512 +time pipeback 10000 4 +time udgback 10000 512 +time udgback 10000 4 +size forks +time forks 1000 0 +time forks 1000 1024 +time forks 1000 102400 +size vforks +time vforks 1000 0 +time vforks 1000 1024 +time vforks 1000 102400 +countenv +size nulljob +time execs 1000 0 nulljob +time execs 1000 1024 nulljob +time execs 1000 102400 nulljob +time vexecs 1000 0 nulljob +time vexecs 1000 1024 nulljob +time vexecs 1000 102400 nulljob +size bigjob +time execs 1000 0 bigjob +time execs 1000 1024 bigjob +time execs 1000 102400 bigjob +time vexecs 1000 0 bigjob +time vexecs 1000 1024 bigjob +time vexecs 1000 102400 bigjob +# fill environment with ~1024 bytes +setenv a 012345678901234567890123456789012345678901234567890123456780123456789 +setenv b 012345678901234567890123456789012345678901234567890123456780123456789 +setenv c 012345678901234567890123456789012345678901234567890123456780123456789 +setenv d 012345678901234567890123456789012345678901234567890123456780123456789 +setenv e 012345678901234567890123456789012345678901234567890123456780123456789 +setenv f 012345678901234567890123456789012345678901234567890123456780123456789 +setenv g 012345678901234567890123456789012345678901234567890123456780123456789 +setenv h 012345678901234567890123456789012345678901234567890123456780123456789 +setenv i 012345678901234567890123456789012345678901234567890123456780123456789 +setenv j 012345678901234567890123456789012345678901234567890123456780123456789 +setenv k 012345678901234567890123456789012345678901234567890123456780123456789 +setenv l 012345678901234567890123456789012345678901234567890123456780123456789 +setenv m 012345678901234567890123456789012345678901234567890123456780123456789 +setenv n 012345678901234567890123456789012345678901234567890123456780123456789 +setenv o 012345678901234567890123456789012345678901234567890123456780123456789 +countenv +time execs 1000 0 nulljob +time execs 1000 1024 nulljob +time execs 1000 102400 nulljob +time execs 1000 0 bigjob +time execs 1000 1024 bigjob +time execs 1000 102400 bigjob +exit +cleanup: +rm -f test diff --git a/usr/src/sys/tests/benchmarks/run.awk b/usr/src/sys/tests/benchmarks/run.awk new file mode 100644 index 0000000000..50744fb07a --- /dev/null +++ b/usr/src/sys/tests/benchmarks/run.awk @@ -0,0 +1,3 @@ +$2 == "syscall" { + ncalls = $3; getline; time = substr($2, 0, 4); + print "System Call Overhead: ", (time * 1000000) / ncalls, "us"; } diff --git a/usr/src/sys/tests/benchmarks/seqpage.c b/usr/src/sys/tests/benchmarks/seqpage.c new file mode 100644 index 0000000000..7fd633c088 --- /dev/null +++ b/usr/src/sys/tests/benchmarks/seqpage.c @@ -0,0 +1,58 @@ +/* + * Sequential page access benchmark. + */ +#include + +char *valloc(); + +main(argc, argv) + char *argv[]; +{ + register i, niter; + register char *pf, *lastpage; + int npages = 4096, pagesize, vflag = 0; + char *pages, *name; + + name = argv[0]; + argc--, argv++; +again: + if (argc < 1) { +usage: + printf("usage: %s [ -v ] [ -k #Kb ] niter\n", name); + exit(1); + } + if (strcmp(*argv, "-k") == 0) { + argc--, argv++; + if (argc < 1) + goto usage; + npages = atoi(*argv); + if (npages <= 0) { + printf("%s: Bad virtual memory size.\n", *argv); + exit(2); + } + argc--, argv++; + goto again; + } + if (strcmp(*argv, "-v") == 0) { + argc--, argv++; + vflag++; + goto again; + } + niter = atoi(*argv); + pagesize = getpagesize(); + npages /= pagesize / 1024; + pages = valloc(npages, pagesize); + if (pages == (char *)0) { + printf("Can't allocate %d pages (%2.1f megabytes).\n", + npages, (npages * pagesize) / (1024. * 1024.)); + exit(3); + } + if (pagesize != 1024) + printf("Pagesize %dKb\n", pagesize / 1024); + lastpage = pages + (npages * pagesize); + if (vflag) + vadvise(VA_SEQL); + for (i = 0; i < niter; i++) + for (pf = pages; pf < lastpage; pf += pagesize) + *pf = 1; +} diff --git a/usr/src/sys/tests/benchmarks/seqread.c b/usr/src/sys/tests/benchmarks/seqread.c new file mode 100644 index 0000000000..ec452b9687 --- /dev/null +++ b/usr/src/sys/tests/benchmarks/seqread.c @@ -0,0 +1,32 @@ +/* + * Sequential I/O benchmark. + */ + +#include +#include +#include + +char *malloc(); + +main(argc, argv) + char *argv[]; +{ + register int i, max; + char *buf; + struct stat sb; + int fd; + + if (argc < 2) { + printf("usage: %s file\n", argv[0]); + exit(1); + } + fd = open(argv[1], O_RDONLY); + if (fd < 0) { + perror(argv[1]); + exit(1); + } + fstat(fd, &sb); + buf = malloc(sb.st_blksize); + while (read(fd, buf, sb.st_blksize) == sb.st_blksize) + ; +} diff --git a/usr/src/sys/tests/benchmarks/seqrewrite.c b/usr/src/sys/tests/benchmarks/seqrewrite.c new file mode 100644 index 0000000000..9bf34cec8d --- /dev/null +++ b/usr/src/sys/tests/benchmarks/seqrewrite.c @@ -0,0 +1,35 @@ +/* + * Sequential I/O benchmark. + * + * Overwrites existing data in a file. + */ +#include +#include +#include + +char *malloc(); + +main(argc, argv) + char *argv[]; +{ + register int i, max; + char *buf; + struct stat sb; + int fd; + + if (argc < 2) { + printf("usage: %s file\n", argv[0]); + exit(1); + } + fd = open(argv[1], O_WRONLY, 0644); + if (fd < 0) { + perror(argv[1]); + exit(1); + } + fstat(fd, &sb); + buf = malloc(sb.st_blksize); + max = sb.st_size / sb.st_blksize; + printf("%d writes of %d kilobytes\n", max, sb.st_blksize / 1024); + for (i = 0; i < max; i++) + write(fd, buf, sb.st_blksize); +} diff --git a/usr/src/sys/tests/benchmarks/seqwrite.c b/usr/src/sys/tests/benchmarks/seqwrite.c new file mode 100644 index 0000000000..ad2825c9b5 --- /dev/null +++ b/usr/src/sys/tests/benchmarks/seqwrite.c @@ -0,0 +1,34 @@ +/* + * Sequential I/O benchmark. + */ + +#include +#include +#include + +char *malloc(); + +main(argc, argv) + char *argv[]; +{ + register int i, max; + char *buf; + struct stat sb; + int fd; + + if (argc < 3) { + printf("usage: %s file megabytes\n", argv[0]); + exit(1); + } + fd = open(argv[1], O_WRONLY|O_CREAT|O_TRUNC, 0644); + if (fd < 0) { + perror(argv[1]); + exit(1); + } + fstat(fd, &sb); + buf = malloc(sb.st_blksize); + max = (atoi(argv[2]) * 1024 * 1024) / sb.st_blksize; + printf("%d writes of %d kilobytes\n", max, sb.st_blksize / 1024); + for (i = 0; i < max; i++) + write(fd, buf, sb.st_blksize); +} diff --git a/usr/src/sys/tests/benchmarks/syscall.c b/usr/src/sys/tests/benchmarks/syscall.c new file mode 100644 index 0000000000..c50103eced --- /dev/null +++ b/usr/src/sys/tests/benchmarks/syscall.c @@ -0,0 +1,16 @@ +/* + * System call overhead benchmark. + */ +main(argc, argv) + char *argv[]; +{ + register int ncalls; + + if (argc < 2) { + printf("usage: %s #syscalls\n", argv[0]); + exit(1); + } + ncalls = atoi(argv[1]); + while (ncalls-- > 0) + (void) getpid(); +} diff --git a/usr/src/sys/tests/benchmarks/udgback.c b/usr/src/sys/tests/benchmarks/udgback.c new file mode 100644 index 0000000000..a671b84e93 --- /dev/null +++ b/usr/src/sys/tests/benchmarks/udgback.c @@ -0,0 +1,85 @@ +/* + * IPC benchmark, + * read and reply using UNIX domain datagram sockets. + * + * Process forks and exchanges messages using a + * UNIX domain datagram socket in a request-response fashion. + */ + +#include +#include + +#include +#include +#include +#include +#include + +struct sockaddr_un sun; +struct sockaddr_un myname; + +int catchsig(); +char *malloc(); + +main(argc, argv) + char *argv[]; +{ + register char *buf; + register int i, msgs = 0; + int msglen = 0, ms; + int pid, s, sunlen; + + if (argc < 3) { + printf("usage: %s #msgs msglen\n", argv[0]); + exit(1); + } + msgs = atoi(argv[1]); + msglen = atoi(argv[2]); + buf = malloc(msglen); + if (buf == 0) { + printf("Couldn't allocate data buffer\n"); + exit(1); + } + myname.sun_family = AF_UNIX; + signal(SIGINT, catchsig); + s = socket(AF_UNIX, SOCK_DGRAM, 0); + if (s < 0) { + perror("socket"); + exit(1); + } + sprintf(myname.sun_path, "unixdg%d", getpid()); + sunlen = strlen(myname.sun_path) + 2; + if (bind(s, &myname, sunlen) < 0) { + perror("bind"); + exit(1); + } + pid = fork(); + if (pid == 0) + for (i = 0; i < msgs; i++) { + sunlen = sizeof (sun); + if (recvfrom(s, buf, msglen, 0, &sun, &sunlen) < 0) + perror("recvfrom (child)"); + sunlen = strlen(myname.sun_path) + 2; + if (sendto(s, buf, msglen, 0, &myname, sunlen) < 0) + perror("sendto (child)"); + } + else + for (i = 0; i < msgs; i++) { + sunlen = strlen(myname.sun_path) + 2; + if (sendto(s, buf, msglen, 0, &myname, sunlen) < 0) + perror("sendto (parent)"); + sunlen = sizeof (sun); + if (recvfrom(s, buf, msglen, 0, &sun, &sunlen) < 0) + perror("recvfrom (parent)"); + } + close(s); + unlink(myname.sun_path); +} + +catchsig(s) + int s; +{ + + unlink(myname.sun_path); + exit(1); +} diff --git a/usr/src/sys/tests/benchmarks/udgdiscard.c b/usr/src/sys/tests/benchmarks/udgdiscard.c new file mode 100644 index 0000000000..a283c14777 --- /dev/null +++ b/usr/src/sys/tests/benchmarks/udgdiscard.c @@ -0,0 +1,78 @@ +/* + * IPC benchmark, + * read and discard using UNIX domain datagram sockets. + * + * Process forks with parent sending and child + * receiving (and discarding) messages. + */ + +#include +#include + +#include +#include +#include +#include +#include + +struct sockaddr_un sun; +struct sockaddr_un myname; + +int catchsig(); +char *malloc(); + +main(argc, argv) + char *argv[]; +{ + register char *buf; + register int i, msgs = 0; + int msglen = 0, ms; + int pid, s, sunlen; + + if (argc < 3) { + printf("usage: %s #msgs msglen\n", argv[0]); + exit(1); + } + msgs = atoi(argv[1]); + msglen = atoi(argv[2]); + buf = malloc(msglen); + if (buf == 0) { + printf("Couldn't allocate data buffer\n"); + exit(1); + } + myname.sun_family = AF_UNIX; + signal(SIGINT, catchsig); + s = socket(AF_UNIX, SOCK_DGRAM, 0); + if (s < 0) { + perror("socket"); + exit(1); + } + sprintf(myname.sun_path, "unixdg%d", getpid()); + sunlen = strlen(myname.sun_path) + 2; + if (bind(s, &myname, sunlen) < 0) { + perror("bind"); + exit(1); + } + pid = fork(); + if (pid == 0) + for (i = 0; i < msgs; i++) { + sunlen = sizeof (sun); + if (recvfrom(s, buf, msglen, 0, &sun, &sunlen) < 0) + perror("recvfrom (child)"); + } + else + for (i = 0; i < msgs; i++) { + if (sendto(s, buf, msglen, 0, &myname, sunlen) < 0) + perror("sendto (parent)"); + } + close(s); + unlink(myname.sun_path); +} + +catchsig(s) + int s; +{ + + unlink(myname.sun_path); + exit(1); +} diff --git a/usr/src/sys/tests/benchmarks/udgrand.c b/usr/src/sys/tests/benchmarks/udgrand.c new file mode 100644 index 0000000000..4be4b37d80 --- /dev/null +++ b/usr/src/sys/tests/benchmarks/udgrand.c @@ -0,0 +1,156 @@ +/* + * UNIX domain datagram socket random + * send benchmark. + */ + +#include +#include + +#include +#include +#include +#include +#include + +struct sockaddr_un sun; +struct sockaddr_un myname; + +int catchsig(); +#define MAXMSGS 10000 +int lens[MAXMSGS]; +char *malloc(); + +main(argc, argv) + char *argv[]; +{ + register char *buf; + register int i, kb, msgs = 0; + int msglen = 0, ms, lens[MAXMSGS]; + int pid, s, sunlen; + struct timeval t1, t2; + struct rusage r1, r2; + + if (argc < 3) { + printf("usage: %s #msgs max-msg-length\n", argv[0]); + exit(1); + } + msgs = atoi(argv[1]); + msglen = atoi(argv[2]); + buf = malloc(msglen); + if (buf == 0) { + printf("Couldn't allocate data buffer\n"); + exit(1); + } + for (i = 0; i < msgs; i++) + lens[i] = random() % msglen; + for (i = 0; i < msglen; i++) + buf[i] = random() & 0xff; + myname.sun_family = AF_UNIX; + printf("%d messages, max message length %d bytes\n", msgs, msglen); + signal(SIGINT, catchsig); + pid = fork(); + if (pid == 0) { + s = socket(AF_UNIX, SOCK_DGRAM, 0); + if (s < 0) { + perror("socket"); + exit(1); + } + sprintf(myname.sun_path, "unixdg%d", getpid()); + if (bind(s, &myname, strlen(myname.sun_path) + 2) < 0) { + perror("bind (child)"); + exit(1); + } + for (i = 0; i < msgs; i++) { + sunlen = sizeof (sun); + if (recvfrom(s, buf, lens[i], 0, &sun, &sunlen) < 0) + perror("recvfrom"); + } + } else { + s = socket(AF_UNIX, SOCK_DGRAM, 0); + if (s < 0) { + perror("socket"); + exit(1); + } + sprintf(myname.sun_path, "unixdg%d", getpid()); + if (bind(s, &myname, strlen(myname.sun_path) + 2) < 0) { + perror("bind (parent)"); + exit(1); + } + sun.sun_family = AF_UNIX; + sprintf(sun.sun_path, "unixdg%d", pid); + sunlen = strlen(sun.sun_path) + 2; + getrusage(RUSAGE_SELF, &r1); + gettimeofday(&t1, (struct timezone *)0); + for (kb = 0, i = 0; i < msgs; kb += lens[i], i++) + if (sendto(s, buf, lens[i], 0, &sun, sunlen) < 0) + perror("sendto"); + gettimeofday(&t2, (struct timezone *)0); + getrusage(RUSAGE_SELF, &r2); + timevalsub(&t2, &t1); + ms = t2.tv_usec / 1000; + printf("%d msgs (%d bytes) in %d.%d secs", msgs, + kb, t2.tv_sec, ms / 100); +#define nz(x) (x == 0 ? 1 : x) + printf(", %d bytes/msg, %6.2f kb/s, %4.1f ms/msg\n", + kb / nz(msgs), (8. * kb) / (nz(t2.tv_sec) * 1024.), + (1000. * t2.tv_sec + ms) / nz(msgs)); + timevalsub(&r2.ru_stime, &r1.ru_stime); + timevalsub(&r2.ru_utime, &r1.ru_utime); + r2.ru_nvcsw -= r1.ru_nvcsw; + r2.ru_nivcsw -= r1.ru_nivcsw; + printf("System %d.%d, user %d.%d, %d vcsw, %d ivcsw\n", + r2.ru_stime.tv_sec, r2.ru_stime.tv_usec / 100000, + r2.ru_utime.tv_sec, r2.ru_utime.tv_usec / 100000, + r2.ru_nvcsw, r2.ru_nivcsw); + kill(pid, SIGINT); + } + close(s); + unlink(myname.sun_path); +} + +catchsig(s) + int s; +{ + + unlink(myname.sun_path); + exit(1); +} + +/* + * Add and subtract routines for timevals. + * N.B.: subtract routine doesn't deal with + * results which are before the beginning, + * it just gets very confused in this case. + * Caveat emptor. + */ +timevaladd(t1, t2) + struct timeval *t1, *t2; +{ + + t1->tv_sec += t2->tv_sec; + t1->tv_usec += t2->tv_usec; + timevalfix(t1); +} + +timevalsub(t1, t2) + struct timeval *t1, *t2; +{ + + t1->tv_sec -= t2->tv_sec; + t1->tv_usec -= t2->tv_usec; + timevalfix(t1); +} + +timevalfix(t1) + struct timeval *t1; +{ + + if (t1->tv_usec < 0) { + t1->tv_sec--; + t1->tv_usec += 1000000; + } + if (t1->tv_usec >= 1000000) { + t1->tv_sec++; + t1->tv_usec -= 1000000; + } +} diff --git a/usr/src/sys/tests/benchmarks/udgself.c b/usr/src/sys/tests/benchmarks/udgself.c new file mode 100644 index 0000000000..3e850c387d --- /dev/null +++ b/usr/src/sys/tests/benchmarks/udgself.c @@ -0,0 +1,70 @@ +/* + * IPC benchmark, + * write and discard to self using pipes. + */ + +#include +#include + +#include +#include +#include +#include +#include + +struct sockaddr_un sun; +struct sockaddr_un myname; + +int catchsig(); +char *malloc(); + +main(argc, argv) + char *argv[]; +{ + register char *buf; + register int i, msgs = 0; + int msglen = 0, ms; + int pid, s, sunlen; + + if (argc < 3) { + printf("usage: %s #msgs msglen\n", argv[0]); + exit(1); + } + msgs = atoi(argv[1]); + msglen = atoi(argv[2]); + buf = malloc(msglen); + if (buf == 0) { + printf("Couldn't allocate data buffer\n"); + exit(1); + } + myname.sun_family = AF_UNIX; + signal(SIGINT, catchsig); + s = socket(AF_UNIX, SOCK_DGRAM, 0); + if (s < 0) { + perror("socket"); + exit(1); + } + sprintf(myname.sun_path, "unixdg%d", getpid()); + sunlen = strlen(myname.sun_path) + 2; + if (bind(s, &myname, sunlen) < 0) { + perror("bind"); + exit(1); + } + for (i = 0; i < msgs; i++) { + sunlen = strlen(myname.sun_path) + 2; + if (sendto(s, buf, msglen, 0, &myname, sunlen) < 0) + perror("sendto (parent)"); + if (recvfrom(s, buf, msglen, 0, &sun, &sunlen) < 0) + perror("recvfrom (parent)"); + } + close(s); + unlink(myname.sun_path); +} + +catchsig(s) + int s; +{ + + unlink(myname.sun_path); + exit(1); +} diff --git a/usr/src/sys/tests/benchmarks/valloc.c b/usr/src/sys/tests/benchmarks/valloc.c new file mode 100644 index 0000000000..a3bd8e866e --- /dev/null +++ b/usr/src/sys/tests/benchmarks/valloc.c @@ -0,0 +1,18 @@ +char * +valloc(npages, pagesize) + int npages; + register int pagesize; +{ + int off; + char *base, *sbrk(); + + base = sbrk(0); + off = (int)base & (pagesize - 1); + if (off) { + (void) sbrk(pagesize - off); + base += pagesize - off; + } + if (sbrk(npages * pagesize) == (char *)-1) + return ((char *)0); + return (base); +} diff --git a/usr/src/sys/tests/benchmarks/vexecs.c b/usr/src/sys/tests/benchmarks/vexecs.c new file mode 100644 index 0000000000..9c1d63210c --- /dev/null +++ b/usr/src/sys/tests/benchmarks/vexecs.c @@ -0,0 +1,54 @@ +/* + * Benchmark program to calculate exec + * overhead (approximately). Process + * vforks and execs "null" test program. + * The time to run the vfork program should + * then be deducted from this one to + * estimate the overhead for the exec. + */ + +main(argc, argv) + char *argv[]; +{ + register int nexecs, i; + char *cp, *sbrk(); + int pid, child, status, brksize; + + if (argc < 3) { + printf("usage: %s number-of-execs sbrk-size job-name\n", + argv[0]); + exit(1); + } + nexecs = atoi(argv[1]); + if (nexecs < 0) { + printf("%s: bad number of execs\n", argv[1]); + exit(2); + } + brksize = atoi(argv[2]); + if (brksize < 0) { + printf("%s: bad size to sbrk\n", argv[2]); + exit(3); + } + cp = sbrk(); + if ((int)cp == -1) { + perror("sbrk"); + exit(4); + } + for (i = 0; i < brksize; i += 1024) + cp[i] = i; + while (nexecs-- > 0) { + child = vfork(); + if (child == -1) { + perror("vfork"); + exit(-1); + } + if (child == 0) { + execv(argv[3], argv); + perror("execv"); + _exit(-1); + } + while ((pid = wait(&status)) != -1 && pid != child) + ; + } + exit(0); +} diff --git a/usr/src/sys/tests/benchmarks/vforks.c b/usr/src/sys/tests/benchmarks/vforks.c new file mode 100644 index 0000000000..deace6efc2 --- /dev/null +++ b/usr/src/sys/tests/benchmarks/vforks.c @@ -0,0 +1,49 @@ +/* + * Benchmark program to calculate vfork+wait + * overhead (approximately). Process + * vvforks and exits while parent waits. + * The time to run this program is used + * in calculating exec overhead. + */ + +main(argc, argv) + char *argv[]; +{ + register int nvforks, i; + char *cp; + int pid, child, status, brksize; + + if (argc < 2) { + printf("usage: %s number-of-vforks sbrk-size\n", argv[0]); + exit(1); + } + nvforks = atoi(argv[1]); + if (nvforks < 0) { + printf("%s: bad number of vforks\n", argv[1]); + exit(2); + } + brksize = atoi(argv[2]); + if (brksize < 0) { + printf("%s: bad size to sbrk\n", argv[2]); + exit(3); + } + cp = (char *)sbrk(brksize); + if ((int)cp == -1) { + perror("sbrk"); + exit(4); + } + for (i = 0; i < brksize; i += 1024) + cp[i] = i; + while (nvforks-- > 0) { + child = vfork(); + if (child == -1) { + perror("vfork"); + exit(-1); + } + if (child == 0) + _exit(-1); + while ((pid = wait(&status)) != -1 && pid != child) + ; + } + exit(0); +} -- 2.20.1