diff mbox

add debug trace to CMA

Message ID CA+M3ks4ue7_BKYMRXGAUD6tsuXJJ9mKupDNgPD_5tC_kvSzMgg@mail.gmail.com
State New
Headers show

Commit Message

Benjamin Gaignard Nov. 24, 2011, 12:39 p.m. UTC
Hi all,

I have rebase my patches for debugfs and trace events on top of CMA v17.

Regards,
Benjamin

2011/11/10 Benjamin Gaignard <benjamin.gaignard@linaro.org>

> Hello,
>
> The goal of those two patches is to add debug and trace capabilities to
> CMA on going development.
>
> The first patch allow to dump CMA bitmap status by a simple "cat
> /sys/kernel/debug/cma" command line.
>
> The second add events trace points that can be used for performance and/or
> log with trace tools:
> - to enable it "echo 1 > /sys/kernel/debug/tracing/events/cma/enable"
> - to get the log "cat /sys/kernel/debug/tracing/events/trace"
>
> Regards,
>
> Benjamin
> --
>
> Benjamin Gaignard
>
> Multimedia Working Group
>
> Linaro.org <http://www.linaro.org/>* **│ *Open source software for ARM
> SoCs
>
> **
>
> Follow *Linaro: *Facebook <http://www.facebook.com/pages/Linaro> | Twitter<http://twitter.com/#!/linaroorg>
>  | Blog <http://www.linaro.org/linaro-blog/>
>
>
diff mbox

Patch

From 9c5ce8acfec5edc9585581244bcc002a3ddb9f2b Mon Sep 17 00:00:00 2001
From: benjamin gaignard <benjamin.gaignard@linaro.org>
Date: Tue, 22 Nov 2011 14:34:30 +0100
Subject: [PATCH 2/2] [CMA] add trace points
 trace CMA alloc and release functions

Signed-off-by: benjamin gaignard <benjamin.gaignard@linaro.org>
---
 drivers/base/Kconfig                |    6 ++
 drivers/base/Makefile               |    1 +
 drivers/base/dma-contiguous-trace.c |   13 ++++
 drivers/base/dma-contiguous-trace.h |  126 +++++++++++++++++++++++++++++++++++
 drivers/base/dma-contiguous.c       |   10 +++-
 5 files changed, 155 insertions(+), 1 deletions(-)
 create mode 100644 drivers/base/dma-contiguous-trace.c
 create mode 100644 drivers/base/dma-contiguous-trace.h

diff --git a/drivers/base/Kconfig b/drivers/base/Kconfig
index 99f5fad..44d5cdf 100644
--- a/drivers/base/Kconfig
+++ b/drivers/base/Kconfig
@@ -197,6 +197,12 @@  config CMA_DEBUG
 	  processing calls such as dma_alloc_from_contiguous().
 	  This option does not affect warning and error messages.
 
+config CMA_TRACER
+	bool "Trace CMA allocation"
+	depends on EVENT_TRACING
+	help
+	  Say Y here enable tracing CMA buffer allocation and release.
+
 comment "Default contiguous memory area size:"
 
 config CMA_SIZE_MBYTES
diff --git a/drivers/base/Makefile b/drivers/base/Makefile
index 794546f..da99d8f 100644
--- a/drivers/base/Makefile
+++ b/drivers/base/Makefile
@@ -6,6 +6,7 @@  obj-y			:= core.o sys.o bus.o dd.o syscore.o \
 			   attribute_container.o transport_class.o
 obj-$(CONFIG_DEVTMPFS)	+= devtmpfs.o
 obj-$(CONFIG_CMA) += dma-contiguous.o
+obj-$(CONFIG_CMA_TRACER) += dma-contiguous-trace.o
 obj-y			+= power/
 obj-$(CONFIG_HAS_DMA)	+= dma-mapping.o
 obj-$(CONFIG_HAVE_GENERIC_DMA_COHERENT) += dma-coherent.o
