kong ed178b560b
增加进程的调度policy属性 (#63)
* 添加进程的policy属性

* update

* 修改设置进程策略

* 删除重复定义

* 更正注释及格式

Co-authored-by: longjin <longjin@RinGoTek.cn>
2022-10-21 20:38:01 +08:00

73 lines
1.6 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "sched.h"
#include <common/kprint.h>
#include <common/spinlock.h>
#include <driver/video/video.h>
#include <sched/cfs.h>
/**
* @brief
*
* @param p pcb
* @param attr 调度属性
* @param user 请求是否来自用户态
* @param pi
* @return int
*/
static int __sched_setscheduler(struct process_control_block *p, const struct sched_attr *attr, bool user, bool pi)
{
int policy = attr->sched_policy;
recheck:;
// 这里policy的设置小于0是因为需要在临界区内更新值之后重新到这里判断
if (!IS_VALID_SCHED_POLICY(policy))
{
return -EINVAL;
}
// 修改成功
p->policy = policy;
return 0;
}
static int _sched_setscheduler(struct process_control_block *p, int policy, const struct sched_param *param, bool check)
{
struct sched_attr attr = {.sched_policy = policy};
return __sched_setscheduler(p, &attr, check, true);
}
/**
* sched_setscheduler -设置进程的调度策略
* @param p 需要修改的pcb
* @param policy 需要设置的policy
* @param param structure containing the new RT priority. 目前没有用
*
* @return 成功返回0,否则返回对应的错误码
*
*/
int sched_setscheduler(struct process_control_block *p, int policy, const struct sched_param *param)
{
return _sched_setscheduler(p, policy, param, true);
}
/**
* @brief 包裹shced_cfs_enqueue(),将PCB加入就绪队列
*
* @param pcb
*/
void sched_enqueue(struct process_control_block *pcb)
{
sched_cfs_enqueue(pcb);
}
/**
* @brief 包裹sched_cfs(),调度函数
*
*/
void sched()
{
sched_cfs();
}
void sched_init()
{
sched_cfs_init();
}