27 #if HAVE_SCHED_GETAFFINITY
33 #if HAVE_GETPROCESSAFFINITYMASK
38 #include <sys/param.h>
40 #include <sys/types.h>
41 #include <sys/sysctl.h>
101 #define CPUFLAG_MMXEXT (AV_CPU_FLAG_MMX | AV_CPU_FLAG_MMXEXT | AV_CPU_FLAG_CMOV)
102 #define CPUFLAG_3DNOW (AV_CPU_FLAG_3DNOW | AV_CPU_FLAG_MMX)
103 #define CPUFLAG_3DNOWEXT (AV_CPU_FLAG_3DNOWEXT | CPUFLAG_3DNOW)
104 #define CPUFLAG_SSE (AV_CPU_FLAG_SSE | CPUFLAG_MMXEXT)
105 #define CPUFLAG_SSE2 (AV_CPU_FLAG_SSE2 | CPUFLAG_SSE)
106 #define CPUFLAG_SSE2SLOW (AV_CPU_FLAG_SSE2SLOW | CPUFLAG_SSE2)
107 #define CPUFLAG_SSE3 (AV_CPU_FLAG_SSE3 | CPUFLAG_SSE2)
108 #define CPUFLAG_SSE3SLOW (AV_CPU_FLAG_SSE3SLOW | CPUFLAG_SSE3)
109 #define CPUFLAG_SSSE3 (AV_CPU_FLAG_SSSE3 | CPUFLAG_SSE3)
110 #define CPUFLAG_SSE4 (AV_CPU_FLAG_SSE4 | CPUFLAG_SSSE3)
111 #define CPUFLAG_SSE42 (AV_CPU_FLAG_SSE42 | CPUFLAG_SSE4)
112 #define CPUFLAG_AVX (AV_CPU_FLAG_AVX | CPUFLAG_SSE42)
113 #define CPUFLAG_XOP (AV_CPU_FLAG_XOP | CPUFLAG_AVX)
114 #define CPUFLAG_FMA3 (AV_CPU_FLAG_FMA3 | CPUFLAG_AVX)
115 #define CPUFLAG_FMA4 (AV_CPU_FLAG_FMA4 | CPUFLAG_AVX)
116 #define CPUFLAG_AVX2 (AV_CPU_FLAG_AVX2 | CPUFLAG_AVX)
117 #define CPUFLAG_BMI1 (AV_CPU_FLAG_BMI1)
118 #define CPUFLAG_BMI2 (AV_CPU_FLAG_BMI2 | CPUFLAG_BMI1)
119 static const AVOption cpuflags_opts[] = {
120 {
"flags" , NULL, 0,
AV_OPT_TYPE_FLAGS, { .i64 = 0 }, INT64_MIN, INT64_MAX, .unit =
"flags" },
162 .option = cpuflags_opts,
167 const AVClass *pclass = &
class;
172 return flags & INT_MAX;
177 static const AVOption cpuflags_opts[] = {
178 {
"flags" , NULL, 0,
AV_OPT_TYPE_FLAGS, { .i64 = 0 }, INT64_MIN, INT64_MAX, .unit =
"flags" },
205 #define CPU_FLAG_P2 AV_CPU_FLAG_CMOV | AV_CPU_FLAG_MMX
206 #define CPU_FLAG_P3 CPU_FLAG_P2 | AV_CPU_FLAG_MMX2 | AV_CPU_FLAG_SSE
207 #define CPU_FLAG_P4 CPU_FLAG_P3| AV_CPU_FLAG_SSE2
208 {
"pentium2", NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = CPU_FLAG_P2 }, .unit =
"flags" },
209 {
"pentium3", NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = CPU_FLAG_P3 }, .unit =
"flags" },
210 {
"pentium4", NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = CPU_FLAG_P4 }, .unit =
"flags" },
212 #define CPU_FLAG_K62 AV_CPU_FLAG_MMX | AV_CPU_FLAG_3DNOW
213 #define CPU_FLAG_ATHLON CPU_FLAG_K62 | AV_CPU_FLAG_CMOV | AV_CPU_FLAG_3DNOWEXT | AV_CPU_FLAG_MMX2
214 #define CPU_FLAG_ATHLONXP CPU_FLAG_ATHLON | AV_CPU_FLAG_SSE
215 #define CPU_FLAG_K8 CPU_FLAG_ATHLONXP | AV_CPU_FLAG_SSE2
218 {
"athlon", NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = CPU_FLAG_ATHLON }, .unit =
"flags" },
219 {
"athlonxp", NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = CPU_FLAG_ATHLONXP }, .unit =
"flags" },
239 .option = cpuflags_opts,
242 const AVClass *pclass = &
class;
249 static volatile int printed;
252 #if HAVE_SCHED_GETAFFINITY && defined(CPU_COUNT)
257 if (!sched_getaffinity(0,
sizeof(cpuset), &cpuset))
258 nb_cpus = CPU_COUNT(&cpuset);
259 #elif HAVE_GETPROCESSAFFINITYMASK
261 if (GetProcessAffinityMask(GetCurrentProcess(), &proc_aff, &sys_aff))
262 nb_cpus = av_popcount64(proc_aff);
263 #elif HAVE_SYSCTL && defined(HW_NCPU)
264 int mib[2] = { CTL_HW, HW_NCPU };
265 size_t len =
sizeof(nb_cpus);
267 if (sysctl(mib, 2, &nb_cpus, &len, NULL, 0) == -1)
269 #elif HAVE_SYSCONF && defined(_SC_NPROC_ONLN)
270 nb_cpus = sysconf(_SC_NPROC_ONLN);
271 #elif HAVE_SYSCONF && defined(_SC_NPROCESSORS_ONLN)
272 nb_cpus = sysconf(_SC_NPROCESSORS_ONLN);
292 static const struct {
336 static void print_cpu_flags(
int cpu_flags,
const char *
type)
340 printf(
"cpu_flags(%s) = 0x%08X\n", type, cpu_flags);
341 printf(
"cpu_flags_str(%s) =", type);
342 for (i = 0; cpu_flag_tab[i].flag; i++)
343 if (cpu_flags & cpu_flag_tab[i].flag)
344 printf(
" %s", cpu_flag_tab[i].
name);
349 int main(
int argc,
char **argv)
354 char threads[5] =
"auto";
357 for(i = 0; cpu_flag_tab[i].flag; i++) {
360 fprintf(stderr,
"Table missing %s\n", cpu_flag_tab[i].name);
365 if (cpu_flags_raw < 0)
369 int c =
getopt(argc, argv,
"c:t:");
385 if (len >=
sizeof(threads)) {
386 fprintf(stderr,
"Invalid thread count '%s'\n",
optarg);
395 if (cpu_flags_eff < 0)
398 print_cpu_flags(cpu_flags_raw,
"raw");
399 print_cpu_flags(cpu_flags_eff,
"effective");
400 printf(
"threads = %s (cpu_count = %d)\n", threads, cpu_count);