Changeset 248fc1a in mainline


Ignore:
Timestamp:
2006-02-05T13:56:01Z (19 years ago)
Author:
Ondrej Palkovsky <ondrap@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
444ec64
Parents:
e22f561
Message:

Fixed some typos in slab allocator.
Scheduler now has better algorithm on load balancing.
Unfortunately it reveals deadlock in slab allocator :-/

Location:
generic
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • generic/include/cpu.h

    re22f561 r248fc1a  
    5151        context_t saved_context;
    5252
    53         volatile count_t nrdy;
     53        atomic_t nrdy;
    5454        runq_t rq[RQ_COUNT];
    5555        volatile count_t needs_relink;
  • generic/src/mm/slab.c

    re22f561 r248fc1a  
    253253                list_remove(&slab->link);
    254254                list_prepend(&slab->link, &cache->partial_slabs);
    255                 spinlock_unlock(&cache->slablock);
    256         }
     255        }
     256        spinlock_unlock(&cache->slablock);
    257257        return 0;
    258258}
     
    537537        int i;
    538538        int pages;
     539        ipl_t ipl;
    539540
    540541        memsetb((__address)cache, sizeof(*cache), 0);
     
    581582                cache->flags |= SLAB_CACHE_SLINSIDE;
    582583
     584        /* Add cache to cache list */
     585        ipl = interrupts_disable();
    583586        spinlock_lock(&slab_cache_lock);
    584587
     
    586589
    587590        spinlock_unlock(&slab_cache_lock);
     591        interrupts_restore(ipl);
    588592}
    589593
     
    759763        slab_cache_t *cache;
    760764        link_t *cur;
    761 
     765        ipl_t ipl;
     766       
     767        ipl = interrupts_disable();
    762768        spinlock_lock(&slab_cache_lock);
    763769        printf("SLAB name\tOsize\tPages\tObj/pg\tSlabs\tCached\tAllocobjs\tCtl\n");
     
    772778        }
    773779        spinlock_unlock(&slab_cache_lock);
     780        interrupts_restore(ipl);
    774781}
    775782
  • generic/src/proc/scheduler.c

    re22f561 r248fc1a  
    120120        thread_t *t;
    121121        runq_t *r;
    122         int i, n;
     122        int i;
    123123
    124124        ASSERT(CPU != NULL);
    125125
    126126loop:
    127         interrupts_disable();
    128 
    129         spinlock_lock(&CPU->lock);
    130         n = CPU->nrdy;
    131         spinlock_unlock(&CPU->lock);
    132 
    133127        interrupts_enable();
    134128       
    135         if (n == 0) {
     129        if (atomic_get(&CPU->nrdy) == 0) {
    136130                /*
    137131                 * For there was nothing to run, the CPU goes to sleep
     
    146140       
    147141        i = 0;
    148 retry:
    149142        for (; i<RQ_COUNT; i++) {
    150143                r = &CPU->rq[i];
     
    158151                }
    159152
    160                 /* avoid deadlock with relink_rq() */
    161                 if (!spinlock_trylock(&CPU->lock)) {
    162                         /*
    163                          * Unlock r and try again.
    164                          */
    165                         spinlock_unlock(&r->lock);
    166                         goto retry;
    167                 }
    168                 CPU->nrdy--;
    169                 spinlock_unlock(&CPU->lock);
    170 
     153                atomic_dec(&CPU->nrdy);
    171154                atomic_dec(&nrdy);
    172155                r->n--;
     
    465448{
    466449        thread_t *t;
    467         int count, i, j, k = 0;
     450        int count, average, i, j, k = 0;
    468451        ipl_t ipl;
    469452
     
    480463         * passes. Each time get the most up to date counts.
    481464         */
    482         ipl = interrupts_disable();
    483         spinlock_lock(&CPU->lock);
    484         count = atomic_get(&nrdy) / config.cpu_active;
    485         count -= CPU->nrdy;
    486         spinlock_unlock(&CPU->lock);
    487         interrupts_restore(ipl);
    488 
    489         if (count <= 0)
     465        average = atomic_get(&nrdy) / config.cpu_active;
     466        count = average - atomic_get(&CPU->nrdy);
     467
     468        if (count < 0)
    490469                goto satisfied;
     470
     471        if (!count) { /* Try to steal threads from CPU's that have more then average count */
     472                count = 1;
     473                average += 1;
     474        }
    491475
    492476        /*
     
    506490                         */
    507491                        if (CPU == cpu)
    508                                 continue;                               
     492                                continue;
     493                        if (atomic_get(&cpu->nrdy) <= average)
     494                                continue;
    509495
    510496restart:                ipl = interrupts_disable();
     
    545531                                                goto restart;
    546532                                        }
    547                                         cpu->nrdy--;
     533                                        atomic_dec(&cpu->nrdy);
    548534                                        spinlock_unlock(&cpu->lock);
    549535
     
    567553                                spinlock_lock(&t->lock);
    568554                                #ifdef KCPULB_VERBOSE
    569                                 printf("kcpulb%d: TID %d -> cpu%d, nrdy=%d, avg=%d\n", CPU->id, t->tid, CPU->id, CPU->nrdy, atomic_get(&nrdy) / config.cpu_active);
     555                                printf("kcpulb%d: TID %d -> cpu%d, nrdy=%d, avg=%d\n", CPU->id, t->tid, CPU->id, atomic_get(&CPU->nrdy), atomic_get(&nrdy) / config.cpu_active);
    570556                                #endif
    571557                                t->flags |= X_STOLEN;
     
    590576        }
    591577
    592         if (CPU->nrdy) {
     578        if (atomic_get(&CPU->nrdy)) {
    593579                /*
    594580                 * Be a little bit light-weight and let migrated threads run.
     
    630616                spinlock_lock(&cpus[cpu].lock);
    631617                printf("cpu%d: nrdy: %d needs_relink: %d\n",
    632                        cpus[cpu].id, cpus[cpu].nrdy, cpus[cpu].needs_relink);
     618                       cpus[cpu].id, atomic_get(&cpus[cpu].nrdy), cpus[cpu].needs_relink);
    633619               
    634620                for (i=0; i<RQ_COUNT; i++) {
  • generic/src/proc/thread.c

    re22f561 r248fc1a  
    138138        atomic_inc(&nrdy);
    139139        avg = atomic_get(&nrdy) / config.cpu_active;
    140 
    141         spinlock_lock(&cpu->lock);
    142         if ((++cpu->nrdy) > avg) {
    143                 /*
    144                  * If there are idle halted CPU's, this will wake them up.
    145                  */
    146                 ipi_broadcast(VECTOR_WAKEUP_IPI);
    147         }       
    148         spinlock_unlock(&cpu->lock);
     140        atomic_inc(&cpu->nrdy);
    149141
    150142        interrupts_restore(ipl);
Note: See TracChangeset for help on using the changeset viewer.