From patchwork Thu Sep 8 03:03:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chunyan Zhang X-Patchwork-Id: 75723 Delivered-To: patch@linaro.org Received: by 10.140.106.11 with SMTP id d11csp622352qgf; Wed, 7 Sep 2016 20:04:47 -0700 (PDT) X-Received: by 10.98.10.71 with SMTP id s68mr88426763pfi.110.1473303887276; Wed, 07 Sep 2016 20:04:47 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id pk4si20931190pab.202.2016.09.07.20.04.46; Wed, 07 Sep 2016 20:04:47 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757246AbcIHDEo (ORCPT + 27 others); Wed, 7 Sep 2016 23:04:44 -0400 Received: from mail-pf0-f169.google.com ([209.85.192.169]:34644 "EHLO mail-pf0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751998AbcIHDEk (ORCPT ); Wed, 7 Sep 2016 23:04:40 -0400 Received: by mail-pf0-f169.google.com with SMTP id p64so13008400pfb.1 for ; Wed, 07 Sep 2016 20:04:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=4PnawPFhhvvl9p1LbDhVTEFU4TW/oJ1VY0AOqHRIHWs=; b=LukbLEUdEGje8cGU1IuhLRQYPm/gZ004auMzy/ExOvObI41gxez7QJGMWoe59NLKOP Bfv8u/NwixQgw87jmgH4jv/bs+SmHHz61Boss0oBouHMeArRt541gHuvZ4d28F05ga3f +VIZxe0XFOb7ypxglIXqRXx3F4x/U2tTcx/b4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=4PnawPFhhvvl9p1LbDhVTEFU4TW/oJ1VY0AOqHRIHWs=; b=IJA99PZomfoH5mrvGKm9EVDLiHveuG3vBUvvxrranEW2Mg3fFUFOTKHorDVHcmG8r8 rSPZ1cX5M9tt+igz7OKy0rmhoerBDT4qgty48n5A0dzDEz2M/PXa8YsguJ/hNPkxD1cV 05fx1iPowR9Rzjzi0l1rwY03VtuTzf9bVuuhFY1GTfS74j/MakBRW+SmCM9oOJT30+DT eTzrdCtnhqvrRFJjTz/pnDr1ri9vAKaMb8pg+Cwbo493n9P5ksqv6+iQc6Hk42LwKrYM kJ1PA5lVmpcGrBh2bDFywPxAx5MOqOLTGWQpLvwDtcmQaJY8HSOa0Vxg3qYIYIv4WdVu 1pCw== X-Gm-Message-State: AE9vXwNLYMpMuIsKFjvWqcGOqSF+D4xT6kZJgdvElABqKXaLS3lxFRkOEdnthLHmvg1vb2V4 X-Received: by 10.98.51.131 with SMTP id z125mr88628170pfz.109.1473303879577; Wed, 07 Sep 2016 20:04:39 -0700 (PDT) Received: from ubuntu16.spreadtrum.com ([175.111.195.49]) by smtp.gmail.com with ESMTPSA id k66sm51867852pfc.30.2016.09.07.20.04.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 07 Sep 2016 20:04:39 -0700 (PDT) From: Chunyan Zhang To: rostedt@goodmis.org, mathieu.poirier@linaro.org, alexander.shishkin@linux.intel.com, mingo@redhat.com Cc: arnd@arndb.de, mike.leach@arm.com, tor@ti.com, philippe.langlais@st.com, nicolas.guion@st.com, felipe.balbi@linux.intel.com, zhang.lyra@gmail.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH V6 2/3] stm class: ftrace: Add ftrace-export-over-stm driver Date: Thu, 8 Sep 2016 11:03:03 +0800 Message-Id: <1473303784-18262-3-git-send-email-zhang.chunyan@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1473303784-18262-1-git-send-email-zhang.chunyan@linaro.org> References: <1473303784-18262-1-git-send-email-zhang.chunyan@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch adds a driver that models itself as an stm_source. Once the stm device and stm_source have been linked via sysfs, the driver registers itself as a trace_export and everything passed to the interface from Ftrace subsystem will end up in the STM trace engine. Signed-off-by: Chunyan Zhang --- drivers/hwtracing/stm/Kconfig | 11 ++++++ drivers/hwtracing/stm/Makefile | 2 + drivers/hwtracing/stm/ftrace.c | 88 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 101 insertions(+) create mode 100644 drivers/hwtracing/stm/ftrace.c -- 2.7.4 diff --git a/drivers/hwtracing/stm/Kconfig b/drivers/hwtracing/stm/Kconfig index 847a39b..b34ea96 100644 --- a/drivers/hwtracing/stm/Kconfig +++ b/drivers/hwtracing/stm/Kconfig @@ -39,4 +39,15 @@ config STM_SOURCE_HEARTBEAT If you want to send heartbeat messages over STM devices, say Y. +config STM_SOURCE_FTRACE + tristate "Copy the output from kernel Ftrace to STM engine" + depends on TRACING + help + This option can be used to copy the output from kernel Ftrace + to STM engine. Enabling this option will introduce a slight + timing effect. + + If you want to send kernel Ftrace messages over STM devices, + say Y. + endif diff --git a/drivers/hwtracing/stm/Makefile b/drivers/hwtracing/stm/Makefile index a9ce3d4..3abd84c 100644 --- a/drivers/hwtracing/stm/Makefile +++ b/drivers/hwtracing/stm/Makefile @@ -6,6 +6,8 @@ obj-$(CONFIG_STM_DUMMY) += dummy_stm.o obj-$(CONFIG_STM_SOURCE_CONSOLE) += stm_console.o obj-$(CONFIG_STM_SOURCE_HEARTBEAT) += stm_heartbeat.o +obj-$(CONFIG_STM_SOURCE_FTRACE) += stm_ftrace.o stm_console-y := console.o stm_heartbeat-y := heartbeat.o +stm_ftrace-y := ftrace.o diff --git a/drivers/hwtracing/stm/ftrace.c b/drivers/hwtracing/stm/ftrace.c new file mode 100644 index 0000000..e652bae --- /dev/null +++ b/drivers/hwtracing/stm/ftrace.c @@ -0,0 +1,88 @@ +/* + * Simple kernel driver to link kernel Ftrace and an STM device + * Copyright (c) 2016, Linaro Ltd. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * STM Ftrace will be registered as a trace_export. + */ + +#include +#include +#include + +#define STM_FTRACE_NR_CHANNELS 1 +#define STM_FTRACE_CHAN 0 + +static int stm_ftrace_link(struct stm_source_data *data); +static void stm_ftrace_unlink(struct stm_source_data *data); + +static struct stm_ftrace { + struct stm_source_data data; + struct trace_export ftrace; +} stm_ftrace = { + .data = { + .name = "ftrace", + .nr_chans = STM_FTRACE_NR_CHANNELS, + .link = stm_ftrace_link, + .unlink = stm_ftrace_unlink, + }, +}; + +/** + * stm_ftrace_write() - write data to STM via 'stm_ftrace' source + * @buf: buffer containing the data packet + * @len: length of the data packet + */ +static void notrace +stm_ftrace_write(const char *buf, unsigned int len) +{ + stm_source_write(&stm_ftrace.data, STM_FTRACE_CHAN, buf, len); +} + +static int stm_ftrace_link(struct stm_source_data *data) +{ + struct stm_ftrace *sf = container_of(data, struct stm_ftrace, data); + + sf->ftrace.write = stm_ftrace_write; + sf->ftrace.next = NULL; + + return register_ftrace_export(&sf->ftrace); +} + +static void stm_ftrace_unlink(struct stm_source_data *data) +{ + struct stm_ftrace *sc = container_of(data, struct stm_ftrace, data); + + unregister_ftrace_export(&sc->ftrace); +} + +static int __init stm_ftrace_init(void) +{ + int ret; + + ret = stm_source_register_device(NULL, &stm_ftrace.data); + if (ret) + pr_err("Failed to register stm_source - ftrace.\n"); + + return ret; +} + +static void __exit stm_ftrace_exit(void) +{ + stm_source_unregister_device(&stm_ftrace.data); +} + +module_init(stm_ftrace_init); +module_exit(stm_ftrace_exit); + +MODULE_LICENSE("GPL v2"); +MODULE_DESCRIPTION("stm_ftrace driver"); +MODULE_AUTHOR("Chunyan Zhang ");