[Mesa-dev] [PATCH 1/2] gallium/os: Add CPU time functions

Jonathan Gray jsg at jsg.id.au
Fri Feb 19 03:16:33 UTC 2016


On Fri, Feb 19, 2016 at 12:59:18AM +0100, Bas Nieuwenhuizen wrote:
> Adds functions to query the elapsed CPU time of the current process
> or thread. Implements Linux support only.
> 
> To be used by the gallium HUD.

Wouldn't this be better gated by a configure test?

clock_gettime(2) is documented to support CLOCK_PROCESS_CPUTIME_ID
on OpenBSD for example:

http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man2/clock_getres.2?query=clock_gettime

> 
> Signed-off-by: Bas Nieuwenhuizen <bas at basnieuwenhuizen.nl>
> ---
>  src/gallium/auxiliary/os/os_time.c | 48 ++++++++++++++++++++++++++++++++++++++
>  src/gallium/auxiliary/os/os_time.h | 18 ++++++++++++++
>  2 files changed, 66 insertions(+)
> 
> diff --git a/src/gallium/auxiliary/os/os_time.c b/src/gallium/auxiliary/os/os_time.c
> index 3d2e416..e186f42 100644
> --- a/src/gallium/auxiliary/os/os_time.c
> +++ b/src/gallium/auxiliary/os/os_time.c
> @@ -80,6 +80,54 @@ os_time_get_nano(void)
>  #endif
>  }
>  
> +bool
> +os_cpu_time_supported(void)
> +{
> +#if defined(PIPE_OS_LINUX)
> +
> +   return true;
> +
> +#else
> +
> +   return false;
> +
> +#endif
> +}
> +
> +int64_t
> +os_process_time_get_nano(void)
> +{
> +#if defined(PIPE_OS_LINUX)
> +
> +   struct timespec tv;
> +   clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &tv);
> +   return tv.tv_nsec + tv.tv_sec*INT64_C(1000000000);
> +
> +#else
> +
> +   assert(0 && "os_process_time_get_nano is not implemented on this platform");
> +   return 0;
> +
> +#endif
> +}
> +
> +int64_t
> +os_thread_time_get_nano(void)
> +{
> +#if defined(PIPE_OS_LINUX)
> +
> +   struct timespec tv;
> +   clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tv);
> +   return tv.tv_nsec + tv.tv_sec*INT64_C(1000000000);
> +
> +#else
> +
> +   assert(0 && "os_thread_time_get_nano is not implemented on this platform");
> +   return 0;
> +
> +#endif
> +}
> +
>  
>  #if defined(PIPE_SUBSYSTEM_WINDOWS_USER)
>  
> diff --git a/src/gallium/auxiliary/os/os_time.h b/src/gallium/auxiliary/os/os_time.h
> index 9312e02..8eaca59 100644
> --- a/src/gallium/auxiliary/os/os_time.h
> +++ b/src/gallium/auxiliary/os/os_time.h
> @@ -66,6 +66,24 @@ os_time_get(void)
>     return os_time_get_nano() / 1000;
>  }
>  
> +/*
> + * Returns whether os_process_time_get_nano and os_thread_time_get_nano are
> + * supported.
> + */
> +bool
> +os_cpu_time_supported(void);
> +
> +/*
> + * Get the CPU time spent in the current process.
> + */
> +int64_t
> +os_process_time_get_nano(void);
> +
> +/*
> + * Get the CPUtime spent in the current thread.
> + */
> +int64_t
> +os_thread_time_get_nano(void);
>  
>  /*
>   * Sleep.
> -- 
> 2.7.1
> 
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev


More information about the mesa-dev mailing list