]> Pileus Git - ~andy/linux/commitdiff
tracing/events: Add bounce tracing to swiotbl
authorZoltan Kiss <zoltan.kiss@citrix.com>
Wed, 4 Sep 2013 20:11:05 +0000 (21:11 +0100)
committerKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Wed, 2 Oct 2013 16:53:26 +0000 (12:53 -0400)
Ftrace is currently not able to detect when SWIOTLB has to do double buffering.
Under Xen you can only see it indirectly in function_graph, when
xen_swiotlb_map_page() doesn't stop after range_straddles_page_boundary(), but
calls spinlock functions, memcpy() and xen_phys_to_bus() as well. This patch
introduces the swiotlb:swiotlb_bounced event, which also prints out the
following informations to help you find out why bouncing happened:

dev_name: 0000:08:00.0 dma_mask=ffffffffffffffff dev_addr=9149f000 size=32768
swiotlb_force=0

If you use Xen, and (dev_addr + size + 1) > dma_mask, the buffer is out of the
device's DMA range. If swiotlb_force == 1, you should really change the kernel
parameters. Otherwise, the buffer is not contiguous in mfn space.

Signed-off-by: Zoltan Kiss <zoltan.kiss@citrix.com>
[v1: Don't print 'swiotlb_force=X', just print swiotlb_force if it is enabled]
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
drivers/xen/swiotlb-xen.c
include/trace/events/swiotlb.h [new file with mode: 0644]
lib/swiotlb.c

index 1b2277c311d22e31fc276b09cb6bd1ce3b783e39..b31081007a810cfcaf81d47d8ea07eae41eb8a00 100644 (file)
@@ -42,6 +42,9 @@
 #include <xen/page.h>
 #include <xen/xen-ops.h>
 #include <xen/hvc-console.h>
+
+#define CREATE_TRACE_POINTS
+#include <trace/events/swiotlb.h>
 /*
  * Used to do a quick range check in swiotlb_tbl_unmap_single and
  * swiotlb_tbl_sync_single_*, to see if the memory was in fact allocated by this
@@ -358,6 +361,8 @@ dma_addr_t xen_swiotlb_map_page(struct device *dev, struct page *page,
        /*
         * Oh well, have to allocate and map a bounce buffer.
         */
+       trace_swiotlb_bounced(dev, dev_addr, size, swiotlb_force);
+
        map = swiotlb_tbl_map_single(dev, start_dma_addr, phys, size, dir);
        if (map == SWIOTLB_MAP_ERROR)
                return DMA_ERROR_CODE;
diff --git a/include/trace/events/swiotlb.h b/include/trace/events/swiotlb.h
new file mode 100644 (file)
index 0000000..7ea4c5e
--- /dev/null
@@ -0,0 +1,46 @@
+#undef TRACE_SYSTEM
+#define TRACE_SYSTEM swiotlb
+
+#if !defined(_TRACE_SWIOTLB_H) || defined(TRACE_HEADER_MULTI_READ)
+#define _TRACE_SWIOTLB_H
+
+#include <linux/tracepoint.h>
+
+TRACE_EVENT(swiotlb_bounced,
+
+       TP_PROTO(struct device *dev,
+                dma_addr_t dev_addr,
+                size_t size,
+                int swiotlb_force),
+
+       TP_ARGS(dev, dev_addr, size, swiotlb_force),
+
+       TP_STRUCT__entry(
+               __string(       dev_name,       dev_name(dev)   )
+               __field(        u64,    dma_mask                )
+               __field(        dma_addr_t,     dev_addr        )
+               __field(        size_t, size                    )
+               __field(        int,    swiotlb_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->swiotlb_force = swiotlb_force;
+       ),
+
+       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->swiotlb_force ? "swiotlb_force" : "" )
+);
+
+#endif /*  _TRACE_SWIOTLB_H */
+
+/* This part must be outside protection */
+#include <trace/define_trace.h>
index 4e8686c7e5a4085753121337755bf522ccfe6300..f0d841907da662cce80c1f9ac6e1fece6234357d 100644 (file)
@@ -38,6 +38,8 @@
 #include <linux/bootmem.h>
 #include <linux/iommu-helper.h>
 
+#include <trace/events/swiotlb.h>
+
 #define OFFSET(val,align) ((unsigned long)     \
                           ( (val) & ( (align) - 1)))
 
@@ -726,6 +728,8 @@ dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
        if (dma_capable(dev, dev_addr, size) && !swiotlb_force)
                return dev_addr;
 
+       trace_swiotlb_bounced(dev, dev_addr, size, swiotlb_force);
+
        /* Oh well, have to allocate and map a bounce buffer. */
        map = map_single(dev, phys, size, dir);
        if (map == SWIOTLB_MAP_ERROR) {