Skip to content

Commit 6fe263d

Browse files
Update zello_sysman bb test for power module
Add support for getPowerLimitsExt and setPowerLimitsExt. Related-To: LOCI-3195 Signed-off-by: Bellekallu Rajkiran <[email protected]>
1 parent 046f9d9 commit 6fe263d

File tree

1 file changed

+145
-49
lines changed

1 file changed

+145
-49
lines changed

level_zero/tools/test/black_box_tests/zello_sysman.cpp

Lines changed: 145 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -82,25 +82,26 @@ void usage() {
8282
"\n zello_sysman [OPTIONS]"
8383
"\n"
8484
"\n OPTIONS:"
85-
"\n -p, --pci selectively run pci black box test"
86-
"\n -f, --frequency selectively run frequency black box test"
87-
"\n -s, --standby selectively run standby black box test"
88-
"\n -e, --engine selectively run engine black box test"
89-
"\n -c, --scheduler selectively run scheduler black box test"
90-
"\n -t, --temperature selectively run temperature black box test"
91-
"\n -o, --power selectively run power black box test"
92-
"\n -m, --memory selectively run memory black box test"
93-
"\n -g, --global selectively run device/global operations black box test"
94-
"\n -R, --ras selectively run ras black box test"
95-
"\n -E, --event set and listen to events black box test"
96-
"\n -r, --reset force|noforce selectively run device reset test"
97-
"\n -i, --firmware <image> selectively run device firmware test <image> is the firmware binary needed to flash"
98-
"\n -F, --fabricport selectively run fabricport black box test"
99-
"\n -d, --diagnostics selectively run diagnostics black box test"
100-
"\n -P, --performance selectively run performance black box test"
101-
"\n [--setconfig <deviceNo subdevId engineFlags pFactor>] optionally set the performance factor for the particular handle"
102-
"\n -C, --ecc selectively run ecc black box test"
103-
"\n -h, --help display help message"
85+
"\n -p, --pci selectively run pci black box test"
86+
"\n -f, --frequency selectively run frequency black box test"
87+
"\n -s, --standby selectively run standby black box test"
88+
"\n -e, --engine selectively run engine black box test"
89+
"\n -c, --scheduler selectively run scheduler black box test"
90+
"\n -t, --temperature selectively run temperature black box test"
91+
"\n -o, --power selectively run power black box test"
92+
"\n [--setlimit --sustained/--peak/--instantaneous/--burst <deviceNo limit>] optionally set required power limit for particular device"
93+
"\n -m, --memory selectively run memory black box test"
94+
"\n -g, --global selectively run device/global operations black box test"
95+
"\n -R, --ras selectively run ras black box test"
96+
"\n -E, --event set and listen to events black box test"
97+
"\n -r, --reset force|noforce selectively run device reset test"
98+
"\n -i, --firmware <image> selectively run device firmware test <image> is the firmware binary needed to flash"
99+
"\n -F, --fabricport selectively run fabricport black box test"
100+
"\n -d, --diagnostics selectively run diagnostics black box test"
101+
"\n -P, --performance selectively run performance black box test"
102+
"\n [--setconfig <deviceNo subdevId engineFlags pFactor>] optionally set the performance factor for the particular handle"
103+
"\n -C, --ecc selectively run ecc black box test"
104+
"\n -h, --help display help message"
104105
"\n"
105106
"\n All L0 Syman APIs that set values require root privileged execution"
106107
"\n"
@@ -138,7 +139,84 @@ void getDeviceHandles(ze_driver_handle_t &driverHandle, std::vector<ze_device_ha
138139
}
139140
}
140141

