llsys.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /**
  2. * @file llsys.h
  3. * @brief System information debugging classes.
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewergpl$
  6. *
  7. * Copyright (c) 2001-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #ifndef LL_SYS_H
  33. #define LL_SYS_H
  34. #include <string>
  35. #include "llsingleton.h"
  36. class LLProcessorInfo;
  37. class LLSD;
  38. class LLOSInfo final : public LLSingleton<LLOSInfo>
  39. {
  40. friend class LLSingleton<LLOSInfo>;
  41. protected:
  42. LOG_CLASS(LLOSInfo);
  43. LLOSInfo();
  44. ~LLOSInfo() override;
  45. public:
  46. LL_INLINE const std::string& getOSString() const
  47. {
  48. return mOSString;
  49. }
  50. LL_INLINE const std::string& getOSStringSimple() const
  51. {
  52. return mOSStringSimple;
  53. }
  54. LL_INLINE const std::string& getOSVersionString() const
  55. {
  56. return mOSVersionString;
  57. }
  58. #if LL_LINUX
  59. // Returns the major version number for the Linux kernel. HB
  60. LL_INLINE U32 getKernelVersionMajor() const
  61. {
  62. return mVersionMajor;
  63. }
  64. // Returns the mminor version number for the Linux kernel. HB
  65. LL_INLINE U32 getKernelVersionMinor() const
  66. {
  67. return mVersionMinor;
  68. }
  69. #elif LL_WINDOWS
  70. // When ran under Wine, this method returns the Wine version string. HB
  71. LL_INLINE const std::string& getWineVersionString() const
  72. {
  73. return mWineVersionString;
  74. }
  75. // Returns true when the viewer is running under Wine. HB
  76. LL_INLINE bool underWine() const
  77. {
  78. return mUnderWine;
  79. }
  80. // Windows 10 and later got an inaccurate Sleep() call by default, which
  81. // we change/configure for a 1ms resolution when we detect it. This method
  82. // returns true in such cases (so that the default inaccurate timer can be
  83. // restored on viewer exit). HB
  84. LL_INLINE bool inaccurateSleep() const
  85. {
  86. return mInaccurateSleep;
  87. }
  88. #endif
  89. // Returns 1 on success, 0 or -1 on failure to get a node Id from the MAC
  90. // address of the network interface. On success, the six bytes of this
  91. // address are copied into the unsigned char buffer pointed to by node_id
  92. // (which must therefore point onto a valid and adequately sized buffer).
  93. // I moved this method here from LLUUID, since the latter should not be
  94. // OS-dependent and got nothing to do with networking... This method would
  95. // actually be better as a function in llnet.h/cpp, but then we would need
  96. // to make llcommon dependent on llmessage (because LLUUID and llrand need
  97. // it), so it finally landed here... HB
  98. static S32 getNodeID(unsigned char* node_id);
  99. private:
  100. // OS-dependent code.
  101. static S32 getOSNodeID(unsigned char* node_id);
  102. private:
  103. std::string mOSString;
  104. std::string mOSStringSimple;
  105. std::string mOSVersionString;
  106. #if LL_LINUX
  107. U32 mVersionMajor;
  108. U32 mVersionMinor;
  109. #elif LL_WINDOWS
  110. std::string mWineVersionString;
  111. bool mUnderWine;
  112. bool mInaccurateSleep;
  113. #endif
  114. };
  115. class LLCPUInfo final : public LLSingleton<LLCPUInfo>
  116. {
  117. friend class LLSingleton<LLCPUInfo>;
  118. protected:
  119. LOG_CLASS(LLCPUInfo);
  120. LLCPUInfo();
  121. ~LLCPUInfo() override;
  122. public:
  123. // When passed update_freq is true, checks for the affected core frequency,
  124. // if possible, to try and give a better stat in the returned CPU string).
  125. // HB
  126. std::string getCPUString(bool update_freq = false);
  127. // Returns the CPU family (e.g."AMD K8" or "Intel Pentium Pro").
  128. LL_INLINE const std::string& getFamily() const { return mFamily; }
  129. LL_INLINE bool hasSSE2() const { return mHasSSE2; }
  130. LL_INLINE bool hasSSE3() const { return mHasSSE3; }
  131. LL_INLINE bool hasSSE3S() const { return mHasSSE3S; }
  132. LL_INLINE bool hasSSE41() const { return mHasSSE41; }
  133. LL_INLINE bool hasSSE42() const { return mHasSSE42; }
  134. LL_INLINE bool hasSSE4a() const { return mHasSSE4a; }
  135. LLSD getSSEVersions() const;
  136. LL_INLINE F64 getMHz() const { return mCPUMHz; }
  137. std::string getInfo() const;
  138. LL_INLINE U32 getPhysicalCores() { return mPhysicalCores; }
  139. LL_INLINE U32 getVirtualCores() { return mVirtualCores; }
  140. // Returns the maximum number of child threads the process needs to launch
  141. // to saturate all the available cores. This is in excess of cores that
  142. // should be reserved for the main program render loop and any OpenGL
  143. // threaded driver. A minimum concurrency of 1 thread is always returned.
  144. LL_INLINE U32 getMaxThreadConcurrency() { return mMaxChildThreads; }
  145. // Returns the CPU single-core performance relatively to a 9700K @ 5GHz
  146. // as a factor (1.f = same perfs, larger factor = better perfs).
  147. F32 benchmarkFactor();
  148. // The following methods are no-operations under macOS (which does not
  149. // provide a way to set threads affinity). HB
  150. // Emits its own set of llinfos and llwarns, so no need for a returned
  151. // success boolean.
  152. static void setMainThreadCPUAffinifty(U32 cpu_mask);
  153. // Returns 1 when successful, 0 when failed, -1 when waiting for main
  154. // thread affinity to be set (i.e. when it should be retried). When a
  155. // name is passed, the method warns whenever it could not set the thread
  156. // affinity.
  157. static S32 setThreadCPUAffinity(const char* name = NULL);
  158. private:
  159. // Checks for the affected core frequency (when possible) and returns the
  160. // delta in MHz compared with the frequency cached in mCPUMHz (the latter
  161. // being updated accordingly by this method). NOTE: for now we reject
  162. // negative deltas (i.e. we only account for the max turbo frequency, which
  163. // is normally the one used during rendering). HB
  164. S32 affectedCoreFreqDelta();
  165. private:
  166. LLProcessorInfo* mImpl;
  167. std::string mFamily;
  168. std::string mCPUString;
  169. F64 mCPUMHz;
  170. U32 mPhysicalCores;
  171. U32 mVirtualCores;
  172. U32 mMaxChildThreads;
  173. bool mHasSSE2;
  174. bool mHasSSE3;
  175. bool mHasSSE3S;
  176. bool mHasSSE41;
  177. bool mHasSSE42;
  178. bool mHasSSE4a;
  179. static U32 sMainThreadAffinityMask;
  180. static bool sMainThreadAffinitySet;
  181. };
  182. #endif // LL_LLSYS_H