Modify tid and pid from int to pid_t
[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  * @details The original cpu schedule configuration of the target process is backed up if it is currently not boosted.
36  *
37  * @privlevel partner
38  * @privilege http://tizen.org/privilege/internal/default/partner
39  *
40  * @param[in] pid The target process pid/tids \n
41  *                If pid.pid is nonzero, pid.tid and pid.tid_count are ignored, \n
42  *                                       and cpu boosting is applied for all the threads of pid.pid. \n
43  *                If pid.pid is zero and pid.tid is not NULL, all tids in pid.tid are used. \n
44  *                If pid.pid is zero and pid.tid is NULL, tid of the calling thread is used. \n
45  *                The caller must (de)allocate the buffer in the pid.tid pointer.
46  * @param[in] level The cpu boosting level
47  * @param[in] timeout_msec The timeout in milliseconds, -1 to apply boosting permanently
48  *
49  * @return 0 on success, otherwise a negative error value.
50  */
51 int resource_set_cpu_boosting (resource_pid_t pid, cpu_boosting_level_e level, int timeout_msec);
52
53 /**
54  * @brief Clear cpu boosting for the target process (pid/tids).
55  *
56  * @details The backed-up cpu schedule configuration of the target process is restored. \n
57  *          Without the backed-up configuration, the default non-boosting configuration (SCHED_OTHER and nice=0) is applied. \n
58  *
59  * @privlevel partner
60  * @privilege http://tizen.org/privilege/internal/default/partner
61  *
62  * @param[in] pid The target process pid/tids \n
63  *                If pid.pid is nonzero, pid.tid and pid.tid_count are ignored, \n
64  *                                       and cpu boosting is cleared for all the threads of pid.pid. \n
65  *                If pid.pid is zero and pid.tid is not NULL, all tids in pid.tid are used. \n
66  *                If pid.pid is zero and pid.tid is NULL, tid of the calling thread is used. \n
67  *                The caller must (de)allocate the buffer in the pid.tid pointer.
68  *
69  * @return 0 on success, otherwise a negative error value.
70  */
71 int resource_clear_cpu_boosting (resource_pid_t pid);
72
73 /**
74  * @brief Get the cpu boosting level for the target process (pid/tids).
75  *
76  * @param[in] pid The target process pid/tids \n
77  *                If pid.pid is nonzero, pid.tid and pid.tid_count are ignored, \n
78  *                                       and all the threads of pid.pid are checked. \n
79  *                If pid.pid is zero and pid.tid is not NULL, all tids in pid.tid are checked. \n
80  *                If pid.pid is zero and pid.tid is NULL, the calling thread is checked. \n
81  *                The caller must (de)allocate the buffer in the pid.tid pointer.
82  * @param[out] level The boosting level for the target process (pid/tids) \n
83  *                   level->tid_level will be allocated and filled with cpu_boosting_level_e for tids requested by the pid argument. \n
84  *                   The caller must deallocate the buffer in the level->tid_level pointer after using it.
85  *
86  * @return 0 on success, otherwise a negative error value.
87  */
88 int resource_get_cpu_boosting_level (resource_pid_t pid, cpu_boosting_level_info_t *level);
89
90 /**
91  * @brief Set cpu resource inheritance from the source tid to the destination process (pid/tids).
92  *
93  * @privlevel partner
94  * @privilege http://tizen.org/privilege/internal/default/partner
95  *
96  * @param[in] source_tid The caller thread tid
97  * @param[in] dest_process The name of destination process
98  * @param[in] timeout_msec The timeout in milliseconds, -1 to apply inheritance permanently
99  *
100  * @return 0 on success, otherwise a negative error value.
101  */
102 int resource_set_cpu_inheritance (pid_t source_tid, const char *dest_process, int timeout_msec);
103
104 /**
105  * @brief Clear cpu resource inheritance from the source tid to the destination process (pid/tids).
106  *
107  * @privlevel partner
108  * @privilege http://tizen.org/privilege/internal/default/partner
109  *
110  * @param[in] source_tid The caller thread's tid
111  * @param[in] dest_process The name of destination process
112  *
113  * @return 0 on success, otherwise a negative error value.
114  */
115 int resource_clear_cpu_inheritance (pid_t source_tid, const char *dest_process);
116
117 /**
118  * @brief Register a destination process (pid/tids) for cpu resource inheritance.
119  *
120  * @privlevel partner
121  * @privilege http://tizen.org/privilege/internal/default/partner
122  *
123  * @param[in] dest_process The name of destination process
124  * @param[in] pid The destination process pid/tids \n
125  *                If pid.pid is nonzero, pid.tid and pid.tid_count are ignored, \n
126  *                                       and all the threads of pid.pid are registered. \n
127  *                If pid.pid is zero and pid.tid is not NULL, all tids in pid.tid are registered. \n
128  *                If pid.pid is zero and pid.tid is NULL, tid of the calling thread is registered. \n
129  *                The caller must (de)allocate the buffer in the pid.tid pointer.
130  *
131  * @return 0 on success, otherwise a negative error value.
132  */
133 int resource_register_cpu_inheritance_destination (const char *dest_process, resource_pid_t pid);
134
135 /**
136  * @brief Unregister a destination process for cpu resource inheritance.
137  *
138  * @privlevel partner
139  * @privilege http://tizen.org/privilege/internal/default/partner
140  *
141  * @param[in] dest_process The name of destination process
142  *
143  * @return 0 on success, otherwise a negative error value.
144  */
145 int resource_unregister_cpu_inheritance_destination (const char *dest_process);
146
147
148 #ifdef __cplusplus
149 }
150 #endif
151
152 #endif  // __TIZEN_SYSTEM_CPU_BOOSTING_H__