Add src/test and throw in some of the ad-hoc timing and testing programs
authorMatthew Dillon <dillon@dragonflybsd.org>
Tue, 12 Aug 2003 02:29:44 +0000 (02:29 +0000)
committerMatthew Dillon <dillon@dragonflybsd.org>
Tue, 12 Aug 2003 02:29:44 +0000 (02:29 +0000)
that have been written.

20 files changed:
test/sysmsg/Makefile [new file with mode: 0644]
test/sysmsg/sendsys.h [new file with mode: 0644]
test/sysmsg/sysmsg1.c [new file with mode: 0644]
test/sysmsg/sysmsg2.c [new file with mode: 0644]
test/sysperf/Makefile [new file with mode: 0644]
test/sysperf/blib.c [new file with mode: 0644]
test/sysperf/blib.h [new file with mode: 0644]
test/sysperf/fork1.c [new file with mode: 0644]
test/sysperf/getuid_msg.c [new file with mode: 0644]
test/sysperf/loop1.c [new file with mode: 0644]
test/sysperf/loop2.c [new file with mode: 0644]
test/sysperf/loop3.c [new file with mode: 0644]
test/sysperf/mtx.s [new file with mode: 0644]
test/sysperf/mutex2.c [new file with mode: 0644]
test/sysperf/pipe1.c [new file with mode: 0644]
test/sysperf/quicksw1.c [new file with mode: 0644]
test/sysperf/sw.S [new file with mode: 0644]
test/sysperf/syscall1.c [new file with mode: 0644]
test/sysperf/syscall2.c [new file with mode: 0644]
test/sysperf/syscall3.c [new file with mode: 0644]

