Solid

iokitprocessor.cpp
1/*
2 SPDX-FileCopyrightText: 2009 Harald Fernengel <harry@kdevelop.org>
3 SPDX-FileCopyrightText: 2017 René J.V. Bertin <rjvbertin@gmail.com>
4
5 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
6*/
7
8#include "iokitprocessor.h"
9#include "iokitdevice.h"
10
11#include <qdebug.h>
12
13#include <errno.h>
14#include <sys/sysctl.h>
15#include <sys/types.h>
16
17#include "../shared/cpufeatures.h"
18
19// from cfhelper.cpp
20extern bool q_sysctlbyname(const char *name, QString &result);
21
22using namespace Solid::Backends::IOKit;
23
24Processor::Processor(IOKitDevice *device)
25 : DeviceInterface(device)
26{
27 // IOKitDevice parent(device->parentUdi());
28}
29
30Processor::~Processor()
31{
32}
33
34int Processor::number() const
35{
36 return m_device->property(QLatin1String("IOCPUNumber")).toInt();
37}
38
39int Processor::maxSpeed() const
40{
41 uint64_t freq = 0;
42 size_t size = sizeof(freq);
43
44 if (sysctlbyname("hw.cpufrequency", &freq, &size, nullptr, 0) < 0) {
45 qWarning() << "sysctl error reading hw.cpufrequency:" << strerror(errno);
46 return 0;
47 } else {
48 return int(freq / 1000000);
49 }
50}
51
52bool Processor::canChangeFrequency() const
53{
54 uint64_t minFreq = 0, maxFreq = 0;
55 size_t size = sizeof(uint64_t);
56
57 if (sysctlbyname("hw.cpufrequency_min", &minFreq, &size, nullptr, 0) == 0 //
58 && sysctlbyname("hw.cpufrequency_max", &maxFreq, &size, nullptr, 0) == 0) {
59 return maxFreq > minFreq;
60 }
61 return false;
62}
63
64Solid::Processor::InstructionSets Processor::instructionSets() const
65{
66 // use sysctlbyname() and "machdep.cpu.features" + "machdep.cpu.extfeatures"
67 static Solid::Processor::InstructionSets cpuextensions = Solid::Backends::Shared::cpuFeatures();
68
69 return cpuextensions;
70}
71
72QString Processor::vendor()
73{
74 QString qVendor;
75 q_sysctlbyname("machdep.cpu.vendor", qVendor);
76 return qVendor;
77}
78
79QString Processor::product()
80{
81 QString product;
82 q_sysctlbyname("machdep.cpu.brand_string", product);
83 return product;
84}
85
86#include "moc_iokitprocessor.cpp"
int toInt(bool *ok) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:14:22 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.