From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8B93F3064AF for ; Mon, 24 Nov 2025 13:36:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763991418; cv=none; b=RoF6jIKKwx03iVCqy/3L6A9GoMr6uMZPoT+PTFVqs+DfuEV8jh5cHA6BYIDiEQpQjVRX9nzxh4VAaLq7uqzuqySCaRm0SY489N51q9FanTJ/YsBS/E4N15Iy7hQk0+y9IYTg/Are81qika5Sx+rItT3uYAdOrjhRHm+Zs825ekU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763991418; c=relaxed/simple; bh=R2TNEdLeCr+WebDGIdwE1ouAUwHeWoeWNAusMtOP8Ec=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=SxDCYpPwhdliT8M5O5AdmhEnOWaH8+Bo+X+efpiic0FtxGY87MlQqpOg+ftduEMi3tN5OdVXh/9KosOWRU/9YqGqZN8YmmfGr2wptALW7sKzzNozPIto3OXhzuoM33U9f6li/usJtSSS68oBbdgfdTcaGaSvlCcSAWJTPY5OZVY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=VCM7zPG3; arc=none smtp.client-ip=209.85.216.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="VCM7zPG3" Received: by mail-pj1-f48.google.com with SMTP id 98e67ed59e1d1-343f35d0f99so3507094a91.0 for ; Mon, 24 Nov 2025 05:36:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1763991416; x=1764596216; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=69heBc7lxItVc7wNt1exM2CAHwdvZiFMjd3lDNLudqQ=; b=VCM7zPG3AeAo9EpHIpjefC6NdGXYinTCImtZZZ7Hll7bYQXBIqtMCNaro1XFFoOMGG RssA2DaxuQSeNhPKGwlX+fDfaGLia6FPZzzjsm6KLhCRIMVyFxITa1k/mPiywADBJn5I j3UUmCsrfdKeO39u0bx3d5pA3+xil0xrGN2O6culIAvNKdEjfHliy8wxRx8XyyZu8XGH W2hdo8Y43AEKexw9Ho8cb5WN3wmxhlZIdtOygYlt190vQIn8WoUDlRVf1GKdkoJS6cai M3VzoBAEtZqqthuh+oHTkntPN785qgaSPGqwsiDINkrjpIUk1KUwppCjSaTTatPEqIYZ QJog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763991416; x=1764596216; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=69heBc7lxItVc7wNt1exM2CAHwdvZiFMjd3lDNLudqQ=; b=ZCbHf9QuuoXrRuaGvcmqSJO9aWp5QOOVOfjmOXt1Gzfxbe7cn5KFRQXClKGEwTdA47 R36hnh08HJ9R3xEdKjl/MeVbAixFaHAYrZREIq1lv7zy7W4/ZVUxTcD0Vju3TqP/DVIx DAyurvI6SpKZyA44YdPyQhgujdKPdW1BlaIWid7YD1b7OYhpv7Q+VhbdU9IvyuMrmoA2 cfVyRl+wdAvDtxacIU5zT5E9f1pFb5RPLf5JEWt9H5l3A8qB/LD8sz+VRPZXC0Fac9Mm ZGSM9LUM2c53eYweFAXCGwEShOfV5Xin4wbw6ty0Az4Hk6OHMfK2KosX4RggbKlclKAr +NIA== X-Forwarded-Encrypted: i=1; AJvYcCViBtFveZMpOWLNS9dtGbM8LIAWU2P2RWx9/ka2ugW1vgw/BJHgClt2Uij6mEMdNAbfoTfknmxboGXuvZbjGKw1jao=@vger.kernel.org X-Gm-Message-State: AOJu0Yw+P44l5YujnbDAfB8oBueaTUJyacFdM9C6rbzyDFesXL5PtRcV F0KV2cP0FJgoJXKfZacjQ/rX9ZsE11LpYw4T4O7kZBQeIeP/AArFpukn X-Gm-Gg: ASbGncsjLLA0dATx79DmND9yUxceM48FNApVQZHcsGZFBsCPGEgLVK0GeB6H/tURN9j 7ICRAzlfip5pvSuI91DvxfCJknNwyHlgLTGhFEEt7WKLPZCmrIMDJPtV21i9wNr7aqE2KbZjHsQ b2hLvAd2WzYcyhhRjIh3r1S4l04JY0WOqXfwPxsMcuqF0Y0XFV5WDahYW+9lWUDdxD4PFkdHHim 4RGuJ7qt2iKk8AequfPI116H1/bVkaas+e3m2fMyZf84w1wCht+yxfxkoMidcqF8RPIi70I2Amw LrrJwTWMBj+JqzeA499KcR6vpfzrQkFFN3ThHAa6Qc47kLszZQTzF/oabHAZEg1HqOdGgSWiiCs 9dEBVJnzB5LwzQzeuoa7bb+gu/+078rTY5WaV9WAp8q8glRb4t0sVP8uZpRjJnQFy64cHtzw6IY 7510gMz4VEVJNuNwVnKyb2 X-Google-Smtp-Source: AGHT+IG8VQwWoauvzDFbRHO/aVA7+5Mp7waCEC1xvbAJGyrpIlW5gSd8E1x6DOClV9RsbiV2xW4jVQ== X-Received: by 2002:a17:90b:2f85:b0:340:be4d:a718 with SMTP id 98e67ed59e1d1-34733e4a4eemr14390507a91.7.1763991415673; Mon, 24 Nov 2025 05:36:55 -0800 (PST) Received: from xiao.mioffice.cn ([43.224.245.230]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-345b04771e6sm8091573a91.8.2025.11.24.05.36.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Nov 2025 05:36:55 -0800 (PST) From: Xiang Gao To: sumit.semwal@linaro.org, christian.koenig@amd.com, rostedt@goodmis.org, mhiramat@kernel.org Cc: linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org, mathieu.desnoyers@efficios.com, dhowells@redhat.com, kuba@kernel.org, brauner@kernel.org, akpm@linux-foundation.org, linux-trace-kernel@vger.kernel.org, gaoxiang17 Subject: [PATCH] dma-buf: add some tracepoints to debug. Date: Mon, 24 Nov 2025 21:36:48 +0800 Message-Id: <20251124133648.72668-1-gxxa03070307@gmail.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: gaoxiang17 With these tracepoints, we can track dmabuf in real time. For example: binder:3025_3-10524 [000] ..... 553.310313: dma_buf_export: exp_name=qcom,system name=(null) size=12771328 ino=2799 binder:3025_3-10524 [000] ..... 553.310318: dma_buf_fd: exp_name=qcom,system name=(null) size=12771328 ino=2799 fd=8 RenderThread-9307 [000] ..... 553.310869: dma_buf_get: exp_name=qcom,system name=blastBufferQueue for scaleUpDow size=12771328 ino=2799 fd=673 f_ref=4 RenderThread-9307 [000] ..... 553.310871: dma_buf_attach: dev_name=kgsl-3d0 exp_name=qcom,system name=blastBufferQueue for scaleUpDow size=12771328 ino=2799 RenderThread-9307 [000] ..... 553.310946: dma_buf_mmap_internal: exp_name=qcom,system name=blastBufferQueue for scaleUpDow size=12771328 ino=2799 RenderThread-9307 [004] ..... 553.315084: dma_buf_detach: exp_name=qcom,system name=blastBufferQueue for scaleUpDow size=12771328 ino=2799 RenderThread-9307 [004] ..... 553.315084: dma_buf_put: exp_name=qcom,system name=blastBufferQueue for scaleUpDow size=12771328 ino=2799 f_ref=5 Signed-off-by: gaoxiang17 --- drivers/dma-buf/dma-buf.c | 19 +++ include/trace/events/dma_buf.h | 245 +++++++++++++++++++++++++++++++++ 2 files changed, 264 insertions(+) create mode 100644 include/trace/events/dma_buf.h diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c index 2bcf9ceca997..8b5af73f0218 100644 --- a/drivers/dma-buf/dma-buf.c +++ b/drivers/dma-buf/dma-buf.c @@ -35,6 +35,9 @@ #include "dma-buf-sysfs-stats.h" +#define CREATE_TRACE_POINTS +#include + static inline int is_dma_buf_file(struct file *); static DEFINE_MUTEX(dmabuf_list_mutex); @@ -220,6 +223,8 @@ static int dma_buf_mmap_internal(struct file *file, struct vm_area_struct *vma) dmabuf->size >> PAGE_SHIFT) return -EINVAL; + trace_dma_buf_mmap_internal(dmabuf); + return dmabuf->ops->mmap(dmabuf, vma); } @@ -745,6 +750,8 @@ struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info) __dma_buf_list_add(dmabuf); + trace_dma_buf_export(dmabuf); + return dmabuf; err_dmabuf: @@ -779,6 +786,8 @@ int dma_buf_fd(struct dma_buf *dmabuf, int flags) fd_install(fd, dmabuf->file); + trace_dma_buf_fd(dmabuf, fd); + return fd; } EXPORT_SYMBOL_NS_GPL(dma_buf_fd, "DMA_BUF"); @@ -805,6 +814,8 @@ struct dma_buf *dma_buf_get(int fd) return ERR_PTR(-EINVAL); } + trace_dma_buf_get(fd, file); + return file->private_data; } EXPORT_SYMBOL_NS_GPL(dma_buf_get, "DMA_BUF"); @@ -825,6 +836,8 @@ void dma_buf_put(struct dma_buf *dmabuf) return; fput(dmabuf->file); + + trace_dma_buf_put(dmabuf); } EXPORT_SYMBOL_NS_GPL(dma_buf_put, "DMA_BUF"); @@ -998,6 +1011,8 @@ EXPORT_SYMBOL_NS_GPL(dma_buf_dynamic_attach, "DMA_BUF"); struct dma_buf_attachment *dma_buf_attach(struct dma_buf *dmabuf, struct device *dev) { + trace_dma_buf_attach(dmabuf, dev); + return dma_buf_dynamic_attach(dmabuf, dev, NULL, NULL); } EXPORT_SYMBOL_NS_GPL(dma_buf_attach, "DMA_BUF"); @@ -1024,6 +1039,8 @@ void dma_buf_detach(struct dma_buf *dmabuf, struct dma_buf_attachment *attach) dmabuf->ops->detach(dmabuf, attach); kfree(attach); + + trace_dma_buf_detach(dmabuf); } EXPORT_SYMBOL_NS_GPL(dma_buf_detach, "DMA_BUF"); @@ -1488,6 +1505,8 @@ int dma_buf_mmap(struct dma_buf *dmabuf, struct vm_area_struct *vma, vma_set_file(vma, dmabuf->file); vma->vm_pgoff = pgoff; + trace_dma_buf_mmap(dmabuf); + return dmabuf->ops->mmap(dmabuf, vma); } EXPORT_SYMBOL_NS_GPL(dma_buf_mmap, "DMA_BUF"); diff --git a/include/trace/events/dma_buf.h b/include/trace/events/dma_buf.h new file mode 100644 index 000000000000..796ae444f6ae --- /dev/null +++ b/include/trace/events/dma_buf.h @@ -0,0 +1,245 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#undef TRACE_SYSTEM +#define TRACE_SYSTEM dma_buf + +#if !defined(_TRACE_DMA_BUF_H) || defined(TRACE_HEADER_MULTI_READ) +#define _TRACE_DMA_BUF_H + +#include +#include + +TRACE_EVENT(dma_buf_export, + + TP_PROTO(struct dma_buf *dmabuf), + + TP_ARGS(dmabuf), + + TP_STRUCT__entry( + __string(exp_name, dmabuf->exp_name) + __string(name, dmabuf->name) + __field(size_t, size) + __field(ino_t, ino) + ), + + TP_fast_assign( + __assign_str(exp_name); + __assign_str(name); + __entry->size = dmabuf->size; + __entry->ino = dmabuf->file->f_inode->i_ino; + ), + + TP_printk("exp_name=%s name=%s size=%zu ino=%lu", + __get_str(exp_name), + __get_str(name), + __entry->size, + __entry->ino) +); + +TRACE_EVENT(dma_buf_fd, + + TP_PROTO(struct dma_buf *dmabuf, int fd), + + TP_ARGS(dmabuf, fd), + + TP_STRUCT__entry( + __string(exp_name, dmabuf->exp_name) + __string(name, dmabuf->name) + __field(size_t, size) + __field(ino_t, ino) + __field(int, fd) + ), + + TP_fast_assign( + __assign_str(exp_name); + __assign_str(name); + __entry->size = dmabuf->size; + __entry->ino = dmabuf->file->f_inode->i_ino; + __entry->fd = fd; + ), + + TP_printk("exp_name=%s name=%s size=%zu ino=%lu fd=%d", + __get_str(exp_name), + __get_str(name), + __entry->size, + __entry->ino, + __entry->fd) +); + +TRACE_EVENT(dma_buf_mmap_internal, + + TP_PROTO(struct dma_buf *dmabuf), + + TP_ARGS(dmabuf), + + TP_STRUCT__entry( + __string(exp_name, dmabuf->exp_name) + __string(name, dmabuf->name) + __field(size_t, size) + __field(ino_t, ino) + ), + + TP_fast_assign( + __assign_str(exp_name); + __assign_str(name); + __entry->size = dmabuf->size; + __entry->ino = dmabuf->file->f_inode->i_ino; + ), + + TP_printk("exp_name=%s name=%s size=%zu ino=%lu", + __get_str(exp_name), + __get_str(name), + __entry->size, + __entry->ino) +); + +TRACE_EVENT(dma_buf_mmap, + + TP_PROTO(struct dma_buf *dmabuf), + + TP_ARGS(dmabuf), + + TP_STRUCT__entry( + __string(exp_name, dmabuf->exp_name) + __string(name, dmabuf->name) + __field(size_t, size) + __field(ino_t, ino) + ), + + TP_fast_assign( + __assign_str(exp_name); + __assign_str(name); + __entry->size = dmabuf->size; + __entry->ino = dmabuf->file->f_inode->i_ino; + ), + + TP_printk("exp_name=%s name=%s size=%zu ino=%lu", + __get_str(exp_name), + __get_str(name), + __entry->size, + __entry->ino) +); + +TRACE_EVENT(dma_buf_attach, + + TP_PROTO(struct dma_buf *dmabuf, struct device *dev), + + TP_ARGS(dmabuf, dev), + + TP_STRUCT__entry( + __string(dname, dev_name(dev)) + __string(exp_name, dmabuf->exp_name) + __string(name, dmabuf->name) + __field(size_t, size) + __field(ino_t, ino) + ), + + TP_fast_assign( + __assign_str(dname); + __assign_str(exp_name); + __assign_str(name); + __entry->size = dmabuf->size; + __entry->ino = dmabuf->file->f_inode->i_ino; + ), + + TP_printk("dev_name=%s exp_name=%s name=%s size=%zu ino=%lu", + __get_str(dname), + __get_str(exp_name), + __get_str(name), + __entry->size, + __entry->ino) +); + +TRACE_EVENT(dma_buf_detach, + + TP_PROTO(struct dma_buf *dmabuf), + + TP_ARGS(dmabuf), + + TP_STRUCT__entry( + __string(exp_name, dmabuf->exp_name) + __string(name, dmabuf->name) + __field(size_t, size) + __field(ino_t, ino) + ), + + TP_fast_assign( + __assign_str(exp_name); + __assign_str(name); + __entry->size = dmabuf->size; + __entry->ino = dmabuf->file->f_inode->i_ino; + ), + + TP_printk("exp_name=%s name=%s size=%zu ino=%lu", + __get_str(exp_name), + __get_str(name), + __entry->size, + __entry->ino) +); + +TRACE_EVENT(dma_buf_get, + + TP_PROTO(int fd, struct file *file), + + TP_ARGS(fd, file), + + TP_STRUCT__entry( + __string(exp_name, ((struct dma_buf *)file->private_data)->exp_name) + __string(name, ((struct dma_buf *)file->private_data)->name) + __field(size_t, size) + __field(ino_t, ino) + __field(int, fd) + __field(long, f_ref) + ), + + TP_fast_assign( + __assign_str(exp_name); + __assign_str(name); + __entry->size = ((struct dma_buf *)file->private_data)->size; + __entry->ino = ((struct dma_buf *)file->private_data)->file->f_inode->i_ino; + __entry->fd = fd; + __entry->f_ref = file_ref_get(&file->f_ref); + ), + + TP_printk("exp_name=%s name=%s size=%zu ino=%lu fd=%d f_ref=%ld", + __get_str(exp_name), + __get_str(name), + __entry->size, + __entry->ino, + __entry->fd, + __entry->f_ref) +); + +TRACE_EVENT(dma_buf_put, + + TP_PROTO(struct dma_buf *dmabuf), + + TP_ARGS(dmabuf), + + TP_STRUCT__entry( + __string(exp_name, dmabuf->exp_name) + __string(name, dmabuf->name) + __field(size_t, size) + __field(ino_t, ino) + __field(long, f_ref) + ), + + TP_fast_assign( + __assign_str(exp_name); + __assign_str(name); + __entry->size = dmabuf->size; + __entry->ino = dmabuf->file->f_inode->i_ino; + __entry->f_ref = file_ref_get(&dmabuf->file->f_ref); + ), + + TP_printk("exp_name=%s name=%s size=%zu ino=%lu f_ref=%ld", + __get_str(exp_name), + __get_str(name), + __entry->size, + __entry->ino, + __entry->f_ref) +); + +#endif /* _TRACE_DMA_BUF_H */ + +/* This part must be outside protection */ +#include -- 2.34.1