summaryrefslogtreecommitdiffstats
path: root/cpukit/libmisc/monitor/mon-task.c
blob: 5e948c13a7a3680c08120b40df9c63f52cd264c4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
 * RTEMS Monitor task support
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <rtems.h>
#include <rtems/monitor.h>
#include <rtems/score/threadimpl.h>
#include <rtems/score/threadqimpl.h>

#include <stdio.h>
#include <string.h>    /* memcpy() */

static void
rtems_monitor_task_wait_info(
    rtems_monitor_task_t *canonical_task,
    Thread_Control       *rtems_thread
)
{
    Thread_queue_Context queue_context;

    _Thread_queue_Context_initialize( &queue_context );
    _Thread_Wait_acquire( rtems_thread, &queue_context );

    canonical_task->state = rtems_thread->current_state;
    canonical_task->wait_id = _Thread_Wait_get_id( rtems_thread );
    canonical_task->wait_queue = rtems_thread->Wait.queue;
    canonical_task->wait_operations = rtems_thread->Wait.operations;

    _Thread_Wait_release( rtems_thread, &queue_context );
}

void
rtems_monitor_task_canonical(
    rtems_monitor_task_t  *canonical_task,
    const void            *thread_void
)
{
    Thread_Control    *rtems_thread;
    RTEMS_API_Control *api;

    rtems_thread =
      RTEMS_DECONST( Thread_Control *, (const Thread_Control *) thread_void );

    api = rtems_thread->API_Extensions[ THREAD_API_RTEMS ];

    _Thread_Get_name(
      rtems_thread,
      canonical_task->name_string,
      sizeof( canonical_task->name_string )
    );

    rtems_monitor_task_wait_info( canonical_task, rtems_thread );

    canonical_task->entry = rtems_thread->Start.Entry;
    canonical_task->stack = rtems_thread->Start.Initial_stack.area;
    canonical_task->stack_size = rtems_thread->Start.Initial_stack.size;
    canonical_task->cpu = _Per_CPU_Get_index( _Thread_Get_CPU( rtems_thread ) );
    canonical_task->priority = _Thread_Get_priority( rtems_thread );
    canonical_task->events = api->Event.pending_events;
    /*
     * FIXME: make this optionally cpu_time_executed
     */
#if 0
    canonical_task->ticks = rtems_thread->cpu_time_executed;
#else
    canonical_task->ticks = 0;
#endif

/* XXX modes and attributes only exist in the RTEMS API .. */
/* XXX not directly in the core thread.. they will have to be derived */
/* XXX if they are important enough to include anymore.   */
    canonical_task->modes = 0; /* XXX FIX ME.... rtems_thread->current_modes; */
    canonical_task->attributes = 0 /* XXX FIX ME rtems_thread->API_Extensions[ THREAD_API_RTEMS ]->attribute_set */;
}


void
rtems_monitor_task_dump_header(
    bool verbose RTEMS_UNUSED
)
{
    fprintf(stdout,"\
ID         NAME       CPU PRI STATE  MODES    EVENTS WAITID   WAITQUEUE\n"); /*
0a010004   SHLL         0 100 READY  P:T:nA     NONE 00000000 00000000 [DFLT] */

    rtems_monitor_separator();
}

/*
 */

void
rtems_monitor_task_dump(
    rtems_monitor_task_t *monitor_task,
    bool                  verbose RTEMS_UNUSED
)
{
    int length = 0;

    length += rtems_monitor_dump_id(monitor_task->id);
    length += rtems_monitor_pad(11, length);
    length += fprintf(stdout, "%s", monitor_task->name_string);
    length += rtems_monitor_pad(21, length);
    length += rtems_monitor_dump_decimal(monitor_task->cpu);
    length += rtems_monitor_pad(26, length);
    length += rtems_monitor_dump_priority(monitor_task->priority);
    length += rtems_monitor_pad(30, length);
    length += rtems_monitor_dump_state(monitor_task->state);
    length += rtems_monitor_pad(37, length);
    length += rtems_monitor_dump_modes(monitor_task->modes);
    length += rtems_monitor_pad(44, length);
    length += rtems_monitor_dump_events(monitor_task->events);
    length += rtems_monitor_pad(53, length);
    length += rtems_monitor_dump_id(monitor_task->wait_id);
    length += rtems_monitor_pad(62, length);
    length += rtems_monitor_dump_addr(monitor_task->wait_queue);
    if (monitor_task->wait_operations == &_Thread_queue_Operations_default) {
        length += fprintf(stdout, " [DFLT]");
    } else if (monitor_task->wait_operations == &_Thread_queue_Operations_FIFO) {
        length += fprintf(stdout, " [FIFO]");
    } else if (monitor_task->wait_operations == &_Thread_queue_Operations_priority) {
        length += fprintf(stdout, " [PRIO]");
    } else if (monitor_task->wait_operations == &_Thread_queue_Operations_priority_inherit) {
        length += fprintf(stdout, " [PINH]");
    } else {
        length += fprintf(stdout, " [?]");
    }

    fprintf(stdout,"\n");
}