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