ltp-aiodio: sleep less time when waiting for target file creation
PATCH 1/2 ltp-aiodio: sleep less time when waiting for target file creation
dio_sparse calls read_sparse() to check the content of sparse file, which is direct written by another process. It waits for the file to be existent in a loop and sleeps 0.1s in each loop if the file isn't there yet.
But the sleep time is too long, if the target file doesn't exist in the first loop, the reading process might never read the file before it gets killed. e.g. Running ADSP045 on extN I got:
dio_sparse 0 TINFO : Dirtying free blocks dio_sparse 0 TINFO : Starting I/O tests Child 4554 waits for 'dio_sparse' to appear dio_sparse 0 TINFO : Killing childrens(s) dio_sparse 1 TPASS : Test passed)
The child for reading got killed before it read anything.
So shorten the sleep time, give the child a chance to read the file and really do the test.
dio_sparse 0 TINFO : Dirtying free blocks dio_sparse 0 TINFO : Starting I/O tests
Child 4767 waits for 'dio_sparse' to appear
Child 4767 has opened 'dio_sparse' for reading
Child 4767 loop 0
Child 4767 loop 1
dio_sparse 0 TINFO : Killing childrens(s) dio_sparse 1 TPASS : Test passed)
--- testcases/kernel/io/ltp-aiodio/common_sparse.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
testcases/kernel/io/ltp-aiodio/common_sparse.h +1 -1
@@ -123,7 +123,7 @@ static void read_sparse(char *filename, int filesize)fprintf (stderr,"Child %i waits for '%s' to appear\n" ,getpid (), filename); -usleep (100000 ); +usleep (10 ); }if (fd ==-1 ) {
Signature · 1 line
2.5.5
PATCH 2/2 ltp-aiodio: report posix_memalign errors properly
From posix_memalign(3) the value of errno is indeterminate after a call to posix_memalign(). So TERRNO doesn't work in this case.dio_sparse 1 TBROK : dio_sparse.c:75: posix_memalign(): errno=SUCCESS(0): Success
Report posix_memalign() errors by calling strerror on the return value.dio_sparse 1 TBROK : dio_sparse.c:74: posix_memalign(): Invalid argument
--- testcases/kernel/io/ltp-aiodio/dio_sparse.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
testcases/kernel/io/ltp-aiodio/dio_sparse.c +5 -3
@@ -28,6 +28,7 @@#include <signal.h> #include <fcntl.h> #include <stdio.h> +#include <string.h> #include <unistd.h> #include <memory.h> #include <sys/mman.h>
@@ -55,7 +56,7 @@ int TST_TOTAL = 1;*/ int dio_sparse (char *filename,int align,int writesize,int filesize) { -int fd; +int fd, ret;void *bufptr;int i, w;
@@ -68,9 +69,10 @@ int dio_sparse(char *filename, int align, int writesize, int filesize)SAFE_FTRUNCATE (cleanup, fd, filesize); -if (posix_memalign (&bufptr, align, writesize)) { + ret =posix_memalign (&bufptr, align, writesize); +if (ret) { +tst_resm (TBROK ,"posix_memalign(): %s" ,strerror (ret));close (fd); -tst_resm (TBROK |TERRNO ,"posix_memalign()" );return 1 ; }
Signature · 1 line
2.5.5
PATCH 2/2 ltp-aiodio: report posix_memalign errors properly
Hi!
Quoted 8 lines
int
dio_sparse(char *filename, int align, int writesize, int filesize){testcases/kernel/io/ltp-aiodio/dio_sparse.c +1
-1-int fd; +int fd, ret;void *bufptr;int i, w;
testcases/kernel/io/ltp-aiodio/dio_sparse.c int dio_sparse(char *filename, int align, int writesize, int filesize) · line 74
Quoted 7 lines
testcases/kernel/io/ltp-aiodio/dio_sparse.c +3
-1@@ -68,9 +69,10 @@ int dio_sparse(char *filename, int align, int writesize, int filesize)SAFE_FTRUNCATE (cleanup, fd, filesize); -if (posix_memalign (&bufptr, align, writesize)) { + ret =posix_memalign (&bufptr, align, writesize); +if (ret) { +tst_resm (TBROK ,"posix_memalign(): %s" ,strerror (ret));
We should use tst_strerrno() instead of strerror().
testcases/kernel/io/ltp-aiodio/dio_sparse.c int dio_sparse(char *filename, int align, int writesize, int filesize) · line 77
Quoted 4 lines
testcases/kernel/io/ltp-aiodio/dio_sparse.c +0
-1close (fd); -tst_resm (TBROK |TERRNO ,"posix_memalign()" );return 1 ; }
Otherwise this looks fine.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 2/2 ltp-aiodio: report posix_memalign errors properly
Quoted 10 lines · Cyril Hrubis
Hi!
Quoted 9 lines
int
dio_sparse(char *filename, int align, int writesize, int filesize){testcases/kernel/io/ltp-aiodio/dio_sparse.c +1
-1-int fd; +int fd, ret;void *bufptr;int i, w;@@ -68,9 +69,10 @@ int dio_sparse(char *filename, int align, int writesize, int filesize)
Quoted 8 lines
testcases/kernel/io/ltp-aiodio/dio_sparse.c int dio_sparse(char *filename, int align, int writesize, int filesize) · line 74
Quoted 6 lines
testcases/kernel/io/ltp-aiodio/dio_sparse.c +3
-1SAFE_FTRUNCATE (cleanup, fd, filesize); -if (posix_memalign (&bufptr, align, writesize)) { + ret =posix_memalign (&bufptr, align, writesize); +if (ret) { +tst_resm (TBROK ,"posix_memalign(): %s" ,strerror (ret));We should use
tst_strerrno()instead ofstrerror().
Thanks, new stuff learned, I'm still not so familiar with ltp APIs :)
Quoted 7 lines
testcases/kernel/io/ltp-aiodio/dio_sparse.c int dio_sparse(char *filename, int align, int writesize, int filesize) · line 77
Quoted 5 lines
testcases/kernel/io/ltp-aiodio/dio_sparse.c +0
-1close (fd); -tst_resm (TBROK |TERRNO ,"posix_memalign()" );return 1 ; }Otherwise this looks fine.
Thanks for the review!
Eryu
PATCH 1/2 ltp-aiodio: sleep less time when waiting for target file creation
In reply to Eryu GuanHi!
Quoted 39 lines
dio_sparsecallsread_sparse()to check the content of sparse file, which is direct written by another process. It waits for the file to be existent in a loop and sleeps 0.1s in each loop if the file isn't there yet.But the sleep time is too long, if the target file doesn't exist in the first loop, the reading process might never read the file before it gets killed. e.g. Running ADSP045 on extN I got:
dio_sparse 0 TINFO : Dirtying free blocks dio_sparse 0 TINFO : Starting I/O tests Child 4554 waits for 'dio_sparse' to appear dio_sparse 0 TINFO : Killing childrens(s) dio_sparse 1 TPASS : Test passed)The child for reading got killed before it read anything.
So shorten the sleep time, give the child a chance to read the file and really do the test.
dio_sparse 0 TINFO : Dirtying free blocks dio_sparse 0 TINFO : Starting I/O testsChild 4767 waits for '
dio_sparse' to appear
Child 4767 has opened 'dio_sparse' for reading
Child 4767 loop 0
Child 4767 loop 1dio_sparse 0 TINFO : Killing childrens(s) dio_sparse 1 TPASS : Test passed)Signed-off-by Eryu Guan <[email protected]>--- testcases/kernel/io/ltp-aiodio/common_sparse.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)testcases/kernel/io/ltp-aiodio/common_sparse.h +0
-0
testcases/kernel/io/ltp-aiodio/common_sparse.h static void read_sparse(char *filename, int filesize) · line 126
Quoted 5 lines
testcases/kernel/io/ltp-aiodio/common_sparse.h +1
-1@@ -123,7 +123,7 @@ static void read_sparse(char *filename, int filesize)fprintf (stderr,"Child %i waits for '%s' to appear\n" ,getpid (), filename); -usleep (100000 ); +usleep (10 );
This is just another band aid instead of fixing the real problem. Why don't we use real synchronization instead?
What about we do:
* Remove the loops that kills children from the parent
* Limit the number of iterations in read_sparse to something more reasonable, i.e. 10 or so
That way the parent would actually wait for the children to read the file in the loop that does wait().
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 1/2 ltp-aiodio: sleep less time when waiting for target file creation
Quoted 43 lines · Cyril Hrubis
Hi!
Quoted 42 lines
dio_sparsecallsread_sparse()to check the content of sparse file, which is direct written by another process. It waits for the file to be existent in a loop and sleeps 0.1s in each loop if the file isn't there yet.But the sleep time is too long, if the target file doesn't exist in the first loop, the reading process might never read the file before it gets killed. e.g. Running ADSP045 on extN I got:
dio_sparse 0 TINFO : Dirtying free blocks dio_sparse 0 TINFO : Starting I/O tests Child 4554 waits for 'dio_sparse' to appear dio_sparse 0 TINFO : Killing childrens(s) dio_sparse 1 TPASS : Test passed)The child for reading got killed before it read anything.
So shorten the sleep time, give the child a chance to read the file and really do the test.
dio_sparse 0 TINFO : Dirtying free blocks dio_sparse 0 TINFO : Starting I/O testsChild 4767 waits for '
dio_sparse' to appear
Child 4767 has opened 'dio_sparse' for reading
Child 4767 loop 0
Child 4767 loop 1dio_sparse 0 TINFO : Killing childrens(s) dio_sparse 1 TPASS : Test passed)Signed-off-by Eryu Guan <[email protected]>--- testcases/kernel/io/ltp-aiodio/common_sparse.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)testcases/kernel/io/ltp-aiodio/common_sparse.h +0
-0@@ -123,7 +123,7 @@ static void read_sparse(char *filename, int filesize)fprintf (stderr,"Child %i waits for '%s' to appear\n" ,getpid (), filename);
Quoted 5 lines
testcases/kernel/io/ltp-aiodio/common_sparse.h static void read_sparse(char *filename, int filesize) · line 126
Quoted 2 lines
testcases/kernel/io/ltp-aiodio/common_sparse.h +1
-1-usleep (100000 ); +usleep (10 );This is just another band aid instead of fixing the real problem. Why don't we use real synchronization instead?
You're right, fixing the synchronization is the right way to go, I'll think more and test more about it, thanks!
Eryu
Quoted 13 lines
What about we do:
* Remove the loops that kills children from the parent
* Limit the number of iterations inread_sparseto something more reasonable, i.e. 10 or soThat way the parent would actually wait for the children to read the file in the loop that does
wait().Signature · 2 lines
Cyril Hrubis [email protected]