From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EBD15606A32D for ; Thu, 3 Dec 2026 20:24:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=ZBK+bO+W Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 93D2C112BEB; Thu, 3 Dec 2026 20:24:46 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.20]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6A217112B8B; Thu, 3 Dec 2026 20:24:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796329464; x=1827865464; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=iNW7Nlde1GPZQM8CVBwoh64U9FxA2/l8GuESq5zIQWg=; b=ZBK+bO+WsmICPUQJ9tWk8hpty/9pYGltm27S/ppc7xz1O7gqsUUTIW55 1sE/JOMR6Hv/ywSaXFeZ8Q32IiWETmPYFWzVgIE03qGLjU5lF93Q7wTdi khH1gAkrkzk84HY02Ta0smxtrFcY4IbeGh9gFXbfgAy8rRsYOKbeu3ndo 8VYlYips4+2pRTgeq3+VdiiFYOEsBf99ec5JwISU8KpAp1/dPzNAyvBBF RxZCdGZRfCtpCUOZBrOwsVbH6c7Dv2qo8tCQPkSiCF7xFEPINxtcTLRA4 2gP+7PW9xVH+WIrN5TlqJATuPUd8JJ26nxJmod0Y9HdM/h3BZpiqXyhFd Q==; X-CSE-ConnectionGUID: UFBA4VOIRdmHN5zxxDYuog== X-CSE-MsgGUID: 6X/vssnwR1i/fN+wQzSMTg== X-IronPort-AV: E=McAfee;i="6800,10657,11985"; a="5351167" X-IronPort-AV: E=Sophos;i="6.29,77,1794902400"; d="scan'208";a="5351167" Received: from fmviesa013.fm.intel.com ([10.60.135.153]) by orvoesa112.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2026 12:24:05 -0800 X-CSE-ConnectionGUID: 9gasNEU3RpqhtkI35bPIdg== X-CSE-MsgGUID: McSOJ7z/SaK3ZVWDYpsqiA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.29,77,1794902400"; d="scan'208";a="15862494" Received: from gsse-cloud1.jf.intel.com ([10.54.39.91]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2026 12:24:05 -0800 From: Matthew Brost To: intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org Cc: Carlos Santa , Ryan Neph , Natalie Vock , Arun Pravin , Matthew Auld , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , linux-kernel@vger.kernel.org, =?UTF-8?q?Thomas=20Hellstr=C3=B6m?= , Niranjana Vishwanathapura Subject: [PATCH v6 22/35] drm/xe: Add defrag profiling tracepoints Date: Thu, 3 Dec 2026 12:23:39 -0800 Message-Id: <20261203202352.4153159-23-matthew.brost@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261203202352.4153159-1-matthew.brost@intel.com> References: <20261203202352.4153159-1-matthew.brost@intel.com> X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: intel-xe@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel Xe graphics driver List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Intel-xe" X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 Add two tracepoints to profile the page defragmentation worker: - xe_bo_defrag_worker: emitted on worker entry and exit with the bytes processed in the run. - xe_bo_defrag_one: emitted per BO with the run budget, the prealloc fill ratio (got/want) and the lock-held, lock-wait and prealloc durations, plus the bytes consumed and the result. These break down the cost of a defrag attempt into its locked vs unlocked phases, making it possible to confirm that the expensive beneficial-order allocation and cpu cache mode change happen outside the BO dma-resv lock and that the residual lock-held time is copy-bound (with the tail dominated by lock-wait behind active rendering). v4: - Drop count from trace point - Add phase 1 to lockwait_us (Niranjana) v5: - Reword commit (Sashiko) - Use pp.count rather than used (Sashiko) - Record prealloc_ns regardless of failure (Sashiko) Cc: Carlos Santa Cc: Ryan Neph Cc: Natalie Vock Cc: Arun Pravin Cc: Matthew Auld Cc: Maarten Lankhorst Cc: Maxime Ripard Cc: Thomas Zimmermann Cc: David Airlie Cc: Simona Vetter Cc: dri-devel@lists.freedesktop.org Cc: linux-kernel@vger.kernel.org Cc: Thomas Hellström Signed-off-by: Matthew Brost Reviewed-by: Niranjana Vishwanathapura --- drivers/gpu/drm/xe/xe_bo.c | 18 ++++++++++- drivers/gpu/drm/xe/xe_trace_bo.h | 52 ++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c index 99dc4ffc67b6..d7b4031e724a 100644 --- a/drivers/gpu/drm/xe/xe_bo.c +++ b/drivers/gpu/drm/xe/xe_bo.c @@ -1526,7 +1526,9 @@ static int xe_bo_defrag_one(struct xe_device *xe, struct xe_bo *bo, struct ttm_placement placement; struct ttm_place place; enum ttm_caching tt_caching; - unsigned int order, want = 0; + unsigned int order, want = 0, got = 0; + u64 lock_ns = 0, prealloc_ns = 0, lockwait_ns = 0; + ktime_t t0; int ret = 0; *consumed = 0; @@ -1538,7 +1540,9 @@ static int xe_bo_defrag_one(struct xe_device *xe, struct xe_bo *bo, * the run's byte budget. Then drop the lock so the high-order, possibly * reclaim/compaction stalling allocations happen unlocked. */ + t0 = ktime_get(); xe_bo_lock(bo, false); + lockwait_ns = ktime_to_ns(ktime_sub(ktime_get(), t0)); if (!xe_bo_needs_defrag(bo)) { xe_bo_defrag_remove(bo); xe_bo_unlock(bo); @@ -1567,7 +1571,10 @@ static int xe_bo_defrag_one(struct xe_device *xe, struct xe_bo *bo, xe_bo_unlock(bo); /* Phase 2: preallocate outside the lock; */ + t0 = ktime_get(); ret = ttm_pool_prealloc_fill(pool, tt_caching, &pp, want); + prealloc_ns = ktime_to_ns(ktime_sub(ktime_get(), t0)); + got = pp.count; if (ret || !pp.count) { ret = ret ?: -ENOMEM; xe_gt_stats_incr(xe_root_mmio_gt(xe), @@ -1578,7 +1585,10 @@ static int xe_bo_defrag_one(struct xe_device *xe, struct xe_bo *bo, /* * Phase 3: re-take the lock, re-check, and validate using the prealloc. */ + t0 = ktime_get(); xe_bo_lock(bo, false); + lockwait_ns += ktime_to_ns(ktime_sub(ktime_get(), t0)); + t0 = ktime_get(); if (!xe_bo_needs_defrag(bo)) { xe_bo_defrag_remove(bo); @@ -1641,9 +1651,12 @@ static int xe_bo_defrag_one(struct xe_device *xe, struct xe_bo *bo, unlock: xe_bo_unlock(bo); + lock_ns = ktime_to_ns(ktime_sub(ktime_get(), t0)); out_err: ttm_pool_prealloc_fini(pool, &pp); out: + trace_xe_bo_defrag_one(bo, budget, want, got, lock_ns, prealloc_ns, + lockwait_ns, *consumed, ret); return ret; } @@ -1671,6 +1684,8 @@ static void xe_bo_defrag_worker(struct work_struct *w) return; } + trace_xe_bo_defrag_worker(xe, 0, true); + /* * A wedged device (declared wedged or prepared for a PCI reset) skips * GPU submission, so a defrag move would commit uncopied backing and @@ -1792,6 +1807,7 @@ static void xe_bo_defrag_worker(struct work_struct *w) out: xe_pm_runtime_put(xe); drm_dev_exit(idx); + trace_xe_bo_defrag_worker(xe, defrag_bytes, false); } static int xe_bo_move(struct ttm_buffer_object *ttm_bo, bool evict, diff --git a/drivers/gpu/drm/xe/xe_trace_bo.h b/drivers/gpu/drm/xe/xe_trace_bo.h index 36fc7eb65882..d3c06fd4c7dd 100644 --- a/drivers/gpu/drm/xe/xe_trace_bo.h +++ b/drivers/gpu/drm/xe/xe_trace_bo.h @@ -90,6 +90,58 @@ TRACE_EVENT(xe_bo_move, __get_str(new_placement_name), __get_str(device_id)) ); +TRACE_EVENT(xe_bo_defrag_worker, + TP_PROTO(struct xe_device *xe, u64 defrag_bytes, bool enter), + TP_ARGS(xe, defrag_bytes, enter), + TP_STRUCT__entry(__string(dev, dev_name(xe->drm.dev)) + __field(u64, defrag_bytes) + __field(bool, enter) + ), + TP_fast_assign(__assign_str(dev); + __entry->defrag_bytes = defrag_bytes; + __entry->enter = enter; + ), + TP_printk("dev=%s %s defrag_bytes=%llu", + __get_str(dev), __entry->enter ? "enter" : "exit", + __entry->defrag_bytes) +); + +TRACE_EVENT(xe_bo_defrag_one, + TP_PROTO(struct xe_bo *bo, u64 budget, unsigned int prealloc_want, + unsigned int prealloc_got, u64 lock_ns, u64 prealloc_ns, + u64 lockwait_ns, u64 consumed, int ret), + TP_ARGS(bo, budget, prealloc_want, prealloc_got, lock_ns, + prealloc_ns, lockwait_ns, consumed, ret), + TP_STRUCT__entry(__string(dev, __dev_name_bo(bo)) + __field(size_t, size) + __field(u64, budget) + __field(unsigned int, prealloc_want) + __field(unsigned int, prealloc_got) + __field(u64, lock_us) + __field(u64, prealloc_us) + __field(u64, lockwait_us) + __field(u64, consumed) + __field(int, ret) + ), + TP_fast_assign(__assign_str(dev); + __entry->size = xe_bo_size(bo); + __entry->budget = budget; + __entry->prealloc_want = prealloc_want; + __entry->prealloc_got = prealloc_got; + __entry->lock_us = div_u64(lock_ns, 1000); + __entry->prealloc_us = div_u64(prealloc_ns, 1000); + __entry->lockwait_us = div_u64(lockwait_ns, 1000); + __entry->consumed = consumed; + __entry->ret = ret; + ), + TP_printk("dev=%s size=%zu budget=%llu prealloc=%u/%u lock_us=%llu lockwait_us=%llu prealloc_us=%llu consumed=%llu ret=%d", + __get_str(dev), __entry->size, __entry->budget, + __entry->prealloc_got, __entry->prealloc_want, + __entry->lock_us, __entry->lockwait_us, + __entry->prealloc_us, __entry->consumed, + __entry->ret) +); + DECLARE_EVENT_CLASS(xe_vma, TP_PROTO(struct xe_vma *vma), TP_ARGS(vma), -- 2.34.1