Pass device handles to sysman power module

Signed-off-by: Mayank Raghuwanshi <mayank.raghuwanshi@intel.com>
This commit is contained in:
Mayank Raghuwanshi
2021-09-21 05:51:12 +00:00
committed by Compute-Runtime-Automation
parent b5e0d32fe1
commit e1ad48ccb5
18 changed files with 434 additions and 188 deletions

View File

@@ -8,6 +8,7 @@ set(L0_SRCS_TOOLS_SYSMAN_POWER_LINUX
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/os_power_imp.cpp
${CMAKE_CURRENT_SOURCE_DIR}/os_power_imp.h
${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/os_power_helper.cpp
)
if(UNIX)

View File

@@ -0,0 +1,19 @@
/*
* Copyright (C) 2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "level_zero/tools/source/sysman/power/linux/os_power_imp.h"
namespace L0 {
bool LinuxPowerImp::isEnergyHwmonDir(std::string name) {
if (isSubdevice == false && (name == i915)) {
return true;
}
return false;
}
} // namespace L0

View File

@@ -32,8 +32,8 @@ void powerGetTimestamp(uint64_t &timestamp) {
}
ze_result_t LinuxPowerImp::getProperties(zes_power_properties_t *pProperties) {
pProperties->onSubdevice = false;
pProperties->subdeviceId = 0;
pProperties->onSubdevice = isSubdevice;
pProperties->subdeviceId = subdeviceId;
pProperties->canControl = canControl;
pProperties->isEnergyThresholdSupported = false;
pProperties->defaultLimit = -1;
@@ -58,16 +58,25 @@ ze_result_t LinuxPowerImp::getProperties(zes_power_properties_t *pProperties) {
return ZE_RESULT_SUCCESS;
}
ze_result_t LinuxPowerImp::getPmtEnergyCounter(zes_power_energy_counter_t *pEnergy) {
const std::string key("PACKAGE_ENERGY");
uint64_t energy = 0;
ze_result_t result = pPmt->readValue(key, energy);
// PMT will return energy counter in Q20 format(fixed point representation) where first 20 bits(from LSB) represent decimal part and remaining integral part which is converted into joule by division with 1048576(2^20) and then converted into microjoules
pEnergy->energy = (energy / 1048576) * convertJouleToMicroJoule;
return result;
}
ze_result_t LinuxPowerImp::getEnergyCounter(zes_power_energy_counter_t *pEnergy) {
ze_result_t result = pSysfsAccess->read(i915HwmonDir + "/" + energyCounterNode, pEnergy->energy);
if (result != ZE_RESULT_SUCCESS) {
const std::string key("PACKAGE_ENERGY");
uint64_t energy = 0;
result = pPmt->readValue(key, energy);
// PMT will return energy counter in Q20 format(fixed point representation) where first 20 bits(from LSB) represent decimal part and remaining integral part which is converted into joule by division with 1048576(2^20) and then converted into microjoules
pEnergy->energy = (energy / 1048576) * convertJouleToMicroJoule;
}
powerGetTimestamp(pEnergy->timestamp);
ze_result_t result = pSysfsAccess->read(energyHwmonDir + "/" + energyCounterNode, pEnergy->energy);
if (result != ZE_RESULT_SUCCESS) {
if (pPmt != nullptr) {
return getPmtEnergyCounter(pEnergy);
}
}
if (result != ZE_RESULT_SUCCESS) {
return getErrorCode(result);
}
return result;
}
@@ -131,6 +140,13 @@ ze_result_t LinuxPowerImp::setLimits(const zes_power_sustained_limit_t *pSustain
if (ZE_RESULT_SUCCESS != result) {
return getErrorCode(result);
}
if (isSustainedPowerLimitEnabled != static_cast<uint64_t>(pSustained->enabled)) {
result = pSysfsAccess->write(i915HwmonDir + "/" + sustainedPowerLimitEnabled, static_cast<int>(pSustained->enabled));
if (ZE_RESULT_SUCCESS != result) {
return getErrorCode(result);
}
isSustainedPowerLimitEnabled = static_cast<uint64_t>(pSustained->enabled);
}
if (isSustainedPowerLimitEnabled) {
val = static_cast<uint32_t>(pSustained->power) * milliFactor; // Convert milliWatts to microwatts
@@ -144,6 +160,7 @@ ze_result_t LinuxPowerImp::setLimits(const zes_power_sustained_limit_t *pSustain
return getErrorCode(result);
}
}
result = ZE_RESULT_SUCCESS;
}
if (pBurst != nullptr) {
result = pSysfsAccess->write(i915HwmonDir + "/" + burstPowerLimitEnabled, static_cast<int>(pBurst->enabled));
@@ -159,7 +176,6 @@ ze_result_t LinuxPowerImp::setLimits(const zes_power_sustained_limit_t *pSustain
}
}
}
return result;
}
@@ -187,7 +203,9 @@ bool LinuxPowerImp::isPowerModuleSupported() {
i915HwmonDir = hwmonDir + "/" + tempHwmonDirEntry;
hwmonDirExists = true;
canControl = true;
break;
}
if (isEnergyHwmonDir(name) == true) {
energyHwmonDir = hwmonDir + "/" + tempHwmonDirEntry;
}
}
if (hwmonDirExists == false) {
@@ -196,16 +214,14 @@ bool LinuxPowerImp::isPowerModuleSupported() {
return true;
}
LinuxPowerImp::LinuxPowerImp(OsSysman *pOsSysman) {
LinuxPowerImp::LinuxPowerImp(OsSysman *pOsSysman, ze_bool_t onSubdevice, uint32_t subdeviceId) : isSubdevice(onSubdevice), subdeviceId(subdeviceId) {
LinuxSysmanImp *pLinuxSysmanImp = static_cast<LinuxSysmanImp *>(pOsSysman);
// Lets hardcode subDeviceId to 0, as we are expecting this code to execute on device without subdevice
uint32_t subDeviceId = 0;
pPmt = pLinuxSysmanImp->getPlatformMonitoringTechAccess(subDeviceId);
pPmt = pLinuxSysmanImp->getPlatformMonitoringTechAccess(subdeviceId);
pSysfsAccess = &pLinuxSysmanImp->getSysfsAccess();
}
OsPower *OsPower::create(OsSysman *pOsSysman) {
LinuxPowerImp *pLinuxPowerImp = new LinuxPowerImp(pOsSysman);
OsPower *OsPower::create(OsSysman *pOsSysman, ze_bool_t onSubdevice, uint32_t subdeviceId) {
LinuxPowerImp *pLinuxPowerImp = new LinuxPowerImp(pOsSysman, onSubdevice, subdeviceId);
return static_cast<OsPower *>(pLinuxPowerImp);
}

View File

@@ -27,7 +27,9 @@ class LinuxPowerImp : public OsPower, NEO::NonCopyableOrMovableClass {
ze_result_t setEnergyThreshold(double threshold) override;
bool isPowerModuleSupported() override;
LinuxPowerImp(OsSysman *pOsSysman);
bool isEnergyHwmonDir(std::string name);
ze_result_t getPmtEnergyCounter(zes_power_energy_counter_t *pEnergy);
LinuxPowerImp(OsSysman *pOsSysman, ze_bool_t onSubdevice, uint32_t subdeviceId);
LinuxPowerImp() = default;
~LinuxPowerImp() override = default;
@@ -37,6 +39,7 @@ class LinuxPowerImp : public OsPower, NEO::NonCopyableOrMovableClass {
private:
std::string i915HwmonDir;
std::string energyHwmonDir;
static const std::string hwmonDir;
static const std::string i915;
static const std::string sustainedPowerLimitEnabled;
@@ -49,6 +52,8 @@ class LinuxPowerImp : public OsPower, NEO::NonCopyableOrMovableClass {
static const std::string minPowerLimit;
static const std::string maxPowerLimit;
bool canControl = false;
bool isSubdevice = false;
uint32_t subdeviceId = 0;
ze_result_t getErrorCode(ze_result_t result) {
if (result == ZE_RESULT_ERROR_NOT_AVAILABLE) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 Intel Corporation
* Copyright (C) 2020-2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -22,7 +22,7 @@ class OsPower {
virtual ze_result_t setEnergyThreshold(double threshold) = 0;
virtual bool isPowerModuleSupported() = 0;
static OsPower *create(OsSysman *pOsSysman);
static OsPower *create(OsSysman *pOsSysman, ze_bool_t onSubdevice, uint32_t subdeviceId);
virtual ~OsPower() = default;
};

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 Intel Corporation
* Copyright (C) 2020-2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -19,14 +19,20 @@ PowerHandleContext::~PowerHandleContext() {
}
}
void PowerHandleContext::init() {
Power *pPower = new PowerImp(pOsSysman);
void PowerHandleContext::createHandle(ze_device_handle_t deviceHandle) {
Power *pPower = new PowerImp(pOsSysman, deviceHandle);
if (pPower->initSuccess == true) {
handleList.push_back(pPower);
} else {
delete pPower;
}
}
ze_result_t PowerHandleContext::init(std::vector<ze_device_handle_t> &deviceHandles) {
for (const auto &deviceHandle : deviceHandles) {
createHandle(deviceHandle);
}
return ZE_RESULT_SUCCESS;
}
ze_result_t PowerHandleContext::powerGet(uint32_t *pCount, zes_pwr_handle_t *phPower) {
uint32_t handleListSize = static_cast<uint32_t>(handleList.size());

View File

@@ -1,11 +1,12 @@
/*
* Copyright (C) 2020 Intel Corporation
* Copyright (C) 2020-2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include "level_zero/core/source/device/device.h"
#include <level_zero/zes_api.h>
#include <vector>
@@ -41,12 +42,14 @@ struct PowerHandleContext {
PowerHandleContext(OsSysman *pOsSysman) : pOsSysman(pOsSysman){};
~PowerHandleContext();
void init();
ze_result_t init(std::vector<ze_device_handle_t> &deviceHandles);
ze_result_t powerGet(uint32_t *pCount, zes_pwr_handle_t *phPower);
OsSysman *pOsSysman = nullptr;
std::vector<Power *> handleList = {};
private:
void createHandle(ze_device_handle_t deviceHandle);
};
} // namespace L0

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 Intel Corporation
* Copyright (C) 2020-2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -35,10 +35,11 @@ ze_result_t PowerImp::powerSetEnergyThreshold(double threshold) {
return pOsPower->setEnergyThreshold(threshold);
}
PowerImp::PowerImp(OsSysman *pOsSysman) {
pOsPower = OsPower::create(pOsSysman);
PowerImp::PowerImp(OsSysman *pOsSysman, ze_device_handle_t handle) : deviceHandle(handle) {
ze_device_properties_t deviceProperties = {};
Device::fromHandle(deviceHandle)->getProperties(&deviceProperties);
pOsPower = OsPower::create(pOsSysman, deviceProperties.flags & ZE_DEVICE_PROPERTY_FLAG_SUBDEVICE, deviceProperties.subdeviceId);
UNRECOVERABLE_IF(nullptr == pOsPower);
init();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 Intel Corporation
* Copyright (C) 2020-2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -23,10 +23,13 @@ class PowerImp : public Power, NEO::NonCopyableOrMovableClass {
ze_result_t powerSetEnergyThreshold(double threshold) override;
PowerImp() = default;
PowerImp(OsSysman *pOsSysman);
PowerImp(OsSysman *pOsSysman, ze_device_handle_t device);
~PowerImp() override;
OsPower *pOsPower = nullptr;
void init();
private:
ze_device_handle_t deviceHandle = {};
};
} // namespace L0

View File

@@ -330,13 +330,13 @@ bool WddmPowerImp::isPowerModuleSupported() {
return ((status == ZE_RESULT_SUCCESS) && (enabled));
}
WddmPowerImp::WddmPowerImp(OsSysman *pOsSysman) {
WddmPowerImp::WddmPowerImp(OsSysman *pOsSysman, ze_bool_t onSubdevice, uint32_t subdeviceId) {
WddmSysmanImp *pWddmSysmanImp = static_cast<WddmSysmanImp *>(pOsSysman);
pKmdSysManager = &pWddmSysmanImp->getKmdSysManager();
}
OsPower *OsPower::create(OsSysman *pOsSysman) {
WddmPowerImp *pWddmPowerImp = new WddmPowerImp(pOsSysman);
OsPower *OsPower::create(OsSysman *pOsSysman, ze_bool_t onSubdevice, uint32_t subdeviceId) {
WddmPowerImp *pWddmPowerImp = new WddmPowerImp(pOsSysman, onSubdevice, subdeviceId);
return static_cast<OsPower *>(pWddmPowerImp);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 Intel Corporation
* Copyright (C) 2020-2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -23,7 +23,7 @@ class WddmPowerImp : public OsPower, NEO::NonCopyableOrMovableClass {
ze_result_t setEnergyThreshold(double threshold) override;
bool isPowerModuleSupported() override;
WddmPowerImp(OsSysman *pOsSysman);
WddmPowerImp(OsSysman *pOsSysman, ze_bool_t onSubdevice, uint32_t subdeviceId);
WddmPowerImp() = default;
~WddmPowerImp() override = default;

View File

@@ -76,7 +76,7 @@ ze_result_t SysmanDeviceImp::init() {
return result;
}
if (pPowerHandleContext) {
pPowerHandleContext->init();
pPowerHandleContext->init(deviceHandles);
}
if (pFrequencyHandleContext) {
pFrequencyHandleContext->init(deviceHandles);