1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #include "cpu_boost_wrapper.h" 16 #include "cpp/task.h" 17 #include "dfx/log/ffrt_log_api.h" 18 #include "internal_inc/osal.h" 19 #include "sched/execute_ctx.h" 20 #include "tm/task_base.h" 21 #include "c/ffrt_cpu_boost.h" 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 API_ATTRIBUTE((visibility("default"))) ffrt_cpu_boost_start(int ctx_id)28int ffrt_cpu_boost_start(int ctx_id) 29 { 30 int ret = CpuBoostStart(ctx_id); 31 if (ret == 0) { 32 if (ffrt::ExecuteCtx::Cur() == nullptr) { 33 FFRT_SYSEVENT_LOGW("ExecuteCtx::Cur() is nullptr, save ctxId failed"); 34 return ret; 35 } 36 ffrt::CoTask* curTask = ffrt::IsCoTask(ffrt::ExecuteCtx::Cur()->task) ? 37 static_cast<ffrt::CoTask*>(ffrt::ExecuteCtx::Cur()->task) : nullptr; 38 if (curTask != nullptr && curTask->cpuBoostCtxId < 0) { 39 curTask->cpuBoostCtxId = ctx_id; 40 } 41 } 42 return ret; 43 } 44 45 API_ATTRIBUTE((visibility("default"))) ffrt_cpu_boost_end(int ctx_id)46int ffrt_cpu_boost_end(int ctx_id) 47 { 48 int ret = CpuBoostEnd(ctx_id); 49 if (ret == 0) { 50 if (ffrt::ExecuteCtx::Cur() == nullptr) { 51 FFRT_SYSEVENT_LOGW("ExecuteCtx::Cur() is nullptr, clear ctxId failed"); 52 return ret; 53 } 54 ffrt::CoTask* curTask = ffrt::IsCoTask(ffrt::ExecuteCtx::Cur()->task) ? 55 static_cast<ffrt::CoTask*>(ffrt::ExecuteCtx::Cur()->task) : nullptr; 56 if (curTask != nullptr && curTask->cpuBoostCtxId == ctx_id) { 57 curTask->cpuBoostCtxId = -1; 58 } 59 } 60 return ret; 61 } 62 #ifdef __cplusplus 63 } 64 #endif