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

4.104.114.84.95
Last change on this file since f8c6333 was f8c6333, checked in by Joel Sherrill <joel.sherrill@…>, on 10/15/96 at 21:38:33

added cpu time used field to tcb

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