Changeset 8eec3c8 in mainline for kernel/generic/src/sysinfo/stats.c
- Timestamp:
- 2010-06-10T14:24:50Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- c0f13d2
- Parents:
- 1113c9e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/sysinfo/stats.c
r1113c9e r8eec3c8 44 44 #include <proc/task.h> 45 45 #include <proc/thread.h> 46 #include <interrupt.h> 46 47 #include <str.h> 47 48 #include <errno.h> … … 535 536 } 536 537 538 /** Get exceptions statistics 539 * 540 * @param item Sysinfo item (unused). 541 * @param size Size of the returned data. 542 * @param dry_run Do not get the data, just calculate the size. 543 * 544 * @return Data containing several stats_exc_t structures. 545 * If the return value is not NULL, it should be freed 546 * in the context of the sysinfo request. 547 */ 548 static void *get_stats_exceptions(struct sysinfo_item *item, size_t *size, 549 bool dry_run) 550 { 551 *size = sizeof(stats_exc_t) * IVT_ITEMS; 552 553 if ((dry_run) || (IVT_ITEMS == 0)) 554 return NULL; 555 556 stats_exc_t *stats_exceptions = 557 (stats_exc_t *) malloc(*size, FRAME_ATOMIC); 558 if (stats_exceptions == NULL) { 559 /* No free space for allocation */ 560 *size = 0; 561 return NULL; 562 } 563 564 /* Messing with exception table, avoid deadlock */ 565 irq_spinlock_lock(&exctbl_lock, true); 566 567 unsigned int i; 568 for (i = 0; i < IVT_ITEMS; i++) { 569 stats_exceptions[i].id = i + IVT_FIRST; 570 str_cpy(stats_exceptions[i].desc, EXC_NAME_BUFLEN, exc_table[i].name); 571 stats_exceptions[i].cycles = exc_table[i].cycles; 572 stats_exceptions[i].count = exc_table[i].count; 573 } 574 575 irq_spinlock_unlock(&exctbl_lock, true); 576 577 return ((void *) stats_exceptions); 578 } 579 580 /** Get exception statistics 581 * 582 * Get statistics of a given exception. The exception number 583 * is passed as a string (current limitation of the sysinfo 584 * interface, but it is still reasonable for the given purpose). 585 * 586 * @param name Exception number (string-encoded number). 587 * @param dry_run Do not get the data, just calculate the size. 588 * 589 * @return Sysinfo return holder. The type of the returned 590 * data is either SYSINFO_VAL_UNDEFINED (unknown 591 * exception number or memory allocation error) or 592 * SYSINFO_VAL_FUNCTION_DATA (in that case the 593 * generated data should be freed within the 594 * sysinfo request context). 595 * 596 */ 597 static sysinfo_return_t get_stats_exception(const char *name, bool dry_run) 598 { 599 /* Initially no return value */ 600 sysinfo_return_t ret; 601 ret.tag = SYSINFO_VAL_UNDEFINED; 602 603 /* Parse the exception number */ 604 uint64_t excn; 605 if (str_uint64(name, NULL, 0, true, &excn) != EOK) 606 return ret; 607 608 #if IVT_FIRST > 0 609 if (excn < IVT_FIRST) 610 return ret; 611 #endif 612 613 if (excn >= IVT_ITEMS + IVT_FIRST) 614 return ret; 615 616 if (dry_run) { 617 ret.tag = SYSINFO_VAL_FUNCTION_DATA; 618 ret.data.data = NULL; 619 ret.data.size = sizeof(stats_thread_t); 620 } else { 621 /* Update excn index for accessing exc_table */ 622 excn -= IVT_FIRST; 623 624 /* Allocate stats_exc_t structure */ 625 stats_exc_t *stats_exception = 626 (stats_exc_t *) malloc(sizeof(stats_exc_t), FRAME_ATOMIC); 627 if (stats_exception == NULL) 628 return ret; 629 630 /* Messing with exception table, avoid deadlock */ 631 irq_spinlock_lock(&exctbl_lock, true); 632 633 /* Correct return value */ 634 ret.tag = SYSINFO_VAL_FUNCTION_DATA; 635 ret.data.data = (void *) stats_exception; 636 ret.data.size = sizeof(stats_exc_t); 637 638 stats_exception->id = excn; 639 str_cpy(stats_exception->desc, EXC_NAME_BUFLEN, exc_table[excn].name); 640 stats_exception->cycles = exc_table[excn].cycles; 641 stats_exception->count = exc_table[excn].count; 642 643 irq_spinlock_unlock(&exctbl_lock, true); 644 } 645 646 return ret; 647 } 648 537 649 /** Get physical memory statistics 538 650 * … … 651 763 sysinfo_set_item_fn_data("system.tasks", NULL, get_stats_tasks); 652 764 sysinfo_set_item_fn_data("system.threads", NULL, get_stats_threads); 765 sysinfo_set_item_fn_data("system.exceptions", NULL, get_stats_exceptions); 653 766 sysinfo_set_subtree_fn("system.tasks", NULL, get_stats_task); 654 767 sysinfo_set_subtree_fn("system.threads", NULL, get_stats_thread); 768 sysinfo_set_subtree_fn("system.exceptions", NULL, get_stats_exception); 655 769 } 656 770
Note:
See TracChangeset
for help on using the changeset viewer.