ia64/xen-unstable

changeset 6124:be3f65e478d9

Change vpit->period and friends to count in nanoseconds.

This actually reduces the amount of 64 bit math we need to do.

Signed-off-by: Edwin Zhai <edwin.zhai@intel.com>
Signed-off-by: Arun Sharma <arun.sharma@intel.com>
author kaf24@firebug.cl.cam.ac.uk
date Thu Aug 11 21:07:17 2005 +0000 (2005-08-11)
parents ca873c2f5ca2
children edd2f9171644
files xen/arch/x86/vmx_intercept.c
line diff
     1.1 --- a/xen/arch/x86/vmx_intercept.c	Thu Aug 11 21:06:35 2005 +0000
     1.2 +++ b/xen/arch/x86/vmx_intercept.c	Thu Aug 11 21:07:17 2005 +0000
     1.3 @@ -74,10 +74,10 @@ int register_io_handler(unsigned long ad
     1.4  
     1.5  static void pit_cal_count(struct vmx_virpit_t *vpit)
     1.6  {
     1.7 -    unsigned int usec_delta = (unsigned int)((NOW() - vpit->inject_point) / 1000);
     1.8 -    if (usec_delta > vpit->period * 1000)
     1.9 +    u64 nsec_delta = (unsigned int)((NOW() - vpit->inject_point));
    1.10 +    if (nsec_delta > vpit->period)
    1.11          VMX_DBG_LOG(DBG_LEVEL_1, "VMX_PIT:long time has passed from last injection!");
    1.12 -    vpit->count = vpit->init_val - ((usec_delta * PIT_FREQ / 1000000) % vpit->init_val );
    1.13 +    vpit->count = vpit->init_val - ((nsec_delta * PIT_FREQ / 1000000000ULL) % vpit->init_val );
    1.14  }
    1.15  
    1.16  static void pit_latch_io(struct vmx_virpit_t *vpit)
    1.17 @@ -197,9 +197,10 @@ int intercept_pit_io(ioreq_t *p)
    1.18  static void pit_timer_fn(void *data)
    1.19  {
    1.20      struct vmx_virpit_t *vpit = data;
    1.21 -    int missed_ticks;
    1.22 +    s_time_t   next;
    1.23 +    int        missed_ticks;
    1.24  
    1.25 -    missed_ticks = (NOW() - vpit->scheduled) / MILLISECS(vpit->period);
    1.26 +    missed_ticks = (NOW() - vpit->scheduled)/(s_time_t) vpit->period;
    1.27  
    1.28      /* Set the pending intr bit, and send evtchn notification to myself. */
    1.29      if (test_and_set_bit(vpit->vector, vpit->intr_bitmap))
    1.30 @@ -208,13 +209,13 @@ static void pit_timer_fn(void *data)
    1.31      /* pick up missed timer tick */
    1.32      if ( missed_ticks > 0 ) {
    1.33          vpit->pending_intr_nr += missed_ticks;
    1.34 -        vpit->scheduled += missed_ticks * MILLISECS(vpit->period);
    1.35 +        vpit->scheduled += missed_ticks * vpit->period;
    1.36      }
    1.37 -    vpit->scheduled += MILLISECS(vpit->period);
    1.38 -    set_ac_timer(&vpit->pit_timer, vpit->scheduled);
    1.39 +    next = vpit->scheduled + vpit->period;
    1.40 +    set_ac_timer(&vpit->pit_timer, next);
    1.41 +    vpit->scheduled = next;
    1.42  }
    1.43  
    1.44 -
    1.45  /* Only some PIT operations such as load init counter need a hypervisor hook.
    1.46   * leave all other operations in user space DM
    1.47   */
    1.48 @@ -236,16 +237,17 @@ void vmx_hooks_assist(struct vcpu *d)
    1.49              reinit = 1;
    1.50          }
    1.51          else
    1.52 -            init_ac_timer(&vpit->pit_timer, pit_timer_fn, vpit, 0);
    1.53 +            init_ac_timer(&vpit->pit_timer, pit_timer_fn, vpit, d->processor);
    1.54  
    1.55          /* init count for this channel */
    1.56          vpit->init_val = (p->u.data & 0xFFFF) ; 
    1.57 -        /* frequency(ms) of pit */
    1.58 -        vpit->period = DIV_ROUND(((vpit->init_val) * 1000), PIT_FREQ); 
    1.59 -        if (vpit->period < 1) {
    1.60 +        /* frequency(ns) of pit */
    1.61 +        vpit->period = DIV_ROUND(((vpit->init_val) * 1000000000ULL), PIT_FREQ); 
    1.62 +        VMX_DBG_LOG(DBG_LEVEL_1,"VMX_PIT: guest set init pit freq:%u ns, initval:0x%x\n", vpit->period, vpit->init_val);
    1.63 +        if (vpit->period < 900000) { /* < 0.9 ms */
    1.64              printk("VMX_PIT: guest programmed too small an init_val: %x\n",
    1.65                     vpit->init_val);
    1.66 -            vpit->period = 1;
    1.67 +            vpit->period = 1000000;
    1.68          }
    1.69          vpit->vector = ((p->u.data >> 16) & 0xFF);
    1.70          vpit->channel = ((p->u.data >> 24) & 0x3);
    1.71 @@ -272,7 +274,7 @@ void vmx_hooks_assist(struct vcpu *d)
    1.72  
    1.73          vpit->intr_bitmap = intr;
    1.74  
    1.75 -        vpit->scheduled = NOW() + MILLISECS(vpit->period);
    1.76 +        vpit->scheduled = NOW() + vpit->period;
    1.77          set_ac_timer(&vpit->pit_timer, vpit->scheduled);
    1.78  
    1.79          /*restore the state*/