linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [patch 2/3] scheduler: add full memory barriers upon task
@ 2010-02-02 22:42 George Spelvin
  0 siblings, 0 replies; only message in thread
From: George Spelvin @ 2010-02-02 22:42 UTC (permalink / raw)
  To: rostedt; +Cc: linux, linux-kernel

> again:
>   tmp_mask = mm_cpumask(current->mm);
>   smp_mb();
>    rcu_read_lock(); /* ensures validity of cpu_curr(cpu) tasks */
>    for_each_cpu(cpu, tmp_mask) {
>      spin_lock_irq(&cpu_rq(cpu)->lock);
>      ret = current->mm == cpu_curr(cpu)->mm;
>      spin_unlock_irq(&cpu_rq(cpu)->lock);
>      if (ret)
>        smp_call_function_single(cpu, membarrier_ipi, NULL, 1);
>    }
>    rcu_read_unlock();
>    smp_mb();
>    if (tmp_mask != mm_cpumask(current->mm)) {
>       /* do check for signals here */
>       goto again;
>    }

How about the harder-to-livelock version that avoids sending
a second IPI to all the processors if the retry condition
hits?

(It also caches current->mm across the various barriers, as I think the
compiler will have difficulty inferring that otherwise).


cpumask_t unsent_mask;
cpumask_setall(&unsent_mask);
cpumask_clear_cpu(smp_processor_id(), &unsent_mask);

struct mm_struct const *current_mm = current->mm;

for (;;) {
    cpumask_t const *tmp_mask = mm_cpumask(current_mm);
    int cpu = cpumask_next_and(-1, tmp_mask, &unsent_mask);

    if (cpu > nr_cpu_ids)
	break;

    smp_mb();
    rcu_read_lock(); /* ensures validity of cpu_curr(cpu) tasks */
    do {
	struct mm_struct const *other_mm;
	spin_lock_irq(&cpu_rq(cpu)->lock);
	other_mm = cpu_curr(cpu)->mm;
	spin_unlock_irq(&cpu_rq(cpu)->lock);
	if (other_mm == current_mm) {
	    smp_call_function_single(cpu, membarrier_ipi, NULL, 1);
	    cpumask_clear_cpu(cpu, &unsent_mask);
        }
	cpu = cpumask_next_and(cpu, tmp_mask, &unsent_mask);
    } while (cpu < nr_cpu_ids);
    rcu_read_unlock();
    smp_mb();
    /* And now check again if any more CPUs have joined the mm */
}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2010-02-02 22:42 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-02-02 22:42 [patch 2/3] scheduler: add full memory barriers upon task George Spelvin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).