Ignore:
File:
1 edited

Legend:

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

    rfc47885 r96b02eb9  
    160160static size_t get_task_virtmem(as_t *as)
    161161{
     162        size_t result = 0;
     163
    162164        /*
    163          * We are holding spinlocks here and therefore are not allowed to
    164          * block. Only attempt to lock the address space and address space
    165          * area mutexes conditionally. If it is not possible to lock either
    166          * object, return inexact statistics by skipping the respective object.
     165         * We are holding some spinlocks here and therefore are not allowed to
     166         * block. Only attempt to lock the address space and address space area
     167         * mutexes conditionally. If it is not possible to lock either object,
     168         * allow the statistics to be inexact by skipping the respective object.
     169         *
     170         * Note that it may be infinitely better to let the address space
     171         * management code compute these statistics as it proceeds instead of
     172         * having them calculated here over and over again here.
    167173         */
    168        
     174
    169175        if (SYNCH_FAILED(mutex_trylock(&as->lock)))
    170                 return 0;
    171        
    172         size_t pages = 0;
     176                return result * PAGE_SIZE;
    173177       
    174178        /* Walk the B+ tree and count pages */
     
    185189                        if (SYNCH_FAILED(mutex_trylock(&area->lock)))
    186190                                continue;
    187                        
    188                         pages += area->pages;
     191                        result += area->pages;
    189192                        mutex_unlock(&area->lock);
    190193                }
     
    193196        mutex_unlock(&as->lock);
    194197       
    195         return (pages << PAGE_WIDTH);
    196 }
    197 
    198 /** Get the resident (used) size of a virtual address space
    199  *
    200  * @param as Address space.
    201  *
    202  * @return Size of the resident (used) virtual address space (bytes).
    203  *
    204  */
    205 static size_t get_task_resmem(as_t *as)
    206 {
    207         /*
    208          * We are holding spinlocks here and therefore are not allowed to
    209          * block. Only attempt to lock the address space and address space
    210          * area mutexes conditionally. If it is not possible to lock either
    211          * object, return inexact statistics by skipping the respective object.
    212          */
    213        
    214         if (SYNCH_FAILED(mutex_trylock(&as->lock)))
    215                 return 0;
    216        
    217         size_t pages = 0;
    218        
    219         /* Walk the B+ tree and count pages */
    220         link_t *cur;
    221         for (cur = as->as_area_btree.leaf_head.next;
    222             cur != &as->as_area_btree.leaf_head; cur = cur->next) {
    223                 btree_node_t *node =
    224                     list_get_instance(cur, btree_node_t, leaf_link);
    225                
    226                 unsigned int i;
    227                 for (i = 0; i < node->keys; i++) {
    228                         as_area_t *area = node->value[i];
    229                        
    230                         if (SYNCH_FAILED(mutex_trylock(&area->lock)))
    231                                 continue;
    232                        
    233                         pages += area->resident;
    234                         mutex_unlock(&area->lock);
    235                 }
    236         }
    237        
    238         mutex_unlock(&as->lock);
    239        
    240         return (pages << PAGE_WIDTH);
     198        return result * PAGE_SIZE;
    241199}
    242200
     
    257215        str_cpy(stats_task->name, TASK_NAME_BUFLEN, task->name);
    258216        stats_task->virtmem = get_task_virtmem(task->as);
    259         stats_task->resmem = get_task_resmem(task->as);
    260217        stats_task->threads = atomic_get(&task->refcount);
    261218        task_get_accounting(task, &(stats_task->ucycles),
Note: See TracChangeset for help on using the changeset viewer.