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

5
Last change on this file since ef30eb1 was fc438dae, checked in by Sebastian Huber <sebastian.huber@…>, on 12/21/17 at 07:47:12

monitor: Fix thread priority values

  • 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/score/schedulerimpl.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 = SCHEDULER_PRIORITY_UNMAP(
115      _Thread_Get_priority( rtems_thread )
116    );
117    canonical_task->events = api->Event.pending_events;
118    /*
119     * FIXME: make this optionally cpu_time_executed
120     */
121#if 0
122    canonical_task->ticks = rtems_thread->cpu_time_executed;
123#else
124    canonical_task->ticks = 0;
125#endif
126
127/* XXX modes and attributes only exist in the RTEMS API .. */
128/* XXX not directly in the core thread.. they will have to be derived */
129/* XXX if they are important enough to include anymore.   */
130    canonical_task->modes = 0; /* XXX FIX ME.... rtems_thread->current_modes; */
131    canonical_task->attributes = 0 /* XXX FIX ME rtems_thread->API_Extensions[ THREAD_API_RTEMS ]->attribute_set */;
132}
133
134
135void
136rtems_monitor_task_dump_header(
137    bool verbose RTEMS_UNUSED
138)
139{
140    fprintf(stdout,"\
141ID       NAME                 SHED PRI STATE  MODES    EVENTS WAITINFO\n"); /*
1420a010004 SHLL                 UPD  100 READY  P:T:nA   NONE   00000000 */
143
144    rtems_monitor_separator();
145}
146
147/*
148 */
149
150void
151rtems_monitor_task_dump(
152    rtems_monitor_task_t *monitor_task,
153    bool                  verbose RTEMS_UNUSED
154)
155{
156    int length = 0;
157
158    length += rtems_monitor_dump_id(monitor_task->id);
159    length += rtems_monitor_pad(9, length);
160
161    if (strcmp(monitor_task->short_name, monitor_task->long_name) == 0) {
162        length += fprintf(stdout, "%s", monitor_task->short_name);
163    } else {
164        length += fprintf(
165          stdout,
166          "%s %s",
167          monitor_task->short_name,
168          monitor_task->long_name
169        );
170    }
171
172    length += rtems_monitor_pad(30, length);
173    length += fprintf(stdout, "%s", monitor_task->scheduler_name);
174    length += rtems_monitor_pad(35, length);
175    length += rtems_monitor_dump_priority(monitor_task->priority);
176    length += rtems_monitor_pad(39, length);
177    length += rtems_monitor_dump_state(monitor_task->state);
178    length += rtems_monitor_pad(46, length);
179    length += rtems_monitor_dump_modes(monitor_task->modes);
180    length += rtems_monitor_pad(53, length);
181    length += rtems_monitor_dump_events(monitor_task->events);
182    length += rtems_monitor_pad(62, length);
183    length += fprintf(stdout, "%s", monitor_task->wait);
184
185    fprintf(stdout,"\n");
186}
Note: See TracBrowser for help on using the repository browser.