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 "ipc_local_notify.h"
12 : #include "runtime_api_exception.h"
13 : #include "exchange_ipc_notify_dto.h"
14 :
15 : namespace Hccl {
16 :
17 15 : IpcLocalNotify::IpcLocalNotify(bool devUsed) : BaseLocalNotify(RmaType::IPC, devUsed)
18 : {
19 : // SetIpc
20 15 : auto name = GetNotify()->SetIpcName();
21 15 : s32 sRet = memcpy_s(ipcName, RTS_IPC_MEM_NAME_LEN, name.c_str(), name.size());
22 15 : if (sRet != EOK) {
23 0 : THROW<RuntimeApiException>(StringFormat("[IpcLocalNotify]memcpy_s ipcname failed, cname[%s]", name.c_str()));
24 : }
25 15 : }
26 :
27 1 : void IpcLocalNotify::Wait(const Stream &stream, u32 timeout) const
28 : {
29 1 : GetNotify()->Wait(stream, timeout);
30 1 : }
31 :
32 1 : void IpcLocalNotify::Post(const Stream &stream) const
33 : {
34 1 : GetNotify()->Post(stream);
35 1 : }
36 :
37 0 : std::unique_ptr<Serializable> IpcLocalNotify::GetExchangeDto()
38 : {
39 : std::unique_ptr<ExchangeIpcNotifyDto> dto
40 0 : = make_unique<ExchangeIpcNotifyDto>(GetNotify()->GetHandleAddr(), GetNotify()->GetId(), HrtDeviceGetBareTgid(),
41 0 : GetNotify()->GetDevPhyId(), GetNotify()->IsDevUsed());
42 0 : (void)memcpy_s(dto->name, RTS_IPC_MEM_NAME_LEN, ipcName, RTS_IPC_MEM_NAME_LEN);
43 0 : return std::unique_ptr<Serializable>(dto.release());
44 0 : }
45 :
46 3 : string IpcLocalNotify::Describe() const
47 : {
48 3 : return StringFormat("IpcLocalNotify[notify=%s]", GetNotify()->Describe().c_str());
49 : }
50 :
51 1 : void IpcLocalNotify::Grant(u32 pid) const
52 : {
53 1 : u32 myPid = HrtDeviceGetBareTgid();
54 1 : if (pid != myPid) {
55 0 : GetNotify()->SetIpcPid(static_cast<s32>(pid));
56 : }
57 1 : }
58 :
59 : } // namespace Hccl
|