diff --git a/platform/linux-generic/arch/common/odp/api/abi/time_cpu_inlines.h b/platform/linux-generic/arch/common/odp/api/abi/time_cpu_inlines.h index a3fa6af03f7..500e8385599 100644 --- a/platform/linux-generic/arch/common/odp/api/abi/time_cpu_inlines.h +++ b/platform/linux-generic/arch/common/odp/api/abi/time_cpu_inlines.h @@ -22,6 +22,10 @@ typedef struct _odp_time_global_t { uint64_t freq_hz; uint64_t start_time; uint64_t start_time_ns; + uint64_t mult_to_ns; + uint64_t mult_from_ns; + uint32_t shift_to_ns; + uint32_t shift_from_ns; } _odp_time_global_t; @@ -45,9 +49,14 @@ static inline odp_time_t _odp_time_cur_strict(void) static inline uint64_t _odp_time_to_ns(odp_time_t time) { + uint64_t count = time.count; + +#ifdef __SIZEOF_INT128__ + return (uint64_t)(((__uint128_t)count * _odp_time_glob.mult_to_ns) >> + _odp_time_glob.shift_to_ns); +#else uint64_t nsec; uint64_t freq_hz = _odp_time_glob.freq_hz; - uint64_t count = time.count; uint64_t sec = 0; if (count >= freq_hz) { @@ -58,12 +67,18 @@ static inline uint64_t _odp_time_to_ns(odp_time_t time) nsec = (_ODP_TIME_GIGA_HZ * count) / freq_hz; return (sec * _ODP_TIME_GIGA_HZ) + nsec; +#endif } static inline odp_time_t _odp_time_from_ns(uint64_t ns) { odp_time_t time; uint64_t count; + +#ifdef __SIZEOF_INT128__ + count = (uint64_t)(((__uint128_t)ns * _odp_time_glob.mult_from_ns) >> + _odp_time_glob.shift_from_ns); +#else uint64_t freq_hz = _odp_time_glob.freq_hz; uint64_t sec = 0; @@ -74,7 +89,7 @@ static inline odp_time_t _odp_time_from_ns(uint64_t ns) count = sec * freq_hz; count += (ns * freq_hz) / ODP_TIME_SEC_IN_NS; - +#endif time.count = count; return time; diff --git a/platform/linux-generic/arch/common/odp_time_cpu.c b/platform/linux-generic/arch/common/odp_time_cpu.c index 6416f55756d..33216d990f6 100644 --- a/platform/linux-generic/arch/common/odp_time_cpu.c +++ b/platform/linux-generic/arch/common/odp_time_cpu.c @@ -40,6 +40,25 @@ int _odp_time_init_global(void) _ODP_PRINT("HW time counter freq: %" PRIu64 " hz\n\n", global->freq_hz); +#ifdef __SIZEOF_INT128__ + /* Find the maximum shift for which the multiplier fits into 64 bits */ + for (global->shift_to_ns = 63; global->shift_to_ns > 0; global->shift_to_ns--) { + if ((((__uint128_t)_ODP_TIME_GIGA_HZ << global->shift_to_ns) / + global->freq_hz) <= UINT64_MAX) + break; + } + global->mult_to_ns = (uint64_t)(((__uint128_t)_ODP_TIME_GIGA_HZ << global->shift_to_ns) / + global->freq_hz); + + for (global->shift_from_ns = 63; global->shift_from_ns > 0; global->shift_from_ns--) { + if ((((__uint128_t)global->freq_hz << global->shift_from_ns) / + ODP_TIME_SEC_IN_NS) <= UINT64_MAX) + break; + } + global->mult_from_ns = (uint64_t)(((__uint128_t)global->freq_hz << global->shift_from_ns) / + ODP_TIME_SEC_IN_NS); +#endif + count = _odp_time_cpu_global(); time.count = count; global->start_time = count; diff --git a/test/performance/odp_ml_perf.c b/test/performance/odp_ml_perf.c index 70b049655b8..52b2f7f2e88 100644 --- a/test/performance/odp_ml_perf.c +++ b/test/performance/odp_ml_perf.c @@ -282,6 +282,11 @@ static int parse_args(int argc, char *argv[]) exit(EXIT_FAILURE); } + if (glb->opt.warmup < 0) { + ODPH_ERR("Invalid number of warmup rounds: %d\n", glb->opt.warmup); + exit(EXIT_FAILURE); + } + printf("Options:\n"); printf("--------\n"); printf("model_name: %s\n", glb->opt.model_name); @@ -456,7 +461,7 @@ static void dequantize_output(uint8_t *out_d_addr, uint8_t *out_q_addr) static int test_ml(void *ptr) { - odp_time_t time; + odp_time_t time = ODP_TIME_NULL; odp_ml_data_seg_t inp_seg[MAX_IO]; uint8_t *inp_addr; odp_ml_data_seg_t out_seg[MAX_IO]; @@ -588,7 +593,7 @@ static int test_ml(void *ptr) static int test_ml_create(void *ptr) { - odp_time_t time; + odp_time_t time = ODP_TIME_NULL; int thread_idx = (int)(uintptr_t)ptr; odp_ml_model_t mdl; odp_ml_model_param_t model_param; @@ -630,7 +635,7 @@ static int test_ml_create(void *ptr) static int test_ml_load(void *ptr) { - odp_time_t time; + odp_time_t time = ODP_TIME_NULL; int thread_idx = (int)(uintptr_t)ptr; odp_ml_model_t mdl; odp_ml_model_param_t model_param;