diff options
author | Marek Olšák <[email protected]> | 2017-02-11 20:48:13 +0100 |
---|---|---|
committer | Marek Olšák <[email protected]> | 2017-02-14 21:47:51 +0100 |
commit | 6c61a8bfc6cb30e30b806a30f30c0e9b01b0d673 (patch) | |
tree | eb2c10395bf5469f48ec90b320bf1bc9226a2c76 /src | |
parent | 5d19b503af41b8ad3d0ca9e2a279dca7106403be (diff) |
gallium/os: add per-thread time clock queries
Reviewed-by: Nicolai Hähnle <[email protected]>
Diffstat (limited to 'src')
-rw-r--r-- | src/gallium/auxiliary/os/os_thread.h | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/gallium/auxiliary/os/os_thread.h b/src/gallium/auxiliary/os/os_thread.h index 21faf4b3beb..0caf955b89f 100644 --- a/src/gallium/auxiliary/os/os_thread.h +++ b/src/gallium/auxiliary/os/os_thread.h @@ -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_ */ |