diff --git a/drivers/base/dma-contiguous-trace.c b/drivers/base/dma-contiguous-trace.c
new file mode 100644
index 0000000..1cbb18f
--- /dev/null
+++ b/drivers/base/dma-contiguous-trace.c
@@ -0,0 +1,13 @@ 
+/*
+ * dma-contiguous-trace.c
+ *
+ * Copyright (C) ST-Ericsson SA 2011
+ * Author: <benjamin.gaignard@linaro.org> for ST-Ericsson.
+ * License terms:  GNU General Public License (GPL), version 2
+ */
+#ifndef __CHECKER__
+
+#define CREATE_TRACE_POINTS
+#include "dma-contiguous-trace.h"
+
+#endif
diff --git a/drivers/base/dma-contiguous-trace.h b/drivers/base/dma-contiguous-trace.h
new file mode 100644
index 0000000..ec23bef
--- /dev/null
+++ b/drivers/base/dma-contiguous-trace.h
@@ -0,0 +1,126 @@ 
+/*
+ * dma-contiguous-trace.h
+ *
+ * Copyright (C) ST-Ericsson SA 2011
+ * Author: <benjamin.gaignard@linaro.org> for ST-Ericsson.
+ * License terms:  GNU General Public License (GPL), version 2
+ */
+
+#if !defined(__TRACE_CMA) || defined(TRACE_HEADER_MULTI_READ)
+#define __TRACE_CMA
+
+#include <linux/tracepoint.h>
+#include <linux/dma-contiguous.h>
+
+#if !defined(CONFIG_CMA_TRACER) || defined(__CHECKER__)
+#undef TRACE_EVENT
+#define TRACE_EVENT(name, proto, ...) \
+static inline void trace_ ## name(proto) {}
+#endif
+
+#define PRIV_ENTRY	__field(struct cma *, priv)
+#define PRIV_ASSIGN	__entry->priv = priv
+
+#undef TRACE_SYSTEM
+#define TRACE_SYSTEM cma
+
+TRACE_EVENT(cma_alloc_start,
+	TP_PROTO(struct cma *priv, int count, unsigned int align),
+	TP_ARGS(priv, count, align),
+	TP_STRUCT__entry(
+		PRIV_ENTRY
+		__field(int, count)
+		__field(unsigned int, align)
+	),
+	TP_fast_assign(
+		PRIV_ASSIGN;
+		__entry->count = count;
+		__entry->align = align;
+	),
+	TP_printk(
+		"[%p] CMA alloc start count=0x%x align=0x%x", __entry->priv,
+			__entry->count, __entry->align
+	)
+);
+
+TRACE_EVENT(cma_alloc_end_success,
+	TP_PROTO(struct cma *priv, unsigned long pfn, int count),
+	TP_ARGS(priv, pfn, count),
+	TP_STRUCT__entry(
+		PRIV_ENTRY
+		__field(unsigned long, pfn)
+		__field(int, count)
+	),
+	TP_fast_assign(
+		PRIV_ASSIGN;
+		__entry->pfn = pfn;
+		__entry->count = count;
+	),
+	TP_printk(
+		"[%p] CMA alloc success pfn=0x%lx count=0x%x", __entry->priv,
+			__entry->pfn, __entry->count
+	)
+);
+
+TRACE_EVENT(cma_alloc_end_failed,
+	TP_PROTO(struct cma *priv, int count),
+	TP_ARGS(priv, count),
+	TP_STRUCT__entry(
+		PRIV_ENTRY
+		__field(int, count)
+	),
+	TP_fast_assign(
+		PRIV_ASSIGN;
+		__entry->count = count;
+	),
+	TP_printk(
+		"[%p] CMA alloc failed count=0x%x", __entry->priv,
+			__entry->count
+	)
+);
+
+TRACE_EVENT(cma_release_start,
+	TP_PROTO(struct cma *priv, unsigned long pfn, int count),
+	TP_ARGS(priv, pfn, count),
+	TP_STRUCT__entry(
+		PRIV_ENTRY
+		__field(unsigned long, pfn)
+		__field(int, count)
+	),
+	TP_fast_assign(
+		PRIV_ASSIGN;
+		__entry->pfn = pfn;
+		__entry->count = count;
+	),
+	TP_printk(
+		"[%p] CMA start release pfn=0x%lx count=0x%x", __entry->priv,
+			__entry->pfn, __entry->count
+	)
+);
+
+TRACE_EVENT(cma_release_end,
+	TP_PROTO(struct cma *priv, unsigned long pfn, int count),
+	TP_ARGS(priv, pfn, count),
+	TP_STRUCT__entry(
+		PRIV_ENTRY
+		__field(unsigned long, pfn)
+		__field(int, count)
+	),
+	TP_fast_assign(
+		PRIV_ASSIGN;
+		__entry->pfn = pfn;
+		__entry->count = count;
+	),
+	TP_printk(
+		"[%p] CMA end release pfn=0x%lx count=0x%x", __entry->priv,
+			__entry->pfn, __entry->count
+	)
+);
+
+#endif /* __TRACE_CMA */
+
+#undef TRACE_INCLUDE_PATH
+#define TRACE_INCLUDE_PATH ../../drivers/base
+#undef TRACE_INCLUDE_FILE
+#define TRACE_INCLUDE_FILE dma-contiguous-trace
+#include <trace/define_trace.h>
diff --git a/drivers/base/dma-contiguous.c b/drivers/base/dma-contiguous.c
index 98c0a84..8613dcc 100644
--- a/drivers/base/dma-contiguous.c
+++ b/drivers/base/dma-contiguous.c
@@ -404,6 +404,8 @@  struct page *dma_alloc_from_contiguous(struct device *dev, int count,
 	pr_debug("%s(cma %p, count %d, align %d)\n", __func__, (void *)cma,
 		 count, align);
 
+	trace_cma_alloc_start(cma, count, align);
+
 	if (!count)
 		return NULL;
 
@@ -425,8 +427,12 @@  struct page *dma_alloc_from_contiguous(struct device *dev, int count,
 	mutex_unlock(&cma_mutex);
 
 	pr_debug("%s(): returned %p\n", __func__, pfn_to_page(pfn));
+
+	trace_cma_alloc_end_success(cma, pfn, count);
+
 	return pfn_to_page(pfn);
 free:
+	trace_cma_alloc_end_failed(cma, count);
 	bitmap_clear(cma->bitmap, pageno, count);
 error:
 	mutex_unlock(&cma_mutex);
@@ -458,12 +464,14 @@  int dma_release_from_contiguous(struct device *dev, struct page *pages,
 
 	if (pfn < cma->base_pfn || pfn >= cma->base_pfn + cma->count)
 		return 0;
-
+	trace_cma_release_start(cma, pfn, count);
 	mutex_lock(&cma_mutex);
 
 	bitmap_clear(cma->bitmap, pfn - cma->base_pfn, count);
 	free_contig_range(pfn, count);
 
 	mutex_unlock(&cma_mutex);
+	trace_cma_release_end(cma, pfn, count);
+
 	return 1;
 }
-- 
1.7.0.4