The threads TL and TP are masked to the CPU0, and according
to our test, threads TB will be on CPU0 or the others.

Now, run the cases on the Linux Kernel versions which before the CFS
scheduler go into it. And according to our test, if the threads TB
run on the CPU0, it may preempt TL, and thread TL may not have a chance
to run, also no chance to get the mutex lock, then the TB can easyly
get the mutex lock, and the test returns FAIL.

But, run the cases on the Kernel versions which with CFS schedules,
this FAIL state will be fewer.

This patch mask the threads TB to make sure it is not on the first CPU,
so that the thread TL will always have the chance to get the mutex lock
before threads TB try to get it.

Also with some cleanup.

Signed-off-by: Wanlong Gao <[email protected]>
Signed-off-by: Peng Haitao <[email protected]>
---
 .../functional/threads/pi_test/pitest-1.c          |   16 +++++++++--
 .../functional/threads/pi_test/pitest-2.c          |   29 ++++++++++++++++++-
 .../functional/threads/pi_test/pitest-3.c          |   22 ++++++++++++++-
 .../functional/threads/pi_test/pitest-4.c          |   20 +++++++++++++
 .../functional/threads/pi_test/pitest-5.c          |   12 +++++++-
 .../functional/threads/pi_test/pitest-6.c          |   12 +++++++-
 6 files changed, 103 insertions(+), 8 deletions(-)

diff --git 
a/testcases/open_posix_testsuite/functional/threads/pi_test/pitest-1.c 
b/testcases/open_posix_testsuite/functional/threads/pi_test/pitest-1.c
index 8ab27a2..5192522 100644
--- a/testcases/open_posix_testsuite/functional/threads/pi_test/pitest-1.c
+++ b/testcases/open_posix_testsuite/functional/threads/pi_test/pitest-1.c
@@ -138,13 +138,13 @@ void *thread_tl(void *param)
 
 #if __linux__
        rc = sched_setaffinity((pid_t)0, sizeof(mask), &mask);
-#endif
-       test_set_priority(pthread_self(), SCHED_FIFO, tp->priority);
        if (rc < 0) {
                EPRINTF("UNRESOLVED: Thread %s index %d: Can't set affinity: %d 
%s",
                        tp->name, tp->index, rc, strerror(rc));
                exit(UNRESOLVED);
        }
+#endif
+       test_set_priority(pthread_self(), SCHED_FIFO, tp->priority);
 
        DPRINTF(stdout, "#EVENT %f Thread TL Started\n",
                seconds_read() - base_time);
@@ -199,6 +199,16 @@ void *thread_tb(void *arg)
        struct timespec boost_time;
        double seconds, t0, t1;
        int rc;
+       unsigned long mask = ((1 << cpus) - 1) & ~1;
+
+#if __linux__
+       rc = sched_setaffinity((pid_t)0, sizeof(mask), &mask);
+       if (rc < 0) {
+               EPRINTF("UNRESOLVED: Thread TB: Can't set affinity: "
+                       "%d %s", rc, strerror(rc));
+               exit(UNRESOLVED);
+       }
+#endif
 
        test_set_priority(pthread_self(), SCHED_FIFO, 4);
 
@@ -325,4 +335,4 @@ int main(int argc, char **argv)
        ts_stop = 1;
        DPRINTF(stderr,"Main Thread: stop sampler thread \n");
        return 0;
-}
\ No newline at end of file
+}
diff --git 
a/testcases/open_posix_testsuite/functional/threads/pi_test/pitest-2.c 
b/testcases/open_posix_testsuite/functional/threads/pi_test/pitest-2.c
index 244fd65..4abcd09 100644
--- a/testcases/open_posix_testsuite/functional/threads/pi_test/pitest-2.c
+++ b/testcases/open_posix_testsuite/functional/threads/pi_test/pitest-2.c
@@ -102,12 +102,12 @@ void *thread_fn(void *param)
 
 #if __linux__
        rc = sched_setaffinity(0, sizeof(mask), &mask);
-#endif
        if (rc < 0) {
                EPRINTF("UNRESOLVED: Thread %s index %d: Can't set affinity: "
                        "%d %s", tp->name, tp->index, rc, strerror(rc));
                exit(UNRESOLVED);
        }
+#endif
        test_set_priority(pthread_self(), SCHED_FIFO, tp->priority);
         DPRINTF(stdout, "#EVENT %f Thread %s Started\n",
                seconds_read() - base_time, tp->name);
