Skip to content

Commit 900a550

Browse files
nairvis-beepAndroid (Google) Code Review
authored andcommitted
Merge "Add debug sysprops to disable sched fifo in surfaceflinger" into main
2 parents bdb3bc4 + 4944c11 commit 900a550

9 files changed

Lines changed: 53 additions & 9 deletions

File tree

libs/renderengine/threaded/RenderEngineThreaded.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <future>
2424

2525
#include <android-base/stringprintf.h>
26+
#include <common/FlagManager.h>
2627
#include <common/trace.h>
2728
#include <private/gui/SyncFeatures.h>
2829
#include <processgroup/processgroup.h>
@@ -60,7 +61,7 @@ status_t RenderEngineThreaded::setSchedFifo(bool enabled) {
6061

6162
struct sched_param param = {0};
6263
int sched_policy;
63-
if (enabled) {
64+
if (enabled && !FlagManager::getInstance().disable_sched_fifo_re()) {
6465
sched_policy = SCHED_FIFO;
6566
param.sched_priority = kFifoPriority;
6667
} else {

services/surfaceflinger/DisplayHardware/AidlComposerHal.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,9 @@ void AidlComposer::registerCallback(HWC2::ComposerCallback& callback) {
357357
mAidlComposerCallback = ndk::SharedRefBase::make<AidlIComposerCallbackWrapper>(callback);
358358

359359
ndk::SpAIBinder binder = mAidlComposerCallback->asBinder();
360-
AIBinder_setMinSchedulerPolicy(binder.get(), SCHED_FIFO, 2);
360+
if (!FlagManager::getInstance().disable_sched_fifo_composer_callback()) {
361+
AIBinder_setMinSchedulerPolicy(binder.get(), SCHED_FIFO, 2);
362+
}
361363

362364
const auto status = mAidlComposerClient->registerCallback(mAidlComposerCallback);
363365
if (!status.isOk()) {

services/surfaceflinger/DisplayHardware/HidlComposerHal.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <aidl/android/hardware/graphics/common/DisplayHotplugEvent.h>
2929
#include <android/binder_manager.h>
3030
#include <android/hardware/graphics/composer/2.1/types.h>
31+
#include <common/FlagManager.h>
3132
#include <common/trace.h>
3233
#include <composer-command-buffer/2.2/ComposerCommandBuffer.h>
3334
#include <hidl/HidlTransportSupport.h>
@@ -301,7 +302,9 @@ std::string HidlComposer::dumpDebugInfo() {
301302
}
302303

303304
void HidlComposer::registerCallback(const sp<IComposerCallback>& callback) {
304-
android::hardware::setMinSchedulerPolicy(callback, SCHED_FIFO, 2);
305+
if (!FlagManager::getInstance().disable_sched_fifo_composer_callback()) {
306+
android::hardware::setMinSchedulerPolicy(callback, SCHED_FIFO, 2);
307+
}
305308

306309
auto ret = [&]() {
307310
if (mClient_2_4) {

services/surfaceflinger/Scheduler/EventThread.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,8 @@ sp<EventThreadConnection> EventThread::createEventConnection(
344344
auto connection = sp<EventThreadConnection>::make(const_cast<EventThread*>(this),
345345
IPCThreadState::self()->getCallingUid(),
346346
eventRegistration);
347-
if (FlagManager::getInstance().misc1()) {
347+
if (FlagManager::getInstance().misc1() &&
348+
!FlagManager::getInstance().disable_sched_fifo_sf_sched()) {
348349
const int policy = SCHED_FIFO;
349350
connection->setMinSchedulerPolicy(policy, sched_get_priority_min(policy));
350351
}

services/surfaceflinger/Scheduler/src/Timer.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <sys/timerfd.h>
2525
#include <sys/unistd.h>
2626

27+
#include <common/FlagManager.h>
2728
#include <common/trace.h>
2829
#include <ftl/concat.h>
2930
#include <ftl/enum.h>
@@ -155,8 +156,10 @@ bool Timer::dispatch() {
155156
setDebugState(DebugState::Running);
156157
struct sched_param param = {0};
157158
param.sched_priority = 2;
158-
if (pthread_setschedparam(pthread_self(), SCHED_FIFO, &param) != 0) {
159-
ALOGW("Failed to set SCHED_FIFO on dispatch thread");
159+
if (!FlagManager::getInstance().disable_sched_fifo_sf_sched()) {
160+
if (pthread_setschedparam(pthread_self(), SCHED_FIFO, &param) != 0) {
161+
ALOGW("Failed to set SCHED_FIFO on dispatch thread");
162+
}
160163
}
161164

162165
if (pthread_setname_np(pthread_self(), "TimerDispatch") != 0) {

services/surfaceflinger/SurfaceFlinger.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7116,7 +7116,7 @@ status_t SurfaceFlinger::setSchedFifo(bool enabled) {
71167116

71177117
struct sched_param param = {0};
71187118
int sched_policy;
7119-
if (enabled) {
7119+
if (enabled && !FlagManager::getInstance().disable_sched_fifo_sf()) {
71207120
sched_policy = SCHED_FIFO;
71217121
param.sched_priority = kFifoPriority;
71227122
} else {

services/surfaceflinger/common/FlagManager.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,19 @@ void FlagManager::dump(std::string& result) const {
104104
dumpFlag(result, (aconfig), #name, std::bind(&FlagManager::name, this))
105105
#define DUMP_LEGACY_SERVER_FLAG(name) DUMP_FLAG_INTERNAL(name, false)
106106
#define DUMP_ACONFIG_FLAG(name) DUMP_FLAG_INTERNAL(name, true)
107+
#define DUMP_SYSPROP_FLAG(name) \
108+
dumpFlag(result, (true), "debug.sf." #name, std::bind(&FlagManager::name, this))
107109

108110
base::StringAppendF(&result, "FlagManager values: \n");
109111

112+
/// Sysprop flags ///
113+
DUMP_SYSPROP_FLAG(disable_sched_fifo_sf);
114+
DUMP_SYSPROP_FLAG(disable_sched_fifo_sf_binder);
115+
DUMP_SYSPROP_FLAG(disable_sched_fifo_sf_sched);
116+
DUMP_SYSPROP_FLAG(disable_sched_fifo_re);
117+
DUMP_SYSPROP_FLAG(disable_sched_fifo_composer);
118+
DUMP_SYSPROP_FLAG(disable_sched_fifo_composer_callback);
119+
110120
/// Legacy server flags ///
111121
DUMP_LEGACY_SERVER_FLAG(use_adpf_cpu_hint);
112122
DUMP_LEGACY_SERVER_FLAG(use_skia_tracing);
@@ -185,6 +195,12 @@ bool FlagManager::getServerConfigurableFlag(const char* experimentFlagName) cons
185195
const auto res = parseBool(value.c_str());
186196
return res.has_value() && res.value();
187197
}
198+
#define FLAG_MANAGER_SYSPROP_FLAG(name, defaultVal) \
199+
bool FlagManager::name() const { \
200+
static const bool kFlagValue = \
201+
base::GetBoolProperty("debug.sf." #name, /* default value*/ defaultVal); \
202+
return kFlagValue; \
203+
}
188204

189205
#define FLAG_MANAGER_LEGACY_SERVER_FLAG(name, syspropOverride, serverFlagName) \
190206
bool FlagManager::name() const { \
@@ -215,6 +231,14 @@ bool FlagManager::getServerConfigurableFlag(const char* experimentFlagName) cons
215231
#define FLAG_MANAGER_ACONFIG_FLAG_IMPORTED(name, syspropOverride, owner) \
216232
FLAG_MANAGER_ACONFIG_INTERNAL(name, syspropOverride, owner)
217233

234+
/// Debug sysprop flags - default value is always false ///
235+
FLAG_MANAGER_SYSPROP_FLAG(disable_sched_fifo_sf, /* default */ false)
236+
FLAG_MANAGER_SYSPROP_FLAG(disable_sched_fifo_sf_binder, /* default */ false)
237+
FLAG_MANAGER_SYSPROP_FLAG(disable_sched_fifo_sf_sched, /* default */ false)
238+
FLAG_MANAGER_SYSPROP_FLAG(disable_sched_fifo_re, /* default */ false)
239+
FLAG_MANAGER_SYSPROP_FLAG(disable_sched_fifo_composer, /* default */ false)
240+
FLAG_MANAGER_SYSPROP_FLAG(disable_sched_fifo_composer_callback, /* default */ false)
241+
218242
/// Legacy server flags ///
219243
FLAG_MANAGER_LEGACY_SERVER_FLAG(test_flag, "", "")
220244
FLAG_MANAGER_LEGACY_SERVER_FLAG(use_adpf_cpu_hint, "debug.sf.enable_adpf_cpu_hint",

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ class FlagManager {
4242

4343
void setUnitTestMode();
4444

45+
/// Debug sysprop flags ///
46+
bool disable_sched_fifo_sf() const;
47+
bool disable_sched_fifo_sf_binder() const;
48+
bool disable_sched_fifo_sf_sched() const;
49+
bool disable_sched_fifo_re() const;
50+
bool disable_sched_fifo_composer() const;
51+
bool disable_sched_fifo_composer_callback() const;
52+
4553
/// Legacy server flags ///
4654
bool test_flag() const;
4755
bool use_adpf_cpu_hint() const;

services/surfaceflinger/main_surfaceflinger.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ int main(int, char**) {
132132
// Set the minimum policy of surfaceflinger node to be SCHED_FIFO.
133133
// So any thread with policy/priority lower than {SCHED_FIFO, 1}, will run
134134
// at least with SCHED_FIFO policy and priority 1.
135-
if (errorInPriorityModification == 0) {
135+
if (errorInPriorityModification == 0 &&
136+
!FlagManager::getInstance().disable_sched_fifo_sf_binder()) {
136137
flinger->setMinSchedulerPolicy(SCHED_FIFO, newPriority);
137138
}
138139

@@ -150,7 +151,8 @@ int main(int, char**) {
150151

151152
// publish gui::ISurfaceComposer, the new AIDL interface
152153
sp<SurfaceComposerAIDL> composerAIDL = sp<SurfaceComposerAIDL>::make(flinger);
153-
if (FlagManager::getInstance().misc1()) {
154+
if (FlagManager::getInstance().misc1() &&
155+
!FlagManager::getInstance().disable_sched_fifo_composer()) {
154156
composerAIDL->setMinSchedulerPolicy(SCHED_FIFO, newPriority);
155157
}
156158
sm->addService(String16("SurfaceFlingerAIDL"), composerAIDL, false,

0 commit comments

Comments
 (0)