[Spice-devel] [PATCH v2] stats: use CLOCK_THREAD_CPUTIME_ID for cpu statistics

Frediano Ziglio fziglio at redhat.com
Mon Jan 11 07:45:40 PST 2016


Use CLOCK_THREAD_CPUTIME_ID instead of getting the clock
with pthread_getcpuclockid.
This avoids to call red_worker_get_clockid. This function returns
uninitialized value at the time DisplayChannel is built resulting in setting
statistics to CLOCK_REALTIME (which is 0) instead to cpu time as expected.

Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
 server/display-channel.c |  2 +-
 server/red-worker.c      | 16 ++--------------
 server/red-worker.h      |  1 -
 3 files changed, 3 insertions(+), 16 deletions(-)

diff --git a/server/display-channel.c b/server/display-channel.c
index ec4ca10..3bf065c 100644
--- a/server/display-channel.c
+++ b/server/display-channel.c
@@ -2041,7 +2041,7 @@ DisplayChannel* display_channel_new(RedWorker *worker, int migrate, int stream_v
         &cbs, dcc_handle_message);
     spice_return_val_if_fail(display, NULL);
 
-    clockid_t stat_clock = red_worker_get_clockid(worker);
+    clockid_t stat_clock = CLOCK_THREAD_CPUTIME_ID;
     stat_init(&display->add_stat, "add", stat_clock);
     stat_init(&display->exclude_stat, "exclude", stat_clock);
     stat_init(&display->__exclude_stat, "__exclude", stat_clock);
diff --git a/server/red-worker.c b/server/red-worker.c
index dfaf4ba..ae798ec 100644
--- a/server/red-worker.c
+++ b/server/red-worker.c
@@ -67,7 +67,6 @@ struct SpiceWatch {
 
 struct RedWorker {
     pthread_t thread;
-    clockid_t clockid;
     QXLInstance *qxl;
     RedDispatcher *red_dispatcher;
     int running;
@@ -256,7 +255,7 @@ static int red_process_display(RedWorker *worker, uint32_t max_pipe_size, int *r
 
         if (worker->record_fd)
             red_record_qxl_command(worker->record_fd, &worker->mem_slots, ext_cmd,
-                                   stat_now(worker->clockid));
+                                   stat_now(CLOCK_THREAD_CPUTIME_ID));
 
         stat_inc_counter(worker->command_counter, 1);
         worker->display_poll_tries = 0;
@@ -1348,7 +1347,7 @@ static void worker_dispatcher_record(void *opaque, uint32_t message_type, void *
 {
     RedWorker *worker = opaque;
 
-    red_record_event(worker->record_fd, 1, message_type, stat_now(worker->clockid));
+    red_record_event(worker->record_fd, 1, message_type, stat_now(CLOCK_THREAD_CPUTIME_ID));
 }
 
 static void register_callbacks(Dispatcher *dispatcher)
@@ -1619,10 +1618,6 @@ SPICE_GNUC_NORETURN static void *red_worker_main(void *arg)
         spice_error("failed to create timer queue");
     }
 
-    if (pthread_getcpuclockid(pthread_self(), &worker->clockid)) {
-        spice_warning("getcpuclockid failed");
-    }
-
     RED_CHANNEL(worker->cursor_channel)->thread_id = pthread_self();
     RED_CHANNEL(worker->display_channel)->thread_id = pthread_self();
 
@@ -1723,10 +1718,3 @@ RedChannel* red_worker_get_display_channel(RedWorker *worker)
 
     return RED_CHANNEL(worker->display_channel);
 }
-
-clockid_t red_worker_get_clockid(RedWorker *worker)
-{
-    spice_return_val_if_fail(worker, 0);
-
-    return worker->clockid;
-}
diff --git a/server/red-worker.h b/server/red-worker.h
index 1f0cd99..91533e1 100644
--- a/server/red-worker.h
+++ b/server/red-worker.h
@@ -97,7 +97,6 @@ bool       red_worker_run(RedWorker *worker);
 QXLInstance* red_worker_get_qxl(RedWorker *worker);
 RedChannel* red_worker_get_cursor_channel(RedWorker *worker);
 RedChannel* red_worker_get_display_channel(RedWorker *worker);
-clockid_t red_worker_get_clockid(RedWorker *worker);
 RedMemSlotInfo* red_worker_get_memslot(RedWorker *worker);
 
 void red_drawable_unref(RedWorker *worker, RedDrawable *red_drawable,
-- 
2.4.3



More information about the Spice-devel mailing list