diff options
Diffstat (limited to 'xbmc/utils/CPUInfo.h')
| -rw-r--r-- | xbmc/utils/CPUInfo.h | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/xbmc/utils/CPUInfo.h b/xbmc/utils/CPUInfo.h new file mode 100644 index 0000000..473402d --- /dev/null +++ b/xbmc/utils/CPUInfo.h | |||
| @@ -0,0 +1,120 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2005-2018 Team Kodi | ||
| 3 | * This file is part of Kodi - https://kodi.tv | ||
| 4 | * | ||
| 5 | * SPDX-License-Identifier: GPL-2.0-or-later | ||
| 6 | * See LICENSES/README.md for more information. | ||
| 7 | */ | ||
| 8 | |||
| 9 | #pragma once | ||
| 10 | |||
| 11 | #include "threads/SystemClock.h" | ||
| 12 | #include "utils/Temperature.h" | ||
| 13 | |||
| 14 | #include <memory> | ||
| 15 | #include <string> | ||
| 16 | #include <vector> | ||
| 17 | |||
| 18 | enum CpuFeature | ||
| 19 | { | ||
| 20 | CPU_FEATURE_MMX = 1 << 0, | ||
| 21 | CPU_FEATURE_MMX2 = 1 << 1, | ||
| 22 | CPU_FEATURE_SSE = 1 << 2, | ||
| 23 | CPU_FEATURE_SSE2 = 1 << 3, | ||
| 24 | CPU_FEATURE_SSE3 = 1 << 4, | ||
| 25 | CPU_FEATURE_SSSE3 = 1 << 5, | ||
| 26 | CPU_FEATURE_SSE4 = 1 << 6, | ||
| 27 | CPU_FEATURE_SSE42 = 1 << 7, | ||
| 28 | CPU_FEATURE_3DNOW = 1 << 8, | ||
| 29 | CPU_FEATURE_3DNOWEXT = 1 << 9, | ||
| 30 | CPU_FEATURE_ALTIVEC = 1 << 10, | ||
| 31 | CPU_FEATURE_NEON = 1 << 11, | ||
| 32 | }; | ||
| 33 | |||
| 34 | struct CoreInfo | ||
| 35 | { | ||
| 36 | int m_id = 0; | ||
| 37 | double m_usagePercent = 0.0; | ||
| 38 | std::size_t m_activeTime = 0; | ||
| 39 | std::size_t m_idleTime = 0; | ||
| 40 | std::size_t m_totalTime = 0; | ||
| 41 | }; | ||
| 42 | |||
| 43 | class CCPUInfo | ||
| 44 | { | ||
| 45 | public: | ||
| 46 | // Defines to help with calls to CPUID | ||
| 47 | const unsigned int CPUID_INFOTYPE_MANUFACTURER = 0x00000000; | ||
| 48 | const unsigned int CPUID_INFOTYPE_STANDARD = 0x00000001; | ||
| 49 | const unsigned int CPUID_INFOTYPE_EXTENDED_IMPLEMENTED = 0x80000000; | ||
| 50 | const unsigned int CPUID_INFOTYPE_EXTENDED = 0x80000001; | ||
| 51 | const unsigned int CPUID_INFOTYPE_PROCESSOR_1 = 0x80000002; | ||
| 52 | const unsigned int CPUID_INFOTYPE_PROCESSOR_2 = 0x80000003; | ||
| 53 | const unsigned int CPUID_INFOTYPE_PROCESSOR_3 = 0x80000004; | ||
| 54 | |||
| 55 | // Standard Features | ||
| 56 | // Bitmasks for the values returned by a call to cpuid with eax=0x00000001 | ||
| 57 | const unsigned int CPUID_00000001_ECX_SSE3 = (1 << 0); | ||
| 58 | const unsigned int CPUID_00000001_ECX_SSSE3 = (1 << 9); | ||
| 59 | const unsigned int CPUID_00000001_ECX_SSE4 = (1 << 19); | ||
| 60 | const unsigned int CPUID_00000001_ECX_SSE42 = (1 << 20); | ||
| 61 | |||
| 62 | const unsigned int CPUID_00000001_EDX_MMX = (1 << 23); | ||
| 63 | const unsigned int CPUID_00000001_EDX_SSE = (1 << 25); | ||
| 64 | const unsigned int CPUID_00000001_EDX_SSE2 = (1 << 26); | ||
| 65 | |||
| 66 | // Extended Features | ||
| 67 | // Bitmasks for the values returned by a call to cpuid with eax=0x80000001 | ||
| 68 | const unsigned int CPUID_80000001_EDX_MMX2 = (1 << 22); | ||
| 69 | const unsigned int CPUID_80000001_EDX_MMX = (1 << 23); | ||
| 70 | const unsigned int CPUID_80000001_EDX_3DNOWEXT = (1 << 30); | ||
| 71 | const unsigned int CPUID_80000001_EDX_3DNOW = (1 << 31); | ||
| 72 | |||
| 73 | // In milliseconds | ||
| 74 | const int MINIMUM_TIME_BETWEEN_READS{500}; | ||
| 75 | |||
| 76 | static std::shared_ptr<CCPUInfo> GetCPUInfo(); | ||
| 77 | |||
| 78 | virtual bool SupportsCPUUsage() const { return true; } | ||
| 79 | |||
| 80 | virtual int GetUsedPercentage() = 0; | ||
| 81 | virtual float GetCPUFrequency() = 0; | ||
| 82 | virtual bool GetTemperature(CTemperature& temperature) = 0; | ||
| 83 | |||
| 84 | bool HasCoreId(int coreId) const; | ||
| 85 | const CoreInfo GetCoreInfo(int coreId); | ||
| 86 | std::string GetCoresUsageString() const; | ||
| 87 | |||
| 88 | unsigned int GetCPUFeatures() const { return m_cpuFeatures; } | ||
| 89 | int GetCPUCount() const { return m_cpuCount; } | ||
| 90 | std::string GetCPUModel() { return m_cpuModel; } | ||
| 91 | std::string GetCPUBogoMips() { return m_cpuBogoMips; } | ||
| 92 | std::string GetCPUSoC() { return m_cpuSoC; } | ||
| 93 | std::string GetCPUHardware() { return m_cpuHardware; } | ||
| 94 | std::string GetCPURevision() { return m_cpuRevision; } | ||
| 95 | std::string GetCPUSerial() { return m_cpuSerial; } | ||
| 96 | |||
| 97 | protected: | ||
| 98 | CCPUInfo() = default; | ||
| 99 | virtual ~CCPUInfo() = default; | ||
| 100 | |||
| 101 | int m_lastUsedPercentage; | ||
| 102 | XbmcThreads::EndTime m_nextUsedReadTime; | ||
| 103 | std::string m_cpuVendor; | ||
| 104 | std::string m_cpuModel; | ||
| 105 | std::string m_cpuBogoMips; | ||
| 106 | std::string m_cpuSoC; | ||
| 107 | std::string m_cpuHardware; | ||
| 108 | std::string m_cpuRevision; | ||
| 109 | std::string m_cpuSerial; | ||
| 110 | |||
| 111 | double m_usagePercent{0.0}; | ||
| 112 | std::size_t m_activeTime{0}; | ||
| 113 | std::size_t m_idleTime{0}; | ||
| 114 | std::size_t m_totalTime{0}; | ||
| 115 | |||
| 116 | int m_cpuCount; | ||
| 117 | unsigned int m_cpuFeatures; | ||
| 118 | |||
| 119 | std::vector<CoreInfo> m_cores; | ||
| 120 | }; | ||
