Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:18

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  *
0006  * @brief RTEMS Monitor task support
0007  */
0008 
0009 /*
0010  * COPYRIGHT (c) 1989-2022. On-Line Applications Research Corporation (OAR).
0011  *
0012  * Redistribution and use in source and binary forms, with or without
0013  * modification, are permitted provided that the following conditions
0014  * are met:
0015  * 1. Redistributions of source code must retain the above copyright
0016  *    notice, this list of conditions and the following disclaimer.
0017  * 2. Redistributions in binary form must reproduce the above copyright
0018  *    notice, this list of conditions and the following disclaimer in the
0019  *    documentation and/or other materials provided with the distribution.
0020  *
0021  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0022  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0023  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0024  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0025  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0026  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0027  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0028  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0029  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0030  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0031  * POSSIBILITY OF SUCH DAMAGE.
0032  */
0033 
0034 #ifdef HAVE_CONFIG_H
0035 #include "config.h"
0036 #endif
0037 
0038 #include <rtems.h>
0039 #include <rtems/monitor.h>
0040 #include <rtems/rtems/tasksdata.h>
0041 #include <rtems/score/threadimpl.h>
0042 #include <rtems/score/threadqimpl.h>
0043 
0044 #include <inttypes.h>
0045 #include <stdio.h>
0046 #include <string.h>    /* memcpy() */
0047 
0048 static void
0049 rtems_monitor_task_wait_info(
0050     rtems_monitor_task_t *canonical_task,
0051     Thread_Control       *rtems_thread
0052 )
0053 {
0054     Thread_queue_Context      queue_context;
0055     const Thread_queue_Queue *queue;
0056 
0057     canonical_task->wait[0] = '\0';
0058 
0059     _Thread_queue_Context_initialize( &queue_context );
0060     _Thread_Wait_acquire( rtems_thread, &queue_context );
0061 
0062     queue = rtems_thread->Wait.queue;
0063 
0064     if ( queue != NULL ) {
0065       Objects_Id id;
0066 
0067       _Thread_queue_Queue_get_name_and_id(
0068         queue,
0069         canonical_task->wait,
0070         sizeof(canonical_task->wait),
0071         &id
0072       );
0073 
0074       if (id != 0) {
0075         snprintf(
0076           canonical_task->wait,
0077           sizeof(canonical_task->wait),
0078           "%08" PRIx32,
0079           id
0080         );
0081       }
0082     } else if (
0083       (rtems_thread->current_state & STATES_WAITING_FOR_BSD_WAKEUP) != 0
0084     ) {
0085       const char *wmesg;
0086 
0087       wmesg = rtems_thread->Wait.return_argument_second.immutable_object;
0088 
0089       if (wmesg != NULL) {
0090         strlcpy(
0091           canonical_task->wait,
0092           wmesg,
0093           sizeof(canonical_task->wait)
0094         );
0095       }
0096     }
0097 
0098     _Thread_Wait_release( rtems_thread, &queue_context );
0099 }
0100 
0101 void
0102 rtems_monitor_task_canonical(
0103     rtems_monitor_task_t  *canonical_task,
0104     const void            *thread_void
0105 )
0106 {
0107     Thread_Control    *rtems_thread;
0108     RTEMS_API_Control *api;
0109     Objects_Name       name;
0110 
0111     rtems_thread =
0112       RTEMS_DECONST( Thread_Control *, (const Thread_Control *) thread_void );
0113 
0114     api = rtems_thread->API_Extensions[ THREAD_API_RTEMS ];
0115 
0116     _Objects_Name_to_string(
0117       rtems_thread->Object.name,
0118       false,
0119       canonical_task->short_name,
0120       sizeof( canonical_task->short_name )
0121     );
0122 
0123     _Thread_Get_name(
0124       rtems_thread,
0125       canonical_task->long_name,
0126       sizeof( canonical_task->long_name )
0127     );
0128 
0129     name.name_u32 = _Thread_Scheduler_get_home( rtems_thread )->name;
0130     _Objects_Name_to_string(
0131       name,
0132       false,
0133       canonical_task->scheduler_name,
0134       sizeof( canonical_task->scheduler_name )
0135     );
0136 
0137     rtems_monitor_task_wait_info( canonical_task, rtems_thread );
0138 
0139     canonical_task->state = rtems_thread->current_state;
0140     canonical_task->entry = rtems_thread->Start.Entry;
0141     canonical_task->stack = rtems_thread->Start.Initial_stack.area;
0142     canonical_task->stack_size = rtems_thread->Start.Initial_stack.size;
0143     canonical_task->priority = _Thread_Get_unmapped_priority( rtems_thread );
0144     canonical_task->events = api->Event.pending_events;
0145     /*
0146      * FIXME: make this optionally cpu_time_executed
0147      */
0148 #if 0
0149     canonical_task->ticks = rtems_thread->cpu_time_executed;
0150 #else
0151     canonical_task->ticks = 0;
0152 #endif
0153 
0154 /* XXX modes and attributes only exist in the RTEMS API .. */
0155 /* XXX not directly in the core thread.. they will have to be derived */
0156 /* XXX if they are important enough to include anymore.   */
0157     canonical_task->modes = 0; /* XXX FIX ME.... rtems_thread->current_modes; */
0158     canonical_task->attributes = 0 /* XXX FIX ME rtems_thread->API_Extensions[ THREAD_API_RTEMS ]->attribute_set */;
0159 }
0160 
0161 
0162 void
0163 rtems_monitor_task_dump_header(
0164     bool verbose RTEMS_UNUSED
0165 )
0166 {
0167     fprintf(stdout,"\
0168 ID       NAME                 SHED PRI STATE  MODES    EVENTS WAITINFO\n"); /*
0169 0a010004 SHLL                 UPD  100 READY  P:T:nA   NONE   00000000 */
0170 
0171     rtems_monitor_separator();
0172 }
0173 
0174 /*
0175  */
0176 
0177 void
0178 rtems_monitor_task_dump(
0179     rtems_monitor_task_t *monitor_task,
0180     bool                  verbose RTEMS_UNUSED
0181 )
0182 {
0183     int length = 0;
0184 
0185     length += rtems_monitor_dump_id(monitor_task->id);
0186     length += rtems_monitor_pad(9, length);
0187 
0188     if (strcmp(monitor_task->short_name, monitor_task->long_name) == 0) {
0189         length += fprintf(stdout, "%s", monitor_task->short_name);
0190     } else {
0191         length += fprintf(
0192           stdout,
0193           "%s %s",
0194           monitor_task->short_name,
0195           monitor_task->long_name
0196         );
0197     }
0198 
0199     length += rtems_monitor_pad(30, length);
0200     length += fprintf(stdout, "%s", monitor_task->scheduler_name);
0201     length += rtems_monitor_pad(35, length);
0202     length += rtems_monitor_dump_priority(monitor_task->priority);
0203     length += rtems_monitor_pad(39, length);
0204     length += rtems_monitor_dump_state(monitor_task->state);
0205     length += rtems_monitor_pad(46, length);
0206     length += rtems_monitor_dump_modes(monitor_task->modes);
0207     length += rtems_monitor_pad(53, length);
0208     length += rtems_monitor_dump_events(monitor_task->events);
0209     length += rtems_monitor_pad(62, length);
0210     length += fprintf(stdout, "%s", monitor_task->wait);
0211 
0212     fprintf(stdout,"\n");
0213 }