Subversion Repositories HelenOS

Rev

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

Rev 4342 Rev 4345
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
#include <print.h>
29
#include <print.h>
30
#include <debug.h>
30
#include <debug.h>
31
 
31
 
32
#include <test.h>
32
#include <test.h>
33
#include <atomic.h>
33
#include <atomic.h>
34
#include <proc/thread.h>
34
#include <proc/thread.h>
35
#include <time/delay.h>
35
#include <time/delay.h>
36
 
36
 
37
#include <arch.h>
37
#include <arch.h>
38
 
38
 
39
#define THREADS   25
39
#define THREADS   25
40
#define DELAY     10000L
40
#define DELAY     10000L
41
#define ATTEMPTS  5
41
#define ATTEMPTS  5
42
 
42
 
43
static atomic_t threads_ok;
43
static atomic_t threads_ok;
44
static atomic_t threads_fault;
44
static atomic_t threads_fault;
45
static waitq_t can_start;
45
static waitq_t can_start;
46
static bool sh_quiet;
46
static bool sh_quiet;
47
 
47
 
48
 
48
 
49
static void testit1(void *data)
49
static void testit1(void *data)
50
{
50
{
51
    int i;
51
    int i;
52
    int arg __attribute__((aligned(16))) = (int) ((unative_t) data);
52
    int arg __attribute__((aligned(16))) = (int) ((unative_t) data);
53
    int after_arg __attribute__((aligned(16)));
53
    int after_arg __attribute__((aligned(16)));
54
 
54
 
55
    thread_detach(THREAD);
55
    thread_detach(THREAD);
56
   
56
   
57
    waitq_sleep(&can_start);
57
    waitq_sleep(&can_start);
58
 
58
 
59
    for (i = 0; i < ATTEMPTS; i++) {
59
    for (i = 0; i < ATTEMPTS; i++) {
60
        asm volatile (
60
        asm volatile (
61
            "movlpd %0, %%xmm2\n"
61
            "movlpd %[arg], %%xmm2\n"
62
            : "=m" (arg)
62
            : [arg] "=m" (arg)
63
        );
63
        );
64
 
64
 
65
        delay(DELAY);
65
        delay(DELAY);
66
        asm volatile (
66
        asm volatile (
67
            "movlpd %%xmm2, %0\n"
67
            "movlpd %%xmm2, %[after_arg]\n"
68
            : "=m" (after_arg)
68
            : [after_arg] "=m" (after_arg)
69
        );
69
        );
70
       
70
       
71
        if (arg != after_arg) {
71
        if (arg != after_arg) {
72
            if (!sh_quiet)
72
            if (!sh_quiet)
73
                printf("tid%" PRIu64 ": arg(%d) != %d\n", THREAD->tid, arg, after_arg);
73
                printf("tid%" PRIu64 ": arg(%d) != %d\n", THREAD->tid, arg, after_arg);
74
            atomic_inc(&threads_fault);
74
            atomic_inc(&threads_fault);
75
            break;
75
            break;
76
        }
76
        }
77
    }
77
    }
78
    atomic_inc(&threads_ok);
78
    atomic_inc(&threads_ok);
79
}
79
}
80
 
80
 
81
static void testit2(void *data)
81
static void testit2(void *data)
82
{
82
{
83
    int i;
83
    int i;
84
    int arg __attribute__((aligned(16))) = (int) ((unative_t) data);
84
    int arg __attribute__((aligned(16))) = (int) ((unative_t) data);
85
    int after_arg __attribute__((aligned(16)));
85
    int after_arg __attribute__((aligned(16)));
86
   
86
   
87
    thread_detach(THREAD);
87
    thread_detach(THREAD);
88
   
88
   
89
    waitq_sleep(&can_start);
89
    waitq_sleep(&can_start);
90
 
90
 
91
    for (i = 0; i < ATTEMPTS; i++) {
91
    for (i = 0; i < ATTEMPTS; i++) {
92
        asm volatile (
92
        asm volatile (
93
            "movlpd %0, %%xmm2\n"
93
            "movlpd %[arg], %%xmm2\n"
94
            : "=m" (arg)
94
            : [arg] "=m" (arg)
95
        );
95
        );
96
 
96
 
97
        scheduler();
97
        scheduler();
98
        asm volatile (
98
        asm volatile (
99
            "movlpd %%xmm2, %0\n"
99
            "movlpd %%xmm2, %[after_arg]\n"
100
            : "=m" (after_arg)
100
            : [after_arg] "=m" (after_arg)
101
        );
101
        );
102
       
102
       
103
        if (arg != after_arg) {
103
        if (arg != after_arg) {
104
            if (!sh_quiet)
104
            if (!sh_quiet)
105
                printf("tid%" PRIu64 ": arg(%d) != %d\n", THREAD->tid, arg, after_arg);
105
                printf("tid%" PRIu64 ": arg(%d) != %d\n", THREAD->tid, arg, after_arg);
106
            atomic_inc(&threads_fault);
106
            atomic_inc(&threads_fault);
107
            break;
107
            break;
108
        }
108
        }
109
    }
109
    }
110
    atomic_inc(&threads_ok);
110
    atomic_inc(&threads_ok);
111
}
111
}
112
 
