source: rtems/cpukit/libmisc/monitor/mon-task.c @ e1b7c188

5
Last change on this file since e1b7c188 was b7af3e44, checked in by Sebastian Huber <sebastian.huber@…>, on 11/08/18 at 09:57:21

rtems: Move internal structures to tasksdata.h

Update #3598.

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