source: rtems/cpukit/score/include/rtems/score/thread.h @ ecc3fe3

4.104.114.84.95
Last change on this file since ecc3fe3 was ecc3fe3, checked in by Joel Sherrill <joel.sherrill@…>, on 09/23/98 at 16:41:00

IDLE task stack size now specified as a field in the CPU Table for all
ports.

  • Property mode set to 100644
File size: 15.6 KB
Line 
1/*  thread.h
2 *
3 *  This include file contains all constants and structures associated
4 *  with the thread control block.
5 *
6 *  COPYRIGHT (c) 1989-1998.
7 *  On-Line Applications Research Corporation (OAR).
8 *  Copyright assigned to U.S. Government, 1994.
9 *
10 *  The license and distribution terms for this file may be
11 *  found in the file LICENSE in this distribution or at
12 *  http://www.OARcorp.com/rtems/license.html.
13 *
14 *  $Id$
15 */
16
17#ifndef __THREAD_h
18#define __THREAD_h
19
20#ifdef __cplusplus
21extern "C" {
22#endif
23
24#include <rtems/score/context.h>
25#include <rtems/score/cpu.h>
26#include <rtems/score/mppkt.h>
27#include <rtems/score/object.h>
28#include <rtems/score/priority.h>
29#include <rtems/score/stack.h>
30#include <rtems/score/states.h>
31#include <rtems/score/tod.h>
32#include <rtems/score/tqdata.h>
33#include <rtems/score/watchdog.h>
34
35/*
36 *  The following defines the "return type" of a thread.
37 */
38
39typedef void Thread;
40
41/*
42 *  The following defines the ways in which the entry point for a
43 *  thread can be invoked.  Basically, it can be passed any
44 *  combination/permutation of a pointer and an unsigned32 value.
45 *
46 *  NOTE: For now, we are ignoring the return type.
47 */
48
49typedef enum {
50  THREAD_START_NUMERIC,
51  THREAD_START_POINTER,
52  THREAD_START_BOTH_POINTER_FIRST,
53  THREAD_START_BOTH_NUMERIC_FIRST
54} Thread_Start_types;
55
56typedef Thread ( *Thread_Entry )();   /* basic type */
57
58typedef Thread ( *Thread_Entry_numeric )( unsigned32 );
59typedef Thread ( *Thread_Entry_pointer )( void * );
60typedef Thread ( *Thread_Entry_both_pointer_first )( void *, unsigned32 );
61typedef Thread ( *Thread_Entry_both_numeric_first )( unsigned32, void * );
62
63/*
64 *  The following lists the algorithms used to manage the thread cpu budget.
65 *
66 *  Reset Timeslice:   At each context switch, reset the time quantum.
67 *  Exhaust Timeslice: Only reset the quantum once it is consumed.
68 *  Callout:           Execute routine when budget is consumed.
69 */
70
71typedef enum {
72  THREAD_CPU_BUDGET_ALGORITHM_NONE,
73  THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE,
74  THREAD_CPU_BUDGET_ALGORITHM_EXHAUST_TIMESLICE,
75  THREAD_CPU_BUDGET_ALGORITHM_CALLOUT
76}  Thread_CPU_budget_algorithms;
77
78typedef struct Thread_Control_struct Thread_Control;
79
80typedef void (*Thread_CPU_budget_algorithm_callout )( Thread_Control * );
81
82/*
83 *  The following structure contains the information which defines
84 *  the starting state of a thread.
85 */
86
87typedef struct {
88  Thread_Entry         entry_point;      /* starting thread address         */
89  Thread_Start_types   prototype;        /* how task is invoked             */
90  void                *pointer_argument; /* pointer argument                */
91  unsigned32           numeric_argument; /* numeric argument                */
92                                         /* initial execution modes         */
93  boolean              is_preemptible;
94  Thread_CPU_budget_algorithms          budget_algorithm;
95  Thread_CPU_budget_algorithm_callout   budget_callout;
96  unsigned32           isr_level;
97  Priority_Control     initial_priority; /* initial priority                */
98  boolean              core_allocated_stack;
99  Stack_Control        Initial_stack;    /* stack information               */
100  void                *fp_context;       /* initial FP context area address */
101  void                *stack;            /* initial stack area address      */
102}   Thread_Start_information;
103
104/*
105 *  The following structure contains the information necessary to manage
106 *  a thread which it is  waiting for a resource.
107 */
108
109#define THREAD_STATUS_PROXY_BLOCKING 0x1111111
110
111typedef struct {
112  Objects_Id            id;              /* waiting on this object       */
113  unsigned32            count;           /* "generic" fields to be used */
114  void                 *return_argument; /*   when blocking */
115  void                 *return_argument_1;
116  unsigned32            option;
117
118  /*
119   *  NOTE: The following assumes that all API return codes can be
120   *        treated as an unsigned32. 
121   */
122  unsigned32            return_code;     /* status for thread awakened   */
123
124  Chain_Control         Block2n;         /* 2 - n priority blocked chain */
125  Thread_queue_Control *queue;           /* pointer to thread queue      */
126}   Thread_Wait_information;
127
128/*
129 *  The following defines the control block used to manage
130 *  each thread proxy.
131 *
132 *  NOTE: It is critical that proxies and threads have identical
133 *        memory images for the shared part.
134 */
135
136typedef struct {
137  Objects_Control          Object;
138  States_Control           current_state;
139  Priority_Control         current_priority;
140  Priority_Control         real_priority;
141  unsigned32               resource_count;
142  Thread_Wait_information  Wait;
143  Watchdog_Control         Timer;
144  MP_packet_Prefix        *receive_packet;
145     /****************** end of common block ********************/
146  Chain_Node               Active;
147}   Thread_Proxy_control;
148
149
150/*
151 *  The following record defines the control block used
152 *  to manage each thread.
153 *
154 *  NOTE: It is critical that proxies and threads have identical
155 *        memory images for the shared part.
156 */
157
158typedef enum {
159  THREAD_API_RTEMS,
160  THREAD_API_POSIX
161}  Thread_APIs;
162
163#define THREAD_API_FIRST THREAD_API_RTEMS
164#define THREAD_API_LAST  THREAD_API_POSIX
165
166struct Thread_Control_struct {
167  Objects_Control                       Object;
168  States_Control                        current_state;
169  Priority_Control                      current_priority;
170  Priority_Control                      real_priority;
171  unsigned32                            resource_count;
172  Thread_Wait_information               Wait;
173  Watchdog_Control                      Timer;
174  MP_packet_Prefix                     *receive_packet;
175     /****************** end of common block ********************/
176  boolean                               is_global;
177  boolean                               do_post_task_switch_extension;
178
179  boolean                               is_preemptible;
180  unsigned32                            cpu_time_budget;
181  Thread_CPU_budget_algorithms          budget_algorithm;
182  Thread_CPU_budget_algorithm_callout   budget_callout;
183
184  unsigned32                            ticks_executed;
185  Chain_Control                        *ready;
186  Priority_Information                  Priority_map;
187  Thread_Start_information              Start;
188  Context_Control                       Registers;
189  void                                 *fp_context;
190  void                                 *API_Extensions[ THREAD_API_LAST + 1 ];
191  void                                **extensions;
192};
193
194/*
195 *  The following defines the information control block used to
196 *  manage this class of objects.
197 */
198 
199SCORE_EXTERN Objects_Information _Thread_Internal_information;
200 
201/*
202 *  The following define the thread control pointers used to access
203 *  and manipulate the idle thread.
204 */
205 
206SCORE_EXTERN Thread_Control *_Thread_Idle;
207
208/*
209 *  The following context area contains the context of the "thread"
210 *  which invoked the start multitasking routine.  This context is
211 *  restored as the last action of the stop multitasking routine.  Thus
212 *  control of the processor can be returned to the environment
213 *  which initiated the system.
214 */
215 
216SCORE_EXTERN Context_Control _Thread_BSP_context;
217 
218/*
219 *  The following declares the dispatch critical section nesting
220 *  counter which is used to prevent context switches at inopportune
221 *  moments.
222 */
223
224SCORE_EXTERN unsigned32 _Thread_Dispatch_disable_level;
225
226/*
227 *  If this is non-zero, then the post-task switch extension
228 *  is run regardless of the state of the per thread flag.
229 */
230
231SCORE_EXTERN unsigned32 _Thread_Do_post_task_switch_extension;
232
233/*
234 *  The following holds how many user extensions are in the system.  This
235 *  is used to determine how many user extension data areas to allocate
236 *  per thread.
237 */
238
239SCORE_EXTERN unsigned32 _Thread_Maximum_extensions;
240
241/*
242 *  The following is used to manage the length of a timeslice quantum.
243 */
244
245SCORE_EXTERN unsigned32 _Thread_Ticks_per_timeslice;
246
247/*
248 *  The following points to the array of FIFOs used to manage the
249 *  set of ready threads.
250 */
251
252SCORE_EXTERN Chain_Control *_Thread_Ready_chain;
253
254/*
255 *  The following points to the thread which is currently executing.
256 *  This thread is implicitly manipulated by numerous directives.
257 */
258
259SCORE_EXTERN Thread_Control *_Thread_Executing;
260
261/*
262 *  The following points to the highest priority ready thread
263 *  in the system.  Unless the current thread is not preemptibl,
264 *  then this thread will be context switched to when the next
265 *  dispatch occurs.
266 */
267
268SCORE_EXTERN Thread_Control *_Thread_Heir;
269
270/*
271 *  The following points to the thread whose floating point
272 *  context is currently loaded.
273 */
274
275SCORE_EXTERN Thread_Control *_Thread_Allocated_fp;
276
277/*
278 *  _Thread_Handler_initialization
279 *
280 *  DESCRIPTION:
281 *
282 *  This routine performs the initialization necessary for this handler.
283 */
284
285void _Thread_Handler_initialization (
286  unsigned32   ticks_per_timeslice,
287  unsigned32   maximum_extensions,
288  unsigned32   maximum_proxies
289);
290
291/*
292 *  _Thread_Create_idle
293 *
294 *  DESCRIPTION:
295 *
296 *  This routine creates the idle thread.
297 *
298 *  WARNING!! No thread should be created before this one.
299 */
300 
301void _Thread_Create_idle( void );
302
303/*
304 *  _Thread_Start_multitasking
305 *
306 *  DESCRIPTION:
307 *
308 *  This routine initiates multitasking.  It is invoked only as
309 *  part of initialization and its invocation is the last act of
310 *  the non-multitasking part of the system initialization.
311 */
312
313void _Thread_Start_multitasking( void );
314
315/*
316 *  _Thread_Dispatch
317 *
318 *  DESCRIPTION:
319 *
320 *  This routine is responsible for transferring control of the
321 *  processor from the executing thread to the heir thread.  As part
322 *  of this process, it is responsible for the following actions:
323 *
324 *     + saving the context of the executing thread
325 *     + restoring the context of the heir thread
326 *     + dispatching any signals for the resulting executing thread
327 */
328
329void _Thread_Dispatch( void );
330
331/*
332 *  _Thread_Initialize
333 *
334 *  DESCRIPTION:
335 *
336 *  XXX
337 *
338 *  NOTES:
339 *
340 *  If stack_area is NULL, it is allocated from the workspace.
341 *
342 *  If the stack is allocated from the workspace, then it is guaranteed to be
343 *  of at least minimum size.
344 */
345
346boolean _Thread_Initialize(
347  Objects_Information                  *information,
348  Thread_Control                       *the_thread,
349  void                                 *stack_area,
350  unsigned32                            stack_size,
351  boolean                               is_fp,
352  Priority_Control                      priority,
353  boolean                               is_preemptible,
354  Thread_CPU_budget_algorithms          budget_algorithm,
355  Thread_CPU_budget_algorithm_callout   budget_callout,
356  unsigned32                            isr_level,
357  Objects_Name                          name
358);
359
360/*
361 *  _Thread_Start
362 *
363 *  DESCRIPTION:
364 *
365 *  XXX
366 */
367 
368boolean _Thread_Start(
369  Thread_Control           *the_thread,
370  Thread_Start_types        the_prototype,
371  void                     *entry_point,
372  void                     *pointer_argument,
373  unsigned32                numeric_argument
374);
375
376/*
377 *  _Thread_Restart
378 *
379 *  DESCRIPTION:
380 *
381 *  XXX
382 */
383 
384/* XXX multiple task arg profiles */
385 
386boolean _Thread_Restart(
387  Thread_Control           *the_thread,
388  void                     *pointer_argument,
389  unsigned32                numeric_argument
390);
391
392/*
393 *  _Thread_Close
394 *
395 *  DESCRIPTION:
396 *
397 *  XXX
398 */
399 
400void _Thread_Close(
401  Objects_Information  *information,
402  Thread_Control       *the_thread
403);
404
405/*
406 *  _Thread_Ready
407 *
408 *  DESCRIPTION:
409 *
410 *  This routine removes any set states for the_thread.  It performs
411 *  any necessary scheduling operations including the selection of
412 *  a new heir thread.
413 */
414
415void _Thread_Ready(
416  Thread_Control *the_thread
417);
418
419/*
420 *  _Thread_Clear_state
421 *
422 *  DESCRIPTION:
423 *
424 *  This routine clears the indicated STATES for the_thread.  It performs
425 *  any necessary scheduling operations including the selection of
426 *  a new heir thread.
427 */
428
429void _Thread_Clear_state(
430  Thread_Control *the_thread,
431  States_Control  state
432);
433
434/*
435 *  _Thread_Set_state
436 *
437 *  DESCRIPTION:
438 *
439 *  This routine sets the indicated states for the_thread.  It performs
440 *  any necessary scheduling operations including the selection of
441 *  a new heir thread.
442 *
443 */
444
445void _Thread_Set_state(
446  Thread_Control *the_thread,
447  States_Control  state
448);
449
450/*
451 *  _Thread_Set_transient
452 *
453 *  DESCRIPTION:
454 *
455 *  This routine sets the TRANSIENT state for the_thread.  It performs
456 *  any necessary scheduling operations including the selection of
457 *  a new heir thread.
458 */
459
460void _Thread_Set_transient(
461  Thread_Control *the_thread
462);
463
464/*
465 *  _Thread_Reset_timeslice
466 *
467 *  DESCRIPTION:
468 *
469 *  This routine is invoked upon expiration of the currently
470 *  executing thread's timeslice.  If no other thread's are ready
471 *  at the priority of the currently executing thread, then the
472 *  executing thread's timeslice is reset.  Otherwise, the
473 *  currently executing thread is placed at the rear of the
474 *  FIFO for this priority and a new heir is selected.
475 */
476
477void _Thread_Reset_timeslice( void );
478
479/*
480 *  _Thread_Tickle_timeslice
481 *
482 *  DESCRIPTION:
483 *
484 *  This routine is invoked as part of processing each clock tick.
485 *  It is responsible for determining if the current thread allows
486 *  timeslicing and, if so, when its timeslice expires.
487 */
488
489void _Thread_Tickle_timeslice( void );
490
491/*
492 *  _Thread_Yield_processor
493 *
494 *  DESCRIPTION:
495 *
496 *  This routine is invoked when a thread wishes to voluntarily
497 *  transfer control of the processor to another thread of equal
498 *  or greater priority.
499 */
500
501void _Thread_Yield_processor( void );
502
503/*
504 *  _Thread_Load_environment
505 *
506 *  DESCRIPTION:
507 *
508 *  This routine initializes the context of the_thread to its
509 *  appropriate starting state.
510 */
511
512void _Thread_Load_environment(
513  Thread_Control *the_thread
514);
515
516/*
517 *  _Thread_Handler
518 *
519 *  DESCRIPTION:
520 *
521 *  This routine is the wrapper function for all threads.  It is
522 *  the starting point for all threads.  The user provided thread
523 *  entry point is invoked by this routine.  Operations
524 *  which must be performed immediately before and after the user's
525 *  thread executes are found here.
526 */
527
528void _Thread_Handler( void );
529
530/*
531 *  _Thread_Delay_ended
532 *
533 *  DESCRIPTION:
534 *
535 *  This routine is invoked when a thread must be unblocked at the
536 *  end of a time based delay (i.e. wake after or wake when).
537 */
538
539void _Thread_Delay_ended(
540  Objects_Id  id,
541  void       *ignored
542);
543
544/*
545 *  _Thread_Change_priority
546 *
547 *  DESCRIPTION:
548 *
549 *  This routine changes the current priority of the_thread to
550 *  new_priority.  It performs any necessary scheduling operations
551 *  including the selection of a new heir thread.
552 */
553
554void _Thread_Change_priority (
555  Thread_Control   *the_thread,
556  Priority_Control  new_priority,
557  boolean           prepend_it
558);
559
560/*
561 *  _Thread_Set_priority
562 *
563 *  DESCRIPTION:
564 *
565 *  This routine updates the priority related fields in the_thread
566 *  control block to indicate the current priority is now new_priority.
567 */
568
569void _Thread_Set_priority(
570  Thread_Control   *the_thread,
571  Priority_Control  new_priority
572);
573
574/*
575 *  _Thread_Evaluate_mode
576 *
577 *  DESCRIPTION:
578 *
579 *  This routine XXX
580 */
581
582boolean _Thread_Evaluate_mode( void );
583
584/*
585 *  _Thread_Get
586 *
587 *  NOTE:  If we are not using static inlines, this must be a real
588 *         subroutine call.
589 */
590 
591#ifndef USE_INLINES
592Thread_Control *_Thread_Get (
593  Objects_Id           id,
594  Objects_Locations   *location
595);
596#endif
597
598/*
599 *  _Thread_Idle_body
600 *
601 *  DESCRIPTION:
602 *
603 *  This routine is the body of the system idle thread.
604 */
605 
606#if (CPU_PROVIDES_IDLE_THREAD_BODY == FALSE)
607Thread _Thread_Idle_body(
608  unsigned32 ignored
609);
610#endif
611
612#ifndef __RTEMS_APPLICATION__
613#include <rtems/score/thread.inl>
614#endif
615#include <rtems/score/threadmp.h>
616
617#ifdef __cplusplus
618}
619#endif
620
621#endif
622/* end of include file */
Note: See TracBrowser for help on using the repository browser.