Changeset a35b458 in mainline for kernel/generic/src/sysinfo
- Timestamp:
- 2018-03-02T20:10:49Z (8 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f1380b7
- Parents:
- 3061bc1
- git-author:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-02-28 17:38:31)
- git-committer:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:10:49)
- Location:
- kernel/generic/src/sysinfo
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/sysinfo/stats.c
r3061bc1 ra35b458 99 99 if (dry_run) 100 100 return NULL; 101 101 102 102 /* Assumption: config.cpu_count is constant */ 103 103 stats_cpu_t *stats_cpus = (stats_cpu_t *) malloc(*size, FRAME_ATOMIC); … … 106 106 return NULL; 107 107 } 108 108 109 109 size_t i; 110 110 for (i = 0; i < config.cpu_count; i++) { 111 111 irq_spinlock_lock(&cpus[i].lock, true); 112 112 113 113 stats_cpus[i].id = cpus[i].id; 114 114 stats_cpus[i].active = cpus[i].active; … … 116 116 stats_cpus[i].busy_cycles = cpus[i].busy_cycles; 117 117 stats_cpus[i].idle_cycles = cpus[i].idle_cycles; 118 118 119 119 irq_spinlock_unlock(&cpus[i].lock, true); 120 120 } 121 121 122 122 return ((void *) stats_cpus); 123 123 } … … 137 137 size_t *count = (size_t *) arg; 138 138 (*count)++; 139 139 140 140 return true; 141 141 } … … 156 156 * object, return inexact statistics by skipping the respective object. 157 157 */ 158 158 159 159 if (mutex_trylock(&as->lock) != EOK) 160 160 return 0; 161 161 162 162 size_t pages = 0; 163 163 164 164 /* Walk the B+ tree and count pages */ 165 165 list_foreach(as->as_area_btree.leaf_list, leaf_link, btree_node_t, … … 168 168 for (i = 0; i < node->keys; i++) { 169 169 as_area_t *area = node->value[i]; 170 170 171 171 if (mutex_trylock(&area->lock) != EOK) 172 172 continue; 173 173 174 174 pages += area->pages; 175 175 mutex_unlock(&area->lock); 176 176 } 177 177 } 178 178 179 179 mutex_unlock(&as->lock); 180 180 181 181 return (pages << PAGE_WIDTH); 182 182 } … … 197 197 * object, return inexact statistics by skipping the respective object. 198 198 */ 199 199 200 200 if (mutex_trylock(&as->lock) != EOK) 201 201 return 0; 202 202 203 203 size_t pages = 0; 204 204 205 205 /* Walk the B+ tree and count pages */ 206 206 list_foreach(as->as_area_btree.leaf_list, leaf_link, btree_node_t, node) { … … 208 208 for (i = 0; i < node->keys; i++) { 209 209 as_area_t *area = node->value[i]; 210 210 211 211 if (mutex_trylock(&area->lock) != EOK) 212 212 continue; 213 213 214 214 pages += area->resident; 215 215 mutex_unlock(&area->lock); 216 216 } 217 217 } 218 218 219 219 mutex_unlock(&as->lock); 220 220 221 221 return (pages << PAGE_WIDTH); 222 222 } … … 234 234 assert(interrupts_disabled()); 235 235 assert(irq_spinlock_locked(&task->lock)); 236 236 237 237 stats_task->task_id = task->taskid; 238 238 str_cpy(stats_task->name, TASK_NAME_BUFLEN, task->name); … … 260 260 stats_task_t **iterator = (stats_task_t **) arg; 261 261 task_t *task = avltree_get_instance(node, task_t, tasks_tree_node); 262 262 263 263 /* Interrupts are already disabled */ 264 264 irq_spinlock_lock(&(task->lock), false); 265 265 266 266 /* Record the statistics and increment the iterator */ 267 267 produce_stats_task(task, *iterator); 268 268 (*iterator)++; 269 269 270 270 irq_spinlock_unlock(&(task->lock), false); 271 271 272 272 return true; 273 273 } … … 289 289 /* Messing with task structures, avoid deadlock */ 290 290 irq_spinlock_lock(&tasks_lock, true); 291 291 292 292 /* First walk the task tree to count the tasks */ 293 293 size_t count = 0; 294 294 avltree_walk(&tasks_tree, avl_count_walker, (void *) &count); 295 295 296 296 if (count == 0) { 297 297 /* No tasks found (strange) */ … … 300 300 return NULL; 301 301 } 302 302 303 303 *size = sizeof(stats_task_t) * count; 304 304 if (dry_run) { … … 306 306 return NULL; 307 307 } 308 308 309 309 stats_task_t *stats_tasks = (stats_task_t *) malloc(*size, FRAME_ATOMIC); 310 310 if (stats_tasks == NULL) { … … 314 314 return NULL; 315 315 } 316 316 317 317 /* Walk tha task tree again to gather the statistics */ 318 318 stats_task_t *iterator = stats_tasks; 319 319 avltree_walk(&tasks_tree, task_serialize_walker, (void *) &iterator); 320 320 321 321 irq_spinlock_unlock(&tasks_lock, true); 322 322 323 323 return ((void *) stats_tasks); 324 324 } … … 336 336 assert(interrupts_disabled()); 337 337 assert(irq_spinlock_locked(&thread->lock)); 338 338 339 339 stats_thread->thread_id = thread->tid; 340 340 stats_thread->task_id = thread->task->taskid; … … 343 343 stats_thread->ucycles = thread->ucycles; 344 344 stats_thread->kcycles = thread->kcycles; 345 345 346 346 if (thread->cpu != NULL) { 347 347 stats_thread->on_cpu = true; … … 366 366 stats_thread_t **iterator = (stats_thread_t **) arg; 367 367 thread_t *thread = avltree_get_instance(node, thread_t, threads_tree_node); 368 368 369 369 /* Interrupts are already disabled */ 370 370 irq_spinlock_lock(&thread->lock, false); 371 371 372 372 /* Record the statistics and increment the iterator */ 373 373 produce_stats_thread(thread, *iterator); 374 374 (*iterator)++; 375 375 376 376 irq_spinlock_unlock(&thread->lock, false); 377 377 378 378 return true; 379 379 } … … 395 395 /* Messing with threads structures, avoid deadlock */ 396 396 irq_spinlock_lock(&threads_lock, true); 397 397 398 398 /* First walk the thread tree to count the threads */ 399 399 size_t count = 0; 400 400 avltree_walk(&threads_tree, avl_count_walker, (void *) &count); 401 401 402 402 if (count == 0) { 403 403 /* No threads found (strange) */ … … 406 406 return NULL; 407 407 } 408 408 409 409 *size = sizeof(stats_thread_t) * count; 410 410 if (dry_run) { … … 412 412 return NULL; 413 413 } 414 414 415 415 stats_thread_t *stats_threads = (stats_thread_t *) malloc(*size, FRAME_ATOMIC); 416 416 if (stats_threads == NULL) { … … 420 420 return NULL; 421 421 } 422 422 423 423 /* Walk tha thread tree again to gather the statistics */ 424 424 stats_thread_t *iterator = stats_threads; 425 425 avltree_walk(&threads_tree, thread_serialize_walker, (void *) &iterator); 426 426 427 427 irq_spinlock_unlock(&threads_lock, true); 428 428 429 429 return ((void *) stats_threads); 430 430 } … … 454 454 sysinfo_return_t ret; 455 455 ret.tag = SYSINFO_VAL_UNDEFINED; 456 456 457 457 /* Parse the task ID */ 458 458 task_id_t task_id; 459 459 if (str_uint64_t(name, NULL, 0, true, &task_id) != EOK) 460 460 return ret; 461 461 462 462 /* Messing with task structures, avoid deadlock */ 463 463 irq_spinlock_lock(&tasks_lock, true); 464 464 465 465 task_t *task = task_find_by_id(task_id); 466 466 if (task == NULL) { … … 469 469 return ret; 470 470 } 471 471 472 472 if (dry_run) { 473 473 ret.tag = SYSINFO_VAL_FUNCTION_DATA; 474 474 ret.data.data = NULL; 475 475 ret.data.size = sizeof(stats_task_t); 476 476 477 477 irq_spinlock_unlock(&tasks_lock, true); 478 478 } else { … … 484 484 return ret; 485 485 } 486 486 487 487 /* Correct return value */ 488 488 ret.tag = SYSINFO_VAL_FUNCTION_DATA; 489 489 ret.data.data = (void *) stats_task; 490 490 ret.data.size = sizeof(stats_task_t); 491 491 492 492 /* Hand-over-hand locking */ 493 493 irq_spinlock_exchange(&tasks_lock, &task->lock); 494 494 495 495 produce_stats_task(task, stats_task); 496 496 497 497 irq_spinlock_unlock(&task->lock, true); 498 498 } 499 499 500 500 return ret; 501 501 } … … 525 525 sysinfo_return_t ret; 526 526 ret.tag = SYSINFO_VAL_UNDEFINED; 527 527 528 528 /* Parse the thread ID */ 529 529 thread_id_t thread_id; 530 530 if (str_uint64_t(name, NULL, 0, true, &thread_id) != EOK) 531 531 return ret; 532 532 533 533 /* Messing with threads structures, avoid deadlock */ 534 534 irq_spinlock_lock(&threads_lock, true); 535 535 536 536 thread_t *thread = thread_find_by_id(thread_id); 537 537 if (thread == NULL) { … … 540 540 return ret; 541 541 } 542 542 543 543 if (dry_run) { 544 544 ret.tag = SYSINFO_VAL_FUNCTION_DATA; 545 545 ret.data.data = NULL; 546 546 ret.data.size = sizeof(stats_thread_t); 547 547 548 548 irq_spinlock_unlock(&threads_lock, true); 549 549 } else { … … 555 555 return ret; 556 556 } 557 557 558 558 /* Correct return value */ 559 559 ret.tag = SYSINFO_VAL_FUNCTION_DATA; 560 560 ret.data.data = (void *) stats_thread; 561 561 ret.data.size = sizeof(stats_thread_t); 562 562 563 563 /* Hand-over-hand locking */ 564 564 irq_spinlock_exchange(&threads_lock, &thread->lock); 565 565 566 566 produce_stats_thread(thread, stats_thread); 567 567 568 568 irq_spinlock_unlock(&thread->lock, true); 569 569 } 570 570 571 571 return ret; 572 572 } … … 587 587 { 588 588 *size = sizeof(stats_exc_t) * IVT_ITEMS; 589 589 590 590 if ((dry_run) || (IVT_ITEMS == 0)) 591 591 return NULL; 592 592 593 593 stats_exc_t *stats_exceptions = 594 594 (stats_exc_t *) malloc(*size, FRAME_ATOMIC); … … 598 598 return NULL; 599 599 } 600 600 601 601 #if (IVT_ITEMS > 0) 602 602 /* Messing with exception table, avoid deadlock */ 603 603 irq_spinlock_lock(&exctbl_lock, true); 604 604 605 605 unsigned int i; 606 606 for (i = 0; i < IVT_ITEMS; i++) { … … 611 611 stats_exceptions[i].count = exc_table[i].count; 612 612 } 613 613 614 614 irq_spinlock_unlock(&exctbl_lock, true); 615 615 #endif 616 616 617 617 return ((void *) stats_exceptions); 618 618 } … … 642 642 sysinfo_return_t ret; 643 643 ret.tag = SYSINFO_VAL_UNDEFINED; 644 644 645 645 /* Parse the exception number */ 646 646 uint64_t excn; 647 647 if (str_uint64_t(name, NULL, 0, true, &excn) != EOK) 648 648 return ret; 649 649 650 650 #if (IVT_FIRST > 0) 651 651 if (excn < IVT_FIRST) 652 652 return ret; 653 653 #endif 654 654 655 655 #if (IVT_ITEMS + IVT_FIRST == 0) 656 656 return ret; … … 659 659 return ret; 660 660 #endif 661 661 662 662 if (dry_run) { 663 663 ret.tag = SYSINFO_VAL_FUNCTION_DATA; … … 667 667 /* Update excn index for accessing exc_table */ 668 668 excn -= IVT_FIRST; 669 669 670 670 /* Allocate stats_exc_t structure */ 671 671 stats_exc_t *stats_exception = … … 673 673 if (stats_exception == NULL) 674 674 return ret; 675 675 676 676 /* Messing with exception table, avoid deadlock */ 677 677 irq_spinlock_lock(&exctbl_lock, true); 678 678 679 679 /* Correct return value */ 680 680 ret.tag = SYSINFO_VAL_FUNCTION_DATA; 681 681 ret.data.data = (void *) stats_exception; 682 682 ret.data.size = sizeof(stats_exc_t); 683 683 684 684 stats_exception->id = excn; 685 685 str_cpy(stats_exception->desc, EXC_NAME_BUFLEN, exc_table[excn].name); … … 687 687 stats_exception->cycles = exc_table[excn].cycles; 688 688 stats_exception->count = exc_table[excn].count; 689 689 690 690 irq_spinlock_unlock(&exctbl_lock, true); 691 691 } 692 692 693 693 return ret; 694 694 } … … 711 711 if (dry_run) 712 712 return NULL; 713 713 714 714 stats_physmem_t *stats_physmem = 715 715 (stats_physmem_t *) malloc(*size, FRAME_ATOMIC); … … 718 718 return NULL; 719 719 } 720 720 721 721 zones_stats(&(stats_physmem->total), &(stats_physmem->unavail), 722 722 &(stats_physmem->used), &(stats_physmem->free)); 723 723 724 724 return ((void *) stats_physmem); 725 725 } … … 742 742 if (dry_run) 743 743 return NULL; 744 744 745 745 load_t *stats_load = (load_t *) malloc(*size, FRAME_ATOMIC); 746 746 if (stats_load == NULL) { … … 748 748 return NULL; 749 749 } 750 750 751 751 /* To always get consistent values acquire the mutex */ 752 752 mutex_lock(&load_lock); 753 753 754 754 unsigned int i; 755 755 for (i = 0; i < LOAD_STEPS; i++) 756 756 stats_load[i] = avenrdy[i] << LOAD_KERNEL_SHIFT; 757 757 758 758 mutex_unlock(&load_lock); 759 759 760 760 return ((void *) stats_load); 761 761 } … … 768 768 load *= exp; 769 769 load += (ready << LOAD_FIXED_SHIFT) * (LOAD_FIXED_1 - exp); 770 770 771 771 return (load >> LOAD_FIXED_SHIFT); 772 772 } … … 782 782 { 783 783 thread_detach(THREAD); 784 784 785 785 while (true) { 786 786 atomic_count_t ready = atomic_get(&nrdy); 787 787 788 788 /* Mutually exclude with get_stats_load() */ 789 789 mutex_lock(&load_lock); 790 790 791 791 unsigned int i; 792 792 for (i = 0; i < LOAD_STEPS; i++) 793 793 avenrdy[i] = load_calc(avenrdy[i], load_exp[i], ready); 794 794 795 795 mutex_unlock(&load_lock); 796 796 797 797 thread_sleep(LOAD_INTERVAL); 798 798 } … … 805 805 { 806 806 mutex_initialize(&load_lock, MUTEX_PASSIVE); 807 807 808 808 sysinfo_set_item_gen_data("system.cpus", NULL, get_stats_cpus, NULL); 809 809 sysinfo_set_item_gen_data("system.physmem", NULL, get_stats_physmem, NULL); -
kernel/generic/src/sysinfo/sysinfo.c
r3061bc1 ra35b458 64 64 { 65 65 sysinfo_item_t *item = (sysinfo_item_t *) obj; 66 66 67 67 item->name = NULL; 68 68 item->val_type = SYSINFO_VAL_UNDEFINED; … … 70 70 item->subtree.table = NULL; 71 71 item->next = NULL; 72 72 73 73 return EOK; 74 74 } … … 84 84 { 85 85 sysinfo_item_t *item = (sysinfo_item_t *) obj; 86 86 87 87 if (item->name != NULL) 88 88 free(item->name); 89 89 90 90 return 0; 91 91 } … … 101 101 sizeof(sysinfo_item_t), 0, sysinfo_item_constructor, 102 102 sysinfo_item_destructor, SLAB_CACHE_MAGDEFERRED); 103 103 104 104 mutex_initialize(&sysinfo_lock, MUTEX_ACTIVE); 105 105 } … … 127 127 { 128 128 assert(subtree != NULL); 129 129 130 130 sysinfo_item_t *cur = subtree; 131 131 132 132 /* Walk all siblings */ 133 133 while (cur != NULL) { 134 134 size_t i = 0; 135 135 136 136 /* Compare name with path */ 137 137 while ((cur->name[i] != 0) && (name[i] == cur->name[i])) 138 138 i++; 139 139 140 140 /* Check for perfect name and path match */ 141 141 if ((name[i] == 0) && (cur->name[i] == 0)) 142 142 return cur; 143 143 144 144 /* Partial match up to the delimiter */ 145 145 if ((name[i] == '.') && (cur->name[i] == 0)) { … … 155 155 **ret = cur->subtree.generator.fn(name + i + 1, 156 156 dry_run, cur->subtree.generator.data); 157 157 158 158 return NULL; 159 159 default: … … 161 161 if (ret != NULL) 162 162 *ret = NULL; 163 163 164 164 return NULL; 165 165 } 166 166 } 167 167 168 168 cur = cur->next; 169 169 } 170 170 171 171 /* Not found, no data generated */ 172 172 if (ret != NULL) 173 173 *ret = NULL; 174 174 175 175 return NULL; 176 176 } … … 193 193 { 194 194 assert(psubtree != NULL); 195 195 196 196 if (*psubtree == NULL) { 197 197 /* No parent */ 198 198 199 199 size_t i = 0; 200 200 201 201 /* Find the first delimiter in name */ 202 202 while ((name[i] != 0) && (name[i] != '.')) 203 203 i++; 204 204 205 205 *psubtree = 206 206 (sysinfo_item_t *) slab_alloc(sysinfo_item_cache, 0); 207 207 assert(*psubtree); 208 208 209 209 /* Fill in item name up to the delimiter */ 210 210 (*psubtree)->name = str_ndup(name, i); 211 211 assert((*psubtree)->name); 212 212 213 213 /* Create subtree items */ 214 214 if (name[i] == '.') { … … 217 217 &((*psubtree)->subtree.table)); 218 218 } 219 219 220 220 /* No subtree needs to be created */ 221 221 return *psubtree; 222 222 } 223 223 224 224 sysinfo_item_t *cur = *psubtree; 225 225 226 226 /* Walk all siblings */ 227 227 while (cur != NULL) { 228 228 size_t i = 0; 229 229 230 230 /* Compare name with path */ 231 231 while ((cur->name[i] != 0) && (name[i] == cur->name[i])) 232 232 i++; 233 233 234 234 /* Check for perfect name and path match 235 235 * -> item is already present. … … 237 237 if ((name[i] == 0) && (cur->name[i] == 0)) 238 238 return cur; 239 239 240 240 /* Partial match up to the delimiter */ 241 241 if ((name[i] == '.') && (cur->name[i] == 0)) { … … 257 257 } 258 258 } 259 259 260 260 /* No match and no more siblings to check 261 261 * -> create a new sibling item. … … 266 266 while ((name[i] != 0) && (name[i] != '.')) 267 267 i++; 268 268 269 269 sysinfo_item_t *item = 270 270 (sysinfo_item_t *) slab_alloc(sysinfo_item_cache, 0); 271 271 assert(item); 272 272 273 273 cur->next = item; 274 274 275 275 /* Fill in item name up to the delimiter */ 276 276 item->name = str_ndup(name, i); 277 277 assert(item->name); 278 278 279 279 /* Create subtree items */ 280 280 if (name[i] == '.') { … … 283 283 &(item->subtree.table)); 284 284 } 285 285 286 286 /* No subtree needs to be created */ 287 287 return item; 288 288 } 289 289 290 290 cur = cur->next; 291 291 } 292 292 293 293 /* Unreachable */ 294 294 assert(false); … … 309 309 /* Protect sysinfo tree consistency */ 310 310 mutex_lock(&sysinfo_lock); 311 311 312 312 if (root == NULL) 313 313 root = &global_root; 314 314 315 315 sysinfo_item_t *item = sysinfo_create_path(name, root); 316 316 if (item != NULL) { … … 318 318 item->val.val = val; 319 319 } 320 320 321 321 mutex_unlock(&sysinfo_lock); 322 322 } … … 340 340 /* Protect sysinfo tree consistency */ 341 341 mutex_lock(&sysinfo_lock); 342 342 343 343 if (root == NULL) 344 344 root = &global_root; 345 345 346 346 sysinfo_item_t *item = sysinfo_create_path(name, root); 347 347 if (item != NULL) { … … 350 350 item->val.data.size = size; 351 351 } 352 352 353 353 mutex_unlock(&sysinfo_lock); 354 354 } … … 368 368 /* Protect sysinfo tree consistency */ 369 369 mutex_lock(&sysinfo_lock); 370 370 371 371 if (root == NULL) 372 372 root = &global_root; 373 373 374 374 sysinfo_item_t *item = sysinfo_create_path(name, root); 375 375 if (item != NULL) { … … 378 378 item->val.gen_val.data = data; 379 379 } 380 380 381 381 mutex_unlock(&sysinfo_lock); 382 382 } … … 401 401 /* Protect sysinfo tree consistency */ 402 402 mutex_lock(&sysinfo_lock); 403 403 404 404 if (root == NULL) 405 405 root = &global_root; 406 406 407 407 sysinfo_item_t *item = sysinfo_create_path(name, root); 408 408 if (item != NULL) { … … 411 411 item->val.gen_data.data = data; 412 412 } 413 413 414 414 mutex_unlock(&sysinfo_lock); 415 415 } … … 426 426 /* Protect sysinfo tree consistency */ 427 427 mutex_lock(&sysinfo_lock); 428 428 429 429 if (root == NULL) 430 430 root = &global_root; 431 431 432 432 sysinfo_item_t *item = sysinfo_create_path(name, root); 433 433 if (item != NULL) 434 434 item->val_type = SYSINFO_VAL_UNDEFINED; 435 435 436 436 mutex_unlock(&sysinfo_lock); 437 437 } … … 451 451 /* Protect sysinfo tree consistency */ 452 452 mutex_lock(&sysinfo_lock); 453 453 454 454 if (root == NULL) 455 455 root = &global_root; 456 456 457 457 sysinfo_item_t *item = sysinfo_create_path(name, root); 458 458 459 459 /* Change the type of the subtree only if it is not already 460 460 a fixed subtree */ … … 464 464 item->subtree.generator.data = data; 465 465 } 466 466 467 467 mutex_unlock(&sysinfo_lock); 468 468 } … … 492 492 for (sysinfo_item_t *cur = root; cur; cur = cur->next) { 493 493 size_t length; 494 494 495 495 if (spaces == 0) { 496 496 printf("%s", cur->name); … … 501 501 length = str_length(cur->name) + 1; 502 502 } 503 503 504 504 sysarg_t val; 505 505 size_t size; 506 506 507 507 /* Display node value and type */ 508 508 switch (cur->val_type) { … … 531 531 printf("+ %s [unknown]\n", cur->name); 532 532 } 533 533 534 534 /* Recursivelly nest into the subtree */ 535 535 switch (cur->subtree_type) { … … 562 562 while we are dumping it */ 563 563 mutex_lock(&sysinfo_lock); 564 564 565 565 if (root == NULL) 566 566 sysinfo_dump_internal(global_root, 0); 567 567 else 568 568 sysinfo_dump_internal(root, 0); 569 569 570 570 mutex_unlock(&sysinfo_lock); 571 571 } … … 590 590 if (root == NULL) 591 591 root = &global_root; 592 592 593 593 /* Try to find the item or generate data */ 594 594 sysinfo_return_t ret; … … 596 596 sysinfo_item_t *item = sysinfo_find_item(name, *root, &ret_ptr, 597 597 dry_run); 598 598 599 599 if (item != NULL) { 600 600 /* Item found in the fixed sysinfo tree */ 601 601 602 602 ret.tag = item->val_type; 603 603 switch (item->val_type) { … … 625 625 } 626 626 } 627 627 628 628 return ret; 629 629 } … … 645 645 sysinfo_return_t ret; 646 646 ret.tag = SYSINFO_VAL_UNDEFINED; 647 647 648 648 if (size > SYSINFO_MAX_PATH) 649 649 return ret; 650 650 651 651 char *path = (char *) malloc(size + 1, 0); 652 652 assert(path); 653 653 654 654 if ((copy_from_uspace(path, ptr, size + 1) == 0) && 655 655 (path[size] == 0)) { … … 662 662 mutex_unlock(&sysinfo_lock); 663 663 } 664 664 665 665 free(path); 666 666 return ret; … … 686 686 if (root == NULL) 687 687 root = &global_root; 688 688 689 689 sysinfo_item_t *subtree = NULL; 690 690 691 691 if (name[0] != 0) { 692 692 /* Try to find the item */ … … 698 698 } else 699 699 subtree = *root; 700 700 701 701 sysinfo_return_t ret; 702 702 ret.tag = SYSINFO_VAL_UNDEFINED; 703 703 704 704 if (subtree != NULL) { 705 705 /* … … 709 709 for (sysinfo_item_t *cur = subtree; cur; cur = cur->next) 710 710 size += str_size(cur->name) + 1; 711 711 712 712 if (dry_run) { 713 713 ret.tag = SYSINFO_VAL_DATA; … … 719 719 if (names == NULL) 720 720 return ret; 721 721 722 722 size_t pos = 0; 723 723 for (sysinfo_item_t *cur = subtree; cur; cur = cur->next) { … … 725 725 pos += str_size(cur->name) + 1; 726 726 } 727 727 728 728 /* Correct return value */ 729 729 ret.tag = SYSINFO_VAL_DATA; … … 732 732 } 733 733 } 734 734 735 735 return ret; 736 736 } … … 754 754 ret.data.data = NULL; 755 755 ret.data.size = 0; 756 756 757 757 if (size > SYSINFO_MAX_PATH) 758 758 return ret; 759 759 760 760 char *path = (char *) malloc(size + 1, 0); 761 761 assert(path); 762 762 763 763 if ((copy_from_uspace(path, ptr, size + 1) == 0) && 764 764 (path[size] == 0)) { … … 771 771 mutex_unlock(&sysinfo_lock); 772 772 } 773 773 774 774 free(path); 775 775 return ret; … … 794 794 { 795 795 errno_t rc; 796 796 797 797 /* 798 798 * Get the keys. … … 803 803 sysinfo_return_t ret = 804 804 sysinfo_get_keys_uspace(path_ptr, path_size, true); 805 805 806 806 /* Check return data tag */ 807 807 if (ret.tag == SYSINFO_VAL_DATA) … … 810 810 else 811 811 rc = EINVAL; 812 812 813 813 return (sys_errno_t) rc; 814 814 } … … 842 842 { 843 843 errno_t rc; 844 844 845 845 /* Get the keys */ 846 846 sysinfo_return_t ret = sysinfo_get_keys_uspace(path_ptr, path_size, 847 847 false); 848 848 849 849 /* Check return data tag */ 850 850 if (ret.tag == SYSINFO_VAL_DATA) { … … 853 853 if (rc == EOK) 854 854 rc = copy_to_uspace(size_ptr, &size, sizeof(size)); 855 855 856 856 free(ret.data.data); 857 857 } else 858 858 rc = EINVAL; 859 859 860 860 return (sys_errno_t) rc; 861 861 } … … 882 882 */ 883 883 sysinfo_return_t ret = sysinfo_get_item_uspace(path_ptr, path_size, true); 884 884 885 885 /* 886 886 * Map generated value types to constant types (user space does … … 891 891 else if (ret.tag == SYSINFO_VAL_FUNCTION_DATA) 892 892 ret.tag = SYSINFO_VAL_DATA; 893 893 894 894 return (sysarg_t) ret.tag; 895 895 } … … 913 913 { 914 914 errno_t rc; 915 915 916 916 /* 917 917 * Get the item. … … 921 921 */ 922 922 sysinfo_return_t ret = sysinfo_get_item_uspace(path_ptr, path_size, true); 923 923 924 924 /* Only constant or generated numerical value is returned */ 925 925 if ((ret.tag == SYSINFO_VAL_VAL) || (ret.tag == SYSINFO_VAL_FUNCTION_VAL)) … … 927 927 else 928 928 rc = EINVAL; 929 929 930 930 return (sys_errno_t) rc; 931 931 } … … 949 949 { 950 950 errno_t rc; 951 951 952 952 /* 953 953 * Get the item. … … 957 957 */ 958 958 sysinfo_return_t ret = sysinfo_get_item_uspace(path_ptr, path_size, true); 959 959 960 960 /* Only the size of constant or generated binary data is considered */ 961 961 if ((ret.tag == SYSINFO_VAL_DATA) || (ret.tag == SYSINFO_VAL_FUNCTION_DATA)) … … 964 964 else 965 965 rc = EINVAL; 966 966 967 967 return (sys_errno_t) rc; 968 968 } … … 999 999 { 1000 1000 errno_t rc; 1001 1001 1002 1002 /* Get the item */ 1003 1003 sysinfo_return_t ret = sysinfo_get_item_uspace(path_ptr, path_size, 1004 1004 false); 1005 1005 1006 1006 /* Only constant or generated binary data is considered */ 1007 1007 if ((ret.tag == SYSINFO_VAL_DATA) || … … 1013 1013 } else 1014 1014 rc = EINVAL; 1015 1015 1016 1016 /* N.B.: The generated binary data should be freed */ 1017 1017 if ((ret.tag == SYSINFO_VAL_FUNCTION_DATA) && (ret.data.data != NULL)) 1018 1018 free(ret.data.data); 1019 1019 1020 1020 return (sys_errno_t) rc; 1021 1021 }
Note:
See TracChangeset
for help on using the changeset viewer.
