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

Last change on this file since 5803f37 was 5803f37, checked in by Sebastian Huber <sebastian.huber@…>, on Jun 28, 2019 at 6:30:11 AM

score: Add and use _Thread_Get_unmapped_priority().

Add and use _Thread_Get_unmapped_real_priority().

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