ia64/xen-unstable

changeset 738:3ed38d186154

bitkeeper revision 1.436.1.1 (3f6b10042XNDJJ-K-YoN8Em1IaZzdg)

schedule.c:
Fix schedule_timeout to do the right thing with idle domains.
author kaf24@scramble.cl.cam.ac.uk
date Fri Sep 19 14:17:40 2003 +0000 (2003-09-19)
parents a3017cd62e5d
children 33cdf06502cb
files xen/common/schedule.c
line diff
     1.1 --- a/xen/common/schedule.c	Thu Sep 18 13:27:45 2003 +0000
     1.2 +++ b/xen/common/schedule.c	Fri Sep 19 14:17:40 2003 +0000
     1.3 @@ -612,10 +612,13 @@ long schedule_timeout(long timeout)
     1.4  {
     1.5      struct timer_list timer;
     1.6      unsigned long expire;
     1.7 -    
     1.8 +
     1.9      switch (timeout)
    1.10      {
    1.11      case MAX_SCHEDULE_TIMEOUT:
    1.12 +        /* Sanity! This just wouldn't make sense. */
    1.13 +        if ( is_idle_task(current) )
    1.14 +            panic("Arbitrary sleep in idle task!");
    1.15          /*
    1.16           * These two special cases are useful to be comfortable in the caller.
    1.17           * Nothing more. We could take MAX_SCHEDULE_TIMEOUT from one of the
    1.18 @@ -624,6 +627,7 @@ long schedule_timeout(long timeout)
    1.19           */
    1.20          schedule();
    1.21          goto out;
    1.22 +
    1.23      default:
    1.24          /*
    1.25           * Another bit of PARANOID. Note that the retval will be 0 since no
    1.26 @@ -644,17 +648,34 @@ long schedule_timeout(long timeout)
    1.27      
    1.28      expire = timeout + jiffies;
    1.29      
    1.30 -    init_timer(&timer);
    1.31 -    timer.expires = expire;
    1.32 -    timer.data = (unsigned long) current;
    1.33 -    timer.function = process_timeout;
    1.34 -    
    1.35 -    add_timer(&timer);
    1.36 -    schedule();
    1.37 -    del_timer_sync(&timer);
    1.38 -    
    1.39 -    timeout = expire - jiffies;
    1.40 -    
    1.41 +    if ( is_idle_task(current) )
    1.42 +    {
    1.43 +        /*
    1.44 +         * If the idle task is calling in then it shouldn't ever sleep. We 
    1.45 +         * therefore force it to TASK_RUNNING here and busy-wait. We spin on 
    1.46 +         * schedule to give other domains a chance meanwhile.
    1.47 +         */
    1.48 +        set_current_state(TASK_RUNNING);
    1.49 +        do { 
    1.50 +            schedule();
    1.51 +            timeout = expire - jiffies;
    1.52 +        } 
    1.53 +        while ( (timeout > 0) && is_idle_task(current) );
    1.54 +    }
    1.55 +    else
    1.56 +    {
    1.57 +        init_timer(&timer);
    1.58 +        timer.expires = expire;
    1.59 +        timer.data = (unsigned long) current;
    1.60 +        timer.function = process_timeout;
    1.61 +        
    1.62 +        add_timer(&timer);
    1.63 +        schedule();
    1.64 +        del_timer_sync(&timer);
    1.65 +        
    1.66 +        timeout = expire - jiffies;
    1.67 +    }
    1.68 +
    1.69   out:
    1.70      return timeout < 0 ? 0 : timeout;
    1.71  }