ia64/xen-unstable

changeset 718:ec38a236c5db

bitkeeper revision 1.424.1.1 (3f61e2afHSuo-MbsBfF4HF_JFYfgdQ)

sched.h, schedule.c, setup.c, process.c:
Fix initialisation of idle tasks so that they are put on the runqueue earlier.
author kaf24@scramble.cl.cam.ac.uk
date Fri Sep 12 15:13:51 2003 +0000 (2003-09-12)
parents 4778f77eb1bf
children d0cdb9994a2b
files xen/arch/i386/process.c xen/arch/i386/setup.c xen/common/schedule.c xen/include/xeno/sched.h
line diff
     1.1 --- a/xen/arch/i386/process.c	Thu Sep 11 10:15:23 2003 +0000
     1.2 +++ b/xen/arch/i386/process.c	Fri Sep 12 15:13:51 2003 +0000
     1.3 @@ -73,9 +73,8 @@ void cpu_idle (void)
     1.4  {
     1.5      int cpu = smp_processor_id();
     1.6  
     1.7 +    /* Just some sanity to ensure that the scheduler is set up okay. */
     1.8      ASSERT(current->domain == IDLE_DOMAIN_ID);
     1.9 -
    1.10 -    current->has_cpu = 1;
    1.11      (void)wake_up(current);
    1.12      schedule();
    1.13  
     2.1 --- a/xen/arch/i386/setup.c	Thu Sep 11 10:15:23 2003 +0000
     2.2 +++ b/xen/arch/i386/setup.c	Fri Sep 12 15:13:51 2003 +0000
     2.3 @@ -271,6 +271,8 @@ void __init cpu_init(void)
     2.4      mapcache[nr] = (unsigned long *)get_free_page(GFP_KERNEL);
     2.5      clear_page(mapcache[nr]);
     2.6      *pl2e = mk_l2_pgentry(__pa(mapcache[nr]) | PAGE_HYPERVISOR);
     2.7 +
     2.8 +    init_idle_task();
     2.9  }
    2.10  
    2.11  static void __init do_initcalls(void)
     3.1 --- a/xen/common/schedule.c	Thu Sep 11 10:15:23 2003 +0000
     3.2 +++ b/xen/common/schedule.c	Fri Sep 12 15:13:51 2003 +0000
     3.3 @@ -1,22 +1,15 @@
     3.4  /* -*-  Mode:C; c-basic-offset:4; tab-width:4 -*-
     3.5   ****************************************************************************
     3.6 - * (C) 2002 - Rolf Neugebauer - Intel Research Cambridge
     3.7 + * (C) 2002-2003 - Rolf Neugebauer - Intel Research Cambridge
     3.8 + * (C) 2002-2003 University of Cambridge
     3.9   ****************************************************************************
    3.10   *
    3.11 - *        File: schedule.c
    3.12 - *      Author: Rolf Neugebauer (neugebar@dcs.gla.ac.uk)
    3.13 - *     Changes: 
    3.14 - *              
    3.15 - *        Date: Nov 2002
    3.16 + *        File: common/schedule.c
    3.17 + *      Author: Rolf Neugebar & Keir Fraser
    3.18   * 
    3.19 - * Environment: Xen Hypervisor
    3.20   * Description: CPU scheduling
    3.21   *              implements A Borrowed Virtual Time scheduler.
    3.22   *              (see Duda & Cheriton SOSP'99)
    3.23 - *
    3.24 - ****************************************************************************
    3.25 - * $Id: c-insert.c,v 1.7 2002/11/08 16:04:34 rn Exp $
    3.26 - ****************************************************************************
    3.27   */
    3.28  
    3.29  #include <xeno/config.h>
    3.30 @@ -39,20 +32,16 @@
    3.31  #define TRC(_x)
    3.32  #endif
    3.33  
    3.34 -#define SCHED_HISTO
    3.35 +/*#define SCHED_HISTO*/
    3.36  #ifdef SCHED_HISTO
    3.37  #define BUCKETS 31
    3.38  #endif
    3.39  
    3.40 +#define MCU            (s32)MICROSECS(100)    /* Minimum unit */
    3.41 +#define MCU_ADVANCE    10                     /* default weight */
    3.42 +#define TIME_SLOP      (s32)MICROSECS(50)     /* allow time to slip a bit */
    3.43 +static s32 ctx_allow = (s32)MILLISECS(5);     /* context switch allowance */
    3.44  
    3.45 -#define MCU          (s32)MICROSECS(100)    /* Minimum unit */
    3.46 -#define MCU_ADVANCE  10                     /* default weight */
    3.47 -#define TIME_SLOP    (s32)MICROSECS(50)     /* allow time to slip a bit */
    3.48 -static s32 ctx_allow=(s32)MILLISECS(5);     /* context switch allowance */
    3.49 -
    3.50 -/*****************************************************************************
    3.51 - * per CPU data for the scheduler.
    3.52 - *****************************************************************************/
    3.53  typedef struct schedule_data_st
    3.54  {
    3.55      spinlock_t          lock;           /* lock for protecting this */
    3.56 @@ -64,61 +53,59 @@ typedef struct schedule_data_st
    3.57  #ifdef SCHED_HISTO
    3.58      u32                 hist[BUCKETS];  /* for scheduler latency histogram */
    3.59  #endif
    3.60 -
    3.61  } __cacheline_aligned schedule_data_t;
    3.62  schedule_data_t schedule_data[NR_CPUS];
    3.63  
    3.64 -struct ac_timer     v_timer;        /* scheduling timer  */
    3.65 +struct ac_timer v_timer;        /* scheduling timer  */
    3.66  static void virt_timer(unsigned long foo);
    3.67  static void dump_rqueue(struct list_head *queue, char *name);
    3.68  
    3.69  
    3.70 -/*****************************************************************************
    3.71 - * Some convenience functions
    3.72 - *****************************************************************************/
    3.73 -/* add a task to the head of the runqueue */
    3.74  static inline void __add_to_runqueue_head(struct task_struct * p)
    3.75 -{
    3.76 -    
    3.77 +{    
    3.78      list_add(&p->run_list, &schedule_data[p->processor].runqueue);
    3.79  }
    3.80 -/* add a task to the tail of the runqueue */
    3.81 +
    3.82  static inline void __add_to_runqueue_tail(struct task_struct * p)
    3.83  {
    3.84      list_add_tail(&p->run_list, &schedule_data[p->processor].runqueue);
    3.85  }
    3.86  
    3.87 -/* remove a task from runqueue  */
    3.88  static inline void __del_from_runqueue(struct task_struct * p)
    3.89  {
    3.90      list_del(&p->run_list);
    3.91      p->run_list.next = NULL;
    3.92  }
    3.93 -/* is task on run queue?  */
    3.94 +
    3.95  static inline int __task_on_runqueue(struct task_struct *p)
    3.96  {
    3.97 -    return (p->run_list.next != NULL);
    3.98 +    return p->run_list.next != NULL;
    3.99  }
   3.100  
   3.101  #define next_domain(p) \\
   3.102          list_entry((p)->run_list.next, struct task_struct, run_list)
   3.103  
   3.104 -/* calculate evt  */
   3.105  static void __calc_evt(struct task_struct *p)
   3.106  {
   3.107      s_time_t now = NOW();
   3.108 -    if (p->warpback) {
   3.109 -        if (((now - p->warped) < p->warpl) &&
   3.110 -            ((now - p->uwarped) > p->warpu)) {
   3.111 +    if ( p->warpback ) 
   3.112 +    {
   3.113 +        if ( ((now - p->warped) < p->warpl) &&
   3.114 +             ((now - p->uwarped) > p->warpu) )
   3.115 +        {
   3.116              /* allowed to warp */
   3.117              p->evt = p->avt - p->warp;
   3.118 -        } else {
   3.119 +        } 
   3.120 +        else 
   3.121 +        {
   3.122              /* warped for too long -> unwarp */
   3.123              p->evt      = p->avt;
   3.124              p->uwarped  = now;
   3.125              p->warpback = 0;
   3.126          }
   3.127 -    } else {
   3.128 +    } 
   3.129 +    else 
   3.130 +    {
   3.131          p->evt = p->avt;
   3.132      }
   3.133  }
   3.134 @@ -132,11 +119,14 @@ void sched_add_domain(struct task_struct
   3.135      p->state       = TASK_SUSPENDED;
   3.136      p->mcu_advance = MCU_ADVANCE;
   3.137  
   3.138 -    if (p->domain == IDLE_DOMAIN_ID) {
   3.139 +    if ( p->domain == IDLE_DOMAIN_ID )
   3.140 +    {
   3.141          p->avt = 0xffffffff;
   3.142          p->evt = 0xffffffff;
   3.143          schedule_data[p->processor].idle = p;
   3.144 -    } else {
   3.145 +    } 
   3.146 +    else 
   3.147 +    {
   3.148          /* set avt end evt to system virtual time */
   3.149          p->avt         = schedule_data[p->processor].svt;
   3.150          p->evt         = schedule_data[p->processor].svt;
   3.151 @@ -154,6 +144,19 @@ void sched_rem_domain(struct task_struct
   3.152  }
   3.153  
   3.154  
   3.155 +void init_idle_task(void)
   3.156 +{
   3.157 +    unsigned long flags;
   3.158 +    struct task_struct *p = current;
   3.159 +    spin_lock_irqsave(&schedule_data[p->processor].lock, flags);
   3.160 +    p->has_cpu = 1;
   3.161 +    p->state = TASK_RUNNING;
   3.162 +    if ( !__task_on_runqueue(p) )
   3.163 +        __add_to_runqueue_head(p);
   3.164 +    spin_unlock_irqrestore(&schedule_data[p->processor].lock, flags);
   3.165 +}
   3.166 +
   3.167 +
   3.168  /****************************************************************************
   3.169   * wake up a domain which had been sleeping
   3.170   ****************************************************************************/
     4.1 --- a/xen/include/xeno/sched.h	Thu Sep 11 10:15:23 2003 +0000
     4.2 +++ b/xen/include/xeno/sched.h	Fri Sep 12 15:13:51 2003 +0000
     4.3 @@ -271,6 +271,7 @@ void sched_rem_domain(struct task_struct
     4.4  long sched_bvtctl(unsigned long ctx_allow);
     4.5  long sched_adjdom(int dom, unsigned long mcu_adv, unsigned long warp, 
     4.6                    unsigned long warpl, unsigned long warpu);
     4.7 +void init_idle_task(void);
     4.8  int  wake_up(struct task_struct *p);
     4.9  long schedule_timeout(long timeout);
    4.10  long do_yield(void);