From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id A41064569F for ; Wed, 19 Jul 2023 19:55:57 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 52C8668C61A; Wed, 19 Jul 2023 22:55:49 +0300 (EEST) Received: from ursule.remlab.net (vps-a2bccee9.vps.ovh.net [51.75.19.47]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6DD7E68C33E for ; Wed, 19 Jul 2023 22:55:41 +0300 (EEST) Received: from basile.remlab.net (localhost [IPv6:::1]) by ursule.remlab.net (Postfix) with ESMTP id 08C59C0214 for ; Wed, 19 Jul 2023 22:55:40 +0300 (EEST) From: =?UTF-8?q?R=C3=A9mi=20Denis-Courmont?= To: ffmpeg-devel@ffmpeg.org Date: Wed, 19 Jul 2023 22:55:36 +0300 Message-Id: <20230719195540.46961-2-remi@remlab.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <2113654.OBFZWjSADL@basile.remlab.net> References: <2113654.OBFZWjSADL@basile.remlab.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/6] checkasm: use pointers for start/stop functions X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Linux and MacOS kernel performance APIs are not always available. This introduces function pointers so that we can fall back to other timing functions (in later changesets). If AV_READ_TIME is the only configured timer, then this sticks to inline assembler since there will be nothing to fall back to (or from), and some people are concerned than an indirect function call is too much overhead. --- tests/checkasm/checkasm.c | 25 +++++++++++++++++++++++-- tests/checkasm/checkasm.h | 24 ++++++------------------ 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/tests/checkasm/checkasm.c b/tests/checkasm/checkasm.c index 63141e1f7a..933d85bac3 100644 --- a/tests/checkasm/checkasm.c +++ b/tests/checkasm/checkasm.c @@ -57,6 +57,14 @@ #if HAVE_UNISTD_H #include #endif +#if CONFIG_LINUX_PERF +#include +#include +#include +#endif +#if CONFIG_MACOS_KPERF +#include "libavutil/macos_kperf.h" +#endif #if !HAVE_ISATTY #define isatty(fd) 1 @@ -313,6 +321,8 @@ static struct { /* perf */ int nop_time; int sysfd; + uint64_t (*start)(void); + uint64_t (*stop)(void); int cpu_flag; const char *cpu_flag_name; @@ -513,6 +523,12 @@ static int measure_nop_time(void) uint16_t nops[10000]; int i, nop_sum = 0; av_unused const int sysfd = state.sysfd; +#if CONFIG_LINUX_PERF || CONFIG_MACOS_KPERF + struct { + uint64_t (*start)(void); + uint64_t (*stop)(void); + } p = { state.start, state.stop }, *perf = &p; +#endif for (i = 0; i < 10000; i++) { uint64_t t = checkasm_bench_start(); @@ -650,7 +666,7 @@ static void print_cpu_name(void) } #if CONFIG_LINUX_PERF -uint64_t checkasm_bench_linux_perf_start(void) +static uint64_t checkasm_bench_linux_perf_start(void) { int fd = state.sysfd; @@ -659,7 +675,7 @@ uint64_t checkasm_bench_linux_perf_start(void) return 0; } -uint64_t checkasm_bench_linux_perf_stop(void) +static uint64_t checkasm_bench_linux_perf_stop(void) { uint64_t t; int fd = state.sysfd; @@ -686,12 +702,15 @@ static int bench_init_linux(void) perror("syscall"); return -1; } + state.start = checkasm_bench_linux_perf_start; + state.stop = checkasm_bench_linux_perf_stop; return 0; } #elif CONFIG_MACOS_KPERF static int bench_init_kperf(void) { ff_kperf_init(); + state.start = state.stop = ff_kperf_cycles; return 0; } #else @@ -882,6 +901,8 @@ CheckasmPerf *checkasm_get_perf_context(void) CheckasmPerf *perf = &state.current_func_ver->perf; memset(perf, 0, sizeof(*perf)); perf->sysfd = state.sysfd; + perf->start = state.start; + perf->stop = state.stop; return perf; } diff --git a/tests/checkasm/checkasm.h b/tests/checkasm/checkasm.h index 8a62b98f3e..3b3a1ab35b 100644 --- a/tests/checkasm/checkasm.h +++ b/tests/checkasm/checkasm.h @@ -26,15 +26,6 @@ #include #include "config.h" -#if CONFIG_LINUX_PERF -#include // read(3) -#include -#include -#include -#elif CONFIG_MACOS_KPERF -#include "libavutil/macos_kperf.h" -#endif - #include "libavutil/avstring.h" #include "libavutil/cpu.h" #include "libavutil/internal.h" @@ -236,16 +227,13 @@ typedef struct CheckasmPerf { int sysfd; uint64_t cycles; int iterations; + uint64_t (*start)(void); + uint64_t (*stop)(void); } CheckasmPerf; -#if CONFIG_LINUX_PERF -uint64_t checkasm_bench_linux_perf_start(void); -uint64_t checkasm_bench_linux_perf_stop(void); -#define checkasm_bench_start() checkasm_bench_linux_perf_start() -#define checkasm_bench_stop() checkasm_bench_linux_perf_stop() -#elif CONFIG_MACOS_KPERF -#define checkasm_bench_start() ff_kperf_cycles() -#define checkasm_bench_stop() ff_kperf_cycles() +#if CONFIG_LINUX_PERF || CONFIG_MACOS_KPERF +#define checkasm_bench_start() (perf->start)() +#define checkasm_bench_stop() (perf->stop)() #elif defined (AV_READ_TIME) #define checkasm_bench_start() AV_READ_TIME() #define checkasm_bench_stop() AV_READ_TIME() @@ -258,7 +246,7 @@ uint64_t checkasm_bench_linux_perf_stop(void); #define bench_new(...)\ do {\ if (checkasm_bench_func()) {\ - struct CheckasmPerf *perf = checkasm_get_perf_context();\ + struct CheckasmPerf *restrict perf = checkasm_get_perf_context();\ av_unused const int sysfd = perf->sysfd;\ func_type *tfunc = func_new;\ uint64_t tsum = 0;\ -- 2.40.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".