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