cp: implement mutex dependency tracking
[hvf.git] / cp / include / sched.h
blobcbf8fbb4031f3720003fdcce43f640a636642f48
1 /*
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
5 * details.
6 */
8 #ifndef __SCHED_H
9 #define __SCHED_H
11 #include <list.h>
12 #include <page.h>
13 #include <dat.h>
14 #include <clock.h>
15 #include <interrupt.h>
16 #include <ldep.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
23 #define TASK_LOCKED 2
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 */
32 struct psw {
33 u8 _zero0:1,
34 r:1, /* PER Mask (R) */
35 _zero1:3,
36 t:1, /* DAT Mode (T) */
37 io:1, /* I/O Mask (IO) */
38 ex:1; /* External Mask (EX) */
40 u8 key:4, /* Key */
41 _zero2:1,
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 */
50 u8 _zero3:7,
51 ea:1; /* Extended Addressing (EA) */
53 u32 ba:1, /* Basic Addressing (BA) */
54 _zero4:31;
56 u64 ptr;
60 * saved registers for guests
62 * NOTE: some registers are saved in the SIE control block!
64 struct guest_regs {
65 u64 gpr[16];
66 u32 ar[16];
67 u64 fpr[64];
68 u32 fpcr;
71 /* saved registers for CP tasks */
72 struct regs {
73 struct psw psw;
74 u64 gpr[16];
75 u64 cr1;
79 * These states mirror those described in chapter 4 of SA22-7832-06
81 enum virt_cpustate {
82 GUEST_STOPPED = 0,
83 GUEST_OPERATING,
84 GUEST_LOAD,
85 GUEST_CHECKSTOP,
88 #include <sie.h>
90 struct virt_cpu {
91 /* the SIE control block is picky about alignment */
92 struct sie_cb sie_cb;
94 struct guest_regs regs;
95 u64 cpuid;
97 enum virt_cpustate state;
100 #define TASK_NAME_LEN 16
103 * This structure describes a running process.
105 struct task {
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 */
121 int nr_locks;
122 struct held_lock lock_stack[LDEP_STACK_SIZE];
125 struct virt_sys {
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)
164 return *PSA_CURRENT;
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)
173 *PSA_CURRENT = 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());
187 asm volatile(
188 " svc %0\n"
189 : /* output */
190 : /* input */
191 "i" (SVC_SCHEDULE)
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());
207 asm volatile(
208 " svc %0\n"
209 : /* output */
210 : /* input */
211 "i" (SVC_SCHEDULE_BLOCKED)
215 #endif