• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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      * This hint indicates an upcoming CPU workload that is abnormally large and
80      * not representative of the workload. This should be used for rare, one-time
81      * operations and should be ignored by any load tracking or session hysteresis.
82      */
83     CPU_LOAD_SPIKE = 8,
84 
85     /**
86      * This hint indicates an upcoming GPU workload that is abnormally large and
87      * not representative of the workload. This should be used for rare, one-time
88      * operations and should be ignored by any load tracking or session hysteresis.
89      */
90     GPU_LOAD_SPIKE = 9,
91 };
92 
93 // Allows access to PowerHAL's SessionTags without needing to import its AIDL
94 enum class SessionTag : int32_t {
95   OTHER = 0,
96   SURFACEFLINGER = 1,
97   HWUI = 2,
98   GAME = 3,
99   APP = 4,
100   SYSUI = 5,
101 };
102 
103 /**
104  * Sends performance hints to inform the hint session of changes in the workload.
105  *
106  * @param session The performance hint session instance to update.
107  * @param hint The hint to send to the session.
108  * @return 0 on success
109  *         EPIPE if communication with the system service has failed.
110  */
111 int APerformanceHint_sendHint(APerformanceHintSession* session, SessionHint hint);
112 
113 /**
114  * Return the list of thread ids, this API should only be used for testing only.
115  */
116 int APerformanceHint_getThreadIds(APerformanceHintSession* session,
117                                   int32_t* const threadIds, size_t* const size);
118 
119 /**
120  * Creates a session with additional options
121  */
122 APerformanceHintSession* APerformanceHint_createSessionInternal(APerformanceHintManager* manager,
123                                         const int32_t* threadIds, size_t size,
124                                         int64_t initialTargetWorkDurationNanos, SessionTag tag);
125 /**
126  * Creates a session using ASessionCreationConfig
127  */
128 int APerformanceHint_createSessionUsingConfigInternal(
129         APerformanceHintManager* manager,
130         ASessionCreationConfig* config,
131         APerformanceHintSession** sessionOut,
132         SessionTag tag);
133 
134 /**
135  * Creates a session from the Java SDK implementation
136  */
137 APerformanceHintSession* APerformanceHint_createSessionFromJava(APerformanceHintManager* manager,
138                                         const int32_t* threadIds, size_t size,
139                                         int64_t initialTargetWorkDurationNanos);
140 
141 /**
142  * Special method for Java SDK implementation to kill sessions
143  */
144 void APerformanceHint_closeSessionFromJava(APerformanceHintSession* session);
145 
146 /**
147  * Forces FMQ to be enabled or disabled, for testing only.
148  */
149 void APerformanceHint_setUseFMQForTesting(bool enabled);
150 
151 /**
152  * Get the rate limiter properties for testing.
153  */
154 void APerformanceHint_getRateLimiterPropertiesForTesting(
155         int32_t* maxLoadHintsPerInterval, int64_t* loadHintInterval);
156 
157 /*
158  * Forces the "new load hint" flag to be disabled for testing.
159  */
160 void APerformanceHint_setUseNewLoadHintBehaviorForTesting(bool newBehavior);
161 
162 /*
163  * Forces the graphics pipeline flag to be enabled or disabled, for testing only.
164  */
165 void APerformanceHint_setUseGraphicsPipelineForTesting(bool enabled);
166 
167 __END_DECLS
168 
169 #endif // ANDROID_PRIVATE_NATIVE_PERFORMANCE_HINT_PRIVATE_H
170