----- Original Message -----
> From: "Jan Stancek" <[email protected]>
> To: [email protected]
> Cc: [email protected]
> Sent: Thursday, 3 October, 2013 2:58:14 PM
> Subject: Re: [LTP] [PATCH 3/3] pthread_attr_setschedpolicy/2-1.c: give 
> threads a moment to block on mutex
> 
> 
> 
> ----- Original Message -----
> > From: [email protected]
> > To: "Jan Stancek" <[email protected]>
> > Cc: [email protected]
> > Sent: Thursday, 3 October, 2013 2:38:34 PM
> > Subject: Re: [LTP] [PATCH 3/3] pthread_attr_setschedpolicy/2-1.c: give
> > threads a moment to block on mutex
> > 
> > Hi!
> > > Use small sleep for lack of better way to check that all threads
> > > are blocked on mutex "mutex".
> > > 
> > > Signed-off-by: Jan Stancek <[email protected]>
> > > ---
> > >  .../interfaces/pthread_attr_setschedpolicy/2-1.c   |    3 +++
> > >  1 files changed, 3 insertions(+), 0 deletions(-)
> > > 
> > > diff --git
> > > a/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_setschedpolicy/2-1.c
> > > b/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_setschedpolicy/2-1.c
> > > index 80ce906..1f8825a 100644
> > > ---
> > > a/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_setschedpolicy/2-1.c
> > > +++
> > > b/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_setschedpolicy/2-1.c
> > > @@ -161,6 +161,9 @@ int main(void)
> > >   if (rc)
> > >           FAIL_AND_EXIT("create_thread HIGH", rc);
> > >  
> > > + /* give threads a moment so they can block on mutex "mutex" */
> > > + sleep(2);
> > > +
> > >   rc = pthread_mutex_unlock(&mutex);
> > >   if (rc)
> > >           FAIL_AND_EXIT("pthread_mutex_unlock()", rc);
> > 
> > Hmm, so you did hit the small window for race condition between the new
> > thread signals the main thread that it's executed and the next call to
> > the mutex_lock on the tested mutex?
> 
> Yes, I'm assuming this is reason why I see it sporadically failing on
> different distros/kernels. I see it happening the most on IBM z/VM (s390)
> guests which have overcommitted resources, which affects scheduling.
> 
> It takes longer, but I could trigger it on x86_64 too.
> 
> > 
> > I do not like this solution much, but this is not easy to do properly.
> > One posibility is to pinpoint the threads on one cpu via the affinity()
> > interface (open_posix_testsuite/include/affinity.h) then we can wait in
> > the main thread until the thread with lowest priority is executed and
> > safely say that the rest is locked on the mutex allready (as they run
> > with FIFO scheduling).
> 
> I was considering this too, but there are some problems:
> 
> 1. pthread_setaffinity_np is not portable / sched_setaffinity is Linux only
> 2. linux default sched_rt_runtime_us gives 0.05s to be used by
>    SCHED_OTHER (non-RT tasks) (Documentation/scheduler/sched-rt-group.txt)
>    If we set also main thread to use SCHED_FIFO, then this shouldn't be
>    problem.
> 
> If you are OK with using pthread_setaffinity_np(), I can add that.

Sorry, I overlooked you already gave example to function in affinity.h.
I'll use this one.

Regards,
Jan

> 
> Regards,
> Jan
> 
> > 
> > --
> > Cyril Hrubis
> > [email protected]
> > 
> 
> ------------------------------------------------------------------------------
> October Webinars: Code for Performance
> Free Intel webinars can help you accelerate application performance.
> Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from
> the latest Intel processors and coprocessors. See abstracts and register >
> http://pubads.g.doubleclick.net/gampad/clk?id=60134791&iu=/4140/ostg.clktrk
> _______________________________________________
> Ltp-list mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/ltp-list
> 

------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60134791&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to