[Spice-devel] [PATCH 10/11] Replace now() with get_mononotonic_time()

Frediano Ziglio fziglio at redhat.com
Thu Oct 29 11:22:03 PDT 2015


> 
> From: Marc-André Lureau <marcandre.lureau at gmail.com>
> 
> ---
>  server/Makefile.am       |  1 -
>  server/display-channel.h |  5 +----
>  server/red_channel.c     | 16 ++++++++--------
>  server/red_time.h        | 32 --------------------------------
>  server/red_worker.c      | 22 +++++++++++-----------
>  server/utils.h           |  2 ++
>  6 files changed, 22 insertions(+), 56 deletions(-)
>  delete mode 100644 server/red_time.h
> 
> diff --git a/server/Makefile.am b/server/Makefile.am
> index 28757ab..d2a7343 100644
> --- a/server/Makefile.am
> +++ b/server/Makefile.am
> @@ -103,7 +103,6 @@ libspice_server_la_SOURCES =			\
>  	red_replay_qxl.c			\
>  	red_replay_qxl.h			\
>  	red_parse_qxl.h				\
> -	red_time.h				\
>  	red_worker.c				\
>  	red_worker.h				\
>  	display-channel.c			\
> diff --git a/server/display-channel.h b/server/display-channel.h
> index 1b38932..fc4fbaa 100644
> --- a/server/display-channel.h
> +++ b/server/display-channel.h
> @@ -50,12 +50,9 @@
>  #include "migration_protocol.h"
>  #include "main_dispatcher.h"
>  #include "spice_server_utils.h"
> -#include "red_time.h"
>  #include "spice_bitmap_utils.h"
>  #include "spice_image_cache.h"
> -
> -
> -typedef int64_t red_time_t;
> +#include "utils.h"
>  
>  typedef struct DisplayChannel DisplayChannel;
>  
> diff --git a/server/red_channel.c b/server/red_channel.c
> index 6e9bf29..7330ae2 100644
> --- a/server/red_channel.c
> +++ b/server/red_channel.c
> @@ -43,7 +43,7 @@
>  #include "reds.h"
>  #include "reds_stream.h"
>  #include "main_dispatcher.h"
> -#include "red_time.h"
> +#include "utils.h"
>  
>  typedef struct EmptyMsgPipeItem {
>      PipeItem base;
> @@ -2344,7 +2344,7 @@ int
> red_channel_client_wait_outgoing_item(RedChannelClient *rcc,
>          return TRUE;
>      }
>      if (timeout != -1) {
> -        end_time = red_now() + timeout;
> +        end_time = red_get_monotonic_time() + timeout;
>      } else {
>          end_time = UINT64_MAX;
>      }
> @@ -2355,7 +2355,7 @@ int
> red_channel_client_wait_outgoing_item(RedChannelClient *rcc,
>          red_channel_client_receive(rcc);
>          red_channel_client_send(rcc);
>      } while ((blocked = red_channel_client_blocked(rcc)) &&
> -             (timeout == -1 || red_now() < end_time));
> +             (timeout == -1 || red_get_monotonic_time() < end_time));
>  
>      if (blocked) {
>          spice_warning("timeout");
> @@ -2377,7 +2377,7 @@ int
> red_channel_client_wait_pipe_item_sent(RedChannelClient *rcc,
>      spice_info(NULL);
>  
>      if (timeout != -1) {
> -        end_time = red_now() + timeout;
> +        end_time = red_get_monotonic_time() + timeout;
>      } else {
>          end_time = UINT64_MAX;
>      }
> @@ -2391,7 +2391,7 @@ int
> red_channel_client_wait_pipe_item_sent(RedChannelClient *rcc,
>      red_channel_client_push(rcc);
>  
>      while((item_in_pipe = ring_item_is_linked(&item->link)) &&
> -          (timeout == -1 || red_now() < end_time)) {
> +          (timeout == -1 || red_get_monotonic_time() < end_time)) {
>          usleep(CHANNEL_BLOCKED_SLEEP_DURATION);
>          red_channel_client_receive(rcc);
>          red_channel_client_send(rcc);
> @@ -2404,7 +2404,7 @@ int
> red_channel_client_wait_pipe_item_sent(RedChannelClient *rcc,
>          return FALSE;
>      } else {
>          return red_channel_client_wait_outgoing_item(rcc,
> -                                                     timeout == -1 ? -1 :
> end_time - red_now());
> +                                                     timeout == -1 ? -1 :
> end_time - red_get_monotonic_time());
>      }
>  }
>  
> @@ -2416,7 +2416,7 @@ int red_channel_wait_all_sent(RedChannel *channel,
>      int blocked = FALSE;
>  
>      if (timeout != -1) {
> -        end_time = red_now() + timeout;
> +        end_time = red_get_monotonic_time() + timeout;
>      } else {
>          end_time = UINT64_MAX;
>      }
> @@ -2424,7 +2424,7 @@ int red_channel_wait_all_sent(RedChannel *channel,
>      red_channel_push(channel);
>      while (((max_pipe_size = red_channel_max_pipe_size(channel)) ||
>             (blocked = red_channel_any_blocked(channel))) &&
> -           (timeout == -1 || red_now() < end_time)) {
> +           (timeout == -1 || red_get_monotonic_time() < end_time)) {
>          spice_debug("pipe-size %u blocked %d", max_pipe_size, blocked);
>          usleep(CHANNEL_BLOCKED_SLEEP_DURATION);
>          red_channel_receive(channel);
> diff --git a/server/red_time.h b/server/red_time.h
> deleted file mode 100644
> index 94c1ba6..0000000
> --- a/server/red_time.h
> +++ /dev/null
> @@ -1,32 +0,0 @@
> -/* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
> -/*
> -   Copyright (C) 2009-2015 Red Hat, Inc.
> -
> -   This library is free software; you can redistribute it and/or
> -   modify it under the terms of the GNU Lesser General Public
> -   License as published by the Free Software Foundation; either
> -   version 2.1 of the License, or (at your option) any later version.
> -
> -   This library is distributed in the hope that it will be useful,
> -   but WITHOUT ANY WARRANTY; without even the implied warranty of
> -   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> -   Lesser General Public License for more details.
> -
> -   You should have received a copy of the GNU Lesser General Public
> -   License along with this library; if not, see
> <http://www.gnu.org/licenses/>.
> -*/
> -#ifndef H_RED_TIME
> -#define H_RED_TIME
> -
> -#include <time.h>
> -
> -static inline uint64_t red_now(void)
> -{
> -    struct timespec time;
> -
> -    clock_gettime(CLOCK_MONOTONIC, &time);
> -
> -    return ((uint64_t) time.tv_sec) * 1000000000 + time.tv_nsec;
> -}
> -
> -#endif
> diff --git a/server/red_worker.c b/server/red_worker.c
> index 9ccda1d..0542b29 100644
> --- a/server/red_worker.c
> +++ b/server/red_worker.c
> @@ -3998,7 +3998,7 @@ static int red_process_commands(RedWorker *worker,
> uint32_t max_pipe_size, int *
>  {
>      QXLCommandExt ext_cmd;
>      int n = 0;
> -    uint64_t start = red_now();
> +    uint64_t start = red_get_monotonic_time();
>  
>      if (!worker->running) {
>          *ring_is_empty = TRUE;
> @@ -4098,7 +4098,7 @@ static int red_process_commands(RedWorker *worker,
> uint32_t max_pipe_size, int *
>          n++;
>          if ((worker->display_channel &&
>               red_channel_all_blocked(&worker->display_channel->common.base))
> -            || red_now() - start > 10 * 1000 * 1000) {
> +            || red_get_monotonic_time() - start > 10 * 1000 * 1000) {
>              worker->event_timeout = 0;
>              return n;
>          }
> @@ -7596,7 +7596,7 @@ static inline int
> red_marshall_stream_data(RedChannelClient *rcc,
>      }
>  
>      StreamAgent *agent = &dcc->stream_agents[get_stream_id(worker, stream)];
> -    uint64_t time_now = red_now();
> +    uint64_t time_now = red_get_monotonic_time();
>      size_t outbuf_size;
>  
>      if (!dcc->use_mjpeg_encoder_rate_control) {
> @@ -8568,7 +8568,7 @@ static inline void flush_display_commands(RedWorker
> *worker)
>          if (ring_is_empty) {
>              break;
>          }
> -        end_time = red_now() + DISPLAY_CLIENT_TIMEOUT;
> +        end_time = red_get_monotonic_time() + DISPLAY_CLIENT_TIMEOUT;
>          int sleep_count = 0;
>          for (;;) {
>              red_channel_push(RED_CHANNEL(worker->display_channel));
> @@ -8581,7 +8581,7 @@ static inline void flush_display_commands(RedWorker
> *worker)
>              red_channel_send(channel);
>              // TODO: MC: the whole timeout will break since it takes lowest
>              timeout, should
>              // do it client by client.
> -            if (red_now() >= end_time) {
> +            if (red_get_monotonic_time() >= end_time) {
>                  spice_warning("update timeout");
>                  red_disconnect_all_display_TODO_remove_me(channel);
>              } else {
> @@ -8612,7 +8612,7 @@ static inline void flush_cursor_commands(RedWorker
> *worker)
>          if (ring_is_empty) {
>              break;
>          }
> -        end_time = red_now() + DISPLAY_CLIENT_TIMEOUT;
> +        end_time = red_get_monotonic_time() + DISPLAY_CLIENT_TIMEOUT;
>          int sleep_count = 0;
>          for (;;) {
>              red_channel_push(RED_CHANNEL(worker->cursor_channel));
> @@ -8623,7 +8623,7 @@ static inline void flush_cursor_commands(RedWorker
> *worker)
>              RedChannel *channel = (RedChannel *)worker->cursor_channel;
>              red_channel_receive(channel);
>              red_channel_send(channel);
> -            if (red_now() >= end_time) {
> +            if (red_get_monotonic_time() >= end_time) {
>                  spice_warning("flush cursor timeout");
>                  cursor_channel_disconnect(worker->cursor_channel);
>                  worker->cursor_channel = NULL;
> @@ -8657,7 +8657,7 @@ static void
> push_new_primary_surface(DisplayChannelClient *dcc)
>  static int display_channel_client_wait_for_init(DisplayChannelClient *dcc)
>  {
>      dcc->expect_init = TRUE;
> -    uint64_t end_time = red_now() + DISPLAY_CLIENT_TIMEOUT;
> +    uint64_t end_time = red_get_monotonic_time() + DISPLAY_CLIENT_TIMEOUT;
>      for (;;) {
>          red_channel_client_receive(&dcc->common.base);
>          if (!red_channel_client_is_connected(&dcc->common.base)) {
> @@ -8673,7 +8673,7 @@ static int
> display_channel_client_wait_for_init(DisplayChannelClient *dcc)
>              }
>              return TRUE;
>          }
> -        if (red_now() > end_time) {
> +        if (red_get_monotonic_time() > end_time) {
>              spice_warning("timeout");
>              red_channel_client_disconnect(&dcc->common.base);
>              break;
> @@ -10086,7 +10086,7 @@ void handle_dev_stop(void *opaque, void *payload)
>  
>  static int display_channel_wait_for_migrate_data(DisplayChannel *display)
>  {
> -    uint64_t end_time = red_now() + DISPLAY_CLIENT_MIGRATE_DATA_TIMEOUT;
> +    uint64_t end_time = red_get_monotonic_time() +
> DISPLAY_CLIENT_MIGRATE_DATA_TIMEOUT;
>      RedChannel *channel = &display->common.base;
>      RedChannelClient *rcc;
>  
> @@ -10105,7 +10105,7 @@ static int
> display_channel_wait_for_migrate_data(DisplayChannel *display)
>          if (!red_channel_client_waits_for_migrate_data(rcc)) {
>              return TRUE;
>          }
> -        if (red_now() > end_time) {
> +        if (red_get_monotonic_time() > end_time) {
>              spice_warning("timeout");
>              red_channel_client_disconnect(rcc);
>              break;
> diff --git a/server/utils.h b/server/utils.h
> index ca8b7f1..1ebc32f 100644
> --- a/server/utils.h
> +++ b/server/utils.h
> @@ -20,6 +20,8 @@
>  
>  #include <time.h>
>  
> +typedef int64_t red_time_t;
> +
>  /* FIXME: consider g_get_monotonic_time (), but in microseconds */
>  static inline red_time_t red_get_monotonic_time(void)
>  {

Acked

Frediano


More information about the Spice-devel mailing list