This source file includes following definitions.
- preempt_vmx_c
- test_preempt_vmx
- main
1
2
3
4
5
6
7
8
9
10
11
12
13 #include <stdio.h>
14 #include <unistd.h>
15 #include <sys/syscall.h>
16 #include <sys/time.h>
17 #include <sys/types.h>
18 #include <sys/wait.h>
19 #include <stdlib.h>
20 #include <pthread.h>
21
22 #include "utils.h"
23
24
25 #define PREEMPT_TIME 20
26
27
28
29
30 #define THREAD_FACTOR 8
31
32 __thread vector int varray[] = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10,11,12},
33 {13,14,15,16},{17,18,19,20},{21,22,23,24},
34 {25,26,27,28},{29,30,31,32},{33,34,35,36},
35 {37,38,39,40},{41,42,43,44},{45,46,47,48}};
36
37 int threads_starting;
38 int running;
39
40 extern void preempt_vmx(vector int *varray, int *threads_starting, int *running);
41
42 void *preempt_vmx_c(void *p)
43 {
44 int i, j;
45 srand(pthread_self());
46 for (i = 0; i < 12; i++)
47 for (j = 0; j < 4; j++)
48 varray[i][j] = rand();
49
50
51 preempt_vmx(varray, &threads_starting, &running);
52 return p;
53 }
54
55 int test_preempt_vmx(void)
56 {
57 int i, rc, threads;
58 pthread_t *tids;
59
60 threads = sysconf(_SC_NPROCESSORS_ONLN) * THREAD_FACTOR;
61 tids = malloc(threads * sizeof(pthread_t));
62 FAIL_IF(!tids);
63
64 running = true;
65 threads_starting = threads;
66 for (i = 0; i < threads; i++) {
67 rc = pthread_create(&tids[i], NULL, preempt_vmx_c, NULL);
68 FAIL_IF(rc);
69 }
70
71 setbuf(stdout, NULL);
72
73 printf("\tWaiting for all workers to start...");
74 while(threads_starting)
75 asm volatile("": : :"memory");
76 printf("done\n");
77
78 printf("\tWaiting for %d seconds to let some workers get preempted...", PREEMPT_TIME);
79 sleep(PREEMPT_TIME);
80 printf("done\n");
81
82 printf("\tStopping workers...");
83
84
85
86
87 running = 0;
88 for (i = 0; i < threads; i++) {
89 void *rc_p;
90 pthread_join(tids[i], &rc_p);
91
92
93
94
95
96 if ((long) rc_p)
97 printf("oops\n");
98 FAIL_IF((long) rc_p);
99 }
100 printf("done\n");
101
102 return 0;
103 }
104
105 int main(int argc, char *argv[])
106 {
107 return test_harness(test_preempt_vmx, "vmx_preempt");
108 }