Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log platform selection #3212

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
Draft

Log platform selection #3212

wants to merge 14 commits into from

Conversation

RAOF
Copy link
Contributor

@RAOF RAOF commented Feb 1, 2024

Some logging, so I can get a snap on the Pi.

@RAOF RAOF marked this pull request as draft February 1, 2024 06:45
Copy link

codecov bot commented Feb 1, 2024

Codecov Report

Attention: 81 lines in your changes are missing coverage. Please review.

Comparison is base (5ca823e) 77.80% compared to head (60642de) 77.75%.

Files Patch % Lines
src/platforms/gbm-kms/server/buffer_allocator.cpp 0.00% 14 Missing ⚠️
src/platforms/gbm-kms/server/kms/platform.cpp 0.00% 12 Missing ⚠️
src/platforms/eglstream-kms/server/platform.cpp 0.00% 8 Missing ⚠️
src/platforms/eglstream-kms/server/display.cpp 0.00% 6 Missing ⚠️
src/platforms/gbm-kms/server/kms/display.cpp 0.00% 6 Missing ⚠️
...latforms/common/server/cpu_copy_output_surface.cpp 0.00% 4 Missing ⚠️
...on/server/kms_cpu_addressable_display_provider.cpp 0.00% 4 Missing ⚠️
...platforms/gbm-kms/server/gbm_display_allocator.cpp 0.00% 4 Missing ⚠️
...rc/platforms/gbm-kms/server/kms/display_buffer.cpp 0.00% 4 Missing ⚠️
src/platforms/x11/graphics/display_sink.cpp 0.00% 4 Missing ⚠️
... and 8 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3212      +/-   ##
==========================================
- Coverage   77.80%   77.75%   -0.05%     
==========================================
  Files        1062     1073      +11     
  Lines       74623    75146     +523     
==========================================
+ Hits        58061    58431     +370     
- Misses      16562    16715     +153     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@AlanGriffiths AlanGriffiths left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's also a legacy CStrFree hidden in existing code

Comment on lines 35 to 38
namespace mir
{
using CStr = std::unique_ptr<char[], CStringFree>;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That looks like a recipe for an ODR violation - thanks to the anon namespace CStringFree is a different type in each translation unit and that makes the mir::CStr definition different in each TU.

Comment on lines 17 to 38
#include <cstdlib>
#include <memory>

namespace
{
class CStringFree
{
public:
void operator()(char* str)
{
if(str)
{
free(str);
}
}
};
}

namespace mir
{
using CStr = std::unique_ptr<char[], CStringFree>;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. what? No header guards?
  2. The null check is redundant
  3. The operator() can be const
  4. This doesn't handle const c_strings
Suggested change
#include <cstdlib>
#include <memory>
namespace
{
class CStringFree
{
public:
void operator()(char* str)
{
if(str)
{
free(str);
}
}
};
}
namespace mir
{
using CStr = std::unique_ptr<char[], CStringFree>;
}
#ifndef MIR_OWNING_C_STR_
#define MIR_OWNING_C_STR_
#include <cstdlib>
#include <memory>
namespace mir
{
using CStr = std::unique_ptr<char[], decltype([](char const* p) { ::free(const_cast<char *>(p)); })>;
}
#endif

Comment on lines 373 to 396
rendering_platforms.reserve(rendering_platform_map.size());

// We want to make the egl-generic platform the last resort
// So don't push it into rendering_platforms until the rest are done
std::shared_ptr<graphics::RenderingPlatform> egl_generic;

for (auto const& rp : rendering_platform_map)
{
if (rp.first != "mir:egl-generic")
{
rendering_platforms.push_back(rp.second);
}
else
{
egl_generic = rp.second;
}
}

// If we skipped egl-generic, add it to the end
if (egl_generic)
{
rendering_platforms.push_back(egl_generic);
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this code is ugly, but why are we dropping it?

The commit comment "FIXME: Ooops! Don't throw away most of our hardware platforms!" doesn't reflect the change. (It just makes the order non-deterministic.)

@@ -311,6 +312,13 @@ auto mgg::DisplaySink::gbm_device() const -> std::shared_ptr<struct gbm_device>
return gbm;
}

auto mgg::DisplaySink::describe_output() const -> std::string
{
std::unique_ptr<char[], void(*)(char*)> drm_node{drmGetDeviceNameFromFd2(drm_fd()), [](char* to_free) { free(to_free); }};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another incantation for CStr

@Saviq
Copy link
Collaborator

Saviq commented Feb 1, 2024

Can confirm this brings Pi's performance back to what's expected.

@freefos this is work-in-progress, but could you confirm with snap refresh ubuntu-frame --channel 22/edge/mir-pr3212 please?

@AlanGriffiths
Copy link
Contributor

Can confirm this brings Pi's performance back to what's expected.

I'm struggling to know what changed to make that happen.

Apart from logging, the change to src/server/graphics/default_configuration.cpp looks like the only thing. But that avoids sorting rendering_platforms to "mostly alphabetical, with mir:egl-generic at the end" and leaves it in "order encountered". That probably just makes the first viable platform non-deterministic, which isn't necessarily a good thing.

@Saviq
Copy link
Collaborator

Saviq commented Feb 1, 2024

I'm struggling to know what changed to make that happen.

Here's @RAOF's explanation from Matrix:

In the “load egl-generic last” patch we made it so that we only keep the last device's platform for any given platform type.
So all the “make sure to match the renderer to the display when possible” code is selecting from a set that doesn't include the renderer that matches the display!

Yes, it needs a better solution (and bringing back the determinism), but this PR, so far, just confirmed the issue.

With both 2.15 and this PR, MotionMark in WPE detects 60fps with Frame at ~15% CPU, compared to 2.16.2 detecting 15fps at 50-60% CPU usage of Frame.

The logging from this branch provides:

Platform selection: Output gbm-kms (/dev/dri/card0) - KMS connector id: 89: Selected renderer: GBM surface on
/dev/dri/card0

@AlanGriffiths
Copy link
Contributor

In the “load egl-generic last” patch we made it so that we only keep the last device's platform for any given platform type.

Oh! We load multiple instances of each platform? I hadn't understood that. Easy to fix. (Incoming...)

#include <memory>
namespace mir
{
using CStr = std::unique_ptr<char[], decltype([](char const* p) { ::free(const_cast<char *>(p)); })>;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh. You learn something new every day. decltype(<lambda literal>) is a neat way of getting a type with a specific operator()!

@freefos
Copy link

freefos commented Feb 2, 2024

@Saviq I can confirm this fixes the fps issue.
129-mir2.16.2+dev81
image

@freefos
Copy link

freefos commented Feb 2, 2024

@Saviq With this release wpe-webkit-mir-kiosk restarts once in a while.
log_129-mir2.16.2+dev81_wpe-kiosk.txt

@freefos
Copy link

freefos commented Feb 2, 2024

@Saviq Its again the issue where the memory usage increases until it crashes.
As described here: canonical/ubuntu-frame#159
This hapens only when there is a vnc connection open.
But now it wasn't our web application but the motionmark website that is active.
image

@Saviq
Copy link
Collaborator

Saviq commented Feb 2, 2024

Thanks @freefos. #3213 is what we're going to backport to 2.16 soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triaged Triage into JIRA to plan it in
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants