|
0
|
1 /*================================================================= |
|
|
2 // |
|
|
3 // kcache1.c |
|
|
4 // |
|
|
5 // Cache timing test |
|
|
6 // |
|
|
7 //========================================================================== |
|
|
8 //####COPYRIGHTBEGIN#### |
|
|
9 // |
|
|
10 // ------------------------------------------- |
|
|
11 // The contents of this file are subject to the Cygnus eCos Public License |
|
|
12 // Version 1.0 (the "License"); you may not use this file except in |
|
|
13 // compliance with the License. You may obtain a copy of the License at |
|
|
14 // http://sourceware.cygnus.com/ecos |
|
|
15 // |
|
|
16 // Software distributed under the License is distributed on an "AS IS" |
|
|
17 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the |
|
|
18 // License for the specific language governing rights and limitations under |
|
|
19 // the License. |
|
|
20 // |
|
|
21 // The Original Code is eCos - Embedded Cygnus Operating System, released |
|
|
22 // September 30, 1998. |
|
|
23 // |
|
|
24 // The Initial Developer of the Original Code is Cygnus. Portions created |
|
2
|
25 // by Cygnus are Copyright (C) 1998,1999 Cygnus Solutions. All Rights Reserved. |
|
0
|
26 // ------------------------------------------- |
|
|
27 // |
|
|
28 //####COPYRIGHTEND#### |
|
|
29 //========================================================================== |
|
|
30 //#####DESCRIPTIONBEGIN#### |
|
|
31 // |
|
|
32 // Author(s): dsm |
|
|
33 // Contributors: dsm, nickg |
|
|
34 // Date: 1998-06-18 |
|
|
35 //####DESCRIPTIONEND#### |
|
|
36 */ |
|
|
37 |
|
2
|
38 #include <cyg/hal/hal_arch.h> // CYGNUM_HAL_STACK_SIZE_TYPICAL |
|
|
39 |
|
0
|
40 #include <cyg/kernel/kapi.h> |
|
|
41 |
|
|
42 #include <cyg/infra/testcase.h> |
|
|
43 |
|
|
44 #ifdef CYGVAR_KERNEL_COUNTERS_CLOCK |
|
|
45 #ifdef CYGFUN_KERNEL_API_C |
|
|
46 |
|
|
47 #include <cyg/infra/diag.h> |
|
|
48 #include <cyg/hal/hal_cache.h> |
|
2
|
49 #include <cyg/hal/hal_intr.h> |
|
0
|
50 |
|
|
51 // ------------------------------------------------------------------------- |
|
|
52 // If the HAL does not supply this, we supply our own version |
|
|
53 |
|
|
54 #ifndef HAL_DCACHE_PURGE_ALL |
|
|
55 |
|
|
56 static cyg_uint8 dca[HAL_DCACHE_SIZE + HAL_DCACHE_LINE_SIZE*2]; |
|
|
57 |
|
|
58 #define HAL_DCACHE_PURGE_ALL() \ |
|
|
59 CYG_MACRO_START \ |
|
|
60 volatile cyg_uint8 *addr = &dca[HAL_DCACHE_LINE_SIZE]; \ |
|
|
61 volatile cyg_uint8 tmp = 0; \ |
|
|
62 int i; \ |
|
|
63 for( i = 0; i < HAL_DCACHE_SIZE; i += HAL_DCACHE_LINE_SIZE ) \ |
|
|
64 { \ |
|
|
65 tmp = addr[i]; \ |
|
|
66 } \ |
|
|
67 CYG_MACRO_END |
|
|
68 |
|
|
69 #endif |
|
|
70 |
|
|
71 // ------------------------------------------------------------------------- |
|
|
72 |
|
|
73 #define NTHREADS 1 |
|
2
|
74 #define STACKSIZE CYGNUM_HAL_STACK_SIZE_TYPICAL |
|
0
|
75 |
|
|
76 static cyg_handle_t thread[NTHREADS]; |
|
|
77 |
|
|
78 static cyg_thread thread_obj[NTHREADS]; |
|
|
79 static char stack[NTHREADS][STACKSIZE]; |
|
|
80 |
|
|
81 #define MAXSIZE 1<<18 |
|
|
82 |
|
|
83 volatile char m[MAXSIZE]; |
|
|
84 |
|
2
|
85 #ifndef MAX_STRIDE |
|
|
86 #define MAX_STRIDE 64 |
|
|
87 #endif |
|
|
88 |
|
0
|
89 // ------------------------------------------------------------------------- |
|
|
90 |
|
|
91 static void time0(register cyg_uint32 stride) |
|
|
92 { |
|
|
93 register cyg_uint32 j,k; |
|
|
94 cyg_tick_count_t count0, count1; |
|
|
95 cyg_ucount32 t; |
|
|
96 register char c; |
|
|
97 |
|
|
98 count0 = cyg_current_time(); |
|
|
99 |
|
2
|
100 k = 0; |
|
|
101 if ( cyg_test_is_simulator ) |
|
|
102 k = 3960; |
|
|
103 |
|
|
104 for(; k<4000;k++) { |
|
0
|
105 for(j=0; j<(HAL_DCACHE_SIZE/HAL_DCACHE_LINE_SIZE); j++) { |
|
|
106 c=m[stride*j]; |
|
|
107 } |
|
|
108 } |
|
|
109 |
|
|
110 count1 = cyg_current_time(); |
|
|
111 t = count1 - count0; |
|
|
112 diag_printf("stride=%d, time=%d\n", stride, t); |
|
|
113 } |
|
|
114 |
|
|
115 // ------------------------------------------------------------------------- |
|
|
116 |
|
|
117 void time1(void) |
|
|
118 { |
|
|
119 cyg_uint32 i; |
|
|
120 |
|
2
|
121 for(i=1; i<=MAX_STRIDE; i+=i) { |
|
0
|
122 time0(i); |
|
|
123 } |
|
|
124 } |
|
|
125 |
|
|
126 // ------------------------------------------------------------------------- |
|
|
127 // This test could be improved by counting number of passes possible |
|
|
128 // in a given number of ticks. |
|
|
129 |
|
|
130 static void entry0( cyg_addrword_t data ) |
|
|
131 { |
|
2
|
132 register CYG_INTERRUPT_STATE oldints; |
|
|
133 |
|
|
134 HAL_DISABLE_INTERRUPTS(oldints); |
|
0
|
135 HAL_DCACHE_PURGE_ALL(); |
|
|
136 HAL_ICACHE_INVALIDATE_ALL(); |
|
|
137 HAL_DCACHE_INVALIDATE_ALL(); |
|
|
138 HAL_ICACHE_DISABLE(); |
|
|
139 HAL_DCACHE_DISABLE(); |
|
2
|
140 HAL_RESTORE_INTERRUPTS(oldints); |
|
0
|
141 CYG_TEST_INFO("Dcache off Icache off"); |
|
|
142 time1(); |
|
|
143 |
|
2
|
144 HAL_DISABLE_INTERRUPTS(oldints); |
|
0
|
145 HAL_DCACHE_PURGE_ALL(); |
|
|
146 HAL_ICACHE_INVALIDATE_ALL(); |
|
|
147 HAL_DCACHE_INVALIDATE_ALL(); |
|
|
148 HAL_ICACHE_DISABLE(); |
|
|
149 HAL_DCACHE_ENABLE(); |
|
2
|
150 HAL_RESTORE_INTERRUPTS(oldints); |
|
0
|
151 CYG_TEST_INFO("Dcache on Icache off"); |
|
|
152 time1(); |
|
|
153 |
|
2
|
154 HAL_DISABLE_INTERRUPTS(oldints); |
|
0
|
155 HAL_DCACHE_PURGE_ALL(); |
|
|
156 HAL_ICACHE_INVALIDATE_ALL(); |
|
|
157 HAL_DCACHE_INVALIDATE_ALL(); |
|
|
158 HAL_ICACHE_ENABLE(); |
|
|
159 HAL_DCACHE_DISABLE(); |
|
2
|
160 HAL_RESTORE_INTERRUPTS(oldints); |
|
0
|
161 CYG_TEST_INFO("Dcache off Icache on"); |
|
|
162 time1(); |
|
|
163 |
|
2
|
164 HAL_DISABLE_INTERRUPTS(oldints); |
|
0
|
165 HAL_DCACHE_PURGE_ALL(); |
|
|
166 HAL_ICACHE_INVALIDATE_ALL(); |
|
|
167 HAL_DCACHE_INVALIDATE_ALL(); |
|
|
168 HAL_ICACHE_ENABLE(); |
|
|
169 HAL_DCACHE_ENABLE(); |
|
2
|
170 HAL_RESTORE_INTERRUPTS(oldints); |
|
0
|
171 CYG_TEST_INFO("Dcache on Icache on"); |
|
|
172 time1(); |
|
|
173 |
|
|
174 |
|
2
|
175 HAL_DISABLE_INTERRUPTS(oldints); |
|
0
|
176 HAL_DCACHE_PURGE_ALL(); |
|
|
177 HAL_ICACHE_INVALIDATE_ALL(); |
|
|
178 HAL_DCACHE_INVALIDATE_ALL(); |
|
|
179 HAL_ICACHE_DISABLE(); |
|
|
180 HAL_DCACHE_DISABLE(); |
|
2
|
181 HAL_RESTORE_INTERRUPTS(oldints); |
|
0
|
182 CYG_TEST_INFO("Dcache off Icache off"); |
|
|
183 time1(); |
|
|
184 |
|
|
185 CYG_TEST_PASS_FINISH("End of test"); |
|
|
186 } |
|
|
187 |
|
|
188 // ------------------------------------------------------------------------- |
|
|
189 |
|
|
190 void kcache2_main( void ) |
|
|
191 { |
|
|
192 CYG_TEST_INIT(); |
|
|
193 |
|
|
194 cyg_thread_create(4, entry0 , (cyg_addrword_t)0, "kcache1", |
|
2
|
195 (void *)stack[0], STACKSIZE, &thread[0], &thread_obj[0]); |
|
0
|
196 cyg_thread_resume(thread[0]); |
|
|
197 |
|
|
198 cyg_scheduler_start(); |
|
|
199 } |
|
|
200 |
|
|
201 // ------------------------------------------------------------------------- |
|
|
202 |
|
|
203 externC void |
|
|
204 cyg_start( void ) |
|
|
205 { |
|
|
206 kcache2_main(); |
|
|
207 } |
|
|
208 |
|
|
209 // ------------------------------------------------------------------------- |
|
|
210 |
|
|
211 #else // def CYGFUN_KERNEL_API_C |
|
|
212 #define N_A_MSG "Kernel C API layer disabled" |
|
|
213 #endif // def CYGFUN_KERNEL_API_C |
|
|
214 #else // def CYGVAR_KERNEL_COUNTERS_CLOCK |
|
|
215 #define N_A_MSG "Kernel real-time clock disabled" |
|
|
216 #endif // def CYGVAR_KERNEL_COUNTERS_CLOCK |
|
|
217 |
|
|
218 #ifdef N_A_MSG |
|
|
219 externC void |
|
|
220 cyg_start( void ) |
|
|
221 { |
|
|
222 CYG_TEST_INIT(); |
|
2
|
223 CYG_TEST_NA( N_A_MSG ); |
|
0
|
224 } |
|
|
225 #endif // N_A_MSG |
|
|
226 |
|
|
227 // ------------------------------------------------------------------------- |
|
|
228 /* EOF kcache1.c */ |