2017-12-21 00:45:38 +01:00
|
|
|
/*
|
2022-02-23 11:38:34 +00:00
|
|
|
* Copyright (C) 2019-2022 Intel Corporation
|
2017-12-21 00:45:38 +01:00
|
|
|
*
|
2019-03-26 11:59:46 +01:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 00:45:38 +01:00
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2020-02-23 22:44:01 +01:00
|
|
|
#include "shared/source/utilities/cpu_info.h"
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2020-12-07 15:52:36 +01:00
|
|
|
#include "shared/source/os_interface/linux/os_inc.h"
|
|
|
|
|
|
2021-09-02 21:25:03 +00:00
|
|
|
#include <cstdint>
|
2020-12-07 15:52:36 +01:00
|
|
|
#include <fstream>
|
2022-03-28 16:30:45 +00:00
|
|
|
#include <sys/auxv.h>
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2019-03-26 11:59:46 +01:00
|
|
|
namespace NEO {
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2022-05-16 14:06:56 +00:00
|
|
|
void cpuidLinuxWrapper(int cpuInfo[4], int functionId) {
|
2022-03-28 16:30:45 +00:00
|
|
|
cpuInfo[0] = getauxval(AT_HWCAP);
|
2019-07-31 18:43:05 -07:00
|
|
|
}
|
|
|
|
|
|
2022-05-16 14:06:56 +00:00
|
|
|
void cpuidexLinuxWrapper(int *cpuInfo, int functionId, int subfunctionId) {
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
|
2022-05-16 14:06:56 +00:00
|
|
|
void getCpuFlagsLinux(std::string &cpuFlags) {
|
2021-01-11 11:18:44 +00:00
|
|
|
std::ifstream cpuinfo(std::string(Os::sysFsProcPathPrefix) + "/cpuinfo");
|
|
|
|
|
std::string line;
|
|
|
|
|
while (std::getline(cpuinfo, line)) {
|
2022-03-28 16:30:45 +00:00
|
|
|
if (line.substr(0, 8) == "Features") {
|
2021-01-11 11:18:44 +00:00
|
|
|
cpuFlags = line;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-16 14:06:56 +00:00
|
|
|
void (*CpuInfo::cpuidexFunc)(int *, int, int) = cpuidexLinuxWrapper;
|
|
|
|
|
void (*CpuInfo::cpuidFunc)(int[4], int) = cpuidLinuxWrapper;
|
|
|
|
|
void (*CpuInfo::getCpuFlagsFunc)(std::string &) = getCpuFlagsLinux;
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
|
const CpuInfo CpuInfo::instance;
|
|
|
|
|
|
|
|
|
|
void CpuInfo::cpuid(
|
|
|
|
|
uint32_t cpuInfo[4],
|
|
|
|
|
uint32_t functionId) const {
|
2019-07-31 18:43:05 -07:00
|
|
|
cpuidFunc(reinterpret_cast<int *>(cpuInfo), functionId);
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CpuInfo::cpuidex(
|
|
|
|
|
uint32_t cpuInfo[4],
|
|
|
|
|
uint32_t functionId,
|
|
|
|
|
uint32_t subfunctionId) const {
|
|
|
|
|
cpuidexFunc(reinterpret_cast<int *>(cpuInfo), functionId, subfunctionId);
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-26 11:59:46 +01:00
|
|
|
} // namespace NEO
|