From patchwork Tue Jul 7 10:10:42 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chunyan Zhang X-Patchwork-Id: 50814 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f70.google.com (mail-la0-f70.google.com [209.85.215.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id E657622A03 for ; Tue, 7 Jul 2015 10:12:49 +0000 (UTC) Received: by laer2 with SMTP id r2sf55767801lae.3 for ; Tue, 07 Jul 2015 03:12:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:in-reply-to:references :sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=TCRTVrW+ehkQA6ckN42ZNpdAuUTrZg4iA8vpbMIvFaw=; b=mv8U9XTuKF2mRg1kMQiH33JPoMiX6QbuOsx9pBVUFsA3nCvPyoRk1YFiOf2rVPRjoU t46jK8JEsHy+g+t5QlB44TsqVSzP7lnD1oJyURTPo6mfqJX1iICEv0/wDrbfdhdStZ56 Air7Qscigg9bmisbO/SfWJx65jDK7y5VIMMQWSl0W1iDxXyZ0A2xhdYou3R92oMDuRiT sbnQpef5RyBPSQUvX+UqNzz5NC8PnXRFrO2GwrExCgttO6aMbK5MUxs1wzXhjuYkLLsZ /P0oakv6UGzwtp3H7f4zN0voC9D52AanpaCdjZcYfoxoMMRX5c+ahwB788w2bZighJb8 8/zQ== X-Gm-Message-State: ALoCoQlRMOoyLVjXLLeyvLC+8JydJ3ikzwATQnyPewfLH3G7ZR8o97oWa5zYCytbh+4wAkgg8wLS X-Received: by 10.112.13.200 with SMTP id j8mr1804833lbc.14.1436263968569; Tue, 07 Jul 2015 03:12:48 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.6.202 with SMTP id d10ls804831laa.69.gmail; Tue, 07 Jul 2015 03:12:48 -0700 (PDT) X-Received: by 10.152.204.43 with SMTP id kv11mr3280205lac.15.1436263968383; Tue, 07 Jul 2015 03:12:48 -0700 (PDT) Received: from mail-la0-f48.google.com (mail-la0-f48.google.com. [209.85.215.48]) by mx.google.com with ESMTPS id dx6si8114117lbc.64.2015.07.07.03.12.48 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 Jul 2015 03:12:48 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.48 as permitted sender) client-ip=209.85.215.48; Received: by lagx9 with SMTP id x9so188706777lag.1 for ; Tue, 07 Jul 2015 03:12:48 -0700 (PDT) X-Received: by 10.112.166.2 with SMTP id zc2mr3249170lbb.29.1436263968251; Tue, 07 Jul 2015 03:12:48 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.108.230 with SMTP id hn6csp2282874lbb; Tue, 7 Jul 2015 03:12:46 -0700 (PDT) X-Received: by 10.66.155.36 with SMTP id vt4mr7569816pab.32.1436263964082; Tue, 07 Jul 2015 03:12:44 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v5si33970032pdb.7.2015.07.07.03.12.43; Tue, 07 Jul 2015 03:12:44 -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; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756855AbbGGKMb (ORCPT + 29 others); Tue, 7 Jul 2015 06:12:31 -0400 Received: from mail-pd0-f176.google.com ([209.85.192.176]:36414 "EHLO mail-pd0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752568AbbGGKMP (ORCPT ); Tue, 7 Jul 2015 06:12:15 -0400 Received: by pddu5 with SMTP id u5so35869897pdd.3 for ; Tue, 07 Jul 2015 03:12:15 -0700 (PDT) X-Received: by 10.70.42.101 with SMTP id n5mr7394945pdl.93.1436263935466; Tue, 07 Jul 2015 03:12:15 -0700 (PDT) Received: from zcy-ubuntu.spreadtrum.com ([175.111.195.49]) by mx.google.com with ESMTPSA id o7sm21361821pdi.16.2015.07.07.03.12.11 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 07 Jul 2015 03:12:14 -0700 (PDT) From: Chunyan Zhang To: rostedt@goodmis.org, mingo@redhat.com Cc: mathieu.poirier@linaro.org, serge.broslavsky@linaro.org, broonie@kernel.org, alexander.shishkin@linux.intel.com, zhang.lyra@gmail.com, linux-kernel@vger.kernel.org Subject: [RFC PATCH v3 3/4] trace: Introduce trace log output function for STM Date: Tue, 7 Jul 2015 18:10:42 +0800 Message-Id: X-Mailer: git-send-email 1.9.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: zhang.chunyan@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.48 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , This patch introduced a few functions to print the event trace log to STM buffer when the trace event happened and the event information was committed to ring buffer. Before outputting the trace log to STM, we have to get the human readable trace log content and print it into a local buffer in the format of a string, the function 'trace_event_buf_vprintf()' is just for this purpose. Signed-off-by: Chunyan Zhang --- kernel/trace/Makefile | 1 + kernel/trace/trace_output_stm.c | 99 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 kernel/trace/trace_output_stm.c diff --git a/kernel/trace/Makefile b/kernel/trace/Makefile index 9b1044e..002de34 100644 --- a/kernel/trace/Makefile +++ b/kernel/trace/Makefile @@ -67,4 +67,5 @@ obj-$(CONFIG_UPROBE_EVENT) += trace_uprobe.o obj-$(CONFIG_TRACEPOINT_BENCHMARK) += trace_benchmark.o +obj-$(CONFIG_STM_TRACE_EVENT) += trace_output_stm.o libftrace-y := ftrace.o diff --git a/kernel/trace/trace_output_stm.c b/kernel/trace/trace_output_stm.c new file mode 100644 index 0000000..689c6d5 --- /dev/null +++ b/kernel/trace/trace_output_stm.c @@ -0,0 +1,99 @@ +#include +#include +#include +#include "trace.h" + +#define STM_OUTPUT_STRLEN 128 + +/* store the event trace log for STM */ +struct trace_buffer_stm { + char buffer[STM_OUTPUT_STRLEN]; + unsigned int used_len; + unsigned int size; +}; + +static struct trace_buffer_stm *trace_event_stm_buffer; +static struct trace_seq *stm_tmp_seq; +static int stm_buffers_allocated; + +void trace_event_buf_vprintf(struct trace_buffer_stm *tb, const char *fmt, ...) +{ + va_list ap; + char *buffer = tb->buffer + tb->used_len; + unsigned int size = tb->size - tb->used_len; + + va_start(ap, fmt); + tb->used_len += vsnprintf(buffer, size, fmt, ap); + va_end(ap); +} +EXPORT_SYMBOL_GPL(trace_event_buf_vprintf); + +static inline void stm_buf_reset(struct trace_buffer_stm *tb) +{ + tb->used_len = 0; +} + +void trace_event_stm_log(struct trace_event_buffer *buffer) +{ + + struct trace_seq *p = stm_tmp_seq; + struct trace_buffer_stm *tb; + struct trace_event_call *event_call = buffer->trace_file->event_call; + struct trace_entry *entry = (struct trace_entry *)buffer->entry; + + if (!stm_buffers_allocated) + return; + + tb = trace_event_stm_buffer; + + if (event_call->output_stm) + event_call->output_stm(p, entry, tb); + + stm_trace_event_write(tb->buffer, tb->used_len); + + stm_buf_reset(tb); +} +EXPORT_SYMBOL_GPL(trace_event_stm_log); + +static int alloc_stm_tmp_seq(void) +{ + struct trace_seq *seq; + + seq = kzalloc(sizeof(struct trace_seq), GFP_KERNEL); + if (!seq) + return -ENOMEM; + + stm_tmp_seq = seq; + + return 0; +} + +static int alloc_stm_trace_buffer(void) +{ + struct trace_buffer_stm *buffer; + + buffer = kzalloc(sizeof(struct trace_buffer_stm), GFP_KERNEL); + if (!buffer) + return -ENOMEM; + + buffer->used_len = 0; + buffer->size = ARRAY_SIZE(buffer->buffer); + + trace_event_stm_buffer = buffer; + + return 0; +} + +static __init int trace_stm_init_buffers(void) +{ + if (alloc_stm_trace_buffer()) + return -ENOMEM; + + if (alloc_stm_tmp_seq()) + return -ENOMEM; + + stm_buffers_allocated = 1; + + return 0; +} +fs_initcall(trace_stm_init_buffers);