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
1=== modified file 'src/power-request.c'
2--- src/power-request.c 2014-05-13 22:05:20 +0000
3+++ src/power-request.c 2014-08-06 16:08:38 +0000
4@@ -127,10 +127,22 @@
5 }
6 }
7
8+static gboolean release_wake_lock_cb(gpointer user_data)
9+{
10+ int ret;
11+
12+ powerd_debug("Unblocking suspend");
13+ ret = libsuspend_release_wake_lock(power_request_wakelock_name);
14+ if (ret)
15+ powerd_warn("Could not release wake lock");
16+
17+ // Only call timeout callback once
18+ return FALSE;
19+}
20+
21 static void unblock_suspend(void)
22 {
23 gint old_count;
24- int ret;
25 gboolean retry;
26
27 do {
28@@ -142,10 +154,12 @@
29 retry = !g_atomic_int_compare_and_exchange(&suspend_block_count,
30 old_count, old_count - 1);
31 if (!retry && old_count == 1) {
32- powerd_debug("Unblocking suspend");
33- ret = libsuspend_release_wake_lock(power_request_wakelock_name);
34- if (ret)
35- powerd_warn("Could not release wake lock");
36+ // To prevent the device from suspending right away after the last
37+ // lock is released, add a timeout and wait 6 seconds to release the
38+ // final lock.
39+ // This fixes bug: https://bugs.launchpad.net/music-app/+bug/1342351
40+ g_timeout_add_seconds(6, release_wake_lock_cb, NULL);
41+ powerd_debug("Delaying suspend 6 seconds");
42 }
43 } while (retry);
44 }

Subscribers

People subscribed via source and target branches