source: mainline/kernel/test/fpu/mips2.c@ c8410ec9

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since c8410ec9 was 95155b0c, checked in by Martin Decky <martin@…>, 19 years ago

benchmarking with statistics (initial)

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