[FFmpeg-cvslog] bsd: use number of logical CPUs as automatic thread count
Janne Grunau
git at videolan.org
Fri Dec 23 03:38:00 CET 2011
ffmpeg | branch: master | Janne Grunau <janne-libav at jannau.net> | Thu Dec 22 21:10:07 2011 +0100| [b9e2226972737ab202ac1f5a6e005af80072bb39] | committer: Janne Grunau
bsd: use number of logical CPUs as automatic thread count
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=b9e2226972737ab202ac1f5a6e005af80072bb39
---
configure | 2 ++
libavcodec/pthread.c | 10 ++++++++++
2 files changed, 12 insertions(+), 0 deletions(-)
diff --git a/configure b/configure
index 64233cc..9b510de 100755
--- a/configure
+++ b/configure
@@ -1138,6 +1138,7 @@ HAVE_LIST="
symver
symver_asm_label
symver_gnu_asm
+ sysctl
sys_mman_h
sys_resource_h
sys_select_h
@@ -2856,6 +2857,7 @@ check_func strerror_r
check_func strptime
check_func strtok_r
check_func sched_getaffinity
+check_func sysctl
check_func_headers io.h setmode
check_func_headers lzo/lzo1x.h lzo1x_999_compress
check_lib2 "windows.h psapi.h" GetProcessMemoryInfo -lpsapi
diff --git a/libavcodec/pthread.c b/libavcodec/pthread.c
index bf6733f..0b57156 100644
--- a/libavcodec/pthread.c
+++ b/libavcodec/pthread.c
@@ -36,6 +36,9 @@
#include <sched.h>
#elif HAVE_GETSYSTEMINFO
#include <windows.h>
+#elif HAVE_SYSCTL
+#include <sys/sysctl.h>
+#include <sys/types.h>
#endif
#include "avcodec.h"
@@ -162,6 +165,13 @@ static int get_logical_cpus(AVCodecContext *avctx)
SYSTEM_INFO sysinfo;
GetSystemInfo(&sysinfo);
nb_cpus = sysinfo.dwNumberOfProcessors;
+#elif HAVE_SYSCTL
+ int mib[2] = { CTL_HW, HW_NCPU };
+ size_t len = sizeof(nb_cpus);
+
+ ret = sysctl(mib, 2, &nb_cpus, &len, NULL, 0);
+ if (ret == -1)
+ nb_cpus = 0;
#endif
av_log(avctx, AV_LOG_DEBUG, "detected %d logical cores\n", nb_cpus);
return FFMIN(nb_cpus, MAX_AUTO_THREADS);
More information about the ffmpeg-cvslog
mailing list