mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-05 07:48:45 +00:00
serve: log a driver GPU pause that happens between requests (AMD on Linux)
The paused-GPU counter of the AMD driver was read only when a request began and when it ended, so a pause between two requests, or while the engine sat idle after READY, showed in no line. The engine now also reads the counter at READY and when each request ends (whichever way it ends), and when the next request begins it prints one line if the counter moved by 100 ms or more in between: strata serve: the graphics driver paused the GPU for N ms between requests while Linux moved memory the GPU uses The bar is the one the per-request line uses. A failed read leaves no mark, so two unrelated counters never make a gap, and a counter that went back prints nothing. The begin-of-request read is the one that was already there; the other builds (no HIP, not Linux) read nothing. Diagnostic only: no new setting, no change to any existing line. gpu_pause_time_test gains the line's cases and a sequence test of the bookkeeping (GpuPauseIdle).
This commit is contained in:
1 parent
6f1613cc1c
commit
f55afa1521
3 files changed
+60
-3
No files matched your search
@@ -5,8 +5,8 @@
|
||||
// from the host, and counts the time per GPU in /sys/class/kfd/kfd/proc/<pid>/stats_<gpu id>/evicted_ms (whole ms
|
||||
// since the process opened the GPU). On p620 (R9700) a slow prompt read lost about exactly that time while
|
||||
// background compaction moved pages (RESULTS-GH-URGENT.md, "GPU queue evictions from page migration"), and no log
|
||||
// showed it. The engine reads the counter once when a request begins, once when it ends and in the stall report;
|
||||
// never on the hot path.
|
||||
// showed it. The engine reads the counter at READY, once when a request begins, once when it ends (that read also starts the
|
||||
// gap to the next request) and in the stall report; never on the hot path.
|
||||
//
|
||||
// Header-only and without the GPU runtime, so the reader and the lines are tested on the CPU against a fake tree
|
||||
// (tests/core/gpu_pause_time_test.cpp). A missing, unreadable or unexpected counter means "not available" (-1): no
|
||||
@@ -109,4 +109,24 @@ inline std::string gpu_pause_request_line(int64_t at_start, int64_t at_end) {
|
||||
" ms during this request while Linux moved memory the GPU uses; the request was slower by up to that much";
|
||||
}
|
||||
|
||||
/// The per-gap line (no newline): the counter moved by at least kGpuPauseReportMs while the engine sat idle, between READY (or
|
||||
/// the end of the previous request) and the start of the next request. "" when either read is not available or below the bar.
|
||||
/// [DRAFT, not approved] wording: the request line's words with "between requests" in place of "during this request" and no
|
||||
/// "slower" clause (nothing was running).
|
||||
inline std::string gpu_pause_between_line(int64_t idle_from, int64_t at_begin) {
|
||||
if (idle_from < 0 || at_begin < idle_from || at_begin - idle_from < kGpuPauseReportMs) return "";
|
||||
return "strata serve: the graphics driver paused the GPU for " + std::to_string(at_begin - idle_from) +
|
||||
" ms between requests while Linux moved memory the GPU uses";
|
||||
}
|
||||
|
||||
/// The counter's value when the engine last went idle: at READY, and again at the end of every request (whichever way it ends).
|
||||
/// -1 until read, and again after a read that failed, so a failed read never makes a gap out of two unrelated counters.
|
||||
/// Touched only by the request loop's thread.
|
||||
struct GpuPauseIdle {
|
||||
int64_t from = -1;
|
||||
void idle(int64_t counter_now) { from = counter_now; }
|
||||
/// A request begins with the counter at `counter_now`: the line for the gap since the engine went idle, or "".
|
||||
std::string begin(int64_t counter_now) const { return gpu_pause_between_line(from, counter_now); }
|
||||
};
|
||||
|
||||
} // namespace strata::core
|
||||
@@ -1755,6 +1755,9 @@ static int64_t gpu_pause_now() {
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
/// The same counter when the engine last went idle (READY, then the end of every request): the next request's begin reports a pause that
|
||||
/// happened in between. Only the request loop's thread touches it.
|
||||
static strata::core::GpuPauseIdle g_gpu_pause_idle;
|
||||
constexpr int64_t kVramSafeMib =
|
||||
#ifdef _WIN32
|
||||
1024; // WDDM pages instead of failing (docs/DETAILS.md, the sysmem fallback): the line #2065 fell below
|
||||
@@ -14422,6 +14425,7 @@ int main(int argc, char** argv) {
|
||||
strata::core::pin_sim_report("at READY");
|
||||
strata::core::pin_reserve_release_hard(); // the load is over: nothing else needs the headroom
|
||||
strata::core::manifest::instance().write("ready"); // STRATA_MANIFEST (a no-op unless it is set)
|
||||
g_gpu_pause_idle.idle(gpu_pause_now()); // AMD on Linux: the gap before the first request starts here (the start-up's own pauses are not a "between")
|
||||
std::printf("READY %lld stop hold holdb\n", (long long) o.max_context); // "stop": this engine honours STOP; "hold": GEN hold=N:ID; "holdb": the --batch slots end at the hold too (BDONE hold)
|
||||
std::fflush(stdout);
|
||||
std::string line;
|
||||
@@ -15903,9 +15907,15 @@ int main(int argc, char** argv) {
|
||||
strata::core::progress().busy.store(false);
|
||||
strata::core::progress().allow_until_ms.store(0);
|
||||
strata::core::progress_at("idle");
|
||||
g_gpu_pause_idle.idle(gpu_pause_now()); // the gap to the next request starts here, whichever way this one ended
|
||||
}
|
||||
} busy_scope;
|
||||
g_req_gpu_pause_ms.store(gpu_pause_now()); // AMD on Linux: the driver's GPU pause counter, once per request
|
||||
{ // AMD on Linux: the driver's GPU pause counter, once per request; a pause since the engine went idle gets its own line
|
||||
const int64_t pause_begin = gpu_pause_now();
|
||||
const std::string gap_line = g_gpu_pause_idle.begin(pause_begin);
|
||||
if (!gap_line.empty()) std::fprintf(stderr, "%s\n", gap_line.c_str());
|
||||
g_req_gpu_pause_ms.store(pause_begin);
|
||||
}
|
||||
{ // #2065: said, never changed - the free VRAM now (the verify windows' captures and the batch layouts
|
||||
// eat into what startup reported), once per 128 MiB lower it gets
|
||||
size_t vf_b = 0, vt_b = 0;
|
||||
|
||||
@@ -145,6 +145,33 @@ int main() {
|
||||
"strata serve: the graphics driver paused the GPU for 954 ms during this request while Linux moved memory "
|
||||
"the GPU uses; the request was slower by up to that much");
|
||||
|
||||
// the gap line: the same bar, from READY or the end of the previous request to the next request's begin
|
||||
CHECK(gpu_pause_between_line(-1, 900).empty()); // never idle yet / the read failed
|
||||
CHECK(gpu_pause_between_line(100, -1).empty());
|
||||
CHECK(gpu_pause_between_line(100, 50).empty()); // a counter that went back (a new process): no line
|
||||
CHECK(gpu_pause_between_line(1000, 1099).empty());
|
||||
CHECK(gpu_pause_between_line(1000, 1100) ==
|
||||
"strata serve: the graphics driver paused the GPU for 100 ms between requests while Linux moved memory the GPU uses");
|
||||
|
||||
// the bookkeeping over a sequence, as the request loop calls it
|
||||
{
|
||||
GpuPauseIdle idle;
|
||||
CHECK(idle.begin(500).empty()); // before READY was read: nothing to compare with
|
||||
idle.idle(500); // READY
|
||||
CHECK(idle.begin(560).empty()); // 60 ms before the first request: below the bar
|
||||
idle.idle(900); // the first request ended (it paused 340 ms inside: its own line)
|
||||
CHECK(idle.begin(900).empty()); // the next one began at once: no gap
|
||||
idle.idle(950); // it ended
|
||||
CHECK(idle.begin(1450) == // 500 ms of driver pause while idle
|
||||
"strata serve: the graphics driver paused the GPU for 500 ms between requests while Linux moved memory the GPU uses");
|
||||
CHECK(idle.begin(1450) == idle.begin(1450)); // begin() does not move the mark: only idle() does
|
||||
idle.idle(-1); // a failed read at an end: no gap is made from unrelated counters
|
||||
CHECK(idle.begin(5000).empty());
|
||||
idle.idle(5000);
|
||||
CHECK(idle.begin(5099).empty());
|
||||
CHECK(!idle.begin(5100).empty());
|
||||
}
|
||||
|
||||
if (failed) { std::fprintf(stderr, "gpu_pause_time_test: %d failed\n", failed); return 1; }
|
||||
std::printf("gpu_pause_time_test: ok\n");
|
||||
return 0;
|
||||
|
||||
Reference in new issue
Block a user