| 1 | /* |
| 2 | * Copyright (c) 2019-2022, Intel Corporation |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | * Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice shall be included |
| 12 | * in all copies or substantial portions of the Software. |
| 13 | * |
| 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 20 | * OTHER DEALINGS IN THE SOFTWARE. |
| 21 | */ |
| 22 | //! |
| 23 | //! \file mos_util_debug.cpp |
| 24 | //! \brief Common OS debug across different platform |
| 25 | //! \details Common OS debug across different platform |
| 26 | //! |
| 27 | |
| 28 | #include "mos_util_debug.h" |
| 29 | |
| 30 | #if MOS_MESSAGES_ENABLED |
| 31 | #include "media_user_setting.h" |
| 32 | |
| 33 | //! |
| 34 | //! \brief DDI dump file name template |
| 35 | //! |
| 36 | #define DDILogPathTemplate "%s\\ddi_dump_%d.%s" |
| 37 | |
| 38 | const char * const MosUtilDebug::m_mosLogLevelName[MOS_MESSAGE_LVL_COUNT] = { |
| 39 | "", // DISABLED |
| 40 | "CRITICAL", |
| 41 | "WARNING ", |
| 42 | "NORMAL ", |
| 43 | "VERBOSE ", |
| 44 | "ENTER ", |
| 45 | "EXIT ", |
| 46 | "ENTER ", // ENTER VERBOSE |
| 47 | "EXIT ", // EXIT VERBOSE |
| 48 | }; |
| 49 | |
| 50 | const char * const MosUtilDebug::m_mosComponentName[MOS_COMPONENT_COUNT] = { |
| 51 | "[MOS]: ", |
| 52 | "[MHW]: ", |
| 53 | "[CODEC]:", |
| 54 | "[VP]: ", |
| 55 | "[CP]: ", |
| 56 | MOS_COMPONENT_NAME_DDI_STRING, |
| 57 | "[CM]: ", |
| 58 | "[CPLIB]:", |
| 59 | "[SCAL]: ", |
| 60 | "[MMC]: ", |
| 61 | "[MCPY]: " |
| 62 | }; |
| 63 | |
| 64 | const char* MosUtilDebug::m_pcComponentUserFeatureKeys[MOS_COMPONENT_COUNT][3] = { |
| 65 | { |
| 66 | __MOS_USER_FEATURE_KEY_MESSAGE_OS_TAG, |
| 67 | __MOS_USER_FEATURE_KEY_BY_SUB_COMPONENT_OS, |
| 68 | __MOS_USER_FEATURE_KEY_SUB_COMPONENT_OS_TAG |
| 69 | }, |
| 70 | |
| 71 | { |
| 72 | __MOS_USER_FEATURE_KEY_MESSAGE_MHW_TAG, |
| 73 | __MOS_USER_FEATURE_KEY_BY_SUB_COMPONENT_MHW, |
| 74 | __MOS_USER_FEATURE_KEY_SUB_COMPONENT_MHW_TAG |
| 75 | }, |
| 76 | |
| 77 | { |
| 78 | __MOS_USER_FEATURE_KEY_MESSAGE_CODEC_TAG, |
| 79 | __MOS_USER_FEATURE_KEY_BY_SUB_COMPONENT_CODEC, |
| 80 | __MOS_USER_FEATURE_KEY_SUB_COMPONENT_CODEC_TAG |
| 81 | }, |
| 82 | |
| 83 | { |
| 84 | __MOS_USER_FEATURE_KEY_MESSAGE_VP_TAG, |
| 85 | __MOS_USER_FEATURE_KEY_BY_SUB_COMPONENT_VP, |
| 86 | __MOS_USER_FEATURE_KEY_SUB_COMPONENT_VP_TAG |
| 87 | }, |
| 88 | |
| 89 | { |
| 90 | __MOS_USER_FEATURE_KEY_MESSAGE_CP_TAG, |
| 91 | __MOS_USER_FEATURE_KEY_BY_SUB_COMPONENT_CP, |
| 92 | __MOS_USER_FEATURE_KEY_SUB_COMPONENT_CP_TAG |
| 93 | }, |
| 94 | |
| 95 | { |
| 96 | __MOS_USER_FEATURE_KEY_MESSAGE_DDI_TAG, |
| 97 | __MOS_USER_FEATURE_KEY_BY_SUB_COMPONENT_DDI, |
| 98 | __MOS_USER_FEATURE_KEY_SUB_COMPONENT_DDI_TAG |
| 99 | }, |
| 100 | |
| 101 | { |
| 102 | __MOS_USER_FEATURE_KEY_MESSAGE_CM_TAG, |
| 103 | __MOS_USER_FEATURE_KEY_BY_SUB_COMPONENT_CM, |
| 104 | __MOS_USER_FEATURE_KEY_SUB_COMPONENT_CM_TAG |
| 105 | }, |
| 106 | |
| 107 | {// CPLIB |
| 108 | __MOS_USER_FEATURE_KEY_MESSAGE_CP_TAG, |
| 109 | __MOS_USER_FEATURE_KEY_BY_SUB_COMPONENT_CP, |
| 110 | __MOS_USER_FEATURE_KEY_SUB_COMPONENT_CP_TAG |
| 111 | }, |
| 112 | |
| 113 | { |
| 114 | __MOS_USER_FEATURE_KEY_MESSAGE_SCALABILITY_TAG, |
| 115 | __MOS_USER_FEATURE_KEY_BY_SUB_COMPONENT_SCALABILITY, |
| 116 | __MOS_USER_FEATURE_KEY_SUB_COMPONENT_SCALABILITY_TAG |
| 117 | }, |
| 118 | |
| 119 | { |
| 120 | __MOS_USER_FEATURE_KEY_MESSAGE_MMC_TAG, |
| 121 | __MOS_USER_FEATURE_KEY_BY_SUB_COMPONENT_MMC, |
| 122 | __MOS_USER_FEATURE_KEY_SUB_COMPONENT_MMC_TAG |
| 123 | }, |
| 124 | |
| 125 | { |
| 126 | __MOS_USER_FEATURE_KEY_MESSAGE_MCPY_TAG, |
| 127 | __MOS_USER_FEATURE_KEY_BY_SUB_COMPONENT_MCPY, |
| 128 | __MOS_USER_FEATURE_KEY_SUB_COMPONENT_MCPY_TAG |
| 129 | } |
| 130 | }; |
| 131 | |
| 132 | const uint8_t MosUtilDebug::m_subComponentCount[MOS_COMPONENT_COUNT] = { |
| 133 | MOS_SUBCOMP_COUNT, |
| 134 | MOS_HW_SUBCOMP_COUNT, |
| 135 | MOS_CODEC_SUBCOMP_COUNT, |
| 136 | MOS_VP_SUBCOMP_COUNT, |
| 137 | MOS_CP_SUBCOMP_COUNT, |
| 138 | MOS_DDI_SUBCOMP_COUNT, |
| 139 | MOS_CM_SUBCOMP_COUNT |
| 140 | }; |
| 141 | |
| 142 | MOS_MESSAGE_PARAMS MosUtilDebug::m_mosMsgParams = {}; |
| 143 | |
| 144 | void MosUtilDebug::MosSetSubCompMessageLevel(MOS_COMPONENT_ID compID, uint8_t subCompID, MOS_MESSAGE_LEVEL msgLevel) |
| 145 | { |
| 146 | if (compID >= MOS_COMPONENT_COUNT) |
| 147 | { |
| 148 | MOS_OS_ASSERTMESSAGE("Invalid component %d.", compID); |
| 149 | return; |
| 150 | } |
| 151 | |
| 152 | if (subCompID >= MOS_MAX_SUBCOMPONENT_COUNT) |
| 153 | { |
| 154 | MOS_OS_ASSERTMESSAGE("Invalid sub-component %d.", subCompID); |
| 155 | return; |
| 156 | } |
| 157 | |
| 158 | if (msgLevel >= MOS_MESSAGE_LVL_COUNT) |
| 159 | { |
| 160 | MOS_OS_ASSERTMESSAGE("Invalid msg level %d.", msgLevel); |
| 161 | return; |
| 162 | } |
| 163 | |
| 164 | m_mosMsgParams.components[compID].subComponents[subCompID].uiMessageLevel = msgLevel; |
| 165 | } |
| 166 | |
| 167 | void MosUtilDebug::MosSetCompMessageLevel(MOS_COMPONENT_ID compID, MOS_MESSAGE_LEVEL msgLevel) |
| 168 | { |
| 169 | if (compID >= MOS_COMPONENT_COUNT) |
| 170 | { |
| 171 | MOS_OS_ASSERTMESSAGE("Invalid component %d.", compID); |
| 172 | return; |
| 173 | } |
| 174 | |
| 175 | if (msgLevel >= MOS_MESSAGE_LVL_COUNT) |
| 176 | { |
| 177 | MOS_OS_ASSERTMESSAGE("Invalid msg level %d.", msgLevel); |
| 178 | return; |
| 179 | } |
| 180 | m_mosMsgParams.components[compID].component.uiMessageLevel = msgLevel; |
| 181 | } |
| 182 | |
| 183 | void MosUtilDebug::MosSetCompMessageLevelAll(MOS_MESSAGE_LEVEL msgLevel) |
| 184 | { |
| 185 | if (msgLevel >= MOS_MESSAGE_LVL_COUNT) |
| 186 | { |
| 187 | MOS_OS_ASSERTMESSAGE("Invalid msg level %d.", msgLevel); |
| 188 | return; |
| 189 | } |
| 190 | |
| 191 | uint32_t i = 0; |
| 192 | |
| 193 | for(i = 0; i < MOS_COMPONENT_COUNT; i++) |
| 194 | { |
| 195 | MosSetCompMessageLevel((MOS_COMPONENT_ID)i, msgLevel); |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | void MosUtilDebug::MosSubCompAssertEnableDisable(MOS_COMPONENT_ID compID, uint8_t subCompID, int32_t bEnable) |
| 200 | { |
| 201 | if (compID >= MOS_COMPONENT_COUNT) |
| 202 | { |
| 203 | MOS_OS_ASSERTMESSAGE("Invalid component %d.", compID); |
| 204 | return; |
| 205 | } |
| 206 | |
| 207 | if (subCompID >= MOS_MAX_SUBCOMPONENT_COUNT) |
| 208 | { |
| 209 | MOS_OS_ASSERTMESSAGE("Invalid sub-component %d.", subCompID); |
| 210 | return; |
| 211 | } |
| 212 | |
| 213 | m_mosMsgParams.components[compID].subComponents[subCompID].bAssertEnabled = bEnable; |
| 214 | } |
| 215 | |
| 216 | void MosUtilDebug::MosCompAssertEnableDisable(MOS_COMPONENT_ID compID, int32_t bEnable) |
| 217 | { |
| 218 | if (compID >= MOS_COMPONENT_COUNT) |
| 219 | { |
| 220 | MOS_OS_ASSERTMESSAGE("Invalid component %d.", compID); |
| 221 | return; |
| 222 | } |
| 223 | |
| 224 | m_mosMsgParams.components[compID].component.bAssertEnabled = bEnable; |
| 225 | } |
| 226 | |
| 227 | void MosUtilDebug::MosMessageInitComponent(MOS_COMPONENT_ID compID, MediaUserSettingSharedPtr userSettingPtr) |
| 228 | { |
| 229 | uint32_t uiCompUserFeatureSetting = 0; |
| 230 | uint64_t uiSubCompUserFeatureSetting = 0; |
| 231 | uint8_t i = 0; |
| 232 | const char *messageKey = nullptr; |
| 233 | const char *bySubComponentsKey = nullptr; |
| 234 | const char *subComponentsKey = nullptr; |
| 235 | MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 236 | uint32_t compLevel = 0; |
| 237 | |
| 238 | if (compID >= MOS_COMPONENT_COUNT ) |
| 239 | { |
| 240 | MOS_OS_ASSERTMESSAGE("Invalid component %d.", compID); |
| 241 | return; |
| 242 | } |
| 243 | |
| 244 | messageKey = m_pcComponentUserFeatureKeys[compID][0]; |
| 245 | bySubComponentsKey = m_pcComponentUserFeatureKeys[compID][1]; |
| 246 | subComponentsKey = m_pcComponentUserFeatureKeys[compID][2]; |
| 247 | |
| 248 | eStatus = ReadUserSetting( |
| 249 | userSettingPtr, |
| 250 | uiCompUserFeatureSetting, |
| 251 | messageKey, |
| 252 | MediaUserSetting::Group::Device); |
| 253 | // If the user feature key was not found, create it with the default value. |
| 254 | if (eStatus != MOS_STATUS_SUCCESS) |
| 255 | { |
| 256 | ReportUserSetting( |
| 257 | userSettingPtr, |
| 258 | messageKey, |
| 259 | uiCompUserFeatureSetting, |
| 260 | MediaUserSetting::Group::Device); |
| 261 | } |
| 262 | |
| 263 | // Extract the 3-bit message level and 1-bit assert flag setting for this component. |
| 264 | // Extract the 4th bit message level to enable the WARNING message (take effect when log enabled) |
| 265 | compLevel = uiCompUserFeatureSetting & 0x7; |
| 266 | if (compLevel > 1) |
| 267 | { |
| 268 | compLevel = compLevel + 1; |
| 269 | } |
| 270 | else if ((uiCompUserFeatureSetting & 0x10) && (compLevel == 1)) |
| 271 | { |
| 272 | compLevel = 2; |
| 273 | } |
| 274 | MosSetCompMessageLevel(compID, (MOS_MESSAGE_LEVEL) compLevel); |
| 275 | MosCompAssertEnableDisable(compID, (uiCompUserFeatureSetting >> 3) & 0x1); |
| 276 | |
| 277 | // Check if sub-components should be set seperately. |
| 278 | eStatus = ReadUserSetting( |
| 279 | userSettingPtr, |
| 280 | m_mosMsgParams.components[compID].bBySubComponent, |
| 281 | bySubComponentsKey, |
| 282 | MediaUserSetting::Group::Device); |
| 283 | |
| 284 | // If the user feature key was not found, create it with default (0) value. |
| 285 | if (eStatus != MOS_STATUS_SUCCESS) |
| 286 | { |
| 287 | ReportUserSetting( |
| 288 | userSettingPtr, |
| 289 | bySubComponentsKey, |
| 290 | m_mosMsgParams.components[compID].bBySubComponent, |
| 291 | MediaUserSetting::Group::Device); |
| 292 | } |
| 293 | |
| 294 | // Set sub components: |
| 295 | if (m_mosMsgParams.components[compID].bBySubComponent) |
| 296 | { |
| 297 | // Check if sub-components should be set seperately. |
| 298 | eStatus = ReadUserSetting( |
| 299 | userSettingPtr, |
| 300 | uiSubCompUserFeatureSetting, |
| 301 | subComponentsKey, |
| 302 | MediaUserSetting::Group::Device); |
| 303 | |
| 304 | // If the user feature key was not found, create it with default (0) value. |
| 305 | if (eStatus != MOS_STATUS_SUCCESS) |
| 306 | { |
| 307 | ReportUserSetting( |
| 308 | userSettingPtr, |
| 309 | subComponentsKey, |
| 310 | uiSubCompUserFeatureSetting, |
| 311 | MediaUserSetting::Group::Device); |
| 312 | } |
| 313 | |
| 314 | for(i = 0; i < m_subComponentCount[compID]; i++) |
| 315 | { |
| 316 | // Extract the 3-bit message level and 1-bit assert flag setting for each sub-comp |
| 317 | // from the user feature key and populate to the MOS message params structure |
| 318 | // Extract the 4th bit message level to enable the WARNING message (take effect when log enabled) |
| 319 | compLevel = uiSubCompUserFeatureSetting & 0x7; |
| 320 | if (compLevel > 1) |
| 321 | { |
| 322 | compLevel = compLevel + 1; |
| 323 | } |
| 324 | else if ((uiSubCompUserFeatureSetting & 0x10) && (compLevel == 1)) |
| 325 | { |
| 326 | compLevel = 2; |
| 327 | } |
| 328 | MosSetSubCompMessageLevel(compID, i, (MOS_MESSAGE_LEVEL)compLevel); |
| 329 | MosSubCompAssertEnableDisable(compID, i, (uiSubCompUserFeatureSetting >> 3) & 0x1); |
| 330 | |
| 331 | uiSubCompUserFeatureSetting = (uiSubCompUserFeatureSetting >> 5); |
| 332 | } |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | MOS_STATUS MosUtilDebug::MosHLTInit(MediaUserSettingSharedPtr userSettingPtr) |
| 337 | { |
| 338 | uint32_t nPID = 0; |
| 339 | char hltFileName[MOS_MAX_HLT_FILENAME_LEN] = {0}; |
| 340 | char fileNamePrefix[MOS_MAX_HLT_FILENAME_LEN]; |
| 341 | int32_t bUseHybridLogTrace = false; |
| 342 | int32_t bEnableFlush = false; |
| 343 | int32_t bEnableMemoryFootPrint = false; |
| 344 | MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 345 | |
| 346 | if (m_mosMsgParams.uiCounter != 0 ) |
| 347 | { |
| 348 | MOS_OS_NORMALMESSAGE("HLT settings already set."); |
| 349 | return MOS_STATUS_UNKNOWN; |
| 350 | } |
| 351 | |
| 352 | |
| 353 | eStatus = ReadUserSetting( |
| 354 | userSettingPtr, |
| 355 | bEnableFlush, |
| 356 | __MOS_USER_FEATURE_KEY_FLUSH_LOG_FILE_BEFORE_SUBMISSION, |
| 357 | MediaUserSetting::Group::Device); |
| 358 | |
| 359 | |
| 360 | ReportUserSetting( |
| 361 | userSettingPtr, |
| 362 | __MOS_USER_FEATURE_KEY_FLUSH_LOG_FILE_BEFORE_SUBMISSION, |
| 363 | bEnableFlush, |
| 364 | MediaUserSetting::Group::Device); |
| 365 | |
| 366 | if (!bEnableFlush) |
| 367 | { |
| 368 | MOS_OS_NORMALMESSAGE("HLT flush is not enabled."); |
| 369 | } |
| 370 | |
| 371 | m_mosMsgParams.bUseHybridLogTrace = false; |
| 372 | m_mosMsgParams.pLogFile = nullptr; |
| 373 | m_mosMsgParams.pTraceFile = nullptr; |
| 374 | m_mosMsgParams.bEnableFlush = bEnableFlush; |
| 375 | |
| 376 | // disable memory foot print |
| 377 | eStatus = ReadUserSetting( |
| 378 | userSettingPtr, |
| 379 | bEnableMemoryFootPrint, |
| 380 | __MOS_USER_FEATURE_KEY_ENABLE_MEMORY_FOOT_PRINT, |
| 381 | MediaUserSetting::Group::Device); |
| 382 | |
| 383 | ReportUserSetting( |
| 384 | userSettingPtr, |
| 385 | __MOS_USER_FEATURE_KEY_ENABLE_MEMORY_FOOT_PRINT, |
| 386 | bEnableMemoryFootPrint, |
| 387 | MediaUserSetting::Group::Device); |
| 388 | |
| 389 | if (bEnableMemoryFootPrint) |
| 390 | { |
| 391 | MOS_OS_NORMALMESSAGE("Mos memory foot print is enabled."); |
| 392 | } |
| 393 | |
| 394 | m_mosMsgParams.bEnableMemoryFootPrint = bEnableMemoryFootPrint; |
| 395 | |
| 396 | // Check if HLT should be enabled. |
| 397 | eStatus = ReadUserSetting( |
| 398 | userSettingPtr, |
| 399 | bUseHybridLogTrace, |
| 400 | __MOS_USER_FEATURE_KEY_MESSAGE_HLT_ENABLED, |
| 401 | MediaUserSetting::Group::Device); |
| 402 | // If the user feature key was not found, create it with the default value. |
| 403 | if (eStatus != MOS_STATUS_SUCCESS) |
| 404 | { |
| 405 | ReportUserSetting( |
| 406 | userSettingPtr, |
| 407 | __MOS_USER_FEATURE_KEY_MESSAGE_HLT_ENABLED, |
| 408 | bUseHybridLogTrace, |
| 409 | MediaUserSetting::Group::Device); |
| 410 | } |
| 411 | |
| 412 | bUseHybridLogTrace = (MosUtilities::m_mosUltFlag && *MosUtilities::m_mosUltFlag) ? 1 : bUseHybridLogTrace; |
| 413 | |
| 414 | // Dumping memory mapped regions to trace file disabled for now |
| 415 | // Need to add new user feature key or derive from the above key. |
| 416 | m_mosMsgParams.bEnableMaps = 0; |
| 417 | |
| 418 | if (!bUseHybridLogTrace) |
| 419 | { |
| 420 | MOS_OS_NORMALMESSAGE("HLT not enabled."); |
| 421 | return MOS_STATUS_SUCCESS; //[SH]: Check this. |
| 422 | } |
| 423 | |
| 424 | nPID = (MosUtilities::m_mosUltFlag && *MosUtilities::m_mosUltFlag) ? 0 : MosUtilities::MosGetPid(); |
| 425 | |
| 426 | // Get logfile directory. |
| 427 | MosLogFileNamePrefix(fileNamePrefix, userSettingPtr); |
| 428 | MosUtilities::MosSecureStringPrint(hltFileName, MOS_MAX_HLT_FILENAME_LEN, MOS_MAX_HLT_FILENAME_LEN - 1, MOS_LOG_PATH_TEMPLATE, fileNamePrefix, nPID, MosUtilities::MosGetCurrentThreadId(), "log"); |
| 429 | |
| 430 | #if defined(LINUX) || defined(ANDROID) |
| 431 | eStatus = MosUtilities::MosCreateDirectory(fileNamePrefix); |
| 432 | if (MOS_FAILED(eStatus)) |
| 433 | { |
| 434 | MOS_OS_NORMALMESSAGE("Failed to create output directory. Status = %d", eStatus); |
| 435 | } |
| 436 | #endif |
| 437 | |
| 438 | eStatus = MosUtilities::MosSecureFileOpen(&m_mosMsgParams.pLogFile, hltFileName, "w"); |
| 439 | |
| 440 | if (MOS_FAILED(eStatus)) |
| 441 | { |
| 442 | MOS_OS_NORMALMESSAGE("Failed to open log file '%s'.", hltFileName); |
| 443 | m_mosMsgParams.pLogFile = nullptr; |
| 444 | } |
| 445 | |
| 446 | if(m_mosMsgParams.pLogFile == nullptr) |
| 447 | { |
| 448 | return MOS_STATUS_HLT_INIT_FAILED; |
| 449 | } |
| 450 | |
| 451 | // Only if logfile init succeeded, bUseHybridLogTrace is set. |
| 452 | m_mosMsgParams.bUseHybridLogTrace = true; |
| 453 | |
| 454 | // Output preface information |
| 455 | MosHltpPreface(m_mosMsgParams.pLogFile); |
| 456 | MOS_OS_NORMALMESSAGE("HLT initialized successfuly (%s).", hltFileName); |
| 457 | |
| 458 | //[SH]: Trace and log are enabled with the same key right now. This can be changed to enable/disable them independently. |
| 459 | MosUtilities::MosSecureStringPrint(hltFileName, MOS_MAX_HLT_FILENAME_LEN, MOS_MAX_HLT_FILENAME_LEN - 1, MOS_LOG_PATH_TEMPLATE, fileNamePrefix, nPID, MosUtilities::MosGetCurrentThreadId(), "hlt"); |
| 460 | |
| 461 | eStatus = MosUtilities::MosSecureFileOpen(&m_mosMsgParams.pTraceFile, hltFileName, "w"); |
| 462 | |
| 463 | if (MOS_FAILED(eStatus)) |
| 464 | { |
| 465 | MOS_OS_NORMALMESSAGE("Failed to open trace file '%s'.", hltFileName); |
| 466 | } |
| 467 | |
| 468 | return MOS_STATUS_SUCCESS; |
| 469 | } |
| 470 | |
| 471 | void MosUtilDebug::MosMessageInit(MediaUserSettingSharedPtr userSettingPtr) |
| 472 | { |
| 473 | uint8_t i = 0; |
| 474 | MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 475 | |
| 476 | if(m_mosMsgParams.uiCounter == 0) // first time only |
| 477 | { |
| 478 | eStatus = ReadUserSetting( |
| 479 | userSettingPtr, |
| 480 | m_mosMsgParams.bDisableAssert, |
| 481 | __MOS_USER_FEATURE_KEY_DISABLE_ASSERT, |
| 482 | MediaUserSetting::Group::Device); |
| 483 | // If the user feature key was not found, create it with default value. |
| 484 | if (eStatus != MOS_STATUS_SUCCESS) |
| 485 | { |
| 486 | ReportUserSetting( |
| 487 | userSettingPtr, |
| 488 | __MOS_USER_FEATURE_KEY_DISABLE_ASSERT, |
| 489 | m_mosMsgParams.bDisableAssert, |
| 490 | MediaUserSetting::Group::Device); |
| 491 | } |
| 492 | |
| 493 | // Set all sub component messages to critical level by default. |
| 494 | MosSetCompMessageLevelAll(MOS_MESSAGE_LVL_CRITICAL); |
| 495 | |
| 496 | // Set print level and asserts for each component |
| 497 | for(i = 0; i < MOS_COMPONENT_COUNT; i++) |
| 498 | { |
| 499 | MosMessageInitComponent((MOS_COMPONENT_ID)i, userSettingPtr); |
| 500 | } |
| 501 | |
| 502 | // Check if MOS messages are enabled |
| 503 | eStatus = ReadUserSetting( |
| 504 | userSettingPtr, |
| 505 | m_mosMsgParams.bUseOutputDebugString, |
| 506 | __MOS_USER_FEATURE_KEY_MESSAGE_PRINT_ENABLED, |
| 507 | MediaUserSetting::Group::Device); |
| 508 | |
| 509 | // If the user feature key was not found, create it with default value. |
| 510 | if (eStatus != MOS_STATUS_SUCCESS) |
| 511 | { |
| 512 | eStatus = ReportUserSetting( |
| 513 | userSettingPtr, |
| 514 | __MOS_USER_FEATURE_KEY_MESSAGE_PRINT_ENABLED, |
| 515 | m_mosMsgParams.bUseOutputDebugString, |
| 516 | MediaUserSetting::Group::Device); |
| 517 | } |
| 518 | |
| 519 | if (MosUtilities::m_mosUltFlag && (*MosUtilities::m_mosUltFlag)) |
| 520 | { |
| 521 | // set all msg level |
| 522 | MosSetCompMessageLevelAll(MOS_MESSAGE_LVL_CRITICAL); |
| 523 | m_mosMsgParams.bUseOutputDebugString = 1; |
| 524 | m_mosMsgParams.components[MOS_COMPONENT_OS].bBySubComponent = 0; |
| 525 | MosCompAssertEnableDisable(MOS_COMPONENT_CM, 0); |
| 526 | MosCompAssertEnableDisable(MOS_COMPONENT_VP, 1); |
| 527 | } |
| 528 | |
| 529 | MosHLTInit(userSettingPtr); |
| 530 | |
| 531 | // all above action should not be covered by memninja since its destroy is behind memninja counter report to test result. |
| 532 | if (MosUtilities::m_mosMemAllocCounter && |
| 533 | MosUtilities::m_mosMemAllocCounterGfx && |
| 534 | MosUtilities::m_mosMemAllocFakeCounter) |
| 535 | { |
| 536 | *MosUtilities::m_mosMemAllocCounter = 0; |
| 537 | *MosUtilities::m_mosMemAllocFakeCounter = 0; |
| 538 | *MosUtilities::m_mosMemAllocCounterGfx = 0; |
| 539 | } |
| 540 | else |
| 541 | { |
| 542 | MOS_OS_ASSERTMESSAGE("MemNinja count pointers are nullptr"); |
| 543 | } |
| 544 | |
| 545 | MOS_OS_VERBOSEMESSAGE("MemNinja leak detection begin"); |
| 546 | } |
| 547 | |
| 548 | // uiCounter's thread safety depends on global_lock in VPG_Initialize |
| 549 | m_mosMsgParams.uiCounter++; // Will be zero initially since it is part of a global structure. |
| 550 | |
| 551 | } |
| 552 | |
| 553 | void MosUtilDebug::MosHLTClose() |
| 554 | { |
| 555 | if(m_mosMsgParams.pTraceFile != nullptr) |
| 556 | { |
| 557 | fclose(m_mosMsgParams.pTraceFile); |
| 558 | m_mosMsgParams.pTraceFile = nullptr; |
| 559 | |
| 560 | MOS_OS_NORMALMESSAGE("Trace file is closed."); |
| 561 | } |
| 562 | |
| 563 | if(m_mosMsgParams.pLogFile != nullptr) |
| 564 | { |
| 565 | MOS_OS_NORMALMESSAGE("Log file is closing, total services %d.", |
| 566 | m_mosMsgParams.uiCounter); |
| 567 | |
| 568 | fclose(m_mosMsgParams.pLogFile); |
| 569 | m_mosMsgParams.pLogFile = nullptr; |
| 570 | } |
| 571 | } |
| 572 | |
| 573 | void MosUtilDebug::MosMessageClose() |
| 574 | { |
| 575 | // uiCounter's thread safety depends on global_lock in VPG_Terminate |
| 576 | if(m_mosMsgParams.uiCounter == 1) |
| 577 | { |
| 578 | MosHLTClose(); |
| 579 | MosUtilities::MosZeroMemory(&m_mosMsgParams, sizeof(MOS_MESSAGE_PARAMS)); |
| 580 | } |
| 581 | else |
| 582 | { |
| 583 | m_mosMsgParams.uiCounter--; |
| 584 | } |
| 585 | } |
| 586 | |
| 587 | void MosUtilDebug::MosHLTFlush() |
| 588 | { |
| 589 | if (!m_mosMsgParams.bEnableFlush) |
| 590 | { |
| 591 | return; |
| 592 | } |
| 593 | |
| 594 | MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 595 | if (m_mosMsgParams.pLogFile != nullptr) |
| 596 | { |
| 597 | #if COMMON_DLL_SEPARATION_SUPPORT |
| 598 | // Every DLL has its own C Runtime (CRT), |
| 599 | // and fflush is not safe across dlls. |
| 600 | // When common dll separation is enabled, We should call back into common dll for all DDI dlls. |
| 601 | MosUtilities::MosFlushToFileInCommon(m_mosMsgParams.pLogFile); |
| 602 | #else |
| 603 | fflush(m_mosMsgParams.pLogFile); |
| 604 | #endif |
| 605 | } |
| 606 | if (m_mosMsgParams.pTraceFile != nullptr) |
| 607 | { |
| 608 | #if COMMON_DLL_SEPARATION_SUPPORT |
| 609 | // Every DLL has its own C Runtime (CRT), |
| 610 | // and fflush is not safe across dlls. |
| 611 | // When common dll separation is enabled, We should call back into common dll for all DDI dlls. |
| 612 | MosUtilities::MosFlushToFileInCommon(m_mosMsgParams.pTraceFile); |
| 613 | #else |
| 614 | fflush(m_mosMsgParams.pTraceFile); |
| 615 | #endif |
| 616 | } |
| 617 | } |
| 618 | |
| 619 | bool MosUtilDebug::EnableMemoryFootPrint() |
| 620 | { |
| 621 | return m_mosMsgParams.bEnableMemoryFootPrint; |
| 622 | } |
| 623 | |
| 624 | void MosUtilDebug::MosMessage( |
| 625 | MOS_MESSAGE_LEVEL level, |
| 626 | MOS_COMPONENT_ID compID, |
| 627 | uint8_t subCompID, |
| 628 | const PCCHAR functionName, |
| 629 | int32_t lineNum, |
| 630 | const PCCHAR message, |
| 631 | ...) |
| 632 | { |
| 633 | va_list var_args; |
| 634 | va_start(var_args, message); |
| 635 | MosMessageInternal(level, compID, subCompID, functionName, lineNum, message, var_args); |
| 636 | va_end(var_args); |
| 637 | return; |
| 638 | } |
| 639 | |
| 640 | int32_t MosUtilDebug::MosShouldPrintMessage( |
| 641 | MOS_MESSAGE_LEVEL level, |
| 642 | MOS_COMPONENT_ID compID, |
| 643 | uint8_t subCompID, |
| 644 | const char * const message) |
| 645 | { |
| 646 | if (message == nullptr) |
| 647 | { |
| 648 | return false; |
| 649 | } |
| 650 | |
| 651 | if (compID >= MOS_COMPONENT_COUNT || |
| 652 | subCompID >= MOS_MAX_SUBCOMPONENT_COUNT || |
| 653 | level >= MOS_MESSAGE_LVL_COUNT) |
| 654 | { |
| 655 | MOS_OS_ASSERTMESSAGE("Invalid compoent ID %d, subCompID %d, and msg level %d.", compID, subCompID, level); |
| 656 | return false; |
| 657 | } |
| 658 | |
| 659 | // If trace is enabled, return true, otherwise continue checking if log is enabled |
| 660 | if (MosUtilities::MosShouldTraceEventMsg(level, compID)) |
| 661 | { |
| 662 | return true; |
| 663 | } |
| 664 | |
| 665 | // Check if message level set for comp (and if needed for subcomp) is equal or greater than requested level |
| 666 | if (m_mosMsgParams.components[compID].component.uiMessageLevel < level) |
| 667 | { |
| 668 | return false; |
| 669 | } |
| 670 | |
| 671 | if (m_mosMsgParams.components[compID].bBySubComponent && |
| 672 | m_mosMsgParams.components[compID].subComponents[subCompID].uiMessageLevel < level) |
| 673 | { |
| 674 | return false; |
| 675 | } |
| 676 | |
| 677 | return true; |
| 678 | |
| 679 | } |
| 680 | |
| 681 | #if MOS_ASSERT_ENABLED |
| 682 | |
| 683 | int32_t MosUtilDebug::MosShouldAssert(MOS_COMPONENT_ID compID, uint8_t subCompID) |
| 684 | { |
| 685 | if (m_mosMsgParams.bDisableAssert) |
| 686 | { |
| 687 | return false; |
| 688 | } |
| 689 | |
| 690 | if (compID >= MOS_COMPONENT_COUNT || |
| 691 | subCompID >= MOS_MAX_SUBCOMPONENT_COUNT) |
| 692 | { |
| 693 | MOS_OS_ASSERTMESSAGE("Invalid compoent ID %d, subCompID %d", compID, subCompID); |
| 694 | return false; |
| 695 | } |
| 696 | |
| 697 | if (!m_mosMsgParams.components[compID].component.bAssertEnabled) |
| 698 | { |
| 699 | return false; |
| 700 | } |
| 701 | |
| 702 | if (m_mosMsgParams.components[compID].bBySubComponent && |
| 703 | !m_mosMsgParams.components[compID].subComponents[subCompID].bAssertEnabled) |
| 704 | { |
| 705 | return false; |
| 706 | } |
| 707 | |
| 708 | return true; |
| 709 | |
| 710 | } |
| 711 | #endif // MOS_ASSERT_ENABLED |
| 712 | |
| 713 | #endif // MOS_MESSAGES_ENABLED |