From 176f19781825d77ae1cfe81b3afe5e7afe66f2b8 Mon Sep 17 00:00:00 2001 From: Xiang Li Date: Tue, 10 Sep 2024 12:09:50 -0400 Subject: [PATCH 1/3] [Build] use timespec_get to get current time Replace clock_gettime with timespec_get which works on Windows as well. For #4661 --- extension/llm/runner/util.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extension/llm/runner/util.h b/extension/llm/runner/util.h index d6ab23827f9..efc39b83972 100644 --- a/extension/llm/runner/util.h +++ b/extension/llm/runner/util.h @@ -68,7 +68,7 @@ ET_EXPERIMENTAL void inline safe_printf(const char* piece) { ET_EXPERIMENTAL long inline time_in_ms() { // return time in milliseconds, for benchmarking the model speed struct timespec time; - clock_gettime(CLOCK_REALTIME, &time); + timespec_get(&time, TIME_UTC); return time.tv_sec * 1000 + time.tv_nsec / 1000000; } From d48882b89aa779cfcdf51f06a1bca1c9d9fff22f Mon Sep 17 00:00:00 2001 From: Xiang Li Date: Sat, 22 Mar 2025 18:37:04 -0400 Subject: [PATCH 2/3] Not using timespec_get on android api level < 29 --- extension/llm/runner/util.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/extension/llm/runner/util.h b/extension/llm/runner/util.h index efc39b83972..67530a7b730 100644 --- a/extension/llm/runner/util.h +++ b/extension/llm/runner/util.h @@ -68,7 +68,13 @@ ET_EXPERIMENTAL void inline safe_printf(const char* piece) { ET_EXPERIMENTAL long inline time_in_ms() { // return time in milliseconds, for benchmarking the model speed struct timespec time; + // The `timespec_get` function is only available on Android API levels + // above 29. +#if defined(__ANDROID_API__) && __ANDROID_API__ < 29 + clock_gettime(CLOCK_REALTIME, &time); +#else timespec_get(&time, TIME_UTC); +#endif return time.tv_sec * 1000 + time.tv_nsec / 1000000; } From 5b166f1e4aac05881831007132cbb4fd784e08ca Mon Sep 17 00:00:00 2001 From: Xiang Li Date: Tue, 25 Mar 2025 10:46:31 -0400 Subject: [PATCH 3/3] Fix comment. --- extension/llm/runner/util.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extension/llm/runner/util.h b/extension/llm/runner/util.h index 67530a7b730..f7b48433cfb 100644 --- a/extension/llm/runner/util.h +++ b/extension/llm/runner/util.h @@ -69,7 +69,7 @@ ET_EXPERIMENTAL long inline time_in_ms() { // return time in milliseconds, for benchmarking the model speed struct timespec time; // The `timespec_get` function is only available on Android API levels - // above 29. + // 29 or later. #if defined(__ANDROID_API__) && __ANDROID_API__ < 29 clock_gettime(CLOCK_REALTIME, &time); #else