source: rtems/cpukit/include/rtems/score/schedulernode.h @ 255fe43

Last change on this file since 255fe43 was 255fe43, checked in by Joel Sherrill <joel@…>, on 03/01/22 at 20:40:44

cpukit/: Scripted embedded brains header file clean up

Updates #4625.

  • Property mode set to 100644
File size: 7.3 KB
Line 
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/**
4 * @file
5 *
6 * @ingroup RTEMSScoreScheduler
7 *
8 * @brief This header file provides interfaces of the
9 *   @ref RTEMSScoreScheduler related to scheduler nodes which are used by the
10 *   implementation and the @ref RTEMSImplApplConfig.
11 */
12
13/*
14 * Copyright (c) 2014, 2016 embedded brains GmbH.  All rights reserved.
15 *
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions
18 * are met:
19 * 1. Redistributions of source code must retain the above copyright
20 *    notice, this list of conditions and the following disclaimer.
21 * 2. Redistributions in binary form must reproduce the above copyright
22 *    notice, this list of conditions and the following disclaimer in the
23 *    documentation and/or other materials provided with the distribution.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
29 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
36 */
37
38#ifndef _RTEMS_SCORE_SCHEDULERNODE_H
39#define _RTEMS_SCORE_SCHEDULERNODE_H
40
41#include <rtems/score/basedefs.h>
42#include <rtems/score/chain.h>
43#include <rtems/score/priority.h>
44#include <rtems/score/isrlock.h>
45
46/**
47 * @addtogroup RTEMSScoreScheduler
48 *
49 * @{
50 */
51
52struct _Thread_Control;
53
54#ifdef __cplusplus
55extern "C" {
56#endif /* __cplusplus */
57
58#if defined(RTEMS_SMP)
59/**
60 * @brief The scheduler node requests.
61 */
62typedef enum {
63  /**
64   * @brief The scheduler node is not on the list of pending requests.
65   */
66  SCHEDULER_NODE_REQUEST_NOT_PENDING,
67
68  /**
69   * @brief There is a pending scheduler node request to add this scheduler
70   * node to the Thread_Control::Scheduler::Scheduler_nodes chain.
71   */
72  SCHEDULER_NODE_REQUEST_ADD,
73
74  /**
75   * @brief There is a pending scheduler node request to remove this scheduler
76   * node from the Thread_Control::Scheduler::Scheduler_nodes chain.
77   */
78  SCHEDULER_NODE_REQUEST_REMOVE,
79
80  /**
81   * @brief The scheduler node is on the list of pending requests, but nothing
82   * should change.
83   */
84  SCHEDULER_NODE_REQUEST_NOTHING,
85
86} Scheduler_Node_request;
87#endif
88
89typedef struct Scheduler_Node Scheduler_Node;
90
91/**
92 * @brief Scheduler node for per-thread data.
93 */
94struct Scheduler_Node {
95#if defined(RTEMS_SMP)
96  /**
97   * @brief Chain node for usage in various scheduler data structures.
98   *
99   * Strictly, this is the wrong place for this field since the data structures
100   * to manage scheduler nodes belong to the particular scheduler
101   * implementation.  Currently, all SMP scheduler implementations use chains
102   * or red-black trees.  The node is here to simplify things, just like the
103   * object node in the thread control block.
104   */
105  union {
106    Chain_Node Chain;
107    RBTree_Node RBTree;
108  } Node;
109
110  /**
111   * @brief The sticky level determines if this scheduler node should use an
112   * idle thread in case this node is scheduled and the owner thread is
113   * blocked.
114   */
115  int sticky_level;
116
117  /**
118   * @brief The thread using this node.
119   *
120   * This is either the owner or an idle thread.
121   */
122  struct _Thread_Control *user;
123
124  /**
125   * @brief The idle thread claimed by this node in case the sticky level is
126   * greater than zero and the thread is block or is scheduled on another
127   * scheduler instance.
128   *
129   * This is necessary to ensure the priority ceiling protocols work across
130   * scheduler boundaries.
131   */
132  struct _Thread_Control *idle;
133#endif
134
135  /**
136   * @brief The thread owning this node.
137   */
138  struct _Thread_Control *owner;
139
140#if defined(RTEMS_SMP)
141  /**
142   * @brief Block to register and manage this scheduler node in the thread
143   * control block of the owner of this scheduler node.
144   */
145  struct {
146    /**
147     * @brief Node to add this scheduler node to
148     * Thread_Control::Scheduler::Wait_nodes.
149     */
150    Chain_Node Wait_node;
151
152    /**
153     * @brief Node to add this scheduler node to
154     * Thread_Control::Scheduler::Scheduler_nodes or a temporary remove list.
155     */
156    union {
157      /**
158       * @brief The node for Thread_Control::Scheduler::Scheduler_nodes.
159       */
160      Chain_Node Chain;
161
162      /**
163       * @brief The next pointer for a temporary remove list.
164       *
165       * @see _Thread_Scheduler_process_requests().
166       */
167      Scheduler_Node *next;
168    } Scheduler_node;
169
170    /**
171     * @brief Link to the next scheduler node in the
172     * Thread_Control::Scheduler::requests list.
173     */
174    Scheduler_Node *next_request;
175
176    /**
177     * @brief The current scheduler node request.
178     */
179    Scheduler_Node_request request;
180  } Thread;
181#endif
182
183  /**
184   * @brief Thread wait support block.
185   */
186  struct {
187    Priority_Aggregation Priority;
188  } Wait;
189
190  /**
191   * @brief The thread priority information used by the scheduler.
192   *
193   * The thread priority is manifest in two independent areas.  One area is the
194   * user visible thread priority along with a potential thread queue.  The
195   * other is the scheduler.  During a thread priority change, the user visible
196   * thread priority and the thread queue are first updated and the thread
197   * priority value here is changed.  Once this is done the scheduler is
198   * notified via the update priority operation, so that it can update its
199   * internal state and honour a new thread priority value.
200   */
201  struct {
202    /**
203     * @brief The thread priority value of this scheduler node.
204     *
205     * The producer of this value is _Thread_Change_priority().  The consumer
206     * is the scheduler via the unblock and update priority operations.
207     *
208     * This priority control consists of two parts.  One part is the plain
209     * priority value (most-significant 63 bits).  The other part is the
210     * least-significant bit which indicates if the thread should be appended
211     * (bit set) or prepended (bit cleared) to its priority group, see
212     * SCHEDULER_PRIORITY_APPEND().
213     *
214     * @see _Scheduler_Node_get_priority() and _Scheduler_Node_set_priority().
215     */
216#if defined(RTEMS_SMP) && CPU_SIZEOF_POINTER == 8
217    Atomic_Ulong value;
218#else
219    Priority_Control value;
220#endif
221
222#if defined(RTEMS_SMP) && CPU_SIZEOF_POINTER != 8
223    /**
224     * @brief The lock protects the priority value.
225     */
226    ISR_lock_Control Lock;
227#endif
228  } Priority;
229};
230
231#if defined(RTEMS_SMP)
232/**
233 * @brief The size of a scheduler node.
234 *
235 * This value is provided via <rtems/confdefs.h>.
236 */
237extern const size_t _Scheduler_Node_size;
238#endif
239
240#if defined(RTEMS_SMP)
241#define SCHEDULER_NODE_OF_THREAD_WAIT_NODE( node ) \
242  RTEMS_CONTAINER_OF( node, Scheduler_Node, Thread.Wait_node )
243
244#define SCHEDULER_NODE_OF_THREAD_SCHEDULER_NODE( node ) \
245  RTEMS_CONTAINER_OF( node, Scheduler_Node, Thread.Scheduler_node.Chain )
246#endif
247
248#ifdef __cplusplus
249}
250#endif /* __cplusplus */
251
252/** @} */
253
254#endif /* _RTEMS_SCORE_SCHEDULERNODE_H */
Note: See TracBrowser for help on using the repository browser.