sched.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #include "sched.h"
  2. #include <common/kprint.h>
  3. #include <common/spinlock.h>
  4. #include <driver/video/video.h>
  5. #include <sched/cfs.h>
  6. /**
  7. * @brief
  8. *
  9. * @param p pcb
  10. * @param attr 调度属性
  11. * @param user 请求是否来自用户态
  12. * @param pi
  13. * @return int
  14. */
  15. static int __sched_setscheduler(struct process_control_block *p, const struct sched_attr *attr, bool user, bool pi)
  16. {
  17. int policy = attr->sched_policy;
  18. recheck:;
  19. // 这里policy的设置小于0是因为,需要在临界区内更新值之后,重新到这里判断
  20. if (!IS_VALID_SCHED_POLICY(policy))
  21. {
  22. return -EINVAL;
  23. }
  24. // 修改成功
  25. p->policy = policy;
  26. return 0;
  27. }
  28. static int _sched_setscheduler(struct process_control_block *p, int policy, const struct sched_param *param, bool check)
  29. {
  30. struct sched_attr attr = {.sched_policy = policy};
  31. return __sched_setscheduler(p, &attr, check, true);
  32. }
  33. /**
  34. * sched_setscheduler -设置进程的调度策略
  35. * @param p 需要修改的pcb
  36. * @param policy 需要设置的policy
  37. * @param param structure containing the new RT priority. 目前没有用
  38. *
  39. * @return 成功返回0,否则返回对应的错误码
  40. *
  41. */
  42. int sched_setscheduler(struct process_control_block *p, int policy, const struct sched_param *param)
  43. {
  44. return _sched_setscheduler(p, policy, param, true);
  45. }
  46. /**
  47. * @brief 包裹shced_cfs_enqueue(),将PCB加入就绪队列
  48. *
  49. * @param pcb
  50. */
  51. void sched_enqueue(struct process_control_block *pcb)
  52. {
  53. sched_cfs_enqueue(pcb);
  54. }
  55. /**
  56. * @brief 包裹sched_cfs(),调度函数
  57. *
  58. */
  59. void sched()
  60. {
  61. sched_cfs();
  62. }
  63. void sched_init()
  64. {
  65. sched_cfs_init();
  66. }