MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / av_cpu_count

Function av_cpu_count

libavutil/cpu.c:227–279  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

225}
226
227int av_cpu_count(void)
228{
229 static atomic_int printed = 0;
230
231 int nb_cpus = 1;
232 int count = 0;
233#if HAVE_WINRT
234 SYSTEM_INFO sysinfo;
235#endif
236#if HAVE_SCHED_GETAFFINITY && defined(CPU_COUNT)
237 cpu_set_t cpuset;
238
239 CPU_ZERO(&cpuset);
240
241 if (!sched_getaffinity(0, sizeof(cpuset), &cpuset))
242 nb_cpus = CPU_COUNT(&cpuset);
243#elif HAVE_GETPROCESSAFFINITYMASK
244 DWORD_PTR proc_aff, sys_aff;
245 if (GetProcessAffinityMask(GetCurrentProcess(), &proc_aff, &sys_aff))
246 nb_cpus = av_popcount64(proc_aff);
247#elif HAVE_SYSCTL && defined(HW_NCPUONLINE)
248 int mib[2] = { CTL_HW, HW_NCPUONLINE };
249 size_t len = sizeof(nb_cpus);
250
251 if (sysctl(mib, 2, &nb_cpus, &len, NULL, 0) == -1)
252 nb_cpus = 0;
253#elif HAVE_SYSCTL && defined(HW_NCPU)
254 int mib[2] = { CTL_HW, HW_NCPU };
255 size_t len = sizeof(nb_cpus);
256
257 if (sysctl(mib, 2, &nb_cpus, &len, NULL, 0) == -1)
258 nb_cpus = 0;
259#elif HAVE_SYSCONF && defined(_SC_NPROC_ONLN)
260 nb_cpus = sysconf(_SC_NPROC_ONLN);
261#elif HAVE_SYSCONF && defined(_SC_NPROCESSORS_ONLN)
262 nb_cpus = sysconf(_SC_NPROCESSORS_ONLN);
263#elif HAVE_WINRT
264 GetNativeSystemInfo(&sysinfo);
265 nb_cpus = sysinfo.dwNumberOfProcessors;
266#endif
267
268 if (!atomic_exchange_explicit(&printed, 1, memory_order_relaxed))
269 av_log(NULL, AV_LOG_DEBUG, "detected %d logical cores\n", nb_cpus);
270
271 count = atomic_load_explicit(&cpu_count, memory_order_relaxed);
272
273 if (count > 0) {
274 nb_cpus = count;
275 av_log(NULL, AV_LOG_DEBUG, "overriding to %d logical cores\n", nb_cpus);
276 }
277
278 return nb_cpus;
279}
280
281void av_cpu_force_count(int count)
282{

Callers 15

mainFunction · 0.85
ff_frame_thread_initFunction · 0.85
aom_initFunction · 0.85
get_confFunction · 0.85
svt_jpegxs_enc_initFunction · 0.85
libuavs3d_initFunction · 0.85
svt_jpegxs_dec_initFunction · 0.85
get_confFunction · 0.85
vpx_initFunction · 0.85
aom_initFunction · 0.85

Calls 1

av_logFunction · 0.85

Tested by 1

mainFunction · 0.68