Line data Source code
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 :
11 : #ifndef ENDPOINT_MONITOR_H
12 : #define ENDPOINT_MONITOR_H
13 : #include <thread>
14 : #include <unordered_set>
15 : #include <mutex>
16 : #include <atomic>
17 : #include "log.h"
18 : #include "hccl/hccl_types.h"
19 : #include "hcomm_res_defs.h"
20 : #include "hccp_ctx.h"
21 :
22 : namespace hcomm {
23 :
24 : class EndpointMonitor {
25 : public:
26 264 : EndpointMonitor() = default;
27 : EndpointMonitor(const EndpointMonitor&) = delete;
28 : EndpointMonitor& operator=(const EndpointMonitor&) = delete;
29 : EndpointMonitor(EndpointMonitor&&) = delete;
30 : EndpointMonitor& operator=(EndpointMonitor&&) = delete;
31 : ~EndpointMonitor();
32 :
33 : static EndpointMonitor& GetInstance(s32 deviceId);
34 : HcclResult RegisterToEndpointMonitor(s32 deviceLogicId, EndpointHandle epHandle);
35 : HcclResult UnRegisterToEndpointMonitor();
36 : void RemoveEpHandleFromEndpointMonitor(EndpointHandle epHandle);
37 :
38 : private:
39 : HcclResult RunMonitorThread();
40 : void MonitorThread();
41 : HcclResult DeInit(s32 deviceLogicId);
42 :
43 : void ProcessUbAsyncEvents();
44 : void PrintUbAsyncEventsContext(void* epHandle, u32 seq, const struct AsyncEvent& event);
45 :
46 : static constexpr u32 MONITOR_INTERVAL = 1000;
47 : std::unique_ptr<std::thread> endpointMonitorThread_;
48 :
49 : std::atomic<bool> initialized_{false};
50 : std::atomic<bool> endpointMonitorThreadFlag_{false};
51 : std::mutex threadLock_;
52 : u32 devPhyId_{0};
53 : s32 deviceLogicId_{0};
54 : std::unordered_set<u64> epHandleSet_;
55 :
56 : struct AsyncEvent events_[ASYNC_EVENT_MAX_NUM];
57 : };
58 : } // namespace hcomm
59 : #endif // ENDPOINT_MONITOR_H
|