Gromacs  2020.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Functions
gmx::anonymous_namespace{cpuinfo.cpp} Namespace Reference

Classes

struct  ApicIdLayout
 The layout of the bits in the APIC ID. More...
 

Functions

void trimString (std::string *s)
 Remove initial and trailing whitespace from string. More...
 
int executeX86CpuID (unsigned int level, unsigned int ecxval, unsigned int *eax, unsigned int *ebx, unsigned int *ecx, unsigned int *edx)
 execute x86 cpuid instructions with custom level and extended level More...
 
CpuInfo::Vendor detectX86Vendor ()
 Detect x86 vendors by using the cpuid assembly instructions. More...
 
void setFeatureFromBit (std::set< CpuInfo::Feature > *featureSet, CpuInfo::Feature feature, unsigned int registerValue, unsigned char bit)
 Simple utility function to set/clear feature in a set. More...
 
void detectX86Features (std::string *brand, int *family, int *model, int *stepping, std::set< CpuInfo::Feature > *features)
 Process x86 cpuinfo features that are common to Intel and AMD CPUs. More...
 
std::vector< unsigned int > detectX86ApicIDs (bool haveX2Apic)
 Return a vector with x86 APIC IDs for all threads. More...
 
void renumberIndex (std::vector< unsigned int > *v)
 Utility to renumber indices extracted from APIC IDs. More...
 
ApicIdLayout detectX2ApicIdLayout ()
 Detect the APIC ID layout for x2APIC.
 
ApicIdLayout detectAmdApicIdLayout (unsigned int maxExtLevel)
 Detect the APIC ID layout for standard APIC or xAPIC on AMD. More...
 
std::vector
< CpuInfo::LogicalProcessor
detectX86LogicalProcessors ()
 Try to detect basic CPU topology information using x86 cpuid. More...
 
std::map< std::string,
std::string > 
parseProcCpuInfo ()
 Parse /proc/cpuinfo into a simple string map. More...
 
CpuInfo::Vendor detectProcCpuInfoVendor (const std::map< std::string, std::string > &cpuInfo)
 Try to detect vendor from /proc/cpuinfo. More...
 
void detectProcCpuInfoIbm (const std::map< std::string, std::string > &cpuInfo, std::string *brand, std::set< CpuInfo::Feature > *features)
 Detect IBM processor name and features from /proc/cpuinfo. More...
 
void detectProcCpuInfoArm (const std::map< std::string, std::string > &cpuInfo, std::string *brand, int *family, int *model, int *stepping, std::set< CpuInfo::Feature > *features)
 Detect ARM processor name and features from /proc/cpuinfo. More...
 
void detectProcCpuInfo (CpuInfo::Vendor *vendor, std::string *brand, int *family, int *model, int *stepping, std::set< CpuInfo::Feature > *features)
 Try to detect vendor, cpu and features from /proc/cpuinfo. More...
 

Function Documentation

ApicIdLayout gmx::anonymous_namespace{cpuinfo.cpp}::detectAmdApicIdLayout ( unsigned int  maxExtLevel)

Detect the APIC ID layout for standard APIC or xAPIC on AMD.

Parameters
[in]maxExtLevelThe largest CPUID extended function input value supported by the processor implementation
void gmx::anonymous_namespace{cpuinfo.cpp}::detectProcCpuInfo ( CpuInfo::Vendor *  vendor,
std::string *  brand,
int *  family,
int *  model,
int *  stepping,
std::set< CpuInfo::Feature > *  features 
)

Try to detect vendor, cpu and features from /proc/cpuinfo.

Parameters
[out]vendorDetected hardware vendor
[out]brandString where to write the brand string
[out]familyMajor version of processor
[out]modelMiddle version of processor
[out]steppingMinor version of processor
[out]featuresFeature set where supported features are inserted

This routine reads the /proc/cpuinfo file into a map and calls subroutines that attempt to parse by matching keys and values to known strings. It is much more fragile than our x86 detection, but it does not depend on specific system calls, intrinsics or assembly instructions.

void gmx::anonymous_namespace{cpuinfo.cpp}::detectProcCpuInfoArm ( const std::map< std::string, std::string > &  cpuInfo,
std::string *  brand,
int *  family,
int *  model,
int *  stepping,
std::set< CpuInfo::Feature > *  features 
)

Detect ARM processor name and features from /proc/cpuinfo.

Parameters
cpuInfoMap returned from parseProcCpuinfo()
[out]brandString where to write the brand string
[out]familyMajor version of processor
[out]modelMiddle version of processor
[out]steppingMinor version of processor
[out]featuresFeature set where supported features are inserted

This routine tries to match a few common labels in /proc/cpuinfo to see if we can find the processor name and features. It is likely fragile.

void gmx::anonymous_namespace{cpuinfo.cpp}::detectProcCpuInfoIbm ( const std::map< std::string, std::string > &  cpuInfo,
std::string *  brand,
std::set< CpuInfo::Feature > *  features 
)

Detect IBM processor name and features from /proc/cpuinfo.

