From 7e7e0609ee7bd0d4f04d6d19917a2de8f8e2347a Mon Sep 17 00:00:00 2001 From: Su Hong Koo Date: Tue, 23 Sep 2025 14:40:03 -0400 Subject: [PATCH] drm_hwcomposer: Add tracing around validate/present paths Add perferto tracing around validate and present paths. Specifically around code that blocks on the main thread (e.g. commit, fence waits). These should increase the visibility of what is blocking the presentation hot path in perfetto traces. Change-Id: I6db60648c5e1d5f1a666ebc52f5ae5ad57e0e82a --- drm/DrmAtomicStateManager.cpp | 14 +++++++++++--- hwc/HwcDisplay.cpp | 9 +++++++++ hwc3/ComposerClient.cpp | 3 +++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/drm/DrmAtomicStateManager.cpp b/drm/DrmAtomicStateManager.cpp index 75f3c6e..53b9e68 100644 --- a/drm/DrmAtomicStateManager.cpp +++ b/drm/DrmAtomicStateManager.cpp @@ -119,6 +119,7 @@ bool DrmAtomicStateManager::CommitFrame(AtomicCommitArgs &args) { auto *drm = pipe_->device; if (args.test_only) { + ATRACE_NAME("TestOnlyCommit"); auto err = drmModeAtomicCommit(*drm->GetFd(), atomic_request->property_set.get(), flags | DRM_MODE_ATOMIC_TEST_ONLY, drm); @@ -134,15 +135,21 @@ bool DrmAtomicStateManager::CommitFrame(AtomicCommitArgs &args) { bool nonblock = !args.blocking && !args.active; flags |= nonblock ? DRM_MODE_ATOMIC_NONBLOCK : 0U; - auto err = drmModeAtomicCommit(*drm->GetFd(), - atomic_request->property_set.get(), flags, - drm); + int err = 0; + { + ATRACE_NAME((nonblock ? "Commit_nonblock" : "Commit_block")); + err = drmModeAtomicCommit(*drm->GetFd(), atomic_request->property_set.get(), + flags, drm); + } + if (err != 0 && args.seamless) { ALOGE( "Seamless commit failed, retrying a full modeset (visual artifacts may " "be observed). Error: %s", strerror_r(errno, err_buf, error_buf_max_size)); + ATRACE_NAME("SeamlessFallbackFullModesetCommit"); + err = drmModeAtomicCommit(*drm->GetFd(), atomic_request->property_set.get(), flags | DRM_MODE_ATOMIC_ALLOW_MODESET, drm); } @@ -227,6 +234,7 @@ bool DrmAtomicStateManager::SetWriteBackFenceIfNeeded( // Wait on input fence if provided if (args.writeback_release_fence) { + ATRACE_NAME("WritebackFenceWait"); sync_wait(*args.writeback_release_fence, -1); } diff --git a/hwc/HwcDisplay.cpp b/hwc/HwcDisplay.cpp index 0e3b773..0788a0a 100644 --- a/hwc/HwcDisplay.cpp +++ b/hwc/HwcDisplay.cpp @@ -22,6 +22,7 @@ #include #include +#include #include "backend/Backend.h" #include "backend/BackendManager.h" @@ -223,6 +224,8 @@ void HwcDisplay::SetOutputType(OutputType hdr_output_type) { } HwcDisplay::ConfigError HwcDisplay::SetConfig(ConfigId config) { + ATRACE_CALL(); + const HwcDisplayConfig *new_config = GetConfig(config); if (new_config == nullptr) { ALOGE("Could not find active mode for %u", config); @@ -376,6 +379,8 @@ auto HwcDisplay::AcceptValidatedComposition() -> void { auto HwcDisplay::PresentStagedComposition( std::optional desired_present_time, SharedFd &out_present_fence, std::vector &out_release_fences) -> bool { + ATRACE_CALL(); + if (IsInHeadlessMode()) { return true; } @@ -785,6 +790,8 @@ uint32_t HwcDisplay::GetCurrentVsyncPeriodNs() const { bool HwcDisplay::TestComposition( Backend::ValidatedComposition &composition) const { + ATRACE_CALL(); + if (IsInHeadlessMode()) { return true; } @@ -920,6 +927,8 @@ std::optional HwcDisplay::CreateFrameUpdateCommit( bool HwcDisplay::CommitComposition( const Backend::CompositionTypeMap &composition, SharedFd &out_present_fence) { + ATRACE_CALL(); + if (IsInHeadlessMode()) { ALOGE("%s: Display is in headless mode, should never reach here", __func__); return true; diff --git a/hwc3/ComposerClient.cpp b/hwc3/ComposerClient.cpp index 92479c9..dd0f858 100644 --- a/hwc3/ComposerClient.cpp +++ b/hwc3/ComposerClient.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #include "bufferinfo/BufferInfo.h" #include "compositor/DisplayInfo.h" @@ -711,6 +712,8 @@ void ComposerClient::DispatchLayerCommand(int64_t display_handle, } void ComposerClient::ExecuteDisplayCommand(const DisplayCommand& command) { + ATRACE_CALL(); + const int64_t display_handle = command.display; HwcDisplay* display = hwc_->GetDisplay(display_handle); if (display == nullptr) {