Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


Merge branch 'devel'
[palacios.git] / kitten / include / lwk / task.h
1 #ifndef _LWK_TASK_H
2 #define _LWK_TASK_H
3
4 #include <lwk/types.h>
5 #include <lwk/idspace.h>
6 #include <lwk/cpumask.h>
7
8 /**
9  * Valid user-space created task IDs are in interval
10  * [TASK_MIN_ID, TASK_MAX_ID].
11  */
12 #define TASK_MIN_ID                    0
13 #define TASK_MAX_ID                    4094
14
15 /**
16  * The task ID to use for the init_task.
17  * Put it at the top of the space to keep it out of the way.
18  */
19 #define INIT_TASK_ID                   TASK_MAX_ID
20
21 /**
22  * Task states
23  */
24 #define TASKSTATE_READY                (1 << 0)
25 #define TASKSTATE_UNINTERRUPTIBLE      (1 << 1)
26 #define TASKSTATE_INTERRUPTIBLE        (1 << 2)
27 #define TASKSTATE_EXIT_ZOMBIE          (1 << 3)
28 typedef unsigned int taskstate_t;
29
30 /**
31  * Events that tasks may wait for and be sent.
32  */
33 #define LWKEVENT_CHILD_TASK_EXITED     (1 << 0)
34 #define LWKEVENT_PORTALS_EVENT_POSTED  (1 << 1)
35 typedef unsigned long event_t;
36
37 /**
38  * Initial conditions to use for new task.
39  */
40 typedef struct {
41         uid_t                  uid;
42         uid_t                  gid;
43         id_t                   aspace_id;
44         vaddr_t                entry_point;
45         vaddr_t                stack_ptr;
46         id_t                   cpu_id;
47         const user_cpumask_t * cpumask;
48 } start_state_t;
49
50 /**
51  * Core task management API.
52  * These are accessible from both kernel-space and user-space (via syscalls).
53  */
54 extern int task_get_myid(id_t *id);
55 extern int task_create(id_t id_request, const char *name,
56                        const start_state_t *start_state, id_t *id);
57 extern int task_exit(int status);
58 extern int task_yield(void);
59
60 #ifdef __KERNEL__
61
62 #include <lwk/types.h>
63 #include <lwk/init.h>
64 #include <lwk/spinlock.h>
65 #include <lwk/list.h>
66 #include <lwk/seqlock.h>
67 #include <lwk/signal.h>
68 #include <lwk/idspace.h>
69 #include <arch/atomic.h>
70 #include <arch/page.h>
71 #include <arch/processor.h>
72 #include <arch/task.h>
73 #include <arch/current.h>
74 #include <arch/mmu.h>
75
76 /**
77  * Flags for task_struct.flags field.
78  */
79 #define PF_USED_MATH    0x00002000      /* if unset the fpu must be initialized before use */
80
81 /**
82  * Signal handler structure.
83  */
84 struct sighand_struct {
85         atomic_t                count;
86         struct k_sigaction      action[_NSIG];
87         spinlock_t              siglock;
88         struct list_head        signalfd_list;
89 };
90
91 /**
92  * Task structure (aka Process Control Block).
93  * There is one of these for each OS-managed thread of execution in the
94  * system.  A task is a generic "context of execution"... it either
95  * represents a user-level process, user-level thread, or kernel thread.
96  */
97 struct task_struct {
98         id_t                    id;              /* The task's ID */
99         char                    name[16];        /* The task's name */
100         struct hlist_node       ht_link;         /* Task hash table linkage */
101
102         taskstate_t             state;           /* The task's current state */
103
104         uid_t                   uid;             /* user ID */
105         gid_t                   gid;             /* group ID */
106
107         struct aspace *         aspace;          /* Address space task is in */
108         struct sighand_struct * sighand;         /* signal handler info */
109
110         cpumask_t               cpumask;         /* CPUs this task may migrate
111                                                     to and create tasks on */
112         id_t                    cpu_id;          /* CPU this task is bound to */
113
114         struct list_head        sched_link;      /* For per-CPU scheduling lists */
115
116         unsigned long           ptrace;
117         uint32_t                flags;
118
119         int                     exit_status;     /* Reason the task exited */
120
121         struct arch_task        arch;            /* arch specific task info */
122 };
123
124 union task_union {
125         struct task_struct      task_info;
126         unsigned long           stack[TASK_SIZE/sizeof(long)];
127 };
128
129 extern union task_union bootstrap_task_union;
130 extern struct aspace bootstrap_aspace;
131
132 /**
133  * Valid task IDs are in interval [__TASK_MIN_ID, __TASK_MAX_ID].
134  */
135 #define __TASK_MIN_ID   TASK_MIN_ID
136 #define __TASK_MAX_ID   TASK_MAX_ID+1  /* +1 for IDLE_TASK_ID */
137
138 /**
139  * ID of the idle task.
140  */
141 #define IDLE_TASK_ID    TASK_MAX_ID+1
142
143 /**
144  * Checks to see if a task structure is the init task.
145  * The init task is the first user-space task created by the kernel.
146  */
147 static inline int
148 is_init(struct task_struct *tsk)
149 {
150         return (tsk->id == 1);
151 }
152
153 #define clear_stopped_child_used_math(child) do { (child)->flags &= ~PF_USED_MATH; } while (0)
154 #define set_stopped_child_used_math(child) do { (child)->flags |= PF_USED_MATH; } while (0)
155 #define clear_used_math() clear_stopped_child_used_math(current)
156 #define set_used_math() set_stopped_child_used_math(current)
157 #define conditional_stopped_child_used_math(condition, child) \
158         do { (child)->flags &= ~PF_USED_MATH, (child)->flags |= (condition) ? PF_USED_MATH : 0; } while (0)
159 #define conditional_used_math(condition) \
160         conditional_stopped_child_used_math(condition, current)
161 #define copy_to_stopped_child_used_math(child) \
162         do { (child)->flags &= ~PF_USED_MATH, (child)->flags |= current->flags & PF_USED_MATH; } while (0)
163 /* NOTE: this will return 0 or PF_USED_MATH, it will never return 1 */
164 #define tsk_used_math(p) ((p)->flags & PF_USED_MATH)
165 #define used_math() tsk_used_math(current)
166
167 extern int __init task_subsys_init(void);
168
169 extern int arch_task_create(struct task_struct *task,
170                             const start_state_t *start_state);
171
172 extern int sys_task_get_myid(id_t __user *id);
173 extern int sys_task_create(id_t id_request, const char __user *name,
174                            const start_state_t __user *start_state,
175                            id_t __user *id);
176 extern int sys_task_exit(int status);
177 extern int sys_task_yield(void);
178
179 extern int __task_reserve_id(id_t id);
180 extern int __task_create(id_t id, const char *name,
181                          const start_state_t *start_state,
182                          struct task_struct **task);
183
184 #endif
185 #endif