Changeset 133962b in rtems
- Timestamp:
- 07/22/14 14:40:54 (9 years ago)
- Branches:
- 4.11, 5, master
- Children:
- 2a86615
- Parents:
- b2356837
- git-author:
- Jennifer Averett <jennifer.averett@…> (07/22/14 14:40:54)
- git-committer:
- Jennifer Averett <jennifer.averett@…> (09/05/14 11:50:29)
- Location:
- cpukit/libmisc
- Files:
-
- 2 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
cpukit/libmisc/Makefile.am
rb2356837 r133962b 19 19 noinst_LIBRARIES += libcapture.a 20 20 libcapture_a_SOURCES = capture/capture.c capture/capture-cli.c \ 21 capture/capture.h capture/capture-cli.h 21 capture/capture_user_extension.c \ 22 capture/capture.h capture/captureimpl.h capture/capture-cli.h 22 23 23 24 ## cpuuse -
cpukit/libmisc/capture/capture.c
rb2356837 r133962b 30 30 #include <rtems/rtems/tasksimpl.h> 31 31 32 #include "capture .h"32 #include "captureimpl.h" 33 33 34 34 #include <rtems/score/statesimpl.h> … … 58 58 #endif 59 59 60 static bool61 rtems_capture_create_task (rtems_tcb* current_task,62 rtems_tcb* new_task);63 64 static void65 rtems_capture_start_task (rtems_tcb* current_task,66 rtems_tcb* started_task);67 68 static void69 rtems_capture_restart_task (rtems_tcb* current_task,70 rtems_tcb* restarted_task);71 72 static void73 rtems_capture_delete_task (rtems_tcb* current_task,74 rtems_tcb* deleted_task);75 76 static void77 rtems_capture_switch_task (rtems_tcb* current_task,78 rtems_tcb* heir_task);79 80 static void81 rtems_capture_begin_task (rtems_tcb* begin_task);82 83 static void84 rtems_capture_exitted_task (rtems_tcb* exitted_task);85 86 static void87 rtems_capture_terminated_task (rtems_tcb* terminated_task);88 89 /*90 * Global capture flags.91 */92 #define RTEMS_CAPTURE_ON (1U << 0)93 #define RTEMS_CAPTURE_NO_MEMORY (1U << 1)94 #define RTEMS_CAPTURE_OVERFLOW (1U << 2)95 #define RTEMS_CAPTURE_TRIGGERED (1U << 3)96 #define RTEMS_CAPTURE_READER_ACTIVE (1U << 4)97 #define RTEMS_CAPTURE_READER_WAITING (1U << 5)98 #define RTEMS_CAPTURE_GLOBAL_WATCH (1U << 6)99 #define RTEMS_CAPTURE_ONLY_MONITOR (1U << 7)100 60 101 61 /* … … 111 71 static rtems_capture_control_t* capture_controls; 112 72 static int capture_extension_index; 113 static rtems_id capture_id;114 73 static rtems_capture_timestamp capture_timestamp; 115 74 static rtems_task_priority capture_ceiling; … … 118 77 static rtems_interrupt_lock capture_lock = 119 78 RTEMS_INTERRUPT_LOCK_INITIALIZER("capture"); 120 121 static const rtems_extensions_table capture_extensions = {122 .thread_create = rtems_capture_create_task,123 .thread_start = rtems_capture_start_task,124 .thread_restart = rtems_capture_restart_task,125 .thread_delete = rtems_capture_delete_task,126 .thread_switch = rtems_capture_switch_task,127 .thread_begin = rtems_capture_begin_task,128 .thread_exitted = rtems_capture_exitted_task,129 .fatal = NULL,130 .thread_terminate = rtems_capture_terminated_task131 };132 79 133 80 /* … … 152 99 }; 153 100 101 void rtems_capture_set_extension_index(int index) 102 { 103 capture_extension_index = index; 104 } 105 106 int rtems_capture_get_extension_index(void) 107 { 108 return capture_extension_index; 109 } 110 111 uint32_t rtems_capture_get_flags(void) 112 { 113 return capture_flags; 114 } 115 116 void rtems_capture_set_flags(uint32_t mask) 117 { 118 capture_flags |= mask; 119 } 120 121 122 rtems_capture_task_t* rtems_capture_find_capture_task( rtems_id ct_id ) 123 { 124 rtems_capture_task_t* ct; 125 126 for (ct = capture_tasks; ct; ct = ct->forw) { 127 if (ct->id == ct_id) 128 break; 129 } 130 return ct; 131 } 132 154 133 /* 155 134 * This function returns the current time. If a handler is provided 156 135 * by the user get the time from that. 157 136 */ 158 static inlinevoid137 void 159 138 rtems_capture_get_time (rtems_capture_time_t* time) 160 139 { … … 291 270 * This function setups a stack so its usage can be monitored. 292 271 */ 293 static inlinevoid272 void 294 273 rtems_capture_init_stack_usage (rtems_capture_task_t* task) 295 274 { … … 379 358 * This function create the task control. 380 359 */ 381 static inlinertems_capture_task_t*360 rtems_capture_task_t* 382 361 rtems_capture_create_capture_task (rtems_tcb* new_task) 383 362 { … … 457 436 * deleted. 458 437 */ 459 static inlinevoid438 void 460 439 rtems_capture_destroy_capture_task (rtems_capture_task_t* task) 461 440 { … … 488 467 * This function records a capture record into the capture buffer. 489 468 */ 490 static inlinevoid469 void 491 470 rtems_capture_record (rtems_capture_task_t* task, 492 471 uint32_t events) … … 551 530 * cause of a trigger. 552 531 */ 553 staticbool532 bool 554 533 rtems_capture_trigger (rtems_capture_task_t* ft, 555 534 rtems_capture_task_t* tt, … … 617 596 618 597 /* 619 * This function is called when a task is created.620 */621 static bool622 rtems_capture_create_task (rtems_tcb* current_task,623 rtems_tcb* new_task)624 {625 rtems_capture_task_t* ct;626 rtems_capture_task_t* nt;627 628 ct = current_task->extensions[capture_extension_index];629 630 /*631 * The task pointers may not be known as the task may have632 * been created before the capture engine was open. Add them.633 */634 635 if (ct == NULL)636 ct = rtems_capture_create_capture_task (current_task);637 638 /*639 * Create the new task's capture control block.640 */641 nt = rtems_capture_create_capture_task (new_task);642 643 if (rtems_capture_trigger (ct, nt, RTEMS_CAPTURE_CREATE))644 {645 rtems_capture_record (ct, RTEMS_CAPTURE_CREATED_BY_EVENT);646 rtems_capture_record (nt, RTEMS_CAPTURE_CREATED_EVENT);647 }648 649 return 1 == 1;650 }651 652 /*653 * This function is called when a task is started.654 */655 static void656 rtems_capture_start_task (rtems_tcb* current_task,657 rtems_tcb* started_task)658 {659 /*660 * Get the capture task control block so we can trace this661 * event.662 */663 rtems_capture_task_t* ct;664 rtems_capture_task_t* st;665 666 ct = current_task->extensions[capture_extension_index];667 st = started_task->extensions[capture_extension_index];668 669 /*670 * The task pointers may not be known as the task may have671 * been created before the capture engine was open. Add them.672 */673 674 if (ct == NULL)675 ct = rtems_capture_create_capture_task (current_task);676 677 if (st == NULL)678 st = rtems_capture_create_capture_task (started_task);679 680 if (rtems_capture_trigger (ct, st, RTEMS_CAPTURE_START))681 {682 rtems_capture_record (ct, RTEMS_CAPTURE_STARTED_BY_EVENT);683 rtems_capture_record (st, RTEMS_CAPTURE_STARTED_EVENT);684 }685 686 rtems_capture_init_stack_usage (st);687 }688 689 /*690 * This function is called when a task is restarted.691 */692 static void693 rtems_capture_restart_task (rtems_tcb* current_task,694 rtems_tcb* restarted_task)695 {696 /*697 * Get the capture task control block so we can trace this698 * event.699 */700 rtems_capture_task_t* ct;701 rtems_capture_task_t* rt;702 703 ct = current_task->extensions[capture_extension_index];704 rt = restarted_task->extensions[capture_extension_index];705 706 /*707 * The task pointers may not be known as the task may have708 * been created before the capture engine was open. Add them.709 */710 711 if (ct == NULL)712 ct = rtems_capture_create_capture_task (current_task);713 714 if (rt == NULL)715 rt = rtems_capture_create_capture_task (restarted_task);716 717 if (rtems_capture_trigger (ct, rt, RTEMS_CAPTURE_RESTART))718 {719 rtems_capture_record (ct, RTEMS_CAPTURE_RESTARTED_BY_EVENT);720 rtems_capture_record (rt, RTEMS_CAPTURE_RESTARTED_EVENT);721 }722 723 rtems_capture_task_stack_usage (rt);724 rtems_capture_init_stack_usage (rt);725 }726 727 /*728 * This function is called when a task is deleted.729 */730 static void731 rtems_capture_delete_task (rtems_tcb* current_task,732 rtems_tcb* deleted_task)733 {734 /*735 * Get the capture task control block so we can trace this736 * event.737 */738 rtems_capture_task_t* ct;739 rtems_capture_task_t* dt;740 741 /*742 * The task pointers may not be known as the task may have743 * been created before the capture engine was open. Add them.744 */745 746 ct = current_task->extensions[capture_extension_index];747 dt = deleted_task->extensions[capture_extension_index];748 749 if (ct == NULL)750 ct = rtems_capture_create_capture_task (current_task);751 752 if (dt == NULL)753 dt = rtems_capture_create_capture_task (deleted_task);754 755 if (rtems_capture_trigger (ct, dt, RTEMS_CAPTURE_DELETE))756 {757 rtems_capture_record (ct, RTEMS_CAPTURE_DELETED_BY_EVENT);758 rtems_capture_record (dt, RTEMS_CAPTURE_DELETED_EVENT);759 }760 761 rtems_capture_task_stack_usage (dt);762 763 /*764 * This task's tcb will be invalid. This signals the765 * task has been deleted.766 */767 dt->tcb = 0;768 769 rtems_capture_destroy_capture_task (dt);770 }771 772 /*773 * This function is called when a task is begun.774 */775 static void776 rtems_capture_begin_task (rtems_tcb* begin_task)777 {778 /*779 * Get the capture task control block so we can trace this780 * event.781 */782 rtems_capture_task_t* bt;783 784 bt = begin_task->extensions[capture_extension_index];785 786 /*787 * The task pointers may not be known as the task may have788 * been created before the capture engine was open. Add them.789 */790 791 if (bt == NULL)792 bt = rtems_capture_create_capture_task (begin_task);793 794 if (rtems_capture_trigger (NULL, bt, RTEMS_CAPTURE_BEGIN))795 rtems_capture_record (bt, RTEMS_CAPTURE_BEGIN_EVENT);796 }797 798 /*799 * This function is called when a task is exitted. That is800 * returned rather than was deleted.801 */802 static void803 rtems_capture_exitted_task (rtems_tcb* exitted_task)804 {805 /*806 * Get the capture task control block so we can trace this807 * event.808 */809 rtems_capture_task_t* et;810 811 et = exitted_task->extensions[capture_extension_index];812 813 /*814 * The task pointers may not be known as the task may have815 * been created before the capture engine was open. Add them.816 */817 818 if (et == NULL)819 et = rtems_capture_create_capture_task (exitted_task);820 821 if (rtems_capture_trigger (NULL, et, RTEMS_CAPTURE_EXITTED))822 rtems_capture_record (et, RTEMS_CAPTURE_EXITTED_EVENT);823 824 rtems_capture_task_stack_usage (et);825 }826 827 /*828 * This function is called when a termination request is identified.829 */830 static void831 rtems_capture_terminated_task (rtems_tcb* terminated_task)832 {833 /*834 * Get the capture task control block so we can trace this835 * event.836 */837 rtems_capture_task_t* tt;838 839 tt = terminated_task->extensions[capture_extension_index];840 841 /*842 * The task pointers may not be known as the task may have843 * been created before the capture engine was open. Add them.844 */845 846 if (tt == NULL)847 tt = rtems_capture_create_capture_task (terminated_task);848 849 if (rtems_capture_trigger (NULL, tt, RTEMS_CAPTURE_TERMINATED))850 rtems_capture_record (tt, RTEMS_CAPTURE_TERMINATED_EVENT);851 852 rtems_capture_task_stack_usage (tt);853 }854 855 /*856 * This function is called when a context is switched.857 */858 static void859 rtems_capture_switch_task (rtems_tcb* current_task,860 rtems_tcb* heir_task)861 {862 /*863 * Only perform context switch trace processing if tracing is864 * enabled.865 */866 if (capture_flags & RTEMS_CAPTURE_ON)867 {868 rtems_capture_time_t time;869 870 /*871 * Get the cpature task control block so we can update the872 * reference and perform any watch or trigger functions.873 * The task pointers may not be known as the task may have874 * been created before the capture engine was open. Add them.875 */876 rtems_capture_task_t* ct;877 rtems_capture_task_t* ht;878 879 880 if (_States_Is_dormant (current_task->current_state))881 {882 rtems_id ct_id = current_task->Object.id;883 884 for (ct = capture_tasks; ct; ct = ct->forw)885 if (ct->id == ct_id)886 break;887 }888 else889 {890 ct = current_task->extensions[capture_extension_index];891 892 if (ct == NULL)893 ct = rtems_capture_create_capture_task (current_task);894 }895 896 ht = heir_task->extensions[capture_extension_index];897 898 if (ht == NULL)899 ht = rtems_capture_create_capture_task (heir_task);900 901 /*902 * Update the execution time. Assume the time will not overflow903 * for now. This may need to change.904 */905 rtems_capture_get_time (&time);906 907 /*908 * We could end up with null pointers for both the current task909 * and the heir task.910 */911 912 if (ht)913 {914 ht->in++;915 ht->time_in = time;916 }917 918 if (ct)919 {920 ct->out++;921 if (ct->time_in)922 ct->time += time - ct->time_in;923 }924 925 if (rtems_capture_trigger (ct, ht, RTEMS_CAPTURE_SWITCH))926 {927 rtems_capture_record (ct, RTEMS_CAPTURE_SWITCHED_OUT_EVENT);928 rtems_capture_record (ht, RTEMS_CAPTURE_SWITCHED_IN_EVENT);929 }930 }931 }932 933 /*934 598 * This function initialises the realtime capture engine allocating the trace 935 599 * buffer. It is assumed we have a working heap at stage of initialisation. … … 938 602 rtems_capture_open (uint32_t size, rtems_capture_timestamp timestamp __attribute__((unused))) 939 603 { 940 rtems_name name;941 604 rtems_status_code sc; 942 605 … … 962 625 capture_floor = 255; 963 626 964 /* 965 * Register the user extension handlers for the CAPture Engine. 966 */ 967 name = rtems_build_name ('C', 'A', 'P', 'E'); 968 sc = rtems_extension_create (name, &capture_extensions, &capture_id); 627 sc = rtems_capture_user_extension_open(); 969 628 970 629 if (sc != RTEMS_SUCCESSFUL) 971 630 { 972 capture_id = 0;973 631 free (capture_records); 974 632 capture_records = NULL; 975 }976 else977 {978 capture_extension_index = rtems_object_id_get_index (capture_id);979 633 } 980 634 … … 1017 671 */ 1018 672 1019 sc = rtems_ extension_delete (capture_id);673 sc = rtems_capture_user_extension_close(); 1020 674 1021 675 if (sc != RTEMS_SUCCESSFUL)
Note: See TracChangeset
for help on using the changeset viewer.