Subversion Repositories HelenOS

Rev

Rev 3069 | Rev 4153 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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