From d65ffc65765b2155aef7afc31e288bb3c47119e9 Mon Sep 17 00:00:00 2001 From: ZhuChenyanX Date: Thu, 12 Dec 2024 08:36:12 +0000 Subject: [PATCH] Fix CtsGpuProfilingDataTest fail Rename the perfetto gpu data producer name from libpps-producer to libgpudataproducer to align with AGI/cts. To pass the test, it also need following cmd: 1, setenforce 0 2, sysctl dev.i915.perf_stream_paranoid=0 sysctl dev.i915_ag.perf_stream_paranoid=0 When in vm mode, at least 1 gpu needs to be passthoughed. SRIOV mode has no metrics info provided under dir: /sys/dev/char/%d:%d/device/drm Tracked-On: OAM-128278 Signed-off-by: ZhuChenyanX --- android/Android.mk | 7 +++---- android/mesa3d_cross.mk | 1 + android/perfetto/pps-producer.cc | 29 +++++++++++++++++++++++++++-- src/intel/ds/intel_driver_ds.cc | 5 +++++ src/intel/ds/intel_pps_driver.cc | 10 +++++++++- src/tool/pps/cfg/gpu.cfg | 9 +++++++++ src/tool/pps/cfg/intel.cfg | 15 +++++++++++++++ src/tool/pps/cfg/system.cfg | 15 +++++++++++++++ src/tool/pps/pps_datasource.cc | 9 +++++++++ src/tool/pps/pps_producer.cc | 21 ++++++++++++++++++++- 10 files changed, 113 insertions(+), 8 deletions(-) diff --git a/android/Android.mk b/android/Android.mk index 339d7f25e73..a8b790bcdc5 100644 --- a/android/Android.mk +++ b/android/Android.mk @@ -183,8 +183,8 @@ ifneq ($(strip $(BOARD_MESA3D_GALLIUM_DRIVERS)),) $(eval $(call mesa3d-lib,libgallium_dri,.so.0,dri,MESA3D_GALLIUM_DRI_BIN)) # Module 'libglapi', produces '/vendor/lib{64}/libglapi.so' $(eval $(call mesa3d-lib,libglapi,.so.0,,MESA3D_LIBGLAPI_BIN)) -# Module 'libpps-producer', produces '/vendor/lib{64}/libpps-producer.so' -$(eval $(call mesa3d-lib,libpps-producer,.so.0,,MESA3D_LIBPPS_PRODUCER)) +# Module 'libgpudataproducer', produces '/vendor/lib{64}/libgpudataproducer.so' +$(eval $(call mesa3d-lib,libgpudataproducer,.so.0,,MESA3D_LIBPPS_PRODUCER)) # Module 'libEGL_mesa', produces '/vendor/lib{64}/egl/libEGL_mesa.so' $(eval $(call mesa3d-lib,libEGL_mesa,.so.1,egl,MESA3D_LIBEGL_BIN)) @@ -206,10 +206,9 @@ endif #------------------------------------------------------------------------------- include $(CLEAR_VARS) -LOCAL_SHARED_LIBRARIES := libpps-producer LOCAL_SRC_FILES := perfetto/pps-producer.cc LOCAL_VENDOR_MODULE := true -LOCAL_MODULE := pps-producer +LOCAL_MODULE := gpudataproducer LOCAL_CPP_EXTENSION := .cc LOCAL_MODULE_TAGS := optional include $(BUILD_EXECUTABLE) diff --git a/android/mesa3d_cross.mk b/android/mesa3d_cross.mk index 244ad815814..ae36cf020db 100644 --- a/android/mesa3d_cross.mk +++ b/android/mesa3d_cross.mk @@ -96,6 +96,7 @@ MESON_GEN_NINJA := \ -Dlmsensors=disabled \ -Dandroid-libbacktrace=disabled \ -Dperfetto=true \ + -Ddatasources=auto \ $(BOARD_MESA3D_MESON_ARGS) \ MESON_BUILD := PATH=/usr/bin:/bin:/sbin:$$PATH ninja -C $(MESON_OUT_DIR)/build diff --git a/android/perfetto/pps-producer.cc b/android/perfetto/pps-producer.cc index e829e0949cb..bec2b60b728 100644 --- a/android/perfetto/pps-producer.cc +++ b/android/perfetto/pps-producer.cc @@ -1,5 +1,30 @@ -extern int pps_main(int argc, const char **argv); +#include +#include + +typedef void (*pps_main_fn_t)(int, const char **); + +#define PPS_LIB "/vendor/lib64/libgpudataproducer.so" int main(int argc, const char **argv) { - return pps_main(argc, argv); + char *error; + + void *handle = dlopen(PPS_LIB, RTLD_GLOBAL); + if ((error = dlerror()) != nullptr || handle == nullptr) { + fprintf(stdout, "Error loading lib: %s\n", error); + return -1; + } + + pps_main_fn_t ppsFn = (pps_main_fn_t)dlsym(handle, "pps_main"); + if (((error = dlerror()) != nullptr) || (ppsFn == nullptr)) { + fprintf(stdout, "Error looking for pps_main symbol: %s\n", error); + dlclose(handle); + return -1; + } + + fprintf(stdout, "start call pps_main\n"); + (*ppsFn)(argc, argv); + fprintf(stdout, "end call pps_main\n"); + + dlclose(handle); + return 0; } diff --git a/src/intel/ds/intel_driver_ds.cc b/src/intel/ds/intel_driver_ds.cc index cc732658a31..843c43f4867 100644 --- a/src/intel/ds/intel_driver_ds.cc +++ b/src/intel/ds/intel_driver_ds.cc @@ -566,7 +566,12 @@ intel_driver_ds_init_once(void) #ifdef HAVE_PERFETTO util_perfetto_init(); perfetto::DataSourceDescriptor dsd; +#ifdef ANDROID + /* AGI requires this name */ + dsd.set_name("gpu.renderstages"); +#else dsd.set_name("gpu.renderstages.intel"); +#endif IntelRenderpassDataSource::Register(dsd); #endif } diff --git a/src/intel/ds/intel_pps_driver.cc b/src/intel/ds/intel_pps_driver.cc index 66f27030d86..8c202a088ce 100644 --- a/src/intel/ds/intel_pps_driver.cc +++ b/src/intel/ds/intel_pps_driver.cc @@ -19,6 +19,7 @@ #include "drm-uapi/i915_drm.h" #include "common/intel_gem.h" +#include #include "dev/intel_device_info.h" #include "perf/intel_perf.h" #include "perf/intel_perf_query.h" @@ -85,7 +86,14 @@ bool IntelDriver::init_perfcnt() perf = std::make_unique(drm_device.fd); - const char *metric_set_name = getenv("INTEL_PERFETTO_METRIC_SET"); + const char *metric_set_name = NULL; +#ifdef ANDROID + char metric_set_buf[PROPERTY_VALUE_MAX] = ""; + if (property_get("persist.vendor.intel.perfetto.metric_set", metric_set_buf, NULL) > 0) + metric_set_name = metric_set_buf; +#else + metric_set_name = getenv("INTEL_PERFETTO_METRIC_SET"); +#endif struct intel_perf_query_info *default_query = nullptr; selected_query = nullptr; diff --git a/src/tool/pps/cfg/gpu.cfg b/src/tool/pps/cfg/gpu.cfg index 11cdfa8f82a..7759d655736 100644 --- a/src/tool/pps/cfg/gpu.cfg +++ b/src/tool/pps/cfg/gpu.cfg @@ -21,4 +21,13 @@ data_sources { } } +data_sources { + config { + name: "gpu.counters" + gpu_counter_config { + counter_period_ns: 1000000000 + } + } +} + duration_ms: 16000 diff --git a/src/tool/pps/cfg/intel.cfg b/src/tool/pps/cfg/intel.cfg index bb9e2d22dbc..4b9ce40099a 100644 --- a/src/tool/pps/cfg/intel.cfg +++ b/src/tool/pps/cfg/intel.cfg @@ -58,6 +58,21 @@ data_sources { } } +data_sources { + config { + name: "gpu.counters" + gpu_counter_config { + counter_period_ns: 100000 + } + } +} + +data_sources { + config { + name: "gpu.renderstages" + } +} + data_sources { config { name: "track_event" diff --git a/src/tool/pps/cfg/system.cfg b/src/tool/pps/cfg/system.cfg index f48f5f943a3..87fbaefca80 100644 --- a/src/tool/pps/cfg/system.cfg +++ b/src/tool/pps/cfg/system.cfg @@ -39,6 +39,21 @@ data_sources { } } +data_sources { + config { + name: "gpu.counters" + gpu_counter_config { + counter_period_ns: 100000 + } + } +} + +data_sources { + config { + name: "gpu.renderstages" + } +} + data_sources { config { name: "track_event" diff --git a/src/tool/pps/pps_datasource.cc b/src/tool/pps/pps_datasource.cc index 99ca51d6b7c..f5caf7feb17 100644 --- a/src/tool/pps/pps_datasource.cc +++ b/src/tool/pps/pps_datasource.cc @@ -51,6 +51,8 @@ void GpuDataSource::OnSetup(const SetupArgs &args) } this->driver = driver; + // use first available driver, to avoid be covered by following failed driver. + break; } } if (driver == nullptr) { @@ -324,7 +326,12 @@ void GpuDataSource::register_data_source(const std::string &_driver_name) { driver_name = _driver_name; static perfetto::DataSourceDescriptor dsd; +#ifdef ANDROID + /* AGI requires this name */ + dsd.set_name("gpu.counters"); +#else dsd.set_name("gpu.counters." + driver_name); +#endif Driver * driver = nullptr; auto drm_devices = DrmDevice::create_all(); @@ -336,6 +343,8 @@ void GpuDataSource::register_data_source(const std::string &_driver_name) if ((driver != nullptr) && !driver->init_perfcnt()) { driver = nullptr; } + // use first available driver, to avoid be covered by following failed driver. + break; } if (driver != nullptr) { diff --git a/src/tool/pps/pps_producer.cc b/src/tool/pps/pps_producer.cc index c84c6806f51..6266b5df56a 100644 --- a/src/tool/pps/pps_producer.cc +++ b/src/tool/pps/pps_producer.cc @@ -11,7 +11,7 @@ #include "pps_datasource.h" -int pps_main(int argc, const char **argv) +extern "C" int pps_main(int argc, const char **argv) { using namespace pps; @@ -35,3 +35,22 @@ int pps_main(int argc, const char **argv) return EXIT_SUCCESS; } + +extern "C" void start() +{ + using namespace pps; + + // Connects to the system tracing service + perfetto::TracingInitArgs args; + args.backends = perfetto::kSystemBackend; + perfetto::Tracing::Initialize(args); + + GpuDataSource::register_data_source(Driver::default_driver_name()); + + while (true) { + GpuDataSource::wait_started(); + GpuDataSource::Trace(GpuDataSource::trace_callback); + } + + return; +} \ No newline at end of file