Changeset cd50486 in mainline for kernel/generic/src/sysinfo/stats.c
- Timestamp:
- 2011-02-06T22:03:55Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 25971d2
- Parents:
- 1110ebd (diff), 960ff451 (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/sysinfo/stats.c
r1110ebd rcd50486 160 160 static size_t get_task_virtmem(as_t *as) 161 161 { 162 size_t result = 0;163 164 162 /* 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. 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. 173 167 */ 174 168 175 169 if (SYNCH_FAILED(mutex_trylock(&as->lock))) 176 return result * PAGE_SIZE; 170 return 0; 171 172 size_t pages = 0; 177 173 178 174 /* 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 space202 *203 * @param as Address space.204 *205 * @return Size of the resident (used) virtual address space (bytes).206 *207 */208 static 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 to214 * block. Only attempt to lock the address space and address space area215 * 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 space219 * management code compute these statistics as it proceeds instead of220 * 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 */227 175 link_t *cur; 228 176 for (cur = as->as_area_btree.leaf_head.next; … … 238 186 continue; 239 187 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 188 pages += area->pages; 252 189 mutex_unlock(&area->lock); 253 190 } … … 256 193 mutex_unlock(&as->lock); 257 194 258 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 */ 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); 259 241 } 260 242
Note:
See TracChangeset
for help on using the changeset viewer.