112
 
113
 
113
 
114
char * test_sse1(bool quiet)
114
char * test_sse1(bool quiet)
115
{
115
{
116
    unsigned int i, total = 0;
116
    unsigned int i, total = 0;
117
    sh_quiet = quiet;
117
    sh_quiet = quiet;
118
   
118
   
119
    waitq_initialize(&can_start);
119
    waitq_initialize(&can_start);
120
    atomic_set(&threads_ok, 0);
120
    atomic_set(&threads_ok, 0);
121
    atomic_set(&threads_fault, 0);
121
    atomic_set(&threads_fault, 0);
122
   
122
   
123
    if (!quiet)
123
    if (!quiet)
124
        printf("Creating %u threads... ", 2 * THREADS);
124
        printf("Creating %u threads... ", 2 * THREADS);
125
 
125
 
126
    for (i = 0; i < THREADS; i++) {
126
    for (i = 0; i < THREADS; i++) {
127
        thread_t *t;
127
        thread_t *t;
128
       
128
       
129
        if (!(t = thread_create(testit1, (void *) ((unative_t) 2 * i), TASK, 0, "testit1", false))) {
129
        if (!(t = thread_create(testit1, (void *) ((unative_t) 2 * i), TASK, 0, "testit1", false))) {
130
            if (!quiet)
130
            if (!quiet)
131
                printf("could not create thread %u\n", 2 * i);
131
                printf("could not create thread %u\n", 2 * i);
132
            break;
132
            break;
133
        }
133
        }
134
        thread_ready(t);
134
        thread_ready(t);
135
        total++;
135
        total++;
136
       
136
       
137
        if (!(t = thread_create(testit2, (void *) ((unative_t) 2 * i + 1), TASK, 0, "testit2", false))) {
137
        if (!(t = thread_create(testit2, (void *) ((unative_t) 2 * i + 1), TASK, 0, "testit2", false))) {
138
            if (!quiet)
138
            if (!quiet)
139
                printf("could not create thread %u\n", 2 * i + 1);
139
                printf("could not create thread %u\n", 2 * i + 1);
140
            break;
140
            break;
141
        }
141
        }
142
        thread_ready(t);
142
        thread_ready(t);
143
        total++;
143
        total++;
144
    }
144
    }
145
   
145
   
146
    if (!quiet)
146
    if (!quiet)
147
        printf("ok\n");
147
        printf("ok\n");
148
       
148
       
149
    thread_sleep(1);
149
    thread_sleep(1);
150
    waitq_wakeup(&can_start, WAKEUP_ALL);
150
    waitq_wakeup(&can_start, WAKEUP_ALL);
151
   
151
   
152
    while (atomic_get(&threads_ok) != (long) total) {
152
    while (atomic_get(&threads_ok) != (long) total) {
153
        if (!quiet)
153
        if (!quiet)
154
            printf("Threads left: %d\n", total - atomic_get(&threads_ok));
154
            printf("Threads left: %d\n", total - atomic_get(&threads_ok));
155
        thread_sleep(1);
155
        thread_sleep(1);
156
    }
156
    }
157
   
157
   
158
    if (atomic_get(&threads_fault) == 0)
158
    if (atomic_get(&threads_fault) == 0)
159
        return NULL;
159
        return NULL;
160
   
160
   
161
    return "Test failed";
161
    return "Test failed";
162
}
162
}
163
 
163