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
@@ -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
@@ -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
new file mode 100644
@@ -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
new file mode 100644
@@ -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>
@@ -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