增加进程的调度policy属性 (#63)

* 添加进程的policy属性

* update

* 修改设置进程策略

* 删除重复定义

* 更正注释及格式

Co-authored-by: longjin <longjin@RinGoTek.cn>
This commit is contained in:
kong 2022-10-21 20:38:01 +08:00 committed by GitHub
parent c2fa7bf46d
commit ed178b560b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 170 additions and 72 deletions

View File

@ -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)));

View File

@ -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);

View File

@ -81,7 +81,6 @@ void sched_cfs()
}
}
process_switch_mm(proc);
switch_proc(current_pcb, proc);

View File

@ -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加入就绪队列
*

View File

@ -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();
/**