[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <alpine.LFD.2.00.0901071241360.3057@localhost.localdomain>
Date: Wed, 7 Jan 2009 12:55:49 -0800 (PST)
From: Linus Torvalds <torvalds@...ux-foundation.org>
To: Steven Rostedt <rostedt@...dmis.org>
cc: Peter Zijlstra <peterz@...radead.org>, paulmck@...ux.vnet.ibm.com,
Gregory Haskins <ghaskins@...ell.com>,
Ingo Molnar <mingo@...e.hu>, Matthew Wilcox <matthew@....cx>,
Andi Kleen <andi@...stfloor.org>,
Chris Mason <chris.mason@...cle.com>,
Andrew Morton <akpm@...ux-foundation.org>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
linux-fsdevel <linux-fsdevel@...r.kernel.org>,
linux-btrfs <linux-btrfs@...r.kernel.org>,
Thomas Gleixner <tglx@...utronix.de>,
Nick Piggin <npiggin@...e.de>,
Peter Morreale <pmorreale@...ell.com>,
Sven Dietrich <SDietrich@...ell.com>
Subject: Re: [PATCH -v5][RFC]: mutex: implement adaptive spinning
On Wed, 7 Jan 2009, Steven Rostedt wrote:
>
> Next comes the issue to know if the owner is still running. Wouldn't we
> need to do something like
>
> if (task_thread_info(cpu_rq(cpu)->curr) == owner)
Yes. After verifying that "cpu" is in a valid range.
> I understand that this should not be a problem, but I'm afraid it will
> give me nightmares at night. ;-)
>
> God that code had better be commented well.
Well, the good news is that it really would be just a few - admittedly
very subtle - lines, each basically generating just a couple of machine
instructions. So we'd be looking at code where the actual assembly output
should hopefully be in the ten-to-twenty instruction range, and the C code
itself would be about five times as many comments as actual real lines.
So the code really shouldn't be much worse than
/*
* Look out! "thread" is an entirely speculative pointer
* access and not reliable.
*/
void loop_while_oncpu(struct mutex *lock, struct thread_struct *thread)
{
for (;;) {
unsigned cpu;
struct runqueue *rq;
if (lock->owner != thread)
break;
/*
* Need to access the cpu field knowing that
* DEBUG_PAGEALLOC could have unmapped it if
* the mutex owner just released it and exited.
*/
if (__get_user(cpu, &thread->cpu))
break;
/*
* Even if the access succeeded (likely case),
* the cpu field may no longer be valid. FIXME:
* this needs to validate that we can do a
* get_cpu() and that we have the percpu area.
*/
if (cpu >= NR_CPUS)
break;
if (!cpu_online(cpu))
break;
/*
* Is that thread really running on that cpu?
*/
rq = cpu_rq(cpu);
if (task_thread_info(rq->curr) != thread)
break;
cpu_relax();
}
}
and it all looks like it shouldn't be all that bad. Yeah, it's like 50
lines of C code, but it's mostly comments about subtle one-liners that
really expand to almost no real code at all.
Linus
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists