@@ -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+
811825const char CPUINFO_FILE[] = " /proc/cpuinfo" ;
812826
813827class LLProcessorInfoLinuxImpl : public LLProcessorInfoImpl
@@ -819,8 +833,32 @@ class LLProcessorInfoLinuxImpl : public LLProcessorInfoImpl
819833 }
820834
821835 virtual ~LLProcessorInfoLinuxImpl () {}
836+
822837private:
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