[Spice-devel,1/7] server: Rename red_get_monotonic_time() to spice_get_monotonic_time_ns()

Submitted by Francois Gouget on Dec. 11, 2015, 11:21 a.m.

Details

Message ID 38662a40f22a6df8aae15fbf314d9f81f73860ad.1449832051.git.fgouget@free.fr
State New
Headers show
Series "Series without cover letter" ( rev: 1 ) in Spice

Not browsing as part of any series.

Commit Message

Francois Gouget Dec. 11, 2015, 11:21 a.m.
This is a generic function not tied to the red_xxx functionality and the
new name clarifies that it returns the time in nanoseconds (unlike
g_get_monotonic_time()).

Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
---
 server/dcc-send.c        |  2 +-
 server/dcc.c             |  4 ++--
 server/display-channel.c |  8 ++++----
 server/main-channel.c    |  2 +-
 server/mjpeg-encoder.c   |  6 +++---
 server/red-channel.c     | 20 ++++++++++----------
 server/red-worker.c      | 12 ++++++------
 server/stream.c          |  2 +-
 server/utils.h           |  2 +-
 9 files changed, 29 insertions(+), 29 deletions(-)

Of course this will conflict with the 'framerate estimate' patch but it 
has not been committed yet anyway. So I'm resubmitting it at the end of 
this patch series since it seems to systematically getting stuck in 
limbo.

Patch hide | download patch | download mbox

diff --git a/server/dcc-send.c b/server/dcc-send.c
index 30303e7..a8f42db 100644
--- a/server/dcc-send.c
+++ b/server/dcc-send.c
@@ -1689,7 +1689,7 @@  static int red_marshall_stream_data(RedChannelClient *rcc,
     }
 
     StreamAgent *agent = &dcc->stream_agents[get_stream_id(display, stream)];
