Re: RFC on fixing mutex spinning on owner

From: Peter Zijlstra
Date: Thu Mar 17 2016 - 06:18:31 EST


On Thu, Mar 17, 2016 at 08:05:26AM +0000, Nicholas Mc Guire wrote:
> scanning for that patter with a quite relaxed spatch did not
> turn up more than a hand full:
>
> @resched_spin exists@
> position p;
> @@
>
> (
> * while@p (...) {
> ...
> if (need_resched() || ...)
> break;
> ...
> \(cpu_relax\|cpu_relax_lowlatency\)();
> }
> |
> * while@p (!need_resched()) {
> ...
> \(cpu_relax\|cpu_relax_lowlatency\)();
> }
> )
>
> @script:python@
> p << resched_spin.p;
> @@
> print "%s:%s " % (p[0].file,p[0].line)
>
>
> is this making some wrong assumptions here or is this
> really so infrequent ?

Ah, a tool, nice! :-)

There should be one in the osq_lock, one in mutex, one in rwsem-xadd,
davidlohr was adding one to rt_mutex; and these are the one I can
remember from the top of my head.

But I would not be surprised if there are a fair few more. Also for (;;)
is a frequent loop pattern.

My biggest worry is how to not forget adding this annotation if we
create yet another instance of this. The tool could help I suppose.

Also, maybe the tracer should measure the time from need_resched()
getting true until the next preemption point, instead of the entire time
preemption was disabled. Which would avoid the entire issue altogether.