1 | /* |
---|
2 | * RTEMS Monitor task support |
---|
3 | */ |
---|
4 | |
---|
5 | #ifdef HAVE_CONFIG_H |
---|
6 | #include "config.h" |
---|
7 | #endif |
---|
8 | |
---|
9 | #include <rtems.h> |
---|
10 | #include <rtems/monitor.h> |
---|
11 | #include <rtems/score/threadimpl.h> |
---|
12 | #include <rtems/score/threadqimpl.h> |
---|
13 | |
---|
14 | #include <stdio.h> |
---|
15 | #include <string.h> /* memcpy() */ |
---|
16 | |
---|
17 | static void |
---|
18 | rtems_monitor_task_wait_info( |
---|
19 | rtems_monitor_task_t *canonical_task, |
---|
20 | Thread_Control *rtems_thread |
---|
21 | ) |
---|
22 | { |
---|
23 | Thread_queue_Context queue_context; |
---|
24 | const Thread_queue_Queue *queue; |
---|
25 | |
---|
26 | _Thread_queue_Context_initialize( &queue_context ); |
---|
27 | _Thread_Wait_acquire( rtems_thread, &queue_context ); |
---|
28 | |
---|
29 | queue = rtems_thread->Wait.queue; |
---|
30 | |
---|
31 | if ( queue != NULL ) { |
---|
32 | _Thread_queue_Queue_get_name_and_id( |
---|
33 | queue, |
---|
34 | canonical_task->wait_name, |
---|
35 | sizeof(canonical_task->wait_name), |
---|
36 | &canonical_task->wait_id |
---|
37 | ); |
---|
38 | } else { |
---|
39 | canonical_task->wait_id = 0; |
---|
40 | canonical_task->wait_name[0] = '\0'; |
---|
41 | } |
---|
42 | |
---|
43 | _Thread_Wait_release( rtems_thread, &queue_context ); |
---|
44 | } |
---|
45 | |
---|
46 | void |
---|
47 | rtems_monitor_task_canonical( |
---|
48 | rtems_monitor_task_t *canonical_task, |
---|
49 | const void *thread_void |
---|
50 | ) |
---|
51 | { |
---|
52 | Thread_Control *rtems_thread; |
---|
53 | RTEMS_API_Control *api; |
---|
54 | |
---|
55 | rtems_thread = |
---|
56 | RTEMS_DECONST( Thread_Control *, (const Thread_Control *) thread_void ); |
---|
57 | |
---|
58 | api = rtems_thread->API_Extensions[ THREAD_API_RTEMS ]; |
---|
59 | |
---|
60 | _Thread_Get_name( |
---|
61 | rtems_thread, |
---|
62 | canonical_task->name_string, |
---|
63 | sizeof( canonical_task->name_string ) |
---|
64 | ); |
---|
65 | |
---|
66 | rtems_monitor_task_wait_info( canonical_task, rtems_thread ); |
---|
67 | |
---|
68 | canonical_task->state = rtems_thread->current_state; |
---|
69 | canonical_task->entry = rtems_thread->Start.Entry; |
---|
70 | canonical_task->stack = rtems_thread->Start.Initial_stack.area; |
---|
71 | canonical_task->stack_size = rtems_thread->Start.Initial_stack.size; |
---|
72 | canonical_task->cpu = _Per_CPU_Get_index( _Thread_Get_CPU( rtems_thread ) ); |
---|
73 | canonical_task->priority = _Thread_Get_priority( rtems_thread ); |
---|
74 | canonical_task->events = api->Event.pending_events; |
---|
75 | /* |
---|
76 | * FIXME: make this optionally cpu_time_executed |
---|
77 | */ |
---|
78 | #if 0 |
---|
79 | canonical_task->ticks = rtems_thread->cpu_time_executed; |
---|
80 | #else |
---|
81 | canonical_task->ticks = 0; |
---|
82 | #endif |
---|
83 | |
---|
84 | /* XXX modes and attributes only exist in the RTEMS API .. */ |
---|
85 | /* XXX not directly in the core thread.. they will have to be derived */ |
---|
86 | /* XXX if they are important enough to include anymore. */ |
---|
87 | canonical_task->modes = 0; /* XXX FIX ME.... rtems_thread->current_modes; */ |
---|
88 | canonical_task->attributes = 0 /* XXX FIX ME rtems_thread->API_Extensions[ THREAD_API_RTEMS ]->attribute_set */; |
---|
89 | } |
---|
90 | |
---|
91 | |
---|
92 | void |
---|
93 | rtems_monitor_task_dump_header( |
---|
94 | bool verbose RTEMS_UNUSED |
---|
95 | ) |
---|
96 | { |
---|
97 | fprintf(stdout,"\ |
---|
98 | ID NAME CPU PRI STATE MODES EVENTS WAITID WAITQUEUE\n"); /* |
---|
99 | 0a010004 SHLL 0 100 READY P:T:nA NONE 00000000 00000000 [DFLT] */ |
---|
100 | |
---|
101 | rtems_monitor_separator(); |
---|
102 | } |
---|
103 | |
---|
104 | /* |
---|
105 | */ |
---|
106 | |
---|
107 | void |
---|
108 | rtems_monitor_task_dump( |
---|
109 | rtems_monitor_task_t *monitor_task, |
---|
110 | bool verbose RTEMS_UNUSED |
---|
111 | ) |
---|
112 | { |
---|
113 | int length = 0; |
---|
114 | |
---|
115 | length += rtems_monitor_dump_id(monitor_task->id); |
---|
116 | length += rtems_monitor_pad(11, length); |
---|
117 | length += fprintf(stdout, "%s", monitor_task->name_string); |
---|
118 | length += rtems_monitor_pad(21, length); |
---|
119 | length += rtems_monitor_dump_decimal(monitor_task->cpu); |
---|
120 | length += rtems_monitor_pad(26, length); |
---|
121 | length += rtems_monitor_dump_priority(monitor_task->priority); |
---|
122 | length += rtems_monitor_pad(30, length); |
---|
123 | length += rtems_monitor_dump_state(monitor_task->state); |
---|
124 | length += rtems_monitor_pad(37, length); |
---|
125 | length += rtems_monitor_dump_modes(monitor_task->modes); |
---|
126 | length += rtems_monitor_pad(44, length); |
---|
127 | length += rtems_monitor_dump_events(monitor_task->events); |
---|
128 | length += rtems_monitor_pad(53, length); |
---|
129 | length += rtems_monitor_dump_id(monitor_task->wait_id); |
---|
130 | length += rtems_monitor_pad(62, length); |
---|
131 | length += fprintf(stdout, "%s", monitor_task->wait_name); |
---|
132 | |
---|
133 | fprintf(stdout,"\n"); |
---|
134 | } |
---|