• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/cpu_task.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)28 int 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_LOGW("ExecuteCtx::Cur() is nullptr, save ctxId failed");
34             return ret;
35         }
36         ffrt::CPUEUTask* curTask = ffrt::ExecuteCtx::Cur()->task;
37         if (curTask != nullptr && curTask->cpuBoostCtxId < 0) {
38             curTask->cpuBoostCtxId = ctx_id;
39         }
40     }
41     return ret;
42 }
43 
44 API_ATTRIBUTE((visibility("default")))
ffrt_cpu_boost_end(int ctx_id)45 int ffrt_cpu_boost_end(int ctx_id)
46 {
47     int ret = CpuBoostEnd(ctx_id);
48     if (ret == 0) {
49         if (ffrt::ExecuteCtx::Cur() == nullptr) {
50             FFRT_LOGW("ExecuteCtx::Cur() is nullptr, clear ctxId failed");
51             return ret;
52         }
53         ffrt::CPUEUTask* curTask = ffrt::ExecuteCtx::Cur()->task;
54         if (curTask != nullptr && curTask->cpuBoostCtxId == ctx_id) {
55             curTask->cpuBoostCtxId = -1;
56         }
57     }
58     return ret;
59 }
60 #ifdef __cplusplus
61 }
62 #endif