PipeWire 1.7.0
Loading...
Searching...
No Matches
cpu.h
Go to the documentation of this file.
1/* Simple Plugin API */
2/* SPDX-FileCopyrightText: Copyright © 2018 Wim Taymans */
3/* SPDX-License-Identifier: MIT */
4
5#ifndef SPA_CPU_H
6#define SPA_CPU_H
7
8#include <stdarg.h>
9#include <errno.h>
10
11#include <spa/utils/defs.h>
12#include <spa/utils/hook.h>
13
14#ifdef __cplusplus
15extern "C" {
16#endif
17
18#ifndef SPA_API_CPU
19 #ifdef SPA_API_IMPL
20 #define SPA_API_CPU SPA_API_IMPL
21 #else
22 #define SPA_API_CPU static inline
23 #endif
24#endif
25
34
38#define SPA_TYPE_INTERFACE_CPU SPA_TYPE_INFO_INTERFACE_BASE "CPU"
39
40#define SPA_VERSION_CPU 0
41struct spa_cpu { struct spa_interface iface; };
42
43/* x86 specific */
44#define SPA_CPU_FLAG_MMX (1<<0)
45#define SPA_CPU_FLAG_MMXEXT (1<<1)
46#define SPA_CPU_FLAG_3DNOW (1<<2)
47#define SPA_CPU_FLAG_SSE (1<<3)
48#define SPA_CPU_FLAG_SSE2 (1<<4)
49#define SPA_CPU_FLAG_3DNOWEXT (1<<5)
50#define SPA_CPU_FLAG_SSE3 (1<<6)
51#define SPA_CPU_FLAG_SSSE3 (1<<7)
52#define SPA_CPU_FLAG_SSE41 (1<<8)
53#define SPA_CPU_FLAG_SSE42 (1<<9)
54#define SPA_CPU_FLAG_AESNI (1<<10)
55#define SPA_CPU_FLAG_AVX (1<<11)
56#define SPA_CPU_FLAG_XOP (1<<12)
57#define SPA_CPU_FLAG_FMA4 (1<<13)
58#define SPA_CPU_FLAG_CMOV (1<<14)
59#define SPA_CPU_FLAG_AVX2 (1<<15)
60#define SPA_CPU_FLAG_FMA3 (1<<16)
61#define SPA_CPU_FLAG_BMI1 (1<<17)
62#define SPA_CPU_FLAG_BMI2 (1<<18)
63#define SPA_CPU_FLAG_AVX512 (1<<19)
64#define SPA_CPU_FLAG_SLOW_UNALIGNED (1<<20)
65#define SPA_CPU_FLAG_SLOW_GATHER (1<<21)
67/* PPC specific */
68#define SPA_CPU_FLAG_ALTIVEC (1<<0)
69#define SPA_CPU_FLAG_VSX (1<<1)
70#define SPA_CPU_FLAG_POWER8 (1<<2)
71
72/* ARM specific */
73#define SPA_CPU_FLAG_ARMV5TE (1 << 0)
74#define SPA_CPU_FLAG_ARMV6 (1 << 1)
75#define SPA_CPU_FLAG_ARMV6T2 (1 << 2)
76#define SPA_CPU_FLAG_VFP (1 << 3)
77#define SPA_CPU_FLAG_VFPV3 (1 << 4)
78#define SPA_CPU_FLAG_NEON (1 << 5)
79#define SPA_CPU_FLAG_ARMV8 (1 << 6)
81/* RISCV specific */
82#define SPA_CPU_FLAG_RISCV_V (1 << 0)
83
84#define SPA_CPU_FORCE_AUTODETECT ((uint32_t)-1)
85
86#define SPA_CPU_VM_NONE (0)
87#define SPA_CPU_VM_OTHER (1 << 0)
88#define SPA_CPU_VM_KVM (1 << 1)
89#define SPA_CPU_VM_QEMU (1 << 2)
90#define SPA_CPU_VM_BOCHS (1 << 3)
91#define SPA_CPU_VM_XEN (1 << 4)
92#define SPA_CPU_VM_UML (1 << 5)
93#define SPA_CPU_VM_VMWARE (1 << 6)
94#define SPA_CPU_VM_ORACLE (1 << 7)
95#define SPA_CPU_VM_MICROSOFT (1 << 8)
96#define SPA_CPU_VM_ZVM (1 << 9)
97#define SPA_CPU_VM_PARALLELS (1 << 10)
98#define SPA_CPU_VM_BHYVE (1 << 11)
99#define SPA_CPU_VM_QNX (1 << 12)
100#define SPA_CPU_VM_ACRN (1 << 13)
101#define SPA_CPU_VM_POWERVM (1 << 14)
103SPA_API_CPU const char *spa_cpu_vm_type_to_string(uint32_t vm_type)
105 switch(vm_type) {
106 case SPA_CPU_VM_NONE:
107 return NULL;
109 return "kvm";
111 return "qemu";
113 return "bochs";
115 return "xen";
117 return "uml";
119 return "vmware";
121 return "oracle";
123 return "microsoft";
125 return "zvm";
127 return "parallels";
128 case SPA_CPU_VM_BHYVE:
129 return "bhyve";
131 return "qnx";
133 return "acrn";
135 return "powervm";
137 return "other";
138 default:
139 return "unknown";
141}
149#define SPA_VERSION_CPU_METHODS 2
150 uint32_t version;
151
153 uint32_t (*get_flags) (void *object);
156 int (*force_flags) (void *object, uint32_t flags);
157
159 uint32_t (*get_count) (void *object);
162 uint32_t (*get_max_align) (void *object);
163
164 /* check if running in a VM. Since:1 */
165 uint32_t (*get_vm_type) (void *object);
166
167 /* denormals will be handled as zero, either with FTZ or DAZ.
168 * Since:2 */
169 int (*zero_denormals) (void *object, bool enable);
170};
171
172SPA_API_CPU uint32_t spa_cpu_get_flags(struct spa_cpu *c)
173{
174 return spa_api_method_r(uint32_t, 0, spa_cpu, &c->iface, get_flags, 0);
175}
176SPA_API_CPU int spa_cpu_force_flags(struct spa_cpu *c, uint32_t flags)
177{
178 return spa_api_method_r(int, -ENOTSUP, spa_cpu, &c->iface, force_flags, 0, flags);
179}
180SPA_API_CPU uint32_t spa_cpu_get_count(struct spa_cpu *c)
181{
182 return spa_api_method_r(uint32_t, 0, spa_cpu, &c->iface, get_count, 0);
183}
184SPA_API_CPU uint32_t spa_cpu_get_max_align(struct spa_cpu *c)
185{
186 return spa_api_method_r(uint32_t, 0, spa_cpu, &c->iface, get_max_align, 0);
187}
188SPA_API_CPU uint32_t spa_cpu_get_vm_type(struct spa_cpu *c)
189{
190 return spa_api_method_r(uint32_t, 0, spa_cpu, &c->iface, get_vm_type, 1);
191}
192SPA_API_CPU int spa_cpu_zero_denormals(struct spa_cpu *c, bool enable)
193{
194 return spa_api_method_r(int, -ENOTSUP, spa_cpu, &c->iface, zero_denormals, 2, enable);
195}
196
198#define SPA_KEY_CPU_FORCE "cpu.force"
199#define SPA_KEY_CPU_VM_TYPE "cpu.vm.type"
200#define SPA_KEY_CPU_ZERO_DENORMALS "cpu.zero.denormals"
201
206#ifdef __cplusplus
207} /* extern "C" */
208#endif
210#endif /* SPA_CPU_H */
#define SPA_API_CPU
Definition cpu.h:29
spa/utils/defs.h
#define SPA_CPU_VM_POWERVM
Definition cpu.h:160
#define SPA_CPU_VM_OTHER
Definition cpu.h:132
SPA_API_CPU int spa_cpu_zero_denormals(struct spa_cpu *c, bool enable)
Definition cpu.h:252
#define SPA_CPU_VM_PARALLELS
Definition cpu.h:152
#define SPA_CPU_VM_QNX
Definition cpu.h:156
SPA_API_CPU uint32_t spa_cpu_get_count(struct spa_cpu *c)
Definition cpu.h:240
SPA_API_CPU uint32_t spa_cpu_get_max_align(struct spa_cpu *c)
Definition cpu.h:244
#define SPA_CPU_VM_VMWARE
Definition cpu.h:144
#define SPA_CPU_VM_ORACLE
Definition cpu.h:146
SPA_API_CPU int spa_cpu_force_flags(struct spa_cpu *c, uint32_t flags)
Definition cpu.h:236
SPA_API_CPU const char * spa_cpu_vm_type_to_string(uint32_t vm_type)
Definition cpu.h:162
#define SPA_CPU_VM_MICROSOFT
Definition cpu.h:148
#define SPA_CPU_VM_XEN
Definition cpu.h:140
#define SPA_CPU_VM_KVM
Definition cpu.h:134
SPA_API_CPU uint32_t spa_cpu_get_flags(struct spa_cpu *c)
Definition cpu.h:232
#define SPA_CPU_VM_ZVM
Definition cpu.h:150
#define SPA_CPU_VM_BHYVE
Definition cpu.h:154
#define SPA_CPU_VM_UML
Definition cpu.h:142
#define SPA_CPU_VM_BOCHS
Definition cpu.h:138
SPA_API_CPU uint32_t spa_cpu_get_vm_type(struct spa_cpu *c)
Definition cpu.h:248
#define SPA_CPU_VM_NONE
Definition cpu.h:130
#define SPA_CPU_VM_QEMU
Definition cpu.h:136
#define SPA_CPU_VM_ACRN
Definition cpu.h:158
#define spa_api_method_r(rtype, def, type, o, method, version,...)
Definition hook.h:291
spa/utils/hook.h
methods
Definition cpu.h:205
uint32_t(* get_max_align)(void *object)
get maximum required alignment of data
Definition cpu.h:222
int(* force_flags)(void *object, uint32_t flags)
force CPU flags, use SPA_CPU_FORCE_AUTODETECT to autodetect CPU flags
Definition cpu.h:216
uint32_t(* get_count)(void *object)
get number of CPU cores
Definition cpu.h:219
uint32_t(* get_flags)(void *object)
get CPU flags
Definition cpu.h:213
int(* zero_denormals)(void *object, bool enable)
Definition cpu.h:229
uint32_t(* get_vm_type)(void *object)
Definition cpu.h:225
uint32_t version
Definition cpu.h:210
Definition cpu.h:50
struct spa_interface iface
Definition cpu.h:50
Definition hook.h:148