[Mesa-dev] [PATCH 1/4] gallium/os: add per-thread time clock queries

Marek Olšák maraeo at gmail.com
Sat Feb 11 19:58:56 UTC 2017


From: Marek Olšák <marek.olsak at amd.com>

---
 src/gallium/auxiliary/os/os_thread.h | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/src/gallium/auxiliary/os/os_thread.h b/src/gallium/auxiliary/os/os_thread.h
index 21faf4b..0caf955 100644
--- a/src/gallium/auxiliary/os/os_thread.h
+++ b/src/gallium/auxiliary/os/os_thread.h
@@ -328,11 +328,42 @@ pipe_tsd_set(pipe_tsd *tsd, void *value)
    if (tsd->initMagic != (int) PIPE_TSD_INIT_MAGIC) {
       pipe_tsd_init(tsd);
    }
    if (tss_set(tsd->key, value) != 0) {
       exit(-1);
    }
 }
 
 
 
+/*
+ * Thread statistics.
+ */
+
+/* Return the time of a thread's CPU time clock. */
+static inline int64_t
+pipe_thread_get_time_nano(pipe_thread thread)
+{
+#if defined(PIPE_OS_LINUX) && defined(HAVE_PTHREAD)
+   struct timespec ts;
+   clockid_t cid;
+
+   pthread_getcpuclockid(thread, &cid);
+   clock_gettime(cid, &ts);
+   return (int64_t)ts.tv_sec * 1000000000 + ts.tv_nsec;
+#else
+   return 0;
+#endif
+}
+
+/* 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 pipe_thread_get_time_nano(pthread_self());
+#else
+   return 0;
+#endif
+}
+
 #endif /* OS_THREAD_H_ */
-- 
2.7.4



More information about the mesa-dev mailing list