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