Changeset deada67 in mainline for kernel/test/mm/slab2.c


Ignore:
Timestamp:
2006-12-19T17:54:50Z (19 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
730376d
Parents:
6536a4a9
Message:

quiet variants of tests

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/test/mm/slab2.c

    r6536a4a9 rdeada67  
    4343 *  now allocation should clean magazines and allow for full allocation.
    4444 */
    45 static void totalmemtest(void)
     45static void totalmemtest(bool quiet)
    4646{
    4747        slab_cache_t *cache1;
     
    5050
    5151        void *data1, *data2;
    52         void *olddata1=NULL, *olddata2=NULL;
     52        void *olddata1 = NULL, *olddata2 = NULL;
    5353       
    5454        cache1 = slab_cache_create("cache1_tst", ITEM_SIZE, 0, NULL, NULL, 0);
    5555        cache2 = slab_cache_create("cache2_tst", ITEM_SIZE, 0, NULL, NULL, 0);
    56 
    57         printf("Allocating...");
     56       
     57        if (!quiet)
     58                printf("Allocating...");
     59       
    5860        /* Use atomic alloc, so that we find end of memory */
    5961        do {
    6062                data1 = slab_alloc(cache1, FRAME_ATOMIC);
    6163                data2 = slab_alloc(cache2, FRAME_ATOMIC);
    62                 if (!data1 || !data2) {
     64                if ((!data1) || (!data2)) {
    6365                        if (data1)
    64                                 slab_free(cache1,data1);
     66                                slab_free(cache1, data1);
    6567                        if (data2)
    66                                 slab_free(cache2,data2);
     68                                slab_free(cache2, data2);
    6769                        break;
    6870                }
    69                 memsetb((uintptr_t)data1, ITEM_SIZE, 0);
    70                 memsetb((uintptr_t)data2, ITEM_SIZE, 0);
    71                 *((void **)data1) = olddata1;
    72                 *((void **)data2) = olddata2;
     71                memsetb((uintptr_t) data1, ITEM_SIZE, 0);
     72                memsetb((uintptr_t) data2, ITEM_SIZE, 0);
     73                *((void **) data1) = olddata1;
     74                *((void **) data2) = olddata2;
    7375                olddata1 = data1;
    7476                olddata2 = data2;
    75         } while(1);
    76         printf("done.\n");
     77        } while (1);
     78       
     79        if (!quiet) {
     80                printf("done.\n");
     81                printf("Deallocating cache2...");
     82        }
     83       
    7784        /* We do not have memory - now deallocate cache2 */
    78         printf("Deallocating cache2...");
    7985        while (olddata2) {
    80                 data2 = *((void **)olddata2);
     86                data2 = *((void **) olddata2);
    8187                slab_free(cache2, olddata2);
    8288                olddata2 = data2;
    8389        }
    84         printf("done.\n");
    85 
    86         printf("Allocating to cache1...\n");
    87         for (i=0; i<30; i++) {
     90       
     91        if (!quiet) {
     92                printf("done.\n");
     93                printf("Allocating to cache1...\n");
     94        }
     95       
     96        for (i = 0; i < 30; i++) {
    8897                data1 = slab_alloc(cache1, FRAME_ATOMIC);
    8998                if (!data1) {
    90                         printf("Incorrect memory size - use another test.");
     99                        if (!quiet)
     100                                printf("Incorrect memory size - use another test.");
    91101                        return;
    92102                }
    93                 memsetb((uintptr_t)data1, ITEM_SIZE, 0);
    94                 *((void **)data1) = olddata1;
     103                memsetb((uintptr_t) data1, ITEM_SIZE, 0);
     104                *((void **) data1) = olddata1;
    95105                olddata1 = data1;
    96106        }
    97107        while (1) {
    98108                data1 = slab_alloc(cache1, FRAME_ATOMIC);
    99                 if (!data1) {
    100                         break;
    101                 }
    102                 memsetb((uintptr_t)data1, ITEM_SIZE, 0);
    103                 *((void **)data1) = olddata1;
    104                 olddata1 = data1;
    105         }
    106         printf("Deallocating cache1...");
     109                if (!data1)
     110                        break;
     111                memsetb((uintptr_t) data1, ITEM_SIZE, 0);
     112                *((void **) data1) = olddata1;
     113                olddata1 = data1;
     114        }
     115       
     116        if (!quiet)
     117                printf("Deallocating cache1...");
     118       
    107119        while (olddata1) {
    108                 data1 = *((void **)olddata1);
     120                data1 = *((void **) olddata1);
    109121                slab_free(cache1, olddata1);
    110122                olddata1 = data1;
    111123        }
    112         printf("done.\n");
    113         slab_print_list();
     124       
     125        if (!quiet) {
     126                printf("done.\n");
     127                slab_print_list();
     128        }
     129       
    114130        slab_cache_destroy(cache1);
    115131        slab_cache_destroy(cache2);
     
    120136static condvar_t thread_starter;
    121137static mutex_t starter_mutex;
     138static bool sh_quiet;
    122139
    123140#define THREADS 8
     
    126143{
    127144        void *data = NULL, *new;
    128 
     145       
    129146        thread_detach(THREAD);
    130 
     147       
    131148        mutex_lock(&starter_mutex);
    132149        condvar_wait(&thread_starter,&starter_mutex);
    133150        mutex_unlock(&starter_mutex);
    134                
    135         printf("Starting thread #%d...\n",THREAD->tid);
     151       
     152        if (!sh_quiet)
     153                printf("Starting thread #%d...\n",THREAD->tid);
    136154
    137155        /* Alloc all */
    138         printf("Thread #%d allocating...\n", THREAD->tid);
     156        if (!sh_quiet)
     157                printf("Thread #%d allocating...\n", THREAD->tid);
     158       
    139159        while (1) {
    140160                /* Call with atomic to detect end of memory */
     
    142162                if (!new)
    143163                        break;
    144                 *((void **)new) = data;
    145                 data = new;
    146         }
    147         printf("Thread #%d releasing...\n", THREAD->tid);
     164                *((void **) new) = data;
     165                data = new;
     166        }
     167       
     168        if (!sh_quiet)
     169                printf("Thread #%d releasing...\n", THREAD->tid);
     170       
    148171        while (data) {
    149172                new = *((void **)data);
    150                 *((void **)data) = NULL;
     173                *((void **) data) = NULL;
    151174                slab_free(thr_cache, data);
    152175                data = new;
    153176        }
    154         printf("Thread #%d allocating...\n", THREAD->tid);
     177       
     178        if (!sh_quiet)
     179                printf("Thread #%d allocating...\n", THREAD->tid);
     180       
    155181        while (1) {
    156182                /* Call with atomic to detect end of memory */
     
    158184                if (!new)
    159185                        break;
    160                 *((void **)new) = data;
    161                 data = new;
    162         }
    163         printf("Thread #%d releasing...\n", THREAD->tid);
     186                *((void **) new) = data;
     187                data = new;
     188        }
     189       
     190        if (!sh_quiet)
     191                printf("Thread #%d releasing...\n", THREAD->tid);
     192       
    164193        while (data) {
    165194                new = *((void **)data);
    166                 *((void **)data) = NULL;
     195                *((void **) data) = NULL;
    167196                slab_free(thr_cache, data);
    168197                data = new;
    169198        }
    170 
    171         printf("Thread #%d finished\n", THREAD->tid);
     199       
     200        if (!sh_quiet)
     201                printf("Thread #%d finished\n", THREAD->tid);
     202       
    172203        slab_print_list();
    173204        semaphore_up(&thr_sem);
    174205}
    175206
    176 static void multitest(int size)
     207static void multitest(int size, bool quiet)
    177208{
    178209        /* Start 8 threads that just allocate as much as possible,
     
    181212        thread_t *t;
    182213        int i;
    183 
    184         printf("Running stress test with size %d\n", size);
     214       
     215        if (!quiet)
     216                printf("Running stress test with size %d\n", size);
     217       
    185218        condvar_initialize(&thread_starter);
    186219        mutex_initialize(&starter_mutex);
    187220
    188         thr_cache = slab_cache_create("thread_cache", size, 0,
    189                                       NULL, NULL,
    190                                       0);
     221        thr_cache = slab_cache_create("thread_cache", size, 0, NULL, NULL, 0);
    191222        semaphore_initialize(&thr_sem,0);
    192223        for (i = 0; i < THREADS; i++) { 
    193                 if (!(t = thread_create(slabtest, NULL, TASK, 0, "slabtest", false)))
    194                         printf("Could not create thread %d\n", i);
    195                 else
     224                if (!(t = thread_create(slabtest, NULL, TASK, 0, "slabtest", false))) {
     225                        if (!quiet)
     226                                printf("Could not create thread %d\n", i);
     227                } else
    196228                        thread_ready(t);
    197229        }
     
    203235       
    204236        slab_cache_destroy(thr_cache);
    205         printf("Stress test complete.\n");
     237        if (!quiet)
     238                printf("Stress test complete.\n");
    206239}
    207240
    208241char * test_slab2(bool quiet)
    209242{
    210         printf("Running reclaim single-thread test .. pass 1\n");
    211         totalmemtest();
    212         printf("Running reclaim single-thread test .. pass 2\n");
    213         totalmemtest();
    214         printf("Reclaim test OK.\n");
    215 
    216         multitest(128);
    217         multitest(2048);
    218         multitest(8192);
    219         printf("All done.\n");
     243        sh_quiet = quiet;
     244       
     245        if (!quiet)
     246                printf("Running reclaim single-thread test .. pass 1\n");
     247        totalmemtest(quiet);
     248        if (!quiet)
     249                printf("Running reclaim single-thread test .. pass 2\n");
     250        totalmemtest(quiet);
     251        if (!quiet)
     252                printf("Reclaim test OK.\n");
     253       
     254        multitest(128, quiet);
     255        multitest(2048, quiet);
     256        multitest(8192, quiet);
    220257       
    221258        return NULL;
Note: See TracChangeset for help on using the changeset viewer.