@@ -139,6 +139,11 @@ void *thread_tl(void *param)
 
 #if __linux__
        rc = sched_setaffinity((pid_t)0, sizeof(mask), &mask);
+       if (rc < 0) {
+               EPRINTF("UNRESOLVED: Thread %s index %d: Can't set affinity: %d 
%s",
+                       tp->name, tp->index, rc, strerror(rc));
+               exit(UNRESOLVED);
+       }
 #endif
        test_set_priority(pthread_self(),SCHED_FIFO, tp->priority);
 
@@ -199,6 +204,16 @@ void *thread_tb1(void *arg)
        struct timespec boost_time;
        double t0, t1;
        int rc;
+       unsigned long mask = ((1 << cpus) - 1) & ~1;
+
+#if __linux__
+       rc = sched_setaffinity((pid_t)0, sizeof(mask), &mask);
+       if (rc < 0) {
+               EPRINTF("UNRESOLVED: Thread TB1: Can't set affinity: "
+                       "%d %s", rc, strerror(rc));
+               exit(UNRESOLVED);
+       }
+#endif
 
        test_set_priority(pthread_self(),SCHED_FIFO, 4);
 
@@ -228,6 +243,16 @@ void *thread_tb2(void *arg)
        struct timespec boost_time;
        double t0, t1;
        int rc;
+       unsigned long mask = ((1 << cpus) - 1) & ~1;
+
+#if __linux__
+       rc = sched_setaffinity((pid_t)0, sizeof(mask), &mask);
+       if (rc < 0) {
+               EPRINTF("UNRESOLVED: Thread TB2: Can't set affinity: "
+                       "%d %s", rc, strerror(rc));
+               exit(UNRESOLVED);
+       }
+#endif
 
        test_set_priority(pthread_self(),SCHED_FIFO, 6);
 
@@ -360,4 +385,4 @@ int main(int argc, char **argv)
        ts_stop = 1;
        DPRINTF(stderr,"Main Thread: stop sampler thread \n");
        return 0;
-}
\ No newline at end of file
+}
diff --git 
a/testcases/open_posix_testsuite/functional/threads/pi_test/pitest-3.c 
b/testcases/open_posix_testsuite/functional/threads/pi_test/pitest-3.c
index 20470f0..d6c0c90 100644
--- a/testcases/open_posix_testsuite/functional/threads/pi_test/pitest-3.c
+++ b/testcases/open_posix_testsuite/functional/threads/pi_test/pitest-3.c
@@ -213,6 +213,16 @@ void *thread_tb1(void *arg)
        struct timespec boost_time;
        double t0, t1;
        int rc;
+       unsigned long mask = ((1 << cpus) - 1) & ~1;
+
+#if __linux__
+       rc = sched_setaffinity((pid_t)0, sizeof(mask), &mask);
+       if (rc < 0) {
+               EPRINTF("UNRESOLVED: Thread TB1: Can't set affinity: "
+                       "%d %s", rc, strerror(rc));
+               exit(UNRESOLVED);
+       }
+#endif
 
        test_set_priority(pthread_self(),SCHED_FIFO, 4);
        DPRINTF(stderr,"Thread TB1: started\n");
@@ -241,6 +251,16 @@ void *thread_tb2(void *arg)
        struct timespec boost_time;
        double t0, t1;
        int rc;
+       unsigned long mask = ((1 << cpus) - 1) & ~1;
+
+#if __linux__
+       rc = sched_setaffinity((pid_t)0, sizeof(mask), &mask);
+       if (rc < 0) {
+               EPRINTF("UNRESOLVED: Thread TB2: Can't set affinity: "
+                       "%d %s", rc, strerror(rc));
+               exit(UNRESOLVED);
+       }
+#endif
 
        test_set_priority(pthread_self(),SCHED_FIFO, 6);
        DPRINTF(stderr,"Thread TB2: started\n");
@@ -376,4 +396,4 @@ int main(int argc, char **argv)
        ts_stop = 1;
        DPRINTF(stderr,"Main Thread: stop sampler thread\n");
        return 0;
