android STR suspend/resume framework
console:/sys/power # cat wake_lock PowerManager.SuspendLockout PowerManagerService.Display
console:/sys/power # cat wake_unlock KeyEvents PowerManagerService.WakeLocks
上述wake_lock、wake_unlock里的内容分别是如下incSuspendCounter()、decSuspendCounter()写进去的,mUseSuspendCounter的值是0:
systemhardwareinterfacessuspend1.0defaultSystemSuspend.cpp
void SystemSuspend::incSuspendCounter(const string& name) { auto l = std::lock_guard(mCounterLock); if (mUseSuspendCounter) { mSuspendCounter++; } else { if (!WriteStringToFd(name, mWakeLockFd)) { PLOG(ERROR) << "error writing " << name << " to " << kSysPowerWakeLock; } } }
void SystemSuspend::decSuspendCounter(const string& name) { auto l = std::lock_guard(mCounterLock); if (mUseSuspendCounter) { if (--mSuspendCounter == 0) { mCounterCondVar.notify_one(); } } else { if (!WriteStringToFd(name, mWakeUnlockFd)) { PLOG(ERROR) << "error writing " << name << " to " << kSysPowerWakeUnlock; } } }
上面wake_lock写入路径
PowerManagerService.Display(hwbinder server端):
12-31 19:00:11.805 2746 2746 D listed wake lock: #00 pc 000000000000b868 /system/bin/hw/android.system.suspend@1.0-service (android::system::suspend::V1_0::SystemSuspend::incSuspendCounter(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&)+136) 12-31 19:00:11.805 2746 2746 D listed wake lock: #01 pc 000000000000c4dc /system/bin/hw/android.system.suspend@1.0-service (android::system::suspend::V1_0::SystemSuspend::acquireWakeLock(android::system::suspend::V1_0::WakeLockType, android::hardware::hidl_string const&)+332) 12-31 19:00:11.805 2746 2746 D listed wake lock: #02 pc 000000000000fc64 /system/lib64/android.system.suspend@1.0.so (android::system::suspend::V1_0::BnHwSystemSuspend::_hidl_acquireWakeLock(android::hidl::base::V1_0::BnHwBase*, android::hardware::Parcel const&, android::hardware::Parcel*, std::__1::function<void (android::hardware::Parcel&)>)+252) 12-31 19:00:11.805 2746 2746 D listed wake lock: #03 pc 0000000000010194 /system/lib64/android.system.suspend@1.0.so (android::system::suspend::V1_0::BnHwSystemSuspend::onTransact(unsigned int, android::hardware::Parcel const&, android::hardware::Parcel*, unsigned int, std::__1::function<void (android::hardware::Parcel&)>)+316) 12-31 19:00:11.805 2746 2746 D listed wake lock: #04 pc 0000000000096604 /system/lib64/libhidlbase.so (android::hardware::BHwBinder::transact(unsigned int, android::hardware::Parcel const&, android::hardware::Parcel*, unsigned int, std::__1::function<void (android::hardware::Parcel&)>)+68) 12-31 19:00:11.805 2746 2746 D listed wake lock: #05 pc 0000000000099fcc /system/lib64/libhidlbase.so (android::hardware::IPCThreadState::getAndExecuteCommand()+1036) 12-31 19:00:11.805 2746 2746 D listed wake lock: #06 pc 000000000009b1e0 /system/lib64/libhidlbase.so (android::hardware::IPCThreadState::joinThreadPool(bool)+96) 12-31 19:00:11.805 2746 2746 D listed wake lock: #07 pc 000000000000a608 /system/bin/hw/android.system.suspend@1.0-service (main+1464) 12-31 19:00:11.805 2746 2746 D listed wake lock: #08 pc 000000000007d844 /apex/com.android.runtime/lib64/bionic/libc.so (__libc_init+108) 12-31 19:00:11.805 2746 2746 E /system/bin/hw/android.system.suspend@1.0-service: inc suspend cnt, name:PowerManagerService.DisplaymUseSuspendCounter: 0: Success
上面wake_unlock写入路径:
PowerManagerService.WakeLocks(hwbinder serser端):
09-19 09:31:00.023 2748 2748 D listed wake unlock(a on): #00 pc 000000000000cbb4 /system/bin/hw/android.system.suspend@1.0-service (android::system::suspend::V1_0::SystemSuspend::decSuspendCounter(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&)+116) 09-19 09:31:00.023 2748 2748 D listed wake unlock(a on): #01 pc 000000000000d1a4 /system/bin/hw/android.system.suspend@1.0-service (_ZNSt3__117__call_once_proxyINS_5tupleIJOZN7android6system7suspend4V1_08WakeLock11releaseOnceEvEUlvE_EEEEEvPv+52) 09-19 09:31:00.023 2748 2748 D listed wake unlock(a on): #02 pc 00000000000b0f74 /system/lib64/libc++.so (std::__1::__call_once(unsigned long volatile&, void*, void (*)(void*))+156) 09-19 09:31:00.023 2748 2748 D listed wake unlock(a on): #03 pc 000000000000bcc8 /system/bin/hw/android.system.suspend@1.0-service (android::system::suspend::V1_0::WakeLock::release()+80) 09-19 09:31:00.023 2748 2748 D listed wake unlock(a on): #04 pc 0000000000016f5c /system/lib64/android.system.suspend@1.0.so (android::system::suspend::V1_0::BnHwWakeLock::_hidl_release(android::hidl::base::V1_0::BnHwBase*, android::hardware::Parcel const&, android::hardware::Parcel*, std::__1::function<void (android::hardware::Parcel&)>)+164) 09-19 09:31:00.023 2748 2748 D listed wake unlock(a on): #05 pc 000000000001734c /system/lib64/android.system.suspend@1.0.so (android::system::suspend::V1_0::BnHwWakeLock::onTransact(unsigned int, android::hardware::Parcel const&, android::hardware::Parcel*, unsigned int, std::__1::function<void (android::hardware::Parcel&)>)+308) 09-19 09:31:00.023 2748 2748 D listed wake unlock(a on): #06 pc 0000000000096604 /system/lib64/libhidlbase.so (android::hardware::BHwBinder::transact(unsigned int, android::hardware::Parcel const&, android::hardware::Parcel*, unsigned int, std::__1::function<void (android::hardware::Parcel&)>)+68) 09-19 09:31:00.023 2748 2748 D listed wake unlock(a on): #07 pc 0000000000099fcc /system/lib64/libhidlbase.so (android::hardware::IPCThreadState::getAndExecuteCommand()+1036) 09-19 09:31:00.023 2748 2748 D listed wake unlock(a on): #08 pc 000000000009b1e0 /system/lib64/libhidlbase.so (android::hardware::IPCThreadState::joinThreadPool(bool)+96) 09-19 09:31:00.023 2748 2748 D listed wake unlock(a on): #09 pc 000000000000a608 /system/bin/hw/android.system.suspend@1.0-service (main+1464) 09-19 09:31:00.023 2748 2748 D listed wake unlock(a on): #10 pc 000000000007d844 /apex/com.android.runtime/lib64/bionic/libc.so (__libc_init+108) 09-19 09:31:00.023 2748 2748 E /system/bin/hw/android.system.suspend@1.0-service: dec suspend cnt, name:PowerManagerService.WakeLocksmUseSuspendCounter: 0: Success
STR待机过程中,会先将wake_lock里的lock release,在STR resume时再acquire lock:
STR待机过程中release lock(PowerManagerService.Display):
09-19 09:36:24.666 2748 2748 D listed wake unlock(suspend): #00 pc 000000000000cc28 /system/bin/hw/android.system.suspend@1.0-service (android::system::suspend::V1_0::SystemSuspend::decSuspendCounter(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&)+232) 09-19 09:36:24.666 2748 2748 D listed wake unlock(suspend): #01 pc 000000000000d1a4 /system/bin/hw/android.system.suspend@1.0-service (_ZNSt3__117__call_once_proxyINS_5tupleIJOZN7android6system7suspend4V1_08WakeLock11releaseOnceEvEUlvE_EEEEEvPv+52) 09-19 09:36:24.666 2748 2748 D listed wake unlock(suspend): #02 pc 00000000000b0f74 /system/lib64/libc++.so (std::__1::__call_once(unsigned long volatile&, void*, void (*)(void*))+156) 09-19 09:36:24.666 2748 2748 D listed wake unlock(suspend): #03 pc 000000000000bcc8 /system/bin/hw/android.system.suspend@1.0-service (android::system::suspend::V1_0::WakeLock::release()+80) 09-19 09:36:24.666 2748 2748 D listed wake unlock(suspend): #04 pc 0000000000016f5c /system/lib64/android.system.suspend@1.0.so (android::system::suspend::V1_0::BnHwWakeLock::_hidl_release(android::hidl::base::V1_0::BnHwBase*, android::hardware::Parcel const&, android::hardware::Parcel*, std::__1::function<void (android::hardware::Parcel&)>)+164) 09-19 09:36:24.666 2748 2748 D listed wake unlock(suspend): #05 pc 000000000001734c /system/lib64/android.system.suspend@1.0.so (android::system::suspend::V1_0::BnHwWakeLock::onTransact(unsigned int, android::hardware::Parcel const&, android::hardware::Parcel*, unsigned int, std::__1::function<void (android::hardware::Parcel&)>)+308) 09-19 09:36:24.666 2748 2748 D listed wake unlock(suspend): #06 pc 0000000000096604 /system/lib64/libhidlbase.so (android::hardware::BHwBinder::transact(unsigned int, android::hardware::Parcel const&, android::hardware::Parcel*, unsigned int, std::__1::function<void (android::hardware::Parcel&)>)+68) 09-19 09:36:24.666 2748 2748 D listed wake unlock(suspend): #07 pc 0000000000099fcc /system/lib64/libhidlbase.so (android::hardware::IPCThreadState::getAndExecuteCommand()+1036) 09-19 09:36:24.666 2748 2748 D listed wake unlock(suspend): #08 pc 000000000009b1e0 /system/lib64/libhidlbase.so (android::hardware::IPCThreadState::joinThreadPool(bool)+96) 09-19 09:36:24.666 2748 2748 D listed wake unlock(suspend): #09 pc 000000000000a608 /system/bin/hw/android.system.suspend@1.0-service (main+1464) 09-19 09:36:24.666 2748 2748 D listed wake unlock(suspend): #10 pc 000000000007d844 /apex/com.android.runtime/lib64/bionic/libc.so (__libc_init+108) 09-19 09:36:24.666 2748 2748 E /system/bin/hw/android.system.suspend@1.0-service: dec suspend cnt, name:PowerManagerService.DisplaymUseSuspendCounter: 0: Success
wakeup count file
systemhardwareinterfacessuspend1.0defaultmain.cpp
static constexpr char kSysPowerWakeupCount[] = "/sys/power/wakeup_count"; int main() { unique_fd wakeupCountFd{TEMP_FAILURE_RETRY(open(kSysPowerWakeupCount, O_CLOEXEC | O_RDWR))}; sp<SystemSuspend> suspend = new SystemSuspend(std::move(wakeupCountFd), std::move(stateFd), 100 /* maxStatsEntries */, 100ms /* baseSleepTime */, suspendControl, false /* mUseSuspendCounter*/); status_t status = suspend->registerAsService();
SystemSuspend::SystemSuspend(unique_fd wakeupCountFd, unique_fd stateFd, size_t maxStatsEntries, std::chrono::milliseconds baseSleepTime, const sp<SuspendControlService>& controlService, bool useSuspendCounter) : mSuspendCounter(0), mWakeupCountFd(std::move(wakeupCountFd)),