Subversion Repositories HelenOS

Rev

Rev 2021 | Rev 2029 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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