From 9573b24e529c80c06b35c353e429bd275f18413d Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Mon, 7 Jan 2019 15:02:18 +0100 Subject: [PATCH] cpu: add force cpu flags Use PIPEWIRE_CPU to force cpu flags. --- spa/include/spa/support/cpu.h | 5 +++++ spa/plugins/support/cpu.c | 13 +++++++++++++ src/pipewire/pipewire.c | 5 +++++ 3 files changed, 23 insertions(+) diff --git a/spa/include/spa/support/cpu.h b/spa/include/spa/support/cpu.h index 054912d94..9c5c0be7f 100644 --- a/spa/include/spa/support/cpu.h +++ b/spa/include/spa/support/cpu.h @@ -66,6 +66,7 @@ extern "C" { #define SPA_CPU_FLAG_NEON (1 << 5) #define SPA_CPU_FLAG_ARMV8 (1 << 6) +#define SPA_CPU_FORCE_AUTODETECT ((uint32_t)-1) /** * The CPU features interface */ @@ -82,6 +83,9 @@ struct spa_cpu { /** get CPU flags */ uint32_t (*get_flags) (struct spa_cpu *cpu); + /** force CPU flags, use SPA_CPU_FORCE_AUTODETECT to autodetect CPU flags */ + int (*force_flags) (struct spa_cpu *cpu, uint32_t flags); + /** get number of CPU cores */ uint32_t (*get_count) (struct spa_cpu *cpu); @@ -90,6 +94,7 @@ struct spa_cpu { }; #define spa_cpu_get_flags(c) (c)->get_flags((c)) +#define spa_cpu_force_flags(c,f) (c)->force_flags((c), (f)) #define spa_cpu_get_count(c) (c)->get_count((c)) #define spa_cpu_get_max_align(c) (c)->get_max_align((c)) diff --git a/spa/plugins/support/cpu.c b/spa/plugins/support/cpu.c index 7ef7b0811..244413ae4 100644 --- a/spa/plugins/support/cpu.c +++ b/spa/plugins/support/cpu.c @@ -45,6 +45,7 @@ struct impl { struct spa_log *log; uint32_t flags; + uint32_t force; uint32_t count; uint32_t max_align; }; @@ -58,9 +59,19 @@ static uint32_t impl_cpu_get_flags(struct spa_cpu *cpu) { struct impl *impl = SPA_CONTAINER_OF(cpu, struct impl, cpu); + if (impl->force != SPA_CPU_FORCE_AUTODETECT) + return impl->force; return impl->flags; } +static int +impl_cpu_force_flags(struct spa_cpu *cpu, uint32_t flags) +{ + struct impl *impl = SPA_CONTAINER_OF(cpu, struct impl, cpu); + impl->force = flags; + return 0; +} + static uint32_t get_count(struct impl *this) { cpu_set_t cpuset; @@ -88,6 +99,7 @@ static const struct spa_cpu impl_cpu = { SPA_VERSION_CPU, NULL, impl_cpu_get_flags, + impl_cpu_force_flags, impl_cpu_get_count, impl_cpu_get_max_align, }; @@ -146,6 +158,7 @@ impl_init(const struct spa_handle_factory *factory, this->log = support[i].data; } this->flags = 0; + this->force = SPA_CPU_FORCE_AUTODETECT; this->max_align = 16; this->count = get_count(this); init(this); diff --git a/src/pipewire/pipewire.c b/src/pipewire/pipewire.c index 504a46d08..fd344370a 100644 --- a/src/pipewire/pipewire.c +++ b/src/pipewire/pipewire.c @@ -35,6 +35,7 @@ #include #include +#include #include "pipewire.h" #include "private.h" @@ -445,6 +446,10 @@ void pw_init(int *argc, char **argv[]) iface = load_interface(plugin, "cpu", SPA_TYPE_INTERFACE_CPU, &info, support->n_support, support->support); if (iface != NULL) { + struct spa_cpu *cpu = iface->iface; + if ((str = getenv("PIPEWIRE_CPU"))) + spa_cpu_force_flags(cpu, strtoul(str, NULL, 0)); + support->support[support->n_support++] = SPA_SUPPORT_INIT(SPA_TYPE_INTERFACE_CPU, iface->iface); }