Changeset c5613b7 in mainline


Ignore:
Timestamp:
2006-02-04T01:59:42Z (19 years ago)
Author:
Ondrej Palkovsky <ondrap@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
10e16a7
Parents:
81e52f2a
Message:

Added slab stress test.
Fixed race condition in slab allocator.
Moved initialization of slab to the point where we know correct config.cpu_count
Correctly passes tests on amd64, ia32 in both bochs & qemu.

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • generic/src/main/main.c

    r81e52f2a rc5613b7  
    164164        page_init();
    165165        tlb_init();
    166         slab_cache_init();
    167166        arch_post_mm_init();
    168167
     
    174173        arch_pre_smp_init();
    175174        smp_init();
     175        /* Slab must be initialized AFTER we know the number of processors */
     176        slab_cache_init();
     177
    176178        printf("config.memory_size=%dM\n", config.memory_size/(1024*1024));
    177179        printf("config.cpu_count=%d\n", config.cpu_count);
  • generic/src/mm/slab.c

    r81e52f2a rc5613b7  
    387387 * no empty magazine is available and cannot be allocated
    388388 *
     389 * Assume mag_cache[CPU->id].lock is held
     390 *
    389391 * We have 2 magazines bound to processor.
    390392 * First try the current.
     
    421423
    422424        /* Flush last to magazine list */
    423         if (lastmag)
     425        if (lastmag) {
     426                spinlock_lock(&cache->lock);
    424427                list_prepend(&lastmag->link, &cache->magazines);
     428                spinlock_unlock(&cache->lock);
     429        }
    425430        /* Move current as last, save new as current */
    426431        cache->mag_cache[CPU->id].last = cmag; 
     
    514519        spinlock_initialize(&cache->lock, "cachelock");
    515520        if (! (cache->flags & SLAB_CACHE_NOMAGAZINE)) {
    516                 for (i=0; i< config.cpu_count; i++) {
     521                for (i=0; i < config.cpu_count; i++) {
    517522                        memsetb((__address)&cache->mag_cache[i],
    518523                                sizeof(cache->mag_cache[i]), 0);
     
    650655        ipl_t ipl;
    651656        void *result = NULL;
    652 
     657       
    653658        /* Disable interrupts to avoid deadlocks with interrupt handlers */
    654659        ipl = interrupts_disable();
  • test/mm/slab2/test.c

    r81e52f2a rc5613b7  
    7474        }while(1);
    7575        printf("done.\n");
    76         slab_print_list();
    7776        /* We do not have memory - now deallocate cache2 */
    7877        printf("Deallocating cache2...");
     
    8483        printf("done.\n");
    8584
    86         slab_print_list();
    8785        printf("Allocating to cache1...\n");
    8886        for (i=0; i<30; i++) {
     
    9593                olddata1 = data1;
    9694        }
    97         slab_print_list();
    9895        while (1) {
    9996                data1 = slab_alloc(cache1, FRAME_ATOMIC);
     
    105102                olddata1 = data1;
    106103        }
    107         slab_print_list();
    108104        printf("Deallocating cache1...");
    109105        while (olddata1) {
     
    118114}
    119115
     116slab_cache_t *thr_cache;
     117semaphore_t thr_sem;
     118
     119#define THREADS 8
     120
     121static void thread(void *priv)
     122{
     123        void *data=NULL, *new;
     124
     125        printf("Starting thread #%d...\n",THREAD->tid);
     126
     127        /* Alloc all */
     128        printf("Thread #%d allocating...\n", THREAD->tid);
     129        while (1) {
     130                /* Call with atomic to detect end of memory */
     131                new = slab_alloc(thr_cache, FRAME_ATOMIC);
     132                if (!new)
     133                        break;
     134                *((void **)new) = data;
     135                data = new;
     136        }
     137        printf("Thread #%d releasing...\n", THREAD->tid);
     138        while (data) {
     139                new = *((void **)data);
     140                slab_free(thr_cache, data);
     141                data = new;
     142        }
     143        printf("Thread #%d allocating...\n", THREAD->tid);
     144        while (1) {
     145                /* Call with atomic to detect end of memory */
     146                new = slab_alloc(thr_cache, FRAME_ATOMIC);
     147                if (!new)
     148                        break;
     149                *((void **)new) = data;
     150                data = new;
     151        }
     152        printf("Thread #%d releasing...\n", THREAD->tid);
     153        while (data) {
     154                new = *((void **)data);
     155                slab_free(thr_cache, data);
     156                data = new;
     157        }
     158
     159
     160        printf("Thread #%d finished\n", THREAD->tid);
     161        slab_print_list();
     162        semaphore_up(&thr_sem);
     163}
     164
     165
     166static void multitest(int size)
     167{
     168        /* Start 8 threads that just allocate as much as possible,
     169         * then release everything, then again allocate, then release
     170         */
     171        thread_t *t;
     172        int i;
     173
     174        printf("Running stress test with size %d\n", size);
     175        thr_cache = slab_cache_create("thread_cache", size, 0,
     176                                      NULL, NULL,
     177                                      0);
     178        semaphore_initialize(&thr_sem,0);
     179        for (i=0; i<THREADS; i++) { 
     180                if (!(t = thread_create(thread, NULL, TASK, 0)))
     181                        panic("could not create thread\n");
     182                thread_ready(t);
     183        }
     184
     185        for (i=0; i<THREADS; i++)
     186                semaphore_down(&thr_sem);
     187       
     188        slab_cache_destroy(thr_cache);
     189        printf("Stress test complete.\n");
     190}
     191
    120192void test(void)
    121193{
    122         printf("Running reclaim test .. pass1\n");
     194        printf("Running reclaim single-thread test .. pass1\n");
    123195        totalmemtest();
    124         printf("Running reclaim test .. pass2\n");
     196        printf("Running reclaim single-thread test .. pass2\n");
    125197        totalmemtest();
    126198        printf("Reclaim test OK.\n");
    127 }
     199
     200        multitest(128);
     201        multitest(2048);
     202        printf("All done.\n");
     203}
Note: See TracChangeset for help on using the changeset viewer.