Changeset deada67 in mainline for kernel/test/mm/slab1.c
- Timestamp:
- 2006-12-19T17:54:50Z (19 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 730376d
- Parents:
- 6536a4a9
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/test/mm/slab1.c
r6536a4a9 rdeada67 38 38 static void * data[VAL_COUNT]; 39 39 40 static void testit(int size, int count )40 static void testit(int size, int count, bool quiet) 41 41 { 42 42 slab_cache_t *cache; 43 43 int i; 44 44 45 printf("Creating cache, object size: %d.\n", size); 46 cache = slab_cache_create("test_cache", size, 0, NULL, NULL, 47 SLAB_CACHE_NOMAGAZINE); 48 printf("Allocating %d items...", count); 45 if (!quiet) 46 printf("Creating cache, object size: %d.\n", size); 47 48 cache = slab_cache_create("test_cache", size, 0, NULL, NULL, 49 SLAB_CACHE_NOMAGAZINE); 50 51 if (!quiet) 52 printf("Allocating %d items...", count); 53 49 54 for (i = 0; i < count; i++) { 50 55 data[i] = slab_alloc(cache, 0); 51 56 memsetb((uintptr_t) data[i], size, 0); 52 57 } 53 printf("done.\n"); 54 printf("Freeing %d items...", count); 55 for (i = 0; i < count; i++) { 58 59 if (!quiet) { 60 printf("done.\n"); 61 printf("Freeing %d items...", count); 62 } 63 64 for (i = 0; i < count; i++) 56 65 slab_free(cache, data[i]); 66 67 if (!quiet) { 68 printf("done.\n"); 69 printf("Allocating %d items...", count); 57 70 } 58 printf("done.\n"); 59 60 printf("Allocating %d items...", count); 71 61 72 for (i = 0; i < count; i++) { 62 73 data[i] = slab_alloc(cache, 0); 63 74 memsetb((uintptr_t) data[i], size, 0); 64 75 } 65 printf("done.\n"); 66 67 printf("Freeing %d items...", count / 2); 68 for (i = count - 1; i >= count / 2; i--) { 76 77 if (!quiet) { 78 printf("done.\n"); 79 printf("Freeing %d items...", count / 2); 80 } 81 82 for (i = count - 1; i >= count / 2; i--) 69 83 slab_free(cache, data[i]); 84 85 if (!quiet) { 86 printf("done.\n"); 87 printf("Allocating %d items...", count / 2); 70 88 } 71 printf("done.\n"); 72 73 printf("Allocating %d items...", count / 2); 89 74 90 for (i = count / 2; i < count; i++) { 75 91 data[i] = slab_alloc(cache, 0); 76 92 memsetb((uintptr_t) data[i], size, 0); 77 93 } 78 printf("done.\n"); 79 printf("Freeing %d items...", count); 80 for (i = 0; i < count; i++) { 94 95 if (!quiet) { 96 printf("done.\n"); 97 printf("Freeing %d items...", count); 98 } 99 100 for (i = 0; i < count; i++) 81 101 slab_free(cache, data[i]); 82 } 83 printf("done.\n"); 102 103 if (!quiet) 104 printf("done.\n"); 84 105 slab_cache_destroy(cache); 85 86 printf("Test complete.\n"); 106 107 if (!quiet) 108 printf("Test complete.\n"); 87 109 } 88 110 89 static void testsimple( void)111 static void testsimple(bool quiet) 90 112 { 91 testit(100, VAL_COUNT );92 testit(200, VAL_COUNT );93 testit(1024, VAL_COUNT );94 testit(2048, 512 );95 testit(4000, 128 );96 testit(8192, 128 );97 testit(16384, 128 );98 testit(16385, 128 );113 testit(100, VAL_COUNT, quiet); 114 testit(200, VAL_COUNT, quiet); 115 testit(1024, VAL_COUNT, quiet); 116 testit(2048, 512, quiet); 117 testit(4000, 128, quiet); 118 testit(8192, 128, quiet); 119 testit(16384, 128, quiet); 120 testit(16385, 128, quiet); 99 121 } 100 122 … … 106 128 static slab_cache_t *thr_cache; 107 129 static semaphore_t thr_sem; 130 static bool sh_quiet; 108 131 109 132 static void slabtest(void *data) … … 114 137 thread_detach(THREAD); 115 138 116 printf("Starting thread #%d...\n",THREAD->tid); 139 if (!sh_quiet) 140 printf("Starting thread #%d...\n", THREAD->tid); 141 117 142 for (j = 0; j < 10; j++) { 118 143 for (i = 0; i < THR_MEM_COUNT; i++) … … 125 150 slab_free(thr_cache, thr_data[offs][i]); 126 151 } 127 printf("Thread #%d finished\n", THREAD->tid); 152 153 if (!sh_quiet) 154 printf("Thread #%d finished\n", THREAD->tid); 155 128 156 semaphore_up(&thr_sem); 129 157 } 130 158 131 static void testthreads( void)159 static void testthreads(bool quiet) 132 160 { 133 161 thread_t *t; 134 162 int i; 135 163 136 thr_cache = slab_cache_create("thread_cache", THR_MEM_SIZE, 0, 137 NULL, NULL, 138 SLAB_CACHE_NOMAGAZINE); 164 thr_cache = slab_cache_create("thread_cache", THR_MEM_SIZE, 0, NULL, NULL, 165 SLAB_CACHE_NOMAGAZINE); 139 166 semaphore_initialize(&thr_sem, 0); 140 167 for (i = 0; i < THREADS; i++) { 141 if (!(t = thread_create(slabtest, (void *) (unative_t) i, TASK, 0, "slabtest", false))) 142 printf("Could not create thread %d\n", i); 143 else 168 if (!(t = thread_create(slabtest, (void *) (unative_t) i, TASK, 0, "slabtest", false))) { 169 if (!quiet) 170 printf("Could not create thread %d\n", i); 171 } else 144 172 thread_ready(t); 145 173 } … … 149 177 150 178 slab_cache_destroy(thr_cache); 151 printf("Test complete.\n");152 179 180 if (!quiet) 181 printf("Test complete.\n"); 153 182 } 154 183 155 184 char * test_slab1(bool quiet) 156 185 { 157 testsimple(); 158 testthreads(); 186 sh_quiet = quiet; 187 188 testsimple(quiet); 189 testthreads(quiet); 159 190 160 191 return NULL;
Note:
See TracChangeset
for help on using the changeset viewer.