1 .\" $NetBSD: a1.t,v 1.2 1998/01/09 06:54:35 perry Exp $
3 .\" Copyright (c) 1985 The Regents of the University of California.
4 .\" All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
14 .\" 3. Neither the name of the University nor the names of its contributors
15 .\" may be used to endorse or promote products derived from this software
16 .\" without specific prior written permission.
18 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" @(#)a1.t 5.1 (Berkeley) 4/17/91
32 .ds RH Appendix A \- Benchmark sources
43 \s+2Appendix A \- Benchmark sources\s-2
45 The programs shown here run under 4.2 with only routines
46 from the standard libraries. When run under 4.1 they were augmented
47 with a \fIgetpagesize\fP routine and a copy of the \fIrandom\fP
48 function from the C library. The \fIvforks\fP and \fIvexecs\fP
49 programs are constructed from the \fIforks\fP and \fIexecs\fP programs,
50 respectively, by substituting calls to \fIfork\fP with calls to
57 * System call overhead benchmark.
65 printf("usage: %s #syscalls\n", argv[0]);
68 ncalls = atoi(argv[1]);
78 * Context switching benchmark.
80 * Force system to context switch 2*nsigs
81 * times by forking and exchanging signals.
82 * To calculate system overhead for a context
83 * switch, the signocsw program must be run
84 * with nsigs. Overhead is then estimated by
86 * t2 = time signocsw <n>
87 * overhead = t1 - 2 * t2;
101 printf("usage: %s nsignals\n", argv[0]);
104 nsigs = atoi(argv[1]);
105 signal(SIGALRM, sigsub);
110 kill(otherpid, SIGALRM);
119 signal(SIGALRM, sigsub);
120 kill(otherpid, SIGALRM);
130 * Signal without context switch benchmark.
144 printf("usage: %s nsignals\n", argv[0]);
147 nsigs = atoi(argv[1]);
148 signal(SIGALRM, sigsub);
150 for (i = 0; i < nsigs; i++)
157 signal(SIGALRM, sigsub);
166 * write to self using pipes.
174 register int i, iter;
177 printf("usage: %s iterations message-size\n", argv[0]);
183 msgsize = atoi(*argv);
184 if (msgsize > sizeof (buf) || msgsize <= 0) {
185 printf("%s: Bad message size.\n", *argv);
192 for (i = 0; i < iter; i++) {
193 write(fd[1], buf, msgsize);
194 read(fd[0], buf, msgsize);
204 * write and discard using pipes.
212 register int i, iter;
215 printf("usage: %s iterations message-size\n", argv[0]);
221 msgsize = atoi(*argv);
222 if (msgsize > sizeof (buf) || msgsize <= 0) {
223 printf("%s: Bad message size.\n", *argv);
231 for (i = 0; i < iter; i++)
232 read(fd[0], buf, msgsize);
234 for (i = 0; i < iter; i++)
235 write(fd[1], buf, msgsize);
244 * read and reply using pipes.
246 * Process forks and exchanges messages
247 * over a pipe in a request-response fashion.
254 int fd[2], fd2[2], msgsize;
255 register int i, iter;
258 printf("usage: %s iterations message-size\n", argv[0]);
264 msgsize = atoi(*argv);
265 if (msgsize > sizeof (buf) || msgsize <= 0) {
266 printf("%s: Bad message size.\n", *argv);
278 for (i = 0; i < iter; i++) {
279 read(fd[0], buf, msgsize);
280 write(fd2[1], buf, msgsize);
283 for (i = 0; i < iter; i++) {
284 write(fd[1], buf, msgsize);
285 read(fd2[0], buf, msgsize);
294 * Benchmark program to calculate fork+wait
295 * overhead (approximately). Process
296 * forks and exits while parent waits.
297 * The time to run this program is used
298 * in calculating exec overhead.
304 register int nforks, i;
306 int pid, child, status, brksize;
309 printf("usage: %s number-of-forks sbrk-size\n", argv[0]);
312 nforks = atoi(argv[1]);
314 printf("%s: bad number of forks\n", argv[1]);
317 brksize = atoi(argv[2]);
319 printf("%s: bad size to sbrk\n", argv[2]);
322 cp = (char *)sbrk(brksize);
327 for (i = 0; i < brksize; i += 1024)
329 while (nforks-- > 0) {
337 while ((pid = wait(&status)) != -1 && pid != child)
348 * Benchmark program to calculate exec
349 * overhead (approximately). Process
350 * forks and execs "null" test program.
351 * The time to run the fork program should
352 * then be deducted from this one to
353 * estimate the overhead for the exec.
359 register int nexecs, i;
361 int pid, child, status, brksize;
364 printf("usage: %s number-of-execs sbrk-size job-name\n",
368 nexecs = atoi(argv[1]);
370 printf("%s: bad number of execs\n", argv[1]);
373 brksize = atoi(argv[2]);
375 printf("%s: bad size to sbrk\n", argv[2]);
383 for (i = 0; i < brksize; i += 1024)
385 while (nexecs-- > 0) {
392 execv(argv[3], argv);
396 while ((pid = wait(&status)) != -1 && pid != child)
407 * Benchmark "null job" program.
422 * Benchmark "null big job" program.
424 /* 250 here is intended to approximate vi's text+data size */
425 char space[1024 * 250] = "force into data segment";
440 * Sequential page access benchmark.
442 #include <sys/vadvise.h>
450 register char *pf, *lastpage;
451 int npages = 4096, pagesize, vflag = 0;
459 printf("usage: %s [ -v ] [ -p #pages ] niter\n", name);
462 if (strcmp(*argv, "-p") == 0) {
466 npages = atoi(*argv);
468 printf("%s: Bad page count.\n", *argv);
474 if (strcmp(*argv, "-v") == 0) {
480 pagesize = getpagesize();
481 pages = valloc(npages * pagesize);
482 if (pages == (char *)0) {
483 printf("Can't allocate %d pages (%2.1f megabytes).\n",
484 npages, (npages * pagesize) / (1024. * 1024.));
487 lastpage = pages + (npages * pagesize);
490 for (i = 0; i < niter; i++)
491 for (pf = pages; pf < lastpage; pf += pagesize)
500 * Random page access benchmark.
502 #include <sys/vadvise.h>
510 register int npages = 4096, pagesize, pn, i, niter;
511 int vflag = 0, debug = 0;
519 printf("usage: %s [ -d ] [ -v ] [ -p #pages ] niter\n", name);
522 if (strcmp(*argv, "-p") == 0) {
526 npages = atoi(*argv);
528 printf("%s: Bad page count.\n", *argv);
534 if (strcmp(*argv, "-v") == 0) {
539 if (strcmp(*argv, "-d") == 0) {
545 pagesize = getpagesize();
546 pages = valloc(npages * pagesize);
547 if (pages == (char *)0) {
548 printf("Can't allocate %d pages (%2.1f megabytes).\n",
549 npages, (npages * pagesize) / (1024. * 1024.));
554 for (i = 0; i < niter; i++) {
555 pn = random() % npages;
557 printf("touch page %d\n", pn);
558 pages[pagesize * pn] = 1;
567 * Random page access with
568 * a gaussian distribution.
570 * Allocate a large (zero fill on demand) address
571 * space and fault the pages in a random gaussian
575 float sqrt(), log(), rnd(), cos(), gauss();
582 register int pn, i, niter, delta;
583 register char *pages;
585 int npages = 4096, pagesize, debug = 0;
594 "usage: %s [ -d ] [ -p #pages ] [ -s standard-deviation ] iterations\n", name);
597 if (strcmp(*argv, "-s") == 0) {
601 sscanf(*argv, "%f", &sd);
603 printf("%s: Bad standard deviation.\n", *argv);
609 if (strcmp(*argv, "-p") == 0) {
613 npages = atoi(*argv);
615 printf("%s: Bad page count.\n", *argv);
621 if (strcmp(*argv, "-d") == 0) {
627 pagesize = getpagesize();
628 pages = valloc(npages*pagesize);
629 if (pages == (char *)0) {
630 printf("Can't allocate %d pages (%2.1f megabytes).\n",
631 npages, (npages*pagesize) / (1024. * 1024.));
635 for (i = 0; i < niter; i++) {
636 delta = gauss(sd, 0.0);
637 while (pn + delta < 0 || pn + delta > npages)
638 delta = gauss(sd, 0.0);
641 printf("touch page %d\n", pn);
643 pages[pn * pagesize] = 1;
651 register float qa, qb;
653 qa = sqrt(log(rnd()) * -2.0);
654 qb = 3.14159 * rnd();
655 return (qa * cos(qb) * sd + mean);
662 static int biggest = 0x7fffffff;
664 return ((float)rand(seed) / (float)biggest);