public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: tip-bot for Zhaolei <zhaolei@cn.fujitsu.com>
To: linux-tip-commits@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, hpa@zytor.com, mingo@redhat.com,
	rostedt@goodmis.org, zhaolei@cn.fujitsu.com, tglx@linutronix.de
Subject: [tip:tracing/core] ftrace: Move setting of clock-source out of options
Date: Wed, 26 Aug 2009 07:23:42 GMT	[thread overview]
Message-ID: <tip-5079f3261ffd7fe4a537679af695f2328943a245@git.kernel.org> (raw)
In-Reply-To: <4A939D08.6050604@cn.fujitsu.com>

Commit-ID:  5079f3261ffd7fe4a537679af695f2328943a245
Gitweb:     http://git.kernel.org/tip/5079f3261ffd7fe4a537679af695f2328943a245
Author:     Zhaolei <zhaolei@cn.fujitsu.com>
AuthorDate: Tue, 25 Aug 2009 16:12:56 +0800
Committer:  Steven Rostedt <rostedt@goodmis.org>
CommitDate: Wed, 26 Aug 2009 00:32:08 -0400

ftrace: Move setting of clock-source out of options

There are many clock sources for the tracing system but we can only
enable/disable one at a time with the trace/options file.
We can move the setting of clock-source out of options and add a separate
file for it:
 # cat trace_clock
 [local] global
 # echo global > trace_clock
 # cat trace_clock
 local [global]

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
LKML-Reference: <4A939D08.6050604@cn.fujitsu.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>


---
 kernel/trace/trace.c |   92 ++++++++++++++++++++++++++++++++++++++++---------
 kernel/trace/trace.h |    7 ++--
 2 files changed, 79 insertions(+), 20 deletions(-)

diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 8ac2043..63dbc7f 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -323,12 +323,21 @@ static const char *trace_options[] = {
 	"printk-msg-only",
 	"context-info",
 	"latency-format",
-	"global-clock",
 	"sleep-time",
 	"graph-time",
 	NULL
 };
 
+static struct {
+	u64 (*func)(void);
+	const char *name;
+} trace_clocks[] = {
+	{ trace_clock_local,	"local" },
+	{ trace_clock_global,	"global" },
+};
+
+int trace_clock_id;
+
 /*
  * ftrace_max_lock is used to protect the swapping of buffers
  * when taking a max snapshot. The buffers themselves are
@@ -2159,22 +2168,6 @@ static void set_tracer_flags(unsigned int mask, int enabled)
 		trace_flags |= mask;
 	else
 		trace_flags &= ~mask;
-
-	if (mask == TRACE_ITER_GLOBAL_CLK) {
-		u64 (*func)(void);
-
-		if (enabled)
-			func = trace_clock_global;
-		else
-			func = trace_clock_local;
-
-		mutex_lock(&trace_types_lock);
-		ring_buffer_set_clock(global_trace.buffer, func);
-
-		if (max_tr.buffer)
-			ring_buffer_set_clock(max_tr.buffer, func);
-		mutex_unlock(&trace_types_lock);
-	}
 }
 
 static ssize_t
@@ -3142,6 +3135,62 @@ tracing_mark_write(struct file *filp, const char __user *ubuf,
 	return cnt;
 }
 
+static ssize_t tracing_clock_read(struct file *filp, char __user *ubuf,
+				  size_t cnt, loff_t *ppos)
+{
+	char buf[64];
+	int bufiter = 0;
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(trace_clocks); i++)
+		bufiter += snprintf(buf + bufiter, sizeof(buf) - bufiter,
+			"%s%s%s%s", i ? " " : "",
+			i == trace_clock_id ? "[" : "", trace_clocks[i].name,
+			i == trace_clock_id ? "]" : "");
+	bufiter += snprintf(buf + bufiter, sizeof(buf) - bufiter, "\n");
+
+	return simple_read_from_buffer(ubuf, cnt, ppos, buf, bufiter);
+}
+
+static ssize_t tracing_clock_write(struct file *filp, const char __user *ubuf,
+				   size_t cnt, loff_t *fpos)
+{
+	char buf[64];
+	const char *clockstr;
+	int i;
+
+	if (cnt >= sizeof(buf))
+		return -EINVAL;
+
+	if (copy_from_user(&buf, ubuf, cnt))
+		return -EFAULT;
+
+	buf[cnt] = 0;
+
+	clockstr = strstrip(buf);
+
+	for (i = 0; i < ARRAY_SIZE(trace_clocks); i++) {
+		if (strcmp(trace_clocks[i].name, clockstr) == 0)
+			break;
+	}
+	if (i == ARRAY_SIZE(trace_clocks))
+		return -EINVAL;
+
+	trace_clock_id = i;
+
+	mutex_lock(&trace_types_lock);
+
+	ring_buffer_set_clock(global_trace.buffer, trace_clocks[i].func);
+	if (max_tr.buffer)
+		ring_buffer_set_clock(max_tr.buffer, trace_clocks[i].func);
+
+	mutex_unlock(&trace_types_lock);
+
+	*fpos += cnt;
+
+	return cnt;
+}
+
 static const struct file_operations tracing_max_lat_fops = {
 	.open		= tracing_open_generic,
 	.read		= tracing_max_lat_read,
@@ -3179,6 +3228,12 @@ static const struct file_operations tracing_mark_fops = {
 	.write		= tracing_mark_write,
 };
 
+static const struct file_operations trace_clock_fops = {
+	.open		= tracing_open_generic,
+	.read		= tracing_clock_read,
+	.write		= tracing_clock_write,
+};
+
 struct ftrace_buffer_info {
 	struct trace_array	*tr;
 	void			*spare;
@@ -3918,6 +3973,9 @@ static __init int tracer_init_debugfs(void)
 	trace_create_file("saved_cmdlines", 0444, d_tracer,
 			NULL, &tracing_saved_cmdlines_fops);
 
+	trace_create_file("trace_clock", 0644, d_tracer, NULL,
+			  &trace_clock_fops);
+
 #ifdef CONFIG_DYNAMIC_FTRACE
 	trace_create_file("dyn_ftrace_total_info", 0444, d_tracer,
 			&ftrace_update_tot_cnt, &tracing_dyn_info_fops);
diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
index 64dda57..654fd65 100644
--- a/kernel/trace/trace.h
+++ b/kernel/trace/trace.h
@@ -568,6 +568,8 @@ trace_vprintk(unsigned long ip, const char *fmt, va_list args);
 
 extern unsigned long trace_flags;
 
+extern int trace_clock_id;
+
 /* Standard output formatting function used for function return traces */
 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
 extern enum print_line_t print_graph_function(struct trace_iterator *iter);
