• 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 
16 #ifndef FFRT_INNER_API_C_TASK_H
17 #define FFRT_INNER_API_C_TASK_H
18 #include <stdint.h>
19 #include <stdbool.h>
20 #include "type_def_ext.h"
21 
22 /**
23  * @brief Skips a task.
24  *
25  * @param handle Indicates a task handle.
26  * @return Returns <b>0</b> if the task is skipped;
27            returns <b>-1</b> otherwise.
28  * @since 10
29  */
30 FFRT_C_API int ffrt_skip(ffrt_task_handle_t handle);
31 
32 /**
33  * @brief Sets cgroup attribute.
34  *
35  * @param qos Indicates the Qos, only support for qos_defined_ive.
36  * @param attr Indicates the cgroup attribute.
37  * @return Returns <b>0</b> if cgroup attribute set success;
38  *         returns <b>-1</b> if cgroup attribute set fail.
39  */
40 FFRT_C_API int ffrt_set_cgroup_attr(ffrt_qos_t qos, ffrt_os_sched_attr* attr);
41 
42 /**
43  * @brief Restore the ffrt threads attribute to the default value for all Qos.
44  */
45 FFRT_C_API void ffrt_restore_qos_config(void);
46 
47 /**
48  * @brief Sets the max num of ffrt threads in a QoS.
49  *
50  * @param qos Indicates the QoS.
51  * @param num Indicates the max num.
52  * @return Returns <b>0</b> if max num set success;
53  *         return <b>-1</b> if max num set fail;
54  */
55 FFRT_C_API int ffrt_set_cpu_worker_max_num(ffrt_qos_t qos, uint32_t num);
56 
57 /**
58  * @brief Sets whether the task notifies worker, only support for normal task.
59  *
60  * @param attr Indicates a pointer to the task attribute.
61  * @param notify Indicates whether the task notifies worker.
62  */
63 FFRT_C_API void ffrt_task_attr_set_notify_worker(ffrt_task_attr_t* attr, bool notify);
64 
65 /**
66  * @brief Notifies a specified number of workers at a specified QoS level.
67  *
68  * @param qos Indicates the QoS.
69  * @param number Indicates the number of workers to be notified.
70  */
71 FFRT_C_API void ffrt_notify_workers(ffrt_qos_t qos, int number);
72 
73 /**
74  * @brief Obtains the ID of this queue.
75  *
76  * @return Returns the queue ID.
77  */
78 FFRT_C_API int64_t ffrt_this_queue_get_id(void);
79 
80 /**
81  * @brief Enable the worker escape function (When all the worker threads under a QoS level fully block, the system will
82  * temporarily exceed the limit on the number of worker threads and create new worker threads to execute tasks).
83  * Delay penalty is added for escape function. As the number of threads increases, the thread creation delay increases.
84  * Calling this function does not take effect when the escape function is enabled.
85  *
86  * @param one_stage_interval_ms Indicates the interval for creating threads in one-stage, default value is 10ms.
87  *                              If input parameter value is smaller than the default value, the setting fails.
88  * @param two_stage_interval_ms Indicates the interval for creating threads in two-stage, default value is 100ms.
89  *                              If input parameter value is smaller than the default value, the setting fails.
90  * @param three_stage_interval_ms Indicates the interval for creating threads in three-stage, default value is 1000ms.
91  *                              If input parameter value is smaller than the default value, the setting fails.
92  * @param one_stage_worker_num Indicates the number of workers in one-stage.
93  * @param two_stage_worker_num Indicates the number of workers in two-stage.
94  * @return Returns 0 if the parameters are valid and the escape function is enabled successfully;
95  *         returns 1 otherwise.
96  */
97 FFRT_C_API int ffrt_enable_worker_escape(uint64_t one_stage_interval_ms, uint64_t two_stage_interval_ms,
98     uint64_t three_stage_interval_ms, uint64_t one_stage_worker_num, uint64_t two_stage_worker_num);
99 
100 /**
101  * @brief Disable the worker escape function (When all the worker threads under a QoS level fully block, the system will
102  * temporarily exceed the limit on the number of worker threads and create new worker threads to execute tasks).
103  */
104 FFRT_C_API void ffrt_disable_worker_escape(void);
105 
106 /**
107  * @brief Set the sched mode of the QoS.
108  */
109 FFRT_C_API void ffrt_set_sched_mode(ffrt_qos_t qos, ffrt_sched_mode mode);
110 #endif
111