#ifndef KERNEL_SCHED_H_ #define KERNEL_SCHED_H_ #include #include #include #include #include #include #define PRIO_MAX 32 #ifdef __cplusplus extern "C" { #endif struct channel; struct runqueue; enum sched_priority { PRIO_IDLE = 4, PRIO_SUBNORMAL = 6, PRIO_NORMAL = 10, PRIO_SUPERNORMAL = 14, PRIO_HIGH = 18, PRIO_REALTIME = 24, }; enum sched_mode { /* used when calling from non-interrupt context. threads that aren't in state THREAD_READY are removed from the runqueue. */ SCHED_NORMAL = 0, /* used when calling from interrupt context. threads that aren't in state THREAD_READY are still added to the runqueue. */ SCHED_IRQ = 1, }; struct runqueue { struct queue rq_queues[PRIO_MAX]; uint32_t rq_readybits; spin_lock_t rq_lock; unsigned int rq_nthreads; struct thread *rq_cur, *rq_idle; }; struct timer { struct queue_entry t_entry; struct cpu_data *t_cpu; struct thread *t_owner; unsigned long t_expiry; void (*t_callback)(struct timer *); }; extern kern_status_t sched_init(void); extern void schedule(enum sched_mode mode); extern void preempt_disable(void); extern void preempt_enable(void); extern void rq_init(struct runqueue *rq); extern struct thread *rq_dequeue(struct runqueue *rq); extern void rq_enqueue(struct runqueue *rq, struct thread *thr); static inline void rq_lock(struct runqueue *rq, unsigned long *flags) { spin_lock_irqsave(&rq->rq_lock, flags); } static inline void rq_unlock(struct runqueue *rq, unsigned long flags) { spin_unlock_irqrestore(&rq->rq_lock, flags); } extern void rq_remove_thread(struct runqueue *rq, struct thread *thr); extern struct runqueue *cpu_rq(unsigned int cpu); extern cycles_t default_quantum(void); extern bool need_resched(void); extern struct task *current_task(void); extern struct thread *current_thread(void); extern struct runqueue *select_rq_for_thread(struct thread *thr); extern void schedule_thread_on_cpu(struct thread *thr); extern void start_charge_period(void); extern void end_charge_period(void); extern void add_timer(struct timer *timer); extern void remove_timer(struct timer *timer); extern unsigned long schedule_timeout(unsigned long clock_ticks); extern unsigned long milli_sleep(unsigned long ms); extern void sleep_forever(void); #ifdef __cplusplus } #endif #endif