141-
void testSysmanPower(ze_device_handle_t &device) {
142+
void getPowerLimits(const zes_pwr_handle_t &handle) {
143+
uint32_t limitCount = 0;
144+
VALIDATECALL(zesPowerGetLimitsExt(handle, &limitCount, nullptr));
145+
if (limitCount == 0) {
146+
std::cout << "powerLimitDesc.count = " << limitCount << std::endl;
147+
} else {
148+
std::vector<zes_power_limit_ext_desc_t> allLimits(limitCount);
149+
VALIDATECALL(zesPowerGetLimitsExt(handle, &limitCount, allLimits.data()));
150+
if (verbose) {
151+
for (uint32_t i = 0; i < limitCount; i++) {
152+
switch (allLimits[i].level) {
153+
case ZES_POWER_LEVEL_SUSTAINED:
154+
std::cout << " --- Sustained Power Limit --- " << std::endl;
155+
break;
156+
case ZES_POWER_LEVEL_PEAK:
157+
std::cout << " --- Peak Power Limit --- " << std::endl;
158+
break;
159+
case ZES_POWER_LEVEL_BURST:
160+
std::cout << " --- Burst Power Limit --- " << std::endl;
161+
break;
162+
case ZES_POWER_LEVEL_INSTANTANEOUS:
163+
std::cout << " --- Instantaneous Power Limit --- " << std::endl;
164+
break;
165+
default:
166+
std::cout << " --- Invalid Power Limit --- " << std::endl;
167+
return;
168+
}
169+
170+
std::cout << "powerLimit.intervalValueLocked = " << +allLimits[i].intervalValueLocked << std::endl;
171+
std::cout << "powerLimit.enabledStateLocked = " << +allLimits[i].enabledStateLocked << std::endl;
172+
std::cout << "powerLimit.limitValueLocked = " << +allLimits[i].limitValueLocked << std::endl;
173+
std::cout << "powerLimit.source = " << allLimits[i].source << std::endl;
174+
std::cout << "powerLimit.limitUnit = " << allLimits[i].limitUnit << std::endl;
175+
std::cout << "powerLimit.limit = " << allLimits[i].limit << std::endl;
176+
std::cout << "powerLimit.interval = " << allLimits[i].interval << std::endl;
177+
}
178+
}
179+
}
180+
}
181+
182+
void setPowerLimit(const zes_pwr_handle_t &handle, std::vector<std::string> &buf) {
183+
zes_power_level_t level;
184+
uint32_t limitCount = 0;
185+
ze_bool_t isPowerLevelAvailable = false;
186+
187+
if (buf[1] == "--sustained") {
188+
level = ZES_POWER_LEVEL_SUSTAINED;
189+
} else if (buf[1] == "--peak") {
190+
level = ZES_POWER_LEVEL_PEAK;
191+
} else if (buf[1] == "--instantaneous") {
192+
level = ZES_POWER_LEVEL_INSTANTANEOUS;
193+
} else {
194+
level = ZES_POWER_LEVEL_BURST;
195+
}
196+
197+
VALIDATECALL(zesPowerGetLimitsExt(handle, &limitCount, nullptr));
198+
if (limitCount != 0) {
199+
std::vector<zes_power_limit_ext_desc_t> allLimits(limitCount);
200+
VALIDATECALL(zesPowerGetLimitsExt(handle, &limitCount, allLimits.data()));
201+
for (uint32_t i = 0; i < limitCount; i++) {
202+
if (allLimits[i].level == level) {
203+
allLimits[i].limit = static_cast<int32_t>(std::stoi(buf[3]));
204+
isPowerLevelAvailable = true;
205+
break;
206+
}
207+
}
208+
209+
if (isPowerLevelAvailable) {
210+
VALIDATECALL(zesPowerSetLimitsExt(handle, &limitCount, allLimits.data()));
211+
} else {
212+
std::cout << "Unsupported Power Level to set limit" << std::endl;
213+
}
214+
} else {
215+
std::cout << "Unsupported Power Level to set limit" << std::endl;
216+
}
217+
}
218+
219+
void testSysmanPower(ze_device_handle_t &device, std::vector<std::string> &buf, uint32_t &curDeviceIndex) {
142220
std::cout << std::endl
143221
<< " ---- Power tests ---- " << std::endl;
144222
bool iamroot = (geteuid() == 0);
@@ -152,7 +230,7 @@ void testSysmanPower(ze_device_handle_t &device) {
152230
VALIDATECALL(zesDeviceEnumPowerDomains(device, &count, handles.data()));
153231

154232
for (const auto &handle : handles) {
155-
zes_power_properties_t properties;
233+
zes_power_properties_t properties = {};
156234
VALIDATECALL(zesPowerGetProperties(handle, &properties));
157235
if (verbose) {
158236
std::cout << "properties.canControl = " << static_cast<uint32_t>(properties.canControl) << std::endl;
@@ -167,36 +245,28 @@ void testSysmanPower(ze_device_handle_t &device) {
167245
std::cout << "energyCounter.energy = " << energyCounter.energy << std::endl;
168246
std::cout << "energyCounter.timestamp = " << energyCounter.timestamp << std::endl;
169247
}
170-
zes_power_sustained_limit_t sustainedGetDefault = {};
171-
zes_power_burst_limit_t burstGetDefault = {};
172-
VALIDATECALL(zesPowerGetLimits(handle, &sustainedGetDefault, &burstGetDefault, nullptr));
173-
if (verbose) {
174-
std::cout << "sustainedGetDefault.enabled = " << static_cast<uint32_t>(sustainedGetDefault.enabled) << std::endl;
175-
if (sustainedGetDefault.enabled) {
176-
std::cout << "sustainedGetDefault.power = " << sustainedGetDefault.power << std::endl;
177-
std::cout << "sustainedGetDefault.interval = " << sustainedGetDefault.interval << std::endl;
178-
}
179-
std::cout << "burstGetDefault.enabled = " << static_cast<uint32_t>(burstGetDefault.enabled) << std::endl;
180-
if (burstGetDefault.enabled) {
181-
std::cout << "burstGetDefault.power = " << burstGetDefault.power << std::endl;
182-
}
183-
}
184-
if (iamroot) {
185-
zes_power_sustained_limit_t sustainedSet = {};
186-
sustainedSet.power = sustainedGetDefault.power - sustainedGetDefault.power / 10; //Randomly try to reduce power
187-
sustainedSet.interval = sustainedGetDefault.interval - sustainedGetDefault.interval / 10;
188-
zes_power_burst_limit_t burstSet = {};
189-
if (burstGetDefault.enabled) {
190-
burstSet.enabled = 0;
248+
249+
if (!properties.onSubdevice) {
250+
zes_power_sustained_limit_t sustainedGetDefault = {};
251+
zes_power_peak_limit_t peakGetDefault = {};
252+
VALIDATECALL(zesPowerGetLimits(handle, &sustainedGetDefault, nullptr, &peakGetDefault));
253+
if (iamroot) {
254+
VALIDATECALL(zesPowerSetLimits(handle, &sustainedGetDefault, nullptr, &peakGetDefault));
191255
}
192-
VALIDATECALL(zesPowerSetLimits(handle, &sustainedSet, &burstSet, nullptr));
193-
if (verbose) {
194-
std::cout << "zesPowerSetLimits success" << std::endl;
195-
std::cout << "Now restore the power values to default ones" << std::endl;
256+
if (buf.size() != 0) {
257+
uint32_t deviceIndex = static_cast<uint32_t>(std::stoi(buf[2]));
258+
if (deviceIndex == curDeviceIndex) {
259+
if (iamroot) {
260+
setPowerLimit(handle, buf);
261+
} else {
262+
std::cout << "In sufficient permissions to set power limit" << std::endl;
263+
}
264+
}
196265
}
197-
VALIDATECALL(zesPowerSetLimits(handle, &sustainedGetDefault, &burstGetDefault, nullptr));
266+
getPowerLimits(handle);
198267
}
199268
}
269+
curDeviceIndex++;
200270
}
201271

202272
std::string getEngineFlagType(zes_engine_type_flags_t engineFlag) {
@@ -1192,6 +1262,19 @@ bool checkpFactorArguments(std::vector<ze_device_handle_t> &devices, std::vector
11921262
return true;
11931263
}
11941264

1265+
bool validatePowerLimitArguments(const size_t devCount, std::vector<std::string> &buf) {
1266+
if ((buf.size() != 4 || buf[0] != "--setlimit" || (!(buf[1] == "--sustained" || buf[1] == "--peak" || buf[1] == "--instantaneous" || buf[1] == "--burst")))) {
1267+
return false;
1268+
}
1269+
1270+
uint32_t devIndex = static_cast<uint32_t>(std::stoi(buf[2]));
1271+
if (devIndex >= devCount) {
1272+
return false;
1273+
}
1274+
1275+
return true;
1276+
}
1277+
11951278
bool validateGetenv(const char *name) {
11961279
const char *env = getenv(name);
11971280
if ((nullptr == env) || (0 == strcmp("0", env)))
@@ -1217,7 +1300,7 @@ int main(int argc, char *argv[]) {
12171300
{"engine", no_argument, nullptr, 'e'},
12181301
{"scheduler", no_argument, nullptr, 'c'},
12191302
{"temperature", no_argument, nullptr, 't'},
1220-
{"power", no_argument, nullptr, 'o'},
1303+
{"power", optional_argument, nullptr, 'o'},
12211304
{"global", no_argument, nullptr, 'g'},
12221305
{"ras", no_argument, nullptr, 'R'},
12231306
{"memory", no_argument, nullptr, 'm'},
@@ -1302,8 +1385,21 @@ int main(int argc, char *argv[]) {
13021385
});
13031386
break;
13041387
case 'o':
1388+
deviceIndex = 0;
1389+
while (optind < argc) {
1390+
buf.push_back(argv[optind]);
1391+
optind++;
1392+
}
1393+
1394+
if (buf.size() != 0) {
1395+
if (validatePowerLimitArguments(devices.size(), buf) == false) {
1396+
std::cout << "Invalid Arguments passed to set power limit" << std::endl;
1397+
usage();
1398+
exit(0);
1399+
}
1400+
}
13051401
std::for_each(devices.begin(), devices.end(), [&](auto device) {
1306-
testSysmanPower(device);
1402+
testSysmanPower(device, buf, deviceIndex);
13071403
});
13081404
break;
13091405
case 'g':

0 commit comments

Comments
 (0)