ia64/xen-unstable
changeset 16449:96409cebd74b
[Mini-OS] Fix domain blocking race
A callback which wakes a thread may happen between the moment
schedule() gives hand to the idle thread and the latter blocks the
domain. Idle hence needs to atomically check that no thread is
running and block, else awoken threads may have to wait up to 10
seconds.
Signed-off-by: Samuel Thibault <samuel.thibault@citrix.com>
A callback which wakes a thread may happen between the moment
schedule() gives hand to the idle thread and the latter blocks the
domain. Idle hence needs to atomically check that no thread is
running and block, else awoken threads may have to wait up to 10
seconds.
Signed-off-by: Samuel Thibault <samuel.thibault@citrix.com>
author | Keir Fraser <keir.fraser@citrix.com> |
---|---|
date | Sat Nov 24 13:31:39 2007 +0000 (2007-11-24) |
parents | 2c52520f3284 |
children | 5e8e82e80f3b |
files | extras/mini-os/sched.c |
line diff
1.1 --- a/extras/mini-os/sched.c Sat Nov 24 13:31:01 2007 +0000 1.2 +++ b/extras/mini-os/sched.c Sat Nov 24 13:31:39 2007 +0000 1.3 @@ -224,12 +224,29 @@ void wake(struct thread *thread) 1.4 void idle_thread_fn(void *unused) 1.5 { 1.6 s_time_t until; 1.7 + unsigned long flags; 1.8 + struct list_head *iterator; 1.9 + struct thread *next, *thread; 1.10 for(;;) 1.11 { 1.12 schedule(); 1.13 - /* block until the next timeout expires, or for 10 secs, whichever comes first */ 1.14 - until = blocking_time(); 1.15 - block_domain(until); 1.16 + next = NULL; 1.17 + local_irq_save(flags); 1.18 + list_for_each(iterator, &idle_thread->thread_list) 1.19 + { 1.20 + thread = list_entry(iterator, struct thread, thread_list); 1.21 + if(is_runnable(thread)) 1.22 + { 1.23 + next = thread; 1.24 + break; 1.25 + } 1.26 + } 1.27 + if (!next) { 1.28 + /* block until the next timeout expires, or for 10 secs, whichever comes first */ 1.29 + until = blocking_time(); 1.30 + block_domain(until); 1.31 + } 1.32 + local_irq_restore(flags); 1.33 wake_expired(); 1.34 } 1.35 }