PDA

View Full Version : How I detect a Multi-Threading or Dual Core CPU capable ?


=A=RGOS
29th March 2007, 08:35
Hello,

I don't find on google a source code compatible with AMD and Intel for detect the presence of dual core / multithreading capable CPU.

If your are a response, I will thank very much.

Bye .

akupenguin
29th March 2007, 09:19
int x264_cpu_num_processors( void )
{
#if defined(WIN32)
return pthread_num_processors_np();

#elif defined(SYS_LINUX)
unsigned int bit;
int np;
cpu_set_t aff;
memset( &aff, 0, sizeof(aff) );
sched_getaffinity( 0, sizeof(aff), &aff );
for( np = 0, bit = 0; bit < 8*sizeof(aff); bit++ )
np += (((uint8_t *)&aff)[bit / 8] >> (bit % 8)) & 1;
return np;

#elif defined(SYS_BEOS)
system_info info;
get_system_info( &info );
return info.cpu_count;

#elif defined(SYS_MACOSX)
int np;
size_t length = sizeof( np );
if( sysctlbyname("hw.ncpu", &np, &length, NULL, 0) )
np = 1;
return np;

#else
return 1;
#endif
}

JohnnyMalaria
29th March 2007, 18:15
pthread_num_processors_np requires the Pthreads-w32 library.

For Windows, you can use a native Windows function:

GetSystemInfo to get the number of CPUs (logical) - see http://msdn2.microsoft.com/en-us/library/ms724381.aspx

Generically, you can use the CPUID function to find out specific information on a CPU. With multiple CPUs (as opposed to multicores), you'll have to assign a thread specifically to each CPU and call the CPUID function - unless you are willing to assume that all the CPUs are the same.

=A=RGOS
29th March 2007, 20:23
Many thank for your response.
The first source code of x264 work correctly.

@JohnnyMalaria : For my use the first code is correct because it's portable.

bye.