🆕 为AP处理器配置进程调度

This commit is contained in:
fslongjin
2022-04-14 00:26:41 +08:00
parent 82e34f271f
commit ddbfb822c4
8 changed files with 90 additions and 45 deletions

View File

@ -482,8 +482,18 @@ void do_IRQ(struct pt_regs *rsp, ul number)
else if (number > 0x80)
{
printk_color(RED, BLACK, "SMP IPI [ %d ]\n", number);
//printk_color(RED, BLACK, "SMP IPI [ %d ]\n", number);
apic_local_apic_edge_ack(number);
if (number == 0xc8) // 来自BSP的HPET中断消息
{
sched_cfs_ready_queue[proc_current_cpu_id].cpu_exec_proc_jiffies -= 2;
++(current_pcb->virtual_runtime);
if (sched_cfs_ready_queue[proc_current_cpu_id].cpu_exec_proc_jiffies <= 0)
current_pcb->flags |= PROC_NEED_SCHED;
//printk_color(RED, BLACK, "CPU_exec_task_jiffies:%d current_pcb = %#018lx\t current_pcb->thread=%#018lx\n", sched_cfs_ready_queue[proc_current_cpu_id].cpu_exec_proc_jiffies, (ul)current_pcb, (ul)current_pcb->thread);
}
}
else
{
@ -501,7 +511,7 @@ void do_IRQ(struct pt_regs *rsp, ul number)
kBUG("current_pcb->preempt_count<0! pid=%d", current_pcb->pid); // should not be here
// 检测当前进程是否可被调度
if (current_pcb->flags & PROC_NEED_SCHED)
if (current_pcb->flags & PROC_NEED_SCHED && proc_current_cpu_id == 1)
{
sched_cfs();
}

View File

@ -6,6 +6,7 @@
#include <driver/timers/timer.h>
#include <process/process.h>
#include <sched/sched.h>
#include <smp/ipi.h>
static struct acpi_HPET_description_table_t *hpet_table;
static uint64_t HPET_REG_BASE = 0;
@ -50,11 +51,16 @@ hardware_intr_controller HPET_intr_controller =
void HPET_handler(uint64_t number, uint64_t param, struct pt_regs *regs)
{
//printk("(HPET)");
// printk("(HPET)");
switch (param)
{
case 0: // 定时器0中断
++timer_jiffies;
// 将HEPT中断消息转发到ap:1处理器
ipi_send_IPI(DEST_PHYSICAL, IDLE, ICR_LEVEL_DE_ASSERT, EDGE_TRIGGER, 0xc8,
ICR_APIC_FIXED, ICR_No_Shorthand, true, 1);
// 若当前时间比定时任务的时间间隔大,则进入中断下半部
if (container_of(list_next(&timer_func_head.list), struct timer_func_list_t, list)->expire_jiffies <= timer_jiffies)
set_softirq_status(TIMER_SIRQ);
@ -63,20 +69,22 @@ void HPET_handler(uint64_t number, uint64_t param, struct pt_regs *regs)
{
case 0:
case 1:
--sched_cfs_ready_queue.cpu_exec_proc_jiffies;
--sched_cfs_ready_queue[proc_current_cpu_id].cpu_exec_proc_jiffies;
++current_pcb->virtual_runtime;
break;
case 2:
default:
sched_cfs_ready_queue.cpu_exec_proc_jiffies -= 2;
sched_cfs_ready_queue[proc_current_cpu_id].cpu_exec_proc_jiffies -= 2;
current_pcb->virtual_runtime += 2;
break;
}
if (sched_cfs_ready_queue.cpu_exec_proc_jiffies <= 0)
/* 由于目前只有BSP处理器会收到HPET中断因此这里只会标记BSP处理器的进程需要调度
if (sched_cfs_ready_queue[proc_current_cpu_id].cpu_exec_proc_jiffies <= 0)
{
current_pcb->flags |= PROC_NEED_SCHED;
}
*/
break;
@ -155,8 +163,6 @@ int HPET_init()
// 使用I/O APIC 的IRQ2接收hpet定时器0的中断
apic_make_rte_entry(&entry, 34, IO_APIC_FIXED, DEST_PHYSICAL, IDLE, POLARITY_HIGH, IRR_RESET, EDGE_TRIGGER, MASKED, 0);
*(uint64_t *)(HPET_REG_BASE + MAIN_CNT) = 0;
io_mfence();
*(uint64_t *)(HPET_REG_BASE + TIM0_CONF) = 0x004c; // 设置定时器0为周期定时边沿触发投递到IO APIC的2号引脚这里有点绕写的是8259的引脚号但是因为禁用了8259因此会被路由到IO APIC的2号引脚
@ -166,8 +172,6 @@ int HPET_init()
rtc_get_cmos_time(&rtc_now);
kinfo("HPET Initialized.");
*(uint64_t *)(HPET_REG_BASE + GEN_CONF) = 3; // 置位旧设备中断路由兼容标志位、定时器组使能标志位
io_mfence();