-}
\ No newline at end of file
+}
diff --git 
a/testcases/open_posix_testsuite/functional/threads/pi_test/pitest-4.c 
b/testcases/open_posix_testsuite/functional/threads/pi_test/pitest-4.c
index ad940dc..4b0b6e3 100644
--- a/testcases/open_posix_testsuite/functional/threads/pi_test/pitest-4.c
+++ b/testcases/open_posix_testsuite/functional/threads/pi_test/pitest-4.c
@@ -179,6 +179,16 @@ void *thread_tb1(void *arg)
        struct timespec boost_time;
        double t0, t1;
        int rc;
+       unsigned long mask = ((1 << cpus) - 1) & ~1;
+
+#if __linux__
+       rc = sched_setaffinity((pid_t)0, sizeof(mask), &mask);
+       if (rc < 0) {
+               EPRINTF("UNRESOLVED: Thread TB1: Can't set affinity: "
+                       "%d %s", rc, strerror(rc));
+               exit(UNRESOLVED);
+       }
+#endif
 
        test_set_priority(pthread_self(),SCHED_FIFO, 2);
        DPRINTF(stderr,"Thread TB1: started\n");
@@ -211,6 +221,16 @@ void *thread_tb2(void *arg)
        struct timespec boost_time;
        double t0, t1;
        int rc;
+       unsigned long mask = ((1 << cpus) - 1) & ~1;
+
+#if __linux__
+       rc = sched_setaffinity((pid_t)0, sizeof(mask), &mask);
+       if (rc < 0) {
+               EPRINTF("UNRESOLVED: Thread TB2: Can't set affinity: "
+                       "%d %s", rc, strerror(rc));
+               exit(UNRESOLVED);
+       }
+#endif
 
        test_set_priority(pthread_self(),SCHED_FIFO, 5);
        DPRINTF(stderr,"Thread TB2: started\n");
diff --git 
a/testcases/open_posix_testsuite/functional/threads/pi_test/pitest-5.c 
b/testcases/open_posix_testsuite/functional/threads/pi_test/pitest-5.c
index 9eaa1fc..5ad46f4 100644
--- a/testcases/open_posix_testsuite/functional/threads/pi_test/pitest-5.c
+++ b/testcases/open_posix_testsuite/functional/threads/pi_test/pitest-5.c
@@ -220,6 +220,16 @@ void *thread_tb(void *arg)
        struct timespec ts;
        ts.tv_sec = 2;
        ts.tv_nsec = 0;
+       unsigned long mask = ((1 << cpus) - 1) & ~1;
+
+#if __linux__
+       rc = sched_setaffinity((pid_t)0, sizeof(mask), &mask);
+       if (rc < 0) {
+               EPRINTF("UNRESOLVED: Thread TB: Can't set affinity: "
+                       "%d %s", rc, strerror(rc));
+               exit(UNRESOLVED);
+       }
+#endif
 
        test_set_priority(pthread_self(),SCHED_FIFO, 4);
        DPRINTF(stderr,"Thread TB: started\n");
@@ -342,4 +352,4 @@ int main(int argc, char **argv)
        ts_stop = 1;
        DPRINTF(stderr,"Main Thread: stop sampler thread\n");
        return 0;
-}
\ No newline at end of file
+}
diff --git 
a/testcases/open_posix_testsuite/functional/threads/pi_test/pitest-6.c 
b/testcases/open_posix_testsuite/functional/threads/pi_test/pitest-6.c
index 2621cc2..81e1495 100644
--- a/testcases/open_posix_testsuite/functional/threads/pi_test/pitest-6.c
+++ b/testcases/open_posix_testsuite/functional/threads/pi_test/pitest-6.c
@@ -199,6 +199,16 @@ void *thread_tb(void *arg)
        struct timespec boost_time;
        double t0, t1;
        int rc;
+       unsigned long mask = ((1 << cpus) - 1) & ~1;
+
+#if __linux__
+       rc = sched_setaffinity((pid_t)0, sizeof(mask), &mask);
+       if (rc < 0) {
+               EPRINTF("UNRESOLVED: Thread TB: Can't set affinity: "
+                       "%d %s", rc, strerror(rc));
+               exit(UNRESOLVED);
+       }
+#endif
 
        test_set_priority(pthread_self(), SCHED_FIFO, 4);
        DPRINTF(stderr,"Thread TB: started\n");
@@ -328,4 +338,4 @@ int main(int argc, char **argv)
        ts_stop = 1;
        DPRINTF(stderr,"Main Thread: stop sampler thread\n");
        return 0;
-}
\ No newline at end of file
+}
-- 
1.7.7.rc1


------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2dcopy1
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to