Ignore:
File:
1 edited

Legend:

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

    r6e121b8 r9efff92  
    3838#include <sysinfo/stats.h>
    3939#include <sysinfo/sysinfo.h>
    40 #include <synch/spinlock.h>
    41 #include <synch/mutex.h>
    4240#include <time/clock.h>
    4341#include <mm/frame.h>
     
    7068static load_t avenrdy[LOAD_STEPS] = {0, 0, 0};
    7169
    72 /** Load calculation lock */
    73 static mutex_t load_lock;
     70/** Load calculation spinlock */
     71SPINLOCK_STATIC_INITIALIZE_NAME(load_lock, "load_lock");
    7472
    7573/** Get system uptime
     
    158156static size_t get_task_virtmem(as_t *as)
    159157{
     158        mutex_lock(&as->lock);
     159       
    160160        size_t result = 0;
    161 
    162         /*
    163          * We are holding some spinlocks here and therefore are not allowed to
    164          * block. Only attempt to lock the address space and address space area
    165          * mutexes conditionally. If it is not possible to lock either object,
    166          * allow the statistics to be inexact by skipping the respective object.
    167          *
    168          * Note that it may be infinitely better to let the address space
    169          * management code compute these statistics as it proceeds instead of
    170          * having them calculated here over and over again here.
    171          */
    172 
    173         if (SYNCH_FAILED(mutex_trylock(&as->lock)))
    174                 return result * PAGE_SIZE;
    175161       
    176162        /* Walk the B+ tree and count pages */
     
    185171                        as_area_t *area = node->value[i];
    186172                       
    187                         if (SYNCH_FAILED(mutex_trylock(&area->lock)))
    188                                 continue;
     173                        mutex_lock(&area->lock);
    189174                        result += area->pages;
    190175                        mutex_unlock(&area->lock);
     
    346331       
    347332        /* Interrupts are already disabled */
    348         spinlock_lock(&thread->lock);
     333        spinlock_lock(&(thread->lock));
    349334       
    350335        /* Record the statistics and increment the iterator */
     
    352337        (*iterator)++;
    353338       
    354         spinlock_unlock(&thread->lock);
     339        spinlock_unlock(&(thread->lock));
    355340       
    356341        return true;
     
    617602        }
    618603       
    619         /* To always get consistent values acquire the mutex */
    620         mutex_lock(&load_lock);
     604        /* To always get consistent values acquire the spinlock */
     605        ipl_t ipl = interrupts_disable();
     606        spinlock_lock(&load_lock);
    621607       
    622608        unsigned int i;
     
    624610                stats_load[i] = avenrdy[i] << LOAD_FIXED_SHIFT;
    625611       
    626         mutex_unlock(&load_lock);
     612        spinlock_unlock(&load_lock);
     613        interrupts_restore(ipl);
    627614       
    628615        return ((void *) stats_load);
     
    655642               
    656643                /* Mutually exclude with get_stats_load() */
    657                 mutex_lock(&load_lock);
     644                ipl_t ipl = interrupts_disable();
     645                spinlock_lock(&load_lock);
    658646               
    659647                unsigned int i;
     
    661649                        avenrdy[i] = load_calc(avenrdy[i], load_exp[i], ready);
    662650               
    663                 mutex_unlock(&load_lock);
     651                spinlock_unlock(&load_lock);
     652                interrupts_restore(ipl);
    664653               
    665654                thread_sleep(LOAD_INTERVAL);
     
    672661void stats_init(void)
    673662{
    674         mutex_initialize(&load_lock, MUTEX_PASSIVE);
    675 
    676663        sysinfo_set_item_fn_val("system.uptime", NULL, get_stats_uptime);
    677664        sysinfo_set_item_fn_data("system.cpus", NULL, get_stats_cpus);
Note: See TracChangeset for help on using the changeset viewer.