Improve explanation in cpu boosting API specification
[platform/core/api/resource.git] / include / cpu-boosting.h
1 /* MIT License
2  *
3  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy
6  * of this software and associated documentation files (the "Software"), to deal
7  * in the Software without restriction, including without limitation the rights
8  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9  * copies of the Software, and to permit persons to whom the Software is furnished
10  * to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in all
13  * copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21  * THE SOFTWARE. */
22
23 #ifndef __TIZEN_SYSTEM_CPU_BOOSTING_H__
24 #define __TIZEN_SYSTEM_CPU_BOOSTING_H__
25
26 #include "cpu-boosting-type.h"
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31
32 /**
33  * @brief Set cpu boosting for the target process (pid/tids).
34  *
35  * @remarks The original cpu schedule configuration of the target process is backed up if it is currently not boosted. \n
36  * @param[in] pid The target process pid/tids \n
37  *                If pid.pid is nonzero, pid.tid and pid.tid_count are ignored, \n
38  *                                       and cpu boosting is applied for all the threads of pid.pid. \n
39  *                If pid.pid is zero and pid.tid is not NULL, all tids in the list are used \n
40  *                If pid.pid is zero and pid.tid is NULL, tid of the calling thread is used. \n
41  *                The caller must (de)allocate the buffer in the pid.tid pointer.
42  * @param[in] level The cpu boosting level
43  * @param[in] timeout_msec The timeout in milliseconds, -1 to apply boosting permanently
44  *
45  * @return 0 on success, otherwise a negative error value.
46  */
47 int resource_set_cpu_boosting (resource_pid_t pid, cpu_boosting_level_e level, int timeout_msec);
48
49 /**
50  * @brief Clear cpu boosting for the target process (pid/tids).
51  *
52  * @remarks The backed-up cpu schedule configuration of the target process is restored. \n
53  *          Without the backed-up configuration, the default non-boosting configuration (SCHED_OTHER and nice=0) is applied. \n
54  * @param[in] pid The target process pid/tids \n
55  *                If pid.pid is nonzero, pid.tid and pid.tid_count are ignored, \n
56  *                                       and cpu boosting is cleared for all the threads of pid.pid. \n
57  *                If pid.pid is zero and pid.tid is not NULL, all tids in the list are used \n
58  *                If pid.pid is zero and pid.tid is NULL, tid of the calling thread is used. \n
59  *                The caller must (de)allocate the buffer in the pid.tid pointer.
60  *
61  * @return 0 on success, otherwise a negative error value.
62  */
63 int resource_clear_cpu_boosting (resource_pid_t pid);
64
65 /**
66  * @brief Get the cpu boosting level for the target process (pid/tids).
67  *
68  * @param[in] pid The target process pid/tids \n
69  *                If pid.pid is nonzero, pid.tid and pid.tid_count are ignored, \n
70  *                                       and all the threads of pid.pid are checked. \n
71  *                If pid.pid is zero and pid.tid is not NULL, all tids in the list are checked. \n
72  *                If pid.pid is zero and pid.tid is NULL, the calling thread is checked. \n
73  *                The caller must (de)allocate the buffer in the pid.tid pointer.
74  * @param[out] level The boosting level for the target process (pid/tids) \n
75  *                   The level->tid_level array will be filled with cpu_boosting_level_e for tids requested by the pid argument. \n
76  *                   The caller must (de)allocate the buffer in the level.tid_level pointer.
77  *
78  * @return 0 on success, otherwise a negative error value.
79  */
80 int resource_get_cpu_boosting_level (resource_pid_t pid, cpu_boosting_level_info_t *level);
81
82 /**
83  * @brief Set cpu resource inheritance from the source tid to the destination process (pid/tids).
84  *
85  * @param[in] source_tid The caller thread tid
86  * @param[in] dest_process The name of destination process
87  * @param[in] timeout_msec The timeout in milliseconds, -1 to apply inheritance permanently
88  *
89  * @return 0 on success, otherwise a negative error value.
90  */
91 int resource_set_cpu_inheritance (int source_tid, const char *dest_process, int timeout_msec);
92
93 /**
94  * @brief Clear cpu resource inheritance from the source tid to the destination process (pid/tids).
95  *
96  * @param[in] source_tid The caller thread's tid
97  * @param[in] dest_process The name of destination process
98  *
99  * @return 0 on success, otherwise a negative error value.
100  */
101 int resource_clear_cpu_inheritance (int source_tid, const char *dest_process);
102
103 /**
104  * @brief Register a destination process (pid/tids) for cpu resource inheritance.
105  *
106  * @param[in] dest_process The name of destination process
107  * @param[in] pid The destination process pid/tids \n
108  *                If pid.pid is nonzero, pid.tid and pid.tid_count are ignored. \n
109  *                                       and all the threads of pid.pid are registered. \n
110  *                If pid.pid is zero and pid.tid is not NULL, all tids in the list are used \n
111  *                If pid.pid is zero and pid.tid is NULL, pid of the calling thread is used. \n
112  *                The caller must (de)allocate the buffer in the pid.tid pointer.
113  *
114  * @return 0 on success, otherwise a negative error value.
115  */
116 int resource_register_cpu_inheritance_destination (const char *dest_process, resource_pid_t pid);
117
118 /**
119  * @brief Unregister a destination process for cpu resource inheritance.
120  *
121  * @param[in] dest_process The name of destination process
122  *
123  * @return 0 on success, otherwise a negative error value.
124  */
125 int resource_unregister_cpu_inheritance_destination (const char *dest_process);
126
127
128 #ifdef __cplusplus
129 }
130 #endif
131
132 #endif  // __TIZEN_SYSTEM_CPU_BOOSTING_H__