summaryrefslogtreecommitdiffstats
path: root/cpukit/include/rtems/score/thread.h
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2021-10-27 12:59:09 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2021-11-15 08:56:53 +0100
commit240a1f79b1fcb58b9ae7bfc393e1f890e4492683 (patch)
tree92c47fa4899b2f0a8306e32bc18d66fbbf6b216f /cpukit/include/rtems/score/thread.h
parentscore: Do not shadow parameter (diff)
downloadrtems-240a1f79b1fcb58b9ae7bfc393e1f890e4492683.tar.bz2
score: Introduce CPU budget operations
This patch set replaces the CPU budget algorithm enumeration with a set of CPU budget operations which implement a particular CPU budget algorithm. This helps to hide the CPU budget algorithm implementation details from the general thread handling. The CPU budget callouts are turned into CPU budget operations. This slightly reduces the size of the thread control block. All schedulers used the default scheduler tick implementation. The tick scheduler operation is removed and the CPU budget operations are directly used in _Watchdog_Tick() if the executing thread uses a CPU budget algorithm. This is performance improvement for all threads which do not use a CPU budget algorithm (default behaviour).
Diffstat (limited to 'cpukit/include/rtems/score/thread.h')
-rw-r--r--cpukit/include/rtems/score/thread.h94
1 files changed, 49 insertions, 45 deletions
diff --git a/cpukit/include/rtems/score/thread.h b/cpukit/include/rtems/score/thread.h
index aff2f58d77..4c8a97c0f7 100644
--- a/cpukit/include/rtems/score/thread.h
+++ b/cpukit/include/rtems/score/thread.h
@@ -76,14 +76,6 @@ extern "C" {
*@{
*/
-#define RTEMS_SCORE_THREAD_ENABLE_EXHAUST_TIMESLICE
-
-/*
- * With the addition of the Constant Block Scheduler (CBS),
- * this feature is needed even when POSIX is disabled.
- */
-#define RTEMS_SCORE_THREAD_ENABLE_SCHEDULER_CALLOUT
-
#if defined(RTEMS_DEBUG)
#define RTEMS_SCORE_THREAD_ENABLE_RESOURCE_COUNT
#endif
@@ -148,27 +140,47 @@ typedef struct {
} Thread_Entry_information;
/**
- * The following lists the algorithms used to manage the thread cpu budget.
- *
- * Reset Timeslice: At each context switch, reset the time quantum.
- * Exhaust Timeslice: Only reset the quantum once it is consumed.
- * Callout: Execute routine when budget is consumed.
+ * @brief This structure contains operations which manage the CPU budget of a
+ * thread.
*/
-typedef enum {
- THREAD_CPU_BUDGET_ALGORITHM_NONE,
- THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE,
- #if defined(RTEMS_SCORE_THREAD_ENABLE_EXHAUST_TIMESLICE)
- THREAD_CPU_BUDGET_ALGORITHM_EXHAUST_TIMESLICE,
- #endif
- #if defined(RTEMS_SCORE_THREAD_ENABLE_SCHEDULER_CALLOUT)
- THREAD_CPU_BUDGET_ALGORITHM_CALLOUT
- #endif
-} Thread_CPU_budget_algorithms;
+typedef struct {
+ /**
+ * @brief This operation is called at each clock tick for the executing
+ * thread.
+ */
+ void ( *at_tick )( Thread_Control * );
-/** This defines thes the entry point for the thread specific timeslice
- * budget management algorithm.
+ /**
+ * @brief This operation is called right before a context switch to the
+ * thread is performed.
+ */
+ void ( *at_context_switch )( Thread_Control * );
+
+ /**
+ * @brief This operation is called to initialize the CPU budget of the
+ * thread.
+ */
+ void ( *initialize )( Thread_Control * );
+} Thread_CPU_budget_operations;
+
+/**
+ * @brief This structure is used to control the CPU budget of a thread.
*/
-typedef void (*Thread_CPU_budget_algorithm_callout )( Thread_Control * );
+typedef struct {
+ /**
+ * @brief If this member is not NULL, then it references the CPU budget
+ * operations used to manage the CPU budget of the thread, otherwise it is
+ * NULL.
+ */
+ const Thread_CPU_budget_operations *operations;
+
+ /**
+ * @brief This member contains the count of the time quantum that this thread
+ * is allowed to consume until an action takes place defined by the CPU
+ * budget operations.
+ */
+ uint32_t available;
+} Thread_CPU_budget_control;
/**
* The following structure contains the information which defines
@@ -182,12 +194,13 @@ typedef struct {
* it started.
*/
bool is_preemptible;
- /** This field indicates the CPU budget algorith. */
- Thread_CPU_budget_algorithms budget_algorithm;
- /** This field is the routine to invoke when the CPU allotment is
- * consumed.
+
+ /**
+ * @brief This member may provide the CPU budget operations activated when a
+ * thread is initialized before it is started or restarted.
*/
- Thread_CPU_budget_algorithm_callout budget_callout;
+ const Thread_CPU_budget_operations *cpu_budget_operations;
+
/** This field is the initial ISR disable level of this thread. */
uint32_t isr_level;
/** This field is the initial priority. */
@@ -772,9 +785,7 @@ struct _Thread_Control {
* the following fields
*
* - RTEMS_API_Control::Signal,
- * - Thread_Control::budget_algorithm,
- * - Thread_Control::budget_callout,
- * - Thread_Control::cpu_time_budget,
+ * - Thread_Control::CPU_budget,
* - Thread_Control::current_state,
* - Thread_Control::Post_switch_actions,
* - Thread_Control::Scheduler::control, and
@@ -841,18 +852,11 @@ struct _Thread_Control {
*/
bool was_created_with_inherited_scheduler;
- /** This field is the length of the time quantum that this thread is
- * allowed to consume. The algorithm used to manage limits on CPU usage
- * is specified by budget_algorithm.
- */
- uint32_t cpu_time_budget;
- /** This field is the algorithm used to manage this thread's time
- * quantum. The algorithm may be specified as none which case,
- * no limit is in place.
+ /**
+ * @brief This member contains the CPU budget control used to manage the CPU
+ * budget of the thread.
*/
- Thread_CPU_budget_algorithms budget_algorithm;
- /** This field is the method invoked with the budgeted time is consumed. */
- Thread_CPU_budget_algorithm_callout budget_callout;
+ Thread_CPU_budget_control CPU_budget;
/**
* @brief This member contains the amount of CPU time consumed by this thread