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
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 */
40 #define TASK_NAME_LEN 16
43 * This structure describes a running process.
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 */
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*),
80 * current - the current task's task struct
82 #define current extract_task()
84 #define PSA_CURRENT ((struct task**) 0x290)
87 * extract_task - return the current task struct
89 static inline struct task
*extract_task(void)
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
)
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());
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());
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());
157 "i" (SVC_SCHEDULE_EXIT
)