Skip to content

Commit 4ae2f6e

Browse files
Sysman: Add support for device level energy counters
Related-To: LOCI-2724 Signed-off-by: Bellekallu Rajkiran <[email protected]>
1 parent 0134845 commit 4ae2f6e

File tree

6 files changed

+26
-21
lines changed

6 files changed

+26
-21
lines changed

level_zero/tools/source/sysman/power/power.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@ void PowerHandleContext::createHandle(ze_device_handle_t deviceHandle) {
2727
delete pPower;
2828
}
2929
}
30-
ze_result_t PowerHandleContext::init(std::vector<ze_device_handle_t> &deviceHandles) {
30+
ze_result_t PowerHandleContext::init(std::vector<ze_device_handle_t> &deviceHandles, ze_device_handle_t coreDevice) {
31+
// Create Handle for device level power
32+
if (deviceHandles.size() > 1) {
33+
createHandle(coreDevice);
34+
}
35+
3136
for (const auto &deviceHandle : deviceHandles) {
3237
createHandle(deviceHandle);
3338
}

level_zero/tools/source/sysman/power/power.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ struct PowerHandleContext {
4242
PowerHandleContext(OsSysman *pOsSysman) : pOsSysman(pOsSysman){};
4343
~PowerHandleContext();
4444

45-
ze_result_t init(std::vector<ze_device_handle_t> &deviceHandles);
45+
ze_result_t init(std::vector<ze_device_handle_t> &deviceHandles, ze_device_handle_t coreDevice);
4646
ze_result_t powerGet(uint32_t *pCount, zes_pwr_handle_t *phPower);
4747

4848
OsSysman *pOsSysman = nullptr;

level_zero/tools/source/sysman/sysman_imp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ ze_result_t SysmanDeviceImp::init() {
8181
return result;
8282
}
8383
if (pPowerHandleContext) {
84-
pPowerHandleContext->init(deviceHandles);
84+
pPowerHandleContext->init(deviceHandles, hCoreDevice);
8585
}
8686
if (pFrequencyHandleContext) {
8787
pFrequencyHandleContext->init(deviceHandles);

level_zero/tools/test/unit_tests/sources/sysman/power/linux/mock_sysfs_power.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ class SysmanDevicePowerFixture : public SysmanDeviceFixture {
390390
pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject.emplace(deviceProperties.subdeviceId, pPmt);
391391
}
392392

393-
pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles);
393+
pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles, device->toHandle());
394394
}
395395
void TearDown() override {
396396
if (!sysmanUltsEnable) {
@@ -462,7 +462,7 @@ class SysmanDevicePowerMultiDeviceFixture : public SysmanMultiDeviceFixture {
462462
pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject.emplace(deviceProperties.subdeviceId, pPmt);
463463
}
464464

465-
pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles);
465+
pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles, device->toHandle());
466466
}
467467
void TearDown() override {
468468
if (!sysmanUltsEnable) {

level_zero/tools/test/unit_tests/sources/sysman/power/linux/test_zes_power.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerProperties
9090
delete handle;
9191
}
9292
pSysmanDeviceImp->pPowerHandleContext->handleList.clear();
93-
pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles);
93+
pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles, device->toHandle());
9494
auto handles = getPowerHandles(powerHandleComponentCount);
9595
for (auto handle : handles) {
9696
zes_power_properties_t properties;
@@ -114,7 +114,7 @@ TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerProperties
114114
delete handle;
115115
}
116116
pSysmanDeviceImp->pPowerHandleContext->handleList.clear();
117-
pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles);
117+
pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles, device->toHandle());
118118
auto handles = getPowerHandles(powerHandleComponentCount);
119119
for (auto handle : handles) {
120120
zes_power_properties_t properties;
@@ -137,7 +137,7 @@ TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerProperties
137137
delete handle;
138138
}
139139
pSysmanDeviceImp->pPowerHandleContext->handleList.clear();
140-
pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles);
140+
pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles, device->toHandle());
141141
auto handles = getPowerHandles(powerHandleComponentCount);
142142
for (auto handle : handles) {
143143
zes_power_properties_t properties;
@@ -387,7 +387,7 @@ TEST_F(SysmanDevicePowerFixture, GivenGetPowerLimitsWhenPowerLimitsAreDisabledWh
387387
TEST_F(SysmanDevicePowerFixture, GivenScanDiectoriesFailAndPmtIsNotNullPointerThenPowerModuleIsSupported) {
388388
EXPECT_CALL(*pSysfsAccess.get(), scanDirEntries(_, _))
389389
.WillRepeatedly(Return(ZE_RESULT_ERROR_NOT_AVAILABLE));
390-
pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles);
390+
pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles, device->toHandle());
391391
ze_device_properties_t deviceProperties = {ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES};
392392
Device::fromHandle(device)->getProperties(&deviceProperties);
393393
PublicLinuxPowerImp *pPowerImp = new PublicLinuxPowerImp(pOsSysman, deviceProperties.flags & ZE_DEVICE_PROPERTY_FLAG_SUBDEVICE, deviceProperties.subdeviceId);
@@ -402,7 +402,7 @@ TEST_F(SysmanDevicePowerFixture, GivenComponentCountZeroWhenEnumeratingPowerDoma
402402
delete handle;
403403
}
404404
pSysmanDeviceImp->pPowerHandleContext->handleList.clear();
405-
pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles);
405+
pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles, device->toHandle());
406406
uint32_t count = 0;
407407
EXPECT_EQ(zesDeviceEnumPowerDomains(device->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS);
408408
EXPECT_EQ(count, powerHandleComponentCount);
@@ -415,7 +415,7 @@ TEST_F(SysmanDevicePowerFixture, GivenInvalidComponentCountWhenEnumeratingPowerD
415415
delete handle;
416416
}
417417
pSysmanDeviceImp->pPowerHandleContext->handleList.clear();
418-
pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles);
418+
pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles, device->toHandle());
419419
uint32_t count = 0;
420420
EXPECT_EQ(zesDeviceEnumPowerDomains(device->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS);
421421
EXPECT_EQ(count, powerHandleComponentCount);
@@ -432,7 +432,7 @@ TEST_F(SysmanDevicePowerFixture, GivenComponentCountZeroWhenEnumeratingPowerDoma
432432
delete handle;
433433
}
434434
pSysmanDeviceImp->pPowerHandleContext->handleList.clear();
435-
pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles);
435+
pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles, device->toHandle());
436436
uint32_t count = 0;
437437
EXPECT_EQ(zesDeviceEnumPowerDomains(device->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS);
438438
EXPECT_EQ(count, powerHandleComponentCount);
@@ -451,7 +451,7 @@ TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerProperties
451451
delete handle;
452452
}
453453
pSysmanDeviceImp->pPowerHandleContext->handleList.clear();
454-
pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles);
454+
pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles, device->toHandle());
455455
auto handles = getPowerHandles(powerHandleComponentCount);
456456

