diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-01-27 00:29:53 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-01-27 00:29:53 +0000 |
commit | 2f11a9087110067d58d2c7fcb90a95fb1a89d555 (patch) | |
tree | 67ca3c43c812896b427ae816dd0c57c26d2812f5 | |
parent | fceaf29ba58fe03d6535ffa9be6b14ad323f1509 (diff) | |
parent | a628880b6542a1d3a2b3d3c8a402716667db7eca (diff) | |
download | interfaces-android13-qpr3-s7-release.tar.gz |
Snap for 9531772 from a628880b6542a1d3a2b3d3c8a402716667db7eca to tm-qpr3-releaseandroid-13.0.0_r83android-13.0.0_r79android-13.0.0_r78android-13.0.0_r77android-13.0.0_r76android-13.0.0_r75android-13.0.0_r71android-13.0.0_r70android-13.0.0_r69android-13.0.0_r68android-13.0.0_r67android-13.0.0_r63android-13.0.0_r62android-13.0.0_r61android-13.0.0_r56android-13.0.0_r54android-13.0.0_r53android-13.0.0_r52android-13.0.0_r51android-13.0.0_r50android13-qpr3-s9-releaseandroid13-qpr3-s8-releaseandroid13-qpr3-s7-releaseandroid13-qpr3-s6-releaseandroid13-qpr3-s5-releaseandroid13-qpr3-s4-releaseandroid13-qpr3-s3-releaseandroid13-qpr3-s2-releaseandroid13-qpr3-s14-releaseandroid13-qpr3-s13-releaseandroid13-qpr3-s12-releaseandroid13-qpr3-s11-releaseandroid13-qpr3-s10-releaseandroid13-qpr3-s1-releaseandroid13-qpr3-release
Change-Id: Ic6566193481855e091367281224602e54ff521b7
-rw-r--r-- | suspend/1.0/default/SystemSuspend.cpp | 26 | ||||
-rw-r--r-- | suspend/1.0/default/SystemSuspendUnitTest.cpp | 34 |
2 files changed, 50 insertions, 10 deletions
diff --git a/suspend/1.0/default/SystemSuspend.cpp b/suspend/1.0/default/SystemSuspend.cpp index 5e5a745..5374ea9 100644 --- a/suspend/1.0/default/SystemSuspend.cpp +++ b/suspend/1.0/default/SystemSuspend.cpp @@ -56,6 +56,12 @@ static const char kSleepState[] = "mem"; static constexpr char kSysPowerWakeLock[] = "/sys/power/wake_lock"; static constexpr char kSysPowerWakeUnlock[] = "/sys/power/wake_unlock"; static constexpr char kUnknownWakeup[] = "unknown"; +// This is used to disable autosuspend when zygote is restarted +// it allows the system to make progress before autosuspend is kicked +// NOTE: If the name of this wakelock is changed then also update the name +// in rootdir/init.zygote32.rc, rootdir/init.zygote64.rc, and +// rootdir/init.zygote64_32.rc +static constexpr char kZygoteKernelWakelock[] = "zygote_kwl"; // This function assumes that data in fd is small enough that it can be read in one go. // We use this function instead of the ones available in libbase because it doesn't block @@ -150,10 +156,11 @@ SystemSuspend::SystemSuspend(unique_fd wakeupCountFd, unique_fd stateFd, unique_ if (mWakeLockFd < 0) { PLOG(ERROR) << "error opening " << kSysPowerWakeLock; } - mWakeUnlockFd.reset(TEMP_FAILURE_RETRY(open(kSysPowerWakeUnlock, O_CLOEXEC | O_RDWR))); - if (mWakeUnlockFd < 0) { - PLOG(ERROR) << "error opening " << kSysPowerWakeUnlock; - } + } + + mWakeUnlockFd.reset(TEMP_FAILURE_RETRY(open(kSysPowerWakeUnlock, O_CLOEXEC | O_RDWR))); + if (mWakeUnlockFd < 0) { + PLOG(ERROR) << "error opening " << kSysPowerWakeUnlock; } } @@ -161,6 +168,14 @@ bool SystemSuspend::enableAutosuspend(const sp<IBinder>& token) { auto tokensLock = std::lock_guard(mAutosuspendClientTokensLock); auto autosuspendLock = std::lock_guard(mAutosuspendLock); + // Disable zygote kernel wakelock, since explicitly attempting to + // enable autosuspend. This should be done even if autosuspend is + // already enabled, since it could be the case that the framework + // is restarting and connecting to the existing suspend service. + if (!WriteStringToFd(kZygoteKernelWakelock, mWakeUnlockFd)) { + PLOG(ERROR) << "error writing " << kZygoteKernelWakelock << " to " << kSysPowerWakeUnlock; + } + bool hasToken = std::find(mAutosuspendClientTokens.begin(), mAutosuspendClientTokens.end(), token) != mAutosuspendClientTokens.end(); @@ -327,7 +342,8 @@ void SystemSuspend::initAutosuspendLocked() { bool success; { auto tokensLock = std::lock_guard(mAutosuspendClientTokensLock); - checkAutosuspendClientsLivenessLocked(); + // TODO: Clean up client tokens after soaking the new approach + // checkAutosuspendClientsLivenessLocked(); autosuspendLock.lock(); base::ScopedLockAssertion autosuspendLocked(mAutosuspendLock); diff --git a/suspend/1.0/default/SystemSuspendUnitTest.cpp b/suspend/1.0/default/SystemSuspendUnitTest.cpp index f6e216b..a4d58b5 100644 --- a/suspend/1.0/default/SystemSuspendUnitTest.cpp +++ b/suspend/1.0/default/SystemSuspendUnitTest.cpp @@ -198,8 +198,12 @@ class SystemSuspendTest : public ::testing::Test { } virtual void TearDown() override { + // Allow some time for the autosuspend loop to happen, if unblocked + std::this_thread::sleep_for(100ms); + if (!isReadBlocked(wakeupCountFd)) readFd(wakeupCountFd); - if (!isReadBlocked(stateFd)) readFd(stateFd).empty(); + if (!isReadBlocked(stateFd)) readFd(stateFd); + ASSERT_TRUE(isReadBlocked(wakeupCountFd)); ASSERT_TRUE(isReadBlocked(stateFd)); } @@ -209,7 +213,12 @@ class SystemSuspendTest : public ::testing::Test { ASSERT_TRUE(WriteStringToFd(wakeupCount, wakeupCountFd)); } - bool isSystemSuspendBlocked(int timeout_ms = 20) { return isReadBlocked(stateFd, timeout_ms); } + bool isSystemSuspendBlocked(int timeout_ms = 20) { + // Allow some time for the autosuspend loop to happen, if unblocked + std::this_thread::sleep_for(100ms); + + return isReadBlocked(stateFd, timeout_ms); + } std::shared_ptr<IWakeLock> acquireWakeLock(const std::string& name = "TestLock") { std::shared_ptr<IWakeLock> wl = nullptr; @@ -305,18 +314,32 @@ TEST_F(SystemSuspendTest, OnlyOneEnableAutosuspend) { // Tests that autosuspend thread can only enabled again after its been disabled. TEST_F(SystemSuspendTest, EnableAutosuspendAfterDisableAutosuspend) { bool enabled = false; - unblockSystemSuspendFromWakeupCount(); + + checkLoop(1); + controlServiceInternal->enableAutosuspend(new BBinder(), &enabled); + ASSERT_FALSE(enabled); + systemSuspend->disableAutosuspend(); + unblockSystemSuspendFromWakeupCount(); + controlServiceInternal->enableAutosuspend(new BBinder(), &enabled); - ASSERT_EQ(enabled, true); + ASSERT_TRUE(enabled); } TEST_F(SystemSuspendTest, DisableAutosuspendBlocksSuspend) { checkLoop(1); systemSuspend->disableAutosuspend(); + unblockSystemSuspendFromWakeupCount(); ASSERT_TRUE(isSystemSuspendBlocked()); + + // Re-enable autosuspend + bool enabled = false; + controlServiceInternal->enableAutosuspend(new BBinder(), &enabled); + ASSERT_TRUE(enabled); } +// TODO: Clean up binder tokens after soaking new implementation +/* TEST_F(SystemSuspendTest, BlockAutosuspendIfBinderIsDead) { class DeadBinder : public BBinder { android::status_t pingBinder() override { return android::UNKNOWN_ERROR; } @@ -385,6 +408,7 @@ TEST_F(SystemSuspendTest, UnresponsiveClientDoesNotBlockAcquireRelease) { ASSERT_FALSE(timedOut); } +*/ TEST_F(SystemSuspendTest, AutosuspendLoop) { checkLoop(5); @@ -417,10 +441,10 @@ TEST_F(SystemSuspendTest, MultipleWakeLocks) { std::shared_ptr<IWakeLock> wl1 = acquireWakeLock(); ASSERT_NE(wl1, nullptr); ASSERT_TRUE(isSystemSuspendBlocked()); - unblockSystemSuspendFromWakeupCount(); { std::shared_ptr<IWakeLock> wl2 = acquireWakeLock(); ASSERT_NE(wl2, nullptr); + unblockSystemSuspendFromWakeupCount(); ASSERT_TRUE(isSystemSuspendBlocked()); } ASSERT_TRUE(isSystemSuspendBlocked()); |