ia64/xen-unstable

changeset 5151:0c7bde5b8e83

bitkeeper revision 1.1552 (429480ffbijN4G0QJScaV1h7mcJ23Q)

Simplify the ac_timer interface: mod_ac_timer/add_ac_timer replaced
by set_ac_timer.
Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Wed May 25 13:43:27 2005 +0000 (2005-05-25)
parents 321a7af76a9b
children 6ce01dc5f62f
files xen/arch/ia64/vlsapic.c xen/arch/x86/vmx_intercept.c xen/common/ac_timer.c xen/common/sched_bvt.c xen/common/schedule.c xen/include/xen/ac_timer.h
line diff
     1.1 --- a/xen/arch/ia64/vlsapic.c	Wed May 25 13:07:42 2005 +0000
     1.2 +++ b/xen/arch/ia64/vlsapic.c	Wed May 25 13:43:27 2005 +0000
     1.3 @@ -216,18 +216,13 @@ void vtm_interruption_update(VCPU *vcpu,
     1.4      /* Both last_itc & cur_itc < itm, wait for fire condition */
     1.5      else if ( vtm->timer_hooked ) {
     1.6          expires = NOW() + tick_to_ns(0-diff_now) + TIMER_SLOP;
     1.7 -        mod_ac_timer (&(vtm->vtm_timer), expires);
     1.8 -	printf("mod vtm_timer\n");
     1.9 -//fire_itc = cur_itc;
    1.10 -//fire_itm = vitm;
    1.11 +        set_ac_timer(&vtm->vtm_timer, expires);
    1.12      }
    1.13      else {
    1.14 -        vtm->vtm_timer.expires = NOW() + tick_to_ns(0-diff_now) + TIMER_SLOP;
    1.15 +        expires = NOW() + tick_to_ns(0-diff_now) + TIMER_SLOP;
    1.16          vtm->vtm_timer.cpu = vcpu->processor;
    1.17 -            add_ac_timer(&(vtm->vtm_timer));
    1.18 -            vtm->timer_hooked = 1;
    1.19 -//fire_itc = cur_itc;
    1.20 -//fire_itm = vitm;
    1.21 +        set_ac_timer(&vtm->vtm_timer, expires);
    1.22 +        vtm->timer_hooked = 1;
    1.23      }
    1.24      local_irq_restore(spsr);
    1.25  }
     2.1 --- a/xen/arch/x86/vmx_intercept.c	Wed May 25 13:07:42 2005 +0000
     2.2 +++ b/xen/arch/x86/vmx_intercept.c	Wed May 25 13:43:27 2005 +0000
     2.3 @@ -193,14 +193,11 @@ static void pit_timer_fn(unsigned long d
     2.4  {
     2.5      struct vmx_virpit_t *vpit = (struct vmx_virpit_t*)data;
     2.6  
     2.7 -    /* rearm itself */
     2.8 -    vpit->pit_timer.expires = NOW() + MILLISECS(vpit->period);
     2.9 -
    2.10      /*set the pending intr bit in shared page, send evtchn notification to myself*/
    2.11      if (test_and_set_bit(vpit->vector, vpit->intr_bitmap))
    2.12          vpit->pending_intr_nr++; /* if originaly set, then count the pending intr */
    2.13  
    2.14 -    add_ac_timer(&(vpit->pit_timer));
    2.15 +    set_ac_timer(&vpit->pit_timer, NOW() + MILLISECS(vpit->period));
    2.16  }
    2.17  
    2.18  
     3.1 --- a/xen/common/ac_timer.c	Wed May 25 13:07:42 2005 +0000
     3.2 +++ b/xen/common/ac_timer.c	Wed May 25 13:43:27 2005 +0000
     3.3 @@ -114,23 +114,31 @@ static int remove_entry(struct ac_timer 
     3.4  
     3.5  
     3.6  /* Add new entry @t to @heap. Return TRUE if new top of heap. */
     3.7 -static int add_entry(struct ac_timer **heap, struct ac_timer *t)
     3.8 +static int add_entry(struct ac_timer ***pheap, struct ac_timer *t)
     3.9  {
    3.10 -    int sz = GET_HEAP_SIZE(heap);
    3.11 +    int sz, limit;
    3.12 +    struct ac_timer **heap;
    3.13 +
    3.14 +    /* Create initial heap if not already initialised. */
    3.15 +    if ( unlikely((heap = *pheap) == NULL) )
    3.16 +    {
    3.17 +        heap = xmalloc_array(struct ac_timer *, DEFAULT_HEAP_LIMIT + 1);
    3.18 +        BUG_ON(heap == NULL);
    3.19 +        SET_HEAP_SIZE(heap, 0);
    3.20 +        SET_HEAP_LIMIT(heap, DEFAULT_HEAP_LIMIT);
    3.21 +        *pheap = heap;
    3.22 +    }
    3.23  
    3.24      /* Copy the heap if it is full. */
    3.25 -    if ( unlikely(sz == GET_HEAP_LIMIT(heap)) )
    3.26 +    if ( unlikely((sz = GET_HEAP_SIZE(heap)) == GET_HEAP_LIMIT(heap)) )
    3.27      {
    3.28 -        int i, limit = (GET_HEAP_LIMIT(heap)+1) << 1;
    3.29 -        struct ac_timer **new_heap = xmalloc_array(struct ac_timer *, limit);
    3.30 -        if ( new_heap == NULL ) BUG();
    3.31 -        memcpy(new_heap, heap, (limit>>1)*sizeof(struct ac_timer *));
    3.32 -        for ( i = 0; i < NR_CPUS; i++ )
    3.33 -            if ( ac_timers[i].heap == heap )
    3.34 -                ac_timers[i].heap = new_heap;
    3.35 -        xfree(heap);
    3.36 -        heap = new_heap;
    3.37 -        SET_HEAP_LIMIT(heap, limit-1);
    3.38 +        limit = (GET_HEAP_LIMIT(heap) << 1) + 1; /* 2^(n+1) - 1 */
    3.39 +        heap = xmalloc_array(struct ac_timer *, limit + 1);
    3.40 +        BUG_ON(heap == NULL);
    3.41 +        memcpy(heap, *pheap, ((limit >> 1) + 1) * sizeof(struct ac_timer *));
    3.42 +        SET_HEAP_LIMIT(heap, limit);
    3.43 +        xfree(*pheap);
    3.44 +        *pheap = heap;
    3.45      }
    3.46  
    3.47      SET_HEAP_SIZE(heap, ++sz);
    3.48 @@ -148,22 +156,10 @@ static int add_entry(struct ac_timer **h
    3.49  static inline void __add_ac_timer(struct ac_timer *timer)
    3.50  {
    3.51      int cpu = timer->cpu;
    3.52 -    if ( add_entry(ac_timers[cpu].heap, timer) )
    3.53 +    if ( add_entry(&ac_timers[cpu].heap, timer) )
    3.54          cpu_raise_softirq(cpu, AC_TIMER_SOFTIRQ);
    3.55  }
    3.56  
    3.57 -void add_ac_timer(struct ac_timer *timer) 
    3.58 -{
    3.59 -    int           cpu = timer->cpu;
    3.60 -    unsigned long flags;
    3.61 -
    3.62 -    spin_lock_irqsave(&ac_timers[cpu].lock, flags);
    3.63 -    ASSERT(timer != NULL);
    3.64 -    ASSERT(!active_ac_timer(timer));
    3.65 -    __add_ac_timer(timer);
    3.66 -    spin_unlock_irqrestore(&ac_timers[cpu].lock, flags);
    3.67 -}
    3.68 -
    3.69  
    3.70  static inline void __rem_ac_timer(struct ac_timer *timer)
    3.71  {
    3.72 @@ -172,6 +168,22 @@ static inline void __rem_ac_timer(struct
    3.73          cpu_raise_softirq(cpu, AC_TIMER_SOFTIRQ);
    3.74  }
    3.75  
    3.76 +
    3.77 +void set_ac_timer(struct ac_timer *timer, s_time_t expires)
    3.78 +{
    3.79 +    int           cpu = timer->cpu;
    3.80 +    unsigned long flags;
    3.81 +
    3.82 +    spin_lock_irqsave(&ac_timers[cpu].lock, flags);
    3.83 +    ASSERT(timer != NULL);
    3.84 +    if ( active_ac_timer(timer) )
    3.85 +        __rem_ac_timer(timer);
    3.86 +    timer->expires = expires;
    3.87 +    __add_ac_timer(timer);
    3.88 +    spin_unlock_irqrestore(&ac_timers[cpu].lock, flags);
    3.89 +}
    3.90 +
    3.91 +
    3.92  void rem_ac_timer(struct ac_timer *timer)
    3.93  {
    3.94      int           cpu = timer->cpu;
    3.95 @@ -185,21 +197,6 @@ void rem_ac_timer(struct ac_timer *timer
    3.96  }
    3.97  
    3.98  
    3.99 -void mod_ac_timer(struct ac_timer *timer, s_time_t new_time)
   3.100 -{
   3.101 -    int           cpu = timer->cpu;
   3.102 -    unsigned long flags;
   3.103 -
   3.104 -    spin_lock_irqsave(&ac_timers[cpu].lock, flags);
   3.105 -    ASSERT(timer != NULL);
   3.106 -    if ( active_ac_timer(timer) )
   3.107 -        __rem_ac_timer(timer);
   3.108 -    timer->expires = new_time;
   3.109 -    __add_ac_timer(timer);
   3.110 -    spin_unlock_irqrestore(&ac_timers[cpu].lock, flags);
   3.111 -}
   3.112 -
   3.113 -
   3.114  static void ac_timer_softirq_action(void)
   3.115  {
   3.116      int              cpu = smp_processor_id();
   3.117 @@ -271,15 +268,7 @@ void __init ac_timer_init(void)
   3.118      open_softirq(AC_TIMER_SOFTIRQ, ac_timer_softirq_action);
   3.119  
   3.120      for ( i = 0; i < NR_CPUS; i++ )
   3.121 -    {
   3.122 -        ac_timers[i].heap = xmalloc_array(
   3.123 -            struct ac_timer *, DEFAULT_HEAP_LIMIT+1);
   3.124 -        BUG_ON(ac_timers[i].heap == NULL);
   3.125 -
   3.126 -        SET_HEAP_SIZE(ac_timers[i].heap, 0);
   3.127 -        SET_HEAP_LIMIT(ac_timers[i].heap, DEFAULT_HEAP_LIMIT);
   3.128          spin_lock_init(&ac_timers[i].lock);
   3.129 -    }
   3.130  
   3.131      register_keyhandler('a', dump_timerq, "dump ac_timer queues");
   3.132  }
     4.1 --- a/xen/common/sched_bvt.c	Wed May 25 13:07:42 2005 +0000
     4.2 +++ b/xen/common/sched_bvt.c	Wed May 25 13:43:27 2005 +0000
     4.3 @@ -110,9 +110,7 @@ static void warp_timer_fn(unsigned long 
     4.4          cpu_raise_softirq(cpu, SCHEDULE_SOFTIRQ);   
     4.5      }
     4.6      
     4.7 -    /* set unwarp timer */
     4.8 -    inf->unwarp_timer.expires = NOW() + inf->warpu;
     4.9 -    add_ac_timer(&inf->unwarp_timer);
    4.10 +    set_ac_timer(&inf->unwarp_timer, NOW() + inf->warpu);
    4.11  
    4.12      spin_unlock_irq(&schedule_data[cpu].schedule_lock);
    4.13  }
    4.14 @@ -276,7 +274,7 @@ static void bvt_wake(struct exec_domain 
    4.15      if ( is_idle_task(curr->domain) || (einf->evt <= curr_evt) )
    4.16          cpu_raise_softirq(cpu, SCHEDULE_SOFTIRQ);
    4.17      else if ( schedule_data[cpu].s_timer.expires > r_time )
    4.18 -        mod_ac_timer(&schedule_data[cpu].s_timer, r_time);
    4.19 +        set_ac_timer(&schedule_data[cpu].s_timer, r_time);
    4.20  }
    4.21  
    4.22  
    4.23 @@ -439,13 +437,8 @@ static struct task_slice bvt_do_schedule
    4.24              min_avt = p_einf->avt;
    4.25      }
    4.26      
    4.27 -    if(next_einf->inf->warp && next_einf->inf->warpl > 0)
    4.28 -    {
    4.29 -        /* Set the timer up */ 
    4.30 -        next_einf->inf->warp_timer.expires = now + next_einf->inf->warpl;
    4.31 -        /* Add it to the heap */
    4.32 -        add_ac_timer(&next_einf->inf->warp_timer);
    4.33 -    }
    4.34 +    if ( next_einf->inf->warp && next_einf->inf->warpl > 0 )
    4.35 +        set_ac_timer(&next_einf->inf->warp_timer, now + next_einf->inf->warpl);
    4.36     
    4.37      /* Extract the domain pointers from the dom infos */
    4.38      next        = next_einf->exec_domain;
     5.1 --- a/xen/common/schedule.c	Wed May 25 13:07:42 2005 +0000
     5.2 +++ b/xen/common/schedule.c	Wed May 25 13:43:27 2005 +0000
     5.3 @@ -298,10 +298,10 @@ long do_set_timer_op(s_time_t timeout)
     5.4  {
     5.5      struct exec_domain *ed = current;
     5.6  
     5.7 -    rem_ac_timer(&ed->timer);
     5.8 -    
     5.9 -    if ( (ed->timer.expires = timeout) != 0 )
    5.10 -        add_ac_timer(&ed->timer);
    5.11 +    if ( timeout == 0 )
    5.12 +        rem_ac_timer(&ed->timer);
    5.13 +    else
    5.14 +        set_ac_timer(&ed->timer, timeout);
    5.15  
    5.16      return 0;
    5.17  }
    5.18 @@ -423,9 +423,7 @@ static void __enter_scheduler(void)
    5.19      
    5.20      next->lastschd = now;
    5.21  
    5.22 -    /* reprogramm the timer */
    5.23 -    schedule_data[cpu].s_timer.expires = now + r_time;
    5.24 -    add_ac_timer(&schedule_data[cpu].s_timer);
    5.25 +    set_ac_timer(&schedule_data[cpu].s_timer, now + r_time);
    5.26  
    5.27      /* Must be protected by the schedule_lock! */
    5.28      set_bit(_VCPUF_running, &next->vcpu_flags);
    5.29 @@ -510,8 +508,7 @@ static void t_timer_fn(unsigned long unu
    5.30  
    5.31      page_scrub_schedule_work();
    5.32  
    5.33 -    t_timer[cpu].expires = NOW() + MILLISECS(10);
    5.34 -    add_ac_timer(&t_timer[cpu]);
    5.35 +    set_ac_timer(&t_timer[cpu], NOW() + MILLISECS(10));
    5.36  }
    5.37  
    5.38  /* Domain timer function, sends a virtual timer interrupt to domain */
     6.1 --- a/xen/include/xen/ac_timer.h	Wed May 25 13:07:42 2005 +0000
     6.2 +++ b/xen/include/xen/ac_timer.h	Wed May 25 13:43:27 2005 +0000
     6.3 @@ -62,9 +62,8 @@ static __inline__ int active_ac_timer(st
     6.4   * This function can be called for any CPU from any CPU in any context, BUT:
     6.5   *  -- The private fields must have been initialised (ac_timer_init).
     6.6   *  -- All public fields must be initialised.
     6.7 - *  -- The timer must not currently be on a timer list.
     6.8   */
     6.9 -extern void add_ac_timer(struct ac_timer *timer);
    6.10 +extern void set_ac_timer(struct ac_timer *timer, s_time_t expires);
    6.11  
    6.12  /*
    6.13   * This function can be called for any CPU from any CPU in any context, BUT:
    6.14 @@ -74,13 +73,6 @@ extern void add_ac_timer(struct ac_timer
    6.15   */
    6.16  extern void rem_ac_timer(struct ac_timer *timer);
    6.17  
    6.18 -/*
    6.19 - * This function can be called for any CPU from any CPU in any context, BUT:
    6.20 - *  -- The private fields must have been initialised (ac_timer_init).
    6.21 - *  -- All public fields must be initialised.
    6.22 - */
    6.23 -extern void mod_ac_timer(struct ac_timer *timer, s_time_t new_time);
    6.24 -
    6.25  
    6.26  /*
    6.27   * PRIVATE DEFINITIONS