7#include "winprocessor.h"
9#include <solid/devices/backends/shared/cpufeatures.h>
13using namespace Solid::Backends::Win;
15typedef BOOL(WINAPI *GLPI_fn)(SYSTEM_LOGICAL_PROCESSOR_INFORMATION *Buffer, DWORD *ReturnLength);
16GLPI_fn pGetLogicalProcessorInformation = (GLPI_fn)GetProcAddress(LoadLibraryA(
"kernel32.dll"),
"GetLogicalProcessorInformation");
18WinProcessor::WinProcessor(WinDevice *device)
19 : WinInterface(device)
21 m_number = m_device->udi().mid(m_device->udi().length() - 1).toInt();
24WinProcessor::~WinProcessor()
28int WinProcessor::number()
const
33int WinProcessor::maxSpeed()
const
35 return updateCache()[m_number].speed;
38bool WinProcessor::canChangeFrequency()
const
44Solid::Processor::InstructionSets WinProcessor::instructionSets()
const
46 static Solid::Processor::InstructionSets set = Solid::Backends::Shared::cpuFeatures();
50QSet<QString> WinProcessor::getUdis()
52 static QSet<QString> out;
54 const QMap<int, ProcessorInfo>
map = updateCache();
55 for (
const ProcessorInfo &info : map) {
56 out << QStringLiteral(
"/org/kde/solid/win/cpu/device#%1,cpu#%2").arg(info.id).arg(info.lgicalId);
62DWORD WinProcessor::countSetBits(ULONG_PTR bitMask)
64 DWORD LSHIFT =
sizeof(ULONG_PTR) * 8 - 1;
65 DWORD bitSetCount = 0;
66 ULONG_PTR bitTest = (ULONG_PTR)1 << LSHIFT;
69 for (i = 0; i <= LSHIFT; ++i) {
70 bitSetCount += ((bitMask & bitTest) ? 1 : 0);
77const QMap<int, WinProcessor::ProcessorInfo> &WinProcessor::updateCache()
79 static QMap<int, ProcessorInfo> p;
83 pGetLogicalProcessorInformation(NULL, &size);
84 char *buff =
new char[size];
85 SYSTEM_LOGICAL_PROCESSOR_INFORMATION *info = (SYSTEM_LOGICAL_PROCESSOR_INFORMATION *)buff;
86 pGetLogicalProcessorInformation(info, &size);
87 size /=
sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION);
89 uint processorCoreCount = 0;
90 uint logicalProcessorCount = 0;
92 for (uint i = 0; i < size; ++i) {
93 if (info[i].Relationship == RelationProcessorCore) {
95 uint old = logicalProcessorCount;
96 logicalProcessorCount += countSetBits(info[i].ProcessorMask);
97 for (; old < logicalProcessorCount; ++old) {
98 QSettings settings(QLatin1String(
"HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\") +
QString::number(old),
101 proc.id = processorCoreCount;
103 proc.speed = settings.value(
"~MHz").toInt();
104 proc.vendor = settings.value(
"VendorIdentifier").toString().trimmed();
105 proc.name = settings.value(
"ProcessorNameString").toString().trimmed();
106 proc.produuct = settings.value(
"Identifier").toString().trimmed();
110 processorCoreCount++;
118#include "moc_winprocessor.cpp"
bool isEmpty() const const
bool isEmpty() const const
QString number(double n, char format, int precision)
QFuture< void > map(Iterator begin, Iterator end, MapFunctor &&function)