RTEMS CPU Kit with SuperCore  4.11.2
thread.h
Go to the documentation of this file.
1 
10 /*
11  * COPYRIGHT (c) 1989-2014.
12  * On-Line Applications Research Corporation (OAR).
13  *
14  * Copyright (c) 2014 embedded brains GmbH.
15  *
16  * The license and distribution terms for this file may be
17  * found in the file LICENSE in this distribution or at
18  * http://www.rtems.org/license/LICENSE.
19  */
20 
21 #ifndef _RTEMS_SCORE_THREAD_H
22 #define _RTEMS_SCORE_THREAD_H
23 
24 #include <rtems/score/atomic.h>
25 #include <rtems/score/context.h>
26 #if defined(RTEMS_MULTIPROCESSING)
27 #include <rtems/score/mppkt.h>
28 #endif
29 #include <rtems/score/isrlock.h>
30 #include <rtems/score/object.h>
31 #include <rtems/score/priority.h>
32 #include <rtems/score/resource.h>
33 #include <rtems/score/stack.h>
34 #include <rtems/score/states.h>
35 #include <rtems/score/threadq.h>
36 #include <rtems/score/watchdog.h>
37 
38 #if defined(RTEMS_SMP)
39  #include <rtems/score/cpuset.h>
40 #endif
41 
42 struct Per_CPU_Control;
43 
44 struct Scheduler_Control;
45 
46 struct Scheduler_Node;
47 
48 #ifdef __cplusplus
49 extern "C" {
50 #endif
51 
69 #if defined(RTEMS_POSIX_API)
70  #define RTEMS_SCORE_THREAD_ENABLE_EXHAUST_TIMESLICE
71 #endif
72 
73 /*
74  * With the addition of the Constant Block Scheduler (CBS),
75  * this feature is needed even when POSIX is disabled.
76  */
77 #define RTEMS_SCORE_THREAD_ENABLE_SCHEDULER_CALLOUT
78 
79 #if defined(RTEMS_POSIX_API)
80  #define RTEMS_SCORE_THREAD_ENABLE_USER_PROVIDED_STACK_VIA_API
81 #endif
82 
83 /*
84  * The user can define this at configure time and go back to ticks
85  * resolution.
86  */
87 #include <rtems/score/timestamp.h>
88 
89 typedef Timestamp_Control Thread_CPU_usage_t;
90 
99 typedef void *Thread;
100 
111 
119 typedef enum {
120  THREAD_START_NUMERIC,
121  THREAD_START_POINTER,
122  #if defined(FUNCTIONALITY_NOT_CURRENTLY_USED_BY_ANY_API)
123  THREAD_START_BOTH_POINTER_FIRST,
124  THREAD_START_BOTH_NUMERIC_FIRST
125  #endif
127 
129 typedef Thread ( *Thread_Entry )( void ); /* basic type */
130 
135 
139 typedef Thread ( *Thread_Entry_pointer )( void * );
140 
145 
151 
159 typedef enum {
160  THREAD_CPU_BUDGET_ALGORITHM_NONE,
161  THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE,
162  #if defined(RTEMS_SCORE_THREAD_ENABLE_EXHAUST_TIMESLICE)
163  THREAD_CPU_BUDGET_ALGORITHM_EXHAUST_TIMESLICE,
164  #endif
165  #if defined(RTEMS_SCORE_THREAD_ENABLE_SCHEDULER_CALLOUT)
166  THREAD_CPU_BUDGET_ALGORITHM_CALLOUT
167  #endif
169 
174 
175 #if !defined(RTEMS_SMP)
176 
181 struct rtems_task_variable_tt;
182 
188 typedef struct {
190  struct rtems_task_variable_tt *next;
194  void **ptr;
196  void *gval;
198  void *tval;
200  void (*dtor)(void *);
202 #endif
203 
208 typedef struct {
212  Thread_Start_types prototype;
216  Thread_Entry_numeric_type numeric_argument;
217  /*-------------- initial execution modes ----------------- */
223  Thread_CPU_budget_algorithms budget_algorithm;
229  uint32_t isr_level;
232  #if defined(RTEMS_SCORE_THREAD_ENABLE_USER_PROVIDED_STACK_VIA_API)
233 
234  bool core_allocated_stack;
235  #endif
236 
238  #if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
239 
241  #endif
242 
243  void *stack;
245  void *tls_area;
247 
258 typedef union {
259  void *mutable_object;
260  const void *immutable_object;
262 
277 typedef unsigned int Thread_Wait_flags;
278 
285 typedef struct {
289  union {
294 
299  } Node;
300 
304  uint32_t count;
311  uint32_t option;
317  uint32_t return_code;
318 
322  uint32_t timeout_code;
323 
333 
338 #if defined(RTEMS_SMP)
339  Atomic_Uint flags;
340 #else
341  Thread_Wait_flags flags;
342 #endif
343 
353 
361 typedef struct {
366 
374 
382 
390 
401 
403  uint32_t resource_count;
404 
409 #if defined(RTEMS_MULTIPROCESSING)
410 
411  MP_packet_Prefix *receive_packet;
412 #endif
413  /****************** end of common block ********************/
417 
425 typedef enum {
430 } Thread_APIs;
431 
433 #define THREAD_API_FIRST THREAD_API_RTEMS
434 
436 #define THREAD_API_LAST THREAD_API_POSIX
437 
438 typedef struct Thread_Action Thread_Action;
439 
456 typedef void ( *Thread_Action_handler )(
457  Thread_Control *thread,
458  Thread_Action *action,
459  struct Per_CPU_Control *cpu,
460  ISR_Level level
461 );
462 
481  Chain_Node Node;
482  Thread_Action_handler handler;
483 };
484 
490 typedef struct {
491  Chain_Control Chain;
493 
501 typedef enum {
502  THREAD_LIFE_NORMAL = 0x0,
503  THREAD_LIFE_PROTECTED = 0x1,
504  THREAD_LIFE_RESTARTING = 0x2,
505  THREAD_LIFE_PROTECTED_RESTARTING = 0x3,
506  THREAD_LIFE_TERMINATING = 0x4,
507  THREAD_LIFE_PROTECTED_TERMINATING = 0x5,
508  THREAD_LIFE_RESTARTING_TERMINATING = 0x6,
509  THREAD_LIFE_PROTECTED_RESTARTING_TERMINATING = 0x7
511 
515 typedef struct {
521 
526 
536 
537 #if defined(RTEMS_SMP)
538 
541 typedef enum {
547  THREAD_SCHEDULER_BLOCKED,
548 
556  THREAD_SCHEDULER_SCHEDULED,
557 
563  THREAD_SCHEDULER_READY
564 } Thread_Scheduler_state;
565 #endif
566 
570 typedef struct {
571 #if defined(RTEMS_SMP)
572 
575  Thread_Scheduler_state state;
576 
582  const struct Scheduler_Control *own_control;
583 
589  const struct Scheduler_Control *control;
590 
597  struct Scheduler_Node *own_node;
598 #endif
599 
610 
611 #if defined(RTEMS_SMP)
612 
615  struct Per_CPU_Control *cpu;
616 
617 #if defined(RTEMS_DEBUG)
618 
622  struct Per_CPU_Control *debug_real_cpu;
623 #endif
624 #endif
626 
627 typedef struct {
628  uint32_t flags;
629  void * control;
631 
632 #if defined(RTEMS_SMP)
633 
649 typedef struct {
653  ISR_lock_Control *current;
654 
659  ISR_lock_Control Default;
660 
664  Atomic_Uint generation;
665 } Thread_Lock_control;
666 #endif
667 
676 
684 
692 
700 
711 
713  uint32_t resource_count;
718 #if defined(RTEMS_MULTIPROCESSING)
719 
720  MP_packet_Prefix *receive_packet;
721 #endif
722  /*================= end of common block =================*/
723 
724 #if defined(RTEMS_SMP)
725 
728  Thread_Lock_control Lock;
729 #endif
730 
731 #ifdef __RTEMS_STRICT_ORDER_MUTEX__
732 
735  Chain_Control lock_mutex;
736 #endif
737 #if defined(RTEMS_SMP)
738 
742  Resource_Node Resource_node;
743 #endif
744 #if defined(RTEMS_MULTIPROCESSING)
745 
746  bool is_global;
747 #endif
748 
751  bool is_fp;
752 
757 
758 #if __RTEMS_ADA__
759 
760  void *rtems_ada_self;
761 #endif
762 
766  uint32_t cpu_time_budget;
771  Thread_CPU_budget_algorithms budget_algorithm;
777  Thread_CPU_usage_t cpu_time_used;
778 
783 
784  Thread_Action_control Post_switch_actions;
785 
788 #if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
789 
793 #endif
794 
795  struct _reent *libc_reent;
797  void *API_Extensions[ THREAD_API_LAST + 1 ];
798 
799 #if !defined(RTEMS_SMP)
800 
802 #endif
803 
812 
819 
820  Thread_Capture_control Capture;
821 
827  void *extensions[ RTEMS_ZERO_LENGTH_ARRAY ];
828 };
829 
830 #if (CPU_PROVIDES_IDLE_THREAD_BODY == FALSE)
831 
836 void *_Thread_Idle_body(
837  uintptr_t ignored
838 );
839 #endif
840 
844 
852 );
853 
857 typedef struct {
864 
871 
886 
894 extern const size_t _Thread_Control_add_on_count;
895 
903 extern const size_t _Thread_Control_size;
904 
907 #ifdef __cplusplus
908 }
909 #endif
910 
911 #endif
912 /* end of include file */
void(* Thread_Action_handler)(Thread_Control *thread, Thread_Action *action, struct Per_CPU_Control *cpu, ISR_Level level)
Thread action handler.
Definition: thread.h:456
Constants and Structures Associated with the Object Handler.
const size_t _Thread_Control_add_on_count
Thread control add-on count.
void * _Thread_Idle_body(uintptr_t ignored)
This routine is the body of the system idle thread.
Context_Control_fp * fp_context
This field is the initial FP context area address.
Definition: thread.h:240
Thread Priority Manipulation Routines.
This is used to manage each element (node) which is placed on a chain.
Definition: chain.h:65
uintptr_t CPU_Uint32ptr
Type that can store a 32-bit integer or a pointer.
Definition: types.h:41
The following record contains the prefix for every packet passed between nodes in an MP system...
Definition: mppkt.h:80
Chain_Node Active
This field is used to manage the set of proxies in the system.
Definition: thread.h:415
Thread_Life_state state
The current thread life state.
Definition: thread.h:525
The following structure contains the information which defines the starting state of a thread...
Definition: thread.h:208
const Thread_queue_Operations * operations
The current thread queue operations.
Definition: thread.h:351
Thread(* Thread_Entry_both_pointer_first)(void *, Thread_Entry_numeric_type)
This type corresponds to a thread entry point which takes a single untyped pointer and an unsigned th...
Definition: thread.h:144
Thread_Wait_information Wait
This field is the blocking information for this proxy.
Definition: thread.h:406
Scheduler control.
Definition: scheduler.h:192
The following defines the Object Control Block used to manage each object local to this node...
Definition: object.h:232
Priority_Control current_priority
This field is the current priority state of this thread.
Definition: thread.h:683
Information About Each Thread&#39;s Context.
void rtems_iterate_over_all_threads(rtems_per_thread_routine routine)
Iterates over all threads.
Definition: iterateoverthreads.c:24
Thread_CPU_budget_algorithm_callout budget_callout
This field is the method invoked with the budgeted time is consumed.
Definition: thread.h:773
uint32_t timeout_code
Code to set the timeout return code in _Thread_Timeout().
Definition: thread.h:322
Chain_Node Chain
A node for chains.
Definition: thread.h:293
Thread_queue_Control * queue
The current thread queue.
Definition: thread.h:332
This defines the minimal set of integer and processor state registers that must be saved during a vol...
Definition: cpu.h:248
Union type to hold a pointer to an immutable or a mutable object.
Definition: thread.h:258
Thread_Start_information Start
This field contains information about the starting state of this thread.
Definition: thread.h:782
void ** ptr
This field points to the physical memory location of this per task variable.
Definition: thread.h:194
Definition: thread.h:627
uint32_t cpu_time_budget
This field is the length of the time quantum that this thread is allowed to consume.
Definition: thread.h:766
Information About the CPU Set.
void * gval
This field is to the global value for this per task variable.
Definition: thread.h:196
Thread_CPU_budget_algorithms budget_algorithm
This field is the algorithm used to manage this thread&#39;s time quantum.
Definition: thread.h:771
The control block used to manage each watchdog timer.
Definition: watchdog.h:98
Priority_Control real_priority
This field is the base priority of this thread.
Definition: thread.h:381
This is used to manage a chain.
Definition: chain.h:83
void * return_argument
This field is for a pointer to a user return argument.
Definition: thread.h:306
uint32_t return_code
This field will contain the return status from a blocking operation.
Definition: thread.h:317
size_t destination_offset
Offset of the pointer field in Thread_Control referencing an application configuration dependent memo...
Definition: thread.h:863
Helpers for Manipulating Timestamps.
Thread Execution State Information.
This is the structure used to manage sets of tasks which are blocked waiting to acquire a resource...
Definition: threadq.h:171
void * tls_area
The thread-local storage (TLS) area.
Definition: thread.h:245
This value is for the Classic RTEMS API.
Definition: thread.h:427
Constants and Structures Associated with Watchdog Timers.
bool priority_restore_hint
Hints if a priority restore is necessary once the resource count changes from one to zero...
Definition: thread.h:710
Constants and Structures Needed to Declare a Thread Queue.
Thread_Control * terminator
The terminator thread of this thread.
Definition: thread.h:534
ISR lock control.
Definition: isrlock.h:56
Resource node to reflect ownership of resources and a dependency on a resource.
Definition: resource.h:150
void(* rtems_per_thread_routine)(Thread_Control *)
This defines the type for a method which operates on a single thread.
Definition: thread.h:843
Thread(* Thread_Entry)(void)
This type corresponds to a very simple style thread entry point.
Definition: thread.h:129
uint32_t resource_count
This field is the number of mutexes currently held by this proxy.
Definition: thread.h:403
Information required to manage a thread while it is blocked.
Definition: thread.h:285
Thread queue operations.
Definition: threadq.h:118
bool priority_restore_hint
Hints if a priority restore is necessary once the resource count changes from one to zero...
Definition: thread.h:400
Thread_CPU_usage_t cpu_time_used
This field is the amount of CPU time consumed by this thread since it was created.
Definition: thread.h:777
uint32_t Priority_Control
The following type defines the control block used to manage thread priorities.
Definition: priority.h:56
Thread_Scheduler_control Scheduler
Scheduler related control.
Definition: thread.h:756
struct rtems_task_variable_tt * next
This field points to the next per task variable for this task.
Definition: thread.h:190
size_t source_offset
Offset relative to the thread control block begin to an application configuration dependent memory ar...
Definition: thread.h:869
uint32_t priority_generation
Generation of the current priority value.
Definition: thread.h:389
void(* Thread_CPU_budget_algorithm_callout)(Thread_Control *)
This defines thes the entry point for the thread specific timeslice budget management algorithm...
Definition: thread.h:173
Objects_Control Object
This field is the object management structure for each thread.
Definition: thread.h:673
uint32_t ISR_Level
The following type defines the control block used to manage the interrupt level portion of the status...
Definition: isrlevel.h:42
Control block to manage thread actions.
Definition: thread.h:490
Thread(* Thread_Entry_both_numeric_first)(Thread_Entry_numeric_type, void *)
This type corresponds to a thread entry point which takes a single unsigned thirty-two bit integer an...
Definition: thread.h:150
struct Scheduler_Node * node
The scheduler node of this thread.
Definition: thread.h:609
This structure defines the Thread Control Block (TCB).
Definition: thread.h:671
bool is_fp
This field is true if the thread uses the floating point unit.
Definition: thread.h:751
Per CPU Core Structure.
Definition: percpu.h:233
bool is_preemptible
This field indicates whether the thread was preemptible when it started.
Definition: thread.h:221
Thread_Start_types prototype
This field indicates the how task is invoked.
Definition: thread.h:212
Thread control add-on.
Definition: thread.h:857
Thread action.
Definition: thread.h:480
struct _reent * libc_reent
This field points to the newlib reentrancy structure for this thread.
Definition: thread.h:795
Thread_Life_state
Thread life states.
Definition: thread.h:501
Thread_Start_types
The following defines the ways in which the entry point for a thread can be invoked.
Definition: thread.h:119
uint32_t resource_count
This field is the number of mutexes currently held by this thread.
Definition: thread.h:713
Objects_Id id
This field is the Id of the object this thread is waiting upon.
Definition: thread.h:302
Context_Control_fp * fp_context
This field points to the floating point context for this thread.
Definition: thread.h:792
Specification for the Packet Handler.
Thread_Life_control Life
Thread life-cycle control.
Definition: thread.h:818
Priority_Control real_priority
This field is the base priority of this thread.
Definition: thread.h:691
uint32_t isr_level
This field is the initial ISR disable level of this thread.
Definition: thread.h:229
uint32_t priority_generation
Generation of the current priority value.
Definition: thread.h:699
This defines the complete set of floating point registers that must be saved during any context switc...
Definition: cpu.h:294
Thread(* Thread_Entry_pointer)(void *)
This type corresponds to a thread entry point which takes a single untyped pointer as an argument...
Definition: thread.h:139
Watchdog_Control Timer
This field is the Watchdog used to manage proxy delays and timeouts.
Definition: thread.h:408
Priority_Control initial_priority
This field is the initial priority.
Definition: thread.h:231
Thread_CPU_budget_algorithm_callout budget_callout
This field is the routine to invoke when the CPU allotment is consumed.
Definition: thread.h:227
States_Control current_state
This field is the current execution state of this thread.
Definition: thread.h:675
struct bintime Timestamp_Control
Define the Timestamp control type.
Definition: timestamp.h:55
SCORE_EXTERN void * rtems_ada_self
Self for the GNU Ada Run-Time.
Definition: threadimpl.h:55
This value is for the POSIX API.
Definition: thread.h:429
uint32_t States_Control
The following type defines the control block used to manage a thread&#39;s state.
Definition: states.h:41
Stack_Control Initial_stack
This field is the stack information.
Definition: thread.h:237
void * tval
This field is to this thread&#39;s value for this per task variable.
Definition: thread.h:198
States_Control current_state
This field is the current execution state of this proxy.
Definition: thread.h:365
uint32_t count
This field is used to return an integer while when blocked.
Definition: thread.h:304
Thread scheduler control.
Definition: thread.h:570
Context_Control Registers
This field contains the context of this thread.
Definition: thread.h:787
CPU_Uint32ptr Thread_Entry_numeric_type
Type of the numeric argument of a thread entry function with at least one numeric argument...
Definition: thread.h:110
Atomic Operations API.
Watchdog_Control Timer
This field is the Watchdog used to manage thread delays and timeouts.
Definition: thread.h:717
Scheduler node for per-thread data.
Definition: scheduler.h:281
Chain_Control Key_Chain
This is the thread key value chain&#39;s control, which is used to track all key value for specific threa...
Definition: thread.h:811
Thread_Wait_information_Object_argument_type return_argument_second
This field is for a pointer to a second user return argument.
Definition: thread.h:309
Thread_Wait_flags flags
This field contains several flags used to control the wait class and state of a thread in case fine-g...
Definition: thread.h:341
The following defines the control block used to manage each thread proxy.
Definition: thread.h:361
The following defines the control block used to manage each stack.
Definition: stack.h:48
Objects_Control Object
This field is the object management structure for each proxy.
Definition: thread.h:363
Thread_APIs
The following record defines the control block used to manage each thread.
Definition: thread.h:425
Thread_CPU_budget_algorithms budget_algorithm
This field indicates the CPU budget algorith.
Definition: thread.h:223
Thread_Entry_numeric_type numeric_argument
This field is the numeric argument passed at thread start.
Definition: thread.h:216
const size_t _Thread_Control_size
Size of the thread control block of a particular application.
void * stack
This field is the initial stack area address.
Definition: thread.h:243
Thread life control.
Definition: thread.h:515
Thread_Entry entry_point
This field is the starting address for the thread.
Definition: thread.h:210
Thread_Action Action
Thread life action used to react upon thread restart and delete requests.
Definition: thread.h:520
uint32_t Objects_Id
The following type defines the control block used to manage object IDs.
Definition: object.h:122
void * pointer_argument
This field is the pointer argument passed at thread start.
Definition: thread.h:214
void * Thread
The following defines the "return type" of a thread.
Definition: thread.h:99
RBTree_Node RBTree
A node for red-black trees.
Definition: thread.h:298
const Thread_Control_add_on _Thread_Control_add_ons[]
Thread control add-ons.
Thread(* Thread_Entry_numeric)(Thread_Entry_numeric_type)
This type corresponds to a thread entry point which takes a single unsigned thirty-two bit integer as...
Definition: thread.h:134
This is used to manage each element (node) which is placed on a RBT.
Definition: rbtree.h:75
ISR Locks.
Information About the Thread Stack Handler.
Thread_Wait_information Wait
This field is the blocking information for this thread.
Definition: thread.h:715
rtems_task_variable_t * task_variables
This field points to the set of per task variables.
Definition: thread.h:801
uint32_t option
This field contains any options in effect on this blocking operation.
Definition: thread.h:311
Priority_Control current_priority
This field is the current priority state of this thread.
Definition: thread.h:373
bool is_preemptible
This field is true if the thread is preemptible.
Definition: thread.h:749
Thread_CPU_budget_algorithms
The following lists the algorithms used to manage the thread cpu budget.
Definition: thread.h:159
#define THREAD_API_LAST
This macro defines the last API which has threads.
Definition: thread.h:436
unsigned int Thread_Wait_flags
This type is able to contain several flags used to control the wait class and state of a thread...
Definition: thread.h:277
Internal structure used to manager per task variables.
Definition: thread.h:188