• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Aucun tag

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

system/hardware/interfaces


Commit MetaInfo

Révisionfe11412c1508b3010c54fb6f34e3120179209289 (tree)
l'heure2019-03-26 09:14:18
AuteurTri Vo <trong@goog...>
Commiterandroid-build-merger

Message de Log

Ability to choose either suspend counter or /sys/power/wake_lock. am: a833d47822 am: 85ad4a9a10
am: f7791b77c5

Change-Id: I23fa71e80b2ad2c6812407fa3adfe62e26fbc749

Change Summary

Modification

--- a/suspend/1.0/default/SystemSuspend.cpp
+++ b/suspend/1.0/default/SystemSuspend.cpp
@@ -42,6 +42,10 @@ namespace suspend {
4242 namespace V1_0 {
4343
4444 static const char kSleepState[] = "mem";
45+// TODO(b/128923994): we only need /sys/power/wake_[un]lock to export debugging info via
46+// /sys/kernel/debug/wakeup_sources.
47+static constexpr char kSysPowerWakeLock[] = "/sys/power/wake_lock";
48+static constexpr char kSysPowerWakeUnlock[] = "/sys/power/wake_unlock";
4549
4650 // This function assumes that data in fd is small enough that it can be read in one go.
4751 // We use this function instead of the ones available in libbase because it doesn't block
@@ -67,9 +71,9 @@ TimestampType getEpochTimeNow() {
6771 return std::chrono::duration_cast<std::chrono::microseconds>(timeSinceEpoch).count();
6872 }
6973
70-WakeLock::WakeLock(SystemSuspend* systemSuspend, const WakeLockIdType& id)
71- : mReleased(), mSystemSuspend(systemSuspend), mId(id) {
72- mSystemSuspend->incSuspendCounter();
74+WakeLock::WakeLock(SystemSuspend* systemSuspend, const WakeLockIdType& id, const string& name)
75+ : mReleased(), mSystemSuspend(systemSuspend), mId(id), mName(name) {
76+ mSystemSuspend->incSuspendCounter(mName);
7377 }
7478
7579 WakeLock::~WakeLock() {
@@ -83,22 +87,37 @@ Return<void> WakeLock::release() {
8387
8488 void WakeLock::releaseOnce() {
8589 std::call_once(mReleased, [this]() {
86- mSystemSuspend->decSuspendCounter();
90+ mSystemSuspend->decSuspendCounter(mName);
8791 mSystemSuspend->deleteWakeLockStatsEntry(mId);
8892 });
8993 }
9094
9195 SystemSuspend::SystemSuspend(unique_fd wakeupCountFd, unique_fd stateFd, size_t maxStatsEntries,
9296 std::chrono::milliseconds baseSleepTime,
93- const sp<SuspendControlService>& controlService)
97+ const sp<SuspendControlService>& controlService,
98+ bool useSuspendCounter)
9499 : mSuspendCounter(0),
95100 mWakeupCountFd(std::move(wakeupCountFd)),
96101 mStateFd(std::move(stateFd)),
97102 mMaxStatsEntries(maxStatsEntries),
98103 mBaseSleepTime(baseSleepTime),
99104 mSleepTime(baseSleepTime),
100- mControlService(controlService) {
105+ mControlService(controlService),
106+ mUseSuspendCounter(useSuspendCounter),
107+ mWakeLockFd(-1),
108+ mWakeUnlockFd(-1) {
101109 mControlService->setSuspendService(this);
110+
111+ if (!mUseSuspendCounter) {
112+ mWakeLockFd.reset(TEMP_FAILURE_RETRY(open(kSysPowerWakeLock, O_CLOEXEC | O_RDWR)));
113+ if (mWakeLockFd < 0) {
114+ PLOG(ERROR) << "error opening " << kSysPowerWakeLock;
115+ }
116+ mWakeUnlockFd.reset(TEMP_FAILURE_RETRY(open(kSysPowerWakeUnlock, O_CLOEXEC | O_RDWR)));
117+ if (mWakeUnlockFd < 0) {
118+ PLOG(ERROR) << "error opening " << kSysPowerWakeUnlock;
119+ }
120+ }
102121 }
103122
104123 bool SystemSuspend::enableAutosuspend() {
@@ -133,7 +152,7 @@ Return<sp<IWakeLock>> SystemSuspend::acquireWakeLock(WakeLockType /* type */,
133152 const hidl_string& name) {
134153 auto pid = getCallingPid();
135154 auto wlId = getWakeLockId(pid, name);
136- IWakeLock* wl = new WakeLock{this, wlId};
155+ IWakeLock* wl = new WakeLock{this, wlId, name};
137156 {
138157 auto l = std::lock_guard(mStatsLock);
139158
@@ -174,15 +193,27 @@ Return<void> SystemSuspend::debug(const hidl_handle& handle,
174193 return Void();
175194 }
176195
177-void SystemSuspend::incSuspendCounter() {
196+void SystemSuspend::incSuspendCounter(const string& name) {
178197 auto l = std::lock_guard(mCounterLock);
179- mSuspendCounter++;
198+ if (mUseSuspendCounter) {
199+ mSuspendCounter++;
200+ } else {
201+ if (!WriteStringToFd(name, mWakeLockFd)) {
202+ PLOG(ERROR) << "error writing " << name << " to " << kSysPowerWakeLock;
203+ }
204+ }
180205 }
181206
182-void SystemSuspend::decSuspendCounter() {
207+void SystemSuspend::decSuspendCounter(const string& name) {
183208 auto l = std::lock_guard(mCounterLock);
184- if (--mSuspendCounter == 0) {
185- mCounterCondVar.notify_one();
209+ if (mUseSuspendCounter) {
210+ if (--mSuspendCounter == 0) {
211+ mCounterCondVar.notify_one();
212+ }
213+ } else {
214+ if (!WriteStringToFd(name, mWakeUnlockFd)) {
215+ PLOG(ERROR) << "error writing " << name << " to " << kSysPowerWakeUnlock;
216+ }
186217 }
187218 }
188219
--- a/suspend/1.0/default/SystemSuspend.h
+++ b/suspend/1.0/default/SystemSuspend.h
@@ -53,7 +53,7 @@ TimestampType getEpochTimeNow();
5353
5454 class WakeLock : public IWakeLock {
5555 public:
56- WakeLock(SystemSuspend* systemSuspend, const WakeLockIdType& id);
56+ WakeLock(SystemSuspend* systemSuspend, const WakeLockIdType& id, const std::string& name);
5757 ~WakeLock();
5858
5959 Return<void> release();
@@ -64,17 +64,18 @@ class WakeLock : public IWakeLock {
6464
6565 SystemSuspend* mSystemSuspend;
6666 WakeLockIdType mId;
67+ std::string mName;
6768 };
6869
6970 class SystemSuspend : public ISystemSuspend {
7071 public:
7172 SystemSuspend(unique_fd wakeupCountFd, unique_fd stateFd, size_t maxStatsEntries,
7273 std::chrono::milliseconds baseSleepTime,
73- const sp<SuspendControlService>& controlService);
74+ const sp<SuspendControlService>& controlService, bool useSuspendCounter = true);
7475 Return<sp<IWakeLock>> acquireWakeLock(WakeLockType type, const hidl_string& name) override;
7576 Return<void> debug(const hidl_handle& handle, const hidl_vec<hidl_string>& options) override;
76- void incSuspendCounter();
77- void decSuspendCounter();
77+ void incSuspendCounter(const std::string& name);
78+ void decSuspendCounter(const std::string& name);
7879 void deleteWakeLockStatsEntry(WakeLockIdType id);
7980 bool enableAutosuspend();
8081 bool forceSuspend();
@@ -107,6 +108,13 @@ class SystemSuspend : public ISystemSuspend {
107108 void updateSleepTime(bool success);
108109
109110 sp<SuspendControlService> mControlService;
111+
112+ // If true, use mSuspendCounter to keep track of native wake locks. Otherwise, rely on
113+ // /sys/power/wake_lock interface to block suspend.
114+ // TODO(b/128923994): remove dependency on /sys/power/wake_lock interface.
115+ bool mUseSuspendCounter;
116+ unique_fd mWakeLockFd;
117+ unique_fd mWakeUnlockFd;
110118 };
111119
112120 } // namespace V1_0
--- a/suspend/1.0/default/android.system.suspend@1.0-service.rc
+++ b/suspend/1.0/default/android.system.suspend@1.0-service.rc
@@ -1,4 +1,5 @@
11 service system_suspend /system/bin/hw/android.system.suspend@1.0-service
22 class hal
33 user system
4- group system
4+ group system wakelock
5+ capabilities BLOCK_SUSPEND
--- a/suspend/1.0/default/main.cpp
+++ b/suspend/1.0/default/main.cpp
@@ -81,7 +81,7 @@ int main() {
8181
8282 sp<SystemSuspend> suspend =
8383 new SystemSuspend(std::move(wakeupCountFd), std::move(stateFd), 100 /* maxStatsEntries */,
84- 100ms /* baseSleepTime */, suspendControl);
84+ 100ms /* baseSleepTime */, suspendControl, false /* mUseSuspendCounter*/);
8585 status_t status = suspend->registerAsService();
8686 if (android::OK != status) {
8787 LOG(FATAL) << "Unable to register system-suspend service: " << status;