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 "datadump/datadump_interface.h"
12 : #include "aicpusd_util.h"
13 : #include "profiling_adp.h"
14 : #include "core/aicpusd_interface_process.h"
15 : #include "core/aicpusd_event_manager.h"
16 : #include "core/aicpusd_threads_process.h"
17 : #include "core/aicpusd_cust_so_manager.h"
18 : #include "core/aicpusd_msg_send.h"
19 : #include "aicpusd_monitor.h"
20 : #include "aicpusd_lastword.h"
21 : #include "dump_task.h"
22 : #include "common/aicpusd_util.h"
23 : #include "common/aicpusd_context.h"
24 : #include "dump_task.h"
25 : #include "aicpu_engine.h"
26 : #include "tsd.h"
27 :
28 : extern "C" {
29 1 : int32_t InitAICPUDatadump(const uint32_t deviceId, const pid_t hostPid)
30 : {
31 4 : if (AicpuSchedule::AicpuUtil::IsEnvValEqual("AICPU_APP_LOG_SWITCH", "0")) {
32 0 : aicpusd_info("AICPU_APP_LOG_SWITCH is setted to 0 to switch off applog");
33 : } else {
34 1 : LogAttr logAttr = {};
35 1 : logAttr.type = APPLICATION;
36 1 : logAttr.pid = static_cast<uint32_t>(hostPid);
37 1 : logAttr.deviceId = deviceId;
38 1 : logAttr.mode = 0;
39 1 : if (DlogSetAttrAicpu(logAttr) != 0) {
40 0 : aicpusd_warn("Set log attr failed");
41 : }
42 : }
43 :
44 : // Make sure AicpusdLastword are created first,to ensure the last exit
45 1 : AicpuSchedule::AicpusdLastword::GetInstance();
46 2 : const std::vector<uint32_t> deviceVec{deviceId};
47 1 : auto deployContext = AicpuSchedule::DeployContext::DEVICE;
48 1 : const int32_t status = AicpuSchedule::GetAicpuDeployContext(deployContext);
49 1 : if (status != AicpuSchedule::AICPU_SCHEDULE_OK) {
50 0 : aicpusd_err("Get current deploy ctx failed.");
51 0 : return status;
52 : }
53 : process_sign pidSign;
54 1 : if (deployContext == AicpuSchedule::DeployContext::DEVICE) {
55 1 : const drvError_t ret = drvGetProcessSign(&pidSign);
56 1 : if (ret != DRV_ERROR_NONE) {
57 0 : aicpusd_err("Get process sign failed, ret[%d].", ret);
58 0 : return AICPU_SCHEDULE_FAIL;
59 : }
60 : } else {
61 0 : pidSign.sign[0U] = '\0';
62 : }
63 1 : aicpusd_info("Get process sign success");
64 6 : return AicpuSchedule::AicpuScheduleInterface::GetInstance().InitAICPUScheduler(deviceVec,
65 : hostPid,
66 : pidSign.sign,
67 : PROFILING_CLOSE,
68 : 0U,
69 1 : false);
70 1 : }
71 :
72 2 : int32_t StopAICPUDatadump(uint32_t deviceId, pid_t hostPid)
73 : {
74 : UNUSED(deviceId);
75 : UNUSED(hostPid);
76 2 : AicpuSchedule::OpDumpTaskManager::GetInstance().ClearResource();
77 2 : aicpusd_run_info("Successfully stopped AICPU scheduler, deviceId[%u], hostPid[%d].", deviceId, hostPid);
78 2 : return AicpuSchedule::AICPU_SCHEDULE_OK;
79 : }
80 : }
|