Changes in kernel/generic/src/sysinfo/stats.c [9efff92:6e121b8] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/sysinfo/stats.c
r9efff92 r6e121b8 38 38 #include <sysinfo/stats.h> 39 39 #include <sysinfo/sysinfo.h> 40 #include <synch/spinlock.h> 41 #include <synch/mutex.h> 40 42 #include <time/clock.h> 41 43 #include <mm/frame.h> … … 68 70 static load_t avenrdy[LOAD_STEPS] = {0, 0, 0}; 69 71 70 /** Load calculation spinlock */71 SPINLOCK_STATIC_INITIALIZE_NAME(load_lock, "load_lock");72 /** Load calculation lock */ 73 static mutex_t load_lock; 72 74 73 75 /** Get system uptime … … 156 158 static size_t get_task_virtmem(as_t *as) 157 159 { 158 mutex_lock(&as->lock);159 160 160 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; 161 175 162 176 /* Walk the B+ tree and count pages */ … … 171 185 as_area_t *area = node->value[i]; 172 186 173 mutex_lock(&area->lock); 187 if (SYNCH_FAILED(mutex_trylock(&area->lock))) 188 continue; 174 189 result += area->pages; 175 190 mutex_unlock(&area->lock); … … 331 346 332 347 /* Interrupts are already disabled */ 333 spinlock_lock(& (thread->lock));348 spinlock_lock(&thread->lock); 334 349 335 350 /* Record the statistics and increment the iterator */ … … 337 352 (*iterator)++; 338 353 339 spinlock_unlock(& (thread->lock));354 spinlock_unlock(&thread->lock); 340 355 341 356 return true; … … 602 617 } 603 618 604 /* To always get consistent values acquire the spinlock */ 605 ipl_t ipl = interrupts_disable(); 606 spinlock_lock(&load_lock); 619 /* To always get consistent values acquire the mutex */ 620 mutex_lock(&load_lock); 607 621 608 622 unsigned int i; … … 610 624 stats_load[i] = avenrdy[i] << LOAD_FIXED_SHIFT; 611 625 612 spinlock_unlock(&load_lock); 613 interrupts_restore(ipl); 626 mutex_unlock(&load_lock); 614 627 615 628 return ((void *) stats_load); … … 642 655 643 656 /* Mutually exclude with get_stats_load() */ 644 ipl_t ipl = interrupts_disable(); 645 spinlock_lock(&load_lock); 657 mutex_lock(&load_lock); 646 658 647 659 unsigned int i; … … 649 661 avenrdy[i] = load_calc(avenrdy[i], load_exp[i], ready); 650 662 651 spinlock_unlock(&load_lock); 652 interrupts_restore(ipl); 663 mutex_unlock(&load_lock); 653 664 654 665 thread_sleep(LOAD_INTERVAL); … … 661 672 void stats_init(void) 662 673 { 674 mutex_initialize(&load_lock, MUTEX_PASSIVE); 675 663 676 sysinfo_set_item_fn_val("system.uptime", NULL, get_stats_uptime); 664 677 sysinfo_set_item_fn_data("system.cpus", NULL, get_stats_cpus);
Note:
See TracChangeset
for help on using the changeset viewer.