From: Subrata <ris...@li...> - 2010-07-03 17:41:26
|
The branch, master, has been updated via 65f7070cb3f67eba009e68413187727f508623e1 (commit) via 785ef40630157d66067b1577a238184e0170e383 (commit) via bd2dce17303a69463e926bb5a6a955e7890f65f3 (commit) via a9e2238be689fd8e4d25bc7eefca1cb11535ce7a (commit) via 5305c4a10cf26799c81e6f0362750988457d3002 (commit) via a21dab25b7ef183d049b31b0d3fed1d48c16dc2b (commit) via b4f57c7d26b58f3d80b46340f10a397d21957866 (commit) via 76a720a381f351b33eb203c7c519e6f44bbe7219 (commit) from 13adcb0c4496e75bdcdbc02410b46b9fbc6120a8 (commit) - Log ----------------------------------------------------------------- commit 65f7070cb3f67eba009e68413187727f508623e1 Author: Subrata Modak <sub...@su...> Date: Sat Jul 3 23:10:38 2010 +0530 From: gowrishankar <gow...@li...> In a scenario where a thread other than high priority noise thread is scheduled after the barrier, a priority inversion will not occur, defeating the purpose of test. We need to tightly synchronize the threads so that the noise thread always begins the test and gets preempted by the low prio thread through the PI logic. This change is applied on testpi-4. Signed-off-by: Gowrishankar<gow...@in...> Tested-by: Gowrishankar<gow...@in...> Acked-by: Darren Hart <dv...@us...> commit 785ef40630157d66067b1577a238184e0170e383 Author: Subrata Modak <sub...@su...> Date: Sat Jul 3 23:10:14 2010 +0530 From: gowrishankar <gow...@li...> testpi-4 defines THREAD_STOP which is not used anywhere in the program. Signed-off-by: Gowrishankar <gow...@in...> Tested-by: Gowrishankar <gow...@in...> Acked-by: Darren Hart <dv...@us...> commit bd2dce17303a69463e926bb5a6a955e7890f65f3 Author: Subrata Modak <sub...@su...> Date: Sat Jul 3 23:09:55 2010 +0530 From: gowrishankar <gow...@li...> Instead of lock/unlock of mutex to burn cpu cycles, we can use busy_work_ms from librttest which is more explicit (burn cycles, not provide some synchronization). Also this patch removes the id increment since it is not used. Signed-off-by: Gowrishankar <gow...@in...> Tested-by: Gowrishankar <gow...@in...> Acked-by: Darren Hart <dv...@us...> commit a9e2238be689fd8e4d25bc7eefca1cb11535ce7a Author: Subrata Modak <sub...@su...> Date: Sat Jul 3 23:09:32 2010 +0530 From: gowrishankar <gow...@li...> Since main() sets the cpu affinity, it is not necessary for the spawned threads to do so, as the threads inherit the cpu affinity. Signed-off-by: Gowrishankar <gow...@in...> Tested-by: Gowrishankar <gow...@in...> Acked-by: Darren Hart <dv...@us...> commit 5305c4a10cf26799c81e6f0362750988457d3002 Author: Subrata Modak <sub...@su...> Date: Sat Jul 3 23:09:02 2010 +0530 From: gowrishankar <gow...@li...> This patch adds the description to the test testpi-4. Signed-off-by: Gowrishankar <gow...@in...> Tested-by: Gowrishankar <gowrishankar.m@in.ibm. commit a21dab25b7ef183d049b31b0d3fed1d48c16dc2b Author: Subrata Modak <sub...@su...> Date: Sat Jul 3 23:06:38 2010 +0530 From: gowrishankar <gow...@li...> testpi-4 is initializing mutex step by step which can be done by reusing the init_pi_mutex() funtion available in librttest. Signed-off-by: Gowrishankar <gow...@in...> Tested-by: Gowrishankar <gow...@in...> Acked-by: Darren Hart <dv...@us...> commit b4f57c7d26b58f3d80b46340f10a397d21957866 Author: Subrata Modak <sub...@su...> Date: Sat Jul 3 23:06:16 2010 +0530 From: gowrishankar <gow...@li...> This patch cleans up the testpi-4 so as to follow the C coding style standards. Signed-off-by: Gowrishankar <gow...@in...> Tested-by: Gowrishankar <gow...@in...> Acked-by: Darren Hart <dv...@us...> commit 76a720a381f351b33eb203c7c519e6f44bbe7219 Author: Subrata Modak <sub...@su...> Date: Sat Jul 3 21:08:18 2010 +0530 While executing the ltp on an nfs root mounted system, I faced a problem with some of the ltp test cases. These tests either did not close their file descriptors or did no unmap the mmaped files. This results in a failures while trying to clean up the temporary directory of the testcase. I have fixed all of the above tests with the following patch. Signed-off-by: Darshak P Shah<dar...@li...>, ----------------------------------------------------------------------- Summary of changes: testcases/kernel/io/direct_io/diotest2.c | 1 + testcases/kernel/io/direct_io/diotest3.c | 1 + testcases/kernel/io/direct_io/diotest5.c | 1 + testcases/kernel/io/direct_io/diotest6.c | 1 + testcases/kernel/mem/mmapstress/mmapstress01.c | 7 +- testcases/kernel/mem/mmapstress/mmapstress02.c | 4 + testcases/kernel/mem/mmapstress/mmapstress05.c | 9 + testcases/kernel/mem/mmapstress/mmapstress10.c | 122 +++++++--- testcases/kernel/syscalls/open/open10.c | 5 + testcases/kernel/syscalls/ppoll/ppoll01.c | 4 +- testcases/kernel/syscalls/splice/splice02.c | 1 + testcases/kernel/syscalls/utimes/utimes01.c | 2 + testcases/realtime/func/pi-tests/testpi-4.c | 329 +++++++++++------------- 13 files changed, 275 insertions(+), 212 deletions(-) diff --git a/testcases/kernel/io/direct_io/diotest2.c b/testcases/kernel/io/direct_io/diotest2.c index fb87094..d2e63f2 100644 --- a/testcases/kernel/io/direct_io/diotest2.c +++ b/testcases/kernel/io/direct_io/diotest2.c @@ -275,6 +275,7 @@ static void setup(void) if ((fd1 = open(filename, O_DIRECT, 0600)) < 0) { tst_brkm(TCONF, cleanup, "O_DIRECT is not supported by this filesystem. %s", strerror(errno)); } + close(fd1); } diff --git a/testcases/kernel/io/direct_io/diotest3.c b/testcases/kernel/io/direct_io/diotest3.c index 5ef5d67..1f3e5c9 100644 --- a/testcases/kernel/io/direct_io/diotest3.c +++ b/testcases/kernel/io/direct_io/diotest3.c @@ -363,6 +363,7 @@ static void setup(void) if ((fd1 = open(filename, O_DIRECT, 0600)) < 0) { tst_brkm(TCONF, cleanup, "O_DIRECT is not supported by this filesystem. %s", strerror(errno)); } + close(fd1); } static void cleanup(void) diff --git a/testcases/kernel/io/direct_io/diotest5.c b/testcases/kernel/io/direct_io/diotest5.c index bda2291..6703d5d 100644 --- a/testcases/kernel/io/direct_io/diotest5.c +++ b/testcases/kernel/io/direct_io/diotest5.c @@ -309,6 +309,7 @@ static void setup(void) if ((fd1 = open(filename, O_DIRECT, 0600)) < 0) { tst_brkm(TCONF, cleanup, "O_DIRECT is not supported by this filesystem. %s", strerror(errno)); } + close(fd1); } static void cleanup(void) diff --git a/testcases/kernel/io/direct_io/diotest6.c b/testcases/kernel/io/direct_io/diotest6.c index 65718ca..9d68cb1 100644 --- a/testcases/kernel/io/direct_io/diotest6.c +++ b/testcases/kernel/io/direct_io/diotest6.c @@ -387,6 +387,7 @@ static void setup(void) if ((fd1 = open(filename, O_DIRECT, 0600)) < 0) { tst_brkm(TCONF, cleanup, "O_DIRECT is not supported by this filesystem. %s", strerror(errno)); } + close(fd1); } static void cleanup(void) diff --git a/testcases/kernel/mem/mmapstress/mmapstress01.c b/testcases/kernel/mem/mmapstress/mmapstress01.c index 0de81c1..8a6219f 100644 --- a/testcases/kernel/mem/mmapstress/mmapstress01.c +++ b/testcases/kernel/mem/mmapstress/mmapstress01.c @@ -590,7 +590,11 @@ child_mapper(char *file, unsigned procno, unsigned nprocs) anyfail(); } } - + if (munmap(maddr, mapsize) == -1) { + perror("munmap failed"); + local_flag = FAILED; + anyfail(); + } exit(0); } @@ -694,6 +698,7 @@ fileokay(char *file, uchar_t *expbuf) } } } + close(fd); return 1; } diff --git a/testcases/kernel/mem/mmapstress/mmapstress02.c b/testcases/kernel/mem/mmapstress/mmapstress02.c index f801a2e..8ed46f6 100644 --- a/testcases/kernel/mem/mmapstress/mmapstress02.c +++ b/testcases/kernel/mem/mmapstress/mmapstress02.c @@ -165,6 +165,10 @@ main(int argc, char *argv[]) { CLEANERROR("close failed"); anyfail(); } + if (munmap(mmapaddr, pagesize) == -1) { + CLEANERROR("munmap failed"); + anyfail(); + } if (unlink(tmpname) == -1) { ERROR("unlink failed"); anyfail(); diff --git a/testcases/kernel/mem/mmapstress/mmapstress05.c b/testcases/kernel/mem/mmapstress/mmapstress05.c index 4d25b8d..6a857e1 100644 --- a/testcases/kernel/mem/mmapstress/mmapstress05.c +++ b/testcases/kernel/mem/mmapstress/mmapstress05.c @@ -61,6 +61,15 @@ void ok_exit(); #define ERROR(M) (void)fprintf(stderr, "%s: errno = %d; " M "\n", \ progname, errno); #define CLEAN (void)close(fd); \ + if (munmap(mmapaddr+pagesize, pagesize) == -1) { \ + ERROR("munmap failed"); \ + } \ + if (munmap(mmapaddr, pagesize) == -1) { \ + ERROR("munmap failed"); \ + } \ + if (munmap(mmapaddr+2*pagesize, pagesize) == -1) { \ + ERROR("munmap failed"); \ + } \ if (unlink(tmpname)) { \ ERROR("couldn't clean up temp file"); \ } diff --git a/testcases/kernel/mem/mmapstress/mmapstress10.c b/testcases/kernel/mem/mmapstress/mmapstress10.c index 33c7dd8..ca5418e 100644 --- a/testcases/kernel/mem/mmapstress/mmapstress10.c +++ b/testcases/kernel/mem/mmapstress/mmapstress10.c @@ -154,6 +154,15 @@ unsigned do_offset = 0; unsigned pattern = 0; char filename[64]; +void clean_mapper(int sig); +void clean_writer(int sig); + +int fd_mapper = 0; +caddr_t maddr_mapper; +size_t mapsize_mapper; + +int fd_writer = 0; + int main(int argc, char *argv[]) { @@ -484,8 +493,8 @@ main(int argc, char *argv[]) cleanup: for (i = 0; i < nprocs; i++) - (void)kill(pidarray[i], SIGKILL); - (void)kill(wr_pid, SIGKILL); + (void)kill(pidarray[i], SIGUSR1); + (void)kill(wr_pid, SIGUSR1); while (wait(&wait_stat) != -1 || errno != ECHILD) continue; @@ -531,9 +540,7 @@ child_mapper(char *file, unsigned procno, unsigned nprocs) off_t offset; #endif /* LARGE_FILE */ size_t validsize; - size_t mapsize; - caddr_t maddr, paddr; - int fd; + caddr_t paddr; int pagesize = sysconf(_SC_PAGE_SIZE); unsigned randpage; unsigned int seed; @@ -542,25 +549,38 @@ child_mapper(char *file, unsigned procno, unsigned nprocs) unsigned mappages; unsigned mapflags; unsigned i; + struct sigaction sa_mapper; mapflags = MAP_SHARED; seed = initrand(); /* initialize random seed */ + sa_mapper.sa_handler = clean_mapper; + sa_mapper.sa_flags = 0; + if (sigemptyset(&sa_mapper.sa_mask)) { + perror("sigempty error"); + anyfail(); + } + + if (sigaction(SIGUSR1, &sa_mapper, 0) == -1) { + perror("sigaction error SIGUSR1"); + anyfail(); + } + #ifdef LARGE_FILE - if ((fd = open64(file, O_RDWR)) == -1) { + if ((fd_mapper = open64(file, O_RDWR)) == -1) { #else /* LARGE_FILE */ - if ((fd = open(file, O_RDWR)) == -1) { + if ((fd_mapper = open(file, O_RDWR)) == -1) { #endif /* LARGE_FILE */ perror("open error"); anyfail(); } #ifdef LARGE_FILE - if (fstat64(fd, &statbuf) == -1) { + if (fstat64(fd_mapper, &statbuf) == -1) { #else /* LARGE_FILE */ - if (fstat(fd, &statbuf) == -1) { + if (fstat(fd_mapper, &statbuf) == -1) { #endif /* LARGE_FILE */ perror("stat error"); anyfail(); @@ -571,29 +591,29 @@ child_mapper(char *file, unsigned procno, unsigned nprocs) fprintf(stderr, "size_t overflow when setting up map\n"); anyfail(); } - mapsize = (size_t)(statbuf.st_size - sparseoffset); - mappages = roundup(mapsize, pagesize) / pagesize; + mapsize_mapper = (size_t)(statbuf.st_size - sparseoffset); + mappages = roundup(mapsize_mapper, pagesize) / pagesize; offset = sparseoffset; if (do_offset) { int pageoffset = lrand48() % mappages; int byteoffset = pageoffset * pagesize; offset += byteoffset; - mapsize -= byteoffset; + mapsize_mapper -= byteoffset; mappages -= pageoffset; } #ifdef LARGE_FILE - if ((maddr = mmap64(0, mapsize, PROT_READ|PROT_WRITE, - mapflags, fd, offset)) == (caddr_t)-1) { + if ((maddr_mapper = mmap64(0, mapsize_mapper, PROT_READ|PROT_WRITE, + mapflags, fd_mapper, offset)) == (caddr_t)-1) { #else /* LARGE_FILE */ - if ((maddr = mmap(0, mapsize, PROT_READ|PROT_WRITE, - mapflags, fd, offset)) == (caddr_t)-1) { + if ((maddr_mapper = mmap(0, mapsize_mapper, PROT_READ|PROT_WRITE, + mapflags, fd_mapper, offset)) == (caddr_t)-1) { #endif /* LARGE_FILE */ perror("mmap error"); anyfail(); } - (void)close(fd); + (void)close(fd_mapper); nloops = (randloops) ? (lrand48() % MAXLOOPS) : MAXLOOPS; @@ -601,12 +621,12 @@ child_mapper(char *file, unsigned procno, unsigned nprocs) #ifdef LARGE_FILE (void)printf("child %d (pid %ld): seed %d, fsize %Ld, " "mapsize %d, off %Ld, loop %d\n", - procno, getpid(), seed, filesize, mapsize, + procno, getpid(), seed, filesize, mapsize_mapper, offset/pagesize, nloops); #else /* LARGE_FILE */ (void)printf("child %d (pid %d): seed %d, fsize %ld, " "mapsize %ld, off %ld, loop %d\n", - procno, getpid(), seed, filesize, (long)mapsize, + procno, getpid(), seed, filesize, (long)mapsize_mapper, offset/pagesize, nloops); #endif /* LARGE_FILE */ } @@ -616,13 +636,13 @@ child_mapper(char *file, unsigned procno, unsigned nprocs) */ for (loopcnt = 0; loopcnt < nloops; loopcnt++) { randpage = lrand48() % mappages; - paddr = maddr + (randpage * pagesize); /* page address */ + paddr = maddr_mapper + (randpage * pagesize); /* page address */ if (randpage < mappages - 1 - || !(mapsize % pagesize)) + || !(mapsize_mapper % pagesize)) validsize = pagesize; else - validsize = mapsize % pagesize; + validsize = mapsize_mapper % pagesize; /* * Because one child is mapping file in extend mode, @@ -652,14 +672,17 @@ child_mapper(char *file, unsigned procno, unsigned nprocs) * Exercise msync() as well! */ randpage = lrand48() % mappages; - paddr = maddr + (randpage * pagesize); /* page address */ + paddr = maddr_mapper + (randpage * pagesize); /* page address */ if (msync(paddr, (mappages - randpage)*pagesize, MS_SYNC) == -1) { perror("msync error"); anyfail(); } } - + if ( munmap(maddr_mapper,mapsize_mapper) == -1 ) { + perror("munmap failed"); + anyfail(); + } exit(0); } @@ -675,7 +698,20 @@ child_mapper(char *file, unsigned procno, unsigned nprocs) void child_writer(char *file, uchar_t *buf) /* buf already set up in main */ { - int fd; + struct sigaction sa_writer; + + sa_writer.sa_handler = clean_writer; + sa_writer.sa_flags = 0; + if (sigemptyset(&sa_writer.sa_mask)) { + perror("sigempty error"); + anyfail(); + } + + if (sigaction(SIGUSR1, &sa_writer, 0) == -1) { + perror("sigaction error SIGUSR1"); + anyfail(); + } + #ifdef LARGE_FILE struct stat64 statbuf; off64_t off; @@ -688,18 +724,18 @@ child_writer(char *file, uchar_t *buf) /* buf already set up in main */ int cnt; #ifdef LARGE_FILE - if ((fd = open64(file, O_RDWR)) == -1) { + if ((fd_writer = open64(file, O_RDWR)) == -1) { #else /* LARGE_FILE */ - if ((fd = open(file, O_RDWR)) == -1) { + if ((fd_writer = open(file, O_RDWR)) == -1) { #endif /* LARGE_FILE */ perror("open error"); anyfail(); } #ifdef LARGE_FILE - if ((off = lseek64(fd, 0, SEEK_END)) == -1) { + if ((off = lseek64(fd_writer, 0, SEEK_END)) == -1) { #else /* LARGE_FILE */ - if ((off = lseek(fd, 0, SEEK_END)) == -1) { + if ((off = lseek(fd_writer, 0, SEEK_END)) == -1) { #endif /* LARGE_FILE */ perror("lseek error"); anyfail(); @@ -708,9 +744,9 @@ child_writer(char *file, uchar_t *buf) /* buf already set up in main */ for (;;) { #ifdef LARGE_FILE - if (fstat64(fd, &statbuf) == -1) { + if (fstat64(fd_writer, &statbuf) == -1) { #else /* LARGE_FILE */ - if (fstat(fd, &statbuf) == -1) { + if (fstat(fd_writer, &statbuf) == -1) { #endif /* LARGE_FILE */ perror("fstat error"); anyfail(); @@ -734,7 +770,7 @@ child_writer(char *file, uchar_t *buf) /* buf already set up in main */ p = buf + (off % pagesize); - if ((cnt = write(fd, p, growsize)) != growsize) { + if ((cnt = write(fd_writer, p, growsize)) != growsize) { if (cnt == -1) perror("write error"); else @@ -747,12 +783,13 @@ child_writer(char *file, uchar_t *buf) /* buf already set up in main */ (void)sleep(sleeptime); if (dosync) { - if (fsync(fd) == -1) { + if (fsync(fd_writer) == -1) { perror("fsync error"); anyfail(); } } } + close(fd_writer); } @@ -814,6 +851,7 @@ fileokay(char *file, uchar_t *expbuf) cnt = read(fd, (char *)readbuf, pagesize); if (cnt == -1) { perror("read error"); + close(fd); return 0; } else if (cnt != pagesize) { /* @@ -822,6 +860,7 @@ fileokay(char *file, uchar_t *expbuf) if ((i * pagesize) + cnt != mapsize) { (void)fprintf(stderr, "read %d of %ld bytes\n", (i*pagesize)+cnt, (long)mapsize); + close(fd); return 0; } } @@ -841,6 +880,7 @@ fileokay(char *file, uchar_t *expbuf) (void)fprintf(stderr, ", pg %d off %d, " "(fsize %ld)\n", i, j, statbuf.st_size); #endif /* LARGE_FILE */ + close(fd); return 0; } } @@ -866,6 +906,21 @@ clean_up_file(int sig) exit(1); } +void clean_mapper(int sig) +{ + if (fd_mapper) + close(fd_mapper); + munmap(maddr_mapper,mapsize_mapper); + exit (0); +} + +void clean_writer(int sig) +{ + if (fd_writer) + close(fd_writer); + exit(0); +} + unsigned int initrand(void) { @@ -887,7 +942,6 @@ initrand(void) return (seed); } - /***** LTP Port *****/ void ok_exit() { diff --git a/testcases/kernel/syscalls/open/open10.c b/testcases/kernel/syscalls/open/open10.c index 48aca44..ac015ef 100644 --- a/testcases/kernel/syscalls/open/open10.c +++ b/testcases/kernel/syscalls/open/open10.c @@ -282,6 +282,7 @@ int main(int ac, char *av[]) tst_resm(TFAIL|TERRNO, "open(%s) failed", nosetgid_A); local_flag = FAILED; } + close(ret); if ((ret = stat(nosetgid_A, &buf)) < 0) { tst_resm(TFAIL|TERRNO, "stat(%s) failed", nosetgid_A); @@ -310,6 +311,7 @@ int main(int ac, char *av[]) tst_resm(TFAIL|TERRNO, "open(%s) failed", setgid_A); local_flag = FAILED; } + close(ret); if ((ret = stat(setgid_A, &buf)) < 0) { tst_resm(TFAIL|TERRNO, "stat(%s) failed", setgid_A); @@ -357,6 +359,7 @@ int main(int ac, char *av[]) tst_resm(TFAIL|TERRNO, "open(%s) failed", nosetgid_B); local_flag = FAILED; } + close(ret); if ((ret = stat(nosetgid_B, &buf)) < 0) { tst_resm(TFAIL|TERRNO, "stat(%s) failed", nosetgid_B); @@ -386,6 +389,7 @@ int main(int ac, char *av[]) tst_resm(TFAIL|TERRNO, "open(%s) failed", setgid_B); local_flag = FAILED; } + close(ret); if ((ret = stat(setgid_B, &buf)) < 0) { tst_resm(TFAIL|TERRNO, "stat(%s) failed", setgid_B); @@ -436,6 +440,7 @@ int main(int ac, char *av[]) tst_resm(TFAIL|TERRNO, "open(%s) failed", root_setgid_B); local_flag = FAILED; } + close(ret); if ((ret = stat(root_setgid_B, &buf)) < 0) { tst_resm(TFAIL|TERRNO, "stat(%s) failed", root_setgid_B); diff --git a/testcases/kernel/syscalls/ppoll/ppoll01.c b/testcases/kernel/syscalls/ppoll/ppoll01.c index a41a840..f192a4a 100644 --- a/testcases/kernel/syscalls/ppoll/ppoll01.c +++ b/testcases/kernel/syscalls/ppoll/ppoll01.c @@ -378,8 +378,10 @@ static int do_test(struct test_case *tc) { } result |= (sys_errno != tc->err) || !cmp_ok; PRINT_RESULT_CMP(sys_ret >= 0, tc->ret, tc->err, sys_ret, sys_errno, cmp_ok); - cleanup: if (fd >= 0) + cleanup: if (fd >= 0) { + close(fd); cleanup_file(fpath); + } sigemptyset(&sigmask); sigprocmask(SIG_SETMASK, &sigmask, NULL); diff --git a/testcases/kernel/syscalls/splice/splice02.c b/testcases/kernel/syscalls/splice/splice02.c index 3b3e4fd..b581a67 100644 --- a/testcases/kernel/syscalls/splice/splice02.c +++ b/testcases/kernel/syscalls/splice/splice02.c @@ -148,6 +148,7 @@ int main(int ac, char **av) { } else if (TEST_RETURN == 0){ tst_resm(TPASS, "splice() system call Passed"); + close(fd); cleanup(); tst_exit(); } diff --git a/testcases/kernel/syscalls/utimes/utimes01.c b/testcases/kernel/syscalls/utimes/utimes01.c index ae2fa2d..30f12c0 100644 --- a/testcases/kernel/syscalls/utimes/utimes01.c +++ b/testcases/kernel/syscalls/utimes/utimes01.c @@ -234,6 +234,8 @@ static int do_test(struct test_case *tc) TEST(rc = setup_file(TESTDIR, "test.file", fpath)); if (rc < 0) return 1; + /* The test just needs the file, so no need to keep it open. */ + close(rc); /* * Change effective user id diff --git a/testcases/realtime/func/pi-tests/testpi-4.c b/testcases/realtime/func/pi-tests/testpi-4.c index 1756588..63f8430 100644 --- a/testcases/realtime/func/pi-tests/testpi-4.c +++ b/testcases/realtime/func/pi-tests/testpi-4.c @@ -20,8 +20,8 @@ * testpi-4.c * * DESCRIPTION - * - * + * This testcase verifies that the SCHED_OTHER thread can preempt + * the SCHED_RR thread via priority inheritance. * * USAGE: * Use run_auto.sh script in current directory to build and run test. @@ -30,7 +30,9 @@ * * * HISTORY - * + * 2010-06-29 Thread synchronization changes by using + * conditional variables by Gowrishankar. + * by Gowrishankar <gow...@in...> * *****************************************************************************/ @@ -49,201 +51,176 @@ pthread_barrier_t barrier; void usage(void) { - rt_help(); - printf("testpi-4 specific options:\n"); + rt_help(); + printf("testpi-4 specific options:\n"); } int parse_args(int c, char *v) { - - int handled = 1; - switch (c) { - case 'h': - usage(); - exit(0); - default: - handled = 0; - break; - } - return handled; + int handled = 1; + switch (c) { + case 'h': + usage(); + exit(0); + default: + handled = 0; + break; + } + return handled; } int gettid(void) { - return syscall(__NR_gettid); + return syscall(__NR_gettid); } -typedef void* (*entrypoint_t)(void*); - -#define THREAD_STOP 1 - +typedef void *(*entrypoint_t)(void *); pthread_mutex_t *glob_mutex; +static pthread_mutex_t cond_mutex = PTHREAD_MUTEX_INITIALIZER; +static pthread_cond_t cond_var = PTHREAD_COND_INITIALIZER; -void* func_nonrt(void* arg) +void *func_nonrt(void *arg) { - struct thread* pthr = (struct thread* )arg; - int rc, i, j, tid = gettid(); - cpu_set_t mask; - CPU_ZERO(&mask); - CPU_SET(0, &mask); - - rc = sched_setaffinity(0, sizeof(mask), &mask); - if (rc < 0) { - printf("Thread %d: Can't set affinity: %d %s\n", tid, rc, strerror(rc)); - exit(-1); - } - - printf("Thread %d started running with priority %d\n", tid, pthr->priority); - pthread_mutex_lock(glob_mutex); - printf("Thread %d at start pthread pol %d pri %d - Got global lock\n", tid, pthr->policy, pthr->priority); - pthread_barrier_wait(&barrier); - - for (i=0;i<10000;i++) { - if (i%100 == 0) { - printf("Thread %d loop %d pthread pol %d pri %d\n", tid, i, pthr->policy, pthr->priority); - fflush(NULL); - } - pthr->id++; - for (j=0;j<5000;j++) { - pthread_mutex_lock(&(pthr->mutex)); - pthread_mutex_unlock(&(pthr->mutex)); - } - } - pthread_mutex_unlock(glob_mutex); - return NULL; + struct thread *pthr = (struct thread *)arg; + int i, tid = gettid(); + + printf("Thread %d started running with priority %d\n", tid, + pthr->priority); + pthread_mutex_lock(glob_mutex); + printf("Thread %d at start pthread pol %d pri %d - Got global lock\n", + tid, pthr->policy, pthr->priority); + + /* Wait for other RT threads to start up */ + pthread_barrier_wait(&barrier); + + /* Wait for the high priority noise thread to start and signal us */ + pthread_mutex_lock(&cond_mutex); + pthread_cond_wait(&cond_var, &cond_mutex); + pthread_mutex_unlock(&cond_mutex); + + for (i = 0; i < 10000; i++) { + if (i%100 == 0) { + printf("Thread %d loop %d pthread pol %d pri %d\n", + tid, i, pthr->policy, pthr->priority); + fflush(NULL); + } + busy_work_ms(1); + } + pthread_mutex_unlock(glob_mutex); + return NULL; } -void* func_rt(void* arg) +void *func_rt(void *arg) { - struct thread* pthr = (struct thread* )arg; - int rc, i, j, tid = gettid(); - cpu_set_t mask; - CPU_ZERO(&mask); - CPU_SET(0, &mask); - - rc = sched_setaffinity(0, sizeof(mask), &mask); - if (rc < 0) { - printf("Thread %d: Can't set affinity: %d %s\n", tid, rc, strerror(rc)); - exit(-1); - } - - printf("Thread %d started running with prio %d\n", tid, pthr->priority); - pthread_barrier_wait(&barrier); - pthread_mutex_lock(glob_mutex); - printf("Thread %d at start pthread pol %d pri %d - Got global lock\n", tid, pthr->policy, pthr->priority); - - /* we just use the mutex as something to slow things down */ - /* say who we are and then do nothing for a while. The aim - * of this is to show that high priority threads make more - * progress than lower priority threads.. - */ - for (i=0;i<1000;i++) { - if (i%100 == 0) { - printf("Thread %d loop %d pthread pol %d pri %d\n", tid, i, pthr->policy, pthr->priority); - fflush(NULL); - } - pthr->id++; - for (j=0;j<5000;j++) { - pthread_mutex_lock(&(pthr->mutex)); - pthread_mutex_unlock(&(pthr->mutex)); - } - } - pthread_mutex_unlock(glob_mutex); - return NULL; + struct thread *pthr = (struct thread *)arg; + int i, tid = gettid(); + + printf("Thread %d started running with prio %d\n", tid, + pthr->priority); + pthread_barrier_wait(&barrier); + pthread_mutex_lock(glob_mutex); + printf("Thread %d at start pthread pol %d pri %d - Got global lock\n", + tid, pthr->policy, pthr->priority); + + /* we just use the mutex as something to slow things down, + * say who we are and then do nothing for a while. The aim + * of this is to show that high priority threads make more + * progress than lower priority threads.. + */ + for (i = 0; i < 1000; i++) { + if (i%100 == 0) { + printf("Thread %d loop %d pthread pol %d pri %d\n", + tid, i, pthr->policy, pthr->priority); + fflush(NULL); + } + busy_work_ms(1); + } + pthread_mutex_unlock(glob_mutex); + return NULL; } -void* func_noise(void* arg) +void *func_noise(void *arg) { - struct thread* pthr = (struct thread* )arg; - int rc, i, j, tid = gettid(); - cpu_set_t mask; - CPU_ZERO(&mask); - CPU_SET(0, &mask); - - rc = sched_setaffinity(0, sizeof(mask), &mask); - if (rc < 0) { - printf("Thread %d: Can't set affinity: %d %s\n", tid, rc, strerror(rc)); - exit(-1); - } - - printf("Noise Thread started running with prio %d\n", pthr->priority); - pthread_barrier_wait(&barrier); - - for (i=0;i<10000;i++) { - if (i%100 == 0) { - printf("Noise Thread %d loop %d pthread pol %d pri %d\n", tid, i, pthr->policy, pthr->priority); - fflush(NULL); - } - pthr->id++; - for (j=0;j<5000;j++) { - pthread_mutex_lock(&(pthr->mutex)); - pthread_mutex_unlock(&(pthr->mutex)); - } - } - return NULL; + struct thread *pthr = (struct thread *)arg; + int i, tid = gettid(); + + printf("Noise Thread started running with prio %d\n", + pthr->priority); + pthread_barrier_wait(&barrier); + + /* Give the other threads time to wait on the condition variable.*/ + usleep(1000); + + /* Noise thread begins the test */ + pthread_mutex_lock(&cond_mutex); + pthread_cond_broadcast(&cond_var); + pthread_mutex_unlock(&cond_mutex); + + for (i = 0; i < 10000; i++) { + if (i%100 == 0) { + printf("Noise Thread %d loop %d pthread pol %d "\ + "pri %d\n", tid, i, pthr->policy, + pthr->priority); + fflush(NULL); + } + busy_work_ms(1); + } + return NULL; } /* * Test pthread creation at different thread priorities. */ -int main(int argc, char* argv[]) { - pthread_mutexattr_t mutexattr; - int i, retc, protocol, nopi = 0; - cpu_set_t mask; - CPU_ZERO(&mask); - CPU_SET(0, &mask); - setup(); - - rt_init("h",parse_args,argc,argv); - - if ((retc = pthread_barrier_init(&barrier, NULL, 5))) { - printf("pthread_barrier_init failed: %s\n", strerror(retc)); - exit(retc); - } - - retc = sched_setaffinity(0, sizeof(mask), &mask); - if (retc < 0) { - printf("Main Thread: Can't set affinity: %d %s\n", retc, strerror(retc)); - exit(-1); - } - for (i=0;i<argc;i++) { - if (strcmp(argv[i],"nopi") == 0) nopi = 1; - } - - printf("Start %s\n", argv[0]); - - glob_mutex = malloc(sizeof(pthread_mutex_t)); - if (glob_mutex == NULL) { - printf("Malloc failed\n"); - exit(errno); - } - - if (!nopi) { - if (pthread_mutexattr_init(&mutexattr) != 0) { - printf("Failed to init mutexattr\n"); - } - if (pthread_mutexattr_setprotocol(&mutexattr, PTHREAD_PRIO_INHERIT) != 0) { - printf("Can't set protocol prio inherit\n"); - } - if (pthread_mutexattr_getprotocol(&mutexattr, &protocol) != 0) { - printf("Can't get mutexattr protocol\n"); - } else { - printf("protocol in mutexattr is %d\n", protocol); - } - if ((retc = pthread_mutex_init(glob_mutex, &mutexattr)) != 0) { - printf("Failed to init mutex: %d\n", retc); - } - } - - create_other_thread(func_nonrt, NULL); - create_rr_thread(func_rt, NULL, 20); - create_rr_thread(func_rt, NULL, 30); - create_rr_thread(func_rt, NULL, 40); - create_rr_thread(func_noise, NULL, 40); - - printf("Joining threads\n"); - join_threads(); - printf("Done\n"); - - return 0; +int main(int argc, char *argv[]) +{ + int i, retc, nopi = 0; + cpu_set_t mask; + CPU_ZERO(&mask); + CPU_SET(0, &mask); + setup(); + + rt_init("h", parse_args, argc, argv); + + retc = pthread_barrier_init(&barrier, NULL, 5); + if (retc) { + printf("pthread_barrier_init failed: %s\n", strerror(retc)); + exit(retc); + } + + retc = sched_setaffinity(0, sizeof(mask), &mask); + if (retc < 0) { + printf("Main Thread: Can't set affinity: %d %s\n", retc, + strerror(retc)); + exit(-1); + } + for (i = 0; i < argc; i++) { + if (strcmp(argv[i], "nopi") == 0) + nopi = 1; + } + + printf("Start %s\n", argv[0]); + + glob_mutex = malloc(sizeof(pthread_mutex_t)); + if (glob_mutex == NULL) { + printf("Malloc failed\n"); + exit(errno); + } + + if (!nopi) + init_pi_mutex(glob_mutex); + + create_other_thread(func_nonrt, NULL); + create_rr_thread(func_rt, NULL, 20); + create_rr_thread(func_rt, NULL, 30); + create_rr_thread(func_rt, NULL, 40); + create_rr_thread(func_noise, NULL, 40); + + printf("Joining threads\n"); + join_threads(); + printf("Done\n"); + + pthread_mutex_destroy(glob_mutex); + pthread_mutex_destroy(&cond_mutex); + pthread_cond_destroy(&cond_var); + return 0; } hooks/post-receive -- ltp |