[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [PATCH 3/7] add gettimeofday function to time managment



On Wed, Apr 04, 2018 at 03:50:50PM +0000, Pawel Wieczorkiewicz wrote:
> From: Paul Semel <phentex@xxxxxxxxx>
> 
> Signed-off-by: Paul Semel <phentex@xxxxxxxxx>
> 
> cr https://code.amazon.com/reviews/CR-786225
> ---
>  common/time.c      | 14 ++++++++++++++
>  include/xtf/time.h | 12 ++++++++++++
>  2 files changed, 26 insertions(+)
> 
> diff --git a/common/time.c b/common/time.c
> index 37a9faf..c80bc11 100644
> --- a/common/time.c
> +++ b/common/time.c
> @@ -92,6 +92,20 @@ uint64_t current_time(void)
>      return seconds + (since_boot_time() / 1000000000);
>  }
>  
> +/* The POSIX gettimeofday syscall normally takes a second argument, which is
> + * the timezone (struct timezone). However, it sould be NULL because linux
> + * doesn't use it anymore. So we need for us to add it in this function

IMO it's better to use the POSIX prototype.

I would instead panic if tz != NULL, or return EOPNOTSUPP.

> + */
> +int gettimeofday(struct timeval *tp)
> +{
> +    if (!tp)
> +        return -1;
> +
> +    tp->sec = current_time();
> +    tp->nsec = shared_info.wc_nsec + (since_boot_time() % 1000000000);

Please add a define for 1000000000.

Also, I'm not sure this is accurate.

current_time already calls since_boot_time, so you end up using data
from two different since_boot_time calls in order to fill the timeval
struct, which is wrong (ie: those calls will return different values
which you are mixing).

> +    return 0;
> +}
> +
>  /*
>   * Local variables:
>   * mode: C
> diff --git a/include/xtf/time.h b/include/xtf/time.h
> index a8c10eb..16356eb 100644
> --- a/include/xtf/time.h
> +++ b/include/xtf/time.h
> @@ -8,6 +8,16 @@
>  
>  #include <xtf/types.h>
>  
> +struct timeval {
> +#if !defined(__i386__)
> +    uint64_t sec;
> +    uint64_t nsec;
> +#else
> +    uint32_t sec;
> +    uint32_t nsec;
> +#endif
> +};

Let's have a sane interface from the start and always use 64bit
fields.

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.