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