-
Notifications
You must be signed in to change notification settings - Fork 1
Development #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Development #31
Conversation
WalkthroughThe changes introduce a deferred process termination system by adding new process states and a termination queue. Scheduler and process management logic are updated to handle dying and zombie processes, defer cleanup, and unify termination handling. New metadata fields and enums are added to track termination reasons and process hierarchy. Changes
Sequence Diagram(s)sequenceDiagram
participant Process
participant Scheduler
participant TerminationQueue
participant Cleanup
Process->>Scheduler: Calls TerminateProcess(pid, reason, code)
Scheduler->>TerminationQueue: Enqueue process as DYING
Scheduler->>Process: Mark as DYING, remove from scheduling
Note right of Scheduler: Process state transitions to ZOMBIE
loop On schedule
Scheduler->>TerminationQueue: Check for ZOMBIE/TERMINATED processes
TerminationQueue->>Cleanup: Dequeue and clean up process
Cleanup->>Process: Free resources, reset struct, free slot
end
Possibly related PRs
Poem
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (2)
Kernel/Process/Process.h (1)
63-66
: Good additions for process lifecycle tracking.The termination metadata fields are well-chosen. Note that
parent_pid
appears to be unused in the current implementation - consider documenting its intended future use or removing it if not needed.Kernel/Process/Process.c (1)
54-93
: Well-implemented deferred termination mechanism.The function properly handles all termination scenarios including the currently running process. Line 76 has an outdated comment that can be removed since
GetSystemTicks()
is already implemented.- proc->termination_time = GetSystemTicks(); // You'll need to implement this + proc->termination_time = GetSystemTicks();
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
Kernel/Core/Kernel.c
(0 hunks)Kernel/Process/Process.c
(6 hunks)Kernel/Process/Process.h
(3 hunks)
💤 Files with no reviewable changes (1)
- Kernel/Core/Kernel.c
🔇 Additional comments (8)
Kernel/Process/Process.h (3)
31-33
: LGTM! Well-structured process state additions.The new PROC_ZOMBIE and PROC_DYING states properly support deferred cleanup and prevent race conditions during termination.
36-42
: Well-designed termination reason enumeration.The enum provides good coverage of termination scenarios and will help with debugging and logging process lifecycle events.
116-117
: Function declarations match implementation.The new functions are properly declared and align with the deferred termination design.
Kernel/Process/Process.c (5)
355-391
: Excellent handling of dying processes in the scheduler.The scheduler properly skips context saving for terminated processes and ensures they're not rescheduled. This prevents potential crashes from accessing invalid process state.
407-415
: Good defensive programming with state verification.Verifying the process state before scheduling prevents race conditions where a process might have been terminated between dequeuing and scheduling.
545-559
: Properly integrated with the new termination system.Using
TerminateProcess
ensures consistent cleanup and the infinite halt loop provides a good safeguard.
644-688
: Excellent batched cleanup implementation.The limited cleanup per call (3 processes) prevents interrupt latency issues while ensuring eventual cleanup of all terminated processes. The deferred cleanup via termination queue is much more efficient than scanning all processes.
732-754
: Security subsystem properly integrated with termination system.The state checks prevent unnecessary validation of terminated processes, and using
TerminateProcess
ensures proper cleanup of security violations.
static void AddToTerminationQueue(uint32_t slot) { | ||
if (term_queue_count >= MAX_PROCESSES) return; | ||
|
||
termination_queue[term_queue_tail] = slot; | ||
term_queue_tail = (term_queue_tail + 1) % MAX_PROCESSES; | ||
term_queue_count++; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential issue: Silent failure when termination queue is full.
The function silently returns when the queue is full, which could lead to zombie processes that never get cleaned up.
Consider logging an error or panic when the queue is full:
static void AddToTerminationQueue(uint32_t slot) {
- if (term_queue_count >= MAX_PROCESSES) return;
+ if (term_queue_count >= MAX_PROCESSES) {
+ PrintKernelError("[KERNEL] Termination queue full! Cannot add slot ");
+ PrintKernelInt(slot);
+ PrintKernelError("\n");
+ Panic("Termination queue overflow");
+ }
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
static void AddToTerminationQueue(uint32_t slot) { | |
if (term_queue_count >= MAX_PROCESSES) return; | |
termination_queue[term_queue_tail] = slot; | |
term_queue_tail = (term_queue_tail + 1) % MAX_PROCESSES; | |
term_queue_count++; | |
} | |
static void AddToTerminationQueue(uint32_t slot) { | |
if (term_queue_count >= MAX_PROCESSES) { | |
PrintKernelError("[KERNEL] Termination queue full! Cannot add slot "); | |
PrintKernelInt(slot); | |
PrintKernelError("\n"); | |
Panic("Termination queue overflow"); | |
} | |
termination_queue[term_queue_tail] = slot; | |
term_queue_tail = (term_queue_tail + 1) % MAX_PROCESSES; | |
term_queue_count++; | |
} |
🤖 Prompt for AI Agents
In Kernel/Process/Process.c around lines 36 to 42, the AddToTerminationQueue
function silently returns when the termination queue is full, risking zombie
processes. Modify the function to log an error or trigger a panic when
term_queue_count reaches MAX_PROCESSES, ensuring that this critical condition is
noticed and handled appropriately.
Summary by CodeRabbit
New Features
Improvements