Skip to content
This repository was archived by the owner on Jan 4, 2026. It is now read-only.

Conversation

@assembler-0
Copy link
Owner

@assembler-0 assembler-0 commented Oct 26, 2025

silent build and apic SMP awareness

Summary by CodeRabbit

  • Chores

    • Reduced build verbosity and suppressed noisy assembler/Rust warnings for cleaner compile output.
    • Added build integration improvements for Rust components.
  • Refactor

    • Converted APIC/timer and TSC code to per-CPU data for more consistent multi-CPU behavior.
    • Centralized APIC access and timer management.
  • Bug Fixes

    • Simplified interrupt entry paths and improved timer calibration with a safer fallback when APIC timing is unavailable.

@coderabbitai
Copy link

coderabbitai bot commented Oct 26, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This pull request centralizes APIC state into a PerCpuData structure and exposes a GetPerCpuData() accessor plus new APIC/PIC and timer APIs. TSC calibration and APIC/timer code now use per-CPU fields. The ISR_ERRCODE macro was removed. Build system changes silence rule messages, add SILENT_BUILD-controlled assembler warning flags and a Corrosion_CARGO_BUILD_FLAGS public variable, and integrate a corrosion subdirectory with Rust crate flags. A parsing alignment and RIP-relative directive were added in pxs.asm. No exported public type signatures were removed.

Poem

🐰 I hopped through code both near and far,
Moved APIC bits into each CPU jar,
The noisy build now whispers low,
Error-code macro—out it goes!
Tiny drum (TSC) ticks in its new row. 🎋

Pre-merge checks

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Title Check ❓ Inconclusive The pull request title is "Development," which is excessively vague and generic. This title does not convey any meaningful information about the actual changes in the pull request. The changeset includes significant modifications across multiple files: silent build improvements (CMake and flags configuration), SMP-aware APIC refactoring with per-CPU data structures, interrupt handling changes, and TSC calibration updates. However, the title provides no indication of any of these changes and could apply to virtually any development work, making it impossible for a teammate scanning history to understand what this PR accomplishes. The title should be updated to reflect the main objectives mentioned in the PR description: "Silent build and APIC SMP awareness" or a more descriptive variant like "Refactor APIC for per-CPU data and implement silent build mode" would clearly communicate the primary changes to reviewers and future readers.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 568b394 and b537e0e.

📒 Files selected for processing (3)
  • CMakeLists.txt (3 hunks)
  • arch/x86_64/asm/pxs.asm (6 hunks)
  • cmake/flags.cmake (1 hunks)

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

Comment @coderabbitai help to get the list of available commands and usage tips.

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: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
drivers/APIC/APIC.c (1)

194-247: Excellent calibration approach that addresses previous issues.

The dynamic APIC bus frequency calibration using PIT correctly measures the actual hardware frequency instead of assuming a hardcoded value. This directly addresses the high CPU usage issue from PR#131 where a hardcoded 100MHz assumption didn't match the actual hardware. The formula apic_bus_freq / frequency_hz (line 244) properly computes the initial count for the desired timer frequency.

Based on learnings from PR#131.


Optional: Consider named constants for calibration values.

Lines 236 and 239 use magic numbers that could be more readable as named constants:

