afsconfig-and-rcsid-all-around-20010705
[openafs.git] / src / lwp / test / test.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 #include <afs/param.h>
11 #include <afsconfig.h>
12
13 RCSID("$Header$");
14
15 #include <stdio.h>
16 #include <sys/time.h>
17 #include <potpourri.h>
18 #include "lwp.h"
19
20 char semaphore;
21
22 int OtherProcess()
23     {
24     for(;;)
25         {
26         LWP_SignalProcess(&semaphore);
27         }
28     }
29
30 main(argc, argv)
31 int argc; char *argv[];
32     {
33     struct timeval t1, t2;
34     int pid, otherpid;
35     register int i,  count, x;
36     char *waitarray[2];
37     static char c[] = "OtherProcess";
38     
39     count = atoi(argv[1]);
40
41     assert(LWP_InitializeProcessSupport(0, &pid) == LWP_SUCCESS);
42     assert(LWP_CreateProcess(OtherProcess,4096,0, 0, c, &otherpid) == LWP_SUCCESS);
43
44     waitarray[0] = &semaphore;
45     waitarray[1] = 0;
46     gettimeofday(&t1, NULL);
47     for (i = 0; i < count; i++)
48         {
49         LWP_MwaitProcess(1, waitarray, 1);
50         }
51     gettimeofday(&t2, NULL);
52
53     x = (t2.tv_sec -t1.tv_sec)*1000000 + (t2.tv_usec - t1.tv_usec);
54     printf("%d milliseconds for %d MWaits (%f usec per Mwait and Signal)\n", x/1000, count, (float)(x/count));
55     }