Subversion Repositories HelenOS

Rev

Rev 2050 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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