• 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évisionf7791b77c561b0a632d498591898609bb2022831 (tree)
l'heure2019-03-26 08:55:40
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

Change-Id: I2d3b08a40ceb5fc81e8f4853d7c051db1ed4bbee

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() {
@@ -117,7 +136,7 @@ Return<sp<IWakeLock>> SystemSuspend::acquireWakeLock(WakeLockType /* type */,
117136 const hidl_string& name) {
118137 auto pid = getCallingPid();
119138 auto wlId = getWakeLockId(pid, name);
120- IWakeLock* wl = new WakeLock{this, wlId};
139+ IWakeLock* wl = new WakeLock{this, wlId, name};
121140 {
122141 auto l = std::lock_guard(mStatsLock);
123142
@@ -158,15 +177,27 @@ Return<void> SystemSuspend::debug(const hidl_handle& handle,
158177 return Void();
159178 }
160179
161-void SystemSuspend::incSuspendCounter() {
180+void SystemSuspend::incSuspendCounter(const string& name) {
162181 auto l = std::lock_guard(mCounterLock);
163- mSuspendCounter++;
182+ if (mUseSuspendCounter) {
183+ mSuspendCounter++;
184+ } else {
185+ if (!WriteStringToFd(name, mWakeLockFd)) {
186+ PLOG(ERROR) << "error writing " << name << " to " << kSysPowerWakeLock;
187+ }
188+ }
164189 }
165190
166-void SystemSuspend::decSuspendCounter() {
191+void SystemSuspend::decSuspendCounter(const string& name) {
167192 auto l = std::lock_guard(mCounterLock);
168- if (--mSuspendCounter == 0) {
169- mCounterCondVar.notify_one();
193+ if (mUseSuspendCounter) {
194+ if (--mSuspendCounter == 0) {
195+ mCounterCondVar.notify_one();
196+ }
197+ } else {
198+ if (!WriteStringToFd(name, mWakeUnlockFd)) {
199+ PLOG(ERROR) << "error writing " << name << " to " << kSysPowerWakeUnlock;
200+ }
170201 }
171202 }
172203
--- 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
@@ -106,6 +107,13 @@ class SystemSuspend : public ISystemSuspend {
106107 void updateSleepTime(bool success);
107108
108109 sp<SuspendControlService> mControlService;
110+
111+ // If true, use mSuspendCounter to keep track of native wake locks. Otherwise, rely on
112+ // /sys/power/wake_lock interface to block suspend.
113+ // TODO(b/128923994): remove dependency on /sys/power/wake_lock interface.
114+ bool mUseSuspendCounter;
115+ unique_fd mWakeLockFd;
116+ unique_fd mWakeUnlockFd;
109117 };
110118
111119 } // 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;