| 1 |
/* |
| 2 |
* Copyright (C) 2022-2023 Intel Corporation |
| 3 |
* |
| 4 |
* SPDX-License-Identifier: MIT |
| 5 |
* |
| 6 |
*/ |
| 7 |
|
| 8 |
#include "shared/source/debug_settings/debug_settings_manager.h" |
| 9 |
#include "shared/source/os_interface/linux/engine_info.h" |
| 10 |
#include "shared/source/os_interface/linux/i915_prelim.h" |
| 11 |
|
| 12 |
#include "level_zero/core/source/device/device_imp.h" |
| 13 |
#include "level_zero/tools/source/sysman/linux/os_sysman_imp.h" |
| 14 |
#include "level_zero/tools/source/sysman/scheduler/linux/os_scheduler_imp.h" |
| 15 |
|
| 16 |
namespace L0 { |
| 17 |
|
| 18 |
const std::string LinuxSchedulerImp::preemptTimeoutMilliSecs("preempt_timeout_ms"); |
| 19 |
const std::string LinuxSchedulerImp::defaultPreemptTimeouttMilliSecs(".defaults/preempt_timeout_ms"); |
| 20 |
const std::string LinuxSchedulerImp::timesliceDurationMilliSecs("timeslice_duration_ms"); |
| 21 |
const std::string LinuxSchedulerImp::defaultTimesliceDurationMilliSecs(".defaults/timeslice_duration_ms"); |
| 22 |
const std::string LinuxSchedulerImp::heartbeatIntervalMilliSecs("heartbeat_interval_ms"); |
| 23 |
const std::string LinuxSchedulerImp::defaultHeartbeatIntervalMilliSecs(".defaults/heartbeat_interval_ms"); |
| 24 |
const std::string LinuxSchedulerImp::engineDir("engine"); |
| 25 |
const std::string LinuxSchedulerImp::enableEuDebug("prelim_enable_eu_debug"); |
| 26 |
constexpr uint16_t milliSecsToMicroSecs = 1000; |
| 27 |
|
| 28 |
static const std::map<__u16, std::string> i915EngineClassToSysfsEngineMap = { |
| 29 |
{drm_i915_gem_engine_class::I915_ENGINE_CLASS_RENDER, "rcs"}, |
| 30 |
{static_cast<__u16>(drm_i915_gem_engine_class::I915_ENGINE_CLASS_COMPUTE), "ccs"}, |
| 31 |
{drm_i915_gem_engine_class::I915_ENGINE_CLASS_COPY, "bcs"}, |
| 32 |
{drm_i915_gem_engine_class::I915_ENGINE_CLASS_VIDEO, "vcs"}, |
| 33 |
{drm_i915_gem_engine_class::I915_ENGINE_CLASS_VIDEO_ENHANCE, "vecs"}}; |
| 34 |
|
| 35 |
static const std::map<std::string, zes_engine_type_flag_t> sysfsEngineMapToLevel0EngineType = { |
| 36 |
{"rcs", ZES_ENGINE_TYPE_FLAG_RENDER}, |
| 37 |
{"ccs", ZES_ENGINE_TYPE_FLAG_COMPUTE}, |
| 38 |
{"bcs", ZES_ENGINE_TYPE_FLAG_DMA}, |
| 39 |
{"vcs", ZES_ENGINE_TYPE_FLAG_MEDIA}, |
| 40 |
{"vecs", ZES_ENGINE_TYPE_FLAG_OTHER}}; |
| 41 |
|
| 42 |
static const std::multimap<zes_engine_type_flag_t, std::string> level0EngineTypeToSysfsEngineMap = { |
| 43 |
{ZES_ENGINE_TYPE_FLAG_RENDER, "rcs"}, |
| 44 |
{ZES_ENGINE_TYPE_FLAG_COMPUTE, "ccs"}, |
| 45 |
{ZES_ENGINE_TYPE_FLAG_DMA, "bcs"}, |
| 46 |
{ZES_ENGINE_TYPE_FLAG_MEDIA, "vcs"}, |
| 47 |
{ZES_ENGINE_TYPE_FLAG_OTHER, "vecs"}}; |
| 48 |
|
| 49 |
static const std::map<std::string, __u16> sysfsEngineMapToi915EngineClass = { |
| 50 |
{"rcs", drm_i915_gem_engine_class::I915_ENGINE_CLASS_RENDER}, |
| 51 |
{"ccs", static_cast<__u16>(drm_i915_gem_engine_class::I915_ENGINE_CLASS_COMPUTE)}, |
| 52 |
{"bcs", drm_i915_gem_engine_class::I915_ENGINE_CLASS_COPY}, |
| 53 |
{"vcs", drm_i915_gem_engine_class::I915_ENGINE_CLASS_VIDEO}, |
| 54 |
{"vecs", drm_i915_gem_engine_class::I915_ENGINE_CLASS_VIDEO_ENHANCE}}; |
| 55 |
|
| 56 |
ze_result_t LinuxSchedulerImp::getCurrentMode(zes_sched_mode_t *pMode) { |
| 57 |
uint64_t timeout = 0; |
| 58 |
uint64_t timeslice = 0; |
| 59 |
uint64_t heartbeat = 0; |
| 60 |
ze_result_t result = getPreemptTimeout(timeout, false); |
| 61 |
if (result != ZE_RESULT_SUCCESS) { |
| 62 |
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to get preempt timeout and returning error:0x%x \n", __FUNCTION__, result); |
| 63 |
return result; |
| 64 |
} |
| 65 |
result = getTimesliceDuration(timeslice, false); |
| 66 |
if (result != ZE_RESULT_SUCCESS) { |
| 67 |
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to get timeslice duration and returning error:0x%x \n", __FUNCTION__, result); |
| 68 |
return result; |
| 69 |
} |
| 70 |
result = getHeartbeatInterval(heartbeat, false); |
| 71 |
if (result != ZE_RESULT_SUCCESS) { |
| 72 |
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to get heartbeat interval and returning error:0x%x \n", __FUNCTION__, result); |
| 73 |
return result; |
| 74 |
} |
| 75 |
|
| 76 |
if (timeslice > 0) { |
| 77 |
*pMode = ZES_SCHED_MODE_TIMESLICE; |
| 78 |
} else { |
| 79 |
if (timeout > 0) { |
| 80 |
*pMode = ZES_SCHED_MODE_TIMEOUT; |
| 81 |
} else { |
| 82 |
if (heartbeat == 0) { |
| 83 |
// If we are here, it means heartbeat = 0, timeout = 0, timeslice = 0. |
| 84 |
if (isComputeUnitDebugModeEnabled()) { |
| 85 |
*pMode = ZES_SCHED_MODE_COMPUTE_UNIT_DEBUG; |
| 86 |
} else { |
| 87 |
*pMode = ZES_SCHED_MODE_EXCLUSIVE; |
| 88 |
} |
| 89 |
} else { |
| 90 |
// If we are here it means heartbeat > 0, timeout = 0, timeslice = 0. |
| 91 |
// And we dont know what that mode is. |
| 92 |
*pMode = ZES_SCHED_MODE_FORCE_UINT32; |
| 93 |
result = ZE_RESULT_ERROR_UNKNOWN; |
| 94 |
} |
| 95 |
} |
| 96 |
} |
| 97 |
return result; |
| 98 |
} |
| 99 |
|
| 100 |
ze_result_t LinuxSchedulerImp::setExclusiveModeImp() { |
| 101 |
uint64_t timeslice = 0, timeout = 0, heartbeat = 0; |
| 102 |
ze_result_t result = setPreemptTimeout(timeout); |
| 103 |
if (result != ZE_RESULT_SUCCESS) { |
| 104 |
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to set preempt timeout and returning error:0x%x \n", __FUNCTION__, result); |
| 105 |
return result; |
| 106 |
} |
| 107 |
result = setTimesliceDuration(timeslice); |
| 108 |
if (result != ZE_RESULT_SUCCESS) { |
| 109 |
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to set timeslice duration and returning error:0x%x \n", __FUNCTION__, result); |
| 110 |
return result; |
| 111 |
} |
| 112 |
result = setHeartbeatInterval(heartbeat); |
| 113 |
return result; |
| 114 |
} |
| 115 |
|
| 116 |
ze_result_t LinuxSchedulerImp::setExclusiveMode(ze_bool_t *pNeedReload) { |
| 117 |
*pNeedReload = false; |
| 118 |
|
| 119 |
zes_sched_mode_t currMode; |
| 120 |
ze_result_t result = getCurrentMode(&currMode); |
| 121 |
if (result != ZE_RESULT_SUCCESS) { |
| 122 |
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to get current mode and returning error:0x%x \n", __FUNCTION__, result); |
| 123 |
return result; |
| 124 |
} |
| 125 |
|
| 126 |
if (currMode == ZES_SCHED_MODE_COMPUTE_UNIT_DEBUG) { |
| 127 |
// Unset this mode |
| 128 |
result = disableComputeUnitDebugMode(pNeedReload); |
| 129 |
if (result != ZE_RESULT_SUCCESS) { |
| 130 |
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); |
| 131 |
return result; |
| 132 |
} |
| 133 |
} |
| 134 |
|
| 135 |
return setExclusiveModeImp(); |
| 136 |
} |
| 137 |
|
| 138 |
ze_result_t LinuxSchedulerImp::getTimeoutModeProperties(ze_bool_t getDefaults, zes_sched_timeout_properties_t *pConfig) { |
| 139 |
uint64_t heartbeat = 0; |
| 140 |
ze_result_t result = getHeartbeatInterval(heartbeat, getDefaults); |
| 141 |
if (result != ZE_RESULT_SUCCESS) { |
| 142 |
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to get heart beat interval and returning error:0x%x \n", __FUNCTION__, result); |
| 143 |
return result; |
| 144 |
} |
| 145 |
pConfig->watchdogTimeout = heartbeat; |
| 146 |
|
| 147 |
return result; |
| 148 |
} |
| 149 |
|
| 150 |
ze_result_t LinuxSchedulerImp::getTimesliceModeProperties(ze_bool_t getDefaults, zes_sched_timeslice_properties_t *pConfig) { |
| 151 |
uint64_t timeout = 0, timeslice = 0; |
| 152 |
ze_result_t result = getPreemptTimeout(timeout, getDefaults); |
| 153 |
if (result != ZE_RESULT_SUCCESS) { |
| 154 |
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to get preempt timeout and returning error:0x%x \n", __FUNCTION__, result); |
| 155 |
return result; |
| 156 |
} |
| 157 |
result = getTimesliceDuration(timeslice, getDefaults); |
| 158 |
if (result != ZE_RESULT_SUCCESS) { |
| 159 |
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to get timeslice duration and returning error:0x%x \n", __FUNCTION__, result); |
| 160 |
return result; |
| 161 |
} |
| 162 |
pConfig->interval = timeslice; |
| 163 |
pConfig->yieldTimeout = timeout; |
| 164 |
return result; |
| 165 |
} |
| 166 |
|
| 167 |
ze_result_t LinuxSchedulerImp::setTimeoutMode(zes_sched_timeout_properties_t *pProperties, ze_bool_t *pNeedReload) { |
| 168 |
*pNeedReload = false; |
| 169 |
zes_sched_mode_t currMode; |
| 170 |
ze_result_t result = getCurrentMode(&currMode); |
| 171 |
if (result != ZE_RESULT_SUCCESS) { |
| 172 |
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to get current mode and returning error:0x%x \n", __FUNCTION__, result); |
| 173 |
return result; |
| 174 |
} |
| 175 |
|
| 176 |
if (pProperties->watchdogTimeout < minTimeoutModeHeartbeat) { |
| 177 |
// watchdogTimeout(in usec) less than 5000 would be computed to |
| 178 |
// 0 milli seconds preempt timeout, and then after returning from |
| 179 |
// this method, we would end up in EXCLUSIVE mode |
| 180 |
return ZE_RESULT_ERROR_INVALID_ARGUMENT; |
| 181 |
} |
| 182 |
|
| 183 |
if (currMode == ZES_SCHED_MODE_COMPUTE_UNIT_DEBUG) { |
| 184 |
// Unset this mode |
| 185 |
result = disableComputeUnitDebugMode(pNeedReload); |
| 186 |
if (result != ZE_RESULT_SUCCESS) { |
| 187 |
// failed to disable compute unit debug mode |
| 188 |
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); |
| 189 |
return result; |
| 190 |
} |
| 191 |
} |
| 192 |
|
| 193 |
result = setHeartbeatInterval(pProperties->watchdogTimeout); |
| 194 |
if (result != ZE_RESULT_SUCCESS) { |
| 195 |
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to set heartbeat interval and returning error:0x%x \n", __FUNCTION__, result); |
| 196 |
return result; |
| 197 |
} |
| 198 |
|
| 199 |
uint64_t timeout = (pProperties->watchdogTimeout) / 5; |
| 200 |
result = setPreemptTimeout(timeout); |
| 201 |
if (result != ZE_RESULT_SUCCESS) { |
| 202 |
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to set preempt timeout and returning error:0x%x \n", __FUNCTION__, result); |
| 203 |
return result; |
| 204 |
} |
| 205 |
|
| 206 |
uint64_t timeslice = 0; |
| 207 |
result = setTimesliceDuration(timeslice); |
| 208 |
if (result != ZE_RESULT_SUCCESS) { |
| 209 |
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to set timeslice duration and returning error:0x%x \n", __FUNCTION__, result); |
| 210 |
return result; |
| 211 |
} |
| 212 |
return result; |
| 213 |
} |
| 214 |
|
| 215 |
ze_result_t LinuxSchedulerImp::setTimesliceMode(zes_sched_timeslice_properties_t *pProperties, ze_bool_t *pNeedReload) { |
| 216 |
if (pProperties->interval < minTimeoutInMicroSeconds) { |
| 217 |
// interval(in usec) less than 1000 would be computed to |
| 218 |
// 0 milli seconds interval. |
| 219 |
return ZE_RESULT_ERROR_INVALID_ARGUMENT; |
| 220 |
} |
| 221 |
*pNeedReload = false; |
| 222 |
|
| 223 |
zes_sched_mode_t currMode; |
| 224 |
ze_result_t result = getCurrentMode(&currMode); |
| 225 |
if (result != ZE_RESULT_SUCCESS) { |
| 226 |
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to get current mode and returning error:0x%x \n", __FUNCTION__, result); |
| 227 |
return result; |
| 228 |
} |
| 229 |
|
| 230 |
if (currMode == ZES_SCHED_MODE_COMPUTE_UNIT_DEBUG) { |
| 231 |
// Unset this mode |
| 232 |
result = disableComputeUnitDebugMode(pNeedReload); |
| 233 |
if (result != ZE_RESULT_SUCCESS) { |
| 234 |
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); |
| 235 |
return result; |
| 236 |
} |
| 237 |
} |
| 238 |
|
| 239 |
result = setPreemptTimeout(pProperties->yieldTimeout); |
| 240 |
if (result != ZE_RESULT_SUCCESS) { |
| 241 |
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to set preempt timeout and returning error:0x%x \n", __FUNCTION__, result); |
| 242 |
return result; |
| 243 |
} |
| 244 |
result = setTimesliceDuration(pProperties->interval); |
| 245 |
if (result != ZE_RESULT_SUCCESS) { |
| 246 |
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to set timeslice duration and returning error:0x%x \n", __FUNCTION__, result); |
| 247 |
return result; |
| 248 |
} |
| 249 |
uint64_t heartbeat = 2500 * (pProperties->interval); |
| 250 |
return setHeartbeatInterval(heartbeat); |
| 251 |
} |
| 252 |
|
| 253 |
ze_result_t LinuxSchedulerImp::getProperties(zes_sched_properties_t &schedProperties) { |
| 254 |
schedProperties.onSubdevice = onSubdevice; |
| 255 |
schedProperties.subdeviceId = subdeviceId; |
| 256 |
schedProperties.canControl = canControlScheduler(); |
| 257 |
schedProperties.engines = this->engineType; |
| 258 |
schedProperties.supportedModes = (1 << ZES_SCHED_MODE_TIMEOUT) | (1 << ZES_SCHED_MODE_TIMESLICE) | (1 << ZES_SCHED_MODE_EXCLUSIVE); |
| 259 |
return ZE_RESULT_SUCCESS; |
| 260 |
} |
| 261 |
|
| 262 |
ze_result_t LinuxSchedulerImp::getPreemptTimeout(uint64_t &timeout, ze_bool_t getDefault) { |
| 263 |
ze_result_t result = ZE_RESULT_ERROR_UNKNOWN; |
| 264 |
uint32_t i = 0; |
| 265 |
std::vector<uint64_t> timeoutVec = {}; |
| 266 |
std::string path = ""; |
| 267 |
timeoutVec.resize(listOfEngines.size()); |
| 268 |
for (const auto &engineName : listOfEngines) { |
| 269 |
if (getDefault) { |
| 270 |
path = engineDir + "/" + engineName + "/" + defaultPreemptTimeouttMilliSecs; |
| 271 |
result = pSysfsAccess->read(path, timeout); |
| 272 |
} else { |
| 273 |
path = engineDir + "/" + engineName + "/" + preemptTimeoutMilliSecs; |
| 274 |
result = pSysfsAccess->read(path, timeout); |
| 275 |
} |
| 276 |
if (result == ZE_RESULT_SUCCESS) { |
| 277 |
timeout = timeout * milliSecsToMicroSecs; |
| 278 |
timeoutVec[i] = timeout; |
| 279 |
i++; |
| 280 |
} else { |
| 281 |
if (result == ZE_RESULT_ERROR_NOT_AVAILABLE) { |
| 282 |
result = ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; |
| 283 |
} |
| 284 |
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); |
| 285 |
return result; |
| 286 |
} |
| 287 |
} |
| 288 |
|
| 289 |
if (engineType == ZES_ENGINE_TYPE_FLAG_COMPUTE) { |
| 290 |
timeout = *std::max_element(timeoutVec.begin(), timeoutVec.end()); |
| 291 |
return result; |
| 292 |
} |
| 293 |
|
| 294 |
// check if all engines of the same type have the same scheduling param values |
| 295 |
if (std::adjacent_find(timeoutVec.begin(), timeoutVec.end(), std::not_equal_to<>()) == timeoutVec.end()) { |
| 296 |
timeout = timeoutVec[0]; |
| 297 |
return result; |
| 298 |
} else { |
| 299 |
return ZE_RESULT_ERROR_UNKNOWN; |
| 300 |
} |
| 301 |
} |
| 302 |
|
| 303 |
ze_result_t LinuxSchedulerImp::getTimesliceDuration(uint64_t ×lice, ze_bool_t getDefault) { |
| 304 |
ze_result_t result = ZE_RESULT_ERROR_UNKNOWN; |
| 305 |
uint32_t i = 0; |
| 306 |
std::vector<uint64_t> timesliceVec = {}; |
| 307 |
std::string path = ""; |
| 308 |
timesliceVec.resize(listOfEngines.size()); |
| 309 |
for (const auto &engineName : listOfEngines) { |
| 310 |
if (getDefault) { |
| 311 |
path = engineDir + "/" + engineName + "/" + defaultTimesliceDurationMilliSecs; |
| 312 |
result = pSysfsAccess->read(path, timeslice); |
| 313 |
} else { |
| 314 |
path = engineDir + "/" + engineName + "/" + timesliceDurationMilliSecs; |
| 315 |
result = pSysfsAccess->read(path, timeslice); |
| 316 |
} |
| 317 |
if (result == ZE_RESULT_SUCCESS) { |
| 318 |
timeslice = timeslice * milliSecsToMicroSecs; |
| 319 |
timesliceVec[i] = timeslice; |
| 320 |
i++; |
| 321 |
} else { |
| 322 |
if (result == ZE_RESULT_ERROR_NOT_AVAILABLE) { |
| 323 |
result = ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; |
| 324 |
} |
| 325 |
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); |
| 326 |
return result; |
| 327 |
} |
| 328 |
} |
| 329 |
// check if all engines of the same type have the same scheduling param values |
| 330 |
if (std::adjacent_find(timesliceVec.begin(), timesliceVec.end(), std::not_equal_to<>()) == timesliceVec.end()) { |
| 331 |
timeslice = timesliceVec[0]; |
| 332 |
return result; |
| 333 |
} else { |
| 334 |
return ZE_RESULT_ERROR_UNKNOWN; |
| 335 |
} |
| 336 |
} |
| 337 |
|
| 338 |
ze_result_t LinuxSchedulerImp::getHeartbeatInterval(uint64_t &heartbeat, ze_bool_t getDefault) { |
| 339 |
ze_result_t result = ZE_RESULT_ERROR_UNKNOWN; |
| 340 |
uint32_t i = 0; |
| 341 |
std::vector<uint64_t> heartbeatVec = {}; |
| 342 |
std::string path = ""; |
| 343 |
heartbeatVec.resize(listOfEngines.size()); |
| 344 |
for (const auto &engineName : listOfEngines) { |
| 345 |
if (getDefault) { |
| 346 |
path = engineDir + "/" + engineName + "/" + defaultHeartbeatIntervalMilliSecs; |
| 347 |
result = pSysfsAccess->read(path, heartbeat); |
| 348 |
} else { |
| 349 |
path = engineDir + "/" + engineName + "/" + heartbeatIntervalMilliSecs; |
| 350 |
result = pSysfsAccess->read(path, heartbeat); |
| 351 |
} |
| 352 |
if (result == ZE_RESULT_SUCCESS) { |
| 353 |
heartbeat = heartbeat * milliSecsToMicroSecs; |
| 354 |
heartbeatVec[i] = heartbeat; |
| 355 |
i++; |
| 356 |
} else { |
| 357 |
if (result == ZE_RESULT_ERROR_NOT_AVAILABLE) { |
| 358 |
result = ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; |
| 359 |
} |
| 360 |
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); |
| 361 |
return result; |
| 362 |
} |
| 363 |
} |
| 364 |
// check if all engines of the same type have the same scheduling param values |
| 365 |
if (std::adjacent_find(heartbeatVec.begin(), heartbeatVec.end(), std::not_equal_to<>()) == heartbeatVec.end()) { |
| 366 |
heartbeat = heartbeatVec[0]; |
| 367 |
return result; |
| 368 |
} else { |
| 369 |
return ZE_RESULT_ERROR_UNKNOWN; |
| 370 |
} |
| 371 |
} |
| 372 |
|
| 373 |
ze_result_t LinuxSchedulerImp::setPreemptTimeout(uint64_t timeout) { |
| 374 |
timeout = timeout / milliSecsToMicroSecs; |
| 375 |
ze_result_t result = ZE_RESULT_ERROR_UNKNOWN; |
| 376 |
for (const auto &engineName : listOfEngines) { |
| 377 |
result = pSysfsAccess->write(engineDir + "/" + engineName + "/" + preemptTimeoutMilliSecs, timeout); |
| 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 Preempt timeout into engineDir/%s/preemptTimeoutMilliSecs and returning error:0x%x \n", __FUNCTION__, engineName.c_str(), result); |
| 383 |
return result; |
| 384 |
} |
| 385 |
} |
| 386 |
return result; |
| 387 |
} |
| 388 |
|
| 389 |
ze_result_t LinuxSchedulerImp::setTimesliceDuration(uint64_t timeslice) { |
| 390 |
timeslice = timeslice / milliSecsToMicroSecs; |
| 391 |
ze_result_t result = ZE_RESULT_ERROR_UNKNOWN; |
| 392 |
for (const auto &engineName : listOfEngines) { |
| 393 |
result = pSysfsAccess->write(engineDir + "/" + engineName + "/" + timesliceDurationMilliSecs, timeslice); |
| 394 |
if (result != ZE_RESULT_SUCCESS) { |
| 395 |
if (result == ZE_RESULT_ERROR_NOT_AVAILABLE) { |
| 396 |
result = ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; |
| 397 |
} |
| 398 |
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); |
| 399 |
return result; |
| 400 |
} |
| 401 |
} |
| 402 |
return result; |
| 403 |
} |
| 404 |
|
| 405 |
ze_result_t LinuxSchedulerImp::setHeartbeatInterval(uint64_t heartbeat) { |
| 406 |
heartbeat = heartbeat / milliSecsToMicroSecs; |
| 407 |
ze_result_t result = ZE_RESULT_ERROR_UNKNOWN; |
| 408 |
for (const auto &engineName : listOfEngines) { |
| 409 |
result = pSysfsAccess->write(engineDir + "/" + engineName + "/" + heartbeatIntervalMilliSecs, heartbeat); |
| 410 |
if (result != ZE_RESULT_SUCCESS) { |
| 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 write Heartbeat interval into engineDir/%s/heartbeatIntervalMilliSecs and returning error:0x%x \n", __FUNCTION__, engineName.c_str(), result); |
| 415 |
return result; |
| 416 |
} |
| 417 |
} |
| 418 |
return result; |
| 419 |
} |
| 420 |
|
| 421 |
ze_bool_t LinuxSchedulerImp::canControlScheduler() { |
| 422 |
return 1; |
| 423 |
} |
| 424 |
|
| 425 |
ze_result_t LinuxSchedulerImp::updateComputeUnitDebugNode(uint64_t val) { |
| 426 |
// I915 will be reloaded if we toggle value of enableEuDebug |
| 427 |
// Hence for gracefull handling close all i915 clients before toggling enableEuDebug |
| 428 |
auto pDevice = pLinuxSysmanImp->getDeviceHandle(); |
| 429 |
auto devicePtr = static_cast<DeviceImp *>(pDevice); |
| 430 |
NEO::ExecutionEnvironment *executionEnvironment = devicePtr->getNEODevice()->getExecutionEnvironment(); |
| 431 |
auto restorer = std::make_unique<L0::ExecutionEnvironmentRefCountRestore>(executionEnvironment); |
| 432 |
pLinuxSysmanImp->releaseDeviceResources(); |
| 433 |
ze_result_t result = pLinuxSysmanImp->gpuProcessCleanup(true); |
| 434 |
if (ZE_RESULT_SUCCESS != result) { |
| 435 |
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, |
| 436 |
"updateComputeUnitDebugNode: gpuProcessCleanup() failed with error code: %ld\n", result); |
| 437 |
return result; |
| 438 |
} |
| 439 |
result = pSysfsAccess->write(enableEuDebug, val); |
| 440 |
if (result != ZE_RESULT_SUCCESS) { |
| 441 |
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, |
| 442 |
"updateComputeUnitDebugNode: Write to sysfs node %s failed with error code: %ld\n", enableEuDebug.c_str(), result); |
| 443 |
} |
| 444 |
pLinuxSysmanImp->initDevice(); |
| 445 |
return result; |
| 446 |
} |
| 447 |
|
| 448 |
ze_result_t LinuxSchedulerImp::setComputeUnitDebugMode(ze_bool_t *pNeedReload) { |
| 449 |
auto result = setExclusiveModeImp(); |
| 450 |
if (result != ZE_RESULT_SUCCESS) { |
| 451 |
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, |
| 452 |
"setComputeUnitDebugMode: Exclusive mode set(precontiion to set Debug mode) failed. Error code: %ld\n", result); |
| 453 |
return result; |
| 454 |
} |
| 455 |
|
| 456 |
*pNeedReload = false; |
| 457 |
uint64_t val = 1; |
| 458 |
auto ret = pSysfsAccess->canWrite(enableEuDebug); |
| 459 |
if (ret != ZE_RESULT_SUCCESS) { |
| 460 |
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, |
| 461 |
"setComputeUnitDebugMode: sysfs node %s not writable. Error code: %ld\n", enableEuDebug.c_str(), result); |
| 462 |
return ret; |
| 463 |
} |
| 464 |
return updateComputeUnitDebugNode(val); |
| 465 |
} |
| 466 |
|
| 467 |
bool LinuxSchedulerImp::isComputeUnitDebugModeEnabled() { |
| 468 |
uint64_t val = 0; |
| 469 |
auto result = pSysfsAccess->read(enableEuDebug, val); |
| 470 |
if (result != ZE_RESULT_SUCCESS) { |
| 471 |
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, |
| 472 |
"isComputeUnitDebugModeEnabled: Read from sysfs node %s failed with error code: %ld\n", enableEuDebug.c_str(), result); |
| 473 |
return false; |
| 474 |
} |
| 475 |
return (val == 0) ? false : true; |
| 476 |
} |
| 477 |
|
| 478 |
ze_result_t LinuxSchedulerImp::disableComputeUnitDebugMode(ze_bool_t *pNeedReload) { |
| 479 |
*pNeedReload = false; |
| 480 |
uint64_t val = 0; |
| 481 |
return updateComputeUnitDebugNode(val); |
| 482 |
} |
| 483 |
|
| 484 |
static ze_result_t getNumEngineTypeAndInstancesForSubDevices(std::map<zes_engine_type_flag_t, std::vector<std::string>> &mapOfEngines, |
| 485 |
NEO::Drm *pDrm, uint32_t subdeviceId) { |
| 486 |
auto engineInfo = pDrm->getEngineInfo(); |
| 487 |
if (engineInfo == nullptr) { |
| 488 |
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; |
| 489 |
} |
| 490 |
std::vector<NEO::EngineClassInstance> listOfEngines; |
| 491 |
engineInfo->getListOfEnginesOnATile(subdeviceId, listOfEngines); |
| 492 |
for (const auto &engine : listOfEngines) { |
| 493 |
auto sysfEngineString = i915EngineClassToSysfsEngineMap.find(static_cast<drm_i915_gem_engine_class>(engine.engineClass)); |
| 494 |
if (sysfEngineString == i915EngineClassToSysfsEngineMap.end()) { |
| 495 |
continue; |
| 496 |
} |
| 497 |
|
| 498 |
std::string sysfsEngineDirNode = sysfEngineString->second + std::to_string(engine.engineInstance); |
| 499 |
auto level0EngineType = sysfsEngineMapToLevel0EngineType.find(sysfEngineString->second); |
| 500 |
auto ret = mapOfEngines.find(level0EngineType->second); |
| 501 |
if (ret != mapOfEngines.end()) { |
| 502 |
ret->second.push_back(sysfsEngineDirNode); |
| 503 |
} else { |
| 504 |
std::vector<std::string> engineVec = {}; |
| 505 |
engineVec.push_back(sysfsEngineDirNode); |
| 506 |
mapOfEngines.emplace(level0EngineType->second, engineVec); |
| 507 |
} |
| 508 |
} |
| 509 |
return ZE_RESULT_SUCCESS; |
| 510 |
} |
| 511 |
|
| 512 |
static ze_result_t getNumEngineTypeAndInstancesForDevice(std::map<zes_engine_type_flag_t, std::vector<std::string>> &mapOfEngines, SysfsAccess *pSysfsAccess) { |
| 513 |
std::vector<std::string> localListOfAllEngines = {}; |
| 514 |
auto result = pSysfsAccess->scanDirEntries(LinuxSchedulerImp::engineDir, localListOfAllEngines); |
| 515 |
if (ZE_RESULT_SUCCESS != result) { |
| 516 |
if (result == ZE_RESULT_ERROR_NOT_AVAILABLE) { |
| 517 |
result = ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; |
| 518 |
} |
| 519 |
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); |
| 520 |
return result; |
| 521 |
} |
| 522 |
for_each(localListOfAllEngines.begin(), localListOfAllEngines.end(), |
| 523 |
[&](std::string &mappedEngine) { |
| 524 |
for (auto itr = level0EngineTypeToSysfsEngineMap.begin(); itr != level0EngineTypeToSysfsEngineMap.end(); itr++) { |
| 525 |
char digits[] = "0123456789"; |
| 526 |
auto mappedEngineName = mappedEngine.substr(0, mappedEngine.find_first_of(digits, 0)); |
| 527 |
if (0 == mappedEngineName.compare(itr->second.c_str())) { |
| 528 |
auto ret = mapOfEngines.find(itr->first); |
| 529 |
if (ret != mapOfEngines.end()) { |
| 530 |
ret->second.push_back(mappedEngine); |
| 531 |
} else { |
| 532 |
std::vector<std::string> engineVec = {}; |
| 533 |
engineVec.push_back(mappedEngine); |
| 534 |
mapOfEngines.emplace(itr->first, engineVec); |
| 535 |
} |
| 536 |
} |
| 537 |
} |
| 538 |
}); |
| 539 |
return result; |
| 540 |
} |
| 541 |
|
| 542 |
ze_result_t OsScheduler::getNumEngineTypeAndInstances( |
| 543 |
std::map<zes_engine_type_flag_t, std::vector<std::string>> &mapOfEngines, OsSysman *pOsSysman, ze_device_handle_t subdeviceHandle) { |
| 544 |
LinuxSysmanImp *pLinuxSysmanImp = static_cast<LinuxSysmanImp *>(pOsSysman); |
| 545 |
auto pDrm = &pLinuxSysmanImp->getDrm(); |
| 546 |
auto pSysfsAccess = &pLinuxSysmanImp->getSysfsAccess(); |
| 547 |
uint32_t subdeviceId = std::numeric_limits<uint32_t>::max(); |
| 548 |
ze_bool_t onSubdevice = false; |
| 549 |
SysmanDeviceImp::getSysmanDeviceInfo(subdeviceHandle, subdeviceId, onSubdevice, true); |
| 550 |
if (onSubdevice) { |
| 551 |
return getNumEngineTypeAndInstancesForSubDevices(mapOfEngines, pDrm, subdeviceId); |
| 552 |
} |
| 553 |
|
| 554 |
return getNumEngineTypeAndInstancesForDevice(mapOfEngines, pSysfsAccess); |
| 555 |
} |
| 556 |
|
| 557 |
LinuxSchedulerImp::LinuxSchedulerImp( |
| 558 |
OsSysman *pOsSysman, zes_engine_type_flag_t type, std::vector<std::string> &listOfEngines, ze_bool_t isSubdevice, |
| 559 |
uint32_t subdeviceId) : engineType(type), onSubdevice(isSubdevice), subdeviceId(subdeviceId) { |
| 560 |
pLinuxSysmanImp = static_cast<LinuxSysmanImp *>(pOsSysman); |
| 561 |
pSysfsAccess = &pLinuxSysmanImp->getSysfsAccess(); |
| 562 |
this->listOfEngines = listOfEngines; |
| 563 |
} |
| 564 |
|
| 565 |
std::unique_ptr<OsScheduler> OsScheduler::create( |
| 566 |
OsSysman *pOsSysman, zes_engine_type_flag_t type, std::vector<std::string> &listOfEngines, ze_bool_t isSubdevice, uint32_t subdeviceId) { |
| 567 |
std::unique_ptr<LinuxSchedulerImp> pLinuxSchedulerImp = std::make_unique<LinuxSchedulerImp>(pOsSysman, type, listOfEngines, isSubdevice, subdeviceId); |
| 568 |
return pLinuxSchedulerImp; |
| 569 |
} |
| 570 |
|
| 571 |
} // namespace L0 |