Subversion Repositories HelenOS

Rev

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

Rev 2745 Rev 3069
1
/*
1
/*
2
 * Copyright (c) 2005 Ondrej Palkovsky
2
 * Copyright (c) 2005 Ondrej Palkovsky
3
 * All rights reserved.
3
 * All rights reserved.
4
 *
4
 *
5
 * Redistribution and use in source and binary forms, with or without
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
6
 * modification, are permitted provided that the following conditions
7
 * are met:
7
 * are met:
8
 *
8
 *
9
 * - Redistributions of source code must retain the above copyright
9
 * - Redistributions of source code must retain the above copyright
10
 *   notice, this list of conditions and the following disclaimer.
10
 *   notice, this list of conditions and the following disclaimer.
11
 * - Redistributions in binary form must reproduce the above copyright
11
 * - Redistributions in binary form must reproduce the above copyright
12
 *   notice, this list of conditions and the following disclaimer in the
12
 *   notice, this list of conditions and the following disclaimer in the
13
 *   documentation and/or other materials provided with the distribution.
13
 *   documentation and/or other materials provided with the distribution.
14
 * - The name of the author may not be used to endorse or promote products
14
 * - The name of the author may not be used to endorse or promote products
15
 *   derived from this software without specific prior written permission.
15
 *   derived from this software without specific prior written permission.
16
 *
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
27
 */
28
 
28
 
29
#if (defined(ia32) || defined(amd64) || defined(ia32xen))
29
#if (defined(ia32) || defined(amd64) || defined(ia32xen))
30
 
30
 
31
#include <print.h>
31
#include <print.h>
32
#include <debug.h>
32
#include <debug.h>
33
 
33
 
34
#include <test.h>
34
#include <test.h>
35
#include <atomic.h>
35
#include <atomic.h>
36
#include <proc/thread.h>
36
#include <proc/thread.h>
37
#include <time/delay.h>
37
#include <time/delay.h>
38
 
38
 
39
#include <arch.h>
39
#include <arch.h>
40
 
40
 
41
#define THREADS     25
41
#define THREADS     25
42
#define DELAY       10000L
42
#define DELAY       10000L
43
#define ATTEMPTS        5
43
#define ATTEMPTS        5
44
 
44
 
45
static atomic_t threads_ok;
45
static atomic_t threads_ok;
46
static atomic_t threads_fault;
46
static atomic_t threads_fault;
47
static waitq_t can_start;
47
static waitq_t can_start;
48
static bool sh_quiet;
48
static bool sh_quiet;
49
 
49
 
50
 
50
 
51
static void testit1(void *data)
51
static void testit1(void *data)
52
{
52
{
53
    int i;
53
    int i;
54
    int arg __attribute__((aligned(16))) = (int) ((unative_t) data);
54
    int arg __attribute__((aligned(16))) = (int) ((unative_t) data);
55
    int after_arg __attribute__((aligned(16)));
55
    int after_arg __attribute__((aligned(16)));
56
 
56
 
57
    thread_detach(THREAD);
57
    thread_detach(THREAD);
58
   
58
   
59
    waitq_sleep(&can_start);
59
    waitq_sleep(&can_start);
60
 
60
 
61
    for (i = 0; i < ATTEMPTS; i++) {
61
    for (i = 0; i < ATTEMPTS; i++) {
62
        asm volatile (
62
        asm volatile (
63
            "movlpd %0, %%xmm2\n"
63
            "movlpd %0, %%xmm2\n"
64
            : "=m" (arg)
64
            : "=m" (arg)
65
        );
65
        );
66
 
66
 
67
        delay(DELAY);
67
        delay(DELAY);
68
        asm volatile (
68
        asm volatile (
69
            "movlpd %%xmm2, %0\n"
69
            "movlpd %%xmm2, %0\n"
70
            : "=m" (after_arg)
70
            : "=m" (after_arg)
71
        );
71
        );
72
       
72
       
73
        if (arg != after_arg) {
73
        if (arg != after_arg) {
74
            if (!sh_quiet)
74
            if (!sh_quiet)
75
                printf("tid%llu: arg(%d) != %d\n", THREAD->tid, arg, after_arg);
75
                printf("tid%" PRIu64 ": arg(%d) != %d\n", THREAD->tid, arg, after_arg);
76
            atomic_inc(&threads_fault);
76
            atomic_inc(&threads_fault);
77
            break;
77
            break;
78
        }
78
        }
79
    }
79
    }
80
    atomic_inc(&threads_ok);
80
    atomic_inc(&threads_ok);
81
}
81
}
82
 
82
 
