Ignore:
File:
1 edited

Legend:

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

    rfc47885 ra0ce870  
    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 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 */
     179        link_t *cur;
     180        for (cur = as->as_area_btree.leaf_head.next;
     181            cur != &as->as_area_btree.leaf_head; cur = cur->next) {
     182                btree_node_t *node =
     183                    list_get_instance(cur, btree_node_t, leaf_link);
     184               
     185                unsigned int i;
     186                for (i = 0; i < node->keys; i++) {
     187                        as_area_t *area = node->value[i];
     188                       
     189                        if (SYNCH_FAILED(mutex_trylock(&area->lock)))
     190                                continue;
     191                        result += area->pages;
     192                        mutex_unlock(&area->lock);
     193                }
     194        }
     195       
     196        mutex_unlock(&as->lock);
     197       
     198        return result * PAGE_SIZE;
     199}
     200
     201/** Get the resident (used) size of a virtual address space
     202 *
     203 * @param as Address space.
     204 *
     205 * @return Size of the resident (used) virtual address space (bytes).
     206 *
     207 */
     208static size_t get_task_resmem(as_t *as)
     209{
     210        size_t result = 0;
     211       
     212        /*
     213         * We are holding some spinlocks here and therefore are not allowed to
     214         * block. Only attempt to lock the address space and address space area
     215         * mutexes conditionally. If it is not possible to lock either object,
     216         * allow the statistics to be inexact by skipping the respective object.
     217         *
     218         * Note that it may be infinitely better to let the address space
     219         * management code compute these statistics as it proceeds instead of
     220         * having them calculated over and over again here.
     221         */
     222       
     223        if (SYNCH_FAILED(mutex_trylock(&as->lock)))
     224                return result * PAGE_SIZE;
     225       
     226        /* Walk the B+ tree of AS areas */
    175227        link_t *cur;
    176228        for (cur = as->as_area_btree.leaf_head.next;
     
    186238                                continue;
    187239                       
    188                         pages += area->pages;
     240                        /* Walk the B+ tree of resident pages */
     241                        link_t *rcur;
     242                        for (rcur = area->used_space.leaf_head.next;
     243                            rcur != &area->used_space.leaf_head; rcur = rcur->next) {
     244                                btree_node_t *rnode =
     245                                    list_get_instance(rcur, btree_node_t, leaf_link);
     246                               
     247                                unsigned int j;
     248                                for (j = 0; j < rnode->keys; j++)
     249                                        result += (size_t) rnode->value[i];
     250                        }
     251                       
    189252                        mutex_unlock(&area->lock);
    190253                }
     
    193256        mutex_unlock(&as->lock);
    194257       
    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);
     258        return result * PAGE_SIZE;
    241259}
    242260
Note: See TracChangeset for help on using the changeset viewer.