[PATCH 3/4] swiotlb: Add tracepoint swiotlb_unbounced

From: GuoRui.Yu
Date: Sat Jan 28 2023 - 03:33:22 EST


Add a new tracepoint swiotlb_unbounced to facilitate statistics of
swiotlb buffer usage.

Signed-off-by: GuoRui.Yu <GuoRui.Yu@xxxxxxxxxxxxxxxxx>
---
include/trace/events/swiotlb.h | 28 ++++++++++++++++++++++++++++
kernel/dma/common-swiotlb.c | 1 +
2 files changed, 29 insertions(+)

diff --git a/include/trace/events/swiotlb.h b/include/trace/events/swiotlb.h
index da05c9ebd224..0707adc34df5 100644
--- a/include/trace/events/swiotlb.h
+++ b/include/trace/events/swiotlb.h
@@ -35,6 +35,34 @@ TRACE_EVENT(swiotlb_bounced,
__entry->force ? "FORCE" : "NORMAL")
);

+TRACE_EVENT(swiotlb_unbounced,
+ TP_PROTO(struct device *dev, dma_addr_t dev_addr, size_t size),
+ TP_ARGS(dev, dev_addr, size),
+
+ TP_STRUCT__entry(
+ __string(dev_name, dev_name(dev))
+ __field(u64, dma_mask)
+ __field(dma_addr_t, dev_addr)
+ __field(size_t, size)
+ __field(bool, force)
+ ),
+
+ TP_fast_assign(
+ __assign_str(dev_name, dev_name(dev));
+ __entry->dma_mask = (dev->dma_mask ? *dev->dma_mask : 0);
+ __entry->dev_addr = dev_addr;
+ __entry->size = size;
+ __entry->force = is_swiotlb_force_bounce(dev);
+ ),
+
+ TP_printk("dev_name: %s dma_mask=%llx dev_addr=%llx size=%zu %s",
+ __get_str(dev_name),
+ __entry->dma_mask,
+ (unsigned long long)__entry->dev_addr,
+ __entry->size,
+ __entry->force ? "FORCE" : "NORMAL")
+);
+
#endif /* _TRACE_SWIOTLB_H */

/* This part must be outside protection */
diff --git a/kernel/dma/common-swiotlb.c b/kernel/dma/common-swiotlb.c
index 553325d5c9cd..e3676a8358f2 100644
--- a/kernel/dma/common-swiotlb.c
+++ b/kernel/dma/common-swiotlb.c
@@ -46,6 +46,7 @@ void swiotlb_tbl_unmap_single(struct device *dev, phys_addr_t tlb_addr,
size_t mapping_size, enum dma_data_direction dir,
unsigned long attrs)
{
+ trace_swiotlb_unbounced(dev, phys_to_dma(dev, tlb_addr), mapping_size);
/*
* First, sync the memory before unmapping the entry
*/
--
2.31.1