comparison packages/kernel/current/tests/tm_basic.cxx @ 2:443894e2e912 ecos-v1_2_1-release

Block commit of eCos version 1.2.1
author jlarmour
date Tue, 11 May 1999 12:24:34 +0000
parents 3111d98ba7b3
children 1d7f19c9e4d1
comparison
equal deleted inserted replaced
1:72f549f0d891 2:443894e2e912
20 // 20 //
21 // The Original Code is eCos - Embedded Cygnus Operating System, released 21 // The Original Code is eCos - Embedded Cygnus Operating System, released
22 // September 30, 1998. 22 // September 30, 1998.
23 // 23 //
24 // The Initial Developer of the Original Code is Cygnus. Portions created 24 // The Initial Developer of the Original Code is Cygnus. Portions created
25 // by Cygnus are Copyright (C) 1998 Cygnus Solutions. All Rights Reserved. 25 // by Cygnus are Copyright (C) 1998,1999 Cygnus Solutions. All Rights Reserved.
26 // ------------------------------------------- 26 // -------------------------------------------
27 // 27 //
28 //####COPYRIGHTEND#### 28 //####COPYRIGHTEND####
29 //========================================================================== 29 //==========================================================================
30 //#####DESCRIPTIONBEGIN#### 30 //#####DESCRIPTIONBEGIN####
31 // 31 //
32 // Author(s): gthomas 32 // Author(s): gthomas
33 // Contributors: gthomas 33 // Contributors: gthomas
34 // Date: 1998-10-19 34 // Date: 1998-10-19
35 // Description: Very simple timing test setup 35 // Description: Very simple kernel timing test
36 //####DESCRIPTIONEND#### 36 //####DESCRIPTIONEND####
37 37
38 #include <pkgconf/kernel.h> 38 #include <pkgconf/kernel.h>
39 39
40 #include <cyg/kernel/sched.hxx> 40 #include <cyg/kernel/sched.hxx>
46 #include <cyg/kernel/clock.hxx> 46 #include <cyg/kernel/clock.hxx>
47 #include <cyg/kernel/clock.inl> 47 #include <cyg/kernel/clock.inl>
48 #include <cyg/kernel/kapi.h> 48 #include <cyg/kernel/kapi.h>
49 49
50 #include <cyg/infra/testcase.h> 50 #include <cyg/infra/testcase.h>
51
52 // Define this to see the statistics with the first sample datum removed.
53 // This can expose the effects of caches on the speed of operations.
54 #undef STATS_WITHOUT_FIRST_SAMPLE
55
56 #if defined(CYGFUN_KERNEL_API_C) && \
57 defined(CYGSEM_KERNEL_SCHED_MLQUEUE) && \
58 defined(CYGVAR_KERNEL_COUNTERS_CLOCK) && \
59 !defined(CYGPKG_HAL_I386_LINUX) && \
60 (CYGNUM_KERNEL_SCHED_PRIORITIES > 12)
61
51 #define NTHREADS 1 62 #define NTHREADS 1
52 #include "testaux.hxx" 63 #include "testaux.hxx"
53 64
54 // Structure used to keep track of times 65 // Structure used to keep track of times
55 typedef struct fun_times { 66 typedef struct fun_times {
56 cyg_uint32 start; 67 cyg_uint32 start;
57 cyg_uint32 end; 68 cyg_uint32 end;
58 } fun_times; 69 } fun_times;
59 70
60 #define NSAMPLES 10 71 #define NSAMPLES 32
61 #define NTEST_THREADS 32 72 #define NTEST_THREADS 24
62 #define NTHREAD_SWITCHES 128 73 #define NTHREAD_SWITCHES 128
63 #define NMUTEXES 32 74 #define NMUTEXES 32
64 #define NMBOXES 32 75 #define NMBOXES 32
65 #define NSEMAPHORES 32 76 #define NSEMAPHORES 32
66 #define NSCHEDS 128 77 #define NSCHEDS 128
67 #define NCOUNTERS 32 78 #define NCOUNTERS 32
68 #define NALARMS 32 79 #define NALARMS 32
69 80
70 #define STACK_SIZE 2048 // Is this large enough? 81 #define NSAMPLES_SIM 2
82 #define NTEST_THREADS_SIM 2
83 #define NTHREAD_SWITCHES_SIM 4
84 #define NMUTEXES_SIM 2
85 #define NMBOXES_SIM 2
86 #define NSEMAPHORES_SIM 2
87 #define NSCHEDS_SIM 4
88 #define NCOUNTERS_SIM 2
89 #define NALARMS_SIM 2
90
91 static int nsamples;
92 static int ntest_threads;
93 static int nthread_switches;
94 static int nmutexes;
95 static int nmboxes;
96 static int nsemaphores;
97 static int nscheds;
98 static int ncounters;
99 static int nalarms;
100
101 #define STACK_SIZE CYGNUM_HAL_STACK_SIZE_MINIMUM
102
71 static char stacks[NTEST_THREADS][STACK_SIZE]; 103 static char stacks[NTEST_THREADS][STACK_SIZE];
72 static cyg_thread test_threads[NTEST_THREADS]; 104 static cyg_thread test_threads[NTEST_THREADS];
73 static cyg_handle_t threads[NTEST_THREADS]; 105 static cyg_handle_t threads[NTEST_THREADS];
74 static int overhead; 106 static int overhead;
75 static cyg_sem_t synchro; 107 static cyg_sem_t synchro;
101 133
102 static cyg_alarm test_alarms[NALARMS]; 134 static cyg_alarm test_alarms[NALARMS];
103 static cyg_handle_t alarms[NALARMS]; 135 static cyg_handle_t alarms[NALARMS];
104 static fun_times alarm_ft[NALARMS]; 136 static fun_times alarm_ft[NALARMS];
105 137
138 static long rtc_resolution[] = CYGNUM_KERNEL_COUNTERS_RTC_RESOLUTION;
139 static long ns_per_system_clock;
140
141 #ifdef HAL_CLOCK_LATENCY
142 // Data kept by kernel real time clock measuring clock interrupt latency
143 extern cyg_tick_count total_clock_latency, total_clock_interrupts;
144 extern cyg_int32 min_clock_latency, max_clock_latency;
145 extern bool measure_clock_latency;
146 #endif
147
106 externC void diag_printf(const char *, ...); 148 externC void diag_printf(const char *, ...);
107 externC void sprintf(char *, const char *, ...);
108 149
109 void run_sched_tests(void); 150 void run_sched_tests(void);
110 void run_thread_tests(void); 151 void run_thread_tests(void);
111 void run_thread_switch_test(void); 152 void run_thread_switch_test(void);
112 void run_mutex_tests(void); 153 void run_mutex_tests(void);
116 void run_semaphore_tests(void); 157 void run_semaphore_tests(void);
117 void run_semaphore_circuit_test(void); 158 void run_semaphore_circuit_test(void);
118 void run_counter_tests(void); 159 void run_counter_tests(void);
119 void run_alarm_tests(void); 160 void run_alarm_tests(void);
120 161
121 #ifdef HAL_CLOCK_LATENCY
122 extern cyg_tick_count total_clock_latency, total_clock_interrupts;
123 extern cyg_int32 min_clock_latency, max_clock_latency;
124 #endif
125
126 cyg_uint32
127 ticks_to_us(cyg_uint32 ticks)
128 {
129 int us;
130 // Assumes that the clock is set up for 10ms ticks
131 us = (10000 * ticks) / CYGNUM_KERNEL_COUNTERS_RTC_PERIOD;
132 return (us);
133 }
134
135 // Wait until a clock tick [real time clock] has passed. This should keep it 162 // Wait until a clock tick [real time clock] has passed. This should keep it
136 // from happening again during a measurement, thus minimizing any fluctuations 163 // from happening again during a measurement, thus minimizing any fluctuations
137 void 164 void
138 wait_for_tick(void) 165 wait_for_tick(void)
139 { 166 {
140 cyg_uint32 tv0, tv1; 167 cyg_tick_count_t tv0, tv1;
141 HAL_CLOCK_READ(&tv0); 168 tv0 = cyg_current_time();
142 while (true) { 169 while (true) {
143 HAL_CLOCK_READ(&tv1); 170 tv1 = cyg_current_time();
144 if (tv1 < tv0) break; 171 if (tv1 != tv0) break;
145 tv0 = tv1; 172 }
146 } 173 }
174
175 // Display a number of ticks as microseconds
176 // Note: for improved calculation significance, values are kept in ticks*1000
177 void
178 show_ticks_in_us(cyg_uint32 ticks)
179 {
180 long long ns;
181 ns = (ns_per_system_clock * (long long)ticks) / CYGNUM_KERNEL_COUNTERS_RTC_PERIOD;
182 ns += 5; // for rounding to .01us
183 diag_printf("%5d.%02d", (int)(ns/1000), (int)((ns%1000)/10));
184 }
185
186 //
187 // If the kernel is instrumented to measure clock interrupt latency, these
188 // measurements can be drastically perturbed by printing via "diag_printf()"
189 // since that code may run with interrupts disabled for long periods.
190 //
191 // In order to get accurate/reasonable latency figures _for the kernel
192 // primitive functions beint tested_, the kernel's latency measurements
193 // are suspended while the printing actually takes place.
194 //
195 // The measurements are reenabled after the printing, thus allowing for
196 // fair measurements of the kernel primitives, which are not distorted
197 // by the printing mechanisms.
198
199 #ifdef HAL_CLOCK_LATENCY
200 void
201 disable_clock_latency_measurement(void)
202 {
203 wait_for_tick();
204 measure_clock_latency = false;
205 }
206
207 void
208 enable_clock_latency_measurement(void)
209 {
210 wait_for_tick();
211 measure_clock_latency = true;
212 }
213
214 // Ensure that the measurements are reasonable (no startup anomalies)
215 void
216 reset_clock_latency_measurement(void)
217 {
218 disable_clock_latency_measurement();
219 total_clock_latency = 0;
220 total_clock_interrupts = 0;
221 min_clock_latency = 0x7FFFFFFF;
222 max_clock_latency = 0;
223 enable_clock_latency_measurement();
224 }
225 #else
226 #define disable_clock_latency_measurement()
227 #define enable_clock_latency_measurement()
228 #define reset_clock_latency_measurement()
229 #endif
230
231 void
232 show_times_hdr(void)
233 {
234 disable_clock_latency_measurement();
235 diag_printf("\n");
236 diag_printf(" Confidence\n");
237 diag_printf(" Ave Min Max Var Ave Min Function\n");
238 diag_printf(" ====== ====== ====== ====== ========== ========\n");
239 enable_clock_latency_measurement();
240 }
241
242 void
243 show_times_detail(fun_times ft[], int nsamples, char *title, bool ignore_first)
244 {
245 int i, delta, min, max, con_ave, con_min, ave_dev;
246 int start_sample, total_samples;
247 cyg_int32 total, ave;
248
249 if (ignore_first) {
250 start_sample = 1;
251 total_samples = nsamples-1;
252 } else {
253 start_sample = 0;
254 total_samples = nsamples;
255 }
256 total = 0;
257 min = 0x7FFFFFFF;
258 max = 0;
259 for (i = start_sample; i < nsamples; i++) {
260 if (ft[i].end < ft[i].start) {
261 // Clock wrapped around (timer tick)
262 delta = (ft[i].end+CYGNUM_KERNEL_COUNTERS_RTC_PERIOD) - ft[i].start;
263 } else {
264 delta = ft[i].end - ft[i].start;
265 }
266 delta -= overhead;
267 if (delta < 0) delta = 0;
268 delta *= 1000;
269 total += delta;
270 if (delta < min) min = delta;
271 if (delta > max) max = delta;
272 }
273 ave = total / total_samples;
274 total = 0;
275 ave_dev = 0;
276 for (i = start_sample; i < nsamples; i++) {
277 if (ft[i].end < ft[i].start) {
278 // Clock wrapped around (timer tick)
279 delta = (ft[i].end+CYGNUM_KERNEL_COUNTERS_RTC_PERIOD) - ft[i].start;
280 } else {
281 delta = ft[i].end - ft[i].start;
282 }
283 delta -= overhead;
284 if (delta < 0) delta = 0;
285 delta *= 1000;
286 delta = delta - ave;
287 if (delta < 0) delta = -delta;
288 ave_dev += delta;
289 }
290 ave_dev /= total_samples;
291 con_ave = 0;
292 con_min = 0;
293 for (i = start_sample; i < nsamples; i++) {
294 if (ft[i].end < ft[i].start) {
295 // Clock wrapped around (timer tick)
296 delta = (ft[i].end+CYGNUM_KERNEL_COUNTERS_RTC_PERIOD) - ft[i].start;
297 } else {
298 delta = ft[i].end - ft[i].start;
299 }
300 delta -= overhead;
301 if (delta < 0) delta = 0;
302 delta *= 1000;
303 if ((delta <= (ave+ave_dev)) && (delta >= (ave-ave_dev))) con_ave++;
304 if ((delta <= (min+ave_dev)) && (delta >= (min-ave_dev))) con_min++;
305 }
306 con_ave = (con_ave * 100) / total_samples;
307 con_min = (con_min * 100) / total_samples;
308 show_ticks_in_us(ave);
309 show_ticks_in_us(min);
310 show_ticks_in_us(max);
311 show_ticks_in_us(ave_dev);
312 disable_clock_latency_measurement();
313 diag_printf(" %3d%% %3d%%", con_ave, con_min);
314 diag_printf(" %s\n", title);
315 enable_clock_latency_measurement();
316 }
317
318 void
319 show_times(fun_times ft[], int nsamples, char *title)
320 {
321 show_times_detail(ft, nsamples, title, false);
322 #ifdef STATS_WITHOUT_FIRST_SAMPLE
323 show_times_detail(ft, nsamples, "", true);
324 #endif
325 }
326
327 void
328 show_test_parameters(void)
329 {
330 disable_clock_latency_measurement();
331 diag_printf("\nTesting parameters:\n");
332 diag_printf(" Clock samples: %3d\n", nsamples);
333 diag_printf(" Threads: %3d\n", ntest_threads);
334 diag_printf(" Thread switches: %3d\n", nthread_switches);
335 diag_printf(" Mutexes: %3d\n", nmutexes);
336 diag_printf(" Mailboxes: %3d\n", nmboxes);
337 diag_printf(" Semaphores: %3d\n", nsemaphores);
338 diag_printf(" Scheduler operations: %3d\n", nscheds);
339 diag_printf(" Counters: %3d\n", ncounters);
340 diag_printf(" Alarms: %3d\n", nalarms);
341 diag_printf("\n");
342 enable_clock_latency_measurement();
343 }
344
345 void
346 end_of_test_group(void)
347 {
348 disable_clock_latency_measurement();
349 diag_printf("\n");
350 enable_clock_latency_measurement();
147 } 351 }
148 352
149 // Compute a name for a thread 353 // Compute a name for a thread
150 char * 354 char *
151 thread_name(char *basename, int indx) { 355 thread_name(char *basename, int indx) {
162 366
163 // test1 - empty test, simply exit. Last thread signals parent. 367 // test1 - empty test, simply exit. Last thread signals parent.
164 void 368 void
165 test1(cyg_uint32 indx) 369 test1(cyg_uint32 indx)
166 { 370 {
167 if (indx == (NTEST_THREADS-1)) { 371 if (indx == (cyg_uint32)(ntest_threads-1)) {
168 cyg_semaphore_post(&synchro); // Signal that last thread is dying 372 cyg_semaphore_post(&synchro); // Signal that last thread is dying
169 } 373 }
170 cyg_thread_exit(); 374 cyg_thread_exit();
171 } 375 }
172 376
173 // test2 - measure thread switch times 377 // test2 - measure thread switch times
174 void 378 void
175 test2(cyg_uint32 indx) 379 test2(cyg_uint32 indx)
176 { 380 {
177 int i; 381 int i;
178 for (i = 0; i < NTHREAD_SWITCHES; i++) { 382 for (i = 0; i < nthread_switches; i++) {
179 if (indx == 0) { 383 if (indx == 0) {
180 HAL_CLOCK_READ(&test2_ft[i].start); 384 HAL_CLOCK_READ(&test2_ft[i].start);
181 } else { 385 } else {
182 HAL_CLOCK_READ(&test2_ft[i].end); 386 HAL_CLOCK_READ(&test2_ft[i].end);
183 } 387 }
193 void 397 void
194 mutex_test(cyg_uint32 indx) 398 mutex_test(cyg_uint32 indx)
195 { 399 {
196 int i; 400 int i;
197 cyg_mutex_lock(&test_mutexes[0]); 401 cyg_mutex_lock(&test_mutexes[0]);
198 for (i = 0; i < NMUTEXES; i++) { 402 for (i = 0; i < nmutexes; i++) {
199 cyg_semaphore_wait(&synchro); 403 cyg_semaphore_wait(&synchro);
200 wait_for_tick(); // Wait until the next clock tick to minimize aberations 404 wait_for_tick(); // Wait until the next clock tick to minimize aberations
201 HAL_CLOCK_READ(&mutex_ft[i].start); 405 HAL_CLOCK_READ(&mutex_ft[i].start);
202 cyg_mutex_unlock(&test_mutexes[0]); 406 cyg_mutex_unlock(&test_mutexes[0]);
203 cyg_mutex_lock(&test_mutexes[0]); 407 cyg_mutex_lock(&test_mutexes[0]);
213 void *item; 417 void *item;
214 do { 418 do {
215 item = cyg_mbox_get(test_mbox_handles[0]); 419 item = cyg_mbox_get(test_mbox_handles[0]);
216 HAL_CLOCK_READ(&mbox_ft[(int)item].end); 420 HAL_CLOCK_READ(&mbox_ft[(int)item].end);
217 cyg_semaphore_post(&synchro); 421 cyg_semaphore_post(&synchro);
218 } while ((int)item != (NMBOXES-1)); 422 } while ((int)item != (nmboxes-1));
219 cyg_thread_exit(); 423 cyg_thread_exit();
220 } 424 }
221 425
222 // Full-circuit semaphore post/wait test 426 // Full-circuit semaphore post/wait test
223 void 427 void
224 semaphore_test(cyg_uint32 indx) 428 semaphore_test(cyg_uint32 indx)
225 { 429 {
226 int i; 430 int i;
227 for (i = 0; i < NSEMAPHORES; i++) { 431 for (i = 0; i < nsemaphores; i++) {
228 cyg_semaphore_wait(&test_semaphores[0]); 432 cyg_semaphore_wait(&test_semaphores[0]);
229 HAL_CLOCK_READ(&semaphore_ft[i].end); 433 HAL_CLOCK_READ(&semaphore_ft[i].end);
230 cyg_semaphore_post(&synchro); 434 cyg_semaphore_post(&synchro);
231 } 435 }
232 cyg_thread_exit(); 436 cyg_thread_exit();
233 } 437 }
234 438
235 void 439 //
236 show_times_hdr(void) 440 // This set of tests is used to measure kernel primitives that deal with threads
237 { 441 //
238 diag_printf("\n");
239 diag_printf(" Ave Min Max Variance Function\n");
240 diag_printf("====== ====== ====== ======== ========\n");
241 }
242
243 void
244 show_times(fun_times ft[], int nsamples, char *title)
245 {
246 int i, delta, min, max;
247 cyg_uint32 total, ave, var;
248 total = 0;
249 min = 0x7FFFFFFF;
250 max = 0;
251 for (i = 0; i < nsamples; i++) {
252 if (ft[i].end < ft[i].start) {
253 // Clock wrapped around (timer tick)
254 delta = (ft[i].end+CYGNUM_KERNEL_COUNTERS_RTC_PERIOD) - ft[i].start;
255 } else {
256 delta = ft[i].end - ft[i].start;
257 }
258 delta -= 2*overhead;
259 if (delta < 0) delta = 0;
260 total += delta;
261 if (delta < min) min = delta;
262 if (delta > max) max = delta;
263 }
264 ave = total / nsamples;
265 total = 0;
266 for (i = 0; i < nsamples; i++) {
267 if (ft[i].end < ft[i].start) {
268 // Clock wrapped around (timer tick)
269 delta = (ft[i].end+CYGNUM_KERNEL_COUNTERS_RTC_PERIOD) - ft[i].start;
270 } else {
271 delta = ft[i].end - ft[i].start;
272 }
273 delta -= 2*overhead;
274 if (delta < 0) delta = 0;
275 total = (delta - ave) * (delta - ave);
276 }
277 var = total / (nsamples - 1);
278 diag_printf("%6d %6d %6d %6d %s\n",
279 ticks_to_us(ave), ticks_to_us(min), ticks_to_us(max), ticks_to_us(var), title);
280 }
281
282 void
283 show_test_parameters(void)
284 {
285 diag_printf("\nTesting parameters:\n");
286 diag_printf(" Clock samples: %3d\n", NSAMPLES);
287 diag_printf(" Threads: %3d\n", NTEST_THREADS);
288 diag_printf(" Thread switches: %3d\n", NTHREAD_SWITCHES);
289 diag_printf(" Mutexes: %3d\n", NMUTEXES);
290 diag_printf(" Mailboxes: %3d\n", NMBOXES);
291 diag_printf(" Semaphores: %3d\n", NSEMAPHORES);
292 diag_printf(" Scheduler operations: %3d\n", NSCHEDS);
293 diag_printf(" Counters: %3d\n", NCOUNTERS);
294 diag_printf(" Alarms: %3d\n", NALARMS);
295 diag_printf("\n");
296 }
297
298 void 442 void
299 run_thread_tests(void) 443 run_thread_tests(void)
300 { 444 {
301 int i; 445 int i;
302 cyg_priority_t prio; 446 cyg_priority_t prio;
303 447
304 // Set my priority higher than any I plan to create 448 // Set my priority higher than any I plan to create
305 cyg_thread_set_priority(cyg_thread_self(), 2); 449 cyg_thread_set_priority(cyg_thread_self(), 2);
306 450
307 wait_for_tick(); // Wait until the next clock tick to minimize aberations 451 wait_for_tick(); // Wait until the next clock tick to minimize aberations
308 for (i = 0; i < NTEST_THREADS; i++) { 452 for (i = 0; i < ntest_threads; i++) {
309 HAL_CLOCK_READ(&thread_ft[i].start); 453 HAL_CLOCK_READ(&thread_ft[i].start);
310 cyg_thread_create(10, // Priority - just a number 454 cyg_thread_create(10, // Priority - just a number
311 test0, // entry 455 test0, // entry
312 i, // index 456 i, // index
313 thread_name("thread", i), // Name 457 thread_name("thread", i), // Name
316 &threads[i], // Handle 460 &threads[i], // Handle
317 &test_threads[i] // Thread data structure 461 &test_threads[i] // Thread data structure
318 ); 462 );
319 HAL_CLOCK_READ(&thread_ft[i].end); 463 HAL_CLOCK_READ(&thread_ft[i].end);
320 } 464 }
321 show_times(thread_ft, NTEST_THREADS, "Create thread"); 465 show_times(thread_ft, ntest_threads, "Create thread");
322 466
323 wait_for_tick(); // Wait until the next clock tick to minimize aberations 467 wait_for_tick(); // Wait until the next clock tick to minimize aberations
324 for (i = 0; i < NTEST_THREADS; i++) { 468 for (i = 0; i < ntest_threads; i++) {
325 HAL_CLOCK_READ(&thread_ft[i].start); 469 HAL_CLOCK_READ(&thread_ft[i].start);
326 cyg_thread_yield(); 470 cyg_thread_yield();
327 HAL_CLOCK_READ(&thread_ft[i].end); 471 HAL_CLOCK_READ(&thread_ft[i].end);
328 } 472 }
329 show_times(thread_ft, NTEST_THREADS, "Yield thread [all suspended]"); 473 show_times(thread_ft, ntest_threads, "Yield thread [all suspended]");
330 474
331 wait_for_tick(); // Wait until the next clock tick to minimize aberations 475 wait_for_tick(); // Wait until the next clock tick to minimize aberations
332 for (i = 0; i < NTEST_THREADS; i++) { 476 for (i = 0; i < ntest_threads; i++) {
333 HAL_CLOCK_READ(&thread_ft[i].start); 477 HAL_CLOCK_READ(&thread_ft[i].start);
334 cyg_thread_suspend(threads[i]); 478 cyg_thread_suspend(threads[i]);
335 HAL_CLOCK_READ(&thread_ft[i].end); 479 HAL_CLOCK_READ(&thread_ft[i].end);
336 } 480 }
337 show_times(thread_ft, NTEST_THREADS, "Suspend [suspended] thread"); 481 show_times(thread_ft, ntest_threads, "Suspend [suspended] thread");
338 482
339 wait_for_tick(); // Wait until the next clock tick to minimize aberations 483 wait_for_tick(); // Wait until the next clock tick to minimize aberations
340 for (i = 0; i < NTEST_THREADS; i++) { 484 for (i = 0; i < ntest_threads; i++) {
341 HAL_CLOCK_READ(&thread_ft[i].start); 485 HAL_CLOCK_READ(&thread_ft[i].start);
342 cyg_thread_resume(threads[i]); 486 cyg_thread_resume(threads[i]);
343 HAL_CLOCK_READ(&thread_ft[i].end); 487 HAL_CLOCK_READ(&thread_ft[i].end);
344 } 488 }
345 show_times(thread_ft, NTEST_THREADS, "Resume thread"); 489 show_times(thread_ft, ntest_threads, "Resume thread");
346 490
347 wait_for_tick(); // Wait until the next clock tick to minimize aberations 491 wait_for_tick(); // Wait until the next clock tick to minimize aberations
348 for (i = 0; i < NTEST_THREADS; i++) { 492 for (i = 0; i < ntest_threads; i++) {
349 HAL_CLOCK_READ(&thread_ft[i].start); 493 HAL_CLOCK_READ(&thread_ft[i].start);
350 cyg_thread_set_priority(threads[i], 11); 494 cyg_thread_set_priority(threads[i], 11);
351 HAL_CLOCK_READ(&thread_ft[i].end); 495 HAL_CLOCK_READ(&thread_ft[i].end);
352 } 496 }
353 show_times(thread_ft, NTEST_THREADS, "Set priority"); 497 show_times(thread_ft, ntest_threads, "Set priority");
354 498
355 wait_for_tick(); // Wait until the next clock tick to minimize aberations 499 wait_for_tick(); // Wait until the next clock tick to minimize aberations
356 for (i = 0; i < NTEST_THREADS; i++) { 500 for (i = 0; i < ntest_threads; i++) {
357 HAL_CLOCK_READ(&thread_ft[i].start); 501 HAL_CLOCK_READ(&thread_ft[i].start);
358 prio = cyg_thread_get_priority(threads[i]); 502 prio = cyg_thread_get_priority(threads[i]);
359 HAL_CLOCK_READ(&thread_ft[i].end); 503 HAL_CLOCK_READ(&thread_ft[i].end);
360 } 504 }
361 show_times(thread_ft, NTEST_THREADS, "Get priority"); 505 show_times(thread_ft, ntest_threads, "Get priority");
362 506
363 wait_for_tick(); // Wait until the next clock tick to minimize aberations 507 wait_for_tick(); // Wait until the next clock tick to minimize aberations
364 for (i = 0; i < NTEST_THREADS; i++) { 508 for (i = 0; i < ntest_threads; i++) {
365 HAL_CLOCK_READ(&thread_ft[i].start); 509 HAL_CLOCK_READ(&thread_ft[i].start);
366 cyg_thread_kill(threads[i]); 510 cyg_thread_kill(threads[i]);
367 HAL_CLOCK_READ(&thread_ft[i].end); 511 HAL_CLOCK_READ(&thread_ft[i].end);
368 } 512 }
369 show_times(thread_ft, NTEST_THREADS, "Kill [suspended] thread"); 513 show_times(thread_ft, ntest_threads, "Kill [suspended] thread");
370 514
371 wait_for_tick(); // Wait until the next clock tick to minimize aberations 515 wait_for_tick(); // Wait until the next clock tick to minimize aberations
372 for (i = 0; i < NTEST_THREADS; i++) { 516 for (i = 0; i < ntest_threads; i++) {
373 HAL_CLOCK_READ(&thread_ft[i].start); 517 HAL_CLOCK_READ(&thread_ft[i].start);
374 cyg_thread_yield(); 518 cyg_thread_yield();
375 HAL_CLOCK_READ(&thread_ft[i].end); 519 HAL_CLOCK_READ(&thread_ft[i].end);
376 } 520 }
377 show_times(thread_ft, NTEST_THREADS, "Yield [no other] thread"); 521 show_times(thread_ft, ntest_threads, "Yield [no other] thread");
378 522
379 // Set my priority higher than any I plan to create 523 // Set my priority higher than any I plan to create
380 cyg_thread_set_priority(cyg_thread_self(), 2); 524 cyg_thread_set_priority(cyg_thread_self(), 2);
381 525
382 // Recreate the test set 526 // Recreate the test set
383 for (i = 0; i < NTEST_THREADS; i++) { 527 for (i = 0; i < ntest_threads; i++) {
384 cyg_thread_create(10, // Priority - just a number 528 cyg_thread_create(10, // Priority - just a number
385 test0, // entry 529 test0, // entry
386 i, // index 530 i, // index
387 thread_name("thread", i), // Name 531 thread_name("thread", i), // Name
388 &stacks[i][0], // Stack 532 &stacks[i][0], // Stack
391 &test_threads[i] // Thread data structure 535 &test_threads[i] // Thread data structure
392 ); 536 );
393 } 537 }
394 538
395 wait_for_tick(); // Wait until the next clock tick to minimize aberations 539 wait_for_tick(); // Wait until the next clock tick to minimize aberations
396 for (i = 0; i < NTEST_THREADS; i++) { 540 for (i = 0; i < ntest_threads; i++) {
397 HAL_CLOCK_READ(&thread_ft[i].start); 541 HAL_CLOCK_READ(&thread_ft[i].start);
398 cyg_thread_resume(threads[i]); 542 cyg_thread_resume(threads[i]);
399 HAL_CLOCK_READ(&thread_ft[i].end); 543 HAL_CLOCK_READ(&thread_ft[i].end);
400 } 544 }
401 show_times(thread_ft, NTEST_THREADS, "Resume [suspended low priority] thread"); 545 show_times(thread_ft, ntest_threads, "Resume [suspended low prio] thread");
402 546
403 wait_for_tick(); // Wait until the next clock tick to minimize aberations 547 wait_for_tick(); // Wait until the next clock tick to minimize aberations
404 for (i = 0; i < NTEST_THREADS; i++) { 548 for (i = 0; i < ntest_threads; i++) {
405 HAL_CLOCK_READ(&thread_ft[i].start); 549 HAL_CLOCK_READ(&thread_ft[i].start);
406 cyg_thread_resume(threads[i]); 550 cyg_thread_resume(threads[i]);
407 HAL_CLOCK_READ(&thread_ft[i].end); 551 HAL_CLOCK_READ(&thread_ft[i].end);
408 } 552 }
409 show_times(thread_ft, NTEST_THREADS, "Resume [runnable low priority] thread"); 553 show_times(thread_ft, ntest_threads, "Resume [runnable low prio] thread");
410 554
411 wait_for_tick(); // Wait until the next clock tick to minimize aberations 555 wait_for_tick(); // Wait until the next clock tick to minimize aberations
412 for (i = 0; i < NTEST_THREADS; i++) { 556 for (i = 0; i < ntest_threads; i++) {
413 HAL_CLOCK_READ(&thread_ft[i].start); 557 HAL_CLOCK_READ(&thread_ft[i].start);
414 cyg_thread_suspend(threads[i]); 558 cyg_thread_suspend(threads[i]);
415 HAL_CLOCK_READ(&thread_ft[i].end); 559 HAL_CLOCK_READ(&thread_ft[i].end);
416 } 560 }
417 show_times(thread_ft, NTEST_THREADS, "Suspend [runnable] thread"); 561 show_times(thread_ft, ntest_threads, "Suspend [runnable] thread");
418 562
419 563
420 wait_for_tick(); // Wait until the next clock tick to minimize aberations 564 wait_for_tick(); // Wait until the next clock tick to minimize aberations
421 for (i = 0; i < NTEST_THREADS; i++) { 565 for (i = 0; i < ntest_threads; i++) {
422 HAL_CLOCK_READ(&thread_ft[i].start); 566 HAL_CLOCK_READ(&thread_ft[i].start);
423 cyg_thread_yield(); 567 cyg_thread_yield();
424 HAL_CLOCK_READ(&thread_ft[i].end); 568 HAL_CLOCK_READ(&thread_ft[i].end);
425 } 569 }
426 show_times(thread_ft, NTEST_THREADS, "Yield [only low prio] thread"); 570 show_times(thread_ft, ntest_threads, "Yield [only low prio] thread");
427 571
428 wait_for_tick(); // Wait until the next clock tick to minimize aberations 572 wait_for_tick(); // Wait until the next clock tick to minimize aberations
429 for (i = 0; i < NTEST_THREADS; i++) { 573 for (i = 0; i < ntest_threads; i++) {
430 HAL_CLOCK_READ(&thread_ft[i].start); 574 HAL_CLOCK_READ(&thread_ft[i].start);
431 cyg_thread_suspend(threads[i]); 575 cyg_thread_suspend(threads[i]);
432 HAL_CLOCK_READ(&thread_ft[i].end); 576 HAL_CLOCK_READ(&thread_ft[i].end);
433 } 577 }
434 show_times(thread_ft, NTEST_THREADS, "Suspend [runnable->not runnable] thread"); 578 show_times(thread_ft, ntest_threads, "Suspend [runnable->not runnable]");
435 for (i = 0; i < NTEST_THREADS; i++) { 579 for (i = 0; i < ntest_threads; i++) {
436 cyg_thread_resume(threads[i]); 580 cyg_thread_resume(threads[i]);
437 } 581 }
438 582
439 wait_for_tick(); // Wait until the next clock tick to minimize aberations 583 wait_for_tick(); // Wait until the next clock tick to minimize aberations
440 for (i = 0; i < NTEST_THREADS; i++) { 584 for (i = 0; i < ntest_threads; i++) {
441 HAL_CLOCK_READ(&thread_ft[i].start); 585 HAL_CLOCK_READ(&thread_ft[i].start);
442 cyg_thread_kill(threads[i]); 586 cyg_thread_kill(threads[i]);
443 HAL_CLOCK_READ(&thread_ft[i].end); 587 HAL_CLOCK_READ(&thread_ft[i].end);
444 } 588 }
445 show_times(thread_ft, NTEST_THREADS, "Kill [runnable] thread"); 589 show_times(thread_ft, ntest_threads, "Kill [runnable] thread");
590
591 wait_for_tick(); // Wait until the next clock tick to minimize aberations
592 for (i = 0; i < ntest_threads; i++) {
593 HAL_CLOCK_READ(&thread_ft[i].start);
594 cyg_thread_delete(threads[i]);
595 HAL_CLOCK_READ(&thread_ft[i].end);
596 }
597 show_times(thread_ft, ntest_threads, "Destroy [dead] thread");
598
599 // Recreate the test set
600 for (i = 0; i < ntest_threads; i++) {
601 cyg_thread_create(10, // Priority - just a number
602 test0, // entry
603 i, // index
604 thread_name("thread", i), // Name
605 &stacks[i][0], // Stack
606 STACK_SIZE, // Size
607 &threads[i], // Handle
608 &test_threads[i] // Thread data structure
609 );
610 cyg_thread_resume(threads[i]);
611 }
612
613 wait_for_tick(); // Wait until the next clock tick to minimize aberations
614 for (i = 0; i < ntest_threads; i++) {
615 HAL_CLOCK_READ(&thread_ft[i].start);
616 cyg_thread_delete(threads[i]);
617 HAL_CLOCK_READ(&thread_ft[i].end);
618 }
619 show_times(thread_ft, ntest_threads, "Destroy [runnable] thread");
620
446 // Set my priority lower than any I plan to create 621 // Set my priority lower than any I plan to create
447 cyg_thread_set_priority(cyg_thread_self(), 3); 622 cyg_thread_set_priority(cyg_thread_self(), 3);
448 623
449 // Set up the end-of-threads synchronizer 624 // Set up the end-of-threads synchronizer
450 cyg_semaphore_init(&synchro, 0); 625 cyg_semaphore_init(&synchro, 0);
451 626
452 // Recreate the test set 627 // Recreate the test set
453 for (i = 0; i < NTEST_THREADS; i++) { 628 for (i = 0; i < ntest_threads; i++) {
454 cyg_thread_create(2, // Priority - just a number 629 cyg_thread_create(2, // Priority - just a number
455 test1, // entry 630 test1, // entry
456 i, // index 631 i, // index
457 thread_name("thread", i), // Name 632 thread_name("thread", i), // Name
458 &stacks[i][0], // Stack 633 &stacks[i][0], // Stack
461 &test_threads[i] // Thread data structure 636 &test_threads[i] // Thread data structure
462 ); 637 );
463 } 638 }
464 639
465 wait_for_tick(); // Wait until the next clock tick to minimize aberations 640 wait_for_tick(); // Wait until the next clock tick to minimize aberations
466 for (i = 0; i < NTEST_THREADS; i++) { 641 for (i = 0; i < ntest_threads; i++) {
467 HAL_CLOCK_READ(&thread_ft[i].start); 642 HAL_CLOCK_READ(&thread_ft[i].start);
468 cyg_thread_resume(threads[i]); 643 cyg_thread_resume(threads[i]);
469 HAL_CLOCK_READ(&thread_ft[i].end); 644 HAL_CLOCK_READ(&thread_ft[i].end);
470 } 645 }
471 show_times(thread_ft, NTEST_THREADS, "Resume [high priority] thread"); 646 show_times(thread_ft, ntest_threads, "Resume [high priority] thread");
472 cyg_semaphore_wait(&synchro); // Wait for all threads to finish 647 cyg_semaphore_wait(&synchro); // Wait for all threads to finish
473 // Make sure they are all dead 648 // Make sure they are all dead
474 for (i = 0; i < NTEST_THREADS; i++) { 649 for (i = 0; i < ntest_threads; i++) {
475 cyg_thread_kill(threads[i]); 650 cyg_thread_delete(threads[i]);
476 } 651 }
477 652
478 run_thread_switch_test(); 653 run_thread_switch_test();
654 end_of_test_group();
479 } 655 }
480 656
481 void 657 void
482 run_thread_switch_test(void) 658 run_thread_switch_test(void)
483 { 659 {
498 } 674 }
499 // Set up the end-of-threads synchronizer 675 // Set up the end-of-threads synchronizer
500 cyg_semaphore_init(&synchro, 0); 676 cyg_semaphore_init(&synchro, 0);
501 cyg_semaphore_wait(&synchro); 677 cyg_semaphore_wait(&synchro);
502 wait_for_tick(); // Wait until the next clock tick to minimize aberations 678 wait_for_tick(); // Wait until the next clock tick to minimize aberations
503 show_times(test2_ft, NTHREAD_SWITCHES, "Thread switch"); 679 show_times(test2_ft, nthread_switches, "Thread switch");
504 // Clean up 680 // Clean up
505 for (i = 0; i < 2; i++) { 681 for (i = 0; i < 2; i++) {
506 cyg_thread_kill(threads[i]); 682 cyg_thread_delete(threads[i]);
507 } 683 }
508 } 684 }
509 685
510 void 686 void
511 run_mutex_tests(void) 687 run_mutex_tests(void)
512 { 688 {
513 int i; 689 int i;
514 690
515 // Mutex primitives 691 // Mutex primitives
516 wait_for_tick(); // Wait until the next clock tick to minimize aberations 692 wait_for_tick(); // Wait until the next clock tick to minimize aberations
517 for (i = 0; i < NMUTEXES; i++) { 693 for (i = 0; i < nmutexes; i++) {
518 HAL_CLOCK_READ(&mutex_ft[i].start); 694 HAL_CLOCK_READ(&mutex_ft[i].start);
519 cyg_mutex_init(&test_mutexes[i]); 695 cyg_mutex_init(&test_mutexes[i]);
520 HAL_CLOCK_READ(&mutex_ft[i].end); 696 HAL_CLOCK_READ(&mutex_ft[i].end);
521 } 697 }
522 show_times(mutex_ft, NMUTEXES, "Init mutex"); 698 show_times(mutex_ft, nmutexes, "Init mutex");
523 699
524 wait_for_tick(); // Wait until the next clock tick to minimize aberations 700 wait_for_tick(); // Wait until the next clock tick to minimize aberations
525 for (i = 0; i < NMUTEXES; i++) { 701 for (i = 0; i < nmutexes; i++) {
526 HAL_CLOCK_READ(&mutex_ft[i].start); 702 HAL_CLOCK_READ(&mutex_ft[i].start);
527 cyg_mutex_lock(&test_mutexes[i]); 703 cyg_mutex_lock(&test_mutexes[i]);
528 HAL_CLOCK_READ(&mutex_ft[i].end); 704 HAL_CLOCK_READ(&mutex_ft[i].end);
529 } 705 }
530 show_times(mutex_ft, NMUTEXES, "Lock [unlocked] mutex"); 706 show_times(mutex_ft, nmutexes, "Lock [unlocked] mutex");
531 707
532 wait_for_tick(); // Wait until the next clock tick to minimize aberations 708 wait_for_tick(); // Wait until the next clock tick to minimize aberations
533 for (i = 0; i < NMUTEXES; i++) { 709 for (i = 0; i < nmutexes; i++) {
534 HAL_CLOCK_READ(&mutex_ft[i].start); 710 HAL_CLOCK_READ(&mutex_ft[i].start);
535 cyg_mutex_unlock(&test_mutexes[i]); 711 cyg_mutex_unlock(&test_mutexes[i]);
536 HAL_CLOCK_READ(&mutex_ft[i].end); 712 HAL_CLOCK_READ(&mutex_ft[i].end);
537 } 713 }
538 show_times(mutex_ft, NMUTEXES, "Unlock [locked] mutex"); 714 show_times(mutex_ft, nmutexes, "Unlock [locked] mutex");
539 715
540 wait_for_tick(); // Wait until the next clock tick to minimize aberations 716 wait_for_tick(); // Wait until the next clock tick to minimize aberations
541 for (i = 0; i < NMUTEXES; i++) { 717 for (i = 0; i < nmutexes; i++) {
542 HAL_CLOCK_READ(&mutex_ft[i].start); 718 HAL_CLOCK_READ(&mutex_ft[i].start);
543 cyg_mutex_trylock(&test_mutexes[i]); 719 cyg_mutex_trylock(&test_mutexes[i]);
544 HAL_CLOCK_READ(&mutex_ft[i].end); 720 HAL_CLOCK_READ(&mutex_ft[i].end);
545 } 721 }
546 show_times(mutex_ft, NMUTEXES, "Trylock [unlocked] mutex"); 722 show_times(mutex_ft, nmutexes, "Trylock [unlocked] mutex");
547 723
548 wait_for_tick(); // Wait until the next clock tick to minimize aberations 724 wait_for_tick(); // Wait until the next clock tick to minimize aberations
549 for (i = 0; i < NMUTEXES; i++) { 725 for (i = 0; i < nmutexes; i++) {
550 HAL_CLOCK_READ(&mutex_ft[i].start); 726 HAL_CLOCK_READ(&mutex_ft[i].start);
551 cyg_mutex_trylock(&test_mutexes[i]); 727 cyg_mutex_trylock(&test_mutexes[i]);
552 HAL_CLOCK_READ(&mutex_ft[i].end); 728 HAL_CLOCK_READ(&mutex_ft[i].end);
553 } 729 }
554 show_times(mutex_ft, NMUTEXES, "Trylock [locked] mutex"); 730 show_times(mutex_ft, nmutexes, "Trylock [locked] mutex");
555 731
556 wait_for_tick(); // Wait until the next clock tick to minimize aberations 732 wait_for_tick(); // Wait until the next clock tick to minimize aberations
557 for (i = 0; i < NMUTEXES; i++) { 733 for (i = 0; i < nmutexes; i++) {
558 HAL_CLOCK_READ(&mutex_ft[i].start); 734 HAL_CLOCK_READ(&mutex_ft[i].start);
559 cyg_mutex_destroy(&test_mutexes[i]); 735 cyg_mutex_destroy(&test_mutexes[i]);
560 HAL_CLOCK_READ(&mutex_ft[i].end); 736 HAL_CLOCK_READ(&mutex_ft[i].end);
561 } 737 }
562 show_times(mutex_ft, NMUTEXES, "Destroy mutex"); 738 show_times(mutex_ft, nmutexes, "Destroy mutex");
563 run_mutex_circuit_test(); 739 run_mutex_circuit_test();
740 end_of_test_group();
564 } 741 }
565 742
566 void 743 void
567 run_mutex_circuit_test(void) 744 run_mutex_circuit_test(void)
568 { 745 {
582 &mutex_test_thread // Thread data structure 759 &mutex_test_thread // Thread data structure
583 ); 760 );
584 cyg_thread_resume(mutex_test_thread_handle); 761 cyg_thread_resume(mutex_test_thread_handle);
585 // Need to raise priority so that this thread will block on the "lock" 762 // Need to raise priority so that this thread will block on the "lock"
586 cyg_thread_set_priority(cyg_thread_self(), 2); 763 cyg_thread_set_priority(cyg_thread_self(), 2);
587 for (i = 0; i < NMUTEXES; i++) { 764 for (i = 0; i < nmutexes; i++) {
588 cyg_semaphore_post(&synchro); 765 cyg_semaphore_post(&synchro);
589 cyg_mutex_lock(&test_mutexes[0]); 766 cyg_mutex_lock(&test_mutexes[0]);
590 HAL_CLOCK_READ(&mutex_ft[i].end); 767 HAL_CLOCK_READ(&mutex_ft[i].end);
591 cyg_mutex_unlock(&test_mutexes[0]); 768 cyg_mutex_unlock(&test_mutexes[0]);
592 cyg_semaphore_wait(&synchro); 769 cyg_semaphore_wait(&synchro);
593 } 770 }
594 show_times(mutex_ft, NMUTEXES, "Unlock/Lock mutex"); 771 cyg_thread_delete(mutex_test_thread_handle);
772 show_times(mutex_ft, nmutexes, "Unlock/Lock mutex");
595 } 773 }
596 774
597 void 775 void
598 run_mbox_tests(void) 776 run_mbox_tests(void)
599 { 777 {
600 int i, cnt; 778 int i, cnt;
601 void *item; 779 void *item;
602 // Mailbox primitives 780 // Mailbox primitives
603 wait_for_tick(); // Wait until the next clock tick to minimize aberations 781 wait_for_tick(); // Wait until the next clock tick to minimize aberations
604 for (i = 0; i < NMBOXES; i++) { 782 for (i = 0; i < nmboxes; i++) {
605 HAL_CLOCK_READ(&mbox_ft[i].start); 783 HAL_CLOCK_READ(&mbox_ft[i].start);
606 cyg_mbox_create(&test_mbox_handles[i], &test_mboxes[i]); 784 cyg_mbox_create(&test_mbox_handles[i], &test_mboxes[i]);
607 HAL_CLOCK_READ(&mbox_ft[i].end); 785 HAL_CLOCK_READ(&mbox_ft[i].end);
608 } 786 }
609 show_times(mbox_ft, NMBOXES, "Create mbox"); 787 show_times(mbox_ft, nmboxes, "Create mbox");
610 788
611 wait_for_tick(); // Wait until the next clock tick to minimize aberations 789 wait_for_tick(); // Wait until the next clock tick to minimize aberations
612 for (i = 0; i < NMBOXES; i++) { 790 for (i = 0; i < nmboxes; i++) {
613 HAL_CLOCK_READ(&mbox_ft[i].start); 791 HAL_CLOCK_READ(&mbox_ft[i].start);
614 cnt = cyg_mbox_peek(test_mbox_handles[i]); 792 cnt = cyg_mbox_peek(test_mbox_handles[i]);
615 HAL_CLOCK_READ(&mbox_ft[i].end); 793 HAL_CLOCK_READ(&mbox_ft[i].end);
616 } 794 }
617 show_times(mbox_ft, NMBOXES, "Peek [empty] mbox"); 795 show_times(mbox_ft, nmboxes, "Peek [empty] mbox");
618 796
619 wait_for_tick(); // Wait until the next clock tick to minimize aberations 797 #ifdef CYGMFN_KERNEL_SYNCH_MBOXT_PUT_CAN_WAIT
620 for (i = 0; i < NMBOXES; i++) { 798 wait_for_tick(); // Wait until the next clock tick to minimize aberations
799 for (i = 0; i < nmboxes; i++) {
621 HAL_CLOCK_READ(&mbox_ft[i].start); 800 HAL_CLOCK_READ(&mbox_ft[i].start);
622 cyg_mbox_put(test_mbox_handles[i], (void *)i); 801 cyg_mbox_put(test_mbox_handles[i], (void *)i);
623 HAL_CLOCK_READ(&mbox_ft[i].end); 802 HAL_CLOCK_READ(&mbox_ft[i].end);
624 } 803 }
625 show_times(mbox_ft, NMBOXES, "Put [first] mbox"); 804 show_times(mbox_ft, nmboxes, "Put [first] mbox");
626 805
627 wait_for_tick(); // Wait until the next clock tick to minimize aberations 806 wait_for_tick(); // Wait until the next clock tick to minimize aberations
628 for (i = 0; i < NMBOXES; i++) { 807 for (i = 0; i < nmboxes; i++) {
629 HAL_CLOCK_READ(&mbox_ft[i].start); 808 HAL_CLOCK_READ(&mbox_ft[i].start);
630 cnt = cyg_mbox_peek(test_mbox_handles[i]); 809 cnt = cyg_mbox_peek(test_mbox_handles[i]);
631 HAL_CLOCK_READ(&mbox_ft[i].end); 810 HAL_CLOCK_READ(&mbox_ft[i].end);
632 } 811 }
633 show_times(mbox_ft, NMBOXES, "Peek [1 msg] mbox"); 812 show_times(mbox_ft, nmboxes, "Peek [1 msg] mbox");
634 813
635 wait_for_tick(); // Wait until the next clock tick to minimize aberations 814 wait_for_tick(); // Wait until the next clock tick to minimize aberations
636 for (i = 0; i < NMBOXES; i++) { 815 for (i = 0; i < nmboxes; i++) {
637 HAL_CLOCK_READ(&mbox_ft[i].start); 816 HAL_CLOCK_READ(&mbox_ft[i].start);
638 cyg_mbox_put(test_mbox_handles[i], (void *)i); 817 cyg_mbox_put(test_mbox_handles[i], (void *)i);
639 HAL_CLOCK_READ(&mbox_ft[i].end); 818 HAL_CLOCK_READ(&mbox_ft[i].end);
640 } 819 }
641 show_times(mbox_ft, NMBOXES, "Put [second] mbox"); 820 show_times(mbox_ft, nmboxes, "Put [second] mbox");
642 821
643 wait_for_tick(); // Wait until the next clock tick to minimize aberations 822 wait_for_tick(); // Wait until the next clock tick to minimize aberations
644 for (i = 0; i < NMBOXES; i++) { 823 for (i = 0; i < nmboxes; i++) {
645 HAL_CLOCK_READ(&mbox_ft[i].start); 824 HAL_CLOCK_READ(&mbox_ft[i].start);
646 cnt = cyg_mbox_peek(test_mbox_handles[i]); 825 cnt = cyg_mbox_peek(test_mbox_handles[i]);
647 HAL_CLOCK_READ(&mbox_ft[i].end); 826 HAL_CLOCK_READ(&mbox_ft[i].end);
648 } 827 }
649 show_times(mbox_ft, NMBOXES, "Peek [2 msgs] mbox"); 828 show_times(mbox_ft, nmboxes, "Peek [2 msgs] mbox");
650 829
651 wait_for_tick(); // Wait until the next clock tick to minimize aberations 830 wait_for_tick(); // Wait until the next clock tick to minimize aberations
652 for (i = 0; i < NMBOXES; i++) { 831 for (i = 0; i < nmboxes; i++) {
653 HAL_CLOCK_READ(&mbox_ft[i].start); 832 HAL_CLOCK_READ(&mbox_ft[i].start);
654 item = cyg_mbox_get(test_mbox_handles[i]); 833 item = cyg_mbox_get(test_mbox_handles[i]);
655 HAL_CLOCK_READ(&mbox_ft[i].end); 834 HAL_CLOCK_READ(&mbox_ft[i].end);
656 } 835 }
657 show_times(mbox_ft, NMBOXES, "Get [first] mbox"); 836 show_times(mbox_ft, nmboxes, "Get [first] mbox");
658 837
659 wait_for_tick(); // Wait until the next clock tick to minimize aberations 838 wait_for_tick(); // Wait until the next clock tick to minimize aberations
660 for (i = 0; i < NMBOXES; i++) { 839 for (i = 0; i < nmboxes; i++) {
661 HAL_CLOCK_READ(&mbox_ft[i].start); 840 HAL_CLOCK_READ(&mbox_ft[i].start);
662 item = cyg_mbox_get(test_mbox_handles[i]); 841 item = cyg_mbox_get(test_mbox_handles[i]);
663 HAL_CLOCK_READ(&mbox_ft[i].end); 842 HAL_CLOCK_READ(&mbox_ft[i].end);
664 } 843 }
665 show_times(mbox_ft, NMBOXES, "Get [second] mbox"); 844 show_times(mbox_ft, nmboxes, "Get [second] mbox");
666 845 #endif // ifdef CYGMFN_KERNEL_SYNCH_MBOXT_PUT_CAN_WAIT
667 wait_for_tick(); // Wait until the next clock tick to minimize aberations 846
668 for (i = 0; i < NMBOXES; i++) { 847 wait_for_tick(); // Wait until the next clock tick to minimize aberations
848 for (i = 0; i < nmboxes; i++) {
669 HAL_CLOCK_READ(&mbox_ft[i].start); 849 HAL_CLOCK_READ(&mbox_ft[i].start);
670 cyg_mbox_tryput(test_mbox_handles[i], (void *)i); 850 cyg_mbox_tryput(test_mbox_handles[i], (void *)i);
671 HAL_CLOCK_READ(&mbox_ft[i].end); 851 HAL_CLOCK_READ(&mbox_ft[i].end);
672 } 852 }
673 show_times(mbox_ft, NMBOXES, "Tryput [first] mbox"); 853 show_times(mbox_ft, nmboxes, "Tryput [first] mbox");
674 854
675 wait_for_tick(); // Wait until the next clock tick to minimize aberations 855 wait_for_tick(); // Wait until the next clock tick to minimize aberations
676 for (i = 0; i < NMBOXES; i++) { 856 for (i = 0; i < nmboxes; i++) {
677 HAL_CLOCK_READ(&mbox_ft[i].start); 857 HAL_CLOCK_READ(&mbox_ft[i].start);
678 item = cyg_mbox_peek_item(test_mbox_handles[i]); 858 item = cyg_mbox_peek_item(test_mbox_handles[i]);
679 HAL_CLOCK_READ(&mbox_ft[i].end); 859 HAL_CLOCK_READ(&mbox_ft[i].end);
680 } 860 }
681 show_times(mbox_ft, NMBOXES, "Peek item [non-empty] mbox"); 861 show_times(mbox_ft, nmboxes, "Peek item [non-empty] mbox");
682 862
683 wait_for_tick(); // Wait until the next clock tick to minimize aberations 863 wait_for_tick(); // Wait until the next clock tick to minimize aberations
684 for (i = 0; i < NMBOXES; i++) { 864 for (i = 0; i < nmboxes; i++) {
685 HAL_CLOCK_READ(&mbox_ft[i].start); 865 HAL_CLOCK_READ(&mbox_ft[i].start);
686 item = cyg_mbox_tryget(test_mbox_handles[i]); 866 item = cyg_mbox_tryget(test_mbox_handles[i]);
687 HAL_CLOCK_READ(&mbox_ft[i].end); 867 HAL_CLOCK_READ(&mbox_ft[i].end);
688 } 868 }
689 show_times(mbox_ft, NMBOXES, "Tryget [non-empty] mbox"); 869 show_times(mbox_ft, nmboxes, "Tryget [non-empty] mbox");
690 870
691 wait_for_tick(); // Wait until the next clock tick to minimize aberations 871 wait_for_tick(); // Wait until the next clock tick to minimize aberations
692 for (i = 0; i < NMBOXES; i++) { 872 for (i = 0; i < nmboxes; i++) {
693 HAL_CLOCK_READ(&mbox_ft[i].start); 873 HAL_CLOCK_READ(&mbox_ft[i].start);
694 item = cyg_mbox_peek_item(test_mbox_handles[i]); 874 item = cyg_mbox_peek_item(test_mbox_handles[i]);
695 HAL_CLOCK_READ(&mbox_ft[i].end); 875 HAL_CLOCK_READ(&mbox_ft[i].end);
696 } 876 }
697 show_times(mbox_ft, NMBOXES, "Peek item [empty] mbox"); 877 show_times(mbox_ft, nmboxes, "Peek item [empty] mbox");
698 878
699 wait_for_tick(); // Wait until the next clock tick to minimize aberations 879 wait_for_tick(); // Wait until the next clock tick to minimize aberations
700 for (i = 0; i < NMBOXES; i++) { 880 for (i = 0; i < nmboxes; i++) {
701 HAL_CLOCK_READ(&mbox_ft[i].start); 881 HAL_CLOCK_READ(&mbox_ft[i].start);
702 item = cyg_mbox_tryget(test_mbox_handles[i]); 882 item = cyg_mbox_tryget(test_mbox_handles[i]);
703 HAL_CLOCK_READ(&mbox_ft[i].end); 883 HAL_CLOCK_READ(&mbox_ft[i].end);
704 } 884 }
705 show_times(mbox_ft, NMBOXES, "Tryget [empty] mbox"); 885 show_times(mbox_ft, nmboxes, "Tryget [empty] mbox");
706 886
707 wait_for_tick(); // Wait until the next clock tick to minimize aberations 887 wait_for_tick(); // Wait until the next clock tick to minimize aberations
708 for (i = 0; i < NMBOXES; i++) { 888 for (i = 0; i < nmboxes; i++) {
709 HAL_CLOCK_READ(&mbox_ft[i].start); 889 HAL_CLOCK_READ(&mbox_ft[i].start);
710 cyg_mbox_waiting_to_get(test_mbox_handles[i]); 890 cyg_mbox_waiting_to_get(test_mbox_handles[i]);
711 HAL_CLOCK_READ(&mbox_ft[i].end); 891 HAL_CLOCK_READ(&mbox_ft[i].end);
712 } 892 }
713 show_times(mbox_ft, NMBOXES, "Waiting to get mbox"); 893 show_times(mbox_ft, nmboxes, "Waiting to get mbox");
714 894
715 wait_for_tick(); // Wait until the next clock tick to minimize aberations 895 wait_for_tick(); // Wait until the next clock tick to minimize aberations
716 for (i = 0; i < NMBOXES; i++) { 896 for (i = 0; i < nmboxes; i++) {
717 HAL_CLOCK_READ(&mbox_ft[i].start); 897 HAL_CLOCK_READ(&mbox_ft[i].start);
718 cyg_mbox_waiting_to_put(test_mbox_handles[i]); 898 cyg_mbox_waiting_to_put(test_mbox_handles[i]);
719 HAL_CLOCK_READ(&mbox_ft[i].end); 899 HAL_CLOCK_READ(&mbox_ft[i].end);
720 } 900 }
721 show_times(mbox_ft, NMBOXES, "Waiting to put mbox"); 901 show_times(mbox_ft, nmboxes, "Waiting to put mbox");
722 902
723 wait_for_tick(); // Wait until the next clock tick to minimize aberations 903 wait_for_tick(); // Wait until the next clock tick to minimize aberations
724 for (i = 0; i < NMBOXES; i++) { 904 for (i = 0; i < nmboxes; i++) {
725 HAL_CLOCK_READ(&mbox_ft[i].start); 905 HAL_CLOCK_READ(&mbox_ft[i].start);
726 cyg_mbox_delete(test_mbox_handles[i]); 906 cyg_mbox_delete(test_mbox_handles[i]);
727 HAL_CLOCK_READ(&mbox_ft[i].end); 907 HAL_CLOCK_READ(&mbox_ft[i].end);
728 } 908 }
729 show_times(mbox_ft, NMBOXES, "Delete mbox"); 909 show_times(mbox_ft, nmboxes, "Delete mbox");
730 910
731 run_mbox_circuit_test(); 911 run_mbox_circuit_test();
912 end_of_test_group();
732 } 913 }
733 914
734 void 915 void
735 run_mbox_circuit_test(void) 916 run_mbox_circuit_test(void)
736 { 917 {
918 #ifdef CYGMFN_KERNEL_SYNCH_MBOXT_PUT_CAN_WAIT
737 int i; 919 int i;
738 // Set my priority lower than any I plan to create 920 // Set my priority lower than any I plan to create
739 cyg_thread_set_priority(cyg_thread_self(), 3); 921 cyg_thread_set_priority(cyg_thread_self(), 3);
740 // Set up for full mbox put/get test 922 // Set up for full mbox put/get test
741 cyg_mbox_create(&test_mbox_handles[0], &test_mboxes[0]); 923 cyg_mbox_create(&test_mbox_handles[0], &test_mboxes[0]);
748 STACK_SIZE, // Size 930 STACK_SIZE, // Size
749 &mbox_test_thread_handle, // Handle 931 &mbox_test_thread_handle, // Handle
750 &mbox_test_thread // Thread data structure 932 &mbox_test_thread // Thread data structure
751 ); 933 );
752 cyg_thread_resume(mbox_test_thread_handle); 934 cyg_thread_resume(mbox_test_thread_handle);
753 for (i = 0; i < NMBOXES; i++) { 935 for (i = 0; i < nmboxes; i++) {
754 wait_for_tick(); // Wait until the next clock tick to minimize aberations 936 wait_for_tick(); // Wait until the next clock tick to minimize aberations
755 HAL_CLOCK_READ(&mbox_ft[i].start); 937 HAL_CLOCK_READ(&mbox_ft[i].start);
756 cyg_mbox_put(test_mbox_handles[0], (void *)i); 938 cyg_mbox_put(test_mbox_handles[0], (void *)i);
757 cyg_semaphore_wait(&synchro); 939 cyg_semaphore_wait(&synchro);
758 } 940 }
759 show_times(mbox_ft, NMBOXES, "Put/Get mbox"); 941 cyg_thread_delete(mbox_test_thread_handle);
942 show_times(mbox_ft, nmboxes, "Put/Get mbox");
943 #endif
760 } 944 }
761 945
762 void 946 void
763 run_semaphore_tests(void) 947 run_semaphore_tests(void)
764 { 948 {
765 int i; 949 int i;
766 cyg_ucount32 sem_val; 950 cyg_count32 sem_val;
767 // Semaphore primitives 951 // Semaphore primitives
768 wait_for_tick(); // Wait until the next clock tick to minimize aberations 952 wait_for_tick(); // Wait until the next clock tick to minimize aberations
769 for (i = 0; i < NSEMAPHORES; i++) { 953 for (i = 0; i < nsemaphores; i++) {
770 HAL_CLOCK_READ(&semaphore_ft[i].start); 954 HAL_CLOCK_READ(&semaphore_ft[i].start);
771 cyg_semaphore_init(&test_semaphores[i], 0); 955 cyg_semaphore_init(&test_semaphores[i], 0);
772 HAL_CLOCK_READ(&semaphore_ft[i].end); 956 HAL_CLOCK_READ(&semaphore_ft[i].end);
773 } 957 }
774 show_times(semaphore_ft, NSEMAPHORES, "Init semaphore"); 958 show_times(semaphore_ft, nsemaphores, "Init semaphore");
775 959
776 wait_for_tick(); // Wait until the next clock tick to minimize aberations 960 wait_for_tick(); // Wait until the next clock tick to minimize aberations
777 for (i = 0; i < NSEMAPHORES; i++) { 961 for (i = 0; i < nsemaphores; i++) {
778 HAL_CLOCK_READ(&semaphore_ft[i].start); 962 HAL_CLOCK_READ(&semaphore_ft[i].start);
779 cyg_semaphore_post(&test_semaphores[i]); 963 cyg_semaphore_post(&test_semaphores[i]);
780 HAL_CLOCK_READ(&semaphore_ft[i].end); 964 HAL_CLOCK_READ(&semaphore_ft[i].end);
781 } 965 }
782 show_times(semaphore_ft, NSEMAPHORES, "Post [0] semaphore"); 966 show_times(semaphore_ft, nsemaphores, "Post [0] semaphore");
783 967
784 wait_for_tick(); // Wait until the next clock tick to minimize aberations 968 wait_for_tick(); // Wait until the next clock tick to minimize aberations
785 for (i = 0; i < NSEMAPHORES; i++) { 969 for (i = 0; i < nsemaphores; i++) {
786 HAL_CLOCK_READ(&semaphore_ft[i].start); 970 HAL_CLOCK_READ(&semaphore_ft[i].start);
787 cyg_semaphore_wait(&test_semaphores[i]); 971 cyg_semaphore_wait(&test_semaphores[i]);
788 HAL_CLOCK_READ(&semaphore_ft[i].end); 972 HAL_CLOCK_READ(&semaphore_ft[i].end);
789 } 973 }
790 show_times(semaphore_ft, NSEMAPHORES, "Wait [1] semaphore"); 974 show_times(semaphore_ft, nsemaphores, "Wait [1] semaphore");
791 975
792 wait_for_tick(); // Wait until the next clock tick to minimize aberations 976 wait_for_tick(); // Wait until the next clock tick to minimize aberations
793 for (i = 0; i < NSEMAPHORES; i++) { 977 for (i = 0; i < nsemaphores; i++) {
794 HAL_CLOCK_READ(&semaphore_ft[i].start); 978 HAL_CLOCK_READ(&semaphore_ft[i].start);
795 cyg_semaphore_trywait(&test_semaphores[i]); 979 cyg_semaphore_trywait(&test_semaphores[i]);
796 HAL_CLOCK_READ(&semaphore_ft[i].end); 980 HAL_CLOCK_READ(&semaphore_ft[i].end);
797 } 981 }
798 show_times(semaphore_ft, NSEMAPHORES, "Trywait [0] semaphore"); 982 show_times(semaphore_ft, nsemaphores, "Trywait [0] semaphore");
799 983
800 wait_for_tick(); // Wait until the next clock tick to minimize aberations 984 wait_for_tick(); // Wait until the next clock tick to minimize aberations
801 for (i = 0; i < NSEMAPHORES; i++) { 985 for (i = 0; i < nsemaphores; i++) {
802 cyg_semaphore_post(&test_semaphores[i]); 986 cyg_semaphore_post(&test_semaphores[i]);
803 HAL_CLOCK_READ(&semaphore_ft[i].start); 987 HAL_CLOCK_READ(&semaphore_ft[i].start);
804 cyg_semaphore_trywait(&test_semaphores[i]); 988 cyg_semaphore_trywait(&test_semaphores[i]);
805 HAL_CLOCK_READ(&semaphore_ft[i].end); 989 HAL_CLOCK_READ(&semaphore_ft[i].end);
806 } 990 }
807 show_times(semaphore_ft, NSEMAPHORES, "Trywait [1] semaphore"); 991 show_times(semaphore_ft, nsemaphores, "Trywait [1] semaphore");
808 992
809 wait_for_tick(); // Wait until the next clock tick to minimize aberations 993 wait_for_tick(); // Wait until the next clock tick to minimize aberations
810 for (i = 0; i < NSEMAPHORES; i++) { 994 for (i = 0; i < nsemaphores; i++) {
811 HAL_CLOCK_READ(&semaphore_ft[i].start); 995 HAL_CLOCK_READ(&semaphore_ft[i].start);
812 cyg_semaphore_peek(&test_semaphores[i], &sem_val); 996 cyg_semaphore_peek(&test_semaphores[i], &sem_val);
813 HAL_CLOCK_READ(&semaphore_ft[i].end); 997 HAL_CLOCK_READ(&semaphore_ft[i].end);
814 } 998 }
815 show_times(semaphore_ft, NSEMAPHORES, "Peek semaphore"); 999 show_times(semaphore_ft, nsemaphores, "Peek semaphore");
816 1000
817 wait_for_tick(); // Wait until the next clock tick to minimize aberations 1001 wait_for_tick(); // Wait until the next clock tick to minimize aberations
818 for (i = 0; i < NSEMAPHORES; i++) { 1002 for (i = 0; i < nsemaphores; i++) {
819 HAL_CLOCK_READ(&semaphore_ft[i].start); 1003 HAL_CLOCK_READ(&semaphore_ft[i].start);
820 cyg_semaphore_destroy(&test_semaphores[i]); 1004 cyg_semaphore_destroy(&test_semaphores[i]);
821 HAL_CLOCK_READ(&semaphore_ft[i].end); 1005 HAL_CLOCK_READ(&semaphore_ft[i].end);
822 } 1006 }
823 show_times(semaphore_ft, NSEMAPHORES, "Destroy semaphore"); 1007 show_times(semaphore_ft, nsemaphores, "Destroy semaphore");
824 1008
825 run_semaphore_circuit_test(); 1009 run_semaphore_circuit_test();
1010 end_of_test_group();
826 } 1011 }
827 1012
828 void 1013 void
829 run_semaphore_circuit_test(void) 1014 run_semaphore_circuit_test(void)
830 { 1015 {
842 STACK_SIZE, // Size 1027 STACK_SIZE, // Size
843 &semaphore_test_thread_handle, // Handle 1028 &semaphore_test_thread_handle, // Handle
844 &semaphore_test_thread // Thread data structure 1029 &semaphore_test_thread // Thread data structure
845 ); 1030 );
846 cyg_thread_resume(semaphore_test_thread_handle); 1031 cyg_thread_resume(semaphore_test_thread_handle);
847 for (i = 0; i < NSEMAPHORES; i++) { 1032 for (i = 0; i < nsemaphores; i++) {
848 wait_for_tick(); // Wait until the next clock tick to minimize aberations 1033 wait_for_tick(); // Wait until the next clock tick to minimize aberations
849 HAL_CLOCK_READ(&semaphore_ft[i].start); 1034 HAL_CLOCK_READ(&semaphore_ft[i].start);
850 cyg_semaphore_post(&test_semaphores[0]); 1035 cyg_semaphore_post(&test_semaphores[0]);
851 cyg_semaphore_wait(&synchro); 1036 cyg_semaphore_wait(&synchro);
852 } 1037 }
853 show_times(semaphore_ft, NSEMAPHORES, "Post/Wait semaphore"); 1038 cyg_thread_delete(semaphore_test_thread_handle);
1039 show_times(semaphore_ft, nsemaphores, "Post/Wait semaphore");
854 } 1040 }
855 1041
856 void 1042 void
857 run_counter_tests(void) 1043 run_counter_tests(void)
858 { 1044 {
859 int i; 1045 int i;
860 cyg_tick_count_t val; 1046 cyg_tick_count_t val=0;
861 1047
862 wait_for_tick(); // Wait until the next clock tick to minimize aberations 1048 wait_for_tick(); // Wait until the next clock tick to minimize aberations
863 for (i = 0; i < NCOUNTERS; i++) { 1049 for (i = 0; i < ncounters; i++) {
864 HAL_CLOCK_READ(&counter_ft[i].start); 1050 HAL_CLOCK_READ(&counter_ft[i].start);
865 cyg_counter_create(&counters[i], &test_counters[i]); 1051 cyg_counter_create(&counters[i], &test_counters[i]);
866 HAL_CLOCK_READ(&counter_ft[i].end); 1052 HAL_CLOCK_READ(&counter_ft[i].end);
867 } 1053 }
868 show_times(counter_ft, NCOUNTERS, "Create counter"); 1054 show_times(counter_ft, ncounters, "Create counter");
869 1055
870 wait_for_tick(); // Wait until the next clock tick to minimize aberations 1056 wait_for_tick(); // Wait until the next clock tick to minimize aberations
871 for (i = 0; i < NCOUNTERS; i++) { 1057 for (i = 0; i < ncounters; i++) {
872 HAL_CLOCK_READ(&counter_ft[i].start); 1058 HAL_CLOCK_READ(&counter_ft[i].start);
873 val = cyg_counter_current_value(counters[i]); 1059 val = cyg_counter_current_value(counters[i]);
874 HAL_CLOCK_READ(&counter_ft[i].end); 1060 HAL_CLOCK_READ(&counter_ft[i].end);
875 } 1061 }
876 show_times(counter_ft, NCOUNTERS, "Get counter value"); 1062 show_times(counter_ft, ncounters, "Get counter value");
877 1063
878 wait_for_tick(); // Wait until the next clock tick to minimize aberations 1064 wait_for_tick(); // Wait until the next clock tick to minimize aberations
879 for (i = 0; i < NCOUNTERS; i++) { 1065 for (i = 0; i < ncounters; i++) {
880 HAL_CLOCK_READ(&counter_ft[i].start); 1066 HAL_CLOCK_READ(&counter_ft[i].start);
881 cyg_counter_set_value(counters[i], val); 1067 cyg_counter_set_value(counters[i], val);
882 HAL_CLOCK_READ(&counter_ft[i].end); 1068 HAL_CLOCK_READ(&counter_ft[i].end);
883 } 1069 }
884 show_times(counter_ft, NCOUNTERS, "Set counter value"); 1070 show_times(counter_ft, ncounters, "Set counter value");
885 1071
886 wait_for_tick(); // Wait until the next clock tick to minimize aberations 1072 wait_for_tick(); // Wait until the next clock tick to minimize aberations
887 for (i = 0; i < NCOUNTERS; i++) { 1073 for (i = 0; i < ncounters; i++) {
888 HAL_CLOCK_READ(&counter_ft[i].start); 1074 HAL_CLOCK_READ(&counter_ft[i].start);
889 cyg_counter_tick(counters[i]); 1075 cyg_counter_tick(counters[i]);
890 HAL_CLOCK_READ(&counter_ft[i].end); 1076 HAL_CLOCK_READ(&counter_ft[i].end);
891 } 1077 }
892 show_times(counter_ft, NCOUNTERS, "Tick counter"); 1078 show_times(counter_ft, ncounters, "Tick counter");
893 1079
894 wait_for_tick(); // Wait until the next clock tick to minimize aberations 1080 wait_for_tick(); // Wait until the next clock tick to minimize aberations
895 for (i = 0; i < NCOUNTERS; i++) { 1081 for (i = 0; i < ncounters; i++) {
896 HAL_CLOCK_READ(&counter_ft[i].start); 1082 HAL_CLOCK_READ(&counter_ft[i].start);
897 cyg_counter_delete(counters[i]); 1083 cyg_counter_delete(counters[i]);
898 HAL_CLOCK_READ(&counter_ft[i].end); 1084 HAL_CLOCK_READ(&counter_ft[i].end);
899 } 1085 }
900 show_times(counter_ft, NCOUNTERS, "Delete counter"); 1086 show_times(counter_ft, ncounters, "Delete counter");
1087 end_of_test_group();
901 } 1088 }
902 1089
903 // Alarm callback function 1090 // Alarm callback function
904 void 1091 void
905 alarm_cb(cyg_handle_t alarm, cyg_addrword_t val) 1092 alarm_cb(cyg_handle_t alarm, cyg_addrword_t val)
910 // Callback used to test determinancy 1097 // Callback used to test determinancy
911 static volatile int alarm_cnt; 1098 static volatile int alarm_cnt;
912 void 1099 void
913 alarm_cb2(cyg_handle_t alarm, cyg_addrword_t indx) 1100 alarm_cb2(cyg_handle_t alarm, cyg_addrword_t indx)
914 { 1101 {
915 if (alarm_cnt == NSCHEDS) return; 1102 if (alarm_cnt == nscheds) return;
916 sched_ft[alarm_cnt].start = 0; 1103 sched_ft[alarm_cnt].start = 0;
917 HAL_CLOCK_READ(&sched_ft[alarm_cnt++].end); 1104 HAL_CLOCK_READ(&sched_ft[alarm_cnt++].end);
918 if (alarm_cnt == NSCHEDS) { 1105 if (alarm_cnt == nscheds) {
919 cyg_semaphore_post(&synchro); 1106 cyg_semaphore_post(&synchro);
920 } 1107 }
921 } 1108 }
922 1109
923 // Null thread, used to keep scheduler busy 1110 // Null thread, used to keep scheduler busy
935 int i; 1122 int i;
936 cyg_tick_count_t init_val, step_val; 1123 cyg_tick_count_t init_val, step_val;
937 cyg_handle_t rtc_handle; 1124 cyg_handle_t rtc_handle;
938 1125
939 wait_for_tick(); // Wait until the next clock tick to minimize aberations 1126 wait_for_tick(); // Wait until the next clock tick to minimize aberations
940 for (i = 0; i < NCOUNTERS; i++) { 1127 for (i = 0; i < ncounters; i++) {
941 cyg_counter_create(&counters[i], &test_counters[i]); 1128 cyg_counter_create(&counters[i], &test_counters[i]);
942 } 1129 }
943 for (i = 0; i < NALARMS; i++) { 1130 for (i = 0; i < nalarms; i++) {
944 HAL_CLOCK_READ(&alarm_ft[i].start); 1131 HAL_CLOCK_READ(&alarm_ft[i].start);
945 cyg_alarm_create(counters[0], alarm_cb, 0, &alarms[i], &test_alarms[i]); 1132 cyg_alarm_create(counters[0], alarm_cb, 0, &alarms[i], &test_alarms[i]);
946 HAL_CLOCK_READ(&alarm_ft[i].end); 1133 HAL_CLOCK_READ(&alarm_ft[i].end);
947 } 1134 }
948 show_times(alarm_ft, NALARMS, "Create alarm"); 1135 show_times(alarm_ft, nalarms, "Create alarm");
949 1136
950 wait_for_tick(); // Wait until the next clock tick to minimize aberations 1137 wait_for_tick(); // Wait until the next clock tick to minimize aberations
951 init_val = 0; step_val = 0; 1138 init_val = 0; step_val = 0;
952 for (i = 0; i < NALARMS; i++) { 1139 for (i = 0; i < nalarms; i++) {
953 HAL_CLOCK_READ(&alarm_ft[i].start); 1140 HAL_CLOCK_READ(&alarm_ft[i].start);
954 cyg_alarm_initialize(alarms[i], init_val, step_val); 1141 cyg_alarm_initialize(alarms[i], init_val, step_val);
955 HAL_CLOCK_READ(&alarm_ft[i].end); 1142 HAL_CLOCK_READ(&alarm_ft[i].end);
956 } 1143 }
957 show_times(alarm_ft, NALARMS, "Initialize alarm"); 1144 show_times(alarm_ft, nalarms, "Initialize alarm");
958 1145
959 wait_for_tick(); // Wait until the next clock tick to minimize aberations 1146 wait_for_tick(); // Wait until the next clock tick to minimize aberations
960 init_val = 0; step_val = 0; 1147 init_val = 0; step_val = 0;
961 for (i = 0; i < NALARMS; i++) { 1148 for (i = 0; i < nalarms; i++) {
962 HAL_CLOCK_READ(&alarm_ft[i].start); 1149 HAL_CLOCK_READ(&alarm_ft[i].start);
963 cyg_alarm_disable(alarms[i]); 1150 cyg_alarm_disable(alarms[i]);
964 HAL_CLOCK_READ(&alarm_ft[i].end); 1151 HAL_CLOCK_READ(&alarm_ft[i].end);
965 } 1152 }
966 show_times(alarm_ft, NALARMS, "Disable alarm"); 1153 show_times(alarm_ft, nalarms, "Disable alarm");
967 1154
968 wait_for_tick(); // Wait until the next clock tick to minimize aberations 1155 wait_for_tick(); // Wait until the next clock tick to minimize aberations
969 init_val = 0; step_val = 0; 1156 init_val = 0; step_val = 0;
970 for (i = 0; i < NALARMS; i++) { 1157 for (i = 0; i < nalarms; i++) {
971 HAL_CLOCK_READ(&alarm_ft[i].start); 1158 HAL_CLOCK_READ(&alarm_ft[i].start);
972 cyg_alarm_enable(alarms[i]); 1159 cyg_alarm_enable(alarms[i]);
973 HAL_CLOCK_READ(&alarm_ft[i].end); 1160 HAL_CLOCK_READ(&alarm_ft[i].end);
974 } 1161 }
975 show_times(alarm_ft, NALARMS, "Enable alarm"); 1162 show_times(alarm_ft, nalarms, "Enable alarm");
976 1163
977 wait_for_tick(); // Wait until the next clock tick to minimize aberations 1164 wait_for_tick(); // Wait until the next clock tick to minimize aberations
978 for (i = 0; i < NALARMS; i++) { 1165 for (i = 0; i < nalarms; i++) {
979 HAL_CLOCK_READ(&alarm_ft[i].start); 1166 HAL_CLOCK_READ(&alarm_ft[i].start);
980 cyg_alarm_delete(alarms[i]); 1167 cyg_alarm_delete(alarms[i]);
981 HAL_CLOCK_READ(&alarm_ft[i].end); 1168 HAL_CLOCK_READ(&alarm_ft[i].end);
982 } 1169 }
983 show_times(alarm_ft, NALARMS, "Delete alarm"); 1170 show_times(alarm_ft, nalarms, "Delete alarm");
984 1171
985 wait_for_tick(); // Wait until the next clock tick to minimize aberations 1172 wait_for_tick(); // Wait until the next clock tick to minimize aberations
986 cyg_counter_create(&counters[0], &test_counters[0]); 1173 cyg_counter_create(&counters[0], &test_counters[0]);
987 cyg_alarm_create(counters[0], alarm_cb, 0, &alarms[0], &test_alarms[0]); 1174 cyg_alarm_create(counters[0], alarm_cb, 0, &alarms[0], &test_alarms[0]);
988 init_val = 9999; step_val = 9999; 1175 init_val = 9999; step_val = 9999;
989 cyg_alarm_initialize(alarms[0], init_val, step_val); 1176 cyg_alarm_initialize(alarms[0], init_val, step_val);
990 cyg_alarm_enable(alarms[0]); 1177 cyg_alarm_enable(alarms[0]);
991 for (i = 0; i < NCOUNTERS; i++) { 1178 for (i = 0; i < ncounters; i++) {
992 HAL_CLOCK_READ(&counter_ft[i].start); 1179 HAL_CLOCK_READ(&counter_ft[i].start);
993 cyg_counter_tick(counters[0]); 1180 cyg_counter_tick(counters[0]);
994 HAL_CLOCK_READ(&counter_ft[i].end); 1181 HAL_CLOCK_READ(&counter_ft[i].end);
995 } 1182 }
996 show_times(counter_ft, NCOUNTERS, "Tick counter [1 alarm]"); 1183 show_times(counter_ft, ncounters, "Tick counter [1 alarm]");
997 1184
998 wait_for_tick(); // Wait until the next clock tick to minimize aberations 1185 wait_for_tick(); // Wait until the next clock tick to minimize aberations
999 cyg_counter_create(&counters[0], &test_counters[0]); 1186 cyg_counter_create(&counters[0], &test_counters[0]);
1000 for (i = 0; i < NALARMS; i++) { 1187 for (i = 0; i < nalarms; i++) {
1001 cyg_alarm_create(counters[0], alarm_cb, 0, &alarms[i], &test_alarms[i]); 1188 cyg_alarm_create(counters[0], alarm_cb, 0, &alarms[i], &test_alarms[i]);
1002 init_val = 9999; step_val = 9999; 1189 init_val = 9999; step_val = 9999;
1003 cyg_alarm_initialize(alarms[i], init_val, step_val); 1190 cyg_alarm_initialize(alarms[i], init_val, step_val);
1004 cyg_alarm_enable(alarms[i]); 1191 cyg_alarm_enable(alarms[i]);
1005 } 1192 }
1006 for (i = 0; i < NCOUNTERS; i++) { 1193 for (i = 0; i < ncounters; i++) {
1007 HAL_CLOCK_READ(&counter_ft[i].start); 1194 HAL_CLOCK_READ(&counter_ft[i].start);
1008 cyg_counter_tick(counters[0]); 1195 cyg_counter_tick(counters[0]);
1009 HAL_CLOCK_READ(&counter_ft[i].end); 1196 HAL_CLOCK_READ(&counter_ft[i].end);
1010 } 1197 }
1011 show_times(counter_ft, NCOUNTERS, "Tick counter [many alarms]"); 1198 show_times(counter_ft, ncounters, "Tick counter [many alarms]");
1012 1199
1013 wait_for_tick(); // Wait until the next clock tick to minimize aberations 1200 wait_for_tick(); // Wait until the next clock tick to minimize aberations
1014 cyg_counter_create(&counters[0], &test_counters[0]); 1201 cyg_counter_create(&counters[0], &test_counters[0]);
1015 cyg_alarm_create(counters[0], alarm_cb, 0, &alarms[0], &test_alarms[0]); 1202 cyg_alarm_create(counters[0], alarm_cb, 0, &alarms[0], &test_alarms[0]);
1016 init_val = 1; step_val = 1; 1203 init_val = 1; step_val = 1;
1017 cyg_alarm_initialize(alarms[0], init_val, step_val); 1204 cyg_alarm_initialize(alarms[0], init_val, step_val);
1018 cyg_alarm_enable(alarms[0]); 1205 cyg_alarm_enable(alarms[0]);
1019 for (i = 0; i < NCOUNTERS; i++) { 1206 for (i = 0; i < ncounters; i++) {
1020 HAL_CLOCK_READ(&counter_ft[i].start); 1207 HAL_CLOCK_READ(&counter_ft[i].start);
1021 cyg_counter_tick(counters[0]); 1208 cyg_counter_tick(counters[0]);
1022 HAL_CLOCK_READ(&counter_ft[i].end); 1209 HAL_CLOCK_READ(&counter_ft[i].end);
1023 } 1210 }
1024 show_times(counter_ft, NCOUNTERS, "Tick & fire counter [1 alarm]"); 1211 show_times(counter_ft, ncounters, "Tick & fire counter [1 alarm]");
1025 1212
1026 wait_for_tick(); // Wait until the next clock tick to minimize aberations 1213 wait_for_tick(); // Wait until the next clock tick to minimize aberations
1027 cyg_counter_create(&counters[0], &test_counters[0]); 1214 cyg_counter_create(&counters[0], &test_counters[0]);
1028 for (i = 0; i < NALARMS; i++) { 1215 for (i = 0; i < nalarms; i++) {
1029 cyg_alarm_create(counters[0], alarm_cb, i, &alarms[i], &test_alarms[i]); 1216 cyg_alarm_create(counters[0], alarm_cb, i, &alarms[i], &test_alarms[i]);
1030 init_val = 1; step_val = 1; 1217 init_val = 1; step_val = 1;
1031 cyg_alarm_initialize(alarms[i], init_val, step_val); 1218 cyg_alarm_initialize(alarms[i], init_val, step_val);
1032 cyg_alarm_enable(alarms[i]); 1219 cyg_alarm_enable(alarms[i]);
1033 } 1220 }
1034 for (i = 0; i < NCOUNTERS; i++) { 1221 for (i = 0; i < nalarms; i++) {
1035 HAL_CLOCK_READ(&counter_ft[i].start); 1222 HAL_CLOCK_READ(&alarm_ft[i].start);
1036 cyg_counter_tick(counters[0]); 1223 cyg_counter_tick(counters[0]);
1037 HAL_CLOCK_READ(&counter_ft[i].end); 1224 HAL_CLOCK_READ(&alarm_ft[i].end);
1038 } 1225 }
1039 for (i = 0; i < NALARMS; i++) { 1226 for (i = 0; i < nalarms; i++) {
1040 cyg_alarm_delete(alarms[i]); 1227 cyg_alarm_delete(alarms[i]);
1041 } 1228 }
1042 show_times(counter_ft, NCOUNTERS, "Tick & fire counter [many alarms]"); 1229 show_times(alarm_ft, nalarms, "Tick & fire counters [>1 together]");
1230
1231 wait_for_tick(); // Wait until the next clock tick to minimize aberations
1232 cyg_counter_create(&counters[0], &test_counters[0]);
1233 for (i = 0; i < nalarms; i++) {
1234 cyg_alarm_create(counters[0], alarm_cb, i, &alarms[i], &test_alarms[i]);
1235 init_val = i+1; step_val = nalarms+1;
1236 cyg_alarm_initialize(alarms[i], init_val, step_val);
1237 cyg_alarm_enable(alarms[i]);
1238 }
1239 for (i = 0; i < nalarms; i++) {
1240 HAL_CLOCK_READ(&alarm_ft[i].start);
1241 cyg_counter_tick(counters[0]);
1242 HAL_CLOCK_READ(&alarm_ft[i].end);
1243 }
1244 for (i = 0; i < nalarms; i++) {
1245 cyg_alarm_delete(alarms[i]);
1246 }
1247 show_times(alarm_ft, nalarms, "Tick & fire counters [>1 separately]");
1043 1248
1044 wait_for_tick(); // Wait until the next clock tick to minimize aberations 1249 wait_for_tick(); // Wait until the next clock tick to minimize aberations
1045 cyg_clock_to_counter(cyg_real_time_clock(), &rtc_handle); 1250 cyg_clock_to_counter(cyg_real_time_clock(), &rtc_handle);
1046 cyg_alarm_create(rtc_handle, alarm_cb2, 0, &alarms[0], &test_alarms[0]); 1251 cyg_alarm_create(rtc_handle, alarm_cb2, 0, &alarms[0], &test_alarms[0]);
1047 init_val = 5; step_val = 5; alarm_cnt = 0; 1252 init_val = 5; step_val = 5; alarm_cnt = 0;
1049 cyg_semaphore_init(&synchro, 0); 1254 cyg_semaphore_init(&synchro, 0);
1050 cyg_alarm_enable(alarms[0]); 1255 cyg_alarm_enable(alarms[0]);
1051 cyg_semaphore_wait(&synchro); 1256 cyg_semaphore_wait(&synchro);
1052 cyg_alarm_disable(alarms[0]); 1257 cyg_alarm_disable(alarms[0]);
1053 cyg_alarm_delete(alarms[0]); 1258 cyg_alarm_delete(alarms[0]);
1054 show_times(sched_ft, NSCHEDS, "Alarm latency [0 threads]"); 1259 show_times(sched_ft, nscheds, "Alarm latency [0 threads]");
1055 1260
1056 // Set my priority higher than any I plan to create 1261 // Set my priority higher than any I plan to create
1057 cyg_thread_set_priority(cyg_thread_self(), 2); 1262 cyg_thread_set_priority(cyg_thread_self(), 2);
1058 for (i = 0; i < 2; i++) { 1263 for (i = 0; i < 2; i++) {
1059 cyg_thread_create(10, // Priority - just a number 1264 cyg_thread_create(10, // Priority - just a number
1075 cyg_semaphore_init(&synchro, 0); 1280 cyg_semaphore_init(&synchro, 0);
1076 cyg_alarm_enable(alarms[0]); 1281 cyg_alarm_enable(alarms[0]);
1077 cyg_semaphore_wait(&synchro); 1282 cyg_semaphore_wait(&synchro);
1078 cyg_alarm_disable(alarms[0]); 1283 cyg_alarm_disable(alarms[0]);
1079 cyg_alarm_delete(alarms[0]); 1284 cyg_alarm_delete(alarms[0]);
1080 show_times(sched_ft, NSCHEDS, "Alarm latency [2 threads]"); 1285 show_times(sched_ft, nscheds, "Alarm latency [2 threads]");
1081 for (i = 0; i < 2; i++) { 1286 for (i = 0; i < 2; i++) {
1082 cyg_thread_suspend(threads[i]); 1287 cyg_thread_suspend(threads[i]);
1083 cyg_thread_kill(threads[i]); 1288 cyg_thread_delete(threads[i]);
1084 } 1289 }
1085 1290
1086 // Set my priority higher than any I plan to create 1291 // Set my priority higher than any I plan to create
1087 cyg_thread_set_priority(cyg_thread_self(), 2); 1292 cyg_thread_set_priority(cyg_thread_self(), 2);
1088 for (i = 0; i < NTEST_THREADS; i++) { 1293 for (i = 0; i < ntest_threads; i++) {
1089 cyg_thread_create(10, // Priority - just a number 1294 cyg_thread_create(10, // Priority - just a number
1090 alarm_test, // entry 1295 alarm_test, // entry
1091 i, // index 1296 i, // index
1092 thread_name("thread", i), // Name 1297 thread_name("thread", i), // Name
1093 &stacks[i][0], // Stack 1298 &stacks[i][0], // Stack
1105 cyg_semaphore_init(&synchro, 0); 1310 cyg_semaphore_init(&synchro, 0);
1106 cyg_alarm_enable(alarms[0]); 1311 cyg_alarm_enable(alarms[0]);
1107 cyg_semaphore_wait(&synchro); 1312 cyg_semaphore_wait(&synchro);
1108 cyg_alarm_disable(alarms[0]); 1313 cyg_alarm_disable(alarms[0]);
1109 cyg_alarm_delete(alarms[0]); 1314 cyg_alarm_delete(alarms[0]);
1110 show_times(sched_ft, NSCHEDS, "Alarm latency [many threads]"); 1315 show_times(sched_ft, nscheds, "Alarm latency [many threads]");
1111 for (i = 0; i < NTEST_THREADS; i++) { 1316 for (i = 0; i < ntest_threads; i++) {
1112 cyg_thread_suspend(threads[i]); 1317 cyg_thread_suspend(threads[i]);
1113 cyg_thread_kill(threads[i]); 1318 cyg_thread_delete(threads[i]);
1114 } 1319 }
1320 end_of_test_group();
1115 } 1321 }
1116 1322
1117 void 1323 void
1118 run_sched_tests(void) 1324 run_sched_tests(void)
1119 { 1325 {
1120 int i; 1326 int i;
1121 1327
1122 wait_for_tick(); // Wait until the next clock tick to minimize aberations 1328 wait_for_tick(); // Wait until the next clock tick to minimize aberations
1123 for (i = 0; i < NSCHEDS; i++) { 1329 for (i = 0; i < nscheds; i++) {
1124 HAL_CLOCK_READ(&sched_ft[i].start); 1330 HAL_CLOCK_READ(&sched_ft[i].start);
1125 cyg_scheduler_lock(); 1331 cyg_scheduler_lock();
1126 HAL_CLOCK_READ(&sched_ft[i].end); 1332 HAL_CLOCK_READ(&sched_ft[i].end);
1127 cyg_scheduler_unlock(); 1333 cyg_scheduler_unlock();
1128 } 1334 }
1129 show_times(sched_ft, NSCHEDS, "Scheduler lock"); 1335 show_times(sched_ft, nscheds, "Scheduler lock");
1130 1336
1131 wait_for_tick(); // Wait until the next clock tick to minimize aberations 1337 wait_for_tick(); // Wait until the next clock tick to minimize aberations
1132 for (i = 0; i < NSCHEDS; i++) { 1338 for (i = 0; i < nscheds; i++) {
1133 cyg_scheduler_lock(); 1339 cyg_scheduler_lock();
1134 HAL_CLOCK_READ(&sched_ft[i].start); 1340 HAL_CLOCK_READ(&sched_ft[i].start);
1135 cyg_scheduler_unlock(); 1341 cyg_scheduler_unlock();
1136 HAL_CLOCK_READ(&sched_ft[i].end); 1342 HAL_CLOCK_READ(&sched_ft[i].end);
1137 } 1343 }
1138 show_times(sched_ft, NSCHEDS, "Scheduler unlock [0 threads]"); 1344 show_times(sched_ft, nscheds, "Scheduler unlock [0 threads]");
1139 1345
1140 // Set my priority higher than any I plan to create 1346 // Set my priority higher than any I plan to create
1141 cyg_thread_set_priority(cyg_thread_self(), 2); 1347 cyg_thread_set_priority(cyg_thread_self(), 2);
1142 for (i = 0; i < 1; i++) { 1348 for (i = 0; i < 1; i++) {
1143 cyg_thread_create(10, // Priority - just a number 1349 cyg_thread_create(10, // Priority - just a number
1149 &threads[i], // Handle 1355 &threads[i], // Handle
1150 &test_threads[i] // Thread data structure 1356 &test_threads[i] // Thread data structure
1151 ); 1357 );
1152 } 1358 }
1153 wait_for_tick(); // Wait until the next clock tick to minimize aberations 1359 wait_for_tick(); // Wait until the next clock tick to minimize aberations
1154 for (i = 0; i < NSCHEDS; i++) { 1360 for (i = 0; i < nscheds; i++) {
1155 cyg_scheduler_lock(); 1361 cyg_scheduler_lock();
1156 HAL_CLOCK_READ(&sched_ft[i].start); 1362 HAL_CLOCK_READ(&sched_ft[i].start);
1157 cyg_scheduler_unlock(); 1363 cyg_scheduler_unlock();
1158 HAL_CLOCK_READ(&sched_ft[i].end); 1364 HAL_CLOCK_READ(&sched_ft[i].end);
1159 } 1365 }
1160 show_times(sched_ft, NSCHEDS, "Scheduler unlock [1 suspended thread]"); 1366 show_times(sched_ft, nscheds, "Scheduler unlock [1 suspended]");
1161 for (i = 0; i < 1; i++) { 1367 for (i = 0; i < 1; i++) {
1162 cyg_thread_kill(threads[i]); 1368 cyg_thread_delete(threads[i]);
1163 } 1369 }
1164 1370
1165 // Set my priority higher than any I plan to create 1371 // Set my priority higher than any I plan to create
1166 cyg_thread_set_priority(cyg_thread_self(), 2); 1372 cyg_thread_set_priority(cyg_thread_self(), 2);
1167 for (i = 0; i < NTEST_THREADS; i++) { 1373 for (i = 0; i < ntest_threads; i++) {
1168 cyg_thread_create(10, // Priority - just a number 1374 cyg_thread_create(10, // Priority - just a number
1169 test0, // entry 1375 test0, // entry
1170 i, // index 1376 i, // index
1171 thread_name("thread", i), // Name 1377 thread_name("thread", i), // Name
1172 &stacks[i][0], // Stack 1378 &stacks[i][0], // Stack
1174 &threads[i], // Handle 1380 &threads[i], // Handle
1175 &test_threads[i] // Thread data structure 1381 &test_threads[i] // Thread data structure
1176 ); 1382 );
1177 } 1383 }
1178 wait_for_tick(); // Wait until the next clock tick to minimize aberations 1384 wait_for_tick(); // Wait until the next clock tick to minimize aberations
1179 for (i = 0; i < NSCHEDS; i++) { 1385 for (i = 0; i < nscheds; i++) {
1180 cyg_scheduler_lock(); 1386 cyg_scheduler_lock();
1181 HAL_CLOCK_READ(&sched_ft[i].start); 1387 HAL_CLOCK_READ(&sched_ft[i].start);
1182 cyg_scheduler_unlock(); 1388 cyg_scheduler_unlock();
1183 HAL_CLOCK_READ(&sched_ft[i].end); 1389 HAL_CLOCK_READ(&sched_ft[i].end);
1184 } 1390 }
1185 show_times(sched_ft, NSCHEDS, "Scheduler unlock [many suspended threads]"); 1391 show_times(sched_ft, nscheds, "Scheduler unlock [many suspended]");
1186 for (i = 0; i < NTEST_THREADS; i++) { 1392 for (i = 0; i < ntest_threads; i++) {
1187 cyg_thread_kill(threads[i]); 1393 cyg_thread_delete(threads[i]);
1188 } 1394 }
1189 1395
1190 // Set my priority higher than any I plan to create 1396 // Set my priority higher than any I plan to create
1191 cyg_thread_set_priority(cyg_thread_self(), 2); 1397 cyg_thread_set_priority(cyg_thread_self(), 2);
1192 for (i = 0; i < NTEST_THREADS; i++) { 1398 for (i = 0; i < ntest_threads; i++) {
1193 cyg_thread_create(10, // Priority - just a number 1399 cyg_thread_create(10, // Priority - just a number
1194 test0, // entry 1400 test0, // entry
1195 i, // index 1401 i, // index
1196 thread_name("thread", i), // Name 1402 thread_name("thread", i), // Name
1197 &stacks[i][0], // Stack 1403 &stacks[i][0], // Stack
1200 &test_threads[i] // Thread data structure 1406 &test_threads[i] // Thread data structure
1201 ); 1407 );
1202 cyg_thread_resume(threads[i]); 1408 cyg_thread_resume(threads[i]);
1203 } 1409 }
1204 wait_for_tick(); // Wait until the next clock tick to minimize aberations 1410 wait_for_tick(); // Wait until the next clock tick to minimize aberations
1205 for (i = 0; i < NSCHEDS; i++) { 1411 for (i = 0; i < nscheds; i++) {
1206 cyg_scheduler_lock(); 1412 cyg_scheduler_lock();
1207 HAL_CLOCK_READ(&sched_ft[i].start); 1413 HAL_CLOCK_READ(&sched_ft[i].start);
1208 cyg_scheduler_unlock(); 1414 cyg_scheduler_unlock();
1209 HAL_CLOCK_READ(&sched_ft[i].end); 1415 HAL_CLOCK_READ(&sched_ft[i].end);
1210 } 1416 }
1211 show_times(sched_ft, NSCHEDS, "Scheduler unlock [many low prio threads]"); 1417 show_times(sched_ft, nscheds, "Scheduler unlock [many low prio]");
1212 for (i = 0; i < NTEST_THREADS; i++) { 1418 for (i = 0; i < ntest_threads; i++) {
1213 cyg_thread_kill(threads[i]); 1419 cyg_thread_delete(threads[i]);
1214 } 1420 }
1421 end_of_test_group();
1215 } 1422 }
1216 1423
1217 void 1424 void
1218 run_all_tests(CYG_ADDRESS id) 1425 run_all_tests(CYG_ADDRESS id)
1219 { 1426 {
1220 int i; 1427 int i, j;
1221 cyg_uint32 tv[NSAMPLES], tv0, tv1, us; 1428 cyg_uint32 tv[nsamples], tv0, tv1;
1222 cyg_tick_count_t ticks; 1429 cyg_uint32 min_stack, max_stack, total_stack, actual_stack;
1430 cyg_tick_count_t ticks, tick0, tick1;
1223 #ifdef CYG_SCHEDULER_LOCK_TIMINGS 1431 #ifdef CYG_SCHEDULER_LOCK_TIMINGS
1224 cyg_uint32 lock_ave, lock_max; 1432 cyg_uint32 lock_ave, lock_max;
1225 #endif 1433 #endif
1226 #ifdef HAL_CLOCK_LATENCY 1434 #ifdef HAL_CLOCK_LATENCY
1227 cyg_int32 clock_ave; 1435 cyg_int32 clock_ave;
1228 #endif 1436 #endif
1229 1437
1230 for (i = 0; i < NSAMPLES; i++) { 1438 disable_clock_latency_measurement();
1439 diag_printf("\neCos Kernel Timings\n");
1440 diag_printf("Notes: all times are in microseconds (.000001) unless otherwise stated\n");
1441 #ifdef STATS_WITHOUT_FIRST_SAMPLE
1442 diag_printf(" second line of results have first sample removed\n");
1443 #endif
1444
1445 cyg_thread_delay(2); // Make sure the clock is actually running
1446
1447 ns_per_system_clock = 1000000/rtc_resolution[1];
1448
1449 for (i = 0; i < nsamples; i++) {
1231 HAL_CLOCK_READ(&tv[i]); 1450 HAL_CLOCK_READ(&tv[i]);
1232 } 1451 }
1233 diag_printf("Clock: ");
1234 tv0 = 0; 1452 tv0 = 0;
1235 for (i = 0; i < NSAMPLES; i++) { 1453 for (i = 1; i < nsamples; i++) {
1236 diag_printf("%x ", tv[i]); 1454 tv0 += tv[i] - tv[i-1];
1237 if (i > 0) { 1455 }
1238 tv0 += tv[i] - tv[i-1]; 1456 end_of_test_group();
1457
1458 overhead = tv0 / (nsamples-1);
1459 diag_printf("Reading the hardware clock takes %d 'ticks' overhead\n", overhead);
1460 diag_printf("... this value will be factored out of all other measurements\n");
1461
1462 // Try and measure how long the clock interrupt handling takes
1463 for (i = 0; i < nsamples; i++) {
1464 tick0 = cyg_current_time();
1465 while (true) {
1466 tick1 = cyg_current_time();
1467 if (tick0 != tick1) break;
1239 } 1468 }
1240 } 1469 HAL_CLOCK_READ(&tv[i]);
1241 diag_printf("\n"); 1470 }
1242 1471 tv1 = 0;
1243 overhead = tv0 / (NSAMPLES-1); 1472 for (i = 0; i < nsamples; i++) {
1244 diag_printf("Average %d clock ticks overhead\n", overhead); 1473 tv1 += tv[i] * 1000;
1245 1474 }
1246 // Try and measure how long the clock interrupt handling takes 1475 tv1 = tv1 / nsamples;
1247 HAL_CLOCK_READ(&tv0);
1248 while (true) {
1249 HAL_CLOCK_READ(&tv1);
1250 if (tv1 < tv0) break;
1251 tv0 = tv1;
1252 }
1253 tv1 -= overhead; // Adjust out the cost of getting the timer value 1476 tv1 -= overhead; // Adjust out the cost of getting the timer value
1254 us = ticks_to_us(tv1); 1477 diag_printf("Clock interrupt took");
1255 diag_printf("Clock interrupt took %d microseconds (%d clock ticks)\n", us, tv1); 1478 show_ticks_in_us(tv1);
1479 diag_printf(" microseconds (%d raw clock ticks)\n", tv1/1000);
1480 enable_clock_latency_measurement();
1256 1481
1257 ticks = cyg_current_time(); 1482 ticks = cyg_current_time();
1258 diag_printf("Ticks: %x\n", (int)ticks);
1259 1483
1260 show_test_parameters(); 1484 show_test_parameters();
1261 show_times_hdr(); 1485 show_times_hdr();
1486
1487 reset_clock_latency_measurement();
1262 1488
1263 run_thread_tests(); 1489 run_thread_tests();
1264 run_sched_tests(); 1490 run_sched_tests();
1265 run_mutex_tests(); 1491 run_mutex_tests();
1266 run_mbox_tests(); 1492 run_mbox_tests();
1268 run_counter_tests(); 1494 run_counter_tests();
1269 run_alarm_tests(); 1495 run_alarm_tests();
1270 1496
1271 #ifdef CYG_SCHEDULER_LOCK_TIMINGS 1497 #ifdef CYG_SCHEDULER_LOCK_TIMINGS
1272 Cyg_Scheduler::get_lock_times(&lock_ave, &lock_max); 1498 Cyg_Scheduler::get_lock_times(&lock_ave, &lock_max);
1273 diag_printf("\nMax lock: %d, Ave lock: %d\n", ticks_to_us(lock_max), ticks_to_us(lock_ave)); 1499 diag_printf("\nMax lock:");
1500 show_ticks_in_us(lock_max);
1501 diag_printf(", Ave lock:");
1502 show_ticks_in_us(lock_ave);
1503 diag_printf("\n");
1274 #endif 1504 #endif
1275 1505
1276 #ifdef HAL_CLOCK_LATENCY 1506 #ifdef HAL_CLOCK_LATENCY
1277 clock_ave = total_clock_latency / total_clock_interrupts; 1507 // Display latency figures in same format as all other numbers
1278 diag_printf("\nClock/interrupt latency - ave: %d, min: %d, max: %d\n", 1508 disable_clock_latency_measurement();
1279 ticks_to_us(clock_ave), ticks_to_us(min_clock_latency), ticks_to_us(max_clock_latency)); 1509 clock_ave = (total_clock_latency*1000) / total_clock_interrupts;
1510 show_ticks_in_us(clock_ave);
1511 show_ticks_in_us(min_clock_latency*1000);
1512 show_ticks_in_us(max_clock_latency*1000);
1513 show_ticks_in_us(0);
1514 diag_printf(" Clock/interrupt latency\n\n");
1515 enable_clock_latency_measurement();
1280 #endif 1516 #endif
1281 1517
1518 disable_clock_latency_measurement();
1519 min_stack = STACK_SIZE;
1520 max_stack = 0;
1521 total_stack = 0;
1522 for (i = 0; i < NTEST_THREADS; i++) {
1523 for (j = 0; j < STACK_SIZE; j++) {
1524 if (stacks[i][j]) break;
1525 }
1526 actual_stack = STACK_SIZE-j;
1527 if (actual_stack < min_stack) min_stack = actual_stack;
1528 if (actual_stack > max_stack) max_stack = actual_stack;
1529 total_stack += actual_stack;
1530 }
1531 for (j = 0; j < STACKSIZE; j++) {
1532 if (stack[j]) break;
1533 }
1534 diag_printf("%5d %5d %5d (main stack: %5d) Thread stack used (%d total)\n",
1535 total_stack/NTEST_THREADS, min_stack, max_stack,
1536 STACKSIZE - j, STACK_SIZE);
1537 enable_clock_latency_measurement();
1538
1282 ticks = cyg_current_time(); 1539 ticks = cyg_current_time();
1283 diag_printf("\nTiming complete - %d ms total\n", (int)ticks*10); 1540 diag_printf("\nTiming complete - %d ms total\n\n", (int)((ticks*ns_per_system_clock)/1000));
1284 1541
1285 CYG_TEST_PASS_FINISH("Basic timing OK"); 1542 CYG_TEST_PASS_FINISH("Basic timing OK");
1286 } 1543 }
1287 1544
1288 void tm_basic_main( void ) 1545 void tm_basic_main( void )
1289 { 1546 {
1290 CYG_TEST_INIT(); 1547 CYG_TEST_INIT();
1548
1549 if (cyg_test_is_simulator) {
1550 nsamples = NSAMPLES_SIM;
1551 ntest_threads = NTEST_THREADS_SIM;
1552 nthread_switches = NTHREAD_SWITCHES_SIM;
1553 nmutexes = NMUTEXES_SIM;
1554 nmboxes = NMBOXES_SIM;
1555 nsemaphores = NSEMAPHORES_SIM;
1556 nscheds = NSCHEDS_SIM;
1557 ncounters = NCOUNTERS_SIM;
1558 nalarms = NALARMS_SIM;
1559 } else {
1560 nsamples = NSAMPLES;
1561 ntest_threads = NTEST_THREADS;
1562 nthread_switches = NTHREAD_SWITCHES;
1563 nmutexes = NMUTEXES;
1564 nmboxes = NMBOXES;
1565 nsemaphores = NSEMAPHORES;
1566 nscheds = NSCHEDS;
1567 ncounters = NCOUNTERS;
1568 nalarms = NALARMS;
1569 }
1291 1570
1292 new_thread(run_all_tests, 0); 1571 new_thread(run_all_tests, 0);
1293 1572
1294 Cyg_Scheduler::scheduler.start(); 1573 Cyg_Scheduler::scheduler.start();
1295 } 1574 }
1297 externC void 1576 externC void
1298 cyg_start( void ) 1577 cyg_start( void )
1299 { 1578 {
1300 tm_basic_main(); 1579 tm_basic_main();
1301 } 1580 }
1581
1582 #else // CYGFUN_KERNEL_API_C
1583
1584 externC void
1585 cyg_start( void )
1586 {
1587 CYG_TEST_INIT();
1588 CYG_TEST_PASS_FINISH("Timing tests require:\n"
1589 "CYGFUN_KERNEL_API_C && \n"
1590 "CYGSEM_KERNEL_SCHED_MLQUEUE &&\n"
1591 "CYGVAR_KERNEL_COUNTERS_CLOCK &&\n"
1592 "!CYGPKG_HAL_I386_LINUX &&\n"
1593 "(CYGNUM_KERNEL_SCHED_PRIORITIES > 12)\n");
1594 }
1595 #endif // CYGFUN_KERNEL_API_C, etc.
1596
1302 // EOF tm_basic.cxx 1597 // EOF tm_basic.cxx