| 1 |
/* |
| 2 |
* Copyright (C) 2020-2023 Intel Corporation |
| 3 |
* |
| 4 |
* SPDX-License-Identifier: MIT |
| 5 |
* |
| 6 |
*/ |
| 7 |
|
| 8 |
#include "level_zero/tools/source/sysman/scheduler/linux/os_scheduler_imp.h" |
| 9 |
|
| 10 |
#include "shared/source/debug_settings/debug_settings_manager.h" |
| 11 |
|
| 12 |
#include "level_zero/tools/source/sysman/linux/os_sysman_imp.h" |
| 13 |
|
| 14 |
namespace L0 { |
| 15 |
|
| 16 |
const std::string LinuxSchedulerImp::preemptTimeoutMilliSecs("preempt_timeout_ms"); |
| 17 |
const std::string LinuxSchedulerImp::defaultPreemptTimeouttMilliSecs(".defaults/preempt_timeout_ms"); |
| 18 |
const std::string LinuxSchedulerImp::timesliceDurationMilliSecs("timeslice_duration_ms"); |
| 19 |
const std::string LinuxSchedulerImp::defaultTimesliceDurationMilliSecs(".defaults/timeslice_duration_ms"); |
| 20 |
const std::string LinuxSchedulerImp::heartbeatIntervalMilliSecs("heartbeat_interval_ms"); |
| 21 |
const std::string LinuxSchedulerImp::defaultHeartbeatIntervalMilliSecs(".defaults/heartbeat_interval_ms"); |
| 22 |
const std::string LinuxSchedulerImp::enableEuDebug(""); |
| 23 |
const std::string LinuxSchedulerImp::engineDir("engine"); |
| 24 |
|
| 25 |
static const std::multimap<zes_engine_type_flag_t, std::string> level0EngineTypeToSysfsEngineMap = { |
| 26 |
{ZES_ENGINE_TYPE_FLAG_RENDER, "rcs"}, |
| 27 |
{ZES_ENGINE_TYPE_FLAG_DMA, "bcs"}, |
| 28 |
{ZES_ENGINE_TYPE_FLAG_MEDIA, "vcs"}, |
| 29 |
{ZES_ENGINE_TYPE_FLAG_OTHER, "vecs"}}; |
| 30 |
|
| 31 |
ze_result_t LinuxSchedulerImp::getProperties(zes_sched_properties_t &schedProperties) { |
| 32 |
schedProperties.onSubdevice = onSubdevice; |
| 33 |
schedProperties.subdeviceId = subdeviceId; |
| 34 |
schedProperties.canControl = canControlScheduler(); |
| 35 |
schedProperties.engines = this->engineType; |
| 36 |
schedProperties.supportedModes = (1 << ZES_SCHED_MODE_TIMEOUT) | (1 << ZES_SCHED_MODE_TIMESLICE) | (1 << ZES_SCHED_MODE_EXCLUSIVE); |
| 37 |
return ZE_RESULT_SUCCESS; |
| 38 |
} |
| 39 |
|
| 40 |
ze_result_t LinuxSchedulerImp::getCurrentMode(zes_sched_mode_t *pMode) { |
| 41 |
uint64_t timeout = 0; |
| 42 |
uint64_t timeslice = 0; |
| 43 |
uint64_t heartbeat = 0; |
| 44 |
ze_result_t result = getPreemptTimeout(timeout, false); |
| 45 |
if (result != ZE_RESULT_SUCCESS) { |
| 46 |
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to get preempt timeout and returning error:0x%x \n", __FUNCTION__, result); |
| 47 |
return result; |
| 48 |
} |
| 49 |
result = getTimesliceDuration(timeslice, false); |
| 50 |
if (result != ZE_RESULT_SUCCESS) { |
| 51 |
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to get timeslice duration and returning error:0x%x \n", __FUNCTION__, result); |
| 52 |
return result; |
| 53 |
} |
| 54 |
result = getHeartbeatInterval(heartbeat, false); |
| 55 |
if (result != ZE_RESULT_SUCCESS) { |
| 56 |
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to get heartbeat interval and returning error:0x%x \n", __FUNCTION__, result); |
| 57 |
return result; |
| 58 |
} |
| 59 |
|
| 60 |
if (timeslice > 0) { |
| 61 |
*pMode = ZES_SCHED_MODE_TIMESLICE; |
| 62 |
} else { |
| 63 |
if (timeout > 0) { |
| 64 |
*pMode = ZES_SCHED_MODE_TIMEOUT; |
| 65 |
} else { |
| 66 |
if (heartbeat == 0) { |
| 67 |
// If we are here, it means heartbeat = 0, timeout = 0, timeslice = 0. |
| 68 |
if (isComputeUnitDebugModeEnabled()) { |
| 69 |
*pMode = ZES_SCHED_MODE_COMPUTE_UNIT_DEBUG; |
| 70 |
} else { |
| 71 |
*pMode = ZES_SCHED_MODE_EXCLUSIVE; |
| 72 |
} |
| 73 |
} else { |
| 74 |
// If we are here it means heartbeat > 0, timeout = 0, timeslice = 0. |
| 75 |
// And we dont know what that mode is. |
| 76 |
*pMode = ZES_SCHED_MODE_FORCE_UINT32; |
| 77 |
result = ZE_RESULT_ERROR_UNKNOWN; |
| 78 |
} |
| 79 |
} |
| 80 |
} |
| 81 |
return result; |
| 82 |
} |
| 83 |
|
| 84 |
ze_result_t LinuxSchedulerImp::setExclusiveModeImp() { |
| 85 |
uint64_t timeslice = 0, timeout = 0, heartbeat = 0; |
| 86 |
ze_result_t result = setPreemptTimeout(timeout); |
| 87 |
if (result != ZE_RESULT_SUCCESS) { |
| 88 |
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to set preempt timeout and returning error:0x%x \n", __FUNCTION__, result); |
| 89 |
return result; |
| 90 |
} |
| 91 |
result = setTimesliceDuration(timeslice); |
| 92 |
if (result != ZE_RESULT_SUCCESS) { |
| 93 |
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to set timeslice duration and returning error:0x%x \n", __FUNCTION__, result); |
| 94 |
return result; |
| 95 |
} |
| 96 |
result = setHeartbeatInterval(heartbeat); |
| 97 |
return result; |
| 98 |
} |
| 99 |
|
| 100 |
ze_result_t LinuxSchedulerImp::setExclusiveMode(ze_bool_t *pNeedReload) { |
| 101 |
*pNeedReload = false; |
| 102 |
|
| 103 |
zes_sched_mode_t currMode; |
| 104 |
ze_result_t result = getCurrentMode(&currMode); |
| 105 |
if (result != ZE_RESULT_SUCCESS) { |
| 106 |
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to get current mode and returning error:0x%x \n", __FUNCTION__, result); |
| 107 |
return result; |
| 108 |
} |
| 109 |
|
| 110 |
if (currMode == ZES_SCHED_MODE_COMPUTE_UNIT_DEBUG) { |
| 111 |
// Unset this mode |
| 112 |
result = disableComputeUnitDebugMode(pNeedReload); |
| 113 |
if (result != ZE_RESULT_SUCCESS) { |
| 114 |
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to diasble COMPUTE_UNIT_DEBUG mode and returning error:0x%x \n", __FUNCTION__, result); |
| 115 |
return result; |
| 116 |
} |
| 117 |
} |
| 118 |
|
| 119 |
return setExclusiveModeImp(); |
| 120 |
} |
| 121 |
|
| 122 |
ze_result_t LinuxSchedulerImp::getTimeoutModeProperties(ze_bool_t getDefaults, zes_sched_timeout_properties_t *pConfig) { |
| 123 |
uint64_t heartbeat = 0; |
| 124 |
ze_result_t result = getHeartbeatInterval(heartbeat, getDefaults); |
| 125 |
if (result != ZE_RESULT_SUCCESS) { |
| 126 |
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to get heart beat interval and returning error:0x%x \n", __FUNCTION__, result); |
| 127 |
return result; |
| 128 |
} |
| 129 |
pConfig->watchdogTimeout = heartbeat; |
| 130 |
|
| 131 |
return result; |
| 132 |
} |
| 133 |
|
| 134 |
ze_result_t LinuxSchedulerImp::getTimesliceModeProperties(ze_bool_t getDefaults, zes_sched_timeslice_properties_t *pConfig) { |
| 135 |
uint64_t timeout = 0, timeslice = 0; |
| 136 |
ze_result_t result = getPreemptTimeout(timeout, getDefaults); |
| 137 |
if (result != ZE_RESULT_SUCCESS) { |
| 138 |
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to get preempt timeout and returning error:0x%x \n", __FUNCTION__, result); |
| 139 |
return result; |
| 140 |
} |
| 141 |
result = getTimesliceDuration(timeslice, getDefaults); |
| 142 |
if (result != ZE_RESULT_SUCCESS) { |
| 143 |
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to get timeslice duration and returning error:0x%x \n", __FUNCTION__, result); |
| 144 |
return result; |
| 145 |
} |
| 146 |
pConfig->interval = timeslice; |
| 147 |
pConfig->yieldTimeout = timeout; |
| 148 |
return result; |
| 149 |
} |
| 150 |
|
| 151 |
ze_result_t LinuxSchedulerImp::setTimeoutMode(zes_sched_timeout_properties_t *pProperties, ze_bool_t *pNeedReload) { |
| 152 |
*pNeedReload = false; |
| 153 |
zes_sched_mode_t currMode; |
| 154 |
ze_result_t result = getCurrentMode(&currMode); |
| 155 |
if (result != ZE_RESULT_SUCCESS) { |
| 156 |
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to get current mode and returning error:0x%x \n", __FUNCTION__, result); |
| 157 |
return result; |
| 158 |
} |
| 159 |
|
| 160 |
if (pProperties->watchdogTimeout < minTimeoutModeHeartbeat) { |
| 161 |
// watchdogTimeout(in usec) less than 5000 would be computed to |
| 162 |
// 0 milli seconds preempt timeout, and then after returning from |
| 163 |
// this method, we would end up in EXCLUSIVE mode |
| 164 |
return ZE_RESULT_ERROR_INVALID_ARGUMENT; |
| 165 |
} |
| 166 |
|
| 167 |
if (currMode == ZES_SCHED_MODE_COMPUTE_UNIT_DEBUG) { |
| 168 |
// Unset this mode |
| 169 |
result = disableComputeUnitDebugMode(pNeedReload); |
| 170 |
if (result != ZE_RESULT_SUCCESS) { |
| 171 |
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to diasble COMPUTE_UNIT_DEBUG mode and returning error:0x%x \n", __FUNCTION__, result); |
| 172 |
return result; |
| 173 |
} |
| 174 |
} |
| 175 |
|
| 176 |
result = setHeartbeatInterval(pProperties->watchdogTimeout); |
| 177 |
if (result != ZE_RESULT_SUCCESS) { |
| 178 |
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to set heartbeat interval and returning error:0x%x \n", __FUNCTION__, result); |
| 179 |
return result; |
| 180 |
} |
| 181 |
|
| 182 |
uint64_t timeout = (pProperties->watchdogTimeout) / 5; |
| 183 |
result = setPreemptTimeout(timeout); |
| 184 |
if (result != ZE_RESULT_SUCCESS) { |
| 185 |
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to set preempt timeout and returning error:0x%x \n", __FUNCTION__, result); |
| 186 |
return result; |
| 187 |
} |
| 188 |
|
| 189 |
uint64_t timeslice = 0; |
| 190 |
result = setTimesliceDuration(timeslice); |
| 191 |
if (result != ZE_RESULT_SUCCESS) { |
| 192 |
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to set timeslice duration and returning error:0x%x \n", __FUNCTION__, result); |
| 193 |
return result; |
| 194 |
} |
| 195 |
return result; |
| 196 |
} |
| 197 |
|
| 198 |
ze_result_t LinuxSchedulerImp::setTimesliceMode(zes_sched_timeslice_properties_t *pProperties, ze_bool_t *pNeedReload) { |
| 199 |
if (pProperties->interval < minTimeoutInMicroSeconds) { |
| 200 |
// interval(in usec) less than 1000 would be computed to |
| 201 |
// 0 milli seconds interval. |
| 202 |
return ZE_RESULT_ERROR_INVALID_ARGUMENT; |
| 203 |
} |
| 204 |
*pNeedReload = false; |
| 205 |
|
| 206 |
zes_sched_mode_t currMode; |
| 207 |
ze_result_t result = getCurrentMode(&currMode); |
| 208 |
if (result != ZE_RESULT_SUCCESS) { |
| 209 |
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to get current mode and returning error:0x%x \n", __FUNCTION__, result); |
| 210 |
return result; |
| 211 |
} |
| 212 |
|
| 213 |
if (currMode == ZES_SCHED_MODE_COMPUTE_UNIT_DEBUG) { |
| 214 |
// Unset this mode |
| 215 |
result = disableComputeUnitDebugMode(pNeedReload); |
| 216 |
if (result != ZE_RESULT_SUCCESS) { |
| 217 |
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to diasble COMPUTE_UNIT_DEBUG mode and returning error:0x%x \n", __FUNCTION__, result); |
| 218 |
return result; |
| 219 |
} |
| 220 |
} |
| 221 |
|
| 222 |
result = setPreemptTimeout(pProperties->yieldTimeout); |
| 223 |
if (result != ZE_RESULT_SUCCESS) { |
| 224 |
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to set preempt timeout and returning error:0x%x \n", __FUNCTION__, result); |
| 225 |
return result; |
| 226 |
} |
| 227 |
result = setTimesliceDuration(pProperties->interval); |
| 228 |
if (result != ZE_RESULT_SUCCESS) { |
| 229 |
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to set timeslice duration and returning error:0x%x \n", __FUNCTION__, result); |
| 230 |
return result; |
| 231 |
} |
| 232 |
uint64_t heartbeat = 2500 * (pProperties->interval); |
| 233 |
return setHeartbeatInterval(heartbeat); |
| 234 |
} |
| 235 |
|
| 236 |
ze_result_t LinuxSchedulerImp::getPreemptTimeout(uint64_t &timeout, ze_bool_t getDefault) { |
| 237 |
ze_result_t result = ZE_RESULT_ERROR_UNKNOWN; |
| 238 |
uint32_t i = 0; |
| 239 |
std::vector<uint64_t> timeoutVec = {}; |
| 240 |
std::string path = ""; |
| 241 |
timeoutVec.resize(listOfEngines.size()); |
| 242 |
for (const auto &engineName : listOfEngines) { |
| 243 |
if (getDefault) { |
| 244 |
path = engineDir + "/" + engineName + "/" + defaultPreemptTimeouttMilliSecs; |
| 245 |
result = pSysfsAccess->read(path, timeout); |
| 246 |
} else { |
| 247 |
path = engineDir + "/" + engineName + "/" + preemptTimeoutMilliSecs; |
| 248 |
result = pSysfsAccess->read(path, timeout); |
| 249 |
} |
| 250 |
if (result == ZE_RESULT_SUCCESS) { |
| 251 |
timeout = timeout * milliSecsToMicroSecs; |
| 252 |
timeoutVec[i] = timeout; |
| 253 |
i++; |
| 254 |
} else { |
| 255 |
if (result == ZE_RESULT_ERROR_NOT_AVAILABLE) { |
| 256 |
result = ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; |
| 257 |
} |
| 258 |
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to read preempt timeout from %s and returning error:0x%x \n", __FUNCTION__, path.c_str(), result); |
| 259 |
return result; |
| 260 |
} |
| 261 |
} |
| 262 |
// check if all engines of the same type have the same scheduling param values |
| 263 |
if (std::adjacent_find(timeoutVec.begin(), timeoutVec.end(), std::not_equal_to<>()) == timeoutVec.end()) { |
| 264 |
timeout = timeoutVec[0]; |
| 265 |
return result; |
| 266 |
} else { |
| 267 |
return ZE_RESULT_ERROR_UNKNOWN; |
| 268 |
} |
| 269 |
} |
| 270 |
|
| 271 |
ze_result_t LinuxSchedulerImp::getTimesliceDuration(uint64_t ×lice, ze_bool_t getDefault) { |
| 272 |
ze_result_t result = ZE_RESULT_ERROR_UNKNOWN; |
| 273 |
uint32_t i = 0; |
| 274 |
std::vector<uint64_t> timesliceVec = {}; |
| 275 |
std::string path = ""; |
| 276 |
timesliceVec.resize(listOfEngines.size()); |
| 277 |
for (const auto &engineName : listOfEngines) { |
| 278 |
if (getDefault) { |
| 279 |
path = engineDir + "/" + engineName + "/" + defaultTimesliceDurationMilliSecs; |
| 280 |
result = pSysfsAccess->read(path, timeslice); |
| 281 |
} else { |
| 282 |
path = engineDir + "/" + engineName + "/" + timesliceDurationMilliSecs; |
| 283 |
result = pSysfsAccess->read(path, timeslice); |
| 284 |
} |
| 285 |
if (result == ZE_RESULT_SUCCESS) { |
| 286 |
timeslice = timeslice * milliSecsToMicroSecs; |
| 287 |
timesliceVec[i] = timeslice; |
| 288 |
i++; |
| 289 |
} else { |
| 290 |
if (result == ZE_RESULT_ERROR_NOT_AVAILABLE) { |
| 291 |
result = ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; |
| 292 |
} |
| 293 |
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to read timeslice duration from %s and returning error:0x%x \n", __FUNCTION__, path.c_str(), result); |
| 294 |
return result; |
| 295 |
} |
| 296 |
} |
| 297 |
// check if all engines of the same type have the same scheduling param values |
| 298 |
if (std::adjacent_find(timesliceVec.begin(), timesliceVec.end(), std::not_equal_to<>()) == timesliceVec.end()) { |
| 299 |
timeslice = timesliceVec[0]; |
| 300 |
return result; |
| 301 |
} else { |
| 302 |
return ZE_RESULT_ERROR_UNKNOWN; |
| 303 |
} |
| 304 |
} |
| 305 |
|
| 306 |
ze_result_t LinuxSchedulerImp::getHeartbeatInterval(uint64_t &heartbeat, ze_bool_t getDefault) { |
| 307 |
ze_result_t result = ZE_RESULT_ERROR_UNKNOWN; |
| 308 |
uint32_t i = 0; |
| 309 |
std::vector<uint64_t> heartbeatVec = {}; |
| 310 |
std::string path = ""; |
| 311 |
heartbeatVec.resize(listOfEngines.size()); |
| 312 |
for (const auto &engineName : listOfEngines) { |
| 313 |
if (getDefault) { |
| 314 |
path = engineDir + "/" + engineName + "/" + defaultHeartbeatIntervalMilliSecs; |
| 315 |
result = pSysfsAccess->read(path, heartbeat); |
| 316 |
} else { |
| 317 |
path = engineDir + "/" + engineName + "/" + heartbeatIntervalMilliSecs; |
| 318 |
result = pSysfsAccess->read(path, heartbeat); |
| 319 |
} |
| 320 |
if (result == ZE_RESULT_SUCCESS) { |
| 321 |
heartbeat = heartbeat * milliSecsToMicroSecs; |
| 322 |
heartbeatVec[i] = heartbeat; |
| 323 |
i++; |
| 324 |
} else { |
| 325 |
if (result == ZE_RESULT_ERROR_NOT_AVAILABLE) { |
| 326 |
result = ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; |
| 327 |
} |
| 328 |
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to read heartbeat interval from %s and returning error:0x%x \n", __FUNCTION__, path.c_str(), result); |
| 329 |
return result; |
| 330 |
} |
| 331 |
} |
| 332 |
// check if all engines of the same type have the same scheduling param values |
| 333 |
if (std::adjacent_find(heartbeatVec.begin(), heartbeatVec.end(), std::not_equal_to<>()) == heartbeatVec.end()) { |
| 334 |
heartbeat = heartbeatVec[0]; |
| 335 |
return result; |
| 336 |
} else { |
| 337 |
return ZE_RESULT_ERROR_UNKNOWN; |
| 338 |
} |
| 339 |
} |
| 340 |
|
| 341 |
ze_result_t LinuxSchedulerImp::setPreemptTimeout(uint64_t timeout) { |
| 342 |
timeout = timeout / milliSecsToMicroSecs; |
| 343 |
ze_result_t result = ZE_RESULT_ERROR_UNKNOWN; |
| 344 |
for (const auto &engineName : listOfEngines) { |
| 345 |
result = pSysfsAccess->write(engineDir + "/" + engineName + "/" + preemptTimeoutMilliSecs, timeout); |
| 346 |
if (result != ZE_RESULT_SUCCESS) { |
| 347 |
if (result == ZE_RESULT_ERROR_NOT_AVAILABLE) { |
| 348 |
result = ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; |
| 349 |
} |
| 350 |
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to write Preempt timeout into engineDir/%s/preemptTimeoutMilliSecs and returning error:0x%x \n", __FUNCTION__, engineName.c_str(), result); |
| 351 |
return result; |
| 352 |
} |
| 353 |
} |
| 354 |
return result; |
| 355 |
} |
| 356 |
|
| 357 |
ze_result_t LinuxSchedulerImp::setTimesliceDuration(uint64_t timeslice) { |
| 358 |
timeslice = timeslice / milliSecsToMicroSecs; |
| 359 |
ze_result_t result = ZE_RESULT_ERROR_UNKNOWN; |
| 360 |
for (const auto &engineName : listOfEngines) { |
| 361 |
result = pSysfsAccess->write(engineDir + "/" + engineName + "/" + timesliceDurationMilliSecs, timeslice); |
| 362 |
if (result != ZE_RESULT_SUCCESS) { |
| 363 |
if (result == ZE_RESULT_ERROR_NOT_AVAILABLE) { |
| 364 |
result = ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; |
| 365 |
} |
| 366 |
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to write Timeslice duration into engineDir/%s/timesliceDurationMilliSecs and returning error:0x%x \n", __FUNCTION__, engineName.c_str(), result); |
| 367 |
return result; |
| 368 |
} |
| 369 |
} |
| 370 |
return result; |
| 371 |
} |
| 372 |
|
| 373 |
ze_result_t LinuxSchedulerImp::setHeartbeatInterval(uint64_t heartbeat) { |
| 374 |
heartbeat = heartbeat / milliSecsToMicroSecs; |
| 375 |
ze_result_t result = ZE_RESULT_ERROR_UNKNOWN; |
| 376 |
for (const auto &engineName : listOfEngines) { |
| 377 |
result = pSysfsAccess->write(engineDir + "/" + engineName + "/" + heartbeatIntervalMilliSecs, heartbeat); |
| 378 |
if (result != ZE_RESULT_SUCCESS) { |
| 379 |
if (result == ZE_RESULT_ERROR_NOT_AVAILABLE) { |
| 380 |
result = ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; |
| 381 |
} |
| 382 |
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to write Heartbeat interval into engineDir/%s/heartbeatIntervalMilliSecs and returning error:0x%x \n", __FUNCTION__, engineName.c_str(), result); |
| 383 |
return result; |
| 384 |
} |
| 385 |
} |
| 386 |
return result; |
| 387 |
} |
| 388 |
|
| 389 |
ze_bool_t LinuxSchedulerImp::canControlScheduler() { |
| 390 |
return 1; |
| 391 |
} |
| 392 |
|
| 393 |
ze_result_t LinuxSchedulerImp::setComputeUnitDebugMode(ze_bool_t *pNeedReload) { |
| 394 |
*pNeedReload = false; |
| 395 |
return pSysfsAccess->write(enableEuDebug, 1); |
| 396 |
} |
| 397 |
|
| 398 |
bool LinuxSchedulerImp::isComputeUnitDebugModeEnabled() { |
| 399 |
return false; |
| 400 |
} |
| 401 |
|
| 402 |
ze_result_t LinuxSchedulerImp::disableComputeUnitDebugMode(ze_bool_t *pNeedReload) { |
| 403 |
*pNeedReload = false; |
| 404 |
return pSysfsAccess->write(enableEuDebug, 0); |
| 405 |
} |
| 406 |
|
| 407 |
static ze_result_t getNumEngineTypeAndInstancesForDevice(std::map<zes_engine_type_flag_t, std::vector<std::string>> &mapOfEngines, SysfsAccess *pSysfsAccess) { |
| 408 |
std::vector<std::string> localListOfAllEngines = {}; |
| 409 |
auto result = pSysfsAccess->scanDirEntries(LinuxSchedulerImp::engineDir, localListOfAllEngines); |
| 410 |
if (ZE_RESULT_SUCCESS != result) { |
| 411 |
if (result == ZE_RESULT_ERROR_NOT_AVAILABLE) { |
| 412 |
result = ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; |
| 413 |
} |
| 414 |
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to scan directory entries to list all engines and returning error:0x%x \n", __FUNCTION__, result); |
| 415 |
return result; |
| 416 |
} |
| 417 |
for_each(localListOfAllEngines.begin(), localListOfAllEngines.end(), |
| 418 |
[&](std::string &mappedEngine) { |
| 419 |
for (auto itr = level0EngineTypeToSysfsEngineMap.begin(); itr != level0EngineTypeToSysfsEngineMap.end(); itr++) { |
| 420 |
char digits[] = "0123456789"; |
| 421 |
auto mappedEngineName = mappedEngine.substr(0, mappedEngine.find_first_of(digits, 0)); |
| 422 |
if (0 == mappedEngineName.compare(itr->second.c_str())) { |
| 423 |
auto ret = mapOfEngines.find(itr->first); |
| 424 |
if (ret != mapOfEngines.end()) { |
| 425 |
ret->second.push_back(mappedEngine); |
| 426 |
} else { |
| 427 |
std::vector<std::string> engineVec = {}; |
| 428 |
engineVec.push_back(mappedEngine); |
| 429 |
mapOfEngines.emplace(itr->first, engineVec); |
| 430 |
} |
| 431 |
} |
| 432 |
} |
| 433 |
}); |
| 434 |
return result; |
| 435 |
} |
| 436 |
|
| 437 |
ze_result_t OsScheduler::getNumEngineTypeAndInstances( |
| 438 |
std::map<zes_engine_type_flag_t, std::vector<std::string>> &mapOfEngines, OsSysman *pOsSysman, ze_device_handle_t subdeviceHandle) { |
| 439 |
LinuxSysmanImp *pLinuxSysmanImp = static_cast<LinuxSysmanImp *>(pOsSysman); |
| 440 |
auto pSysfsAccess = &pLinuxSysmanImp->getSysfsAccess(); |
| 441 |
return getNumEngineTypeAndInstancesForDevice(mapOfEngines, pSysfsAccess); |
| 442 |
} |
| 443 |
|
| 444 |
LinuxSchedulerImp::LinuxSchedulerImp( |
| 445 |
OsSysman *pOsSysman, zes_engine_type_flag_t type, std::vector<std::string> &listOfEngines, ze_bool_t isSubdevice, |
| 446 |
uint32_t subdeviceId) : engineType(type), onSubdevice(isSubdevice), subdeviceId(subdeviceId) { |
| 447 |
LinuxSysmanImp *pLinuxSysmanImp = static_cast<LinuxSysmanImp *>(pOsSysman); |
| 448 |
pSysfsAccess = &pLinuxSysmanImp->getSysfsAccess(); |
| 449 |
this->listOfEngines = listOfEngines; |
| 450 |
} |
| 451 |
|
| 452 |
std::unique_ptr<OsScheduler> OsScheduler::create( |
| 453 |
OsSysman *pOsSysman, zes_engine_type_flag_t type, std::vector<std::string> &listOfEngines, ze_bool_t isSubdevice, uint32_t subdeviceId) { |
| 454 |
std::unique_ptr<LinuxSchedulerImp> pLinuxSchedulerImp = std::make_unique<LinuxSchedulerImp>(pOsSysman, type, listOfEngines, isSubdevice, subdeviceId); |
| 455 |
return pLinuxSchedulerImp; |
| 456 |
} |
| 457 |
|
| 458 |
} // namespace L0 |