Subversion Repositories HelenOS

Rev

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

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