BSD 4_4_Lite2 development
authorCSRG <csrg@ucbvax.Berkeley.EDU>
Tue, 8 Jun 1993 05:24:44 +0000 (21:24 -0800)
committerCSRG <csrg@ucbvax.Berkeley.EDU>
Tue, 8 Jun 1993 05:24:44 +0000 (21:24 -0800)
Work on file usr/src/sys/tests/benchmarks/csw.c

Synthesized-from: CSRG/cd3/4.4BSD-Lite2

usr/src/sys/tests/benchmarks/csw.c [new file with mode: 0644]

diff --git a/usr/src/sys/tests/benchmarks/csw.c b/usr/src/sys/tests/benchmarks/csw.c
new file mode 100644 (file)
index 0000000..8186082
--- /dev/null
@@ -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 <n>
+ *     t2 = time signocsw <n>
+ *     overhead = t1 - 2 * t2;
+ */
+#include <signal.h>
+
+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);
+}