1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
|
/*
* Copyright (C) 2020-2026 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "level_zero/tools/source/sysman/ras/linux/os_ras_imp.h"
#include "shared/source/debug_settings/debug_settings_manager.h"
#include "shared/source/helpers/string.h"
#include "shared/source/os_interface/linux/system_info.h"
#include "level_zero/tools/source/sysman/linux/fs_access.h"
#include "level_zero/tools/source/sysman/linux/os_sysman_imp.h"
#include "level_zero/tools/source/sysman/sysman_const.h"
#include <algorithm>
namespace L0 {
static bool isMemoryTypeHbm(LinuxSysmanImp *pLinuxSysmanImp) {
uint32_t memType = pLinuxSysmanImp->getMemoryType();
if (memType == NEO::DeviceBlobConstants::MemoryType::hbm2e || memType == NEO::DeviceBlobConstants::MemoryType::hbm2) {
return true;
}
return false;
}
void OsRas::getSupportedRasErrorTypes(std::set<zes_ras_error_type_t> &errorType, OsSysman *pOsSysman, ze_device_handle_t deviceHandle) {
constexpr auto maxErrorTypes = 2;
LinuxRasSourceGt::getSupportedRasErrorTypes(errorType, pOsSysman, deviceHandle);
if (errorType.size() < maxErrorTypes) {
auto pLinuxSysmanImp = static_cast<LinuxSysmanImp *>(pOsSysman);
if (isMemoryTypeHbm(pLinuxSysmanImp) == true) {
LinuxRasSourceHbm::getSupportedRasErrorTypes(errorType, pOsSysman, deviceHandle);
}
}
}
ze_result_t LinuxRasImp::osRasGetConfig(zes_ras_config_t *config) {
config->totalThreshold = totalThreshold;
memcpy_s(config->detailedThresholds.category, maxRasErrorCategoryCount * sizeof(uint64_t), categoryThreshold, maxRasErrorCategoryCount * sizeof(uint64_t));
return ZE_RESULT_SUCCESS;
}
ze_result_t LinuxRasImp::osRasSetConfig(const zes_ras_config_t *config) {
if (pFsAccess->isRootUser() == true) {
totalThreshold = config->totalThreshold;
memcpy_s(categoryThreshold, maxRasErrorCategoryCount * sizeof(uint64_t), config->detailedThresholds.category, maxRasErrorCategoryCount * sizeof(uint64_t));
return ZE_RESULT_SUCCESS;
}
PRINT_STRING(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Insufficient permissions and returning error:0x%x \n", __FUNCTION__, ZE_RESULT_ERROR_INSUFFICIENT_PERMISSIONS);
return ZE_RESULT_ERROR_INSUFFICIENT_PERMISSIONS;
}
ze_result_t LinuxRasImp::osRasGetProperties(zes_ras_properties_t &properties) {
properties.pNext = nullptr;
properties.type = osRasErrorType;
properties.onSubdevice = isSubdevice;
properties.subdeviceId = subdeviceId;
return ZE_RESULT_SUCCESS;
}
ze_result_t LinuxRasImp::osRasGetState(zes_ras_state_t &state, ze_bool_t clear) {
if (clear == true) {
if (pFsAccess->isRootUser() == false) {
PRINT_STRING(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Insufficient permissions and returning error:0x%x \n", __FUNCTION__, ZE_RESULT_ERROR_INSUFFICIENT_PERMISSIONS);
return ZE_RESULT_ERROR_INSUFFICIENT_PERMISSIONS;
}
}
ze_result_t result = ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
for (auto &rasSource : rasSources) {
zes_ras_state_t localState = {};
ze_result_t localResult = rasSource->osRasGetState(localState, clear);
if (localResult != ZE_RESULT_SUCCESS) {
continue;
}
for (uint32_t i = 0; i < maxRasErrorCategoryCount; i++) {
state.category[i] += localState.category[i];
}
result = ZE_RESULT_SUCCESS;
}
return result;
}
ze_result_t LinuxRasImp::osRasGetStateExp(uint32_t *pCount, zes_ras_state_exp_t *pState) {
ze_result_t result = ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE;
uint32_t totalCategoryCount = 0;
std::vector<uint32_t> numCategoriesBySources = {};
for (auto &rasSource : rasSources) {
totalCategoryCount += rasSource->osRasGetCategoryCount();
numCategoriesBySources.push_back(totalCategoryCount);
}
if (*pCount == 0) {
*pCount = totalCategoryCount;
return ZE_RESULT_SUCCESS;
}
uint32_t remainingCategories = std::min(totalCategoryCount, *pCount);
uint32_t numCategoriesAssigned = 0u;
for (uint32_t rasSourceIdx = 0u; rasSourceIdx < rasSources.size(); rasSourceIdx++) {
auto &rasSource = rasSources[rasSourceIdx];
uint32_t numCategoriesRequested = std::min(remainingCategories, numCategoriesBySources[rasSourceIdx]);
ze_result_t localResult = rasSource->osRasGetStateExp(numCategoriesRequested, &pState[numCategoriesAssigned]);
if (localResult != ZE_RESULT_SUCCESS) {
continue;
}
remainingCategories -= numCategoriesRequested;
numCategoriesAssigned += numCategoriesBySources[rasSourceIdx];
result = localResult;
if (remainingCategories == 0u) {
break;
}
}
return result;
}
ze_result_t LinuxRasImp::osRasClearStateExp(zes_ras_error_category_exp_t category) {
if (pFsAccess->isRootUser() == false) {
PRINT_STRING(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Insufficient permissions and returning error:0x%x \n", __FUNCTION__, ZE_RESULT_ERROR_INSUFFICIENT_PERMISSIONS);
return ZE_RESULT_ERROR_INSUFFICIENT_PERMISSIONS;
}
if (ZES_RAS_ERROR_CATEGORY_EXP_L3FABRIC_ERRORS < category) {
return ZE_RESULT_ERROR_INVALID_ENUMERATION;
}
ze_result_t result = ZE_RESULT_ERROR_NOT_AVAILABLE;
for (auto &rasSource : rasSources) {
result = rasSource->osRasClearStateExp(category);
if (result != ZE_RESULT_SUCCESS) {
if (result == ZE_RESULT_ERROR_NOT_AVAILABLE) {
continue;
}
return result;
}
}
return result;
}
ze_result_t LinuxRasImp::osRasGetSupportedCategoriesExp(uint32_t *pCount, zes_ras_error_category_exp_t *pCategories) {
if (*pCount == 0) {
*pCount = static_cast<uint32_t>(supportedErrorCategoriesExp.size());
return ZE_RESULT_SUCCESS;
}
uint32_t numCategoriesToCopy = std::min(*pCount, static_cast<uint32_t>(supportedErrorCategoriesExp.size()));
for (uint32_t i = 0; i < numCategoriesToCopy; i++) {
pCategories[i] = supportedErrorCategoriesExp[i];
}
*pCount = numCategoriesToCopy;
return ZE_RESULT_SUCCESS;
}
ze_result_t LinuxRasImp::osRasGetConfigExp(const uint32_t count, zes_intel_ras_config_exp_t *pConfig) {
for (uint32_t i = 0; i < count; i++) {
auto it = std::find_if(categoryExpThresholds.begin(), categoryExpThresholds.end(),
[&pConfig, i](const std::pair<zes_ras_error_category_exp_t, uint64_t> &element) {
return element.first == pConfig[i].category;
});
if (it != categoryExpThresholds.end()) {
pConfig[i].threshold = it->second;
} else {
pConfig[i].threshold = 0;
}
}
return ZE_RESULT_SUCCESS;
}
ze_result_t LinuxRasImp::osRasSetConfigExp(const uint32_t count, const zes_intel_ras_config_exp_t *pConfig) {
if (pFsAccess->isRootUser() == true) {
categoryExpThresholds.clear();
for (uint32_t i = 0; i < count; i++) {
categoryExpThresholds.push_back(std::make_pair(pConfig[i].category, pConfig[i].threshold));
}
return ZE_RESULT_SUCCESS;
}
PRINT_STRING(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Insufficient permissions and returning error:0x%x \n", __FUNCTION__, ZE_RESULT_ERROR_INSUFFICIENT_PERMISSIONS);
return ZE_RESULT_ERROR_INSUFFICIENT_PERMISSIONS;
}
void LinuxRasImp::initSources() {
rasSources.push_back(std::make_unique<L0::LinuxRasSourceGt>(pLinuxSysmanImp, osRasErrorType, isSubdevice, subdeviceId));
if (isMemoryTypeHbm(pLinuxSysmanImp) == true) {
rasSources.push_back(std::make_unique<L0::LinuxRasSourceHbm>(pLinuxSysmanImp, osRasErrorType, subdeviceId));
}
for (const auto &rasSource : rasSources) {
auto categories = rasSource->getSupportedErrorCategories(osRasErrorType);
for ([[maybe_unused]] const auto &category : categories) {
DEBUG_BREAK_IF(std::find(supportedErrorCategoriesExp.begin(), supportedErrorCategoriesExp.end(), category) != supportedErrorCategoriesExp.end());
}
supportedErrorCategoriesExp.insert(supportedErrorCategoriesExp.end(), categories.begin(), categories.end());
}
}
LinuxRasImp::LinuxRasImp(OsSysman *pOsSysman, zes_ras_error_type_t type, ze_bool_t onSubdevice, uint32_t subdeviceId) : osRasErrorType(type), isSubdevice(onSubdevice), subdeviceId(subdeviceId) {
pLinuxSysmanImp = static_cast<LinuxSysmanImp *>(pOsSysman);
pFsAccess = &pLinuxSysmanImp->getFsAccess();
initSources();
}
OsRas *OsRas::create(OsSysman *pOsSysman, zes_ras_error_type_t type, ze_bool_t onSubdevice, uint32_t subdeviceId) {
LinuxRasImp *pLinuxRasImp = new LinuxRasImp(pOsSysman, type, onSubdevice, subdeviceId);
return static_cast<OsRas *>(pLinuxRasImp);
}
} // namespace L0
|