LCOV - code coverage report
Current view: top level - legacy/ascend950/framework/communicator/aicpu/daemon - aicpu_daemon_service.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 91.7 % 36 33
Test Date: 2026-08-04 10:52:23 Functions: 100.0 % 5 5

            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 "aicpu_daemon_service.h"
      11              : #include "sal.h"
      12              : #include "log.h"
      13              : 
      14              : namespace Hccl {
      15              : 
      16              : constexpr u32 TEN_MILLISECOND_OF_USLEEP = 10000;
      17              : std::mutex AicpuDaemonService::mutexForFuncs_;
      18              : 
      19           14 : AicpuDaemonService &AicpuDaemonService::GetInstance()
      20              : {
      21           14 :     static AicpuDaemonService daemonService;
      22           14 :     return daemonService;
      23              : }
      24              : 
      25            1 : void AicpuDaemonService::ServiceRun(void *info)
      26              : {
      27            3 :     HCCL_RUN_INFO("Start background thread");
      28            1 :     auto commandToBackGroud = static_cast<CommandToBackGroud *>(info);
      29              :     while (true) {
      30            2 :         if (*commandToBackGroud == CommandToBackGroud::Stop) {
      31            3 :             HCCL_RUN_INFO("Background thread returned");
      32            1 :             break;
      33              :         }
      34              : 
      35            1 :         std::unique_lock<std::mutex> lock(mutexForFuncs_);
      36            5 :         for (auto &func : daemonFuncs) {
      37            4 :             func->Call();
      38            4 :             if (needBreak) {
      39            0 :                 break;
      40              :             }
      41              :         }
      42            1 :         lock.unlock();
      43              :         
      44            1 :         if (needBreak) {
      45            0 :             HCCL_RUN_INFO("Background thread needBreak");
      46            0 :             break;
      47              :         }
      48              : 
      49            1 :         SaluSleep(TEN_MILLISECOND_OF_USLEEP);
      50            2 :     }
      51            3 :     HCCL_RUN_INFO("Exit background thread");
      52            1 : }
      53              : 
      54            2 : void AicpuDaemonService::ServiceStop(void *info) const
      55              : {
      56            2 :     auto commandToBackGroud = static_cast<CommandToBackGroud *>(info);
      57            2 :     *commandToBackGroud     = CommandToBackGroud::Stop;
      58            6 :     HCCL_INFO("Stop background thread");
      59            2 : }
      60              : 
      61            4 : void AicpuDaemonService::Register(DaemonFunc *daemonFunc)
      62              : {
      63            4 :     std::unique_lock<std::mutex> lock(mutexForFuncs_);
      64            4 :     daemonFuncs.push_back(daemonFunc);
      65           12 :     HCCL_INFO("Background thread register daemonFunc");
      66            4 : }
      67              : 
      68            1 : void AicpuDaemonService::Break()
      69              : {
      70            1 :     needBreak = true;
      71            3 :     HCCL_INFO("Background thread received break");
      72            1 : }
      73              : }
        

Generated by: LCOV version 2.0-1