457457
for (auto handle : handles) {
@@ -469,7 +469,7 @@ TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerEnergyCoun
469469
delete handle;
470470
}
471471
pSysmanDeviceImp->pPowerHandleContext->handleList.clear();
472-
pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles);
472+
pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles, device->toHandle());
473473
auto handles = getPowerHandles(powerHandleComponentCount);
474474

475475
for (auto &deviceHandle : deviceHandles) {
@@ -505,7 +505,7 @@ TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerEnergyCoun
505505
pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject.emplace(deviceProperties.subdeviceId, nullptr);
506506
}
507507
pSysmanDeviceImp->pPowerHandleContext->handleList.clear();
508-
pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles);
508+
pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles, device->toHandle());
509509
auto handles = getPowerHandles(powerHandleComponentCount);
510510

511511
for (auto handle : handles) {
@@ -521,7 +521,7 @@ TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerEnergyThre
521521
delete handle;
522522
}
523523
pSysmanDeviceImp->pPowerHandleContext->handleList.clear();
524-
pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles);
524+
pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles, device->toHandle());
525525
zes_energy_threshold_t threshold;
526526
auto handles = getPowerHandles(powerHandleComponentCount);
527527
for (auto handle : handles) {
@@ -536,7 +536,7 @@ TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenSettingPowerEnergyThre
536536
delete handle;
537537
}
538538
pSysmanDeviceImp->pPowerHandleContext->handleList.clear();
539-
pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles);
539+
pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles, device->toHandle());
540540
double threshold = 0;
541541
auto handles = getPowerHandles(powerHandleComponentCount);
542542
for (auto handle : handles) {
@@ -551,7 +551,7 @@ TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerLimitsThen
551551
delete handle;
552552
}
553553
pSysmanDeviceImp->pPowerHandleContext->handleList.clear();
554-
pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles);
554+
pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles, device->toHandle());
555555
auto handles = getPowerHandles(powerHandleComponentCount);
556556
for (auto handle : handles) {
557557
zes_power_sustained_limit_t sustained;
@@ -568,7 +568,7 @@ TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenSettingPowerLimitsThen
568568
delete handle;
569569
}
570570
pSysmanDeviceImp->pPowerHandleContext->handleList.clear();
571-
pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles);
571+
pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles, device->toHandle());
572572
auto handles = getPowerHandles(powerHandleComponentCount);
573573
for (auto handle : handles) {
574574
zes_power_sustained_limit_t sustained;
@@ -585,7 +585,7 @@ TEST_F(SysmanDevicePowerMultiDeviceFixture, GivenValidPowerHandleWhenGettingPowe
585585
delete handle;
586586
}
587587
pSysmanDeviceImp->pPowerHandleContext->handleList.clear();
588-
pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles);
588+
pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles, device->toHandle());
589589
auto handles = getPowerHandles(powerHandleComponentCount);
590590

591591
for (auto &deviceHandle : deviceHandles) {

level_zero/tools/test/unit_tests/sources/sysman/power/windows/test_zes_sysman_power.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class SysmanDevicePowerFixture : public SysmanDeviceFixture {
5252
deviceHandles.resize(subDeviceCount, nullptr);
5353
Device::fromHandle(device->toHandle())->getSubDevices(&subDeviceCount, deviceHandles.data());
5454
}
55-
pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles);
55+
pSysmanDeviceImp->pPowerHandleContext->init(deviceHandles, device->toHandle());
5656
}
5757
void TearDown() override {
5858
if (!sysmanUltsEnable) {

0 commit comments

Comments
 (0)