From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37378) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a1Fhg-0008VT-U5 for qemu-devel@nongnu.org; Tue, 24 Nov 2015 10:40:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a1Fhd-0005y8-N7 for qemu-devel@nongnu.org; Tue, 24 Nov 2015 10:40:24 -0500 Received: from mx1.redhat.com ([209.132.183.28]:40427) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a1Fhd-0005y2-IU for qemu-devel@nongnu.org; Tue, 24 Nov 2015 10:40:21 -0500 Date: Tue, 24 Nov 2015 16:40:18 +0100 From: Kevin Wolf Message-ID: <20151124154018.GH4296@noname.str.redhat.com> References: <1448060035-31973-1-git-send-email-jsnow@redhat.com> <1448060035-31973-2-git-send-email-jsnow@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1448060035-31973-2-git-send-email-jsnow@redhat.com> Subject: Re: [Qemu-devel] [PATCH 1/2] ide-test: fix timeouts List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: John Snow Cc: pl@kamp.de, qemu-devel@nongnu.org Am 20.11.2015 um 23:53 hat John Snow geschrieben: > Use explicit timeouts instead of trying to fudge > it by counting nsleep calls. > > Signed-off-by: John Snow Isn't wrapping lines at 50 characters a bit extreme? I'm wondering why this is a fix. If anything, I would expect the new version to be less precise because its resolution is much coarser (1 s vs. 400 ns). Should still be good enough, so both the new and the old code look okay to me, but I'd appreciate a commit message that tells the motivation for this change. Kevin > tests/ide-test.c | 18 ++++++++++++++---- > 1 file changed, 14 insertions(+), 4 deletions(-) > > diff --git a/tests/ide-test.c b/tests/ide-test.c > index fc1ce52..d37dc5e 100644 > --- a/tests/ide-test.c > +++ b/tests/ide-test.c > @@ -642,15 +642,20 @@ static void nsleep(int64_t nsecs) > > static uint8_t ide_wait_clear(uint8_t flag) > { > - int i; > uint8_t data; > + time_t st, now; > > /* Wait with a 5 second timeout */ > - for (i = 0; i <= 12500000; i++) { > + time(&st); > + while (true) { > data = inb(IDE_BASE + reg_status); > if (!(data & flag)) { > return data; > } > + time(&now); > + if (difftime(now, st) > 5.0) { > + break; > + } > nsleep(400); > } > g_assert_not_reached(); > @@ -658,14 +663,19 @@ static uint8_t ide_wait_clear(uint8_t flag) > > static void ide_wait_intr(int irq) > { > - int i; > + time_t st, now; > bool intr; > > - for (i = 0; i <= 12500000; i++) { > + time(&st); > + while (true) { > intr = get_irq(irq); > if (intr) { > return; > } > + time(&now); > + if (difftime(now, st) > 5.0) { > + break; > + } > nsleep(400); > } > > -- > 2.4.3 >