diff --git a/test/sysmsg/Makefile b/test/sysmsg/Makefile
new file mode 100644 (file)
index 0000000..49d346b
--- /dev/null
@@ -0,0 +1,17 @@
+# $DragonFly: src/test/sysmsg/Makefile,v 1.1 2003/08/12 02:29:41 dillon Exp $
+#
+
+TARGETS=/tmp/sysmsg1 /tmp/sysmsg2
+
+CFLAGS= -O2 -g -I/usr/src/sys
+
+all:   $(TARGETS)
+
+/tmp/sysmsg1: sysmsg1.c sendsys.h
+       $(CC) $(CFLAGS) sysmsg1.c -o /tmp/sysmsg1
+
+/tmp/sysmsg2: sysmsg2.c sendsys.h
+       $(CC) $(CFLAGS) sysmsg2.c -o /tmp/sysmsg2
+
+clean:
+       rm -f $(TARGETS)
diff --git a/test/sysmsg/sendsys.h b/test/sysmsg/sendsys.h
new file mode 100644 (file)
index 0000000..11026a7
--- /dev/null
@@ -0,0 +1,15 @@
+/*
+ * SENDSYS.H
+ *
+ * $DragonFly: src/test/sysmsg/Attic/sendsys.h,v 1.1 2003/08/12 02:29:41 dillon Exp $
+ */
+
+static __inline
+int
+sendsys(void *port, void *msg, int msgsize)
+{
+    int error;
+    __asm __volatile("int $0x81" : "=a"(error), "=c"(msg), "=d"(msgsize) : "0"(port), "1"(msg), "2"(msgsize) : "memory");
+    return(error);
+}
+
diff --git a/test/sysmsg/sysmsg1.c b/test/sysmsg/sysmsg1.c
new file mode 100644 (file)
index 0000000..e7d2780
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * sysmsg1.c
+ *
+ * $DragonFly: src/test/sysmsg/sysmsg1.c,v 1.1 2003/08/12 02:29:41 dillon Exp $
+ */
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/msgport.h>
+#include <sys/time.h>
+#include <sys/syscall.h>
+#include <sys/sysproto.h>
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <time.h>
+#include "sendsys.h"
+
+int
+main(int ac, char **av)
+{
+    struct write_args writemsg;
+    struct nanosleep_args sleepmsg;
+    struct timespec ts1;
+    struct timespec ts2;
+    int error;
+
+    printf("synchronous sendsys() test: write 'hello!' and 1.5 second nanosleep\n");
+    bzero(&writemsg, sizeof(writemsg));
+    writemsg.usrmsg.umsg.ms_cmd = SYS_write;
+    writemsg.usrmsg.umsg.ms_flags = 0;
+    writemsg.fd = 1;
+    writemsg.buf = "hello!\n";
+    writemsg.nbyte = 7;
+    error = sendsys(NULL, &writemsg.usrmsg, sizeof(writemsg));
+    printf("error code %d\n", error);
+    if (error != 0)
+       exit(1);
+
+    bzero(&sleepmsg, sizeof(sleepmsg));
+    sleepmsg.usrmsg.umsg.ms_cmd = SYS_nanosleep;
+    sleepmsg.usrmsg.umsg.ms_flags = 0; /* NOTE: not async */
+    sleepmsg.rqtp = &ts1;
+    sleepmsg.rmtp = &ts2;
+    ts1.tv_sec = 1;
+    ts1.tv_nsec = 500 * 1000000;
+    error = sendsys(NULL, &sleepmsg.usrmsg, sizeof(sleepmsg));
+    printf("error code %d\n", error);
+    if (error == EASYNC) {
+       struct nanosleep_args *rmsg;
+       printf("async return, waiting...");
+       fflush(stdout);
+       for (;;) {
+           rmsg = (void *)sendsys(NULL, NULL, -1);
+           printf("    rmsg %p\n", rmsg);
+           if (rmsg == &sleepmsg)
+               break;
+           usleep(1000000 / 10);
+       }
+       printf("async return error %d\n", sleepmsg.usrmsg.umsg.ms_error);
+    } else if (error) {
+       printf("error %d\n", error);
+    } 
+    exit(0);
+}
+
diff --git a/test/sysmsg/sysmsg2.c b/test/sysmsg/sysmsg2.c
new file mode 100644 (file)
index 0000000..25847df
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * sysmsg2.c
+ *
+ * $DragonFly: src/test/sysmsg/sysmsg2.c,v 1.1 2003/08/12 02:29:41 dillon Exp $
+ */
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/msgport.h>
+#include <sys/time.h>
+#include <sys/syscall.h>
+#include <sys/sysproto.h>
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <time.h>
+#include "sendsys.h"
+
+int
+main(int ac, char **av)
+{
+    struct write_args writemsg;
+    struct nanosleep_args sleepmsg;
+    struct timespec ts1;
+    struct timespec ts2;
+    int error;
+
+    printf("test synchronous syscall msg write 'hello!'\n");
+    printf("test ASynchronous syscall msg nanosleep for 1.5 seconds\n");
+    printf("WARNING! super-user only, do not ^C the test program!\n");
+
+    bzero(&writemsg, sizeof(writemsg));
+    writemsg.usrmsg.umsg.ms_cmd = SYS_write;
+    writemsg.usrmsg.umsg.ms_flags = 0;
+    writemsg.fd = 1;
+    writemsg.buf = "hello!\n";
+    writemsg.nbyte = 7;
+    error = sendsys(NULL, &writemsg.usrmsg, sizeof(writemsg));
+    printf("error code %d\n", error);
+    if (error != 0)
+       exit(1);
+
+    bzero(&sleepmsg, sizeof(sleepmsg));
+    sleepmsg.usrmsg.umsg.ms_cmd = SYS_nanosleep;
+    sleepmsg.usrmsg.umsg.ms_flags = MSGF_ASYNC;
+    sleepmsg.rqtp = &ts1;
+    sleepmsg.rmtp = &ts2;
+    ts1.tv_sec = 1;
+    ts1.tv_nsec = 500 * 1000000;
+    error = sendsys(NULL, &sleepmsg.usrmsg, sizeof(sleepmsg));
+    printf("error code %d\n", error);
+    if (error == EASYNC) {
+       struct nanosleep_args *rmsg;
+
+       printf("error %d is async return, waiting...", EASYNC);
+       fflush(stdout);
+       for (;;) {
+           rmsg = (void *)sendsys(NULL, NULL, -1);
+           printf("    rmsg %p\n", rmsg);
+           if (rmsg == &sleepmsg)
+               break;
+           usleep(1000000 / 10);
+       }
+       printf("async return error %d\n", sleepmsg.usrmsg.umsg.ms_error);
+    } else if (error) {
+       printf("error %d\n", error);
+    } 
+    exit(0);
+}
+
diff --git a/test/sysperf/Makefile b/test/sysperf/Makefile
new file mode 100644 (file)
index 0000000..a373de3
--- /dev/null
@@ -0,0 +1,52 @@
+#
+# $DragonFly: src/test/sysperf/Makefile,v 1.1 2003/08/12 02:29:44 dillon Exp $
+#
+
+TARGETS=/tmp/sc1 /tmp/sc2 /tmp/sc3 \
+       /tmp/loop1 /tmp/loop2 /tmp/loop3 \
+       /tmp/mt2 \
+       /tmp/fork1 /tmp/pipe1 \
+       /tmp/sw1 /tmp/sw2 /tmp/sw3
+
+CFLAGS= -O2 -g -I/usr/src/sys
+
+all:   $(TARGETS)
+
+/tmp/sc1: syscall1.c getuid_msg.c blib.c
+       $(CC) $(CFLAGS) syscall1.c blib.c -o /tmp/sc1
+
+/tmp/sc2: syscall2.c getuid_msg.c blib.c
+       $(CC) $(CFLAGS) syscall2.c getuid_msg.c blib.c -o /tmp/sc2
+
+/tmp/sc3: syscall3.c getuid_msg.c blib.c
+       $(CC) $(CFLAGS) syscall3.c getuid_msg.c blib.c -o /tmp/sc3
+
+/tmp/fork1: fork1.c blib.c
+       $(CC) $(CFLAGS) fork1.c blib.c -o /tmp/fork1
+
+/tmp/pipe1: pipe1.c blib.c
+       $(CC) $(CFLAGS) pipe1.c blib.c -o /tmp/pipe1
+
+/tmp/loop1: loop1.c blib.c
+       $(CC) $(CFLAGS) loop1.c blib.c -o /tmp/loop1
+
+/tmp/loop2: loop2.c blib.c
+       $(CC) $(CFLAGS) loop2.c blib.c -o /tmp/loop2
+
+/tmp/loop3: loop3.c blib.c
+       $(CC) $(CFLAGS) loop3.c blib.c -o /tmp/loop3
+
+/tmp/mt2: mutex2.c blib.c mtx.s
+       $(CC) $(CFLAGS) mutex2.c blib.c mtx.s -o /tmp/mt2
+
+/tmp/sw1: quicksw1.c blib.c sw.S
+       $(CC) $(CFLAGS) -DUSE_ALL quicksw1.c blib.c sw.S -o /tmp/sw1
+
+/tmp/sw2: quicksw1.c blib.c sw.S
+       $(CC) $(CFLAGS) -DUSE_CALLU1 quicksw1.c blib.c sw.S -o /tmp/sw2
+
+/tmp/sw3: quicksw1.c blib.c sw.S
+       $(CC) $(CFLAGS) -DUSE_CALLU2 quicksw1.c blib.c sw.S -o /tmp/sw3
+
+clean:
+       rm -f $(TARGETS)
diff --git a/test/sysperf/blib.c b/test/sysperf/blib.c
new file mode 100644 (file)
index 0000000..49d419a
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * BLIB.C
+ *
+ * Simple benchmarking library
+ *
+ * $DragonFly: src/test/sysperf/blib.c,v 1.1 2003/08/12 02:29:44 dillon Exp $
+ */
+
+#include <sys/types.h>
+#include <sys/time.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+
+static struct timeval tv1;
+static struct timeval tv2;
+
+void
+start_timing(void)
+{
+    gettimeofday(&tv1, NULL);
+}
+
+int
+stop_timing(long long count, const char *ctl, ...)
+{
+    long long us;
+    va_list va;
+
+    gettimeofday(&tv2, NULL);
+    us = (tv2.tv_usec - tv1.tv_usec) + (tv2.tv_sec - tv1.tv_sec) * 1000000LL;
+    if (ctl == NULL)   /* dummy call to pre-cache */
+       return(us > 1000000);
+
+    va_start(va, ctl);
+    vprintf(ctl, va);
+    va_end(va);
+
+    printf("%6.3fs %lld loops = %6.3fuS/loop\n",
+       (double)us / 1000000.0,
+       count,
+       (double)us / (double)count
+    );
+    return(0);
+}
+
+long long
+get_timing(void)
+{
+    long long us;
+
+    gettimeofday(&tv2, NULL);
+    us = (tv2.tv_usec - tv1.tv_usec) + (tv2.tv_sec - tv1.tv_sec) * 1000000LL;
+    return(us);
+}
+
diff --git a/test/sysperf/blib.h b/test/sysperf/blib.h
new file mode 100644 (file)
index 0000000..7adc7fa
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+ * BLIB.C
+ *
+ * Simple benchmarking library
+ *
+ * $DragonFly: src/test/sysperf/blib.h,v 1.1 2003/08/12 02:29:44 dillon Exp $
+ */
+
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/mman.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <unistd.h>
+#include <string.h>
+
+void start_timing(void);
+int stop_timing(long long count, const char *ctl, ...);
+long long get_timing(void);
+
diff --git a/test/sysperf/fork1.c b/test/sysperf/fork1.c
new file mode 100644 (file)
index 0000000..e36e3ad
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * fork1.c
+ *
+ * $DragonFly: src/test/sysperf/fork1.c,v 1.1 2003/08/12 02:29:44 dillon Exp $
+ */
+
+#include "blib.h"
+
+int
+main(int ac, char **av)
+{
+    int j;
+
+    start_timing();
+    for (j = 0; j < 10000; ++j) {
+       if (fork() == 0) {
+           _exit(1);
+       } else {
+           while (wait(NULL) > 0);
+       }
+    }
+    stop_timing(j, "fork/exit/wait:");
+    return(0);
+}
+
diff --git a/test/sysperf/getuid_msg.c b/test/sysperf/getuid_msg.c
new file mode 100644 (file)
index 0000000..084e0d8
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * getuid_msg.c
+ *
+ * $DragonFly: src/test/sysperf/getuid_msg.c,v 1.1 2003/08/12 02:29:44 dillon Exp $
+ */
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/msgport.h>
+#include <sys/syscall.h>
+#include <sys/sysproto.h>
+#include <sys/sysunion.h>
+
+#include "../sysmsg/sendsys.h"
+
+int
+getuid_msg(void)
+{
+    static struct getuid_args uidmsg;
+    int error;
+
+    /*
+     * In real life use a properly pre-initialized message, e.g. stowed in 
+     * the thread structure or cached in a linked list somewhere.
+     * bzero(&sysmsg.lmsg, sizeof(sysmsg.lmsg))
+     */
+    uidmsg.usrmsg.umsg.ms_cmd = SYS_getuid;    /* XXX lwkt_init_msg() */
+    uidmsg.usrmsg.umsg.ms_flags = MSGF_DONE;
+
+    error = sendsys(NULL, &uidmsg, sizeof(uidmsg));
+    if (error) {
+       printf("error %d\n", error);
+       exit(1);
+    }
+    return(uidmsg.usrmsg.umsg.u.ms_result32);
+}
+
diff --git a/test/sysperf/loop1.c b/test/sysperf/loop1.c
new file mode 100644 (file)
index 0000000..a206505
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * loop1.c
+ *
+ * used as a helper to test AST delivery.  Loops in user mode for 5 seconds.
+ * $DragonFly: src/test/sysperf/loop1.c,v 1.1 2003/08/12 02:29:44 dillon Exp $
+ */
+
+#include "blib.h"
+
+#define LOOP 100000000
+
+static void nop() { }
+
+int
+main(int ac, char **av)
+{
+    int i;
+
+    printf("SMP contention, userland-only loop (run one, then run ncpu copies in parallel\n");
+    start_timing();
+    for (i = 0; i < LOOP; ++i)
+       nop();
+    stop_timing(LOOP, "loop1/user");
+    return(0);
+}
+
diff --git a/test/sysperf/loop2.c b/test/sysperf/loop2.c
new file mode 100644 (file)
index 0000000..ada6b82
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * loop2.c
+ *
+ * Used as a helper to test AST delivery.  Loops in user mode for a few
+ * seconds.  This one forks and runs the loop in two processes.
+ *
+ * $DragonFly: src/test/sysperf/loop2.c,v 1.1 2003/08/12 02:29:44 dillon Exp $
+ */
+
+#include "blib.h"
+
+#define LOOP 100000000
+
+static void nop() { }
+
+int
+main(int ac, char **av)
+{
+    int i;
+    pid_t pid;
+
+    printf("SMP contention, userland-only loop, duel-forks.  Run just one\n");
+
+    start_timing();
+    if (fork() == 0) {
+       for (i = 0; i < LOOP; ++i)
+           nop();
+       _exit(1);
+    } else {
+       for (i = 0; i < LOOP; ++i)
+           nop();
+       while (wait(NULL) > 0);
+       stop_timing(LOOP, "loop2/2xfork");
+    }
+    return(0);
+}
+
diff --git a/test/sysperf/loop3.c b/test/sysperf/loop3.c
new file mode 100644 (file)
index 0000000..dd4d8ee
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * loop3.c
+ *
+ * used as a helper to test AST delivery.  This is an endless loop.
+ *
+ * $DragonFly: src/test/sysperf/loop3.c,v 1.1 2003/08/12 02:29:44 dillon Exp $
+ */
+
+#include "blib.h"
+
+static void nop() { }
+
+int
+main(int ac, char **av)
+{
+    int i;
+
+    printf("(non timing) one process, endless loop in userland\n");
+    for (;;)
+       nop();
+    return(0);
+}
+
diff --git a/test/sysperf/mtx.s b/test/sysperf/mtx.s
new file mode 100644 (file)
index 0000000..c16596e
--- /dev/null
@@ -0,0 +1,19 @@
+               /*
+                * $DragonFly: src/test/sysperf/mtx.s,v 1.1 2003/08/12 02:29:44 dillon Exp $
+                */
+               .text
+               .globl  get_mtx
+               .globl  rel_mtx
+
+get_mtx:
+               movl    mtx,%edx
+               movl    4(%esp),%ecx
+1:             subl    %eax,%eax
+               lock cmpxchgl %ecx,(%edx)
+               jnz     1b
+               ret
+
+rel_mtx:
+               movl    mtx,%edx
+               movl $0,(%edx)
+               ret
diff --git a/test/sysperf/mutex2.c b/test/sysperf/mutex2.c
new file mode 100644 (file)
index 0000000..5990d91
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * mutex2.c
+ *
+ * $DragonFly: src/test/sysperf/mutex2.c,v 1.1 2003/08/12 02:29:44 dillon Exp $
+ */
+
+#include "blib.h"
+
+int *mtx;
+
+int
+main(int ac, char **av)
+{
+    long long count = 0;
+    long long max;
+    int j;
+    int *counter;
+    pid_t pid;
+
+    printf("Test simple locked bus cycle mutex latency\n");
+    printf("auto-forks two processes for the test with shared memory\n");
+    printf("This test is only useful on a SMP box\n");
+
+    start_timing();
+    mtx = mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANON, -1, 0);
+    counter = mtx + 64;
+    while (stop_timing(0, NULL) == 0) {
+       for (j = 0; j < 100; ++j) {
+           get_mtx(1);
+           rel_mtx();
+       }
+       count += 100;
+    }
+    max = count;
+    *mtx = 0;
+    if ((pid = fork()) == 0) {
+       for (;;) {
+           for (j = 0; j < 100; ++j) {
+               get_mtx(2);
+               rel_mtx();      /* release */
+               ++counter[128];
+           }
+       }
+    } else {
+       start_timing();
+       for (count = 0; count < max; count += 100) {
+           for (j = 0; j < 100; ++j) {
+               get_mtx(1);
+               rel_mtx();      /* release */
+               ++counter[64];
+           }
+       }
+       stop_timing(count, "getuid()");
+       printf("proc1=%d proc2=%d\n", counter[64], counter[128]);
+       kill(pid, 9);
+    }
+    return(0);
+}
+
diff --git a/test/sysperf/pipe1.c b/test/sysperf/pipe1.c
new file mode 100644 (file)
index 0000000..50a2d68
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * pipe1.c
+ *
+ * $DragonFly: src/test/sysperf/pipe1.c,v 1.1 2003/08/12 02:29:44 dillon Exp $
+ */
+
+#include "blib.h"
+
+int
+main(int ac, char **av)
+{
+    long long count = 0;
+    long long max;
+    char c;
+    int j;
+    int fds[2];
+
+    printf("tests full duplex pipe 1write,2read,2write,1read loop\n");
+    if (pipe(fds)) {
+       perror("pipe");
+       exit(1);
+    }
+    if (fork() == 0) {
+       /*
+        * child process
+        */
+       close(fds[0]);
+       while (read(fds[1], &c, 1) == 1) {
+           write(fds[1], &c, 1);
+       }
+       _exit(0);
+    } else {
+       /* 
+        * parent process.
+        */
+       close(fds[1]);
+       write(fds[0], &c, 1);   /* prime the caches */
+       read(fds[0], &c, 1);
+       start_timing();
+       for (j = 0; j < 100000; ++j) {
+           write(fds[0], &c, 1);
+           if (read(fds[0], &c, 1) != 1) {
+               fprintf(stderr, "broken pipe during test\n");
+               exit(1);
+           }
+       }
+       stop_timing(j, "full duplex pipe / 1char:");
+       close(fds[0]);
+       while(wait(NULL) >= 0);
+    }
+    return(0);
+}
+
diff --git a/test/sysperf/quicksw1.c b/test/sysperf/quicksw1.c
new file mode 100644 (file)
index 0000000..7e10731
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * quicksw1.c
+ *
+ * $DragonFly: src/test/sysperf/quicksw1.c,v 1.1 2003/08/12 02:29:44 dillon Exp $
+ */
+
+#include "blib.h"
+
+void qswitch(int **oldsw, int *newsw);
+void qstart(int *newsw);
+int *qinit(void *topstk, void *func, void *arg);
+
+static void do_task1(void *arg);
+static void do_task2(void *arg);
+
+int *task1;
+int *task2;
+char stk1[16384];
+char stk2[16384];
+int count;
+
+int
+main(int ac, char **av)
+{
+#if USE_ALL
+    printf("userthread switching test (nonfp) using pushal/popal\n");
+#elif USE_CALLU1
+    printf("userthread switching test (nonfp) using pushl (call-save only)\n");
+#elif USE_CALLU2
+    printf("userthread switching test (nonfp) using subl $N,%%esp;movl (call-save only)\n");
+#else
+#error "The switch method wasn't defined with -D"
+#endif
+
+    task1 = qinit(stk1 + sizeof(stk1), do_task1, NULL);
+    task2 = qinit(stk2 + sizeof(stk2), do_task2, NULL);
+    start_timing();
+    qstart(task1);
+}
+
+static void
+do_task1(void *arg)
+{
+    for (;;) {
+       qswitch(&task1, task2);
+       if (++count > 10000000) {
+               stop_timing(count, "uthread_switch");
+               exit(0);
+       }
+    }
+}
+
+static void
+do_task2(void *arg)
+{
+    for (;;) {
+       ++count;
+       qswitch(&task2, task1);
+    }
+}
+
diff --git a/test/sysperf/sw.S b/test/sysperf/sw.S
new file mode 100644 (file)
index 0000000..8b81a5b
--- /dev/null
@@ -0,0 +1,83 @@
+
+               /*
+                * sw.S
+                *
+                * $DragonFly: src/test/sysperf/sw.S,v 1.1 2003/08/12 02:29:44 dillon Exp $
+                */
+               .text
+               .globl  qswitch, qrestore, qinit, qirestore, qstart
+
+#if USE_ALL
+
+#define PUSHAL         pushal
+#define POPAL          popal
+
+#endif
+
+#if USE_CALLU1
+
+#define PUSHAL         \
+       pushl   %ebx ;  \
+       pushl   %esi ;  \
+       pushl   %edi ;  \
+       pushl   %ebp 
+
+#define POPAL          \
+       popl    %ebp ;  \
+       popl    %edi ;  \
+       popl    %esi ;  \
+       popl    %ebx
+
+#endif
+
+#if USE_CALLU2
+
+#define PUSHAL                 \
+       subl    $16,%esp ;      \
+       movl    %ebx,(%esp) ;   \
+       movl    %esi,4(%esp) ;  \
+       movl    %edi,8(%esp) ;  \
+       movl    %ebp,12(%esp)
+
+#define POPAL                  \
+       movl    (%esp),%ebx ;   \
+       movl    4(%esp),%esi ;  \
+       movl    8(%esp),%edi ;  \
+       movl    12(%esp),%ebp ; \
+       addl    $16,%esp
+
+#endif
+
+               /* qswitch(&olddesc, newdesc) */
+qswitch:
+               movl    8(%esp),%eax    /* new state */
+               movl    4(%esp),%edx    /* save old state */
+               PUSHAL
+               pushl   $qrestore
+               movl    %esp,(%edx)
+               movl    %eax,%esp
+               ret
+
+               /* qstart(newdesc) */
+qstart:
+               movl    4(%esp),%esp
+               ret
+
+qrestore:
+               POPAL
+               ret
+
+               /* newdesc = qinit(topofstk, func, arg) */
+qinit:
+               movl    4(%esp),%eax
+               subl    $16,%eax
+               movl    $qirestore,0(%eax)
+               movl    8(%esp),%ecx
+               movl    %ecx,4(%eax)
+               movl    $0,8(%eax)
+               movl    12(%esp),%ecx
+               movl    %ecx,12(%eax)
+               ret /* return eax */
+
+qirestore:
+               ret
diff --git a/test/sysperf/syscall1.c b/test/sysperf/syscall1.c
new file mode 100644 (file)
index 0000000..551bfa8
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * syscall1.c
+ *
+ * $DragonFly: src/test/sysperf/syscall1.c,v 1.1 2003/08/12 02:29:44 dillon Exp $
+ */
+
+#include "blib.h"
+
+int
+main(int ac, char **av)
+{
+    long long count = 0;
+    long long max;
+    int j;
+
+    printf("timing standard getuid() syscall\n");
+
+    start_timing();
+    while (stop_timing(0, NULL) == 0) {
+       for (j = 0; j < 100; ++j)
+           getuid();
+       count += 100;
+    }
+    max = count;
+    start_timing();
+    for (count = 0; count < max; count += 100) {
+       for (j = 0; j < 100; ++j)
+           getuid();
+    }
+    stop_timing(count, "getuid()");
+    return(0);
+}
+
diff --git a/test/sysperf/syscall2.c b/test/sysperf/syscall2.c
new file mode 100644 (file)
index 0000000..7dc104f
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * syscall2.c
+ *
+ * $DragonFly: src/test/sysperf/syscall2.c,v 1.1 2003/08/12 02:29:44 dillon Exp $
+ */
+
+#include "blib.h"
+
+extern int getuid_msg(void);
+
+int
+main(int ac, char **av)
+{
+    long long count = 0;
+    long long max;
+    int j;
+
+    printf("timing getuid_msg syscall\n");
+
+    start_timing();
+    while (stop_timing(0, NULL) == 0) {
+       for (j = 0; j < 100; ++j)
+           getuid_msg();
+       count += 100;
+    }
+    max = count;
+    start_timing();
+    for (count = 0; count < max; count += 100) {
+       for (j = 0; j < 100; ++j)
+           getuid_msg();
+    }
+    stop_timing(count, "getuid()");
+    return(0);
+}
+
diff --git a/test/sysperf/syscall3.c b/test/sysperf/syscall3.c
new file mode 100644 (file)
index 0000000..7d9820f
--- /dev/null
@@ -0,0 +1,18 @@
+/*
+ * syscall3.c
+ *
+ * $DragonFly: src/test/sysperf/syscall3.c,v 1.1 2003/08/12 02:29:44 dillon Exp $
+ */
+
+#include "blib.h"
+
+int
+main(int ac, char **av)
+{
+    printf("(non timing) one process, endless loop calling getuid_msg()\n");
+    for (;;) 
+       getuid();
+    /* not reached */
+    return(0);
+}
+