Import Upstream version 1.8.5
[hcoop/debian/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 <afsconfig.h>
11 #include <afs/param.h>
12
13
14 #include <stdio.h>
15 #include <sys/time.h>
16 #include "lwp.h"
17
18 char semaphore;
19
20 int
21 OtherProcess()
22 {
23 for (;;) {
24 LWP_SignalProcess(&semaphore);
25 }
26 }
27
28 main(argc, argv)
29 int argc;
30 char *argv[];
31 {
32 struct timeval t1, t2;
33 int pid, otherpid;
34 int i, count, x;
35 char *waitarray[2];
36 static char c[] = "OtherProcess";
37
38 count = atoi(argv[1]);
39
40 assert(LWP_InitializeProcessSupport(0, (PROCESS *) & pid) == LWP_SUCCESS);
41 assert(LWP_CreateProcess
42 (OtherProcess, 4096, 0, 0, c,
43 (PROCESS *) & otherpid) == LWP_SUCCESS);
44
45 waitarray[0] = &semaphore;
46 waitarray[1] = 0;
47 gettimeofday(&t1, NULL);
48 for (i = 0; i < count; i++) {
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",
55 x / 1000, count, (float)(x / count));
56 }