Changeset 8b655705 in mainline for kernel/generic/src/sysinfo/stats.c


Ignore:
Timestamp:
2011-04-15T19:38:07Z (13 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
9dd730d1
Parents:
6b9e85b (diff), b2fb47f (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes.

File:
1 edited

Legend:

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

    r6b9e85b r8b655705  
    160160static size_t get_task_virtmem(as_t *as)
    161161{
    162         size_t result = 0;
    163 
    164162        /*
    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.
     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.
    173167         */
    174 
     168       
    175169        if (SYNCH_FAILED(mutex_trylock(&as->lock)))
    176                 return result * PAGE_SIZE;
     170                return 0;
     171       
     172        size_t pages = 0;
    177173       
    178174        /* Walk the B+ tree and count pages */
     
    189185                        if (SYNCH_FAILED(mutex_trylock(&area->lock)))
    190186                                continue;
    191                         result += area->pages;
     187                       
     188                        pages += area->pages;
    192189                        mutex_unlock(&area->lock);
    193190                }
     
    196193        mutex_unlock(&as->lock);
    197194       
    198         return result * PAGE_SIZE;
     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 */
     205static 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);
    199241}
    200242
     
    215257        str_cpy(stats_task->name, TASK_NAME_BUFLEN, task->name);
    216258        stats_task->virtmem = get_task_virtmem(task->as);
     259        stats_task->resmem = get_task_resmem(task->as);
    217260        stats_task->threads = atomic_get(&task->refcount);
    218261        task_get_accounting(task, &(stats_task->ucycles),
Note: See TracChangeset for help on using the changeset viewer.