1*3117ece4Schristos /* 2*3117ece4Schristos * Copyright (c) Meta Platforms, Inc. and affiliates. 3*3117ece4Schristos * All rights reserved. 4*3117ece4Schristos * 5*3117ece4Schristos * This source code is licensed under both the BSD-style license (found in the 6*3117ece4Schristos * LICENSE file in the root directory of this source tree) and the GPLv2 (found 7*3117ece4Schristos * in the COPYING file in the root directory of this source tree). 8*3117ece4Schristos * You may select, at your option, one of the above-listed licenses. 9*3117ece4Schristos */ 10*3117ece4Schristos 11*3117ece4Schristos #ifndef TIME_FN_H_MODULE_287987 12*3117ece4Schristos #define TIME_FN_H_MODULE_287987 13*3117ece4Schristos 14*3117ece4Schristos #if defined (__cplusplus) 15*3117ece4Schristos extern "C" { 16*3117ece4Schristos #endif 17*3117ece4Schristos 18*3117ece4Schristos 19*3117ece4Schristos 20*3117ece4Schristos /*-**************************************** 21*3117ece4Schristos * Types 22*3117ece4Schristos ******************************************/ 23*3117ece4Schristos 24*3117ece4Schristos #if !defined (__VMS) && (defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */) ) 25*3117ece4Schristos # if defined(_AIX) 26*3117ece4Schristos # include <inttypes.h> 27*3117ece4Schristos # else 28*3117ece4Schristos # include <stdint.h> /* uint64_t */ 29*3117ece4Schristos # endif 30*3117ece4Schristos typedef uint64_t PTime; /* Precise Time */ 31*3117ece4Schristos #else 32*3117ece4Schristos typedef unsigned long long PTime; /* does not support compilers without long long support */ 33*3117ece4Schristos #endif 34*3117ece4Schristos 35*3117ece4Schristos /* UTIL_time_t contains a nanosecond time counter. 36*3117ece4Schristos * The absolute value is not meaningful. 37*3117ece4Schristos * It's only valid to compute the difference between 2 measurements. */ 38*3117ece4Schristos typedef struct { PTime t; } UTIL_time_t; 39*3117ece4Schristos #define UTIL_TIME_INITIALIZER { 0 } 40*3117ece4Schristos 41*3117ece4Schristos 42*3117ece4Schristos /*-**************************************** 43*3117ece4Schristos * Time functions 44*3117ece4Schristos ******************************************/ 45*3117ece4Schristos 46*3117ece4Schristos UTIL_time_t UTIL_getTime(void); 47*3117ece4Schristos 48*3117ece4Schristos /* Timer resolution can be low on some platforms. 49*3117ece4Schristos * To improve accuracy, it's recommended to wait for a new tick 50*3117ece4Schristos * before starting benchmark measurements */ 51*3117ece4Schristos void UTIL_waitForNextTick(void); 52*3117ece4Schristos /* tells if timefn will return correct time measurements 53*3117ece4Schristos * in presence of multi-threaded workload. 54*3117ece4Schristos * note : this is not the case if only C90 clock_t measurements are available */ 55*3117ece4Schristos int UTIL_support_MT_measurements(void); 56*3117ece4Schristos 57*3117ece4Schristos PTime UTIL_getSpanTimeNano(UTIL_time_t clockStart, UTIL_time_t clockEnd); 58*3117ece4Schristos PTime UTIL_clockSpanNano(UTIL_time_t clockStart); 59*3117ece4Schristos 60*3117ece4Schristos PTime UTIL_getSpanTimeMicro(UTIL_time_t clockStart, UTIL_time_t clockEnd); 61*3117ece4Schristos PTime UTIL_clockSpanMicro(UTIL_time_t clockStart); 62*3117ece4Schristos 63*3117ece4Schristos #define SEC_TO_MICRO ((PTime)1000000) /* nb of microseconds in a second */ 64*3117ece4Schristos 65*3117ece4Schristos 66*3117ece4Schristos #if defined (__cplusplus) 67*3117ece4Schristos } 68*3117ece4Schristos #endif 69*3117ece4Schristos 70*3117ece4Schristos #endif /* TIME_FN_H_MODULE_287987 */ 71