Mercurial > ecos-v3_0-branch
annotate packages/kernel/current/tests/kcache2.c @ 64:c38311975d4f ecos-sw-2000-01-28
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
| author | jlarmour |
|---|---|
| date | Fri, 28 Jan 2000 04:59:39 +0000 |
| parents | 306eee292492 |
| children | bf00f99aec69 |
| rev | line source |
|---|---|
| 2 | 1 /*================================================================= |
| 2 // | |
| 3 // kcache2.c | |
| 4 // | |
| 5 // Cache feature/timing tests | |
| 6 // | |
| 7 //========================================================================== | |
| 8 //####COPYRIGHTBEGIN#### | |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
24
diff
changeset
|
9 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
24
diff
changeset
|
10 // ------------------------------------------- |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
24
diff
changeset
|
11 // The contents of this file are subject to the Red Hat eCos Public License |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
24
diff
changeset
|
12 // Version 1.0 (the "License"); you may not use this file except in |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
24
diff
changeset
|
13 // compliance with the License. You may obtain a copy of the License at |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
24
diff
changeset
|
14 // http://sourceware.cygnus.com/ecos |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
24
diff
changeset
|
15 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
24
diff
changeset
|
16 // Software distributed under the License is distributed on an |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
24
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:
24
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:
24
diff
changeset
|
19 // the License. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
24
diff
changeset
|
20 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
24
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:
24
diff
changeset
|
22 // released September 30, 1998. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
24
diff
changeset
|
23 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
24
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:
24
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:
24
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:
24
diff
changeset
|
27 // All Rights Reserved. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
24
diff
changeset
|
28 // ------------------------------------------- |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
24
diff
changeset
|
29 // |
| 2 | 30 //####COPYRIGHTEND#### |
| 31 //========================================================================== | |
| 32 //#####DESCRIPTIONBEGIN#### | |
| 33 // | |
| 34 // Author(s): jskov, based on kcache1.c by dsm | |
| 35 // Contributors: jskov | |
| 36 // Date: 1998-12-10 | |
| 37 // Description: Tests some of the more exotic cache macros. | |
| 38 //####DESCRIPTIONEND#### | |
| 39 */ | |
| 40 | |
| 41 #include <cyg/hal/hal_arch.h> // CYGNUM_HAL_STACK_SIZE_TYPICAL | |
| 42 | |
| 43 #include <cyg/kernel/kapi.h> | |
| 44 | |
| 45 #include <cyg/infra/testcase.h> | |
| 46 | |
| 47 #ifdef CYGVAR_KERNEL_COUNTERS_CLOCK | |
| 48 #ifdef CYGFUN_KERNEL_API_C | |
| 49 | |
| 50 #include <cyg/infra/diag.h> | |
| 51 #include <cyg/hal/hal_cache.h> | |
| 52 | |
| 53 // ------------------------------------------------------------------------- | |
| 54 | |
| 55 #define NTHREADS 1 | |
| 56 #define STACKSIZE CYGNUM_HAL_STACK_SIZE_TYPICAL | |
| 57 | |
| 58 // The following are defaults for loop variables. Note they will be overriden | |
| 59 // on simulator targets, where detected - there is no point testing a cache | |
| 60 // which doesn't exist :-). | |
| 61 | |
| 62 #define TEST_DZERO_LOOPS 5000 // default number of loops for test_dzero() | |
| 63 #define TIME_ILOCK_LOOPS 10000 // default number of loops for time_ilock() | |
| 64 #define TIME_DLOCK_LOOPS 10000 // default number of loops for time_dlock() | |
| 65 | |
| 66 | |
| 67 static cyg_handle_t thread[NTHREADS]; | |
| 68 | |
| 69 static cyg_thread thread_obj[NTHREADS]; | |
| 70 static char stack[NTHREADS][STACKSIZE]; | |
| 71 | |
| 72 #define MAXSIZE 1<<18 | |
| 73 | |
| 74 volatile char m[MAXSIZE]; | |
| 75 | |
| 76 // ------------------------------------------------------------------------- | |
| 77 // Test of data cache zero. | |
| 78 // o Timing comparison with instructions doing the same amount of work. | |
| 79 // o Check that area cleared with the DCACHE_ZERO macro contains zeros. | |
| 80 #ifdef HAL_DCACHE_ZERO | |
| 81 static void test_dzero(void) | |
| 82 { | |
| 83 register cyg_uint32 k, i; | |
| 84 cyg_tick_count_t count0, count1; | |
| 85 cyg_ucount32 t; | |
| 86 volatile cyg_uint32* aligned_p; | |
| 87 volatile cyg_uint32* p; | |
| 88 register CYG_INTERRUPT_STATE oldints; | |
| 89 cyg_ucount32 test_dzero_loops = TEST_DZERO_LOOPS; | |
| 90 | |
| 91 CYG_TEST_INFO("Data cache zero"); | |
| 92 | |
| 93 if (cyg_test_is_simulator) | |
| 94 test_dzero_loops=10; | |
| 95 | |
| 96 aligned_p = (volatile cyg_uint32*) | |
| 97 (((unsigned long) &m[HAL_DCACHE_LINE_SIZE*2]) | |
| 98 & ~(HAL_DCACHE_LINE_SIZE-1)); | |
| 99 | |
| 100 // Time with conventional instructions. | |
| 101 HAL_DISABLE_INTERRUPTS(oldints); | |
| 102 HAL_DCACHE_SYNC(); | |
| 103 HAL_DCACHE_DISABLE(); | |
| 104 HAL_DCACHE_SYNC(); | |
| 105 HAL_DCACHE_INVALIDATE_ALL(); | |
| 106 HAL_DCACHE_ENABLE(); | |
| 107 HAL_RESTORE_INTERRUPTS(oldints); | |
| 108 count0 = cyg_current_time(); | |
| 109 for (k = 0; k < test_dzero_loops; k++) { | |
| 110 p = aligned_p; | |
| 111 for (i = 0; i < HAL_DCACHE_SETS; i++) { | |
| 112 #if (16 == HAL_DCACHE_LINE_SIZE) | |
| 113 *p++ = 0; | |
| 114 *p++ = 0; | |
| 115 *p++ = 0; | |
| 116 *p++ = 0; | |
| 117 #else | |
| 118 #error "Not defined for this cache line size." | |
| 119 #endif | |
| 120 } | |
| 121 | |
| 122 HAL_DISABLE_INTERRUPTS(oldints); | |
| 123 HAL_DCACHE_SYNC(); | |
| 124 HAL_DCACHE_DISABLE(); | |
| 125 HAL_DCACHE_SYNC(); | |
| 126 HAL_DCACHE_INVALIDATE_ALL(); | |
| 127 HAL_DCACHE_ENABLE(); | |
| 128 HAL_RESTORE_INTERRUPTS(oldints); | |
| 129 } | |
| 130 count1 = cyg_current_time(); | |
| 131 t = count1 - count0; | |
| 132 diag_printf("time with instructions: %d\n", t); | |
| 133 | |
| 134 // Initialize the area with non-zero so we can check whether | |
| 135 // the macro cleared the area properly. | |
| 136 p = aligned_p; | |
| 137 for (i = 0; | |
| 138 i < HAL_DCACHE_SETS*HAL_DCACHE_LINE_SIZE/sizeof(cyg_uint32); | |
| 139 i++) { | |
| 140 *p++ = 0xdeadbeef; | |
| 141 } | |
| 142 | |
| 143 // Time with DCACHE_ZERO. | |
| 144 HAL_DISABLE_INTERRUPTS(oldints); | |
| 145 HAL_DCACHE_SYNC(); | |
| 146 HAL_DCACHE_DISABLE(); | |
| 147 HAL_DCACHE_SYNC(); | |
| 148 HAL_DCACHE_INVALIDATE_ALL(); | |
| 149 HAL_DCACHE_ENABLE(); | |
| 150 HAL_RESTORE_INTERRUPTS(oldints); | |
| 151 count0 = cyg_current_time(); | |
| 152 for (k = 0; k < test_dzero_loops; k++) { | |
| 153 HAL_DCACHE_ZERO(aligned_p, HAL_DCACHE_SETS*HAL_DCACHE_LINE_SIZE); | |
| 154 | |
| 155 HAL_DISABLE_INTERRUPTS(oldints); | |
| 156 HAL_DCACHE_SYNC(); | |
| 157 HAL_DCACHE_DISABLE(); | |
| 158 HAL_DCACHE_SYNC(); | |
| 159 HAL_DCACHE_INVALIDATE_ALL(); | |
| 160 HAL_DCACHE_ENABLE(); | |
| 161 HAL_RESTORE_INTERRUPTS(oldints); | |
| 162 } | |
| 163 count1 = cyg_current_time(); | |
| 164 t = count1 - count0; | |
| 165 diag_printf("time with HAL_DCACHE_ZERO: %d\n", t); | |
| 166 | |
| 167 // Verify that the area was actually cleared. | |
| 168 { | |
| 169 cyg_uint32 d; | |
| 170 | |
| 171 d = 0; | |
| 172 p = aligned_p; | |
| 173 for (i = 0; | |
| 174 i < HAL_DCACHE_SETS*HAL_DCACHE_LINE_SIZE/sizeof(cyg_uint32); | |
| 175 i++) { | |
| 176 d |= *p++; | |
| 177 } | |
| 178 | |
| 179 CYG_TEST_CHECK(0 == d, "region not properly cleared"); | |
| 180 } | |
| 181 | |
| 182 } | |
| 183 #endif | |
| 184 | |
| 185 // ------------------------------------------------------------------------- | |
| 186 // Test of data cache write hint. | |
| 187 // Just check that the macro compiles. | |
| 188 #ifdef HAL_DCACHE_WRITE_HINT | |
| 189 static void test_dwrite_hint(void) | |
| 190 { | |
| 191 register cyg_uint32 k; | |
| 192 register CYG_INTERRUPT_STATE oldints; | |
| 193 | |
| 194 CYG_TEST_INFO("Data cache write hint"); | |
| 195 | |
| 196 HAL_DISABLE_INTERRUPTS(oldints); | |
| 197 HAL_DCACHE_SYNC(); | |
| 198 HAL_DCACHE_DISABLE(); | |
| 199 HAL_DCACHE_SYNC(); | |
| 200 HAL_DCACHE_INVALIDATE_ALL(); | |
| 201 HAL_DCACHE_ENABLE(); | |
| 202 HAL_RESTORE_INTERRUPTS(oldints); | |
| 203 | |
| 204 HAL_DCACHE_WRITE_HINT(&m[HAL_DCACHE_LINE_SIZE*2], 2*HAL_DCACHE_LINE_SIZE); | |
| 205 for (k = 0; k < 20; k++); | |
| 206 m[HAL_DCACHE_LINE_SIZE*2] = 42; | |
| 207 } | |
| 208 #endif | |
| 209 | |
| 210 // ------------------------------------------------------------------------- | |
| 211 // Test of data cache read hint. | |
| 212 // Just check that the macro compiles. | |
| 213 #ifdef HAL_DCACHE_READ_HINT | |
| 214 static void test_dread_hint(void) | |
| 215 { | |
| 216 register char c; | |
| 217 register cyg_uint32 k; | |
| 218 register CYG_INTERRUPT_STATE oldints; | |
| 219 | |
| 220 CYG_TEST_INFO("Data cache read hint"); | |
| 221 | |
| 222 HAL_DISABLE_INTERRUPTS(oldints); | |
| 223 HAL_DCACHE_SYNC(); | |
| 224 HAL_DCACHE_DISABLE(); | |
| 225 HAL_DCACHE_SYNC(); | |
| 226 HAL_DCACHE_INVALIDATE_ALL(); | |
| 227 HAL_DCACHE_ENABLE(); | |
| 228 HAL_RESTORE_INTERRUPTS(oldints); | |
| 229 | |
| 230 HAL_DCACHE_READ_HINT(&m[HAL_DCACHE_LINE_SIZE*2], 2*HAL_DCACHE_LINE_SIZE); | |
| 231 for (k = 0; k < 20; k++); | |
| 232 c = m[HAL_DCACHE_LINE_SIZE*2]; | |
| 233 } | |
| 234 #endif | |
| 235 | |
| 236 // ------------------------------------------------------------------------- | |
| 237 // Test of data cache line store. | |
| 238 // Just check that the macro compiles. | |
| 239 #ifdef HAL_DCACHE_STORE | |
| 240 static void test_dstore(void) | |
| 241 { | |
| 242 volatile cyg_uint8* aligned_p; | |
| 243 cyg_int32 i; | |
| 244 register CYG_INTERRUPT_STATE oldints; | |
| 245 | |
| 246 CYG_TEST_INFO("Data cache store region"); | |
| 247 | |
| 248 for (i = 0; i < HAL_DCACHE_LINE_SIZE*16; i++) | |
| 249 m[i] = 0; | |
| 250 | |
| 251 HAL_DISABLE_INTERRUPTS(oldints); | |
| 252 HAL_DCACHE_SYNC(); | |
| 253 HAL_DCACHE_DISABLE(); | |
| 254 HAL_DCACHE_SYNC(); | |
| 255 HAL_DCACHE_INVALIDATE_ALL(); | |
| 256 HAL_DCACHE_ENABLE(); | |
| 257 HAL_RESTORE_INTERRUPTS(oldints); | |
| 258 | |
| 259 aligned_p = (volatile cyg_uint8*) | |
| 260 (((unsigned long) &m[HAL_DCACHE_LINE_SIZE*2]) | |
| 261 & ~(HAL_DCACHE_LINE_SIZE-1)); | |
| 262 | |
| 263 aligned_p[0] = 42; | |
| 264 | |
| 265 HAL_DCACHE_STORE(aligned_p, HAL_DCACHE_LINE_SIZE); | |
| 266 } | |
| 267 #endif | |
| 268 | |
| 269 // ------------------------------------------------------------------------- | |
| 270 // Test of data cache line flush. | |
| 271 // o Requires write-back cache. | |
| 272 // o Check that flushed data is written to memory. | |
| 273 // o Simple range check of macro. | |
| 274 #ifdef HAL_DCACHE_FLUSH | |
| 275 static void test_dflush(void) | |
| 276 { | |
| 277 volatile cyg_uint8* aligned_p; | |
| 278 cyg_int32 i; | |
| 279 register CYG_INTERRUPT_STATE oldints; | |
| 280 | |
| 281 CYG_TEST_INFO("Data cache flush region"); | |
| 282 | |
| 283 for (i = 0; i < HAL_DCACHE_LINE_SIZE*16; i++) | |
| 284 m[i] = 0; | |
| 285 | |
| 286 HAL_DISABLE_INTERRUPTS(oldints); | |
| 287 HAL_DCACHE_SYNC(); | |
| 288 HAL_DCACHE_DISABLE(); | |
| 289 HAL_DCACHE_SYNC(); | |
| 290 HAL_DCACHE_INVALIDATE_ALL(); | |
| 291 HAL_DCACHE_ENABLE(); | |
| 292 HAL_RESTORE_INTERRUPTS(oldints); | |
| 293 | |
| 294 aligned_p = (volatile cyg_uint8*) | |
| 295 (((unsigned long) &m[HAL_DCACHE_LINE_SIZE*2]) | |
| 296 & ~(HAL_DCACHE_LINE_SIZE-1)); | |
| 297 | |
| 298 aligned_p[0] = 42; | |
| 299 aligned_p[HAL_DCACHE_LINE_SIZE] = 43; | |
| 300 | |
| 301 HAL_DCACHE_FLUSH(aligned_p, HAL_DCACHE_LINE_SIZE); | |
| 302 | |
| 303 HAL_DCACHE_DISABLE(); | |
| 304 | |
| 305 CYG_TEST_CHECK(42 == aligned_p[0], | |
| 306 "memory didn't contain flushed data"); | |
| 307 CYG_TEST_CHECK(0 == aligned_p[HAL_DCACHE_LINE_SIZE], | |
| 308 "flushed beyond region"); | |
| 309 | |
| 310 HAL_DCACHE_ENABLE(); | |
| 311 | |
| 312 } | |
| 313 #endif | |
| 314 | |
| 315 // ------------------------------------------------------------------------- | |
| 316 // Test of data cache line invalidate. | |
| 317 // o Requires write-back cache. | |
| 318 // o Check that invalidated data is not written to memory and is invalidated | |
| 319 // in the cache. | |
| 320 // o Simple range check of macro. | |
| 321 #ifdef HAL_DCACHE_INVALIDATE | |
| 322 static void test_dinvalidate(void) | |
| 323 { | |
| 324 volatile cyg_uint8* aligned_p; | |
| 325 cyg_int32 i; | |
| 326 register CYG_INTERRUPT_STATE oldints; | |
| 327 | |
| 328 CYG_TEST_INFO("Data cache invalidate region"); | |
| 329 | |
| 330 for (i = 0; i < HAL_DCACHE_LINE_SIZE*16; i++) | |
| 331 m[i] = 0; | |
| 332 | |
| 333 HAL_DISABLE_INTERRUPTS(oldints); | |
| 334 HAL_DCACHE_SYNC(); | |
| 335 HAL_DCACHE_DISABLE(); | |
| 336 HAL_DCACHE_SYNC(); | |
| 337 HAL_DCACHE_INVALIDATE_ALL(); | |
| 338 HAL_DCACHE_ENABLE(); | |
| 339 HAL_RESTORE_INTERRUPTS(oldints); | |
| 340 | |
| 341 aligned_p = (volatile cyg_uint8*) | |
| 342 (((unsigned long) &m[HAL_DCACHE_LINE_SIZE*2]) | |
| 343 & ~(HAL_DCACHE_LINE_SIZE-1)); | |
| 344 | |
| 345 aligned_p[0] = 43; | |
| 346 aligned_p[HAL_DCACHE_LINE_SIZE-1] = 43; | |
| 347 | |
| 348 aligned_p[HAL_DCACHE_LINE_SIZE] = 42; | |
| 349 | |
| 350 HAL_DCACHE_INVALIDATE(aligned_p, HAL_DCACHE_LINE_SIZE); | |
| 351 | |
| 352 CYG_TEST_CHECK(0 == aligned_p[0] && | |
| 353 0 == aligned_p[HAL_DCACHE_LINE_SIZE-1], | |
| 354 "cache/memory contained invalidated data"); | |
| 355 CYG_TEST_CHECK(42 == aligned_p[HAL_DCACHE_LINE_SIZE], | |
| 356 "invalidated beyond range"); | |
| 357 } | |
| 358 #endif | |
| 359 | |
| 360 // ------------------------------------------------------------------------- | |
| 361 // Test of instruction cache locking. | |
| 362 // o Time difference between repeatedly executing a bunch of instructions | |
| 363 // with and without locking. | |
| 364 #ifdef HAL_ICACHE_LOCK | |
| 365 static void iloop(unsigned long* start, unsigned long* end) | |
| 366 { | |
| 367 register char c; | |
| 368 register CYG_INTERRUPT_STATE oldints; | |
| 369 | |
| 370 label_start: | |
| 371 // Invalidating shouldn't affect locked lines. | |
| 372 HAL_DISABLE_INTERRUPTS(oldints); | |
| 373 HAL_ICACHE_DISABLE(); | |
| 374 HAL_ICACHE_INVALIDATE_ALL(); | |
| 375 HAL_ICACHE_ENABLE(); | |
| 376 HAL_RESTORE_INTERRUPTS(oldints); | |
| 377 | |
| 378 c = m[HAL_DCACHE_LINE_SIZE*0]; | |
| 379 c = m[HAL_DCACHE_LINE_SIZE*1]; | |
| 380 c = m[HAL_DCACHE_LINE_SIZE*2]; | |
| 381 c = m[HAL_DCACHE_LINE_SIZE*3]; | |
| 382 c = m[HAL_DCACHE_LINE_SIZE*4]; | |
| 383 c = m[HAL_DCACHE_LINE_SIZE*5]; | |
| 384 c = m[HAL_DCACHE_LINE_SIZE*6]; | |
| 385 c = m[HAL_DCACHE_LINE_SIZE*7]; | |
| 386 c = m[HAL_DCACHE_LINE_SIZE*8]; | |
| 387 c = m[HAL_DCACHE_LINE_SIZE*9]; | |
| 388 c = m[HAL_DCACHE_LINE_SIZE*10]; | |
| 389 c = m[HAL_DCACHE_LINE_SIZE*11]; | |
| 390 c = m[HAL_DCACHE_LINE_SIZE*12]; | |
| 391 c = m[HAL_DCACHE_LINE_SIZE*13]; | |
| 392 c = m[HAL_DCACHE_LINE_SIZE*14]; | |
| 393 c = m[HAL_DCACHE_LINE_SIZE*15]; | |
| 394 c = m[HAL_DCACHE_LINE_SIZE*16]; | |
| 395 c = m[HAL_DCACHE_LINE_SIZE*17]; | |
| 396 c = m[HAL_DCACHE_LINE_SIZE*18]; | |
| 397 c = m[HAL_DCACHE_LINE_SIZE*19]; | |
| 398 c = m[HAL_DCACHE_LINE_SIZE*20]; | |
| 399 c = m[HAL_DCACHE_LINE_SIZE*21]; | |
| 400 c = m[HAL_DCACHE_LINE_SIZE*22]; | |
| 401 c = m[HAL_DCACHE_LINE_SIZE*23]; | |
| 402 c = m[HAL_DCACHE_LINE_SIZE*24]; | |
| 403 c = m[HAL_DCACHE_LINE_SIZE*25]; | |
| 404 c = m[HAL_DCACHE_LINE_SIZE*26]; | |
| 405 c = m[HAL_DCACHE_LINE_SIZE*27]; | |
| 406 c = m[HAL_DCACHE_LINE_SIZE*28]; | |
| 407 c = m[HAL_DCACHE_LINE_SIZE*29]; | |
| 408 c = m[HAL_DCACHE_LINE_SIZE*30]; | |
| 409 c = m[HAL_DCACHE_LINE_SIZE*31]; | |
| 410 c = m[HAL_DCACHE_LINE_SIZE*32]; | |
| 411 c = m[HAL_DCACHE_LINE_SIZE*33]; | |
| 412 c = m[HAL_DCACHE_LINE_SIZE*34]; | |
| 413 c = m[HAL_DCACHE_LINE_SIZE*35]; | |
| 414 c = m[HAL_DCACHE_LINE_SIZE*36]; | |
| 415 c = m[HAL_DCACHE_LINE_SIZE*37]; | |
| 416 c = m[HAL_DCACHE_LINE_SIZE*38]; | |
| 417 c = m[HAL_DCACHE_LINE_SIZE*39]; | |
| 418 c = m[HAL_DCACHE_LINE_SIZE*40]; | |
| 419 c = m[HAL_DCACHE_LINE_SIZE*41]; | |
| 420 c = m[HAL_DCACHE_LINE_SIZE*42]; | |
| 421 c = m[HAL_DCACHE_LINE_SIZE*43]; | |
| 422 c = m[HAL_DCACHE_LINE_SIZE*44]; | |
| 423 c = m[HAL_DCACHE_LINE_SIZE*45]; | |
| 424 c = m[HAL_DCACHE_LINE_SIZE*46]; | |
| 425 c = m[HAL_DCACHE_LINE_SIZE*47]; | |
| 426 c = m[HAL_DCACHE_LINE_SIZE*48]; | |
| 427 c = m[HAL_DCACHE_LINE_SIZE*49]; | |
| 428 c = m[HAL_DCACHE_LINE_SIZE*50]; | |
| 429 c = m[HAL_DCACHE_LINE_SIZE*51]; | |
| 430 c = m[HAL_DCACHE_LINE_SIZE*52]; | |
| 431 c = m[HAL_DCACHE_LINE_SIZE*53]; | |
| 432 c = m[HAL_DCACHE_LINE_SIZE*54]; | |
| 433 c = m[HAL_DCACHE_LINE_SIZE*55]; | |
| 434 c = m[HAL_DCACHE_LINE_SIZE*56]; | |
| 435 c = m[HAL_DCACHE_LINE_SIZE*57]; | |
| 436 c = m[HAL_DCACHE_LINE_SIZE*58]; | |
| 437 c = m[HAL_DCACHE_LINE_SIZE*59]; | |
| 438 c = m[HAL_DCACHE_LINE_SIZE*60]; | |
| 439 c = m[HAL_DCACHE_LINE_SIZE*61]; | |
| 440 c = m[HAL_DCACHE_LINE_SIZE*62]; | |
| 441 c = m[HAL_DCACHE_LINE_SIZE*63]; | |
| 442 | |
| 443 label_end: | |
| 444 | |
| 445 *start = (unsigned long) &&label_start; | |
| 446 *end = (unsigned long) &&label_end; | |
| 447 } | |
| 448 | |
| 449 static void time_ilock(void) | |
| 450 { | |
| 451 register cyg_ucount32 k; | |
| 452 cyg_tick_count_t count0, count1; | |
| 453 cyg_ucount32 t; | |
| 454 unsigned long start, end; | |
| 455 register cyg_ucount32 time_ilock_loops = TIME_ILOCK_LOOPS; | |
| 456 | |
| 457 CYG_TEST_INFO("Instruction cache lock"); | |
| 458 | |
| 459 if (cyg_test_is_simulator) | |
| 460 time_ilock_loops = 10; | |
| 461 | |
| 462 count0 = cyg_current_time(); | |
| 463 for (k = 0; k < time_ilock_loops; k++) { | |
| 464 iloop(&start, &end); | |
| 465 } | |
| 466 count1 = cyg_current_time(); | |
| 467 t = count1 - count0; | |
| 468 diag_printf("time without lock: %d\n", t); | |
| 469 | |
| 470 HAL_ICACHE_LOCK(start, end-start); | |
| 471 | |
| 472 count0 = cyg_current_time(); | |
| 473 for (k = 0; k < time_ilock_loops; k++) { | |
| 474 iloop(&start, &end); | |
| 475 } | |
| 476 count1 = cyg_current_time(); | |
| 477 t = count1 - count0; | |
| 478 diag_printf("time with lock: %d\n", t); | |
| 479 | |
| 480 HAL_ICACHE_UNLOCK(start, end-start); | |
| 481 } | |
| 482 #endif // ifdef HAL_ICACHE_LOCK | |
| 483 | |
| 484 // ------------------------------------------------------------------------- | |
| 485 // Test of data cache locking. | |
| 486 // o Time difference between repeatedly accessing a memory region | |
| 487 // with and without locking. | |
| 488 #ifdef HAL_DCACHE_LOCK | |
| 489 static void dloop(void) | |
| 490 { | |
| 491 register cyg_uint32 j; | |
| 492 register char c; | |
| 493 register CYG_INTERRUPT_STATE oldints; | |
| 494 | |
| 495 HAL_DISABLE_INTERRUPTS(oldints); | |
| 496 HAL_DCACHE_SYNC(); | |
| 497 HAL_DCACHE_DISABLE(); | |
| 498 HAL_DCACHE_SYNC(); | |
| 499 HAL_DCACHE_INVALIDATE_ALL(); | |
| 500 HAL_DCACHE_ENABLE(); | |
| 501 HAL_RESTORE_INTERRUPTS(oldints); | |
| 502 for (j = 0; j < HAL_DCACHE_SETS; j++) { | |
| 503 c = m[HAL_DCACHE_LINE_SIZE*j]; | |
| 504 } | |
| 505 } | |
| 506 | |
| 507 static void time_dlock(void) | |
| 508 { | |
| 509 register cyg_ucount32 k; | |
| 510 cyg_tick_count_t count0, count1; | |
| 511 cyg_ucount32 t; | |
| 512 register cyg_ucount32 time_dlock_loops = TIME_DLOCK_LOOPS; | |
| 513 | |
| 514 CYG_TEST_INFO("Data cache lock"); | |
| 515 | |
| 516 if (cyg_test_is_simulator) | |
| 517 time_dlock_loops = 10; | |
| 518 | |
| 519 count0 = cyg_current_time(); | |
| 520 for (k = 0; k < time_dlock_loops; k++) { | |
| 521 dloop(); | |
| 522 } | |
| 523 count1 = cyg_current_time(); | |
| 524 t = count1 - count0; | |
| 525 diag_printf("time without lock: %d\n", t); | |
| 526 | |
| 527 HAL_DCACHE_LOCK(&m[0], HAL_DCACHE_SETS*HAL_DCACHE_LINE_SIZE); | |
| 528 | |
| 529 count0 = cyg_current_time(); | |
| 530 for (k = 0; k < time_dlock_loops; k++) { | |
| 531 dloop(); | |
| 532 } | |
| 533 count1 = cyg_current_time(); | |
| 534 t = count1 - count0; | |
| 535 diag_printf("time with lock: %d\n", t); | |
| 536 | |
| 537 HAL_DCACHE_UNLOCK(&m[0], HAL_DCACHE_SETS*HAL_DCACHE_LINE_SIZE); | |
| 538 } | |
| 539 #endif // ifdef HAL_DCACHE_LOCK | |
| 540 | |
| 541 // ------------------------------------------------------------------------- | |
| 542 static void entry0( cyg_addrword_t data ) | |
| 543 { | |
|
24
306eee292492
Merge from eCos master repository on 1999-07-16-05:47:06-BST
jlarmour
parents:
2
diff
changeset
|
544 #ifdef HAL_DCACHE_QUERY_WRITE_MODE |
|
306eee292492
Merge from eCos master repository on 1999-07-16-05:47:06-BST
jlarmour
parents:
2
diff
changeset
|
545 int wmode; |
|
306eee292492
Merge from eCos master repository on 1999-07-16-05:47:06-BST
jlarmour
parents:
2
diff
changeset
|
546 #endif |
| 2 | 547 #ifdef HAL_DCACHE_LOCK |
| 548 time_dlock(); | |
| 549 #endif | |
| 550 #ifdef HAL_ICACHE_LOCK | |
| 551 time_ilock(); | |
| 552 #endif | |
| 553 #ifdef HAL_DCACHE_STORE | |
| 554 test_dstore(); | |
| 555 #endif | |
| 556 #ifdef HAL_DCACHE_READ_HINT | |
| 557 test_dread_hint(); | |
| 558 #endif | |
| 559 #ifdef HAL_DCACHE_WRITE_HINT | |
| 560 test_dwrite_hint(); | |
| 561 #endif | |
| 562 #ifdef HAL_DCACHE_ZERO | |
| 563 test_dzero(); | |
| 564 #endif | |
| 565 | |
| 566 // The below tests only work on a copy-back cache. | |
|
24
306eee292492
Merge from eCos master repository on 1999-07-16-05:47:06-BST
jlarmour
parents:
2
diff
changeset
|
567 #ifdef HAL_DCACHE_QUERY_WRITE_MODE |
|
306eee292492
Merge from eCos master repository on 1999-07-16-05:47:06-BST
jlarmour
parents:
2
diff
changeset
|
568 HAL_DCACHE_QUERY_WRITE_MODE( wmode ); |
|
306eee292492
Merge from eCos master repository on 1999-07-16-05:47:06-BST
jlarmour
parents:
2
diff
changeset
|
569 |
|
306eee292492
Merge from eCos master repository on 1999-07-16-05:47:06-BST
jlarmour
parents:
2
diff
changeset
|
570 if ( HAL_DCACHE_WRITEBACK_MODE == wmode ) { |
| 2 | 571 #ifdef HAL_DCACHE_FLUSH |
| 572 test_dflush(); | |
| 573 #endif | |
| 574 #ifdef HAL_DCACHE_INVALIDATE | |
| 575 test_dinvalidate(); | |
| 576 #endif | |
| 577 } | |
|
24
306eee292492
Merge from eCos master repository on 1999-07-16-05:47:06-BST
jlarmour
parents:
2
diff
changeset
|
578 #endif // def HAL_DCACHE_QUERY_WRITE_MODE |
| 2 | 579 |
| 580 CYG_TEST_PASS_FINISH("End of test"); | |
| 581 } | |
| 582 | |
| 583 // ------------------------------------------------------------------------- | |
| 584 | |
| 585 void kcache2_main( void ) | |
| 586 { | |
| 587 CYG_TEST_INIT(); | |
| 588 | |
| 589 cyg_thread_create(4, entry0 , (cyg_addrword_t)0, "kcache2", | |
| 590 (void *)stack[0], STACKSIZE, &thread[0], &thread_obj[0]); | |
| 591 cyg_thread_resume(thread[0]); | |
| 592 | |
| 593 cyg_scheduler_start(); | |
| 594 } | |
| 595 | |
| 596 // ------------------------------------------------------------------------- | |
| 597 | |
| 598 externC void | |
| 599 cyg_start( void ) | |
| 600 { | |
| 601 kcache2_main(); | |
| 602 } | |
| 603 | |
| 604 // ------------------------------------------------------------------------- | |
| 605 | |
| 606 #else // def CYGFUN_KERNEL_API_C | |
| 607 #define N_A_MSG "Kernel C API layer disabled" | |
| 608 #endif // def CYGFUN_KERNEL_API_C | |
| 609 #else // def CYGVAR_KERNEL_COUNTERS_CLOCK | |
| 610 #define N_A_MSG "Kernel real-time clock disabled" | |
| 611 #endif // def CYGVAR_KERNEL_COUNTERS_CLOCK | |
| 612 | |
| 613 #ifdef N_A_MSG | |
| 614 externC void | |
| 615 cyg_start( void ) | |
| 616 { | |
| 617 CYG_TEST_INIT(); | |
| 618 CYG_TEST_NA( N_A_MSG ); | |
| 619 } | |
| 620 #endif // N_A_MSG | |
| 621 | |
| 622 // ------------------------------------------------------------------------- | |
| 623 /* EOF kcache2.c */ |
