From bde134139835e0db3671c10bb802e00c68b90177 Mon Sep 17 00:00:00 2001 From: Lukas Rusak Date: Wed, 30 Oct 2019 10:21:42 -0700 Subject: [PATCH 1/6] CPUInfoWin32: remove _M_ARM gaurd --- xbmc/platform/win32/CPUInfoWin32.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/xbmc/platform/win32/CPUInfoWin32.cpp b/xbmc/platform/win32/CPUInfoWin32.cpp index 213f74db35836..ebb8239ed65c0 100644 --- a/xbmc/platform/win32/CPUInfoWin32.cpp +++ b/xbmc/platform/win32/CPUInfoWin32.cpp @@ -125,7 +125,6 @@ CCPUInfoWin32::CCPUInfoWin32() else m_cpuQueryLoad = nullptr; -#ifndef _M_ARM int CPUInfo[4]; // receives EAX, EBX, ECD and EDX in that order __cpuid(CPUInfo, 0); @@ -164,7 +163,6 @@ CCPUInfoWin32::CCPUInfoWin32() if (CPUInfo[CPUINFO_EDX] & CPUID_80000001_EDX_3DNOWEXT) m_cpuFeatures |= CPU_FEATURE_3DNOWEXT; } -#endif // ! _M_ARM // Set MMX2 when SSE is present as SSE is a superset of MMX2 and Intel doesn't set the MMX2 cap if (m_cpuFeatures & CPU_FEATURE_SSE) From a67b08fe758bd3c2661f4dc79e383e21ffa597ca Mon Sep 17 00:00:00 2001 From: Lukas Rusak Date: Wed, 30 Oct 2019 10:25:47 -0700 Subject: [PATCH 2/6] CPUInfoLinux: return false if temperature units aren't valid --- xbmc/platform/linux/CPUInfoLinux.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/xbmc/platform/linux/CPUInfoLinux.cpp b/xbmc/platform/linux/CPUInfoLinux.cpp index 9b107353e7da4..53da5c076f67d 100644 --- a/xbmc/platform/linux/CPUInfoLinux.cpp +++ b/xbmc/platform/linux/CPUInfoLinux.cpp @@ -279,6 +279,8 @@ bool CCPUInfoLinux::GetTemperature(CTemperature& temperature) temperature = CTemperature::CreateFromCelsius(value); else if (scale == 'F' || scale == 'f') temperature = CTemperature::CreateFromFahrenheit(value); + else + return false; temperature.SetValid(true); From 4e51f0fa96041127aeb3769a38337786d0a78839 Mon Sep 17 00:00:00 2001 From: Lukas Rusak Date: Wed, 30 Oct 2019 10:26:38 -0700 Subject: [PATCH 3/6] CPUInfoLinux: fix ifdefs for non neon platforms --- xbmc/platform/linux/CPUInfoLinux.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/xbmc/platform/linux/CPUInfoLinux.cpp b/xbmc/platform/linux/CPUInfoLinux.cpp index 53da5c076f67d..46b387fc6b806 100644 --- a/xbmc/platform/linux/CPUInfoLinux.cpp +++ b/xbmc/platform/linux/CPUInfoLinux.cpp @@ -16,10 +16,10 @@ #include #include -#if defined(HAS_NEON) +#if (defined(__arm__) && defined(HAS_NEON)) || defined(__aarch64__) #include #include -#else +#elif defined(__i386__) || defined(__x86_64__) #include #endif @@ -94,7 +94,7 @@ CCPUInfoLinux::CCPUInfoLinux() m_cores.emplace_back(coreInfo); } -#if !defined(HAS_NEON) +#if defined(__i386__) || defined(__x86_64__) unsigned int eax; unsigned int ebx; unsigned int ecx; @@ -184,10 +184,8 @@ CCPUInfoLinux::CCPUInfoLinux() } #endif -#if defined(HAS_NEON) && !defined(__LP64__) +#if defined(HAS_NEON) && defined(__arm__) if (getauxval(AT_HWCAP) & HWCAP_NEON) -#endif -#if defined(HAS_NEON) m_cpuFeatures |= CPU_FEATURE_NEON; #endif From 6048d2e9460c2f0abde9c14ecbe8123290ac4b37 Mon Sep 17 00:00:00 2001 From: Lukas Rusak Date: Wed, 30 Oct 2019 10:31:01 -0700 Subject: [PATCH 4/6] CPUInfo: split posix functions into specific class to allow windows to build --- xbmc/platform/android/CPUInfoAndroid.h | 5 +-- xbmc/platform/darwin/ios/CPUInfoIos.h | 5 +-- xbmc/platform/darwin/osx/CPUInfoOsx.h | 5 +-- xbmc/platform/freebsd/CPUInfoFreebsd.h | 5 +-- xbmc/platform/linux/CPUInfoLinux.cpp | 2 +- xbmc/platform/linux/CPUInfoLinux.h | 5 +-- xbmc/platform/posix/CMakeLists.txt | 2 ++ xbmc/platform/posix/CPUInfoPosix.cpp | 47 ++++++++++++++++++++++++++ xbmc/platform/posix/CPUInfoPosix.h | 21 ++++++++++++ xbmc/platform/win10/CPUInfoWin10.cpp | 6 ++++ xbmc/platform/win10/CPUInfoWin10.h | 1 + xbmc/platform/win32/CPUInfoWin32.cpp | 6 ++++ xbmc/platform/win32/CPUInfoWin32.h | 1 + xbmc/utils/CPUInfo.cpp | 35 ------------------- xbmc/utils/CPUInfo.h | 2 +- 15 files changed, 101 insertions(+), 47 deletions(-) create mode 100644 xbmc/platform/posix/CPUInfoPosix.cpp create mode 100644 xbmc/platform/posix/CPUInfoPosix.h diff --git a/xbmc/platform/android/CPUInfoAndroid.h b/xbmc/platform/android/CPUInfoAndroid.h index 2ec2e6f7a84f8..8c7bf91d63ac3 100644 --- a/xbmc/platform/android/CPUInfoAndroid.h +++ b/xbmc/platform/android/CPUInfoAndroid.h @@ -8,10 +8,11 @@ #pragma once -#include "utils/CPUInfo.h" #include "utils/Temperature.h" -class CCPUInfoAndroid : public CCPUInfo +#include "platform/posix/CPUInfoPosix.h" + +class CCPUInfoAndroid : public CCPUInfoPosix { public: CCPUInfoAndroid(); diff --git a/xbmc/platform/darwin/ios/CPUInfoIos.h b/xbmc/platform/darwin/ios/CPUInfoIos.h index 785761dbe5e94..e7a0cffa1ae37 100644 --- a/xbmc/platform/darwin/ios/CPUInfoIos.h +++ b/xbmc/platform/darwin/ios/CPUInfoIos.h @@ -8,14 +8,15 @@ #pragma once -#include "utils/CPUInfo.h" #include "utils/Temperature.h" +#include "platform/posix/CPUInfoPosix.h" + #include class CPosixResourceCounter; -class CCPUInfoIos : public CCPUInfo +class CCPUInfoIos : public CCPUInfoPosix { public: CCPUInfoIos(); diff --git a/xbmc/platform/darwin/osx/CPUInfoOsx.h b/xbmc/platform/darwin/osx/CPUInfoOsx.h index 5ded61f1a5b60..39b2b1bee32bc 100644 --- a/xbmc/platform/darwin/osx/CPUInfoOsx.h +++ b/xbmc/platform/darwin/osx/CPUInfoOsx.h @@ -8,12 +8,13 @@ #pragma once -#include "utils/CPUInfo.h" #include "utils/Temperature.h" +#include "platform/posix/CPUInfoPosix.h" + class CPosixResourceCounter; -class CCPUInfoOsx : public CCPUInfo +class CCPUInfoOsx : public CCPUInfoPosix { public: CCPUInfoOsx(); diff --git a/xbmc/platform/freebsd/CPUInfoFreebsd.h b/xbmc/platform/freebsd/CPUInfoFreebsd.h index c33ba20985478..08713b176de9c 100644 --- a/xbmc/platform/freebsd/CPUInfoFreebsd.h +++ b/xbmc/platform/freebsd/CPUInfoFreebsd.h @@ -8,10 +8,11 @@ #pragma once -#include "utils/CPUInfo.h" #include "utils/Temperature.h" -class CCPUInfoFreebsd : public CCPUInfo +#include "platform/posix/CPUInfoPosix.h" + +class CCPUInfoFreebsd : public CCPUInfoPosix { public: CCPUInfoFreebsd(); diff --git a/xbmc/platform/linux/CPUInfoLinux.cpp b/xbmc/platform/linux/CPUInfoLinux.cpp index 46b387fc6b806..a60051dcde92c 100644 --- a/xbmc/platform/linux/CPUInfoLinux.cpp +++ b/xbmc/platform/linux/CPUInfoLinux.cpp @@ -264,7 +264,7 @@ float CCPUInfoLinux::GetCPUFrequency() bool CCPUInfoLinux::GetTemperature(CTemperature& temperature) { if (!SysfsUtils::Has("/sys/class/hwmon/hwmon0/temp1_input")) - return CCPUInfo::GetTemperature(temperature); + return CCPUInfoPosix::GetTemperature(temperature); int value{-1}; char scale{'c'}; diff --git a/xbmc/platform/linux/CPUInfoLinux.h b/xbmc/platform/linux/CPUInfoLinux.h index ad1354653a272..cc4d95d00da1f 100644 --- a/xbmc/platform/linux/CPUInfoLinux.h +++ b/xbmc/platform/linux/CPUInfoLinux.h @@ -8,10 +8,11 @@ #pragma once -#include "utils/CPUInfo.h" #include "utils/Temperature.h" -class CCPUInfoLinux : public CCPUInfo +#include "platform/posix/CPUInfoPosix.h" + +class CCPUInfoLinux : public CCPUInfoPosix { public: CCPUInfoLinux(); diff --git a/xbmc/platform/posix/CMakeLists.txt b/xbmc/platform/posix/CMakeLists.txt index 56c7487238408..2c4acd977d605 100644 --- a/xbmc/platform/posix/CMakeLists.txt +++ b/xbmc/platform/posix/CMakeLists.txt @@ -1,4 +1,5 @@ set(SOURCES ConvUtils.cpp + CPUInfoPosix.cpp Filesystem.cpp MessagePrinter.cpp PlatformPosix.cpp @@ -10,6 +11,7 @@ set(SOURCES ConvUtils.cpp XTimeUtils.cpp) set(HEADERS ConvUtils.h + CPUInfoPosix.h PlatformDefs.h PlatformPosix.h PosixMountProvider.h diff --git a/xbmc/platform/posix/CPUInfoPosix.cpp b/xbmc/platform/posix/CPUInfoPosix.cpp new file mode 100644 index 0000000000000..a261b6e385de3 --- /dev/null +++ b/xbmc/platform/posix/CPUInfoPosix.cpp @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2005-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#include "CPUInfoPosix.h" + +#include "ServiceBroker.h" +#include "settings/AdvancedSettings.h" +#include "settings/SettingsComponent.h" + +bool CCPUInfoPosix::GetTemperature(CTemperature& temperature) +{ + std::string cmd = CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_cpuTempCmd; + + temperature.SetValid(false); + + int value{-1}; + char scale{'c'}; + + if (!cmd.empty()) + { + auto p = popen(cmd.c_str(), "r"); + if (p) + { + int ret = fscanf(p, "%d %c", &value, &scale); + pclose(p); + + if (ret < 2) + return false; + } + } + + if (scale == 'C' || scale == 'c') + temperature = CTemperature::CreateFromCelsius(value); + else if (scale == 'F' || scale == 'f') + temperature = CTemperature::CreateFromFahrenheit(value); + else + return false; + + temperature.SetValid(true); + + return true; +} diff --git a/xbmc/platform/posix/CPUInfoPosix.h b/xbmc/platform/posix/CPUInfoPosix.h new file mode 100644 index 0000000000000..0043a60dcdae3 --- /dev/null +++ b/xbmc/platform/posix/CPUInfoPosix.h @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2005-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#pragma once + +#include "utils/CPUInfo.h" + +class CCPUInfoPosix : public CCPUInfo +{ +public: + virtual bool GetTemperature(CTemperature& temperature) override; + +protected: + CCPUInfoPosix() = default; + virtual ~CCPUInfoPosix() = default; +}; diff --git a/xbmc/platform/win10/CPUInfoWin10.cpp b/xbmc/platform/win10/CPUInfoWin10.cpp index 4885ef6cf114b..8a18c89699a5d 100644 --- a/xbmc/platform/win10/CPUInfoWin10.cpp +++ b/xbmc/platform/win10/CPUInfoWin10.cpp @@ -117,3 +117,9 @@ int CCPUInfoWin10::GetUsedPercentage() return static_cast(m_lastUsedPercentage); } + +bool CCPUInfoWin10::GetTemperature(CTemperature& temperature) +{ + temperature.SetValid(false); + return false; +} diff --git a/xbmc/platform/win10/CPUInfoWin10.h b/xbmc/platform/win10/CPUInfoWin10.h index 220f38d6eedfb..dc924901931b8 100644 --- a/xbmc/platform/win10/CPUInfoWin10.h +++ b/xbmc/platform/win10/CPUInfoWin10.h @@ -19,4 +19,5 @@ class CCPUInfoWin10 : public CCPUInfo int GetUsedPercentage() override; float GetCPUFrequency() override { return 0; } + bool GetTemperature(CTemperature& temperature) override; }; diff --git a/xbmc/platform/win32/CPUInfoWin32.cpp b/xbmc/platform/win32/CPUInfoWin32.cpp index ebb8239ed65c0..086402f8bfe03 100644 --- a/xbmc/platform/win32/CPUInfoWin32.cpp +++ b/xbmc/platform/win32/CPUInfoWin32.cpp @@ -285,3 +285,9 @@ float CCPUInfoWin32::GetCPUFrequency() return 0; } + +bool CCPUInfoWin32::GetTemperature(CTemperature& temperature) +{ + temperature.SetValid(false); + return false; +} diff --git a/xbmc/platform/win32/CPUInfoWin32.h b/xbmc/platform/win32/CPUInfoWin32.h index 996de4efaffe1..69bfac2f79a26 100644 --- a/xbmc/platform/win32/CPUInfoWin32.h +++ b/xbmc/platform/win32/CPUInfoWin32.h @@ -19,6 +19,7 @@ class CCPUInfoWin32 : public CCPUInfo int GetUsedPercentage() override; float GetCPUFrequency() override; + bool GetTemperature(CTemperature& temperature) override; private: // avoid inclusion of and others diff --git a/xbmc/utils/CPUInfo.cpp b/xbmc/utils/CPUInfo.cpp index 98dbceb7de99f..b0afdf3f8775e 100644 --- a/xbmc/utils/CPUInfo.cpp +++ b/xbmc/utils/CPUInfo.cpp @@ -8,9 +8,6 @@ #include "CPUInfo.h" -#include "ServiceBroker.h" -#include "settings/AdvancedSettings.h" -#include "settings/SettingsComponent.h" #include "utils/StringUtils.h" bool CCPUInfo::HasCoreId(int coreId) const @@ -60,35 +57,3 @@ std::string CCPUInfo::GetCoresUsageString() const return strCores; } - -bool CCPUInfo::GetTemperature(CTemperature& temperature) -{ - std::string cmd = CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_cpuTempCmd; - - temperature.SetValid(false); - - int value{-1}; - char scale{'c'}; - - if (!cmd.empty()) - { - auto p = popen(cmd.c_str(), "r"); - if (p) - { - int ret = fscanf(p, "%d %c", &value, &scale); - pclose(p); - - if (ret < 2) - return false; - } - } - - if (scale == 'C' || scale == 'c') - temperature = CTemperature::CreateFromCelsius(value); - else if (scale == 'F' || scale == 'f') - temperature = CTemperature::CreateFromFahrenheit(value); - - temperature.SetValid(true); - - return true; -} diff --git a/xbmc/utils/CPUInfo.h b/xbmc/utils/CPUInfo.h index dc298a52a94d9..ad8dd95607a87 100644 --- a/xbmc/utils/CPUInfo.h +++ b/xbmc/utils/CPUInfo.h @@ -77,7 +77,7 @@ class CCPUInfo virtual int GetUsedPercentage() = 0; virtual float GetCPUFrequency() = 0; - virtual bool GetTemperature(CTemperature& temperature); + virtual bool GetTemperature(CTemperature& temperature) = 0; bool HasCoreId(int coreId) const; const CoreInfo GetCoreInfo(int coreId); From 2cb3311f4d5b34252887e2a0ec7bd50ccadb84a6 Mon Sep 17 00:00:00 2001 From: Lukas Rusak Date: Wed, 30 Oct 2019 13:35:31 -0700 Subject: [PATCH 5/6] CCPUInfo: move servicebroker registration earlier in app startup --- xbmc/Application.cpp | 2 ++ xbmc/platform/Platform.cpp | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/xbmc/Application.cpp b/xbmc/Application.cpp index 9ec42b943d95e..787d2ed060e95 100644 --- a/xbmc/Application.cpp +++ b/xbmc/Application.cpp @@ -364,6 +364,8 @@ bool CApplication::Create(const CAppParamParser ¶ms) m_bTestMode = params.m_testmode; m_bStandalone = params.m_standAlone; + CServiceBroker::RegisterCPUInfo(CCPUInfo::GetCPUInfo()); + m_pSettingsComponent.reset(new CSettingsComponent()); m_pSettingsComponent->Init(params); diff --git a/xbmc/platform/Platform.cpp b/xbmc/platform/Platform.cpp index cfd88baa1623b..e1f1465c7949c 100644 --- a/xbmc/platform/Platform.cpp +++ b/xbmc/platform/Platform.cpp @@ -9,7 +9,6 @@ #include "Platform.h" #include "ServiceBroker.h" -#include "utils/CPUInfo.h" // Override for platform ports #if !defined(PLATFORM_OVERRIDE) @@ -29,6 +28,5 @@ CPlatform::~CPlatform() = default; void CPlatform::Init() { - CServiceBroker::RegisterCPUInfo(CCPUInfo::GetCPUInfo()); } From 431577860f9c7853bc0271510849c563ee0bb77c Mon Sep 17 00:00:00 2001 From: Lukas Rusak Date: Wed, 6 Nov 2019 16:08:52 -0800 Subject: [PATCH 6/6] tests: disable GetTemperature test for TestCPUInfo on windows --- xbmc/utils/test/TestCPUInfo.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/xbmc/utils/test/TestCPUInfo.cpp b/xbmc/utils/test/TestCPUInfo.cpp index d395eb41bb7cf..9cf2db9152681 100644 --- a/xbmc/utils/test/TestCPUInfo.cpp +++ b/xbmc/utils/test/TestCPUInfo.cpp @@ -44,7 +44,11 @@ TEST_F(TestCPUInfo, GetCPUFrequency) EXPECT_GE(CServiceBroker::GetCPUInfo()->GetCPUFrequency(), 0.f); } +#if defined(TARGET_WINDOWS) +TEST_F(TestCPUInfo, DISABLED_GetTemperature) +#else TEST_F(TestCPUInfo, GetTemperature) +#endif { CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_cpuTempCmd = "echo '50 c'"; CTemperature t;