The device answers most lifecycle messages the kext waits for within tens of microseconds of the post (a heap texture's size, a library's lookup, a surface's pages: 60 to 110 us on the RTX 3090 host), and the answer then waited for the interrupt, the work loop's wake and the waiter's, about 25 us more (measured in a Vision request). postLifecycle now looks for its answer for at most 150 us before it sleeps (RgfxAnswerLook.hpp): where the control completion ring holds a record the work loop has not taken, it takes the ring in the work loop's gate, as the work loop does, and else pauses the CPU. It never waits for the gate (an IOCommandGate's attemptAction): the event hooks its holder runs take the release table's lock and the pipe clients', which a waiter's caller may hold, and only the sleep's deadline bounds that wait, as before. The rest of the work loop's service follows at the interrupt the record raised. Only a thread whose call waits for an answer looks, and only that long. No answer or order changes. Tested by answer_look_test. Measured, Vision cold request, RTX 3090 host (rts4, the branch without this commit, against the branch with it; host load 3.0 and 5.4), first process / second: a heap texture's size and alignment, 60 calls, 36.3/36.6 -> 26.2/25.3 us a call (its answer's leg after the post 12.7 -> 2.4 us); a library lookup 78.8/87.0 -> 52.0/53.1 us; a surface block's ask (its SURFACE_PAGES), 123 asks, 232/215 -> 173/178 us, 32.0/27.5 -> 25.3/24.1 ms. A pipeline create whose compile outlasts the look is answered as before.
111 lines
3.3 KiB
C++
111 lines
3.3 KiB
C++
// The native test of RgfxAnswerLook.hpp: a waiter's look for its answer takes the ring only where
|
|
// a record waits and the work loop's gate is free, pauses otherwise, ends as the answer comes,
|
|
// and ends at its deadline without one.
|
|
#include "RgfxAnswerLook.hpp"
|
|
|
|
#include <cstdio>
|
|
#include <cstdlib>
|
|
|
|
namespace {
|
|
int checks = 0;
|
|
|
|
void check(bool ok, const char *what)
|
|
{
|
|
checks++;
|
|
if (!ok) {
|
|
std::fprintf(stderr, "answer_look_test: FAILED: %s\n", what);
|
|
std::exit(1);
|
|
}
|
|
}
|
|
|
|
// A look's world: a clock that moves one tick a call, a record that lands after `landsAfter`
|
|
// pauses, an answer that comes with the take of the record where `answers`, and a gate another
|
|
// thread holds for the first `gateHeldFor` takes.
|
|
struct World {
|
|
uint64_t clock = 0;
|
|
int pauses = 0;
|
|
int takes = 0;
|
|
int landsAfter = 0;
|
|
int gateHeldFor = 0;
|
|
int refused = 0;
|
|
bool answers = true;
|
|
bool answered = false;
|
|
bool pendingRecord = false;
|
|
|
|
bool look(uint64_t deadline)
|
|
{
|
|
return rgfxLookForAnswer(
|
|
deadline, [this] { return clock++; }, [this] { return answered; },
|
|
[this] { return pendingRecord; },
|
|
[this] {
|
|
if (refused < gateHeldFor) {
|
|
refused++;
|
|
return false;
|
|
}
|
|
takes++;
|
|
pendingRecord = false;
|
|
answered = answers;
|
|
return true;
|
|
},
|
|
[this] {
|
|
if (++pauses == landsAfter)
|
|
pendingRecord = true;
|
|
});
|
|
}
|
|
};
|
|
} // namespace
|
|
|
|
int main()
|
|
{
|
|
// Answered before the look: nothing taken, no pause.
|
|
{
|
|
World w;
|
|
w.answered = true;
|
|
check(w.look(100), "an answer already there ends the look");
|
|
check(w.takes == 0 && w.pauses == 0, "and takes nothing, pausing never");
|
|
}
|
|
// The record lands after three pauses: one take, which answers.
|
|
{
|
|
World w;
|
|
w.landsAfter = 3;
|
|
check(w.look(100), "a record that lands answers the look");
|
|
check(w.takes == 1 && w.pauses == 3, "with one take, after the pauses before it");
|
|
}
|
|
// No record within the deadline: the look ends unanswered, having taken nothing.
|
|
{
|
|
World w;
|
|
check(!w.look(10), "no answer by the deadline ends the look unanswered");
|
|
check(w.takes == 0 && w.pauses == 10, "having paused until it");
|
|
}
|
|
// A record that answers another waiter: taken, and the look goes on to its deadline.
|
|
{
|
|
World w;
|
|
w.landsAfter = 2;
|
|
w.answers = false;
|
|
check(!w.look(10), "another's answer does not end the look");
|
|
check(w.takes == 1, "but its record is taken");
|
|
}
|
|
// A gate another thread holds: the take does not run, the look pauses and takes the record
|
|
// once the gate is free, never waiting for it.
|
|
{
|
|
World w;
|
|
w.landsAfter = 1;
|
|
w.gateHeldFor = 3;
|
|
check(w.look(100), "a record behind a held gate answers the look once it is free");
|
|
check(w.takes == 1 && w.refused == 3 && w.pauses == 4,
|
|
"after a pause for each take the held gate refused");
|
|
}
|
|
// A gate held to the deadline: the look ends unanswered, the record left to the work loop.
|
|
{
|
|
World w;
|
|
w.landsAfter = 1;
|
|
w.gateHeldFor = 1000;
|
|
check(!w.look(20), "a gate held to the deadline ends the look unanswered");
|
|
check(w.takes == 0 && w.pendingRecord, "leaving the record for the work loop");
|
|
}
|
|
// The bound a pipeline create's thread spends looking is the constant's.
|
|
check(kRgfxAnswerLookNs == 150 * 1000, "a waiter looks 150 us at most");
|
|
std::printf("answer_look_test: OK (%d checks)\n", checks);
|
|
return 0;
|
|
}
|