mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-12-23 12:43:46 +02:00
lavu/kperf: use ff_thread_once()
Signed-off-by: J. Dekker <jdek@itanimul.li>
This commit is contained in:
parent
f614390ecc
commit
c866a099b2
@ -16,7 +16,10 @@
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "avassert.h"
|
||||
#include "macos_kperf.h"
|
||||
#include "thread.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <dlfcn.h>
|
||||
@ -68,69 +71,35 @@ KPERF_LIST
|
||||
#define CONFIG_COUNT 8
|
||||
#define KPC_MASK (KPC_CLASS_CONFIGURABLE_MASK | KPC_CLASS_FIXED_MASK)
|
||||
|
||||
static int ff_kperf_was_init = 0;
|
||||
|
||||
int ff_kperf_init()
|
||||
static void kperf_init(void)
|
||||
{
|
||||
uint64_t config[COUNTERS_COUNT] = {0};
|
||||
void *kperf = NULL;
|
||||
|
||||
if (ff_kperf_was_init)
|
||||
return 0;
|
||||
av_assert0(kperf = dlopen("/System/Library/PrivateFrameworks/kperf.framework/Versions/A/kperf", RTLD_LAZY));
|
||||
|
||||
kperf = dlopen("/System/Library/PrivateFrameworks/kperf.framework/Versions/A/kperf", RTLD_LAZY);
|
||||
if (!kperf) {
|
||||
fprintf(stderr, "kperf: kperf = %p\n", kperf);
|
||||
return -1;
|
||||
}
|
||||
|
||||
#define F(ret, name, ...) \
|
||||
name = (name##proc *)(dlsym(kperf, #name)); \
|
||||
if (!name) { \
|
||||
fprintf(stderr, "kperf: %s = %p\n", #name, (void *)name); \
|
||||
return -1; \
|
||||
}
|
||||
#define F(ret, name, ...) av_assert0(name = (name##proc *)(dlsym(kperf, #name)));
|
||||
KPERF_LIST
|
||||
#undef F
|
||||
|
||||
if (kpc_get_counter_count(KPC_MASK) != COUNTERS_COUNT) {
|
||||
fprintf(stderr, "kperf: wrong fixed counters count\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (kpc_get_config_count(KPC_MASK) != CONFIG_COUNT) {
|
||||
fprintf(stderr, "kperf: wrong fixed config count\n");
|
||||
return -1;
|
||||
}
|
||||
av_assert0(kpc_get_counter_count(KPC_MASK) == COUNTERS_COUNT);
|
||||
av_assert0(kpc_get_config_count(KPC_MASK) == CONFIG_COUNT);
|
||||
|
||||
config[0] = CPMU_CORE_CYCLE | CFGWORD_EL0A64EN_MASK;
|
||||
// config[3] = CPMU_INST_BRANCH | CFGWORD_EL0A64EN_MASK;
|
||||
// config[4] = CPMU_SYNC_BR_ANY_MISP | CFGWORD_EL0A64EN_MASK;
|
||||
// config[5] = CPMU_INST_A64 | CFGWORD_EL0A64EN_MASK;
|
||||
|
||||
if (kpc_set_config(KPC_MASK, config)) {
|
||||
fprintf(stderr, "kperf: kpc_set_config failed\n");
|
||||
return -1;
|
||||
}
|
||||
av_assert0(kpc_set_config(KPC_MASK, config) == 0 || !"the kperf API needs to be run as root");
|
||||
av_assert0(kpc_force_all_ctrs_set(1) == 0);
|
||||
av_assert0(kpc_set_counting(KPC_MASK) == 0);
|
||||
av_assert0(kpc_set_thread_counting(KPC_MASK) == 0);
|
||||
}
|
||||
|
||||
if (kpc_force_all_ctrs_set(1)) {
|
||||
fprintf(stderr, "kperf: kpc_force_all_ctrs_set failed\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (kpc_set_counting(KPC_MASK)) {
|
||||
fprintf(stderr, "kperf: kpc_set_counting failed\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (kpc_set_thread_counting(KPC_MASK)) {
|
||||
fprintf(stderr, "kperf: kpc_set_thread_counting failed\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
ff_kperf_was_init = 1;
|
||||
|
||||
return 0;
|
||||
void ff_kperf_init(void)
|
||||
{
|
||||
static AVOnce init_static_once = AV_ONCE_INIT;
|
||||
ff_thread_once(&init_static_once, kperf_init);
|
||||
}
|
||||
|
||||
uint64_t ff_kperf_cycles()
|
||||
|
@ -21,7 +21,7 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
int ff_kperf_init(void);
|
||||
void ff_kperf_init(void);
|
||||
uint64_t ff_kperf_cycles(void);
|
||||
|
||||
#endif /* AVUTIL_MACOS_KPERF_H */
|
||||
|
@ -131,12 +131,11 @@
|
||||
|
||||
#define START_TIMER \
|
||||
uint64_t tperf; \
|
||||
if (ff_kperf_init()) \
|
||||
av_log(NULL, AV_LOG_ERROR, "ff_kperf_init() failed\n"); \
|
||||
tperf = kperf_cycles();
|
||||
ff_kperf_init(); \
|
||||
tperf = ff_kperf_cycles();
|
||||
|
||||
#define STOP_TIMER(id) \
|
||||
TIMER_REPORT(id, kperf_cycles() - tperf);
|
||||
TIMER_REPORT(id, ff_kperf_cycles() - tperf);
|
||||
|
||||
#elif defined(AV_READ_TIME)
|
||||
#define START_TIMER \
|
||||
|
@ -641,11 +641,7 @@ static int bench_init_linux(void)
|
||||
#elif CONFIG_MACOS_KPERF
|
||||
static int bench_init_kperf(void)
|
||||
{
|
||||
if (ff_kperf_init()) {
|
||||
fprintf(stderr, "checkasm must be run as root to use kperf on macOS\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
ff_kperf_init();
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
|
Loading…
Reference in New Issue
Block a user