From patchwork Wed Jul 19 19:55: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: 42844 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:b813:b0:130:ccc6:6c4b with SMTP id fi19csp1427728pzb; Wed, 19 Jul 2023 12:55:51 -0700 (PDT) X-Google-Smtp-Source: APBJJlHBAZZ36WxSKzulSFl1yRiZybIoVia8Y7duWBA4UvvpQ9mEjboqSJT3U8Ig9a/m9gxlWN7E X-Received: by 2002:a05:6402:654:b0:521:ad49:8493 with SMTP id u20-20020a056402065400b00521ad498493mr3884389edx.6.1689796551198; Wed, 19 Jul 2023 12:55:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689796551; cv=none; d=google.com; s=arc-20160816; b=iqpYUisFtaa6aSuFpEqRAvU2qCA8QSDZJJHUoIQCSrMwEN+FlPu0t8mohMgpu3jml0 Xh7PZUgJHCJW5zsp8eTm2sQA+4dFizDh4zaQdki1acYs7/g3wfnrFaXJI/TZVbqsnWw3 K1d5OAZiufdsEPa5l4Wz1mzn9FEj9ZhqW/YxnwSZZh+LTPLIG45BcaQiyOTD5wE+W7WV nWhzJgDdAN8lJYHhSCfCCpELcXC6KtaToSzdWXobVekXAVMLTaLVhCC3nGDxQGcXDI0v Gdk8vraNC337+AEL6jesZQ4tzTFbCIlH1o+65CBMIuwKLcD5bxCQPKqf3FxzSMcibXhv OLJw== 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=SJ15s4s1r4lpfbM0s7Fk79zDaADxCQ13bColPYNYRCY=; fh=hQcp50obTJ8bXC1it5NuEN23RGKfx0/zZ3s2gmreL+A=; b=Bj/ULtC7gL8p55Hc9htRgX91jPYeAUZq9mjhMo8+a6qCKFNRkIDKat7uEwUGyI6qjn b33UU7pVHymFql/obBXVJHRnjj3d8oF8frJL7vxKeOmCpMrZCVjYYLj6lN+sCdYKDXi8 99XtguTyb1COr3Y4DMVyi8nBcCOlObgzbfyEQaNIDNne87KmTGrkdSN3+Mtq4Fv6ATlR GLHF9h/+e+yp8SsJaTQFbDBFSU/lZq3WB0lMGHG2+P5iH7xmrulxRkDKAo8SzZ0qy4JF kCMcADpBAfEG2AivS/wUkIlpJVmYnzN+oZaUS3YzPa5KSHMEHphn91VZVQnpDUZ4EDyU lW6Q== 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 q18-20020a056402041200b0051e22d772a2si3408883edv.679.2023.07.19.12.55.50; Wed, 19 Jul 2023 12:55:51 -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 8BC3668C5F8; Wed, 19 Jul 2023 22:55: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 5768968BF90 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 CD022C01EF for ; Wed, 19 Jul 2023 22:55:40 +0300 (EEST) From: =?utf-8?q?R=C3=A9mi_Denis-Courmont?= To: ffmpeg-devel@ffmpeg.org Date: Wed, 19 Jul 2023 22:55:35 +0300 Message-Id: <20230719195540.46961-1-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 1/6] 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: XimKW+kTzNh7 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 30e2dc6fed..63141e1f7a 100644 --- a/tests/checkasm/checkasm.c +++ b/tests/checkasm/checkasm.c @@ -514,11 +514,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); @@ -652,6 +650,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, \