Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset c2ab3f4 in mainline


Ignore:
Timestamp:
2010-04-28T21:12:04Z (11 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master
Children:
c050399
Parents:
b8f7ea78 (diff), 55821eea (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge blocking and locking improvements and fixes.

Location:
kernel/generic/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/ddi/ddi.c

    rb8f7ea78 rc2ab3f4  
    4646#include <mm/frame.h>
    4747#include <mm/as.h>
    48 #include <synch/spinlock.h>
     48#include <synch/mutex.h>
    4949#include <syscall/copy.h>
    5050#include <adt/btree.h>
     
    5454
    5555/** This lock protects the parea_btree. */
    56 SPINLOCK_INITIALIZE(parea_lock);
     56static mutex_t parea_lock;
    5757
    5858/** B+tree with enabled physical memory areas. */
     
    6363{
    6464        btree_create(&parea_btree);
     65        mutex_initialize(&parea_lock, MUTEX_PASSIVE);
    6566}
    6667
     
    7273void ddi_parea_register(parea_t *parea)
    7374{
    74         ipl_t ipl = interrupts_disable();
    75         spinlock_lock(&parea_lock);
     75        mutex_lock(&parea_lock);
    7676       
    7777        /*
     
    8080        btree_insert(&parea_btree, (btree_key_t) parea->pbase, parea, NULL);
    8181       
    82         spinlock_unlock(&parea_lock);
    83         interrupts_restore(ipl);
     82        mutex_unlock(&parea_lock);
    8483}
    8584
     
    141140                spinlock_unlock(&zones.lock);
    142141               
    143                 spinlock_lock(&parea_lock);
     142                mutex_lock(&parea_lock);
    144143                btree_node_t *nodep;
    145144                parea_t *parea = (parea_t *) btree_search(&parea_btree,
     
    147146               
    148147                if ((!parea) || (parea->frames < pages)) {
    149                         spinlock_unlock(&parea_lock);
     148                        mutex_unlock(&parea_lock);
    150149                        goto err;
    151150                }
    152151               
    153                 spinlock_unlock(&parea_lock);
     152                mutex_unlock(&parea_lock);
    154153                goto map;
    155154        }
     
    161160       
    162161map:
    163         spinlock_lock(&TASK->lock);
    164        
     162        interrupts_restore(ipl);
     163
    165164        if (!as_area_create(TASK->as, flags, pages * PAGE_SIZE, vp,
    166165            AS_AREA_ATTR_NONE, &phys_backend, &backend_data)) {
     
    169168                 * We report it using ENOMEM.
    170169                 */
    171                 spinlock_unlock(&TASK->lock);
    172                 interrupts_restore(ipl);
    173170                return ENOMEM;
    174171        }
     
    177174         * Mapping is created on-demand during page fault.
    178175         */
    179        
    180         spinlock_unlock(&TASK->lock);
    181         interrupts_restore(ipl);
    182176        return 0;
    183177}
  • kernel/generic/src/mm/frame.c

    rb8f7ea78 rc2ab3f4  
    10331033                spinlock_unlock(&zones.lock);
    10341034                interrupts_restore(ipl);
     1035
     1036                if (!THREAD)
     1037                        panic("Cannot wait for memory to become available.");
    10351038               
    10361039                /*
  • kernel/generic/src/mm/slab.c

    rb8f7ea78 rc2ab3f4  
    555555 * Initialize mag_cache structure in slab cache
    556556 */
    557 static void make_magcache(slab_cache_t *cache)
     557static bool make_magcache(slab_cache_t *cache)
    558558{
    559559        unsigned int i;
     
    562562
    563563        cache->mag_cache = malloc(sizeof(slab_mag_cache_t) * config.cpu_count,
    564             0);
     564            FRAME_ATOMIC);
     565        if (!cache->mag_cache)
     566                return false;
     567
    565568        for (i = 0; i < config.cpu_count; i++) {
    566569                memsetb(&cache->mag_cache[i], sizeof(cache->mag_cache[i]), 0);
     
    568571                    "slab_maglock_cpu");
    569572        }
     573        return true;
    570574}
    571575
     
    597601        spinlock_initialize(&cache->maglock, "slab_maglock");
    598602        if (!(cache->flags & SLAB_CACHE_NOMAGAZINE))
    599                 make_magcache(cache);
     603                (void) make_magcache(cache);
    600604
    601605        /* Compute slab sizes, object counts in slabs etc. */
     
    923927                    SLAB_CACHE_MAGDEFERRED)
    924928                        continue;
    925                 make_magcache(s);
     929                (void) make_magcache(s);
    926930                s->flags &= ~SLAB_CACHE_MAGDEFERRED;
    927931        }
  • kernel/generic/src/synch/mutex.c

    rb8f7ea78 rc2ab3f4  
    4040#include <synch/synch.h>
    4141#include <debug.h>
     42#include <arch.h>
    4243
    4344/** Initialize mutex.
     
    6970        int rc;
    7071
    71         if (mtx->type == MUTEX_PASSIVE) {
     72        if (mtx->type == MUTEX_PASSIVE && THREAD) {
    7273                rc = _semaphore_down_timeout(&mtx->sem, usec, flags);
    7374        } else {
    74                 ASSERT(mtx->type == MUTEX_ACTIVE);
     75                ASSERT(mtx->type == MUTEX_ACTIVE || !THREAD);
    7576                ASSERT(usec == SYNCH_NO_TIMEOUT);
    7677                ASSERT(!(flags & SYNCH_FLAGS_INTERRUPTIBLE));
  • kernel/generic/src/sysinfo/stats.c

    rb8f7ea78 rc2ab3f4  
    3838#include <sysinfo/stats.h>
    3939#include <sysinfo/sysinfo.h>
     40#include <synch/spinlock.h>
     41#include <synch/mutex.h>
    4042#include <time/clock.h>
    4143#include <mm/frame.h>
     
    6870static load_t avenrdy[LOAD_STEPS] = {0, 0, 0};
    6971
    70 /** Load calculation spinlock */
    71 SPINLOCK_STATIC_INITIALIZE_NAME(load_lock, "load_lock");
     72/** Load calculation lock */
     73static mutex_t load_lock;
    7274
    7375/** Get system uptime
     
    344346       
    345347        /* Interrupts are already disabled */
    346         spinlock_lock(&(thread->lock));
     348        spinlock_lock(&thread->lock);
    347349       
    348350        /* Record the statistics and increment the iterator */
     
    350352        (*iterator)++;
    351353       
    352         spinlock_unlock(&(thread->lock));
     354        spinlock_unlock(&thread->lock);
    353355       
    354356        return true;
     
    615617        }
    616618       
    617         /* To always get consistent values acquire the spinlock */
    618         ipl_t ipl = interrupts_disable();
    619         spinlock_lock(&load_lock);
     619        /* To always get consistent values acquire the mutex */
     620        mutex_lock(&load_lock);
    620621       
    621622        unsigned int i;
     
    623624                stats_load[i] = avenrdy[i] << LOAD_FIXED_SHIFT;
    624625       
    625         spinlock_unlock(&load_lock);
    626         interrupts_restore(ipl);
     626        mutex_unlock(&load_lock);
    627627       
    628628        return ((void *) stats_load);
     
    655655               
    656656                /* Mutually exclude with get_stats_load() */
    657                 ipl_t ipl = interrupts_disable();
    658                 spinlock_lock(&load_lock);
     657                mutex_lock(&load_lock);
    659658               
    660659                unsigned int i;
     
    662661                        avenrdy[i] = load_calc(avenrdy[i], load_exp[i], ready);
    663662               
    664                 spinlock_unlock(&load_lock);
    665                 interrupts_restore(ipl);
     663                mutex_unlock(&load_lock);
    666664               
    667665                thread_sleep(LOAD_INTERVAL);
     
    674672void stats_init(void)
    675673{
     674        mutex_initialize(&load_lock, MUTEX_PASSIVE);
     675
    676676        sysinfo_set_item_fn_val("system.uptime", NULL, get_stats_uptime);
    677677        sysinfo_set_item_fn_data("system.cpus", NULL, get_stats_cpus);
  • kernel/generic/src/sysinfo/sysinfo.c

    rb8f7ea78 rc2ab3f4  
    3737#include <print.h>
    3838#include <syscall/copy.h>
    39 #include <synch/spinlock.h>
     39#include <synch/mutex.h>
    4040#include <arch/asm.h>
    4141#include <errno.h>
     
    5252static slab_cache_t *sysinfo_item_slab;
    5353
    54 /** Sysinfo spinlock */
    55 SPINLOCK_STATIC_INITIALIZE_NAME(sysinfo_lock, "sysinfo_lock");
     54/** Sysinfo lock */
     55static mutex_t sysinfo_lock;
    5656
    5757/** Sysinfo item constructor
     
    9898            sizeof(sysinfo_item_t), 0, sysinfo_item_constructor,
    9999            sysinfo_item_destructor, SLAB_CACHE_MAGDEFERRED);
     100
     101        mutex_initialize(&sysinfo_lock, MUTEX_ACTIVE);
    100102}
    101103
    102104/** Recursively find an item in sysinfo tree
    103105 *
    104  * Should be called with interrupts disabled
    105  * and sysinfo_lock held.
     106 * Should be called with sysinfo_lock held.
    106107 *
    107108 * @param name    Current sysinfo path suffix.
     
    168169/** Recursively create items in sysinfo tree
    169170 *
    170  * Should be called with interrupts disabled
    171  * and sysinfo_lock held.
     171 * Should be called with sysinfo_lock held.
    172172 *
    173173 * @param name     Current sysinfo path suffix.
     
    299299{
    300300        /* Protect sysinfo tree consistency */
    301         ipl_t ipl = interrupts_disable();
    302         spinlock_lock(&sysinfo_lock);
     301        mutex_lock(&sysinfo_lock);
    303302       
    304303        if (root == NULL)
     
    311310        }
    312311       
    313         spinlock_unlock(&sysinfo_lock);
    314         interrupts_restore(ipl);
     312        mutex_unlock(&sysinfo_lock);
    315313}
    316314
     
    332330{
    333331        /* Protect sysinfo tree consistency */
    334         ipl_t ipl = interrupts_disable();
    335         spinlock_lock(&sysinfo_lock);
     332        mutex_lock(&sysinfo_lock);
    336333       
    337334        if (root == NULL)
     
    345342        }
    346343       
    347         spinlock_unlock(&sysinfo_lock);
    348         interrupts_restore(ipl);
     344        mutex_unlock(&sysinfo_lock);
    349345}
    350346
     
    361357{
    362358        /* Protect sysinfo tree consistency */
    363         ipl_t ipl = interrupts_disable();
    364         spinlock_lock(&sysinfo_lock);
     359        mutex_lock(&sysinfo_lock);
    365360       
    366361        if (root == NULL)
     
    373368        }
    374369       
    375         spinlock_unlock(&sysinfo_lock);
    376         interrupts_restore(ipl);
     370        mutex_unlock(&sysinfo_lock);
    377371}
    378372
     
    394388{
    395389        /* Protect sysinfo tree consistency */
    396         ipl_t ipl = interrupts_disable();
    397         spinlock_lock(&sysinfo_lock);
     390        mutex_lock(&sysinfo_lock);
    398391       
    399392        if (root == NULL)
     
    406399        }
    407400       
    408         spinlock_unlock(&sysinfo_lock);
    409         interrupts_restore(ipl);
     401        mutex_unlock(&sysinfo_lock);
    410402}
    411403
     
    420412{
    421413        /* Protect sysinfo tree consistency */
    422         ipl_t ipl = interrupts_disable();
    423         spinlock_lock(&sysinfo_lock);
     414        mutex_lock(&sysinfo_lock);
    424415       
    425416        if (root == NULL)
     
    430421                item->val_type = SYSINFO_VAL_UNDEFINED;
    431422       
    432         spinlock_unlock(&sysinfo_lock);
    433         interrupts_restore(ipl);
     423        mutex_unlock(&sysinfo_lock);
    434424}
    435425
     
    446436{
    447437        /* Protect sysinfo tree consistency */
    448         ipl_t ipl = interrupts_disable();
    449         spinlock_lock(&sysinfo_lock);
     438        mutex_lock(&sysinfo_lock);
    450439       
    451440        if (root == NULL)
     
    461450        }
    462451       
    463         spinlock_unlock(&sysinfo_lock);
    464         interrupts_restore(ipl);
     452        mutex_unlock(&sysinfo_lock);
    465453}
    466454
     
    479467/** Dump the structure of sysinfo tree
    480468 *
    481  * Should be called with interrupts disabled
    482  * and sysinfo_lock held. Because this routine
    483  * might take a reasonable long time to proceed,
    484  * having the spinlock held is not optimal, but
    485  * there is no better simple solution.
     469 * Should be called with sysinfo_lock held.
    486470 *
    487471 * @param root  Root item of the current (sub)tree.
     
    559543        /* Avoid other functions to mess with sysinfo
    560544           while we are dumping it */
    561         ipl_t ipl = interrupts_disable();
    562         spinlock_lock(&sysinfo_lock);
     545        mutex_lock(&sysinfo_lock);
    563546       
    564547        if (root == NULL)
     
    567550                sysinfo_dump_internal(root, 0);
    568551       
    569         spinlock_unlock(&sysinfo_lock);
    570         interrupts_restore(ipl);
     552        mutex_unlock(&sysinfo_lock);
    571553}
    572554
    573555/** Return sysinfo item value determined by name
    574556 *
    575  * Should be called with interrupts disabled
    576  * and sysinfo_lock held.
     557 * Should be called with sysinfo_lock held.
    577558 *
    578559 * @param name    Sysinfo path.
     
    659640                 * are reading it.
    660641                 */
    661                 ipl_t ipl = interrupts_disable();
    662                 spinlock_lock(&sysinfo_lock);
     642                mutex_lock(&sysinfo_lock);
    663643                ret = sysinfo_get_item(path, NULL, dry_run);
    664                 spinlock_unlock(&sysinfo_lock);
    665                 interrupts_restore(ipl);
     644                mutex_unlock(&sysinfo_lock);
    666645        }
    667646        free(path);
Note: See TracChangeset for help on using the changeset viewer.