Re: bizarre timing results
From: Gav (gav_at_cs.york.ac.uk)
Date: 04/01/05
- Previous message: Rex: "estimating upper limit of network performance"
- Next in thread: Robert Redelmeier: "Re: bizarre timing results"
- Reply: Robert Redelmeier: "Re: bizarre timing results"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 01 Apr 2005 14:50:52 +0100
> Are you using signals, or how precisely are you waiting?
i'm not using signals (*)
i'm not sure how to answer the second question. the code usually goes
something like this:
[lock mutex]
while([not a state i want])
[wait on state changed condition associated with mutex]
[do some processing]
if([we changed the state])
[wake all those waiting on condition]
[unlock mutex]
i'm not completely sure, but i suspect that most times, the condition
variable will be woken only when a valid state is reached.
>> anyway, i've now put a sched_yield in each thread after they
>> complete one iteration (i.e. before they begin waiting for
>> the other to finish their iteration); it doesn't seem to
>> make any difference empirically:
>
> The yield() needs to be inside the check-loop, or you
> have to use signals.
i was uncertain about doing this originally, since the mutex is only given
up through waiting on the condition; i assumed that if i yield()ed outside
the condition then it would just hold stuff up, since nothing more could
happen until the mutex was unlocked.
<googles and reads...>
having done some reading it is apparent that condition variables are
implemented by futexes which appear to be kernel level wait queues. i've
yet to read up on them, but here's what i've read so far.
[http://www.ussg.iu.edu/hypermail/linux/kernel/0311.1/0684.html]
[http://www.ussg.iu.edu/hypermail/linux/kernel/0203.2/0122.html]
> This is no surprise if you are spinning (busywaiting)
> on a lock.
using conditions doesn't busy wait though right?
> AFAIK, Linux threads are still lightweight processes.
> The scheduler will spread these around to available CPUs,
> but you may pay a MESI communications tax.
mesi?
would that be something to do with attempting to access the same memory
segment simultaneously? or am i way off?
thanks for your continuing help; it's being more enlightening.
gav
(*) generally i would prefer to not rely upon signals; in my experience
their semantics wrt to threading was rather changeable (esp with stuff like
nptl). also i guess they're not very portable, and i don't want to rule out
porting to other platforms (read windows) at this stage.
- Previous message: Rex: "estimating upper limit of network performance"
- Next in thread: Robert Redelmeier: "Re: bizarre timing results"
- Reply: Robert Redelmeier: "Re: bizarre timing results"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|