OpenCores
URL https://opencores.org/ocsvn/c0or1k/c0or1k/trunk

Subversion Repositories c0or1k

[/] [c0or1k/] [trunk/] [include/] [l4/] [generic/] [tcb.h] - Blame information for rev 7

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 drasko
/*
2
 * Thread Control Block, kernel portion.
3
 *
4
 * Copyright (C) 2007-2009 Bahadir Bilgehan Balban
5
 */
6
#ifndef __TCB_H__
7
#define __TCB_H__
8
 
9
#include <l4/lib/list.h>
10
#include <l4/lib/mutex.h>
11
#include <l4/lib/spinlock.h>
12
#include <l4/generic/scheduler.h>
13
#include <l4/generic/resource.h>
14
#include <l4/generic/capability.h>
15
#include <l4/generic/space.h>
16
#include INC_GLUE(memory.h)
17
#include INC_GLUE(syscall.h)
18
#include INC_GLUE(message.h)
19
#include INC_GLUE(context.h)
20
#include INC_SUBARCH(mm.h)
21
 
22
 
23
/*
24
 * These are a mixture of flags that indicate the task is
25
 * in a transitional state that could include one or more
26
 * scheduling states.
27
 */
28
#define TASK_INTERRUPTED                (1 << 0)
29
#define TASK_SUSPENDING                 (1 << 1)
30
#define TASK_RESUMING                   (1 << 2)
31
#define TASK_PENDING_SIGNAL             (TASK_SUSPENDING)
32
#define TASK_REALTIME                   (1 << 5)
33
 
34
/*
35
 * This is to indicate a task (either current or one of
36
 * its children) exit has occured and cleanup needs to be
37
 * called
38
 */
39
#define TASK_EXITED                     (1 << 3)
40
 
41
/* Task states */
42
enum task_state {
43
        TASK_INACTIVE   = 0,
44
        TASK_SLEEPING   = 1,
45
        TASK_RUNNABLE   = 2,
46
};
47
 
48
#define TASK_CID_MASK                   0xFF000000
49
#define TASK_ID_MASK                    0x00FFFFFF
50
#define TASK_CID_SHIFT                  24
51
 
52
static inline l4id_t tid_to_cid(l4id_t tid)
53
{
54
        return (tid & TASK_CID_MASK) >> TASK_CID_SHIFT;
55
}
56
 
57
/* Values that rather have special meaning instead of an id value */
58
static inline int tid_special_value(l4id_t id)
59
{
60
        /* Special ids have top 2 nibbles all set */
61
        return (id & TASK_CID_MASK) == TASK_CID_MASK;
62
}
63
 
64
#define TASK_ID_INVALID                 0xFFFFFFFF
65
struct task_ids {
66
        l4id_t tid;
67
        l4id_t spid;
68
        l4id_t tgid;
69
};
70
 
71
struct container;
72
 
73
struct ktcb {
74
        /* User context */
75
        task_context_t context;
76
 
77
        /*
78
         * Reference to the context on stack
79
         * saved at the beginning of a syscall trap.
80
         */
81
        syscall_context_t *syscall_regs;
82
 
83
        /* Runqueue related */
84
        struct link rq_list;
85
        struct runqueue *rq;
86
 
87
        /* Thread Id information (See space for space id) */
88
        l4id_t tid;             /* Global thread id */
89
        l4id_t tgid;            /* Global thread group id */
90
 
91
        /* CPU affinity */
92
        int affinity;
93
 
94
        /* Other related threads */
95
        l4id_t pagerid;
96
 
97
        /* Flags to indicate various task status */
98
        unsigned int flags;
99
 
100
        /* IPC flags */
101
        unsigned int ipc_flags;
102
 
103
        /* Lock for blocking thread state modifications via a syscall */
104
        struct mutex thread_control_lock;
105
 
106
        /* To protect against thread deletion/modification */
107
        struct spinlock thread_lock;
108
 
109
        u32 ts_need_resched;    /* Scheduling flag */
110
        enum task_state state;
111
 
112
        struct link task_list; /* Global task list. */
113
 
114
        /* UTCB related, see utcb.txt in docs */
115
        unsigned long utcb_address;     /* Virtual ref to task's utcb area */
116
 
117
        /* Thread times */
118
        u32 kernel_time;        /* Ticks spent in kernel */
119
        u32 user_time;          /* Ticks spent in userland */
120
        u32 ticks_left;         /* Timeslice ticks left for reschedule */
121
        u32 ticks_assigned;     /* Ticks assigned to this task on this HZ */
122
        u32 sched_granule;      /* Granularity ticks left for reschedule */
123
        int priority;           /* Task's fixed, default priority */
124
 
125
        /* Number of locks the task currently has acquired */
126
        int nlocks;
127
 
128
        /* Task exit code */
129
        unsigned int exit_code;
130
 
131
        /* Page table information */
132
        struct address_space *space;
133
 
134
        /* Container */
135
        struct container *container;
136
        struct pager *pager;
137
 
138
        /* Capability lists */
139
        struct cap_list cap_list; /* Own private capabilities */
140
 
141
        /* Fields for ipc rendezvous */
142
        struct waitqueue_head wqh_recv;
143
        struct waitqueue_head wqh_send;
144
        l4id_t expected_sender;
145
 
146
        /* Waitqueue for notifiactions */
147
        struct waitqueue_head wqh_notify;
148
 
149
        /* Waitqueue for pagers to wait for task states */
150
        struct waitqueue_head wqh_pager;
151
 
152
        /* Tells where we are when we sleep */
153
        struct spinlock waitlock;
154
        struct waitqueue_head *waiting_on;
155
        struct waitqueue *wq;
156
 
157
        /*
158
         * Extended ipc size and buffer that
159
         * points to the space after ktcb
160
         */
161
        unsigned long extended_ipc_size;
162
        char extended_ipc_buffer[];
163
};
164
 
165
/* Per thread kernel stack unified on a single page. */
166
union ktcb_union {
167
        struct ktcb ktcb;
168
        char kstack[PAGE_SIZE];
169
};
170
 
171
/*
172
 * Each task is allocated a unique global id. A thread group can only belong to
173
 * a single leader, and every thread can only belong to a single thread group.
174
 * These rules allow the fact that every global id can be used to define a
175
 * unique thread group id. Thread local ids are used as an index into the thread
176
 * group's utcb area to discover the per-thread utcb structure.
177
 */
178
static inline void set_task_ids(struct ktcb *task, struct task_ids *ids)
179
{
180
        task->tid = ids->tid;
181
        task->tgid = ids->tgid;
182
}
183
 
184
struct ktcb *tcb_find(l4id_t tid);
185
struct ktcb *tcb_find_lock(l4id_t tid);
186
void tcb_add(struct ktcb *tcb);
187
void tcb_remove(struct ktcb *tcb);
188
 
189
void tcb_init(struct ktcb *tcb);
190
struct ktcb *tcb_alloc_init(l4id_t cid);
191
void tcb_delete(struct ktcb *tcb);
192
void tcb_delete_zombies(void);
193
 
194
void ktcb_list_remove(struct ktcb *task, struct ktcb_list *ktcb_list);
195
void ktcb_list_add(struct ktcb *new, struct ktcb_list *ktcb_list);
196
void init_ktcb_list(struct ktcb_list *ktcb_list);
197
void task_update_utcb(struct ktcb *task);
198
int tcb_check_and_lazy_map_utcb(struct ktcb *task, int page_in);
199
 
200
#endif /* __TCB_H__ */
201
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.