in source/code/scxsystemlib/cpuproperties/cpupropertiesinstance.cpp [324:596]
void CpuPropertiesInstance::Update()
{
SCX_LOGTRACE(m_log, wstring(L"CpuPropertiesInstance update with cpuinfo"));
#if defined(linux)
#elif (defined(sun))
//
//Go to first kstat
//
m_deps->Lookup(cModul_Name, m_cpuInfoIndex, cInstancesNum);
//
//Count Of Logical Processors
//
unsigned int logicalProcessorsCount = 0;
//
//Find the kstat by m_chipid
//
scxulong uChipId;
if (!m_deps->TryGetValue(cAttrName_ChipID, uChipId))
{
throw SCXNotSupportedException(L"Chip Id not exist", SCXSRCLOCATION);
}
scxlong chipId = static_cast<scxlong>( uChipId );
//
//Get clock_MHz and current_clock_Hz
//
scxulong tmpNormSpeed = 0;
if (m_deps->TryGetValue(cAttrName_ClockMHz, tmpNormSpeed))
{
m_processorAttr.normSpeed = static_cast<unsigned short>(tmpNormSpeed);
scxulong tmpCurrentClockSpeed = 0;
if (m_deps->TryGetValue(cAttrName_CurrentClockHz, tmpCurrentClockSpeed))
{
m_processorAttr.currentClockSpeed = static_cast<unsigned int>((tmpCurrentClockSpeed) / cMhzLevel);
}
else
{
//
//NO current_clock_Hz means same as normSpeed.
//
m_processorAttr.currentClockSpeed = m_processorAttr.normSpeed;
}
}
//
//Get processor name and family
//
#if !defined(sparc)
//For x86 kstat provides the correct Intel family number
scxulong familyNum;
if (m_deps->TryGetValue(cAttrName_Family, familyNum))
{
m_processorAttr.family = familyNum;
}
//
// Get Manufacturer from the Vendor_id
//
wstring mfr;
SCX_LOGTRACE(m_log, wstring(L"CpuPropertiesInstance::Update TryGetStringValue ") + cAttrName_Vendor);
if (m_deps->TryGetStringValue(cAttrName_Vendor, mfr))
{
m_processorAttr.manufacturer = mfr;
}
//
// Get Stepping info
//
wstring steppingInfo;
SCX_LOGTRACE(m_log, wstring(L"CpuPropertiesInstance::Update TryGetStringValue ") + cAttrName_Stepping);
if (m_deps->TryGetStringValue(cAttrName_Stepping, steppingInfo))
{
m_processorAttr.stepping = steppingInfo;
}
//
// Get Version info
//
wstring model;
SCX_LOGTRACE(m_log, wstring(L"CpuPropertiesInstance::Update TryGetStringValue ") + cAttrName_Model);
if (m_deps->TryGetStringValue(cAttrName_Model, model))
{
std::wstringstream version(std::wstringstream::out);
version << L"Model " << model << L" Stepping " << steppingInfo;
m_processorAttr.version = version.str();
}
#endif
wstring familyName;
#if PF_Major > 5 || PF_MINOR >= 10
if (m_deps->TryGetStringValue(cAttrName_Brand, familyName))
#else
if (m_deps->TryGetStringValue(cAttrName_Implementation, familyName))
#endif
{
m_processorAttr.name = familyName;
#if defined(sparc)
m_processorAttr.family = cFamily_Sparc_Value[0];
for (int i =1; i< cFamily_Sparc_Array_Length; i++)
{
if (cFamily_Sparc_Name[i] == familyName)
{
m_processorAttr.family = cFamily_Sparc_Value[i];
break;
}
}
#endif
}
#if defined(sparc)
//
//Get processor stepping by get "ver xxx" string in processor implementation information
//
wstring implementationInfo = L"";
if (m_deps->TryGetStringValue(cAttrName_Implementation, implementationInfo))
{
if (implementationInfo == L"")
{
m_processorAttr.stepping = L"";
}
else
{
//
//find "ver xxx" string
//
wstring strFindString(L"ver");
wstring::size_type strPos = implementationInfo.find(strFindString);
if (wstring::npos != strPos)
{
implementationInfo = implementationInfo.substr(strPos);
strFindString = L" ";
strPos = implementationInfo.find(strFindString);
if (wstring::npos != strPos)
{
strPos = implementationInfo.find(strFindString, strPos+1);
implementationInfo = implementationInfo.substr(0, strPos);
}
m_processorAttr.stepping = implementationInfo;
}
}
}
#endif
//
//Make cpu+id string to be a unique id.
//
wstringstream os;
os << "CPU " << chipId;
m_processorAttr.deviceID = os.str();
std::set<scxulong> coreid;
//
//get number Of Logical Processors count the chip_id
//
unsigned int cpuIndex =0;
for ( ; ; )
{
wstringstream cpuInfoName;
cpuInfoName << cModul_Name.c_str() << cpuIndex;
if (!m_deps->Lookup(cModul_Name, cpuInfoName.str(), cInstancesNum)) break;
scxulong uNewChipId = 0;
//
// Check ChipId. If chip_id not exist, give a default value 1.
//
if (!m_deps->TryGetValue(cAttrName_ChipID, uNewChipId))
{
logicalProcessorsCount++;
break;
}
scxlong newChipId = static_cast<scxlong>( uNewChipId );
//
// Check ChipId. If equal, number Of Logical Processors add 1.
//
if (newChipId == chipId)
{
logicalProcessorsCount++;
// Get Core Id
scxulong coreID;
if (m_deps->TryGetValue(cAttrName_CoreID, coreID))
{
coreid.insert(coreID);
}
}
cpuIndex++;
}
m_processorAttr.numberOfLogicalProcessors = logicalProcessorsCount;
if (coreid.size() > 0)
{
m_processorAttr.numberOfCores = coreid.size();
}
else
{
m_processorAttr.numberOfCores = m_processorAttr.numberOfLogicalProcessors;
}
#elif defined(aix)
SCX_LOGTRACE(m_log, wstring(L"Calling FillAttributes"));
if (!FillAttributes())
{
SCX_LOGERROR(m_log, L"FillAttributes failed.");
}
SCX_LOGTRACE(m_log, wstring(L"After FillAttributes"));
#elif defined(hpux)
m_processorAttr.cpuKey = GetId();
m_processorAttr.processorId = m_processorAttr.cpuKey;
m_processorAttr.deviceID = m_processorAttr.cpuKey;
unsigned int numberOfCoresperCPU = 0;
struct pst_processor psp[PST_MAX_PROCS] = { { 0 } };
wstring tmpPhysicalID;
int cpuTotal = pstat_getprocessor(psp, sizeof(struct pst_processor), PST_MAX_PROCS, 0);
if (-1 == cpuTotal)
{
SCX_LOGTRACE(m_log, L"pstat_getprocessor failed. errno " + errno);
throw SCXCoreLib::SCXInvalidStateException(L"pstat_getprocessor failed. errno " + errno, SCXSRCLOCATION);
}
#if (PF_MINOR >= 31)
for (unsigned int i= 0; i< cpuTotal; i++)
{
tmpPhysicalID = StrFrom(psp[i].psp_socket_id);
if (tmpPhysicalID == m_socketId)
{
numberOfCoresperCPU++;
}
}
m_processorAttr.numberOfCores = numberOfCoresperCPU;
m_processorAttr.numberOfLogicalProcessors = numberOfCoresperCPU;
#endif
int64_t cpuChipType ;
if ((cpuChipType = sysconf(_SC_CPU_CHIP_TYPE)) == -1)
{
static SCXCoreLib::LogSuppressor suppressor(SCXCoreLib::eError, SCXCoreLib::eInfo);
std::wstring msg = L"sysconf _SC_CPU_CHIP_TYPE failed. the errno is : " + errno;
SCXCoreLib::SCXLogSeverity severity(suppressor.GetSeverity(msg));
SCX_LOG(m_log, severity, msg);
throw SCXCoreLib::SCXErrnoException(L"sysconf _SC_CPU_CHIP_TYPE failed. errno ", errno, SCXSRCLOCATION);
}
else
{
/*---------------------------------
31 24 23 16 15 8 7 0
----------------------------------
| family | model | rev |number|
----------------------------------
*/
unsigned short stepping = (cpuChipType >> 8) & 0xFF;
m_processorAttr.stepping = StrFrom<int>(stepping);
unsigned short model = (cpuChipType >> 16) & 0xFF ;
std::wstringstream ssVersion(std::wstringstream::out);
ssVersion << L"Model " << model << L" Stepping " << stepping;
m_processorAttr.version = ssVersion.str(); //Model 2 Stepping 12
}
#endif
}