From patchwork Thu Nov 24 12:39:47 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 5307 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 5CE0B23E07 for ; Thu, 24 Nov 2011 12:39:52 +0000 (UTC) Received: from mail-yw0-f52.google.com (mail-yw0-f52.google.com [209.85.213.52]) by fiordland.canonical.com (Postfix) with ESMTP id F2C38A180AF for ; Thu, 24 Nov 2011 12:39:51 +0000 (UTC) Received: by ywa17 with SMTP id 17so953529ywa.11 for ; Thu, 24 Nov 2011 04:39:51 -0800 (PST) Received: by 10.152.135.166 with SMTP id pt6mr17532529lab.26.1322138390686; Thu, 24 Nov 2011 04:39:50 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.152.41.198 with SMTP id h6cs302100lal; Thu, 24 Nov 2011 04:39:50 -0800 (PST) Received: by 10.43.131.196 with SMTP id hr4mr7145484icc.55.1322138388043; Thu, 24 Nov 2011 04:39:48 -0800 (PST) Received: from mail-iy0-f178.google.com (mail-iy0-f178.google.com [209.85.210.178]) by mx.google.com with ESMTPS id k8si64165icw.47.2011.11.24.04.39.47 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 24 Nov 2011 04:39:47 -0800 (PST) Received-SPF: neutral (google.com: 209.85.210.178 is neither permitted nor denied by best guess record for domain of benjamin.gaignard@linaro.org) client-ip=209.85.210.178; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.210.178 is neither permitted nor denied by best guess record for domain of benjamin.gaignard@linaro.org) smtp.mail=benjamin.gaignard@linaro.org Received: by iadj38 with SMTP id j38so3576649iad.37 for ; Thu, 24 Nov 2011 04:39:47 -0800 (PST) MIME-Version: 1.0 Received: by 10.50.188.225 with SMTP id gd1mr32079575igc.50.1322138387192; Thu, 24 Nov 2011 04:39:47 -0800 (PST) Received: by 10.50.40.194 with HTTP; Thu, 24 Nov 2011 04:39:47 -0800 (PST) In-Reply-To: References: Date: Thu, 24 Nov 2011 13:39:47 +0100 Message-ID: Subject: Re: [PATCH] add debug trace to CMA From: Benjamin Gaignard To: linaro-mm-sig@lists.linaro.org, linaro-multimedia@lists.linaro.org Cc: Patch Tracking Hi all, I have rebase my patches for debugfs and trace events on top of CMA v17. Regards, Benjamin 2011/11/10 Benjamin Gaignard > 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 * **│ *Open source software for ARM > SoCs > > ** > > Follow *Linaro: *Facebook | Twitter > | Blog > > >From 9c5ce8acfec5edc9585581244bcc002a3ddb9f2b Mon Sep 17 00:00:00 2001 From: benjamin gaignard 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 --- 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: 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: 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 +#include + +#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 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