Repository navigation
fix(agc): stop and join the profile dump thread when the driver stops - #24970
Conversation
|
Ran a Setup: Windows 11 Pro 10.0.26300, i5-14600K, WinLibs GCC 15.2.0 r7, Release, Shutdown tests:
On Windows these test processes end through Process that runs longer than 20 s: a small harness (below) starts the driver with
So with this PR the thread stops and is joined at shutdown, and shutdown does not wait out the 20 s period. Step 3 of BUILD.md: I reconfigured the same directory with The HarnessCompiled and linked with the flags of #include "prx/libSceAgcDriver/Execution/include/Driver.hpp"
#include "prx/libc/include/Shutdown.hpp"
#include <windows.h>
#include <tlhelp32.h>
#include <chrono>
#include <cstdio>
#include <cstdlib>
#include <filesystem>
#include <thread>
namespace {
using Clock = std::chrono::steady_clock;
Clock::time_point start;
double Seconds() {
return std::chrono::duration<double>(Clock::now() - start).count();
}
int ThreadCount() {
const auto pid = GetCurrentProcessId();
HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);
THREADENTRY32 entry{};
entry.dwSize = sizeof(entry);
int count = 0;
if (Thread32First(snapshot, &entry)) {
do {
if (entry.th32OwnerProcessID == pid) ++count;
} while (Thread32Next(snapshot, &entry));
}
CloseHandle(snapshot);
return count;
}
std::filesystem::file_time_type lastWrite{};
void Watch(const std::filesystem::path& gcda, double untilSeconds) {
while (Seconds() < untilSeconds) {
std::error_code error;
const auto now = std::filesystem::last_write_time(gcda, error);
if (!error && now != lastWrite) {
lastWrite = now;
std::printf("[%6.2f s] gcda written\n", Seconds());
std::fflush(stdout);
}
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
}
}
int main(int argc, char** argv) {
if (argc != 3) {
std::fprintf(stderr, "usage: %s <file.gcda> <seconds before stop>\n", argv[0]);
return 2;
}
const std::filesystem::path gcda = argv[1];
const double before = std::atof(argv[2]);
std::error_code error;
lastWrite = std::filesystem::last_write_time(gcda, error);
std::printf("threads before driver: %d\n", ThreadCount());
start = Clock::now();
AgcDriverWaitIdle_nid_postfix();
std::printf("[%6.2f s] driver up, threads: %d\n", Seconds(), ThreadCount());
std::fflush(stdout);
Watch(gcda, before);
const int threadsBeforeStop = ThreadCount();
const auto stopStart = Clock::now();
LibcRunShutdown_nid_postfix();
const double stopTook = std::chrono::duration<double>(Clock::now() - stopStart).count();
std::printf("[%6.2f s] shutdown took %.3f s, threads: %d before, %d after\n", Seconds(), stopTook, threadsBeforeStop, ThreadCount());
std::fflush(stdout);
Watch(gcda, Seconds() + 45.0);
std::printf("[%6.2f s] threads at exit: %d\n", Seconds(), ThreadCount());
std::fflush(stdout);
return 0;
}AI-assisted: yes |
GPU test run: ✅ no new failures or validation errors on Windows / NVIDIABasis: built and ran · this PR's head Checked
Findings: none from this run; this is a GPU run, not a code review. AI-assisted test run (Claude Code) · head |
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — comments
The lifecycle changes are sound by inspection, but a full review is not justified because no tests or profile-generate build were run here.
What I ran
Read the prepared diff and changed lines at head 37eed55d2b30b5270f271f881a7dc20d5765829c, plus the profile build configuration and shutdown entry point using repo_read.py. No build or tests were run.
Results
| Check | Result | Note |
|---|---|---|
| Diff and changed lines | passed | Both changed files read |
| Targeted lifecycle context | passed | Build mode and shutdown caller checked |
| Build and tests | not run | Author-reported results only |
Findings
Blocking
None.
Non-blocking
- Consider adding a focused regression test for profile-dump shutdown and final dump behavior. The new thread coordination and final dump are only exercised in the profile-generate build, which the description says was not run.
Not verified
No tests, build, profile-generate execution, or physical-console behavior were verified. Author-reported Windows build and test results were not run by this review. Read core/libs/prx/libSceAgcDriver/Execution/src/Driver/Lifecycle.cpp, docs/dev/BUILD.md, core/libs/prx/libSceAgcDriver/CMakeLists.txt, and core/libs/prx/libSceAgcDriver/Execution/src/Driver/EntryPoints.cpp. The review bundle's review/files.json was unavailable; the prepared manifest and listing identify both changed files as included. No files were excluded according to that listing.
To get this to a good state
Nothing is required. Optional: add regression coverage for the profile dump thread lifecycle.
|
AMD run of Code. I read the diff at
Outside
Existing runs.
My run adds an AMD run of the shutdown tests on the current Probe.
Negative control. In the same probe I removed GPU.
Validation. All four runs used the full environment above, but none of these tests creates a Vulkan instance. So the logs contain no loader output and 0 layer inserts, and the GPU plays no part. None of the logs contains Host:
AI-assisted: yes |
|
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
What
Follow-up to #22268, from the two review notes there:
-DAPS5_AGC_PROFILE=generatebuild started a detached thread that dumped and reset the profile counters every 20 s forever, so it could outliveDriver::stop()and race process teardown. Now the driver starts that thread in its constructor andDriver::stop()stops and joins it, then dumps once more. The other builds keep empty start and stop functions.BUILD.mdstep 2 now says to check that the recording reached the scenes. A session that stayed in a menu still leaves.gcdafiles, and theusebuild reports nothing (-Wno-missing-profile), but the driver it builds is laid out for the menu. The draw commits on the[commits]lines (APS5_PIPELINE_STATS=1) show it. It also says to delete old.gcdafiles before recording again.Tested
Windows 11, GCC 15.2 Release: every target builds except 36 shader test executables the local antivirus removes after linking (none in this set), and 11 of 11 driver shutdown and graphics tests pass.
Lifecycle.cppcompiles without warnings (-Wall) with and withoutAPS5_PROFILE_GENERATE. A generate build was not run.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)