login
Header Space

 
 

Re: [BUG] long freezes on thinkpad t60

Score:
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Jarek Poplawski <jarkao2@...>
Cc: Ingo Molnar <mingo@...>, Miklos Szeredi <miklos@...>, <cebbert@...>, <chris@...>, <linux-kernel@...>, <tglx@...>, <akpm@...>
Date: Wednesday, June 20, 2007 - 1:34 pm

On Wed, 20 Jun 2007, Jarek Poplawski wrote:

Well, that's certainly a valid standpoint. I wouldn't claim you're 
_wrong_.

At least in theory.

In *practice*, fair spinlocks are simply not possible. Not as in "it's 
hard to do", but as in "you simply cannot do it".

The thing is, most spinlocks get held for a rather short time (if that 
wasn't the case, you'd use something like a mutex), and it's acually a 
short time not on a "human scale", but on a "CPU core scale".

IOW, the cost of doing the cacheline bouncing is often equal to, or bigger 
than, the actual cost of the operation that happens inside the spinlock!

What does this result in? It automatically means that software simply 
*cannot* do fair spinlocks, because all the timing costs are in parts that 
software doesn't even have any visibility into, or control over!

Yeah, you could add artificial delays, by doing things like cycle counting 
around the spinlock operation to see if you got the lock when it was 
_contended_, or whether you got a lock that wasn't, and then adding some 
statistics etc, but at that point, you don't have a spinlock any more, you 
have something else. I don't know what to call it.

And you could add flags like "this spinlock is getting a lot of 
contention", try some other algorithm etc. But it's all complicated and 
against the whole *point* of a spinlock, which is to get in and out as 
fast as humanly possible.

So in practice, spinlock fairness is inherently tied to the hardware 
behaviour of the cache coherency algorithm.

Which gets us to the next level: we can consider hardware that isn't 
"fair" in its cache coherency to be buggy hardware.

That's also a perfectly fine standpoint, and it's actually one that I have 
a lot of sympathy for. I think it's much easier to some degree to do 
fairness in the cache coherency than at any other level, because it's 
something where the hardware really *could* do things like counting 
bouncing etc.

However, while it's a perfectly fine standpoint, it's also totally 
unrealistic. First off, the hardware doesn't even know whether the 
spinlock "failed" or not on any architecture platform I'm aware of. On 
x86, the spinlock operation under Linux is actually just an atomic 
decrement, and it so happens that the rules for failure was that it didn't 
go negative. But that's just a Linux internal rule - the hardware doesn't 
know.

So you'd have to actualyl have some specific sequence with specific 
fairness rules (maybe you could make the rule be that a failed atomic 
"cmpxchg" counts as a real failure, and if you give higher priority to 
cores with lots of failures etc).

IOW, it's certainly possible *in*theory* to try to make hardware that has 
fairness guarantees. However, any hardware designer will tell you that 
 (a) they have enough problems as it is
 (b) it's simply not worth their time, since there are other (simpler) 
     things that are much much more important.

So the end result:
 - hardware won't do it, and they'd be crazy to really even try (apart 
   from maybe some really simplistic stuff that doesn't _guarantee_ 
   anything, but maybe helps fairness a bit)
 - software cannot do it, without turning spinlocks into something really 
   slow and complicated, at which point they've lost all meaning, and you 
   should just use a higher-level construct like a mutex instead.

In other words, spinlocks are optimized for *lack* of contention. If a 
spinlock has contention, you don't try to make the spinlock "fair". No, 
you try to fix the contention instead!

That way, you fix many things. You probably speed things up, _and_ you 
make it fairer. It might sometimes take some brains and effort, but it's 
worth it.

The patch I sent out was an example of that. You *can* fix contention 
problems. Does it take clever approaches? Yes. It's why we have hashed 
spinlocks, RCU, and code sequences that are entirely lockless and use 
optimistic approaches. And suddenly you get fairness *and* performance!

It's a win-win situation. It does require a bit of effort, but hey, we're 
good at effort.

			Linus
