login
Header Space

 
 

Re: What if a TLB flush needed to sleep?

Score:
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Luck, Tony <tony.luck@...>
Cc: <linux-arch@...>, <linux-mm@...>, <linux-kernel@...>
Date: Wednesday, March 26, 2008 - 8:32 am

On Tue, Mar 25, 2008 at 01:49:54PM -0700, Luck, Tony wrote:

parisc certainly has that problem too.  It won't happen very often, but
it will do an on_each_cpu() and wait for the outcome once in a while.


down_spin() is trivial to implement without knowing the details of the
semaphore code:

void down_spin(struct semaphore *sem)
{
	while (down_trylock(sem))
		cpu_relax();
}

Of course, someone who wrote it could do better ;-)

void down_spin(struct semaphore *sem)
{
	unsigned long flags;
	int count;

	spin_lock_irqsave(&sem->lock, flags);
	count = sem->count - 1;
	if (likely(count >= 0))
		sem->count = count;
	else
		__down_spin(sem);
	spin_unlock_irqrestore(&sem->lock, flags);
}

void __down_spin(struct semaphore *sem)
{
	struct semaphore_waiter waiter;

	list_add_tail(&waiter.list, &sem->wait_list);
	waiter.task = current;
	waiter.up = 0;

	spin_unlock_irq(&sem->lock);
	while (!waiter.up)
		cpu_relax();
	spin_lock_irq(&sem->lock);
}

This more complex implementation is better because:
 - It queues properly (see also down_timeout)
 - It spins on a stack-local variable, not on a global structure

Having done all that ... I bet parisc and ia64 aren't the only two
architectures which can sleep in their tlb flush handlers.

-- 
Intel are signing my paycheques ... these opinions are still mine
"Bill, look, we understand that you're interested in selling us this
operating system, but compare it to ours.  We can't possibly take such
a retrograde step."
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
What if a TLB flush needed to sleep?, Luck, Tony, (Tue Mar 25, 4:49 pm)
Re: What if a TLB flush needed to sleep?, Christoph Lameter, (Wed Mar 26, 3:25 pm)
Re: What if a TLB flush needed to sleep?, Thomas Gleixner, (Wed Mar 26, 4:29 pm)
Re: What if a TLB flush needed to sleep?, Christoph Lameter, (Wed Mar 26, 9:19 pm)
Re: What if a TLB flush needed to sleep?, Peter Zijlstra, (Thu Mar 27, 9:20 am)
Re: What if a TLB flush needed to sleep?, Christoph Lameter, (Thu Mar 27, 2:44 pm)
Re: What if a TLB flush needed to sleep?, Peter Zijlstra, (Fri Mar 28, 5:59 am)
Re: What if a TLB flush needed to sleep?, Matthew Wilcox, (Wed Mar 26, 8:32 am)
RE: What if a TLB flush needed to sleep?, Luck, Tony, (Wed Mar 26, 4:29 pm)
down_spin() implementation, Matthew Wilcox, (Thu Mar 27, 10:15 am)
Re: down_spin() implementation, Jens Axboe, (Fri Mar 28, 8:51 am)
Re: down_spin() implementation, Matthew Wilcox, (Fri Mar 28, 9:17 am)
Re: down_spin() implementation, Jens Axboe, (Fri Mar 28, 9:24 am)
Re: down_spin() implementation, Nick Piggin, (Thu Mar 27, 8:01 pm)
Re: down_spin() implementation, Matthew Wilcox, (Fri Mar 28, 8:45 am)
Re: down_spin() implementation, Nick Piggin, (Fri Mar 28, 9:04 pm)
RE: down_spin() implementation, Luck, Tony, (Fri Mar 28, 5:16 pm)
Re: down_spin() implementation, Arnd Bergmann, (Fri Mar 28, 7:48 pm)
Re: down_spin() implementation, Stephen Rothwell, (Fri Mar 28, 12:51 am)
Re: down_spin() implementation, Nick Piggin, (Fri Mar 28, 1:03 am)
Re: down_spin() implementation, Matthew Wilcox, (Fri Mar 28, 8:46 am)
Re: What if a TLB flush needed to sleep?, Jens Axboe, (Thu Mar 27, 4:09 am)
Re: What if a TLB flush needed to sleep?, Alan Cox, (Tue Mar 25, 5:47 pm)
speck-geostationary