Scheduling Subsystem Refactored; Task Management Refactored; Percpu Refactored; Misc; Bugs Fixed#76
Scheduling Subsystem Refactored; Task Management Refactored; Percpu Refactored; Misc; Bugs Fixed#76
Conversation
There was a problem hiding this comment.
Pull request overview
Large-scale refactor across the kernel’s scheduling/task/percpu subsystems and related syscall/arch glue, plus updates to host tooling for rootfs image generation (libguestfs/virt-make-fs with optional sudo) and various config tweaks.
Changes:
- Reworks scheduler core into per-CPU processor state + scheduler classes, adds event-based wait primitive, and updates task APIs/syscalls accordingly (clone/exit/wait4/yield, etc.).
- Refactors percpu/preemption/interrupt interactions and updates arch context-switch + trap return interfaces for riscv64/loongarch64.
- Updates xtask rootfs mkfs to use virt-make-fs (optionally via sudo) and adjusts devcontainer/Docker dependencies for libguestfs.
Reviewed changes
Copilot reviewed 138 out of 139 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| scripts/xtask/src/tasks/rootfs/mkfs.rs | Adds --sudo flag, adjusts mkfs call signature, skips lost+found at root. |
| scripts/xtask/src/config/build.rs | Switches ext4 image build to virt-make-fs, adds sudo path + chmod, adds root detection helper. |
| conf/platforms/qemu-virt-rv64.toml | Comment formatting/whitespace tweaks in QEMU args. |
| conf/platforms/qemu-virt-rv64.dts | ranges formatting/indentation adjustments. |
| conf/platforms/qemu-virt-la64.toml | Enables -no-reboot and whitespace cleanup. |
| conf/arch/riscv64/kernel.lds.in | Increases RAM/VIRT region length to 100M. |
| conf/arch/loongarch64/kernel.lds.in | Increases RAM/VIRT region length to 100M. |
| conf/.defconfig | Raises max_processes default significantly. |
| anemone-rs/src/os/linux.rs | Fixes clone SIGCHLD constant mapping. |
| anemone-kernel/src/utils/mod.rs | Exposes new cacheline utility module. |
| anemone-kernel/src/utils/cacheline.rs | Adds cacheline constants + CachePadded<T> for supported archs. |
| anemone-kernel/src/time/timekeeper.rs | Uses prelude cur_cpu_id/bsp_cpu_id helpers. |
| anemone-kernel/src/time/api/times.rs | Switches to get_current_task() access pattern. |
| anemone-kernel/src/time/api/nanosleep.rs | Uses yield_now() instead of kernel_yield(). |
| anemone-kernel/src/time/api/gettimeofday.rs | Minor Option binding cleanup (mut removed). |
| anemone-kernel/src/task/wait.rs | Removes old wait-queue implementation. |
| anemone-kernel/src/task/tid.rs | Replaces ad-hoc TID allocator with idalloc, adds constants and dealloc-on-drop. |
| anemone-kernel/src/task/sched.rs | Adds task scheduling/status accessor helpers. |
| anemone-kernel/src/task/mod.rs | Major task struct/status refactor; integrates sched entity, events, flags, hierarchy definitions. |
| anemone-kernel/src/task/files.rs | Simplifies Fd syscall arg parsing; removes unsafe open_fd_at. |
| anemone-kernel/src/task/cpu_usage.rs | Moves Privilege enum here; adds #[track_caller] on settle. |
| anemone-kernel/src/task/api/wait4.rs | Reimplements wait4 around Event + scanning/reaping flow; adds option parsing via syscall_arg_flag32. |
| anemone-kernel/src/task/api/set_tid_address.rs | Switches to get_current_task() access pattern. |
| anemone-kernel/src/task/api/mod.rs | Adds new exit module, minor TODO. |
| anemone-kernel/src/task/api/getppid.rs | Switches to get_current_task() access pattern. |
| anemone-kernel/src/task/api/exit/mod.rs | Introduces new exit subsystem module + kernel_exit implementation. |
| anemone-kernel/src/task/api/exit/exit_group.rs | Adds SYS_EXIT_GROUP handler (temporary NYI). |
| anemone-kernel/src/task/api/exit/exit.rs | Adds SYS_EXIT handler delegating to kernel_exit. |
| anemone-kernel/src/task/api/execve/kernel.rs | Refactors exec path to new task exec switching API; updates privilege accounting. |
| anemone-kernel/src/task/api/execve/binfmt/shebang.rs | Uses get_current_task() for global path building. |
| anemone-kernel/src/task/api/execve/binfmt/mod.rs | Uses get_current_task() for global path building. |
| anemone-kernel/src/task/api/execve/binfmt/elf/parse.rs | Removes unnecessary mut bindings in unsafe slice construction. |
| anemone-kernel/src/task/api/clone/mod.rs | Introduces new clone subsystem + flags/stack parsing + kernel_clone implementation. |
| anemone-kernel/src/task/api/clone/clone3.rs | Placeholder for clone3. |
| anemone-kernel/src/task/api/clone/clone.rs | Adds SYS_CLONE handler with preparse tracer hook, uses new clone types. |
| anemone-kernel/src/task/api/clone.rs | Removes old clone implementation. |
| anemone-kernel/src/syserror.rs | Renames ChildrenNotFound to ChildNotFound and updates errno mapping. |
| anemone-kernel/src/syscall/mod.rs | Removes unused mut on handler pointer. |
| anemone-kernel/src/syscall/handler.rs | Adds syscall_arg_flag32 helper; removes VirtAddr TryFromSyscallArg impl. |
| anemone-kernel/src/syscall/dt.rs | Replaces with_current_task usage with get_current_task; removes some unnecessary mut; refactors C-string scanning structure. |
| anemone-kernel/src/sync/spinlock.rs | Updates IRQ-save locking to new IntrGuard::new() signature. |
| anemone-kernel/src/sync/rwlock.rs | Updates IRQ-save locking to new IntrGuard::new() signature. |
| anemone-kernel/src/sync/mono.rs | Marks MonoFlow<T> as Send (in addition to Sync). |
| anemone-kernel/src/sync/mod.rs | Adds intrlock module stub, module-level TODOs. |
| anemone-kernel/src/sync/intrlock.rs | Adds placeholder module/docs. |
| anemone-kernel/src/sync/counter.rs | Uses prelude ncpus() helper. |
| anemone-kernel/src/sched/switch.rs | Adds arch-agnostic context switch + mapping switch primitives. |
| anemone-kernel/src/sched/rr.rs | Removes old RR scheduler. |
| anemone-kernel/src/sched/processor.rs | Adds new per-CPU scheduler state + enqueue/pick/tick/need_resched APIs + IPI wake integration. |
| anemone-kernel/src/sched/proc.rs | Removes old processor/scheduler implementation. |
| anemone-kernel/src/sched/mod.rs | Rebuilds scheduler module: core loop, schedule/try_to_wake_up, yield_now, Event export, class wiring. |
| anemone-kernel/src/sched/idle.rs | Removes old idle-task implementation. |
| anemone-kernel/src/sched/hal.rs | Simplifies HAL traits, updates TaskContextArch constructor signature. |
| anemone-kernel/src/sched/event.rs | Adds Event primitive (publish/listen) used as wait-queue replacement. |
| anemone-kernel/src/sched/class/rr.rs | Adds RR scheduler class implementation. |
| anemone-kernel/src/sched/class/mod.rs | Adds scheduler class trait, run queue, sched entity definition. |
| anemone-kernel/src/sched/class/idle.rs | Adds idle scheduler class and per-CPU idle task allocation. |
| anemone-kernel/src/sched/api/sched_yield.rs | Adds SYS_SCHED_YIELD handler calling yield_now(). |
| anemone-kernel/src/sched/api/mod.rs | Removes old sched API bundle; now only exports sched_yield module. |
| anemone-kernel/src/prelude.rs | Updates prelude exports (percpu helpers moved out of mm::percpu). |
| anemone-kernel/src/panic.rs | Makes PANIC_OCCURRED private; uses prelude cur_cpu_id(). |
| anemone-kernel/src/mm/uspace/mod.rs | Adds TLB shootdown on edits via IPI; wraps mutating ops to shoot down; tweaks comments and injection helper. |
| anemone-kernel/src/mm/uspace/mmap.rs | Minor test cleanup (remove unused var). |
| anemone-kernel/src/mm/uspace/fault.rs | Switches to get_current_task() and new UserSpace APIs for page-fault handling. |
| anemone-kernel/src/mm/uspace/api/munmap.rs | Uses new UserSpace::unmap wrapper (with shootdown). |
| anemone-kernel/src/mm/uspace/api/mprotect.rs | Uses new UserSpace::protect_range wrapper (with shootdown). |
| anemone-kernel/src/mm/uspace/api/mod.rs | Uses syscall_arg_flag32 for prot/flags; simplifies fd conversion. |
| anemone-kernel/src/mm/uspace/api/mmap.rs | Uses new UserSpace::{map_anonymous,map_file} wrappers (with shootdown); switches to get_current_task(). |
| anemone-kernel/src/mm/uspace/api/madvise.rs | Renames handler function to sys_madvise. |
| anemone-kernel/src/mm/uspace/api/brk.rs | Refactors brk to use new UserSpace::set_brk wrapper (with shootdown). |
| anemone-kernel/src/mm/remap.rs | Removes unused len() helper. |
| anemone-kernel/src/mm/percpu.rs | Removes old percpu implementation (moved to percpu module). |
| anemone-kernel/src/mm/paging/pagetable.rs | Removes unused local var in Drop. |
| anemone-kernel/src/mm/paging/mapper.rs | Simplifies unsafe blocks; comment formatting adjustments. |
| anemone-kernel/src/mm/mod.rs | Drops mm::percpu module export. |
| anemone-kernel/src/mm/kptable.rs | Removes unused counter/logging in preallocation loop. |
| anemone-kernel/src/main.rs | Adds new percpu module; updates init code to use get_current_task(); documents kinit interrupt invariants. |
| anemone-kernel/src/fs/pipe.rs | Uses yield_now() for pipe wait loops. |
| anemone-kernel/src/fs/api/writev.rs | Refactors to single get_current_task() fetch for file+uspace. |
| anemone-kernel/src/fs/api/write.rs | Refactors to single get_current_task() fetch for file+uspace. |
| anemone-kernel/src/fs/api/unlinkat.rs | Uses syscall_arg_flag32; switches to get_current_task() for global paths. |
| anemone-kernel/src/fs/api/stat/mod.rs | Uses syscall_arg_flag32 for stat flags parsing. |
| anemone-kernel/src/fs/api/read.rs | Refactors to single get_current_task() fetch for file+uspace. |
| anemone-kernel/src/fs/api/pipe2.rs | Uses syscall_arg_flag32; switches to get_current_task(). |
| anemone-kernel/src/fs/api/openat.rs | Refactors to reuse task handle; avoids closure for fd open. |
| anemone-kernel/src/fs/api/mod.rs | Uses syscall_arg_flag32; refactors AtFd parsing and path resolution to use get_current_task(). |
| anemone-kernel/src/fs/api/mkdirat.rs | Switches to get_current_task() for global paths. |
| anemone-kernel/src/fs/api/getdents64.rs | Refactors to single get_current_task() fetch; minor mut cleanup. |
| anemone-kernel/src/fs/api/getcwd.rs | Switches to get_current_task(). |
| anemone-kernel/src/fs/api/dup3.rs | Uses syscall_arg_flag32; switches to get_current_task(). |
| anemone-kernel/src/fs/api/dup.rs | Switches to get_current_task(). |
| anemone-kernel/src/fs/api/close.rs | Switches to get_current_task(). |
| anemone-kernel/src/fs/api/chroot.rs | Switches to get_current_task(); flattens control flow. |
| anemone-kernel/src/fs/api/chdir.rs | Switches to get_current_task(); flattens control flow. |
| anemone-kernel/src/fs/api/access/mod.rs | Uses syscall_arg_flag32 for access flags/mode parsing. |
| anemone-kernel/src/exception/trap/hal.rs | Extends trap arch trait with load_utrapframe and additional trapframe setters. |
| anemone-kernel/src/exception/timer.rs | Uses local_sched_tick() instead of immediate try_schedule path. |
| anemone-kernel/src/exception/preempt_counter.rs | Removes old preempt-counter implementation (moved/refactored into percpu). |
| anemone-kernel/src/exception/page_fault.rs | Uses prelude cur_cpu_id(). |
| anemone-kernel/src/exception/mod.rs | Removes exports of old PreemptCounter/PreemptGuard. |
| anemone-kernel/src/exception/ipi.rs | Adds WakeUpTask IPI payload; uses new scheduler enqueue + need_resched integration; updates cpu id helpers. |
| anemone-kernel/src/exception/intr/scoped.rs | Simplifies IntrGuard API; changes with_intr_disabled signature. |
| anemone-kernel/src/exception/intr/hal.rs | Adds local_intr_enabled/disabled helpers on IntrArchTrait. |
| anemone-kernel/src/driver/intc/sifive_plic.rs | Uses prelude ncpus()/cur_cpu_id() helpers. |
| anemone-kernel/src/device/cpu.rs | Removes bsp/ncpus/cur_cpu_id requirements from CpuArchTrait. |
| anemone-kernel/src/debug/kunit.rs | Adjusts interrupt enable/disable handling after IntrGuard API change. |
| anemone-kernel/src/arch/riscv64/utils.rs | Removes old Privilege <-> SPP conversions (Privilege moved). |
| anemone-kernel/src/arch/riscv64/sched.rs | Reworks task entry/guard paths; aligns with new trapframe APIs; removes return_to_cloned_task. |
| anemone-kernel/src/arch/riscv64/mod.rs | Reorders exports; removes utils module. |
| anemone-kernel/src/arch/riscv64/exception/trap/utrap.rs | Updates utrap entry/return handling; uses new sscratch preservation; integrates need_resched scheduling after IRQ. |
| anemone-kernel/src/arch/riscv64/exception/trap/mod.rs | Adds trapframe fields + init helpers; implements TrapArchTrait::load_utrapframe; adds arg/scratch setters. |
| anemone-kernel/src/arch/riscv64/exception/trap/ktrap.rs | Integrates need_resched scheduling after IRQ; hooks percpu hwirq enter/leave. |
| anemone-kernel/src/arch/riscv64/cpu.rs | Removes per-arch cpu-id/ncpu tracking from CpuArchTrait impl. |
| anemone-kernel/src/arch/riscv64/bootstrap.rs | Updates bootstrap to new percpu init signature and scheduler/task registration flow. |
| anemone-kernel/src/arch/loongarch64/utils.rs | Removes old Privilege conversion helpers (Privilege moved). |
| anemone-kernel/src/arch/loongarch64/time.rs | Uses prelude cur_cpu_id() helper. |
| anemone-kernel/src/arch/loongarch64/sched.rs | Reworks task entry/guard paths; aligns with new trapframe APIs; removes return_to_cloned_task. |
| anemone-kernel/src/arch/loongarch64/mod.rs | Reorders modules/exports; removes utils module. |
| anemone-kernel/src/arch/loongarch64/exception/trap/utrap.rs | Updates utrap entry/return handling; preserves save0; integrates need_resched scheduling after IRQ. |
| anemone-kernel/src/arch/loongarch64/exception/trap/mod.rs | Adds trapframe fields + init helpers; implements TrapArchTrait::load_utrapframe; adds arg/scratch setters. |
| anemone-kernel/src/arch/loongarch64/exception/trap/ktrap.rs | Integrates need_resched scheduling after IRQ; hooks percpu hwirq enter/leave. |
| anemone-kernel/src/arch/loongarch64/exception/intr.rs | Uses prelude cur_cpu_id() helper in logs. |
| anemone-kernel/src/arch/loongarch64/cpu.rs | Removes per-arch cpu-id/ncpu tracking from CpuArchTrait impl. |
| anemone-kernel/src/arch/loongarch64/bootstrap.rs | Updates bootstrap to new percpu init signature and scheduler/task registration flow. |
| anemone-kernel/crates/kernel-macros/src/syscall.rs | Extends #[syscall] macro to accept preparse = ... hook and call it with raw regs args. |
| anemone-kernel/crates/kernel-macros/src/percpu.rs | Updates percpu macro output to reference crate::percpu::PerCpu. |
| anemone-kernel/crates/kernel-macros/src/lib.rs | Documents new preparse syscall hook in macro docs. |
| anemone-kernel/crates/idalloc/src/lib.rs | Makes allocator constructor const fn. |
| anemone-kernel/Cargo.toml | Moves wavltree and loongArch64 to workspace deps and formatting cleanup. |
| anemone-abi/src/syscall/riscv.rs | Adds SYS_CLONE3 constant. |
| anemone-abi/src/syscall/loongarch.rs | Adds SYS_CLONE3 constant. |
| anemone-abi/src/process.rs | Renames SIGCHLD constant to CLONE_SIGCHLD; adds CloneArgs struct; adjusts wait flag types/constants. |
| Dockerfile | Adds libguestfs-tools/linux-image-kvm/sudo packages (for rootfs building). |
| Cargo.toml | Adds workspace deps for loongArch64/wavltree; reorganizes proc-macro deps placement. |
| .vscode/settings.json | Adjusts rust-analyzer features/linkedProjects defaults. |
| .devcontainer/devcontainer.json | Adds host networking options and runArgs; minor mounts formatting. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| ) -> Result<(), SysError> { | ||
| let fault_info = PageFaultInfo::new(VirtAddr::new(0), fault_addr, fault_type); | ||
| let fault_info = PageFaultInfo::new(VirtAddr::new(42), fault_addr, fault_type); | ||
| self.handle_page_fault(&fault_info) |
There was a problem hiding this comment.
inject_page_fault hard-codes the fault PC as VirtAddr::new(42), which is an unexplained magic value and will leak into diagnostics/logging. Use a well-defined sentinel (e.g., 0) or pass through a meaningful PC if available, and document the choice.
| /// **Do not call this method unless you are those observers and your work | ||
| /// dosn't rely on the accuracy of the status, or you can ensure that you | ||
| /// just need a single read.** |
There was a problem hiding this comment.
Typo in doc comment: "dosn't" should be "doesn't".
| /// Since [UserSpace] can be shared on multiple cores, so tlb shootdown must be | ||
| /// performed when doing edition. |
There was a problem hiding this comment.
Grammar in comment is off: "Since [UserSpace] can be shared on multiple cores, so ... when doing edition" is hard to read. Consider rephrasing to something like "Because UserSpace may be shared across cores, TLB shootdown must be performed when editing it."
| fn sys_exit_group(exit_code: i8) -> Result<u64, SysError> { | ||
| knoticeln!("[NYI] exit_group: exit_code={}", exit_code); | ||
| exit::kernel_exit(exit_code) | ||
| } |
There was a problem hiding this comment.
exit::kernel_exit(...) likely doesn’t resolve in this module (there’s no in-scope exit module with kernel_exit). Call the intended function via super::kernel_exit(...) or crate::task::exit::kernel_exit(...) (or import it explicitly).
| // TODO: consider again. Currently this impl only serves to allow the utrapframe | ||
| // pointer to be stored in tcb, which is safe. but for such a narrow use case, | ||
| // maybe we shouldn't make MonoFlow itself Send as well, but handle that case | ||
| // separately. | ||
| unsafe impl<T> Send for MonoFlow<T> {} |
There was a problem hiding this comment.
unsafe impl<T> Send for MonoFlow<T> is unsound for non-Send T and can allow moving thread-affine types across CPUs/threads without synchronization. This should almost certainly be unsafe impl<T: Send> Send for MonoFlow<T> (or removed and handled at the specific call site that needs it).
72eb5eb to
bc7489b
Compare
AI Usage