ia64/xen-unstable

changeset 5165:98ec71a98df7

bitkeeper revision 1.1562 (4295c663e2dmLlYutTmiDxZ2_Qkpnw)

Fix ac_timer initialisation.
Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Thu May 26 12:51:47 2005 +0000 (2005-05-26)
parents 943337479992
children d867c2bbd27e fc10e6241938
files xen/common/ac_timer.c
line diff
     1.1 --- a/xen/common/ac_timer.c	Thu May 26 08:06:01 2005 +0000
     1.2 +++ b/xen/common/ac_timer.c	Thu May 26 12:51:47 2005 +0000
     1.3 @@ -26,8 +26,6 @@
     1.4   */
     1.5  #define TIMER_SLOP (50*1000) /* ns */
     1.6  
     1.7 -#define DEFAULT_HEAP_LIMIT 127
     1.8 -
     1.9  struct ac_timers ac_timers[NR_CPUS];
    1.10  
    1.11  /****************************************************************************
    1.12 @@ -110,28 +108,21 @@ static int remove_entry(struct ac_timer 
    1.13  /* Add new entry @t to @heap. Return TRUE if new top of heap. */
    1.14  static int add_entry(struct ac_timer ***pheap, struct ac_timer *t)
    1.15  {
    1.16 -    int sz, limit;
    1.17 -    struct ac_timer **heap;
    1.18 -
    1.19 -    /* Create initial heap if not already initialised. */
    1.20 -    if ( unlikely((heap = *pheap) == NULL) )
    1.21 -    {
    1.22 -        heap = xmalloc_array(struct ac_timer *, DEFAULT_HEAP_LIMIT + 1);
    1.23 -        BUG_ON(heap == NULL);
    1.24 -        SET_HEAP_SIZE(heap, 0);
    1.25 -        SET_HEAP_LIMIT(heap, DEFAULT_HEAP_LIMIT);
    1.26 -        *pheap = heap;
    1.27 -    }
    1.28 +    struct ac_timer **heap = *pheap;
    1.29 +    int sz = GET_HEAP_SIZE(heap);
    1.30  
    1.31      /* Copy the heap if it is full. */
    1.32 -    if ( unlikely((sz = GET_HEAP_SIZE(heap)) == GET_HEAP_LIMIT(heap)) )
    1.33 +    if ( unlikely(sz == GET_HEAP_LIMIT(heap)) )
    1.34      {
    1.35 -        limit = (GET_HEAP_LIMIT(heap) << 1) + 1; /* 2^(n+1) - 1 */
    1.36 -        heap = xmalloc_array(struct ac_timer *, limit + 1);
    1.37 +        /* old_limit == (2^n)-1; new_limit == (2^(n+4))-1 */
    1.38 +        int old_limit = GET_HEAP_LIMIT(heap);
    1.39 +        int new_limit = ((old_limit + 1) << 4) - 1;
    1.40 +        heap = xmalloc_array(struct ac_timer *, new_limit + 1);
    1.41          BUG_ON(heap == NULL);
    1.42 -        memcpy(heap, *pheap, ((limit >> 1) + 1) * sizeof(struct ac_timer *));
    1.43 -        SET_HEAP_LIMIT(heap, limit);
    1.44 -        xfree(*pheap);
    1.45 +        memcpy(heap, *pheap, (old_limit + 1) * sizeof(*heap));
    1.46 +        SET_HEAP_LIMIT(heap, new_limit);
    1.47 +        if ( old_limit != 0 )
    1.48 +            xfree(*pheap);
    1.49          *pheap = heap;
    1.50      }
    1.51  
    1.52 @@ -257,12 +248,23 @@ static void dump_timerq(unsigned char ke
    1.53  
    1.54  void __init ac_timer_init(void)
    1.55  {
    1.56 +    static struct ac_timer *dummy_heap;
    1.57      int i;
    1.58  
    1.59      open_softirq(AC_TIMER_SOFTIRQ, ac_timer_softirq_action);
    1.60  
    1.61 +    /*
    1.62 +     * All CPUs initially share an empty dummy heap. Only those CPUs that
    1.63 +     * are brought online will be dynamically allocated their own heap.
    1.64 +     */
    1.65 +    SET_HEAP_SIZE(&dummy_heap, 0);
    1.66 +    SET_HEAP_LIMIT(&dummy_heap, 0);
    1.67 +
    1.68      for ( i = 0; i < NR_CPUS; i++ )
    1.69 +    {
    1.70          spin_lock_init(&ac_timers[i].lock);
    1.71 +        ac_timers[i].heap = &dummy_heap;
    1.72 +    }
    1.73  
    1.74      register_keyhandler('a', dump_timerq, "dump ac_timer queues");
    1.75  }