gallium/os: add per-thread time clock queries
authorMarek Olšák <marek.olsak@amd.com>
Sat, 11 Feb 2017 19:48:13 +0000 (20:48 +0100)
committerMarek Olšák <marek.olsak@amd.com>
Tue, 14 Feb 2017 20:47:51 +0000 (21:47 +0100)
Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
src/gallium/auxiliary/os/os_thread.h

index 21faf4b3beb611405a4d99c08479246a8dee43ae..0caf955b89f24a8d6ae6a448d7e4476885e0c0ce 100644 (file)
@@ -335,4 +335,35 @@ pipe_tsd_set(pipe_tsd *tsd, void *value)
 
 
 
+/*
+ * 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_ */