Subversion Repositories HelenOS

Rev

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