loader: remove shouting from ORB's variable name
[hvf.git] / cp / include / sched.h
blob1a5d0c0b182de5495c416c94316865f51b81d9dc
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
24 #define TASK_ZOMBIE 3
26 #define STACK_FRAME_SIZE 160
28 #define SCHED_SLICE_MS 30 /* 30ms scheduler slice */
29 #define SCHED_TICKS_PER_SLICE (HZ / SCHED_SLICE_MS)
31 #define HZ 100 /* number of ticks per second */
33 /* saved registers for CP tasks */
34 struct regs {
35 struct psw psw;
36 u64 gpr[16];
37 u64 cr1;
40 #define TASK_NAME_LEN 16
43 * This structure describes a running process.
45 struct task {
46 struct regs regs; /* saved registers */
48 struct list_head run_queue; /* runnable list */
49 struct list_head proc_list; /* processes list */
50 struct list_head blocked_list; /* blocked on mutex/etc. list */
52 u64 slice_end_time; /* end of slice time (ticks) */
54 int state; /* state */
56 void *stack; /* the stack */
58 char name[TASK_NAME_LEN+1]; /* task name */
60 /* lock dependency tracking */
61 int nr_locks;
62 struct held_lock lock_stack[LDEP_STACK_SIZE];
65 extern void init_sched(void); /* initialize the scheduler */
66 extern struct task* create_task(char *name, int (*f)(void*), void*);
67 /* create a new task */
68 extern void __schedule(struct psw *,
69 int newstate); /* scheduler helper - use with caution */
70 extern void __schedule_svc(void);
71 extern void __schedule_blocked_svc(void);
72 extern void __schedule_exit_svc(void);
74 extern void make_runnable(struct task *task);
76 extern void list_tasks(void (*f)(struct task*, void*),
77 void *priv);
79 /**
80 * current - the current task's task struct
82 #define current extract_task()
84 #define PSA_CURRENT ((struct task**) 0x290)
86 /**
87 * extract_task - return the current task struct
89 static inline struct task *extract_task(void)
91 return *PSA_CURRENT;
94 /**
95 * set_task_ptr - set the stack's task struct pointer
96 * @task: task struct pointer to be made current
98 static inline void set_task_ptr(struct task *task)
100 *PSA_CURRENT = task;
104 * schedule - used to explicitly yield the cpu
106 static inline void schedule(void)
109 * if we are not interruptable, we shouldn't call any functions that
110 * may sleep - schedule() is guaranteed to sleep :)
112 BUG_ON(!interruptable());
114 asm volatile(
115 " svc %0\n"
116 : /* output */
117 : /* input */
118 "i" (SVC_SCHEDULE)
123 * schedule_blocked - used to explicitly yield the cpu without readding the
124 * task to the runnable queue
126 static inline void schedule_blocked(void)
129 * if we are not interruptable, we shouldn't call any functions that
130 * may sleep - schedule() is guaranteed to sleep :)
132 BUG_ON(!interruptable());
134 asm volatile(
135 " svc %0\n"
136 : /* output */
137 : /* input */
138 "i" (SVC_SCHEDULE_BLOCKED)
143 * exit - schedule with the intent to terminate the current task
145 static inline void exit(void)
148 * if we are not interruptable, we shouldn't call any functions that
149 * may sleep - schedule() is guaranteed to sleep :)
151 BUG_ON(!interruptable());
153 asm volatile(
154 " svc %0\n"
155 : /* output */
156 : /* input */
157 "i" (SVC_SCHEDULE_EXIT)
161 #endif