Skip to content

Conversation

assembler-0
Copy link
Owner

@assembler-0 assembler-0 commented Aug 16, 2025

Summary by CodeRabbit

  • Refactor
    • Adjusted low-level scheduler loop behavior to improve compiler optimization and runtime predictability.
    • Replaced legacy memory barriers with standards-based fences in process termination paths for improved portability and clarity.
  • Style
    • Minor indentation cleanup with no functional impact.
  • Chores
    • No changes to public interfaces.
    • Internal updates may slightly improve performance and predictability under heavy load.

Copy link

coderabbitai bot commented Aug 16, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Changed IDE init local variable to const and removed the HLT after Yield() in KernelMainHigherHalf’s infinite loop. Replaced legacy __sync_synchronize() barriers with __atomic_thread_fence(__ATOMIC_SEQ_CST) in process termination paths. Minor formatting tweak in FindFreeSlotFast. No public APIs changed.

Changes

Cohort / File(s) Summary
Kernel core loop & init
kernel/core/Kernel.c
Made ide_result a const int during IDE init; removed the hlt instruction previously executed after Yield() in KernelMainHigherHalf’s infinite loop.
Process termination & sync
kernel/process/Process.c
Replaced __sync_synchronize() with __atomic_thread_fence(__ATOMIC_SEQ_CST) in AddToTerminationQueueAtomic and TerminateProcess; indentation/formatting tweak in FindFreeSlotFast.

Sequence Diagram(s)

sequenceDiagram
  participant K as KernelMainHigherHalf
  participant S as Scheduler
  participant CPU

  loop infinite
    K->>S: Yield()
    S-->>K: (returns after context switch)
    Note over K: No HLT executed after return
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • Development #89 — Similar changes to KernelMainHigherHalf loop behavior and atomic barrier updates.
  • Development #25 — Modifies Kernel.c main loop HLT handling; closely related to the removed HLT.
  • pls kill me #36 — Introduces/adjusts atomic operations in termination paths; aligns with fence replacements here.

Poem

I nibble bytes beneath the moon,
Yielding time, I hum a tune.
Fences set, the queues align,
No halt between each hop of mine.
A tiny rabbit in kernel lair—joyful, soft, and aware. 🐇

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 16726ca and 08b5479.

📒 Files selected for processing (1)
  • kernel/core/Kernel.c (1 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch Development

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a 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

🔭 Outside diff range comments (2)
kernel/process/Process.c (2)

308-310: Fix ordering in ASTerminate(): enqueue happens before ZOMBIE — race with cleanup

This violates the documented ordering (set PROC_ZOMBIE, fence, then enqueue). As written, CleanupTerminatedProcesses can observe a non-zombie and skip cleanup permanently.

Apply this diff:

-    AddToTerminationQueueAtomic(slot);
-    proc->state = PROC_ZOMBIE;
+    proc->state = PROC_ZOMBIE;
+    __atomic_thread_fence(__ATOMIC_SEQ_CST);
+    AddToTerminationQueueAtomic(slot);

1164-1173: GetProcessByPid leaks the read lock on success path

The early return exits without ReadUnlock, which can deadlock future readers/writers. Unlock before returning the result.

Apply this refactor:

-Process* GetProcessByPid(uint32_t pid) {
-    ReadLock(&process_table_rwlock);
-    for (int i = 0; i < MAX_PROCESSES; i++) {
-        if (processes[i].pid == pid && processes[i].state != PROC_TERMINATED) {
-            return &processes[i];
-        }
-    }
-    ReadUnlock(&process_table_rwlock);
-    return NULL;
-}
+Process* GetProcessByPid(uint32_t pid) {
+    ReadLock(&process_table_rwlock);
+    Process* result = NULL;
+    for (int i = 0; i < MAX_PROCESSES; i++) {
+        if (processes[i].pid == pid && processes[i].state != PROC_TERMINATED) {
+            result = &processes[i];
+            break;
+        }
+    }
+    ReadUnlock(&process_table_rwlock);
+    return result;
+}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between aa5e116 and 16726ca.

📒 Files selected for processing (2)
  • kernel/core/Kernel.c (1 hunks)
  • kernel/process/Process.c (3 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: assembler-0
PR: assembler-0/VoidFrame#82
File: kernel/process/Process.h:0-0
Timestamp: 2025-08-14T02:11:27.395Z
Learning: In VoidFrame kernel, FastMemcpy was using SSE2 movdqu instructions without preserving XMM registers, causing crashes when called from interrupt context (like the scheduler's FastSchedule function). The fix is to use only general-purpose registers with 64-bit unrolled copies to maintain performance while being interrupt-safe.
Learnt from: assembler-0
PR: assembler-0/VoidFrame#82
File: kernel/process/Process.h:0-0
Timestamp: 2025-08-14T02:11:58.963Z
Learning: In VoidFrame kernel's FastMemcpy implementation (kernel/memory/MemOps.c), memory corruption occurs under high load due to interrupts occurring between SSE2 movdqu load and store instructions, corrupting XMM register state. The fix requires disabling interrupts around SSE operations and adding memory barriers (sfence) to ensure stores complete atomically.
📚 Learning: 2025-08-11T07:18:24.614Z
Learnt from: assembler-0
PR: assembler-0/VoidFrame#69
File: kernel/etc/Shell.c:82-86
Timestamp: 2025-08-11T07:18:24.614Z
Learning: The order of operations in VoidFrame's `TerminateProcess()` is critical: the process state must be set to PROC_ZOMBIE before adding to the termination queue with a memory barrier between them, otherwise CleanupTerminatedProcesses may process the entry before the zombie state is set.

Applied to files:

  • kernel/process/Process.c
📚 Learning: 2025-08-10T08:52:13.313Z
Learnt from: assembler-0
PR: assembler-0/VoidFrame#63
File: kernel/etc/Shell.c:24-28
Timestamp: 2025-08-10T08:52:13.313Z
Learning: In VoidFrame's Process.c, PIDs are allocated using `__sync_fetch_and_add(&next_pid, 1)` which only increments and never reuses freed PIDs, causing PID exhaustion after MAX_PROCESSES terminations.

Applied to files:

  • kernel/process/Process.c
🔇 Additional comments (3)
kernel/process/Process.c (3)

96-112: LGTM: indentation tweak; logic remains correct

The sentinel check against ~1ULL (ignoring slot 0) is consistent with the “up to 64 processes” bitmap design and the subsequent FastFFS flow.


128-132: Switch to __atomic_thread_fence(__ATOMIC_SEQ_CST) is correct here

Maintains the full barrier semantics after publishing the queue entry, before advancing tail. Matches the intent better than legacy __sync_synchronize.


260-263: Correct barrier placement after PROC_ZOMBIE is set

Marking the process ZOMBIE and then issuing a full fence before enqueuing prevents CleanupTerminatedProcesses from observing a non-zombie state. This preserves the required ordering.

@assembler-0 assembler-0 merged commit 1537513 into main Aug 16, 2025
1 check was pending
@coderabbitai coderabbitai bot mentioned this pull request Aug 23, 2025
This was referenced Aug 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant