File indexing completed on 2025-05-11 08:24:18
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
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/semimpl.h>
0041 #include <stdio.h>
0042 #include <string.h> /* memcpy() */
0043
0044 void
0045 rtems_monitor_sema_canonical(
0046 rtems_monitor_sema_t *canonical_sema,
0047 const void *sema_void
0048 )
0049 {
0050 const Semaphore_Control *rtems_sema;
0051 uintptr_t flags;
0052 Thread_Control *owner;
0053
0054 canonical_sema->attribute = 0;
0055 canonical_sema->priority_ceiling = 0;
0056 canonical_sema->max_count = 0;
0057 canonical_sema->cur_count = 0;
0058 canonical_sema->holder_id = 0;
0059
0060 rtems_sema = (const Semaphore_Control *) sema_void;
0061 flags = _Semaphore_Get_flags( rtems_sema );
0062
0063 #if defined(RTEMS_MULTIPROCESSING)
0064 if ( _Semaphore_Is_global( flags ) ) {
0065 canonical_sema->attribute |= RTEMS_GLOBAL;
0066 }
0067 #endif
0068
0069 if ( _Semaphore_Get_discipline( flags ) == SEMAPHORE_DISCIPLINE_PRIORITY ) {
0070 canonical_sema->attribute |= RTEMS_PRIORITY;
0071 }
0072
0073 switch ( _Semaphore_Get_variant( flags ) ) {
0074 case SEMAPHORE_VARIANT_MUTEX_INHERIT_PRIORITY:
0075 canonical_sema->attribute |= RTEMS_BINARY_SEMAPHORE
0076 | RTEMS_INHERIT_PRIORITY;
0077 break;
0078 case SEMAPHORE_VARIANT_MUTEX_PRIORITY_CEILING:
0079 canonical_sema->attribute |= RTEMS_BINARY_SEMAPHORE
0080 | RTEMS_PRIORITY_CEILING;
0081 break;
0082 case SEMAPHORE_VARIANT_MUTEX_NO_PROTOCOL:
0083 canonical_sema->attribute |= RTEMS_BINARY_SEMAPHORE;
0084 break;
0085 #if defined(RTEMS_SMP)
0086 case SEMAPHORE_VARIANT_MRSP:
0087 canonical_sema->attribute |= RTEMS_BINARY_SEMAPHORE
0088 | RTEMS_MULTIPROCESSOR_RESOURCE_SHARING;
0089 break;
0090 #endif
0091 case SEMAPHORE_VARIANT_SIMPLE_BINARY:
0092 canonical_sema->attribute |= RTEMS_SIMPLE_BINARY_SEMAPHORE;
0093 break;
0094 case SEMAPHORE_VARIANT_COUNTING:
0095 canonical_sema->attribute |= RTEMS_COUNTING_SEMAPHORE;
0096 break;
0097 }
0098
0099 switch ( _Semaphore_Get_variant( flags ) ) {
0100 case SEMAPHORE_VARIANT_MUTEX_PRIORITY_CEILING:
0101 canonical_sema->priority_ceiling = _Scheduler_Unmap_priority(
0102 _CORE_ceiling_mutex_Get_scheduler( &rtems_sema->Core_control.Mutex ),
0103 _CORE_ceiling_mutex_Get_priority( &rtems_sema->Core_control.Mutex )
0104 );
0105
0106 case SEMAPHORE_VARIANT_MUTEX_INHERIT_PRIORITY:
0107 case SEMAPHORE_VARIANT_MUTEX_NO_PROTOCOL:
0108 owner = _CORE_mutex_Get_owner(
0109 &rtems_sema->Core_control.Mutex.Recursive.Mutex
0110 );
0111
0112 if (owner != NULL) {
0113 canonical_sema->holder_id = owner->Object.id;
0114 canonical_sema->cur_count = 0;
0115 } else {
0116 canonical_sema->cur_count = 1;
0117 }
0118
0119 canonical_sema->max_count = 1;
0120 break;
0121 #if defined(RTEMS_SMP)
0122 case SEMAPHORE_VARIANT_MRSP:
0123 canonical_sema->cur_count =
0124 _MRSP_Get_owner( &rtems_sema->Core_control.MRSP ) == NULL;
0125 canonical_sema->max_count = 1;
0126 break;
0127 #endif
0128 case SEMAPHORE_VARIANT_SIMPLE_BINARY:
0129 canonical_sema->cur_count = rtems_sema->Core_control.Semaphore.count;
0130 canonical_sema->max_count = 1;
0131 break;
0132 case SEMAPHORE_VARIANT_COUNTING:
0133 canonical_sema->cur_count = rtems_sema->Core_control.Semaphore.count;
0134 canonical_sema->max_count = UINT32_MAX;
0135 break;
0136 }
0137 }
0138
0139
0140 void
0141 rtems_monitor_sema_dump_header(
0142 bool verbose RTEMS_UNUSED
0143 )
0144 {
0145 printf("\
0146 ID NAME ATTR PRICEIL CURR_CNT HOLDID \n");
0147
0148
0149
0150 rtems_monitor_separator();
0151 }
0152
0153
0154
0155
0156 void
0157 rtems_monitor_sema_dump(
0158 rtems_monitor_sema_t *monitor_sema,
0159 bool verbose RTEMS_UNUSED
0160 )
0161 {
0162 int length = 0;
0163
0164 length += rtems_monitor_dump_id(monitor_sema->id);
0165 length += rtems_monitor_pad(11, length);
0166 length += rtems_monitor_dump_name(monitor_sema->id);
0167 length += rtems_monitor_pad(18, length);
0168 length += rtems_monitor_dump_attributes(monitor_sema->attribute);
0169 length += rtems_monitor_pad(30, length);
0170 length += rtems_monitor_dump_priority(monitor_sema->priority_ceiling);
0171 length += rtems_monitor_pad(38, length);
0172 length += rtems_monitor_dump_decimal(monitor_sema->cur_count);
0173 length += rtems_monitor_pad(47, length);
0174 length += rtems_monitor_dump_id(monitor_sema->holder_id);
0175 printf("\n");
0176 }