Loading...
Searching...
No Matches
cpu.h
Go to the documentation of this file.
/* Simple Plugin API */
/* SPDX-FileCopyrightText: Copyright © 2018 Wim Taymans */
/* SPDX-License-Identifier: MIT */
#ifndef SPA_CPU_H
#define SPA_CPU_H
#include <stdarg.h>
#include <errno.h>
#include <spa/utils/defs.h>
#include <spa/utils/hook.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef SPA_API_CPU
#ifdef SPA_API_IMPL
#define SPA_API_CPU SPA_API_IMPL
#else
#define SPA_API_CPU static inline
#endif
#endif
#define SPA_TYPE_INTERFACE_CPU SPA_TYPE_INFO_INTERFACE_BASE "CPU"
#define SPA_VERSION_CPU 0
struct spa_cpu { struct spa_interface iface; };
/* x86 specific */
#define SPA_CPU_FLAG_MMX (1<<0)
#define SPA_CPU_FLAG_MMXEXT (1<<1)
#define SPA_CPU_FLAG_3DNOW (1<<2)
#define SPA_CPU_FLAG_SSE (1<<3)
#define SPA_CPU_FLAG_SSE2 (1<<4)
#define SPA_CPU_FLAG_3DNOWEXT (1<<5)
#define SPA_CPU_FLAG_SSE3 (1<<6)
#define SPA_CPU_FLAG_SSSE3 (1<<7)
#define SPA_CPU_FLAG_SSE41 (1<<8)
#define SPA_CPU_FLAG_SSE42 (1<<9)
#define SPA_CPU_FLAG_AESNI (1<<10)
#define SPA_CPU_FLAG_AVX (1<<11)
#define SPA_CPU_FLAG_XOP (1<<12)
#define SPA_CPU_FLAG_FMA4 (1<<13)
#define SPA_CPU_FLAG_CMOV (1<<14)
#define SPA_CPU_FLAG_AVX2 (1<<15)
#define SPA_CPU_FLAG_FMA3 (1<<16)
#define SPA_CPU_FLAG_BMI1 (1<<17)
#define SPA_CPU_FLAG_BMI2 (1<<18)
#define SPA_CPU_FLAG_AVX512 (1<<19)
#define SPA_CPU_FLAG_SLOW_UNALIGNED (1<<20)
/* PPC specific */
#define SPA_CPU_FLAG_ALTIVEC (1<<0)
#define SPA_CPU_FLAG_VSX (1<<1)
#define SPA_CPU_FLAG_POWER8 (1<<2)
/* ARM specific */
#define SPA_CPU_FLAG_ARMV5TE (1 << 0)
#define SPA_CPU_FLAG_ARMV6 (1 << 1)
#define SPA_CPU_FLAG_ARMV6T2 (1 << 2)
#define SPA_CPU_FLAG_VFP (1 << 3)
#define SPA_CPU_FLAG_VFPV3 (1 << 4)
#define SPA_CPU_FLAG_NEON (1 << 5)
#define SPA_CPU_FLAG_ARMV8 (1 << 6)
/* RISCV specific */
#define SPA_CPU_FLAG_RISCV_V (1 << 0)
#define SPA_CPU_FORCE_AUTODETECT ((uint32_t)-1)
#define SPA_CPU_VM_NONE (0)
#define SPA_CPU_VM_OTHER (1 << 0)
#define SPA_CPU_VM_KVM (1 << 1)
#define SPA_CPU_VM_QEMU (1 << 2)
#define SPA_CPU_VM_BOCHS (1 << 3)
#define SPA_CPU_VM_XEN (1 << 4)
#define SPA_CPU_VM_UML (1 << 5)
#define SPA_CPU_VM_VMWARE (1 << 6)
#define SPA_CPU_VM_ORACLE (1 << 7)
#define SPA_CPU_VM_MICROSOFT (1 << 8)
#define SPA_CPU_VM_ZVM (1 << 9)
#define SPA_CPU_VM_PARALLELS (1 << 10)
#define SPA_CPU_VM_BHYVE (1 << 11)
#define SPA_CPU_VM_QNX (1 << 12)
#define SPA_CPU_VM_ACRN (1 << 13)
#define SPA_CPU_VM_POWERVM (1 << 14)
SPA_API_CPU const char *spa_cpu_vm_type_to_string(uint32_t vm_type)
{
switch(vm_type) {
case SPA_CPU_VM_NONE:
return NULL;
case SPA_CPU_VM_KVM:
return "kvm";
case SPA_CPU_VM_QEMU:
return "qemu";
case SPA_CPU_VM_BOCHS:
return "bochs";
case SPA_CPU_VM_XEN:
return "xen";
case SPA_CPU_VM_UML:
return "uml";
case SPA_CPU_VM_VMWARE:
return "vmware";
case SPA_CPU_VM_ORACLE:
return "oracle";
case SPA_CPU_VM_MICROSOFT:
return "microsoft";
case SPA_CPU_VM_ZVM:
return "zvm";
case SPA_CPU_VM_PARALLELS:
return "parallels";
case SPA_CPU_VM_BHYVE:
return "bhyve";
case SPA_CPU_VM_QNX:
return "qnx";
case SPA_CPU_VM_ACRN:
return "acrn";
case SPA_CPU_VM_POWERVM:
return "powervm";
case SPA_CPU_VM_OTHER:
return "other";
default:
return "unknown";
}
}
struct spa_cpu_methods {
#define SPA_VERSION_CPU_METHODS 2
uint32_t version;
uint32_t (*get_flags) (void *object);
int (*force_flags) (void *object, uint32_t flags);
uint32_t (*get_count) (void *object);
/** get maximum required alignment of data */
uint32_t (*get_max_align) (void *object);
/* check if running in a VM. Since:1 */
uint32_t (*get_vm_type) (void *object);
/* denormals will be handled as zero, either with FTZ or DAZ.
* Since:2 */
int (*zero_denormals) (void *object, bool enable);
};
SPA_API_CPU uint32_t spa_cpu_get_flags(struct spa_cpu *c)
{
return spa_api_method_r(uint32_t, 0, spa_cpu, &c->iface, get_flags, 0);
}
SPA_API_CPU int spa_cpu_force_flags(struct spa_cpu *c, uint32_t flags)
{
return spa_api_method_r(int, -ENOTSUP, spa_cpu, &c->iface, force_flags, 0, flags);
}
SPA_API_CPU uint32_t spa_cpu_get_count(struct spa_cpu *c)
{
return spa_api_method_r(uint32_t, 0, spa_cpu, &c->iface, get_count, 0);
}
SPA_API_CPU uint32_t spa_cpu_get_max_align(struct spa_cpu *c)
{
return spa_api_method_r(uint32_t, 0, spa_cpu, &c->iface, get_max_align, 0);
}
SPA_API_CPU uint32_t spa_cpu_get_vm_type(struct spa_cpu *c)
{
return spa_api_method_r(uint32_t, 0, spa_cpu, &c->iface, get_vm_type, 1);
}
SPA_API_CPU int spa_cpu_zero_denormals(struct spa_cpu *c, bool enable)
{
return spa_api_method_r(int, -ENOTSUP, spa_cpu, &c->iface, zero_denormals, 2, enable);
}
#define SPA_KEY_CPU_FORCE "cpu.force"
#define SPA_KEY_CPU_VM_TYPE "cpu.vm.type"
#define SPA_KEY_CPU_ZERO_DENORMALS "cpu.zero.denormals"
*/
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* SPA_CPU_H */
SPA_API_CPU
#define SPA_API_CPU
Definition cpu.h:29
defs.h
spa/utils/defs.h
SPA_CPU_VM_POWERVM
#define SPA_CPU_VM_POWERVM
Definition cpu.h:158
SPA_CPU_VM_OTHER
#define SPA_CPU_VM_OTHER
Definition cpu.h:130
spa_cpu_zero_denormals
SPA_API_CPU int spa_cpu_zero_denormals(struct spa_cpu *c, bool enable)
Definition cpu.h:250
SPA_CPU_VM_PARALLELS
#define SPA_CPU_VM_PARALLELS
Definition cpu.h:150
SPA_CPU_VM_QNX
#define SPA_CPU_VM_QNX
Definition cpu.h:154
spa_cpu_get_count
SPA_API_CPU uint32_t spa_cpu_get_count(struct spa_cpu *c)
Definition cpu.h:238
spa_cpu_get_max_align
SPA_API_CPU uint32_t spa_cpu_get_max_align(struct spa_cpu *c)
Definition cpu.h:242
SPA_CPU_VM_VMWARE
#define SPA_CPU_VM_VMWARE
Definition cpu.h:142
SPA_CPU_VM_ORACLE
#define SPA_CPU_VM_ORACLE
Definition cpu.h:144
spa_cpu_force_flags
SPA_API_CPU int spa_cpu_force_flags(struct spa_cpu *c, uint32_t flags)
Definition cpu.h:234
spa_cpu_vm_type_to_string
SPA_API_CPU const char * spa_cpu_vm_type_to_string(uint32_t vm_type)
Definition cpu.h:160
SPA_CPU_VM_MICROSOFT
#define SPA_CPU_VM_MICROSOFT
Definition cpu.h:146
SPA_CPU_VM_XEN
#define SPA_CPU_VM_XEN
Definition cpu.h:138
SPA_CPU_VM_KVM
#define SPA_CPU_VM_KVM
Definition cpu.h:132
spa_cpu_get_flags
SPA_API_CPU uint32_t spa_cpu_get_flags(struct spa_cpu *c)
Definition cpu.h:230
SPA_CPU_VM_ZVM
#define SPA_CPU_VM_ZVM
Definition cpu.h:148
SPA_CPU_VM_BHYVE
#define SPA_CPU_VM_BHYVE
Definition cpu.h:152
SPA_CPU_VM_UML
#define SPA_CPU_VM_UML
Definition cpu.h:140
SPA_CPU_VM_BOCHS
#define SPA_CPU_VM_BOCHS
Definition cpu.h:136
spa_cpu_get_vm_type
SPA_API_CPU uint32_t spa_cpu_get_vm_type(struct spa_cpu *c)
Definition cpu.h:246
SPA_CPU_VM_NONE
#define SPA_CPU_VM_NONE
Definition cpu.h:128
SPA_CPU_VM_QEMU
#define SPA_CPU_VM_QEMU
Definition cpu.h:134
SPA_CPU_VM_ACRN
#define SPA_CPU_VM_ACRN
Definition cpu.h:156
spa_api_method_r
#define spa_api_method_r(rtype, def, type, o, method, version,...)
Definition hook.h:291
hook.h
spa/utils/hook.h
spa_cpu_methods
methods
Definition cpu.h:203
spa_cpu_methods::get_max_align
uint32_t(* get_max_align)(void *object)
get maximum required alignment of data
Definition cpu.h:220
spa_cpu_methods::force_flags
int(* force_flags)(void *object, uint32_t flags)
force CPU flags, use SPA_CPU_FORCE_AUTODETECT to autodetect CPU flags
Definition cpu.h:214
spa_cpu_methods::get_count
uint32_t(* get_count)(void *object)
get number of CPU cores
Definition cpu.h:217
spa_cpu_methods::get_flags
uint32_t(* get_flags)(void *object)
get CPU flags
Definition cpu.h:211
spa_cpu_methods::zero_denormals
int(* zero_denormals)(void *object, bool enable)
Definition cpu.h:227
spa_cpu_methods::get_vm_type
uint32_t(* get_vm_type)(void *object)
Definition cpu.h:223
spa_cpu_methods::version
uint32_t version
Definition cpu.h:208
spa_cpu
Definition cpu.h:50
spa_cpu::iface
struct spa_interface iface
Definition cpu.h:50
spa_interface
Definition hook.h:148