Rev 92 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 92 | Rev 94 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (C) 2005 Jakub Vana |
2 | * Copyright (C) 2005 Jakub Vana |
3 | * Copyright (C) 2005 Jakub Jermar |
3 | * Copyright (C) 2005 Jakub Jermar |
4 | * All rights reserved. |
4 | * All rights reserved. |
5 | * |
5 | * |
6 | * Redistribution and use in source and binary forms, with or without |
6 | * Redistribution and use in source and binary forms, with or without |
7 | * modification, are permitted provided that the following conditions |
7 | * modification, are permitted provided that the following conditions |
8 | * are met: |
8 | * are met: |
9 | * |
9 | * |
10 | * - Redistributions of source code must retain the above copyright |
10 | * - Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. |
11 | * notice, this list of conditions and the following disclaimer. |
12 | * - Redistributions in binary form must reproduce the above copyright |
12 | * - Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the |
13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. |
14 | * documentation and/or other materials provided with the distribution. |
15 | * - The name of the author may not be used to endorse or promote products |
15 | * - The name of the author may not be used to endorse or promote products |
16 | * derived from this software without specific prior written permission. |
16 | * derived from this software without specific prior written permission. |
17 | * |
17 | * |
18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 | */ |
28 | */ |
29 | 29 | ||
30 | #include <arch/interrupt.h> |
- | |
31 | #include <print.h> |
30 | #include <print.h> |
32 | #include <debug.h> |
31 | #include <debug.h> |
33 | #include <panic.h> |
32 | #include <panic.h> |
34 | #include <arch/i8259.h> |
- | |
35 | #include <func.h> |
- | |
36 | #include <cpu.h> |
- | |
37 | #include <arch/asm.h> |
- | |
38 | #include <mm/tlb.h> |
- | |
39 | 33 | ||
40 | #include <test.h> |
34 | #include <test.h> |
41 | #include <arch.h> |
- | |
42 | #include <arch/smp/atomic.h> |
35 | #include <arch/smp/atomic.h> |
43 | #include <proc/thread.h> |
36 | #include <proc/thread.h> |
44 | 37 | ||
- | 38 | #include <arch.h> |
|
- | 39 | ||
45 | #define THREADS 150*2 |
40 | #define THREADS 150*2 |
46 | #define ATTEMPTS 10 |
41 | #define ATTEMPTS 10 |
47 | 42 | ||
48 | #define E_10e8 271828182 |
43 | #define E_10e8 271828182 |
49 | #define PI_10e8 314159265 |
44 | #define PI_10e8 314159265 |
50 | 45 | ||
51 | static inline double sqrt(double x) { double v; __asm__ ("fsqrt\n" : "=t" (v) : "0" (x)); return v; } |
46 | static inline double sqrt(double x) { double v; __asm__ ("fsqrt\n" : "=t" (v) : "0" (x)); return v; } |
52 | 47 | ||
53 | static volatile int threads_ok; |
48 | static volatile int threads_ok; |
54 | static waitq_t can_start; |
49 | static waitq_t can_start; |
55 | 50 | ||
56 | static void e(void *data) |
51 | static void e(void *data) |
57 | { |
52 | { |
58 | int i; |
53 | int i; |
59 | double e,d,le,f; |
54 | double e,d,le,f; |
60 | 55 | ||
61 | waitq_sleep(&can_start); |
56 | waitq_sleep(&can_start); |
62 | 57 | ||
63 | for (i = 0; i<ATTEMPTS; i++) { |
58 | for (i = 0; i<ATTEMPTS; i++) { |
64 | le=-1; |
59 | le=-1; |
65 | e=0; |
60 | e=0; |
66 | f=1; |
61 | f=1; |
67 | 62 | ||
68 | for(d=1;e!=le;d*=f,f+=1) { |
63 | for(d=1;e!=le;d*=f,f+=1) { |
69 | le=e; |
64 | le=e; |
70 | e=e+1/d; |
65 | e=e+1/d; |
71 | } |
66 | } |
72 | 67 | ||
73 | if((int)(100000000*e)!=E_10e8) |
68 | if((int)(100000000*e)!=E_10e8) |
74 | panic("tid%d: e*10e8=%d\n", THREAD->tid, (int) 100000000*e); |
69 | panic("tid%d: e*10e8=%d\n", THREAD->tid, (int) 100000000*e); |
75 | } |
70 | } |
76 | 71 | ||
77 | atomic_inc((int *) &threads_ok); |
72 | atomic_inc((int *) &threads_ok); |
78 | } |
73 | } |
79 | 74 | ||
80 | static void pi(void *data) |
75 | static void pi(void *data) |
81 | { |
76 | { |
82 | int i; |
77 | int i; |
83 | double lpi, pi; |
78 | double lpi, pi; |
84 | double n, ab, ad; |
79 | double n, ab, ad; |
85 | 80 | ||
86 | waitq_sleep(&can_start); |
81 | waitq_sleep(&can_start); |
87 | 82 | ||
88 | 83 | ||
89 | for (i = 0; i<ATTEMPTS; i++) { |
84 | for (i = 0; i<ATTEMPTS; i++) { |
90 | lpi = -1; |
85 | lpi = -1; |
91 | pi = 0; |
86 | pi = 0; |
92 | 87 | ||
93 | for (n=2, ab = sqrt(2); lpi != pi; n *= 2, ab = ad) { |
88 | for (n=2, ab = sqrt(2); lpi != pi; n *= 2, ab = ad) { |
94 | double sc, cd; |
89 | double sc, cd; |
95 | 90 | ||
96 | sc = sqrt(1 - (ab*ab/4)); |
91 | sc = sqrt(1 - (ab*ab/4)); |
97 | cd = 1 - sc; |
92 | cd = 1 - sc; |
98 | ad = sqrt(ab*ab/4 + cd*cd); |
93 | ad = sqrt(ab*ab/4 + cd*cd); |
99 | lpi = pi; |
94 | lpi = pi; |
100 | pi = 2 * n * ad; |
95 | pi = 2 * n * ad; |
101 | } |
96 | } |
102 | 97 | ||
103 | if((int)(100000000*pi)!=PI_10e8) |
98 | if((int)(100000000*pi)!=PI_10e8) |
104 | panic("tid%d: pi*10e8=%d\n", THREAD->tid, (int) 100000000*pi); |
99 | panic("tid%d: pi*10e8=%d\n", THREAD->tid, (int) 100000000*pi); |
105 | } |
100 | } |
106 | 101 | ||
107 | atomic_inc((int *) &threads_ok); |
102 | atomic_inc((int *) &threads_ok); |
108 | } |
103 | } |
109 | 104 | ||
110 | 105 | ||
111 | void test(void) |
106 | void test(void) |
112 | { |
107 | { |
113 | thread_t *t; |
108 | thread_t *t; |
114 | int i; |
109 | int i; |
115 | 110 | ||
116 | waitq_initialize(&can_start); |
111 | waitq_initialize(&can_start); |
117 | 112 | ||
118 | printf("FPU test #1\n"); |
113 | printf("FPU test #1\n"); |
119 | printf("Creating %d threads... ", THREADS); |
114 | printf("Creating %d threads... ", THREADS); |
120 | 115 | ||
121 | for (i=0; i<THREADS/2; i++) { |
116 | for (i=0; i<THREADS/2; i++) { |
122 | if (!(t = thread_create(e, NULL, TASK, 0))) |
117 | if (!(t = thread_create(e, NULL, TASK, 0))) |
123 | panic("could not create thread\n"); |
118 | panic("could not create thread\n"); |
124 | thread_ready(t); |
119 | thread_ready(t); |
125 | if (!(t = thread_create(pi, NULL, TASK, 0))) |
120 | if (!(t = thread_create(pi, NULL, TASK, 0))) |
126 | panic("could not create thread\n"); |
121 | panic("could not create thread\n"); |
127 | thread_ready(t); |
122 | thread_ready(t); |
128 | } |
123 | } |
129 | printf("ok\n"); |
124 | printf("ok\n"); |
130 | 125 | ||
131 | thread_sleep(1); |
126 | thread_sleep(1); |
132 | waitq_wakeup(&can_start, WAKEUP_ALL); |
127 | waitq_wakeup(&can_start, WAKEUP_ALL); |
133 | 128 | ||
134 | while (threads_ok != THREADS) |
129 | while (threads_ok != THREADS) |
135 | ; |
130 | ; |
136 | 131 | ||
137 | printf("Test passed.\n"); |
132 | printf("Test passed.\n"); |
138 | } |
133 | } |
139 | 134 |