Skip to content

Commit 87cf0ef

Browse files
Ram IndaniAndroid (Google) Code Review
authored andcommitted
Merge changes I6c8dfb52,Iff26902c into main
* changes: [SF] increase jank threshold to 4 milliseconds Flag to increase jank threshold to 4 milliseconds
2 parents 5906db4 + 29b3d13 commit 87cf0ef

6 files changed

Lines changed: 38 additions & 20 deletions

File tree

services/surfaceflinger/FrameTimeline/FrameTimeline.cpp

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,11 @@ void SurfaceFrame::classifyJankLocked(int32_t displayFrameJankType, const Fps& r
611611
mFrameReadyMetadata = FrameReadyMetadata::OnTimeFinish;
612612
}
613613

614-
if (std::abs(presentDelta) > mJankClassificationThresholds.presentThreshold) {
614+
const nsecs_t presentThreshold =
615+
FlagManager::getInstance().increase_missed_frame_jank_threshold()
616+
? mJankClassificationThresholds.presentThresholdExtended
617+
: mJankClassificationThresholds.presentThresholdLegacy;
618+
if (std::abs(presentDelta) > presentThreshold) {
615619
mFramePresentMetadata = presentDelta > 0 ? FramePresentMetadata::LatePresent
616620
: FramePresentMetadata::EarlyPresent;
617621
// Jank that is missing by less than the render rate period is classified as partial jank,
@@ -629,9 +633,8 @@ void SurfaceFrame::classifyJankLocked(int32_t displayFrameJankType, const Fps& r
629633
} else if (mFramePresentMetadata == FramePresentMetadata::EarlyPresent) {
630634
if (mFrameReadyMetadata == FrameReadyMetadata::OnTimeFinish) {
631635
// Finish on time, Present early
632-
if (deltaToVsync < mJankClassificationThresholds.presentThreshold ||
633-
deltaToVsync >= refreshRate.getPeriodNsecs() -
634-
mJankClassificationThresholds.presentThreshold) {
636+
if (deltaToVsync < presentThreshold ||
637+
deltaToVsync >= refreshRate.getPeriodNsecs() - presentThreshold) {
635638
// Delta factor of vsync
636639
mJankType = JankType::SurfaceFlingerScheduling;
637640
} else {
@@ -667,9 +670,8 @@ void SurfaceFrame::classifyJankLocked(int32_t displayFrameJankType, const Fps& r
667670
if (!(mJankType & JankType::BufferStuffing)) {
668671
// In a stuffed state, if the app finishes on time and there is no display frame
669672
// jank, only buffer stuffing is the root cause of the jank.
670-
if (deltaToVsync < mJankClassificationThresholds.presentThreshold ||
671-
deltaToVsync >= refreshRate.getPeriodNsecs() -
672-
mJankClassificationThresholds.presentThreshold) {
673+
if (deltaToVsync < presentThreshold ||
674+
deltaToVsync >= refreshRate.getPeriodNsecs() - presentThreshold) {
673675
// Delta factor of vsync
674676
mJankType |= JankType::SurfaceFlingerScheduling;
675677
} else {
@@ -1091,7 +1093,11 @@ void FrameTimeline::DisplayFrame::classifyJank(nsecs_t& deadlineDelta, nsecs_t&
10911093
? std::abs(presentDelta) % mRefreshRate.getPeriodNsecs()
10921094
: 0;
10931095

1094-
if (std::abs(presentDelta) > mJankClassificationThresholds.presentThreshold) {
1096+
nsecs_t presentThreshold = FlagManager::getInstance().increase_missed_frame_jank_threshold()
1097+
? mJankClassificationThresholds.presentThresholdExtended
1098+
: mJankClassificationThresholds.presentThresholdLegacy;
1099+
1100+
if (std::abs(presentDelta) > presentThreshold) {
10951101
mFramePresentMetadata = presentDelta > 0 ? FramePresentMetadata::LatePresent
10961102
: FramePresentMetadata::EarlyPresent;
10971103
// Jank that is missing by less than the render rate period is classified as partial jank,
@@ -1122,9 +1128,8 @@ void FrameTimeline::DisplayFrame::classifyJank(nsecs_t& deadlineDelta, nsecs_t&
11221128
if (mFramePresentMetadata == FramePresentMetadata::EarlyPresent) {
11231129
if (mFrameReadyMetadata == FrameReadyMetadata::OnTimeFinish) {
11241130
// Finish on time, Present early
1125-
if (deltaToVsync < mJankClassificationThresholds.presentThreshold ||
1126-
deltaToVsync >= (mRefreshRate.getPeriodNsecs() -
1127-
mJankClassificationThresholds.presentThreshold)) {
1131+
if (deltaToVsync < presentThreshold ||
1132+
deltaToVsync >= (mRefreshRate.getPeriodNsecs() - presentThreshold)) {
11281133
// Delta is a factor of vsync if its within the presentTheshold on either side
11291134
// of the vsyncPeriod. Example: 0-2ms and 9-11ms are both within the threshold
11301135
// of the vsyncPeriod if the threshold was 2ms and the vsyncPeriod was 11ms.
@@ -1142,7 +1147,7 @@ void FrameTimeline::DisplayFrame::classifyJank(nsecs_t& deadlineDelta, nsecs_t&
11421147
}
11431148
} else if (mFramePresentMetadata == FramePresentMetadata::LatePresent) {
11441149
if (std::abs(mSurfaceFlingerPredictions.presentTime - previousPresentTime) <=
1145-
mJankClassificationThresholds.presentThreshold ||
1150+
presentThreshold ||
11461151
previousPresentTime > mSurfaceFlingerPredictions.presentTime) {
11471152
// The previous frame was either presented in the current frame's expected vsync or
11481153
// it was presented even later than the current frame's expected vsync.
@@ -1151,9 +1156,8 @@ void FrameTimeline::DisplayFrame::classifyJank(nsecs_t& deadlineDelta, nsecs_t&
11511156
if (mFrameReadyMetadata == FrameReadyMetadata::OnTimeFinish &&
11521157
!(mJankType & JankType::SurfaceFlingerStuffing)) {
11531158
// Finish on time, Present late
1154-
if (deltaToVsync < mJankClassificationThresholds.presentThreshold ||
1155-
deltaToVsync >= (mRefreshRate.getPeriodNsecs() -
1156-
mJankClassificationThresholds.presentThreshold)) {
1159+
if (deltaToVsync < presentThreshold ||
1160+
deltaToVsync >= (mRefreshRate.getPeriodNsecs() - presentThreshold)) {
11571161
// Delta is a factor of vsync if its within the presentTheshold on either side
11581162
// of the vsyncPeriod. Example: 0-2ms and 9-11ms are both within the threshold
11591163
// of the vsyncPeriod if the threshold was 2ms and the vsyncPeriod was 11ms.
@@ -1165,8 +1169,7 @@ void FrameTimeline::DisplayFrame::classifyJank(nsecs_t& deadlineDelta, nsecs_t&
11651169
} else if (mFrameReadyMetadata == FrameReadyMetadata::LateFinish) {
11661170
if (!(mJankType & JankType::SurfaceFlingerStuffing) ||
11671171
mSurfaceFlingerActuals.presentTime - previousPresentTime >
1168-
mRefreshRate.getPeriodNsecs() +
1169-
mJankClassificationThresholds.presentThreshold) {
1172+
mRefreshRate.getPeriodNsecs() + presentThreshold) {
11701173
// Classify CPU vs GPU if SF wasn't stuffed or if SF was stuffed but this frame
11711174
// was presented more than a vsync late.
11721175
if (mGpuFence != FenceTime::NO_FENCE) {

services/surfaceflinger/FrameTimeline/FrameTimeline.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,10 @@ struct TimelineItem {
107107
struct JankClassificationThresholds {
108108
// The various thresholds for App and SF. If the actual timestamp falls within the threshold
109109
// compared to prediction, we treat it as on time.
110-
nsecs_t presentThreshold = std::chrono::duration_cast<std::chrono::nanoseconds>(2ms).count();
110+
nsecs_t presentThresholdLegacy =
111+
std::chrono::duration_cast<std::chrono::nanoseconds>(2ms).count();
112+
nsecs_t presentThresholdExtended =
113+
std::chrono::duration_cast<std::chrono::nanoseconds>(4ms).count();
111114
nsecs_t deadlineThreshold = std::chrono::duration_cast<std::chrono::nanoseconds>(0ms).count();
112115
nsecs_t startThreshold = std::chrono::duration_cast<std::chrono::nanoseconds>(2ms).count();
113116
};

services/surfaceflinger/common/FlagManager.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ void FlagManager::dump(std::string& result) const {
126126
DUMP_ACONFIG_FLAG(adpf_native_session_manager);
127127
DUMP_ACONFIG_FLAG(adpf_use_fmq_channel);
128128
DUMP_ACONFIG_FLAG(graphite_renderengine_preview_rollout);
129+
DUMP_ACONFIG_FLAG(increase_missed_frame_jank_threshold);
129130
DUMP_ACONFIG_FLAG(refresh_rate_overlay_on_external_display);
130131

131132
/// Trunk stable readonly flags ///
@@ -300,6 +301,7 @@ FLAG_MANAGER_ACONFIG_FLAG(refresh_rate_overlay_on_external_display, "")
300301
FLAG_MANAGER_ACONFIG_FLAG(adpf_gpu_sf, "")
301302
FLAG_MANAGER_ACONFIG_FLAG(adpf_native_session_manager, "");
302303
FLAG_MANAGER_ACONFIG_FLAG(graphite_renderengine_preview_rollout, "");
304+
FLAG_MANAGER_ACONFIG_FLAG(increase_missed_frame_jank_threshold, "");
303305

304306
/// Trunk stable server (R/W) flags from outside SurfaceFlinger ///
305307
FLAG_MANAGER_ACONFIG_FLAG_IMPORTED(adpf_use_fmq_channel, "", android::os)

services/surfaceflinger/common/include/common/FlagManager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class FlagManager {
6161
bool adpf_use_fmq_channel() const;
6262
bool adpf_use_fmq_channel_fixed() const;
6363
bool graphite_renderengine_preview_rollout() const;
64+
bool increase_missed_frame_jank_threshold() const;
6465
bool refresh_rate_overlay_on_external_display() const;
6566

6667
/// Trunk stable readonly flags ///

services/surfaceflinger/surfaceflinger_flags_new.aconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,13 @@ flag {
189189
bug: "293371537"
190190
} # graphite_renderengine_preview_rollout
191191

192+
flag {
193+
name: "increase_missed_frame_jank_threshold"
194+
namespace: "core_graphics"
195+
description: "Increase the jank threshold to 4 milliseconds"
196+
bug: "342265411"
197+
} # increase_missed_frame_jank_threshold
198+
192199
flag {
193200
name: "latch_unsignaled_with_auto_refresh_changed"
194201
namespace: "core_graphics"

services/surfaceflinger/tests/unittests/FrameTimelineTest.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,12 @@ class FrameTimelineTest : public testing::Test {
202202
uint32_t* maxDisplayFrames;
203203
size_t maxTokens;
204204
static constexpr pid_t kSurfaceFlingerPid = 666;
205-
static constexpr nsecs_t kPresentThreshold = std::chrono::nanoseconds(2ns).count();
205+
static constexpr nsecs_t kPresentThresholdLegacy = std::chrono::nanoseconds(2ns).count();
206+
static constexpr nsecs_t kPresentThresholdExtended = std::chrono::nanoseconds(4ns).count();
206207
static constexpr nsecs_t kDeadlineThreshold = std::chrono::nanoseconds(0ns).count();
207208
static constexpr nsecs_t kStartThreshold = std::chrono::nanoseconds(2ns).count();
208-
static constexpr JankClassificationThresholds kTestThresholds{kPresentThreshold,
209+
static constexpr JankClassificationThresholds kTestThresholds{kPresentThresholdLegacy,
210+
kPresentThresholdExtended,
209211
kDeadlineThreshold,
210212
kStartThreshold};
211213
};

0 commit comments

Comments
 (0)