From patchwork Fri Jul 14 18:28:32 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: 42684 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6da1:b0:131:a7d0:bc6d with SMTP id gl33csp3863490pzb; Fri, 14 Jul 2023 11:29:10 -0700 (PDT) X-Google-Smtp-Source: APBJJlGSKrFtlDtAqQdDv09chWXV0Noflng3NpB+KkEw/0pUwLcAXDoVNCe5jd8TUTTuAYm4tdco X-Received: by 2002:a17:906:6492:b0:973:d06d:545f with SMTP id e18-20020a170906649200b00973d06d545fmr4706262ejm.24.1689359349947; Fri, 14 Jul 2023 11:29:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689359349; cv=none; d=google.com; s=arc-20160816; b=ogk1YxFPGHkzCzt4DjzQzvd9J0uHBucy14laYtQkFYM3hgm/oJwrr0/lOuuQw/vOXI D3GNDbUEWG/KqfaE61Dg0uD9W5rd2YojiPSN4oghi1vWC6ddALzRU5/Xa+8GE2ga5ZUQ xP0E1xrN+lFF8O+WoxrWJnslMXsQWuyIpCcg/Vsnz8lwxbPrG3riPys2spmzdbXXWTRx +eP69PTM9KIvn8qWTJ8TE9exr+06mGdqin6rorkvnqYLbRJLNCTRLmaLvnyXjVDVKNIj m+jhl20fwciCY4rlOeN5D9lrStD0xj3fc3vB1vcqmbzxbBxWRThtbzf4xpslxPsB/Xr/ 2zHg== 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=PPrGpiQy+wyrBvYldZ79u/iJQaTdbbCDPPr7F59fa5I=; fh=hQcp50obTJ8bXC1it5NuEN23RGKfx0/zZ3s2gmreL+A=; b=BY2HFdNZ+5LO+RBnn2lLjnM0EZYAhlmzjGtpoXsICkthx9kJyrujZjp7W/Jdsnssea 65xaDZtqg+kXtJrxgyAMwK7bEKN/y1N+9En6E+zizIWctSEo3HG14LUDvWkyKkIpDkfD Rl284FKUxi9ezxAr8zRqpH5WgbWO26a61gn7Hopod8z7FQIXadzrzWu3KftfEplZ6/Sn ZYJuyZ8sSJSCzS7Av/aG3Ykob9LmbfKzzGfHsAqljSD01IT1mILVdfxGH80Fb9Moy5WT u3RpXYt9Q3d+/y4z07CCpUSj5gEvbuCcLTiTS9XaTr13ZxlQEufkoYq3xavA5IyA17GB lzFQ== 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 gh7-20020a170906e08700b0099238b86ef1si9800643ejb.164.2023.07.14.11.29.09; Fri, 14 Jul 2023 11:29:09 -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 6011068C67C; Fri, 14 Jul 2023 21:28:46 +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 9EA7668C541 for ; Fri, 14 Jul 2023 21:28:36 +0300 (EEST) Received: from basile.remlab.net (localhost [IPv6:::1]) by ursule.remlab.net (Postfix) with ESMTP id 33458C0218 for ; Fri, 14 Jul 2023 21:28:36 +0300 (EEST) From: =?utf-8?q?R=C3=A9mi_Denis-Courmont?= To: ffmpeg-devel@ffmpeg.org Date: Fri, 14 Jul 2023 21:28:32 +0300 Message-Id: <20230714182835.66326-4-remi@remlab.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <12243004.O9o76ZdvQC@basile.remlab.net> References: <12243004.O9o76ZdvQC@basile.remlab.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 4/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: xcaOWi/UxpKx 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 | 31 ++++--------------------------- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/tests/checkasm/checkasm.c b/tests/checkasm/checkasm.c index 69a709175f..4b6164301a 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 @@ -508,6 +516,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) { @@ -651,7 +662,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; @@ -660,7 +671,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; @@ -687,24 +698,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 @@ -871,6 +892,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..4962815345 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,24 +227,10 @@ 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 {\ @@ -265,12 +242,12 @@ uint64_t checkasm_bench_linux_perf_stop(void); int ti, tcount = 0;\ uint64_t t = 0; \ for (ti = 0; ti < BENCH_RUNS; ti++) {\ - t = checkasm_bench_start(); \ + t = perf->start(); \ tfunc(__VA_ARGS__);\ tfunc(__VA_ARGS__);\ tfunc(__VA_ARGS__);\ tfunc(__VA_ARGS__);\ - t = checkasm_bench_stop() - t;\ + t = perf->stop() - t;\ if (t*tcount <= tsum*4 && ti > 0) {\ tsum += t;\ tcount++;\