SF: Remove per-display state in scheduler
This CL removes per-display RefreshRateConfigs and AllowedDisplayConfigs
to avoid bugs in the untested multi-display code path of the scheduler,
adds checks to prevent crashes if the internal display is removed, and
cleans up related code by:
1) Replacing AllowedDisplayConfigs with a simple set.
2) Making setAllowedDisplayConfigs consistent with setPowerMode.
3) Removing unnecessary locking and allocation.
Bug: 129433906
Test: Boot with single/multiple display(s)
Change-Id: I3f59e9bdeaceb2cf48b4b9b71cd27f1d6a574680
(cherry picked from commit 645365116b7c77204aaffbb88f9407549445396c)
diff --git a/services/surfaceflinger/Scheduler/RefreshRateStats.h b/services/surfaceflinger/Scheduler/RefreshRateStats.h
index ff63faf..7e7c630 100644
--- a/services/surfaceflinger/Scheduler/RefreshRateStats.h
+++ b/services/surfaceflinger/Scheduler/RefreshRateStats.h
@@ -41,12 +41,8 @@
static constexpr int64_t MS_PER_DAY = 24 * MS_PER_HOUR;
public:
- explicit RefreshRateStats(const std::shared_ptr<RefreshRateConfigs>& refreshRateConfigs,
- const std::shared_ptr<TimeStats>& timeStats)
- : mRefreshRateConfigs(refreshRateConfigs),
- mTimeStats(timeStats),
- mPreviousRecordedTime(systemTime()) {}
- ~RefreshRateStats() = default;
+ RefreshRateStats(const RefreshRateConfigs& refreshRateConfigs, TimeStats& timeStats)
+ : mRefreshRateConfigs(refreshRateConfigs), mTimeStats(timeStats) {}
// Sets power mode. We only collect the information when the power mode is not
// HWC_POWER_MODE_NORMAL. When power mode is HWC_POWER_MODE_NORMAL, we collect the stats based
@@ -83,7 +79,7 @@
flushTime();
std::unordered_map<std::string, int64_t> totalTime;
- for (auto [type, config] : mRefreshRateConfigs->getRefreshRates()) {
+ for (const auto& [type, config] : mRefreshRateConfigs.getRefreshRates()) {
int64_t totalTimeForConfig = 0;
if (!config) {
continue;
@@ -98,11 +94,11 @@
// Traverses through the map of config modes and returns how long they've been running in easy
// to read format.
- std::string doDump() {
+ std::string doDump() const {
std::ostringstream stream;
stream << "+ Refresh rate: running time in seconds\n";
- for (auto stats : getTotalTimes()) {
- stream << stats.first.c_str() << ": " << getDateFormatFromMs(stats.second) << "\n";
+ for (const auto& [name, time] : const_cast<RefreshRateStats*>(this)->getTotalTimes()) {
+ stream << name << ": " << getDateFormatFromMs(time) << '\n';
}
return stream.str();
}
@@ -126,12 +122,12 @@
mPreviousRecordedTime = currentTime;
mConfigModesTotalTime[mode] += timeElapsedMs;
- for (const auto& [type, config] : mRefreshRateConfigs->getRefreshRates()) {
+ for (const auto& [type, config] : mRefreshRateConfigs.getRefreshRates()) {
if (!config) {
continue;
}
if (config->configId == mode) {
- mTimeStats->recordRefreshRate(config->fps, timeElapsed);
+ mTimeStats.recordRefreshRate(config->fps, timeElapsed);
}
}
}
@@ -148,17 +144,17 @@
}
// Keeps information about refresh rate configs that device has.
- std::shared_ptr<RefreshRateConfigs> mRefreshRateConfigs;
+ const RefreshRateConfigs& mRefreshRateConfigs;
// Aggregate refresh rate statistics for telemetry.
- std::shared_ptr<TimeStats> mTimeStats;
+ TimeStats& mTimeStats;
int64_t mCurrentConfigMode = SCREEN_OFF_CONFIG_ID;
int32_t mCurrentPowerMode = HWC_POWER_MODE_OFF;
std::unordered_map<int /* power mode */, int64_t /* duration in ms */> mConfigModesTotalTime;
- nsecs_t mPreviousRecordedTime;
+ nsecs_t mPreviousRecordedTime = systemTime();
};
} // namespace scheduler