Skip to content

mem: remove duplicated trainning req of prefetcher#777

Open
happy-lx wants to merge 1 commit intoxs-devfrom
fix-duplicated-pf-train
Open

mem: remove duplicated trainning req of prefetcher#777
happy-lx wants to merge 1 commit intoxs-devfrom
fix-duplicated-pf-train

Conversation

@happy-lx
Copy link
Copy Markdown
Contributor

@happy-lx happy-lx commented Mar 9, 2026

when mshrAliasFailed/mshrArbFailed/isHitInWriteBuffer, the request will be replayed, it should not train the prefetcher.

Change-Id: I45f209a8ed78d4f17850971b7af8f8b0b12395aa

Summary by CodeRabbit

  • Bug Fixes
    • Fixed incorrect cache miss reporting in edge cases involving MSHR arbitration failures and write buffer hits. Cache miss events will now accurately reflect actual misses, improving the reliability of cache performance metrics and monitoring.

when `mshrAliasFailed`/`mshrArbFailed`/`isHitInWriteBuffer`, the request
will be replayed, it should not train the prefetcher.

Change-Id: I45f209a8ed78d4f17850971b7af8f8b0b12395aa
@happy-lx happy-lx requested a review from XXtaoo March 9, 2026 07:16
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 9, 2026

📝 Walkthrough

Walkthrough

Modified the BaseCache::recvTimingReq function to conditionally notify the Miss probe (ppMiss) only when MSHR alias did not fail, MSHR arbitration did not fail, and the request did not hit in the write buffer. This prevents miss signaling during error or edge case conditions.

Changes

Cohort / File(s) Summary
Cache Miss Probe Notification
src/mem/cache/base.cc
Updated miss probe notification logic to skip signaling when MSHR alias failure, MSHR arbitration failure, or write buffer hits occur.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A miss that's not quite a miss, you see,
When conditions align perfectly,
We skip the signal, hold our tongue,
Let the cache dance to its own sung,
No false alarms in memories so free! 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 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 (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title mentions removing duplicated training requests for the prefetcher, which directly aligns with the PR's stated objective of preventing replayed requests from training the prefetcher when MSHR or write buffer conditions occur.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-duplicated-pf-train

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


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
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 the current code and only fix it if needed.

Inline comments:
In `@src/mem/cache/base.cc`:
- Around line 826-828: The check for replayable misses is duplicated; extract
the predicate into a single helper (e.g., add a method on BaseCache like
canReplayMiss(const Packet* pkt) or isRetryAllowed(const Packet* pkt) that
returns !pkt->mshrAliasFailed() && !pkt->mshrArbFailed() &&
!pkt->isHitInWriteBuffer()), then replace the direct predicate at the ppMiss
notify site (where ppMiss->notify(pkt) is called) and in
BaseCache::CpuSidePort::recvTimingReq with calls to that helper so both sites
share the same logic.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a358f31f-70a4-46a8-9b7e-add5b2d93d7c

📥 Commits

Reviewing files that changed from the base of the PR and between c62c7f4 and b4dede1.

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

Comment on lines +826 to +828
if (!pkt->mshrAliasFailed() && !pkt->mshrArbFailed() && !pkt->isHitInWriteBuffer()) {
ppMiss->notify(pkt);
}
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 | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== Miss probe declarations / notify sites ==="
rg -n -C3 '\bppMiss\b|new ProbePointArg<.*>\(.*"Miss"' src

echo
echo "=== Probe listener registration sites ==="
rg -n -C4 'regProbeListeners|ProbeListener|addEventProbe|add.*Probe' src

echo
echo "=== Miss-probe related registrations in cache + prefetch code ==="
rg -n -C4 '\bppMiss\b|"Miss"' src/mem/cache src/mem/cache/prefetch

Repository: OpenXiangShan/GEM5

Length of output: 50374


🏁 Script executed:

#!/bin/bash
# Find all places where listeners are registered to the "Miss" probe
echo "=== Searching for Miss probe listener registration in prefetch code ==="
rg -n 'PrefetchListener|addListener.*Miss' src/mem/cache/prefetch/

echo
echo "=== BaseCache::regProbeListeners to see how listeners connect ==="
rg -n -A10 'BaseCache::regProbeListeners' src/mem/cache/base.cc

echo
echo "=== All listeners that might connect to cache probes ==="
rg -n 'class.*Listener.*ProbeListenerArgBase' src/mem/cache src/mem/mem_object.cc

echo
echo "=== Check if non-prefetch code uses or listens to cache Miss ==="
rg -n '"Miss"' src/mem/cache/base.cc | head -20

Repository: OpenXiangShan/GEM5

Length of output: 2294


🏁 Script executed:

#!/bin/bash
# Check the retry predicate at lines 3237-3238
echo "=== Retry predicate context around 3237-3238 ==="
sed -n '3230,3250p' src/mem/cache/base.cc

echo
echo "=== Miss notify context around 826-828 ==="
sed -n '820,835p' src/mem/cache/base.cc

echo
echo "=== Verify the three packet predicates are defined ==="
rg -n 'mshrAliasFailed|mshrArbFailed|isHitInWriteBuffer' src/mem/packet.hh | head -20

Repository: OpenXiangShan/GEM5

Length of output: 1734


Only prefetch training listens to the ppMiss probe, but the replay predicate is now duplicated.

Verification confirms that only the prefetcher's PrefetchListener subscribes to the cache's "Miss" probe point (see src/mem/cache/prefetch/base.cc:438), so the guard at lines 826–828 does not suppress replayed misses from non-prefetch consumers. However, the condition duplicates the retry predicate at BaseCache::CpuSidePort::recvTimingReq (lines 3237–3239)—both check !mshrAliasFailed() && !mshrArbFailed() && !isHitInWriteBuffer() (via inverted OR). If either site is modified later without updating the other, the two behaviors could diverge. Consider extracting this predicate to a helper method or constant to keep them in sync.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/mem/cache/base.cc` around lines 826 - 828, The check for replayable
misses is duplicated; extract the predicate into a single helper (e.g., add a
method on BaseCache like canReplayMiss(const Packet* pkt) or
isRetryAllowed(const Packet* pkt) that returns !pkt->mshrAliasFailed() &&
!pkt->mshrArbFailed() && !pkt->isHitInWriteBuffer()), then replace the direct
predicate at the ppMiss notify site (where ppMiss->notify(pkt) is called) and in
BaseCache::CpuSidePort::recvTimingReq with calls to that helper so both sites
share the same logic.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 9, 2026

🚀 Coremark Smoke Test Results

Branch IPC Change
Base (xs-dev) 2.2354 -
This PR 2.2354 ➡️ 0.0000 (0.00%)

✅ Difftest smoke test passed!

@happy-lx happy-lx added the perf label Mar 10, 2026
@github-actions
Copy link
Copy Markdown

🚀 Performance test triggered: spec06-0.8c

@XiangShanRobot
Copy link
Copy Markdown

[Generated by GEM5 Performance Robot]
commit: b4dede1
workflow: On-Demand SPEC Test (Tier 1.5)

Ideal BTB Performance

Overall Score

PR Master Diff(%)
Score 20.62 20.63 -0.05 🔴

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants