From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:37076) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SPoNe-0004FH-Dd for qemu-devel@nongnu.org; Thu, 03 May 2012 01:15:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SPoNb-0001Tl-7X for qemu-devel@nongnu.org; Thu, 03 May 2012 01:15:05 -0400 Received: from v220110690675601.yourvserver.net ([78.47.199.172]:59003) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SPoNa-0001QN-V0 for qemu-devel@nongnu.org; Thu, 03 May 2012 01:15:03 -0400 From: Stefan Weil Date: Thu, 3 May 2012 07:14:53 +0200 Message-Id: <1336022093-21467-7-git-send-email-sw@weilnetz.de> In-Reply-To: <1336022093-21467-1-git-send-email-sw@weilnetz.de> References: <1336022093-21467-1-git-send-email-sw@weilnetz.de> Subject: [Qemu-devel] [PATCH 6/6] qemu-timer: Fix limits for w32 mmtimer List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Stefan Weil , Anthony Liguori timeSetEvent only accepts delays in the range which is returned by timeGetDevCaps. The lower limit is typically 1 (= 1 ms), so the constant value of 1 in the old code usually worked. The upper limit can be as low as 10000 ms, so the latest changes in QEMU's timer handling which introduced timeout values above that limit could result in failures of timeSetEvent when the timer was re-armed. Signed-off-by: Stefan Weil --- qemu-timer.c | 34 ++++++++++++++-------------------- 1 files changed, 14 insertions(+), 20 deletions(-) diff --git a/qemu-timer.c b/qemu-timer.c index 8eadd16..b9fd75d 100644 --- a/qemu-timer.c +++ b/qemu-timer.c @@ -611,7 +611,7 @@ static void unix_stop_timer(struct qemu_alarm_timer *t) #ifdef _WIN32 static MMRESULT mm_timer; -static unsigned mm_period; +static TIMECAPS mm_tc; static void CALLBACK mm_alarm_handler(UINT uTimerID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, @@ -628,16 +628,12 @@ static void CALLBACK mm_alarm_handler(UINT uTimerID, UINT uMsg, static int mm_start_timer(struct qemu_alarm_timer *t) { - TIMECAPS tc; + timeGetDevCaps(&mm_tc, sizeof(mm_tc)); - memset(&tc, 0, sizeof(tc)); - timeGetDevCaps(&tc, sizeof(tc)); + timeBeginPeriod(mm_tc.wPeriodMin); - mm_period = tc.wPeriodMin; - timeBeginPeriod(mm_period); - - mm_timer = timeSetEvent(1, /* interval (ms) */ - mm_period, /* resolution */ + mm_timer = timeSetEvent(mm_tc.wPeriodMin, /* interval (ms) */ + mm_tc.wPeriodMin, /* resolution */ mm_alarm_handler, /* function */ (DWORD_PTR)t, /* parameter */ TIME_ONESHOT | TIME_CALLBACK_FUNCTION); @@ -645,7 +641,7 @@ static int mm_start_timer(struct qemu_alarm_timer *t) if (!mm_timer) { fprintf(stderr, "Failed to initialize win32 alarm timer: %ld\n", GetLastError()); - timeEndPeriod(mm_period); + timeEndPeriod(mm_tc.wPeriodMin); return -1; } @@ -655,23 +651,21 @@ static int mm_start_timer(struct qemu_alarm_timer *t) static void mm_stop_timer(struct qemu_alarm_timer *t) { timeKillEvent(mm_timer); - timeEndPeriod(mm_period); + timeEndPeriod(mm_tc.wPeriodMin); } static void mm_rearm_timer(struct qemu_alarm_timer *t, int64_t delta) { int64_t nearest_delta_ms = delta / 1000000; - if (nearest_delta_ms < 1) { - nearest_delta_ms = 1; - } - /* UINT_MAX can be 32 bit */ - if (nearest_delta_ms > UINT_MAX) { - nearest_delta_ms = UINT_MAX; + if (nearest_delta_ms < mm_tc.wPeriodMin) { + nearest_delta_ms = mm_tc.wPeriodMin; + } else if (nearest_delta_ms > mm_tc.wPeriodMax) { + nearest_delta_ms = mm_tc.wPeriodMax; } timeKillEvent(mm_timer); - mm_timer = timeSetEvent((unsigned int) nearest_delta_ms, - mm_period, + mm_timer = timeSetEvent((UINT)nearest_delta_ms, + mm_tc.wPeriodMin, mm_alarm_handler, (DWORD_PTR)t, TIME_ONESHOT | TIME_CALLBACK_FUNCTION); @@ -680,7 +674,7 @@ static void mm_rearm_timer(struct qemu_alarm_timer *t, int64_t delta) fprintf(stderr, "Failed to re-arm win32 alarm timer %ld\n", GetLastError()); - timeEndPeriod(mm_period); + timeEndPeriod(mm_tc.wPeriodMin); exit(1); } } -- 1.7.9