All of lore.kernel.org
 help / color / mirror / Atom feed
From: Samuel Thibault <samuel.thibault@eu.citrix.com>
To: xen-devel@lists.xensource.com
Subject: [PATCH] [Mini-OS] Fix domain blocking race
Date: Fri, 23 Nov 2007 18:15:41 +0000	[thread overview]
Message-ID: <20071123181541.GA12767@implementation.uk.xensource.com> (raw)

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>

diff -r dc9246357cdb extras/mini-os/sched.c
--- a/extras/mini-os/sched.c	Fri Nov 23 16:42:44 2007 +0000
+++ b/extras/mini-os/sched.c	Fri Nov 23 18:11:18 2007 +0000
@@ -216,12 +216,29 @@
 void idle_thread_fn(void *unused)
 {
     s_time_t until;
+    unsigned long flags;
+    struct list_head *iterator;
+    struct thread *next, *thread;
     for(;;)
     {
         schedule();
-        /* block until the next timeout expires, or for 10 secs, whichever comes first */
-        until = blocking_time();
-        block_domain(until);
+        next = NULL;
+        local_irq_save(flags);
+        list_for_each(iterator, &idle_thread->thread_list)
+        {
+            thread = list_entry(iterator, struct thread, thread_list);
+            if(is_runnable(thread)) 
+            {
+                next = thread;
+                break;
+            }
+        }
+        if (!next) {
+            /* block until the next timeout expires, or for 10 secs, whichever comes first */
+            until = blocking_time();
+            block_domain(until);
+        }
+        local_irq_restore(flags);
         wake_expired();
     }
 }

                 reply	other threads:[~2007-11-23 18:15 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20071123181541.GA12767@implementation.uk.xensource.com \
    --to=samuel.thibault@eu.citrix.com \
    --cc=xen-devel@lists.xensource.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.