From 96b6afbe3c8496e9a081f18679b834edc9baa64b Mon Sep 17 00:00:00 2001 From: Jeremy Erickson Date: Thu, 18 Nov 2010 21:19:53 -0500 Subject: Attempt to fix race condition with plugin switching --- litmus/litmus.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/litmus/litmus.c b/litmus/litmus.c index 0756d0156f8f..1dbe8e52839f 100644 --- a/litmus/litmus.c +++ b/litmus/litmus.c @@ -22,6 +22,7 @@ atomic_t rt_task_count = ATOMIC_INIT(0); static DEFINE_RAW_SPINLOCK(task_transition_lock); /* synchronize plugin switching */ atomic_t cannot_use_plugin = ATOMIC_INIT(0); +atomic_t cpus_waiting_for_plugin = ATOMIC_INIT(0); /* Give log messages sequential IDs. */ atomic_t __log_seq_no = ATOMIC_INIT(0); @@ -382,6 +383,7 @@ void litmus_exit_task(struct task_struct* tsk) /* IPI callback to synchronize plugin switching */ static void synch_on_plugin_switch(void* info) { + atomic_inc(&cpus_waiting_for_plugin); while (atomic_read(&cannot_use_plugin)) cpu_relax(); } @@ -400,9 +402,16 @@ int switch_sched_plugin(struct sched_plugin* plugin) /* forbid other cpus to use the plugin */ atomic_set(&cannot_use_plugin, 1); + + atomic_set(&cpus_waiting_for_plugin, 0); + /* send IPI to force other CPUs to synch with us */ smp_call_function(synch_on_plugin_switch, NULL, 0); + /* wait until all other CPUs have started synch */ + while (atomic_read(&cpus_waiting_for_plugin) < num_online_cpus() - 1) + cpu_relax(); + /* stop task transitions */ raw_spin_lock_irqsave(&task_transition_lock, flags); -- cgit v1.2.2