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