feature: Add common Interface for timestamp in sysman

Related-To: LOCI-4511

Signed-off-by: Mayank Raghuwanshi <mayank.raghuwanshi@intel.com>
This commit is contained in:
Mayank Raghuwanshi
2023-06-13 05:54:39 +00:00
committed by Compute-Runtime-Automation
parent b6e76b9118
commit 171e63409c
16 changed files with 35 additions and 94 deletions

View File

@@ -27,11 +27,6 @@ namespace Sysman {
const std::string LinuxMemoryImp::deviceMemoryHealth("device_memory_health");
void memoryGetTimeStamp(uint64_t &timestamp) {
std::chrono::time_point<std::chrono::steady_clock> ts = std::chrono::steady_clock::now();
timestamp = std::chrono::duration_cast<std::chrono::microseconds>(ts.time_since_epoch()).count();
}
LinuxMemoryImp::LinuxMemoryImp(OsSysman *pOsSysman, ze_bool_t onSubdevice, uint32_t subdeviceId) : isSubdevice(onSubdevice), subdeviceId(subdeviceId) {
pLinuxSysmanImp = static_cast<LinuxSysmanImp *>(pOsSysman);
pDrm = pLinuxSysmanImp->getDrm();
@@ -187,13 +182,11 @@ ze_result_t LinuxMemoryImp::getBandwidthForDg2(zes_mem_bandwidth_t *pBandwidth)
return result;
}
pBandwidth->maxBandwidth = 0u;
uint64_t timeStampVal = 0;
const std::string maxBwFile = "prelim_lmem_max_bw_Mbps";
uint64_t maxBw = 0;
pSysfsAccess->read(maxBwFile, maxBw);
pBandwidth->maxBandwidth = maxBw * MbpsToBytesPerSecond;
memoryGetTimeStamp(timeStampVal);
pBandwidth->timestamp = timeStampVal;
pBandwidth->timestamp = SysmanDevice::getSysmanTimestamp();
return result;
}
@@ -258,10 +251,7 @@ ze_result_t LinuxMemoryImp::getHbmBandwidthPVC(uint32_t numHbmModules, zes_mem_b
pBandwidth->writeCounter = writeCounterH;
pBandwidth->writeCounter = (pBandwidth->writeCounter << 32) | static_cast<uint64_t>(writeCounterL);
pBandwidth->writeCounter = (pBandwidth->writeCounter * transactionSize);
uint64_t timeStampVal = 0;
memoryGetTimeStamp(timeStampVal);
pBandwidth->timestamp = timeStampVal;
pBandwidth->timestamp = SysmanDevice::getSysmanTimestamp();
uint64_t hbmFrequency = 0;
getHbmFrequency(productFamily, stepping, hbmFrequency);
@@ -311,24 +301,7 @@ ze_result_t LinuxMemoryImp::getHbmBandwidth(uint32_t numHbmModules, zes_mem_band
constexpr uint64_t transactionSize = 32;
pBandwidth->readCounter = pBandwidth->readCounter * transactionSize;
pBandwidth->writeCounter = pBandwidth->writeCounter * transactionSize;
uint32_t timeStampL = 0;
std::string timeStamp = vfId + "_TIMESTAMP_L";
result = pPmt->readValue(timeStamp, timeStampL);
if (result != ZE_RESULT_SUCCESS) {
NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s():readValue for timeStampL returning error:0x%x \n", __FUNCTION__, result);
return result;
}
uint32_t timeStampH = 0;
timeStamp = vfId + "_TIMESTAMP_H";
result = pPmt->readValue(timeStamp, timeStampH);
if (result != ZE_RESULT_SUCCESS) {
NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s():readValue for timeStampH returning error:0x%x \n", __FUNCTION__, result);
return result;
}
pBandwidth->timestamp = timeStampH;
pBandwidth->timestamp = (pBandwidth->timestamp << 32) | static_cast<uint64_t>(timeStampL);
pBandwidth->timestamp = SysmanDevice::getSysmanTimestamp();
uint64_t hbmFrequency = 0;
getHbmFrequency(productFamily, stepping, hbmFrequency);

View File

@@ -28,11 +28,6 @@ const std::string LinuxPowerImp::defaultPowerLimit("power_default_limit");
const std::string LinuxPowerImp::minPowerLimit("power_min_limit");
const std::string LinuxPowerImp::maxPowerLimit("power_max_limit");
void powerGetTimestamp(uint64_t &timestamp) {
std::chrono::time_point<std::chrono::steady_clock> ts = std::chrono::steady_clock::now();
timestamp = std::chrono::duration_cast<std::chrono::microseconds>(ts.time_since_epoch()).count();
}
ze_result_t LinuxPowerImp::getProperties(zes_power_properties_t *pProperties) {
pProperties->onSubdevice = isSubdevice;
pProperties->subdeviceId = subdeviceId;
@@ -75,7 +70,7 @@ ze_result_t LinuxPowerImp::getPmtEnergyCounter(zes_power_energy_counter_t *pEner
return result;
}
ze_result_t LinuxPowerImp::getEnergyCounter(zes_power_energy_counter_t *pEnergy) {
powerGetTimestamp(pEnergy->timestamp);
pEnergy->timestamp = SysmanDevice::getSysmanTimestamp();
ze_result_t result = pSysfsAccess->read(i915HwmonDir + "/" + energyCounterNode, pEnergy->energy);
if (result != ZE_RESULT_SUCCESS) {
if (pPmt != nullptr) {

View File

@@ -23,11 +23,6 @@ const std::string LinuxPowerImp::sustainedPowerLimitInterval("power1_max_interva
const std::string LinuxPowerImp::energyCounterNode("energy1_input");
const std::string LinuxPowerImp::defaultPowerLimit("power1_rated_max");
void powerGetTimestamp(uint64_t &timestamp) {
std::chrono::time_point<std::chrono::steady_clock> ts = std::chrono::steady_clock::now();
timestamp = std::chrono::duration_cast<std::chrono::microseconds>(ts.time_since_epoch()).count();
}
ze_result_t LinuxPowerImp::getProperties(zes_power_properties_t *pProperties) {
pProperties->onSubdevice = isSubdevice;
pProperties->subdeviceId = subdeviceId;
@@ -74,7 +69,7 @@ ze_result_t LinuxPowerImp::getPmtEnergyCounter(zes_power_energy_counter_t *pEner
return result;
}
ze_result_t LinuxPowerImp::getEnergyCounter(zes_power_energy_counter_t *pEnergy) {
powerGetTimestamp(pEnergy->timestamp);
pEnergy->timestamp = SysmanDevice::getSysmanTimestamp();
ze_result_t result = pSysfsAccess->read(i915HwmonDir + "/" + energyCounterNode, pEnergy->energy);
if (result != ZE_RESULT_SUCCESS) {
if (pPmt != nullptr) {

View File

@@ -7,6 +7,7 @@
#include "level_zero/sysman/source/power/windows/sysman_os_power_imp.h"
#include "level_zero/sysman/source/sysman_const.h"
#include "level_zero/sysman/source/windows/sysman_kmd_sys_manager.h"
#include "level_zero/sysman/source/windows/zes_os_sysman_imp.h"
@@ -70,7 +71,6 @@ ze_result_t WddmPowerImp::getPropertiesExt(zes_power_ext_properties_t *pExtPoper
ze_result_t WddmPowerImp::getEnergyCounter(zes_power_energy_counter_t *pEnergy) {
uint64_t energyCounter64Bit = 0;
uint64_t valueTimeStamp = 0;
KmdSysman::RequestProperty request;
KmdSysman::ResponseProperty response;
@@ -83,8 +83,7 @@ ze_result_t WddmPowerImp::getEnergyCounter(zes_power_energy_counter_t *pEnergy)
if (status == ZE_RESULT_SUCCESS) {
memcpy_s(&energyCounter64Bit, sizeof(uint64_t), response.dataBuffer, sizeof(uint64_t));
pEnergy->energy = energyCounter64Bit;
memcpy_s(&valueTimeStamp, sizeof(uint64_t), (response.dataBuffer + sizeof(uint64_t)), sizeof(uint64_t));
pEnergy->timestamp = valueTimeStamp;
pEnergy->timestamp = SysmanDevice::getSysmanTimestamp();
}
return status;

View File

@@ -159,5 +159,10 @@ ze_result_t SysmanDevice::deviceEventRegister(zes_device_handle_t hDevice, zes_e
return pSysmanDevice->deviceEventRegister(events);
}
uint64_t SysmanDevice::getSysmanTimestamp() {
std::chrono::time_point<std::chrono::steady_clock> ts = std::chrono::steady_clock::now();
return std::chrono::duration_cast<std::chrono::microseconds>(ts.time_since_epoch()).count();
}
} // namespace Sysman
} // namespace L0

View File

@@ -113,6 +113,7 @@ struct SysmanDevice : _ze_device_handle_t {
static ze_result_t pciGetStats(zes_device_handle_t hDevice, zes_pci_stats_t *pStats);
virtual ze_result_t pciGetStats(zes_pci_stats_t *pStats) = 0;
static ze_result_t fanGet(zes_device_handle_t hDevice, uint32_t *pCount, zes_fan_handle_t *phFan);
virtual ze_result_t fanGet(uint32_t *pCount, zes_fan_handle_t *phFan) = 0;
@@ -120,6 +121,7 @@ struct SysmanDevice : _ze_device_handle_t {
virtual ze_result_t deviceEventRegister(zes_event_type_flags_t events) = 0;
virtual bool deviceEventListen(zes_event_type_flags_t &pEvent, uint64_t timeout) = 0;
static uint64_t getSysmanTimestamp();
virtual OsSysman *deviceGetOsInterface() = 0;
};

View File

@@ -140,7 +140,7 @@ TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerEnergyCoun
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
EXPECT_EQ(energyCounter.energy, pKmdSysManager->mockEnergyCounter64Bit);
EXPECT_EQ(energyCounter.timestamp, pKmdSysManager->mockTimeStamp);
EXPECT_GT(energyCounter.timestamp, 0u);
}
}

View File

@@ -183,13 +183,11 @@ ze_result_t LinuxMemoryImp::getBandwidthForDg2(zes_mem_bandwidth_t *pBandwidth)
return result;
}
pBandwidth->maxBandwidth = 0u;
uint64_t timeStampVal = 0;
const std::string maxBwFile = "prelim_lmem_max_bw_Mbps";
uint64_t maxBw = 0;
pSysfsAccess->read(maxBwFile, maxBw);
pBandwidth->maxBandwidth = maxBw * MbpsToBytesPerSecond;
memoryGetTimeStamp(timeStampVal);
pBandwidth->timestamp = timeStampVal;
pBandwidth->timestamp = SysmanDevice::getSysmanTimestamp();
return result;
}
@@ -233,23 +231,7 @@ ze_result_t LinuxMemoryImp::getHbmBandwidth(uint32_t numHbmModules, zes_mem_band
constexpr uint64_t transactionSize = 32;
pBandwidth->readCounter = pBandwidth->readCounter * transactionSize;
pBandwidth->writeCounter = pBandwidth->writeCounter * transactionSize;
uint32_t timeStampL = 0;
std::string timeStamp = vfId + "_TIMESTAMP_L";
result = pPmt->readValue(timeStamp, timeStampL);
if (result != ZE_RESULT_SUCCESS) {
NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s():readValue for timeStampL returning error:0x%x \n", __FUNCTION__, result);
return result;
}
uint32_t timeStampH = 0;
timeStamp = vfId + "_TIMESTAMP_H";
result = pPmt->readValue(timeStamp, timeStampH);
if (result != ZE_RESULT_SUCCESS) {
NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s():readValue for timeStampH returning error:0x%x \n", __FUNCTION__, result);
return result;
}
pBandwidth->timestamp = timeStampH;
pBandwidth->timestamp = (pBandwidth->timestamp << 32) | static_cast<uint64_t>(timeStampL);
pBandwidth->timestamp = SysmanDevice::getSysmanTimestamp();
uint64_t hbmFrequency = 0;
getHbmFrequency(productFamily, stepping, hbmFrequency);

View File

@@ -9,6 +9,7 @@
#include "shared/source/os_interface/windows/wddm/wddm.h"
#include "level_zero/tools/source/sysman/sysman.h"
#include "level_zero/tools/source/sysman/windows/kmd_sys_manager.h"
template <typename I>
@@ -211,8 +212,7 @@ ze_result_t WddmMemoryImp::getBandwidth(zes_mem_bandwidth_t *pBandwidth) {
pBandwidth->writeCounter = retValu64;
}
std::chrono::time_point<std::chrono::steady_clock> ts = std::chrono::steady_clock::now();
pBandwidth->timestamp = std::chrono::duration_cast<std::chrono::microseconds>(ts.time_since_epoch()).count();
pBandwidth->timestamp = SysmanDevice::getSysmanTimestamp();
return ZE_RESULT_SUCCESS;
}

View File

@@ -27,11 +27,6 @@ const std::string LinuxPowerImp::defaultPowerLimit("power_default_limit");
const std::string LinuxPowerImp::minPowerLimit("power_min_limit");
const std::string LinuxPowerImp::maxPowerLimit("power_max_limit");
void powerGetTimestamp(uint64_t &timestamp) {
std::chrono::time_point<std::chrono::steady_clock> ts = std::chrono::steady_clock::now();
timestamp = std::chrono::duration_cast<std::chrono::microseconds>(ts.time_since_epoch()).count();
}
ze_result_t LinuxPowerImp::getProperties(zes_power_properties_t *pProperties) {
pProperties->onSubdevice = isSubdevice;
pProperties->subdeviceId = subdeviceId;
@@ -74,7 +69,7 @@ ze_result_t LinuxPowerImp::getPmtEnergyCounter(zes_power_energy_counter_t *pEner
return result;
}
ze_result_t LinuxPowerImp::getEnergyCounter(zes_power_energy_counter_t *pEnergy) {
powerGetTimestamp(pEnergy->timestamp);
pEnergy->timestamp = SysmanDevice::getSysmanTimestamp();
ze_result_t result = pSysfsAccess->read(i915HwmonDir + "/" + energyCounterNode, pEnergy->energy);
if (result != ZE_RESULT_SUCCESS) {
if (pPmt != nullptr) {

View File

@@ -11,7 +11,7 @@
#include "level_zero/tools/source/sysman/linux/os_sysman_imp.h"
#include "level_zero/tools/source/sysman/linux/pmt/pmt.h"
#include "level_zero/tools/source/sysman/sysman_const.h"
#include "level_zero/tools/source/sysman/sysman.h"
namespace L0 {
@@ -22,11 +22,6 @@ const std::string LinuxPowerImp::sustainedPowerLimitInterval("power1_max_interva
const std::string LinuxPowerImp::energyCounterNode("energy1_input");
const std::string LinuxPowerImp::defaultPowerLimit("power1_rated_max");
void powerGetTimestamp(uint64_t &timestamp) {
std::chrono::time_point<std::chrono::steady_clock> ts = std::chrono::steady_clock::now();
timestamp = std::chrono::duration_cast<std::chrono::microseconds>(ts.time_since_epoch()).count();
}
ze_result_t LinuxPowerImp::getProperties(zes_power_properties_t *pProperties) {
pProperties->onSubdevice = isSubdevice;
pProperties->subdeviceId = subdeviceId;
@@ -73,7 +68,7 @@ ze_result_t LinuxPowerImp::getPmtEnergyCounter(zes_power_energy_counter_t *pEner
return result;
}
ze_result_t LinuxPowerImp::getEnergyCounter(zes_power_energy_counter_t *pEnergy) {
powerGetTimestamp(pEnergy->timestamp);
pEnergy->timestamp = SysmanDevice::getSysmanTimestamp();
ze_result_t result = pSysfsAccess->read(i915HwmonDir + "/" + energyCounterNode, pEnergy->energy);
if (result != ZE_RESULT_SUCCESS) {
if (pPmt != nullptr) {

View File

@@ -7,6 +7,7 @@
#include "level_zero/tools/source/sysman/power/windows/os_power_imp.h"
#include "level_zero/tools/source/sysman/sysman.h"
#include "level_zero/tools/source/sysman/sysman_const.h"
#include "level_zero/tools/source/sysman/windows/kmd_sys_manager.h"
@@ -71,7 +72,6 @@ ze_result_t WddmPowerImp::getPropertiesExt(zes_power_ext_properties_t *pExtPoper
ze_result_t WddmPowerImp::getEnergyCounter(zes_power_energy_counter_t *pEnergy) {
uint64_t energyCounter64Bit = 0;
uint64_t valueTimeStamp = 0;
KmdSysman::RequestProperty request;
KmdSysman::ResponseProperty response;
@@ -84,8 +84,7 @@ ze_result_t WddmPowerImp::getEnergyCounter(zes_power_energy_counter_t *pEnergy)
if (status == ZE_RESULT_SUCCESS) {
memcpy_s(&energyCounter64Bit, sizeof(uint64_t), response.dataBuffer, sizeof(uint64_t));
pEnergy->energy = energyCounter64Bit;
memcpy_s(&valueTimeStamp, sizeof(uint64_t), (response.dataBuffer + sizeof(uint64_t)), sizeof(uint64_t));
pEnergy->timestamp = valueTimeStamp;
pEnergy->timestamp = SysmanDevice::getSysmanTimestamp();
}
return status;

View File

@@ -307,4 +307,9 @@ ze_result_t SysmanDevice::deviceSetEccState(zes_device_handle_t hDevice, const z
return pSysmanDevice->deviceSetEccState(newState, pState);
}
uint64_t SysmanDevice::getSysmanTimestamp() {
std::chrono::time_point<std::chrono::steady_clock> ts = std::chrono::steady_clock::now();
return std::chrono::duration_cast<std::chrono::microseconds>(ts.time_since_epoch()).count();
}
} // namespace L0

View File

@@ -60,6 +60,7 @@ struct SysmanDevice : _ze_device_handle_t {
static ze_result_t deviceGetEccState(zes_device_handle_t hDevice, zes_device_ecc_properties_t *pState);
static ze_result_t deviceSetEccState(zes_device_handle_t hDevice, const zes_device_ecc_desc_t *newState, zes_device_ecc_properties_t *pState);
static bool deviceEventListen(zes_device_handle_t hDevice, zes_event_type_flags_t &pEvent, uint64_t timeout);
static uint64_t getSysmanTimestamp();
virtual ze_result_t performanceGet(uint32_t *pCount, zes_perf_handle_t *phPerformance) = 0;
virtual ze_result_t powerGet(uint32_t *pCount, zes_pwr_handle_t *phPower) = 0;

View File

@@ -605,7 +605,7 @@ HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingzesSysmanM
for (auto &handle : handles) {
zes_mem_bandwidth_t bandwidth{};
uint64_t expectedReadCounters = 0, expectedWriteCounters = 0;
uint64_t expectedTimestamp = 0, expectedBandwidth = 0;
uint64_t expectedBandwidth = 0;
zes_mem_properties_t properties = {ZES_STRUCTURE_TYPE_MEM_PROPERTIES};
zesMemoryGetProperties(handle, &properties);
@@ -623,10 +623,7 @@ HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingzesSysmanM
EXPECT_EQ(bandwidth.readCounter, expectedReadCounters);
expectedWriteCounters = vF0Hbm0WriteValue + vF0Hbm1WriteValue + vF0Hbm2WriteValue + vF0Hbm3WriteValue;
EXPECT_EQ(bandwidth.writeCounter, expectedWriteCounters);
expectedTimestamp |= vF0TimestampHValue;
expectedTimestamp = (expectedTimestamp << 32) | vF0TimestampLValue;
EXPECT_EQ(bandwidth.timestamp, expectedTimestamp);
EXPECT_EQ(bandwidth.timestamp, expectedTimestamp);
EXPECT_GT(bandwidth.timestamp, 0u);
expectedBandwidth = 128 * hbmRP0Frequency * 1000 * 1000 * 4;
EXPECT_EQ(bandwidth.maxBandwidth, expectedBandwidth);
}
@@ -639,7 +636,7 @@ HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingzesSysmanM
for (auto &handle : handles) {
zes_mem_bandwidth_t bandwidth{};
uint64_t expectedReadCounters = 0, expectedWriteCounters = 0;
uint64_t expectedTimestamp = 0, expectedBandwidth = 0;
uint64_t expectedBandwidth = 0;
zes_mem_properties_t properties = {ZES_STRUCTURE_TYPE_MEM_PROPERTIES};
zesMemoryGetProperties(handle, &properties);
@@ -657,9 +654,7 @@ HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingzesSysmanM
EXPECT_EQ(bandwidth.readCounter, expectedReadCounters);
expectedWriteCounters = vF1Hbm0WriteValue + vF1Hbm1WriteValue + vF1Hbm2WriteValue + vF1Hbm3WriteValue;
EXPECT_EQ(bandwidth.writeCounter, expectedWriteCounters);
expectedTimestamp |= vF1TimestampHValue;
expectedTimestamp = (expectedTimestamp << 32) | vF1TimestampLValue;
EXPECT_EQ(bandwidth.timestamp, expectedTimestamp);
EXPECT_GT(bandwidth.timestamp, 0u);
expectedBandwidth = 128 * hbmRP0Frequency * 1000 * 1000 * 4;
EXPECT_EQ(bandwidth.maxBandwidth, expectedBandwidth);
}

View File

@@ -156,7 +156,7 @@ TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerEnergyCoun
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
EXPECT_EQ(energyCounter.energy, pKmdSysManager->mockEnergyCounter64Bit);
EXPECT_EQ(energyCounter.timestamp, pKmdSysManager->mockTimeStamp);
EXPECT_GT(energyCounter.timestamp, 0u);
}
}