diff options
author | Marek Olšák <marek.olsak@amd.com> | 2020-10-06 18:59:31 -0400 |
---|---|---|
committer | Marge Bot <eric+marge@anholt.net> | 2020-10-30 05:07:57 +0000 |
commit | 96d9f7761d4b313c69664c01682aef8f13bc6c02 (patch) | |
tree | 25148c2a0ec5641604fe4a0e402abd6527549c23 | |
parent | 53a15925da524d871b1331812cd9e91143fadc52 (diff) | |
download | external_mesa3d-96d9f7761d4b313c69664c01682aef8f13bc6c02.tar.gz external_mesa3d-96d9f7761d4b313c69664c01682aef8f13bc6c02.tar.bz2 external_mesa3d-96d9f7761d4b313c69664c01682aef8f13bc6c02.zip |
util: consolidate thread_get_time functions
Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Acked-by: Jose Fonseca <jfonseca@vmware.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7054>
-rw-r--r-- | src/gallium/auxiliary/hud/hud_cpu.c | 4 | ||||
-rw-r--r-- | src/gallium/auxiliary/os/os_thread.h | 17 | ||||
-rw-r--r-- | src/util/u_queue.c | 2 | ||||
-rw-r--r-- | src/util/u_thread.h | 18 |
4 files changed, 20 insertions, 21 deletions
diff --git a/src/gallium/auxiliary/hud/hud_cpu.c b/src/gallium/auxiliary/hud/hud_cpu.c index f10640bb40f..767bff48841 100644 --- a/src/gallium/auxiliary/hud/hud_cpu.c +++ b/src/gallium/auxiliary/hud/hud_cpu.c @@ -333,7 +333,7 @@ query_api_thread_busy_status(struct hud_graph *gr, struct pipe_context *pipe) int64_t thread_now; if (info->main_thread) { - thread_now = pipe_current_thread_get_time_nano(); + thread_now = util_current_thread_get_time_nano(); } else { struct util_queue_monitoring *mon = gr->pane->hud->monitored_queue; @@ -360,7 +360,7 @@ query_api_thread_busy_status(struct hud_graph *gr, struct pipe_context *pipe) } else { /* initialize */ info->last_time = now; - info->last_thread_time = pipe_current_thread_get_time_nano(); + info->last_thread_time = util_current_thread_get_time_nano(); } } diff --git a/src/gallium/auxiliary/os/os_thread.h b/src/gallium/auxiliary/os/os_thread.h index f2629c5ffe5..7ca65a21dd0 100644 --- a/src/gallium/auxiliary/os/os_thread.h +++ b/src/gallium/auxiliary/os/os_thread.h @@ -155,21 +155,4 @@ pipe_tsd_set(pipe_tsd *tsd, void *value) } } - - -/* - * Thread statistics. - */ - -/* Return the time of the current thread's CPU time clock. */ -static inline int64_t -pipe_current_thread_get_time_nano(void) -{ -#if defined(HAVE_PTHREAD) - return u_thread_get_time_nano(pthread_self()); -#else - return 0; -#endif -} - #endif /* OS_THREAD_H_ */ diff --git a/src/util/u_queue.c b/src/util/u_queue.c index 8f6dc08b332..b1478bdf483 100644 --- a/src/util/u_queue.c +++ b/src/util/u_queue.c @@ -696,5 +696,5 @@ util_queue_get_thread_time_nano(struct util_queue *queue, unsigned thread_index) if (thread_index >= queue->num_threads) return 0; - return u_thread_get_time_nano(queue->threads[thread_index]); + return util_thread_get_time_nano(queue->threads[thread_index]); } diff --git a/src/util/u_thread.h b/src/util/u_thread.h index 917ffead6a5..d1fb95e3de1 100644 --- a/src/util/u_thread.h +++ b/src/util/u_thread.h @@ -124,7 +124,7 @@ util_pin_thread_to_L3(thrd_t thread, unsigned L3_index, unsigned cores_per_L3) /* Return the time of a thread's CPU time clock. */ static inline int64_t -u_thread_get_time_nano(thrd_t thread) +util_thread_get_time_nano(thrd_t thread) { #if defined(HAVE_PTHREAD) && !defined(__APPLE__) && !defined(__HAIKU__) struct timespec ts; @@ -138,6 +138,22 @@ u_thread_get_time_nano(thrd_t thread) #endif } +/* Return the time of the current thread's CPU time clock. */ +static inline int64_t +util_current_thread_get_time_nano(void) +{ +#if defined(HAVE_PTHREAD) + return util_thread_get_time_nano(pthread_self()); + +#elif defined(_WIN32) && !defined(__CYGWIN__) + /* The GetCurrentThreadId() handle is only valid within the current thread. */ + return util_thread_get_time_nano(GetCurrentThread()); + +#else + return 0; +#endif +} + static inline bool u_thread_is_self(thrd_t thread) { #if defined(HAVE_PTHREAD) |