From 13c2688c4e52aeff1874a1e23abff3db3488f458 Mon Sep 17 00:00:00 2001 From: CSRG Date: Mon, 7 Jun 1993 21:24:44 -0800 Subject: [PATCH] BSD 4_4_Lite2 development Work on file usr/src/sys/tests/benchmarks/csw.c Synthesized-from: CSRG/cd3/4.4BSD-Lite2 --- usr/src/sys/tests/benchmarks/csw.c | 54 ++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 usr/src/sys/tests/benchmarks/csw.c diff --git a/usr/src/sys/tests/benchmarks/csw.c b/usr/src/sys/tests/benchmarks/csw.c new file mode 100644 index 0000000000..8186082d00 --- /dev/null +++ b/usr/src/sys/tests/benchmarks/csw.c @@ -0,0 +1,54 @@ +/* + * 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 + +void 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 (;;) + sigpause(0); +} + +void +sigsub() +{ + static mustreset = 1; + void (*osig)(); + + if (mustreset) { + osig = signal(SIGALRM, sigsub); + if (osig == sigsub) + mustreset = 0; + } + kill(otherpid, SIGALRM); + if (--nsigs <= 0) + exit(0); +} -- 2.20.1