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 FPU registers are correctly reported in a
10 * signal context. Each worker just spins checking its FPU registers, at some
11 * point a signal will interrupt it and C code will check the signal context
12 * ensuring it is also the same.
17 #include <sys/syscall.h>
19 #include <sys/types.h>
26 /* Number of times each thread should receive the signal */
29 * Factor by which to multiply number of online CPUs for total number of
32 #define THREAD_FACTOR 8
34 __thread double darray[] = {0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0,
35 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0,
42 extern long preempt_fpu(double *darray, int *threads_starting, int *running);
44 void signal_fpu_sig(int sig, siginfo_t *info, void *context)
47 ucontext_t *uc = context;
48 mcontext_t *mc = &uc->uc_mcontext;
50 /* Only the non volatiles were loaded up */
51 for (i = 14; i < 32; i++) {
52 if (mc->fp_regs[i] != darray[i - 14]) {
59 void *signal_fpu_c(void *p)
64 act.sa_sigaction = signal_fpu_sig;
65 act.sa_flags = SA_SIGINFO;
66 rc = sigaction(SIGUSR1, &act, NULL);
70 srand(pthread_self());
71 for (i = 0; i < 21; i++)
74 rc = preempt_fpu(darray, &threads_starting, &running);
79 int test_signal_fpu(void)
81 int i, j, rc, threads;
85 threads = sysconf(_SC_NPROCESSORS_ONLN) * THREAD_FACTOR;
86 tids = malloc(threads * sizeof(pthread_t));
90 threads_starting = threads;
91 for (i = 0; i < threads; i++) {
92 rc = pthread_create(&tids[i], NULL, signal_fpu_c, NULL);
97 printf("\tWaiting for all workers to start...");
98 while (threads_starting)
99 asm volatile("": : :"memory");
102 printf("\tSending signals to all threads %d times...", ITERATIONS);
103 for (i = 0; i < ITERATIONS; i++) {
104 for (j = 0; j < threads; j++) {
105 pthread_kill(tids[j], SIGUSR1);
111 printf("\tStopping workers...");
113 for (i = 0; i < threads; i++) {
114 pthread_join(tids[i], &rc_p);
117 * Harness will say the fail was here, look at why signal_fpu
120 if ((long) rc_p || bad_context)
123 fprintf(stderr, "\t!! bad_context is true\n");
124 FAIL_IF((long) rc_p || bad_context);
132 int main(int argc, char *argv[])
134 return test_harness(test_signal_fpu, "fpu_signal");