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 : #include <sys/file.h>
11 : #include <sys/ioctl.h>
12 : #include "aicpusd_interface_process.h"
13 : #include <unistd.h>
14 : #include "ascend_hal.h"
15 : #include "status.h"
16 : #include "aicpusd_event_manager.h"
17 : #include "aicpusd_status.h"
18 : #include "aicpusd_drv_manager.h"
19 : #include "aicpusd_threads_process.h"
20 : #include "aicpusd_common.h"
21 : #include "aicpusd_monitor.h"
22 : #include "aicpusd_hal_interface_ref.h"
23 : #include "aicpu_cust_sd_dump_process.h"
24 : #include "core/aicpusd_op_executor.h"
25 : #include "core/aicpusd_resource_limit.h"
26 : #include "stackcore_interface_weak.h"
27 : #include "aicpu_cust_sd_mc2_maintenance_thread_api.h"
28 :
29 : namespace AicpuSchedule {
30 : namespace {
31 20 : void RegOpenCustSoCallBack()
32 : {
33 20 : SubProcEventCallBackInfo openCustSoInfo = {};
34 20 : openCustSoInfo.callBackFunc = CustomOpExecutor::OpenKernelSoByAicpuEvent;
35 20 : openCustSoInfo.eventType = AICPU_SUB_EVENT_OPEN_CUSTOM_SO;
36 20 : const int32_t ret = RegEventMsgCallBackFunc(&openCustSoInfo);
37 20 : if (ret != 0) {
38 1 : aicpusd_run_warn("Aicpu-sd-cust main thread reg open custom so callback function failed. eventid[%d]",
39 : static_cast<int32_t>(openCustSoInfo.eventType));
40 1 : return;
41 : }
42 : }
43 : } //namespace
44 : constexpr int32_t SUCCESS_VALUE = 0;
45 : constexpr int32_t ATTACH_TIME_OUT = 20000; // attach fail after 20s blocking attach
46 : /**
47 : * @ingroup AicpuScheduleCore
48 : * @brief it is used to construct a object of AicpuScheduleCore.
49 : */
50 1 : AicpuScheduleInterface::AicpuScheduleInterface()
51 1 : : noThreadFlag_(true),
52 1 : initFlag_(false),
53 1 : aicpuSdPid_(-1),
54 1 : tsdPid_(-1) {}
55 :
56 : /**
57 : * @ingroup AicpuScheduleCore
58 : * @brief it is used to destructor a object of AicpuScheduleCore.
59 : */
60 1 : AicpuScheduleInterface::~AicpuScheduleInterface() {}
61 :
62 132 : AicpuScheduleInterface &AicpuScheduleInterface::GetInstance()
63 : {
64 132 : static AicpuScheduleInterface instance;
65 132 : return instance;
66 : }
67 :
68 4 : void SetCustAicpuMainThreadContext(const uint32_t deviceId, const pid_t hostPid, const uint32_t vfId)
69 : {
70 4 : aicpu::aicpuContext_t context = {};
71 4 : context.tsId = 0U;
72 4 : context.deviceId = deviceId;
73 4 : context.hostPid = hostPid;
74 4 : context.vfId = vfId;
75 4 : aicpu::SetUniqueVfId(AicpuDrvManager::GetInstance().GetUniqueVfId());
76 4 : (void)aicpu::aicpuSetContext(&context);
77 4 : }
78 :
79 : /**
80 : * @ingroup AicpuScheduleInterface
81 : * @brief it use to initialize aicpu schedule.
82 : * @param [in] deviceId
83 : * @param [in] hostPid : the process id of host process
84 : * @param [in] pidSign : the signature of pid ,it is used in drv.
85 : * @param [in] profilingMode
86 : * @param [in] aicpuPid : the process id of aicpu-sd process
87 : * @param [in] vfId : vf id
88 : * @param [in] isOnline : true: online false offline
89 : * @return AICPU_SCHEDULE_OK: success, other: error code
90 : */
91 10 : int32_t AicpuScheduleInterface::InitAICPUScheduler(const uint32_t deviceId,
92 : const pid_t hostPid,
93 : const std::string &pidSign,
94 : const uint32_t profilingMode,
95 : const pid_t aicpuPid,
96 : const uint32_t vfId,
97 : const bool isOnline)
98 : {
99 : (void)pidSign;
100 10 : const std::unique_lock<std::mutex> initLock(mutexForInit_);
101 10 : if (initFlag_) {
102 1 : aicpusd_warn("Aicpu schedule is already init.");
103 1 : return AICPU_SCHEDULE_OK;
104 : }
105 :
106 9 : noThreadFlag_ = false;
107 9 : if (AicpuDrvManager::GetInstance().InitDrvMgr(deviceId, hostPid, vfId, true) != AICPU_SCHEDULE_OK) {
108 2 : aicpusd_err("Failed to init aicpu drv manager");
109 2 : return AICPU_SCHEDULE_ERROR_DRV_ERR;
110 : }
111 7 : aicpu::AicpuRunMode runModeCur = aicpu::AicpuRunMode::THREAD_MODE;
112 7 : if (GetCurrentRunMode(isOnline, runModeCur) != AICPU_SCHEDULE_OK) {
113 1 : aicpusd_err("Aicpu custom get run mode failed");
114 1 : return AICPU_SCHEDULE_ERROR_INIT_FAILED;
115 : }
116 :
117 6 : const int32_t bindPidRet = AicpuSchedule::AicpuDrvManager::GetInstance().CheckBindHostPid();
118 6 : if (bindPidRet != AICPU_SCHEDULE_OK) {
119 0 : aicpusd_err("Check bind pid sign failed, ret[%d].", bindPidRet);
120 0 : return static_cast<int32_t>(ComputProcessRetCode::CP_RET_COMMON_ERROR);
121 : }
122 6 : aicpusd_info("Bind pid sign success.");
123 6 : const uint32_t groupIdCur = DEFAULT_GROUP_ID;
124 6 : int32_t retRes = AicpuDrvManager::GetInstance().InitDrvSchedModule(groupIdCur);
125 6 : if (retRes != static_cast<int32_t>(DRV_ERROR_NONE)) {
126 2 : aicpusd_err("Failed to init the drv schedule module, ret[%d].", retRes);
127 2 : return AICPU_SCHEDULE_ERROR_DRV_ERR;
128 : }
129 4 : SetCustAicpuMainThreadContext(deviceId, hostPid, vfId);
130 4 : retRes = AicpuSchedule::AicpuMonitor::GetInstance().InitAicpuMonitor(deviceId, isOnline);
131 4 : if (retRes != AICPU_SCHEDULE_OK) {
132 1 : aicpusd_err("aicpu monitor init failed, ret[%d]", retRes);
133 1 : return AICPU_SCHEDULE_ERROR_INIT_FAILED;
134 : }
135 3 : retRes = ComputeProcess::GetInstance().Start(deviceId, hostPid, profilingMode, aicpuPid, vfId, runModeCur);
136 3 : if (retRes != static_cast<int32_t>(ComputProcessRetCode::CP_RET_SUCCESS)) {
137 1 : aicpusd_err("Compute process start failed, ret[%d].", retRes);
138 1 : AicpuSchedule::AicpuMonitor::GetInstance().Stop();
139 1 : ComputeProcess::GetInstance().Stop();
140 1 : return AICPU_SCHEDULE_ERROR_INIT_CP_FAILED;
141 : }
142 2 : aicpusd_info("Successfully started compute process, deviceId[%u], hostPid[%d], mode[%d].",
143 : deviceId, hostPid, static_cast<int32_t>(isOnline));
144 2 : initFlag_ = true;
145 2 : return AICPU_SCHEDULE_OK;
146 10 : }
147 :
148 : /**
149 : * @ingroup AicpuScheduleInterface
150 : * @brief it use to stop AICPU scheduler.
151 : * @param [in] deviceId
152 : * @param [in] hostPid :the process id of host
153 : * @return AICPU_SCHEDULE_OK: success, other: error code
154 : */
155 16 : int32_t AicpuScheduleInterface::StopAICPUScheduler(const uint32_t deviceId)
156 : {
157 16 : aicpusd_info("Begin to stop aicpu custom scheduler.");
158 16 : const std::unique_lock<std::mutex> stopLock(mutexForInit_);
159 16 : if (!noThreadFlag_) {
160 4 : ComputeProcess::GetInstance().Stop();
161 : }
162 :
163 16 : noThreadFlag_ = true;
164 16 : initFlag_ = false;
165 : // GetInstance is not null, checked in InitAICPUScheduler
166 16 : AicpuSchedule::AicpuMonitor::GetInstance().Stop();
167 16 : AicpuSchedule::AicpuEventManager::GetInstance().SetRunningFlag(false);
168 16 : AicpuSchedule::AicpuCustDumpProcess::GetInstance().UnitDataDumpProcess();
169 16 : FeatureCtrl::ClearTsMsgVersionInfo();
170 16 : constexpr uint32_t sleepUsecs = 1000U; // sleep 1ms to avoid SchedWaitEvent error
171 16 : (void)usleep(sleepUsecs);
172 16 : if ((FeatureCtrl::ShouldInitDrvThread()) && (&halDrvEventThreadUninit != nullptr)) {
173 16 : const auto unInitRet = halDrvEventThreadUninit(deviceId);
174 16 : aicpusd_run_info("Uninit process drv queue msg on ccpu, ret is %d.", static_cast<int32_t>(unInitRet));
175 : }
176 16 : const auto ret = halEschedDettachDevice(deviceId);
177 16 : if (ret != DRV_ERROR_NONE) {
178 2 : aicpusd_err("Failed to detach device[%u], result[%d].", deviceId, static_cast<int32_t>(ret));
179 2 : return static_cast<int32_t>(ret);
180 : }
181 14 : aicpusd_info("Successfully stopped AICPU custom scheduler.");
182 14 : return AICPU_SCHEDULE_OK;
183 16 : }
184 :
185 10 : int32_t AicpuScheduleInterface::GetCurrentRunMode(const bool isOnline, aicpu::AicpuRunMode &runMode) const
186 : {
187 10 : if (!isOnline) {
188 1 : runMode = aicpu::AicpuRunMode::THREAD_MODE;
189 1 : aicpusd_info("Current aicpu mode is offline (call by api).");
190 1 : return AICPU_SCHEDULE_OK;
191 : }
192 :
193 : drvHdcCapacity capacity;
194 9 : capacity.chanType = HDC_CHAN_TYPE_SOCKET;
195 9 : capacity.maxSegment = 0U;
196 9 : const hdcError_t hdcRet = drvHdcGetCapacity(&capacity);
197 9 : if (hdcRet != DRV_ERROR_NONE) {
198 1 : aicpusd_err("Aicpu cust scheduler get capacity failed, ret[%d].", static_cast<int32_t>(hdcRet));
199 1 : return AICPU_SCHEDULE_ERROR_DRV_ERR;
200 : }
201 :
202 : // online: with host, offline: without host only device
203 8 : if (capacity.chanType == HDC_CHAN_TYPE_SOCKET) {
204 7 : runMode = aicpu::AicpuRunMode::PROCESS_SOCKET_MODE;
205 7 : aicpusd_info("Set aicpu online mode false. current mode is socket_mode.");
206 7 : return AICPU_SCHEDULE_OK;
207 : }
208 :
209 1 : runMode = aicpu::AicpuRunMode::PROCESS_PCIE_MODE;
210 1 : aicpusd_info("Current aicpu mode is online, called from host.");
211 1 : return AICPU_SCHEDULE_OK;
212 : }
213 :
214 20 : void AicpuScheduleInterface::SetAicpuSdProcId(const pid_t aicpuSdPid)
215 : {
216 20 : aicpuSdPid_ = aicpuSdPid;
217 20 : aicpusd_info("Set aicpusd pid:%u", static_cast<uint32_t>(aicpuSdPid_));
218 20 : }
219 :
220 4 : pid_t AicpuScheduleInterface::GetAicpuSdProcId() const
221 : {
222 4 : return aicpuSdPid_;
223 : }
224 :
225 20 : void AicpuScheduleInterface::SetTsdProcId(const pid_t tsdPid)
226 : {
227 20 : tsdPid_ = tsdPid;
228 20 : aicpusd_info("Set tsd pid:%u", static_cast<uint32_t>(tsdPid_));
229 20 : }
230 :
231 0 : pid_t AicpuScheduleInterface::GetTsdProcId() const
232 : {
233 0 : return tsdPid_;
234 : }
235 :
236 22 : void AicpuScheduleInterface::SetLogLevel(const AicpuSchedule::ArgsParser &startParams) const
237 : {
238 22 : if (&dlog_setlevel != nullptr) {
239 22 : if (dlog_setlevel(-1, startParams.GetLogLevel(), startParams.GetEventLevel()) != AicpuSchedule::SUCCESS_VALUE) {
240 0 : aicpusd_warn("Set log level failed");
241 : }
242 22 : if ((startParams.GetCcecpuLogLevel() >= DEBUG_LOG) && (startParams.GetCcecpuLogLevel() <= ERROR_LOG)) {
243 0 : if (dlog_setlevel(CCECPU, startParams.GetCcecpuLogLevel(), startParams.GetEventLevel()) != SUCCESS_VALUE) {
244 0 : aicpusd_warn("Set ccecpu log level failed");
245 : }
246 : }
247 22 : if ((startParams.GetAicpuLogLevel() >= DEBUG_LOG) && (startParams.GetAicpuLogLevel() <= ERROR_LOG)) {
248 0 : if (dlog_setlevel(AICPU, startParams.GetAicpuLogLevel(), startParams.GetEventLevel()) != SUCCESS_VALUE) {
249 0 : aicpusd_warn("Set aicpu log failed");
250 : }
251 : }
252 : }
253 22 : if (&DlogSetAttr != nullptr) {
254 22 : LogAttr logAttr = {};
255 22 : logAttr.type = APPLICATION;
256 22 : logAttr.pid = static_cast<uint32_t>(startParams.GetHostPid());
257 22 : logAttr.deviceId = startParams.GetDeviceId();
258 22 : if (DlogSetAttr(logAttr) != AicpuSchedule::SUCCESS_VALUE) {
259 0 : aicpusd_warn("Set log attr failed");
260 : }
261 : }
262 22 : }
263 22 : void AicpuScheduleInterface::SetTsdEventDstPidByArgs(const AicpuSchedule::ArgsParser &startParams) const
264 : {
265 22 : if ((!startParams.HasTsdPid()) || (startParams.GetTsdPid() == 0U)) {
266 14 : aicpusd_run_info("hastsdpid:%d, tsdpid:%u", startParams.HasTsdPid(), startParams.GetTsdPid());
267 14 : return;
268 : }
269 8 : SetDstTsdEventPid(startParams.GetTsdPid());
270 8 : aicpusd_run_info("cust finish set tsdpid:%u", startParams.GetTsdPid());
271 : }
272 22 : void AicpuScheduleInterface::SetCustAicpuMainThreadAffinity(const AicpuSchedule::ArgsParser &startParams) const
273 : {
274 22 : if (!startParams.HasControlCpuList()) {
275 18 : return;
276 : }
277 8 : pthread_t threadId = pthread_self();
278 8 : std::vector<uint32_t> cpuIds = startParams.GetControlCpuList();
279 : cpu_set_t cpuset;
280 8 : CPU_ZERO(&cpuset);
281 24 : for (const auto cpuId: cpuIds) {
282 16 : CPU_SET(cpuId, &cpuset);
283 16 : aicpusd_info("prepare bind threadId=%lu to cpuId=%u", threadId, static_cast<uint32_t>(cpuId));
284 : }
285 8 : aicpusd_run_info("begin call pthread_setaffinity_np threadId=%lu", threadId);
286 : // 设置线程亲和性
287 8 : int32_t ret = pthread_setaffinity_np(threadId, sizeof(cpu_set_t), &cpuset);
288 8 : if (ret != 0) {
289 2 : aicpusd_err("BindCpu threadId=%lu set affinity failed, ret=%d", threadId, ret);
290 2 : return;
291 : }
292 : // 检查线程实际亲和性
293 6 : ret = pthread_getaffinity_np(threadId, sizeof(cpu_set_t), &cpuset);
294 6 : if (ret != 0) {
295 2 : aicpusd_err("BindCpu threadId=%lu get affinity failed, ret=%d", threadId, ret);
296 2 : return;
297 : }
298 4100 : for (int32_t cpuId = 0; cpuId < CPU_SETSIZE; cpuId++) {
299 4096 : if (CPU_ISSET(cpuId, &cpuset) != 0) {
300 8 : aicpusd_info("BindCpu threadId=%lu to cpuId=%d success", threadId, static_cast<int32_t>(cpuId));
301 : }
302 : }
303 8 : }
304 :
305 15 : bool AicpuScheduleInterface::AttachHostGroup(const std::vector<std::string> &groupNameVec,
306 : const uint32_t grpNameNum) const
307 : {
308 15 : if (grpNameNum == 0U) {
309 1 : aicpusd_info("There is not group need to be attached");
310 1 : return true;
311 : }
312 14 : if (groupNameVec.empty()) {
313 1 : aicpusd_err("Aicpu start failed. Wrong parameters of groupNum[%d] with empty group name", grpNameNum);
314 1 : return false;
315 : }
316 :
317 13 : if (static_cast<uint32_t>(groupNameVec.size()) != grpNameNum) {
318 1 : aicpusd_err("Aicpu start failed. parse group name num[%u] is consistence with num[%u] in parameter",
319 : groupNameVec.size(), grpNameNum);
320 1 : return false;
321 : }
322 32 : for (size_t i = 0UL; i < groupNameVec.size(); ++i) {
323 21 : aicpusd_info("halGrpAttach group[%s].", groupNameVec[i].c_str());
324 21 : const auto drvRet = halGrpAttach(groupNameVec[i].c_str(), ATTACH_TIME_OUT);
325 21 : if (drvRet != DRV_ERROR_NONE) {
326 1 : aicpusd_err("halGrpAttach group[%s] failed. ret[%d]", groupNameVec[i].c_str(), drvRet);
327 1 : return false;
328 : }
329 20 : aicpusd_run_info("halGrpAttach group[%s] success", groupNameVec[i].c_str());
330 : }
331 11 : BuffCfg buffCfg = {};
332 11 : const auto initDrvRet = halBuffInit(&buffCfg);
333 11 : if ((initDrvRet != DRV_ERROR_NONE) && (initDrvRet != DRV_ERROR_REPEATED_INIT)) {
334 1 : aicpusd_err("halBuffInit execute failed. ret[%d]", initDrvRet);
335 1 : return false;
336 : }
337 10 : return true;
338 : }
339 :
340 26 : bool AicpuScheduleInterface::SendVfMsgToDrv(const uint32_t cmd, const uint32_t deviceId, const uint32_t vfId) const
341 : {
342 26 : if (FeatureCtrl::IsVfMode(deviceId, vfId)) {
343 8 : const int32_t fd = open("/dev/qos", O_RDWR);
344 8 : if (fd < 0) {
345 6 : aicpusd_warn("no such file. error[%s],errorno[%d]", strerror(errno), errno);
346 8 : return false;
347 : }
348 : VfMsgInfo vfMsg;
349 2 : vfMsg.deviceId = deviceId;
350 2 : vfMsg.vfId = vfId;
351 2 : const auto ret = ioctl(fd, cmd, PtrToPtr<VfMsgInfo, void>(&vfMsg));
352 2 : if (ret != 0) {
353 2 : aicpusd_warn("ioctl failed, error[%s],errorno[%d]", strerror(errno), errno);
354 2 : (void)close(fd);
355 2 : return false;
356 : }
357 0 : (void)close(fd);
358 : }
359 18 : return true;
360 : }
361 :
362 20 : void RegCreateCustMc2MaintenanceThreadCallBack()
363 : {
364 20 : SubProcEventCallBackInfo createCustMc2MaintenanceThreadInfo = {};
365 20 : createCustMc2MaintenanceThreadInfo.callBackFunc = CreateCustMc2MaintenanceThread;
366 20 : createCustMc2MaintenanceThreadInfo.eventType = TSD_EVENT_START_MC2_THREAD;
367 20 : int32_t ret = RegEventMsgCallBackFunc(&createCustMc2MaintenanceThreadInfo);
368 20 : if (ret != 0) {
369 1 : aicpusd_err("Reg create cust mc2 maintenance thread failed");
370 1 : return;
371 : }
372 : }
373 :
374 37 : int32_t AicpuScheduleInterface::CustAicpuMainProcess(int32_t argc, char_t *argv[]) const
375 : {
376 : try {
377 37 : AicpuSchedule::ArgsParser startParams;
378 37 : if (!startParams.ParseArgs(argc, argv)) {
379 15 : return -1;
380 : }
381 22 : SetLogLevel(startParams);
382 22 : SetTsdEventDstPidByArgs(startParams);
383 22 : SetCustAicpuMainThreadAffinity(startParams);
384 22 : aicpusd_run_info("Start parameter. %s", startParams.GetParaParsedStr().c_str());
385 22 : if (&StackcoreSetSubdirectory != nullptr) {
386 22 : (void)StackcoreSetSubdirectory("udf");
387 : }
388 22 : const pid_t aicpuPid = static_cast<pid_t>(startParams.GetAicpuPid());
389 22 : const uint32_t vfId = startParams.GetVfId();
390 22 : const uint32_t deviceId = startParams.GetDeviceId();
391 22 : const pid_t hostPid = static_cast<pid_t>(startParams.GetHostPid());
392 22 : const uint32_t mode = startParams.GetProfilingMode();
393 22 : if (!startParams.HasTsdPid()) {
394 14 : if (!aicpu::AddToCgroup(deviceId, vfId)) {
395 1 : return -1;
396 : }
397 : }
398 :
399 : // Init custom op executor
400 21 : AicpuSchedule::CustomOpExecutor::GetInstance().InitOpExecutor(hostPid, startParams.GetCustSoPath());
401 21 : AicpuSchedule::AicpuEventManager::GetInstance().InitEventManager(false, true);
402 42 : int32_t ret = AicpuSchedule::AicpuScheduleInterface::GetInstance().InitAICPUScheduler(deviceId, hostPid,
403 42 : startParams.GetPidSign(), mode, aicpuPid, vfId, true);
404 21 : if (ret != AicpuSchedule::AICPU_SCHEDULE_OK) {
405 1 : aicpusd_err("Aicpu custom schedule start failed, ret[%d].", ret);
406 1 : (void)AicpuSchedule::AicpuScheduleInterface::GetInstance().StopAICPUScheduler(deviceId);
407 1 : return -1;
408 : }
409 20 : const pid_t tsdPid = startParams.HasTsdPid() ? startParams.GetTsdPid() : getppid();
410 20 : AicpuSchedule::AicpuScheduleInterface::GetInstance().SetAicpuSdProcId(aicpuPid);
411 20 : AicpuSchedule::AicpuScheduleInterface::GetInstance().SetTsdProcId(tsdPid);
412 20 : const char_t * const libPath = getenv("LD_LIBRARY_PATH");
413 20 : if (libPath == nullptr) {
414 0 : aicpusd_run_info("Aicpu schedule start success, but LD_LIBRARY_PATH is empty.");
415 : } else {
416 20 : aicpusd_run_info("Aicpu schedule start success, LD_LIBRARY_PATH=%s.", libPath);
417 : }
418 20 : AicpuSchedule::RegCreateCustMc2MaintenanceThreadCallBack();
419 20 : AicpuSchedule::RegOpenCustSoCallBack();
420 : // response start message to tsd
421 20 : int32_t rspRet = static_cast<int32_t>(tsd::TSD_OK);
422 20 : if (startParams.GetGrpNameNum() > 0U) {
423 19 : rspRet = StartUpRspAndWaitProcess(deviceId, TSD_CUSTOM_COMPUTE, static_cast<uint32_t>(hostPid), vfId);
424 : } else {
425 1 : rspRet = StartupResponse(deviceId, TSD_CUSTOM_COMPUTE, static_cast<uint32_t>(hostPid), vfId);
426 : }
427 :
428 20 : if (rspRet != static_cast<int32_t>(tsd::TSD_OK)) {
429 5 : aicpusd_err("Cust aicpu startup response return not ok, error_code=%d", rspRet);
430 5 : return -1;
431 : }
432 15 : aicpusd_info("cust aicpu startup response return success");
433 :
434 15 : (void)SendVfMsgToDrv(VM_QOS_PROCESS_STARTUP, deviceId, vfId);
435 : // do group attach
436 15 : if (!AttachHostGroup(startParams.GetGrpNameList(), startParams.GetGrpNameNum())) {
437 4 : aicpusd_err("AttachHostGroup execute failed.");
438 4 : return -1;
439 : }
440 :
441 11 : if (startParams.GetGrpNameNum() > 0U) {
442 10 : aicpusd_run_info("Cust Aicpu schedule attach and init success.");
443 10 : AicpuSchedule::AicpuEventManager::GetInstance().SendCtrlCpuMsg(
444 : aicpuPid, static_cast<uint32_t>(TsdSubEventType::TSD_EVENT_STOP_AICPU_PROCESS_WAIT), nullptr, 0U);
445 : }
446 :
447 : // wait for shutdown
448 11 : const int32_t waitRet = WaitForShutDown(deviceId);
449 11 : if (waitRet != static_cast<int32_t>(tsd::TSD_OK)) {
450 1 : aicpusd_err("wait for shut down return not ok, error code[%d].", waitRet);
451 1 : ret = -1;
452 : } else {
453 10 : aicpusd_info("wait for shut down success");
454 10 : ret = 0;
455 : }
456 11 : (void)AicpuSchedule::AicpuScheduleInterface::GetInstance().StopAICPUScheduler(deviceId);
457 11 : aicpusd_run_info("Aicpu custom schedule stopped.");
458 11 : (void)SendVfMsgToDrv(VM_QOS_PROCESS_SUSPEND, deviceId, vfId);
459 11 : if (&DlogFlush != nullptr) {
460 11 : DlogFlush();
461 : }
462 11 : return ret;
463 37 : } catch (const std::exception &e) {
464 0 : aicpusd_err("Execute main failed, reason=%s", e.what());
465 0 : return -1;
466 0 : }
467 : }
468 : }
|