|
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 |
|
|
25 // by Cygnus are Copyright (C) 1998 Cygnus Solutions. All Rights Reserved. |
|
|
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 |
|
|
38 #include <cyg/kernel/kapi.h> |
|
|
39 |
|
|
40 #include <cyg/infra/testcase.h> |
|
|
41 |
|
|
42 #ifdef CYGVAR_KERNEL_COUNTERS_CLOCK |
|
|
43 #ifdef CYGFUN_KERNEL_API_C |
|
|
44 |
|
|
45 #include <cyg/infra/diag.h> |
|
|
46 #include <cyg/hal/hal_cache.h> |
|
|
47 |
|
|
48 // ------------------------------------------------------------------------- |
|
|
49 // If the HAL does not supply this, we supply our own version |
|
|
50 |
|
|
51 #ifndef HAL_DCACHE_PURGE_ALL |
|
|
52 |
|
|
53 static cyg_uint8 dca[HAL_DCACHE_SIZE + HAL_DCACHE_LINE_SIZE*2]; |
|
|
54 |
|
|
55 #define HAL_DCACHE_PURGE_ALL() \ |
|
|
56 CYG_MACRO_START \ |
|
|
57 volatile cyg_uint8 *addr = &dca[HAL_DCACHE_LINE_SIZE]; \ |
|
|
58 volatile cyg_uint8 tmp = 0; \ |
|
|
59 int i; \ |
|
|
60 for( i = 0; i < HAL_DCACHE_SIZE; i += HAL_DCACHE_LINE_SIZE ) \ |
|
|
61 { \ |
|
|
62 tmp = addr[i]; \ |
|
|
63 } \ |
|
|
64 CYG_MACRO_END |
|
|
65 |
|
|
66 #endif |
|
|
67 |
|
|
68 // ------------------------------------------------------------------------- |
|
|
69 |
|
|
70 #define NTHREADS 1 |
|
|
71 #define STACKSIZE 4096 |
|
|
72 |
|
|
73 static cyg_handle_t thread[NTHREADS]; |
|
|
74 |
|
|
75 static cyg_thread thread_obj[NTHREADS]; |
|
|
76 static char stack[NTHREADS][STACKSIZE]; |
|
|
77 |
|
|
78 #define MAXSIZE 1<<18 |
|
|
79 |
|
|
80 volatile char m[MAXSIZE]; |
|
|
81 |
|
|
82 // ------------------------------------------------------------------------- |
|
|
83 |
|
|
84 static void time0(register cyg_uint32 stride) |
|
|
85 { |
|
|
86 register cyg_uint32 j,k; |
|
|
87 cyg_tick_count_t count0, count1; |
|
|
88 cyg_ucount32 t; |
|
|
89 register char c; |
|
|
90 |
|
|
91 count0 = cyg_current_time(); |
|
|
92 |
|
|
93 for(k=0; k<4000;k++) { |
|
|
94 for(j=0; j<(HAL_DCACHE_SIZE/HAL_DCACHE_LINE_SIZE); j++) { |
|
|
95 c=m[stride*j]; |
|
|
96 } |
|
|
97 } |
|
|
98 |
|
|
99 count1 = cyg_current_time(); |
|
|
100 t = count1 - count0; |
|
|
101 diag_printf("stride=%d, time=%d\n", stride, t); |
|
|
102 } |
|
|
103 |
|
|
104 // ------------------------------------------------------------------------- |
|
|
105 |
|
|
106 void time1(void) |
|
|
107 { |
|
|
108 cyg_uint32 i; |
|
|
109 |
|
|
110 for(i=1; i<65; i+=i) { |
|
|
111 time0(i); |
|
|
112 } |
|
|
113 } |
|
|
114 |
|
|
115 // ------------------------------------------------------------------------- |
|
|
116 // This test could be improved by counting number of passes possible |
|
|
117 // in a given number of ticks. |
|
|
118 |
|
|
119 static void entry0( cyg_addrword_t data ) |
|
|
120 { |
|
|
121 HAL_DCACHE_PURGE_ALL(); |
|
|
122 HAL_ICACHE_INVALIDATE_ALL(); |
|
|
123 HAL_DCACHE_INVALIDATE_ALL(); |
|
|
124 HAL_ICACHE_DISABLE(); |
|
|
125 HAL_DCACHE_DISABLE(); |
|
|
126 CYG_TEST_INFO("Dcache off Icache off"); |
|
|
127 time1(); |
|
|
128 |
|
|
129 HAL_DCACHE_PURGE_ALL(); |
|
|
130 HAL_ICACHE_INVALIDATE_ALL(); |
|
|
131 HAL_DCACHE_INVALIDATE_ALL(); |
|
|
132 HAL_ICACHE_DISABLE(); |
|
|
133 HAL_DCACHE_ENABLE(); |
|
|
134 CYG_TEST_INFO("Dcache on Icache off"); |
|
|
135 time1(); |
|
|
136 |
|
|
137 HAL_DCACHE_PURGE_ALL(); |
|
|
138 HAL_ICACHE_INVALIDATE_ALL(); |
|
|
139 HAL_DCACHE_INVALIDATE_ALL(); |
|
|
140 HAL_ICACHE_ENABLE(); |
|
|
141 HAL_DCACHE_DISABLE(); |
|
|
142 CYG_TEST_INFO("Dcache off Icache on"); |
|
|
143 time1(); |
|
|
144 |
|
|
145 HAL_DCACHE_PURGE_ALL(); |
|
|
146 HAL_ICACHE_INVALIDATE_ALL(); |
|
|
147 HAL_DCACHE_INVALIDATE_ALL(); |
|
|
148 HAL_ICACHE_ENABLE(); |
|
|
149 HAL_DCACHE_ENABLE(); |
|
|
150 CYG_TEST_INFO("Dcache on Icache on"); |
|
|
151 time1(); |
|
|
152 |
|
|
153 |
|
|
154 HAL_DCACHE_PURGE_ALL(); |
|
|
155 HAL_ICACHE_INVALIDATE_ALL(); |
|
|
156 HAL_DCACHE_INVALIDATE_ALL(); |
|
|
157 HAL_ICACHE_DISABLE(); |
|
|
158 HAL_DCACHE_DISABLE(); |
|
|
159 CYG_TEST_INFO("Dcache off Icache off"); |
|
|
160 time1(); |
|
|
161 |
|
|
162 |
|
|
163 CYG_TEST_PASS_FINISH("End of test"); |
|
|
164 } |
|
|
165 |
|
|
166 // ------------------------------------------------------------------------- |
|
|
167 |
|
|
168 void kcache2_main( void ) |
|
|
169 { |
|
|
170 CYG_TEST_INIT(); |
|
|
171 |
|
|
172 cyg_thread_create(4, entry0 , (cyg_addrword_t)0, "kcache1", |
|
|
173 (void *)stack[0], STACKSIZE, &thread[0], &thread_obj[0]); |
|
|
174 cyg_thread_resume(thread[0]); |
|
|
175 |
|
|
176 cyg_scheduler_start(); |
|
|
177 } |
|
|
178 |
|
|
179 // ------------------------------------------------------------------------- |
|
|
180 |
|
|
181 externC void |
|
|
182 cyg_start( void ) |
|
|
183 { |
|
|
184 kcache2_main(); |
|
|
185 } |
|
|
186 |
|
|
187 // ------------------------------------------------------------------------- |
|
|
188 |
|
|
189 #else // def CYGFUN_KERNEL_API_C |
|
|
190 #define N_A_MSG "Kernel C API layer disabled" |
|
|
191 #endif // def CYGFUN_KERNEL_API_C |
|
|
192 #else // def CYGVAR_KERNEL_COUNTERS_CLOCK |
|
|
193 #define N_A_MSG "Kernel real-time clock disabled" |
|
|
194 #endif // def CYGVAR_KERNEL_COUNTERS_CLOCK |
|
|
195 |
|
|
196 #ifdef N_A_MSG |
|
|
197 externC void |
|
|
198 cyg_start( void ) |
|
|
199 { |
|
|
200 CYG_TEST_INIT(); |
|
|
201 CYG_TEST_PASS_FINISH("N/A: " N_A_MSG); |
|
|
202 } |
|
|
203 #endif // N_A_MSG |
|
|
204 |
|
|
205 // ------------------------------------------------------------------------- |
|
|
206 /* EOF kcache1.c */ |