diff options
Diffstat (limited to 'vp8')
-rw-r--r-- | vp8/common/generic/systemdependent.c | 48 | ||||
-rw-r--r-- | vp8/common/onyxc_int.h | 3 | ||||
-rw-r--r-- | vp8/decoder/threading.c | 10 | ||||
-rw-r--r-- | vp8/encoder/ethreading.c | 8 | ||||
-rw-r--r-- | vp8/encoder/onyx_int.h | 1 |
5 files changed, 63 insertions, 7 deletions
diff --git a/vp8/common/generic/systemdependent.c b/vp8/common/generic/systemdependent.c index c36ae2119..d981f3496 100644 --- a/vp8/common/generic/systemdependent.c +++ b/vp8/common/generic/systemdependent.c @@ -17,9 +17,54 @@ #include "vp8/common/idct.h" #include "vp8/common/onyxc_int.h" +#if CONFIG_MULTITHREAD +#if HAVE_UNISTD_H +#include <unistd.h> +#elif defined(_WIN32) +#include <windows.h> +typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO); +#endif +#endif + extern void vp8_arch_x86_common_init(VP8_COMMON *ctx); extern void vp8_arch_arm_common_init(VP8_COMMON *ctx); +#if CONFIG_MULTITHREAD +static int get_cpu_count() +{ + int core_count = 16; + +#if HAVE_UNISTD_H +#if defined(_SC_NPROCESSORS_ONLN) + core_count = sysconf(_SC_NPROCESSORS_ONLN); +#elif defined(_SC_NPROC_ONLN) + core_count = sysconf(_SC_NPROC_ONLN); +#endif +#elif defined(_WIN32) + { + PGNSI pGNSI; + SYSTEM_INFO sysinfo; + + /* Call GetNativeSystemInfo if supported or + * GetSystemInfo otherwise. */ + + pGNSI = (PGNSI) GetProcAddress( + GetModuleHandle(TEXT("kernel32.dll")), "GetNativeSystemInfo"); + if (pGNSI != NULL) + pGNSI(&sysinfo); + else + GetSystemInfo(&sysinfo); + + core_count = sysinfo.dwNumberOfProcessors; + } +#else + /* other platforms */ +#endif + + return core_count > 0 ? core_count : 1; +} +#endif + void vp8_machine_specific_config(VP8_COMMON *ctx) { #if CONFIG_RUNTIME_CPU_DETECT @@ -88,4 +133,7 @@ void vp8_machine_specific_config(VP8_COMMON *ctx) vp8_arch_arm_common_init(ctx); #endif +#if CONFIG_MULTITHREAD + ctx->processor_core_count = get_cpu_count(); +#endif /* CONFIG_MULTITHREAD */ } diff --git a/vp8/common/onyxc_int.h b/vp8/common/onyxc_int.h index 03aed81cb..cf29d03df 100644 --- a/vp8/common/onyxc_int.h +++ b/vp8/common/onyxc_int.h @@ -195,6 +195,9 @@ typedef struct VP8Common #if CONFIG_RUNTIME_CPU_DETECT VP8_COMMON_RTCD rtcd; #endif +#if CONFIG_MULTITHREAD + int processor_core_count; +#endif struct postproc_state postproc_state; } VP8_COMMON; diff --git a/vp8/decoder/threading.c b/vp8/decoder/threading.c index 56275940e..9ef85e9cd 100644 --- a/vp8/decoder/threading.c +++ b/vp8/decoder/threading.c @@ -439,12 +439,18 @@ void vp8_decoder_create_threads(VP8D_COMP *pbi) pbi->b_multithreaded_rd = 0; pbi->allocated_decoding_thread_count = 0; - core_count = (pbi->max_threads > 16) ? 16 : pbi->max_threads; + + /* limit decoding threads to the max number of token partitions */ + core_count = (pbi->max_threads > 8) ? 8 : pbi->max_threads; + + /* limit decoding threads to the available cores */ + if (core_count > pbi->common.processor_core_count) + core_count = pbi->common.processor_core_count; if (core_count > 1) { pbi->b_multithreaded_rd = 1; - pbi->decoding_thread_count = core_count -1; + pbi->decoding_thread_count = core_count - 1; CHECK_MEM_ERROR(pbi->h_decoding_thread, vpx_malloc(sizeof(pthread_t) * pbi->decoding_thread_count)); CHECK_MEM_ERROR(pbi->h_event_start_decoding, vpx_malloc(sizeof(sem_t) * pbi->decoding_thread_count)); diff --git a/vp8/encoder/ethreading.c b/vp8/encoder/ethreading.c index f5006ddab..c00494dcf 100644 --- a/vp8/encoder/ethreading.c +++ b/vp8/encoder/ethreading.c @@ -459,15 +459,15 @@ void vp8cx_create_encoder_threads(VP8_COMP *cpi) cpi->b_multi_threaded = 0; cpi->encoding_thread_count = 0; - cpi->processor_core_count = 32; //vp8_get_proc_core_count(); - if (cpi->processor_core_count > 1 && cpi->oxcf.multi_threaded > 1) + if (cm->processor_core_count > 1 && cpi->oxcf.multi_threaded > 1) { int ithread; int th_count = cpi->oxcf.multi_threaded - 1; - if (cpi->oxcf.multi_threaded > cpi->processor_core_count) - th_count = cpi->processor_core_count - 1; + /* don't allocate more threads than cores available */ + if (cpi->oxcf.multi_threaded > cm->processor_core_count) + th_count = cm->processor_core_count - 1; /* we have th_count + 1 (main) threads processing one row each */ /* no point to have more threads than the sync range allows */ diff --git a/vp8/encoder/onyx_int.h b/vp8/encoder/onyx_int.h index a66056dff..e2e6b367c 100644 --- a/vp8/encoder/onyx_int.h +++ b/vp8/encoder/onyx_int.h @@ -576,7 +576,6 @@ typedef struct // multithread data int * mt_current_mb_col; int mt_sync_range; - int processor_core_count; int b_multi_threaded; int encoding_thread_count; |