已合并
[Profiling]规避David芯片偶现的hwts频率抖动问题 #626
zhengkai创建于 3月3日
[Profiling]规避David芯片偶现的hwts频率抖动问题 #626
已合并
共 4 个文件变更+73-1
| @@ -21,6 +21,8 @@ namespace dvvp { | |||
| 21 | namespace host { | 21 | namespace host { |
| 22 | const char *const PLATFORM_CLOUD = "cloud"; | 22 | const char *const PLATFORM_CLOUD = "cloud"; |
| 23 | const char INFO_FILE_NAME[] = "info.json"; | 23 | const char INFO_FILE_NAME[] = "info.json"; |
| 24 | +const double DAVID_BASE_HWTS_FREQ = 1000.0; | ||
| 25 | +const double ERROR_THRESHOLD = DAVID_BASE_HWTS_FREQ * 0.0005; // 万分之5 = 0.0005,对应绝对值0.5 | ||
| 24 | 26 | ||
| 25 | #define CPU_ID_STR(id_str, begin, num) \ | 27 | #define CPU_ID_STR(id_str, begin, num) \ |
| 26 | do { \ | 28 | do { \ |
| @@ -127,6 +129,7 @@ private: | |||
| 127 | std::string GetHostOscFrequency() const; | 129 | std::string GetHostOscFrequency() const; |
| 128 | std::string GetDeviceOscFrequency(uint32_t deviceId, const std::string &freq) const; | 130 | std::string GetDeviceOscFrequency(uint32_t deviceId, const std::string &freq) const; |
| 129 | std::string EncodeInfoMainJson(SHARED_PTR_ALIA<InfoMain> infoMain) const; | 131 | std::string EncodeInfoMainJson(SHARED_PTR_ALIA<InfoMain> infoMain) const; |
| 132 | + std::string GetHwtsFreq(std::string freq) const; | ||
| 130 | void SetDrvVersion(SHARED_PTR_ALIA<InfoMain> infoMain) const; | 133 | void SetDrvVersion(SHARED_PTR_ALIA<InfoMain> infoMain) const; |
| 131 | 134 | ||
| 132 | private: | 135 | private: |
| @@ -10,6 +10,7 @@ | |||
| 10 | #include "info_json.h" | 10 | #include "info_json.h" |
| 11 | #include <cstdio> | 11 | #include <cstdio> |
| 12 | #include <fstream> | 12 | #include <fstream> |
| 13 | +#include <cmath> | ||
| 13 | #if (defined(linux) || defined(__linux__)) | 14 | #if (defined(linux) || defined(__linux__)) |
| 14 | #include <unistd.h> | 15 | #include <unistd.h> |
| 15 | #endif | 16 | #endif |
| @@ -76,7 +77,7 @@ std::string InfoJson::EncodeInfoMainJson(SHARED_PTR_ALIA<InfoMain> infoMain) con | |||
| 76 | infoMainJson["DeviceInfo"][i]["ctrl_cpu_id"] = infoMain->deviceInfos[i].ctrlCpuId; | 77 | infoMainJson["DeviceInfo"][i]["ctrl_cpu_id"] = infoMain->deviceInfos[i].ctrlCpuId; |
| 77 | infoMainJson["DeviceInfo"][i]["ctrl_cpu"] = infoMain->deviceInfos[i].ctrlCpu; | 78 | infoMainJson["DeviceInfo"][i]["ctrl_cpu"] = infoMain->deviceInfos[i].ctrlCpu; |
| 78 | infoMainJson["DeviceInfo"][i]["ai_cpu"] = infoMain->deviceInfos[i].aiCpu; | 79 | infoMainJson["DeviceInfo"][i]["ai_cpu"] = infoMain->deviceInfos[i].aiCpu; |
| 79 | - infoMainJson["DeviceInfo"][i]["hwts_frequency"] = infoMain->deviceInfos[i].hwtsFrequency; | 80 | + infoMainJson["DeviceInfo"][i]["hwts_frequency"] = GetHwtsFreq(infoMain->deviceInfos[i].hwtsFrequency); |
| 80 | infoMainJson["DeviceInfo"][i]["aic_frequency"] = infoMain->deviceInfos[i].aicFrequency; | 81 | infoMainJson["DeviceInfo"][i]["aic_frequency"] = infoMain->deviceInfos[i].aicFrequency; |
| 81 | infoMainJson["DeviceInfo"][i]["aiv_frequency"] = infoMain->deviceInfos[i].aivFrequency; | 82 | infoMainJson["DeviceInfo"][i]["aiv_frequency"] = infoMain->deviceInfos[i].aivFrequency; |
| 82 | } | 83 | } |
| @@ -115,6 +116,20 @@ std::string InfoJson::EncodeInfoMainJson(SHARED_PTR_ALIA<InfoMain> infoMain) con | |||
| 115 | return infoMainJson.ToString(); | 116 | return infoMainJson.ToString(); |
| 116 | } | 117 | } |
| 117 | 118 | ||
| 119 | +std::string InfoJson::GetHwtsFreq(std::string freq) const | ||
| 120 | +{ | ||
| 121 | + double errorFrqValue = std::fabs(std::stod(freq) - DAVID_BASE_HWTS_FREQ); | ||
| 122 | + std::string hwtsFrequency; | ||
| 123 | + if (ConfigManager::instance()->GetPlatformType() == PlatformType::CHIP_CLOUD_V3 && | ||
| 124 | + errorFrqValue > ERROR_THRESHOLD) { | ||
| 125 | + MSPROF_LOGW("The original hwtsFrequency is %s", freq.c_str()); | ||
| 126 | + hwtsFrequency = std::to_string(static_cast<int>(DAVID_BASE_HWTS_FREQ)); | ||
| 127 | + } else { | ||
| 128 | + hwtsFrequency = freq; | ||
| 129 | + } | ||
| 130 | + return hwtsFrequency; | ||
| 131 | +} | ||
| 132 | + | ||
| 118 | int32_t InfoJson::Generate(std::string &content) | 133 | int32_t InfoJson::Generate(std::string &content) |
| 119 | { | 134 | { |
| 120 | MSPROF_LOGI("Begin to generate info.json, devices: %s.", devices_.c_str()); | 135 | MSPROF_LOGI("Begin to generate info.json, devices: %s.", devices_.c_str()); |
| @@ -152,6 +152,7 @@ set(profilerSrcFile | |||
| 152 | test/platform_utest.cpp | 152 | test/platform_utest.cpp |
| 153 | test/msprof_dynamic_utest.cpp | 153 | test/msprof_dynamic_utest.cpp |
| 154 | test/msprofiler_adapter_utest.cpp | 154 | test/msprofiler_adapter_utest.cpp |
| 155 | + test/info_json_utest.cpp | ||
| 155 | ../stub/drv_stub.cpp | 156 | ../stub/drv_stub.cpp |
| 156 | ../stub/mmpa_stub.cpp | 157 | ../stub/mmpa_stub.cpp |
| 157 | ../stub/prof_api_stub.cpp | 158 | ../stub/prof_api_stub.cpp |
| @@ -0,0 +1,53 @@ | |||
| 1 | +/** | ||
| 2 | + * Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | + * This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | + * CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | + * Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | + * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | + * See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | + */ | ||
| 10 | +#include "gtest/gtest.h" | ||
| 11 | +#include "mockcpp/mockcpp.hpp" | ||
| 12 | +#include "info_json.h" | ||
| 13 | +#include <cstdio> | ||
| 14 | +#include <fstream> | ||
| 15 | +#include "ai_drv_dev_api.h" | ||
| 16 | +#include "config/config.h" | ||
| 17 | +#include "config_manager.h" | ||
| 18 | +#include "errno/error_code.h" | ||
| 19 | +#include "msprof_dlog.h" | ||
| 20 | +#include "prof_manager.h" | ||
| 21 | +#include "securec.h" | ||
| 22 | +#include "utils/utils.h" | ||
| 23 | +#include "platform/platform.h" | ||
| 24 | +#include "task_relationship_mgr.h" | ||
| 25 | +#include "json/json.h" | ||
| 26 | + | ||
| 27 | +using namespace analysis::dvvp::common::error; | ||
| 28 | +using namespace analysis::dvvp::common::utils; | ||
| 29 | +using namespace analysis::dvvp::common::config; | ||
| 30 | +using namespace Analysis::Dvvp::Common::Platform; | ||
| 31 | +using namespace Analysis::Dvvp::Common::Config; | ||
| 32 | +using namespace analysis::dvvp::host; | ||
| 33 | +using namespace Dvvp::Collect::Platform; | ||
| 34 | + | ||
| 35 | +class INFO_JSON_TEST: public testing::Test { | ||
| 36 | +protected: | ||
| 37 | + virtual void SetUp() { | ||
| 38 | + } | ||
| 39 | + virtual void TearDown() { | ||
| 40 | + } | ||
| 41 | +}; | ||
| 42 | + | ||
| 43 | +TEST(INFO_JSON_TEST, GetHwtsFreq) { | ||
| 44 | + GlobalMockObject::verify(); | ||
| 45 | + MOCKER_CPP(&Analysis::Dvvp::Common::Config::ConfigManager::GetPlatformType) | ||
| 46 | + .stubs() | ||
| 47 | + .will(returnValue(PlatformType::CHIP_CLOUD_V3)); | ||
| 48 | + InfoJson infoJson("1", "0", 1); | ||
| 49 | + std::string freq = "1005"; | ||
| 50 | + EXPECT_EQ("1000", infoJson.GetHwtsFreq(freq)); | ||
| 51 | + freq = "1000.1"; | ||
| 52 | + EXPECT_EQ("1000.1", infoJson.GetHwtsFreq(freq)); | ||
| 53 | +} | ||