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