Rev 2042 | Rev 2051 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2042 | Rev 2050 | ||
---|---|---|---|
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 | #if (defined(ia32) || defined(amd64) || defined(ia32xen)) |
29 | #if (defined(ia32) || defined(amd64) || defined(ia32xen)) |
30 | 30 | ||
31 | #include <print.h> |
31 | #include <print.h> |
32 | #include <debug.h> |
32 | #include <debug.h> |
33 | 33 | ||
34 | #include <test.h> |
34 | #include <test.h> |
35 | #include <atomic.h> |
35 | #include <atomic.h> |
36 | #include <proc/thread.h> |
36 | #include <proc/thread.h> |
37 | #include <time/delay.h> |
37 | #include <time/delay.h> |
38 | 38 | ||
39 | #include <arch.h> |
39 | #include <arch.h> |
40 | 40 | ||
41 | #define THREADS 25 |
41 | #define THREADS 25 |
42 | #define DELAY 10000L |
42 | #define DELAY 10000L |
43 | #define ATTEMPTS 5 |
43 | #define ATTEMPTS 5 |
44 | 44 | ||
45 | static atomic_t threads_ok; |
45 | static atomic_t threads_ok; |
46 | static atomic_t threads_fault; |
46 | static atomic_t threads_fault; |
47 | static waitq_t can_start; |
47 | static waitq_t can_start; |
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 %0, %%xmm2\n" |
62 | : "=m" (arg) |
62 | : "=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, %0\n" |
68 | : "=m" (after_arg) |
68 | : "=m" (after_arg) |
69 | ); |
69 | ); |
70 | 70 | ||
71 | if (arg != after_arg) { |
71 | if (arg != after_arg) { |
72 | printf("tid%d: arg(%d) != %d\n", THREAD->tid, arg, after_arg); |
72 | printf("tid%d: arg(%d) != %d\n", THREAD->tid, arg, after_arg); |
73 | atomic_inc(&threads_fault); |
73 | atomic_inc(&threads_fault); |
74 | break; |
74 | break; |
75 | } |
75 | } |
76 | } |
76 | } |
77 | atomic_inc(&threads_ok); |
77 | atomic_inc(&threads_ok); |
78 | } |
78 | } |
79 | 79 | ||
80 | static void testit2(void *data) |
80 | static void testit2(void *data) |
81 | { |
81 | { |
82 | int i; |
82 | int i; |
83 | int arg __attribute__((aligned(16))) = (int) ((unative_t) data); |
83 | int arg __attribute__((aligned(16))) = (int) ((unative_t) data); |
84 | int after_arg __attribute__((aligned(16))); |
84 | int after_arg __attribute__((aligned(16))); |
85 | 85 | ||
86 | thread_detach(THREAD); |
86 | thread_detach(THREAD); |
87 | 87 | ||
88 | waitq_sleep(&can_start); |
88 | waitq_sleep(&can_start); |
89 | 89 | ||
90 | for (i = 0; i < ATTEMPTS; i++) { |
90 | for (i = 0; i < ATTEMPTS; i++) { |
91 | asm volatile ( |
91 | asm volatile ( |
92 | "movlpd %0, %%xmm2\n" |
92 | "movlpd %0, %%xmm2\n" |
93 | : "=m" (arg) |
93 | : "=m" (arg) |
94 | ); |
94 | ); |
95 | 95 | ||
96 | scheduler(); |
96 | scheduler(); |
97 | asm volatile ( |
97 | asm volatile ( |
98 | "movlpd %%xmm2, %0\n" |
98 | "movlpd %%xmm2, %0\n" |
99 | : "=m" (after_arg) |
99 | : "=m" (after_arg) |
100 | ); |
100 | ); |
101 | 101 | ||
102 | if (arg != after_arg) { |
102 | if (arg != after_arg) { |
103 | printf("tid%d: arg(%d) != %d\n", THREAD->tid, arg, after_arg); |
103 | printf("tid%d: arg(%d) != %d\n", THREAD->tid, arg, after_arg); |
104 | atomic_inc(&threads_fault); |
104 | atomic_inc(&threads_fault); |
105 | break; |
105 | break; |
106 | } |
106 | } |
107 | } |
107 | } |
108 | atomic_inc(&threads_ok); |
108 | atomic_inc(&threads_ok); |
109 | } |
109 | } |
110 | 110 | ||
111 | 111 | ||
112 | char * test_sse1(void) |
112 | char * test_sse1(bool quiet) |
113 | { |
113 | { |
114 | unsigned int i, total = 0; |
114 | unsigned int i, total = 0; |
115 | 115 | ||
116 | waitq_initialize(&can_start); |
116 | waitq_initialize(&can_start); |
117 | atomic_set(&threads_ok, 0); |
117 | atomic_set(&threads_ok, 0); |
118 | atomic_set(&threads_fault, 0); |
118 | atomic_set(&threads_fault, 0); |
119 | printf("Creating %d threads... ", 2 * THREADS); |
119 | printf("Creating %d threads... ", 2 * THREADS); |
120 | 120 | ||
121 | for (i = 0; i < THREADS; i++) { |
121 | for (i = 0; i < THREADS; i++) { |
122 | thread_t *t; |
122 | thread_t *t; |
123 | 123 | ||
124 | if (!(t = thread_create(testit1, (void *) ((unative_t) 2 * i), TASK, 0, "testit1", false))) { |
124 | if (!(t = thread_create(testit1, (void *) ((unative_t) 2 * i), TASK, 0, "testit1", false))) { |
125 | printf("could not create thread %d\n", 2 * i); |
125 | printf("could not create thread %d\n", 2 * i); |
126 | break; |
126 | break; |
127 | } |
127 | } |
128 | thread_ready(t); |
128 | thread_ready(t); |
129 | total++; |
129 | total++; |
130 | 130 | ||
131 | if (!(t = thread_create(testit2, (void *) ((unative_t) 2 * i + 1), TASK, 0, "testit2", false))) { |
131 | if (!(t = thread_create(testit2, (void *) ((unative_t) 2 * i + 1), TASK, 0, "testit2", false))) { |
132 | printf("could not create thread %d\n", 2 * i + 1); |
132 | printf("could not create thread %d\n", 2 * i + 1); |
133 | break; |
133 | break; |
134 | } |
134 | } |
135 | thread_ready(t); |
135 | thread_ready(t); |
136 | total++; |
136 | total++; |
137 | } |
137 | } |
138 | printf("ok\n"); |
138 | printf("ok\n"); |
139 | 139 | ||
140 | thread_sleep(1); |
140 | thread_sleep(1); |
141 | waitq_wakeup(&can_start, WAKEUP_ALL); |
141 | waitq_wakeup(&can_start, WAKEUP_ALL); |
142 | 142 | ||
143 | while (atomic_get(&threads_ok) != total) { |
143 | while (atomic_get(&threads_ok) != total) { |
144 | printf("Threads left: %d\n", total - atomic_get(&threads_ok)); |
144 | printf("Threads left: %d\n", total - atomic_get(&threads_ok)); |
145 | thread_sleep(1); |
145 | thread_sleep(1); |
146 | } |
146 | } |
147 | 147 | ||
148 | if (atomic_get(&threads_fault) == 0) |
148 | if (atomic_get(&threads_fault) == 0) |
149 | return NULL; |
149 | return NULL; |
150 | 150 | ||
151 | return "Test failed"; |
151 | return "Test failed"; |
152 | } |
152 | } |
153 | 153 | ||
154 | #endif |
154 | #endif |
155 | 155 |