@@ -656,9 +658,8 @@ enum trace_iterator_flags {
 	TRACE_ITER_PRINTK_MSGONLY	= 0x10000,
 	TRACE_ITER_CONTEXT_INFO		= 0x20000, /* Print pid/cpu/time */
 	TRACE_ITER_LATENCY_FMT		= 0x40000,
-	TRACE_ITER_GLOBAL_CLK		= 0x80000,
-	TRACE_ITER_SLEEP_TIME		= 0x100000,
-	TRACE_ITER_GRAPH_TIME		= 0x200000,
+	TRACE_ITER_SLEEP_TIME		= 0x80000,
+	TRACE_ITER_GRAPH_TIME		= 0x100000,
 };
 
 /*

  parent reply	other threads:[~2009-08-26  7:24 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-24 10:40 [PATCH 0/3] Add walltime support for ring-buffer Zhaolei
2009-07-24 10:42 ` [PATCH] " Zhaolei
2009-07-24 10:47   ` Zhaolei
2009-07-24 10:43 ` [RFC PATCH 1/3] " Zhaolei
2009-07-24 10:43 ` [RFC PATCH 2/3] Apply walltime-supporting functions to trace system Zhaolei
2009-07-24 10:44 ` [RFC PATCH 3/3] Make ftrace display walltime in output Zhaolei
2009-07-24 13:05 ` [PATCH 0/3] Add walltime support for ring-buffer Steven Rostedt
2009-07-28  1:43   ` KOSAKI Motohiro
2009-07-28  1:53     ` Frederic Weisbecker
2009-07-28  2:19       ` Steven Rostedt
2009-08-17  9:22         ` [RFC PATCH] Add timer-source of walltime for ftrace Zhaolei
2009-08-17 16:49           ` Frederic Weisbecker
2009-08-18  2:09             ` Zhaolei
2009-08-18 18:52               ` Steven Rostedt
2009-08-18 15:57           ` KOSAKI Motohiro
2009-08-18 18:58             ` Steven Rostedt
2009-08-19  9:16               ` Zhaolei
2009-08-25  8:12               ` [PATCH 0/3] ftrace: " Zhaolei
2009-08-25  8:12                 ` [PATCH 1/3] ftrace: Move setting of clock-source out of options Zhaolei
2009-08-26  2:35                   ` Steven Rostedt
2009-08-26  7:23                   ` tip-bot for Zhaolei [this message]
2009-08-25  8:14                 ` [PATCH 2/3] ftrace: add tracepoint for xtime Zhaolei
2009-08-26  2:39                   ` Steven Rostedt
2009-09-01  8:03                     ` Zhaolei
2009-09-16 19:56                   ` john stultz
2009-09-16 19:58                     ` john stultz
2009-09-16 20:32                       ` Steven Rostedt
2009-09-16 20:49                         ` john stultz
2009-09-17  6:34                           ` Zhaolei
2009-08-25  8:15                 ` [PATCH 3/3] ftrace: Add timer-source of walltime for ftrace Zhaolei
2009-08-26  2:52                   ` Steven Rostedt
2009-09-16  5:25                 ` [PATCH v2 0/2] " Zhaolei
2009-09-16  5:27                   ` [PATCH v2 1/2] ftrace: add tracepoint for xtime Zhaolei
2009-09-16 19:33                     ` Steven Rostedt
2009-09-16  5:29                   ` [PATCH v2 2/2] ftrace: Add timer-source of walltime for ftrace Zhaolei
2009-09-16  5:59                     ` Frederic Weisbecker
2009-09-16  6:40                       ` Zhaolei
2009-09-16 19:37                         ` Steven Rostedt
2009-09-17  7:10                           ` Zhaolei
2009-11-04  9:39                             ` [PATCH v3] ftrace: Add timer-source of walltime Zhaolei
2009-11-04  9:39                             ` Zhaolei
2009-11-04  9:41                             ` Zhaolei
2009-07-28  2:23       ` [PATCH 0/3] Add walltime support for ring-buffer KOSAKI Motohiro
2009-08-03  7:22         ` Ingo Molnar
2009-08-03  9:32           ` KOSAKI Motohiro
2009-08-04 14:38             ` Ingo Molnar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tip-5079f3261ffd7fe4a537679af695f2328943a245@git.kernel.org \
    --to=zhaolei@cn.fujitsu.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=rostedt@goodmis.org \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox