sched.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #pragma once
  2. #include <common/glib.h>
  3. #include <process/process.h>
  4. /*
  5. * Scheduling policies
  6. */
  7. #define SCHED_NORMAL 0
  8. #define SCHED_FIFO 1
  9. #define SCHED_RR 2
  10. #define SCHED_BATCH 3
  11. /* SCHED_ISO: reserved but not implemented yet */
  12. #define SCHED_IDLE 5
  13. #define SCHED_DEADLINE 6
  14. #define SCHED_MAX_POLICY_NUM SCHED_DEADLINE
  15. #define IS_VALID_SCHED_POLICY(_policy) ((_policy) > 0 && (_policy) <= SCHED_MAX_POLICY_NUM)
  16. struct sched_param
  17. {
  18. int sched_priority;
  19. };
  20. struct sched_attr
  21. {
  22. uint32_t size;
  23. uint32_t sched_policy;
  24. uint64_t sched_flags;
  25. /* SCHED_NORMAL, SCHED_BATCH */
  26. int32_t sched_nice;
  27. /* SCHED_FIFO, SCHED_RR */
  28. uint32_t sched_priority;
  29. /* SCHED_DEADLINE */
  30. uint64_t sched_runtime;
  31. uint64_t sched_deadline;
  32. uint64_t sched_period;
  33. /* Utilization hints */
  34. uint32_t sched_util_min;
  35. uint32_t sched_util_max;
  36. };
  37. static int __sched_setscheduler(struct process_control_block *p, const struct sched_attr *attr, bool user, bool pi);
  38. static int _sched_setscheduler(struct process_control_block *p, int policy, const struct sched_param *param,
  39. bool check);
  40. /**
  41. * sched_setscheduler -设置进程的调度策略
  42. * @param p 需要修改的pcb
  43. * @param policy 需要设置的policy
  44. * @param param structure containing the new RT priority. 目前没有用
  45. *
  46. * @return 成功返回0,否则返回对应的错误码
  47. *
  48. */
  49. int sched_setscheduler(struct process_control_block *p, int policy, const struct sched_param *param);
  50. /**
  51. * @brief 包裹sched_enqueue(),将PCB加入就绪队列
  52. *
  53. * @param pcb
  54. */
  55. void sched_enqueue(struct process_control_block *pcb);
  56. /**
  57. * @brief 包裹sched_cfs(),调度函数
  58. *
  59. */
  60. void sched();
  61. void sched_init();
  62. /**
  63. * @brief 当时钟中断到达时,更新时间片
  64. *
  65. */
  66. void sched_update_jiffies();