ia64/xen-unstable

changeset 2148:5ca8e45604f4

bitkeeper revision 1.1159.1.25 (4117be6bLYYSPEpF52jdon8ylnpbvg)

Merge freefall.cl.cam.ac.uk:/auto/groups/xeno/BK/xeno.bk
into freefall.cl.cam.ac.uk:/auto/groups/xeno/users/cl349/BK/xeno.bk-26dom0
author cl349@freefall.cl.cam.ac.uk
date Mon Aug 09 18:11:55 2004 +0000 (2004-08-09)
parents 949f21fc9e77 ba0b77068ab6
children 0b883cd8b325
files linux-2.4.26-xen-sparse/arch/xen/kernel/time.c linux-2.6.7-xen-sparse/arch/xen/i386/kernel/time.c
line diff
     1.1 --- a/linux-2.4.26-xen-sparse/arch/xen/kernel/time.c	Mon Aug 09 17:38:41 2004 +0000
     1.2 +++ b/linux-2.4.26-xen-sparse/arch/xen/kernel/time.c	Mon Aug 09 18:11:55 2004 +0000
     1.3 @@ -299,6 +299,7 @@ void do_gettimeofday(struct timeval *tv)
     1.4  void do_settimeofday(struct timeval *tv)
     1.5  {
     1.6      struct timeval newtv;
     1.7 +    suseconds_t usec;
     1.8      
     1.9      if ( !independent_wallclock && !(start_info.flags & SIF_INITDOMAIN) )
    1.10          return;
    1.11 @@ -311,12 +312,13 @@ void do_settimeofday(struct timeval *tv)
    1.12       * be stale, so we can retry with fresh ones.
    1.13       */
    1.14   again:
    1.15 -    tv->tv_usec -= __get_time_delta_usecs();
    1.16 +    usec = tv->tv_usec - __get_time_delta_usecs();
    1.17      if ( unlikely(!TIME_VALUES_UP_TO_DATE) )
    1.18      {
    1.19          __get_time_values_from_xen();
    1.20          goto again;
    1.21      }
    1.22 +    tv->tv_usec = usec;
    1.23      
    1.24      HANDLE_USEC_UNDERFLOW(*tv);
    1.25      
     2.1 --- a/linux-2.6.7-xen-sparse/arch/xen/i386/kernel/time.c	Mon Aug 09 17:38:41 2004 +0000
     2.2 +++ b/linux-2.6.7-xen-sparse/arch/xen/i386/kernel/time.c	Mon Aug 09 18:11:55 2004 +0000
     2.3 @@ -114,29 +114,36 @@ u64 processed_system_time;   /* System t
     2.4  
     2.5  #define NS_PER_TICK (1000000000ULL/HZ)
     2.6  
     2.7 -#define HANDLE_USEC_UNDERFLOW(_tv)         \
     2.8 -    do {                                   \
     2.9 -        while ( (_tv).tv_usec < 0 )        \
    2.10 -        {                                  \
    2.11 -            (_tv).tv_usec += 1000000;      \
    2.12 -            (_tv).tv_sec--;                \
    2.13 -        }                                  \
    2.14 -    } while ( 0 )
    2.15 -#define HANDLE_USEC_OVERFLOW(_tv)          \
    2.16 -    do {                                   \
    2.17 -        while ( (_tv).tv_usec >= 1000000 ) \
    2.18 -        {                                  \
    2.19 -            (_tv).tv_usec -= 1000000;      \
    2.20 -            (_tv).tv_sec++;                \
    2.21 -        }                                  \
    2.22 -    } while ( 0 )
    2.23 +#define HANDLE_USEC_UNDERFLOW(_tv) do {		\
    2.24 +	while ((_tv).tv_usec < 0) {		\
    2.25 +		(_tv).tv_usec += USEC_PER_SEC;	\
    2.26 +		(_tv).tv_sec--;			\
    2.27 +	}					\
    2.28 +} while (0)
    2.29 +#define HANDLE_USEC_OVERFLOW(_tv) do {		\
    2.30 +	while ((_tv).tv_usec >= USEC_PER_SEC) {	\
    2.31 +		(_tv).tv_usec -= USEC_PER_SEC;	\
    2.32 +		(_tv).tv_sec++;			\
    2.33 +	}					\
    2.34 +} while (0)
    2.35 +static inline void __normalize_time(time_t *sec, s64 *usec)
    2.36 +{
    2.37 +	while (*usec >= NSEC_PER_SEC) {
    2.38 +		(*usec) -= NSEC_PER_SEC;
    2.39 +		(*sec)++;
    2.40 +	}
    2.41 +	while (*usec < NSEC_PER_SEC) {
    2.42 +		(*usec) += NSEC_PER_SEC;
    2.43 +		(*sec)--;
    2.44 +	}
    2.45 +}
    2.46  
    2.47  /* Does this guest OS track Xen time, or set its wall clock independently? */
    2.48  static int independent_wallclock = 0;
    2.49  static int __init __independent_wallclock(char *str)
    2.50  {
    2.51 -    independent_wallclock = 1;
    2.52 -    return 1;
    2.53 +	independent_wallclock = 1;
    2.54 +	return 1;
    2.55  }
    2.56  __setup("independent_wallclock", __independent_wallclock);
    2.57  
    2.58 @@ -175,6 +182,7 @@ void do_gettimeofday(struct timeval *tv)
    2.59  	unsigned long usec, sec;
    2.60  	unsigned long max_ntp_tick;
    2.61  	unsigned long flags;
    2.62 +	s64 nsec;
    2.63  
    2.64  	do {
    2.65  		unsigned long lost;
    2.66 @@ -199,12 +207,13 @@ void do_gettimeofday(struct timeval *tv)
    2.67  		else if (unlikely(lost))
    2.68  			usec += lost * (USEC_PER_SEC / HZ);
    2.69  
    2.70 -		usec += ((unsigned long)(shadow_system_time -
    2.71 -			processed_system_time) / NSEC_PER_USEC);
    2.72 -
    2.73  		sec = xtime.tv_sec;
    2.74  		usec += (xtime.tv_nsec / NSEC_PER_USEC);
    2.75  
    2.76 +		nsec = shadow_system_time - processed_system_time;
    2.77 +		__normalize_time(&sec, &nsec);
    2.78 +		usec += (long)nsec / NSEC_PER_USEC;
    2.79 +
    2.80  		if (unlikely(!TIME_VALUES_UP_TO_DATE)) {
    2.81  			/*
    2.82  			 * We may have blocked for a long time,
    2.83 @@ -220,8 +229,8 @@ void do_gettimeofday(struct timeval *tv)
    2.84  		}
    2.85  	} while (read_seqretry(&xtime_lock, seq));
    2.86  
    2.87 -	while (usec >= 1000000) {
    2.88 -		usec -= 1000000;
    2.89 +	while (usec >= USEC_PER_SEC) {
    2.90 +		usec -= USEC_PER_SEC;
    2.91  		sec++;
    2.92  	}
    2.93  
    2.94 @@ -244,7 +253,8 @@ EXPORT_SYMBOL(do_gettimeofday);
    2.95  int do_settimeofday(struct timespec *tv)
    2.96  {
    2.97  	time_t wtm_sec, sec = tv->tv_sec;
    2.98 -	long wtm_nsec, nsec = tv->tv_nsec;
    2.99 +	long wtm_nsec;
   2.100 +	s64 nsec;
   2.101  	struct timespec xentime;
   2.102  
   2.103  	if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
   2.104 @@ -261,12 +271,13 @@ int do_settimeofday(struct timespec *tv)
   2.105  	 * be stale, so we can retry with fresh ones.
   2.106  	 */
   2.107   again:
   2.108 -	nsec -= cur_timer->get_offset() * NSEC_PER_USEC;
   2.109 +	nsec = tv->tv_nsec - cur_timer->get_offset() * NSEC_PER_USEC;
   2.110  	if (unlikely(!TIME_VALUES_UP_TO_DATE)) {
   2.111  		__get_time_values_from_xen();
   2.112  		goto again;
   2.113  	}
   2.114  
   2.115 +	__normalize_time(&sec, &nsec);
   2.116  	set_normalized_timespec(&xentime, sec, nsec);
   2.117  
   2.118  	/*
   2.119 @@ -277,8 +288,9 @@ int do_settimeofday(struct timespec *tv)
   2.120  	 */
   2.121  	nsec -= (jiffies - wall_jiffies) * TICK_NSEC;
   2.122  
   2.123 -	nsec -= (unsigned long)(shadow_system_time - processed_system_time);
   2.124 +	nsec -= (shadow_system_time - processed_system_time);
   2.125  
   2.126 +	__normalize_time(&sec, &nsec);
   2.127  	wtm_sec  = wall_to_monotonic.tv_sec + (xtime.tv_sec - sec);
   2.128  	wtm_nsec = wall_to_monotonic.tv_nsec + (xtime.tv_nsec - nsec);
   2.129  
   2.130 @@ -300,7 +312,7 @@ int do_settimeofday(struct timespec *tv)
   2.131  		last_rtc_update = last_update_to_xen = 0;
   2.132  		op.cmd = DOM0_SETTIME;
   2.133  		op.u.settime.secs        = xentime.tv_sec;
   2.134 -		op.u.settime.usecs       = xentime.tv_nsec / 1000;
   2.135 +		op.u.settime.usecs       = xentime.tv_nsec / NSEC_PER_USEC;
   2.136  		op.u.settime.system_time = shadow_system_time;
   2.137  		write_sequnlock_irq(&xtime_lock);
   2.138  		HYPERVISOR_dom0_op(&op);
   2.139 @@ -385,7 +397,7 @@ static inline void do_timer_interrupt(in
   2.140  	    (xtime.tv_sec > (last_update_from_xen + 60))) {
   2.141  		/* Adjust shadow for jiffies that haven't updated xtime yet. */
   2.142  		shadow_tv.tv_usec -= 
   2.143 -			(jiffies - wall_jiffies) * (1000000/HZ);
   2.144 +			(jiffies - wall_jiffies) * (USEC_PER_SEC / HZ);
   2.145  		HANDLE_USEC_UNDERFLOW(shadow_tv);
   2.146  
   2.147  		/*
   2.148 @@ -394,9 +406,9 @@ static inline void do_timer_interrupt(in
   2.149  		 */
   2.150  		sec_diff = xtime.tv_sec - shadow_tv.tv_sec;
   2.151  		if (unlikely(abs(sec_diff) > 1) ||
   2.152 -		    unlikely(((sec_diff * 1000000) + 
   2.153 -		              (xtime.tv_nsec/1000) - shadow_tv.tv_usec) >
   2.154 -		             500000)) {
   2.155 +		    unlikely(((sec_diff * USEC_PER_SEC) +
   2.156 +			      (xtime.tv_nsec / NSEC_PER_USEC) -
   2.157 +			      shadow_tv.tv_usec) > 500000)) {
   2.158  #ifdef CONFIG_XEN_PRIVILEGED_GUEST
   2.159  			last_rtc_update = last_update_to_xen = 0;
   2.160  #endif
   2.161 @@ -405,7 +417,7 @@ static inline void do_timer_interrupt(in
   2.162  
   2.163  		/* Update our unsynchronised xtime appropriately. */
   2.164  		xtime.tv_sec  = shadow_tv.tv_sec;
   2.165 -		xtime.tv_nsec = shadow_tv.tv_usec * 1000;
   2.166 +		xtime.tv_nsec = shadow_tv.tv_usec * NSEC_PER_USEC;
   2.167  
   2.168  		last_update_from_xen = xtime.tv_sec;
   2.169  	}
   2.170 @@ -421,8 +433,8 @@ static inline void do_timer_interrupt(in
   2.171  		struct timeval tv;
   2.172  
   2.173  		tv.tv_sec   = xtime.tv_sec;
   2.174 -		tv.tv_usec  = xtime.tv_nsec / 1000;
   2.175 -		tv.tv_usec += (jiffies - wall_jiffies) * (1000000/HZ);
   2.176 +		tv.tv_usec  = xtime.tv_nsec / NSEC_PER_USEC;
   2.177 +		tv.tv_usec += (jiffies - wall_jiffies) * (USEC_PER_SEC/HZ);
   2.178  		HANDLE_USEC_OVERFLOW(tv);
   2.179  
   2.180  		op.cmd = DOM0_SETTIME;
   2.181 @@ -640,17 +652,17 @@ int set_timeout_timer(void)
   2.182   * now however.
   2.183   */
   2.184  static ctl_table xen_subtable[] = {
   2.185 -    {1, "independent_wallclock", &independent_wallclock,
   2.186 -     sizeof(independent_wallclock), 0644, NULL, proc_dointvec},
   2.187 -    {0}
   2.188 +	{1, "independent_wallclock", &independent_wallclock,
   2.189 +	 sizeof(independent_wallclock), 0644, NULL, proc_dointvec},
   2.190 +	{0}
   2.191  };
   2.192  static ctl_table xen_table[] = {
   2.193 -    {123, "xen", NULL, 0, 0555, xen_subtable},
   2.194 -    {0}
   2.195 +	{123, "xen", NULL, 0, 0555, xen_subtable},
   2.196 +	{0}
   2.197  };
   2.198  static int __init xen_sysctl_init(void)
   2.199  {
   2.200 -    (void)register_sysctl_table(xen_table, 0);
   2.201 -    return 0;
   2.202 +	(void)register_sysctl_table(xen_table, 0);
   2.203 +	return 0;
   2.204  }
   2.205  __initcall(xen_sysctl_init);