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