1484543d1Sopenharmony_ci/* 2484543d1Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd. 3484543d1Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4484543d1Sopenharmony_ci * you may not use this file except in compliance with the License. 5484543d1Sopenharmony_ci * You may obtain a copy of the License at 6484543d1Sopenharmony_ci * 7484543d1Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8484543d1Sopenharmony_ci * 9484543d1Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10484543d1Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11484543d1Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12484543d1Sopenharmony_ci * See the License for the specific language governing permissions and 13484543d1Sopenharmony_ci * limitations under the License. 14484543d1Sopenharmony_ci */ 15484543d1Sopenharmony_ci#ifndef OHOS_STANDARD_SYSTEM 16484543d1Sopenharmony_ci#include "cpu_boost_adapter.h" 17484543d1Sopenharmony_ci#else 18484543d1Sopenharmony_ci#include "cpu_boost_ohos.h" 19484543d1Sopenharmony_ci#endif 20484543d1Sopenharmony_ci#include "cpp/task.h" 21484543d1Sopenharmony_ci#include "dfx/log/ffrt_log_api.h" 22484543d1Sopenharmony_ci#include "internal_inc/osal.h" 23484543d1Sopenharmony_ci#include "sched/execute_ctx.h" 24484543d1Sopenharmony_ci#include "tm/cpu_task.h" 25484543d1Sopenharmony_ci#include "c/ffrt_cpu_boost.h" 26484543d1Sopenharmony_ci 27484543d1Sopenharmony_ci#ifdef __cplusplus 28484543d1Sopenharmony_ciextern "C" { 29484543d1Sopenharmony_ci#endif 30484543d1Sopenharmony_ci 31484543d1Sopenharmony_ciAPI_ATTRIBUTE((visibility("default"))) 32484543d1Sopenharmony_ciint ffrt_cpu_boost_start(int ctx_id) 33484543d1Sopenharmony_ci{ 34484543d1Sopenharmony_ci int ret = ffrt::CpuBoostStart(ctx_id); 35484543d1Sopenharmony_ci if (ret == 0) { 36484543d1Sopenharmony_ci ffrt::CPUEUTask* curTask = ffrt::ExecuteCtx::Cur()->task; 37484543d1Sopenharmony_ci if (curTask != nullptr && curTask->cpuBoostCtxId < 0) { 38484543d1Sopenharmony_ci curTask->cpuBoostCtxId = ctx_id; 39484543d1Sopenharmony_ci } 40484543d1Sopenharmony_ci } 41484543d1Sopenharmony_ci return ret; 42484543d1Sopenharmony_ci} 43484543d1Sopenharmony_ci 44484543d1Sopenharmony_ciAPI_ATTRIBUTE((visibility("default"))) 45484543d1Sopenharmony_ciint ffrt_cpu_boost_end(int ctx_id) 46484543d1Sopenharmony_ci{ 47484543d1Sopenharmony_ci int ret = ffrt::CpuBoostEnd(ctx_id); 48484543d1Sopenharmony_ci if (ret == 0) { 49484543d1Sopenharmony_ci ffrt::CPUEUTask* curTask = ffrt::ExecuteCtx::Cur()->task; 50484543d1Sopenharmony_ci if (curTask != nullptr && curTask->cpuBoostCtxId == ctx_id) { 51484543d1Sopenharmony_ci curTask->cpuBoostCtxId = -1; 52484543d1Sopenharmony_ci } 53484543d1Sopenharmony_ci } 54484543d1Sopenharmony_ci return ret; 55484543d1Sopenharmony_ci} 56484543d1Sopenharmony_ci#ifdef __cplusplus 57484543d1Sopenharmony_ci} 58484543d1Sopenharmony_ci#endif