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