|
@@ -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;
|
|
|
+ }
|
|
|
}
|