source: rtems/cpukit/score/include/rtems/score/thread.h @ 47ca0d0a

4.104.114.84.95
Last change on this file since 47ca0d0a was 47ca0d0a, checked in by Joel Sherrill <joel.sherrill@…>, on 08/01/00 at 18:26:02

The fp_context field is needed if software or hardware floating point
is available.

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