Merge lp:~jhodapp/powerd/fix-music-app-next into lp:powerd

Proposed by Jim Hodapp
Status: Rejected
Rejected by: Ricardo Salveti
Proposed branch: lp:~jhodapp/powerd/fix-music-app-next
Merge into: lp:powerd
Diff against target: 44 lines (+19/-5)
1 file modified
src/power-request.c (+19/-5)
To merge this branch: bzr merge lp:~jhodapp/powerd/fix-music-app-next
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Seth Forshee (community) Disapprove
Ricardo Salveti Pending
Review via email: mp+229823@code.launchpad.net

Commit message

To prevent the device from suspending right away after the last lock is released, add a timeout and wait 6 seconds to release the final lock. This fixes bug: https://bugs.launchpad.net/powerd/+bug/1342351

Description of the change

To prevent the device from suspending right away after the last lock is released, add a timeout and wait 6 seconds to release the final lock. This fixes bug: https://bugs.launchpad.net/powerd/+bug/1342351

To post a comment you must log in.
Revision history for this message
Seth Forshee (sforshee) wrote :

First, I'd argue that powerd shouldn't have this sort of behavior at all, and that the media hub or whoever shouldn't release it's active state request until it's really okay for the device to suspend.

Assuming that powerd should have this behavior, this isn't the right way to do it. The point of using a wake lock here is to avoid a race with the in-kernel autosuspend and handling an incoming request. I.e., block suspend in the kernel until the reqeust can get handed over to the main thread and that thread disables suspend. If powerd were ever used with a kernel lacking autosuspend (e.g. the stock distro kernels) this will fail, because there's no notion of wake locks in these kernels.

It would be better to move the call to enter_suspend() to happen in a timeout 6 seconds in the future, but you've got to make sure that the timeout is cancelled if leaving the suspend state in the interim.

review: Disapprove
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Jim Hodapp (jhodapp) wrote :

Seth, thanks for the feedback. I wasn't quite sure where it should be done and thought about doing that in enter_suspend() as well. It wasn't quite obvious to me what the difference is between the two. Maybe adding a code comment for both functions would be appropriate to make it absolutely clear what the difference is?

I could go either way for a fix, either in powerd or media-hub. I'm discussing your objections to putting this in powerd with rsalveti. I do know of a way of accomplishing this in media-hub and may decide to move it there.

Revision history for this message
Ricardo Salveti (rsalveti) wrote :

Yeah, let's land this in media-hub for now, better to avoid races and regressions.

Unmerged revisions

137. By Jim Hodapp

To prevent the device from suspending right away after the last lock is released, add a timeout and wait 6 seconds to release the final lock. This fixes bug: https://bugs.launchpad.net/music-app/+bug/1342351

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/power-request.c'
--- src/power-request.c 2014-05-13 22:05:20 +0000
+++ src/power-request.c 2014-08-06 16:08:38 +0000
@@ -127,10 +127,22 @@
127 }127 }
128}128}
129129
130static gboolean release_wake_lock_cb(gpointer user_data)
131{
132 int ret;
133
134 powerd_debug("Unblocking suspend");
135 ret = libsuspend_release_wake_lock(power_request_wakelock_name);
136 if (ret)
137 powerd_warn("Could not release wake lock");
138
139 // Only call timeout callback once
140 return FALSE;
141}
142
130static void unblock_suspend(void)143static void unblock_suspend(void)
131{144{
132 gint old_count;145 gint old_count;
133 int ret;
134 gboolean retry;146 gboolean retry;
135147
136 do {148 do {
@@ -142,10 +154,12 @@
142 retry = !g_atomic_int_compare_and_exchange(&suspend_block_count,154 retry = !g_atomic_int_compare_and_exchange(&suspend_block_count,
143 old_count, old_count - 1);155 old_count, old_count - 1);
144 if (!retry && old_count == 1) {156 if (!retry && old_count == 1) {
145 powerd_debug("Unblocking suspend");157 // To prevent the device from suspending right away after the last
146 ret = libsuspend_release_wake_lock(power_request_wakelock_name);158 // lock is released, add a timeout and wait 6 seconds to release the
147 if (ret)159 // final lock.
148 powerd_warn("Could not release wake lock");160 // This fixes bug: https://bugs.launchpad.net/music-app/+bug/1342351
161 g_timeout_add_seconds(6, release_wake_lock_cb, NULL);
162 powerd_debug("Delaying suspend 6 seconds");
149 }163 }
150 } while (retry);164 } while (retry);
151}165}

Subscribers

People subscribed via source and target branches