Created by: Alic3r3L1cwhk
This pull request introduces two major improvements: dynamic boot hart support for SMP systems and a fix for console output corruption in multi-core scenarios. The changes enable the kernel to correctly identify and initialize the boot hart regardless of its ID, supporting both SMP=2 and SMP=4 configurations, and add a lock to ensure SMP-safe console output. Additionally, more detailed debug logging is added to process/task management for easier tracing of process lifecycle events.
Dynamic boot hart support:
- Refactored the kernel entry and initialization flow to support any boot hart ID, not just hart 0. This includes splitting the entry into separate
rust_main_bootandrust_main_secondaryfunctions, adding a_start_secondaryentry inentry.asm, and passing the boot hart ID through initialization routines. (os/src/main.rs,os/src/cpu/mod.rs,os/src/entry.asm) [1] [2] [3] [4] - Added a
BOOT_HART_IDstatic variable and updated the hart startup logic to skip the boot hart and correctly start secondary harts using the new entry point. (os/src/cpu/mod.rs,os/src/entry.asm) [1] [2] [3] - Updated documentation and planning notes to describe the new dual-entry design and summarize test results for both SMP=2 and SMP=4. (
plans/phase-f-dynamic-boot-hart.md)
Console output SMP safety:
- Added a
spin::Mutexlock to theprint()function inconsole.rsto prevent interleaved output and corruption when multiple harts print concurrently. (os/src/console.rs) [1] [2]
Debug logging improvements:
- Added detailed debug logs in process/task management to trace waitpid, exit, and wait queue events, aiding in debugging process lifecycle and synchronization issues. (
os/src/syscall/process.rs,os/src/task/mod.rs) [1] [2] [3] [4] [5]
These changes together ensure robust multi-core boot and operation, and improve observability and correctness in SMP environments.