Skip to content

Commit ccfdcd8

Browse files
Treehugger RobotAndroid (Google) Code Review
authored andcommitted
Merge changes I6f68b884,I870d8f13 into main
* changes: SF: Clean up helpers for thread priority SF: Remove connected_display flag
2 parents 5155aa6 + 4418a39 commit ccfdcd8

11 files changed

Lines changed: 35 additions & 84 deletions

File tree

services/surfaceflinger/Display/DisplayModeController.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,7 @@ auto DisplayModeController::setDesiredMode(PhysicalDisplayId displayId,
9797
const bool force = desiredModeOpt->force;
9898
desiredModeOpt = std::move(desiredMode);
9999
desiredModeOpt->emitEvent |= emitEvent;
100-
if (FlagManager::getInstance().connected_display()) {
101-
desiredModeOpt->force |= force;
102-
}
100+
desiredModeOpt->force |= force;
103101
return DesiredModeAction::None;
104102
}
105103

@@ -191,7 +189,7 @@ auto DisplayModeController::initiateModeChange(
191189
// cleared until the next `SF::initiateDisplayModeChanges`. However, the desired mode has been
192190
// consumed at this point, so clear the `force` flag to prevent an endless loop of
193191
// `initiateModeChange`.
194-
if (FlagManager::getInstance().connected_display()) {
192+
{
195193
std::scoped_lock lock(displayPtr->desiredModeLock);
196194
if (displayPtr->desiredModeOpt) {
197195
displayPtr->desiredModeOpt->force = false;

services/surfaceflinger/DisplayHardware/HWC2.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -439,11 +439,8 @@ Error Display::setActiveConfigWithConstraints(hal::HWConfigId configId,
439439
// FIXME (b/319505580): At least the first config set on an external display must be
440440
// `setActiveConfig`, so skip over the block that calls `setActiveConfigWithConstraints`
441441
// for simplicity.
442-
const bool connected_display = FlagManager::getInstance().connected_display();
443-
444442
if (isVsyncPeriodSwitchSupported() &&
445-
(!connected_display ||
446-
getConnectionType().value_opt() != ui::DisplayConnectionType::External)) {
443+
getConnectionType().value_opt() != ui::DisplayConnectionType::External) {
447444
Hwc2::IComposerClient::VsyncPeriodChangeConstraints hwc2Constraints;
448445
hwc2Constraints.desiredTimeNanos = constraints.desiredTimeNanos;
449446
hwc2Constraints.seamlessRequired = constraints.seamlessRequired;

services/surfaceflinger/Scheduler/Scheduler.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -986,7 +986,7 @@ std::shared_ptr<VsyncSchedule> Scheduler::promotePacesetterDisplayLocked(
986986
if (const auto pacesetterOpt = pacesetterDisplayLocked()) {
987987
const Display& pacesetter = *pacesetterOpt;
988988

989-
if (!FlagManager::getInstance().connected_display() || params.toggleIdleTimer) {
989+
if (params.toggleIdleTimer) {
990990
pacesetter.selectorPtr->setIdleTimerCallbacks(
991991
{.platform = {.onReset = [this] { idleTimerCallback(TimerState::Reset); },
992992
.onExpired = [this] { idleTimerCallback(TimerState::Expired); }},
@@ -1018,7 +1018,7 @@ void Scheduler::applyNewVsyncSchedule(std::shared_ptr<VsyncSchedule> vsyncSchedu
10181018
}
10191019

10201020
void Scheduler::demotePacesetterDisplay(PromotionParams params) {
1021-
if (!FlagManager::getInstance().connected_display() || params.toggleIdleTimer) {
1021+
if (params.toggleIdleTimer) {
10221022
// No need to lock for reads on kMainThreadContext.
10231023
if (const auto pacesetterPtr =
10241024
FTL_FAKE_GUARD(mDisplayLock, pacesetterSelectorPtrLocked())) {

services/surfaceflinger/Scheduler/Scheduler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ class Scheduler : public IEventThreadCallback, android::impl::MessageQueue {
386386
// a deadlock where the main thread joins with the timer thread as the timer thread waits to
387387
// lock a mutex held by the main thread.
388388
struct PromotionParams {
389-
// Whether to stop and start the idle timer. Ignored unless connected_display flag is set.
389+
// Whether to stop and start the idle timer.
390390
bool toggleIdleTimer;
391391
};
392392

services/surfaceflinger/SurfaceFlinger.cpp

Lines changed: 23 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,9 +1009,8 @@ void SurfaceFlinger::init() FTL_FAKE_GUARD(kMainThreadContext) {
10091009
mPowerAdvisor->init();
10101010

10111011
if (base::GetBoolProperty("service.sf.prime_shader_cache"s, true)) {
1012-
if (setSchedFifo(false) != NO_ERROR) {
1013-
ALOGW("Can't set SCHED_OTHER for primeCache");
1014-
}
1012+
constexpr const char* kWhence = "primeCache";
1013+
setSchedFifo(false, kWhence);
10151014

10161015
mRenderEnginePrimeCacheFuture.callOnce([this] {
10171016
renderengine::PrimeCacheConfig config;
@@ -1047,9 +1046,7 @@ void SurfaceFlinger::init() FTL_FAKE_GUARD(kMainThreadContext) {
10471046
return getRenderEngine().primeCache(config);
10481047
});
10491048

1050-
if (setSchedFifo(true) != NO_ERROR) {
1051-
ALOGW("Can't set SCHED_FIFO after primeCache");
1052-
}
1049+
setSchedFifo(true, kWhence);
10531050
}
10541051

10551052
// Avoid blocking the main thread on `init` to set properties.
@@ -2286,8 +2283,7 @@ void SurfaceFlinger::scheduleSample() {
22862283

22872284
void SurfaceFlinger::onComposerHalVsync(hal::HWDisplayId hwcDisplayId, int64_t timestamp,
22882285
std::optional<hal::VsyncPeriodNanos> vsyncPeriod) {
2289-
if (FlagManager::getInstance().connected_display() && timestamp < 0 &&
2290-
vsyncPeriod.has_value()) {
2286+
if (timestamp < 0 && vsyncPeriod.has_value()) {
22912287
if (mIsHdcpViaNegVsync && vsyncPeriod.value() == ~1) {
22922288
const int32_t value = static_cast<int32_t>(-timestamp);
22932289
// one byte is good enough to encode android.hardware.drm.HdcpLevel
@@ -3564,9 +3560,8 @@ std::pair<DisplayModes, DisplayModePtr> SurfaceFlinger::loadDisplayModes(
35643560
std::vector<HWComposer::HWCDisplayMode> hwcModes;
35653561
std::optional<hal::HWConfigId> activeModeHwcIdOpt;
35663562

3567-
const bool isExternalDisplay = FlagManager::getInstance().connected_display() &&
3568-
getHwComposer().getDisplayConnectionType(displayId) ==
3569-
ui::DisplayConnectionType::External;
3563+
const bool isExternalDisplay = getHwComposer().getDisplayConnectionType(displayId) ==
3564+
ui::DisplayConnectionType::External;
35703565

35713566
int attempt = 0;
35723567
constexpr int kMaxAttempts = 3;
@@ -4066,8 +4061,7 @@ void SurfaceFlinger::processDisplayAdded(const wp<IBinder>& displayToken,
40664061
// For an external display, loadDisplayModes already attempted to select the same mode
40674062
// as DM, but SF still needs to be updated to match.
40684063
// TODO (b/318534874): Let DM decide the initial mode.
4069-
if (const auto& physical = state.physical;
4070-
mScheduler && physical && FlagManager::getInstance().connected_display()) {
4064+
if (const auto& physical = state.physical; mScheduler && physical) {
40714065
const bool isInternalDisplay = mPhysicalDisplays.get(physical->id)
40724066
.transform(&PhysicalDisplay::isInternal)
40734067
.value_or(false);
@@ -5710,16 +5704,11 @@ void SurfaceFlinger::setPowerModeInternal(const sp<DisplayDevice>& display, hal:
57105704
}
57115705

57125706
if (displayId == mActiveDisplayId) {
5713-
// TODO(b/281692563): Merge the syscalls. For now, keep uclamp in a separate syscall and
5714-
// set it before SCHED_FIFO due to b/190237315.
5715-
if (setSchedAttr(true) != NO_ERROR) {
5716-
ALOGW("Failed to set uclamp.min after powering on active display: %s",
5717-
strerror(errno));
5718-
}
5719-
if (setSchedFifo(true) != NO_ERROR) {
5720-
ALOGW("Failed to set SCHED_FIFO after powering on active display: %s",
5721-
strerror(errno));
5722-
}
5707+
// TODO: b/281692563 - Merge the syscalls. For now, keep uclamp in a separate syscall
5708+
// and set it before SCHED_FIFO due to b/190237315.
5709+
constexpr const char* kWhence = "setPowerMode(ON)";
5710+
setSchedAttr(true, kWhence);
5711+
setSchedFifo(true, kWhence);
57235712
}
57245713

57255714
getHwComposer().setPowerMode(displayId, mode);
@@ -5746,14 +5735,9 @@ void SurfaceFlinger::setPowerModeInternal(const sp<DisplayDevice>& display, hal:
57465735
if (const auto display = getActivatableDisplay()) {
57475736
onActiveDisplayChangedLocked(activeDisplay.get(), *display);
57485737
} else {
5749-
if (setSchedFifo(false) != NO_ERROR) {
5750-
ALOGW("Failed to set SCHED_OTHER after powering off active display: %s",
5751-
strerror(errno));
5752-
}
5753-
if (setSchedAttr(false) != NO_ERROR) {
5754-
ALOGW("Failed set uclamp.min after powering off active display: %s",
5755-
strerror(errno));
5756-
}
5738+
constexpr const char* kWhence = "setPowerMode(OFF)";
5739+
setSchedFifo(false, kWhence);
5740+
setSchedAttr(false, kWhence);
57575741

57585742
if (currentModeNotDozeSuspend) {
57595743
if (!FlagManager::getInstance().multithreaded_present()) {
@@ -7216,7 +7200,7 @@ static status_t validateScreenshotPermissions(const CaptureArgs& captureArgs) {
72167200
return PERMISSION_DENIED;
72177201
}
72187202

7219-
status_t SurfaceFlinger::setSchedFifo(bool enabled) {
7203+
void SurfaceFlinger::setSchedFifo(bool enabled, const char* whence) {
72207204
static constexpr int kFifoPriority = 2;
72217205
static constexpr int kOtherPriority = 0;
72227206

@@ -7231,19 +7215,19 @@ status_t SurfaceFlinger::setSchedFifo(bool enabled) {
72317215
}
72327216

72337217
if (sched_setscheduler(0, sched_policy, &param) != 0) {
7234-
return -errno;
7218+
const char* kPolicy[] = {"SCHED_OTHER", "SCHED_FIFO"};
7219+
ALOGW("%s: Failed to set %s: %s", whence, kPolicy[sched_policy == SCHED_FIFO],
7220+
strerror(errno));
72357221
}
7236-
7237-
return NO_ERROR;
72387222
}
72397223

7240-
status_t SurfaceFlinger::setSchedAttr(bool enabled) {
7224+
void SurfaceFlinger::setSchedAttr(bool enabled, const char* whence) {
72417225
static const unsigned int kUclampMin =
72427226
base::GetUintProperty<unsigned int>("ro.surface_flinger.uclamp.min"s, 0U);
72437227

72447228
if (!kUclampMin) {
72457229
// uclamp.min set to 0 (default), skip setting
7246-
return NO_ERROR;
7230+
return;
72477231
}
72487232

72497233
sched_attr attr = {};
@@ -7254,10 +7238,9 @@ status_t SurfaceFlinger::setSchedAttr(bool enabled) {
72547238
attr.sched_util_max = 1024;
72557239

72567240
if (syscall(__NR_sched_setattr, 0, &attr, 0)) {
7257-
return -errno;
7241+
const char* kAction[] = {"disable", "enable"};
7242+
ALOGW("%s: Failed to %s uclamp.min: %s", whence, kAction[enabled], strerror(errno));
72587243
}
7259-
7260-
return NO_ERROR;
72617244
}
72627245

72637246
namespace {
@@ -8377,10 +8360,6 @@ status_t SurfaceFlinger::getStalledTransactionInfo(
83778360

83788361
void SurfaceFlinger::updateHdcpLevels(hal::HWDisplayId hwcDisplayId, int32_t connectedLevel,
83798362
int32_t maxLevel) {
8380-
if (!FlagManager::getInstance().connected_display()) {
8381-
return;
8382-
}
8383-
83848363
Mutex::Autolock lock(mStateLock);
83858364

83868365
const auto idOpt = getHwComposer().toPhysicalDisplayId(hwcDisplayId);

services/surfaceflinger/SurfaceFlinger.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,9 @@ class SurfaceFlinger : public BnSurfaceComposer,
211211
SurfaceFlinger(surfaceflinger::Factory&, SkipInitializationTag) ANDROID_API;
212212
explicit SurfaceFlinger(surfaceflinger::Factory&) ANDROID_API;
213213

214-
// set main thread scheduling policy
215-
static status_t setSchedFifo(bool enabled) ANDROID_API;
216-
217-
// set main thread scheduling attributes
218-
static status_t setSchedAttr(bool enabled);
214+
// Set scheduling policy and attributes of main thread.
215+
static void setSchedFifo(bool enabled, const char* whence);
216+
static void setSchedAttr(bool enabled, const char* whence);
219217

220218
static char const* getServiceName() ANDROID_API { return "SurfaceFlinger"; }
221219

services/surfaceflinger/common/FlagManager.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ void FlagManager::dump(std::string& result) const {
139139
DUMP_ACONFIG_FLAG(begone_bright_hlg);
140140
DUMP_ACONFIG_FLAG(cache_when_source_crop_layer_only_moved);
141141
DUMP_ACONFIG_FLAG(commit_not_composited);
142-
DUMP_ACONFIG_FLAG(connected_display);
143142
DUMP_ACONFIG_FLAG(connected_display_hdr);
144143
DUMP_ACONFIG_FLAG(correct_dpi_with_display_size);
145144
DUMP_ACONFIG_FLAG(deprecate_frame_tracker);
@@ -252,7 +251,6 @@ FLAG_MANAGER_LEGACY_SERVER_FLAG(use_skia_tracing, PROPERTY_SKIA_ATRACE_ENABLED,
252251
/// Trunk stable readonly flags ///
253252
FLAG_MANAGER_ACONFIG_FLAG(adpf_fmq_sf, "")
254253
FLAG_MANAGER_ACONFIG_FLAG(arr_setframerate_gte_enum, "debug.sf.arr_setframerate_gte_enum")
255-
FLAG_MANAGER_ACONFIG_FLAG(connected_display, "")
256254
FLAG_MANAGER_ACONFIG_FLAG(enable_small_area_detection, "")
257255
FLAG_MANAGER_ACONFIG_FLAG(stable_edid_ids, "debug.sf.stable_edid_ids")
258256
FLAG_MANAGER_ACONFIG_FLAG(frame_rate_category_mrr, "debug.sf.frame_rate_category_mrr")

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ class FlagManager {
7474
bool begone_bright_hlg() const;
7575
bool cache_when_source_crop_layer_only_moved() const;
7676
bool commit_not_composited() const;
77-
bool connected_display() const;
7877
bool connected_display_hdr() const;
7978
bool correct_dpi_with_display_size() const;
8079
bool deprecate_frame_tracker() const;

services/surfaceflinger/main_surfaceflinger.cpp

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ static void startDisplayService() {
7777
}
7878
}
7979

80-
int main(int, char**) {
80+
int main() {
8181
signal(SIGPIPE, SIG_IGN);
8282

8383
hardware::configureRpcThreadpool(1 /* maxThreads */,
@@ -91,9 +91,7 @@ int main(int, char**) {
9191

9292
// Set uclamp.min setting on all threads, maybe an overkill but we want
9393
// to cover important threads like RenderEngine.
94-
if (SurfaceFlinger::setSchedAttr(true) != NO_ERROR) {
95-
ALOGW("Failed to set uclamp.min during boot: %s", strerror(errno));
96-
}
94+
SurfaceFlinger::setSchedAttr(true, __func__);
9795

9896
// The binder threadpool we start will inherit sched policy and priority
9997
// of (this) creating thread. We want the binder thread pool to have
@@ -160,14 +158,8 @@ int main(int, char**) {
160158

161159
startDisplayService(); // dependency on SF getting registered above
162160

163-
if (SurfaceFlinger::setSchedFifo(true) != NO_ERROR) {
164-
ALOGW("Failed to set SCHED_FIFO during boot: %s", strerror(errno));
165-
}
166-
167-
// run surface flinger in this thread
161+
SurfaceFlinger::setSchedFifo(true, __func__);
168162
flinger->run();
169-
170-
return 0;
171163
}
172164

173165
// TODO(b/129481165): remove the #pragma below and fix conversion issues

services/surfaceflinger/tests/unittests/SurfaceFlinger_DisplayModeSwitching.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -407,8 +407,6 @@ TEST_F(DisplayModeSwitchingTest, changeResolutionSynced) {
407407
}
408408

409409
TEST_F(DisplayModeSwitchingTest, innerXorOuterDisplay) {
410-
SET_FLAG_FOR_TEST(flags::connected_display, true);
411-
412410
const auto [innerDisplay, outerDisplay] = injectOuterDisplay();
413411

414412
EXPECT_TRUE(innerDisplay->isPoweredOn());
@@ -473,8 +471,6 @@ TEST_F(DisplayModeSwitchingTest, innerXorOuterDisplay) {
473471
}
474472

475473
TEST_F(DisplayModeSwitchingTest, innerAndOuterDisplay) {
476-
SET_FLAG_FOR_TEST(flags::connected_display, true);
477-
478474
const auto [innerDisplay, outerDisplay] = injectOuterDisplay();
479475

480476
EXPECT_TRUE(innerDisplay->isPoweredOn());
@@ -543,8 +539,6 @@ TEST_F(DisplayModeSwitchingTest, powerOffDuringModeSet) {
543539
}
544540

545541
TEST_F(DisplayModeSwitchingTest, powerOffDuringConcurrentModeSet) {
546-
SET_FLAG_FOR_TEST(flags::connected_display, true);
547-
548542
const auto [innerDisplay, outerDisplay] = injectOuterDisplay();
549543

550544
EXPECT_TRUE(innerDisplay->isPoweredOn());

0 commit comments

Comments
 (0)