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