Changeset 96348adc in mainline for kernel/test/mm/slab1.c
- Timestamp:
- 2006-12-12T17:24:58Z (18 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 7e13972
- Parents:
- 34db7fa
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/test/mm/slab1.c
r34db7fa r96348adc 35 35 #include <memstr.h> 36 36 37 #ifdef CONFIG_BENCH38 #include <arch/cycle.h>39 #endif40 41 37 #define VAL_COUNT 1024 42 38 … … 52 48 SLAB_CACHE_NOMAGAZINE); 53 49 printf("Allocating %d items...", count); 54 for (i =0; i < count; i++) {50 for (i = 0; i < count; i++) { 55 51 data[i] = slab_alloc(cache, 0); 56 memsetb((uintptr_t) data[i], size, 0);52 memsetb((uintptr_t) data[i], size, 0); 57 53 } 58 54 printf("done.\n"); 59 55 printf("Freeing %d items...", count); 60 for (i =0; i < count; i++) {56 for (i = 0; i < count; i++) { 61 57 slab_free(cache, data[i]); 62 58 } … … 64 60 65 61 printf("Allocating %d items...", count); 66 for (i =0; i < count; i++) {62 for (i = 0; i < count; i++) { 67 63 data[i] = slab_alloc(cache, 0); 68 memsetb((uintptr_t) data[i], size, 0);64 memsetb((uintptr_t) data[i], size, 0); 69 65 } 70 66 printf("done.\n"); 71 67 72 printf("Freeing %d items...", count /2);73 for (i =count-1; i >= count/2; i--) {68 printf("Freeing %d items...", count / 2); 69 for (i = count - 1; i >= count / 2; i--) { 74 70 slab_free(cache, data[i]); 75 71 } 76 72 printf("done.\n"); 77 73 78 printf("Allocating %d items...", count /2);79 for (i =count/2; i < count; i++) {74 printf("Allocating %d items...", count / 2); 75 for (i = count / 2; i < count; i++) { 80 76 data[i] = slab_alloc(cache, 0); 81 memsetb((uintptr_t) data[i], size, 0);77 memsetb((uintptr_t) data[i], size, 0); 82 78 } 83 79 printf("done.\n"); 84 80 printf("Freeing %d items...", count); 85 for (i =0; i < count; i++) {81 for (i = 0; i < count; i++) { 86 82 slab_free(cache, data[i]); 87 83 } … … 104 100 } 105 101 106 107 102 #define THREADS 6 108 103 #define THR_MEM_COUNT 1024 109 104 #define THR_MEM_SIZE 128 110 105 111 void * thr_data[THREADS][THR_MEM_COUNT];112 s lab_cache_t *thr_cache;113 s emaphore_t thr_sem;106 static void * thr_data[THREADS][THR_MEM_COUNT]; 107 static slab_cache_t *thr_cache; 108 static semaphore_t thr_sem; 114 109 115 110 static void slabtest(void *data) 116 111 { 117 int offs = (int) (unative_t) data;118 int i, j;112 int offs = (int) (unative_t) data; 113 int i, j; 119 114 120 115 thread_detach(THREAD); 121 116 122 117 printf("Starting thread #%d...\n",THREAD->tid); 123 for (j =0; j<10; j++) {124 for (i =0; i<THR_MEM_COUNT; i++)118 for (j = 0; j < 10; j++) { 119 for (i = 0; i < THR_MEM_COUNT; i++) 125 120 thr_data[offs][i] = slab_alloc(thr_cache,0); 126 for (i =0; i<THR_MEM_COUNT/2; i++)121 for (i = 0; i < THR_MEM_COUNT / 2; i++) 127 122 slab_free(thr_cache, thr_data[offs][i]); 128 for (i =0; i< THR_MEM_COUNT/2; i++)123 for (i = 0; i < THR_MEM_COUNT / 2; i++) 129 124 thr_data[offs][i] = slab_alloc(thr_cache, 0); 130 for (i =0; i<THR_MEM_COUNT;i++)125 for (i = 0; i < THR_MEM_COUNT; i++) 131 126 slab_free(thr_cache, thr_data[offs][i]); 132 127 } … … 143 138 NULL, NULL, 144 139 SLAB_CACHE_NOMAGAZINE); 145 semaphore_initialize(&thr_sem,0); 146 for (i=0; i<THREADS; i++) { 147 if (!(t = thread_create(slabtest, (void *)(unative_t)i, TASK, 0, "slabtest"))) 148 panic("could not create thread\n"); 149 thread_ready(t); 140 semaphore_initialize(&thr_sem, 0); 141 for (i = 0; i < THREADS; i++) { 142 if (!(t = thread_create(slabtest, (void *) (unative_t) i, TASK, 0, "slabtest"))) 143 printf("Could not create thread %d\n", i); 144 else 145 thread_ready(t); 150 146 } 151 147 152 for (i =0; i<THREADS; i++)148 for (i = 0; i < THREADS; i++) 153 149 semaphore_down(&thr_sem); 154 150 … … 158 154 } 159 155 160 voidtest_slab1(void)156 char * test_slab1(void) 161 157 { 162 #ifdef CONFIG_BENCH163 uint64_t t0 = get_cycle();164 #endif165 158 testsimple(); 166 159 testthreads(); 167 #ifdef CONFIG_BENCH 168 uint64_t dt = get_cycle() - t0; 169 printf("Time: %.*d cycles\n", sizeof(dt) * 2, dt); 170 #endif 160 161 return NULL; 171 162 }
Note:
See TracChangeset
for help on using the changeset viewer.