pps: init driver in OnSetup

Initialization of driver has been moved to register_data_source() from
OnSetup() by: a739889789 ("pps: Report available counters when
gpu.counters* data source is registered")

With above change, pps will destroy driver when collecting data stops
(pps may keep running) then the driver will become nullptr when user try
to collect data again. This will cause segmentation fault in OnSetup().

So this remove driver = nullptr in OnStop() and init driver in OnSetup()
to make sure driver exists when pps-producer run more than once.

Fixes: a739889789 ("pps: Report available counters when gpu.counters*
data source is registered")

Signed-off-by: Julia Zhang <Julia.Zhang@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/36548>
(cherry picked from commit 20b809f1f0)
This commit is contained in:
Julia Zhang 2025-08-25 14:47:14 +08:00 committed by Eric Engestrom
parent 1cfa5a474b
commit a245b6cd72
2 changed files with 4 additions and 2 deletions

View file

@ -3684,7 +3684,7 @@
"description": "pps: init driver in OnSetup",
"nominated": true,
"nomination_type": 2,
"resolution": 0,
"resolution": 1,
"main_sha": null,
"because_sha": "a739889789f454b755ae9ff36cc4998835fee5e1",
"notes": null

View file

@ -40,6 +40,9 @@ float ms(const std::chrono::nanoseconds &t)
void GpuDataSource::OnSetup(const SetupArgs &args)
{
if (!driver->init_perfcnt())
PPS_LOG_ERROR("Failed to initialize %s driver", driver->drm_device.name.c_str());
// Parse perfetto config
const std::string &config_raw = args.config->gpu_counter_config_raw();
perfetto::protos::pbzero::GpuCounterConfig::Decoder config(config_raw);
@ -111,7 +114,6 @@ void GpuDataSource::OnStop(const StopArgs &args)
stop_closure();
driver->disable_perfcnt();
driver = nullptr;
std::lock_guard<std::mutex> lock(started_m);
started = false;