Line data Source code
1 : /**
2 : * Copyright (c) 2025 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 : #include "rts_notify_v2.h"
12 : #include "log.h"
13 : #include "dev_capability.h"
14 : #include "binary_stream.h"
15 : namespace Hccl {
16 :
17 980 : RtsNotify::RtsNotify(bool devUsed) : devPhyId(HrtGetDevicePhyIdByIndex(HrtGetDevice())), devUsed(devUsed)
18 : {
19 980 : s32 deviceID = HrtGetDevice();
20 :
21 980 : if (devUsed) {
22 121 : handle = HrtNotifyCreateWithFlag(deviceID, ACL_NOTIFY_DEVICE_USE_ONLY);
23 : } else {
24 859 : handle = HrtNotifyCreate(deviceID);
25 : }
26 :
27 980 : id = HrtGetNotifyID(handle);
28 980 : }
29 :
30 980 : RtsNotify::~RtsNotify() { DECTOR_TRY_CATCH("RtsNotify", HrtNotifyDestroy(handle)); }
31 :
32 17 : std::string RtsNotify::SetIpcName() const
33 : {
34 17 : char ipcName[RTS_IPC_MEM_NAME_LEN] = {0};
35 17 : HrtIpcSetNotifyName(handle, ipcName, RTS_IPC_MEM_NAME_LEN);
36 34 : return ipcName;
37 : }
38 :
39 0 : void RtsNotify::SetIpcPid(s32 pid) const { HrtSetIpcNotifyPid(handle, pid); }
40 :
41 149 : u32 RtsNotify::GetId() const { return id; }
42 :
43 2 : u64 RtsNotify::GetOffset() const { return HrtNotifyGetOffset(handle); }
44 :
45 20 : u64 RtsNotify::GetHandleAddr() const { return reinterpret_cast<u64>(handle); }
46 :
47 2 : u32 RtsNotify::GetSize() const { return DevCapability::GetInstance().GetNotifySize(); }
48 :
49 2 : bool RtsNotify::IsDevUsed() const { return devUsed; }
50 :
51 14 : u32 RtsNotify::GetDevPhyId() const { return devPhyId; }
52 :
53 62 : std::vector<char> RtsNotify::GetUniqueId() const
54 : {
55 62 : BinaryStream binaryStream;
56 62 : binaryStream << id;
57 62 : binaryStream << devPhyId;
58 164 : HCCL_INFO("[RtsNotify][GetUniqueId]id[%u] devPhyId[%u]", id, devPhyId);
59 62 : std::vector<char> result;
60 62 : binaryStream.Dump(result);
61 62 : return result;
62 62 : }
63 :
64 13 : void RtsNotify::Wait(const Stream& stream, u32 timeout) const
65 : {
66 13 : HrtNotifyWaitWithTimeOut(handle, stream.GetPtr(), timeout);
67 13 : }
68 :
69 10 : void RtsNotify::Post(const Stream& stream) const { HrtNotifyRecord(handle, stream.GetPtr()); }
70 :
71 105 : string RtsNotify::Describe() const
72 : {
73 105 : return StringFormat("RtsNotify[devUsed=%d, id=%u, handle=%p]", devUsed, id, handle);
74 : }
75 :
76 : } // namespace Hccl
|