bugfix: 修复多核启动时,自旋锁持有计数错误的问题

This commit is contained in:
fslongjin
2022-06-09 16:27:55 +08:00
parent 8f180254bc
commit 9322d8ab20
3 changed files with 10 additions and 8 deletions

View File

@ -9,7 +9,7 @@
#define preempt_disable() \
do \
{ \
--(current_pcb->preempt_count);\
++(current_pcb->preempt_count);\
} while (0)
/**
@ -19,5 +19,5 @@ do \
#define preempt_enable() \
do \
{ \
++(current_pcb->preempt_count);\
--(current_pcb->preempt_count);\
}while(0)

View File

@ -152,15 +152,15 @@ union proc_union
{ \
.state = PROC_UNINTERRUPTIBLE, \
.flags = PF_KTHREAD, \
.preempt_count = 0, \
.signal = 0, \
.cpu_id = 0, \
.mm = &initial_mm, \
.thread = &initial_thread, \
.addr_limit = 0xffffffffffffffff, \
.pid = 0, \
.virtual_runtime = 0, \
.signal = 0, \
.priority = 2, \
.preempt_count = 0, \
.cpu_id = 0, \
.virtual_runtime = 0, \
.fds = {0}, \
.next_pcb = &proc, \
.parent_pcb = &proc, \

View File

@ -55,6 +55,7 @@ void smp_init()
continue;
spin_lock(&multi_core_starting_lock);
preempt_enable(); // 由于ap处理器的pcb与bsp的不同因此ap处理器放锁时bsp的自旋锁持有计数不会发生改变,需要手动恢复preempt count
current_starting_cpu = proc_local_apic_structs[i]->local_apic_id;
kdebug("[core %d] acpi processor UID=%d, APIC ID=%d, flags=%#010lx", i, proc_local_apic_structs[i]->ACPI_Processor_UID, proc_local_apic_structs[i]->local_apic_id, proc_local_apic_structs[i]->flags);
@ -95,7 +96,7 @@ void smp_init()
{
*(ul *)(phys_2_virt(global_CR3) + i) = 0UL;
}
kdebug("init proc's preempt_count=%ld", current_pcb->preempt_count);
kinfo("Successfully cleaned page table remapping!\n");
}
@ -147,10 +148,11 @@ void smp_ap_start()
initial_proc[proc_current_cpu_id] = current_pcb;
load_TR(10 + current_starting_cpu * 2);
current_pcb->preempt_count = 0;
// kdebug("IDT_addr = %#018lx", phys_2_virt(IDT_Table));
spin_unlock(&multi_core_starting_lock);
current_pcb->preempt_count = 0;
preempt_disable();// 由于ap处理器的pcb与bsp的不同因此ap处理器放锁时需要手动恢复preempt count
sti();
while (1)