From patchwork Sat Jul 15 15:23:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?R=C3=A9mi_Denis-Courmont?= X-Patchwork-Id: 42740 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6da1:b0:131:a7d0:bc6d with SMTP id gl33csp4376321pzb; Sat, 15 Jul 2023 08:24:06 -0700 (PDT) X-Google-Smtp-Source: APBJJlGqJM3PDivr8mfj6OLKFXFtyx19cnAu8KmthG82lxr4ZgcbhJzQ5OWWTdz0XoTa3/zbJd8V X-Received: by 2002:a05:600c:da:b0:3f7:f584:5796 with SMTP id u26-20020a05600c00da00b003f7f5845796mr7249755wmm.2.1689434646421; Sat, 15 Jul 2023 08:24:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689434646; cv=none; d=google.com; s=arc-20160816; b=E4WLbCxaFdGrVsCau5wo7M9X/MlCiEtQQnuuD76ULv8LyxVLyg3J4879WKeXWjWqm4 gAeXaVrRnhoeuXo15/sSOhQ4k4toIAracKJBzSbfiAOl8cnZj6i46JG+hw+TwrJaSfIa bEjD25w/fq+b7uq0iVnzP5r3LpWCrXExNp6RXQevhPOrNORluFu6yKAj/S5LdTagk7fn cqqrEgP10OEP3ViDxTPiORa//knyP89RRKsodW3qhTcI8FC75jHbNKaXRKppKouzEcaY FgnZpH0pSir6B1n8yv9u3TeydYdD4P1lAxKXJRMOBIfpyOxVZdB2ppqnCia8l3pt3heY vWug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=XcVMEWnRCIk6mHyTBKblHUf2AM0TYGLDknZQ+AfK2NE=; fh=hQcp50obTJ8bXC1it5NuEN23RGKfx0/zZ3s2gmreL+A=; b=OKt7ALF2WViSj0gkIh0M1LDzg4scS+y4764b6aQCfPEpuKEbMRS1Elo9kKtZ9km3xx Bt0B97JMShwtPjQCw4jqiKJXv9sgBev/BmeDrmiTv+/f++dYzzSXH7vRJS9f4KsVP40U FO/zfzr3CibHnlpLcv8XG0cdB0x5DkKcgHMCPl+E8UQiuv5xMA3bwXjfAmQ4j1H30Bdx ykFDxXv6lHElMgzQ21MgxhpQqSitbKUQvwkPksry7BIABv6diwIsMmIJLZshAv1/xU+G u7VDJe+HhmGyvfZTKvzPoWMmxjWjF0b2ze3HnDyHDtzPYiyKX+acVl812ILuibl0GVOe iPPg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id ox29-20020a170907101d00b00988f21df36esi2986763ejb.594.2023.07.15.08.24.05; Sat, 15 Jul 2023 08:24:06 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9EE0368C1FF; Sat, 15 Jul 2023 18:23:48 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from ursule.remlab.net (vps-a2bccee9.vps.ovh.net [51.75.19.47]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D7D0868C2C7 for ; Sat, 15 Jul 2023 18:23:40 +0300 (EEST) Received: from basile.remlab.net (localhost [IPv6:::1]) by ursule.remlab.net (Postfix) with ESMTP id 6DCC2C0217 for ; Sat, 15 Jul 2023 18:23:40 +0300 (EEST) From: =?utf-8?q?R=C3=A9mi_Denis-Courmont?= To: ffmpeg-devel@ffmpeg.org Date: Sat, 15 Jul 2023 18:23:35 +0300 Message-Id: <20230715152339.13234-3-remi@remlab.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <2708777.0sFzvF9Jai@basile.remlab.net> References: <2708777.0sFzvF9Jai@basile.remlab.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/7] 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: MA1WqidvmrRN This makes all calls to the bench start and stop functions via function pointers. While the primary goal is to support run-time selection of the performance measurement back-end in later commits, this has the side benefit of containing platform dependencies in to checkasm.c and out of checkasm.h. --- tests/checkasm/checkasm.c | 33 ++++++++++++++++++++++++++++----- tests/checkasm/checkasm.h | 33 ++++++--------------------------- 2 files changed, 34 insertions(+), 32 deletions(-) diff --git a/tests/checkasm/checkasm.c b/tests/checkasm/checkasm.c index d8f571f301..e921257257 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 @@ -506,6 +514,9 @@ static int cmp_nop(const void *a, const void *b) return *(const uint16_t*)a - *(const uint16_t*)b; } +static uint64_t (*checkasm_bench_start)(void); +static uint64_t (*checkasm_bench_stop)(void); + /* Measure the overhead of the timing code (in decicycles) */ static int measure_nop_time(void) { @@ -649,7 +660,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; @@ -658,7 +669,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; @@ -685,24 +696,34 @@ static int bench_init_linux(void) perror("perf_event_open"); return -1; } + checkasm_bench_start = checkasm_bench_linux_perf_start; + checkasm_bench_stop = checkasm_bench_linux_perf_stop; return 0; } #elif CONFIG_MACOS_KPERF static int bench_init_kperf(void) { ff_kperf_init(); + checkasm_bench_start = checkasm_bench_stop = ff_kperf_cycles; return 0; } -#else +#elif defined (AV_READ_TIME) +static uint64_t ff_read_time(void) +{ + return AV_READ_TIME(); +} + static int bench_init_ffmpeg(void) { -#ifdef AV_READ_TIME printf("benchmarking with native FFmpeg timers\n"); + checkasm_bench_start = checkasm_bench_stop = ff_read_time; return 0; +} #else +static int bench_init_ffmpeg(void) +{ fprintf(stderr, "checkasm: --bench is not supported on your system\n"); return -1; -#endif } #endif @@ -869,6 +890,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 = checkasm_bench_start; + perf->stop = checkasm_bench_start; return perf; } diff --git a/tests/checkasm/checkasm.h b/tests/checkasm/checkasm.h index 8a62b98f3e..8f966f49af 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,41 +227,29 @@ 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() -#elif defined (AV_READ_TIME) -#define checkasm_bench_start() AV_READ_TIME() -#define checkasm_bench_stop() AV_READ_TIME() -#else -#define checkasm_bench_start() UINT64_C(0) -#define checkasm_bench_stop() UINT64_C(0) -#endif - /* Benchmark the function */ #define bench_new(...)\ do {\ if (checkasm_bench_func()) {\ struct CheckasmPerf *perf = checkasm_get_perf_context();\ av_unused const int sysfd = perf->sysfd;\ + uint64_t (*const start)(void) = perf->start;\ + uint64_t (*const stop)(void) = perf->stop;\ func_type *tfunc = func_new;\ uint64_t tsum = 0;\ int ti, tcount = 0;\ uint64_t t = 0; \ for (ti = 0; ti < BENCH_RUNS; ti++) {\ - t = checkasm_bench_start(); \ + t = start(); \ tfunc(__VA_ARGS__);\ tfunc(__VA_ARGS__);\ tfunc(__VA_ARGS__);\ tfunc(__VA_ARGS__);\ - t = checkasm_bench_stop() - t;\ + t = stop() - t;\ if (t*tcount <= tsum*4 && ti > 0) {\ tsum += t;\ tcount++;\