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

Ignore:
Timestamp:
2010-05-08T07:53:23Z (12 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master
Children:
051bc69a
Parents:
6c39a907 (diff), 1317380 (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 mainline changes.

File:
1 edited

Legend:

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

    r6c39a907 r25a76ab8  
    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.
     
    632613/** Return sysinfo item determined by name from user space
    633614 *
    634  * Should be called with interrupts disabled
    635  * and sysinfo_lock held. The path string passed from
    636  * the user space has to be properly null-terminated
     615 * The path string passed from the user space has to be properly null-terminated
    637616 * (the last passed character must be null).
    638617 *
     
    656635       
    657636        if ((copy_from_uspace(path, ptr, size + 1) == 0)
    658             && (path[size] == 0))
     637            && (path[size] == 0)) {
     638                /*
     639                 * Prevent other functions from messing with sysinfo while we
     640                 * are reading it.
     641                 */
     642                mutex_lock(&sysinfo_lock);
    659643                ret = sysinfo_get_item(path, NULL, dry_run);
    660        
     644                mutex_unlock(&sysinfo_lock);
     645        }
    661646        free(path);
    662647        return ret;
     
    677662unative_t sys_sysinfo_get_tag(void *path_ptr, size_t path_size)
    678663{
    679         /* Avoid other functions to mess with sysinfo
    680            while we are reading it */
    681         ipl_t ipl = interrupts_disable();
    682         spinlock_lock(&sysinfo_lock);
    683        
    684         /* Get the item.
    685        
    686            N.B.: There is no need to free any potential generated
    687            binary data since we request a dry run */
     664        /*
     665         * Get the item.
     666         *
     667         * N.B.: There is no need to free any potential generated
     668         * binary data since we request a dry run.
     669         */
    688670        sysinfo_return_t ret = sysinfo_get_item_uspace(path_ptr, path_size, true);
    689671       
    690         /* Map generated value types to constant types
    691            (user space does not care whether the
    692            value is constant or generated) */
     672        /*
     673         * Map generated value types to constant types (user space does not care
     674         * whether the value is constant or generated).
     675         */
    693676        if (ret.tag == SYSINFO_VAL_FUNCTION_VAL)
    694677                ret.tag = SYSINFO_VAL_VAL;
     
    696679                ret.tag = SYSINFO_VAL_DATA;
    697680       
    698         spinlock_unlock(&sysinfo_lock);
    699         interrupts_restore(ipl);
    700        
    701681        return (unative_t) ret.tag;
    702682}
     
    719699    void *value_ptr)
    720700{
    721         /* Avoid other functions to mess with sysinfo
    722            while we are reading it */
    723         ipl_t ipl = interrupts_disable();
    724         spinlock_lock(&sysinfo_lock);
    725        
    726         /* Get the item.
    727        
    728            N.B.: There is no need to free any potential generated
    729            binary data since we request a dry run */
     701        int rc;
     702
     703        /*
     704         * Get the item.
     705         *
     706         * N.B.: There is no need to free any potential generated binary data
     707         * since we request a dry run.
     708         */
    730709        sysinfo_return_t ret = sysinfo_get_item_uspace(path_ptr, path_size, true);
    731         int rc;
    732710       
    733711        /* Only constant or generated numerical value is returned */
     
    737715                rc = EINVAL;
    738716       
    739         spinlock_unlock(&sysinfo_lock);
    740         interrupts_restore(ipl);
    741        
    742717        return (unative_t) rc;
    743718}
     
    760735    void *size_ptr)
    761736{
    762         /* Avoid other functions to mess with sysinfo
    763            while we are reading it */
    764         ipl_t ipl = interrupts_disable();
    765         spinlock_lock(&sysinfo_lock);
    766        
    767         /* Get the item.
    768        
    769            N.B.: There is no need to free any potential generated
    770            binary data since we request a dry run */
     737        int rc;
     738       
     739        /*
     740         * Get the item.
     741         *
     742         * N.B.: There is no need to free any potential generated binary data
     743         * since we request a dry run.
     744         */
    771745        sysinfo_return_t ret = sysinfo_get_item_uspace(path_ptr, path_size, true);
    772         int rc;
    773746       
    774747        /* Only the size of constant or generated binary data is considered */
     
    779752                rc = EINVAL;
    780753       
    781         spinlock_unlock(&sysinfo_lock);
    782         interrupts_restore(ipl);
    783        
    784754        return (unative_t) rc;
    785755}
     
    807777    void *buffer_ptr, size_t buffer_size)
    808778{
    809         /* Avoid other functions to mess with sysinfo
    810            while we are reading it */
    811         ipl_t ipl = interrupts_disable();
    812         spinlock_lock(&sysinfo_lock);
     779        int rc;
    813780       
    814781        /* Get the item */
    815782        sysinfo_return_t ret = sysinfo_get_item_uspace(path_ptr, path_size, false);
    816         int rc;
    817        
     783
    818784        /* Only constant or generated binary data is considered */
    819785        if ((ret.tag == SYSINFO_VAL_DATA) || (ret.tag == SYSINFO_VAL_FUNCTION_DATA)) {
     
    831797                free(ret.data.data);
    832798       
    833         spinlock_unlock(&sysinfo_lock);
    834         interrupts_restore(ipl);
    835        
    836799        return (unative_t) rc;
    837800}
Note: See TracChangeset for help on using the changeset viewer.