Mir

Merge lp:~vanvugt/mir/fix-1373809 into lp:mir

Proposed by Daniel van Vugt
Status: Merged
Approved by: Kevin DuBois
Approved revision: no longer in the source branch.
Merged at revision: 1939
Proposed branch: lp:~vanvugt/mir/fix-1373809
Merge into: lp:mir
Diff against target: 41 lines (+13/-2)
2 files modified
src/common/input/android/android_input_receiver.cpp (+9/-1)
tests/unit-tests/client/input/test_android_input_receiver.cpp (+4/-1)
To merge this branch: bzr merge lp:~vanvugt/mir/fix-1373809
Reviewer Review Type Date Requested Status
Kevin DuBois (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Alexandros Frantzis (community) Approve
Review via email: mp+235917@code.launchpad.net

Commit message

Avoid polling in a loop with timeout zero most of the time. That
will only waste CPU. (LP: #1373809)

This also fixes test failure LP: #1373826.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Alexandros Frantzis (afrantzis) wrote :

Looks sensible.

Does it make sense to experiment with other timeout values, in order to find an even better trade-off between CPU consumption and event latency?

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Kevin DuBois (kdub) wrote :

looks good to me

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/common/input/android/android_input_receiver.cpp'
--- src/common/input/android/android_input_receiver.cpp 2014-09-25 07:57:28 +0000
+++ src/common/input/android/android_input_receiver.cpp 2014-09-25 09:02:15 +0000
@@ -142,11 +142,19 @@
142 }142 }
143143
144 auto reduced_timeout = timeout;144 auto reduced_timeout = timeout;
145 if (input_consumer->hasDeferredEvent() || input_consumer->hasPendingBatch())145 if (input_consumer->hasDeferredEvent())
146 {146 {
147 // consume() didn't finish last time. Retry it immediately.147 // consume() didn't finish last time. Retry it immediately.
148 reduced_timeout = std::chrono::milliseconds::zero();148 reduced_timeout = std::chrono::milliseconds::zero();
149 }149 }
150 else if (input_consumer->hasPendingBatch())
151 {
152 // When in constant motion we will usually "hasPendingBatch".
153 // But the batch won't get flushed until the next frame interval,
154 // so be sure to use a non-zero sleep time to avoid spinning the CPU
155 // for the whole interval...
156 reduced_timeout = std::chrono::milliseconds(1);
157 }
150158
151 auto result = looper->pollOnce(reduced_timeout.count());159 auto result = looper->pollOnce(reduced_timeout.count());
152 if (result == ALOOPER_POLL_WAKE)160 if (result == ALOOPER_POLL_WAKE)
153161
=== modified file 'tests/unit-tests/client/input/test_android_input_receiver.cpp'
--- tests/unit-tests/client/input/test_android_input_receiver.cpp 2014-09-25 07:57:28 +0000
+++ tests/unit-tests/client/input/test_android_input_receiver.cpp 2014-09-25 09:02:15 +0000
@@ -243,8 +243,11 @@
243 // Sadly using real time as droidinput::Looper doesn't use a mocked clock.243 // Sadly using real time as droidinput::Looper doesn't use a mocked clock.
244 ASSERT_LT(duration_cast<nanoseconds>(duration).count(), one_frame);244 ASSERT_LT(duration_cast<nanoseconds>(duration).count(), one_frame);
245245
246 // Verify we don't use all the CPU by not sleeping (LP: #1373809)
247 EXPECT_GT(duration_cast<nanoseconds>(duration).count(), one_millisecond);
248
246 // But later in a frame or so, the motion will be reported:249 // But later in a frame or so, the motion will be reported:
247 t += one_frame;250 t += 2 * one_frame; // Account for the new slower 55Hz event rate
248 ASSERT_TRUE(receiver.next_event(max_timeout, ev));251 ASSERT_TRUE(receiver.next_event(max_timeout, ev));
249 ASSERT_EQ(mir_event_type_motion, ev.type);252 ASSERT_EQ(mir_event_type_motion, ev.type);
250}253}

Subscribers

People subscribed via source and target branches