已合并
【fix】: 防止重复AdxDataDumpServerInit初始化 #4620
lidaoming1创建于 7 天前
【fix】: 防止重复AdxDataDumpServerInit初始化 #4620
已合并
共 5 个文件变更+87-17
| @@ -133,6 +133,7 @@ void SetSessionDeviceId() { | |||
| 133 | 133 | ||
| 134 | static std::mutex mutex_; // BuildGraph and RunGraph use | 134 | static std::mutex mutex_; // BuildGraph and RunGraph use |
| 135 | bool InnerSession::is_dump_server_inited_ = false; | 135 | bool InnerSession::is_dump_server_inited_ = false; |
| 136 | +std::mutex InnerSession::dump_server_mutex_; | ||
| 136 | InnerSession::InnerSession(uint64_t session_id, const std::map<std::string, std::string> &options) | 137 | InnerSession::InnerSession(uint64_t session_id, const std::map<std::string, std::string> &options) |
| 137 | : is_initialized_(false), session_id_(session_id), options_(options) {} | 138 | : is_initialized_(false), session_id_(session_id), options_(options) {} |
| 138 | 139 | ||
| @@ -698,13 +699,16 @@ Status InnerSession::SaveVariables(const Graph &graph, const std::vector<std::st | |||
| 698 | } | 699 | } |
| 699 | 700 | ||
| 700 | Status InnerSession::AddDumpProperties(const DumpProperties &dump_properties) { | 701 | Status InnerSession::AddDumpProperties(const DumpProperties &dump_properties) { |
| 701 | - if (!is_dump_server_inited_) { | 702 | + { |
| 702 | - if ((dump_properties.IsDumpOpen() || dump_properties.IsOpDebugOpen())) { | 703 | + std::lock_guard<std::mutex> lock(dump_server_mutex_); |
| 703 | - GE_IF_BOOL_EXEC(AdxDataDumpServerInit() != kDumpStatus, | 704 | + if (!is_dump_server_inited_) { |
| 704 | - GELOGE(PARAM_INVALID, "[Init][AdxDataDumpServer] failed, session_id:%" PRIu64 ".", session_id_); | 705 | + if ((dump_properties.IsDumpOpen() || dump_properties.IsOpDebugOpen())) { |
| 705 | - return PARAM_INVALID) | 706 | + GE_IF_BOOL_EXEC(AdxDataDumpServerInit() != kDumpStatus, |
| 706 | - GELOGI("Init adx data dump server success"); | 707 | + GELOGE(PARAM_INVALID, "[Init][AdxDataDumpServer] failed, session_id:%" PRIu64 ".", session_id_); |
| 707 | - is_dump_server_inited_ = true; | 708 | + return PARAM_INVALID) |
| 709 | + GELOGI("Init adx data dump server success"); | ||
| 710 | + is_dump_server_inited_ = true; | ||
| 711 | + } | ||
| 708 | } | 712 | } |
| 709 | } | 713 | } |
| 710 | if ((!dump_properties.GetEnableDump().empty()) || (!dump_properties.GetEnableDumpDebug().empty())) { | 714 | if ((!dump_properties.GetEnableDump().empty()) || (!dump_properties.GetEnableDumpDebug().empty())) { |
| @@ -722,16 +726,19 @@ Status InnerSession::AddDumpProperties(const DumpProperties &dump_properties) { | |||
| 722 | 726 | ||
| 723 | Status InnerSession::RemoveDumpProperties() { | 727 | Status InnerSession::RemoveDumpProperties() { |
| 724 | DumpManager::GetInstance().RemoveDumpProperties(session_id_); | 728 | DumpManager::GetInstance().RemoveDumpProperties(session_id_); |
| 725 | - if (is_dump_server_inited_ && DumpManager::GetInstance().GetDumpPropertiesMap().empty()) { | 729 | + { |
| 726 | - GE_IF_BOOL_EXEC(AdxDataDumpServerUnInit() != kDumpStatus, | 730 | + std::lock_guard<std::mutex> lock(dump_server_mutex_); |
| 727 | - GELOGE(PARAM_INVALID, "[UnInit][AdxDataDumpServer] failed, session_id:%" PRIu64 ".", session_id_); | 731 | + if (is_dump_server_inited_ && DumpManager::GetInstance().GetDumpPropertiesMap().empty()) { |
| 728 | - REPORT_INNER_ERR_MSG("E19999", | 732 | + GE_IF_BOOL_EXEC(AdxDataDumpServerUnInit() != kDumpStatus, |
| 729 | - "RemoveDumpProperties failed because AdxDataDumpServerUnInit failed," | 733 | + GELOGE(PARAM_INVALID, "[UnInit][AdxDataDumpServer] failed, session_id:%" PRIu64 ".", session_id_); |
| 730 | - "session_id:%" PRIu64 ".", | 734 | + REPORT_INNER_ERR_MSG("E19999", |
| 731 | - session_id_); | 735 | + "RemoveDumpProperties failed because AdxDataDumpServerUnInit failed," |
| 732 | - return PARAM_INVALID) | 736 | + "session_id:%" PRIu64 ".", |
| 733 | - GELOGI("UnInit adx data dump server success"); | 737 | + session_id_); |
| 734 | - is_dump_server_inited_ = false; | 738 | + return PARAM_INVALID) |
| 739 | + GELOGI("UnInit adx data dump server success"); | ||
| 740 | + is_dump_server_inited_ = false; | ||
| 741 | + } | ||
| 735 | } | 742 | } |
| 736 | return SUCCESS; | 743 | return SUCCESS; |
| 737 | } | 744 | } |
| @@ -170,6 +170,7 @@ class InnerSession { | |||
| 170 | std::vector<std::pair<uint64_t, uint64_t>> &cross_ranges) const; | 170 | std::vector<std::pair<uint64_t, uint64_t>> &cross_ranges) const; |
| 171 | Status InitializeVarManager(); | 171 | Status InitializeVarManager(); |
| 172 | static bool is_dump_server_inited_; | 172 | static bool is_dump_server_inited_; |
| 173 | + static std::mutex dump_server_mutex_; | ||
| 173 | std::shared_ptr<DFlowSessionImpl> dflow_session_impl_; | 174 | std::shared_ptr<DFlowSessionImpl> dflow_session_impl_; |
| 174 | UserGraphsManagerPtr user_graphs_manager_{nullptr}; | 175 | UserGraphsManagerPtr user_graphs_manager_{nullptr}; |
| 175 | UserHybridGraphManagerPtr user_hybrid_graph_manager_{nullptr}; | 176 | UserHybridGraphManagerPtr user_hybrid_graph_manager_{nullptr}; |
| @@ -104,10 +104,12 @@ bool AdxGetWorkspaceInfo(const Adx::OperatorInfoV2 &info, uint32_t index, void * | |||
| 104 | } // namespace ge | 104 | } // namespace ge |
| 105 | 105 | ||
| 106 | int AdxDataDumpServerUnInit() { | 106 | int AdxDataDumpServerUnInit() { |
| 107 | + ge::DumpStub::GetInstance().IncrementAdxUninitCount(); | ||
| 107 | return 0; | 108 | return 0; |
| 108 | } | 109 | } |
| 109 | 110 | ||
| 110 | int AdxDataDumpServerInit() { | 111 | int AdxDataDumpServerInit() { |
| 112 | + ge::DumpStub::GetInstance().IncrementAdxInitCount(); | ||
| 111 | return 0; | 113 | return 0; |
| 112 | } | 114 | } |
| 113 | 115 | ||
| @@ -10,6 +10,7 @@ | |||
| 10 | 10 | ||
| 11 | 11 | ||
| 12 | 12 | ||
| 13 | + | ||
| 13 | 14 | ||
| 14 | 15 | ||
| 15 | 16 | ||
| @@ -161,6 +162,8 @@ class DumpStub { | |||
| 161 | ClearFuncRet(); | 162 | ClearFuncRet(); |
| 162 | dump_configs_.clear(); | 163 | dump_configs_.clear(); |
| 163 | mock_dump_path_.clear(); | 164 | mock_dump_path_.clear(); |
| 165 | + adx_init_count_.store(0, std::memory_order_relaxed); | ||
| 166 | + adx_uninit_count_.store(0, std::memory_order_relaxed); | ||
| 164 | } | 167 | } |
| 165 | 168 | ||
| 166 | void SetMockDumpPath(const std::string &path) { | 169 | void SetMockDumpPath(const std::string &path) { |
| @@ -192,6 +195,23 @@ class DumpStub { | |||
| 192 | return it != call_records_.end() ? it->second : 0; | 195 | return it != call_records_.end() ? it->second : 0; |
| 193 | } | 196 | } |
| 194 | 197 | ||
| 198 | + void IncrementAdxInitCount() { | ||
| 199 | + adx_init_count_.fetch_add(1, std::memory_order_relaxed); | ||
| 200 | + } | ||
| 201 | + void IncrementAdxUninitCount() { | ||
| 202 | + adx_uninit_count_.fetch_add(1, std::memory_order_relaxed); | ||
| 203 | + } | ||
| 204 | + int GetAdxInitCallCount() const { | ||
| 205 | + return adx_init_count_.load(std::memory_order_relaxed); | ||
| 206 | + } | ||
| 207 | + int GetAdxUninitCallCount() const { | ||
| 208 | + return adx_uninit_count_.load(std::memory_order_relaxed); | ||
| 209 | + } | ||
| 210 | + void ResetAdxCallCount() { | ||
| 211 | + adx_init_count_.store(0, std::memory_order_relaxed); | ||
| 212 | + adx_uninit_count_.store(0, std::memory_order_relaxed); | ||
| 213 | + } | ||
| 214 | + | ||
| 195 | private: | 215 | private: |
| 196 | DumpStub() = default; | 216 | DumpStub() = default; |
| 197 | std::mutex mu_; | 217 | std::mutex mu_; |
| @@ -205,6 +225,8 @@ class DumpStub { | |||
| 205 | std::map<Adx::DumpType, Adx::DumpConfig> dump_configs_; | 225 | std::map<Adx::DumpType, Adx::DumpConfig> dump_configs_; |
| 206 | bool is_enable_{true}; | 226 | bool is_enable_{true}; |
| 207 | std::string mock_dump_path_; | 227 | std::string mock_dump_path_; |
| 228 | + std::atomic<int> adx_init_count_{0}; | ||
| 229 | + std::atomic<int> adx_uninit_count_{0}; | ||
| 208 | }; | 230 | }; |
| 209 | } // namespace ge | 231 | } // namespace ge |
| 210 | 232 | ||
| @@ -9,6 +9,7 @@ | |||
| 9 | */ | 9 | */ |
| 10 | 10 | ||
| 11 | 11 | ||
| 12 | + | ||
| 12 | 13 | ||
| 13 | 14 | ||
| 14 | 15 | ||
| @@ -735,4 +736,41 @@ TEST_F(UTEST_dump_manager, set_dump_path_with_acldump_override) { | |||
| 735 | DumpStub::GetInstance().SetMockDumpPath(""); | 736 | DumpStub::GetInstance().SetMockDumpPath(""); |
| 736 | DumpManager::GetInstance().RemoveDumpProperties(0); | 737 | DumpManager::GetInstance().RemoveDumpProperties(0); |
| 737 | } | 738 | } |
| 739 | + | ||
| 740 | +TEST_F(UTEST_dump_manager, ConcurrentAddRemoveDumpProperties_InitUninitCalledOnce) { | ||
| 741 | + DumpManager::GetInstance().RemoveDumpProperties(0); | ||
| 742 | + DumpManager::GetInstance().RemoveDumpProperties(1); | ||
| 743 | + std::map<std::string, std::string> empty_opts; | ||
| 744 | + InnerSession setup_session(997U, empty_opts); | ||
| 745 | + setup_session.RemoveDumpProperties(); | ||
| 746 | + DumpStub::GetInstance().Reset(); | ||
| 747 | + DumpStub::GetInstance().ResetAdxCallCount(); | ||
| 748 | + | ||
| 749 | + constexpr int32_t kN = 10; | ||
| 750 | + std::vector<std::unique_ptr<InnerSession>> sessions; | ||
| 751 | + for (int32_t i = 0; i < kN; ++i) { | ||
| 752 | + sessions.push_back(std::make_unique<InnerSession>(static_cast<uint64_t>(i), empty_opts)); | ||
| 753 | + } | ||
| 754 | + std::vector<std::thread> threads; | ||
| 755 | + for (int32_t i = 0; i < kN; ++i) { | ||
| 756 | + threads.emplace_back([&sessions, i]() { | ||
| 757 | + DumpProperties dp; | ||
| 758 | + dp.SetDumpStatus("on"); | ||
| 759 | + sessions[static_cast<size_t>(i)]->AddDumpProperties(dp); | ||
| 760 | + }); | ||
| 761 | + } | ||
| 762 | + for (auto &t : threads) { | ||
| 763 | + t.join(); | ||
| 764 | + } | ||
| 765 | + EXPECT_EQ(DumpStub::GetInstance().GetAdxInitCallCount(), 1); | ||
| 766 | + | ||
| 767 | + threads.clear(); | ||
| 768 | + for (int32_t i = 0; i < kN; ++i) { | ||
| 769 | + threads.emplace_back([&sessions, i]() { sessions[static_cast<size_t>(i)]->RemoveDumpProperties(); }); | ||
| 770 | + } | ||
| 771 | + for (auto &t : threads) { | ||
| 772 | + t.join(); | ||
| 773 | + } | ||
| 774 | + EXPECT_EQ(DumpStub::GetInstance().GetAdxUninitCallCount(), 1); | ||
| 775 | +} | ||
| 738 | } // namespace ge | 776 | } // namespace ge |