From 2d5b633397db00f6f1f93c2fddc17b256a8523a1 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Tue, 5 Dec 2017 21:50:24 +1100 Subject: [PATCH] [client] changed ivshmem wait timeout to avoid stalls on startup --- client/ivshmem/ivshmem.c | 10 +++++----- client/ivshmem/ivshmem.h | 2 +- client/main.c | 35 ++++++++++++----------------------- 3 files changed, 18 insertions(+), 29 deletions(-) diff --git a/client/ivshmem/ivshmem.c b/client/ivshmem/ivshmem.c index 8c4a2da7..70090bea 100644 --- a/client/ivshmem/ivshmem.c +++ b/client/ivshmem/ivshmem.c @@ -478,7 +478,7 @@ bool ivshmem_process() // ============================================================================ -enum IVSHMEMWaitResult ivshmem_wait_irq(uint16_t vector) +enum IVSHMEMWaitResult ivshmem_wait_irq(uint16_t vector, unsigned int timeout) { if (vector > ivshmem.server.irqCount - 1) return false; @@ -488,13 +488,13 @@ enum IVSHMEMWaitResult ivshmem_wait_irq(uint16_t vector) FD_ZERO(&fds); FD_SET(fd, &fds); - struct timeval timeout; - timeout.tv_sec = 1; - timeout.tv_usec = 0; + struct timeval tv; + tv.tv_sec = timeout / 1000; + tv.tv_usec = (timeout - tv.tv_sec * 1000) * 1000; while(true) { - int ret = select(fd+1, &fds, NULL, NULL, &timeout); + int ret = select(fd+1, &fds, NULL, NULL, &tv); if (ret < 0) { if (errno == EINTR) diff --git a/client/ivshmem/ivshmem.h b/client/ivshmem/ivshmem.h index 1951863f..363a1de6 100644 --- a/client/ivshmem/ivshmem.h +++ b/client/ivshmem/ivshmem.h @@ -35,5 +35,5 @@ enum IVSHMEMWaitResult IVSHMEM_WAIT_RESULT_ERROR }; -enum IVSHMEMWaitResult ivshmem_wait_irq(uint16_t vector); +enum IVSHMEMWaitResult ivshmem_wait_irq(uint16_t vector, unsigned int timeout); bool ivshmem_kick_irq(uint16_t clientID, uint16_t vector); \ No newline at end of file diff --git a/client/main.c b/client/main.c index 6c6f54cd..449c5fa6 100644 --- a/client/main.c +++ b/client/main.c @@ -154,35 +154,23 @@ inline bool areFormatsSame(const struct KVMFRHeader s1, const struct KVMFRHeader (s1.height == s2.height ); } -inline bool waitGuest() +inline int waitGuest() { - bool ready = false; - bool error = false; - while(state.running && !ready && !error) + while(state.running) { - switch(ivshmem_wait_irq(0)) + switch(ivshmem_wait_irq(0, (1000/30))) { - case IVSHMEM_WAIT_RESULT_OK: - ready = true; - break; - + case IVSHMEM_WAIT_RESULT_OK : case IVSHMEM_WAIT_RESULT_TIMEOUT: - ivshmem_kick_irq(state.shm->guestID, 0); - break; + return true; case IVSHMEM_WAIT_RESULT_ERROR: - error = true; - break; + DEBUG_ERROR("error during wait for host"); + return false; } } - if (error) - { - DEBUG_ERROR("error during wait for host"); - return false; - } - - return true; + return false; } int renderThread(void * unused) @@ -192,16 +180,18 @@ int renderThread(void * unused) const LG_Renderer * lgr = NULL; void * lgrData; unsigned int lastTicks = SDL_GetTicks(); - unsigned int frameCount = 0, lastFrameCount = 0; + unsigned int frameCount = 0; + unsigned int lastFrameCount = 0; SDL_Texture * textTexture = NULL; SDL_Rect textRect; while(state.running) { - // wait for the guest to signal ready and copy the header if (!waitGuest()) break; + ++frameCount; + // we must take a copy of the header, both to let the guest advance and to // prevent the contained arguments being abused to overflow buffers memcpy(&header, state.shm, sizeof(struct KVMFRHeader)); @@ -326,7 +316,6 @@ int renderThread(void * unused) break; } - ++frameCount; if (!params.showFPS) { SDL_RenderPresent(state.renderer);