report number of cpu's
This commit is contained in:
parent
2a0a769ebe
commit
9b6453675a
|
|
@ -28,6 +28,9 @@ aux-display pandagl
|
|||
#if $[HAVE_DX8]
|
||||
aux-display pandadx8
|
||||
#endif
|
||||
#if $[HAVE_TINYDISPLAY]
|
||||
aux-display tinydisplay
|
||||
#endif
|
||||
|
||||
# The egg loader is handy to have available by default. This allows
|
||||
# clients to load egg files. (The bam loader is built-in so bam files
|
||||
|
|
|
|||
|
|
@ -119,6 +119,9 @@ DisplayInformation() {
|
|||
_maximum_cpu_frequency = 0;
|
||||
_current_cpu_frequency = 0;
|
||||
|
||||
_num_cpu_cores = 0;
|
||||
_num_logical_cpus = 0;
|
||||
|
||||
_get_memory_information_function = 0;
|
||||
_cpu_time_function = 0;
|
||||
_update_cpu_frequency_function = 0;
|
||||
|
|
@ -667,6 +670,30 @@ update_cpu_frequency(int processor_number) {
|
|||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: DisplayInformation::get_num_cpu_cores
|
||||
// Access: Published
|
||||
// Description: Returns the number of individual CPU cores in the
|
||||
// system, or 0 if this number is not available. A
|
||||
// hyperthreaded CPU counts once here.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
int DisplayInformation::
|
||||
get_num_cpu_cores() {
|
||||
return _num_cpu_cores;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: DisplayInformation::get_num_logical_cpus
|
||||
// Access: Published
|
||||
// Description: Returns the number of logical CPU's in the
|
||||
// system, or 0 if this number is not available. A
|
||||
// hyperthreaded CPU counts as two or more here.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
int DisplayInformation::
|
||||
get_num_logical_cpus() {
|
||||
return _num_logical_cpus;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: DisplayInformation::get_os_version_major
|
||||
// Access: Published
|
||||
|
|
|
|||
|
|
@ -106,6 +106,9 @@ PUBLISHED:
|
|||
PN_uint64 get_current_cpu_frequency();
|
||||
void update_cpu_frequency(int processor_number);
|
||||
|
||||
int get_num_cpu_cores();
|
||||
int get_num_logical_cpus();
|
||||
|
||||
int get_os_version_major();
|
||||
int get_os_version_minor();
|
||||
int get_os_version_build();
|
||||
|
|
@ -164,6 +167,9 @@ public:
|
|||
|
||||
PN_uint64 _maximum_cpu_frequency;
|
||||
PN_uint64 _current_cpu_frequency;
|
||||
|
||||
int _num_cpu_cores;
|
||||
int _num_logical_cpus;
|
||||
|
||||
void (*_get_memory_information_function) (DisplayInformation *display_information);
|
||||
PN_uint64 (*_cpu_time_function) (void);
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
#include "config_windisplay.h"
|
||||
#include "displaySearchParameters.h"
|
||||
#include "dtool_config.h"
|
||||
#include "pbitops.h"
|
||||
|
||||
#include "psapi.h"
|
||||
#include "powrprof.h"
|
||||
|
|
@ -710,6 +711,70 @@ int update_cpu_frequency_function (int processor_number, DisplayInformation *dis
|
|||
return update;
|
||||
}
|
||||
|
||||
void
|
||||
count_number_of_cpus(DisplayInformation *display_information) {
|
||||
int num_cpu_cores = 0;
|
||||
int num_logical_cpus = 0;
|
||||
|
||||
// Get a pointer to the GetLogicalProcessorInformation function.
|
||||
typedef BOOL (WINAPI *LPFN_GLPI)(PSYSTEM_LOGICAL_PROCESSOR_INFORMATION,
|
||||
PDWORD);
|
||||
LPFN_GLPI glpi;
|
||||
glpi = (LPFN_GLPI)GetProcAddress(GetModuleHandle(TEXT("kernel32")),
|
||||
"GetLogicalProcessorInformation");
|
||||
if (glpi == NULL) {
|
||||
windisplay_cat.info()
|
||||
<< "GetLogicalProcessorInformation is not supported.\n";
|
||||
return;
|
||||
}
|
||||
|
||||
// Allocate a buffer to hold the result of the
|
||||
// GetLogicalProcessorInformation call.
|
||||
PSYSTEM_LOGICAL_PROCESSOR_INFORMATION buffer = NULL;
|
||||
DWORD buffer_length = 0;
|
||||
DWORD rc = glpi(buffer, &buffer_length);
|
||||
while (!rc) {
|
||||
if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
|
||||
if (buffer != NULL) {
|
||||
PANDA_FREE_ARRAY(buffer);
|
||||
}
|
||||
|
||||
buffer = (PSYSTEM_LOGICAL_PROCESSOR_INFORMATION)PANDA_MALLOC_ARRAY(buffer_length);
|
||||
nassertv(buffer != NULL);
|
||||
} else {
|
||||
windisplay_cat.info()
|
||||
<< "GetLogicalProcessorInformation failed: " << GetLastError()
|
||||
<< "\n";
|
||||
return;
|
||||
}
|
||||
rc = glpi(buffer, &buffer_length);
|
||||
}
|
||||
|
||||
// Now get the results.
|
||||
PSYSTEM_LOGICAL_PROCESSOR_INFORMATION ptr = buffer;
|
||||
PSYSTEM_LOGICAL_PROCESSOR_INFORMATION end = (PSYSTEM_LOGICAL_PROCESSOR_INFORMATION)((char *)buffer + buffer_length);
|
||||
|
||||
while (ptr < end) {
|
||||
if (ptr->Relationship == RelationProcessorCore) {
|
||||
num_cpu_cores++;
|
||||
|
||||
// A hyperthreaded core supplies more than one logical processor.
|
||||
num_logical_cpus += count_bits_in_word((PN_uint64)(ptr->ProcessorMask));
|
||||
}
|
||||
++ptr;
|
||||
}
|
||||
|
||||
PANDA_FREE_ARRAY(buffer);
|
||||
|
||||
windisplay_cat.info()
|
||||
<< num_cpu_cores << " CPU cores, with "
|
||||
<< num_logical_cpus << " logical processors.\n";
|
||||
|
||||
display_information->_num_cpu_cores = num_cpu_cores;
|
||||
display_information->_num_logical_cpus = num_logical_cpus;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: WinGraphicsPipe::Constructor
|
||||
// Access: Public
|
||||
|
|
@ -851,6 +916,9 @@ WinGraphicsPipe() {
|
|||
|
||||
windisplay_cat.info() << "end CPU ID\n";
|
||||
|
||||
// Number of CPU's
|
||||
count_number_of_cpus(_display_information);
|
||||
|
||||
OSVERSIONINFO version_info;
|
||||
|
||||
version_info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
|
||||
|
|
|
|||
Loading…
Reference in New Issue