sched.c 1.6 KB

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