LCOV - code coverage report
Current view: top level - tsdclient/src - thread_mode_manager.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 91.9 % 309 284
Test Date: 2026-08-31 10:06:05 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           41 : ThreadModeManager::ThreadModeManager(const uint32_t& deviceId)
      25              :     : ClientManager(deviceId),
      26           41 :       startAicpu_(nullptr),
      27           41 :       stopAicpu_(nullptr),
      28           41 :       updateProfiling_(nullptr),
      29           41 :       setAicpuCallback_(nullptr),
      30           41 :       handle_(nullptr),
      31           41 :       vfId_(0),
      32           41 :       qsHandle_(nullptr),
      33           41 :       tfSoHandle_(nullptr),
      34           41 :       startQs_(nullptr),
      35           41 :       adprofHandle_(nullptr),
      36           41 :       startAdprof_(nullptr),
      37           41 :       stopAdprof_(nullptr)
      38           41 : {}
      39              : 
      40            8 : void ThreadModeManager::OpenTfSo(const uint32_t vfId)
      41              : {
      42            8 :     if (tfSoHandle_ != nullptr) {
      43            7 :         return;
      44              :     }
      45            8 :     std::string homeEnv = "";
      46            8 :     GetEnvFromMmSys(MM_ENV_HOME, "HOME", homeEnv);
      47            8 :     if (homeEnv == "") {
      48            6 :         TSD_RUN_INFO("get HOME PATH abnormal.");
      49            6 :         return;
      50              :     }
      51            2 :     std::string tfLibraryPath = homeEnv + "/aicpu_kernels/" + std::to_string(vfId) + "/aicpu_kernels_device/sand_box/";
      52            2 :     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            2 :     tfLibraryPath += "libtensorflow.so";
      57            2 :     tfSoHandle_ = mmDlopen(tfLibraryPath.c_str(), RTLD_GLOBAL | RTLD_NOW);
      58            2 :     if (tfSoHandle_ == nullptr) {
      59            1 :         TSD_RUN_INFO("cannot open %s: [%s]", tfLibraryPath.c_str(), dlerror());
      60            1 :         return;
      61              :     }
      62            1 :     TSD_INFO("OpenTfSo success home[%s], vfid[%u][%s]", homeEnv.c_str(), vfId, tfLibraryPath.c_str());
      63            9 : }
      64              : 
      65            7 : TSD_StatusT ThreadModeManager::Open(const uint32_t rankSize)
      66              : {
      67            7 :     TSD_RUN_INFO("[ThreadModeManager] enter into open process deviceId[%u] rankSize[%u]", logicDeviceId_, rankSize);
      68            7 :     const TSD_StatusT ret = LoadSysOpKernel();
      69            7 :     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            6 :     (void)OpenTfSo(vfId_);
      77            6 :     if (StartCallAICPU() != TSD_OK) {
      78            2 :         TSD_ERROR("[ThreadModeManager] failed call aicpu.");
      79            2 :         return TSD_CLT_OPEN_FAILED;
      80              :     }
      81            4 :     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            4 : TSD_StatusT ThreadModeManager::StartCallAICPU()
     104              : {
     105            4 :     TSD_StatusT ret = TSD_OK;
     106            4 :     if (handle_ == nullptr) {
     107            4 :         const std::string libPath = "/usr/lib64/libaicpu_scheduler.so";
     108            4 :         handle_ = mmDlopen(libPath.c_str(), MMPA_RTLD_NOW | MMPA_RTLD_GLOBAL);
     109            4 :         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            3 :         startAicpu_ = reinterpret_cast<StartAICPU>(mmDlsym(handle_, "InitAICPUScheduler"));
     124            3 :         stopAicpu_ = reinterpret_cast<StopAICPU>(mmDlsym(handle_, "StopAICPUScheduler"));
     125            3 :         updateProfiling_ = reinterpret_cast<UpdateProfiling>(mmDlsym(handle_, "UpdateProfilingMode"));
     126            3 :         setAicpuCallback_ = reinterpret_cast<SetAICPUCallback>(mmDlsym(handle_, "AicpuSetMsprofReporterCallback"));
     127            3 :         if ((startAicpu_ == nullptr) || (stopAicpu_ == nullptr) || (updateProfiling_ == nullptr) ||
     128            3 :             (setAicpuCallback_ == nullptr)) {
     129            0 :             TSD_ERROR("[ThreadModeManager] failed mmDlsym aicpu-sd function, deviceId[%u]", logicDeviceId_);
     130            0 :             return TSD_INTERNAL_ERROR;
     131              :         }
     132            4 :     }
     133            3 :     SetAICPUProfilingCallback();
     134            3 :     const int32_t devicePid = static_cast<int32_t>(getpid());
     135            3 :     TSD_INFO(
     136              :         "[ThreadModeManager] InitAICPUScheduler, deviceId[%u], devicePid[%d], profilingMode_[%d]", logicDeviceId_,
     137              :         devicePid, profilingMode_);
     138              : #ifdef NOT_COVERAGE_BY_UT
     139            3 :     const uint32_t deviceId = logicDeviceId_;
     140            3 :     const int32_t result = (*startAicpu_)(deviceId, devicePid, profilingMode_);
     141            3 :     if (result != 0) {
     142            1 :         ret = TSD_INTERNAL_ERROR;
     143            1 :         TSD_ERROR(
     144              :             "[ThreadModeManager] failed call aicpu interface, logicDeviceId_=%u, result=%d", logicDeviceId_, result);
     145              :     }
     146              : #endif
     147            3 :     return ret;
     148              : }
     149              : 
     150            3 : void ThreadModeManager::SetAICPUProfilingCallback() const
     151              : {
     152            3 :     const std::lock_guard<std::mutex> lk(g_profilingCallbackMut);
     153            3 :     if (g_profilingCallback == nullptr) {
     154            2 :         TSD_RUN_INFO("[ThreadModeManager] profiling callback is nullptr, skip set aicpu profiling callback");
     155            2 :         return;
     156              :     }
     157              : 
     158              : #ifdef NOT_COVERAGE_BY_UT
     159            1 :     const int32_t result = (*setAicpuCallback_)(g_profilingCallback);
     160            1 :     if (result != 0) {
     161            0 :         TSD_ERROR(
     162              :             "[ThreadModeManager] failed call aicpu AicpuSetMsprofReporterCallback interface, "
     163              :             "deviceId_[%u], result[%d]",
     164              :             logicDeviceId_, result);
     165              :     }
     166              : #endif
     167            1 :     TSD_RUN_INFO("[ThreadModeManager] profiling callback call finish");
     168            3 : }
     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            1 :     const int32_t result = (*stopAicpu_)(logicDeviceId_, devicePid);
     182            1 :     if (result != 0) {
     183            0 :         ret = TSD_DEVICEID_ERROR;
     184            0 :         TSD_ERROR("[TsdClient] failed call aicpu interface, logicDeviceId=%u, result=%d", logicDeviceId_, result);
     185              :     }
     186              : #endif
     187            1 :     return ret;
     188              : }
     189              : 
     190            3 : TSD_StatusT ThreadModeManager::UpdateProfilingConf(const uint32_t flag)
     191              : {
     192            3 :     TSD_StatusT ret = TSD_OK;
     193            3 :     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            2 :     const int32_t devicePid = static_cast<int32_t>(getpid());
     200            2 :     TSD_INFO("[TsdClient] UpdateProfilingCallAICPU, logicDeviceId=%u, devicePid=%d", logicDeviceId_, devicePid);
     201            2 :     const int32_t result = (*updateProfiling_)(logicDeviceId_, devicePid, flag);
     202            2 :     if (result != 0) {
     203            1 :         ret = TSD_DEVICEID_ERROR;
     204            1 :         TSD_ERROR(
     205              :             "[TsdClient] failed call aicpu update profiling interface, logicDeviceId=%u, result=%d", logicDeviceId_,
     206              :             result);
     207              :     }
     208              : #endif
     209            2 :     return ret;
     210              : }
     211              : 
     212            8 : TSD_StatusT ThreadModeManager::LoadSysOpKernel()
     213              : {
     214            8 :     if (!CheckPackageExists()) {
     215            3 :         TSD_RUN_INFO("[TsdClient][deviceId_=%u] cannot find aicpu packages", logicDeviceId_);
     216            3 :         return TSD_OK;
     217              :     }
     218              : 
     219            5 :     std::vector<uint32_t> packageTypes;
     220            5 :     packageTypes.push_back(static_cast<uint32_t>(TsdLoadPackageType::TSD_PKG_TYPE_AICPU_KERNEL));
     221            5 :     packageTypes.push_back(static_cast<uint32_t>(TsdLoadPackageType::TSD_PKG_TYPE_AICPU_EXTEND_KERNEL));
     222              : 
     223            5 :     TSD_StatusT ret = 0;
     224           16 :     for (const uint32_t packageType : packageTypes) {
     225            8 :         ret = HandleAICPUPackage(packageType);
     226            8 :         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            3 :     return TSD_OK;
     236            5 : }
     237              : 
     238            5 : TSD_StatusT ThreadModeManager::HandleAICPUPackage(const uint32_t packageType) const
     239              : {
     240            5 :     if (packageName_[packageType] == "") {
     241            4 :         TSD_RUN_INFO(
     242              :             "[TsdClient][deviceId_=%u] package is not existed, skip send, packageType[%u]", logicDeviceId_,
     243              :             packageType);
     244            4 :         return TSD_OK;
     245              :     }
     246              : 
     247            1 :     const uint32_t vfId = static_cast<uint32_t>(vfId_);
     248            1 :     const std::shared_ptr<PackageWorker> worker = PackageWorker::GetInstance(logicDeviceId_, vfId);
     249            1 :     TSD_CHECK_NULLPTR(worker, TSD_MEMORY_EXHAUSTED, "PackageWorker is nullptr");
     250              : 
     251            1 :     const std::string srcPath = packagePath_[packageType];
     252            1 :     TSD_StatusT ret = TSD_OK;
     253            1 :     if (packageType == static_cast<uint32_t>(TsdLoadPackageType::TSD_PKG_TYPE_AICPU_KERNEL)) {
     254            1 :         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            1 :     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            0 :     return TSD_OK;
     269            1 : }
     270              : 
     271           54 : void ThreadModeManager::Destroy()
     272              : {
     273           54 :     if (tfSoHandle_ != nullptr) {
     274            1 :         (void)mmDlclose(tfSoHandle_);
     275            1 :         TSD_INFO("[TsdClient] close aicpu-sd so");
     276            1 :         tfSoHandle_ = nullptr;
     277              :     }
     278           54 :     if (handle_ != nullptr) {
     279            3 :         (void)mmDlclose(handle_);
     280            3 :         TSD_INFO("[TsdClient] close aicpu-sd so");
     281            3 :         handle_ = nullptr;
     282            3 :         startAicpu_ = nullptr;
     283            3 :         stopAicpu_ = nullptr;
     284            3 :         updateProfiling_ = nullptr;
     285            3 :         setAicpuCallback_ = nullptr;
     286              :     }
     287           54 :     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           54 :     if (adprofHandle_ != nullptr) {
     294            7 :         (void)mmDlclose(adprofHandle_);
     295            7 :         TSD_INFO("[TsdClient] close adprof so");
     296            7 :         adprofHandle_ = nullptr;
     297            7 :         startAdprof_ = nullptr;
     298            7 :         stopAdprof_ = nullptr;
     299              :     }
     300           54 : }
     301              : 
     302           44 : 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            1 :     TSD_INFO("[TsdClient] QS Initial, logicDeviceId=%u", logicDeviceId);
     323            1 :     uint32_t qsReschedIntervalValue = 0U;
     324            1 :     std::string qsReschedInterval;
     325            1 :     GetEnvFromMmSys(MM_ENV_QS_RESCHED_INTEVAL, "QS_RESCHED_INTEVAL", qsReschedInterval);
     326            1 :     if (qsReschedInterval.empty()) {
     327            1 :         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            0 :             qsReschedIntervalValue = static_cast<uint32_t>(std::stoi(qsReschedInterval));
     332            0 :         } catch (...) {
     333            0 :             TSD_INFO("QS_RESCHED_INTEVAL[%s] env variable cannot convert to uint32 value", qsReschedInterval.c_str());
     334            0 :         }
     335              :     }
     336            1 :     const int32_t result = (*startQs_)(logicDeviceId, static_cast<uint32_t>(qsReschedIntervalValue));
     337            1 :     if (result != 0) {
     338            0 :         ret = TSD_INTERNAL_ERROR;
     339            0 :         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            1 : }
     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            1 :         TSD_ERROR("openArgs is nullptr");
     389            1 :         return TSD_INTERNAL_ERROR;
     390              :     }
     391            9 :     TSD_RUN_INFO(
     392              :         "[ThreadModeManager] enter into ProcessOpenSubProc subtype:%u", static_cast<uint32_t>(openArgs->procType));
     393            9 :     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            8 :     const TSD_StatusT ret = LoadAdprofLibrary();
     401            8 :     if (ret != TSD_OK) {
     402            2 :         return ret;
     403              :     }
     404              : 
     405            6 :     if (openArgs->extParamCnt > SUB_PROC_PARAM_LIST_MAX_COUNT) {
     406            1 :         TSD_ERROR(
     407              :             "extParamList too long, extParamCnt:%u, max:%u", static_cast<uint32_t>(openArgs->extParamCnt),
     408              :             static_cast<uint32_t>(SUB_PROC_PARAM_LIST_MAX_COUNT));
     409            1 :         return TSD_INTERNAL_ERROR;
     410              :     }
     411              : 
     412            5 :     std::vector<std::string> extParamList;
     413            5 :     char_t* argv[SUB_PROC_PARAM_LIST_MAX_COUNT + 1] = {nullptr};
     414           10 :     for (uint64_t index = 0; index < openArgs->extParamCnt; index++) {
     415            5 :         extParamList.emplace_back(openArgs->extParamList[index].paramInfo, openArgs->extParamList[index].paramLen);
     416            5 :         TSD_INFO(
     417              :             "index:%llu, extra parameters:%s, len:%llu", index, extParamList[index].c_str(),
     418              :             openArgs->extParamList[index].paramLen);
     419            5 :         argv[index] = const_cast<char*>(extParamList[index].c_str());
     420              :     }
     421            5 :     const int32_t result = (*startAdprof_)(static_cast<int32_t>(openArgs->extParamCnt), (const char*)(&argv[0]));
     422            5 :     if (result != 0) {
     423            1 :         TSD_ERROR("[ThreadModeManager] failed call startAdprof logicDeviceId_=%u, result=%d", logicDeviceId_, result);
     424            1 :         return TSD_INTERNAL_ERROR;
     425              :     }
     426            4 :     return TSD_OK;
     427            5 : }
     428              : 
     429            8 : TSD_StatusT ThreadModeManager::LoadAdprofLibrary()
     430              : {
     431            8 :     if (adprofHandle_ != nullptr) {
     432            0 :         return TSD_OK;
     433              :     }
     434            8 :     adprofHandle_ = mmDlopen("libascend_devprof.so", MMPA_RTLD_NOW | MMPA_RTLD_GLOBAL);
     435            8 :     if (adprofHandle_ == nullptr) {
     436            1 :         TSD_ERROR(
     437              :             "[ThreadModeManager] failed open libascend_devprof.so, deviceId[%u], reason[%s]", logicDeviceId_,
     438              :             mmDlerror());
     439            1 :         return TSD_INTERNAL_ERROR;
     440              :     }
     441            7 :     startAdprof_ = reinterpret_cast<StartAdprof>(mmDlsym(adprofHandle_, "AdprofStart"));
     442            7 :     if (startAdprof_ == nullptr) {
     443            1 :         TSD_ERROR(
     444              :             "[ThreadModeManager] failed mmDlsym startAdprof function, deviceId[%u], reason[%s]", logicDeviceId_,
     445              :             mmDlerror());
     446            1 :         return TSD_INTERNAL_ERROR;
     447              :     }
     448            6 :     return TSD_OK;
     449              : }
     450              : 
     451            1 : TSD_StatusT ThreadModeManager::ProcessCloseSubProc(const pid_t closePid)
     452              : {
     453              :     (void)closePid;
     454            1 :     return TSD_INTERNAL_ERROR;
     455              : }
     456              : 
     457            1 : TSD_StatusT ThreadModeManager::GetSubProcStatus(ProcStatusInfo* pidInfo, const uint32_t arrayLen)
     458              : {
     459              :     (void)pidInfo;
     460              :     (void)arrayLen;
     461            1 :     return TSD_INTERNAL_ERROR;
     462              : }
     463              : 
     464            1 : TSD_StatusT ThreadModeManager::RemoveFileOnDevice(const char_t* const filePath, const uint64_t pathLen)
     465              : {
     466              :     (void)filePath;
     467              :     (void)pathLen;
     468            1 :     return TSD_INTERNAL_ERROR;
     469              : }
     470              : 
     471            6 : TSD_StatusT ThreadModeManager::ProcessCloseSubProcList(const ProcStatusParam* closeList, const uint32_t listSize)
     472              : {
     473            6 :     if ((listSize == 0U) || (closeList == nullptr)) {
     474            1 :         TSD_ERROR("[ThreadModeManager]closeList is nullptr or pid list size invalid:%u", listSize);
     475            1 :         return TSD_INTERNAL_ERROR;
     476              :     }
     477            5 :     TSD_RUN_INFO("[ThreadModeManager] enter ExecuteClosePidList cnt:%u, procType:%u", listSize, closeList[0].procType);
     478            5 :     if (closeList[0].procType != TSD_SUB_PROC_ADPROF) {
     479            1 :         TSD_ERROR(
     480              :             "[ThreadModeManager] close in thread mode is not supported, procType:%u",
     481              :             static_cast<uint32_t>(closeList[0].procType));
     482            1 :         return TSD_INTERNAL_ERROR;
     483              :     }
     484              : 
     485            4 :     if (adprofHandle_ == nullptr) {
     486            1 :         TSD_RUN_INFO("[ThreadModeManager] don't need to stop because no start");
     487            1 :         return TSD_OK;
     488              :     }
     489              : 
     490            3 :     if (stopAdprof_ == nullptr) {
     491            3 :         stopAdprof_ = reinterpret_cast<StopAdprof>(mmDlsym(adprofHandle_, "AdprofStop"));
     492            3 :         if (stopAdprof_ == nullptr) {
     493            1 :             TSD_ERROR("[ThreadModeManager] failed mmDlsym stopAdprof function, deviceId[%u]", logicDeviceId_);
     494            1 :             return TSD_INTERNAL_ERROR;
     495              :         }
     496              :     }
     497              : 
     498            2 :     TSD_INFO("[ThreadModeManager] stopAdprof, deviceId[%u]", logicDeviceId_);
     499            2 :     const int32_t result = (*stopAdprof_)();
     500            2 :     if (result != 0) {
     501            1 :         TSD_ERROR("[ThreadModeManager] failed call stopAdprof logicDeviceId_=%u, result=%d", logicDeviceId_, result);
     502            1 :         return TSD_INTERNAL_ERROR;
     503              :     }
     504              : 
     505            1 :     return TSD_OK;
     506              : }
     507              : 
     508            2 : TSD_StatusT ThreadModeManager::GetSubProcListStatus(ProcStatusParam* pidInfo, const uint32_t arrayLen)
     509              : {
     510            2 :     if ((pidInfo == nullptr) || (arrayLen == 0U) || (arrayLen > MAX_PROCESS_PID_CNT)) {
     511            1 :         TSD_ERROR("input param is error");
     512            1 :         return TSD_INTERNAL_ERROR;
     513              :     }
     514              : 
     515            1 :     TSD_RUN_INFO(
     516              :         "[ThreadModeManager] enter into GetSubProcListStatus, arrayLen:%u, procType:%u", arrayLen, pidInfo[0].procType);
     517            1 :     if (pidInfo[0].procType == TSD_SUB_PROC_ADPROF) {
     518            1 :         pidInfo[0].curStat = SUB_PROCESS_STATUS_NORMAL;
     519              :     }
     520              : 
     521            1 :     return TSD_OK;
     522              : }
     523            1 : TSD_StatusT ThreadModeManager::CloseNetService() { return TSD_CLOSE_NOT_SUPPORT_NET_SERVICE; }
     524            1 : TSD_StatusT ThreadModeManager::OpenNetService(const NetServiceOpenArgs* args)
     525              : {
     526              :     (void)args;
     527            1 :     return TSD_OPEN_NOT_SUPPORT_NET_SERVICE;
     528              : }
     529              : } // namespace tsd
        

Generated by: LCOV version 2.0-1