1 /*
2  * Copyright (C) 2021 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef ANDROID_PRIVATE_NATIVE_PERFORMANCE_HINT_PRIVATE_H
18 #define ANDROID_PRIVATE_NATIVE_PERFORMANCE_HINT_PRIVATE_H
19 
20 #include <stdint.h>
21 #include <android/performance_hint.h>
22 
23 __BEGIN_DECLS
24 
25 /**
26  * For testing only.
27  */
28 void APerformanceHint_setIHintManagerForTesting(void* iManager);
29 
30 /**
31  * Hints for the session used to signal upcoming changes in the mode or workload.
32  */
33 enum SessionHint: int32_t {
34     /**
35      * This hint indicates a sudden increase in CPU workload intensity. It means
36      * that this hint session needs extra CPU resources immediately to meet the
37      * target duration for the current work cycle.
38      */
39     CPU_LOAD_UP = 0,
40     /**
41      * This hint indicates a decrease in CPU workload intensity. It means that
42      * this hint session can reduce CPU resources and still meet the target duration.
43      */
44     CPU_LOAD_DOWN = 1,
45     /*
46      * This hint indicates an upcoming CPU workload that is completely changed and
47      * unknown. It means that the hint session should reset CPU resources to a known
48      * baseline to prepare for an arbitrary load, and must wake up if inactive.
49      */
50     CPU_LOAD_RESET = 2,
51     /*
52      * This hint indicates that the most recent CPU workload is resuming after a
53      * period of inactivity. It means that the hint session should allocate similar
54      * CPU resources to what was used previously, and must wake up if inactive.
55      */
56     CPU_LOAD_RESUME = 3,
57 
58     /**
59      * This hint indicates an increase in GPU workload intensity. It means that
60      * this hint session needs extra GPU resources to meet the target duration.
61      * This hint must be sent before reporting the actual duration to the session.
62      */
63     GPU_LOAD_UP = 5,
64 
65     /**
66      * This hint indicates a decrease in GPU workload intensity. It means that
67      * this hint session can reduce GPU resources and still meet the target duration.
68      */
69     GPU_LOAD_DOWN = 6,
70 
71     /*
72      * This hint indicates an upcoming GPU workload that is completely changed and
73      * unknown. It means that the hint session should reset GPU resources to a known
74      * baseline to prepare for an arbitrary load, and must wake up if inactive.
75      */
76     GPU_LOAD_RESET = 7,
77 };
78 
79 // Allows access to PowerHAL's SessionTags without needing to import its AIDL
80 enum class SessionTag : int32_t {
81   OTHER = 0,
82   SURFACEFLINGER = 1,
83   HWUI = 2,
84   GAME = 3,
85   APP = 4,
86 };
87 
88 /**
89  * Sends performance hints to inform the hint session of changes in the workload.
90  *
91  * @param session The performance hint session instance to update.
92  * @param hint The hint to send to the session.
93  * @return 0 on success
94  *         EPIPE if communication with the system service has failed.
95  */
96 int APerformanceHint_sendHint(APerformanceHintSession* session, SessionHint hint);
97 
98 /**
99  * Return the list of thread ids, this API should only be used for testing only.
100  */
101 int APerformanceHint_getThreadIds(APerformanceHintSession* session,
102                                   int32_t* const threadIds, size_t* const size);
103 
104 /**
105  * Creates a session with additional options
106  */
107 APerformanceHintSession* APerformanceHint_createSessionInternal(APerformanceHintManager* manager,
108                                         const int32_t* threadIds, size_t size,
109                                         int64_t initialTargetWorkDurationNanos, SessionTag tag);
110 
111 
112 __END_DECLS
113 
114 #endif // ANDROID_PRIVATE_NATIVE_PERFORMANCE_HINT_PRIVATE_H
115