[Spice-devel] [PATCH 6/9] worker: use a single clockid
Frediano Ziglio
fziglio at redhat.com
Wed Oct 21 05:00:35 PDT 2015
From: Marc-André Lureau <marcandre.lureau at gmail.com>
The stat functions in worker are not generic enough to deserve to be
"non-worker", so just pass the worker instance.
---
server/red_worker.c | 59 +++++++++++++++++++++++++++--------------------------
1 file changed, 30 insertions(+), 29 deletions(-)
diff --git a/server/red_worker.c b/server/red_worker.c
index e5486c4..65961db 100644
--- a/server/red_worker.c
+++ b/server/red_worker.c
@@ -162,18 +162,8 @@ static inline red_time_t timespec_to_red_time(struct timespec *time)
return (red_time_t) time->tv_sec * (1000 * 1000 * 1000) + time->tv_nsec;
}
-static clockid_t clock_id;
-
typedef unsigned long stat_time_t;
-static stat_time_t stat_now(void)
-{
- struct timespec ts;
-
- clock_gettime(clock_id, &ts);
- return ts.tv_nsec + ts.tv_sec * 1000 * 1000 * 1000;
-}
-
#if defined(RED_WORKER_STAT) || defined(COMPRESS_STAT)
double stat_cpu_time_to_sec(stat_time_t time)
{
@@ -214,11 +204,11 @@ static inline void stat_init(stat_info_t *info, const char *name)
stat_reset(info);
}
-static inline void stat_add(stat_info_t *info, stat_time_t start)
+static inline void stat_add(struct RedWorker *worker, stat_info_t *info, stat_time_t start)
{
stat_time_t time;
++info->count;
- time = stat_now() - start;
+ time = stat_now(worker) - start;
info->total += time;
info->max = MAX(info->max, time);
info->min = MIN(info->min, time);
@@ -244,12 +234,13 @@ static inline void stat_compress_init(stat_info_t *info, const char *name)
stat_reset(info);
}
-static inline void stat_compress_add(stat_info_t *info, stat_time_t start, int orig_size,
+static inline void stat_compress_add(struct RedWorker *worker, stat_info_t *info,
+ stat_time_t start, int orig_size,
int comp_size)
{
stat_time_t time;
++info->count;
- time = stat_now() - start;
+ time = stat_now(worker) - start;
info->total += time;
info->max = MAX(info->max, time);
info->min = MIN(info->min, time);
@@ -869,6 +860,7 @@ typedef struct ItemTrace {
typedef struct RedWorker {
pthread_t thread;
+ clockid_t clockid;
DisplayChannel *display_channel;
CursorChannel *cursor_channel;
QXLInstance *qxl;
@@ -988,6 +980,16 @@ typedef struct BitmapData {
} BitmapData;
static inline int validate_surface(RedWorker *worker, uint32_t surface_id);
+
+static stat_time_t stat_now(RedWorker *worker)
+{
+ clockid_t clock_id = worker->clockid;
+ struct timespec ts;
+
+ clock_gettime(clock_id, &ts);
+ return ts.tv_nsec + ts.tv_sec * 1000 * 1000 * 1000;
+}
+
static void red_draw_qxl_drawable(RedWorker *worker, Drawable *drawable);
static void red_current_flush(RedWorker *worker, int surface_id);
static void red_draw_drawable(RedWorker *worker, Drawable *item);
@@ -2099,7 +2101,7 @@ static inline void __exclude_region(RedWorker *worker, Ring *ring, TreeItem *ite
{
QRegion and_rgn;
#ifdef RED_WORKER_STAT
- stat_time_t start_time = stat_now();
+ stat_time_t start_time = stat_now(worker);
#endif
region_clone(&and_rgn, rgn);
@@ -2169,7 +2171,7 @@ static void exclude_region(RedWorker *worker, Ring *ring, RingItem *ring_item, Q
TreeItem **last, Drawable *frame_candidate)
{
#ifdef RED_WORKER_STAT
- stat_time_t start_time = stat_now();
+ stat_time_t start_time = stat_now(worker);
#endif
Ring *top_ring;
@@ -3483,7 +3485,7 @@ static inline int red_current_add(RedWorker *worker, Ring *ring, Drawable *drawa
{
DrawItem *item = &drawable->tree_item;
#ifdef RED_WORKER_STAT
- stat_time_t start_time = stat_now();
+ stat_time_t start_time = stat_now(worker);
#endif
RingItem *now;
QRegion exclude_rgn;
@@ -3630,7 +3632,7 @@ static inline int red_current_add_with_shadow(RedWorker *worker, Ring *ring, Dra
SpicePoint *delta)
{
#ifdef RED_WORKER_STAT
- stat_time_t start_time = stat_now();
+ stat_time_t start_time = stat_now(worker);
#endif
Shadow *shadow = __new_shadow(worker, item, delta);
@@ -4737,7 +4739,7 @@ static int red_process_commands(RedWorker *worker, uint32_t max_pipe_size, int *
if (worker->record_fd)
red_record_qxl_command(worker->record_fd, &worker->mem_slots, ext_cmd,
- stat_now());
+ stat_now(worker));
stat_inc_counter(worker->command_counter, 1);
worker->repoll_cmd_ring = 0;
@@ -5761,7 +5763,7 @@ static inline int red_glz_compress_image(DisplayChannelClient *dcc,
DisplayChannel *display_channel = DCC_TO_DC(dcc);
RedWorker *worker = display_channel->common.worker;
#ifdef COMPRESS_STAT
- stat_time_t start_time = stat_now();
+ stat_time_t start_time = stat_now(worker);
#endif
spice_assert(bitmap_fmt_is_rgb(src->format));
GlzData *glz_data = &dcc->glz_data;
@@ -5804,7 +5806,7 @@ static inline int red_glz_compress_image(DisplayChannelClient *dcc,
goto glz;
}
#ifdef COMPRESS_STAT
- start_time = stat_now();
+ start_time = stat_now(worker);
#endif
zlib_data = &worker->zlib_data;
@@ -5867,7 +5869,7 @@ static inline int red_lz_compress_image(DisplayChannelClient *dcc,
int size; // size of the compressed data
#ifdef COMPRESS_STAT
- stat_time_t start_time = stat_now();
+ stat_time_t start_time = stat_now(worker);
#endif
lz_data->data.bufs_tail = red_display_alloc_compress_buf(dcc);
@@ -5953,7 +5955,7 @@ static int red_jpeg_compress_image(DisplayChannelClient *dcc, SpiceImage *dest,
uint8_t *lz_out_start_byte;
#ifdef COMPRESS_STAT
- stat_time_t start_time = stat_now();
+ stat_time_t start_time = stat_now(worker);
#endif
switch (src->format) {
case SPICE_BITMAP_FMT_16BIT:
@@ -6087,7 +6089,7 @@ static int red_lz4_compress_image(DisplayChannelClient *dcc, SpiceImage *dest,
int lz4_size = 0;
#ifdef COMPRESS_STAT
- stat_time_t start_time = stat_now();
+ stat_time_t start_time = stat_now(worker);
#endif
lz4_data->data.bufs_tail = red_display_alloc_compress_buf(dcc);
@@ -6153,7 +6155,7 @@ static inline int red_quic_compress_image(DisplayChannelClient *dcc, SpiceImage
int size, stride;
#ifdef COMPRESS_STAT
- stat_time_t start_time = stat_now();
+ stat_time_t start_time = stat_now(worker);
#endif
switch (src->format) {
@@ -11656,7 +11658,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());
+ red_record_event(worker->record_fd, 1, message_type, stat_now(worker));
}
static void register_callbacks(Dispatcher *dispatcher)
@@ -11960,9 +11962,8 @@ SPICE_GNUC_NORETURN static void *red_worker_main(void *arg)
spice_assert(MAX_PIPE_SIZE > WIDE_CLIENT_ACK_WINDOW &&
MAX_PIPE_SIZE > NARROW_CLIENT_ACK_WINDOW); //ensure wakeup by ack message
- // TODO: call once unconditionnally
- if (pthread_getcpuclockid(pthread_self(), &clock_id)) {
- spice_error("pthread_getcpuclockid failed");
+ if (pthread_getcpuclockid(pthread_self(), &worker->clockid)) {
+ spice_warning("getcpuclockid failed");
}
for (;;) {
--
2.4.3
More information about the Spice-devel
mailing list