アットウィキロゴ

TCB

勉強のため、OSのTCB(Task Control Block)を見てます。

kozos(kozos.c) 9thステップより
/* タスク・コントロール・ブロック(TCB) */
typedef struct _kz_thread {
 struct _kz_thread *next;
 char name[THREAD_NAME_SIZE + 1]; /* スレッド名 */
 int priority;   /* 優先度 */
 char *stack;    /* スタック */
 uint32 flags;   /* 各種フラグ */
#define KZ_THREAD_FLAG_READY (1 << 0)

 struct { /* スレッドのスタート・アップ(thread_init())に渡すパラメータ */
   kz_func_t func; /* スレッドのメイン関数 */
   int argc;       /* スレッドのメイン関数に渡す argc */
   char **argv;    /* スレッドのメイン関数に渡す argv */
 } init;

 struct { /* システム・コール用バッファ */
   kz_syscall_type_t type;
   kz_syscall_param_t *param;
 } syscall;

 kz_context context; /* コンテキスト情報 */
} kz_thread;
  • 特徴
    • システムコール用バッファがある。タスクがお亡くなりになっても、OSに影響が無いという利点がある。
    • コンテキストは、SP保存変数のみ。
  • initとsyscallは、union可能か?→不可:理由は、syscall後に、スレッドのメイン関数をcallするため、各々が必要。
  • flagsは、スレッドの状態を保持する。
  • nextで、backward探索は無い。


FreeRTOS 7.2.0(tasks.c)
/*
* Task control block.  A task control block (TCB) is allocated to each task,
* and stores the context of the task.
*/
typedef struct tskTaskControlBlock
{
volatile portSTACK_TYPE	*pxTopOfStack;		/*< Points to the location of the last item placed on the tasks stack.  THIS MUST BE THE FIRST MEMBER OF THE STRUCT. */

#if ( portUSING_MPU_WRAPPERS == 1 )
	xMPU_SETTINGS xMPUSettings;				/*< The MPU settings are defined as part of the port layer.  THIS MUST BE THE SECOND MEMBER OF THE STRUCT. */
#endif	
	
xListItem				xGenericListItem;	/*< List item used to place the TCB in ready and blocked queues. */
xListItem				xEventListItem;		/*< List item used to place the TCB in event lists. */
unsigned portBASE_TYPE	uxPriority;			/*< The priority of the task where 0 is the lowest priority. */
portSTACK_TYPE			*pxStack;			/*< Points to the start of the stack. */
signed char				pcTaskName[ configMAX_TASK_NAME_LEN ];/*< Descriptive name given to the task when created.  Facilitates debugging only. */

#if ( portSTACK_GROWTH > 0 )
	portSTACK_TYPE *pxEndOfStack;			/*< Used for stack overflow checking on architectures where the stack grows up from low memory. */
#endif

#if ( portCRITICAL_NESTING_IN_TCB == 1 )
	unsigned portBASE_TYPE uxCriticalNesting;
#endif

#if ( configUSE_TRACE_FACILITY == 1 )
	unsigned portBASE_TYPE	uxTCBNumber;	/*< This stores a number that increments each time a TCB is created.  It allows debuggers to determine when a task has been deleted and then recreated. */
	unsigned portBASE_TYPE  uxTaskNumber;	/*< This stores a number specifically for use by third party trace code. */
#endif

#if ( configUSE_MUTEXES == 1 )
	unsigned portBASE_TYPE uxBasePriority;	/*< The priority last assigned to the task - used by the priority inheritance mechanism. */
#endif

#if ( configUSE_APPLICATION_TASK_TAG == 1 )
	pdTASK_HOOK_CODE pxTaskTag;
#endif

#if ( configGENERATE_RUN_TIME_STATS == 1 )
	unsigned long ulRunTimeCounter;		/*< Used for calculating how much CPU time each task is utilising. */
#endif

} tskTCB;
  • #if ~ #endifは、デバッグ向け機能のため、最初は無視して考える。
  • xEventListItem:イベントは、HW割り込みを指すらしい(他に有るかも)。
  • portXXXXは、CPUアーキテクチャ依存で、サイズが異なる場合に対応できる。
  • syscallの概念は無い→直接API関数を呼び出しなので、アプリがコケたらOSもコケる。
    • ex.signed portBASE_TYPE xTaskGenericCreate関数 → [tasks.c]signed portBASE_TYPE xTaskGenericCreate関数


ROSK(ros.h)
/*
Task Control Block Type
*/
typedef struct _tcb_
{
struct _tcb_*		fw;
struct _tcb_*		bw;
char*			name;
state_t			state;
int                     priority;
taskStack_t*		spSaved;
void*			relObj;
addr_t			spBase;
taskEntry_t		entry;
} tcb_t;


USO(Unvoiced Shadow Operating system)
  typedef unsigned short UWORD ;

  typedef struct {
    void  (*tsk)(void);
    UWORD wcount ;
  } TCBP ;
  • タスク状態は別の変数で管理


HOS-v4(include\mknl.h)
/* μカーネル タスクコントロールブロック */
typedef struct t_mknl_tcb
{
T_HOSPAC_CTXINF   ctxinf;		/* コンテキスト情報保存ブロック */
STAT              tskwait;		/* 待ち要因 */
UB                tskstat;		/* タスクの状態 */
UB                texstat;		/* 例外処理の状態 */
PRI               tskpri;		/* 現在の優先度 */
ER_UINT           ercd;			/* 待ち解除要因用エラーコード */
VP_INT            data;			/* 汎用データ領域 */
struct t_mknl_que *que;			/* 属しているキュー  */
struct t_mknl_tcb *next;		/* キューでの次のTCB */
struct t_mknl_tcb *prev;		/* キューでの前のTCB */
struct t_mknl_tcb *tm_next;		/* タイムアウトキューの次のTCB */
struct t_mknl_tcb *tm_prev;		/* タイムアウトキューの前のTCB */
RELTIM            diftim;		/* 直前のTCBとのタイムアウトまでの時間差 */
} T_MKNL_TCB;
  • 一つ前のTCBを指すポインタの重要度が現状不明


-
最終更新:2013年01月18日 08:23