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