mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-05 20:45:43 +00:00
fix(framegen): count a device loss once, however often the compositor reports it
The compositor reports a loss twice, from device_lost() and again from release_lost_device() during recovery. The second report saw no submitted work and cleared the strike, so the breaker never tripped. A loss now counts once until the device is ready again, and the strike counter is atomic since set_engine resets it from another thread.
This commit is contained in:
1 parent
7bd636b25a
commit
0cedf0e0c6
2 files changed
+31
-10
No files matched your search
@@ -81,7 +81,7 @@ static uint64_t g_total_generated;
|
||||
|
||||
#define FG_PROVEN_FRAMES 120
|
||||
#define FG_HANG_STRIKES 2
|
||||
static int g_hang_strikes;
|
||||
static _Atomic int g_hang_strikes;
|
||||
static int g_submitted_since_ready;
|
||||
static uint64_t g_generated_at_ready;
|
||||
|
||||
@@ -89,11 +89,11 @@ static uint64_t g_generated_at_ready;
|
||||
// recovery, so the compositor would recover and hang again for as long as frame generation stays armed.
|
||||
static int framegen_loss_strike(int submitted, uint64_t completed_since_ready) {
|
||||
if (!submitted || completed_since_ready >= FG_PROVEN_FRAMES) {
|
||||
g_hang_strikes = 0;
|
||||
atomic_store(&g_hang_strikes, 0);
|
||||
return 0;
|
||||
}
|
||||
if (++g_hang_strikes < FG_HANG_STRIKES) return 0;
|
||||
g_hang_strikes = 0;
|
||||
if (atomic_fetch_add(&g_hang_strikes, 1) + 1 < FG_HANG_STRIKES) return 0;
|
||||
atomic_store(&g_hang_strikes, 0);
|
||||
return 1;
|
||||
}
|
||||
static float g_presented_rate, g_source_rate;
|
||||
@@ -111,7 +111,7 @@ void vkp_framegen_set_engine(int kind) {
|
||||
atomic_store(&g_kind, kind);
|
||||
atomic_store(&g_failed_kind, -1);
|
||||
atomic_store(&g_cfg_dirty, 1);
|
||||
g_hang_strikes = 0;
|
||||
atomic_store(&g_hang_strikes, 0);
|
||||
}
|
||||
|
||||
void vkp_framegen_set_armed(int armed, int multiplier, int target_fps) {
|
||||
@@ -216,15 +216,21 @@ void vkp_framegen_device_ready(VkDevice dev, VkQueue queue, uint32_t qfam, int f
|
||||
fge_caps_ok(VKP_FG_ENGINE_DDFG) ? "available" : "unavailable");
|
||||
}
|
||||
|
||||
// The compositor reports one loss twice: when it happens and again while releasing the lost device.
|
||||
static int framegen_count_loss(void) {
|
||||
if (atomic_exchange(&g_dev_lost, 1)) return 0;
|
||||
int failed = framegen_loss_strike(g_submitted_since_ready, g_total_generated - g_generated_at_ready);
|
||||
g_submitted_since_ready = 0;
|
||||
return failed;
|
||||
}
|
||||
|
||||
void vkp_framegen_device_lost(void) {
|
||||
if (framegen_loss_strike(g_submitted_since_ready, g_total_generated - g_generated_at_ready)) {
|
||||
if (framegen_count_loss()) {
|
||||
int kind = atomic_load(&g_kind);
|
||||
mark_failed(kind);
|
||||
FGLOG("%s lost the GPU %d times in a row before its frames completed; frame generation stays off "
|
||||
"until it is set again", fge_engine_name(kind), FG_HANG_STRIKES);
|
||||
}
|
||||
g_submitted_since_ready = 0;
|
||||
atomic_store(&g_dev_lost, 1);
|
||||
atomic_store(&g_dev_ready, 0);
|
||||
fge_device_lost();
|
||||
if (g_dev) {
|
||||
|
||||
@@ -15,9 +15,12 @@ class FramegenHangBreakerTest(unittest.TestCase):
|
||||
self.skipTest('A host C compiler is required')
|
||||
root = Path(__file__).resolve().parents[2]
|
||||
source = (root / 'app/src/main/cpp/waylandcomp/src/framegen_bridge.c').read_text()
|
||||
code = '#include <assert.h>\n#include <stdint.h>\n#define FG_PROVEN_FRAMES 120\n#define FG_HANG_STRIKES 2\n'
|
||||
code += 'static int g_hang_strikes;\n'
|
||||
code = '#include <assert.h>\n#include <stdatomic.h>\n#include <stdint.h>\n'
|
||||
code += '#define FG_PROVEN_FRAMES 120\n#define FG_HANG_STRIKES 2\n'
|
||||
code += 'static _Atomic int g_hang_strikes, g_dev_lost;\n'
|
||||
code += 'static int g_submitted_since_ready;\nstatic uint64_t g_total_generated, g_generated_at_ready;\n'
|
||||
code += function(source, 'framegen_loss_strike')
|
||||
code += function(source, 'framegen_count_loss')
|
||||
code += 'int main(void) {\n' + body + '\n}\n'
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
folder = Path(tmp)
|
||||
@@ -49,6 +52,18 @@ class FramegenHangBreakerTest(unittest.TestCase):
|
||||
assert(framegen_loss_strike(1, 0) == 0);
|
||||
''')
|
||||
|
||||
def test_a_loss_reported_twice_counts_once(self):
|
||||
self.run_c('''
|
||||
for (int loss = 0; loss < 2; loss++) {
|
||||
g_dev_lost = 0;
|
||||
g_submitted_since_ready = 1;
|
||||
int first = framegen_count_loss();
|
||||
int again = framegen_count_loss();
|
||||
assert(again == 0);
|
||||
assert(first == (loss == 1));
|
||||
}
|
||||
''')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user