Ignore:
File:
1 edited

Legend:

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

    rc6218327 re1b6742  
    3737#include <print.h>
    3838#include <syscall/copy.h>
    39 #include <synch/mutex.h>
     39#include <synch/spinlock.h>
    4040#include <arch/asm.h>
    4141#include <errno.h>
     
    5252static slab_cache_t *sysinfo_item_slab;
    5353
    54 /** Sysinfo lock */
    55 static mutex_t sysinfo_lock;
     54/** Sysinfo spinlock */
     55SPINLOCK_STATIC_INITIALIZE_NAME(sysinfo_lock, "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);
    102100}
    103101
    104102/** Recursively find an item in sysinfo tree
    105103 *
    106  * Should be called with sysinfo_lock held.
     104 * Should be called with interrupts disabled
     105 * and sysinfo_lock held.
    107106 *
    108107 * @param name    Current sysinfo path suffix.
     
    169168/** Recursively create items in sysinfo tree
    170169 *
    171  * Should be called with sysinfo_lock held.
     170 * Should be called with interrupts disabled
     171 * and sysinfo_lock held.
    172172 *
    173173 * @param name     Current sysinfo path suffix.
     
    299299{
    300300        /* Protect sysinfo tree consistency */
    301         mutex_lock(&sysinfo_lock);
     301        ipl_t ipl = interrupts_disable();
     302        spinlock_lock(&sysinfo_lock);
    302303       
    303304        if (root == NULL)
     
    310311        }
    311312       
    312         mutex_unlock(&sysinfo_lock);
     313        spinlock_unlock(&sysinfo_lock);
     314        interrupts_restore(ipl);
    313315}
    314316
     
    330332{
    331333        /* Protect sysinfo tree consistency */
    332         mutex_lock(&sysinfo_lock);
     334        ipl_t ipl = interrupts_disable();
     335        spinlock_lock(&sysinfo_lock);
    333336       
    334337        if (root == NULL)
     
    342345        }
    343346       
    344         mutex_unlock(&sysinfo_lock);
     347        spinlock_unlock(&sysinfo_lock);
     348        interrupts_restore(ipl);
    345349}
    346350
     
    357361{
    358362        /* Protect sysinfo tree consistency */
    359         mutex_lock(&sysinfo_lock);
     363        ipl_t ipl = interrupts_disable();
     364        spinlock_lock(&sysinfo_lock);
    360365       
    361366        if (root == NULL)
     
    368373        }
    369374       
    370         mutex_unlock(&sysinfo_lock);
     375        spinlock_unlock(&sysinfo_lock);
     376        interrupts_restore(ipl);
    371377}
    372378
     
    388394{
    389395        /* Protect sysinfo tree consistency */
    390         mutex_lock(&sysinfo_lock);
     396        ipl_t ipl = interrupts_disable();
     397        spinlock_lock(&sysinfo_lock);
    391398       
    392399        if (root == NULL)
     
    399406        }
    400407       
    401         mutex_unlock(&sysinfo_lock);
     408        spinlock_unlock(&sysinfo_lock);
     409        interrupts_restore(ipl);
    402410}
    403411
     
    412420{
    413421        /* Protect sysinfo tree consistency */
    414         mutex_lock(&sysinfo_lock);
     422        ipl_t ipl = interrupts_disable();
     423        spinlock_lock(&sysinfo_lock);
    415424       
    416425        if (root == NULL)
     
    421430                item->val_type = SYSINFO_VAL_UNDEFINED;
    422431       
    423         mutex_unlock(&sysinfo_lock);
     432        spinlock_unlock(&sysinfo_lock);
     433        interrupts_restore(ipl);
    424434}
    425435
     
    436446{
    437447        /* Protect sysinfo tree consistency */
    438         mutex_lock(&sysinfo_lock);
     448        ipl_t ipl = interrupts_disable();
     449        spinlock_lock(&sysinfo_lock);
    439450       
    440451        if (root == NULL)
     
    450461        }
    451462       
    452         mutex_unlock(&sysinfo_lock);
     463        spinlock_unlock(&sysinfo_lock);
     464        interrupts_restore(ipl);
    453465}
    454466
     
    467479/** Dump the structure of sysinfo tree
    468480 *
    469  * Should be called with sysinfo_lock held.
     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.
    470486 *
    471487 * @param root  Root item of the current (sub)tree.
     
    543559        /* Avoid other functions to mess with sysinfo
    544560           while we are dumping it */
    545         mutex_lock(&sysinfo_lock);
     561        ipl_t ipl = interrupts_disable();
     562        spinlock_lock(&sysinfo_lock);
    546563       
    547564        if (root == NULL)
     
    550567                sysinfo_dump_internal(root, 0);
    551568       
    552         mutex_unlock(&sysinfo_lock);
     569        spinlock_unlock(&sysinfo_lock);
     570        interrupts_restore(ipl);
    553571}
    554572
    555573/** Return sysinfo item value determined by name
    556574 *
    557  * Should be called with sysinfo_lock held.
     575 * Should be called with interrupts disabled
     576 * and sysinfo_lock held.
    558577 *
    559578 * @param name    Sysinfo path.
     
    613632/** Return sysinfo item determined by name from user space
    614633 *
    615  * The path string passed from the user space has to be properly null-terminated
     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
    616637 * (the last passed character must be null).
    617638 *
     
    635656       
    636657        if ((copy_from_uspace(path, ptr, size + 1) == 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);
     658            && (path[size] == 0))
    643659                ret = sysinfo_get_item(path, NULL, dry_run);
    644                 mutex_unlock(&sysinfo_lock);
    645         }
     660       
    646661        free(path);
    647662        return ret;
     
    662677unative_t sys_sysinfo_get_tag(void *path_ptr, size_t path_size)
    663678{
    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          */
     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 */
    670688        sysinfo_return_t ret = sysinfo_get_item_uspace(path_ptr, path_size, true);
    671689       
    672         /*
    673          * Map generated value types to constant types (user space does not care
    674          * whether the value is constant or generated).
    675          */
     690        /* Map generated value types to constant types
     691           (user space does not care whether the
     692           value is constant or generated) */
    676693        if (ret.tag == SYSINFO_VAL_FUNCTION_VAL)
    677694                ret.tag = SYSINFO_VAL_VAL;
     
    679696                ret.tag = SYSINFO_VAL_DATA;
    680697       
     698        spinlock_unlock(&sysinfo_lock);
     699        interrupts_restore(ipl);
     700       
    681701        return (unative_t) ret.tag;
    682702}
     
    699719    void *value_ptr)
    700720{
     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 */
     730        sysinfo_return_t ret = sysinfo_get_item_uspace(path_ptr, path_size, true);
    701731        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          */
    709         sysinfo_return_t ret = sysinfo_get_item_uspace(path_ptr, path_size, true);
    710732       
    711733        /* Only constant or generated numerical value is returned */
     
    715737                rc = EINVAL;
    716738       
     739        spinlock_unlock(&sysinfo_lock);
     740        interrupts_restore(ipl);
     741       
    717742        return (unative_t) rc;
    718743}
     
    735760    void *size_ptr)
    736761{
     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 */
     771        sysinfo_return_t ret = sysinfo_get_item_uspace(path_ptr, path_size, true);
    737772        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          */
    745         sysinfo_return_t ret = sysinfo_get_item_uspace(path_ptr, path_size, true);
    746773       
    747774        /* Only the size of constant or generated binary data is considered */
     
    752779                rc = EINVAL;
    753780       
     781        spinlock_unlock(&sysinfo_lock);
     782        interrupts_restore(ipl);
     783       
    754784        return (unative_t) rc;
    755785}
     
    777807    void *buffer_ptr, size_t buffer_size)
    778808{
    779         int rc;
     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);
    780813       
    781814        /* Get the item */
    782815        sysinfo_return_t ret = sysinfo_get_item_uspace(path_ptr, path_size, false);
    783 
     816        int rc;
     817       
    784818        /* Only constant or generated binary data is considered */
    785819        if ((ret.tag == SYSINFO_VAL_DATA) || (ret.tag == SYSINFO_VAL_FUNCTION_DATA)) {
     
    797831                free(ret.data.data);
    798832       
     833        spinlock_unlock(&sysinfo_lock);
     834        interrupts_restore(ipl);
     835       
    799836        return (unative_t) rc;
    800837}
Note: See TracChangeset for help on using the changeset viewer.