已合并
[Profiling]【fix】:兼容驱动不同分支、不同形态修改aicpu通道采集频率 #3944
zhengkai创建于 7月30日
[Profiling]【fix】:兼容驱动不同分支、不同形态修改aicpu通道采集频率 #3944
已合并
共 5 个文件变更+36-7
| @@ -24,8 +24,11 @@ using namespace analysis::dvvp::common::utils; | |||
| 24 | using namespace analysis::dvvp::common::config; | 24 | using namespace analysis::dvvp::common::config; |
| 25 | 25 | ||
| 26 | const std::string ASCEND_HAL_LIB = "libascend_hal.so"; | 26 | const std::string ASCEND_HAL_LIB = "libascend_hal.so"; |
| 27 | -constexpr uint32_t SUPPORT_OSC_FREQ_API_VERSION = 0x071905; | 27 | + |
| 28 | -constexpr uint32_t SUPPORT_ADPROF_VERSION = 0x72316; | 28 | +bool IsDrvApiVersionSupport(DrvFunctionVersion version) |
| 29 | +{ | ||
| 30 | + return Platform::instance()->DrvGetApiVersion() >= static_cast<uint32_t>(version); | ||
| 31 | +} | ||
| 29 | 32 | ||
| 30 | template <class T> | 33 | template <class T> |
| 31 | inline T LoadDlsymApi(VOID_PTR hanle, const std::string &name) | 34 | inline T LoadDlsymApi(VOID_PTR hanle, const std::string &name) |
| @@ -55,7 +58,7 @@ int32_t Platform::Init() | |||
| 55 | if (ascendHalAdaptor_.Init() != PROFILING_SUCCESS) { | 58 | if (ascendHalAdaptor_.Init() != PROFILING_SUCCESS) { |
| 56 | return PROFILING_FAILED; | 59 | return PROFILING_FAILED; |
| 57 | } | 60 | } |
| 58 | - if (DrvGetApiVersion() >= SUPPORT_OSC_FREQ_API_VERSION) { | 61 | + if (IsDrvApiVersionSupport(OSC_FREQ_API_VERSION)) { |
| 59 | 62 | ||
| 60 | enableHostOscFreq_ = analysis::dvvp::driver::DrvGetHostFreq(hostOscFreq_); | 63 | enableHostOscFreq_ = analysis::dvvp::driver::DrvGetHostFreq(hostOscFreq_); |
| 61 | 64 | ||
| @@ -174,7 +177,7 @@ std::string Platform::PlatformGetDeviceOscFreq(uint32_t deviceId, const std::str | |||
| 174 | { | 177 | { |
| 175 | std::string deviceOscFreq; | 178 | std::string deviceOscFreq; |
| 176 | bool enableDeviceOscFreq = false; | 179 | bool enableDeviceOscFreq = false; |
| 177 | - if (DrvGetApiVersion() >= SUPPORT_OSC_FREQ_API_VERSION) { | 180 | + if (IsDrvApiVersionSupport(OSC_FREQ_API_VERSION)) { |
| 178 | enableDeviceOscFreq = analysis::dvvp::driver::DrvGetDeviceFreq(deviceId, deviceOscFreq); | 181 | enableDeviceOscFreq = analysis::dvvp::driver::DrvGetDeviceFreq(deviceId, deviceOscFreq); |
| 179 | } | 182 | } |
| 180 | 183 | ||
| @@ -528,7 +531,7 @@ bool Platform::CheckIfSupportAdprof(uint32_t deviceId) const | |||
| 528 | return false; | 531 | return false; |
| 529 | } | 532 | } |
| 530 | 533 | ||
| 531 | - if (DrvGetApiVersion() < SUPPORT_ADPROF_VERSION | 534 | + if (!IsDrvApiVersionSupport(ADPROF_API_VERSION) |
| 532 | 535 | ||
| 533 | || GetPlatformType() == CHIP_MINI | 536 | || GetPlatformType() == CHIP_MINI |
| 534 | 537 | ||
| @@ -57,6 +57,24 @@ private: | |||
| 57 | HalEschedCreateGrpExFunc halEschedCreateGrpEx_{nullptr}; | 57 | HalEschedCreateGrpExFunc halEschedCreateGrpEx_{nullptr}; |
| 58 | }; | 58 | }; |
| 59 | 59 | ||
| 60 | +// Driver hal API version (__HAL_API_VER_*) in which each feature became available. The value is the | ||
| 61 | +// minimum version that supports the feature, so IsDrvApiVersionSupport() is a single ">=" compare. | ||
| 62 | +// To gate a new feature on the driver version, add one enumerator here with the version it landed in | ||
| 63 | +// -- no new query function is needed. | ||
| 64 | +enum DrvFunctionVersion : uint32_t { | ||
| 65 | + // Host/device oscillator frequency query (DrvGetHostFreq / DrvGetDeviceFreq). | ||
| 66 | + OSC_FREQ_API_VERSION = 0x071905, | ||
| 67 | + // adprof driver channel. | ||
| 68 | + ADPROF_API_VERSION = 0x072316, | ||
| 69 | + // aicpu channel. | ||
| 70 | + DAVID_AICPU_SAMPLE_PERIOD = 0x072419 | ||
| 71 | +}; | ||
| 72 | + | ||
| 73 | +// Whether the running driver supports the given feature. Not cached: DrvGetApiVersion() returns 0 | ||
| 74 | +// while libascend_hal.so is not loaded yet (general-server scenario, or any call before | ||
| 75 | +// Platform::Init()), and caching that 0 would disable every feature for the rest of the process. | ||
| 76 | +bool IsDrvApiVersionSupport(DrvFunctionVersion version); | ||
| 77 | + | ||
| 60 | constexpr uint16_t QOS_STREAM_NAME_MAX_LENGTH = 256; | 78 | constexpr uint16_t QOS_STREAM_NAME_MAX_LENGTH = 256; |
| 61 | struct QosProfileInfo { | 79 | struct QosProfileInfo { |
| 62 | uint32_t devId; // hal接口需要的字段 | 80 | uint32_t devId; // hal接口需要的字段 |
| @@ -16,11 +16,13 @@ | |||
| 16 | 16 | ||
| 17 | 17 | ||
| 18 | 18 | ||
| 19 | + | ||
| 19 | namespace analysis { | 20 | namespace analysis { |
| 20 | namespace dvvp { | 21 | namespace dvvp { |
| 21 | namespace driver { | 22 | namespace driver { |
| 22 | using namespace analysis::dvvp::common::error; | 23 | using namespace analysis::dvvp::common::error; |
| 23 | using namespace Msprofiler::Parser; | 24 | using namespace Msprofiler::Parser; |
| 25 | +using namespace Analysis::Dvvp::Common::Platform; | ||
| 24 | // 32 * 1024 * 0.8 is the full threshold of ai_core_sample | 26 | // 32 * 1024 * 0.8 is the full threshold of ai_core_sample |
| 25 | constexpr uint32_t AI_CORE_SAMPLE_FULL_THRESHOLD = static_cast<uint32_t>(32 * 1024 * 0.8); | 27 | constexpr uint32_t AI_CORE_SAMPLE_FULL_THRESHOLD = static_cast<uint32_t>(32 * 1024 * 0.8); |
| 26 | constexpr int32_t DRV_NOT_ENOUGH_SUB_CHANNEL_RESOURCE = -10; // PROF_NOT_ENOUGH_SUB_CHANNEL_RESOURCE | 28 | constexpr int32_t DRV_NOT_ENOUGH_SUB_CHANNEL_RESOURCE = -10; // PROF_NOT_ENOUGH_SUB_CHANNEL_RESOURCE |
| @@ -318,7 +320,11 @@ int32_t DrvAicoreTaskBasedStart(int32_t profDeviceId, AI_DRV_CHANNEL profChannel | |||
| 318 | 320 | ||
| 319 | int32_t DrvAicpuStart(uint32_t profDeviceId, AI_DRV_CHANNEL profChannel) | 321 | int32_t DrvAicpuStart(uint32_t profDeviceId, AI_DRV_CHANNEL profChannel) |
| 320 | { | 322 | { |
| 321 | - constexpr uint32_t aicpuDrvSamplePeriod = 7U; | 323 | + uint32_t aicpuDrvSamplePeriod = 10U; |
| 324 | + if (IsDrvApiVersionSupport(DAVID_AICPU_SAMPLE_PERIOD) && | ||
| 325 | + Platform::instance()->CheckIfSupport(PLATFORM_AICPU_SAMPLE_PERIOD)) { | ||
| 326 | + aicpuDrvSamplePeriod = 5U; | ||
| 327 | + } | ||
| 322 | struct prof_start_para profStartPara = { .channel_type = PROF_PERIPHERAL_TYPE, | 328 | struct prof_start_para profStartPara = { .channel_type = PROF_PERIPHERAL_TYPE, |
| 323 | .sample_period = aicpuDrvSamplePeriod, | 329 | .sample_period = aicpuDrvSamplePeriod, |
| 324 | .real_time = PROFILE_REAL_TIME, | 330 | .real_time = PROFILE_REAL_TIME, |
| @@ -64,7 +64,8 @@ DavidPlatform::DavidPlatform() | |||
| 64 | PLATFORM_AICSCALE_ACP, | 64 | PLATFORM_AICSCALE_ACP, |
| 65 | PLATFORM_STARS_QOS, | 65 | PLATFORM_STARS_QOS, |
| 66 | PLATFORM_ACLAPI_SETDEVICE_ENABLE, | 66 | PLATFORM_ACLAPI_SETDEVICE_ENABLE, |
| 67 | - PLATFORM_API_STATS | 67 | + PLATFORM_API_STATS, |
| 68 | + PLATFORM_AICPU_SAMPLE_PERIOD | ||
| 68 | }; | 69 | }; |
| 69 | InsertPmuFeature(); | 70 | InsertPmuFeature(); |
| 70 | InsertSysFeature(); | 71 | InsertSysFeature(); |
| @@ -157,6 +157,7 @@ enum PlatformFeature { | |||
| 157 | PLATFORM_ACLAPI_SETDEVICE_ENABLE, | 157 | PLATFORM_ACLAPI_SETDEVICE_ENABLE, |
| 158 | PLATFORM_TASK_NTS, | 158 | PLATFORM_TASK_NTS, |
| 159 | PLATFORM_API_STATS, | 159 | PLATFORM_API_STATS, |
| 160 | + PLATFORM_AICPU_SAMPLE_PERIOD, | ||
| 160 | // MAX | 161 | // MAX |
| 161 | PLATFORM_COLLECTOR_TYPES_MAX | 162 | PLATFORM_COLLECTOR_TYPES_MAX |
| 162 | }; | 163 | }; |
🔴 Critical
DrvAicpuStart函数(第 322-328 行)将constexpr uint32_t aicpuDrvSamplePeriod声明在if和else代码块内部。在 C++ 中,块内声明的变量其作用域仅限于该块,离开块后即不可见。第 330 行在 if/else 块之外使用aicpuDrvSamplePeriod会导致编译错误:use of undeclared identifier 'aicpuDrvSamplePeriod'。证据链:
影响:代码无法通过编译,属于 P0 构建失败级别的问题。
建议:将变量声明移到 if/else 块外部,在块内赋值(不能使用 constexpr,改用 const 或普通变量),或使用三元表达式一步完成。
.real_time =PROFILE_REAL_TIME,