ia64/xen-unstable

changeset 16820:aca8d453da59

minios: make time interface POSIX
timespec uses tv_sec and tv_nsec too. gettimeofday takes a tz
argument.

Signed-off-by: Samuel Thibault <samuel.thibault@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Mon Jan 21 11:20:27 2008 +0000 (2008-01-21)
parents 3f26758bcc02
children 3c49ae5641b0
files extras/mini-os/arch/ia64/time.c extras/mini-os/arch/x86/time.c extras/mini-os/include/sys/time.h extras/mini-os/include/time.h extras/mini-os/kernel.c extras/mini-os/sched.c
line diff
     1.1 --- a/extras/mini-os/arch/ia64/time.c	Fri Jan 18 22:27:51 2008 +0000
     1.2 +++ b/extras/mini-os/arch/ia64/time.c	Mon Jan 21 11:20:27 2008 +0000
     1.3 @@ -147,10 +147,10 @@ calculate_time(void)
     1.4  		new = itc_new - itc_alt;
     1.5  	itc_alt = itc_new;
     1.6  	new = ns_from_cycles(new);
     1.7 -	os_time.ts_nsec += new;
     1.8 -	if (os_time.ts_nsec > 1000000000) {	/* On overflow. */
     1.9 -		os_time.ts_sec++;
    1.10 -		os_time.ts_nsec -= 1000000000;
    1.11 +	os_time.tv_nsec += new;
    1.12 +	if (os_time.tv_nsec > 1000000000) {	/* On overflow. */
    1.13 +		os_time.tv_sec++;
    1.14 +		os_time.tv_nsec -= 1000000000;
    1.15  	}
    1.16  }
    1.17  
    1.18 @@ -177,12 +177,13 @@ monotonic_clock(void)
    1.19  	return delta;
    1.20  }
    1.21  
    1.22 -void
    1.23 -gettimeofday(struct timeval *tv)
    1.24 +int
    1.25 +gettimeofday(struct timeval *tv, void *tz)
    1.26  {
    1.27  	calculate_time();
    1.28 -	tv->tv_sec = os_time.ts_sec;			/* seconds */
    1.29 -	tv->tv_usec = NSEC_TO_USEC(os_time.ts_nsec);	/* microseconds */
    1.30 +	tv->tv_sec = os_time.tv_sec;			/* seconds */
    1.31 +	tv->tv_usec = NSEC_TO_USEC(os_time.tv_nsec);	/* microseconds */
    1.32 +        return 0;
    1.33  };
    1.34  
    1.35  /*
    1.36 @@ -253,16 +254,16 @@ init_time(void)
    1.37  	itm_val = (itc_frequency + HZ/2) / HZ;
    1.38  	printk("  itm_val: %ld\n", itm_val);
    1.39  
    1.40 -	os_time.ts_sec = 0;
    1.41 -	os_time.ts_nsec = 0;
    1.42 +	os_time.tv_sec = 0;
    1.43 +	os_time.tv_nsec = 0;
    1.44  
    1.45  	if (efi_get_time(&tm)) {
    1.46  		printk("  EFI-Time: %d.%d.%d   %d:%d:%d\n", tm.Day,
    1.47  		       tm.Month, tm.Year, tm.Hour, tm.Minute, tm.Second);
    1.48 -		os_time.ts_sec = mktime(SWAP(tm.Year), SWAP(tm.Month),
    1.49 +		os_time.tv_sec = mktime(SWAP(tm.Year), SWAP(tm.Month),
    1.50  					SWAP(tm.Day), SWAP(tm.Hour),
    1.51  					SWAP(tm.Minute), SWAP(tm.Second));
    1.52 -		os_time.ts_nsec = tm.Nanosecond;
    1.53 +		os_time.tv_nsec = tm.Nanosecond;
    1.54  	} else
    1.55  		printk("efi_get_time() failed\n");
    1.56  
     2.1 --- a/extras/mini-os/arch/x86/time.c	Fri Jan 18 22:27:51 2008 +0000
     2.2 +++ b/extras/mini-os/arch/x86/time.c	Mon Jan 21 11:20:27 2008 +0000
     2.3 @@ -175,30 +175,32 @@ static void update_wallclock(void)
     2.4  	do {
     2.5  		shadow_ts_version = s->wc_version;
     2.6  		rmb();
     2.7 -		shadow_ts.ts_sec  = s->wc_sec;
     2.8 -		shadow_ts.ts_nsec = s->wc_nsec;
     2.9 +		shadow_ts.tv_sec  = s->wc_sec;
    2.10 +		shadow_ts.tv_nsec = s->wc_nsec;
    2.11  		rmb();
    2.12  	}
    2.13  	while ((s->wc_version & 1) | (shadow_ts_version ^ s->wc_version));
    2.14  }
    2.15  
    2.16  
    2.17 -void gettimeofday(struct timeval *tv)
    2.18 +int gettimeofday(struct timeval *tv, void *tz)
    2.19  {
    2.20      u64 nsec = monotonic_clock();
    2.21 -    nsec += shadow_ts.ts_nsec;
    2.22 +    nsec += shadow_ts.tv_nsec;
    2.23      
    2.24      
    2.25 -    tv->tv_sec = shadow_ts.ts_sec;
    2.26 +    tv->tv_sec = shadow_ts.tv_sec;
    2.27      tv->tv_sec += NSEC_TO_SEC(nsec);
    2.28      tv->tv_usec = NSEC_TO_USEC(nsec % 1000000000UL);
    2.29 +
    2.30 +    return 0;
    2.31  }
    2.32  
    2.33  
    2.34  void block_domain(s_time_t until)
    2.35  {
    2.36      struct timeval tv;
    2.37 -    gettimeofday(&tv);
    2.38 +    gettimeofday(&tv, NULL);
    2.39      if(monotonic_clock() < until)
    2.40      {
    2.41          HYPERVISOR_set_timer_op(until);
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/extras/mini-os/include/sys/time.h	Mon Jan 21 11:20:27 2008 +0000
     3.3 @@ -0,0 +1,38 @@
     3.4 +/* -*-  Mode:C; c-basic-offset:4; tab-width:4 -*-
     3.5 + ****************************************************************************
     3.6 + * (C) 2003 - Rolf Neugebauer - Intel Research Cambridge
     3.7 + * (C) 2005 - Grzegorz Milos - Intel Research Cambridge
     3.8 + ****************************************************************************
     3.9 + *
    3.10 + *        File: time.h
    3.11 + *      Author: Rolf Neugebauer (neugebar@dcs.gla.ac.uk)
    3.12 + *     Changes: Grzegorz Milos (gm281@cam.ac.uk)
    3.13 + *              Robert Kaiser (kaiser@informatik.fh-wiesbaden.de)
    3.14 + *              
    3.15 + *        Date: Jul 2003, changes: Jun 2005, Sep 2006
    3.16 + * 
    3.17 + * Environment: Xen Minimal OS
    3.18 + * Description: Time and timer functions
    3.19 + *
    3.20 + ****************************************************************************
    3.21 + */
    3.22 +
    3.23 +#ifndef _MINIOS_SYS_TIME_H_
    3.24 +#define _MINIOS_SYS_TIME_H_
    3.25 +
    3.26 +struct timespec {
    3.27 +    time_t      tv_sec;
    3.28 +    long        tv_nsec;
    3.29 +};
    3.30 +
    3.31 +struct timezone {
    3.32 +};
    3.33 +
    3.34 +struct timeval {
    3.35 +	time_t		tv_sec;		/* seconds */
    3.36 +	suseconds_t	tv_usec;	/* microseconds */
    3.37 +};
    3.38 +
    3.39 +int      gettimeofday(struct timeval *tv, void *tz);
    3.40 +
    3.41 +#endif /* _MINIOS_SYS_TIME_H_ */
     4.1 --- a/extras/mini-os/include/time.h	Fri Jan 18 22:27:51 2008 +0000
     4.2 +++ b/extras/mini-os/include/time.h	Mon Jan 21 11:20:27 2008 +0000
     4.3 @@ -38,20 +38,13 @@ typedef s64 s_time_t;
     4.4  #define Time_Max                ((s_time_t) 0x7fffffffffffffffLL)
     4.5  #define FOREVER                 Time_Max
     4.6  #define NSEC_TO_USEC(_nsec)     ((_nsec) / 1000UL)
     4.7 +#define NSEC_TO_MSEC(_nsec)     ((_nsec) / 1000000ULL)
     4.8  #define NSEC_TO_SEC(_nsec)      ((_nsec) / 1000000000ULL)
     4.9  
    4.10  /* wall clock time  */
    4.11  typedef long time_t;
    4.12  typedef long suseconds_t;
    4.13 -struct timeval {
    4.14 -	time_t		tv_sec;		/* seconds */
    4.15 -	suseconds_t	tv_usec;	/* microseconds */
    4.16 -};
    4.17 -
    4.18 -struct timespec {
    4.19 -    time_t      ts_sec;
    4.20 -    long        ts_nsec;
    4.21 -};
    4.22 +#include <sys/time.h>
    4.23  
    4.24  
    4.25  /* prototypes */
    4.26 @@ -59,7 +52,6 @@ void     init_time(void);
    4.27  s_time_t get_s_time(void);
    4.28  s_time_t get_v_time(void);
    4.29  u64      monotonic_clock(void);
    4.30 -void     gettimeofday(struct timeval *tv);
    4.31  void     block_domain(s_time_t until);
    4.32  
    4.33  #endif /* _TIME_H_ */
     5.1 --- a/extras/mini-os/kernel.c	Fri Jan 18 22:27:51 2008 +0000
     5.2 +++ b/extras/mini-os/kernel.c	Mon Jan 21 11:20:27 2008 +0000
     5.3 @@ -75,7 +75,7 @@ static void periodic_thread(void *p)
     5.4      printk("Periodic thread started.\n");
     5.5      for(;;)
     5.6      {
     5.7 -        gettimeofday(&tv);
     5.8 +        gettimeofday(&tv, NULL);
     5.9          printk("T(s=%ld us=%ld)\n", tv.tv_sec, tv.tv_usec);
    5.10          sleep(1000);
    5.11      }
     6.1 --- a/extras/mini-os/sched.c	Fri Jan 18 22:27:51 2008 +0000
     6.2 +++ b/extras/mini-os/sched.c	Mon Jan 21 11:20:27 2008 +0000
     6.3 @@ -270,10 +270,10 @@ void th_f1(void *data)
     6.4          up(&mutex);
     6.5          
     6.6          
     6.7 -        gettimeofday(&tv1);
     6.8 +        gettimeofday(&tv1, NULL);
     6.9          for(;;)
    6.10          {
    6.11 -            gettimeofday(&tv2);
    6.12 +            gettimeofday(&tv2, NULL);
    6.13              if(tv2.tv_sec - tv1.tv_sec > 2) break;
    6.14          }
    6.15