LCOV - code coverage report
Current view: top level - tsdclient/src - thread_mode_manager.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 87.7 % 276 242
Test Date: 2026-07-28 10:52:48 Functions: 96.3 % 27 26

            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 "inc/thread_mode_manager.h"
      12              : #include "driver/ascend_hal.h"
      13              : #include "tsd_log.h"
      14              : #include "tsd_util_func.h"
      15              : #include "env_internal_api.h"
      16              : #include "package_worker.h"
      17              : #include "package_worker_utils.h"
      18              : 
      19              : namespace {
      20              : const uint32_t SUB_PROC_PARAM_LIST_MAX_COUNT = 128U;
      21              : constexpr uint32_t MAX_PROCESS_PID_CNT = 1024U;
      22              : } // namespace
      23              : namespace tsd {
      24            7 : ThreadModeManager::ThreadModeManager(const uint32_t& deviceId)
      25              :     : ClientManager(deviceId),
      26            7 :       startAicpu_(nullptr),
      27            7 :       stopAicpu_(nullptr),
      28            7 :       updateProfiling_(nullptr),
      29            7 :       setAicpuCallback_(nullptr),
      30            7 :       handle_(nullptr),
      31            7 :       vfId_(0),
      32            7 :       qsHandle_(nullptr),
      33            7 :       tfSoHandle_(nullptr),
      34            7 :       startQs_(nullptr),
      35            7 :       adprofHandle_(nullptr),
      36            7 :       startAdprof_(nullptr),
      37            7 :       stopAdprof_(nullptr)
      38            7 : {}
      39              : 
      40           13 : void ThreadModeManager::OpenTfSo(const uint32_t vfId)
      41              : {
      42           13 :     if (tfSoHandle_ != nullptr) {
      43           13 :         return;
      44              :     }
      45           13 :     std::string homeEnv = "";
      46           13 :     GetEnvFromMmSys(MM_ENV_HOME, "HOME", homeEnv);
      47           13 :     if (homeEnv == "") {
      48           13 :         TSD_RUN_INFO("get HOME PATH abnormal.");
      49           13 :         return;
      50              :     }
      51            0 :     std::string tfLibraryPath = homeEnv + "/aicpu_kernels/" + std::to_string(vfId) + "/aicpu_kernels_device/sand_box/";
      52            0 :     if (access(tfLibraryPath.c_str(), R_OK) != 0) {
      53            0 :         TSD_RUN_INFO("access tf path %s abnormal:%s.", tfLibraryPath.c_str(), SafeStrerror().c_str());
      54            0 :         return;
      55              :     }
      56            0 :     tfLibraryPath += "libtensorflow.so";
      57            0 :     tfSoHandle_ = mmDlopen(tfLibraryPath.c_str(), RTLD_GLOBAL | RTLD_NOW);
      58            0 :     if (tfSoHandle_ == nullptr) {
      59            0 :         TSD_RUN_INFO("cannot open %s: [%s]", tfLibraryPath.c_str(), dlerror());
      60            0 :         return;
      61              :     }
      62            0 :     TSD_INFO("OpenTfSo success home[%s], vfid[%u][%s]", homeEnv.c_str(), vfId, tfLibraryPath.c_str());
      63           13 : }
      64              : 
      65            8 : TSD_StatusT ThreadModeManager::Open(const uint32_t rankSize)
      66              : {
      67            8 :     TSD_RUN_INFO("[ThreadModeManager] enter into open process deviceId[%u] rankSize[%u]", logicDeviceId_, rankSize);
      68            8 :     const TSD_StatusT ret = LoadSysOpKernel();
      69            8 :     if (ret != TSD_OK) {
      70            1 :         TSD_ERROR("[ThreadModeManager] check aicpu opkernel failed");
      71            1 :         if (ret >= TSD_SUBPROCESS_NUM_EXCEED_THE_LIMIT) {
      72            1 :             return ret;
      73              :         }
      74            0 :         return TSD_CLT_OPEN_FAILED;
      75              :     }
      76            7 :     (void)OpenTfSo(vfId_);
      77            7 :     if (StartCallAICPU() != TSD_OK) {
      78            1 :         TSD_ERROR("[ThreadModeManager] failed call aicpu.");
      79            1 :         return TSD_CLT_OPEN_FAILED;
      80              :     }
      81            6 :     return TSD_OK;
      82              : }
      83              : 
      84            0 : TSD_StatusT ThreadModeManager::OpenAicpuSd()
      85              : {
      86            0 :     TSD_ERROR("[ThreadModeManager] OpenAicpuSd is not supported");
      87            0 :     return TSD_INTERNAL_ERROR;
      88              : }
      89              : 
      90            3 : TSD_StatusT ThreadModeManager::CapabilityGet(const int32_t type, const uint64_t ptr)
      91              : {
      92            3 :     if (type == TSD_CAPABILITY_ADPROF) {
      93            2 :         bool* const resultPtr = reinterpret_cast<bool*>(static_cast<uintptr_t>(ptr));
      94            2 :         if (resultPtr == nullptr) {
      95            1 :             TSD_ERROR("input ptr is null");
      96            1 :             return TSD_INTERNAL_ERROR;
      97              :         }
      98            1 :         *resultPtr = true;
      99              :     }
     100            2 :     return TSD_OK;
     101              : }
     102              : 
     103            5 : TSD_StatusT ThreadModeManager::StartCallAICPU()
     104              : {
     105            5 :     TSD_StatusT ret = TSD_OK;
     106            5 :     if (handle_ == nullptr) {
     107            2 :         const std::string libPath = "/usr/lib64/libaicpu_scheduler.so";
     108            2 :         handle_ = mmDlopen(libPath.c_str(), MMPA_RTLD_NOW | MMPA_RTLD_GLOBAL);
     109            2 :         if (handle_ == nullptr) {
     110            1 :             TSD_RUN_WARN(
     111              :                 "[ThreadModeManager] Cannot open libaicpu_scheduler.so, deviceId[%u], reason[%s]", logicDeviceId_,
     112              :                 dlerror());
     113            1 :             const std::string helperPath = "libaicpu_scheduler.so";
     114            1 :             handle_ = mmDlopen(helperPath.c_str(), MMPA_RTLD_NOW | MMPA_RTLD_GLOBAL);
     115            1 :             if (handle_ == nullptr) {
     116            1 :                 ret = TSD_INTERNAL_ERROR;
     117            1 :                 TSD_ERROR(
     118              :                     "[ThreadModeManager] failed open libaicpu_scheduler.so, deviceId[%u], reason[%s]", logicDeviceId_,
     119              :                     dlerror());
     120            1 :                 return ret;
     121              :             }
     122            1 :         }
     123            1 :         startAicpu_ = reinterpret_cast<StartAICPU>(mmDlsym(handle_, "InitAICPUScheduler"));
     124            1 :         stopAicpu_ = reinterpret_cast<StopAICPU>(mmDlsym(handle_, "StopAICPUScheduler"));
     125            1 :         updateProfiling_ = reinterpret_cast<UpdateProfiling>(mmDlsym(handle_, "UpdateProfilingMode"));
     126            1 :         setAicpuCallback_ = reinterpret_cast<SetAICPUCallback>(mmDlsym(handle_, "AicpuSetMsprofReporterCallback"));
     127            1 :         if ((startAicpu_ == nullptr) || (stopAicpu_ == nullptr) || (updateProfiling_ == nullptr) ||
     128            1 :             (setAicpuCallback_ == nullptr)) {
     129            0 :             TSD_ERROR("[ThreadModeManager] failed mmDlsym aicpu-sd function, deviceId[%u]", logicDeviceId_);
     130            0 :             return TSD_INTERNAL_ERROR;
     131              :         }
     132            2 :     }
     133            4 :     SetAICPUProfilingCallback();
     134            4 :     const int32_t devicePid = static_cast<int32_t>(getpid());
     135            4 :     TSD_INFO(
     136              :         "[ThreadModeManager] InitAICPUScheduler, deviceId[%u], devicePid[%d], profilingMode_[%d]", logicDeviceId_,
     137              :         devicePid, profilingMode_);
     138              : #ifdef NOT_COVERAGE_BY_UT
     139              :     const uint32_t deviceId = logicDeviceId_;
     140              :     const int32_t result = (*startAicpu_)(deviceId, devicePid, profilingMode_);
     141              :     if (result != 0) {
     142              :         ret = TSD_INTERNAL_ERROR;
     143              :         TSD_ERROR(
     144              :             "[ThreadModeManager] failed call aicpu interface, logicDeviceId_=%u, result=%d", logicDeviceId_, result);
     145              :     }
     146              : #endif
     147            4 :     return ret;
     148              : }
     149              : 
     150            4 : void ThreadModeManager::SetAICPUProfilingCallback() const
     151              : {
     152            4 :     const std::lock_guard<std::mutex> lk(g_profilingCallbackMut);
     153            4 :     if (g_profilingCallback == nullptr) {
     154            0 :         TSD_RUN_INFO("[ThreadModeManager] profiling callback is nullptr, skip set aicpu profiling callback");
     155            0 :         return;
     156              :     }
     157              : 
     158              : #ifdef NOT_COVERAGE_BY_UT
     159              :     const int32_t result = (*setAicpuCallback_)(g_profilingCallback);
     160              :     if (result != 0) {
     161              :         TSD_ERROR(
     162              :             "[ThreadModeManager] failed call aicpu AicpuSetMsprofReporterCallback interface, "
     163              :             "deviceId_[%u], result[%d]",
     164              :             logicDeviceId_, result);
     165              :     }
     166              : #endif
     167            4 :     TSD_RUN_INFO("[ThreadModeManager] profiling callback call finish");
     168            4 : }
     169              : 
     170            1 : TSD_StatusT ThreadModeManager::Close(const uint32_t flag)
     171              : {
     172              :     (void)flag;
     173            1 :     TSD_StatusT ret = TSD_OK;
     174            1 :     if (handle_ == nullptr) {
     175            0 :         TSD_INFO("[TsdClient] don't need to stop because no start");
     176            0 :         return ret;
     177              :     }
     178            1 :     const int32_t devicePid = static_cast<int32_t>(getpid());
     179            1 :     TSD_INFO("[TsdClient] StopAICPUScheduler, deviceId[%u], devicePid[%d]", logicDeviceId_, devicePid);
     180              : #ifdef NOT_COVERAGE_BY_UT
     181              :     const int32_t result = (*stopAicpu_)(logicDeviceId_, devicePid);
     182              :     if (result != 0) {
     183              :         ret = TSD_DEVICEID_ERROR;
     184              :         TSD_ERROR("[TsdClient] failed call aicpu interface, logicDeviceId=%u, result=%d", logicDeviceId_, result);
     185              :     }
     186              : #endif
     187            1 :     return ret;
     188              : }
     189              : 
     190            2 : TSD_StatusT ThreadModeManager::UpdateProfilingConf(const uint32_t& flag)
     191              : {
     192            2 :     TSD_StatusT ret = TSD_OK;
     193            2 :     if (handle_ == nullptr) {
     194            1 :         TSD_ERROR("[TsdClient] don't need to update profiling mode because no start");
     195            1 :         return TSD_CLT_UPDATE_PROFILING_FAILED;
     196              :     }
     197              : 
     198              : #ifdef NOT_COVERAGE_BY_UT
     199              :     const int32_t devicePid = static_cast<int32_t>(getpid());
     200              :     TSD_INFO("[TsdClient] UpdateProfilingCallAICPU, logicDeviceId=%u, devicePid=%d", logicDeviceId_, devicePid);
     201              :     const int32_t result = (*updateProfiling_)(logicDeviceId_, devicePid, flag);
     202              :     if (result != 0) {
     203              :         ret = TSD_DEVICEID_ERROR;
     204              :         TSD_ERROR(
     205              :             "[TsdClient] failed call aicpu update profiling interface, logicDeviceId=%u, result=%d", logicDeviceId_,
     206              :             result);
     207              :     }
     208              : #endif
     209            1 :     return ret;
     210              : }
     211              : 
     212            9 : TSD_StatusT ThreadModeManager::LoadSysOpKernel()
     213              : {
     214            9 :     if (!CheckPackageExists()) {
     215            1 :         TSD_RUN_INFO("[TsdClient][deviceId_=%u] cannot find aicpu packages", logicDeviceId_);
     216            1 :         return TSD_OK;
     217              :     }
     218              : 
     219            8 :     std::vector<uint32_t> packageTypes;
     220            8 :     packageTypes.push_back(static_cast<uint32_t>(TsdLoadPackageType::TSD_PKG_TYPE_AICPU_KERNEL));
     221            8 :     packageTypes.push_back(static_cast<uint32_t>(TsdLoadPackageType::TSD_PKG_TYPE_AICPU_EXTEND_KERNEL));
     222              : 
     223            8 :     TSD_StatusT ret = 0;
     224           20 :     for (const uint32_t packageType : packageTypes) {
     225           14 :         ret = HandleAICPUPackage(packageType);
     226           14 :         if (ret != TSD_OK) {
     227            2 :             TSD_ERROR("[TsdClient][deviceId_=%u] handle aicpu package to device failed, ret[%u]", logicDeviceId_, ret);
     228            2 :             if (ret >= TSD_SUBPROCESS_NUM_EXCEED_THE_LIMIT) {
     229            2 :                 return ret;
     230              :             }
     231            1 :             return TSD_INTERNAL_ERROR;
     232              :         }
     233              :     }
     234              : 
     235            6 :     return TSD_OK;
     236            8 : }
     237              : 
     238           11 : TSD_StatusT ThreadModeManager::HandleAICPUPackage(const uint32_t packageType) const
     239              : {
     240           11 :     if (packageName_[packageType] == "") {
     241            6 :         TSD_RUN_INFO(
     242              :             "[TsdClient][deviceId_=%u] package is not existed, skip send, packageType[%u]", logicDeviceId_,
     243              :             packageType);
     244            6 :         return TSD_OK;
     245              :     }
     246              : 
     247            5 :     const uint32_t vfId = static_cast<uint32_t>(vfId_);
     248            5 :     const std::shared_ptr<PackageWorker> worker = PackageWorker::GetInstance(logicDeviceId_, vfId);
     249            5 :     TSD_CHECK_NULLPTR(worker, TSD_MEMORY_EXHAUSTED, "PackageWorker is nullptr");
     250              : 
     251            5 :     const std::string srcPath = packagePath_[packageType];
     252            5 :     TSD_StatusT ret = TSD_OK;
     253            5 :     if (packageType == static_cast<uint32_t>(TsdLoadPackageType::TSD_PKG_TYPE_AICPU_KERNEL)) {
     254            5 :         ret = worker->LoadPackage(PackageWorkerType::PACKAGE_WORKER_AICPU_THREAD, srcPath, packageName_[packageType]);
     255            0 :     } else if (packageType == static_cast<uint32_t>(TsdLoadPackageType::TSD_PKG_TYPE_AICPU_EXTEND_KERNEL)) {
     256            0 :         ret = worker->LoadPackage(PackageWorkerType::PACKAGE_WORKER_EXTEND_THREAD, srcPath, packageName_[packageType]);
     257              :     }
     258            5 :     if (ret != TSD_OK) {
     259            1 :         TSD_ERROR(
     260              :             "[TsdClient][deviceId_=%u] Load package file[%s] failed, path[%s] packageType[%u]", logicDeviceId_,
     261              :             packageName_[packageType].c_str(), srcPath.c_str(), packageType);
     262            1 :         if (ret >= TSD_SUBPROCESS_NUM_EXCEED_THE_LIMIT) {
     263            1 :             return ret;
     264              :         }
     265            0 :         return TSD_INTERNAL_ERROR;
     266              :     }
     267              : 
     268            4 :     return TSD_OK;
     269            5 : }
     270              : 
     271           20 : void ThreadModeManager::Destroy()
     272              : {
     273           20 :     if (tfSoHandle_ != nullptr) {
     274            0 :         (void)mmDlclose(tfSoHandle_);
     275            0 :         TSD_INFO("[TsdClient] close aicpu-sd so");
     276            0 :         tfSoHandle_ = nullptr;
     277              :     }
     278           20 :     if (handle_ != nullptr) {
     279            1 :         (void)mmDlclose(handle_);
     280            1 :         TSD_INFO("[TsdClient] close aicpu-sd so");
     281            1 :         handle_ = nullptr;
     282            1 :         startAicpu_ = nullptr;
     283            1 :         stopAicpu_ = nullptr;
     284            1 :         updateProfiling_ = nullptr;
     285            1 :         setAicpuCallback_ = nullptr;
     286              :     }
     287           20 :     if (qsHandle_ != nullptr) {
     288            1 :         (void)mmDlclose(qsHandle_);
     289            1 :         TSD_INFO("[TsdClient] close QS so");
     290            1 :         qsHandle_ = nullptr;
     291            1 :         startQs_ = nullptr;
     292              :     }
     293           20 :     if (adprofHandle_ != nullptr) {
     294            6 :         (void)mmDlclose(adprofHandle_);
     295            6 :         TSD_INFO("[TsdClient] close adporf so");
     296            6 :         adprofHandle_ = nullptr;
     297            6 :         startAdprof_ = nullptr;
     298            6 :         stopAdprof_ = nullptr;
     299              :     }
     300           20 : }
     301              : 
     302           10 : ThreadModeManager::~ThreadModeManager() { Destroy(); }
     303              : 
     304            3 : TSD_StatusT ThreadModeManager::InitQs(const InitFlowGwInfo* const initInfo)
     305              : {
     306              :     (void)initInfo;
     307            3 :     if (StartCallQS(logicDeviceId_) != TSD_OK) {
     308            2 :         TSD_ERROR("[TsdClient] handle aicpu package to device failed");
     309            2 :         return TSD_INTERNAL_ERROR;
     310              :     }
     311            1 :     TSD_RUN_INFO("[TsdClient][logicDeviceId_=%u] start QS process success", logicDeviceId_);
     312            1 :     return TSD_OK;
     313              : }
     314              : 
     315            3 : TSD_StatusT ThreadModeManager::StartCallQS(const uint32_t logicDeviceId)
     316              : {
     317            3 :     TSD_StatusT ret = LoadQsLibrary();
     318            3 :     if (ret != TSD_OK) {
     319            2 :         return ret;
     320              :     }
     321              : #ifdef NOT_COVERAGE_BY_UT
     322              :     TSD_INFO("[TsdClient] QS Initial, logicDeviceId=%u", logicDeviceId);
     323              :     uint32_t qsReschedIntervalValue = 0U;
     324              :     std::string qsReschedInterval;
     325              :     GetEnvFromMmSys(MM_ENV_QS_RESCHED_INTEVAL, "QS_RESCHED_INTEVAL", qsReschedInterval);
     326              :     if (qsReschedInterval.empty()) {
     327              :         TSD_INFO(
     328              :             "QS_RESCHED_INTEVAL[%s] env variable does not exist or its value is invalid", qsReschedInterval.c_str());
     329              :     } else {
     330              :         try {
     331              :             qsReschedIntervalValue = static_cast<uint32_t>(std::stoi(qsReschedInterval));
     332              :         } catch (...) {
     333              :             TSD_INFO("QS_RESCHED_INTEVAL[%s] env variable cannot convert to uint32 value", qsReschedInterval.c_str());
     334              :         }
     335              :     }
     336              :     const int32_t result = (*startQs_)(logicDeviceId, static_cast<uint32_t>(qsReschedIntervalValue));
     337              :     if (result != 0) {
     338              :         ret = TSD_INTERNAL_ERROR;
     339              :         TSD_ERROR(
     340              :             "[TsdClient] failed call QS interface, logicDeviceId=%u, result=%d, reschedInterval=%d", logicDeviceId,
     341              :             result, qsReschedIntervalValue);
     342              :     }
     343              : #endif
     344            1 :     return ret;
     345              : }
     346              : 
     347            3 : TSD_StatusT ThreadModeManager::LoadQsLibrary()
     348              : {
     349            3 :     if (qsHandle_ != nullptr) {
     350            0 :         return TSD_OK;
     351              :     }
     352            3 :     qsHandle_ = mmDlopen("/usr/lib64/libqueue_schedule.so", MMPA_RTLD_NOW);
     353            3 :     if (qsHandle_ == nullptr) {
     354            1 :         qsHandle_ = mmDlopen("libqueue_schedule.so", MMPA_RTLD_NOW);
     355              :     }
     356            3 :     if (qsHandle_ == nullptr) {
     357            1 :         TSD_ERROR(
     358              :             "[ThreadModeManager] failed open libqueue_schedule.so, deviceId[%u], reason[%s]", logicDeviceId_,
     359              :             mmDlerror());
     360            1 :         return TSD_INTERNAL_ERROR;
     361              :     }
     362            2 :     if (mmDlsym(qsHandle_, "InitQueueScheduler") == nullptr) {
     363            1 :         TSD_ERROR("[TsdClient] InitQueueScheduler is nullptr, symbol lost");
     364              :     }
     365            2 :     startQs_ = reinterpret_cast<StartQS>(mmDlsym(qsHandle_, "InitQueueScheduler"));
     366            2 :     if (startQs_ == nullptr) {
     367            1 :         (void)mmDlclose(qsHandle_);
     368            1 :         qsHandle_ = nullptr;
     369            1 :         TSD_ERROR("[TsdClient] failed mmDlsym QS function, logicDeviceId=%u", logicDeviceId_);
     370            1 :         return TSD_INTERNAL_ERROR;
     371              :     }
     372            1 :     return TSD_OK;
     373              : }
     374              : 
     375            1 : TSD_StatusT ThreadModeManager::LoadFileToDevice(
     376              :     const char_t* const filePath, const uint64_t pathLen, const char_t* const fileName, const uint64_t fileNameLen)
     377              : {
     378              :     (void)filePath;
     379              :     (void)pathLen;
     380              :     (void)fileName;
     381              :     (void)fileNameLen;
     382            1 :     return TSD_INTERNAL_ERROR;
     383              : }
     384              : 
     385           10 : TSD_StatusT ThreadModeManager::ProcessOpenSubProc(ProcOpenArgs* openArgs)
     386              : {
     387           10 :     if (openArgs == nullptr) {
     388            2 :         TSD_ERROR("openArgs is nullptr");
     389            2 :         return TSD_INTERNAL_ERROR;
     390              :     }
     391            8 :     TSD_RUN_INFO(
     392              :         "[ThreadModeManager] enter into ProcessOpenSubProc subtype:%u", static_cast<uint32_t>(openArgs->procType));
     393            8 :     if (openArgs->procType != TSD_SUB_PROC_ADPROF) {
     394            1 :         TSD_ERROR(
     395              :             "[ThreadModeManager] open in thread mode is not supported, procType:%u",
     396              :             static_cast<uint32_t>(openArgs->procType));
     397            1 :         return TSD_INTERNAL_ERROR;
     398              :     }
     399              : 
     400            7 :     TSD_StatusT ret = LoadAdprofLibrary();
     401            7 :     if (ret != TSD_OK) {
     402            2 :         return ret;
     403              :     }
     404              : 
     405            5 :     if (openArgs->extParamCnt > SUB_PROC_PARAM_LIST_MAX_COUNT) {
     406            0 :         TSD_ERROR("extParamList too long, extParamCnt:%u", static_cast<uint32_t>(openArgs->extParamCnt));
     407            0 :         return TSD_INTERNAL_ERROR;
     408              :     }
     409              : 
     410            5 :     std::vector<std::string> extParamList;
     411            5 :     char_t* argv[SUB_PROC_PARAM_LIST_MAX_COUNT + 1] = {nullptr};
     412           10 :     for (uint64_t index = 0; index < openArgs->extParamCnt; index++) {
     413            5 :         extParamList.emplace_back(openArgs->extParamList[index].paramInfo, openArgs->extParamList[index].paramLen);
     414            5 :         TSD_INFO(
     415              :             "index:%llu, extra parameters:%s, len:%llu", index, extParamList[index].c_str(),
     416              :             openArgs->extParamList[index].paramLen);
     417            5 :         argv[index] = const_cast<char*>(extParamList[index].c_str());
     418              :     }
     419            5 :     const int32_t result = (*startAdprof_)(static_cast<int32_t>(openArgs->extParamCnt), (const char*)(&argv[0]));
     420            5 :     if (result != 0) {
     421            1 :         TSD_ERROR("[ThreadModeManager] failed call startAdprof logicDeviceId_=%u, result=%d", logicDeviceId_, result);
     422            1 :         return TSD_INTERNAL_ERROR;
     423              :     }
     424            4 :     return TSD_OK;
     425            5 : }
     426              : 
     427            7 : TSD_StatusT ThreadModeManager::LoadAdprofLibrary()
     428              : {
     429            7 :     if (adprofHandle_ != nullptr) {
     430            0 :         return TSD_OK;
     431              :     }
     432            7 :     adprofHandle_ = mmDlopen("libascend_devprof.so", MMPA_RTLD_NOW | MMPA_RTLD_GLOBAL);
     433            7 :     if (adprofHandle_ == nullptr) {
     434            1 :         TSD_ERROR(
     435              :             "[ThreadModeManager] failed open libascend_devprof.so, deviceId[%u], reason[%s]", logicDeviceId_,
     436              :             mmDlerror());
     437            1 :         return TSD_INTERNAL_ERROR;
     438              :     }
     439            6 :     startAdprof_ = reinterpret_cast<StartAdprof>(mmDlsym(adprofHandle_, "AdprofStart"));
     440            6 :     if (startAdprof_ == nullptr) {
     441            1 :         TSD_ERROR(
     442              :             "[ThreadModeManager] failed mmDlsym startAdprof function, deviceId[%u], reason[%s]", logicDeviceId_,
     443              :             mmDlerror());
     444            1 :         return TSD_INTERNAL_ERROR;
     445              :     }
     446            5 :     return TSD_OK;
     447              : }
     448              : 
     449            1 : TSD_StatusT ThreadModeManager::ProcessCloseSubProc(const pid_t closePid)
     450              : {
     451              :     (void)closePid;
     452            1 :     return TSD_INTERNAL_ERROR;
     453              : }
     454              : 
     455            1 : TSD_StatusT ThreadModeManager::GetSubProcStatus(ProcStatusInfo* pidInfo, const uint32_t arrayLen)
     456              : {
     457              :     (void)pidInfo;
     458              :     (void)arrayLen;
     459            1 :     return TSD_INTERNAL_ERROR;
     460              : }
     461              : 
     462            1 : TSD_StatusT ThreadModeManager::RemoveFileOnDevice(const char_t* const filePath, const uint64_t pathLen)
     463              : {
     464              :     (void)filePath;
     465              :     (void)pathLen;
     466            1 :     return TSD_INTERNAL_ERROR;
     467              : }
     468              : 
     469            7 : TSD_StatusT ThreadModeManager::ProcessCloseSubProcList(const ProcStatusParam* closeList, const uint32_t listSize)
     470              : {
     471            7 :     if ((listSize == 0U) || (closeList == nullptr)) {
     472            2 :         TSD_ERROR("[ThreadModeManager]closeList is nullptr or pid list size invalid:%u", listSize);
     473            2 :         return TSD_INTERNAL_ERROR;
     474              :     }
     475            5 :     TSD_RUN_INFO("[ThreadModeManager] enter ExecuteClosePidList cnt:%u, procType:%u", listSize, closeList[0].procType);
     476            5 :     if (closeList[0].procType != TSD_SUB_PROC_ADPROF) {
     477            1 :         TSD_ERROR(
     478              :             "[ThreadModeManager] close in thread mode is not supported, procType:%u",
     479              :             static_cast<uint32_t>(closeList[0].procType));
     480            1 :         return TSD_INTERNAL_ERROR;
     481              :     }
     482              : 
     483            4 :     if (adprofHandle_ == nullptr) {
     484            1 :         TSD_RUN_INFO("[ThreadModeManager] don't need to stop because no start");
     485            1 :         return TSD_OK;
     486              :     }
     487              : 
     488            3 :     if (stopAdprof_ == nullptr) {
     489            3 :         stopAdprof_ = reinterpret_cast<StopAdprof>(mmDlsym(adprofHandle_, "AdprofStop"));
     490            3 :         if (stopAdprof_ == nullptr) {
     491            0 :             TSD_ERROR("[ThreadModeManager] failed mmDlsym stopAdprof function, deviceId[%u]", logicDeviceId_);
     492            0 :             return TSD_INTERNAL_ERROR;
     493              :         }
     494              :     }
     495              : 
     496            3 :     TSD_INFO("[ThreadModeManager] stopAdprof, deviceId[%u]", logicDeviceId_);
     497            3 :     const int32_t result = (*stopAdprof_)();
     498            3 :     if (result != 0) {
     499            0 :         TSD_ERROR("[ThreadModeManager] failed call stopAdprof logicDeviceId_=%u, result=%d", logicDeviceId_, result);
     500            0 :         return TSD_INTERNAL_ERROR;
     501              :     }
     502              : 
     503            3 :     return TSD_OK;
     504              : }
     505              : 
     506            2 : TSD_StatusT ThreadModeManager::GetSubProcListStatus(ProcStatusParam* pidInfo, const uint32_t arrayLen)
     507              : {
     508            2 :     if ((pidInfo == nullptr) || (arrayLen == 0U) || (arrayLen > MAX_PROCESS_PID_CNT)) {
     509            1 :         TSD_ERROR("input param is error");
     510            1 :         return TSD_INTERNAL_ERROR;
     511              :     }
     512              : 
     513            1 :     TSD_RUN_INFO(
     514              :         "[ThreadModeManager] enter into GetSubProcListStatus, arrayLen:%u, procType:%u", arrayLen, pidInfo[0].procType);
     515            1 :     if (pidInfo[0].procType == TSD_SUB_PROC_ADPROF) {
     516            1 :         pidInfo[0].curStat = SUB_PROCESS_STATUS_NORMAL;
     517              :     }
     518              : 
     519            1 :     return TSD_OK;
     520              : }
     521            1 : TSD_StatusT ThreadModeManager::CloseNetService() { return TSD_CLOSE_NOT_SUPPORT_NET_SERVICE; }
     522            1 : TSD_StatusT ThreadModeManager::OpenNetService(const NetServiceOpenArgs* args)
     523              : {
     524              :     (void)args;
     525            1 :     return TSD_OPEN_NOT_SUPPORT_NET_SERVICE;
     526              : }
     527              : } // namespace tsd
        

Generated by: LCOV version 2.0-1