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

Changeset 6e121b8 in mainline


Ignore:
Timestamp:
2010-04-28T19:55:35Z (12 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master
Children:
c6218327
Parents:
6b6626d
Message:

Load lock can be mutex a interrupts are not required to be disabled when taking it.

File:
1 edited

Legend:

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

    r6b6626d r6e121b8  
    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);
Note: See TracChangeset for help on using the changeset viewer.