LCOV - code coverage report
Current view: top level - aicpu_schedule/core - aicpusd_resource_limit.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 88.2 % 34 30
Test Date: 2026-07-28 10:54:05 Functions: 100.0 % 1 1

            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 "aicpusd_resource_limit.h"
      12              : 
      13              : #include <string>
      14              : #include "aicpusd_util.h"
      15              : #include "aicpusd_status.h"
      16              : #include "aicpusd_context.h"
      17              : 
      18              : namespace AicpuSchedule {
      19              : static constexpr const uint32_t SLEEP_100_MSECS = 100000U;
      20              : static constexpr const uint32_t MAX_EXECUTE_TRY_TIMES = 3U;
      21           27 : bool AddToCgroup(const uint32_t deviceId, const uint32_t vfId)
      22              : {
      23           27 :     DeployContext deployCtx = DeployContext::DEVICE;
      24           27 :     (void)GetAicpuDeployContext(deployCtx);
      25           27 :     if ((FeatureCtrl::IsAosCore()) || (!FeatureCtrl::ShouldAddtocGroup()) || (AicpuUtil::IsFpga())) {
      26            1 :         aicpusd_run_info("No need to add cgroup");
      27            1 :         return true;
      28              :     }
      29              : 
      30           26 :     const uint32_t pid = static_cast<uint32_t>(drvDeviceGetBareTgid());
      31           52 :     std::string command = "cd /var/ && sudo ./tsdaemon_add_to_usermemory.sh";
      32           26 :     std::string pathStr = "/var/tsdaemon_add_to_usermemory.sh";
      33           26 :     if (access(pathStr.c_str(), F_OK) != 0) {
      34           25 :         pathStr = "/usr/local/Ascend/driver/tools/add_aicpu_tid_to_tasks.sh";
      35           25 :         if (access(pathStr.c_str(), F_OK) != 0) {
      36           25 :             aicpusd_info("Not find add_aicpu_tid_to_tasks.sh.");
      37           25 :             return true;
      38              :         }
      39            0 :         command = "cd /usr/local/Ascend/driver/tools/ && sudo ./tsdaemon_add_to_usermemory.sh";
      40              :     }
      41            1 :     command.append(" memory ")
      42            1 :            .append(std::to_string(pid))
      43            1 :            .append(" ")
      44            2 :            .append(std::to_string(deviceId))
      45            1 :            .append(" ")
      46            1 :            .append(std::to_string(vfId));
      47              : 
      48            1 :     int32_t status = -1;
      49            1 :     uint32_t tryTimes = 0;
      50            1 :     while (tryTimes <= MAX_EXECUTE_TRY_TIMES) {
      51            1 :         status = AicpuUtil::ExecuteCmd(command);
      52            1 :         if (status != 0) {
      53            0 :             aicpusd_run_warn("Adding to cgroup was not successful, ret:[%d], cmd:[%s]", status, command.c_str());
      54            0 :             (void)usleep(SLEEP_100_MSECS);
      55              :         } else {
      56            1 :             aicpusd_info("Add to cgroup successfully, cmd:[%s].", command.c_str());
      57            1 :             break;
      58              :         }
      59            0 :         tryTimes++;
      60              :     }
      61            1 :     aicpusd_run_info("Add to cgroup finished, cmd:[%s].", command.c_str());
      62            1 :     return true;
      63           26 : }
      64              : }
        

Generated by: LCOV version 2.0-1