2 * (C) Copyright 2007-2011 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
4 * This file is released under the GPLv2. See the COPYING file for more
15 #include <interrupt.h>
18 #define CAN_SLEEP 1 /* safe to sleep */
19 #define CAN_LOOP 2 /* safe to busy-wait */
21 #define TASK_RUNNING 0
22 #define TASK_SLEEPING 1
25 #define STACK_FRAME_SIZE 160
27 #define SCHED_SLICE_MS 30 /* 30ms scheduler slice */
28 #define SCHED_TICKS_PER_SLICE (HZ / SCHED_SLICE_MS)
30 #define HZ 100 /* number of ticks per second */
34 r
:1, /* PER Mask (R) */
36 t
:1, /* DAT Mode (T) */
37 io
:1, /* I/O Mask (IO) */
38 ex
:1; /* External Mask (EX) */
42 m
:1, /* Machine-Check Mask (M) */
43 w
:1, /* Wait State (W) */
44 p
:1; /* Problem State (P) */
46 u8 as
:2, /* Address-Space Control (AS) */
47 cc
:2, /* Condition Code (CC) */
48 prog_mask
:4; /* Program Mask */
51 ea
:1; /* Extended Addressing (EA) */
53 u32 ba
:1, /* Basic Addressing (BA) */
60 * saved registers for guests
62 * NOTE: some registers are saved in the SIE control block!
71 /* saved registers for CP tasks */
79 * These states mirror those described in chapter 4 of SA22-7832-06
91 /* the SIE control block is picky about alignment */
94 struct guest_regs regs
;
97 enum virt_cpustate state
;
100 #define TASK_NAME_LEN 16
103 * This structure describes a running process.
106 struct regs regs
; /* saved registers */
108 struct list_head run_queue
; /* runnable list */
109 struct list_head proc_list
; /* processes list */
110 struct list_head blocked_list
; /* blocked on mutex/etc. list */
112 u64 slice_end_time
; /* end of slice time (ticks) */
114 struct virt_cpu
*cpu
; /* guest cpu */
116 int state
; /* state */
118 char name
[TASK_NAME_LEN
+1]; /* task name */
120 /* lock dependency tracking */
122 struct held_lock lock_stack
[LDEP_STACK_SIZE
];
126 struct task
*task
; /* the virtual CPU task */
127 struct user
*directory
; /* the directory information */
129 struct console
*con
; /* the login console */
130 int print_ts
; /* print timestamps */
132 struct list_head guest_pages
; /* list of guest pages */
133 struct list_head virt_devs
; /* list of guest virtual devs */
134 struct list_head online_users
; /* list of online users */
136 struct address_space as
; /* the guest storage */
139 extern void init_sched(void); /* initialize the scheduler */
140 extern struct task
* create_task(char *name
, int (*f
)(void*), void*);
141 /* create a new task */
142 extern void __schedule(struct psw
*,
143 int newstate
); /* scheduler helper - use with caution */
144 extern void __schedule_svc(void);
145 extern void __schedule_blocked_svc(void);
147 extern void make_runnable(struct task
*task
);
149 extern void list_tasks(struct console
*con
,
150 void (*f
)(struct console
*, struct task
*));
153 * current - the current task's task struct
155 #define current extract_task()
157 #define PSA_CURRENT ((struct task**) 0x290)
160 * extract_task - return the current task struct
162 static inline struct task
*extract_task(void)
168 * set_task_ptr - set the stack's task struct pointer
169 * @task: task struct pointer to be made current
171 static inline void set_task_ptr(struct task
*task
)
177 * schedule - used to explicitly yield the cpu
179 static inline void schedule(void)
182 * if we are not interruptable, we shouldn't call any functions that
183 * may sleep - schedule() is guaranteed to sleep :)
185 BUG_ON(!interruptable());
196 * schedule_blocked - used to explicitly yield the cpu without readding the
197 * task to the runnable queue
199 static inline void schedule_blocked(void)
202 * if we are not interruptable, we shouldn't call any functions that
203 * may sleep - schedule() is guaranteed to sleep :)
205 BUG_ON(!interruptable());
211 "i" (SVC_SCHEDULE_BLOCKED
)