11 'ds / \\h'\\w' 'u-\\w'/'u'/
12 'ds /* \\h'\\w' 'u-\\w'/'u'/*
21 'tl '\s14\f3\\*(=F\fP\s0'\\*(=H'\f3\s14\\*(=F\fP\s0'
24 \f2\s12\h'\\n(.lu-\w'\\*(=f'u'\\*(=f\fP\s0\h'|0u'
32 'ie o 'tl '\f2\\*(=M''Page % of \\*(=G\fP'
33 'el 'tl '\f2Page % of \\*(=G''\\*(=M\fP'
60 \f2\s14\h'\\n(.lu-\w'\\$1'u'\\$1\fP\s0\h'|0u'\c
61 .if r x .if \\nx .if d =F .tm \\$1 \\*(=F \\n%
65 .if r x .if \\nx .if d =F .tm \\$1 \\*(=F \\n%
74 .\" Copyright (c) 1985 The Regents of the University of California.
75 .\" All rights reserved.
77 .\" Redistribution and use in source and binary forms, with or without
78 .\" modification, are permitted provided that the following conditions
80 .\" 1. Redistributions of source code must retain the above copyright
81 .\" notice, this list of conditions and the following disclaimer.
82 .\" 2. Redistributions in binary form must reproduce the above copyright
83 .\" notice, this list of conditions and the following disclaimer in the
84 .\" documentation and/or other materials provided with the distribution.
85 .\" 3. Neither the name of the University nor the names of its contributors
86 .\" may be used to endorse or promote products derived from this software
87 .\" without specific prior written permission.
89 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
90 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
91 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
92 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
93 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
94 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
95 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
96 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
97 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
98 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
101 .\" @(#)a1.t 5.1 (Berkeley) 4/17/91
103 .ds RH Appendix A \- Benchmark sources
114 \s+2Appendix A \- Benchmark sources\s-2
116 The programs shown here run under 4.2 with only routines
117 from the standard libraries. When run under 4.1 they were augmented
118 with a \fIgetpagesize\fP routine and a copy of the \fIrandom\fP
119 function from the C library. The \fIvforks\fP and \fIvexecs\fP
120 programs are constructed from the \fIforks\fP and \fIexecs\fP programs,
121 respectively, by substituting calls to \fIfork\fP with calls to
127 \fI\h'\w' 'u-\w'/'u'/\fP\fI*\fP\c\c
130 \fI*\fP System call overhead benchmark\&.
131 \fI*\fP\fI\h'\w' 'u-\w'/'u'/\fP\c
136 \h'|11n'\*(+Kchar\*(-K \fI*\fPargv[];
138 \h'|11n'\*(+Kregister\*(-K \*(+Kint\*(-K ncalls;
140 \h'|11n'\*(+Kif\*(-K (argc < 2) \*(+K{\*(-K
141 \h'|21n'printf("usage: %s #syscalls\en", argv[0]);
144 \h'|11n'ncalls = atoi(argv[1]);
145 \h'|11n'\*(+Kwhile\*(-K (ncalls\*-\*- > 0)
146 \h'|21n'(\*(+Kvoid\*(-K) getpid();
155 \fI\h'\w' 'u-\w'/'u'/\fP\fI*\fP\c\c
158 \fI*\fP Context switching benchmark\&.
160 \fI*\fP Force system to context switch 2\fI*\fPnsigs
161 \fI*\fP times by forking and exchanging signals\&.
162 \fI*\fP To calculate system overhead for a context
163 \fI*\fP switch, the signocsw program must be run
164 \fI*\fP with nsigs\&. Overhead is then estimated by
165 \fI*\fP\h'|11n't1 = time csw <n>
166 \fI*\fP\h'|11n't2 = time signocsw <n>
167 \fI*\fP\h'|11n'overhead = t1 \*- 2 \fI*\fP t2;
168 \fI*\fP\fI\h'\w' 'u-\w'/'u'/\fP\c
171 \*(+K#include\*(-K <signal\&.h>
173 \*(+Kint\*(-K\h'|11n'sigsub();
174 \*(+Kint\*(-K\h'|11n'otherpid;
175 \*(+Kint\*(-K\h'|11n'nsigs;
179 \h'|11n'\*(+Kchar\*(-K \fI*\fPargv[];
181 \h'|11n'\*(+Kint\*(-K pid;
183 \h'|11n'\*(+Kif\*(-K (argc < 2) \*(+K{\*(-K
184 \h'|21n'printf("usage: %s nsignals\en", argv[0]);
187 \h'|11n'nsigs = atoi(argv[1]);
188 \h'|11n'signal(SIGALRM, sigsub);
189 \h'|11n'otherpid = getpid();
190 \h'|11n'pid = fork();
191 \h'|11n'\*(+Kif\*(-K (pid != 0) \*(+K{\*(-K
192 \h'|21n'otherpid = pid;
193 \h'|21n'kill(otherpid, SIGALRM);
195 \h'|11n'\*(+Kfor\*(-K (;;)
205 \h'|11n'signal(SIGALRM, sigsub);
206 \h'|11n'kill(otherpid, SIGALRM);
207 \h'|11n'\*(+Kif\*(-K (\*-\*-nsigs <= 0)
217 \fI\h'\w' 'u-\w'/'u'/\fP\fI*\fP\c\c
220 \fI*\fP Signal without context switch benchmark\&.
221 \fI*\fP\fI\h'\w' 'u-\w'/'u'/\fP\c
224 \*(+K#include\*(-K <signal\&.h>
226 \*(+Kint\*(-K\h'|11n'pid;
227 \*(+Kint\*(-K\h'|11n'nsigs;
228 \*(+Kint\*(-K\h'|11n'sigsub();
232 \h'|11n'\*(+Kchar\*(-K \fI*\fPargv[];
234 \h'|11n'\*(+Kregister\*(-K \*(+Kint\*(-K i;
236 \h'|11n'\*(+Kif\*(-K (argc < 2) \*(+K{\*(-K
237 \h'|21n'printf("usage: %s nsignals\en", argv[0]);
240 \h'|11n'nsigs = atoi(argv[1]);
241 \h'|11n'signal(SIGALRM, sigsub);
242 \h'|11n'pid = getpid();
243 \h'|11n'\*(+Kfor\*(-K (i = 0; i < nsigs; i++)
244 \h'|21n'kill(pid, SIGALRM);
253 \h'|11n'signal(SIGALRM, sigsub);
262 \fI\h'\w' 'u-\w'/'u'/\fP\fI*\fP\c\c
265 \fI*\fP IPC benchmark,
266 \fI*\fP write to self using pipes\&.
267 \fI*\fP\fI\h'\w' 'u-\w'/'u'/\fP\c
273 \h'|11n'\*(+Kchar\*(-K \fI*\fPargv[];
275 \h'|11n'\*(+Kchar\*(-K buf[512];
276 \h'|11n'\*(+Kint\*(-K fd[2], msgsize;
277 \h'|11n'\*(+Kregister\*(-K \*(+Kint\*(-K i, iter;
279 \h'|11n'\*(+Kif\*(-K (argc < 3) \*(+K{\*(-K
280 \h'|21n'printf("usage: %s iterations message\*-size\en", argv[0]);
283 \h'|11n'argc\*-\*-, argv++;
284 \h'|11n'iter = atoi(\fI*\fPargv);
285 \h'|11n'argc\*-\*-, argv++;
286 \h'|11n'msgsize = atoi(\fI*\fPargv);
287 \h'|11n'\*(+Kif\*(-K (msgsize > \*(+Ksizeof\*(-K (buf) || msgsize <= 0) \*(+K{\*(-K
288 \h'|21n'printf("%s: Bad message size\&.\en", \fI*\fPargv);
291 \h'|11n'\*(+Kif\*(-K (pipe(fd) < 0) \*(+K{\*(-K
292 \h'|21n'perror("pipe");
295 \h'|11n'\*(+Kfor\*(-K (i = 0; i < iter; i++) \*(+K{\*(-K
296 \h'|21n'write(fd[1], buf, msgsize);
297 \h'|21n'read(fd[0], buf, msgsize);
307 \fI\h'\w' 'u-\w'/'u'/\fP\fI*\fP\c\c
310 \fI*\fP IPC benchmarkl,
311 \fI*\fP write and discard using pipes\&.
312 \fI*\fP\fI\h'\w' 'u-\w'/'u'/\fP\c
318 \h'|11n'\*(+Kchar\*(-K \fI*\fPargv[];
320 \h'|11n'\*(+Kchar\*(-K buf[512];
321 \h'|11n'\*(+Kint\*(-K fd[2], msgsize;
322 \h'|11n'\*(+Kregister\*(-K \*(+Kint\*(-K i, iter;
324 \h'|11n'\*(+Kif\*(-K (argc < 3) \*(+K{\*(-K
325 \h'|21n'printf("usage: %s iterations message\*-size\en", argv[0]);
328 \h'|11n'argc\*-\*-, argv++;
329 \h'|11n'iter = atoi(\fI*\fPargv);
330 \h'|11n'argc\*-\*-, argv++;
331 \h'|11n'msgsize = atoi(\fI*\fPargv);
332 \h'|11n'\*(+Kif\*(-K (msgsize > \*(+Ksizeof\*(-K (buf) || msgsize <= 0) \*(+K{\*(-K
333 \h'|21n'printf("%s: Bad message size\&.\en", \fI*\fPargv);
336 \h'|11n'\*(+Kif\*(-K (pipe(fd) < 0) \*(+K{\*(-K
337 \h'|21n'perror("pipe");
340 \h'|11n'\*(+Kif\*(-K (fork() == 0)
341 \h'|21n'\*(+Kfor\*(-K (i = 0; i < iter; i++)
342 \h'|31n'read(fd[0], buf, msgsize);
343 \h'|11n'\*(+Kelse\*(-K
344 \h'|21n'\*(+Kfor\*(-K (i = 0; i < iter; i++)
345 \h'|31n'write(fd[1], buf, msgsize);
354 \fI\h'\w' 'u-\w'/'u'/\fP\fI*\fP\c\c
357 \fI*\fP IPC benchmark,
358 \fI*\fP read and reply using pipes\&.
360 \fI*\fP Process forks and exchanges messages
361 \fI*\fP over a pipe in a request\*-response fashion\&.
362 \fI*\fP\fI\h'\w' 'u-\w'/'u'/\fP\c
368 \h'|11n'\*(+Kchar\*(-K \fI*\fPargv[];
370 \h'|11n'\*(+Kchar\*(-K buf[512];
371 \h'|11n'\*(+Kint\*(-K fd[2], fd2[2], msgsize;
372 \h'|11n'\*(+Kregister\*(-K \*(+Kint\*(-K i, iter;
374 \h'|11n'\*(+Kif\*(-K (argc < 3) \*(+K{\*(-K
375 \h'|21n'printf("usage: %s iterations message\*-size\en", argv[0]);
378 \h'|11n'argc\*-\*-, argv++;
379 \h'|11n'iter = atoi(\fI*\fPargv);
380 \h'|11n'argc\*-\*-, argv++;
381 \h'|11n'msgsize = atoi(\fI*\fPargv);
382 \h'|11n'\*(+Kif\*(-K (msgsize > \*(+Ksizeof\*(-K (buf) || msgsize <= 0) \*(+K{\*(-K
383 \h'|21n'printf("%s: Bad message size\&.\en", \fI*\fPargv);
386 \h'|11n'\*(+Kif\*(-K (pipe(fd) < 0) \*(+K{\*(-K
387 \h'|21n'perror("pipe");
390 \h'|11n'\*(+Kif\*(-K (pipe(fd2) < 0) \*(+K{\*(-K
391 \h'|21n'perror("pipe");
394 \h'|11n'\*(+Kif\*(-K (fork() == 0)
395 \h'|21n'\*(+Kfor\*(-K (i = 0; i < iter; i++) \*(+K{\*(-K
396 \h'|31n'read(fd[0], buf, msgsize);
397 \h'|31n'write(fd2[1], buf, msgsize);
399 \h'|11n'\*(+Kelse\*(-K
400 \h'|21n'\*(+Kfor\*(-K (i = 0; i < iter; i++) \*(+K{\*(-K
401 \h'|31n'write(fd[1], buf, msgsize);
402 \h'|31n'read(fd2[0], buf, msgsize);
412 \fI\h'\w' 'u-\w'/'u'/\fP\fI*\fP\c\c
415 \fI*\fP Benchmark program to calculate fork+wait
416 \fI*\fP overhead (approximately)\&. Process
417 \fI*\fP forks and exits while parent waits\&.
418 \fI*\fP The time to run this program is used
419 \fI*\fP in calculating exec overhead\&.
420 \fI*\fP\fI\h'\w' 'u-\w'/'u'/\fP\c
426 \h'|11n'\*(+Kchar\*(-K \fI*\fPargv[];
428 \h'|11n'\*(+Kregister\*(-K \*(+Kint\*(-K nforks, i;
429 \h'|11n'\*(+Kchar\*(-K \fI*\fPcp;
430 \h'|11n'\*(+Kint\*(-K pid, child, status, brksize;
432 \h'|11n'\*(+Kif\*(-K (argc < 2) \*(+K{\*(-K
433 \h'|21n'printf("usage: %s number\*-of\*-forks sbrk\*-size\en", argv[0]);
436 \h'|11n'nforks = atoi(argv[1]);
437 \h'|11n'\*(+Kif\*(-K (nforks < 0) \*(+K{\*(-K
438 \h'|21n'printf("%s: bad number of forks\en", argv[1]);
441 \h'|11n'brksize = atoi(argv[2]);
442 \h'|11n'\*(+Kif\*(-K (brksize < 0) \*(+K{\*(-K
443 \h'|21n'printf("%s: bad size to sbrk\en", argv[2]);
446 \h'|11n'cp = (\*(+Kchar\*(-K \fI*\fP)sbrk(brksize);
447 \h'|11n'\*(+Kif\*(-K ((\*(+Kint\*(-K)cp == \*-1) \*(+K{\*(-K
448 \h'|21n'perror("sbrk");
451 \h'|11n'\*(+Kfor\*(-K (i = 0; i < brksize; i += 1024)
453 \h'|11n'\*(+Kwhile\*(-K (nforks\*-\*- > 0) \*(+K{\*(-K
454 \h'|21n'child = fork();
455 \h'|21n'\*(+Kif\*(-K (child == \*-1) \*(+K{\*(-K
456 \h'|31n'perror("fork");
459 \h'|21n'\*(+Kif\*(-K (child == 0)
460 \h'|31n'\*_exit(\*-1);
461 \h'|21n'\*(+Kwhile\*(-K ((pid = wait(&status)) != \*-1 && pid != child)
473 \fI\h'\w' 'u-\w'/'u'/\fP\fI*\fP\c\c
476 \fI*\fP Benchmark program to calculate exec
477 \fI*\fP overhead (approximately)\&. Process
478 \fI*\fP forks and execs "null" test program\&.
479 \fI*\fP The time to run the fork program should
480 \fI*\fP then be deducted from this one to
481 \fI*\fP estimate the overhead for the exec\&.
482 \fI*\fP\fI\h'\w' 'u-\w'/'u'/\fP\c
488 \h'|11n'\*(+Kchar\*(-K \fI*\fPargv[];
490 \h'|11n'\*(+Kregister\*(-K \*(+Kint\*(-K nexecs, i;
491 \h'|11n'\*(+Kchar\*(-K \fI*\fPcp, \fI*\fPsbrk();
492 \h'|11n'\*(+Kint\*(-K pid, child, status, brksize;
494 \h'|11n'\*(+Kif\*(-K (argc < 3) \*(+K{\*(-K
495 \h'|21n'printf("usage: %s number\*-of\*-execs sbrk\*-size job\*-name\en",
499 \h'|11n'nexecs = atoi(argv[1]);
500 \h'|11n'\*(+Kif\*(-K (nexecs < 0) \*(+K{\*(-K
501 \h'|21n'printf("%s: bad number of execs\en", argv[1]);
504 \h'|11n'brksize = atoi(argv[2]);
505 \h'|11n'\*(+Kif\*(-K (brksize < 0) \*(+K{\*(-K
506 \h'|21n'printf("%s: bad size to sbrk\en", argv[2]);
509 \h'|11n'cp = sbrk(brksize);
510 \h'|11n'\*(+Kif\*(-K ((\*(+Kint\*(-K)cp == \*-1) \*(+K{\*(-K
511 \h'|21n'perror("sbrk");
514 \h'|11n'\*(+Kfor\*(-K (i = 0; i < brksize; i += 1024)
516 \h'|11n'\*(+Kwhile\*(-K (nexecs\*-\*- > 0) \*(+K{\*(-K
517 \h'|21n'child = fork();
518 \h'|21n'\*(+Kif\*(-K (child == \*-1) \*(+K{\*(-K
519 \h'|31n'perror("fork");
522 \h'|21n'\*(+Kif\*(-K (child == 0) \*(+K{\*(-K
523 \h'|31n'execv(argv[3], argv);
524 \h'|31n'perror("execv");
525 \h'|31n'\*_exit(\*-1);
527 \h'|21n'\*(+Kwhile\*(-K ((pid = wait(&status)) != \*-1 && pid != child)
539 \fI\h'\w' 'u-\w'/'u'/\fP\fI*\fP\c\c
542 \fI*\fP Benchmark "null job" program\&.
543 \fI*\fP\fI\h'\w' 'u-\w'/'u'/\fP\c
549 \h'|11n'\*(+Kchar\*(-K \fI*\fPargv[];
561 \fI\h'\w' 'u-\w'/'u'/\fP\fI*\fP\c\c
564 \fI*\fP Benchmark "null big job" program\&.
565 \fI*\fP\fI\h'\w' 'u-\w'/'u'/\fP\c
568 \fI\h'\w' 'u-\w'/'u'/\fP\fI*\fP\c\c
570 250 here is intended to approximate vi\'s text+data size \fI*\fP\fI\h'\w' 'u-\w'/'u'/\fP\c
573 \*(+Kchar\*(-K\h'|11n'space[1024 \fI*\fP 250] = "force into data segment";
577 \h'|11n'\*(+Kchar\*(-K \fI*\fPargv[];
590 \fI\h'\w' 'u-\w'/'u'/\fP\fI*\fP\c\c
593 \fI*\fP Sequential page access benchmark\&.
594 \fI*\fP\fI\h'\w' 'u-\w'/'u'/\fP\c
597 \*(+K#include\*(-K <sys\fI\h'\w' 'u-\w'/'u'/\fPvadvise\&.h>
599 \*(+Kchar\*(-K\h'|11n'\fI*\fPvalloc();
603 \h'|11n'\*(+Kchar\*(-K \fI*\fPargv[];
605 \h'|11n'\*(+Kregister\*(-K i, niter;
606 \h'|11n'\*(+Kregister\*(-K \*(+Kchar\*(-K \fI*\fPpf, \fI*\fPlastpage;
607 \h'|11n'\*(+Kint\*(-K npages = 4096, pagesize, vflag = 0;
608 \h'|11n'\*(+Kchar\*(-K \fI*\fPpages, \fI*\fPname;
610 \h'|11n'name = argv[0];
611 \h'|11n'argc\*-\*-, argv++;
613 \h'|11n'\*(+Kif\*(-K (argc < 1) \*(+K{\*(-K
615 \h'|21n'printf("usage: %s [ \*-v ] [ \*-p #pages ] niter\en", name);
618 \h'|11n'\*(+Kif\*(-K (strcmp(\fI*\fPargv, "\*-p") == 0) \*(+K{\*(-K
619 \h'|21n'argc\*-\*-, argv++;
620 \h'|21n'\*(+Kif\*(-K (argc < 1)
621 \h'|31n'\*(+Kgoto\*(-K usage;
622 \h'|21n'npages = atoi(\fI*\fPargv);
623 \h'|21n'\*(+Kif\*(-K (npages <= 0) \*(+K{\*(-K
624 \h'|31n'printf("%s: Bad page count\&.\en", \fI*\fPargv);
627 \h'|21n'argc\*-\*-, argv++;
628 \h'|21n'\*(+Kgoto\*(-K again;
630 \h'|11n'\*(+Kif\*(-K (strcmp(\fI*\fPargv, "\*-v") == 0) \*(+K{\*(-K
631 \h'|21n'argc\*-\*-, argv++;
633 \h'|21n'\*(+Kgoto\*(-K again;
635 \h'|11n'niter = atoi(\fI*\fPargv);
636 \h'|11n'pagesize = getpagesize();
637 \h'|11n'pages = valloc(npages \fI*\fP pagesize);
638 \h'|11n'\*(+Kif\*(-K (pages == (\*(+Kchar\*(-K \fI*\fP)0) \*(+K{\*(-K
639 \h'|21n'printf("Can\'t allocate %d pages (%2\&.1f megabytes)\&.\en",
640 \h'|21n' npages, (npages \fI*\fP pagesize) \fI\h'\w' 'u-\w'/'u'/\fP (1024\&. \fI*\fP 1024\&.));
643 \h'|11n'lastpage = pages + (npages \fI*\fP pagesize);
644 \h'|11n'\*(+Kif\*(-K (vflag)
645 \h'|21n'vadvise(VA\*_SEQL);
646 \h'|11n'\*(+Kfor\*(-K (i = 0; i < niter; i++)
647 \h'|21n'\*(+Kfor\*(-K (pf = pages; pf < lastpage; pf += pagesize)
648 \h'|31n'\fI*\fPpf = 1;
657 \fI\h'\w' 'u-\w'/'u'/\fP\fI*\fP\c\c
660 \fI*\fP Random page access benchmark\&.
661 \fI*\fP\fI\h'\w' 'u-\w'/'u'/\fP\c
664 \*(+K#include\*(-K <sys\fI\h'\w' 'u-\w'/'u'/\fPvadvise\&.h>
666 \*(+Kchar\*(-K\h'|11n'\fI*\fPvalloc();
667 \*(+Kint\*(-K\h'|11n'rand();
671 \h'|11n'\*(+Kchar\*(-K \fI*\fPargv[];
673 \h'|11n'\*(+Kregister\*(-K \*(+Kint\*(-K npages = 4096, pagesize, pn, i, niter;
674 \h'|11n'\*(+Kint\*(-K vflag = 0, debug = 0;
675 \h'|11n'\*(+Kchar\*(-K \fI*\fPpages, \fI*\fPname;
677 \h'|11n'name = argv[0];
678 \h'|11n'argc\*-\*-, argv++;
680 \h'|11n'\*(+Kif\*(-K (argc < 1) \*(+K{\*(-K
682 \h'|21n'printf("usage: %s [ \*-d ] [ \*-v ] [ \*-p #pages ] niter\en", name);
685 \h'|11n'\*(+Kif\*(-K (strcmp(\fI*\fPargv, "\*-p") == 0) \*(+K{\*(-K
686 \h'|21n'argc\*-\*-, argv++;
687 \h'|21n'\*(+Kif\*(-K (argc < 1)
688 \h'|31n'\*(+Kgoto\*(-K usage;
689 \h'|21n'npages = atoi(\fI*\fPargv);
690 \h'|21n'\*(+Kif\*(-K (npages <= 0) \*(+K{\*(-K
691 \h'|31n'printf("%s: Bad page count\&.\en", \fI*\fPargv);
694 \h'|21n'argc\*-\*-, argv++;
695 \h'|21n'\*(+Kgoto\*(-K again;
697 \h'|11n'\*(+Kif\*(-K (strcmp(\fI*\fPargv, "\*-v") == 0) \*(+K{\*(-K
698 \h'|21n'argc\*-\*-, argv++;
700 \h'|21n'\*(+Kgoto\*(-K again;
702 \h'|11n'\*(+Kif\*(-K (strcmp(\fI*\fPargv, "\*-d") == 0) \*(+K{\*(-K
703 \h'|21n'argc\*-\*-, argv++;
705 \h'|21n'\*(+Kgoto\*(-K again;
707 \h'|11n'niter = atoi(\fI*\fPargv);
708 \h'|11n'pagesize = getpagesize();
709 \h'|11n'pages = valloc(npages \fI*\fP pagesize);
710 \h'|11n'\*(+Kif\*(-K (pages == (\*(+Kchar\*(-K \fI*\fP)0) \*(+K{\*(-K
711 \h'|21n'printf("Can\'t allocate %d pages (%2\&.1f megabytes)\&.\en",
712 \h'|21n' npages, (npages \fI*\fP pagesize) \fI\h'\w' 'u-\w'/'u'/\fP (1024\&. \fI*\fP 1024\&.));
715 \h'|11n'\*(+Kif\*(-K (vflag)
716 \h'|21n'vadvise(VA\*_ANOM);
717 \h'|11n'\*(+Kfor\*(-K (i = 0; i < niter; i++) \*(+K{\*(-K
718 \h'|21n'pn = random() % npages;
719 \h'|21n'\*(+Kif\*(-K (debug)
720 \h'|31n'printf("touch page %d\en", pn);
721 \h'|21n'pages[pagesize \fI*\fP pn] = 1;
731 \fI\h'\w' 'u-\w'/'u'/\fP\fI*\fP\c\c
734 \fI*\fP Random page access with
735 \fI*\fP a gaussian distribution\&.
737 \fI*\fP Allocate a large (zero fill on demand) address
738 \fI*\fP space and fault the pages in a random gaussian
740 \fI*\fP\fI\h'\w' 'u-\w'/'u'/\fP\c
744 \*(+Kfloat\*(-K\h'|11n'sqrt(), log(), rnd(), cos(), gauss();
745 \*(+Kchar\*(-K\h'|11n'\fI*\fPvalloc();
746 \*(+Kint\*(-K\h'|11n'rand();
750 \h'|11n'\*(+Kchar\*(-K \fI*\fPargv[];
752 \h'|11n'\*(+Kregister\*(-K \*(+Kint\*(-K pn, i, niter, delta;
753 \h'|11n'\*(+Kregister\*(-K \*(+Kchar\*(-K \fI*\fPpages;
754 \h'|11n'\*(+Kfloat\*(-K sd = 10\&.0;
755 \h'|11n'\*(+Kint\*(-K npages = 4096, pagesize, debug = 0;
756 \h'|11n'\*(+Kchar\*(-K \fI*\fPname;
758 \h'|11n'name = argv[0];
759 \h'|11n'argc\*-\*-, argv++;
761 \h'|11n'\*(+Kif\*(-K (argc < 1) \*(+K{\*(-K
764 "usage: %s [ \*-d ] [ \*-p #pages ] [ \*-s standard\*-deviation ] iterations\en", name);
767 \h'|11n'\*(+Kif\*(-K (strcmp(\fI*\fPargv, "\*-s") == 0) \*(+K{\*(-K
768 \h'|21n'argc\*-\*-, argv++;
769 \h'|21n'\*(+Kif\*(-K (argc < 1)
770 \h'|31n'\*(+Kgoto\*(-K usage;
771 \h'|21n'sscanf(\fI*\fPargv, "%f", &sd);
772 \h'|21n'\*(+Kif\*(-K (sd <= 0) \*(+K{\*(-K
773 \h'|31n'printf("%s: Bad standard deviation\&.\en", \fI*\fPargv);
776 \h'|21n'argc\*-\*-, argv++;
777 \h'|21n'\*(+Kgoto\*(-K again;
779 \h'|11n'\*(+Kif\*(-K (strcmp(\fI*\fPargv, "\*-p") == 0) \*(+K{\*(-K
780 \h'|21n'argc\*-\*-, argv++;
781 \h'|21n'\*(+Kif\*(-K (argc < 1)
782 \h'|31n'\*(+Kgoto\*(-K usage;
783 \h'|21n'npages = atoi(\fI*\fPargv);
784 \h'|21n'\*(+Kif\*(-K (npages <= 0) \*(+K{\*(-K
785 \h'|31n'printf("%s: Bad page count\&.\en", \fI*\fPargv);
788 \h'|21n'argc\*-\*-, argv++;
789 \h'|21n'\*(+Kgoto\*(-K again;
791 \h'|11n'\*(+Kif\*(-K (strcmp(\fI*\fPargv, "\*-d") == 0) \*(+K{\*(-K
792 \h'|21n'argc\*-\*-, argv++;
794 \h'|21n'\*(+Kgoto\*(-K again;
796 \h'|11n'niter = atoi(\fI*\fPargv);
797 \h'|11n'pagesize = getpagesize();
798 \h'|11n'pages = valloc(npages\fI*\fPpagesize);
799 \h'|11n'\*(+Kif\*(-K (pages == (\*(+Kchar\*(-K \fI*\fP)0) \*(+K{\*(-K
800 \h'|21n'printf("Can\'t allocate %d pages (%2\&.1f megabytes)\&.\en",
801 \h'|21n' npages, (npages\fI*\fPpagesize) \fI\h'\w' 'u-\w'/'u'/\fP (1024\&. \fI*\fP 1024\&.));
805 \h'|11n'\*(+Kfor\*(-K (i = 0; i < niter; i++) \*(+K{\*(-K
806 \h'|21n'delta = gauss(sd, 0\&.0);
807 \h'|21n'\*(+Kwhile\*(-K (pn + delta < 0 || pn + delta > npages)
808 \h'|31n'delta = gauss(sd, 0\&.0);
810 \h'|21n'\*(+Kif\*(-K (debug)
811 \h'|31n'printf("touch page %d\en", pn);
812 \h'|21n'\*(+Kelse\*(-K
813 \h'|31n'pages[pn \fI*\fP pagesize] = 1;
822 \h'|11n'\*(+Kfloat\*(-K sd, mean;
824 \h'|11n'\*(+Kregister\*(-K \*(+Kfloat\*(-K qa, qb;
826 \h'|11n'qa = sqrt(log(rnd()) \fI*\fP \*-2\&.0);
827 \h'|11n'qb = 3\&.14159 \fI*\fP rnd();
828 \h'|11n'\*(+Kreturn\*(-K (qa \fI*\fP cos(qb) \fI*\fP sd + mean);
837 \h'|11n'\*(+Kstatic\*(-K \*(+Kint\*(-K seed = 1;
838 \h'|11n'\*(+Kstatic\*(-K \*(+Kint\*(-K biggest = 0x7fffffff;
840 \h'|11n'\*(+Kreturn\*(-K ((\*(+Kfloat\*(-K)rand(seed) \fI\h'\w' 'u-\w'/'u'/\fP (\*(+Kfloat\*(-K)biggest);
856 'ds / \\h'\\w' 'u-\\w'/'u'/
857 'ds /* \\h'\\w' 'u-\\w'/'u'/*
866 'tl '\s14\f3\\*(=F\fP\s0'\\*(=H'\f3\s14\\*(=F\fP\s0'
869 \f2\s12\h'\\n(.lu-\w'\\*(=f'u'\\*(=f\fP\s0\h'|0u'
877 'ie o 'tl '\f2\\*(=M''Page % of \\*(=G\fP'
878 'el 'tl '\f2Page % of \\*(=G''\\*(=M\fP'
905 \f2\s14\h'\\n(.lu-\w'\\$1'u'\\$1\fP\s0\h'|0u'\c
906 .if r x .if \\nx .if d =F .tm \\$1 \\*(=F \\n%
910 .if r x .if \\nx .if d =F .tm \\$1 \\*(=F \\n%
919 .\" Copyright (c) 1985 The Regents of the University of California.
920 .\" All rights reserved.
922 .\" Redistribution and use in source and binary forms, with or without
923 .\" modification, are permitted provided that the following conditions
925 .\" 1. Redistributions of source code must retain the above copyright
926 .\" notice, this list of conditions and the following disclaimer.
927 .\" 2. Redistributions in binary form must reproduce the above copyright
928 .\" notice, this list of conditions and the following disclaimer in the
929 .\" documentation and/or other materials provided with the distribution.
930 .\" 3. Neither the name of the University nor the names of its contributors
931 .\" may be used to endorse or promote products derived from this software
932 .\" without specific prior written permission.
934 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
935 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
936 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
937 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
938 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
939 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
940 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
941 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
942 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
943 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
946 .\" @(#)a2.t 5.1 (Berkeley) 4/17/91
952 \*(+K#\*(-K! \fI\h'\w' 'u-\w'/'u'/\fPbin\fI\h'\w' 'u-\w'/'u'/\fPcsh \*-fx
953 \*(+K#\*(-K Script to run benchmark programs\&.
956 make clean; time make
958 time seqpage \*-p 7500 10
959 time seqpage \*-v \*-p 7500 10
960 time randpage \*-p 7500 30000
961 time randpage \*-v \*-p 7500 30000
962 time gausspage \*-p 7500 \*-s 1 30000
963 time gausspage \*-p 7500 \*-s 10 30000
964 time gausspage \*-p 7500 \*-s 30 30000
965 time gausspage \*-p 7500 \*-s 40 30000
966 time gausspage \*-p 7500 \*-s 50 30000
967 time gausspage \*-p 7500 \*-s 60 30000
968 time gausspage \*-p 7500 \*-s 80 30000
969 time gausspage \*-p 7500 \*-s 10000 30000
972 time pipeself 10000 512
973 time pipeself 10000 4
974 time udgself 10000 512
976 time pipediscard 10000 512
977 time pipediscard 10000 4
978 time udgdiscard 10000 512
979 time udgdiscard 10000 4
980 time pipeback 10000 512
981 time pipeback 10000 4
982 time udgback 10000 512
987 time forks 1000 102400
990 time vforks 1000 1024
991 time vforks 1000 102400
994 time execs 1000 0 nulljob
995 time execs 1000 1024 nulljob
996 time execs 1000 102400 nulljob
997 time vexecs 1000 0 nulljob
998 time vexecs 1000 1024 nulljob
999 time vexecs 1000 102400 nulljob
1001 time execs 1000 0 bigjob
1002 time execs 1000 1024 bigjob
1003 time execs 1000 102400 bigjob
1004 time vexecs 1000 0 bigjob
1005 time vexecs 1000 1024 bigjob
1006 time vexecs 1000 102400 bigjob
1007 \*(+K#\*(-K fill environment with ~1024 bytes
1008 setenv a 012345678901234567890123456789012345678901234567890123456780123456789
1009 setenv b 012345678901234567890123456789012345678901234567890123456780123456789
1010 setenv c 012345678901234567890123456789012345678901234567890123456780123456789
1011 setenv d 012345678901234567890123456789012345678901234567890123456780123456789
1012 setenv e 012345678901234567890123456789012345678901234567890123456780123456789
1013 setenv f 012345678901234567890123456789012345678901234567890123456780123456789
1014 setenv g 012345678901234567890123456789012345678901234567890123456780123456789
1015 setenv h 012345678901234567890123456789012345678901234567890123456780123456789
1016 setenv i 012345678901234567890123456789012345678901234567890123456780123456789
1017 setenv j 012345678901234567890123456789012345678901234567890123456780123456789
1018 setenv k 012345678901234567890123456789012345678901234567890123456780123456789
1019 setenv l 012345678901234567890123456789012345678901234567890123456780123456789
1020 setenv m 012345678901234567890123456789012345678901234567890123456780123456789
1021 setenv n 012345678901234567890123456789012345678901234567890123456780123456789
1022 setenv o 012345678901234567890123456789012345678901234567890123456780123456789
1024 time execs 1000 0 nulljob
1025 time execs 1000 1024 nulljob
1026 time execs 1000 102400 nulljob
1027 time execs 1000 0 bigjob
1028 time execs 1000 1024 bigjob
1029 time execs 1000 102400 bigjob