Mir

Merge lp:~alan-griffiths/mir/fix-1288570 into lp:mir

Proposed by Alan Griffiths
Status: Merged
Approved by: Alan Griffiths
Approved revision: no longer in the source branch.
Merged at revision: 1458
Proposed branch: lp:~alan-griffiths/mir/fix-1288570
Merge into: lp:mir
Diff against target: 81 lines (+27/-19)
2 files modified
src/server/compositor/switching_bundle.cpp (+26/-19)
src/server/compositor/switching_bundle.h (+1/-0)
To merge this branch: bzr merge lp:~alan-griffiths/mir/fix-1288570
Reviewer Review Type Date Requested Status
Daniel van Vugt Approve
PS Jenkins bot (community) continuous-integration Approve
Alexandros Frantzis (community) Needs Fixing
Review via email: mp+209662@code.launchpad.net

Commit message

compositor: check that client buffers are actually available before completing client_acquire. (fixes 1288570)

Description of the change

compositor: check that client buffers are actually available before completing client_acquire. (fixes 1288570)

To post a comment you must log in.
Revision history for this message
Alexandros Frantzis (afrantzis) wrote :

Without this patch I get a constant 120 FPS when the app is between screens. Applying this patch I get 60FPS for a few seconds, then a couple of seconds of increased frame rate, and so on:

120 FPS
60 FPS
60 FPS
60 FPS
60 FPS
60 FPS
80 FPS
120 FPS
61 FPS
60 FPS
60 FPS
60 FPS
60 FPS
77 FPS
120 FPS
64 FPS
60 FPS
60 FPS
60 FPS
60 FPS
78 FPS
120 FPS
62 FPS
60 FPS
60 FPS
60 FPS
60 FPS
78 FPS

review: Needs Fixing
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

> Without this patch I get a constant 120 FPS when the app is between screens.
> Applying this patch I get 60FPS for a few seconds, then a couple of seconds of
> increased frame rate, and so on:

Weird. I see a steady 60fps for minutes.

As I can't reproduce your result could you help by trying -r1455 of this branch (which simply reinstates the synchronous behavior).

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Alexandros Frantzis (afrantzis) wrote :

With r1455 behavior is the same as with r1457:

60 FPS
66 FPS
120 FPS
77 FPS
60 FPS
60 FPS
60 FPS
60 FPS
65 FPS
120 FPS
78 FPS
60 FPS
60 FPS
60 FPS
60 FPS
65 FPS
120 FPS
78 FPS

FWIW, this is on an intel laptop with screen 1280x800, and external screen 1920x1080 connected with VGA.

Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

On my intel laptop with screen 1600x900 and external 1920x1080 I see a slight variation in speed. (between 56fps and 62fps)

The animation looks fine throughout.

Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

Update - I just saw it hit 90fps

Revision history for this message
Daniel van Vugt (vanvugt) wrote :

Seems to solve the problem for me. Though I don't yet understand the new algorithm to understand why.

Some thoughts:

(1) This shouldn't be inline. There's no performance benefit and it will just bloat the code slightly:
8 +inline
9 +bool mc::SwitchingBundle::client_buffers_available(std::unique_lock<std::mutex> const& /*lock*/)

(2) The lock parameter in the above function is unnecessary (except as documentation?), so should be removed. The function is always called inside a lock anyway.

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

The effect Alexandros reports running on his laptop already exists in -r 1397 and clearly has a different root cause to 1288570.

Landing this and reporting a new bug.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/server/compositor/switching_bundle.cpp'
2--- src/server/compositor/switching_bundle.cpp 2014-03-06 05:29:00 +0000
3+++ src/server/compositor/switching_bundle.cpp 2014-03-06 12:38:10 +0000
4@@ -182,6 +182,29 @@
5 return ring[slot].buf;
6 }
7
8+inline
9+bool mc::SwitchingBundle::client_buffers_available(std::unique_lock<std::mutex> const& /*lock*/)
10+{
11+ /*
12+ * Even if there are free buffers available, we might wish to still
13+ * wait. This is so we don't touch (hence allocate) a third or higher
14+ * buffer until/unless it's absolutely necessary. It becomes necessary
15+ * only when framedropping (above) or with overlapping compositors
16+ * (like with bypass).
17+ * The performance benefit of triple buffering is usually minimal,
18+ * but always uses 50% more memory. So try to avoid it when possible.
19+ */
20+
21+ int min_free =
22+#if 0 // FIXME: This memory optimization breaks timing tests
23+ (nbuffers > 2 && !overlapping_compositors) ? nbuffers - 1 : 1;
24+#else
25+ 1;
26+#endif
27+
28+ return nfree() >= min_free;
29+}
30+
31 void mc::SwitchingBundle::client_acquire(std::function<void(graphics::Buffer* buffer)> complete)
32 {
33 std::unique_lock<std::mutex> lock(guard);
34@@ -199,24 +222,7 @@
35 }
36 else
37 {
38- /*
39- * Even if there are free buffers available, we might wish to still
40- * wait. This is so we don't touch (hence allocate) a third or higher
41- * buffer until/unless it's absolutely necessary. It becomes necessary
42- * only when framedropping (above) or with overlapping compositors
43- * (like with bypass).
44- * The performance benefit of triple buffering is usually minimal,
45- * but always uses 50% more memory. So try to avoid it when possible.
46- */
47-
48- int min_free =
49-#if 0 // FIXME: This memory optimization breaks timing tests
50- (nbuffers > 2 && !overlapping_compositors) ? nbuffers - 1 : 1;
51-#else
52- 1;
53-#endif
54-
55- if (nfree() < min_free)
56+ if (!client_buffers_available(lock))
57 return;
58 }
59
60@@ -362,7 +368,8 @@
61 ncompositors--;
62 }
63
64- if (client_acquire_todo) complete_client_acquire(std::move(lock));
65+ if (client_buffers_available(lock) && client_acquire_todo)
66+ complete_client_acquire(std::move(lock));
67 }
68 }
69
70
71=== modified file 'src/server/compositor/switching_bundle.h'
72--- src/server/compositor/switching_bundle.h 2014-03-06 05:29:00 +0000
73+++ src/server/compositor/switching_bundle.h 2014-03-06 12:38:10 +0000
74@@ -84,6 +84,7 @@
75
76 const std::shared_ptr<graphics::Buffer> &alloc_buffer(int slot);
77 void complete_client_acquire(std::unique_lock<std::mutex> lock);
78+ bool client_buffers_available(std::unique_lock<std::mutex> const& lock);
79 struct SharedBuffer
80 {
81 std::shared_ptr<graphics::Buffer> buf;

Subscribers

People subscribed via source and target branches