source: rtems/cpukit/score/include/rtems/score/priority.h @ 300f6a48

5
Last change on this file since 300f6a48 was 300f6a48, checked in by Sebastian Huber <sebastian.huber@…>, on 06/22/16 at 15:09:23

score: Rework thread priority management

Add priority nodes which contribute to the overall thread priority.

The actual priority of a thread is now an aggregation of priority nodes.
The thread priority aggregation for the home scheduler instance of a
thread consists of at least one priority node, which is normally the
real priority of the thread. The locking protocols (e.g. priority
ceiling and priority inheritance), rate-monotonic period objects and the
POSIX sporadic server add, change and remove priority nodes.

A thread changes its priority now immediately, e.g. priority changes are
not deferred until the thread releases its last resource.

Replace the _Thread_Change_priority() function with

  • _Thread_Priority_perform_actions(),
  • _Thread_Priority_add(),
  • _Thread_Priority_remove(),
  • _Thread_Priority_change(), and
  • _Thread_Priority_update().

Update #2412.
Update #2556.

  • Property mode set to 100644
File size: 4.6 KB
Line 
1/**
2 * @file
3 *
4 * @brief Priority Handler API
5 */
6
7/*
8 *  COPYRIGHT (c) 1989-2011.
9 *  On-Line Applications Research Corporation (OAR).
10 *
11 *  Copyright (c) 2016 embedded brains GmbH.
12 *
13 *  The license and distribution terms for this file may be
14 *  found in the file LICENSE in this distribution or at
15 *  http://www.rtems.org/license/LICENSE.
16 */
17
18#ifndef _RTEMS_SCORE_PRIORITY_H
19#define _RTEMS_SCORE_PRIORITY_H
20
21#include <rtems/score/chain.h>
22#include <rtems/score/cpu.h>
23#include <rtems/score/rbtree.h>
24
25struct Scheduler_Control;
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31/**
32 * @defgroup ScorePriority Priority Handler
33 *
34 * @ingroup Score
35 *
36 * This handler encapsulates functionality which is used to manage thread
37 * priorities.  The actual priority of a thread is an aggregation of priority
38 * nodes.  The thread priority aggregation for the home scheduler instance of a
39 * thread consists of at least one priority node, which is normally the real
40 * priority of the thread.  The locking protocols (e.g. priority ceiling and
41 * priority inheritance), rate-monotonic period objects and the POSIX sporadic
42 * server add, change and remove priority nodes.
43 *
44 * @{
45 */
46
47/**
48 * @brief A plain thread priority value.
49 *
50 * Lower values represent higher priorities.  So, a priority value of zero
51 * represents the highest priority thread.  This value is reserved for internal
52 * threads and the priority ceiling protocol.
53 */
54typedef uint64_t Priority_Control;
55
56/**
57 * @brief The highest (most important) thread priority value.
58 */
59#define PRIORITY_MINIMUM      0
60
61/**
62 * @brief The priority value of pseudo-ISR threads.
63 *
64 * Examples are the MPCI and timer server threads.
65 */
66#define PRIORITY_PSEUDO_ISR   PRIORITY_MINIMUM
67
68/**
69 * @brief The default lowest (least important) thread priority value.
70 *
71 * This value is CPU port dependent.
72 */
73#if defined (CPU_PRIORITY_MAXIMUM)
74  #define PRIORITY_DEFAULT_MAXIMUM      CPU_PRIORITY_MAXIMUM
75#else
76  #define PRIORITY_DEFAULT_MAXIMUM      255
77#endif
78
79/**
80 * @brief The priority node to build up a priority aggregation.
81 */
82typedef struct {
83  /**
84   * @brief Node component for a chain or red-black tree.
85   */
86  union {
87    Chain_Node Chain;
88    RBTree_Node RBTree;
89  } Node;
90
91  /**
92   * @brief The priority value of this node.
93   */
94  Priority_Control priority;
95} Priority_Node;
96
97/**
98 * @brief The priority action type.
99 */
100typedef enum {
101  PRIORITY_ACTION_ADD,
102  PRIORITY_ACTION_CHANGE,
103  PRIORITY_ACTION_REMOVE,
104  PRIORITY_ACTION_INVALID
105} Priority_Action_type;
106
107typedef struct Priority_Aggregation Priority_Aggregation;
108
109/**
110 * @brief The priority aggregation.
111 *
112 * This structure serves two purposes.  Firstly, it provides a place to
113 * register priority nodes and reflects the overall priority of its
114 * contributors.  Secondly, it provides an action block to signal addition,
115 * change and removal of a priority node.
116 */
117struct Priority_Aggregation {
118  /**
119   * @brief This priority node reflects the overall priority of the aggregation.
120   *
121   * The overall priority of the aggregation is the minimum priority of the
122   * priority nodes in the contributors tree.
123   *
124   * This priority node may be used to add this aggregation to another
125   * aggregation to build up a recursive priority scheme.
126   *
127   * In case priority nodes of the contributors tree are added, changed or
128   * removed the priority of this node may change.  To signal such changes to a
129   * priority aggregation the action block may be used.
130   */
131  Priority_Node Node;
132
133  /**
134   * @brief A red-black tree to contain priority nodes contributing to the
135   * overall priority of this priority aggregation.
136   */
137  RBTree_Control Contributors;
138
139#if defined(RTEMS_SMP)
140  /**
141   * @brief The scheduler instance of this priority aggregation.
142   */
143  const struct Scheduler_Control *scheduler;
144#endif
145
146  /**
147   * @brief A priority action block to manage priority node additions, changes
148   * and removals.
149   */
150  struct {
151#if defined(RTEMS_SMP)
152    /**
153     * @brief The next priority aggregation in the action list.
154     */
155    Priority_Aggregation *next;
156#endif
157
158    /**
159     * @brief The priority node of the action.
160     */
161    Priority_Node *node;
162
163    /**
164     * @brief The type of the action.
165     */
166    Priority_Action_type type;
167  } Action;
168};
169
170/**
171 * @brief A list of priority actions.
172 *
173 * Actions are only added to the list.  The action lists reside on the stack
174 * and have a short life-time.  They are moved, processed or destroyed as a
175 * whole.
176 */
177typedef struct {
178  /**
179   * @brief The first action of a priority action list.
180   */
181  Priority_Aggregation *actions;
182} Priority_Actions;
183
184#ifdef __cplusplus
185}
186#endif
187
188/**@}*/
189
190#endif
191/* end of include file */
Note: See TracBrowser for help on using the repository browser.