Re: [PATCH -v7][RFC]: mutex: implement adaptive spinning

Steven Rostedt
2009-01-09T16:44:55Z

On Fri, 9 Jan 2009, Linus Torvalds wrote:

>
>
> On Fri, 9 Jan 2009, Steven Rostedt wrote:
> >
> > I was going to say a while ago...
> > In PREEMPT=y the need_resched() is not needed at all. If you have
> > preemption enabled, you will get preempted in that loop. No need for the
> > need_resched() in the outer loop. Although I'm not sure how it would even
> > hit the "need_resched". If it was set, then it is most likely going to be
> > cleared when coming back from being preempted.
>
> No, no, you miss the point entirely.

No I did not miss your point. I was commenting on the current code ;-)

> So quite frankly, if you have CONFIG_PREEMPT, then the spinning really is
> the wrong thing to do, or the whole mutex slow-path thing should be done
> with preemption disabled so that we only schedule where we _should_ be
> scheduling.

I agree here. I was going to recommend to add a preempt_disable in the
spinner. And keep the need_resched test. Then we should not allow
preemption until we get all the way to the point of the schedule in the
contention case, or when we get the lock.

When we get to the schedule() it then needs to be a:

preempt_enable_no_resched();
schedule();

-- Steve