Skip to content

mem-cache: Align cache hint wakeup ordering with responses#861

Open
happy-lx wants to merge 1 commit into
xs-devfrom
fix-hint
Open

mem-cache: Align cache hint wakeup ordering with responses#861
happy-lx wants to merge 1 commit into
xs-devfrom
fix-hint

Conversation

@happy-lx
Copy link
Copy Markdown
Contributor

@happy-lx happy-lx commented May 25, 2026

Make cache-generated hint wakeups follow the same ordering assumptions as the response path.

Cache::sendHintViaMSHRTargets() used to treat a delayed first target as a reason to delay every later target in the MSHR. That does not match RespPacketQueue::forceOrder, which only preserves order for targets with the same packet address. Compute each hint's base send time from its own critical-word offset and only inherit a later send time from previous hints that matchAddr().

Also schedule BaseCache::SendCustomEvent at Minimum_Pri so a hint event scheduled for the same tick can fire before CPU tick work. This keeps the wakeup signal ahead of the matching timing response in the same cycle instead of letting it slip behind CPU-side processing.

Change-Id: I87a79eccf7ee08f90e7b604808ac04ff96cc6880
Tested: scons build/RISCV/gem5.opt --gold-linker -j64

Summary by CodeRabbit

  • Bug Fixes
    • Corrected event priority handling and hint scheduling logic to maintain proper ordering in cache response operations.

Review Change Stack

Make cache-generated hint wakeups follow the same ordering assumptions as the response path.

Cache::sendHintViaMSHRTargets() used to treat a delayed first target as a reason to delay every later target in the MSHR. That does not match RespPacketQueue::forceOrder, which only preserves order for targets with the same packet address. Compute each hint's base send time from its own critical-word offset and only inherit a later send time from previous hints that matchAddr().

Also schedule BaseCache::SendCustomEvent at Minimum_Pri so a hint event scheduled for the same tick can fire before CPU tick work. This keeps the wakeup signal ahead of the matching timing response in the same cycle instead of letting it slip behind CPU-side processing.

Change-Id: I87a79eccf7ee08f90e7b604808ac04ff96cc6880
Tested: scons build/RISCV/gem5.opt --gold-linker -j64
@happy-lx happy-lx requested a review from XXtaoo May 25, 2026 03:13
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 25, 2026

📝 Walkthrough

Walkthrough

This PR modifies cache event scheduling in two coordinated ways: lowering the priority of custom cache events in the simulation queue, and refactoring hint-scheduling logic to track and enforce response-queue ordering constraints so later targets cannot be scheduled earlier than already-enqueued hints for the same address.

Changes

Hint Event Scheduling

Layer / File(s) Summary
Event priority adjustment
src/mem/cache/base.cc
BaseCache::SendCustomEvent constructs the base Event with Minimum_Pri instead of Stat_Event_Pri.
Hint scheduling order enforcement
src/mem/cache/cache.cc
Cache::sendHintViaMSHRTargets introduces a scheduled_hints vector to track hint timings, replaces firstTgt/firstTgtDelayed logic with iteration over prior hints to enforce force-order semantics, and records each target hint for subsequent comparisons.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • jensen-yan
  • tastynoob

Poem

🐰 Events now march with lighter feet,
Their hints in order, calm and neat.
No race ahead, no out-of-place—
Each scheduled hint knows its true place! 🎯

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'mem-cache: Align cache hint wakeup ordering with responses' directly and clearly summarizes the main change: aligning cache hint wakeup ordering with response semantics.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-hint

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.

@happy-lx happy-lx added the bug Something isn't working label May 25, 2026
Copy link
Copy Markdown

@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

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/mem/cache/base.cc`:
- Around line 105-106: The constructor BaseCache::SendCustomEvent currently uses
Minimum_Pri which runs this hint before all same-tick events; change it to use a
dedicated, narrower priority (e.g., define CacheHint_Pri) that is positioned
only to beat CPU_Tick_Pri but not Debug_Enable_Pri or CPU_Switch_Pri. Replace
Minimum_Pri in the SendCustomEvent initializer with CacheHint_Pri and add the
CacheHint_Pri constant in the event-priority definitions with a value placed
immediately above/before CPU_Tick_Pri (so it wins against CPU_Tick_Pri but does
not preempt Debug_Enable_Pri/CPU_Switch_Pri). Ensure the new constant is
documented where other priority constants are defined.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: fe4ea253-7b9d-4262-8fbd-a2b530c72905

📥 Commits

Reviewing files that changed from the base of the PR and between 7930d36 and eed29e9.

📒 Files selected for processing (2)
  • src/mem/cache/base.cc
  • src/mem/cache/cache.cc

Comment thread src/mem/cache/base.cc
Comment on lines 105 to +106
BaseCache::SendCustomEvent::SendCustomEvent(BaseCache* cache, PacketPtr pkt, int sig, bool deletePkt)
: Event(Stat_Event_Pri, AutoDelete),
: Event(Minimum_Pri, AutoDelete),
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Don't use Minimum_Pri for cache hints.

Line 106 now makes SendCustomEvent run before every other same-tick event, including Debug_Enable_Pri and CPU_Switch_Pri. The PR only needs hints to beat CPU_Tick_Pri; using the absolute minimum priority widens the ordering change enough to break unrelated event-queue contracts.

Suggested fix
-    : Event(Minimum_Pri, AutoDelete),
+    : Event(CPU_Tick_Pri - 1, AutoDelete),
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/mem/cache/base.cc` around lines 105 - 106, The constructor
BaseCache::SendCustomEvent currently uses Minimum_Pri which runs this hint
before all same-tick events; change it to use a dedicated, narrower priority
(e.g., define CacheHint_Pri) that is positioned only to beat CPU_Tick_Pri but
not Debug_Enable_Pri or CPU_Switch_Pri. Replace Minimum_Pri in the
SendCustomEvent initializer with CacheHint_Pri and add the CacheHint_Pri
constant in the event-priority definitions with a value placed immediately
above/before CPU_Tick_Pri (so it wins against CPU_Tick_Pri but does not preempt
Debug_Enable_Pri/CPU_Switch_Pri). Ensure the new constant is documented where
other priority constants are defined.

@github-actions
Copy link
Copy Markdown

🚀 Coremark Smoke Test Results

Branch IPC Change
Base (xs-dev) 2.3130 -
This PR 2.3123 📉 -0.0007 (-0.03%)

✅ Difftest smoke test passed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants