On Thu, Nov 30, 2006 at 12:46:17PM +0100, Ingo Molnar wrote:
> 
>       struct task_struct {
>               ...
>               int hotplug_depth;
>               struct mutex *hotplug_lock;
>       }
>       ...
> 
>       DEFINE_PER_CPU(struct mutex, hotplug_lock);
> 
>       void cpu_hotplug_lock(void)
>       {
>               int cpu = raw_smp_processor_id();
>               /*
>                * Interrupts/softirqs are hotplug-safe:
>                */
>               if (in_interrupt())
>                       return;
>               if (current->hotplug_depth++)
>                       return;
>               current->hotplug_lock = &per_cpu(hotplug_lock, cpu);
>               mutex_lock(current->hotplug_lock);
>       }
> 
>       void cpu_hotplug_unlock(void)
>       {
>               int cpu;
> 
>               if (in_interrupt())
>                       return;
>               if (DEBUG_LOCKS_WARN_ON(!current->hotplug_depth))
>                       return;
>               if (--current->hotplug_depth)
>                       return;
> 
>               mutex_unlock(current->hotplug_lock);
>               current->hotplug_lock = NULL;
>       }
> 

In process context preemptible code, 
Lets say we are currently running on processor i.

cpu_hotplug_lock() ; /* does mutex_lock(&percpu(hotplug_lock, i)) */

/* do some operation, which might sleep */
/* migrates to cpu j */

cpu_hotplug_unlock(); /* does mutex_unlock(&percpu(hotplug_lock, i)
                         while running on cpu j */

This would cause cacheline ping pong, no?

> 
>       Ingo

regards 
gautham.
-- 
Gautham R Shenoy
Linux Technology Center
IBM India.
"Freedom comes with a price tag of responsibility, which is still a bargain,
because Freedom is priceless!"
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to