From 0b2c7e207d1392a172787fc9cf1a0676025e619b Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Fri, 2 Sep 2022 23:57:33 +0100 Subject: [PATCH] c/multi: Use precise sleeper for scheduled frame waiting --- src/xrt/compositor/multi/comp_multi_compositor.c | 12 ++++++++---- src/xrt/compositor/multi/comp_multi_private.h | 7 +++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/xrt/compositor/multi/comp_multi_compositor.c b/src/xrt/compositor/multi/comp_multi_compositor.c index 87630d1f4..e020e8347 100644 --- a/src/xrt/compositor/multi/comp_multi_compositor.c +++ b/src/xrt/compositor/multi/comp_multi_compositor.c @@ -219,7 +219,7 @@ wait_for_scheduled_free(struct multi_compositor *mc) os_mutex_unlock(&mc->slot_lock); - os_nanosleep(U_TIME_1MS_IN_NS); + os_precise_sleeper_nanosleep(&mc->scheduled_sleeper, U_TIME_1MS_IN_NS); os_mutex_lock(&mc->slot_lock); } @@ -566,7 +566,7 @@ multi_compositor_wait_frame(struct xrt_compositor *xc, out_predicted_display_period_ns); // // Wait until the given wake up time. - u_wait_until(&mc->sleeper, wake_up_time_ns); + u_wait_until(&mc->frame_sleeper, wake_up_time_ns); uint64_t now_ns = os_monotonic_get_ns(); @@ -873,7 +873,8 @@ multi_compositor_destroy(struct xrt_compositor *xc) // Does null checking. u_pa_destroy(&mc->upa); - os_precise_sleeper_deinit(&mc->sleeper); + os_precise_sleeper_deinit(&mc->frame_sleeper); + os_precise_sleeper_deinit(&mc->scheduled_sleeper); os_mutex_destroy(&mc->slot_lock); os_mutex_destroy(&mc->event.mutex); @@ -942,7 +943,10 @@ multi_compositor_create(struct multi_system_compositor *msc, mc->base.base.info = msc->xcn->base.info; // Used in wait frame. - os_precise_sleeper_init(&mc->sleeper); + os_precise_sleeper_init(&mc->frame_sleeper); + + // Used in scheduled waiting function. + os_precise_sleeper_init(&mc->scheduled_sleeper); // This is safe to do without a lock since we are not on the list yet. u_paf_create(msc->upaf, &mc->upa); diff --git a/src/xrt/compositor/multi/comp_multi_private.h b/src/xrt/compositor/multi/comp_multi_private.h index 9645da8b1..b6aaa02c3 100644 --- a/src/xrt/compositor/multi/comp_multi_private.h +++ b/src/xrt/compositor/multi/comp_multi_private.h @@ -101,8 +101,11 @@ struct multi_compositor //! Owning system compositor. struct multi_system_compositor *msc; - //! Only matters for Windows and in process. - struct os_precise_sleeper sleeper; + //! Used to implement wait frame, only used for in process. + struct os_precise_sleeper frame_sleeper; + + //! Used when waiting for the scheduled frame to complete. + struct os_precise_sleeper scheduled_sleeper; struct {