1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
|
#include <cpu.h>
#include <graphics/lfb.h>
#include <sys/schedule.h>
#include <usr/math.h>
#include <usr/string.h>
#include <util/mutex.h>
#define MAX_ITER 8192
#define MULTIPLIER 1000000/900
static unsigned long ti, tf;
static unsigned long times[MAX_ITER];
static unsigned long idx = 0;
void test_results(unsigned long off)
{
unsigned long mean=0, stdev=0, max=0;
for (unsigned long i = 0; i < MAX_ITER; i++) {
mean += times[i];
if (times[i] > max)
max = times[i];
}
mean /= MAX_ITER;
for (unsigned long i = 0; i < MAX_ITER; i++) {
unsigned long term = (times[i]-mean)*(times[i]-mean)/MAX_ITER;
stdev += term;
}
stdev = sqrt_rnd(stdev);
char str[] = " ns\0";
char* start;
start = ulong_to_string(mean, str);
draw_string(off*15, 12, start);
start = ulong_to_string(stdev, str);
draw_string(off*15, 13, start);
start = ulong_to_string(max, str);
draw_string(off*15, 14, start);
}
void nopfxn(void) {}
void trace_test(void)
{
sys0_32(SYS_TIME_2, &ti);
sys0_32(SYS_TIME_2, &tf);
times[idx++] = (tf-ti)*MULTIPLIER;
}
void switch_test(void)
{
sys0_32(SYS_TIME_2, &ti);
sys0(SYS_YIELD);
sys0_32(SYS_TIME_2, &tf);
times[idx++] = (tf-ti)*MULTIPLIER;
}
void add_low_test(void)
{
sys0_32(SYS_TIME_2, &ti);
add_thread(nopfxn, 0, 6);
sys0_32(SYS_TIME_2, &tf);
times[idx++] = (tf-ti)*MULTIPLIER;
}
void add_high_test(void)
{
sys0_32(SYS_TIME_2, &ti);
add_thread(nopfxn, 0, 1);
sys0_32(SYS_TIME_2, &tf);
times[idx++] = (tf-ti)*MULTIPLIER;
}
void mutex_create_test(void)
{
struct Mutex* m;
sys0_32(SYS_TIME_2, &ti);
m = create_mutex(0);
sys0_32(SYS_TIME_2, &tf);
delete_mutex(m);
times[idx++] = (tf-ti)*MULTIPLIER;
}
void mutex_delete_test(void)
{
struct Mutex* m = create_mutex(0);
sys0_32(SYS_TIME_2, &ti);
delete_mutex(m);
sys0_32(SYS_TIME_2, &tf);
times[idx++] = (tf-ti)*MULTIPLIER;
}
void mutex_lock_test(struct Mutex* m)
{
sys0_32(SYS_TIME_2, &ti);
lock_mutex(m);
sys0_32(SYS_TIME_2, &tf);
unlock_mutex(m);
times[idx++] = (tf-ti)*MULTIPLIER;
}
void mutex_unlock_test(struct Mutex* m)
{
lock_mutex(m);
sys0_32(SYS_TIME_2, &ti);
unlock_mutex(m);
sys0_32(SYS_TIME_2, &tf);
times[idx++] = (tf-ti)*MULTIPLIER;
}
void semaphore_p_test(unsigned long* sem)
{
sys0_32(SYS_TIME_2, &ti);
sys1(SYS_SEMAPHORE_P, sem);
sys0_32(SYS_TIME_2, &tf);
times[idx++] = (tf-ti)*MULTIPLIER;
}
void semaphore_v_test(unsigned long* sem)
{
sys0_32(SYS_TIME_2, &ti);
sys1(SYS_SEMAPHORE_V, sem);
sys0_32(SYS_TIME_2, &tf);
times[idx++] = (tf-ti)*MULTIPLIER;
}
void test_super(void)
{
for (unsigned long i = 0; i < MAX_ITER; i++) {
add_thread(trace_test, 0, 2);
}
add_thread(test_results,(void*) 0, 0);idx = 0;
for (unsigned long i = 0; i < MAX_ITER; i++) {
add_thread(switch_test, 0, 2);
}
add_thread(test_results,(void*) 1, 0);idx = 0;
for (unsigned long i = 0; i < MAX_ITER; i++) {
add_thread(add_low_test, 0, 2);
}
add_thread(test_results,(void*) 2, 0);idx = 0;
for (unsigned long i = 0; i < MAX_ITER; i++) {
add_thread(add_high_test, 0, 2);
}
add_thread(test_results,(void*) 3, 0);idx = 0;
struct Mutex* m;
for (unsigned long i = 0; i < MAX_ITER; i++) {
add_thread(mutex_create_test, 0, 2);
}
add_thread(test_results,(void*) 4, 0);idx = 0;
for (unsigned long i = 0; i < MAX_ITER; i++) {
add_thread(mutex_delete_test, 0, 2);
}
add_thread(test_results,(void*) 5, 0);idx = 0;
for (unsigned long i = 0; i < MAX_ITER; i++) {
m = create_mutex(0);
lock_mutex(m);
add_thread(mutex_lock_test, 0, 2);
unlock_mutex(m);
delete_mutex(m);
}
add_thread(test_results,(void*) 6, 0);idx = 0;
for (unsigned long i = 0; i < MAX_ITER; i++) {
m = create_mutex(0);
add_thread(mutex_lock_test, 0, 2);
delete_mutex(m);
}
add_thread(test_results,(void*) 7, 0);idx = 0;
for (unsigned long i = 0; i < MAX_ITER; i++) {
m = create_mutex(0);
add_thread(mutex_unlock_test, 0, 2);
delete_mutex(m);
}
add_thread(test_results,(void*) 8, 0);idx = 0;
static unsigned long semp = 0;
for (unsigned long i = 0; i < MAX_ITER; i++) {
semp = 1;
add_thread(semaphore_p_test, &semp, 2);
}
add_thread(test_results,(void*) 9, 0);idx = 0;
for (unsigned long i = 0; i < MAX_ITER; i++) {
semp = 0;
add_thread(semaphore_v_test, &semp, 2);
}
add_thread(test_results,(void*) 10, 0);idx = 0;
for (unsigned long i = 0; i < MAX_ITER; i++) {
semp = 1;
add_thread(semaphore_v_test, &semp, 2);
}
add_thread(test_results,(void*) 11, 0);idx = 0;
}
|