e576bb2002-10-11Martin Nilsson /* || This file is part of Pike. For copyright information see COPYRIGHT. || Pike is distributed under GPL, LGPL and MPL. See the file COPYING || for more information. */
24ddc71998-03-28Henrik Grubbström (Grubba) 
66bcf02002-12-07Henrik Grubbström (Grubba) #ifndef PIKE_RUSAGE_H #define PIKE_RUSAGE_H
5267b71995-08-09Fredrik Hübinette (Hubbe) 
247f732007-06-10Martin Stjernholm #include "global.h" #include <time.h>
fcca612016-02-11Martin Nilsson #ifdef _POSIX_TIMERS
247f732007-06-10Martin Stjernholm #if _POSIX_TIMERS > 0 #ifdef _POSIX_THREAD_CPUTIME # if _POSIX_THREAD_CPUTIME != -1 # if _POSIX_THREAD_CPUTIME != 0 /* Know it to be available at compile time. */ # define HAVE_POSIX_THREAD_GCT # else /* Might be available at run time - have to check with sysconf(3). */ # endif # define MIGHT_HAVE_POSIX_THREAD_GCT # endif
fcca612016-02-11Martin Nilsson #endif /* _POSIX_THREAD_CPUTIME */
247f732007-06-10Martin Stjernholm  #ifdef _POSIX_CPUTIME # if _POSIX_CPUTIME != -1 # if _POSIX_CPUTIME != 0 # define HAVE_POSIX_PROCESS_GCT # endif # define MIGHT_HAVE_POSIX_PROCESS_GCT # endif
fcca612016-02-11Martin Nilsson #endif /* _POSIX_CPUTIME */
247f732007-06-10Martin Stjernholm  #ifdef _POSIX_MONOTONIC_CLOCK # if _POSIX_MONOTONIC_CLOCK != -1 # if _POSIX_MONOTONIC_CLOCK != 0 # define HAVE_POSIX_MONOTONIC_GRT # endif # define MIGHT_HAVE_POSIX_MONOTONIC_GRT # endif
fcca612016-02-11Martin Nilsson #endif /* _POSIX_MONOTONIC_CLOCK */
247f732007-06-10Martin Stjernholm  /* The POSIX CLOCK_REALTIME clock is guaranteed to exist if * _POSIX_TIMERS exist. */ #define HAVE_POSIX_REALTIME_GRT #define MIGHT_HAVE_POSIX_REALTIME_GRT #endif /* _POSIX_TIMERS > 0 */ #endif /* _POSIX_TIMERS */ #ifdef CONFIGURE_TEST_FALLBACK_GCT /* In the configure test that tries to figure out whether the fallback * get_cpu_time is thread local or not. */
c994cd2007-06-11Martin Stjernholm # define cpu_time_is_thread_local -1 # define fallback_gct_impl get_cpu_time_impl
247f732007-06-10Martin Stjernholm # define fallback_gct get_cpu_time
c994cd2007-06-11Martin Stjernholm # define fallback_gct_res get_cpu_time_res
247f732007-06-10Martin Stjernholm # define GCT_IS_FALLBACK #else /* Choose get_cpu_time implementation. Prefer one with thread local time. */ # ifdef HAVE_POSIX_THREAD_GCT # define cpu_time_is_thread_local 1 # define posix_thread_gct_impl get_cpu_time_impl # define posix_thread_gct get_cpu_time # define posix_thread_gct_res get_cpu_time_res # define GCT_IS_POSIX_THREAD
63f9e92009-11-17Martin Stjernholm # elif defined (MIGHT_HAVE_POSIX_THREAD_GCT) # define GCT_RUNTIME_CHOICE
247f732007-06-10Martin Stjernholm # elif FB_CPU_TIME_IS_THREAD_LOCAL == PIKE_YES # define cpu_time_is_thread_local 1 # define fallback_gct_impl get_cpu_time_impl # define fallback_gct get_cpu_time # define fallback_gct_res get_cpu_time_res # define GCT_IS_FALLBACK # elif defined (HAVE_POSIX_PROCESS_GCT) # define cpu_time_is_thread_local 0 # define posix_process_gct_impl get_cpu_time_impl # define posix_process_gct get_cpu_time # define posix_process_gct_res get_cpu_time_res # define GCT_IS_POSIX_PROCESS # elif defined (MIGHT_HAVE_POSIX_PROCESS_GCT) # define GCT_RUNTIME_CHOICE # else # define cpu_time_is_thread_local 0 # define fallback_gct_impl get_cpu_time_impl # define fallback_gct get_cpu_time # define fallback_gct_res get_cpu_time_res # define GCT_IS_FALLBACK # endif #ifdef GCT_RUNTIME_CHOICE # define CPU_TIME_MIGHT_BE_THREAD_LOCAL # define CPU_TIME_MIGHT_NOT_BE_THREAD_LOCAL #elif cpu_time_is_thread_local == 1 # define CPU_TIME_MIGHT_BE_THREAD_LOCAL #else # define CPU_TIME_MIGHT_NOT_BE_THREAD_LOCAL #endif
e8adf52007-06-19Martin Stjernholm /* Always consider cpu time as not thread local if we're compiling * without thread support. */ #ifndef PIKE_THREADS # undef cpu_time_is_thread_local # define cpu_time_is_thread_local 0 # undef CPU_TIME_MIGHT_BE_THREAD_LOCAL # ifndef CPU_TIME_MIGHT_NOT_BE_THREAD_LOCAL # define CPU_TIME_MIGHT_NOT_BE_THREAD_LOCAL # endif #endif
247f732007-06-10Martin Stjernholm #endif /* !CONFIGURE_TEST_FALLBACK_GCT */ /* Choose get_real_time implementation. Prefer one that isn't affected * by wall clock adjustments. */ #ifdef HAVE_POSIX_MONOTONIC_GRT # define real_time_is_monotonic 1 # define posix_monotonic_grt_impl get_real_time_impl # define posix_monotonic_grt get_real_time # define posix_monotonic_grt_res get_real_time_res # define GRT_IS_POSIX_MONOTONIC #elif defined (MIGHT_HAVE_POSIX_MONOTONIC_GRT) # define GRT_RUNTIME_CHOICE
637c072009-04-21Martin Stjernholm #elif defined (HAVE_HOST_GET_CLOCK_SERVICE)
8adf2b2009-04-21Martin Stjernholm /* Define this to avoid special cases in init_rusage. */
637c072009-04-21Martin Stjernholm # define GRT_RUNTIME_CHOICE
247f732007-06-10Martin Stjernholm #elif defined (HAVE_POSIX_REALTIME_GRT) # define real_time_is_monotonic 0 # define posix_realtime_grt_impl get_real_time_impl # define posix_realtime_grt get_real_time # define posix_realtime_grt_res get_real_time_res # define GRT_IS_POSIX_REALTIME #else # define fallback_grt_is_monotonic real_time_is_monotonic # define fallback_grt_impl get_real_time_impl # define fallback_grt get_real_time # define fallback_grt_res get_real_time_res # define GRT_IS_FALLBACK #endif
fde6ed2003-11-27Martin Stjernholm #ifdef HAVE_TIMES extern long pike_clk_tck; #endif
5267b71995-08-09Fredrik Hübinette (Hubbe) /* Prototypes begin here */
5ef9052003-01-13Martin Stjernholm typedef long pike_rusage_t[29];
247f732007-06-10Martin Stjernholm PMOD_EXPORT int pike_get_rusage(pike_rusage_t rusage_values);
5ef9052003-01-13Martin Stjernholm long *low_rusage(void); /* get_cpu_time returns the consumed cpu time (both in kernel and user
247f732007-06-10Martin Stjernholm  * space, if applicable), or -1 if it couldn't be read. Note that many * systems have fairly poor resolution. gettimeofday can therefore be * a better choice to measure small time intervals. */
9a70222016-02-11Martin Nilsson 
f70a532003-01-13Martin Stjernholm /* The time is returned in nanoseconds. */
616c2d2003-01-13Martin Stjernholm typedef INT64 cpu_time_t;
5ef9052003-01-13Martin Stjernholm #define LONG_CPU_TIME
6ce0a22008-01-08Henrik Grubbström (Grubba) #define CPU_TIME_TICKS_LOW /* per second */ (1000000000L)
5ef9052003-01-13Martin Stjernholm #define CPU_TIME_UNIT "ns"
50f4492003-02-14Martin Stjernholm #define PRINT_CPU_TIME PRINTINT64 "d"
9a70222016-02-11Martin Nilsson 
6ce0a22008-01-08Henrik Grubbström (Grubba) #define CPU_TIME_TICKS /* per second */ ((cpu_time_t)CPU_TIME_TICKS_LOW)
247f732007-06-10Martin Stjernholm  #ifdef GCT_RUNTIME_CHOICE
e8adf52007-06-19Martin Stjernholm #ifndef cpu_time_is_thread_local
247f732007-06-10Martin Stjernholm PMOD_EXPORT extern int cpu_time_is_thread_local;
e8adf52007-06-19Martin Stjernholm #endif
247f732007-06-10Martin Stjernholm PMOD_EXPORT extern const char *get_cpu_time_impl; PMOD_EXPORT extern cpu_time_t (*get_cpu_time) (void); PMOD_EXPORT extern cpu_time_t (*get_cpu_time_res) (void); #else PMOD_EXPORT extern const char get_cpu_time_impl[]; PMOD_EXPORT cpu_time_t get_cpu_time (void); PMOD_EXPORT cpu_time_t get_cpu_time_res (void); #endif #ifdef GRT_RUNTIME_CHOICE PMOD_EXPORT extern int real_time_is_monotonic; PMOD_EXPORT extern const char *get_real_time_impl; PMOD_EXPORT extern cpu_time_t (*get_real_time) (void); PMOD_EXPORT extern cpu_time_t (*get_real_time_res) (void); #else #ifdef GRT_IS_FALLBACK PMOD_EXPORT extern int real_time_is_monotonic; #endif PMOD_EXPORT extern const char get_real_time_impl[]; PMOD_EXPORT cpu_time_t get_real_time(void); PMOD_EXPORT cpu_time_t get_real_time_res (void); #endif
5ef9052003-01-13Martin Stjernholm  INT32 internal_rusage(void); /* For compatibility. */
6a118c2002-09-13Martin Stjernholm #if defined(PIKE_DEBUG) || defined(INTERNAL_PROFILING) void debug_print_rusage(FILE *out); #endif
247f732007-06-10Martin Stjernholm  void init_rusage (void);
5267b71995-08-09Fredrik Hübinette (Hubbe) /* Prototypes end here */
66bcf02002-12-07Henrik Grubbström (Grubba) #endif /* !PIKE_RUSAGE_H */