solid: partially deal with TODO related to CPU instructions

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2021-09-10 17:59:14 +03:00
parent 45463e8694
commit 8b050853e2
3 changed files with 31 additions and 7 deletions

View file

@ -155,7 +155,7 @@ QString DevinfoDevice::product() const
return QLatin1String("Loopback device Interface");
}
} else if(queryDeviceInterface(Solid::DeviceInterface::Processor)) {
QByteArray hwmodel = sysctlByName("hw.model");
const QByteArray hwmodel = DevinfoDevice::stringByName("hw.model");
return QString::fromLatin1(hwmodel.constData());
}
@ -275,18 +275,30 @@ QByteArray DevinfoDevice::deviceCtl(const char* field) const
sysctldevicename += '.';
sysctldevicename += field;
return sysctlByName(sysctldevicename.constData());
return DevinfoDevice::stringByName(sysctldevicename.constData());
}
QByteArray DevinfoDevice::sysctlByName(const char* sysctlname) const
QByteArray DevinfoDevice::stringByName(const char* sysctlname)
{
size_t sysctlbuffsize = 200;
size_t sysctlbuffsize = 1024;
char sysctlbuff[sysctlbuffsize];
::memset(sysctlbuff, '\0', sysctlbuffsize * sizeof(char));
const int sysctlresult = ::sysctlbyname(sysctlname, sysctlbuff, &sysctlbuffsize, NULL, 0);
if (sysctlresult == -1) {
// qWarning() << "sysctlbyname" << sysctldevicename << "failed for" << devicename;
// qWarning() << "sysctlbyname failed" << sysctlname;
return QByteArray();
}
return QByteArray(sysctlbuff, sysctlbuffsize);
}
qlonglong DevinfoDevice::integerByName(const char* sysctlname)
{
size_t sysctlbuffsize = sizeof(qlonglong);
qlonglong sysctlbuff = 0;
const int sysctlresult = ::sysctlbyname(sysctlname, &sysctlbuff, &sysctlbuffsize, NULL, 0);
if (sysctlresult == -1) {
// qWarning() << "sysctlbyname failed" << sysctlname;
return -1;
}
return sysctlbuff;
}

View file

@ -68,7 +68,9 @@ public:
QByteArray deviceProperty(const DeviceProperty property) const;
QByteArray devicePnP(const PnPInfo pnp) const;
QByteArray deviceCtl(const char* field) const;
QByteArray sysctlByName(const char* sysctlname) const;
static QByteArray stringByName(const char* sysctlname);
static qlonglong integerByName(const char* sysctlname);
private:
QString m_device;

View file

@ -55,8 +55,18 @@ bool Processor::canChangeFrequency() const
Solid::Processor::InstructionSets Processor::instructionSets() const
{
// TODO:
// TODO: IntelSse2, IntelSse3, IntelSse4, Amd3DNow, AltiVec
Solid::Processor::InstructionSets cpuinstructions = Solid::Processor::NoExtensions;
const qlonglong instructionsse = DevinfoDevice::integerByName("hw.instruction_sse");
// qDebug() << Q_FUNC_INFO << instructionsse;
if (instructionsse == 1) {
// for reference: freebsd-src/sys/amd64/amd64/initcpu.c
cpuinstructions |= Solid::Processor::IntelMmx;
cpuinstructions |= Solid::Processor::IntelSse;
}
return cpuinstructions;
}