freedreno/drm: Only initialize memory data source when Perfetto is active

FdMemoryDataSource was being registered as a Perfetto data source
unconditionally which led to anything calling fd_device_new(...)
attempting to do this even when they might not have Perfetto
initialized which is done as a part of util_perfetto_init, without
which trying to register the event causes a SEGFAULT.

Fixes: c7045e3e63 ("perfetto: unify init")

Signed-off-by: Mark Collins <mark@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/36993>
(cherry picked from commit 098521559d)
This commit is contained in:
Mark Collins 2025-08-25 21:35:45 +00:00 committed by Eric Engestrom
parent 1ce7aca953
commit 17621e7943
2 changed files with 12 additions and 4 deletions

View file

@ -854,7 +854,7 @@
"description": "freedreno/drm: Only initialize memory data source when Perfetto is active",
"nominated": true,
"nomination_type": 2,
"resolution": 0,
"resolution": 1,
"main_sha": null,
"because_sha": "c7045e3e6331c207065b77285ea9e786276ca0d2",
"notes": null

View file

@ -50,17 +50,25 @@ class FdMemoryDataSource : public perfetto::DataSource<FdMemoryDataSource> {
PERFETTO_DECLARE_DATA_SOURCE_STATIC_MEMBERS(FdMemoryDataSource);
PERFETTO_DEFINE_DATA_SOURCE_STATIC_MEMBERS(FdMemoryDataSource);
bool fd_drm_perfetto_active = false;
extern "C" void
fd_drm_perfetto_init(void)
{
perfetto::DataSourceDescriptor dsd;
dsd.set_name("gpu.memory.msm");
FdMemoryDataSource::Register(dsd);
if (!fd_drm_perfetto_active && util_perfetto_is_tracing_enabled()) {
perfetto::DataSourceDescriptor dsd;
dsd.set_name("gpu.memory.msm");
FdMemoryDataSource::Register(dsd);
fd_drm_perfetto_active = true;
}
}
extern "C" void
fd_alloc_log(struct fd_bo *bo, enum fd_alloc_category from, enum fd_alloc_category to)
{
if (!fd_drm_perfetto_active)
return;
/* Special case for BOs that back heap chunks, they don't immediately
* transition to active, despite what the caller thinks:
*/