source: rtems/cpukit/libmisc/monitor/mon-sema.c @ 77ff5599

5
Last change on this file since 77ff5599 was 77ff5599, checked in by Sebastian Huber <sebastian.huber@…>, on 06/10/16 at 06:48:54

score: Introduce map priority scheduler operation

Introduce map/unmap priority scheduler operations to map thread priority
values from/to the user domain to/from the scheduler domain. Use the
map priority operation to validate the thread priority. The EDF
schedulers use this new operation to distinguish between normal
priorities and priorities obtain through a job release.

Update #2173.
Update #2556.

  • Property mode set to 100644
File size: 4.1 KB
Line 
1/*
2 * RTEMS Monitor semaphore support
3 */
4
5#ifdef HAVE_CONFIG_H
6#include "config.h"
7#endif
8
9#include <rtems.h>
10#include "monitor.h"
11#include <rtems/rtems/semimpl.h>
12#include <stdio.h>
13#include <string.h>    /* memcpy() */
14
15void
16rtems_monitor_sema_canonical(
17    rtems_monitor_sema_t  *canonical_sema,
18    const void            *sema_void
19)
20{
21    const Semaphore_Control *rtems_sema = (const Semaphore_Control *) sema_void;
22    Thread_Control *owner;
23
24    memset(canonical_sema, 0, sizeof(*canonical_sema));
25
26#if defined(RTEMS_MULTIPROCESSING)
27    if (rtems_sema->is_global) {
28      canonical_sema->attribute |= RTEMS_GLOBAL;
29    }
30#endif
31
32    if (rtems_sema->discipline == SEMAPHORE_DISCIPLINE_PRIORITY) {
33      canonical_sema->attribute |= RTEMS_PRIORITY;
34    }
35
36    switch ( rtems_sema->variant ) {
37      case SEMAPHORE_VARIANT_MUTEX_INHERIT_PRIORITY:
38        canonical_sema->attribute |= RTEMS_BINARY_SEMAPHORE
39          | RTEMS_INHERIT_PRIORITY;
40        break;
41      case SEMAPHORE_VARIANT_MUTEX_PRIORITY_CEILING:
42        canonical_sema->attribute |= RTEMS_BINARY_SEMAPHORE
43          | RTEMS_PRIORITY_CEILING;
44        break;
45      case SEMAPHORE_VARIANT_MUTEX_NO_PROTOCOL:
46        canonical_sema->attribute |= RTEMS_BINARY_SEMAPHORE;
47        break;
48#if defined(RTEMS_SMP)
49      case SEMAPHORE_VARIANT_MRSP:
50        canonical_sema->attribute |= RTEMS_BINARY_SEMAPHORE
51          | RTEMS_MULTIPROCESSOR_RESOURCE_SHARING;
52        break;
53#endif
54      case SEMAPHORE_VARIANT_SIMPLE_BINARY:
55        canonical_sema->attribute |= RTEMS_SIMPLE_BINARY_SEMAPHORE;
56        break;
57      case SEMAPHORE_VARIANT_COUNTING:
58        canonical_sema->attribute |= RTEMS_COUNTING_SEMAPHORE;
59        break;
60    }
61
62    switch ( rtems_sema->variant ) {
63      case SEMAPHORE_VARIANT_MUTEX_PRIORITY_CEILING:
64        canonical_sema->priority_ceiling = _Scheduler_Unmap_priority(
65          _CORE_ceiling_mutex_Get_scheduler( &rtems_sema->Core_control.Mutex ),
66          _CORE_ceiling_mutex_Get_priority( &rtems_sema->Core_control.Mutex )
67        );
68        /* Fall through */
69      case SEMAPHORE_VARIANT_MUTEX_INHERIT_PRIORITY:
70      case SEMAPHORE_VARIANT_MUTEX_NO_PROTOCOL:
71        owner = _CORE_mutex_Get_owner(
72          &rtems_sema->Core_control.Mutex.Recursive.Mutex
73        );
74
75        if (owner != NULL) {
76          canonical_sema->holder_id = owner->Object.id;
77          canonical_sema->cur_count = 0;
78        } else {
79          canonical_sema->cur_count = 1;
80        }
81
82        canonical_sema->max_count = 1;
83        break;
84#if defined(RTEMS_SMP)
85      case SEMAPHORE_VARIANT_MRSP:
86        canonical_sema->cur_count =
87          rtems_sema->Core_control.MRSP.Resource.owner == NULL;
88        canonical_sema->max_count = 1;
89        break;
90#endif
91      case SEMAPHORE_VARIANT_SIMPLE_BINARY:
92        canonical_sema->cur_count = rtems_sema->Core_control.Semaphore.count;
93        canonical_sema->max_count = 1;
94        break;
95      case SEMAPHORE_VARIANT_COUNTING:
96        canonical_sema->cur_count = rtems_sema->Core_control.Semaphore.count;
97        canonical_sema->max_count = UINT32_MAX;
98        break;
99    }
100}
101
102
103void
104rtems_monitor_sema_dump_header(
105    bool verbose RTEMS_UNUSED
106)
107{
108    printf("\
109  ID       NAME   ATTR        PRICEIL CURR_CNT HOLDID \n");
110/*23456789 123456789 123456789 123456789 123456789 123456789 123456789 1234
111          1         2         3         4         5         6         7    */
112
113    rtems_monitor_separator();
114}
115
116/*
117 */
118
119void
120rtems_monitor_sema_dump(
121    rtems_monitor_sema_t *monitor_sema,
122    bool  verbose RTEMS_UNUSED
123)
124{
125    int length = 0;
126
127    length += rtems_monitor_dump_id(monitor_sema->id);
128    length += rtems_monitor_pad(11, length);
129    length += rtems_monitor_dump_name(monitor_sema->id);
130    length += rtems_monitor_pad(18, length);
131    length += rtems_monitor_dump_attributes(monitor_sema->attribute);
132    length += rtems_monitor_pad(30, length);
133    length += rtems_monitor_dump_priority(monitor_sema->priority_ceiling);
134    length += rtems_monitor_pad(38, length);
135    length += rtems_monitor_dump_decimal(monitor_sema->cur_count);
136    length += rtems_monitor_pad(47, length);
137    length += rtems_monitor_dump_id(monitor_sema->holder_id);
138    printf("\n");
139}
Note: See TracBrowser for help on using the repository browser.