Skip to content

[WIP] Fix: retry perf record lookup by task_id with sliding window scan#298

Open
indigo1973 wants to merge 1 commit intohw-native-sys:mainfrom
indigo1973:prof_0316
Open

[WIP] Fix: retry perf record lookup by task_id with sliding window scan#298
indigo1973 wants to merge 1 commit intohw-native-sys:mainfrom
indigo1973:prof_0316

Conversation

@indigo1973
Copy link
Contributor

Replace single last-record lookup with a backward scan over a window (kPerfScanWindow=4) of recent PerfBuffer records, retried up to kPerfPatchRetries=4 times with SPIN_WAIT_HINT between attempts. Adds bounds check against PLATFORM_PROF_BUFFER_SIZE and DEV_WARN when no matching task_id is found after all retries.

Also unify orchestrator end-timestamp log format to "Thread=%d end=%llu" (matching scheduler threads) and fix --direction help text in perf_to_mermaid.py.

Replace single last-record lookup with a backward scan over a window
(kPerfScanWindow=4) of recent PerfBuffer records, retried up to
kPerfPatchRetries=4 times with SPIN_WAIT_HINT between attempts.
Adds bounds check against PLATFORM_PROF_BUFFER_SIZE and DEV_WARN
when no matching task_id is found after all retries.

Also unify orchestrator end-timestamp log format to "Thread=%d end=%llu"
(matching scheduler threads) and fix --direction help text in
perf_to_mermaid.py.
@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the reliability of performance data collection by introducing a more resilient lookup mechanism for performance records, ensuring that critical metadata is correctly associated even under transient conditions. It also improves logging consistency for profiling and corrects a minor help text error in a related tool.

Highlights

  • Performance Record Lookup: Implemented a robust retry mechanism for perf record lookup by task_id, utilizing a sliding window scan over recent PerfBuffer records.
  • Error Handling: Added bounds checking against PLATFORM_PROF_BUFFER_SIZE and a DEV_WARN message when no matching task_id is found after all retries.
  • Logging Consistency: Unified the orchestrator end-timestamp log format to match scheduler threads for better consistency.
  • Tooling Improvement: Corrected the --direction help text in perf_to_mermaid.py.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • src/a2a3/runtime/tensormap_and_ringbuffer/aicpu/aicpu_executor.cpp
    • Replaced single last-record lookup with a retry loop that performs a backward scan over a kPerfScanWindow (4) of PerfBuffer records.
    • Introduced kPerfPatchRetries (4) attempts with SPIN_WAIT_HINT between retries.
    • Added a check to cap observed_count at PLATFORM_PROF_BUFFER_SIZE.
    • Added a DEV_WARN message if matched_record remains nullptr after all retries.
    • Modified the orchestrator end-timestamp log format from "BENCHMARK: thread=%d end=%llu" to "Thread=%d end=%llu".
  • tools/perf_to_mermaid.py
    • Updated the help text for the --direction argument to correctly state that 'TD' (Top-Down) is the default.
Activity
  • No human activity has been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a robust fix for a potential race condition in performance record lookup by implementing a sliding window scan with a retry mechanism. This is a significant improvement for the reliability of the performance profiling system. The changes also include some nice cleanups, such as unifying a log message format and fixing help text in a script. The core logic change is well-implemented with appropriate safety checks like bounds checking and memory barriers. I have one suggestion to simplify the index calculation for the sliding window to improve readability.

Comment on lines +368 to +372
int32_t start_idx = static_cast<int32_t>(observed_count) - 1;
int32_t end_idx = start_idx - kPerfScanWindow + 1;
if (end_idx < 0) {
end_idx = 0;
}

Choose a reason for hiding this comment

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

medium

The calculation of the scan window's end_idx can be simplified. The current logic, which involves an initial calculation followed by a conditional clamp to zero, can be expressed more concisely in a single line using a ternary operator. This would make the code easier to read and understand at a glance.

                        const int32_t start_idx = static_cast<int32_t>(observed_count) - 1;
                        const int32_t end_idx = (observed_count > (uint32_t)kPerfScanWindow) ? (static_cast<int32_t>(observed_count) - kPerfScanWindow) : 0;

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