[video] Fix the refresh of movies with additional versions or extras
[xbmc.git] / xbmc / platform / win10 / CPUInfoWin10.cpp
blob72a2a53736f7c62efa292675aac60e3be3a6bb80
1 /*
2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #include "CPUInfoWin10.h"
11 #include "ServiceBroker.h"
12 #include "settings/AdvancedSettings.h"
13 #include "settings/SettingsComponent.h"
14 #include "utils/StringUtils.h"
15 #include "utils/Temperature.h"
17 #include <winrt/Windows.Foundation.Metadata.h>
18 #include <winrt/Windows.System.Diagnostics.h>
20 namespace
22 const unsigned int CPUINFO_EAX{0};
23 const unsigned int CPUINFO_EBX{1};
24 const unsigned int CPUINFO_ECX{2};
25 const unsigned int CPUINFO_EDX{3};
26 } // namespace
28 std::shared_ptr<CCPUInfo> CCPUInfo::GetCPUInfo()
30 return std::make_shared<CCPUInfoWin10>();
33 CCPUInfoWin10::CCPUInfoWin10()
35 SYSTEM_INFO siSysInfo;
36 GetNativeSystemInfo(&siSysInfo);
37 m_cpuCount = siSysInfo.dwNumberOfProcessors;
38 m_cpuModel = "Unknown";
40 int CPUInfo[4] = {}; // receives EAX, EBX, ECD and EDX in that order
42 #ifndef _M_ARM
43 __cpuid(CPUInfo, 0);
44 int MaxStdInfoType = CPUInfo[0];
46 if (MaxStdInfoType >= CPUID_INFOTYPE_STANDARD)
48 __cpuid(CPUInfo, CPUID_INFOTYPE_STANDARD);
49 if (CPUInfo[CPUINFO_EDX] & CPUID_00000001_EDX_MMX)
50 m_cpuFeatures |= CPU_FEATURE_MMX;
51 if (CPUInfo[CPUINFO_EDX] & CPUID_00000001_EDX_SSE)
52 m_cpuFeatures |= CPU_FEATURE_SSE;
53 if (CPUInfo[CPUINFO_EDX] & CPUID_00000001_EDX_SSE2)
54 m_cpuFeatures |= CPU_FEATURE_SSE2;
55 if (CPUInfo[CPUINFO_ECX] & CPUID_00000001_ECX_SSE3)
56 m_cpuFeatures |= CPU_FEATURE_SSE3;
57 if (CPUInfo[CPUINFO_ECX] & CPUID_00000001_ECX_SSSE3)
58 m_cpuFeatures |= CPU_FEATURE_SSSE3;
59 if (CPUInfo[CPUINFO_ECX] & CPUID_00000001_ECX_SSE4)
60 m_cpuFeatures |= CPU_FEATURE_SSE4;
61 if (CPUInfo[CPUINFO_ECX] & CPUID_00000001_ECX_SSE42)
62 m_cpuFeatures |= CPU_FEATURE_SSE42;
65 __cpuid(CPUInfo, 0x80000000);
66 int MaxExtInfoType = CPUInfo[0];
68 if (MaxExtInfoType >= CPUID_INFOTYPE_EXTENDED)
70 __cpuid(CPUInfo, CPUID_INFOTYPE_EXTENDED);
72 if (CPUInfo[CPUINFO_EDX] & CPUID_80000001_EDX_MMX)
73 m_cpuFeatures |= CPU_FEATURE_MMX;
74 if (CPUInfo[CPUINFO_EDX] & CPUID_80000001_EDX_MMX2)
75 m_cpuFeatures |= CPU_FEATURE_MMX2;
76 if (CPUInfo[CPUINFO_EDX] & CPUID_80000001_EDX_3DNOW)
77 m_cpuFeatures |= CPU_FEATURE_3DNOW;
78 if (CPUInfo[CPUINFO_EDX] & CPUID_80000001_EDX_3DNOWEXT)
79 m_cpuFeatures |= CPU_FEATURE_3DNOWEXT;
81 #endif
83 // Set MMX2 when SSE is present as SSE is a superset of MMX2 and Intel doesn't set the MMX2 cap
84 if (m_cpuFeatures & CPU_FEATURE_SSE)
85 m_cpuFeatures |= CPU_FEATURE_MMX2;
88 int CCPUInfoWin10::GetUsedPercentage()
90 if (!m_nextUsedReadTime.IsTimePast())
91 return m_lastUsedPercentage;
93 if (!winrt::Windows::Foundation::Metadata::ApiInformation::IsTypePresent(
94 L"Windows.System.Diagnostics.SystemDiagnosticInfo"))
96 return 0;
99 auto diagnostic =
100 winrt::Windows::System::Diagnostics::SystemDiagnosticInfo::GetForCurrentSystem();
101 auto usage = diagnostic.CpuUsage();
102 auto report = usage.GetReport();
104 auto user = report.UserTime().count();
105 auto idle = report.IdleTime().count();
106 auto system = report.KernelTime().count() - idle;
108 auto activeTime = (user + system) - m_activeTime;
109 auto idleTime = idle - m_idleTime;
110 auto totalTime = (user + idle + system) - m_totalTime;
112 m_activeTime += activeTime;
113 m_idleTime += idleTime;
114 m_totalTime += totalTime;
116 m_lastUsedPercentage = activeTime * 100.0f / totalTime;
117 m_nextUsedReadTime.Set(MINIMUM_TIME_BETWEEN_READS);
119 return static_cast<int>(m_lastUsedPercentage);
122 bool CCPUInfoWin10::GetTemperature(CTemperature& temperature)
124 temperature.SetValid(false);
125 return false;