2 * Copyright 2015, Cyril Bur, IBM Corp.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
9 * This test attempts to see if the VMX registers change across preemption.
10 * Two things should be noted here a) The check_vmx function in asm only checks
11 * the non volatile registers as it is reused from the syscall test b) There is
12 * no way to be sure preemption happened so this test just uses many threads
13 * and a long wait. As such, a successful test doesn't mean much but a failure
19 #include <sys/syscall.h>
21 #include <sys/types.h>
28 /* Time to wait for workers to get preempted (seconds) */
29 #define PREEMPT_TIME 20
31 * Factor by which to multiply number of online CPUs for total number of
34 #define THREAD_FACTOR 8
36 __thread vector int varray[] = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10,11,12},
37 {13,14,15,16},{17,18,19,20},{21,22,23,24},
38 {25,26,27,28},{29,30,31,32},{33,34,35,36},
39 {37,38,39,40},{41,42,43,44},{45,46,47,48}};
44 extern void preempt_vmx(vector int *varray, int *threads_starting, int *running);
46 void *preempt_vmx_c(void *p)
49 srand(pthread_self());
50 for (i = 0; i < 12; i++)
51 for (j = 0; j < 4; j++)
52 varray[i][j] = rand();
54 /* Test fails if it ever returns */
55 preempt_vmx(varray, &threads_starting, &running);
59 int test_preempt_vmx(void)
64 threads = sysconf(_SC_NPROCESSORS_ONLN) * THREAD_FACTOR;
65 tids = malloc(threads * sizeof(pthread_t));
69 threads_starting = threads;
70 for (i = 0; i < threads; i++) {
71 rc = pthread_create(&tids[i], NULL, preempt_vmx_c, NULL);
76 /* Not really nessesary but nice to wait for every thread to start */
77 printf("\tWaiting for all workers to start...");
78 while(threads_starting)
79 asm volatile("": : :"memory");
82 printf("\tWaiting for %d seconds to let some workers get preempted...", PREEMPT_TIME);
86 printf("\tStopping workers...");
88 * Working are checking this value every loop. In preempt_vmx 'cmpwi r5,0; bne 2b'.
89 * r5 will have loaded the value of running.
92 for (i = 0; i < threads; i++) {
94 pthread_join(tids[i], &rc_p);
97 * Harness will say the fail was here, look at why preempt_vmx
102 FAIL_IF((long) rc_p);
109 int main(int argc, char *argv[])
111 return test_harness(test_preempt_vmx, "vmx_preempt");