Commit 9e9a869a authored by Loren Merritt's avatar Loren Merritt

--threads=auto to detect number of cpus


git-svn-id: svn://svn.videolan.org/x264/trunk@543 df754926-b1dd-0310-bc7b-ec298dee348c
parent 0b07708c
...@@ -117,7 +117,7 @@ fprofiled: ...@@ -117,7 +117,7 @@ fprofiled:
mv config.mak config.mak2 mv config.mak config.mak2
sed -e 's/CFLAGS.*/& -fprofile-generate/; s/LDFLAGS.*/& -fprofile-generate/' config.mak2 > config.mak sed -e 's/CFLAGS.*/& -fprofile-generate/; s/LDFLAGS.*/& -fprofile-generate/' config.mak2 > config.mak
$(MAKE) x264$(EXE) $(MAKE) x264$(EXE)
$(foreach V, $(VIDS), $(foreach I, 0 1 2, ./x264$(EXE) $(OPT$I) $(V) --progress -o $(DEVNULL) ;)) $(foreach V, $(VIDS), $(foreach I, 0 1 2, ./x264$(EXE) $(OPT$I) $(V) --progress --threads auto -o $(DEVNULL) ;))
rm -f $(SRC2:%.c=%.o) rm -f $(SRC2:%.c=%.o)
sed -e 's/CFLAGS.*/& -fprofile-use/; s/LDFLAGS.*/& -fprofile-use/' config.mak2 > config.mak sed -e 's/CFLAGS.*/& -fprofile-use/; s/LDFLAGS.*/& -fprofile-use/' config.mak2 > config.mak
$(MAKE) $(MAKE)
......
...@@ -200,7 +200,12 @@ int x264_param_parse( x264_param_t *p, const char *name, const char *value ) ...@@ -200,7 +200,12 @@ int x264_param_parse( x264_param_t *p, const char *name, const char *value )
OPT("asm") OPT("asm")
p->cpu = atobool(value) ? x264_cpu_detect() : 0; p->cpu = atobool(value) ? x264_cpu_detect() : 0;
OPT("threads") OPT("threads")
p->i_threads = atoi(value); {
if( !strcmp(value, "auto") )
p->i_threads = 0;
else
p->i_threads = atoi(value);
}
OPT("level") OPT("level")
{ {
if( atof(value) < 6 ) if( atof(value) < 6 )
......
...@@ -21,6 +21,11 @@ ...@@ -21,6 +21,11 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/ *****************************************************************************/
#if defined(HAVE_PTHREAD) && defined(SYS_LINUX)
#define _GNU_SOURCE
#include <sched.h>
#endif
#include <string.h> #include <string.h>
#include "common.h" #include "common.h"
...@@ -143,3 +148,29 @@ void x264_cpu_restore( uint32_t cpu ) ...@@ -143,3 +148,29 @@ void x264_cpu_restore( uint32_t cpu )
} }
#endif #endif
#if defined(HAVE_PTHREAD) && ( defined(SYS_LINUX) || defined(WIN32) )
int x264_cpu_num_processors( void )
{
int np;
#if defined(WIN32)
uint32_t p_aff, s_aff;
GetProcessAffinityMask( GetCurrentProcess(), &p_aff, &s_aff );
#else
uint64_t p_aff;
sched_getaffinity( 0, sizeof(p_aff), (cpu_set_t*)&p_aff );
#endif
for( np = 0; p_aff != 0; p_aff >>= 1 )
np += p_aff&1;
return np;
}
#else
int x264_cpu_num_processors( void )
{
return 1;
}
#endif
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#define _CPU_H 1 #define _CPU_H 1
uint32_t x264_cpu_detect( void ); uint32_t x264_cpu_detect( void );
int x264_cpu_num_processors( void );
/* probably MMX(EXT) centric but .... */ /* probably MMX(EXT) centric but .... */
void x264_cpu_restore( uint32_t cpu ); void x264_cpu_restore( uint32_t cpu );
......
...@@ -331,6 +331,8 @@ static int x264_validate_parameters( x264_t *h ) ...@@ -331,6 +331,8 @@ static int x264_validate_parameters( x264_t *h )
return -1; return -1;
} }
if( h->param.i_threads == 0 )
h->param.i_threads = x264_cpu_num_processors();
h->param.i_threads = x264_clip3( h->param.i_threads, 1, X264_SLICE_MAX ); h->param.i_threads = x264_clip3( h->param.i_threads, 1, X264_SLICE_MAX );
h->param.i_threads = X264_MIN( h->param.i_threads, (h->param.i_height + 15) / 16 ); h->param.i_threads = X264_MIN( h->param.i_threads, (h->param.i_height + 15) / 16 );
#ifndef HAVE_PTHREAD #ifndef HAVE_PTHREAD
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment