Mir

Merge lp:~kdub/mir/fix-1590765 into lp:mir

Proposed by Kevin DuBois
Status: Merged
Approved by: Cemil Azizoglu
Approved revision: no longer in the source branch.
Merged at revision: 3568
Proposed branch: lp:~kdub/mir/fix-1590765
Merge into: lp:mir
Diff against target: 171 lines (+46/-42)
3 files modified
src/client/buffer_vault.cpp (+23/-22)
src/client/buffer_vault.h (+1/-1)
tests/unit-tests/client/test_buffer_vault.cpp (+22/-19)
To merge this branch: bzr merge lp:~kdub/mir/fix-1590765
Reviewer Review Type Date Requested Status
Cemil Azizoglu (community) Approve
Alexandros Frantzis (community) Approve
Mir CI Bot continuous-integration Approve
Review via email: mp+298250@code.launchpad.net

Commit message

optimise a a resize scenario where a buffer reallaction is not necessary. Saves a reallocation, and fixes LP: #1570765 (which was a krillin/vegeta-specific bug)

Description of the change

optimise a a resize scenario where a buffer reallaction is not necessary. Saves a reallocation, and fixes LP: #1570765 (which was a krillin/vegeta-specific bug)

testing:
tested on arale, krillin, frieza
checked backport of fix to 0.23 series against (1590765, 1579076, and 1584784 (frieza-only))

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

FAILED: Continuous integration, rev:3552
https://mir-jenkins.ubuntu.com/job/mir-ci/1182/
Executed test runs:
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-mir/1336/console
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-0-fetch/1387
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=vivid+overlay/1378
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial/1378
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=vivid+overlay/1350
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=vivid+overlay/1350/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial/1350
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial/1350/artifact/output/*zip*/output.zip
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/1350/console
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/1350/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=android,release=vivid+overlay/1350
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=android,release=vivid+overlay/1350/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial/1350
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial/1350/artifact/output/*zip*/output.zip

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

review: Needs Fixing (continuous-integration)
Revision history for this message
Kevin DuBois (kdub) wrote :

accidentally got stuck in "WIP" for a few days

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

PASSED: Continuous integration, rev:3552
https://mir-jenkins.ubuntu.com/job/mir-ci/1214/
Executed test runs:
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-mir/1394
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-0-fetch/1445
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=vivid+overlay/1436
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial/1436
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=vivid+overlay/1408
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=vivid+overlay/1408/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial/1408
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial/1408/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/1408
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/1408/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=android,release=vivid+overlay/1408
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=android,release=vivid+overlay/1408/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial/1408
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial/1408/artifact/output/*zip*/output.zip

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

review: Approve (continuous-integration)
Revision history for this message
Alexandros Frantzis (afrantzis) wrote :

Looks good.

review: Approve
Revision history for this message
Cemil Azizoglu (cemil-azizoglu) wrote :

ok

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/client/buffer_vault.cpp'
2--- src/client/buffer_vault.cpp 2016-06-06 11:51:31 +0000
3+++ src/client/buffer_vault.cpp 2016-06-23 18:45:43 +0000
4@@ -137,9 +137,27 @@
5
6 mcl::NoTLSFuture<std::shared_ptr<mcl::MirBuffer>> mcl::BufferVault::withdraw()
7 {
8+ std::vector<int> free_ids;
9 std::unique_lock<std::mutex> lk(mutex);
10 if (disconnected_)
11 BOOST_THROW_EXCEPTION(std::logic_error("server_disconnected"));
12+
13+ //clean up incorrectly sized buffers
14+ for (auto it = buffers.begin(); it != buffers.end();)
15+ {
16+ auto buffer = checked_buffer_from_map(it->first);
17+ if ((it->second == Owner::Self) && (buffer->size() != size))
18+ {
19+ current_buffer_count--;
20+ free_ids.push_back(it->first);
21+ it = buffers.erase(it);
22+ }
23+ else
24+ {
25+ it++;
26+ }
27+ }
28+
29 mcl::NoTLSPromise<std::shared_ptr<mcl::MirBuffer>> promise;
30 auto it = available_buffer();
31 auto future = promise.get_future();
32@@ -147,6 +165,7 @@
33 {
34 it->second = Owner::ContentProducer;
35 promise.set_value(checked_buffer_from_map(it->first));
36+ lk.unlock();
37 }
38 else
39 {
40@@ -161,6 +180,9 @@
41 if (allocate_buffer)
42 alloc_buffer(s, format, usage);
43 }
44+
45+ for(auto& id : free_ids)
46+ free_buffer(id);
47 return future;
48 }
49
50@@ -283,30 +305,9 @@
51 set_size(lk, new_size);
52 }
53
54-void mcl::BufferVault::set_size(std::unique_lock<std::mutex>& lk, geometry::Size new_size)
55+void mcl::BufferVault::set_size(std::unique_lock<std::mutex> const&, geometry::Size new_size)
56 {
57- if (new_size == size)
58- return;
59- std::vector<int> free_ids;
60 size = new_size;
61- for (auto it = buffers.begin(); it != buffers.end();)
62- {
63- auto buffer = checked_buffer_from_map(it->first);
64- if ((it->second == Owner::Self) && (buffer->size() != size))
65- {
66- current_buffer_count--;
67- free_ids.push_back(it->first);
68- it = buffers.erase(it);
69- }
70- else
71- {
72- it++;
73- }
74- }
75- lk.unlock();
76-
77- for(auto& id : free_ids)
78- free_buffer(id);
79 }
80
81 void mcl::BufferVault::increase_buffer_count()
82
83=== modified file 'src/client/buffer_vault.h'
84--- src/client/buffer_vault.h 2016-06-06 11:51:31 +0000
85+++ src/client/buffer_vault.h 2016-06-23 18:45:43 +0000
86@@ -86,7 +86,7 @@
87 void free_buffer(int free_id);
88 void realloc_buffer(int free_id, geometry::Size size, MirPixelFormat format, int usage);
89 std::shared_ptr<MirBuffer> checked_buffer_from_map(int id);
90- void set_size(std::unique_lock<std::mutex>& lk, geometry::Size new_size);
91+ void set_size(std::unique_lock<std::mutex> const& lk, geometry::Size new_size);
92
93
94 std::shared_ptr<ClientBufferFactory> const platform_factory;
95
96=== modified file 'tests/unit-tests/client/test_buffer_vault.cpp'
97--- tests/unit-tests/client/test_buffer_vault.cpp 2016-06-06 11:51:31 +0000
98+++ tests/unit-tests/client/test_buffer_vault.cpp 2016-06-23 18:45:43 +0000
99@@ -327,9 +327,10 @@
100 EXPECT_CALL(mock_requests, allocate_buffer(new_size,_,_));
101
102 vault.wire_transfer_inbound(package.buffer_id());
103+ Mock::VerifyAndClearExpectations(&mock_requests);
104+
105 vault.wire_transfer_inbound(package4.buffer_id());
106 EXPECT_THAT(vault.withdraw().get()->size(), Eq(new_size));
107- Mock::VerifyAndClearExpectations(&mock_requests);
108 }
109
110 TEST_F(StartedBufferVault, withdraw_gives_only_newly_sized_buffers_after_resize)
111@@ -342,20 +343,6 @@
112 Mock::VerifyAndClearExpectations(&mock_requests);
113 }
114
115-TEST_F(StartedBufferVault, setting_size_frees_unneeded_buffers_right_away)
116-{
117- EXPECT_CALL(mock_requests, free_buffer(_)).Times(3);
118- EXPECT_CALL(mock_requests, allocate_buffer(_,_,_)).Times(0);
119- auto const cycles = 30u;
120- geom::Size new_size(80, 100);
121- for(auto i = 0u; i < cycles; i++)
122- {
123- new_size = geom::Size(geom::Width(i), new_size.height);
124- vault.set_size(new_size);
125- }
126- Mock::VerifyAndClearExpectations(&mock_requests);
127-}
128-
129 TEST_F(StartedBufferVault, scaling_resizes_buffers_right_away)
130 {
131 EXPECT_CALL(mock_requests, allocate_buffer(_,_,_))
132@@ -563,10 +550,28 @@
133 Mock::VerifyAndClearExpectations(&mock_requests);
134 }
135
136+//LP: #1590765 (more efficient allocations, and krillin/mali accommodation)
137+TEST_F(StartedBufferVault, doesnt_free_buffer_until_a_newly_sized_buffer_is_called_for)
138+{
139+ auto i = 0u;
140+ auto const num_resizes = 10u;
141+ std::array<geom::Size, num_resizes> other_sizes;
142+ std::generate(other_sizes.begin(), other_sizes.end(),
143+ [&i, this] { return geom::Size{ size.width.as_int() + i, size.height.as_int() + i }; } );
144+
145+ EXPECT_CALL(mock_requests, free_buffer(_))
146+ .Times(0);
147+ for(auto const& size : other_sizes)
148+ vault.set_size(size);
149+ vault.set_size(size); //set back the original size
150+
151+ auto buffer_future = vault.withdraw();
152+ EXPECT_THAT(buffer_future.get()->size(), Eq(size));
153+ Mock::VerifyAndClearExpectations(&mock_requests);
154+}
155+
156 TEST_F(StartedBufferVault, doesnt_free_buffers_in_the_driver_after_resize)
157 {
158- EXPECT_CALL(mock_requests, free_buffer(_))
159- .Times(2);
160 auto buffer = vault.withdraw().get();
161 vault.set_size(new_size);
162 Mock::VerifyAndClearExpectations(&mock_requests);
163@@ -582,8 +587,6 @@
164
165 TEST_F(StartedBufferVault, doesnt_free_buffers_with_content_after_resize)
166 {
167- EXPECT_CALL(mock_requests, free_buffer(_))
168- .Times(2);
169 auto buffer = vault.withdraw().get();
170 vault.deposit(buffer);
171 vault.set_size(new_size);

Subscribers

People subscribed via source and target branches