Mercurial > nand-ecoscentric
annotate packages/kernel/current/tests/tm_basic.cxx @ 34:29bc183297e1 ecos-sw-1999-09-02
Merge from eCos master repository on 1999-09-02-16:26:10-BST
| author | jlarmour |
|---|---|
| date | Thu, 02 Sep 1999 16:11:22 +0000 |
| parents | d3fbcdfa1b2f |
| children | e7ba79f6d3a8 |
| 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 |
| 747 wait_for_tick(); // Wait until the next clock tick to minimize aberations | |
| 2 | 748 for (i = 0; i < nmutexes; i++) { |
| 0 | 749 HAL_CLOCK_READ(&mutex_ft[i].start); |
| 750 cyg_mutex_destroy(&test_mutexes[i]); | |
| 751 HAL_CLOCK_READ(&mutex_ft[i].end); | |
| 752 } | |
| 2 | 753 show_times(mutex_ft, nmutexes, "Destroy mutex"); |
| 0 | 754 run_mutex_circuit_test(); |
| 2 | 755 end_of_test_group(); |
| 0 | 756 } |
| 757 | |
| 758 void | |
| 759 run_mutex_circuit_test(void) | |
| 760 { | |
| 761 int i; | |
| 762 // Set my priority lower than any I plan to create | |
| 763 cyg_thread_set_priority(cyg_thread_self(), 4); | |
| 764 // Set up for full mutex unlock/lock test | |
| 765 cyg_mutex_init(&test_mutexes[0]); | |
| 766 cyg_semaphore_init(&synchro, 0); | |
| 767 cyg_thread_create(3, // Priority - just a number | |
| 768 mutex_test, // entry | |
| 769 0, // index | |
| 770 thread_name("thread", 0), // Name | |
| 771 &stacks[0][0], // Stack | |
| 772 STACK_SIZE, // Size | |
| 773 &mutex_test_thread_handle, // Handle | |
| 774 &mutex_test_thread // Thread data structure | |
| 775 ); | |
| 776 cyg_thread_resume(mutex_test_thread_handle); | |
| 777 // Need to raise priority so that this thread will block on the "lock" | |
| 778 cyg_thread_set_priority(cyg_thread_self(), 2); | |
| 2 | 779 for (i = 0; i < nmutexes; i++) { |
| 0 | 780 cyg_semaphore_post(&synchro); |
| 781 cyg_mutex_lock(&test_mutexes[0]); | |
| 782 HAL_CLOCK_READ(&mutex_ft[i].end); | |
| 783 cyg_mutex_unlock(&test_mutexes[0]); | |
| 784 cyg_semaphore_wait(&synchro); | |
| 785 } | |
| 2 | 786 cyg_thread_delete(mutex_test_thread_handle); |
| 787 show_times(mutex_ft, nmutexes, "Unlock/Lock mutex"); | |
| 0 | 788 } |
| 789 | |
| 790 void | |
| 791 run_mbox_tests(void) | |
| 792 { | |
| 793 int i, cnt; | |
| 794 void *item; | |
| 795 // Mailbox primitives | |
| 796 wait_for_tick(); // Wait until the next clock tick to minimize aberations | |
| 2 | 797 for (i = 0; i < nmboxes; i++) { |
| 0 | 798 HAL_CLOCK_READ(&mbox_ft[i].start); |
| 799 cyg_mbox_create(&test_mbox_handles[i], &test_mboxes[i]); | |
| 800 HAL_CLOCK_READ(&mbox_ft[i].end); | |
| 801 } | |
| 2 | 802 show_times(mbox_ft, nmboxes, "Create mbox"); |
| 0 | 803 |
| 804 wait_for_tick(); // Wait until the next clock tick to minimize aberations | |
| 2 | 805 for (i = 0; i < nmboxes; i++) { |
| 0 | 806 HAL_CLOCK_READ(&mbox_ft[i].start); |
| 807 cnt = cyg_mbox_peek(test_mbox_handles[i]); | |
| 808 HAL_CLOCK_READ(&mbox_ft[i].end); | |
| 809 } | |
| 2 | 810 show_times(mbox_ft, nmboxes, "Peek [empty] mbox"); |
| 0 | 811 |
| 2 | 812 #ifdef CYGMFN_KERNEL_SYNCH_MBOXT_PUT_CAN_WAIT |
| 0 | 813 wait_for_tick(); // Wait until the next clock tick to minimize aberations |
| 2 | 814 for (i = 0; i < nmboxes; i++) { |
| 0 | 815 HAL_CLOCK_READ(&mbox_ft[i].start); |
| 816 cyg_mbox_put(test_mbox_handles[i], (void *)i); | |
| 817 HAL_CLOCK_READ(&mbox_ft[i].end); | |
| 818 } | |
| 2 | 819 show_times(mbox_ft, nmboxes, "Put [first] mbox"); |
| 0 | 820 |
| 821 wait_for_tick(); // Wait until the next clock tick to minimize aberations | |
| 2 | 822 for (i = 0; i < nmboxes; i++) { |
| 0 | 823 HAL_CLOCK_READ(&mbox_ft[i].start); |
| 824 cnt = cyg_mbox_peek(test_mbox_handles[i]); | |
| 825 HAL_CLOCK_READ(&mbox_ft[i].end); | |
| 826 } | |
| 2 | 827 show_times(mbox_ft, nmboxes, "Peek [1 msg] mbox"); |
| 0 | 828 |
| 829 wait_for_tick(); // Wait until the next clock tick to minimize aberations | |
| 2 | 830 for (i = 0; i < nmboxes; i++) { |
| 831 HAL_CLOCK_READ(&mbox_ft[i].start); | |
| 832 cyg_mbox_put(test_mbox_handles[i], (void *)i); | |
| 833 HAL_CLOCK_READ(&mbox_ft[i].end); | |
| 834 } | |
| 835 show_times(mbox_ft, nmboxes, "Put [second] mbox"); | |
| 836 | |
| 837 wait_for_tick(); // Wait until the next clock tick to minimize aberations | |
| 838 for (i = 0; i < nmboxes; i++) { | |
| 839 HAL_CLOCK_READ(&mbox_ft[i].start); | |
| 840 cnt = cyg_mbox_peek(test_mbox_handles[i]); | |
| 841 HAL_CLOCK_READ(&mbox_ft[i].end); | |
| 842 } | |
| 843 show_times(mbox_ft, nmboxes, "Peek [2 msgs] mbox"); | |
| 844 | |
| 845 wait_for_tick(); // Wait until the next clock tick to minimize aberations | |
| 846 for (i = 0; i < nmboxes; i++) { | |
| 0 | 847 HAL_CLOCK_READ(&mbox_ft[i].start); |
| 848 item = cyg_mbox_get(test_mbox_handles[i]); | |
| 849 HAL_CLOCK_READ(&mbox_ft[i].end); | |
| 850 } | |
| 2 | 851 show_times(mbox_ft, nmboxes, "Get [first] mbox"); |
| 0 | 852 |
| 853 wait_for_tick(); // Wait until the next clock tick to minimize aberations | |
| 2 | 854 for (i = 0; i < nmboxes; i++) { |
| 0 | 855 HAL_CLOCK_READ(&mbox_ft[i].start); |
| 856 item = cyg_mbox_get(test_mbox_handles[i]); | |
| 857 HAL_CLOCK_READ(&mbox_ft[i].end); | |
| 858 } | |
| 2 | 859 show_times(mbox_ft, nmboxes, "Get [second] mbox"); |
| 860 #endif // ifdef CYGMFN_KERNEL_SYNCH_MBOXT_PUT_CAN_WAIT | |
| 0 | 861 |
| 862 wait_for_tick(); // Wait until the next clock tick to minimize aberations | |
| 2 | 863 for (i = 0; i < nmboxes; i++) { |
| 0 | 864 HAL_CLOCK_READ(&mbox_ft[i].start); |
| 865 cyg_mbox_tryput(test_mbox_handles[i], (void *)i); | |
| 866 HAL_CLOCK_READ(&mbox_ft[i].end); | |
| 867 } | |
| 2 | 868 show_times(mbox_ft, nmboxes, "Tryput [first] mbox"); |
| 0 | 869 |
| 870 wait_for_tick(); // Wait until the next clock tick to minimize aberations | |
| 2 | 871 for (i = 0; i < nmboxes; i++) { |
| 0 | 872 HAL_CLOCK_READ(&mbox_ft[i].start); |
| 873 item = cyg_mbox_peek_item(test_mbox_handles[i]); | |
| 874 HAL_CLOCK_READ(&mbox_ft[i].end); | |
| 875 } | |
| 2 | 876 show_times(mbox_ft, nmboxes, "Peek item [non-empty] mbox"); |
| 0 | 877 |
| 878 wait_for_tick(); // Wait until the next clock tick to minimize aberations | |
| 2 | 879 for (i = 0; i < nmboxes; i++) { |
| 0 | 880 HAL_CLOCK_READ(&mbox_ft[i].start); |
| 881 item = cyg_mbox_tryget(test_mbox_handles[i]); | |
| 882 HAL_CLOCK_READ(&mbox_ft[i].end); | |
| 883 } | |
| 2 | 884 show_times(mbox_ft, nmboxes, "Tryget [non-empty] mbox"); |
| 0 | 885 |
| 886 wait_for_tick(); // Wait until the next clock tick to minimize aberations | |
| 2 | 887 for (i = 0; i < nmboxes; i++) { |
| 0 | 888 HAL_CLOCK_READ(&mbox_ft[i].start); |
| 889 item = cyg_mbox_peek_item(test_mbox_handles[i]); | |
| 890 HAL_CLOCK_READ(&mbox_ft[i].end); | |
| 891 } | |
| 2 | 892 show_times(mbox_ft, nmboxes, "Peek item [empty] mbox"); |
| 0 | 893 |
| 894 wait_for_tick(); // Wait until the next clock tick to minimize aberations | |
| 2 | 895 for (i = 0; i < nmboxes; i++) { |
| 0 | 896 HAL_CLOCK_READ(&mbox_ft[i].start); |
| 897 item = cyg_mbox_tryget(test_mbox_handles[i]); | |
| 898 HAL_CLOCK_READ(&mbox_ft[i].end); | |
| 899 } | |
| 2 | 900 show_times(mbox_ft, nmboxes, "Tryget [empty] mbox"); |
| 0 | 901 |
| 902 wait_for_tick(); // Wait until the next clock tick to minimize aberations | |
| 2 | 903 for (i = 0; i < nmboxes; i++) { |
| 0 | 904 HAL_CLOCK_READ(&mbox_ft[i].start); |
| 905 cyg_mbox_waiting_to_get(test_mbox_handles[i]); | |
| 906 HAL_CLOCK_READ(&mbox_ft[i].end); | |
| 907 } | |
| 2 | 908 show_times(mbox_ft, nmboxes, "Waiting to get mbox"); |
| 0 | 909 |
| 910 wait_for_tick(); // Wait until the next clock tick to minimize aberations | |
| 2 | 911 for (i = 0; i < nmboxes; i++) { |
| 0 | 912 HAL_CLOCK_READ(&mbox_ft[i].start); |
| 913 cyg_mbox_waiting_to_put(test_mbox_handles[i]); | |
| 914 HAL_CLOCK_READ(&mbox_ft[i].end); | |
| 915 } | |
| 2 | 916 show_times(mbox_ft, nmboxes, "Waiting to put mbox"); |
| 0 | 917 |
| 918 wait_for_tick(); // Wait until the next clock tick to minimize aberations | |
| 2 | 919 for (i = 0; i < nmboxes; i++) { |
| 0 | 920 HAL_CLOCK_READ(&mbox_ft[i].start); |
| 921 cyg_mbox_delete(test_mbox_handles[i]); | |
| 922 HAL_CLOCK_READ(&mbox_ft[i].end); | |
| 923 } | |
| 2 | 924 show_times(mbox_ft, nmboxes, "Delete mbox"); |
| 0 | 925 |
| 926 run_mbox_circuit_test(); | |
| 2 | 927 end_of_test_group(); |
| 0 | 928 } |
| 929 | |
| 930 void | |
| 931 run_mbox_circuit_test(void) | |
| 932 { | |
| 2 | 933 #ifdef CYGMFN_KERNEL_SYNCH_MBOXT_PUT_CAN_WAIT |
| 0 | 934 int i; |
| 935 // Set my priority lower than any I plan to create | |
| 936 cyg_thread_set_priority(cyg_thread_self(), 3); | |
| 937 // Set up for full mbox put/get test | |
| 938 cyg_mbox_create(&test_mbox_handles[0], &test_mboxes[0]); | |
| 939 cyg_semaphore_init(&synchro, 0); | |
| 940 cyg_thread_create(2, // Priority - just a number | |
| 941 mbox_test, // entry | |
| 942 0, // index | |
| 943 thread_name("thread", 0), // Name | |
| 944 &stacks[0][0], // Stack | |
| 945 STACK_SIZE, // Size | |
| 946 &mbox_test_thread_handle, // Handle | |
| 947 &mbox_test_thread // Thread data structure | |
| 948 ); | |
| 949 cyg_thread_resume(mbox_test_thread_handle); | |
| 2 | 950 for (i = 0; i < nmboxes; i++) { |
| 0 | 951 wait_for_tick(); // Wait until the next clock tick to minimize aberations |
| 952 HAL_CLOCK_READ(&mbox_ft[i].start); | |
| 953 cyg_mbox_put(test_mbox_handles[0], (void *)i); | |
| 954 cyg_semaphore_wait(&synchro); | |
| 955 } | |
| 2 | 956 cyg_thread_delete(mbox_test_thread_handle); |
| 957 show_times(mbox_ft, nmboxes, "Put/Get mbox"); | |
| 958 #endif | |
| 0 | 959 } |
| 960 | |
| 961 void | |
| 962 run_semaphore_tests(void) | |
| 963 { | |
| 964 int i; | |
| 2 | 965 cyg_count32 sem_val; |
| 0 | 966 // Semaphore primitives |
| 967 wait_for_tick(); // Wait until the next clock tick to minimize aberations | |
| 2 | 968 for (i = 0; i < nsemaphores; i++) { |
| 0 | 969 HAL_CLOCK_READ(&semaphore_ft[i].start); |
| 970 cyg_semaphore_init(&test_semaphores[i], 0); | |
| 971 HAL_CLOCK_READ(&semaphore_ft[i].end); | |
| 972 } | |
| 2 | 973 show_times(semaphore_ft, nsemaphores, "Init semaphore"); |
| 0 | 974 |
| 975 wait_for_tick(); // Wait until the next clock tick to minimize aberations | |
| 2 | 976 for (i = 0; i < nsemaphores; i++) { |
| 0 | 977 HAL_CLOCK_READ(&semaphore_ft[i].start); |
| 978 cyg_semaphore_post(&test_semaphores[i]); | |
| 979 HAL_CLOCK_READ(&semaphore_ft[i].end); | |
| 980 } | |
| 2 | 981 show_times(semaphore_ft, nsemaphores, "Post [0] semaphore"); |
| 0 | 982 |
| 983 wait_for_tick(); // Wait until the next clock tick to minimize aberations | |
| 2 | 984 for (i = 0; i < nsemaphores; i++) { |
| 0 | 985 HAL_CLOCK_READ(&semaphore_ft[i].start); |
| 986 cyg_semaphore_wait(&test_semaphores[i]); | |
| 987 HAL_CLOCK_READ(&semaphore_ft[i].end); | |
| 988 } | |
| 2 | 989 show_times(semaphore_ft, nsemaphores, "Wait [1] semaphore"); |
| 0 | 990 |
| 991 wait_for_tick(); // Wait until the next clock tick to minimize aberations | |
| 2 | 992 for (i = 0; i < nsemaphores; i++) { |
| 0 | 993 HAL_CLOCK_READ(&semaphore_ft[i].start); |
| 994 cyg_semaphore_trywait(&test_semaphores[i]); | |
| 995 HAL_CLOCK_READ(&semaphore_ft[i].end); | |
| 996 } | |
| 2 | 997 show_times(semaphore_ft, nsemaphores, "Trywait [0] semaphore"); |
| 0 | 998 |
| 999 wait_for_tick(); // Wait until the next clock tick to minimize aberations | |
| 2 | 1000 for (i = 0; i < nsemaphores; i++) { |
| 0 | 1001 cyg_semaphore_post(&test_semaphores[i]); |
| 1002 HAL_CLOCK_READ(&semaphore_ft[i].start); | |
| 1003 cyg_semaphore_trywait(&test_semaphores[i]); | |
| 1004 HAL_CLOCK_READ(&semaphore_ft[i].end); | |
| 1005 } | |
| 2 | 1006 show_times(semaphore_ft, nsemaphores, "Trywait [1] semaphore"); |
| 0 | 1007 |
| 1008 wait_for_tick(); // Wait until the next clock tick to minimize aberations | |
| 2 | 1009 for (i = 0; i < nsemaphores; i++) { |
| 0 | 1010 HAL_CLOCK_READ(&semaphore_ft[i].start); |
| 1011 cyg_semaphore_peek(&test_semaphores[i], &sem_val); | |
| 1012 HAL_CLOCK_READ(&semaphore_ft[i].end); | |
| 1013 } | |
| 2 | 1014 show_times(semaphore_ft, nsemaphores, "Peek semaphore"); |
| 0 | 1015 |
| 1016 wait_for_tick(); // Wait until the next clock tick to minimize aberations | |
| 2 | 1017 for (i = 0; i < nsemaphores; i++) { |
| 0 | 1018 HAL_CLOCK_READ(&semaphore_ft[i].start); |
| 1019 cyg_semaphore_destroy(&test_semaphores[i]); | |
| 1020 HAL_CLOCK_READ(&semaphore_ft[i].end); | |
| 1021 } | |
| 2 | 1022 show_times(semaphore_ft, nsemaphores, "Destroy semaphore"); |
| 0 | 1023 |
| 1024 run_semaphore_circuit_test(); | |
| 2 | 1025 end_of_test_group(); |
| 0 | 1026 } |
| 1027 | |
| 1028 void | |
| 1029 run_semaphore_circuit_test(void) | |
| 1030 { | |
| 1031 int i; | |
| 1032 // Set my priority lower than any I plan to create | |
| 1033 cyg_thread_set_priority(cyg_thread_self(), 3); | |
| 1034 // Set up for full semaphore post/wait test | |
| 1035 cyg_semaphore_init(&test_semaphores[0], 0); | |
| 1036 cyg_semaphore_init(&synchro, 0); | |
| 1037 cyg_thread_create(2, // Priority - just a number | |
| 1038 semaphore_test, // entry | |
| 1039 0, // index | |
| 1040 thread_name("thread", 0), // Name | |
| 1041 &stacks[0][0], // Stack | |
| 1042 STACK_SIZE, // Size | |
| 1043 &semaphore_test_thread_handle, // Handle | |
| 1044 &semaphore_test_thread // Thread data structure | |
| 1045 ); | |
| 1046 cyg_thread_resume(semaphore_test_thread_handle); | |
| 2 | 1047 for (i = 0; i < nsemaphores; i++) { |
| 0 | 1048 wait_for_tick(); // Wait until the next clock tick to minimize aberations |
| 1049 HAL_CLOCK_READ(&semaphore_ft[i].start); | |
| 1050 cyg_semaphore_post(&test_semaphores[0]); | |
| 1051 cyg_semaphore_wait(&synchro); | |
| 1052 } | |
| 2 | 1053 cyg_thread_delete(semaphore_test_thread_handle); |
| 1054 show_times(semaphore_ft, nsemaphores, "Post/Wait semaphore"); | |
| 0 | 1055 } |
| 1056 | |
| 1057 void | |
| 1058 run_counter_tests(void) | |
| 1059 { | |
| 1060 int i; | |
| 2 | 1061 cyg_tick_count_t val=0; |
| 0 | 1062 |
| 1063 wait_for_tick(); // Wait until the next clock tick to minimize aberations | |
| 2 | 1064 for (i = 0; i < ncounters; i++) { |
| 0 | 1065 HAL_CLOCK_READ(&counter_ft[i].start); |
| 1066 cyg_counter_create(&counters[i], &test_counters[i]); | |
| 1067 HAL_CLOCK_READ(&counter_ft[i].end); | |
| 1068 } | |
| 2 | 1069 show_times(counter_ft, ncounters, "Create counter"); |
| 0 | 1070 |
| 1071 wait_for_tick(); // Wait until the next clock tick to minimize aberations | |
| 2 | 1072 for (i = 0; i < ncounters; i++) { |
| 0 | 1073 HAL_CLOCK_READ(&counter_ft[i].start); |
| 1074 val = cyg_counter_current_value(counters[i]); | |
| 1075 HAL_CLOCK_READ(&counter_ft[i].end); | |
| 1076 } | |
| 2 | 1077 show_times(counter_ft, ncounters, "Get counter value"); |
| 0 | 1078 |
| 1079 wait_for_tick(); // Wait until the next clock tick to minimize aberations | |
| 2 | 1080 for (i = 0; i < ncounters; i++) { |
| 0 | 1081 HAL_CLOCK_READ(&counter_ft[i].start); |
| 1082 cyg_counter_set_value(counters[i], val); | |
| 1083 HAL_CLOCK_READ(&counter_ft[i].end); | |
| 1084 } | |
| 2 | 1085 show_times(counter_ft, ncounters, "Set counter value"); |
| 0 | 1086 |
| 1087 wait_for_tick(); // Wait until the next clock tick to minimize aberations | |
| 2 | 1088 for (i = 0; i < ncounters; i++) { |
| 0 | 1089 HAL_CLOCK_READ(&counter_ft[i].start); |
| 1090 cyg_counter_tick(counters[i]); | |
| 1091 HAL_CLOCK_READ(&counter_ft[i].end); | |
| 1092 } | |
| 2 | 1093 show_times(counter_ft, ncounters, "Tick counter"); |
| 0 | 1094 |
| 1095 wait_for_tick(); // Wait until the next clock tick to minimize aberations | |
| 2 | 1096 for (i = 0; i < ncounters; i++) { |
| 0 | 1097 HAL_CLOCK_READ(&counter_ft[i].start); |
| 1098 cyg_counter_delete(counters[i]); | |
| 1099 HAL_CLOCK_READ(&counter_ft[i].end); | |
| 1100 } | |
| 2 | 1101 show_times(counter_ft, ncounters, "Delete counter"); |
| 1102 end_of_test_group(); | |
| 0 | 1103 } |
| 1104 | |
| 1105 // Alarm callback function | |
| 1106 void | |
| 1107 alarm_cb(cyg_handle_t alarm, cyg_addrword_t val) | |
| 1108 { | |
| 1109 // empty call back | |
| 1110 } | |
| 1111 | |
| 1112 // Callback used to test determinancy | |
| 1113 static volatile int alarm_cnt; | |
| 1114 void | |
| 1115 alarm_cb2(cyg_handle_t alarm, cyg_addrword_t indx) | |
| 1116 { | |
| 2 | 1117 if (alarm_cnt == nscheds) return; |
| 0 | 1118 sched_ft[alarm_cnt].start = 0; |
| 1119 HAL_CLOCK_READ(&sched_ft[alarm_cnt++].end); | |
| 2 | 1120 if (alarm_cnt == nscheds) { |
| 0 | 1121 cyg_semaphore_post(&synchro); |
| 1122 } | |
| 1123 } | |
| 1124 | |
| 1125 // Null thread, used to keep scheduler busy | |
| 1126 void | |
| 1127 alarm_test(cyg_uint32 id) | |
| 1128 { | |
| 1129 while (true) { | |
| 1130 cyg_thread_yield(); | |
| 1131 } | |
| 1132 } | |
| 1133 | |
| 1134 void | |
| 1135 run_alarm_tests(void) | |
| 1136 { | |
| 1137 int i; | |
| 1138 cyg_tick_count_t init_val, step_val; | |
| 1139 cyg_handle_t rtc_handle; | |
| 1140 | |
| 1141 wait_for_tick(); // Wait until the next clock tick to minimize aberations | |
| 2 | 1142 for (i = 0; i < ncounters; i++) { |
| 0 | 1143 cyg_counter_create(&counters[i], &test_counters[i]); |
| 1144 } | |
| 2 | 1145 for (i = 0; i < nalarms; i++) { |
| 0 | 1146 HAL_CLOCK_READ(&alarm_ft[i].start); |
| 1147 cyg_alarm_create(counters[0], alarm_cb, 0, &alarms[i], &test_alarms[i]); | |
| 1148 HAL_CLOCK_READ(&alarm_ft[i].end); | |
| 1149 } | |
| 2 | 1150 show_times(alarm_ft, nalarms, "Create alarm"); |
| 0 | 1151 |
| 1152 wait_for_tick(); // Wait until the next clock tick to minimize aberations | |
| 1153 init_val = 0; step_val = 0; | |
| 2 | 1154 for (i = 0; i < nalarms; i++) { |
| 0 | 1155 HAL_CLOCK_READ(&alarm_ft[i].start); |
| 1156 cyg_alarm_initialize(alarms[i], init_val, step_val); | |
| 1157 HAL_CLOCK_READ(&alarm_ft[i].end); | |
| 1158 } | |
| 2 | 1159 show_times(alarm_ft, nalarms, "Initialize alarm"); |
| 0 | 1160 |
| 1161 wait_for_tick(); // Wait until the next clock tick to minimize aberations | |
| 1162 init_val = 0; step_val = 0; | |
| 2 | 1163 for (i = 0; i < nalarms; i++) { |
| 0 | 1164 HAL_CLOCK_READ(&alarm_ft[i].start); |
| 1165 cyg_alarm_disable(alarms[i]); | |
| 1166 HAL_CLOCK_READ(&alarm_ft[i].end); | |
| 1167 } | |
| 2 | 1168 show_times(alarm_ft, nalarms, "Disable alarm"); |
| 0 | 1169 |
| 1170 wait_for_tick(); // Wait until the next clock tick to minimize aberations | |
| 1171 init_val = 0; step_val = 0; | |
| 2 | 1172 for (i = 0; i < nalarms; i++) { |
| 0 | 1173 HAL_CLOCK_READ(&alarm_ft[i].start); |
| 1174 cyg_alarm_enable(alarms[i]); | |
| 1175 HAL_CLOCK_READ(&alarm_ft[i].end); | |
| 1176 } | |
| 2 | 1177 show_times(alarm_ft, nalarms, "Enable alarm"); |
| 0 | 1178 |
| 1179 wait_for_tick(); // Wait until the next clock tick to minimize aberations | |
| 2 | 1180 for (i = 0; i < nalarms; i++) { |
| 0 | 1181 HAL_CLOCK_READ(&alarm_ft[i].start); |
| 1182 cyg_alarm_delete(alarms[i]); | |
| 1183 HAL_CLOCK_READ(&alarm_ft[i].end); | |
| 1184 } | |
| 2 | 1185 show_times(alarm_ft, nalarms, "Delete 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]); | |
| 1189 cyg_alarm_create(counters[0], alarm_cb, 0, &alarms[0], &test_alarms[0]); | |
| 1190 init_val = 9999; step_val = 9999; | |
| 1191 cyg_alarm_initialize(alarms[0], init_val, step_val); | |
| 1192 cyg_alarm_enable(alarms[0]); | |
| 2 | 1193 for (i = 0; i < ncounters; i++) { |
| 0 | 1194 HAL_CLOCK_READ(&counter_ft[i].start); |
| 1195 cyg_counter_tick(counters[0]); | |
| 1196 HAL_CLOCK_READ(&counter_ft[i].end); | |
| 1197 } | |
| 2 | 1198 show_times(counter_ft, ncounters, "Tick counter [1 alarm]"); |
| 0 | 1199 |
| 1200 wait_for_tick(); // Wait until the next clock tick to minimize aberations | |
| 1201 cyg_counter_create(&counters[0], &test_counters[0]); | |
| 2 | 1202 for (i = 0; i < nalarms; i++) { |
| 0 | 1203 cyg_alarm_create(counters[0], alarm_cb, 0, &alarms[i], &test_alarms[i]); |
| 1204 init_val = 9999; step_val = 9999; | |
| 1205 cyg_alarm_initialize(alarms[i], init_val, step_val); | |
| 1206 cyg_alarm_enable(alarms[i]); | |
| 1207 } | |
| 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 counter [many alarms]"); |
| 0 | 1214 |
| 1215 wait_for_tick(); // Wait until the next clock tick to minimize aberations | |
| 1216 cyg_counter_create(&counters[0], &test_counters[0]); | |
| 1217 cyg_alarm_create(counters[0], alarm_cb, 0, &alarms[0], &test_alarms[0]); | |
| 1218 init_val = 1; step_val = 1; | |
| 1219 cyg_alarm_initialize(alarms[0], init_val, step_val); | |
| 1220 cyg_alarm_enable(alarms[0]); | |
| 2 | 1221 for (i = 0; i < ncounters; i++) { |
| 0 | 1222 HAL_CLOCK_READ(&counter_ft[i].start); |
| 1223 cyg_counter_tick(counters[0]); | |
| 1224 HAL_CLOCK_READ(&counter_ft[i].end); | |
| 1225 } | |
| 2 | 1226 show_times(counter_ft, ncounters, "Tick & fire counter [1 alarm]"); |
| 0 | 1227 |
| 1228 wait_for_tick(); // Wait until the next clock tick to minimize aberations | |
| 1229 cyg_counter_create(&counters[0], &test_counters[0]); | |
| 2 | 1230 for (i = 0; i < nalarms; i++) { |
| 0 | 1231 cyg_alarm_create(counters[0], alarm_cb, i, &alarms[i], &test_alarms[i]); |
| 1232 init_val = 1; step_val = 1; | |
| 1233 cyg_alarm_initialize(alarms[i], init_val, step_val); | |
| 1234 cyg_alarm_enable(alarms[i]); | |
| 1235 } | |
| 2 | 1236 for (i = 0; i < nalarms; i++) { |
| 1237 HAL_CLOCK_READ(&alarm_ft[i].start); | |
| 0 | 1238 cyg_counter_tick(counters[0]); |
| 2 | 1239 HAL_CLOCK_READ(&alarm_ft[i].end); |
| 0 | 1240 } |
| 2 | 1241 for (i = 0; i < nalarms; i++) { |
| 0 | 1242 cyg_alarm_delete(alarms[i]); |
| 1243 } | |
| 2 | 1244 show_times(alarm_ft, nalarms, "Tick & fire counters [>1 together]"); |
| 1245 | |
| 1246 wait_for_tick(); // Wait until the next clock tick to minimize aberations | |
| 1247 cyg_counter_create(&counters[0], &test_counters[0]); | |
| 1248 for (i = 0; i < nalarms; i++) { | |
| 1249 cyg_alarm_create(counters[0], alarm_cb, i, &alarms[i], &test_alarms[i]); | |
| 1250 init_val = i+1; step_val = nalarms+1; | |
| 1251 cyg_alarm_initialize(alarms[i], init_val, step_val); | |
| 1252 cyg_alarm_enable(alarms[i]); | |
| 1253 } | |
| 1254 for (i = 0; i < nalarms; i++) { | |
| 1255 HAL_CLOCK_READ(&alarm_ft[i].start); | |
| 1256 cyg_counter_tick(counters[0]); | |
| 1257 HAL_CLOCK_READ(&alarm_ft[i].end); | |
| 1258 } | |
| 1259 for (i = 0; i < nalarms; i++) { | |
| 1260 cyg_alarm_delete(alarms[i]); | |
| 1261 } | |
| 1262 show_times(alarm_ft, nalarms, "Tick & fire counters [>1 separately]"); | |
| 0 | 1263 |
| 1264 wait_for_tick(); // Wait until the next clock tick to minimize aberations | |
| 1265 cyg_clock_to_counter(cyg_real_time_clock(), &rtc_handle); | |
| 1266 cyg_alarm_create(rtc_handle, alarm_cb2, 0, &alarms[0], &test_alarms[0]); | |
| 1267 init_val = 5; step_val = 5; alarm_cnt = 0; | |
| 1268 cyg_alarm_initialize(alarms[0], init_val, step_val); | |
| 1269 cyg_semaphore_init(&synchro, 0); | |
| 1270 cyg_alarm_enable(alarms[0]); | |
| 1271 cyg_semaphore_wait(&synchro); | |
| 1272 cyg_alarm_disable(alarms[0]); | |
| 1273 cyg_alarm_delete(alarms[0]); | |
| 2 | 1274 show_times(sched_ft, nscheds, "Alarm latency [0 threads]"); |
| 0 | 1275 |
| 1276 // Set my priority higher than any I plan to create | |
| 1277 cyg_thread_set_priority(cyg_thread_self(), 2); | |
| 1278 for (i = 0; i < 2; i++) { | |
| 1279 cyg_thread_create(10, // Priority - just a number | |
| 1280 alarm_test, // entry | |
| 1281 i, // index | |
| 1282 thread_name("thread", i), // Name | |
| 1283 &stacks[i][0], // Stack | |
| 1284 STACK_SIZE, // Size | |
| 1285 &threads[i], // Handle | |
| 1286 &test_threads[i] // Thread data structure | |
| 1287 ); | |
| 1288 cyg_thread_resume(threads[i]); | |
| 1289 } | |
| 1290 wait_for_tick(); // Wait until the next clock tick to minimize aberations | |
| 1291 cyg_clock_to_counter(cyg_real_time_clock(), &rtc_handle); | |
| 1292 cyg_alarm_create(rtc_handle, alarm_cb2, 0, &alarms[0], &test_alarms[0]); | |
| 1293 init_val = 5; step_val = 5; alarm_cnt = 0; | |
| 1294 cyg_alarm_initialize(alarms[0], init_val, step_val); | |
| 1295 cyg_semaphore_init(&synchro, 0); | |
| 1296 cyg_alarm_enable(alarms[0]); | |
| 1297 cyg_semaphore_wait(&synchro); | |
| 1298 cyg_alarm_disable(alarms[0]); | |
| 1299 cyg_alarm_delete(alarms[0]); | |
| 2 | 1300 show_times(sched_ft, nscheds, "Alarm latency [2 threads]"); |
| 0 | 1301 for (i = 0; i < 2; i++) { |
| 1302 cyg_thread_suspend(threads[i]); | |
| 2 | 1303 cyg_thread_delete(threads[i]); |
| 0 | 1304 } |
| 1305 | |
| 1306 // Set my priority higher than any I plan to create | |
| 1307 cyg_thread_set_priority(cyg_thread_self(), 2); | |
| 2 | 1308 for (i = 0; i < ntest_threads; i++) { |
| 0 | 1309 cyg_thread_create(10, // Priority - just a number |
| 1310 alarm_test, // entry | |
| 1311 i, // index | |
| 1312 thread_name("thread", i), // Name | |
| 1313 &stacks[i][0], // Stack | |
| 1314 STACK_SIZE, // Size | |
| 1315 &threads[i], // Handle | |
| 1316 &test_threads[i] // Thread data structure | |
| 1317 ); | |
| 1318 cyg_thread_resume(threads[i]); | |
| 1319 } | |
| 1320 wait_for_tick(); // Wait until the next clock tick to minimize aberations | |
| 1321 cyg_clock_to_counter(cyg_real_time_clock(), &rtc_handle); | |
| 1322 cyg_alarm_create(rtc_handle, alarm_cb2, 0, &alarms[0], &test_alarms[0]); | |
| 1323 init_val = 5; step_val = 5; alarm_cnt = 0; | |
| 1324 cyg_alarm_initialize(alarms[0], init_val, step_val); | |
| 1325 cyg_semaphore_init(&synchro, 0); | |
| 1326 cyg_alarm_enable(alarms[0]); | |
| 1327 cyg_semaphore_wait(&synchro); | |
| 1328 cyg_alarm_disable(alarms[0]); | |
| 1329 cyg_alarm_delete(alarms[0]); | |
| 2 | 1330 show_times(sched_ft, nscheds, "Alarm latency [many threads]"); |
| 1331 for (i = 0; i < ntest_threads; i++) { | |
| 0 | 1332 cyg_thread_suspend(threads[i]); |
| 2 | 1333 cyg_thread_delete(threads[i]); |
| 0 | 1334 } |
| 2 | 1335 end_of_test_group(); |
| 0 | 1336 } |
| 1337 | |
| 1338 void | |
| 1339 run_sched_tests(void) | |
| 1340 { | |
| 1341 int i; | |
| 1342 | |
| 1343 wait_for_tick(); // Wait until the next clock tick to minimize aberations | |
| 2 | 1344 for (i = 0; i < nscheds; i++) { |
| 0 | 1345 HAL_CLOCK_READ(&sched_ft[i].start); |
| 1346 cyg_scheduler_lock(); | |
| 1347 HAL_CLOCK_READ(&sched_ft[i].end); | |
| 1348 cyg_scheduler_unlock(); | |
| 1349 } | |
| 2 | 1350 show_times(sched_ft, nscheds, "Scheduler lock"); |
| 0 | 1351 |
| 1352 wait_for_tick(); // Wait until the next clock tick to minimize aberations | |
| 2 | 1353 for (i = 0; i < nscheds; i++) { |
| 0 | 1354 cyg_scheduler_lock(); |
| 1355 HAL_CLOCK_READ(&sched_ft[i].start); | |
| 1356 cyg_scheduler_unlock(); | |
| 1357 HAL_CLOCK_READ(&sched_ft[i].end); | |
| 1358 } | |
| 2 | 1359 show_times(sched_ft, nscheds, "Scheduler unlock [0 threads]"); |
| 0 | 1360 |
| 1361 // Set my priority higher than any I plan to create | |
| 1362 cyg_thread_set_priority(cyg_thread_self(), 2); | |
| 1363 for (i = 0; i < 1; i++) { | |
| 1364 cyg_thread_create(10, // Priority - just a number | |
| 1365 test0, // entry | |
| 1366 i, // index | |
| 1367 thread_name("thread", i), // Name | |
| 1368 &stacks[i][0], // Stack | |
| 1369 STACK_SIZE, // Size | |
| 1370 &threads[i], // Handle | |
| 1371 &test_threads[i] // Thread data structure | |
| 1372 ); | |
| 1373 } | |
| 1374 wait_for_tick(); // Wait until the next clock tick to minimize aberations | |
| 2 | 1375 for (i = 0; i < nscheds; i++) { |
| 0 | 1376 cyg_scheduler_lock(); |
| 1377 HAL_CLOCK_READ(&sched_ft[i].start); | |
| 1378 cyg_scheduler_unlock(); | |
| 1379 HAL_CLOCK_READ(&sched_ft[i].end); | |
| 1380 } | |
| 2 | 1381 show_times(sched_ft, nscheds, "Scheduler unlock [1 suspended]"); |
| 0 | 1382 for (i = 0; i < 1; i++) { |
| 2 | 1383 cyg_thread_delete(threads[i]); |
| 0 | 1384 } |
| 1385 | |
| 1386 // Set my priority higher than any I plan to create | |
| 1387 cyg_thread_set_priority(cyg_thread_self(), 2); | |
| 2 | 1388 for (i = 0; i < ntest_threads; i++) { |
| 0 | 1389 cyg_thread_create(10, // Priority - just a number |
| 1390 test0, // entry | |
| 1391 i, // index | |
| 1392 thread_name("thread", i), // Name | |
| 1393 &stacks[i][0], // Stack | |
| 1394 STACK_SIZE, // Size | |
| 1395 &threads[i], // Handle | |
| 1396 &test_threads[i] // Thread data structure | |
| 1397 ); | |
| 1398 } | |
| 1399 wait_for_tick(); // Wait until the next clock tick to minimize aberations | |
| 2 | 1400 for (i = 0; i < nscheds; i++) { |
| 0 | 1401 cyg_scheduler_lock(); |
| 1402 HAL_CLOCK_READ(&sched_ft[i].start); | |
| 1403 cyg_scheduler_unlock(); | |
| 1404 HAL_CLOCK_READ(&sched_ft[i].end); | |
| 1405 } | |
| 2 | 1406 show_times(sched_ft, nscheds, "Scheduler unlock [many suspended]"); |
| 1407 for (i = 0; i < ntest_threads; i++) { | |
| 1408 cyg_thread_delete(threads[i]); | |
| 0 | 1409 } |
| 1410 | |
| 1411 // Set my priority higher than any I plan to create | |
| 1412 cyg_thread_set_priority(cyg_thread_self(), 2); | |
| 2 | 1413 for (i = 0; i < ntest_threads; i++) { |
| 0 | 1414 cyg_thread_create(10, // Priority - just a number |
| 1415 test0, // entry | |
| 1416 i, // index | |
| 1417 thread_name("thread", i), // Name | |
| 1418 &stacks[i][0], // Stack | |
| 1419 STACK_SIZE, // Size | |
| 1420 &threads[i], // Handle | |
| 1421 &test_threads[i] // Thread data structure | |
| 1422 ); | |
| 1423 cyg_thread_resume(threads[i]); | |
| 1424 } | |
| 1425 wait_for_tick(); // Wait until the next clock tick to minimize aberations | |
| 2 | 1426 for (i = 0; i < nscheds; i++) { |
| 0 | 1427 cyg_scheduler_lock(); |
| 1428 HAL_CLOCK_READ(&sched_ft[i].start); | |
| 1429 cyg_scheduler_unlock(); | |
| 1430 HAL_CLOCK_READ(&sched_ft[i].end); | |
| 1431 } | |
| 2 | 1432 show_times(sched_ft, nscheds, "Scheduler unlock [many low prio]"); |
| 1433 for (i = 0; i < ntest_threads; i++) { | |
| 1434 cyg_thread_delete(threads[i]); | |
| 0 | 1435 } |
| 2 | 1436 end_of_test_group(); |
| 0 | 1437 } |
| 1438 | |
| 1439 void | |
| 1440 run_all_tests(CYG_ADDRESS id) | |
| 1441 { | |
| 2 | 1442 int i, j; |
| 1443 cyg_uint32 tv[nsamples], tv0, tv1; | |
| 1444 cyg_uint32 min_stack, max_stack, total_stack, actual_stack; | |
| 1445 cyg_tick_count_t ticks, tick0, tick1; | |
| 0 | 1446 #ifdef CYG_SCHEDULER_LOCK_TIMINGS |
| 1447 cyg_uint32 lock_ave, lock_max; | |
| 1448 #endif | |
|
34
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
10
diff
changeset
|
1449 #if defined(CYGVAR_KERNEL_COUNTERS_CLOCK_LATENCY) && defined(HAL_CLOCK_LATENCY) |
| 0 | 1450 cyg_int32 clock_ave; |
| 1451 #endif | |
| 1452 | |
| 2 | 1453 disable_clock_latency_measurement(); |
|
8
ece80412419a
Merge from eCos master repository on 1999-05-21-22:05:54-BST
jlarmour
parents:
4
diff
changeset
|
1454 |
|
ece80412419a
Merge from eCos master repository on 1999-05-21-22:05:54-BST
jlarmour
parents:
4
diff
changeset
|
1455 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
|
1456 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
|
1457 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
|
1458 cyg_test_clear_interrupt_stack(); |
|
ece80412419a
Merge from eCos master repository on 1999-05-21-22:05:54-BST
jlarmour
parents:
4
diff
changeset
|
1459 |
| 2 | 1460 diag_printf("\neCos Kernel Timings\n"); |
| 1461 diag_printf("Notes: all times are in microseconds (.000001) unless otherwise stated\n"); | |
| 1462 #ifdef STATS_WITHOUT_FIRST_SAMPLE | |
| 1463 diag_printf(" second line of results have first sample removed\n"); | |
| 1464 #endif | |
| 1465 | |
| 1466 cyg_thread_delay(2); // Make sure the clock is actually running | |
| 1467 | |
| 1468 ns_per_system_clock = 1000000/rtc_resolution[1]; | |
| 1469 | |
| 1470 for (i = 0; i < nsamples; i++) { | |
| 0 | 1471 HAL_CLOCK_READ(&tv[i]); |
| 1472 } | |
| 1473 tv0 = 0; | |
| 2 | 1474 for (i = 1; i < nsamples; i++) { |
| 1475 tv0 += tv[i] - tv[i-1]; | |
| 0 | 1476 } |
| 2 | 1477 end_of_test_group(); |
| 0 | 1478 |
| 2 | 1479 overhead = tv0 / (nsamples-1); |
| 1480 diag_printf("Reading the hardware clock takes %d 'ticks' overhead\n", overhead); | |
| 1481 diag_printf("... this value will be factored out of all other measurements\n"); | |
| 0 | 1482 |
| 1483 // Try and measure how long the clock interrupt handling takes | |
| 2 | 1484 for (i = 0; i < nsamples; i++) { |
| 1485 tick0 = cyg_current_time(); | |
| 1486 while (true) { | |
| 1487 tick1 = cyg_current_time(); | |
| 1488 if (tick0 != tick1) break; | |
| 1489 } | |
| 1490 HAL_CLOCK_READ(&tv[i]); | |
| 0 | 1491 } |
| 2 | 1492 tv1 = 0; |
| 1493 for (i = 0; i < nsamples; i++) { | |
| 1494 tv1 += tv[i] * 1000; | |
| 1495 } | |
| 1496 tv1 = tv1 / nsamples; | |
| 0 | 1497 tv1 -= overhead; // Adjust out the cost of getting the timer value |
| 2 | 1498 diag_printf("Clock interrupt took"); |
| 1499 show_ticks_in_us(tv1); | |
| 1500 diag_printf(" microseconds (%d raw clock ticks)\n", tv1/1000); | |
| 1501 enable_clock_latency_measurement(); | |
| 0 | 1502 |
| 1503 ticks = cyg_current_time(); | |
| 1504 | |
| 1505 show_test_parameters(); | |
| 1506 show_times_hdr(); | |
| 1507 | |
| 2 | 1508 reset_clock_latency_measurement(); |
| 1509 | |
| 0 | 1510 run_thread_tests(); |
| 1511 run_sched_tests(); | |
| 1512 run_mutex_tests(); | |
| 1513 run_mbox_tests(); | |
| 1514 run_semaphore_tests(); | |
| 1515 run_counter_tests(); | |
| 1516 run_alarm_tests(); | |
| 1517 | |
| 1518 #ifdef CYG_SCHEDULER_LOCK_TIMINGS | |
| 1519 Cyg_Scheduler::get_lock_times(&lock_ave, &lock_max); | |
| 2 | 1520 diag_printf("\nMax lock:"); |
| 1521 show_ticks_in_us(lock_max); | |
| 1522 diag_printf(", Ave lock:"); | |
| 1523 show_ticks_in_us(lock_ave); | |
| 1524 diag_printf("\n"); | |
| 0 | 1525 #endif |
| 1526 | |
|
34
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
10
diff
changeset
|
1527 #if defined(CYGVAR_KERNEL_COUNTERS_CLOCK_LATENCY) && defined(HAL_CLOCK_LATENCY) |
| 2 | 1528 // Display latency figures in same format as all other numbers |
| 1529 disable_clock_latency_measurement(); | |
| 1530 clock_ave = (total_clock_latency*1000) / total_clock_interrupts; | |
| 1531 show_ticks_in_us(clock_ave); | |
| 1532 show_ticks_in_us(min_clock_latency*1000); | |
| 1533 show_ticks_in_us(max_clock_latency*1000); | |
| 1534 show_ticks_in_us(0); | |
| 1535 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
|
1536 enable_clock_latency_measurement(); |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
10
diff
changeset
|
1537 #endif |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
10
diff
changeset
|
1538 |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
10
diff
changeset
|
1539 #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
|
1540 disable_clock_latency_measurement(); |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
10
diff
changeset
|
1541 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
|
1542 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
|
1543 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
|
1544 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
|
1545 show_ticks_in_us(0); |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
10
diff
changeset
|
1546 diag_printf(" Clock DSR latency\n\n"); |
| 2 | 1547 enable_clock_latency_measurement(); |
| 0 | 1548 #endif |
| 1549 | |
| 2 | 1550 disable_clock_latency_measurement(); |
| 1551 min_stack = STACK_SIZE; | |
| 1552 max_stack = 0; | |
| 1553 total_stack = 0; | |
| 1554 for (i = 0; i < NTEST_THREADS; i++) { | |
| 1555 for (j = 0; j < STACK_SIZE; j++) { | |
| 1556 if (stacks[i][j]) break; | |
| 1557 } | |
| 1558 actual_stack = STACK_SIZE-j; | |
| 1559 if (actual_stack < min_stack) min_stack = actual_stack; | |
| 1560 if (actual_stack > max_stack) max_stack = actual_stack; | |
| 1561 total_stack += actual_stack; | |
| 1562 } | |
| 1563 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
|
1564 if (((char *)stack[0])[j]) break; |
| 2 | 1565 } |
| 1566 diag_printf("%5d %5d %5d (main stack: %5d) Thread stack used (%d total)\n", | |
| 1567 total_stack/NTEST_THREADS, min_stack, max_stack, | |
| 1568 STACKSIZE - j, STACK_SIZE); | |
|
8
ece80412419a
Merge from eCos master repository on 1999-05-21-22:05:54-BST
jlarmour
parents:
4
diff
changeset
|
1569 |
|
ece80412419a
Merge from eCos master repository on 1999-05-21-22:05:54-BST
jlarmour
parents:
4
diff
changeset
|
1570 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
|
1571 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
|
1572 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
|
1573 |
| 2 | 1574 enable_clock_latency_measurement(); |
| 1575 | |
| 0 | 1576 ticks = cyg_current_time(); |
| 2 | 1577 diag_printf("\nTiming complete - %d ms total\n\n", (int)((ticks*ns_per_system_clock)/1000)); |
| 0 | 1578 |
| 1579 CYG_TEST_PASS_FINISH("Basic timing OK"); | |
| 1580 } | |
| 1581 | |
| 1582 void tm_basic_main( void ) | |
| 1583 { | |
| 1584 CYG_TEST_INIT(); | |
| 1585 | |
| 2 | 1586 if (cyg_test_is_simulator) { |
| 1587 nsamples = NSAMPLES_SIM; | |
| 1588 ntest_threads = NTEST_THREADS_SIM; | |
| 1589 nthread_switches = NTHREAD_SWITCHES_SIM; | |
| 1590 nmutexes = NMUTEXES_SIM; | |
| 1591 nmboxes = NMBOXES_SIM; | |
| 1592 nsemaphores = NSEMAPHORES_SIM; | |
| 1593 nscheds = NSCHEDS_SIM; | |
| 1594 ncounters = NCOUNTERS_SIM; | |
| 1595 nalarms = NALARMS_SIM; | |
| 1596 } else { | |
| 1597 nsamples = NSAMPLES; | |
| 1598 ntest_threads = NTEST_THREADS; | |
| 1599 nthread_switches = NTHREAD_SWITCHES; | |
| 1600 nmutexes = NMUTEXES; | |
| 1601 nmboxes = NMBOXES; | |
| 1602 nsemaphores = NSEMAPHORES; | |
| 1603 nscheds = NSCHEDS; | |
| 1604 ncounters = NCOUNTERS; | |
| 1605 nalarms = NALARMS; | |
| 1606 } | |
| 1607 | |
| 0 | 1608 new_thread(run_all_tests, 0); |
| 1609 | |
| 1610 Cyg_Scheduler::scheduler.start(); | |
|
4
1d7f19c9e4d1
Merge from eCos master repository on 1999-05-11-21:11:10-BST
jlarmour
parents:
2
diff
changeset
|
1611 |
| 0 | 1612 } |
| 1613 | |
| 1614 externC void | |
| 1615 cyg_start( void ) | |
| 1616 { | |
| 1617 tm_basic_main(); | |
| 1618 } | |
| 2 | 1619 |
| 1620 #else // CYGFUN_KERNEL_API_C | |
| 1621 | |
| 1622 externC void | |
| 1623 cyg_start( void ) | |
| 1624 { | |
| 1625 CYG_TEST_INIT(); | |
| 1626 CYG_TEST_PASS_FINISH("Timing tests require:\n" | |
| 1627 "CYGFUN_KERNEL_API_C && \n" | |
| 1628 "CYGSEM_KERNEL_SCHED_MLQUEUE &&\n" | |
| 1629 "CYGVAR_KERNEL_COUNTERS_CLOCK &&\n" | |
| 1630 "!CYGPKG_HAL_I386_LINUX &&\n" | |
| 1631 "(CYGNUM_KERNEL_SCHED_PRIORITIES > 12)\n"); | |
| 1632 } | |
| 1633 #endif // CYGFUN_KERNEL_API_C, etc. | |
| 1634 | |
| 0 | 1635 // EOF tm_basic.cxx |
