《操作系统》的实验代码。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
2.4 KiB

10 years ago
  1. #ifndef __KERN_SCHEDULE_SCHED_H__
  2. #define __KERN_SCHEDULE_SCHED_H__
  3. #include <defs.h>
  4. #include <list.h>
  5. #include <skew_heap.h>
  6. #define MAX_TIME_SLICE 20
  7. struct proc_struct;
  8. typedef struct {
  9. unsigned int expires; //the expire time
  10. struct proc_struct *proc; //the proc wait in this timer. If the expire time is end, then this proc will be scheduled
  11. list_entry_t timer_link; //the timer list
  12. } timer_t;
  13. #define le2timer(le, member) \
  14. to_struct((le), timer_t, member)
  15. // init a timer
  16. static inline timer_t *
  17. timer_init(timer_t *timer, struct proc_struct *proc, int expires) {
  18. timer->expires = expires;
  19. timer->proc = proc;
  20. list_init(&(timer->timer_link));
  21. return timer;
  22. }
  23. struct run_queue;
  24. // The introduction of scheduling classes is borrrowed from Linux, and makes the
  25. // core scheduler quite extensible. These classes (the scheduler modules) encapsulate
  26. // the scheduling policies.
  27. struct sched_class {
  28. // the name of sched_class
  29. const char *name;
  30. // Init the run queue
  31. void (*init)(struct run_queue *rq);
  32. // put the proc into runqueue, and this function must be called with rq_lock
  33. void (*enqueue)(struct run_queue *rq, struct proc_struct *proc);
  34. // get the proc out runqueue, and this function must be called with rq_lock
  35. void (*dequeue)(struct run_queue *rq, struct proc_struct *proc);
  36. // choose the next runnable task
  37. struct proc_struct *(*pick_next)(struct run_queue *rq);
  38. // dealer of the time-tick
  39. void (*proc_tick)(struct run_queue *rq, struct proc_struct *proc);
  40. /* for SMP support in the future
  41. * load_balance
  42. * void (*load_balance)(struct rq* rq);
  43. * get some proc from this rq, used in load_balance,
  44. * return value is the num of gotten proc
  45. * int (*get_proc)(struct rq* rq, struct proc* procs_moved[]);
  46. */
  47. };
  48. struct run_queue {
  49. list_entry_t run_list;
  50. unsigned int proc_num;
  51. int max_time_slice;
  52. // For LAB6 ONLY
  53. skew_heap_entry_t *lab6_run_pool;
  54. };
  55. void sched_init(void);
  56. void wakeup_proc(struct proc_struct *proc);
  57. void schedule(void);
  58. void add_timer(timer_t *timer); // add timer to timer_list
  59. void del_timer(timer_t *timer); // del timer from timer_list
  60. void run_timer_list(void); // call scheduler to update tick related info, and check the timer is expired? If expired, then wakup proc
  61. #endif /* !__KERN_SCHEDULE_SCHED_H__ */