mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-12 05:56:48 +00:00
增加进程的调度policy属性 (#63)
* 添加进程的policy属性 * update * 修改设置进程策略 * 删除重复定义 * 更正注释及格式 Co-authored-by: longjin <longjin@RinGoTek.cn>
This commit is contained in:
parent
c2fa7bf46d
commit
ed178b560b
@ -101,6 +101,7 @@ struct process_control_block
|
||||
struct process_control_block *parent_pcb;
|
||||
|
||||
int32_t exit_code; // 进程退出时的返回码
|
||||
uint32_t policy; // 进程调度策略标志位
|
||||
wait_queue_node_t wait_child_proc_exit; // 子进程退出等待队列
|
||||
|
||||
/* PF_kTHREAD | PF_IO_WORKER 的进程,worker_private不为NULL*/
|
||||
@ -108,8 +109,7 @@ struct process_control_block
|
||||
};
|
||||
|
||||
// 将进程的pcb和内核栈融合到一起,8字节对齐
|
||||
union proc_union
|
||||
{
|
||||
union proc_union {
|
||||
struct process_control_block pcb;
|
||||
ul stack[STACK_SIZE / sizeof(ul)];
|
||||
} __attribute__((aligned(8)));
|
||||
|
@ -45,7 +45,8 @@
|
||||
.parent_pcb = &proc, \
|
||||
.exit_code = 0, \
|
||||
.wait_child_proc_exit = 0, \
|
||||
.worker_private = NULL \
|
||||
.worker_private = NULL, \
|
||||
.policy = SCHED_NORMAL \
|
||||
}
|
||||
|
||||
/**
|
||||
@ -183,7 +184,7 @@ void process_exit_notify();
|
||||
* @return int
|
||||
*/
|
||||
|
||||
pid_t kernel_thread(int (*fn)(void*), void* arg, unsigned long flags);
|
||||
pid_t kernel_thread(int (*fn)(void *), void *arg, unsigned long flags);
|
||||
|
||||
int process_fd_alloc(struct vfs_file_t *file);
|
||||
|
||||
|
@ -81,7 +81,6 @@ void sched_cfs()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
process_switch_mm(proc);
|
||||
|
||||
switch_proc(current_pcb, proc);
|
||||
|
@ -1,9 +1,53 @@
|
||||
#include "sched.h"
|
||||
#include <common/kprint.h>
|
||||
#include <driver/video/video.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加入就绪队列
|
||||
*
|
||||
|
@ -2,6 +2,61 @@
|
||||
|
||||
#include <common/glib.h>
|
||||
#include <process/process.h>
|
||||
|
||||
/*
|
||||
* Scheduling policies
|
||||
*/
|
||||
#define SCHED_NORMAL 0
|
||||
#define SCHED_FIFO 1
|
||||
#define SCHED_RR 2
|
||||
#define SCHED_BATCH 3
|
||||
/* SCHED_ISO: reserved but not implemented yet */
|
||||
#define SCHED_IDLE 5
|
||||
#define SCHED_DEADLINE 6
|
||||
#define SCHED_MAX_POLICY_NUM SCHED_DEADLINE
|
||||
|
||||
#define IS_VALID_SCHED_POLICY(_policy) ((_policy) > 0 && (_policy) <= SCHED_MAX_POLICY_NUM)
|
||||
|
||||
struct sched_param
|
||||
{
|
||||
int sched_priority;
|
||||
};
|
||||
struct sched_attr
|
||||
{
|
||||
uint32_t size;
|
||||
|
||||
uint32_t sched_policy;
|
||||
uint64_t sched_flags;
|
||||
|
||||
/* SCHED_NORMAL, SCHED_BATCH */
|
||||
int32_t sched_nice;
|
||||
|
||||
/* SCHED_FIFO, SCHED_RR */
|
||||
uint32_t sched_priority;
|
||||
|
||||
/* SCHED_DEADLINE */
|
||||
uint64_t sched_runtime;
|
||||
uint64_t sched_deadline;
|
||||
uint64_t sched_period;
|
||||
|
||||
/* Utilization hints */
|
||||
uint32_t sched_util_min;
|
||||
uint32_t sched_util_max;
|
||||
};
|
||||
|
||||
static int __sched_setscheduler(struct process_control_block *p, const struct sched_attr *attr, bool user, bool pi);
|
||||
static int _sched_setscheduler(struct process_control_block *p, int policy, const struct sched_param *param,
|
||||
bool check);
|
||||
/**
|
||||
* 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);
|
||||
/**
|
||||
* @brief 包裹sched_enqueue(),将PCB加入就绪队列
|
||||
*
|
||||
@ -14,7 +69,6 @@ void sched_enqueue(struct process_control_block *pcb);
|
||||
*/
|
||||
void sched();
|
||||
|
||||
|
||||
void sched_init();
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user