Rev 2027 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2027 | Rev 2029 | ||
---|---|---|---|
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 | #if (defined(ia32) || defined(amd64) || defined(ia64) || defined(ia32xen)) |
30 | #if (defined(ia32) || defined(amd64) || defined(ia64) || defined(ia32xen)) |
31 | 31 | ||
32 | #include <print.h> |
32 | #include <print.h> |
33 | #include <debug.h> |
33 | #include <debug.h> |
34 | #include <panic.h> |
- | |
35 | 34 | ||
36 | #include <test.h> |
35 | #include <test.h> |
37 | #include <atomic.h> |
36 | #include <atomic.h> |
38 | #include <proc/thread.h> |
37 | #include <proc/thread.h> |
39 | 38 | ||
40 | #include <arch.h> |
39 | #include <arch.h> |
41 | #include <arch/arch.h> |
40 | #include <arch/arch.h> |
42 | 41 | ||
43 | 42 | ||
44 | #define THREADS 150 |
43 | #define THREADS 150 |
45 | #define ATTEMPTS 100 |
44 | #define ATTEMPTS 100 |
46 | 45 | ||
47 | #define E_10e8 271828182 |
46 | #define E_10e8 271828182 |
48 | #define PI_10e8 314159265 |
47 | #define PI_10e8 314159265 |
49 | 48 | ||
50 | 49 | ||
51 | #ifdef KERN_ia32_ARCH_H_ |
50 | #ifdef KERN_ia32_ARCH_H_ |
52 | static inline double sqrt(double x) |
51 | static inline double sqrt(double x) |
53 | { |
52 | { |
54 | double v; |
53 | double v; |
55 | 54 | ||
56 | asm ( |
55 | asm ( |
57 | "fsqrt\n" |
56 | "fsqrt\n" |
58 | : "=t" (v) |
57 | : "=t" (v) |
59 | : "0" (x) |
58 | : "0" (x) |
60 | ); |
59 | ); |
61 | 60 | ||
62 | return v; |
61 | return v; |
63 | } |
62 | } |
64 | #endif |
63 | #endif |
65 | 64 | ||
66 | #ifdef KERN_amd64_ARCH_H_ |
65 | #ifdef KERN_amd64_ARCH_H_ |
67 | static inline double sqrt(double x) |
66 | static inline double sqrt(double x) |
68 | { |
67 | { |
69 | double v; |
68 | double v; |
70 | 69 | ||
71 | asm ( |
70 | asm ( |
72 | "fsqrt\n" |
71 | "fsqrt\n" |
73 | : "=t" (v) |
72 | : "=t" (v) |
74 | : "0" (x) |
73 | : "0" (x) |
75 | ); |
74 | ); |
76 | 75 | ||
77 | return v; |
76 | return v; |
78 | } |
77 | } |
79 | #endif |
78 | #endif |
80 | 79 | ||
81 | #ifdef KERN_ia64_ARCH_H_ |
80 | #ifdef KERN_ia64_ARCH_H_ |
82 | 81 | ||
83 | #undef PI_10e8 |
82 | #undef PI_10e8 |
84 | #define PI_10e8 3141592 |
83 | #define PI_10e8 3141592 |
85 | 84 | ||
86 | static inline long double sqrt(long double a) |
85 | static inline long double sqrt(long double a) |
87 | { |
86 | { |
88 | long double x = 1; |
87 | long double x = 1; |
89 | long double lx = 0; |
88 | long double lx = 0; |
90 | 89 | ||
91 | if (a < 0.00000000000000001) |
90 | if (a < 0.00000000000000001) |
92 | return 0; |
91 | return 0; |
93 | 92 | ||
94 | while(x != lx) { |
93 | while(x != lx) { |
95 | lx = x; |
94 | lx = x; |
96 | x = (x + (a / x)) / 2; |
95 | x = (x + (a / x)) / 2; |
97 | } |
96 | } |
98 | 97 | ||
99 | return x; |
98 | return x; |
100 | } |
99 | } |
101 | #endif |
100 | #endif |
102 | 101 | ||
103 | 102 | ||
104 | static atomic_t threads_ok; |
103 | static atomic_t threads_ok; |
105 | static atomic_t threads_fault; |
104 | static atomic_t threads_fault; |
106 | static waitq_t can_start; |
105 | static waitq_t can_start; |
107 | 106 | ||
108 | static void e(void *data) |
107 | static void e(void *data) |
109 | { |
108 | { |
110 | int i; |
109 | int i; |
111 | double e,d,le,f; |
110 | double e,d,le,f; |
112 | 111 | ||
113 | thread_detach(THREAD); |
112 | thread_detach(THREAD); |
114 | 113 | ||
115 | waitq_sleep(&can_start); |
114 | waitq_sleep(&can_start); |
116 | 115 | ||
117 | for (i = 0; i<ATTEMPTS; i++) { |
116 | for (i = 0; i<ATTEMPTS; i++) { |
118 | le = -1; |
117 | le = -1; |
119 | e = 0; |
118 | e = 0; |
120 | f = 1; |
119 | f = 1; |
121 | 120 | ||
122 | for (d = 1; e != le; d *= f, f += 1) { |
121 | for (d = 1; e != le; d *= f, f += 1) { |
123 | le = e; |
122 | le = e; |
124 | e = e + 1 / d; |
123 | e = e + 1 / d; |
125 | } |
124 | } |
126 | 125 | ||
127 | if ((int) (100000000 * e) != E_10e8) { |
126 | if ((int) (100000000 * e) != E_10e8) { |
128 | printf("tid%d: e*10e8=%zd should be %zd\n", THREAD->tid, (unative_t) (100000000 * e), (unative_t) E_10e8); |
127 | printf("tid%d: e*10e8=%zd should be %zd\n", THREAD->tid, (unative_t) (100000000 * e), (unative_t) E_10e8); |
129 | atomic_inc(&threads_fault); |
128 | atomic_inc(&threads_fault); |
130 | break; |
129 | break; |
131 | } |
130 | } |
132 | } |
131 | } |
133 | atomic_inc(&threads_ok); |
132 | atomic_inc(&threads_ok); |
134 | } |
133 | } |
135 | 134 | ||
136 | static void pi(void *data) |
135 | static void pi(void *data) |
137 | { |
136 | { |
138 | int i; |
137 | int i; |
139 | double lpi, pi; |
138 | double lpi, pi; |
140 | double n, ab, ad; |
139 | double n, ab, ad; |
141 | 140 | ||
142 | thread_detach(THREAD); |
141 | thread_detach(THREAD); |
143 | 142 | ||
144 | waitq_sleep(&can_start); |
143 | waitq_sleep(&can_start); |
145 | 144 | ||
146 | for (i = 0; i < ATTEMPTS; i++) { |
145 | for (i = 0; i < ATTEMPTS; i++) { |
147 | lpi = -1; |
146 | lpi = -1; |
148 | pi = 0; |
147 | pi = 0; |
149 | 148 | ||
150 | for (n = 2, ab = sqrt(2); lpi != pi; n *= 2, ab = ad) { |
149 | for (n = 2, ab = sqrt(2); lpi != pi; n *= 2, ab = ad) { |
151 | double sc, cd; |
150 | double sc, cd; |
152 | 151 | ||
153 | sc = sqrt(1 - (ab * ab / 4)); |
152 | sc = sqrt(1 - (ab * ab / 4)); |
154 | cd = 1 - sc; |
153 | cd = 1 - sc; |
155 | ad = sqrt(ab * ab / 4 + cd * cd); |
154 | ad = sqrt(ab * ab / 4 + cd * cd); |
156 | lpi = pi; |
155 | lpi = pi; |
157 | pi = 2 * n * ad; |
156 | pi = 2 * n * ad; |
158 | } |
157 | } |
159 | 158 | ||
160 | #ifdef KERN_ia64_ARCH_H_ |
159 | #ifdef KERN_ia64_ARCH_H_ |
161 | if ((int) (1000000 * pi) != PI_10e8) { |
160 | if ((int) (1000000 * pi) != PI_10e8) { |
162 | printf("tid%d: pi*10e8=%zd should be %zd\n", THREAD->tid, (unative_t) (1000000 * pi), (unative_t) (PI_10e8 / 100)); |
161 | printf("tid%d: pi*10e8=%zd should be %zd\n", THREAD->tid, (unative_t) (1000000 * pi), (unative_t) (PI_10e8 / 100)); |
163 | atomic_inc(&threads_fault); |
162 | atomic_inc(&threads_fault); |
164 | break; |
163 | break; |
165 | } |
164 | } |
166 | #else |
165 | #else |
167 | if ((int) (100000000 * pi) != PI_10e8) { |
166 | if ((int) (100000000 * pi) != PI_10e8) { |
168 | printf("tid%d: pi*10e8=%zd should be %zd\n", THREAD->tid, (unative_t) (100000000 * pi), (unative_t) PI_10e8); |
167 | printf("tid%d: pi*10e8=%zd should be %zd\n", THREAD->tid, (unative_t) (100000000 * pi), (unative_t) PI_10e8); |
169 | atomic_inc(&threads_fault); |
168 | atomic_inc(&threads_fault); |
170 | break; |
169 | break; |
171 | } |
170 | } |
172 | #endif |
171 | #endif |
173 | } |
172 | } |
174 | atomic_inc(&threads_ok); |
173 | atomic_inc(&threads_ok); |
175 | } |
174 | } |
176 | 175 | ||
177 | char * test_fpu1(void) |
176 | char * test_fpu1(void) |
178 | { |
177 | { |
179 | unsigned int i, total = 0; |
178 | unsigned int i, total = 0; |
180 | 179 | ||
181 | waitq_initialize(&can_start); |
180 | waitq_initialize(&can_start); |
182 | atomic_set(&threads_ok, 0); |
181 | atomic_set(&threads_ok, 0); |
183 | atomic_set(&threads_fault, 0); |
182 | atomic_set(&threads_fault, 0); |
184 | printf("Creating %d threads... ", 2 * THREADS); |
183 | printf("Creating %d threads... ", 2 * THREADS); |
185 | 184 | ||
186 | for (i = 0; i < THREADS; i++) { |
185 | for (i = 0; i < THREADS; i++) { |
187 | thread_t *t; |
186 | thread_t *t; |
188 | 187 | ||
189 | if (!(t = thread_create(e, NULL, TASK, 0, "e"))) { |
188 | if (!(t = thread_create(e, NULL, TASK, 0, "e"))) { |
190 | printf("could not create thread %d\n", 2 * i); |
189 | printf("could not create thread %d\n", 2 * i); |
191 | break; |
190 | break; |
192 | } |
191 | } |
193 | thread_ready(t); |
192 | thread_ready(t); |
194 | total++; |
193 | total++; |
195 | 194 | ||
196 | if (!(t = thread_create(pi, NULL, TASK, 0, "pi"))) { |
195 | if (!(t = thread_create(pi, NULL, TASK, 0, "pi"))) { |
197 | printf("could not create thread %d\n", 2 * i + 1); |
196 | printf("could not create thread %d\n", 2 * i + 1); |
198 | break; |
197 | break; |
199 | } |
198 | } |
200 | thread_ready(t); |
199 | thread_ready(t); |
201 | total++; |
200 | total++; |
202 | } |
201 | } |
203 | printf("ok\n"); |
202 | printf("ok\n"); |
204 | 203 | ||
205 | thread_sleep(1); |
204 | thread_sleep(1); |
206 | waitq_wakeup(&can_start, WAKEUP_ALL); |
205 | waitq_wakeup(&can_start, WAKEUP_ALL); |
207 | 206 | ||
208 | while (atomic_get(&threads_ok) != total) { |
207 | while (atomic_get(&threads_ok) != total) { |
209 | printf("Threads left: %d\n", total - atomic_get(&threads_ok)); |
208 | printf("Threads left: %d\n", total - atomic_get(&threads_ok)); |
210 | thread_sleep(1); |
209 | thread_sleep(1); |
211 | } |
210 | } |
212 | 211 | ||
213 | if (atomic_get(&threads_fault) == 0) |
212 | if (atomic_get(&threads_fault) == 0) |
214 | return NULL; |
213 | return NULL; |
215 | 214 | ||
216 | return "Test failed"; |
215 | return "Test failed"; |
217 | } |
216 | } |
218 | 217 | ||
219 | #endif |
218 | #endif |
220 | 219 |