Mercurial > nand-ecoscentric
comparison packages/kernel/current/tests/kcache2.c @ 477:658c231c7e71
Fix kcache2 test for 32 byte cache line size. Add low level cache testing.
| author | gthomas |
|---|---|
| date | Sat, 04 Jan 2003 03:23:15 +0000 |
| parents | d2c90368aeef |
| children | a2a11bab520d |
comparison
equal
deleted
inserted
replaced
| 476:27c8b9bbe227 | 477:658c231c7e71 |
|---|---|
| 7 //========================================================================== | 7 //========================================================================== |
| 8 //####ECOSGPLCOPYRIGHTBEGIN#### | 8 //####ECOSGPLCOPYRIGHTBEGIN#### |
| 9 // ------------------------------------------- | 9 // ------------------------------------------- |
| 10 // This file is part of eCos, the Embedded Configurable Operating System. | 10 // This file is part of eCos, the Embedded Configurable Operating System. |
| 11 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. | 11 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. |
| 12 // Copyright (C) 2003 Gary Thomas | |
| 12 // | 13 // |
| 13 // eCos is free software; you can redistribute it and/or modify it under | 14 // eCos is free software; you can redistribute it and/or modify it under |
| 14 // the terms of the GNU General Public License as published by the Free | 15 // the terms of the GNU General Public License as published by the Free |
| 15 // Software Foundation; either version 2 or (at your option) any later version. | 16 // Software Foundation; either version 2 or (at your option) any later version. |
| 16 // | 17 // |
| 39 //####ECOSGPLCOPYRIGHTEND#### | 40 //####ECOSGPLCOPYRIGHTEND#### |
| 40 //========================================================================== | 41 //========================================================================== |
| 41 //#####DESCRIPTIONBEGIN#### | 42 //#####DESCRIPTIONBEGIN#### |
| 42 // | 43 // |
| 43 // Author(s): jskov, based on kcache1.c by dsm | 44 // Author(s): jskov, based on kcache1.c by dsm |
| 44 // Contributors: jskov | 45 // Contributors: jskov, gthomas |
| 45 // Date: 1998-12-10 | 46 // Date: 1998-12-10 |
| 46 // Description: Tests some of the more exotic cache macros. | 47 // Description: Tests some of the more exotic cache macros. |
| 47 //####DESCRIPTIONEND#### | 48 //####DESCRIPTIONEND#### |
| 48 */ | 49 */ |
| 49 | 50 |
| 70 | 71 |
| 71 #define TEST_DZERO_LOOPS 5000 // default number of loops for test_dzero() | 72 #define TEST_DZERO_LOOPS 5000 // default number of loops for test_dzero() |
| 72 #define TIME_ILOCK_LOOPS 10000 // default number of loops for time_ilock() | 73 #define TIME_ILOCK_LOOPS 10000 // default number of loops for time_ilock() |
| 73 #define TIME_DLOCK_LOOPS 10000 // default number of loops for time_dlock() | 74 #define TIME_DLOCK_LOOPS 10000 // default number of loops for time_dlock() |
| 74 | 75 |
| 76 // Define this to enable a simple, but hopefully useful, data cache | |
| 77 // test. It may help discover if the cache support has been defined | |
| 78 // properly (in terms of size and shape) | |
| 79 #ifdef HAL_DCACHE_SIZE | |
| 80 //#define _TEST_DCACHE_OPERATION | |
| 81 #endif | |
| 75 | 82 |
| 76 static cyg_handle_t thread[NTHREADS]; | 83 static cyg_handle_t thread[NTHREADS]; |
| 77 | 84 |
| 78 static cyg_thread thread_obj[NTHREADS]; | 85 static cyg_thread thread_obj[NTHREADS]; |
| 79 static char stack[NTHREADS][STACKSIZE]; | 86 static char stack[NTHREADS][STACKSIZE]; |
| 117 count0 = cyg_current_time(); | 124 count0 = cyg_current_time(); |
| 118 for (k = 0; k < test_dzero_loops; k++) { | 125 for (k = 0; k < test_dzero_loops; k++) { |
| 119 p = aligned_p; | 126 p = aligned_p; |
| 120 for (i = 0; i < HAL_DCACHE_SETS; i++) { | 127 for (i = 0; i < HAL_DCACHE_SETS; i++) { |
| 121 #if (16 == HAL_DCACHE_LINE_SIZE) | 128 #if (16 == HAL_DCACHE_LINE_SIZE) |
| 129 *p++ = 0; | |
| 130 *p++ = 0; | |
| 131 *p++ = 0; | |
| 132 *p++ = 0; | |
| 133 #elif (32 == HAL_DCACHE_LINE_SIZE) | |
| 134 *p++ = 0; | |
| 135 *p++ = 0; | |
| 136 *p++ = 0; | |
| 137 *p++ = 0; | |
| 122 *p++ = 0; | 138 *p++ = 0; |
| 123 *p++ = 0; | 139 *p++ = 0; |
| 124 *p++ = 0; | 140 *p++ = 0; |
| 125 *p++ = 0; | 141 *p++ = 0; |
| 126 #else | 142 #else |
| 290 // Test of data cache total flush (sync). | 306 // Test of data cache total flush (sync). |
| 291 // o No semantic requirement. | 307 // o No semantic requirement. |
| 292 // o Check that flushed data is written to memory. | 308 // o Check that flushed data is written to memory. |
| 293 // o Simple invocation check of macro. | 309 // o Simple invocation check of macro. |
| 294 #ifdef HAL_DCACHE_LINE_SIZE // So we can find our way around memory | 310 #ifdef HAL_DCACHE_LINE_SIZE // So we can find our way around memory |
| 311 | |
| 312 #ifdef _TEST_DCACHE_OPERATION | |
| 313 static void | |
| 314 test_dcache_operation(void) | |
| 315 { | |
| 316 long *lp = (long *)m; | |
| 317 int i, errs; | |
| 318 | |
| 319 CYG_TEST_INFO("Data cache basic"); | |
| 320 | |
| 321 HAL_DISABLE_INTERRUPTS(oldints); | |
| 322 HAL_DCACHE_SYNC(); | |
| 323 HAL_DCACHE_DISABLE(); | |
| 324 HAL_DCACHE_SYNC(); | |
| 325 // Fill test buffer | |
| 326 for (i = 0; i < sizeof(m)/sizeof(*lp); i++) { | |
| 327 lp[i] = i; | |
| 328 } | |
| 329 HAL_DCACHE_INVALIDATE_ALL(); | |
| 330 HAL_DCACHE_ENABLE(); | |
| 331 // Now push data through the cache | |
| 332 for (i = 256; i < 256+HAL_DCACHE_SIZE/sizeof(*lp); i++) { | |
| 333 lp[i] = 0xFF000000 + i; | |
| 334 } | |
| 335 // Now force cache clean and off | |
| 336 HAL_DCACHE_SYNC(); | |
| 337 HAL_DCACHE_DISABLE(); | |
| 338 // Verify the data | |
| 339 diag_printf("Verify data with cache off\n"); | |
| 340 errs = 0; | |
| 341 for (i = 0; i < sizeof(m)/sizeof(*lp); i++) { | |
| 342 if ((i >= 256) && (i < 256+HAL_DCACHE_SIZE/sizeof(*lp))) { | |
| 343 if (lp[i] != (0xFF000000 + i)) { | |
| 344 if (++errs < 16) { | |
| 345 diag_printf("Data inside test range changed - was: %x, is %x, index: %x\n", | |
| 346 0xFF000000+i, lp[i], i); | |
| 347 } | |
| 348 } | |
| 349 } else { | |
| 350 if (lp[i] != i) { | |
| 351 if (++errs < 16) { | |
| 352 diag_printf("Data outside test range changed - was: %x, is %x, index: %x\n", | |
| 353 i, lp[i], i); | |
| 354 } | |
| 355 } | |
| 356 } | |
| 357 } | |
| 358 diag_printf("%d total errors during compare\n", errs); | |
| 359 diag_dump_buf(&lp[240], 128); | |
| 360 HAL_RESTORE_INTERRUPTS(oldints); | |
| 361 } | |
| 362 #endif | |
| 363 | |
| 295 static void test_dsync(void) | 364 static void test_dsync(void) |
| 296 { | 365 { |
| 297 volatile cyg_uint8* aligned_p; | 366 volatile cyg_uint8* aligned_p; |
| 298 cyg_int32 i; | 367 cyg_int32 i; |
| 299 register CYG_INTERRUPT_STATE oldints; | 368 register CYG_INTERRUPT_STATE oldints; |
| 324 CYG_TEST_CHECK(43 == aligned_p[HAL_DCACHE_LINE_SIZE], | 393 CYG_TEST_CHECK(43 == aligned_p[HAL_DCACHE_LINE_SIZE], |
| 325 "memory didn't contain flushed data next block"); | 394 "memory didn't contain flushed data next block"); |
| 326 | 395 |
| 327 HAL_DCACHE_INVALIDATE_ALL(); | 396 HAL_DCACHE_INVALIDATE_ALL(); |
| 328 | 397 |
| 398 diag_printf("Data: %x %x\n", aligned_p[0], aligned_p[HAL_DCACHE_LINE_SIZE]); | |
| 329 CYG_TEST_CHECK(42 == aligned_p[0], | 399 CYG_TEST_CHECK(42 == aligned_p[0], |
| 330 "memory didn't contain flushed data after invalidate"); | 400 "memory didn't contain flushed data after invalidate"); |
| 331 CYG_TEST_CHECK(43 == aligned_p[HAL_DCACHE_LINE_SIZE], | 401 CYG_TEST_CHECK(43 == aligned_p[HAL_DCACHE_LINE_SIZE], |
| 332 "memory didn't contain flushed data next block after invalidate"); | 402 "memory didn't contain flushed data next block after invalidate"); |
| 333 | 403 |
| 747 | 817 |
| 748 // ------------------------------------------------------------------------- | 818 // ------------------------------------------------------------------------- |
| 749 static void entry0( cyg_addrword_t data ) | 819 static void entry0( cyg_addrword_t data ) |
| 750 { | 820 { |
| 751 int numtests = 0; | 821 int numtests = 0; |
| 822 #ifdef _TEST_DCACHE_OPERATION | |
| 823 test_dcache_operation(); | |
| 824 #endif | |
| 752 #ifdef HAL_DCACHE_QUERY_WRITE_MODE | 825 #ifdef HAL_DCACHE_QUERY_WRITE_MODE |
| 753 int wmode; | 826 int wmode; |
| 754 #endif | 827 #endif |
| 755 #ifdef HAL_DCACHE_LOCK | 828 #ifdef HAL_DCACHE_LOCK |
| 756 time_dlock(); numtests++; | 829 time_dlock(); numtests++; |
