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 <inttypes.h> |
---|
15 | #include <stdio.h> |
---|
16 | #include <string.h> /* memcpy() */ |
---|
17 | |
---|
18 | static void |
---|
19 | rtems_monitor_task_wait_info( |
---|
20 | rtems_monitor_task_t *canonical_task, |
---|
21 | Thread_Control *rtems_thread |
---|
22 | ) |
---|
23 | { |
---|
24 | Thread_queue_Context queue_context; |
---|
25 | const Thread_queue_Queue *queue; |
---|
26 | |
---|
27 | canonical_task->wait[0] = '\0'; |
---|
28 | |
---|
29 | _Thread_queue_Context_initialize( &queue_context ); |
---|
30 | _Thread_Wait_acquire( rtems_thread, &queue_context ); |
---|
31 | |
---|
32 | queue = rtems_thread->Wait.queue; |
---|
33 | |
---|
34 | if ( queue != NULL ) { |
---|
35 | Objects_Id id; |
---|
36 | |
---|
37 | _Thread_queue_Queue_get_name_and_id( |
---|
38 | queue, |
---|
39 | canonical_task->wait, |
---|
40 | sizeof(canonical_task->wait), |
---|
41 | &id |
---|
42 | ); |
---|
43 | |
---|
44 | if (id != 0) { |
---|
45 | snprintf( |
---|
46 | canonical_task->wait, |
---|
47 | sizeof(canonical_task->wait), |
---|
48 | "%08" PRIx32, |
---|
49 | id |
---|
50 | ); |
---|
51 | } |
---|
52 | } else if ( |
---|
53 | (rtems_thread->current_state & STATES_WAITING_FOR_BSD_WAKEUP) != 0 |
---|
54 | ) { |
---|
55 | const char *wmesg; |
---|
56 | |
---|
57 | wmesg = rtems_thread->Wait.return_argument_second.immutable_object; |
---|
58 | |
---|
59 | if (wmesg != NULL) { |
---|
60 | strlcpy( |
---|
61 | canonical_task->wait, |
---|
62 | wmesg, |
---|
63 | sizeof(canonical_task->wait) |
---|
64 | ); |
---|
65 | } |
---|
66 | } |
---|
67 | |
---|
68 | _Thread_Wait_release( rtems_thread, &queue_context ); |
---|
69 | } |
---|
70 | |
---|
71 | void |
---|
72 | rtems_monitor_task_canonical( |
---|
73 | rtems_monitor_task_t *canonical_task, |
---|
74 | const void *thread_void |
---|
75 | ) |
---|
76 | { |
---|
77 | Thread_Control *rtems_thread; |
---|
78 | RTEMS_API_Control *api; |
---|
79 | Objects_Name name; |
---|
80 | |
---|
81 | rtems_thread = |
---|
82 | RTEMS_DECONST( Thread_Control *, (const Thread_Control *) thread_void ); |
---|
83 | |
---|
84 | api = rtems_thread->API_Extensions[ THREAD_API_RTEMS ]; |
---|
85 | |
---|
86 | _Objects_Name_to_string( |
---|
87 | rtems_thread->Object.name, |
---|
88 | false, |
---|
89 | canonical_task->short_name, |
---|
90 | sizeof( canonical_task->short_name ) |
---|
91 | ); |
---|
92 | |
---|
93 | _Thread_Get_name( |
---|
94 | rtems_thread, |
---|
95 | canonical_task->long_name, |
---|
96 | sizeof( canonical_task->long_name ) |
---|
97 | ); |
---|
98 | |
---|
99 | name.name_u32 = _Thread_Scheduler_get_home( rtems_thread )->name; |
---|
100 | _Objects_Name_to_string( |
---|
101 | name, |
---|
102 | false, |
---|
103 | canonical_task->scheduler_name, |
---|
104 | sizeof( canonical_task->scheduler_name ) |
---|
105 | ); |
---|
106 | |
---|
107 | rtems_monitor_task_wait_info( canonical_task, rtems_thread ); |
---|
108 | |
---|
109 | canonical_task->state = rtems_thread->current_state; |
---|
110 | canonical_task->entry = rtems_thread->Start.Entry; |
---|
111 | canonical_task->stack = rtems_thread->Start.Initial_stack.area; |
---|
112 | canonical_task->stack_size = rtems_thread->Start.Initial_stack.size; |
---|
113 | canonical_task->priority = _Thread_Get_priority( rtems_thread ); |
---|
114 | canonical_task->events = api->Event.pending_events; |
---|
115 | /* |
---|
116 | * FIXME: make this optionally cpu_time_executed |
---|
117 | */ |
---|
118 | #if 0 |
---|
119 | canonical_task->ticks = rtems_thread->cpu_time_executed; |
---|
120 | #else |
---|
121 | canonical_task->ticks = 0; |
---|
122 | #endif |
---|
123 | |
---|
124 | /* XXX modes and attributes only exist in the RTEMS API .. */ |
---|
125 | /* XXX not directly in the core thread.. they will have to be derived */ |
---|
126 | /* XXX if they are important enough to include anymore. */ |
---|
127 | canonical_task->modes = 0; /* XXX FIX ME.... rtems_thread->current_modes; */ |
---|
128 | canonical_task->attributes = 0 /* XXX FIX ME rtems_thread->API_Extensions[ THREAD_API_RTEMS ]->attribute_set */; |
---|
129 | } |
---|
130 | |
---|
131 | |
---|
132 | void |
---|
133 | rtems_monitor_task_dump_header( |
---|
134 | bool verbose RTEMS_UNUSED |
---|
135 | ) |
---|
136 | { |
---|
137 | fprintf(stdout,"\ |
---|
138 | ID NAME SHED PRI STATE MODES EVENTS WAITINFO\n"); /* |
---|
139 | 0a010004 SHLL UPD 100 READY P:T:nA NONE 00000000 */ |
---|
140 | |
---|
141 | rtems_monitor_separator(); |
---|
142 | } |
---|
143 | |
---|
144 | /* |
---|
145 | */ |
---|
146 | |
---|
147 | void |
---|
148 | rtems_monitor_task_dump( |
---|
149 | rtems_monitor_task_t *monitor_task, |
---|
150 | bool verbose RTEMS_UNUSED |
---|
151 | ) |
---|
152 | { |
---|
153 | int length = 0; |
---|
154 | |
---|
155 | length += rtems_monitor_dump_id(monitor_task->id); |
---|
156 | length += rtems_monitor_pad(9, length); |
---|
157 | |
---|
158 | if (strcmp(monitor_task->short_name, monitor_task->long_name) == 0) { |
---|
159 | length += fprintf(stdout, "%s", monitor_task->short_name); |
---|
160 | } else { |
---|
161 | length += fprintf( |
---|
162 | stdout, |
---|
163 | "%s %s", |
---|
164 | monitor_task->short_name, |
---|
165 | monitor_task->long_name |
---|
166 | ); |
---|
167 | } |
---|
168 | |
---|
169 | length += rtems_monitor_pad(30, length); |
---|
170 | length += fprintf(stdout, "%s", monitor_task->scheduler_name); |
---|
171 | length += rtems_monitor_pad(35, length); |
---|
172 | length += rtems_monitor_dump_priority(monitor_task->priority); |
---|
173 | length += rtems_monitor_pad(39, length); |
---|
174 | length += rtems_monitor_dump_state(monitor_task->state); |
---|
175 | length += rtems_monitor_pad(46, length); |
---|
176 | length += rtems_monitor_dump_modes(monitor_task->modes); |
---|
177 | length += rtems_monitor_pad(53, length); |
---|
178 | length += rtems_monitor_dump_events(monitor_task->events); |
---|
179 | length += rtems_monitor_pad(62, length); |
---|
180 | length += fprintf(stdout, "%s", monitor_task->wait); |
---|
181 | |
---|
182 | fprintf(stdout,"\n"); |
---|
183 | } |
---|