A program which sets up a TLS segment and then loops with random sleeps
[dragonfly.git] / test / sysperf / quicksw1.c
1 /*
2  * quicksw1.c
3  *
4  * $DragonFly: src/test/sysperf/quicksw1.c,v 1.1 2003/08/12 02:29:44 dillon Exp $
5  */
6
7 #include "blib.h"
8
9 void qswitch(int **oldsw, int *newsw);
10 void qstart(int *newsw);
11 int *qinit(void *topstk, void *func, void *arg);
12
13 static void do_task1(void *arg);
14 static void do_task2(void *arg);
15
16 int *task1;
17 int *task2;
18 char stk1[16384];
19 char stk2[16384];
20 int count;
21
22 int
23 main(int ac, char **av)
24 {
25 #if USE_ALL
26     printf("userthread switching test (nonfp) using pushal/popal\n");
27 #elif USE_CALLU1
28     printf("userthread switching test (nonfp) using pushl (call-save only)\n");
29 #elif USE_CALLU2
30     printf("userthread switching test (nonfp) using subl $N,%%esp;movl (call-save only)\n");
31 #else
32 #error "The switch method wasn't defined with -D"
33 #endif
34
35     task1 = qinit(stk1 + sizeof(stk1), do_task1, NULL);
36     task2 = qinit(stk2 + sizeof(stk2), do_task2, NULL);
37     start_timing();
38     qstart(task1);
39 }
40
41 static void
42 do_task1(void *arg)
43 {
44     for (;;) {
45         qswitch(&task1, task2);
46         if (++count > 10000000) {
47                 stop_timing(count, "uthread_switch");
48                 exit(0);
49         }
50     }
51 }
52
53 static void
54 do_task2(void *arg)
55 {
56     for (;;) {
57         ++count;
58         qswitch(&task2, task1);
59     }
60 }
61