direct-io.hg

changeset 2513:8cd5855b0bab

bitkeeper revision 1.1159.79.13 (4151745aQFYQyiyDcwHh4KsbytECJg)

Fix time.
author cl349@freefall.cl.cam.ac.uk
date Wed Sep 22 12:47:22 2004 +0000 (2004-09-22)
parents 4553261ed7cb
children 669a7dd084ec
files netbsd-2.0-xen-sparse/sys/arch/xen/conf/XEN netbsd-2.0-xen-sparse/sys/arch/xen/xen/clock.c
line diff
     1.1 --- a/netbsd-2.0-xen-sparse/sys/arch/xen/conf/XEN	Wed Sep 22 12:26:34 2004 +0000
     1.2 +++ b/netbsd-2.0-xen-sparse/sys/arch/xen/conf/XEN	Wed Sep 22 12:47:22 2004 +0000
     1.3 @@ -13,7 +13,6 @@ maxusers	32		# estimated number of users
     1.4  #
     1.5  options		XEN
     1.6  #options		DOM0OPS
     1.7 -options		HZ=50
     1.8  
     1.9  #options 	I586_CPU
    1.10  options 	I686_CPU
     2.1 --- a/netbsd-2.0-xen-sparse/sys/arch/xen/xen/clock.c	Wed Sep 22 12:26:34 2004 +0000
     2.2 +++ b/netbsd-2.0-xen-sparse/sys/arch/xen/xen/clock.c	Wed Sep 22 12:47:22 2004 +0000
     2.3 @@ -54,13 +54,17 @@
     2.4  static int xen_timer_handler(void *, struct trapframe *);
     2.5  
     2.6  /* These are peridically updated in shared_info, and then copied here. */
     2.7 -static unsigned long shadow_tsc_stamp;
     2.8 -static u_int64_t shadow_system_time;
     2.9 +static uint64_t shadow_tsc_stamp;
    2.10 +static uint64_t shadow_system_time;
    2.11  static unsigned long shadow_time_version;
    2.12  static struct timeval shadow_tv;
    2.13  
    2.14  static int timeset;
    2.15  
    2.16 +static uint64_t processed_system_time;
    2.17 +
    2.18 +#define NS_PER_TICK (1000000000ULL/hz)
    2.19 +
    2.20  /*
    2.21   * Reads a consistent set of time-base values from Xen, into a shadow data
    2.22   * area.  Must be called at splclock.
    2.23 @@ -79,6 +83,16 @@ get_time_values_from_xen(void)
    2.24  	} while (shadow_time_version != HYPERVISOR_shared_info->time_version1);
    2.25  }
    2.26  
    2.27 +static uint64_t
    2.28 +get_tsc_offset_ns(void)
    2.29 +{
    2.30 +	uint32_t tsc_delta;
    2.31 +	struct cpu_info *ci = curcpu();
    2.32 +
    2.33 +	tsc_delta = cpu_counter32() - shadow_tsc_stamp;
    2.34 +	return tsc_delta * 1000000000 / cpu_frequency(ci);
    2.35 +}
    2.36 +
    2.37  void
    2.38  inittodr(time_t base)
    2.39  {
    2.40 @@ -190,6 +204,9 @@ xen_initclocks()
    2.41  {
    2.42  	int irq = bind_virq_to_irq(VIRQ_TIMER);
    2.43  
    2.44 +	get_time_values_from_xen();
    2.45 +	processed_system_time = shadow_system_time;
    2.46 +
    2.47  	event_set_handler(irq, (int (*)(void *))xen_timer_handler,
    2.48  	    NULL, IPL_CLOCK);
    2.49  	hypervisor_enable_irq(irq);
    2.50 @@ -198,6 +215,8 @@ xen_initclocks()
    2.51  static int
    2.52  xen_timer_handler(void *arg, struct trapframe *regs)
    2.53  {
    2.54 +	int64_t delta;
    2.55 +
    2.56  #if defined(I586_CPU) || defined(I686_CPU)
    2.57  	static int microset_iter; /* call cc_microset once/sec */
    2.58  	struct cpu_info *ci = curcpu();
    2.59 @@ -223,7 +242,13 @@ xen_timer_handler(void *arg, struct trap
    2.60  
    2.61  	get_time_values_from_xen();
    2.62  
    2.63 -	hardclock((struct clockframe *)regs);
    2.64 +	delta = (int64_t)(shadow_system_time + get_tsc_offset_ns() -
    2.65 +			  processed_system_time);
    2.66 +	while (delta >= NS_PER_TICK) {
    2.67 +		hardclock((struct clockframe *)regs);
    2.68 +		delta -= NS_PER_TICK;
    2.69 +		processed_system_time += NS_PER_TICK;
    2.70 +	}
    2.71  
    2.72  	return 0;
    2.73  }