Update sysfs path for sysman freq module

Signed-off-by: Mayank Raghuwanshi <mayank.raghuwanshi@intel.com>
This commit is contained in:
Mayank Raghuwanshi
2021-06-20 17:39:41 +05:30
committed by Compute-Runtime-Automation
parent a19eab36fb
commit 6436714987
6 changed files with 199 additions and 19 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 Intel Corporation
* Copyright (C) 2020-2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -11,14 +11,23 @@
namespace L0 {
namespace ult {
const std::string minFreqFile("gt_min_freq_mhz");
const std::string maxFreqFile("gt_max_freq_mhz");
const std::string requestFreqFile("gt_punit_req_freq_mhz");
const std::string tdpFreqFile("gt_rapl_PL1_freq_mhz");
const std::string actualFreqFile("gt_act_freq_mhz");
const std::string efficientFreqFile("gt_RP1_freq_mhz");
const std::string maxValFreqFile("gt_RP0_freq_mhz");
const std::string minValFreqFile("gt_RPn_freq_mhz");
const std::string minFreqFile("gt/gt0/rps_min_freq_mhz");
const std::string maxFreqFile("gt/gt0/rps_max_freq_mhz");
const std::string requestFreqFile("gt/gt0/punit_req_freq_mhz");
const std::string tdpFreqFile("gt/gt0/rapl_PL1_freq_mhz");
const std::string actualFreqFile("gt/gt0/rps_act_freq_mhz");
const std::string efficientFreqFile("gt/gt0/rps_RP1_freq_mhz");
const std::string maxValFreqFile("gt/gt0/rps_RP0_freq_mhz");
const std::string minValFreqFile("gt/gt0/rps_RPn_freq_mhz");
const std::string minFreqFileLegacy("gt_min_freq_mhz");
const std::string maxFreqFileLegacy("gt_max_freq_mhz");
const std::string requestFreqFileLegacy("punit_req_freq_mhz");
const std::string tdpFreqFileLegacy("rapl_PL1_freq_mhz");
const std::string actualFreqFileLegacy("gt_act_freq_mhz");
const std::string efficientFreqFileLegacy("gt_RP1_freq_mhz");
const std::string maxValFreqFileLegacy("gt_RP0_freq_mhz");
const std::string minValFreqFileLegacy("gt_RPn_freq_mhz");
class FrequencySysfsAccess : public SysfsAccess {};
@@ -35,6 +44,15 @@ struct Mock<FrequencySysfsAccess> : public FrequencySysfsAccess {
MOCK_METHOD(ze_result_t, read, (const std::string file, double &val), (override));
MOCK_METHOD(ze_result_t, write, (const std::string file, const double val), (override));
MOCK_METHOD(bool, directoryExists, (const std::string path), (override));
bool mockDirectoryExistsSuccess(const std::string path) {
return true;
}
bool mockDirectoryExistsFailure(const std::string path) {
return false;
}
ze_result_t getMaxValReturnErrorNotAvailable(const std::string file, double &val) {
if (file.compare(maxValFreqFile) == 0) {
@@ -156,6 +174,62 @@ struct Mock<FrequencySysfsAccess> : public FrequencySysfsAccess {
return ZE_RESULT_SUCCESS;
}
ze_result_t getValLegacy(const std::string file, double &val) {
if (file.compare(minFreqFileLegacy) == 0) {
val = mockMin;
}
if (file.compare(maxFreqFileLegacy) == 0) {
val = mockMax;
}
if (file.compare(requestFreqFileLegacy) == 0) {
val = mockRequest;
}
if (file.compare(tdpFreqFileLegacy) == 0) {
val = mockTdp;
}
if (file.compare(actualFreqFileLegacy) == 0) {
val = mockActual;
}
if (file.compare(efficientFreqFileLegacy) == 0) {
val = mockEfficient;
}
if (file.compare(maxValFreqFileLegacy) == 0) {
val = mockMaxVal;
}
if (file.compare(minValFreqFileLegacy) == 0) {
val = mockMinVal;
}
return ZE_RESULT_SUCCESS;
}
ze_result_t setValLegacy(const std::string file, const double val) {
if (file.compare(minFreqFileLegacy) == 0) {
mockMin = val;
}
if (file.compare(maxFreqFileLegacy) == 0) {
mockMax = val;
}
if (file.compare(requestFreqFileLegacy) == 0) {
mockRequest = val;
}
if (file.compare(tdpFreqFileLegacy) == 0) {
mockTdp = val;
}
if (file.compare(actualFreqFileLegacy) == 0) {
mockActual = val;
}
if (file.compare(efficientFreqFileLegacy) == 0) {
mockEfficient = val;
}
if (file.compare(maxValFreqFileLegacy) == 0) {
mockMaxVal = val;
}
if (file.compare(minValFreqFileLegacy) == 0) {
mockMinVal = val;
}
return ZE_RESULT_SUCCESS;
}
ze_result_t getVal(const std::string file, double &val) {
if (file.compare(minFreqFile) == 0) {
val = mockMin;

View File

@@ -30,10 +30,10 @@ constexpr double minVal = 300.0;
constexpr uint32_t numClocks = static_cast<uint32_t>((maxFreq - minFreq) / step) + 1;
constexpr uint32_t handleComponentCount = 1u;
class SysmanDeviceFrequencyFixture : public SysmanDeviceFixture {
protected:
std::unique_ptr<Mock<FrequencySysfsAccess>> pSysfsAccess;
SysfsAccess *pSysfsAccessOld = nullptr;
std::vector<ze_device_handle_t> deviceHandles;
void SetUp() override {
SysmanDeviceFixture::SetUp();
@@ -53,6 +53,8 @@ class SysmanDeviceFrequencyFixture : public SysmanDeviceFixture {
.WillByDefault(::testing::Invoke(pSysfsAccess.get(), &Mock<FrequencySysfsAccess>::getVal));
ON_CALL(*pSysfsAccess.get(), write(_, _))
.WillByDefault(::testing::Invoke(pSysfsAccess.get(), &Mock<FrequencySysfsAccess>::setVal));
ON_CALL(*pSysfsAccess.get(), directoryExists(_))
.WillByDefault(::testing::Invoke(pSysfsAccess.get(), &Mock<FrequencySysfsAccess>::mockDirectoryExistsSuccess));
// delete handles created in initial SysmanDeviceHandleContext::init() call
for (auto handle : pSysmanDeviceImp->pFrequencyHandleContext->handleList) {
@@ -60,7 +62,6 @@ class SysmanDeviceFrequencyFixture : public SysmanDeviceFixture {
}
pSysmanDeviceImp->pFrequencyHandleContext->handleList.clear();
uint32_t subDeviceCount = 0;
std::vector<ze_device_handle_t> deviceHandles;
// We received a device handle. Check for subdevices in this device
Device::fromHandle(device->toHandle())->getSubDevices(&subDeviceCount, nullptr);
if (subDeviceCount == 0) {
@@ -302,6 +303,67 @@ TEST_F(SysmanDeviceFrequencyFixture, GivenValidFrequencyHandleWhenCallingzesFreq
}
}
TEST_F(SysmanDeviceFrequencyFixture, GivenValidFrequencyHandleWhenCallingzesFrequencyGetStateWithLegacyPathThenVerifyzesFrequencyGetStateTestCallSucceeds) {
ON_CALL(*pSysfsAccess.get(), read(_, _))
.WillByDefault(::testing::Invoke(pSysfsAccess.get(), &Mock<FrequencySysfsAccess>::getValLegacy));
ON_CALL(*pSysfsAccess.get(), write(_, _))
.WillByDefault(::testing::Invoke(pSysfsAccess.get(), &Mock<FrequencySysfsAccess>::setValLegacy));
ON_CALL(*pSysfsAccess.get(), directoryExists(_))
.WillByDefault(::testing::Invoke(pSysfsAccess.get(), &Mock<FrequencySysfsAccess>::mockDirectoryExistsFailure));
for (auto handle : pSysmanDeviceImp->pFrequencyHandleContext->handleList) {
delete handle;
}
pSysmanDeviceImp->pFrequencyHandleContext->handleList.clear();
pSysmanDeviceImp->pFrequencyHandleContext->init(deviceHandles);
auto handles = get_freq_handles(handleComponentCount);
for (auto handle : handles) {
const double testRequestValue = 400.0;
const double testTdpValue = 1100.0;
const double testEfficientValue = 300.0;
const double testActualValue = 550.0;
zes_freq_state_t state;
pSysfsAccess->setValLegacy(requestFreqFileLegacy, testRequestValue);
pSysfsAccess->setValLegacy(tdpFreqFileLegacy, testTdpValue);
pSysfsAccess->setValLegacy(actualFreqFileLegacy, testActualValue);
pSysfsAccess->setValLegacy(efficientFreqFileLegacy, testEfficientValue);
EXPECT_EQ(ZE_RESULT_SUCCESS, zesFrequencyGetState(handle, &state));
EXPECT_DOUBLE_EQ(testRequestValue, state.request);
EXPECT_DOUBLE_EQ(testTdpValue, state.tdp);
EXPECT_DOUBLE_EQ(testEfficientValue, state.efficient);
EXPECT_DOUBLE_EQ(testActualValue, state.actual);
EXPECT_EQ(0u, state.throttleReasons);
EXPECT_EQ(nullptr, state.pNext);
EXPECT_LE(state.currentVoltage, 0);
}
}
TEST_F(SysmanDeviceFrequencyFixture, GivenValidFrequencyHandleWhenCallingzesFrequencyGetRangeWithLegacyPathThenVerifyzesFrequencyGetRangeTestCallSucceeds) {
ON_CALL(*pSysfsAccess.get(), read(_, _))
.WillByDefault(::testing::Invoke(pSysfsAccess.get(), &Mock<FrequencySysfsAccess>::getValLegacy));
ON_CALL(*pSysfsAccess.get(), write(_, _))
.WillByDefault(::testing::Invoke(pSysfsAccess.get(), &Mock<FrequencySysfsAccess>::setValLegacy));
ON_CALL(*pSysfsAccess.get(), directoryExists(_))
.WillByDefault(::testing::Invoke(pSysfsAccess.get(), &Mock<FrequencySysfsAccess>::mockDirectoryExistsFailure));
for (auto handle : pSysmanDeviceImp->pFrequencyHandleContext->handleList) {
delete handle;
}
pSysmanDeviceImp->pFrequencyHandleContext->handleList.clear();
pSysmanDeviceImp->pFrequencyHandleContext->init(deviceHandles);
auto handles = get_freq_handles(handleComponentCount);
double minFreqLegacy = 400.0;
double maxFreqLegacy = 1200.0;
pSysfsAccess->setValLegacy(minFreqFileLegacy, minFreqLegacy);
pSysfsAccess->setValLegacy(maxFreqFileLegacy, maxFreqLegacy);
for (auto handle : handles) {
zes_freq_range_t limits;
EXPECT_EQ(ZE_RESULT_SUCCESS, zesFrequencyGetRange(handle, &limits));
EXPECT_DOUBLE_EQ(minFreqLegacy, limits.min);
EXPECT_DOUBLE_EQ(maxFreqLegacy, limits.max);
}
}
TEST_F(SysmanDeviceFrequencyFixture, GivenValidStatePointerWhenValidatingfrequencyGetStateWhenOneOfTheFrequencyStateThenNegativeValueIsReturned) {
auto pFrequencyImp = std::make_unique<FrequencyImp>(pOsSysman, device->toHandle(), ZES_FREQ_DOMAIN_GPU);
zes_freq_state_t state = {};

View File

@@ -41,6 +41,23 @@ TEST_F(SysmanDeviceFixture, GivenCreateFsAccessHandleWhenCallinggetFsAccessThenC
EXPECT_EQ(&pLinuxSysmanImp->getFsAccess(), pLinuxSysmanImp->pFsAccess);
}
TEST_F(SysmanDeviceFixture, GivenCreateFsAccessHandleWhenCallingdirectoryExistsWithDifferentPathsThenDesiredResultsAreObtained) {
auto FsAccess = FsAccess::create();
char cwd[PATH_MAX];
std::string path = getcwd(cwd, PATH_MAX);
EXPECT_TRUE(FsAccess->directoryExists(path));
path = "invalidDiretory";
EXPECT_FALSE(FsAccess->directoryExists(path));
delete FsAccess;
}
TEST_F(SysmanDeviceFixture, GivenCreateSysfsAccessHandleWhenCallingDirectoryExistsWithInvalidPathThenFalseIsRetured) {
auto SysfsAccess = SysfsAccess::create("");
std::string path = "invalidDiretory";
EXPECT_FALSE(SysfsAccess->directoryExists(path));
delete SysfsAccess;
}
TEST_F(SysmanDeviceFixture, GivenValidPathnameWhenCallingFsAccessExistsThenSuccessIsReturned) {
auto FsAccess = pLinuxSysmanImp->getFsAccess();