From: Steven Rostedt <rostedt@goodmis.org>
To: Peter Zijlstra <peterz@infradead.org>
Cc: linux-kernel@vger.kernel.org, Ingo Molnar <mingo@elte.hu>,
Andrew Morton <akpm@linux-foundation.org>,
Frederic Weisbecker <fweisbec@gmail.com>,
Li Zefan <lizf@cn.fujitsu.com>,
Mathieu Desnoyers <compudj@krystal.dyndns.org>
Subject: Re: [PATCH 2/3] tracing/profile: add ref count for registering profile events
Date: Fri, 11 Sep 2009 10:40:25 -0400 [thread overview]
Message-ID: <1252680025.18996.684.camel@gandalf.stny.rr.com> (raw)
In-Reply-To: <1252678183.7126.34.camel@laptop>
On Fri, 2009-09-11 at 16:09 +0200, Peter Zijlstra wrote:
> On Fri, 2009-09-11 at 16:04 +0200, Peter Zijlstra wrote:
> > On Fri, 2009-09-11 at 09:54 -0400, Steven Rostedt wrote:
> >
> > > +#ifdef MODULE
> > > +# define event_trace_up_ref() \
> > > + do { \
> > > + if (!try_module_get(THIS_MODULE)) { \
> > > + atomic_dec(&event_call->profile_count); \
> > > + return -ENOENT; \
> > > + } \
> > > + } while (0)
> > > +# define event_trace_down_ref() module_put(THIS_MODULE)
> > > +#else
> > > +# define event_trace_up_ref() do { } while (0)
> > > +# define event_trace_down_ref() do { } while (0)
> > > +#endif
> >
> > That's like truely gruesomely ugly.
> >
> > At the very least write it like:
> >
> > int event_trace_up_ref(struct ftrace_event_call *call)
> > {
> > if (!try_module_get(THIS_MODULE)) {
> > atomic_dev(&call->profile_count);
> > return -ENOENT;
> > }
> > return 0;
> > }
>
> Or we can go with Li's original patch, that was less ugly.
Here's another version of the patch (less ugly). I forgot that the
try_module_get should handle code compiled with !CONFIG_MODULE.
This should be less ugly.
-- Steve
diff --git a/include/trace/ftrace.h b/include/trace/ftrace.h
index 308bafd..6d5edd1 100644
--- a/include/trace/ftrace.h
+++ b/include/trace/ftrace.h
@@ -409,16 +409,23 @@ static int ftrace_profile_enable_##call(struct ftrace_event_call *event_call) \
{ \
int ret = 0; \
\
- if (!atomic_inc_return(&event_call->profile_count)) \
+ if (!atomic_inc_return(&event_call->profile_count)) { \
+ if (!try_module_get(THIS_MODULE)) \
+ goto out_fail; \
ret = register_trace_##call(ftrace_profile_##call); \
+ } \
\
return ret; \
+ out_fail: \
+ atomic_dec(&event_call->profile_count); \
} \
\
static void ftrace_profile_disable_##call(struct ftrace_event_call *event_call)\
{ \
- if (atomic_add_negative(-1, &event_call->profile_count)) \
+ if (atomic_add_negative(-1, &event_call->profile_count)) { \
unregister_trace_##call(ftrace_profile_##call); \
+ module_put(THIS_MODULE) \
+ } \
}
#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
next prev parent reply other threads:[~2009-09-11 14:40 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-09-11 13:54 [PATCH 0/3] [GIT PULL] tracing: various updates Steven Rostedt
2009-09-11 13:54 ` [PATCH 1/3] x86/tracing: comment need for atomic nop Steven Rostedt
2009-09-11 13:54 ` [PATCH 2/3] tracing/profile: add ref count for registering profile events Steven Rostedt
2009-09-11 14:04 ` Peter Zijlstra
2009-09-11 14:09 ` Peter Zijlstra
2009-09-11 14:33 ` Steven Rostedt
2009-09-11 14:37 ` Peter Zijlstra
2009-09-11 14:52 ` Steven Rostedt
2009-09-12 14:14 ` Mathieu Desnoyers
2009-09-11 14:40 ` Steven Rostedt [this message]
2009-09-11 14:12 ` Steven Rostedt
2009-09-11 13:54 ` [PATCH 3/3] tracing: add latency format to function_graph tracer Steven Rostedt
2009-09-11 14:55 ` Frederic Weisbecker
2009-09-11 15:11 ` Steven Rostedt
2009-09-11 15:18 ` Frederic Weisbecker
2009-09-11 15:38 ` Török Edwin
2009-09-11 15:43 ` Frederic Weisbecker
2009-09-11 15:50 ` Steven Rostedt
2009-09-11 16:08 ` Török Edwin
2009-09-12 10:25 ` Matt Fleming
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=1252680025.18996.684.camel@gandalf.stny.rr.com \
--to=rostedt@goodmis.org \
--cc=akpm@linux-foundation.org \
--cc=compudj@krystal.dyndns.org \
--cc=fweisbec@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lizf@cn.fujitsu.com \
--cc=mingo@elte.hu \
--cc=peterz@infradead.org \
/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
all inboxes | Powered by JetHome®