From patchwork Fri Jul 14 18:28:31 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: 42683 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6da1:b0:131:a7d0:bc6d with SMTP id gl33csp3863423pzb; Fri, 14 Jul 2023 11:29:01 -0700 (PDT) X-Google-Smtp-Source: APBJJlF1eI4r9gDmzhSZf3RMQleuTDENrbsI6XkL2RbaXNiZxy7DML/Xr1bQWd0gwjxWhKk9wt5U X-Received: by 2002:aa7:c1d4:0:b0:51e:2492:3202 with SMTP id d20-20020aa7c1d4000000b0051e24923202mr5897431edp.33.1689359341330; Fri, 14 Jul 2023 11:29:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689359341; cv=none; d=google.com; s=arc-20160816; b=t6o1iWCnv2/mhHuFcbN9jrsLI4d3Wn/uFOx39MwF8LdfY2PqsTEP281eZ84Wbr7M78 WmFmiEf/DP9v09OdoDYmvduktO3Yff2Jt3cQp3QApr3T0folMd4/Gqtjihjxmnw04uIX bL8kQZC10Wc8CtHOpCr1zjfF1bN8yOh9xtezEGtEN1GQHz6I0ikNCrT4sk+gArTFMMas 1+u+NMlwytsB0xdGuTi5u2zIs7iQxES+Esxgf0Er/Qn12XQMTFB5yskhUHOvXp2ggXVm xsqd26L5qrghGhYaD+nhP66po97GGnBihkoedkYoXuEvE1GEaMwtJI1lD1BtbnBuvToY m5Bg== 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=3funrLvu9KfuuQ3pEPB/UiBeb22p00s7D/8OJ0mMtpo=; fh=hQcp50obTJ8bXC1it5NuEN23RGKfx0/zZ3s2gmreL+A=; b=x4SpFL3N3njUXA8D45SyJEC6Dhl8TKUqjYGCgkDI7YUdegr4ulCyAMC8S6ik3ySbkt iQI4UE3b7R3eEj0Y2PSpjrpxaQxXOfVM7mfQXYVcEGR5BUxl8nH1YQk1LnopI3YrFASE L43HGJyHP3Z5DlDWeTZuff8zvOa1AUq6MD4kBwwdlHplv2EXSLiIt9j8/ZiKXrQ041DE yqBhFlr4Toiohx7NNya5bOrAF2YXY4lt5g5AD75l8jx5OTccJD+qsyYdgJ+mbWwd/DeJ CP7bCpn+2am9gr+/AtmkluWX+Li5teSnCfMTYtMEjHfan2xEggalp+q3rctmByGAXP6H 3EOg== 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 y22-20020a056402135600b0051e0d7f1e3esi2523009edw.419.2023.07.14.11.29.00; Fri, 14 Jul 2023 11:29:01 -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 4008568C665; Fri, 14 Jul 2023 21:28:45 +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 598DF68C541 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 F2316C0217 for ; Fri, 14 Jul 2023 21:28:35 +0300 (EEST) From: =?utf-8?q?R=C3=A9mi_Denis-Courmont?= To: ffmpeg-devel@ffmpeg.org Date: Fri, 14 Jul 2023 21:28:31 +0300 Message-Id: <20230714182835.66326-3-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 3/7] checkasm: make perf macros functional 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: cnmZAxspGOeO This converts the bench/perf start/stop macros into functional macros, and for that to work, take the Linux perf code out of line. --- tests/checkasm/checkasm.c | 24 ++++++++++++++++++++---- tests/checkasm/checkasm.h | 36 +++++++++++++----------------------- 2 files changed, 33 insertions(+), 27 deletions(-) diff --git a/tests/checkasm/checkasm.c b/tests/checkasm/checkasm.c index bfc0a48079..69a709175f 100644 --- a/tests/checkasm/checkasm.c +++ b/tests/checkasm/checkasm.c @@ -515,11 +515,9 @@ static int measure_nop_time(void) int i, nop_sum = 0; av_unused const int sysfd = state.sysfd; - uint64_t t = 0; for (i = 0; i < 10000; i++) { - PERF_START(t); - PERF_STOP(t); - nops[i] = t; + uint64_t t = checkasm_bench_start(); + nops[i] = checkasm_bench_stop() - t; } qsort(nops, 10000, sizeof(uint16_t), cmp_nop); @@ -653,6 +651,24 @@ static void print_cpu_name(void) } #if CONFIG_LINUX_PERF +uint64_t checkasm_bench_linux_perf_start(void) +{ + int fd = state.sysfd; + + ioctl(fd, PERF_EVENT_IOC_RESET, 0); + ioctl(fd, PERF_EVENT_IOC_ENABLE, 0); + return 0; +} + +uint64_t checkasm_bench_linux_perf_stop(void) +{ + uint64_t t; + int fd = state.sysfd; + + ioctl(fd, PERF_EVENT_IOC_DISABLE, 0); + return (read(fd, &t, sizeof(t)) == sizeof (t)) ? t : 0; +} + static int bench_init_linux(void) { struct perf_event_attr attr = { diff --git a/tests/checkasm/checkasm.h b/tests/checkasm/checkasm.h index 117d4dd35c..8a62b98f3e 100644 --- a/tests/checkasm/checkasm.h +++ b/tests/checkasm/checkasm.h @@ -238,25 +238,20 @@ typedef struct CheckasmPerf { int iterations; } CheckasmPerf; -#if defined(AV_READ_TIME) || CONFIG_LINUX_PERF || CONFIG_MACOS_KPERF - #if CONFIG_LINUX_PERF -#define PERF_START(t) do { \ - ioctl(sysfd, PERF_EVENT_IOC_RESET, 0); \ - ioctl(sysfd, PERF_EVENT_IOC_ENABLE, 0); \ -} while (0) -#define PERF_STOP(t) do { \ - int ret; \ - ioctl(sysfd, PERF_EVENT_IOC_DISABLE, 0); \ - ret = read(sysfd, &t, sizeof(t)); \ - (void)ret; \ -} while (0) +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 PERF_START(t) t = ff_kperf_cycles() -#define PERF_STOP(t) t = ff_kperf_cycles() - t +#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 PERF_START(t) t = AV_READ_TIME() -#define PERF_STOP(t) t = AV_READ_TIME() - t +#define checkasm_bench_start() UINT64_C(0) +#define checkasm_bench_stop() UINT64_C(0) #endif /* Benchmark the function */ @@ -270,12 +265,12 @@ typedef struct CheckasmPerf { int ti, tcount = 0;\ uint64_t t = 0; \ for (ti = 0; ti < BENCH_RUNS; ti++) {\ - PERF_START(t);\ + t = checkasm_bench_start(); \ tfunc(__VA_ARGS__);\ tfunc(__VA_ARGS__);\ tfunc(__VA_ARGS__);\ tfunc(__VA_ARGS__);\ - PERF_STOP(t);\ + t = checkasm_bench_stop() - t;\ if (t*tcount <= tsum*4 && ti > 0) {\ tsum += t;\ tcount++;\ @@ -286,11 +281,6 @@ typedef struct CheckasmPerf { perf->iterations++;\ }\ } while (0) -#else -#define bench_new(...) while(0) -#define PERF_START(t) while(0) -#define PERF_STOP(t) while(0) -#endif #define DECL_CHECKASM_CHECK_FUNC(type) \ int checkasm_check_##type(const char *const file, const int line, \