mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-18 12:16:31 +00:00
完善ipi通信机制
This commit is contained in:
@ -32,6 +32,17 @@ void ipi_send_IPI(uint32_t dest_mode, uint32_t deliver_status, uint32_t level, u
|
||||
*(uint32_t *)(APIC_LOCAL_APIC_VIRT_BASE_ADDR + 0x310) = (uint32_t)(((*(ul *)&icr_entry) >> 32) & 0xffff);
|
||||
*(uint32_t *)(APIC_LOCAL_APIC_VIRT_BASE_ADDR + 0x300) = (uint32_t)((*(ul *)&icr_entry) & 0xffff);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
int ipi_regiserIPI(uint64_t irq_num, void *arg,
|
||||
void (*handler)(uint64_t irq_num, uint64_t param, struct pt_regs *regs),
|
||||
uint64_t param, hardware_intr_controller *controller, char *irq_name)
|
||||
{
|
||||
irq_desc_t *p = &SMP_IPI_desc[irq_num-200];
|
||||
p->controller = NULL; // 由于ipi不涉及到具体的硬件操作,因此不需要controller
|
||||
p->irq_name = irq_name;
|
||||
p->parameter = param;
|
||||
p->flags = 0;
|
||||
p->handler = handler;
|
||||
return 0;
|
||||
}
|
@ -29,3 +29,18 @@
|
||||
*/
|
||||
void ipi_send_IPI(uint32_t dest_mode, uint32_t deliver_status, uint32_t level, uint32_t trigger,
|
||||
uint32_t vector, uint32_t deliver_mode, uint32_t dest_shorthand, bool apic_type, uint32_t destination);
|
||||
|
||||
/**
|
||||
* @brief ipi中断处理注册函数
|
||||
*
|
||||
* @param irq_num 中断向量号
|
||||
* @param arg 参数
|
||||
* @param handler 处理函数
|
||||
* @param param 参数
|
||||
* @param controller 当前为NULL
|
||||
* @param irq_name ipi中断名
|
||||
* @return int 成功:0
|
||||
*/
|
||||
int ipi_regiserIPI(uint64_t irq_num, void *arg,
|
||||
void (*handler)(uint64_t irq_num, uint64_t param, struct pt_regs *regs),
|
||||
uint64_t param, hardware_intr_controller *controller, char *irq_name);
|
@ -484,15 +484,11 @@ void do_IRQ(struct pt_regs *rsp, ul 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);
|
||||
irq_desc_t * irq = &SMP_IPI_desc[number-200];
|
||||
if(irq->handler!=NULL)
|
||||
irq->handler(number, irq->parameter, rsp);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -65,26 +65,7 @@ void HPET_handler(uint64_t number, uint64_t param, struct pt_regs *regs)
|
||||
if (container_of(list_next(&timer_func_head.list), struct timer_func_list_t, list)->expire_jiffies <= timer_jiffies)
|
||||
set_softirq_status(TIMER_SIRQ);
|
||||
|
||||
switch (current_pcb->priority)
|
||||
{
|
||||
case 0:
|
||||
case 1:
|
||||
--sched_cfs_ready_queue[proc_current_cpu_id].cpu_exec_proc_jiffies;
|
||||
++current_pcb->virtual_runtime;
|
||||
break;
|
||||
case 2:
|
||||
default:
|
||||
sched_cfs_ready_queue[proc_current_cpu_id].cpu_exec_proc_jiffies -= 2;
|
||||
current_pcb->virtual_runtime += 2;
|
||||
break;
|
||||
}
|
||||
|
||||
/* 由于目前只有BSP处理器会收到HPET中断,因此这里只会标记BSP处理器的进程需要调度
|
||||
if (sched_cfs_ready_queue[proc_current_cpu_id].cpu_exec_proc_jiffies <= 0)
|
||||
{
|
||||
current_pcb->flags |= PROC_NEED_SCHED;
|
||||
}
|
||||
*/
|
||||
sched_update_jiffies();
|
||||
|
||||
break;
|
||||
|
||||
|
@ -101,6 +101,30 @@ void sched_cfs()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 当时钟中断到达时,更新时间片
|
||||
*
|
||||
*/
|
||||
void sched_update_jiffies()
|
||||
{
|
||||
switch (current_pcb->priority)
|
||||
{
|
||||
case 0:
|
||||
case 1:
|
||||
--sched_cfs_ready_queue[proc_current_cpu_id].cpu_exec_proc_jiffies;
|
||||
++current_pcb->virtual_runtime;
|
||||
break;
|
||||
case 2:
|
||||
default:
|
||||
sched_cfs_ready_queue[proc_current_cpu_id].cpu_exec_proc_jiffies -= 2;
|
||||
current_pcb->virtual_runtime += 2;
|
||||
break;
|
||||
}
|
||||
// 时间片耗尽,标记可调度
|
||||
if (sched_cfs_ready_queue[proc_current_cpu_id].cpu_exec_proc_jiffies <= 0)
|
||||
current_pcb->flags |= PROC_NEED_SCHED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 初始化进程调度器
|
||||
*
|
||||
|
@ -40,3 +40,9 @@ struct process_control_block *sched_cfs_dequeue();
|
||||
*
|
||||
*/
|
||||
void sched_init();
|
||||
|
||||
/**
|
||||
* @brief 当时钟中断到达时,更新时间片
|
||||
*
|
||||
*/
|
||||
void sched_update_jiffies();
|
@ -6,7 +6,6 @@
|
||||
#error "error type of arch!"
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* @brief 发送ipi消息
|
||||
*
|
||||
@ -22,3 +21,18 @@
|
||||
*/
|
||||
extern void ipi_send_IPI(uint32_t dest_mode, uint32_t deliver_status, uint32_t level, uint32_t trigger,
|
||||
uint32_t vector, uint32_t deliver_mode, uint32_t dest_shorthand, bool apic_type, uint32_t destination);
|
||||
|
||||
/**
|
||||
* @brief ipi中断处理注册函数
|
||||
*
|
||||
* @param irq_num 中断向量号
|
||||
* @param arg 参数
|
||||
* @param handler 处理函数
|
||||
* @param param 参数
|
||||
* @param controller 当前为NULL
|
||||
* @param irq_name ipi中断名
|
||||
* @return int 成功:0
|
||||
*/
|
||||
extern int ipi_regiserIPI(uint64_t irq_num, void *arg,
|
||||
void (*handler)(uint64_t irq_num, uint64_t param, struct pt_regs *regs),
|
||||
uint64_t param, hardware_intr_controller *controller, char *irq_name);
|
@ -7,8 +7,12 @@
|
||||
#include "../process/process.h"
|
||||
#include "../process/spinlock.h"
|
||||
|
||||
#include <sched/sched.h>
|
||||
|
||||
#include "ipi.h"
|
||||
|
||||
void ipi_0xc8_handler(uint64_t irq_num, uint64_t param, struct pt_regs *regs); // 由BSP转发的HPET中断处理函数
|
||||
|
||||
static spinlock_t multi_core_starting_lock; // 多核启动锁
|
||||
|
||||
static struct acpi_Processor_Local_APIC_Structure_t *proc_local_apic_structs[MAX_SUPPORTED_PROCESSOR_NUM];
|
||||
@ -38,6 +42,9 @@ void smp_init()
|
||||
|
||||
memset((void *)SMP_IPI_desc, 0, sizeof(irq_desc_t) * SMP_IRQ_NUM);
|
||||
|
||||
// 注册接收bsp处理器的hpet中断转发的处理函数
|
||||
ipi_regiserIPI(0xc8, NULL, &ipi_0xc8_handler, NULL, NULL, "IPI 0xc8");
|
||||
|
||||
ipi_send_IPI(DEST_PHYSICAL, IDLE, ICR_LEVEL_DE_ASSERT, EDGE_TRIGGER, 0x00, ICR_INIT, ICR_ALL_EXCLUDE_Self, true, 0x00);
|
||||
|
||||
for (int i = 1; i < total_processor_num; ++i) // i从1开始,不初始化bsp
|
||||
@ -155,3 +162,9 @@ void smp_ap_start()
|
||||
while (1) // 这里要循环hlt,原因是当收到中断后,核心会被唤醒,处理完中断之后不会自动hlt
|
||||
hlt();
|
||||
}
|
||||
|
||||
// 由BSP转发的HPET中断处理函数
|
||||
void ipi_0xc8_handler(uint64_t irq_num, uint64_t param, struct pt_regs *regs)
|
||||
{
|
||||
sched_update_jiffies();
|
||||
}
|
Reference in New Issue
Block a user