From 297b27655eaf4a0cfd097b2ae94add4b19fed9eb Mon Sep 17 00:00:00 2001 From: Attila Nagy Date: Fri, 25 Mar 2011 12:53:03 +0200 Subject: Runtime detection of available processor cores. Detect the number of available cores and limit the thread allocation accordingly. On decoder side limit the number of threads to the max number of token partition. Core detetction works on Windows and Posix platforms, which define _SC_NPROCESSORS_ONLN or _SC_NPROC_ONLN. Change-Id: I76cbe37c18d3b8035e508b7a1795577674efc078 --- vp8/decoder/threading.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'vp8/decoder') diff --git a/vp8/decoder/threading.c b/vp8/decoder/threading.c index 3d9d428ef..4cc7f534d 100644 --- a/vp8/decoder/threading.c +++ b/vp8/decoder/threading.c @@ -429,12 +429,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)); -- cgit v1.2.3