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