From: Kang Kai <Kai.Kang@windriver.com>
To: Jan Stancek <jstancek@redhat.com>
Cc: ltp-list@lists.sourceforge.net
Subject: Re: [LTP] [PATCH 1/3] pthread_cond_signal/1-1: use sched_yield to sync threads
Date: Mon, 13 Aug 2012 10:50:56 +0800 [thread overview]
Message-ID: <50286B90.90104@windriver.com> (raw)
In-Reply-To: <5024E0F0.3080406@redhat.com>
On 2012年08月10日 18:22, Jan Stancek wrote:
> Hi,
Hi Jan,
Thanks for your reply.
> Here's a different proposal: don't count how many pthread_cond_signals it took,
> if any fails SIGALRM will trigger testcase failure.
That is a more simple solution, and I agree with you.
Regards,
Kai
>
> diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_signal/1-1.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_signal/1-1.c
> index bf55b31..266d42f 100644
> --- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_signal/1-1.c
> +++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_signal/1-1.c
> @@ -134,9 +134,7 @@ int main()
> alarm(5);
>
> /* loop to wake up the rest threads */
> - i=0;
> - while (waken_num< THREAD_NUM) {
> - ++i;
> + for (i=1; i<THREAD_NUM; i++) {
> fprintf(stderr,"[Main thread] signals to wake up the next thread\n");
> if (pthread_cond_signal(&td.cond) != 0) {
> fprintf(stderr,"Main failed to signal the condition\n");
> @@ -145,12 +143,6 @@ int main()
> usleep(100);
> }
>
> - if (i>= THREAD_NUM) {
> - fprintf(stderr,"[Main thread] had to signal the condition %i times\n", i+1);
> - fprintf(stderr,"[Main thread] to wake up %i threads\n. Test FAILED.\n", THREAD_NUM);
> - exit(PTS_FAIL);
> - }
> -
> /* join all secondary threads */
> for (i=0; i<THREAD_NUM; i++) {
> if (pthread_join(thread[i], NULL) != 0) {
>
> Regards,
> Jan
>
> On 08/09/2012 12:30 PM, Kang Kai wrote:
>> This case fails on mips board routerstation randomly. The root cause is
>> that when main thread call usleep(100) after signal the child threads,
>> no child thread is scheduled to run. So the case fails.
>>
>> I update it to set main thread with a lower priority and child threads
>> with a higher one, then call sched_yield and usleep in main thread will
>> make sure that one of the child threads will be scheduled.
>>
>> Signed-off-by: Kang Kai<kai.kang@windriver.com>
>> ---
>> .../interfaces/pthread_cond_signal/1-1.c | 44 +++++++++++++++++++-
>> 1 files changed, 42 insertions(+), 2 deletions(-)
>>
>> diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_signal/1-1.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_signal/1-1.c
>> index bf55b31..77374bf 100644
>> --- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_signal/1-1.c
>> +++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_signal/1-1.c
>> @@ -12,6 +12,7 @@
>>
>> #define _XOPEN_SOURCE 600
>>
>> +#include<errno.h>
>> #include<pthread.h>
>> #include<stdio.h>
>> #include<stdlib.h>
>> @@ -20,6 +21,7 @@
>> #include "posixtest.h"
>>
>> #define THREAD_NUM 3
>> +#define SCHED_POLICY SCHED_FIFO
>>
>> struct testdata
>> {
>> @@ -77,6 +79,10 @@ int main()
>> {
>> int i, rc;
>> struct sigaction act;
>> + int pid;
>> + int policy;
>> + struct sched_param param;
>> + pthread_attr_t attr;
>>
>> if (pthread_mutex_init(&td.mutex, NULL) != 0) {
>> fprintf(stderr,"Fail to initialize mutex\n");
>> @@ -87,8 +93,35 @@ int main()
>> return PTS_UNRESOLVED;
>> }
>>
>> + pid = getpid();
>> + param.sched_priority = sched_get_priority_min(SCHED_POLICY);
>> + if (sched_setscheduler(pid, SCHED_POLICY,¶m) != 0) {
>> + fprintf(stderr, "Fail to set main thread scheduler.\n");
>> + if (errno == EPERM)
>> + fprintf(stderr, "Failed with EPERM: are you root?\n");
>> + return PTS_UNRESOLVED;
>> + }
>> +
>> + if (pthread_attr_init(&attr) != 0) {
>> + fprintf(stderr, "Fail to init child thread attribute.\n");
>> + return PTS_UNRESOLVED;
>> + }
>> + if (pthread_attr_setschedpolicy(&attr, SCHED_POLICY) != 0) {
>> + fprintf(stderr, "Fail to set child thread schedule policy attribute.\n");
>> + return PTS_UNRESOLVED;
>> + }
>> + param.sched_priority += 10;
>> + if (pthread_attr_setschedparam(&attr,¶m) != 0) {
>> + fprintf(stderr, "Fail to set child thread schedule priority attribute.\n");
>> + return PTS_UNRESOLVED;
>> + }
>> + if (pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED) != 0) {
>> + fprintf(stderr, "Fail to set child thread inheritace attribute.\n");
>> + return PTS_UNRESOLVED;
>> + }
>> +
>> for (i=0; i<THREAD_NUM; i++) { /* create THREAD_NUM threads */
>> - if (pthread_create(&thread[i], NULL, thr_func, NULL) != 0) {
>> + if (pthread_create(&thread[i],&attr, thr_func, NULL) != 0) {
>> fprintf(stderr,"Fail to create thread[%d]\n", i);
>> exit(PTS_UNRESOLVED);
>> }
>> @@ -96,6 +129,8 @@ int main()
>> while (start_num< THREAD_NUM) /* waiting for all threads started */
>> usleep(100);
>>
>> + pthread_attr_destroy(&attr);
>> +
>> /* Acquire the mutex to make sure that all waiters are currently
>> blocked on pthread_cond_wait */
>> if (pthread_mutex_lock(&td.mutex) != 0) {
>> @@ -142,6 +177,7 @@ int main()
>> fprintf(stderr,"Main failed to signal the condition\n");
>> exit(PTS_UNRESOLVED);
>> }
>> + sched_yield();
>> usleep(100);
>> }
>>
>> @@ -158,6 +194,10 @@ int main()
>> exit(PTS_UNRESOLVED);
>> }
>> }
>> +
>> + pthread_mutex_destroy(&td.mutex);
>> + pthread_cond_destroy(&td.cond);
>> +
>> printf("Test PASSED\n");
>> return PTS_PASS;
>> -}
>> \ No newline at end of file
>> +}
>
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond. Discussions
> will include endpoint security, mobile security and the latest in malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> Ltp-list mailing list
> Ltp-list@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/ltp-list
>
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
next prev parent reply other threads:[~2012-08-13 2:50 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-09 10:30 [LTP] Patches for posix test cases Kang Kai
2012-08-09 10:30 ` [LTP] [PATCH 1/3] pthread_cond_signal/1-1: use sched_yield to sync threads Kang Kai
2012-08-10 10:22 ` Jan Stancek
2012-08-13 2:50 ` Kang Kai [this message]
2012-08-23 1:57 ` Wanlong Gao
2012-08-09 10:30 ` [LTP] [PATCH 2/3] mq_open/16-1: use tmp file to share info Kang Kai
2012-08-10 9:31 ` Jan Stancek
2012-09-03 8:45 ` Kang Kai
2012-09-04 6:35 ` Jan Stancek
2012-09-04 9:44 ` Kang Kai
2012-09-04 5:33 ` Wanlong Gao
2012-09-04 7:40 ` Kang Kai
2012-09-04 8:27 ` Kang Kai
2012-09-04 8:41 ` Wanlong Gao
2012-09-04 8:45 ` Kang Kai
2012-08-09 10:30 ` [LTP] [PATCH 3/3] timer_settime/5-3: fix test hung Kang Kai
2012-08-10 9:16 ` Jan Stancek
2012-08-21 4:01 ` Wanlong Gao
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=50286B90.90104@windriver.com \
--to=kai.kang@windriver.com \
--cc=jstancek@redhat.com \
--cc=ltp-list@lists.sourceforge.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox