0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #include <stdio.h>
0014 #include <unistd.h>
0015 #include <sys/syscall.h>
0016 #include <sys/time.h>
0017 #include <sys/types.h>
0018 #include <sys/wait.h>
0019 #include <stdlib.h>
0020 #include <pthread.h>
0021
0022 #include "utils.h"
0023
0024
0025 #define PREEMPT_TIME 20
0026
0027
0028
0029
0030 #define THREAD_FACTOR 8
0031
0032 __thread vector int varray[] = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10,11,12},
0033 {13,14,15,16},{17,18,19,20},{21,22,23,24},
0034 {25,26,27,28},{29,30,31,32},{33,34,35,36},
0035 {37,38,39,40},{41,42,43,44},{45,46,47,48}};
0036
0037 int threads_starting;
0038 int running;
0039
0040 extern void preempt_vmx(vector int *varray, int *threads_starting, int *running);
0041
0042 void *preempt_vmx_c(void *p)
0043 {
0044 int i, j;
0045 srand(pthread_self());
0046 for (i = 0; i < 12; i++)
0047 for (j = 0; j < 4; j++)
0048 varray[i][j] = rand();
0049
0050
0051 preempt_vmx(varray, &threads_starting, &running);
0052 return p;
0053 }
0054
0055 int test_preempt_vmx(void)
0056 {
0057 int i, rc, threads;
0058 pthread_t *tids;
0059
0060
0061 SKIP_IF(!have_hwcap2(PPC_FEATURE2_ARCH_2_07));
0062
0063 threads = sysconf(_SC_NPROCESSORS_ONLN) * THREAD_FACTOR;
0064 tids = malloc(threads * sizeof(pthread_t));
0065 FAIL_IF(!tids);
0066
0067 running = true;
0068 threads_starting = threads;
0069 for (i = 0; i < threads; i++) {
0070 rc = pthread_create(&tids[i], NULL, preempt_vmx_c, NULL);
0071 FAIL_IF(rc);
0072 }
0073
0074 setbuf(stdout, NULL);
0075
0076 printf("\tWaiting for all workers to start...");
0077 while(threads_starting)
0078 asm volatile("": : :"memory");
0079 printf("done\n");
0080
0081 printf("\tWaiting for %d seconds to let some workers get preempted...", PREEMPT_TIME);
0082 sleep(PREEMPT_TIME);
0083 printf("done\n");
0084
0085 printf("\tStopping workers...");
0086
0087
0088
0089
0090 running = 0;
0091 for (i = 0; i < threads; i++) {
0092 void *rc_p;
0093 pthread_join(tids[i], &rc_p);
0094
0095
0096
0097
0098
0099 if ((long) rc_p)
0100 printf("oops\n");
0101 FAIL_IF((long) rc_p);
0102 }
0103 printf("done\n");
0104
0105 return 0;
0106 }
0107
0108 int main(int argc, char *argv[])
0109 {
0110 return test_harness(test_preempt_vmx, "vmx_preempt");
0111 }