qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@web.de>
To: Ed Swierk <eswierk@aristanetworks.com>
Cc: qemu-devel@nongnu.org
Subject: [Qemu-devel] Re: [PATCH] slirp: Use monotonic clock if available (v2)
Date: Sat, 25 Jul 2009 12:30:25 +0200	[thread overview]
Message-ID: <4A6ADEC1.4090200@web.de> (raw)
In-Reply-To: <1248383614.14831.40.camel@localhost.localdomain>

[-- Attachment #1: Type: text/plain, Size: 2637 bytes --]

Ed Swierk wrote:
> Calling gettimeofday() to compute a time interval can cause problems if
> the system clock jumps forwards or backwards; replace updtime() with
> qemu_get_clock(rt_clock), which calls clock_gettime(CLOCK_MONOTONIC) if
> it is available.
> 
> Also remove some useless macros.
> 
> Signed-off-by: Ed Swierk <eswierk@aristanetworks.com>
> 

Nice fix & cleanup.

Acked-by: Jan Kiszka <jan.kiszka@siemens.com>

> ---
> diff --git a/slirp/slirp.c b/slirp/slirp.c
> index c68c6ab..3798780 100644
> --- a/slirp/slirp.c
> +++ b/slirp/slirp.c
> @@ -22,6 +22,7 @@
>   * THE SOFTWARE.
>   */
>  #include "qemu-common.h"
> +#include "qemu-timer.h"
>  #include "qemu-char.h"
>  #include "slirp.h"
>  #include "hw/hw.h"
> @@ -238,29 +239,6 @@ void slirp_cleanup(Slirp *slirp)
>  #define CONN_CANFRCV(so) (((so)->so_state & (SS_FCANTRCVMORE|SS_ISFCONNECTED)) == SS_ISFCONNECTED)
>  #define UPD_NFDS(x) if (nfds < (x)) nfds = (x)
>  
> -/*
> - * curtime kept to an accuracy of 1ms
> - */
> -#ifdef _WIN32
> -static void updtime(void)
> -{
> -    struct _timeb tb;
> -
> -    _ftime(&tb);
> -
> -    curtime = tb.time * 1000 + tb.millitm;
> -}
> -#else
> -static void updtime(void)
> -{
> -    struct timeval tv;
> -
> -    gettimeofday(&tv, NULL);
> -
> -    curtime = tv.tv_sec * 1000 + tv.tv_usec / 1000;
> -}
> -#endif
> -
>  void slirp_select_fill(int *pnfds,
>                         fd_set *readfds, fd_set *writefds, fd_set *xfds)
>  {
> @@ -399,8 +377,7 @@ void slirp_select_poll(fd_set *readfds, fd_set *writefds, fd_set *xfds,
>      global_writefds = writefds;
>      global_xfds = xfds;
>  
> -	/* Update time */
> -	updtime();
> +    curtime = qemu_get_clock(rt_clock);
>  
>      TAILQ_FOREACH(slirp, &slirp_instances, entry) {
>  	/*
> diff --git a/slirp/slirp.h b/slirp/slirp.h
> index 22058cd..020412c 100644
> --- a/slirp/slirp.h
> +++ b/slirp/slirp.h
> @@ -108,10 +108,6 @@ typedef unsigned char u_int8_t;
>  #include <arpa/inet.h>
>  #endif
>  
> -#ifdef GETTIMEOFDAY_ONE_ARG
> -#define gettimeofday(x, y) gettimeofday(x)
> -#endif
> -
>  /* Systems lacking strdup() definition in <string.h>. */
>  #if defined(ultrix)
>  char *strdup(const char *);
> diff --git a/slirp/slirp_config.h b/slirp/slirp_config.h
> index ebaa99c..e977e77 100644
> --- a/slirp/slirp_config.h
> +++ b/slirp/slirp_config.h
> @@ -187,9 +187,6 @@
>  #define NO_UNIX_SOCKETS
>  #endif
>  
> -/* Define if gettimeofday only takes one argument */
> -#undef GETTIMEOFDAY_ONE_ARG
> -
>  /* Define if you have revoke() */
>  #undef HAVE_REVOKE
>  


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 257 bytes --]

      reply	other threads:[~2009-07-25 10:30 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-23 21:13 [Qemu-devel] [PATCH] slirp: Use monotonic clock if available (v2) Ed Swierk
2009-07-25 10:30 ` Jan Kiszka [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4A6ADEC1.4090200@web.de \
    --to=jan.kiszka@web.de \
    --cc=eswierk@aristanetworks.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).