[Spice-commits] 3 commits - server/dcc.c server/dcc-send.c server/display-channel.c server/main-channel.c server/mjpeg-encoder.c server/red-channel.c server/reds.c server/reds-private.h server/red-worker.c server/spice_timer_queue.c server/stream.c server/utils.h

Frediano Ziglio fziglio at kemper.freedesktop.org
Fri Dec 11 04:44:38 PST 2015


 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/reds-private.h      |    2 --
 server/reds.c              |    6 ++----
 server/spice_timer_queue.c |   15 ++++-----------
 server/stream.c            |    2 +-
 server/utils.h             |    7 ++++++-
 12 files changed, 40 insertions(+), 46 deletions(-)

New commits:
commit c9282b3bc743d474d9c0734e75ac176a0bdfb170
Author: Francois Gouget <fgouget at codeweavers.com>
Date:   Fri Dec 11 12:22:10 2015 +0100

    server: Use spice_get_monotonic_time_ms() in spice_timer_queue.c
    
    This reduces code duplication.
    
    Signed-off-by: Francois Gouget <fgouget at codeweavers.com>
    Acked-by: Frediano Ziglio <fziglio at redhat.com>

diff --git a/server/spice_timer_queue.c b/server/spice_timer_queue.c
index 60017cc..12ac131 100644
--- a/server/spice_timer_queue.c
+++ b/server/spice_timer_queue.c
@@ -20,6 +20,7 @@
 #include "red-common.h"
 #include "spice_timer_queue.h"
 #include "common/ring.h"
+#include "utils.h"
 
 static Ring timer_queue_list;
 static int queue_count = 0;
@@ -178,13 +179,9 @@ static void _spice_timer_set(SpiceTimer *timer, uint32_t ms, uint64_t now)
 
 void spice_timer_set(SpiceTimer *timer, uint32_t ms)
 {
-    struct timespec now;
-
     spice_assert(pthread_equal(timer->queue->thread, pthread_self()) != 0);
 
-    clock_gettime(CLOCK_MONOTONIC, &now);
-    _spice_timer_set(timer, ms,
-                     (uint64_t)now.tv_sec * 1000 + (now.tv_nsec / 1000 / 1000));
+    _spice_timer_set(timer, ms, spice_get_monotonic_time_ms());
 }
 
 void spice_timer_cancel(SpiceTimer *timer)
@@ -217,7 +214,6 @@ void spice_timer_remove(SpiceTimer *timer)
 
 unsigned int spice_timer_queue_get_timeout_ms(void)
 {
-    struct timespec now;
     int64_t now_ms;
     RingItem *head;
     SpiceTimer *head_timer;
@@ -232,8 +228,7 @@ unsigned int spice_timer_queue_get_timeout_ms(void)
     head = ring_get_head(&queue->active_timers);
     head_timer = SPICE_CONTAINEROF(head, SpiceTimer, active_link);
 
-    clock_gettime(CLOCK_MONOTONIC, &now);
-    now_ms = ((int64_t)now.tv_sec * 1000) + (now.tv_nsec / 1000 / 1000);
+    now_ms = spice_get_monotonic_time_ms();
 
     return MAX(0, ((int64_t)head_timer->expiry_time - now_ms));
 }
@@ -241,7 +236,6 @@ unsigned int spice_timer_queue_get_timeout_ms(void)
 
 void spice_timer_queue_cb(void)
 {
-    struct timespec now;
     uint64_t now_ms;
     RingItem *head;
     SpiceTimerQueue *queue = spice_timer_queue_find_with_lock();
@@ -252,8 +246,7 @@ void spice_timer_queue_cb(void)
         return;
     }
 
-    clock_gettime(CLOCK_MONOTONIC, &now);
-    now_ms = ((uint64_t)now.tv_sec * 1000) + (now.tv_nsec / 1000 / 1000);
+    now_ms = spice_get_monotonic_time_ms();
 
     while ((head = ring_get_head(&queue->active_timers))) {
         SpiceTimer *timer = SPICE_CONTAINEROF(head, SpiceTimer, active_link);
commit f7613250c57de92f407f682858ed2529c38c7dd6
Author: Francois Gouget <fgouget at codeweavers.com>
Date:   Fri Dec 11 12:22:03 2015 +0100

    server: Add spice_get_monotonic_time_ms()
    
    Signed-off-by: Francois Gouget <fgouget at codeweavers.com>
    Acked-by: Frediano Ziglio <fziglio at redhat.com>

diff --git a/server/reds-private.h b/server/reds-private.h
index 790f61c..5afde30 100644
--- a/server/reds-private.h
+++ b/server/reds-private.h
@@ -18,8 +18,6 @@
 #ifndef REDS_PRIVATE_H
 #define REDS_PRIVATE_H
 
-#include <time.h>
-
 #include <spice/protocol.h>
 
 #define MIGRATE_TIMEOUT (1000 * 10) /* 10sec */
diff --git a/server/reds.c b/server/reds.c
index 75a7d95..31362ef 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -29,7 +29,6 @@
 #include <arpa/inet.h>
 #include <netdb.h>
 #include <limits.h>
-#include <time.h>
 #include <pthread.h>
 #include <sys/mman.h>
 #include <fcntl.h>
@@ -69,6 +68,7 @@
 #include "smartcard.h"
 #endif
 #include "reds-stream.h"
+#include "utils.h"
 
 #include "reds-private.h"
 
@@ -2882,9 +2882,7 @@ static void migrate_timeout(void *opaque)
 
 uint32_t reds_get_mm_time(void)
 {
-    struct timespec time_space;
-    clock_gettime(CLOCK_MONOTONIC, &time_space);
-    return time_space.tv_sec * 1000 + time_space.tv_nsec / 1000 / 1000;
+    return spice_get_monotonic_time_ms();
 }
 
 void reds_enable_mm_time(void)
diff --git a/server/utils.h b/server/utils.h
index 7c94880..3aa5be0 100644
--- a/server/utils.h
+++ b/server/utils.h
@@ -59,6 +59,11 @@ static inline red_time_t spice_get_monotonic_time_ns(void)
     return (red_time_t) time.tv_sec * (1000 * 1000 * 1000) + time.tv_nsec;
 }
 
+static inline red_time_t spice_get_monotonic_time_ms(void)
+{
+    return g_get_monotonic_time() / 1000;
+}
+
 int rgb32_data_has_alpha(int width, int height, size_t stride,
                          uint8_t *data, int *all_set_out);
 
commit 65b60250d0c0818eed30c59e70120ca40d72f33e
Author: Francois Gouget <fgouget at codeweavers.com>
Date:   Fri Dec 11 12:21:34 2015 +0100

    server: Rename red_get_monotonic_time() to spice_get_monotonic_time_ns()
    
    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 at codeweavers.com>
    Acked-by: Frediano Ziglio <fziglio at redhat.com>

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 80d7335..ec4ca10 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 = drawable->first_frame_time = red_get_monotonic_time();
+    drawable->creation_time = drawable->first_frame_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 b65d430..ae70296 100644
--- a/server/stream.c
+++ b/server/stream.c
@@ -902,7 +902,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;
 


More information about the Spice-commits mailing list