Parameters
cpuInfoMap returned from parseProcCpuinfo()
[out]brandString where to write the brand string
[out]featuresFeature set where supported features are inserted

This routine tries to match a few common labels in /proc/cpuinfo to see if we can find the processor name and features. It is likely fragile.

CpuInfo::Vendor gmx::anonymous_namespace{cpuinfo.cpp}::detectProcCpuInfoVendor ( const std::map< std::string, std::string > &  cpuInfo)

Try to detect vendor from /proc/cpuinfo.

Parameters
cpuInfoMap returned from parseProcCpuinfo()

This routine tries to match a few common labels in /proc/cpuinfo to see if they begin with the name of a standard vendor. If the file cannot be read or if no match is found, we return gmx::CpuInfo::Vendor::Unknown.

std::vector<unsigned int> gmx::anonymous_namespace{cpuinfo.cpp}::detectX86ApicIDs ( bool  haveX2Apic)

Return a vector with x86 APIC IDs for all threads.

Parameters
haveX2ApicTrue if the processors supports x2APIC, otherwise vanilla APIC.
Returns
A new std::vector of unsigned integer APIC IDs, one for each logical processor in the system.
void gmx::anonymous_namespace{cpuinfo.cpp}::detectX86Features ( std::string *  brand,
int *  family,
int *  model,
int *  stepping,
std::set< CpuInfo::Feature > *  features 
)

Process x86 cpuinfo features that are common to Intel and AMD CPUs.

Parameters
[out]brandString where to write the x86 brand string
[out]familyMajor version of processor
[out]modelMiddle version of processor
[out]steppingMinor version of processor
[out]featuresFeature set where supported features are inserted
std::vector<CpuInfo::LogicalProcessor> gmx::anonymous_namespace{cpuinfo.cpp}::detectX86LogicalProcessors ( )

Try to detect basic CPU topology information using x86 cpuid.

If x2APIC support is present, this is our first choice, otherwise we attempt to use old vanilla APIC.

Returns
A new vector of entries with socket, core, hwthread information for each logical processor.
CpuInfo::Vendor gmx::anonymous_namespace{cpuinfo.cpp}::detectX86Vendor ( )

Detect x86 vendors by using the cpuid assembly instructions.

If support for the cpuid instruction is present, we check for Intel, AMD or Hygon vendors

Returns
gmx::CpuInfo::Vendor::Intel, gmx::CpuInfo::Vendor::Amd, gmx::CpuInfl::Vendor::Hygon, . If neither Intel, Amd nor Hygon can be identified, or if the code fails to execute, gmx::CpuInfo::Vendor::Unknown is returned.
int gmx::anonymous_namespace{cpuinfo.cpp}::executeX86CpuID ( unsigned int  level,
unsigned int  ecxval,
unsigned int *  eax,
unsigned int *  ebx,
unsigned int *  ecx,
unsigned int *  edx 
)

execute x86 cpuid instructions with custom level and extended level

Parameters
levelThe main cpuid level (input argument for eax register)
ecxvalExtended level (input argument for ecx register)
eaxOutput in eax register
ebxOutput in ebx register
ecxOutput in ecx register
edxOutput in edx register
Returns
0 on success, or non-zero if the instruction could not execute.
std::map<std::string, std::string> gmx::anonymous_namespace{cpuinfo.cpp}::parseProcCpuInfo ( )

Parse /proc/cpuinfo into a simple string map.

This routine will read the contents of /proc/cpuinfo, and for each line that is not empty we will assign the (trimmed) string to the right of the colon as a key, and the left-hand side as the value in the map. For multi-processor systems where lines are repeated the latter lines will overwrite the first occurrence.

Returns
New map with the contents. If the file is not available, the returned map will be empty.
void gmx::anonymous_namespace{cpuinfo.cpp}::renumberIndex ( std::vector< unsigned int > *  v)

Utility to renumber indices extracted from APIC IDs.

Parameters
vVector with unsigned integer indices

This routine returns the number of unique different elements found in the vector, and renumbers these starting from 0. For example, the vector {0,1,2,8,9,10,8,9,10,0,1,2} will be rewritten to {0,1,2,3,4,5,3,4,5,0,1,2}, and it returns 6 for the number of unique elements.

void gmx::anonymous_namespace{cpuinfo.cpp}::setFeatureFromBit ( std::set< CpuInfo::Feature > *  featureSet,
CpuInfo::Feature  feature,
unsigned int  registerValue,
unsigned char  bit 
)

Simple utility function to set/clear feature in a set.

Parameters
featureSetPointer to the feature set to update
featureThe specific feature to set/clear
registerValueRegister value (returned from cpuid)
bitBit to check in registerValue. The feature will be added to the featureSet if this bit is set.
Note
Nothing is done if the bit is not set. In particular, this will not erase anything if the feature already exists in the set.
void gmx::anonymous_namespace{cpuinfo.cpp}::trimString ( std::string *  s)

Remove initial and trailing whitespace from string.

Parameters
sPointer to string where whitespace will be removed