1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright 2015, Cyril Bur, IBM Corp.
5 * This test attempts to see if the VMX registers change across preemption.
6 * Two things should be noted here a) The check_vmx function in asm only checks
7 * the non volatile registers as it is reused from the syscall test b) There is
8 * no way to be sure preemption happened so this test just uses many threads
9 * and a long wait. As such, a successful test doesn't mean much but a failure
15 #include <sys/syscall.h>
17 #include <sys/types.h>
24 /* Time to wait for workers to get preempted (seconds) */
25 #define PREEMPT_TIME 20
27 * Factor by which to multiply number of online CPUs for total number of
30 #define THREAD_FACTOR 8
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}};
40 extern void preempt_vmx(vector
int *varray
, int *threads_starting
, int *running
);
42 void *preempt_vmx_c(void *p
)
45 srand(pthread_self());
46 for (i
= 0; i
< 12; i
++)
47 for (j
= 0; j
< 4; j
++)
48 varray
[i
][j
] = rand();
50 /* Test fails if it ever returns */
51 preempt_vmx(varray
, &threads_starting
, &running
);
55 int test_preempt_vmx(void)
60 // vcmpequd used in vmx_asm.S is v2.07
61 SKIP_IF(!have_hwcap2(PPC_FEATURE2_ARCH_2_07
));
63 threads
= sysconf(_SC_NPROCESSORS_ONLN
) * THREAD_FACTOR
;
64 tids
= malloc(threads
* sizeof(pthread_t
));
68 threads_starting
= threads
;
69 for (i
= 0; i
< threads
; i
++) {
70 rc
= pthread_create(&tids
[i
], NULL
, preempt_vmx_c
, NULL
);
75 /* Not really nessesary but nice to wait for every thread to start */
76 printf("\tWaiting for all workers to start...");
77 while(threads_starting
)
78 asm volatile("": : :"memory");
81 printf("\tWaiting for %d seconds to let some workers get preempted...", PREEMPT_TIME
);
85 printf("\tStopping workers...");
87 * Working are checking this value every loop. In preempt_vmx 'cmpwi r5,0; bne 2b'.
88 * r5 will have loaded the value of running.
91 for (i
= 0; i
< threads
; i
++) {
93 pthread_join(tids
[i
], &rc_p
);
96 * Harness will say the fail was here, look at why preempt_vmx
101 FAIL_IF((long) rc_p
);
108 int main(int argc
, char *argv
[])
110 return test_harness(test_preempt_vmx
, "vmx_preempt");