source: rtems/cpukit/score/include/rtems/score/mrsp.h @ 864d3475

4.11
Last change on this file since 864d3475 was 864d3475, checked in by Sebastian Huber <sebastian.huber@…>, on Dec 17, 2014 at 2:11:00 PM

smp: Fix timeout for MrsP semaphores

The previous timeout handling was flawed. In case a waiting thread
helped out the owner could use the scheduler node indefinitely long.
Update the resource tree in _MRSP_Timeout() to avoid this issue.

Bug reported by Luca Bonato.

  • Property mode set to 100644
File size: 4.2 KB
Line 
1/*
2 * Copyright (c) 2014 embedded brains GmbH.  All rights reserved.
3 *
4 *  embedded brains GmbH
5 *  Dornierstr. 4
6 *  82178 Puchheim
7 *  Germany
8 *  <rtems@embedded-brains.de>
9 *
10 * The license and distribution terms for this file may be
11 * found in the file LICENSE in this distribution or at
12 * http://www.rtems.org/license/LICENSE.
13 */
14
15#ifndef _RTEMS_SCORE_MRSP_H
16#define _RTEMS_SCORE_MRSP_H
17
18#include <rtems/score/cpuopts.h>
19
20#if defined(RTEMS_SMP)
21
22#include <rtems/score/chain.h>
23#include <rtems/score/scheduler.h>
24#include <rtems/score/thread.h>
25
26#ifdef __cplusplus
27extern "C" {
28#endif /* __cplusplus */
29
30/**
31 * @defgroup ScoreMRSP Multiprocessor Resource Sharing Protocol Handler
32 *
33 * @ingroup Score
34 *
35 * @brief Multiprocessor Resource Sharing Protocol (MrsP).
36 *
37 * The Multiprocessor Resource Sharing Protocol (MrsP) is defined in A.  Burns
38 * and A.J.  Wellings, A Schedulability Compatible Multiprocessor Resource
39 * Sharing Protocol - MrsP, Proceedings of the 25th Euromicro Conference on
40 * Real-Time Systems (ECRTS 2013), July 2013.  It is a generalization of the
41 * Priority Ceiling Protocol to SMP systems.  Each MrsP semaphore uses a
42 * ceiling priority per scheduler instance.  A task obtaining or owning a MrsP
43 * semaphore will execute with the ceiling priority for its scheduler instance
44 * as specified by the MrsP semaphore object.  Tasks waiting to get ownership
45 * of a MrsP semaphore will not relinquish the processor voluntarily.  In case
46 * the owner of a MrsP semaphore gets preempted it can ask all tasks waiting
47 * for this semaphore to help out and temporarily borrow the right to execute
48 * on one of their assigned processors.
49 *
50 * @{
51 */
52
53/**
54 * @brief MrsP status code.
55 *
56 * The values are chosen to directly map to RTEMS status codes.  In case this
57 * implementation is used for other APIs, then for example the errno values can
58 * be added with a bit shift.
59 */
60typedef enum {
61  MRSP_SUCCESSFUL = 0,
62  MRSP_TIMEOUT = 6,
63  MRSP_INVALID_NUMBER = 10,
64  MRSP_RESOUCE_IN_USE = 12,
65  MRSP_UNSATISFIED = 13,
66  MRSP_INCORRECT_STATE = 14,
67  MRSP_INVALID_PRIORITY = 19,
68  MRSP_NOT_OWNER_OF_RESOURCE = 23,
69  MRSP_NO_MEMORY = 26,
70
71  /**
72   * @brief Internal state used for MRSP_Rival::status to indicate that this
73   * rival waits for resource ownership.
74   */
75  MRSP_WAIT_FOR_OWNERSHIP = 255
76} MRSP_Status;
77
78/**
79 * @brief MrsP rival.
80 *
81 * The rivals are used by threads waiting for resource ownership.  They are
82 * registered in the MRSP control block.
83 */
84typedef struct {
85  /**
86   * @brief The node for registration in the MRSP rival chain.
87   *
88   * The chain operations are protected by the Giant lock and disabled
89   * interrupts.
90   *
91   * @see MRSP_Control::Rivals.
92   */
93  Chain_Node Node;
94
95  /**
96   * @brief Identification of the rival thread.
97   */
98  Thread_Control *thread;
99
100  /**
101   * @brief The initial priority of the thread at the begin of the resource
102   * obtain sequence.
103   *
104   * Used to restore the priority after a release of this resource or timeout.
105   */
106  Priority_Control initial_priority;
107
108  /**
109   * @brief The initial help state of the thread at the begin of the resource
110   * obtain sequence.
111   *
112   * Used to restore this state after a timeout.
113   */
114  Scheduler_Help_state initial_help_state;
115
116  /**
117   * @brief The rival status.
118   *
119   * Initially the status is set to MRSP_WAIT_FOR_OWNERSHIP.  The rival will
120   * busy wait until a status change happens.  This can be MRSP_SUCCESSFUL or
121   * MRSP_TIMEOUT.  State changes are protected by the Giant lock and disabled
122   * interrupts.
123   */
124  volatile MRSP_Status status;
125} MRSP_Rival;
126
127/**
128 * @brief MrsP control block.
129 */
130typedef struct {
131  /**
132   * @brief Basic resource control.
133   */
134  Resource_Control Resource;
135
136  /**
137   * @brief A chain of MrsP rivals waiting for resource ownership.
138   *
139   * @see MRSP_Rival::Node.
140   */
141  Chain_Control Rivals;
142
143  /**
144   * @brief The initial priority of the owner before it was elevated to the
145   * ceiling priority.
146   */
147  Priority_Control initial_priority_of_owner;
148
149  /**
150   * @brief One ceiling priority per scheduler instance.
151   */
152  Priority_Control *ceiling_priorities;
153} MRSP_Control;
154
155/** @} */
156
157#ifdef __cplusplus
158}
159#endif /* __cplusplus */
160
161#endif /* RTEMS_SMP */
162
163#endif /* _RTEMS_SCORE_MRSP_H */
Note: See TracBrowser for help on using the repository browser.