Skip to content

Commit c442fbc

Browse files
committed
Cherrypick LLProcessor cleanup from 57d4237
Signed-off-by: Rye <[email protected]>
1 parent 51e1751 commit c442fbc

File tree

1 file changed

+48
-17
lines changed

1 file changed

+48
-17
lines changed

indra/llcommon/llprocessor.cpp

Lines changed: 48 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,20 @@ class LLProcessorInfoDarwinImpl : public LLProcessorInfoImpl
808808
};
809809

810810
#elif LL_LINUX
811+
812+
// *NOTE:Mani - eww, macros! srry.
813+
#define LLPI_SET_INFO_STRING(llpi_id, cpuinfo_id) \
814+
if (!cpuinfo[cpuinfo_id].empty()) \
815+
{ setInfo(llpi_id, cpuinfo[cpuinfo_id]);}
816+
817+
#define LLPI_SET_INFO_INT(llpi_id, cpuinfo_id) \
818+
{\
819+
S32 result; \
820+
if (!cpuinfo[cpuinfo_id].empty() \
821+
&& LLStringUtil::convertToS32(cpuinfo[cpuinfo_id], result)) \
822+
{ setInfo(llpi_id, result);} \
823+
}
824+
811825
const char CPUINFO_FILE[] = "/proc/cpuinfo";
812826

813827
class LLProcessorInfoLinuxImpl : public LLProcessorInfoImpl
@@ -819,8 +833,32 @@ class LLProcessorInfoLinuxImpl : public LLProcessorInfoImpl
819833
}
820834

821835
virtual ~LLProcessorInfoLinuxImpl() {}
836+
822837
private:
823838

839+
F64 getCPUMaxMHZ()
840+
{
841+
// Nicky: We just look into cpu0. In theory we could iterate over all cores
842+
// "/sys/devices/system/cpu/cpu*/cpufreq/cpuinfo_max_freq"
843+
// But those should not fluctuate that much?
844+
std::ifstream fIn { "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq" };
845+
846+
if( !fIn.is_open() )
847+
return 0.0;
848+
849+
std::string strLine;
850+
fIn >> strLine;
851+
if( strLine.empty() )
852+
return 0.0l;
853+
854+
F64 mhz {};
855+
if( !LLStringUtil::convertToF64(strLine, mhz ) )
856+
return 0.0;
857+
858+
mhz = mhz / 1000.0;
859+
return mhz;
860+
}
861+
824862
void get_proc_cpuinfo()
825863
{
826864
std::map< std::string, std::string > cpuinfo;
@@ -855,24 +893,17 @@ class LLProcessorInfoLinuxImpl : public LLProcessorInfoImpl
855893
}
856894
# if LL_X86
857895

858-
// *NOTE:Mani - eww, macros! srry.
859-
#define LLPI_SET_INFO_STRING(llpi_id, cpuinfo_id) \
860-
if (!cpuinfo[cpuinfo_id].empty()) \
861-
{ setInfo(llpi_id, cpuinfo[cpuinfo_id]);}
862-
863-
#define LLPI_SET_INFO_INT(llpi_id, cpuinfo_id) \
864-
{\
865-
S32 result; \
866-
if (!cpuinfo[cpuinfo_id].empty() \
867-
&& LLStringUtil::convertToS32(cpuinfo[cpuinfo_id], result)) \
868-
{ setInfo(llpi_id, result);} \
896+
F64 mhzFromSys = getCPUMaxMHZ();
897+
F64 mhzFromProc {};
898+
if( !LLStringUtil::convertToF64(cpuinfo["cpu mhz"], mhzFromProc ) )
899+
mhzFromProc = 0.0;
900+
if (mhzFromSys > 1.0 && mhzFromSys > mhzFromProc )
901+
{
902+
setInfo( eFrequency, mhzFromSys );
869903
}
870-
871-
F64 mhz;
872-
if (LLStringUtil::convertToF64(cpuinfo["cpu mhz"], mhz)
873-
&& 200.0 < mhz && mhz < 10000.0)
904+
else if ( 200.0 < mhzFromProc && mhzFromProc < 10000.0)
874905
{
875-
setInfo(eFrequency,(F64)(mhz));
906+
setInfo(eFrequency,(F64)(mhzFromProc));
876907
}
877908

878909
LLPI_SET_INFO_STRING(eBrandName, "model name");
@@ -882,7 +913,7 @@ class LLProcessorInfoLinuxImpl : public LLProcessorInfoImpl
882913
LLPI_SET_INFO_INT(eModel, "model");
883914

884915

885-
S32 family;
916+
S32 family{};
886917
if (!cpuinfo["cpu family"].empty()
887918
&& LLStringUtil::convertToS32(cpuinfo["cpu family"], family))
888919
{

0 commit comments

Comments
 (0)