source: rtems/cpukit/include/rtems/score/schedulernode.h @ 7b85efb8

Last change on this file since 7b85efb8 was 7b85efb8, checked in by Joel Sherrill <joel@…>, on 02/16/22 at 21:16:11

cpukit/include/rtems/score/[s-z]*.h: Change license to BSD-2

Updates #3053.

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