《操作系统》的实验代码。
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

70 rindas
2.0 KiB

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