ide-test: fix failure for test_flush
PATCH 1/1 ide-test: fix failure for test_flush
bd07684aacfb61668ae2c25b7dd00b64f3d7c7f3 added a test to ensure BSY flag is set when a flush request is in flight. It does this by setting a blkdebug breakpoint on flush_to_os before issuing a CMD_FLUSH_CACHE. It then resumes CMD_FLUSH_CACHE operation and checks that BSY is unset.
The actual unsetting of BSY does not occur until ide_flush_cb gets called in a bh, however, so in some cases this check will race with the actual completion.
Fix this by polling the ide status register until BSY flag gets unset before we do our final sanity checks. According to f68ec8379e88502b4841a110c070e9b118d3151c this is in line with how a guest would determine whether or not the device is still busy.
--- tests/ide-test.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
tests/ide-test.c +4 -1
@@ -455,7 +455,10 @@ static void test_flush(void) data =inb (IDE_BASE + reg_device); g_assert_cmpint(data & DEV, ==, 0); - data =inb (IDE_BASE + reg_status); +do { + data =inb (IDE_BASE + reg_status); + }while (data &BSY ); +assert_bit_set (data,DRDY );assert_bit_clear (data,BSY |DF |ERR |DRQ );
Signature · 1 line
1.7.9.5
Kevin Wolf
AppliedAm 10.06.2013 um 20:23 hat Michael Roth geschrieben:
Quoted 9 lines
bd07684aacfb61668ae2c25b7dd00b64f3d7c7f3added a test to ensure BSY flag is set when a flush request is in flight. It does this by setting a blkdebug breakpoint onflush_to_osbefore issuing aCMD_FLUSH_CACHE. It then resumesCMD_FLUSH_CACHEoperation and checks that BSY is unset.The actual unsetting of BSY does not occur until
ide_flush_cbgets called in a bh, however, so in some cases this check will race with the actual completion.
Quoted 6 lines
Fix this by polling the ide status register until BSY flag gets unset before we do our final sanity checks. According to
f68ec8379e88502b4841a110c070e9b118d3151cthis is in line with how a guest would determine whether or not the device is still busy.Signed-off-by Michael Roth <[email protected]>
Thanks, applied to the block branch.
Kevin
Am 10.06.2013 20:23, schrieb Michael Roth:
Quoted 24 lines
bd07684aacfb61668ae2c25b7dd00b64f3d7c7f3added a test to ensure BSY flag is set when a flush request is in flight. It does this by setting a blkdebug breakpoint onflush_to_osbefore issuing aCMD_FLUSH_CACHE. It then resumesCMD_FLUSH_CACHEoperation and checks that BSY is unset.The actual unsetting of BSY does not occur until
ide_flush_cbgets called in a bh, however, so in some cases this check will race with the actual completion.Fix this by polling the ide status register until BSY flag gets unset before we do our final sanity checks. According to
f68ec8379e88502b4841a110c070e9b118d3151cthis is in line with how a guest would determine whether or not the device is still busy.Signed-off-by Michael Roth <[email protected]>--- tests/ide-test.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)tests/ide-test.c +0
-0
tests/ide-test.c static void test_flush(void) · line 460
Quoted 7 lines
tests/ide-test.c +3
-1@@ -455,7 +455,10 @@ static void test_flush(void) data =inb (IDE_BASE + reg_device); g_assert_cmpint(data & DEV, ==, 0); - data =inb (IDE_BASE + reg_status); +do { + data =inb (IDE_BASE + reg_status); + }while (data &BSY );
Is a busy loop really a good idea for a qtest? CC'ing Anthony. For the theoretical case that BSY is not cleared it might be better to terminate the loop with some timeout to get an assertion failure or at least use some form of sleep() to yield the thread while waiting?
tests/ide-test.c static void test_flush(void) · line 463
Quoted 3 lines
tests/ide-test.c +1
-0+assert_bit_set (data,DRDY );assert_bit_clear (data,BSY |DF |ERR |DRQ );
This BSY clear assertion will always be true now due to the above while condition; it won't if we change it though.
Regards,
Andreas
Quoted 1 line
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
Am 11.06.2013 um 12:05 hat Andreas Färber geschrieben:
Quoted 28 lines
Am 10.06.2013 20:23, schrieb Michael Roth:
Quoted 27 lines
bd07684aacfb61668ae2c25b7dd00b64f3d7c7f3added a test to ensure BSY flag is set when a flush request is in flight. It does this by setting a blkdebug breakpoint onflush_to_osbefore issuing aCMD_FLUSH_CACHE. It then resumesCMD_FLUSH_CACHEoperation and checks that BSY is unset.The actual unsetting of BSY does not occur until
ide_flush_cbgets called in a bh, however, so in some cases this check will race with the actual completion.Fix this by polling the ide status register until BSY flag gets unset before we do our final sanity checks. According to
f68ec8379e88502b4841a110c070e9b118d3151cthis is in line with how a guest would determine whether or not the device is still busy.Signed-off-by Michael Roth <[email protected]>--- tests/ide-test.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)tests/ide-test.c +0
-0@@ -455,7 +455,10 @@ static void test_flush(void) data =inb (IDE_BASE + reg_device); g_assert_cmpint(data & DEV, ==, 0);
Quoted 9 lines
tests/ide-test.c static void test_flush(void) · line 460
Quoted 4 lines
tests/ide-test.c +3
-1- data =inb (IDE_BASE + reg_status); +do { + data =inb (IDE_BASE + reg_status); + }while (data &BSY );Is a busy loop really a good idea for a qtest? CC'ing Anthony. For the theoretical case that BSY is not cleared it might be better to terminate the loop with some timeout to get an assertion failure or at least use some form of
sleep()to yield the thread while waiting?
FWIW, the floppy test already has a busy wait for IRQs, which results in the same failure mode. I think it's okay for a test case, but if someone felt like implementing timeouts, that would be great and we could apply them on top.
Kevin
Quoted 28 lines · Andreas Färber
Am 10.06.2013 20:23, schrieb Michael Roth:
Quoted 27 lines
bd07684aacfb61668ae2c25b7dd00b64f3d7c7f3added a test to ensure BSY flag is set when a flush request is in flight. It does this by setting a blkdebug breakpoint onflush_to_osbefore issuing aCMD_FLUSH_CACHE. It then resumesCMD_FLUSH_CACHEoperation and checks that BSY is unset.The actual unsetting of BSY does not occur until
ide_flush_cbgets called in a bh, however, so in some cases this check will race with the actual completion.Fix this by polling the ide status register until BSY flag gets unset before we do our final sanity checks. According to
f68ec8379e88502b4841a110c070e9b118d3151cthis is in line with how a guest would determine whether or not the device is still busy.Signed-off-by Michael Roth <[email protected]>--- tests/ide-test.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)tests/ide-test.c +0
-0@@ -455,7 +455,10 @@ static void test_flush(void) data =inb (IDE_BASE + reg_device); g_assert_cmpint(data & DEV, ==, 0);
Quoted 6 lines
tests/ide-test.c static void test_flush(void) · line 460
Quoted 4 lines
tests/ide-test.c +3
-1- data =inb (IDE_BASE + reg_status); +do { + data =inb (IDE_BASE + reg_status); + }while (data &BSY );Is a busy loop really a good idea for a qtest? CC'ing Anthony.
I'm not sure, my main justification was simply that we currently do it in ide-test for send_dma_request()
Quoted 4 lines
For the theoretical case that BSY is not cleared it might be better to terminate the loop with some timeout to get an assertion failure or at least use some form of
sleep()to yield the thread while waiting?
I don't think yielding/sleeping is too big a deal since we do a blocking read() on each iteration which i assume will result in a yield while the inb is being processed by qemu. Timeouts might be nice thing to add later though. What about something like this?
inb_wait(addr, testfn, opaque, timeout) {
while (timeout == -1 || timeout-- > 0) {
val = inb(addr);
if (testfn(val, opaque)) {
return val;
}
usleep(1000);
}
abort()
}It's not particularly precise, but for imposing a rough limit it should work.
Quoted 16 lines
tests/ide-test.c static void test_flush(void) · line 463
Quoted 3 lines
tests/ide-test.c +1
-0+assert_bit_set (data,DRDY );assert_bit_clear (data,BSY |DF |ERR |DRQ );This BSY clear assertion will always be true now due to the above while condition; it won't if we change it though.
Regards,
AndreasQuoted 1 line
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
Anthony Liguori
AppliedApplied. Thanks.
Regards,
Anthony Liguori