-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[BUG] long freezes on thinkpad t60, Miklos Szeredi, (Thu May 24, 8:04 am)
Re: [BUG] long freezes on thinkpad t60, Henrique de Moraes Holschuh..., (Thu May 24, 6:08 pm)
Re: [BUG] long freezes on thinkpad t60, Kok, Auke, (Thu May 24, 6:13 pm)
Re: [BUG] long freezes on thinkpad t60, Ingo Molnar, (Fri May 25, 2:58 am)
Re: [BUG] long freezes on thinkpad t60, Ingo Molnar, (Thu May 24, 8:54 am)
Re: [BUG] long freezes on thinkpad t60, Miklos Szeredi, (Thu May 24, 10:03 am)
Re: [BUG] long freezes on thinkpad t60, Ingo Molnar, (Thu May 24, 10:10 am)
Re: [BUG] long freezes on thinkpad t60, Miklos Szeredi, (Thu May 24, 10:28 am)
Re: [BUG] long freezes on thinkpad t60, Ingo Molnar, (Thu May 24, 10:42 am)
Re: [BUG] long freezes on thinkpad t60, Ingo Molnar, (Thu May 24, 10:44 am)
Re: [BUG] long freezes on thinkpad t60, Miklos Szeredi, (Thu May 24, 1:09 pm)
Re: [BUG] long freezes on thinkpad t60, Ingo Molnar, (Thu May 24, 5:01 pm)
Re: [BUG] long freezes on thinkpad t60, Miklos Szeredi, (Fri May 25, 5:51 am)
Re: [BUG] long freezes on thinkpad t60, Miklos Szeredi, (Thu Jun 14, 12:04 pm)
Re: [BUG] long freezes on thinkpad t60, Ingo Molnar, (Sat Jun 16, 6:37 am)
Re: [BUG] long freezes on thinkpad t60, Miklos Szeredi, (Sun Jun 17, 5:46 pm)
Re: [BUG] long freezes on thinkpad t60, Ingo Molnar, (Mon Jun 18, 2:43 am)
Re: [BUG] long freezes on thinkpad t60, Miklos Szeredi, (Mon Jun 18, 3:24 am)
Re: [BUG] long freezes on thinkpad t60, Ingo Molnar, (Mon Jun 18, 4:12 am)
Re: [BUG] long freezes on thinkpad t60, Linus Torvalds, (Mon Jun 18, 12:34 pm)
Re: [BUG] long freezes on thinkpad t60, Jarek Poplawski, (Wed Jun 20, 5:36 am)
Re: [BUG] long freezes on thinkpad t60, Linus Torvalds, (Wed Jun 20, 1:34 pm)
Re: [BUG] long freezes on thinkpad t60, Ingo Molnar, (Thu Jun 21, 3:30 am)
Re: [BUG] long freezes on thinkpad t60, Linus Torvalds, (Thu Jun 21, 11:50 am)
Re: [BUG] long freezes on thinkpad t60, Ingo Molnar, (Thu Jun 21, 12:08 pm)
Re: [BUG] long freezes on thinkpad t60, Chuck Ebbert, (Thu Jun 21, 12:44 pm)
Re: [BUG] long freezes on thinkpad t60, Linus Torvalds, (Thu Jun 21, 1:31 pm)
Re: [BUG] long freezes on thinkpad t60, Ingo Molnar, (Thu Jun 21, 4:18 pm)
Re: [BUG] long freezes on thinkpad t60, Linus Torvalds, (Thu Jun 21, 4:36 pm)
Re: [BUG] long freezes on thinkpad t60, Ingo Molnar, (Thu Jun 21, 4:16 pm)
Re: [BUG] long freezes on thinkpad t60, Ingo Molnar, (Fri Jun 22, 4:17 am)
Re: [BUG] long freezes on thinkpad t60, Miklos Szeredi, (Sat Jun 23, 6:36 am)
Re: [BUG] long freezes on thinkpad t60, Jarek Poplawski, (Mon Jun 25, 2:45 am)
Re: [BUG] long freezes on thinkpad t60, Linus Torvalds, (Sat Jun 23, 12:39 pm)
Re: [BUG] long freezes on thinkpad t60, Eric Dumazet, (Thu Jun 21, 2:29 pm)
Re: [BUG] long freezes on thinkpad t60, Linus Torvalds, (Thu Jun 21, 2:44 pm)
Re: [BUG] long freezes on thinkpad t60, Nick Piggin, (Tue Jun 26, 4:42 am)
Re: [BUG] long freezes on thinkpad t60, Linus Torvalds, (Tue Jun 26, 1:23 pm)
Re: [BUG] long freezes on thinkpad t60, Nick Piggin, (Wed Jun 27, 1:23 am)
Re: [BUG] long freezes on thinkpad t60, Linus Torvalds, (Wed Jun 27, 2:04 am)
Re: [BUG] long freezes on thinkpad t60, Linus Torvalds, (Wed Jun 27, 3:47 pm)
Re: [BUG] long freezes on thinkpad t60, Nick Piggin, (Mon Jul 2, 3:06 am)
Re: [BUG] long freezes on thinkpad t60, Davide Libenzi, (Wed Jun 27, 4:17 pm)
Re: [BUG] long freezes on thinkpad t60, Linus Torvalds, (Wed Jun 27, 6:11 pm)
Re: [BUG] long freezes on thinkpad t60, Davide Libenzi, (Wed Jun 27, 7:30 pm)
Re: [BUG] long freezes on thinkpad t60, Linus Torvalds, (Wed Jun 27, 8:46 pm)
Re: [BUG] long freezes on thinkpad t60, Davide Libenzi, (Wed Jun 27, 11:03 pm)
Re: [BUG] long freezes on thinkpad t60, Ingo Molnar, (Wed Jun 27, 4:10 pm)
Re: [BUG] long freezes on thinkpad t60, Nick Piggin, (Wed Jun 27, 2:20 am)
Re: [BUG] long freezes on thinkpad t60, Jarek Poplawski, (Tue Jun 26, 6:56 am)
Re: [BUG] long freezes on thinkpad t60, Ingo Molnar, (Thu Jun 21, 4:12 pm)
Re: [BUG] long freezes on thinkpad t60, Ingo Molnar, (Thu Jun 21, 3:56 pm)
Re: [BUG] long freezes on thinkpad t60, Linus Torvalds, (Thu Jun 21, 4:10 pm)
Re: [BUG] long freezes on thinkpad t60, Ingo Molnar, (Thu Jun 21, 4:23 pm)
Re: [BUG] long freezes on thinkpad t60, Linus Torvalds, (Thu Jun 21, 3:35 pm)
Re: [BUG] long freezes on thinkpad t60, Eric Dumazet, (Thu Jun 21, 4:36 pm)
Re: [BUG] long freezes on thinkpad t60, Ingo Molnar, (Thu Jun 21, 4:09 pm)
Re: [BUG] long freezes on thinkpad t60, Linus Torvalds, (Thu Jun 21, 4:14 pm)
[patch] spinlock debug: make looping nicer, Ingo Molnar, (Thu Jun 21, 4:42 pm)
Re: [patch] spinlock debug: make looping nicer, Linus Torvalds, (Thu Jun 21, 4:58 pm)
Re: [patch] spinlock debug: make looping nicer, Ingo Molnar, (Thu Jun 21, 5:15 pm)
Re: [patch] spinlock debug: make looping nicer, Jarek Poplawski, (Fri Jun 22, 3:00 am)
Re: [BUG] long freezes on thinkpad t60, Ingo Molnar, (Thu Jun 21, 4:30 pm)
Re: [BUG] long freezes on thinkpad t60, Linus Torvalds, (Thu Jun 21, 4:48 pm)
Re: [BUG] long freezes on thinkpad t60, Ingo Molnar, (Thu Jun 21, 5:06 pm)
Re: [BUG] long freezes on thinkpad t60, Linus Torvalds, (Thu Jun 21, 12:32 pm)
Re: [BUG] long freezes on thinkpad t60, Jarek Poplawski, (Thu Jun 21, 3:38 am)
Re: [BUG] long freezes on thinkpad t60, Linus Torvalds, (Thu Jun 21, 12:01 pm)
Re: [BUG] long freezes on thinkpad t60, Jarek Poplawski, (Fri Jun 22, 6:38 am)
Re: [BUG] long freezes on thinkpad t60, Ingo Molnar, (Thu Jun 21, 4:39 am)
Re: [BUG] long freezes on thinkpad t60, Jarek Poplawski, (Thu Jun 21, 7:09 am)
Re: [BUG] long freezes on thinkpad t60, Ingo Molnar, (Mon Jun 18, 2:00 pm)
Re: [BUG] long freezes on thinkpad t60, Linus Torvalds, (Mon Jun 18, 2:25 pm)
Re: [BUG] long freezes on thinkpad t60, Miklos Szeredi, (Mon Jun 18, 1:41 pm)
Re: [BUG] long freezes on thinkpad t60, Linus Torvalds, (Mon Jun 18, 1:48 pm)
Re: [BUG] long freezes on thinkpad t60, Ingo Molnar, (Mon Jun 18, 2:02 pm)
Re: [BUG] long freezes on thinkpad t60, Miklos Szeredi, (Mon Jun 18, 4:25 am)
Re: [BUG] long freezes on thinkpad t60, Ingo Molnar, (Mon Jun 18, 4:31 am)
Re: [BUG] long freezes on thinkpad t60, Miklos Szeredi, (Mon Jun 18, 4:34 am)
Re: [BUG] long freezes on thinkpad t60, Ingo Molnar, (Mon Jun 18, 5:18 am)
Re: [BUG] long freezes on thinkpad t60, Ingo Molnar, (Mon Jun 18, 5:38 am)
Re: [BUG] long freezes on thinkpad t60, Ingo Molnar, (Mon Jun 18, 5:44 am)
Re: [BUG] long freezes on thinkpad t60, Miklos Szeredi, (Mon Jun 18, 6:18 am)
Re: [BUG] long freezes on thinkpad t60, Ingo Molnar, (Mon Jun 18, 8:36 am)
Re: [BUG] long freezes on thinkpad t60, Miklos Szeredi, (Mon Jun 18, 9:10 am)
Re: [BUG] long freezes on thinkpad t60, Andrew Morton, (Mon Jun 18, 4:20 am)
Re: [BUG] long freezes on thinkpad t60, Ravikiran G Thirumalai, (Tue Jun 19, 12:22 am)
Re: [BUG] long freezes on thinkpad t60, Chuck Ebbert, (Fri Jun 15, 5:25 pm)
speck-geostationary