diff options
author | Clément Bœsch <cboesch@gopro.com> | 2017-09-01 15:11:18 +0200 |
---|---|---|
committer | Clément Bœsch <u@pkh.me> | 2017-09-08 18:51:05 +0200 |
commit | e0d56f097f42bcdbe6c3b2f57df62a4da63f2094 (patch) | |
tree | 5951ae1e60a3b1abc125937443a7b279ca9afdca /tests/checkasm/checkasm.h | |
parent | cf0eed2525bda50991ba0af4f808533403b08f7c (diff) | |
download | ffmpeg-e0d56f097f42bcdbe6c3b2f57df62a4da63f2094.tar.gz |
checkasm: use perf API on Linux ARM*
On ARM platforms, accessing the PMU registers requires special user
access permissions. Since there is no other way to get accurate timers,
the current implementation of timers in FFmpeg rely on these registers.
Unfortunately, enabling user access to these registers on Linux is not
trivial, and generally involve compiling a random and unreliable github
kernel module, or patching somehow your kernel.
Such module is very unlikely to reach the upstream anytime soon. Quoting
Robin Murphin from ARM:
> Say you do give userspace direct access to the PMU; now run two or more
> programs at once that believe they can use the counters for their own
> "minimal-overhead" profiling. Have fun interpreting those results...
>
> And that's not even getting into the implications of scheduling across
> different CPUs, CPUidle, etc. where the PMU state is completely beyond
> userspace's control. In general, the plan to provide userspace with
> something which might happen to just about work in a few corner cases,
> but is meaningless, misleading or downright broken in all others, is to
> never do so.
As a result, the alternative is to use the Performance Monitoring Linux
API which makes use of these registers internally (assuming the PMU of
your ARM board is supported in the kernel, which is definitely not a
given...).
While the Linux API is obviously cross platform, it does have a
significant overhead which needs to be taken into account. As a result,
that mode is only weakly enabled on ARM platforms exclusively.
Note on the non flexibility of the implementation: the timers (native
FFmpeg vs Linux API) are selected at compilation time to prevent the
need of function calls, which would result in a negative impact on the
cycle counters.
Diffstat (limited to 'tests/checkasm/checkasm.h')
-rw-r--r-- | tests/checkasm/checkasm.h | 47 |
1 files changed, 42 insertions, 5 deletions
diff --git a/tests/checkasm/checkasm.h b/tests/checkasm/checkasm.h index 3165b21086..b29a61331e 100644 --- a/tests/checkasm/checkasm.h +++ b/tests/checkasm/checkasm.h @@ -25,6 +25,14 @@ #include <stdint.h> #include "config.h" + +#if CONFIG_LINUX_PERF +#include <unistd.h> // read(3) +#include <sys/ioctl.h> +#include <asm/unistd.h> +#include <linux/perf_event.h> +#endif + #include "libavutil/avstring.h" #include "libavutil/cpu.h" #include "libavutil/internal.h" @@ -58,10 +66,12 @@ void checkasm_check_vp8dsp(void); void checkasm_check_vp9dsp(void); void checkasm_check_videodsp(void); +struct CheckasmPerf; + void *checkasm_check_func(void *func, const char *name, ...) av_printf_format(2, 3); int checkasm_bench_func(void); void checkasm_fail_func(const char *msg, ...) av_printf_format(1, 2); -void checkasm_update_bench(int iterations, uint64_t cycles); +struct CheckasmPerf *checkasm_get_perf_context(void); void checkasm_report(const char *name, ...) av_printf_format(1, 2); /* float compare utilities */ @@ -178,32 +188,59 @@ void checkasm_checked_call(void *func, ...); #define declare_new_float(ret, ...) declare_new(ret, __VA_ARGS__) #endif +typedef struct CheckasmPerf { + int sysfd; + uint64_t cycles; + int iterations; +} CheckasmPerf; + +#if defined(AV_READ_TIME) || CONFIG_LINUX_PERF + +#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 { \ + ioctl(sysfd, PERF_EVENT_IOC_DISABLE, 0); \ + read(sysfd, &t, sizeof(t)); \ +} while (0) +#else +#define PERF_START(t) t = AV_READ_TIME() +#define PERF_STOP(t) t = AV_READ_TIME() - t +#endif + /* Benchmark the function */ -#ifdef AV_READ_TIME #define bench_new(...)\ do {\ if (checkasm_bench_func()) {\ + struct CheckasmPerf *perf = checkasm_get_perf_context();\ + av_unused const int sysfd = perf->sysfd;\ func_type *tfunc = func_new;\ uint64_t tsum = 0;\ int ti, tcount = 0;\ + uint64_t t = 0; \ for (ti = 0; ti < BENCH_RUNS; ti++) {\ - uint64_t t = AV_READ_TIME();\ + PERF_START(t);\ tfunc(__VA_ARGS__);\ tfunc(__VA_ARGS__);\ tfunc(__VA_ARGS__);\ tfunc(__VA_ARGS__);\ - t = AV_READ_TIME() - t;\ + PERF_STOP(t);\ if (t*tcount <= tsum*4 && ti > 0) {\ tsum += t;\ tcount++;\ }\ }\ emms_c();\ - checkasm_update_bench(tcount, tsum);\ + perf->cycles += t;\ + perf->iterations++;\ }\ } while (0) #else #define bench_new(...) while(0) +#define PERF_START(t) while(0) +#define PERF_STOP(t) while(0) #endif #endif /* TESTS_CHECKASM_CHECKASM_H */ |