1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright 2015, Cyril Bur, IBM Corp.
5 * This test attempts to see if the FPU registers are correctly reported in a
6 * signal context. Each worker just spins checking its FPU registers, at some
7 * point a signal will interrupt it and C code will check the signal context
8 * ensuring it is also the same.
13 #include <sys/syscall.h>
15 #include <sys/types.h>
23 /* Number of times each thread should receive the signal */
26 * Factor by which to multiply number of online CPUs for total number of
29 #define THREAD_FACTOR 8
31 __thread double darray[32];
37 extern long preempt_fpu(double *darray, int *threads_starting, int *running);
39 void signal_fpu_sig(int sig, siginfo_t *info, void *context)
42 ucontext_t *uc = context;
43 mcontext_t *mc = &uc->uc_mcontext;
45 // Don't check f30/f31, they're used as scratches in check_all_fprs()
46 for (i = 0; i < 30; i++) {
47 if (mc->fp_regs[i] != darray[i]) {
54 void *signal_fpu_c(void *p)
58 act.sa_sigaction = signal_fpu_sig;
59 act.sa_flags = SA_SIGINFO;
60 rc = sigaction(SIGUSR1, &act, NULL);
64 srand(pthread_self());
65 randomise_darray(darray, ARRAY_SIZE(darray));
66 rc = preempt_fpu(darray, &threads_starting, &running);
71 int test_signal_fpu(void)
73 int i, j, rc, threads;
77 threads = sysconf(_SC_NPROCESSORS_ONLN) * THREAD_FACTOR;
78 tids = malloc(threads * sizeof(pthread_t));
82 threads_starting = threads;
83 for (i = 0; i < threads; i++) {
84 rc = pthread_create(&tids[i], NULL, signal_fpu_c, NULL);
89 printf("\tWaiting for all workers to start...");
90 while (threads_starting)
91 asm volatile("": : :"memory");
94 printf("\tSending signals to all threads %d times...", ITERATIONS);
95 for (i = 0; i < ITERATIONS; i++) {
96 for (j = 0; j < threads; j++) {
97 pthread_kill(tids[j], SIGUSR1);
103 printf("\tStopping workers...");
105 for (i = 0; i < threads; i++) {
106 pthread_join(tids[i], &rc_p);
109 * Harness will say the fail was here, look at why signal_fpu
112 if ((long) rc_p || bad_context)
115 fprintf(stderr, "\t!! bad_context is true\n");
116 FAIL_IF((long) rc_p || bad_context);
124 int main(int argc, char *argv[])
126 return test_harness(test_signal_fpu, "fpu_signal");