-    uint64_t time_now = red_get_monotonic_time();
+    uint64_t time_now = spice_get_monotonic_time_ns();
     size_t outbuf_size;
 
     if (!dcc->use_mjpeg_encoder_rate_control) {
diff --git a/server/dcc.c b/server/dcc.c
index a893ea4..f47cbec 100644
--- a/server/dcc.c
+++ b/server/dcc.c
@@ -415,7 +415,7 @@  static void dcc_create_all_streams(DisplayChannelClient *dcc)
 static int display_channel_client_wait_for_init(DisplayChannelClient *dcc)
 {
     dcc->expect_init = TRUE;
-    uint64_t end_time = red_get_monotonic_time() + DISPLAY_CLIENT_TIMEOUT;
+    uint64_t end_time = spice_get_monotonic_time_ns() + DISPLAY_CLIENT_TIMEOUT;
     for (;;) {
         red_channel_client_receive(RED_CHANNEL_CLIENT(dcc));
         if (!red_channel_client_is_connected(RED_CHANNEL_CLIENT(dcc))) {
@@ -431,7 +431,7 @@  static int display_channel_client_wait_for_init(DisplayChannelClient *dcc)
             }
             return TRUE;
         }
-        if (red_get_monotonic_time() > end_time) {
+        if (spice_get_monotonic_time_ns() > end_time) {
             spice_warning("timeout");
             red_channel_client_disconnect(RED_CHANNEL_CLIENT(dcc));
             break;
diff --git a/server/display-channel.c b/server/display-channel.c
index 7cbcea5..442b8fa 100644
--- a/server/display-channel.c
+++ b/server/display-channel.c
@@ -181,7 +181,7 @@  int display_channel_get_streams_timeout(DisplayChannel *display)
     Ring *ring = &display->streams;
     RingItem *item = ring;
 
-    red_time_t now = red_get_monotonic_time();
+    red_time_t now = spice_get_monotonic_time_ns();
     while ((item = ring_next(ring, item))) {
         Stream *stream;
 
@@ -1187,7 +1187,7 @@  void display_channel_process_draw(DisplayChannel *display, RedDrawable *red_draw
 
 int display_channel_wait_for_migrate_data(DisplayChannel *display)
 {
-    uint64_t end_time = red_get_monotonic_time() + DISPLAY_CLIENT_MIGRATE_DATA_TIMEOUT;
+    uint64_t end_time = spice_get_monotonic_time_ns() + DISPLAY_CLIENT_MIGRATE_DATA_TIMEOUT;
     RedChannel *channel = &display->common.base;
     RedChannelClient *rcc;
     int ret = FALSE;
@@ -1212,7 +1212,7 @@  int display_channel_wait_for_migrate_data(DisplayChannel *display)
             ret = TRUE;
             break;
         }
-        if (red_get_monotonic_time() > end_time) {
+        if (spice_get_monotonic_time_ns() > end_time) {
             spice_warning("timeout");
             red_channel_client_disconnect(rcc);
             break;
@@ -1371,7 +1371,7 @@  Drawable *display_channel_drawable_try_new(DisplayChannel *display,
 
     bzero(drawable, sizeof(Drawable));
     drawable->refs = 1;
-    drawable->creation_time = red_get_monotonic_time();
+    drawable->creation_time = spice_get_monotonic_time_ns();
     ring_item_init(&drawable->list_link);
     ring_item_init(&drawable->surface_list_link);
     ring_item_init(&drawable->tree_item.base.siblings_link);
diff --git a/server/main-channel.c b/server/main-channel.c
index e74ba76..6cd2e59 100644
--- a/server/main-channel.c
+++ b/server/main-channel.c
@@ -588,7 +588,7 @@  static void main_channel_marshall_notify(RedChannelClient *rcc,
     SpiceMsgNotify notify;
 
     red_channel_client_init_send_data(rcc, SPICE_MSG_NOTIFY, &item->base);
-    notify.time_stamp = red_get_monotonic_time(); // TODO - move to main_new_notify_item
+    notify.time_stamp = spice_get_monotonic_time_ns(); // TODO - move to main_new_notify_item
     notify.severity = SPICE_NOTIFY_SEVERITY_WARN;
     notify.visibilty = SPICE_NOTIFY_VISIBILITY_HIGH;
     notify.what = SPICE_WARN_GENERAL;
diff --git a/server/mjpeg-encoder.c b/server/mjpeg-encoder.c
index 08af1eb..9c51f7b 100644
--- a/server/mjpeg-encoder.c
+++ b/server/mjpeg-encoder.c
@@ -716,7 +716,7 @@  static int mjpeg_encoder_start_frame(MJpegEncoder *encoder,
         uint64_t now;
         uint64_t interval;
 
-        now = red_get_monotonic_time();
+        now = spice_get_monotonic_time_ns();
 
         if (!rate_control->adjusted_fps_start_time) {
             rate_control->adjusted_fps_start_time = now;
@@ -995,7 +995,7 @@  static void mjpeg_encoder_decrease_bit_rate(MJpegEncoder *encoder)
     if (rate_control->warmup_start_time) {
         uint64_t now;
 
-        now = red_get_monotonic_time();
+        now = spice_get_monotonic_time_ns();
         if (now - rate_control->warmup_start_time < MJPEG_WARMUP_TIME) {
             spice_debug("during warmup. ignoring");
             return;
@@ -1351,7 +1351,7 @@  MJpegEncoder *mjpeg_encoder_new(uint64_t starting_bit_rate,
         encoder->rate_control.during_quality_eval = TRUE;
         encoder->rate_control.quality_eval_data.type = MJPEG_QUALITY_EVAL_TYPE_SET;
         encoder->rate_control.quality_eval_data.reason = MJPEG_QUALITY_EVAL_REASON_RATE_CHANGE;
-        encoder->rate_control.warmup_start_time = red_get_monotonic_time();
+        encoder->rate_control.warmup_start_time = spice_get_monotonic_time_ns();
     } else {
         encoder->cbs.get_roundtrip_ms = NULL;
         mjpeg_encoder_reset_quality(encoder, MJPEG_LEGACY_STATIC_QUALITY_ID, MJPEG_MAX_FPS, 0);
diff --git a/server/red-channel.c b/server/red-channel.c
index 7dfb9bf..361f1a5 100644
--- a/server/red-channel.c
+++ b/server/red-channel.c
@@ -553,7 +553,7 @@  static void red_channel_client_send_ping(RedChannelClient *rcc)
 
     red_channel_client_init_send_data(rcc, SPICE_MSG_PING, NULL);
     ping.id = rcc->latency_monitor.id;
-    ping.timestamp = red_get_monotonic_time();
+    ping.timestamp = spice_get_monotonic_time_ns();
     spice_marshall_msg_ping(rcc->send_data.marshaller, &ping);
     red_channel_client_begin_send_message(rcc);
 }
@@ -1432,7 +1432,7 @@  static void red_channel_client_restart_ping_timer(RedChannelClient *rcc)
 {
     uint64_t passed, timeout;
 
-    passed = red_get_monotonic_time();
+    passed = spice_get_monotonic_time_ns();
     passed = passed - rcc->latency_monitor.last_pong_time;
     passed /= 1000*1000;
     timeout = PING_TEST_IDLE_NET_TIMEOUT_MS;
@@ -1480,7 +1480,7 @@  static void red_channel_client_handle_pong(RedChannelClient *rcc, SpiceMsgPing *
         return;
     }
 
-    now = red_get_monotonic_time();
+    now = spice_get_monotonic_time_ns();
 
     if (rcc->latency_monitor.state == PING_STATE_WARMUP) {
         rcc->latency_monitor.state = PING_STATE_LATENCY;
@@ -2318,7 +2318,7 @@  int red_channel_client_wait_outgoing_item(RedChannelClient *rcc,
         return TRUE;
     }
     if (timeout != -1) {
-        end_time = red_get_monotonic_time() + timeout;
+        end_time = spice_get_monotonic_time_ns() + timeout;
     } else {
         end_time = UINT64_MAX;
     }
@@ -2329,7 +2329,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_get_monotonic_time() < end_time));
+             (timeout == -1 || spice_get_monotonic_time_ns() < end_time));
 
     if (blocked) {
         spice_warning("timeout");
@@ -2351,7 +2351,7 @@  int red_channel_client_wait_pipe_item_sent(RedChannelClient *rcc,
     spice_info(NULL);
 
     if (timeout != -1) {
-        end_time = red_get_monotonic_time() + timeout;
+        end_time = spice_get_monotonic_time_ns() + timeout;
     } else {
         end_time = UINT64_MAX;
     }
@@ -2365,7 +2365,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_get_monotonic_time() < end_time)) {
+          (timeout == -1 || spice_get_monotonic_time_ns() < end_time)) {
         usleep(CHANNEL_BLOCKED_SLEEP_DURATION);
         red_channel_client_receive(rcc);
         red_channel_client_send(rcc);
@@ -2378,7 +2378,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_get_monotonic_time());
+                                                     timeout == -1 ? -1 : end_time - spice_get_monotonic_time_ns());
     }
 }
 
@@ -2390,7 +2390,7 @@  int red_channel_wait_all_sent(RedChannel *channel,
     int blocked = FALSE;
 
     if (timeout != -1) {
-        end_time = red_get_monotonic_time() + timeout;
+        end_time = spice_get_monotonic_time_ns() + timeout;
     } else {
         end_time = UINT64_MAX;
     }
@@ -2398,7 +2398,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_get_monotonic_time() < end_time)) {
+           (timeout == -1 || spice_get_monotonic_time_ns() < 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-worker.c b/server/red-worker.c
index baa8458..15e7d12 100644
--- a/server/red-worker.c
+++ b/server/red-worker.c
@@ -228,7 +228,7 @@  static int red_process_display(RedWorker *worker, uint32_t max_pipe_size, int *r
 {
     QXLCommandExt ext_cmd;
     int n = 0;
-    uint64_t start = red_get_monotonic_time();
+    uint64_t start = spice_get_monotonic_time_ns();
 
     if (!worker->running) {
         *ring_is_empty = TRUE;
@@ -330,7 +330,7 @@  static int red_process_display(RedWorker *worker, uint32_t max_pipe_size, int *r
         n++;
         if ((worker->display_channel &&
              red_channel_all_blocked(&worker->display_channel->common.base))
-            || red_get_monotonic_time() - start > 10 * 1000 * 1000) {
+            || spice_get_monotonic_time_ns() - start > 10 * 1000 * 1000) {
             worker->event_timeout = 0;
             return n;
         }
@@ -397,7 +397,7 @@  static void flush_display_commands(RedWorker *worker)
         if (ring_is_empty) {
             break;
         }
-        end_time = red_get_monotonic_time() + DISPLAY_CLIENT_TIMEOUT;
+        end_time = spice_get_monotonic_time_ns() + DISPLAY_CLIENT_TIMEOUT;
         int sleep_count = 0;
         for (;;) {
             red_channel_push(RED_CHANNEL(worker->display_channel));
@@ -410,7 +410,7 @@  static 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_get_monotonic_time() >= end_time) {
+            if (spice_get_monotonic_time_ns() >= end_time) {
                 spice_warning("update timeout");
                 red_disconnect_all_display_TODO_remove_me(channel);
             } else {
@@ -441,7 +441,7 @@  static void flush_cursor_commands(RedWorker *worker)
         if (ring_is_empty) {
             break;
         }
-        end_time = red_get_monotonic_time() + DISPLAY_CLIENT_TIMEOUT;
+        end_time = spice_get_monotonic_time_ns() + DISPLAY_CLIENT_TIMEOUT;
         int sleep_count = 0;
         for (;;) {
             red_channel_push(RED_CHANNEL(worker->cursor_channel));
@@ -452,7 +452,7 @@  static void flush_cursor_commands(RedWorker *worker)
             RedChannel *channel = (RedChannel *)worker->cursor_channel;
             red_channel_receive(channel);
             red_channel_send(channel);
-            if (red_get_monotonic_time() >= end_time) {
+            if (spice_get_monotonic_time_ns() >= end_time) {
                 spice_warning("flush cursor timeout");
                 cursor_channel_disconnect(worker->cursor_channel);
                 worker->cursor_channel = NULL;
diff --git a/server/stream.c b/server/stream.c
index cb7271e..0a569b0 100644
--- a/server/stream.c
+++ b/server/stream.c
@@ -888,7 +888,7 @@  void stream_timeout(DisplayChannel *display)
     Ring *ring = &display->streams;
     RingItem *item;
 
-    red_time_t now = red_get_monotonic_time();
+    red_time_t now = spice_get_monotonic_time_ns();
     item = ring_get_head(ring);
     while (item) {
         Stream *stream = SPICE_CONTAINEROF(item, Stream, link);
diff --git a/server/utils.h b/server/utils.h
index d7b9e40..7c94880 100644
--- a/server/utils.h
+++ b/server/utils.h
@@ -51,7 +51,7 @@  static inline int test_bit(int index, uint32_t val)
 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)
+static inline red_time_t spice_get_monotonic_time_ns(void)
 {
     struct timespec time;
 

Comments

> 
> This is a generic function not tied to the red_xxx functionality and the
> new name clarifies that it returns the time in nanoseconds (unlike
> g_get_monotonic_time()).
> 
> Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
> ---
>  server/dcc-send.c        |  2 +-
>  server/dcc.c             |  4 ++--
>  server/display-channel.c |  8 ++++----
>  server/main-channel.c    |  2 +-
>  server/mjpeg-encoder.c   |  6 +++---
>  server/red-channel.c     | 20 ++++++++++----------
>  server/red-worker.c      | 12 ++++++------
>  server/stream.c          |  2 +-
>  server/utils.h           |  2 +-
>  9 files changed, 29 insertions(+), 29 deletions(-)
> 
> Of course this will conflict with the 'framerate estimate' patch but it
> has not been committed yet anyway. So I'm resubmitting it at the end of
> this patch series since it seems to systematically getting stuck in
> limbo.
> 
> diff --git a/server/dcc-send.c b/server/dcc-send.c
> index 30303e7..a8f42db 100644
> --- a/server/dcc-send.c
> +++ b/server/dcc-send.c
> @@ -1689,7 +1689,7 @@ static int red_marshall_stream_data(RedChannelClient
> *rcc,
>      }
>  
>      StreamAgent *agent = &dcc->stream_agents[get_stream_id(display,
>      stream)];
> -    uint64_t time_now = red_get_monotonic_time();
> +    uint64_t time_now = spice_get_monotonic_time_ns();
>      size_t outbuf_size;
>  
>      if (!dcc->use_mjpeg_encoder_rate_control) {
> diff --git a/server/dcc.c b/server/dcc.c
> index a893ea4..f47cbec 100644
> --- a/server/dcc.c
> +++ b/server/dcc.c
> @@ -415,7 +415,7 @@ static void dcc_create_all_streams(DisplayChannelClient
> *dcc)
>  static int display_channel_client_wait_for_init(DisplayChannelClient *dcc)
>  {
>      dcc->expect_init = TRUE;
> -    uint64_t end_time = red_get_monotonic_time() + DISPLAY_CLIENT_TIMEOUT;
> +    uint64_t end_time = spice_get_monotonic_time_ns() +
> DISPLAY_CLIENT_TIMEOUT;
>      for (;;) {
>          red_channel_client_receive(RED_CHANNEL_CLIENT(dcc));
>          if (!red_channel_client_is_connected(RED_CHANNEL_CLIENT(dcc))) {
> @@ -431,7 +431,7 @@ static int
> display_channel_client_wait_for_init(DisplayChannelClient *dcc)
>              }
>              return TRUE;
>          }
> -        if (red_get_monotonic_time() > end_time) {
> +        if (spice_get_monotonic_time_ns() > end_time) {
>              spice_warning("timeout");
>              red_channel_client_disconnect(RED_CHANNEL_CLIENT(dcc));
>              break;
> diff --git a/server/display-channel.c b/server/display-channel.c
> index 7cbcea5..442b8fa 100644
> --- a/server/display-channel.c
> +++ b/server/display-channel.c
> @@ -181,7 +181,7 @@ int display_channel_get_streams_timeout(DisplayChannel
> *display)
>      Ring *ring = &display->streams;
>      RingItem *item = ring;
>  
> -    red_time_t now = red_get_monotonic_time();
> +    red_time_t now = spice_get_monotonic_time_ns();
>      while ((item = ring_next(ring, item))) {
>          Stream *stream;
>  
> @@ -1187,7 +1187,7 @@ void display_channel_process_draw(DisplayChannel
> *display, RedDrawable *red_draw
>  
>  int display_channel_wait_for_migrate_data(DisplayChannel *display)
>  {
> -    uint64_t end_time = red_get_monotonic_time() +
> DISPLAY_CLIENT_MIGRATE_DATA_TIMEOUT;
> +    uint64_t end_time = spice_get_monotonic_time_ns() +
> DISPLAY_CLIENT_MIGRATE_DATA_TIMEOUT;
>      RedChannel *channel = &display->common.base;
>      RedChannelClient *rcc;
>      int ret = FALSE;
> @@ -1212,7 +1212,7 @@ int
> display_channel_wait_for_migrate_data(DisplayChannel *display)
>              ret = TRUE;
>              break;
>          }
> -        if (red_get_monotonic_time() > end_time) {
> +        if (spice_get_monotonic_time_ns() > end_time) {
>              spice_warning("timeout");
>              red_channel_client_disconnect(rcc);
>              break;
> @@ -1371,7 +1371,7 @@ Drawable
> *display_channel_drawable_try_new(DisplayChannel *display,
>  
>      bzero(drawable, sizeof(Drawable));
>      drawable->refs = 1;
> -    drawable->creation_time = red_get_monotonic_time();
> +    drawable->creation_time = spice_get_monotonic_time_ns();
>      ring_item_init(&drawable->list_link);
>      ring_item_init(&drawable->surface_list_link);
>      ring_item_init(&drawable->tree_item.base.siblings_link);
> diff --git a/server/main-channel.c b/server/main-channel.c
> index e74ba76..6cd2e59 100644
> --- a/server/main-channel.c
> +++ b/server/main-channel.c
> @@ -588,7 +588,7 @@ static void main_channel_marshall_notify(RedChannelClient
> *rcc,
>      SpiceMsgNotify notify;
>  
>      red_channel_client_init_send_data(rcc, SPICE_MSG_NOTIFY, &item->base);
> -    notify.time_stamp = red_get_monotonic_time(); // TODO - move to
> main_new_notify_item
> +    notify.time_stamp = spice_get_monotonic_time_ns(); // TODO - move to
> main_new_notify_item
>      notify.severity = SPICE_NOTIFY_SEVERITY_WARN;
>      notify.visibilty = SPICE_NOTIFY_VISIBILITY_HIGH;
>      notify.what = SPICE_WARN_GENERAL;
> diff --git a/server/mjpeg-encoder.c b/server/mjpeg-encoder.c
> index 08af1eb..9c51f7b 100644
> --- a/server/mjpeg-encoder.c
> +++ b/server/mjpeg-encoder.c
> @@ -716,7 +716,7 @@ static int mjpeg_encoder_start_frame(MJpegEncoder
> *encoder,
>          uint64_t now;
>          uint64_t interval;
>  
> -        now = red_get_monotonic_time();
> +        now = spice_get_monotonic_time_ns();
>  
>          if (!rate_control->adjusted_fps_start_time) {
>              rate_control->adjusted_fps_start_time = now;
> @@ -995,7 +995,7 @@ static void mjpeg_encoder_decrease_bit_rate(MJpegEncoder
> *encoder)
>      if (rate_control->warmup_start_time) {
>          uint64_t now;
>  
> -        now = red_get_monotonic_time();
> +        now = spice_get_monotonic_time_ns();
>          if (now - rate_control->warmup_start_time < MJPEG_WARMUP_TIME) {
>              spice_debug("during warmup. ignoring");
>              return;
> @@ -1351,7 +1351,7 @@ MJpegEncoder *mjpeg_encoder_new(uint64_t
> starting_bit_rate,
>          encoder->rate_control.during_quality_eval = TRUE;
>          encoder->rate_control.quality_eval_data.type =
>          MJPEG_QUALITY_EVAL_TYPE_SET;
>          encoder->rate_control.quality_eval_data.reason =
>          MJPEG_QUALITY_EVAL_REASON_RATE_CHANGE;
> -        encoder->rate_control.warmup_start_time = red_get_monotonic_time();
> +        encoder->rate_control.warmup_start_time =
> spice_get_monotonic_time_ns();
>      } else {
>          encoder->cbs.get_roundtrip_ms = NULL;
>          mjpeg_encoder_reset_quality(encoder, MJPEG_LEGACY_STATIC_QUALITY_ID,
>          MJPEG_MAX_FPS, 0);
> diff --git a/server/red-channel.c b/server/red-channel.c
> index 7dfb9bf..361f1a5 100644
> --- a/server/red-channel.c
> +++ b/server/red-channel.c
> @@ -553,7 +553,7 @@ static void red_channel_client_send_ping(RedChannelClient
> *rcc)
>  
>      red_channel_client_init_send_data(rcc, SPICE_MSG_PING, NULL);
>      ping.id = rcc->latency_monitor.id;
> -    ping.timestamp = red_get_monotonic_time();
> +    ping.timestamp = spice_get_monotonic_time_ns();
>      spice_marshall_msg_ping(rcc->send_data.marshaller, &ping);
>      red_channel_client_begin_send_message(rcc);
>  }
> @@ -1432,7 +1432,7 @@ static void
> red_channel_client_restart_ping_timer(RedChannelClient *rcc)
>  {
>      uint64_t passed, timeout;
>  
> -    passed = red_get_monotonic_time();
> +    passed = spice_get_monotonic_time_ns();
>      passed = passed - rcc->latency_monitor.last_pong_time;
>      passed /= 1000*1000;
>      timeout = PING_TEST_IDLE_NET_TIMEOUT_MS;
> @@ -1480,7 +1480,7 @@ static void
> red_channel_client_handle_pong(RedChannelClient *rcc, SpiceMsgPing *
>          return;
>      }
>  
> -    now = red_get_monotonic_time();
> +    now = spice_get_monotonic_time_ns();
>  
>      if (rcc->latency_monitor.state == PING_STATE_WARMUP) {
>          rcc->latency_monitor.state = PING_STATE_LATENCY;
> @@ -2318,7 +2318,7 @@ int
> red_channel_client_wait_outgoing_item(RedChannelClient *rcc,
>          return TRUE;
>      }
>      if (timeout != -1) {
> -        end_time = red_get_monotonic_time() + timeout;
> +        end_time = spice_get_monotonic_time_ns() + timeout;
>      } else {
>          end_time = UINT64_MAX;
>      }
> @@ -2329,7 +2329,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_get_monotonic_time() < end_time));
> +             (timeout == -1 || spice_get_monotonic_time_ns() < end_time));
>  
>      if (blocked) {
>          spice_warning("timeout");
> @@ -2351,7 +2351,7 @@ int
> red_channel_client_wait_pipe_item_sent(RedChannelClient *rcc,
>      spice_info(NULL);
>  
>      if (timeout != -1) {
> -        end_time = red_get_monotonic_time() + timeout;
> +        end_time = spice_get_monotonic_time_ns() + timeout;
>      } else {
>          end_time = UINT64_MAX;
>      }
> @@ -2365,7 +2365,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_get_monotonic_time() < end_time)) {
> +          (timeout == -1 || spice_get_monotonic_time_ns() < end_time)) {
>          usleep(CHANNEL_BLOCKED_SLEEP_DURATION);
>          red_channel_client_receive(rcc);
>          red_channel_client_send(rcc);
> @@ -2378,7 +2378,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_get_monotonic_time());
> +                                                     timeout == -1 ? -1 :
> end_time - spice_get_monotonic_time_ns());
>      }
>  }
>  
> @@ -2390,7 +2390,7 @@ int red_channel_wait_all_sent(RedChannel *channel,
>      int blocked = FALSE;
>  
>      if (timeout != -1) {
> -        end_time = red_get_monotonic_time() + timeout;
> +        end_time = spice_get_monotonic_time_ns() + timeout;
>      } else {
>          end_time = UINT64_MAX;
>      }
> @@ -2398,7 +2398,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_get_monotonic_time() < end_time)) {
> +           (timeout == -1 || spice_get_monotonic_time_ns() < 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-worker.c b/server/red-worker.c
> index baa8458..15e7d12 100644
> --- a/server/red-worker.c
> +++ b/server/red-worker.c
> @@ -228,7 +228,7 @@ static int red_process_display(RedWorker *worker,
> uint32_t max_pipe_size, int *r
>  {
>      QXLCommandExt ext_cmd;
>      int n = 0;
> -    uint64_t start = red_get_monotonic_time();
> +    uint64_t start = spice_get_monotonic_time_ns();
>  
>      if (!worker->running) {
>          *ring_is_empty = TRUE;
> @@ -330,7 +330,7 @@ static int red_process_display(RedWorker *worker,
> uint32_t max_pipe_size, int *r
>          n++;
>          if ((worker->display_channel &&
>               red_channel_all_blocked(&worker->display_channel->common.base))
> -            || red_get_monotonic_time() - start > 10 * 1000 * 1000) {
> +            || spice_get_monotonic_time_ns() - start > 10 * 1000 * 1000) {
>              worker->event_timeout = 0;
>              return n;
>          }
> @@ -397,7 +397,7 @@ static void flush_display_commands(RedWorker *worker)
>          if (ring_is_empty) {
>              break;
>          }
> -        end_time = red_get_monotonic_time() + DISPLAY_CLIENT_TIMEOUT;
> +        end_time = spice_get_monotonic_time_ns() + DISPLAY_CLIENT_TIMEOUT;
>          int sleep_count = 0;
>          for (;;) {
>              red_channel_push(RED_CHANNEL(worker->display_channel));
> @@ -410,7 +410,7 @@ static 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_get_monotonic_time() >= end_time) {
> +            if (spice_get_monotonic_time_ns() >= end_time) {
>                  spice_warning("update timeout");
>                  red_disconnect_all_display_TODO_remove_me(channel);
>              } else {
> @@ -441,7 +441,7 @@ static void flush_cursor_commands(RedWorker *worker)
>          if (ring_is_empty) {
>              break;
>          }
> -        end_time = red_get_monotonic_time() + DISPLAY_CLIENT_TIMEOUT;
> +        end_time = spice_get_monotonic_time_ns() + DISPLAY_CLIENT_TIMEOUT;
>          int sleep_count = 0;
>          for (;;) {
>              red_channel_push(RED_CHANNEL(worker->cursor_channel));
> @@ -452,7 +452,7 @@ static void flush_cursor_commands(RedWorker *worker)
>              RedChannel *channel = (RedChannel *)worker->cursor_channel;
>              red_channel_receive(channel);
>              red_channel_send(channel);
> -            if (red_get_monotonic_time() >= end_time) {
> +            if (spice_get_monotonic_time_ns() >= end_time) {
>                  spice_warning("flush cursor timeout");
>                  cursor_channel_disconnect(worker->cursor_channel);
>                  worker->cursor_channel = NULL;
> diff --git a/server/stream.c b/server/stream.c
> index cb7271e..0a569b0 100644
> --- a/server/stream.c
> +++ b/server/stream.c
> @@ -888,7 +888,7 @@ void stream_timeout(DisplayChannel *display)
>      Ring *ring = &display->streams;
>      RingItem *item;
>  
> -    red_time_t now = red_get_monotonic_time();
> +    red_time_t now = spice_get_monotonic_time_ns();
>      item = ring_get_head(ring);
>      while (item) {
>          Stream *stream = SPICE_CONTAINEROF(item, Stream, link);
> diff --git a/server/utils.h b/server/utils.h
> index d7b9e40..7c94880 100644
> --- a/server/utils.h
> +++ b/server/utils.h
> @@ -51,7 +51,7 @@ static inline int test_bit(int index, uint32_t val)
>  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)
> +static inline red_time_t spice_get_monotonic_time_ns(void)
>  {
>      struct timespec time;
>  

Acked-by: Frediano Ziglio <fziglio@redhat.com>

Frediano