mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-18 16:26:31 +00:00
🆕 为AP处理器配置进程调度
This commit is contained in:
@ -1,6 +1,8 @@
|
||||
#include "sched.h"
|
||||
#include <common/kprint.h>
|
||||
|
||||
struct sched_queue_t sched_cfs_ready_queue[MAX_CPU_NUM]; // 就绪队列
|
||||
|
||||
/**
|
||||
* @brief 从就绪队列中取出PCB
|
||||
*
|
||||
@ -8,16 +10,16 @@
|
||||
*/
|
||||
struct process_control_block *sched_cfs_dequeue()
|
||||
{
|
||||
if (list_empty(&sched_cfs_ready_queue.proc_queue.list))
|
||||
if (list_empty(&sched_cfs_ready_queue[proc_current_cpu_id].proc_queue.list))
|
||||
{
|
||||
kdebug("list empty");
|
||||
return &initial_proc_union.pcb;
|
||||
}
|
||||
|
||||
struct process_control_block *proc = container_of(list_next(&sched_cfs_ready_queue.proc_queue.list), struct process_control_block, list);
|
||||
struct process_control_block *proc = container_of(list_next(&sched_cfs_ready_queue[proc_current_cpu_id].proc_queue.list), struct process_control_block, list);
|
||||
|
||||
list_del(&proc->list);
|
||||
--sched_cfs_ready_queue.count;
|
||||
--sched_cfs_ready_queue[proc_current_cpu_id].count;
|
||||
return proc;
|
||||
}
|
||||
|
||||
@ -28,10 +30,10 @@ struct process_control_block *sched_cfs_dequeue()
|
||||
*/
|
||||
void sched_cfs_enqueue(struct process_control_block *pcb)
|
||||
{
|
||||
struct process_control_block *proc = container_of(list_next(&sched_cfs_ready_queue.proc_queue.list), struct process_control_block, list);
|
||||
struct process_control_block *proc = container_of(list_next(&sched_cfs_ready_queue[proc_current_cpu_id].proc_queue.list), struct process_control_block, list);
|
||||
if (proc == &initial_proc_union.pcb)
|
||||
return;
|
||||
if ((list_empty(&sched_cfs_ready_queue.proc_queue.list)) == 0)
|
||||
if ((list_empty(&sched_cfs_ready_queue[proc_current_cpu_id].proc_queue.list)) == 0)
|
||||
{
|
||||
while (proc->virtual_runtime < pcb->virtual_runtime)
|
||||
{
|
||||
@ -39,7 +41,7 @@ void sched_cfs_enqueue(struct process_control_block *pcb)
|
||||
}
|
||||
}
|
||||
list_append(&proc->list, &pcb->list);
|
||||
++sched_cfs_ready_queue.count;
|
||||
++sched_cfs_ready_queue[proc_current_cpu_id].count;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -58,17 +60,17 @@ void sched_cfs()
|
||||
if (current_pcb->state = PROC_RUNNING) // 本次切换由于时间片到期引发,则再次加入就绪队列,否则交由其它功能模块进行管理
|
||||
sched_cfs_enqueue(current_pcb);
|
||||
|
||||
if (sched_cfs_ready_queue.cpu_exec_proc_jiffies <= 0)
|
||||
if (sched_cfs_ready_queue[proc_current_cpu_id].cpu_exec_proc_jiffies <= 0)
|
||||
{
|
||||
switch (proc->priority)
|
||||
{
|
||||
case 0:
|
||||
case 1:
|
||||
sched_cfs_ready_queue.cpu_exec_proc_jiffies = 4 / sched_cfs_ready_queue.count;
|
||||
sched_cfs_ready_queue[proc_current_cpu_id].cpu_exec_proc_jiffies = 4 / sched_cfs_ready_queue[proc_current_cpu_id].count;
|
||||
break;
|
||||
case 2:
|
||||
default:
|
||||
sched_cfs_ready_queue.cpu_exec_proc_jiffies = (4 / sched_cfs_ready_queue.count) << 2;
|
||||
sched_cfs_ready_queue[proc_current_cpu_id].cpu_exec_proc_jiffies = (4 / sched_cfs_ready_queue[proc_current_cpu_id].count) << 2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -79,20 +81,20 @@ void sched_cfs()
|
||||
// kdebug("not switch.");
|
||||
sched_cfs_enqueue(proc);
|
||||
|
||||
if (sched_cfs_ready_queue.cpu_exec_proc_jiffies <= 0)
|
||||
if (sched_cfs_ready_queue[proc_current_cpu_id].cpu_exec_proc_jiffies <= 0)
|
||||
{
|
||||
switch (proc->priority)
|
||||
{
|
||||
case 0:
|
||||
case 1:
|
||||
sched_cfs_ready_queue.cpu_exec_proc_jiffies = 4 / sched_cfs_ready_queue.count;
|
||||
//sched_cfs_ready_queue.cpu_exec_proc_jiffies = 5;
|
||||
sched_cfs_ready_queue[proc_current_cpu_id].cpu_exec_proc_jiffies = 4 / sched_cfs_ready_queue[proc_current_cpu_id].count;
|
||||
// sched_cfs_ready_queue.cpu_exec_proc_jiffies = 5;
|
||||
break;
|
||||
case 2:
|
||||
default:
|
||||
//sched_cfs_ready_queue.cpu_exec_proc_jiffies = 5;
|
||||
// sched_cfs_ready_queue.cpu_exec_proc_jiffies = 5;
|
||||
|
||||
sched_cfs_ready_queue.cpu_exec_proc_jiffies = (4 / sched_cfs_ready_queue.count) << 2;
|
||||
sched_cfs_ready_queue[proc_current_cpu_id].cpu_exec_proc_jiffies = (4 / sched_cfs_ready_queue[proc_current_cpu_id].count) << 2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -105,9 +107,13 @@ void sched_cfs()
|
||||
*/
|
||||
void sched_init()
|
||||
{
|
||||
memset(&sched_cfs_ready_queue, 0, sizeof(struct sched_queue_t));
|
||||
list_init(&sched_cfs_ready_queue.proc_queue.list);
|
||||
sched_cfs_ready_queue.count = 1; // 因为存在IDLE进程,因此为1
|
||||
sched_cfs_ready_queue.cpu_exec_proc_jiffies = 8;
|
||||
sched_cfs_ready_queue.proc_queue.virtual_runtime = 0x7fffffffffffffff;
|
||||
memset(&sched_cfs_ready_queue, 0, sizeof(struct sched_queue_t) * MAX_CPU_NUM);
|
||||
for (int i = 0; i < MAX_CPU_NUM; ++i)
|
||||
{
|
||||
|
||||
list_init(&sched_cfs_ready_queue[i].proc_queue.list);
|
||||
sched_cfs_ready_queue[i].count = 1; // 因为存在IDLE进程,因此为1
|
||||
sched_cfs_ready_queue[i].cpu_exec_proc_jiffies = 5;
|
||||
sched_cfs_ready_queue[i].proc_queue.virtual_runtime = 0x7fffffffffffffff;
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@
|
||||
#include <common/glib.h>
|
||||
#include <process/process.h>
|
||||
|
||||
// @todo: 用红黑树重写cfs的队列
|
||||
struct sched_queue_t
|
||||
{
|
||||
long count; // 当前队列中的数量
|
||||
@ -10,8 +11,8 @@ struct sched_queue_t
|
||||
struct process_control_block proc_queue;
|
||||
};
|
||||
|
||||
// @todo: 用红黑树重写cfs的队列
|
||||
struct sched_queue_t sched_cfs_ready_queue; // 就绪队列
|
||||
|
||||
extern struct sched_queue_t sched_cfs_ready_queue[MAX_CPU_NUM]; // 就绪队列
|
||||
|
||||
/**
|
||||
* @brief 调度函数
|
||||
|
Reference in New Issue
Block a user