+#define APIC_CALIBRATION_SCALE_FACTOR 100  // Scale 10ms measurement to 1 second
+#define APIC_FALLBACK_BUS_FREQ_HZ 100000000  // 100MHz fallback
+
 void ApicTimerSetFrequency(uint32_t frequency_hz) {

Then update the usage:

-            cpu_data->apic_bus_freq = ticks_per_10ms * 100;
+            cpu_data->apic_bus_freq = ticks_per_10ms * APIC_CALIBRATION_SCALE_FACTOR;
-            cpu_data->apic_bus_freq = 100000000; // Fallback: 100MHz
+            cpu_data->apic_bus_freq = APIC_FALLBACK_BUS_FREQ_HZ;
📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fbe93d7 and 568b394.

📒 Files selected for processing (6)
  • CMakeLists.txt (1 hunks)
  • arch/x86_64/interrupts/Interrupts.asm (0 hunks)
  • cmake/flags.cmake (1 hunks)
  • drivers/APIC/APIC.c (5 hunks)
  • drivers/APIC/APIC.h (1 hunks)
  • drivers/TSC.c (2 hunks)
💤 Files with no reviewable changes (1)
  • arch/x86_64/interrupts/Interrupts.asm
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-09-16T12:30:38.427Z
Learnt from: assembler-0
PR: assembler-0/VoidFrame#131
File: drivers/Apic.c:179-199
Timestamp: 2025-09-16T12:30:38.427Z
Learning: In the VoidFrame kernel APIC implementation in drivers/Apic.c, the hardcoded 100MHz APIC bus frequency assumption causes extremely high CPU usage. The user found that using frequency_hz directly as initial_count (instead of the complex calculation) provides the same smoothness with much lower CPU usage, indicating their system has a much slower APIC bus than assumed.

Applied to files:

  • drivers/APIC/APIC.c
  • drivers/TSC.c
🧬 Code graph analysis (3)
drivers/APIC/APIC.c (2)
kernel/etc/Console.c (2)
  • PrintKernelF (272-279)
  • PrintKernelWarning (239-244)
mm/VMem.c (1)
  • VMemMapMMIO (702-753)
drivers/TSC.c (1)
drivers/APIC/APIC.c (1)
  • GetPerCpuData (53-55)
drivers/APIC/APIC.h (1)
drivers/APIC/APIC.c (1)
  • GetPerCpuData (53-55)
🪛 Clang (14.0.6)
drivers/APIC/APIC.c

[warning] 44-44: variable 'g_bsp_per_cpu_data' is non-const and globally accessible, consider making it const

(cppcoreguidelines-avoid-non-const-global-variables)


[warning] 195-195: statement should be inside braces

(readability-braces-around-statements)


[warning] 236-236: 100 is a magic number; consider replacing it with a named constant

(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers)


[warning] 239-239: 100000000 is a magic number; consider replacing it with a named constant

(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers)

drivers/TSC.c

[warning] 6-6: variable 'tsc_freq_hz' is non-const and globally accessible, consider making it const

(cppcoreguidelines-avoid-non-const-global-variables)


[warning] 7-7: variable 'tsc_calibrated' is non-const and globally accessible, consider making it const

(cppcoreguidelines-avoid-non-const-global-variables)


[warning] 27-27: statement should be inside braces

(readability-braces-around-statements)

🪛 Gitleaks (8.28.0)
drivers/APIC/APIC.c

[high] 236-236: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

🔇 Additional comments (7)
cmake/flags.cmake (1)

8-8: Verify that suppressing all NASM warnings is intentional.

The -w-all flag suppresses ALL warnings from the NASM assembler, which could hide legitimate issues such as deprecated syntax, incorrect instruction usage, or potential bugs in assembly code. While this aligns with the silent build objective, ensure this trade-off is acceptable for your development workflow.

drivers/APIC/APIC.h (1)

7-46: LGTM! Well-designed per-CPU APIC API.

The PerCpuData structure and accessor function provide a clean foundation for SMP-aware APIC management. The public API comprehensively covers APIC/IOAPIC control and clearly documents the replacement of legacy PIC functions.

drivers/APIC/APIC.c (4)

43-55: Good incremental approach to per-CPU data.

The BSP-only per-CPU data instance with a clean accessor provides a solid foundation for future SMP expansion. The initialization values are safe, and the comment clearly documents the current limitation and future direction.


90-96: LGTM! Clean refactoring to per-CPU data.

The LAPIC accessor functions correctly use the per-CPU data structure instead of global state, maintaining the same logic while improving SMP readiness.


184-192: LGTM! Timer installation correctly uses per-CPU data.

The function properly stores the frequency in per-CPU data and delegates to ApicTimerSetFrequency() for calibration and setup.


260-290: LGTM! LAPIC setup correctly integrated with per-CPU data.

The LAPIC MMIO mapping and initialization properly stores the virtual base address in the per-CPU data structure. The mapping sequence (allocate, unmap, remap with MMIO flags) and error handling are appropriate.

drivers/TSC.c (1)

12-27: I need to verify that ApicTimerSetFrequency actually initializes apic_bus_freq. Let me search for its full implementation:Based on the verification results, I can now provide a definitive assessment. The initialization order shown in the kernel code is correct and resolves the concern raised in the original review comment.

Initialization order is correct—no action required.

The script output confirms that ApicTimerInstall(250) is called at line 602 of kernel/core/Kernel.c before TSCInit() is called at line 606. Since ApicTimerInstall immediately invokes ApicTimerSetFrequency synchronously, the APIC calibration will have completed before TSC calibration begins. This ensures that cpu_data->apic_bus_freq is properly initialized before being accessed by the TSC calibration code.

The concern about potential infinite loops or zero-value division in TSC.c (lines 23 and 26-27) is mitigated by the proper boot sequence.

if(SILENT_BUILD)
string(APPEND C_FLAGS " -w")
string(APPEND CMAKE_ASM_NASM_FLAGS " -w-all")
set(Corrosion_CARGO_BUILD_FLAGS "--quiet")
Copy link

@coderabbitai coderabbitai bot Oct 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

Verify the correct Corrosion variable name and scope.

The variable name Corrosion_CARGO_BUILD_FLAGS should be verified against the Corrosion documentation to ensure it follows the correct naming convention. Corrosion typically uses uppercase variable names (e.g., CORROSION_*). Additionally, if this is intended to be a "public" build flag as indicated in the summary, confirm whether it should be set as a cache variable or with PARENT_SCOPE.


🌐 Web query:

What is the correct variable name to set Cargo build flags in Corrosion CMake?

💡 Result:

Use Corrosion's built‑in options rather than a single global variable:

  • For import-time flags: pass FLAGS to corrosion_import_crate(... FLAGS ...). [1]
  • Per-target (recommended): call corrosion_set_cargo_flags(<target_name> ...). [2]

(Some projects expose their own cache variable like SLINT_LIBRARY_CARGO_FLAGS, but that is project-specific — not a Corrosion standard.) [1][2]

Sources:
[1] Corrosion usage / corrosion_import_crate.
[2] Corrosion usage / per-target options (corrosion_set_cargo_flags).


Remove non-standard variable; use Corrosion's documented API instead.

The variable Corrosion_CARGO_BUILD_FLAGS is not a standard Corrosion variable. Instead, use either the FLAGS parameter in corrosion_import_crate() for import-time flags or call corrosion_set_cargo_flags() for per-target flags. The current variable will not be recognized by Corrosion and has no effect.

🤖 Prompt for AI Agents
In cmake/flags.cmake around line 9, remove the non-standard
set(Corrosion_CARGO_BUILD_FLAGS "--quiet") line because Corrosion does not honor
that variable; instead, pass cargo flags via the documented API: add FLAGS
"--quiet" to the relevant corrosion_import_crate(...) call for import-time flags
or call corrosion_set_cargo_flags(<target> "--quiet") after creating the
Corrosion target for per-target flags. Ensure you delete the stray variable,
update the import or target creation sites to use FLAGS or
corrosion_set_cargo_flags() respectively, and re-run CMake to verify the flag is
applied.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so how do i make cargo actually shutup as this doesnt work?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Find all corrosion_import_crate calls
rg -n "corrosion_import_crate" -C 3

# Find all Corrosion-related function calls
rg -n "corrosion_" -C 2

# List all CMake files in the repository
fd -e cmake -e txt CMakeLists

Length of output: 67979


@assembler-0, to silence Cargo builds with Corrosion, you need to use the FLAGS parameter in your corrosion_import_crate() calls. The variable you're setting isn't a standard Corrosion variable.

Here's the fix:

In cmake/flags.cmake, remove the line:

set(Corrosion_CARGO_BUILD_FLAGS "--quiet")

In CMakeLists.txt, modify both corrosion_import_crate() calls to conditionally add the FLAGS parameter:

if(SILENT_BUILD)
    set(CARGO_QUIET_FLAG FLAGS "--quiet")
else()
    set(CARGO_QUIET_FLAG "")
endif()

corrosion_import_crate(
        MANIFEST_PATH ${RUST_HEAP_MANIFEST_PATH}
        NO_STD
        ${CARGO_QUIET_FLAG}
)
corrosion_import_crate(
        MANIFEST_PATH ${RUST_ATOMIC_MANIFEST_PATH}
        NO_STD
        ${CARGO_QUIET_FLAG}
)

This approach:

  1. Creates a variable containing FLAGS "--quiet" when SILENT_BUILD is enabled
  2. Expands it into the corrosion_import_crate() calls, which will add the --quiet flag to all Cargo invocations for those crates

The FLAGS parameter is documented in Corrosion and passes arguments directly to cargo build.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well that didnt help, there are still warnings-wait warnings, i think its -Awarnings right? so how to do that then and same for nasm, its not very silent

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧩 Analysis chain

🌐 Web query:

How to set RUSTFLAGS in Corrosion CMake to suppress warnings

💡 Result:

Use Corrosion's helper functions — either add rustc flags for the target or set the RUSTFLAGS env var for the target.

Examples (replace rust-target-name with your imported crate target):

  • Add flags that propagate to crate and its dependencies:
    corrosion_add_target_rustflags(rust-target-name "-A" "warnings")

  • Add flags that apply only to the crate (not its cargo-built dependencies):
    corrosion_add_target_local_rustflags(rust-target-name "-A" "warnings")

  • Set RUSTFLAGS explicitly as an environment variable for the target:
    corrosion_set_env_vars(rust-target-name RUSTFLAGS="-A warnings")

Notes:

  • Use -A to allow/suppress a lint, -W to warn, -D to deny. Example to suppress unused warnings: "-A" "dead_code".
  • corrosion_add_target_local_rustflags is useful to avoid rebuilding dependencies when switching flags.

Sources: Corrosion usage docs describing corrosion_add_target_rustflags / corrosion_add_target_local_rustflags / corrosion_set_env_vars. [1][2]

References
[1] Corrosion usage — per-target options (corrosion_add_target_rustflags, corrosion_add_target_local_rustflags, corrosion_set_env_vars).
[2] Corrosion advanced/usage pages.


🌐 Web query:

NASM assembler flags to suppress all warnings and messages

💡 Result:

Use NASM's -w and -s options.

  • Disable all warnings: -w-all (or -Wno-all).
  • Suppress non‑critical output (only critical errors remain): -s.

Example:
nasm -f elf -w-all -s source.asm -o out.o

Sources: NASM manual (warning classes / -w options) [1]; nasm man summary showing -s (silent) [2].


🏁 Script executed:

#!/bin/bash
# Find the Cargo.toml files for the Rust crates and extract the package names
echo "=== Rust crate names ==="
fd -e toml Cargo.toml --exec grep -H "^name = " {}

Length of output: 135


@assembler-0, yes, -A warnings is the correct Rust flag! Here's how to properly silence both Cargo and NASM:

For Rust warnings, add these lines in CMakeLists.txt right after your corrosion_import_crate() calls:

if(SILENT_BUILD)
    corrosion_add_target_rustflags(voidframe-mm "-A" "warnings")
    corrosion_add_target_rustflags(voidframe-spinlock "-A" "warnings")
endif()

This passes -A warnings to rustc, which suppresses all compiler warnings.

For NASM, modify the line in cmake/flags.cmake to add the -s (silent) flag:

if(SILENT_BUILD)
    string(APPEND C_FLAGS " -w")
    string(APPEND CMAKE_ASM_NASM_FLAGS " -w-all -s")
    # Remove the Corrosion_CARGO_BUILD_FLAGS line - it doesn't work
endif()

The -s flag tells NASM to suppress all non-critical output, so combined with -w-all (disable all warnings), NASM will be completely silent.

Summary of changes:

  1. Remove the set(Corrosion_CARGO_BUILD_FLAGS "--quiet") line from cmake/flags.cmake
  2. Add -s to the NASM flags in cmake/flags.cmake
  3. Add the corrosion_add_target_rustflags() calls in CMakeLists.txt after importing the crates

This should give you a truly silent build! 🤫

@assembler-0 assembler-0 merged commit 5673a23 into main Oct 26, 2025
1 check passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants