Mir

Merge lp:~vanvugt/mir/generalise-next_frame_after into lp:mir

Proposed by Daniel van Vugt
Status: Merged
Merged at revision: 4170
Proposed branch: lp:~vanvugt/mir/generalise-next_frame_after
Merge into: lp:mir
Diff against target: 107 lines (+41/-5)
3 files modified
src/client/frame_clock.cpp (+10/-2)
src/client/frame_clock.h (+4/-3)
tests/unit-tests/client/test_frame_clock.cpp (+27/-0)
To merge this branch: bzr merge lp:~vanvugt/mir/generalise-next_frame_after
Reviewer Review Type Date Requested Status
Mir CI Bot continuous-integration Needs Fixing
Alan Griffiths Approve
Review via email: mp+323450@code.launchpad.net

Commit message

Generalise FrameClock::next_frame_after() to accept arbitrary
timestamps rather than assuming the input parameter is always
an in-phase frame timestamp.

Description of the change

Although I no longer have a hard need for this change, it's still worth landing so as to avoid future mistakes where someone might think next_frame_after(time) works correctly for an arbitrary time. This branch makes it so.

To post a comment you must log in.
Revision history for this message
Mir CI Bot (mir-ci-bot) wrote :

PASSED: Continuous integration, rev:4160
https://mir-jenkins.ubuntu.com/job/mir-ci/3383/
Executed test runs:
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-mir/4581
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-0-fetch/4709
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial+overlay/4698
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=zesty/4698
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=zesty/4613
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=zesty/4613/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial+overlay/4613
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial+overlay/4613/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=zesty/4613
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=zesty/4613/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=mesa,release=zesty/4613
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=mesa,release=zesty/4613/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial+overlay/4613
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial+overlay/4613/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://mir-jenkins.ubuntu.com/job/mir-ci/3383/rebuild

review: Approve (continuous-integration)
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

I don't find the naming easy to follow, but that's pre-existing

review: Approve
Revision history for this message
Mir CI Bot (mir-ci-bot) wrote :

FAILED: Autolanding.
More details in the following jenkins job:
https://mir-jenkins.ubuntu.com/job/mir-autolanding/1307/
Executed test runs:
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-mir/4625
    FAILURE: https://mir-jenkins.ubuntu.com/job/generic-land-mp/1392/console
    None: https://mir-jenkins.ubuntu.com/job/generic-land-mp/1393/console
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-0-fetch/4754
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial+overlay/4743
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=zesty/4743
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=zesty/4657
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=zesty/4657/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial+overlay/4657
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial+overlay/4657/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=zesty/4657
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=zesty/4657/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=mesa,release=zesty/4657
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=mesa,release=zesty/4657/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial+overlay/4657
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial+overlay/4657/artifact/output/*zip*/output.zip

review: Needs Fixing (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/client/frame_clock.cpp'
--- src/client/frame_clock.cpp 2016-11-29 08:00:45 +0000
+++ src/client/frame_clock.cpp 2017-05-01 07:03:11 +0000
@@ -31,6 +31,7 @@
31FrameClock::FrameClock(FrameClock::GetCurrentTime gct)31FrameClock::FrameClock(FrameClock::GetCurrentTime gct)
32 : get_current_time{gct}32 : get_current_time{gct}
33 , config_changed{false}33 , config_changed{false}
34 , phase{0}
34 , period{0}35 , period{0}
35 , resync_callback{std::bind(&FrameClock::fallback_resync_callback, this)}36 , resync_callback{std::bind(&FrameClock::fallback_resync_callback, this)}
36{37{
@@ -61,7 +62,7 @@
61 return period != period.zero() ? now - (now % period) : now;62 return period != period.zero() ? now - (now % period) : now;
62}63}
6364
64PosixTimestamp FrameClock::next_frame_after(PosixTimestamp prev) const65PosixTimestamp FrameClock::next_frame_after(PosixTimestamp when) const
65{66{
66 Lock lock(mutex);67 Lock lock(mutex);
67 /*68 /*
@@ -70,7 +71,12 @@
70 * it has no physical screen to sync to. Hence not throttled at all.71 * it has no physical screen to sync to. Hence not throttled at all.
71 */72 */
72 if (period == period.zero())73 if (period == period.zero())
73 return prev;74 return when;
75
76 /* Phase correction in case 'when' isn't in phase: */
77 auto const prev = when - ((when % period) - phase);
78 /* Verify it's been corrected: */
79 assert(prev % period == phase);
7480
75 /*81 /*
76 * Regardless of render times and scheduling delays, we should always82 * Regardless of render times and scheduling delays, we should always
@@ -109,6 +115,8 @@
109 auto const server_frame = resync_callback();115 auto const server_frame = resync_callback();
110 lock.lock();116 lock.lock();
111117
118 phase = server_frame % period;
119
112 /*120 /*
113 * Avoid mismatches (which will throw) and ensure we're always121 * Avoid mismatches (which will throw) and ensure we're always
114 * comparing timestamps of the same clock ID. This means our result122 * comparing timestamps of the same clock ID. This means our result
115123
=== modified file 'src/client/frame_clock.h'
--- src/client/frame_clock.h 2016-12-15 08:15:54 +0000
+++ src/client/frame_clock.h 2017-05-01 07:03:11 +0000
@@ -52,10 +52,10 @@
5252
53 /**53 /**
54 * Return the next timestamp to sleep_until, which comes after the last one54 * Return the next timestamp to sleep_until, which comes after the last one
55 * that was slept till. On the first frame you can just provide an55 * that was slept till (or more generally after time 'when'). On the first
56 * uninitialized timestamp.56 * frame you can just provide an uninitialized timestamp.
57 */57 */
58 time::PosixTimestamp next_frame_after(time::PosixTimestamp prev) const;58 time::PosixTimestamp next_frame_after(time::PosixTimestamp when) const;
5959
60private:60private:
61 time::PosixTimestamp fallback_resync_callback() const;61 time::PosixTimestamp fallback_resync_callback() const;
@@ -64,6 +64,7 @@
6464
65 mutable std::mutex mutex; // Protects below fields:65 mutable std::mutex mutex; // Protects below fields:
66 mutable bool config_changed;66 mutable bool config_changed;
67 mutable std::chrono::nanoseconds phase;
67 std::chrono::nanoseconds period;68 std::chrono::nanoseconds period;
68 ResyncCallback resync_callback;69 ResyncCallback resync_callback;
69};70};
7071
=== modified file 'tests/unit-tests/client/test_frame_clock.cpp'
--- tests/unit-tests/client/test_frame_clock.cpp 2017-03-13 08:12:52 +0000
+++ tests/unit-tests/client/test_frame_clock.cpp 2017-05-01 07:03:11 +0000
@@ -116,6 +116,33 @@
116 EXPECT_EQ(one_frame, e - d);116 EXPECT_EQ(one_frame, e - d);
117}117}
118118
119TEST_F(FrameClockTest, interval_is_perfectly_smooth_despite_parameter_jitter)
120{
121 FrameClock clock(with_fake_time);
122 clock.set_period(one_frame);
123
124 PosixTimestamp a;
125 auto b = clock.next_frame_after(a);
126
127 fake_sleep_until(b);
128 fake_sleep_for(one_frame/13); // short render time
129
130 auto c = clock.next_frame_after(b + 3ms);
131 EXPECT_EQ(one_frame, c - b);
132
133 fake_sleep_until(c);
134 fake_sleep_for(one_frame/7); // short render time
135
136 auto d = clock.next_frame_after(c + 1ms);
137 EXPECT_EQ(one_frame, d - c);
138
139 fake_sleep_until(d);
140 fake_sleep_for(one_frame/5); // short render time
141
142 auto e = clock.next_frame_after(d + 7ms);
143 EXPECT_EQ(one_frame, e - d);
144}
145
119TEST_F(FrameClockTest, long_render_time_is_recoverable_without_decimation)146TEST_F(FrameClockTest, long_render_time_is_recoverable_without_decimation)
120{147{
121 FrameClock clock(with_fake_time);148 FrameClock clock(with_fake_time);

Subscribers

People subscribed via source and target branches