RTEMS
threadcreateidle.c
Go to the documentation of this file.
1 
8 /*
9  * COPYRIGHT (c) 1989-2011.
10  * On-Line Applications Research Corporation (OAR).
11  *
12  * The license and distribution terms for this file may be
13  * found in the file LICENSE in this distribution or at
14  * http://www.rtems.org/license/LICENSE.
15  */
16 
17 #ifdef HAVE_CONFIG_H
18 #include "config.h"
19 #endif
20 
22 #include <rtems/score/threadimpl.h>
23 #include <rtems/score/assert.h>
25 #include <rtems/score/stackimpl.h>
26 #include <rtems/score/sysstate.h>
28 
29 #include <string.h>
30 
31 static void _Thread_Create_idle_for_CPU( Per_CPU_Control *cpu )
32 {
33  Thread_Configuration config;
34  Thread_Control *idle;
35  bool ok;
36 
37  memset( &config, 0, sizeof( config ) );
38  config.scheduler = _Scheduler_Get_by_CPU( cpu );
39 
40 #if defined(RTEMS_SMP)
41  if ( config.scheduler == NULL ) {
42  return;
43  }
44 #endif
45 
47  config.scheduler,
49  );
50  config.budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_NONE;
51  config.name.name_u32 = _Objects_Build_name( 'I', 'D', 'L', 'E' );
52  config.is_fp = CPU_IDLE_TASK_IS_FP;
53  config.is_preemptible = true;
57  _Per_CPU_Get_index( cpu ) * config.stack_size
58  ];
59 
60  /*
61  * The entire workspace is zeroed during its initialization. Thus, all
62  * fields not explicitly assigned were explicitly zeroed by
63  * _Workspace_Initialization.
64  */
66  _Assert( idle != NULL );
67 
68  ok = _Thread_Initialize( &_Thread_Information, idle, &config );
69  _Assert( ok );
70  (void) ok;
71 
72  /*
73  * WARNING!!! This is necessary to "kick" start the system and
74  * MUST be done before _Thread_Start is invoked.
75  */
76  cpu->heir =
77  cpu->executing = idle;
78 #if defined(RTEMS_SMP)
79  cpu->ancestor = idle;
80 #endif
81 
82  idle->is_idle = true;
84  idle->Start.Entry.Kinds.Idle.entry = _Thread_Idle_body;
85 
87 
89  _Scheduler_Start_idle( config.scheduler, idle, cpu );
91 }
92 
93 void _Thread_Create_idle( void )
94 {
95  uint32_t cpu_max;
96  uint32_t cpu_index;
97 
99  cpu_max = _SMP_Get_processor_maximum();
100 
101  for ( cpu_index = 0 ; cpu_index < cpu_max ; ++cpu_index ) {
102  Per_CPU_Control *cpu = _Per_CPU_Get_by_index( cpu_index );
103 
104  if ( _Per_CPU_Is_processor_online( cpu ) ) {
105  _Thread_Create_idle_for_CPU( cpu );
106  }
107  }
108 }
void _Thread_Load_environment(Thread_Control *the_thread)
Initializes enviroment for a thread.
Definition: threadloadenv.c:24
uint32_t name_u32
Definition: object.h:68
static __inline__ const Scheduler_Control * _Scheduler_Get_by_CPU(const Per_CPU_Control *cpu)
Gets the scheduler for the cpu.
Definition: schedulerimpl.h:99
const Thread_Idle_body _Thread_Idle_body
The idle thread body.
Thread_CPU_budget_algorithms budget_algorithm
The thread&#39;s budget algorithm.
Definition: threadimpl.h:161
#define CPU_IDLE_TASK_IS_FP
Definition: cpu.h:132
#define CONTEXT_FP_SIZE
Size of floating point context area.
Definition: context.h:52
struct _Thread_Control * executing
This is the thread executing on this processor.
Definition: percpu.h:420
static __inline__ Priority_Control _Scheduler_Map_priority(const Scheduler_Control *scheduler, Priority_Control priority)
Maps a thread priority from the user domain to the scheduler domain.
Thread_Start_information Start
Definition: thread.h:825
static __inline__ void _System_state_Set(System_state_Codes state)
Sets the current system state to the given state.
Definition: sysstate.h:78
Inlined Routines Associated with the Manipulation of the Scheduler.
Thread_Entry_information Entry
Definition: thread.h:180
static __inline__ void _Scheduler_Start_idle(const Scheduler_Control *scheduler, Thread_Control *the_thread, Per_CPU_Control *cpu)
Starts the idle thread for a particular processor.
struct _Thread_Control * ancestor
The ancestor of the executing thread.
Definition: percpu.h:536
User Extension Handler API.
bool _Thread_Initialize(Thread_Information *information, Thread_Control *the_thread, const Thread_Configuration *config)
Initializes thread.
Inlined Routines from the Stack Handler.
const size_t _Thread_Idle_stack_size
The idle thread stack size in bytes.
Objects_Name name
Name of the object for the thread.
Definition: threadimpl.h:171
Information for the Assert Handler.
Priority_Control priority
The new thread&#39;s priority.
Definition: threadimpl.h:156
const struct _Scheduler_Control * scheduler
The scheduler control instance for the thread.
Definition: threadimpl.h:134
Per CPU Core Structure.
Definition: percpu.h:347
Priority_Control maximum_priority
The maximum priority value of this scheduler.
Definition: scheduler.h:281
The configuration of a new thread to initialize.
Definition: threadimpl.h:130
void _Thread_Create_idle(void)
Creates idle thread.
size_t stack_size
The size of the stack area in bytes.
Definition: threadimpl.h:144
States_Control current_state
Definition: thread.h:749
#define _Objects_Build_name(_C1, _C2, _C3, _C4)
Definition: object.h:242
static void _User_extensions_Thread_start(Thread_Control *started)
Starts a thread.
Definition: userextimpl.h:323
struct _Thread_Control * heir
This is the heir thread for this processor.
Definition: percpu.h:436
void _Thread_Entry_adaptor_idle(Thread_Control *executing)
Calls the start kinds idle entry of the thread.
#define STATES_READY
Definition: statesimpl.h:45
bool is_fp
Indicates whether the thread needs a floating-point area.
Definition: threadimpl.h:181
The system is between end of the first phase of initialization but before multitasking is started...
Definition: sysstate.h:50
System State Handler API.
void * stack_area
The starting address of the stack area.
Definition: threadimpl.h:139
Constants for the idle threads.
Inlined Routines from the Thread Handler.
bool is_preemptible
Indicates whether the new thread is preemptible.
Definition: threadimpl.h:186
union Thread_Entry_information::@25 Kinds
Thread entry data used by the adaptor to call the thread entry function with the right parameters...
static __inline__ Thread_Control * _Thread_Internal_allocate(void)
Allocates an internal thread and returns it.
Definition: threadimpl.h:1116
void(* adaptor)(Thread_Control *executing)
Thread entry adaptor.
Definition: thread.h:138
Thread_Information _Thread_Information
The internal thread objects information.
char _Thread_Idle_stacks[]
The idle thread stacks.
#define _Assert(_e)
Assertion similar to assert() controlled via RTEMS_DEBUG instead of NDEBUG.
Definition: assert.h:100
bool is_idle
Definition: thread.h:789