All of lore.kernel.org
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: Steven Rostedt <rostedt@goodmis.org>,
	Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: "zhangwei(Jovi)" <jovi.zhangwei@huawei.com>,
	Jiri Olsa <jolsa@redhat.com>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Arnaldo Carvalho de Melo <acme@ghostprotocols.net>,
	Srikar Dronamraju <srikar@linux.vnet.ibm.com>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Ingo Molnar <mingo@redhat.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-kernel@vger.kernel.org
Subject: [RFC PATCH 2/4] tracing: Turn "id"->i_private into call->event.type
Date: Tue, 16 Jul 2013 20:57:23 +0200	[thread overview]
Message-ID: <20130716185723.GA21193@redhat.com> (raw)
In-Reply-To: <20130716185658.GA21167@redhat.com>

ftrace_event_id_fops and event_id_read() is overcomplicated.

1. Change event_create_dir() to pass "data = call->event.type"
   to debugfs_create_file().

   This means that ftrace_event_id_fops doesn't need .open()
   and event_id_read() can simply print (int)i_private

2. event_id_read() has no reason to kmalloc "struct trace_seq"
   (more than PAGE_SIZE!), it can use a small buffer.

Note: "if (*ppos) return 0" looks strange and unneeded,
simple_read_from_buffer(ppos) should handle this case corrrectly.

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
 kernel/trace/trace_events.c |   26 +++++++++-----------------
 1 files changed, 9 insertions(+), 17 deletions(-)

diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index cbd1a57..cefbe85 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -962,24 +962,17 @@ static int trace_format_open(struct inode *inode, struct file *file)
 static ssize_t
 event_id_read(struct file *filp, char __user *ubuf, size_t cnt, loff_t *ppos)
 {
-	struct ftrace_event_call *call = filp->private_data;
-	struct trace_seq *s;
-	int r;
+	int id = (long)ACCESS_ONCE(file_inode(filp)->i_private);
+	char buf[32];
+	int len;
 
+	if (!id)
+		return -ENODEV;
 	if (*ppos)
 		return 0;
 
-	s = kmalloc(sizeof(*s), GFP_KERNEL);
-	if (!s)
-		return -ENOMEM;
-
-	trace_seq_init(s);
-	trace_seq_printf(s, "%d\n", call->event.type);
-
-	r = simple_read_from_buffer(ubuf, cnt, ppos,
-				    s->buffer, s->len);
-	kfree(s);
-	return r;
+	len = sprintf(buf, "%d\n", id);
+	return simple_read_from_buffer(ubuf, cnt, ppos, buf, len);
 }
 
 static ssize_t
@@ -1264,7 +1257,6 @@ static const struct file_operations ftrace_event_format_fops = {
 };
 
 static const struct file_operations ftrace_event_id_fops = {
-	.open = tracing_open_generic,
 	.read = event_id_read,
 	.llseek = default_llseek,
 };
@@ -1496,8 +1488,8 @@ event_create_dir(struct dentry *parent,
 
 #ifdef CONFIG_PERF_EVENTS
 	if (call->event.type && call->class->reg)
-		trace_create_file("id", 0444, file->dir, call,
-		 		  id);
+		trace_create_file("id", 0444, file->dir,
+				  (void*)(long)call->event.type, id);
 #endif
 
 	/*
-- 
1.5.5.1


  parent reply	other threads:[~2013-07-16 19:02 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-16 18:56 [RFC PATCH 0/4] tracing: fix open/delete fixes Oleg Nesterov
2013-07-16 18:57 ` [RFC PATCH 1/4] tracing: Change remove_event_from_tracers() to clear d_subdirs->i_private Oleg Nesterov
2013-07-16 18:57 ` Oleg Nesterov [this message]
2013-07-16 19:49   ` [RFC PATCH 2/4] tracing: Turn "id"->i_private into call->event.type Steven Rostedt
2013-07-17 19:39     ` Oleg Nesterov
2013-07-16 18:57 ` [RFC PATCH 3/4] tracing: Kill tracing_open/release_generic_file Oleg Nesterov
2013-07-16 19:51   ` Steven Rostedt
2013-07-17 19:19     ` Oleg Nesterov
2013-07-18 10:56       ` Masami Hiramatsu
2013-07-18 14:55         ` Oleg Nesterov
2013-07-16 18:57 ` [RFC PATCH 4/4] tracing: Change ftrace_event_filter_fops to rely on event_mutex/i_private Oleg Nesterov
2013-07-17  2:36 ` [RFC PATCH 0/4] tracing: fix open/delete fixes Masami Hiramatsu
2013-07-17 14:43   ` Oleg Nesterov
2013-07-18  8:18     ` Masami Hiramatsu
2013-07-18 15:27       ` Oleg Nesterov
2013-07-17 19:30 ` [RFC PATCH 5/4] tracing: Simplify the ftrace_event_field iteration in f_next/f_show Oleg Nesterov
2013-07-17 19:37   ` Oleg Nesterov
2013-07-17 19:30 ` [RFC PATCH 6/4] tracing: Change f_start() to verify i_private under event_mutex Oleg Nesterov

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=20130716185723.GA21193@redhat.com \
    --to=oleg@redhat.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@ghostprotocols.net \
    --cc=akpm@linux-foundation.org \
    --cc=fweisbec@gmail.com \
    --cc=jolsa@redhat.com \
    --cc=jovi.zhangwei@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=masami.hiramatsu.pt@hitachi.com \
    --cc=mingo@redhat.com \
    --cc=rostedt@goodmis.org \
    --cc=srikar@linux.vnet.ibm.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.