Skip to content

Commit 29b3d13

Browse files
author
ramindani
committed
[SF] increase jank threshold to 4 milliseconds
Test: Manual jank analysis on the trace BUG: 342265411 Flag: com.android.graphics.surfaceflinger.flags.increase_missed_frame_jank_threshold Change-Id: I6c8dfb522d3006d3c810f4b23f359f31b144c5cb
1 parent b9bcf0a commit 29b3d13

3 files changed

Lines changed: 28 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/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)