source: rtems/cpukit/score/include/rtems/score/schedulernode.h @ 6771359f

Last change on this file since 6771359f was 6771359f, checked in by Sebastian Huber <sebastian.huber@…>, on Oct 27, 2016 at 4:42:06 AM

score: Second part of new MrsP implementation

Update #2556.

  • Property mode set to 100644
File size: 5.9 KB
Line 
1/*
2 * Copyright (c) 2014, 2016 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_SCHEDULERNODE_H
16#define _RTEMS_SCORE_SCHEDULERNODE_H
17
18#include <rtems/score/basedefs.h>
19#include <rtems/score/chain.h>
20#include <rtems/score/priority.h>
21#include <rtems/score/smplockseq.h>
22
23struct _Thread_Control;
24
25#ifdef __cplusplus
26extern "C" {
27#endif /* __cplusplus */
28
29#if defined(RTEMS_SMP)
30/**
31 * @brief The scheduler node requests.
32 */
33typedef enum {
34  /**
35   * @brief The scheduler node is not on the list of pending requests.
36   */
37  SCHEDULER_NODE_REQUEST_NOT_PENDING,
38
39  /**
40   * @brief There is a pending scheduler node request to add this scheduler
41   * node to the Thread_Control::Scheduler::Scheduler_nodes chain.
42   */
43  SCHEDULER_NODE_REQUEST_ADD,
44
45  /**
46   * @brief There is a pending scheduler node request to remove this scheduler
47   * node from the Thread_Control::Scheduler::Scheduler_nodes chain.
48   */
49  SCHEDULER_NODE_REQUEST_REMOVE,
50
51  /**
52   * @brief The scheduler node is on the list of pending requests, but nothing
53   * should change.
54   */
55  SCHEDULER_NODE_REQUEST_NOTHING,
56
57} Scheduler_Node_request;
58#endif
59
60typedef struct Scheduler_Node Scheduler_Node;
61
62/**
63 * @brief Scheduler node for per-thread data.
64 */
65struct Scheduler_Node {
66#if defined(RTEMS_SMP)
67  /**
68   * @brief Chain node for usage in various scheduler data structures.
69   *
70   * Strictly this is the wrong place for this field since the data structures
71   * to manage scheduler nodes belong to the particular scheduler
72   * implementation.  Currently all SMP scheduler implementations use chains.
73   * The node is here to simplify things, just like the object node in the
74   * thread control block.  It may be replaced with a union to add a red-black
75   * tree node in the future.
76   */
77  Chain_Node Node;
78
79  /**
80   * @brief The sticky level determines if this scheduler node should use an
81   * idle thread in case this node is scheduled and the owner thread is
82   * blocked.
83   */
84  int sticky_level;
85
86  /**
87   * @brief The thread using this node.
88   *
89   * This is either the owner or an idle thread.
90   */
91  struct _Thread_Control *user;
92
93  /**
94   * @brief The idle thread claimed by this node in case the sticky level is
95   * greater than zero and the thread is block or is scheduled on another
96   * scheduler instance.
97   *
98   * This is necessary to ensure the priority ceiling protocols work across
99   * scheduler boundaries.
100   */
101  struct _Thread_Control *idle;
102#endif
103
104  /**
105   * @brief The thread owning this node.
106   */
107  struct _Thread_Control *owner;
108
109#if defined(RTEMS_SMP)
110  /**
111   * @brief The thread accepting help by this node in case the help state is
112   * not SCHEDULER_HELP_YOURSELF.
113   */
114  struct _Thread_Control *accepts_help;
115
116  /**
117   * @brief Block to register and manage this scheduler node in the thread
118   * control block of the owner of this scheduler node.
119   */
120  struct {
121    /**
122     * @brief Node to add this scheduler node to
123     * Thread_Control::Scheduler::Wait_nodes.
124     */
125    Chain_Node Wait_node;
126
127    /**
128     * @brief Node to add this scheduler node to
129     * Thread_Control::Scheduler::Scheduler_nodes or a temporary remove list.
130     */
131    union {
132      /**
133       * @brief The node for Thread_Control::Scheduler::Scheduler_nodes.
134       */
135      Chain_Node Chain;
136
137      /**
138       * @brief The next pointer for a temporary remove list.
139       *
140       * @see _Thread_Scheduler_process_requests().
141       */
142      Scheduler_Node *next;
143    } Scheduler_node;
144
145    /**
146     * @brief Link to the next scheduler node in the
147     * Thread_Control::Scheduler::requests list.
148     */
149    Scheduler_Node *next_request;
150
151    /**
152     * @brief The current scheduler node request.
153     */
154    Scheduler_Node_request request;
155  } Thread;
156#endif
157
158  /**
159   * @brief Thread wait support block.
160   */
161  struct {
162    Priority_Aggregation Priority;
163  } Wait;
164
165  /**
166   * @brief The thread priority information used by the scheduler.
167   *
168   * The thread priority is manifest in two independent areas.  One area is the
169   * user visible thread priority along with a potential thread queue.  The
170   * other is the scheduler.  During a thread priority change, the user visible
171   * thread priority and the thread queue are first updated and the thread
172   * priority value here is changed.  Once this is done the scheduler is
173   * notified via the update priority operation, so that it can update its
174   * internal state and honour a new thread priority value.
175   */
176  struct {
177    /**
178     * @brief The thread priority value of this scheduler node.
179     *
180     * The producer of this value is _Thread_Change_priority().  The consumer
181     * is the scheduler via the unblock and update priority operations.
182     */
183    Priority_Control value;
184
185#if defined(RTEMS_SMP)
186    /**
187     * @brief Sequence lock to synchronize priority value updates.
188     */
189    SMP_sequence_lock_Control Lock;
190#endif
191
192    /**
193     * @brief In case a priority update is necessary and this is true, then
194     * enqueue the thread as the first of its priority group, otherwise enqueue
195     * the thread as the last of its priority group.
196     */
197    bool prepend_it;
198  } Priority;
199};
200
201#if defined(RTEMS_SMP)
202/**
203 * @brief The size of a scheduler node.
204 *
205 * This value is provided via <rtems/confdefs.h>.
206 */
207extern const size_t _Scheduler_Node_size;
208#endif
209
210#if defined(RTEMS_SMP)
211#define SCHEDULER_NODE_OF_THREAD_WAIT_NODE( node ) \
212  RTEMS_CONTAINER_OF( node, Scheduler_Node, Thread.Wait_node )
213
214#define SCHEDULER_NODE_OF_THREAD_SCHEDULER_NODE( node ) \
215  RTEMS_CONTAINER_OF( node, Scheduler_Node, Thread.Scheduler_node.Chain )
216#endif
217
218#ifdef __cplusplus
219}
220#endif /* __cplusplus */
221
222#endif /* _RTEMS_SCORE_SCHEDULERNODE_H */
Note: See TracBrowser for help on using the repository browser.