83
static void testit2(void *data)
83
static void testit2(void *data)
84
{
84
{
85
    int i;
85
    int i;
86
    int arg __attribute__((aligned(16))) = (int) ((unative_t) data);
86
    int arg __attribute__((aligned(16))) = (int) ((unative_t) data);
87
    int after_arg __attribute__((aligned(16)));
87
    int after_arg __attribute__((aligned(16)));
88
   
88
   
89
    thread_detach(THREAD);
89
    thread_detach(THREAD);
90
   
90
   
91
    waitq_sleep(&can_start);
91
    waitq_sleep(&can_start);
92
 
92
 
93
    for (i = 0; i < ATTEMPTS; i++) {
93
    for (i = 0; i < ATTEMPTS; i++) {
94
        asm volatile (
94
        asm volatile (
95
            "movlpd %0, %%xmm2\n"
95
            "movlpd %0, %%xmm2\n"
96
            : "=m" (arg)
96
            : "=m" (arg)
97
        );
97
        );
98
 
98
 
99
        scheduler();
99
        scheduler();
100
        asm volatile (
100
        asm volatile (
101
            "movlpd %%xmm2, %0\n"
101
            "movlpd %%xmm2, %0\n"
102
            : "=m" (after_arg)
102
            : "=m" (after_arg)
103
        );
103
        );
104
       
104
       
105
        if (arg != after_arg) {
105
        if (arg != after_arg) {
106
            if (!sh_quiet)
106
            if (!sh_quiet)
107
                printf("tid%llu: arg(%d) != %d\n", THREAD->tid, arg, after_arg);
107
                printf("tid%" PRIu64 ": arg(%d) != %d\n", THREAD->tid, arg, after_arg);
108
            atomic_inc(&threads_fault);
108
            atomic_inc(&threads_fault);
109
            break;
109
            break;
110
        }
110
        }
111
    }
111
    }
112
    atomic_inc(&threads_ok);
112
    atomic_inc(&threads_ok);
113
}
113
}
114
 
114
 
115
 
115
 
116
char * test_sse1(bool quiet)
116
char * test_sse1(bool quiet)
117
{
117
{
118
    unsigned int i, total = 0;
118
    unsigned int i, total = 0;
119
    sh_quiet = quiet;
119
    sh_quiet = quiet;
120
   
120
   
121
    waitq_initialize(&can_start);
121
    waitq_initialize(&can_start);
122
    atomic_set(&threads_ok, 0);
122
    atomic_set(&threads_ok, 0);
123
    atomic_set(&threads_fault, 0);
123
    atomic_set(&threads_fault, 0);
124
   
124
   
125
    if (!quiet)
125
    if (!quiet)
126
        printf("Creating %d threads... ", 2 * THREADS);
126
        printf("Creating %u threads... ", 2 * THREADS);
127
 
127
 
128
    for (i = 0; i < THREADS; i++) {
128
    for (i = 0; i < THREADS; i++) {
129
        thread_t *t;
129
        thread_t *t;
130
       
130
       
131
        if (!(t = thread_create(testit1, (void *) ((unative_t) 2 * i), TASK, 0, "testit1", false))) {
131
        if (!(t = thread_create(testit1, (void *) ((unative_t) 2 * i), TASK, 0, "testit1", false))) {
132
            if (!quiet)
132
            if (!quiet)
133
                printf("could not create thread %d\n", 2 * i);
133
                printf("could not create thread %u\n", 2 * i);
134
            break;
134
            break;
135
        }
135
        }
136
        thread_ready(t);
136
        thread_ready(t);
137
        total++;
137
        total++;
138
       
138
       
139
        if (!(t = thread_create(testit2, (void *) ((unative_t) 2 * i + 1), TASK, 0, "testit2", false))) {
139
        if (!(t = thread_create(testit2, (void *) ((unative_t) 2 * i + 1), TASK, 0, "testit2", false))) {
140
            if (!quiet)
140
            if (!quiet)
141
                printf("could not create thread %d\n", 2 * i + 1);
141
                printf("could not create thread %u\n", 2 * i + 1);
142
            break;
142
            break;
143
        }
143
        }
144
        thread_ready(t);
144
        thread_ready(t);
145
        total++;
145
        total++;
146
    }
146
    }
147
   
147
   
148
    if (!quiet)
148
    if (!quiet)
149
        printf("ok\n");
149
        printf("ok\n");
150
       
150
       
151
    thread_sleep(1);
151
    thread_sleep(1);
152
    waitq_wakeup(&can_start, WAKEUP_ALL);
152
    waitq_wakeup(&can_start, WAKEUP_ALL);
153
   
153
   
154
    while (atomic_get(&threads_ok) != (long) total) {
154
    while (atomic_get(&threads_ok) != (long) total) {
155
        if (!quiet)
155
        if (!quiet)
156
            printf("Threads left: %d\n", total - atomic_get(&threads_ok));
156
            printf("Threads left: %d\n", total - atomic_get(&threads_ok));
157
        thread_sleep(1);
157
        thread_sleep(1);
158
    }
158
    }
159
   
159
   
160
    if (atomic_get(&threads_fault) == 0)
160
    if (atomic_get(&threads_fault) == 0)
161
        return NULL;
161
        return NULL;
162
   
162
   
163
    return "Test failed";
163
    return "Test failed";
164
}
164
}
165
 
165
 
166
#endif
166
#endif
167
 
167