Re: [PATCH] tracing: Allow instances to have independent trace flags/trace options.

2014-03-06 Thread Steven Rostedt
On Fri, 14 Feb 2014 15:30:54 -0800
Bharath Ravi  wrote:

> Hi Steven,
> 
> What are your thoughts on this patch?

Ouch, I didn't mean to ignore you for so long. You should have pinged
again. Yeah, I know you pinged twice, but I was hacking away at other
things and even marked this email as "Important". The problem is, I
also marked a lot of other emails as "Important" too, and I'm just now
getting to this one :-(

This patch needs to be broken up into three. And probably needs to
rebase on my ftrace/core branch (note, that branch may rebase. You can
rebase on for-next*, which will not rebase, but also wont have all the
cool stuff I'm currently working on ;-)

First patch: Adds global_trace_flags() function and just substitutes
the trace_flags to global_trace_flags(). Nothing more.

Second patch: Adds the infrastructure to have a global_trace_flags()
and a instance trace_flags(). Just the infrastructure. Do not add any
instance flags.

Third patch: Moves overwrite to the instance trace flags.

Thanks!

-- Steve

* my for-next will rebase, but only when everything is in mainline.
  That is, I might merge stuff from multiple branches into my for-next
  branch, but after everything is in mainline. I just rebase to the
  next mainline release. Only the merge commit will disappear.


> --
> Bharath Ravi |  rbhar...@google.com
> 
> 
> On Thu, Jan 23, 2014 at 11:46 AM, Bharath Ravi  wrote:
> > Hi Steven,
> >
> > This patch allows instances to have their own independent trace
> > options (as opposed to the current globally shared trace options)
> >
> > Does this look like a reasonable change?
> > Bharath Ravi |  rbhar...@google.com
> >
> >
> > On Fri, Nov 22, 2013 at 10:51 AM, Bharath Ravi  wrote:
> >> Currently, the trace options are global, and shared among all
> >> instances. This change divides the set of trace options into global
> >> options and instance specific options. Instance specific options may be
> >> set independently by an instance without affecting either the global
> >> tracer or other instances. Global options are viewable and modifiable
> >> only from the global tracer, preventing tracers from modifying shared
> >> flags.
> >>
> >> Currently, only the "overwrite" flag is a per-instance flag. Others may
> >> be supported as and when instances are modified to support more tracers.
> >>
> >> As a side-effect, the global trace_flags variable is replaced by
> >> instance specific trace_flags in trace_array. References to the old
> >> global flags variable are replaced with accessors to the global_tracer's
> >> trace_flags.
> >>
> >> Signed-off-by: Bharath Ravi 
> >> ---
> >>  kernel/trace/blktrace.c  |   5 +-
> >>  kernel/trace/ftrace.c|   4 +-
> >>  kernel/trace/trace.c | 131 
> >> +--
> >>  kernel/trace/trace.h |  51 +++---
> >>  kernel/trace/trace_events.c  |   2 +-
> >>  kernel/trace/trace_functions_graph.c |  10 +--
> >>  kernel/trace/trace_irqsoff.c |   3 +-
> >>  kernel/trace/trace_kdb.c |   6 +-
> >>  kernel/trace/trace_output.c  |   8 +--
> >>  kernel/trace/trace_printk.c  |   8 +--
> >>  kernel/trace/trace_sched_wakeup.c|   3 +-
> >>  kernel/trace/trace_syscalls.c|   2 +-
> >>  12 files changed, 149 insertions(+), 84 deletions(-)
> >>
> >> diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
> >> index b8b8560..0d71009 100644
> >> --- a/kernel/trace/blktrace.c
> >> +++ b/kernel/trace/blktrace.c
> >> @@ -1350,7 +1350,7 @@ static enum print_line_t print_one_line(struct 
> >> trace_iterator *iter,
> >>
> >> t  = te_blk_io_trace(iter->ent);
> >> what   = t->action & ((1 << BLK_TC_SHIFT) - 1);
> >> -   long_act   = !!(trace_flags & TRACE_ITER_VERBOSE);
> >> +   long_act   = !!(global_trace_flags() & TRACE_ITER_VERBOSE);
> >> log_action = classic ? _log_action_classic : _log_action;
> >>
> >> if (t->action == BLK_TN_MESSAGE) {
> >> @@ -1411,12 +1411,15 @@ static enum print_line_t 
> >> blk_tracer_print_line(struct trace_iterator *iter)
> >>
> >>  static int blk_tracer_set_flag(u32 old_flags, u32 bit, int set)
> >>  {
> >> +   unsigned long trace_flags = global_trace_flags();
> >> /* don't output context-info for blk_classic output */
> >> if (bit == TRACE_BLK_OPT_CLASSIC) {
> >> if (set)
> >> trace_flags &= ~TRACE_ITER_CONTEXT_INFO;
> >> else
> >> trace_flags |= TRACE_ITER_CONTEXT_INFO;
> >> +
> >> +   set_global_trace_flags(trace_flags);
> >> }
> >> return 0;
> >>  }
> >> diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
> >> index 03cf44a..c356d5d 100644
> >> --- a/kernel/trace/ftrace.c
> >> +++ b/kernel/trace/ftrace.c
> >> @@ -911,7 +911,7 @@ static void profile_graph_return(struct 
> >> ftrace_graph_ret *trace)
> >>
> >> calltime = 

Re: [PATCH] tracing: Allow instances to have independent trace flags/trace options.

2014-03-06 Thread Steven Rostedt
On Fri, 14 Feb 2014 15:30:54 -0800
Bharath Ravi rbhar...@google.com wrote:

 Hi Steven,
 
 What are your thoughts on this patch?

Ouch, I didn't mean to ignore you for so long. You should have pinged
again. Yeah, I know you pinged twice, but I was hacking away at other
things and even marked this email as Important. The problem is, I
also marked a lot of other emails as Important too, and I'm just now
getting to this one :-(

This patch needs to be broken up into three. And probably needs to
rebase on my ftrace/core branch (note, that branch may rebase. You can
rebase on for-next*, which will not rebase, but also wont have all the
cool stuff I'm currently working on ;-)

First patch: Adds global_trace_flags() function and just substitutes
the trace_flags to global_trace_flags(). Nothing more.

Second patch: Adds the infrastructure to have a global_trace_flags()
and a instance trace_flags(). Just the infrastructure. Do not add any
instance flags.

Third patch: Moves overwrite to the instance trace flags.

Thanks!

-- Steve

* my for-next will rebase, but only when everything is in mainline.
  That is, I might merge stuff from multiple branches into my for-next
  branch, but after everything is in mainline. I just rebase to the
  next mainline release. Only the merge commit will disappear.


 --
 Bharath Ravi |  rbhar...@google.com
 
 
 On Thu, Jan 23, 2014 at 11:46 AM, Bharath Ravi rbhar...@google.com wrote:
  Hi Steven,
 
  This patch allows instances to have their own independent trace
  options (as opposed to the current globally shared trace options)
 
  Does this look like a reasonable change?
  Bharath Ravi |  rbhar...@google.com
 
 
  On Fri, Nov 22, 2013 at 10:51 AM, Bharath Ravi rbhar...@google.com wrote:
  Currently, the trace options are global, and shared among all
  instances. This change divides the set of trace options into global
  options and instance specific options. Instance specific options may be
  set independently by an instance without affecting either the global
  tracer or other instances. Global options are viewable and modifiable
  only from the global tracer, preventing tracers from modifying shared
  flags.
 
  Currently, only the overwrite flag is a per-instance flag. Others may
  be supported as and when instances are modified to support more tracers.
 
  As a side-effect, the global trace_flags variable is replaced by
  instance specific trace_flags in trace_array. References to the old
  global flags variable are replaced with accessors to the global_tracer's
  trace_flags.
 
  Signed-off-by: Bharath Ravi rbhar...@google.com
  ---
   kernel/trace/blktrace.c  |   5 +-
   kernel/trace/ftrace.c|   4 +-
   kernel/trace/trace.c | 131 
  +--
   kernel/trace/trace.h |  51 +++---
   kernel/trace/trace_events.c  |   2 +-
   kernel/trace/trace_functions_graph.c |  10 +--
   kernel/trace/trace_irqsoff.c |   3 +-
   kernel/trace/trace_kdb.c |   6 +-
   kernel/trace/trace_output.c  |   8 +--
   kernel/trace/trace_printk.c  |   8 +--
   kernel/trace/trace_sched_wakeup.c|   3 +-
   kernel/trace/trace_syscalls.c|   2 +-
   12 files changed, 149 insertions(+), 84 deletions(-)
 
  diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
  index b8b8560..0d71009 100644
  --- a/kernel/trace/blktrace.c
  +++ b/kernel/trace/blktrace.c
  @@ -1350,7 +1350,7 @@ static enum print_line_t print_one_line(struct 
  trace_iterator *iter,
 
  t  = te_blk_io_trace(iter-ent);
  what   = t-action  ((1  BLK_TC_SHIFT) - 1);
  -   long_act   = !!(trace_flags  TRACE_ITER_VERBOSE);
  +   long_act   = !!(global_trace_flags()  TRACE_ITER_VERBOSE);
  log_action = classic ? blk_log_action_classic : blk_log_action;
 
  if (t-action == BLK_TN_MESSAGE) {
  @@ -1411,12 +1411,15 @@ static enum print_line_t 
  blk_tracer_print_line(struct trace_iterator *iter)
 
   static int blk_tracer_set_flag(u32 old_flags, u32 bit, int set)
   {
  +   unsigned long trace_flags = global_trace_flags();
  /* don't output context-info for blk_classic output */
  if (bit == TRACE_BLK_OPT_CLASSIC) {
  if (set)
  trace_flags = ~TRACE_ITER_CONTEXT_INFO;
  else
  trace_flags |= TRACE_ITER_CONTEXT_INFO;
  +
  +   set_global_trace_flags(trace_flags);
  }
  return 0;
   }
  diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
  index 03cf44a..c356d5d 100644
  --- a/kernel/trace/ftrace.c
  +++ b/kernel/trace/ftrace.c
  @@ -911,7 +911,7 @@ static void profile_graph_return(struct 
  ftrace_graph_ret *trace)
 
  calltime = trace-rettime - trace-calltime;
 
  -   if (!(trace_flags  TRACE_ITER_GRAPH_TIME)) {
  +   if (!(global_trace_flags()  TRACE_ITER_GRAPH_TIME)) {
  int 

Re: [PATCH] tracing: Allow instances to have independent trace flags/trace options.

2014-02-14 Thread Bharath Ravi
Hi Steven,

What are your thoughts on this patch?
--
Bharath Ravi |  rbhar...@google.com


On Thu, Jan 23, 2014 at 11:46 AM, Bharath Ravi  wrote:
> Hi Steven,
>
> This patch allows instances to have their own independent trace
> options (as opposed to the current globally shared trace options)
>
> Does this look like a reasonable change?
> Bharath Ravi |  rbhar...@google.com
>
>
> On Fri, Nov 22, 2013 at 10:51 AM, Bharath Ravi  wrote:
>> Currently, the trace options are global, and shared among all
>> instances. This change divides the set of trace options into global
>> options and instance specific options. Instance specific options may be
>> set independently by an instance without affecting either the global
>> tracer or other instances. Global options are viewable and modifiable
>> only from the global tracer, preventing tracers from modifying shared
>> flags.
>>
>> Currently, only the "overwrite" flag is a per-instance flag. Others may
>> be supported as and when instances are modified to support more tracers.
>>
>> As a side-effect, the global trace_flags variable is replaced by
>> instance specific trace_flags in trace_array. References to the old
>> global flags variable are replaced with accessors to the global_tracer's
>> trace_flags.
>>
>> Signed-off-by: Bharath Ravi 
>> ---
>>  kernel/trace/blktrace.c  |   5 +-
>>  kernel/trace/ftrace.c|   4 +-
>>  kernel/trace/trace.c | 131 
>> +--
>>  kernel/trace/trace.h |  51 +++---
>>  kernel/trace/trace_events.c  |   2 +-
>>  kernel/trace/trace_functions_graph.c |  10 +--
>>  kernel/trace/trace_irqsoff.c |   3 +-
>>  kernel/trace/trace_kdb.c |   6 +-
>>  kernel/trace/trace_output.c  |   8 +--
>>  kernel/trace/trace_printk.c  |   8 +--
>>  kernel/trace/trace_sched_wakeup.c|   3 +-
>>  kernel/trace/trace_syscalls.c|   2 +-
>>  12 files changed, 149 insertions(+), 84 deletions(-)
>>
>> diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
>> index b8b8560..0d71009 100644
>> --- a/kernel/trace/blktrace.c
>> +++ b/kernel/trace/blktrace.c
>> @@ -1350,7 +1350,7 @@ static enum print_line_t print_one_line(struct 
>> trace_iterator *iter,
>>
>> t  = te_blk_io_trace(iter->ent);
>> what   = t->action & ((1 << BLK_TC_SHIFT) - 1);
>> -   long_act   = !!(trace_flags & TRACE_ITER_VERBOSE);
>> +   long_act   = !!(global_trace_flags() & TRACE_ITER_VERBOSE);
>> log_action = classic ? _log_action_classic : _log_action;
>>
>> if (t->action == BLK_TN_MESSAGE) {
>> @@ -1411,12 +1411,15 @@ static enum print_line_t 
>> blk_tracer_print_line(struct trace_iterator *iter)
>>
>>  static int blk_tracer_set_flag(u32 old_flags, u32 bit, int set)
>>  {
>> +   unsigned long trace_flags = global_trace_flags();
>> /* don't output context-info for blk_classic output */
>> if (bit == TRACE_BLK_OPT_CLASSIC) {
>> if (set)
>> trace_flags &= ~TRACE_ITER_CONTEXT_INFO;
>> else
>> trace_flags |= TRACE_ITER_CONTEXT_INFO;
>> +
>> +   set_global_trace_flags(trace_flags);
>> }
>> return 0;
>>  }
>> diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
>> index 03cf44a..c356d5d 100644
>> --- a/kernel/trace/ftrace.c
>> +++ b/kernel/trace/ftrace.c
>> @@ -911,7 +911,7 @@ static void profile_graph_return(struct ftrace_graph_ret 
>> *trace)
>>
>> calltime = trace->rettime - trace->calltime;
>>
>> -   if (!(trace_flags & TRACE_ITER_GRAPH_TIME)) {
>> +   if (!(global_trace_flags() & TRACE_ITER_GRAPH_TIME)) {
>> int index;
>>
>> index = trace->depth;
>> @@ -4836,7 +4836,7 @@ ftrace_graph_probe_sched_switch(void *ignore,
>>  * Does the user want to count the time a function was asleep.
>>  * If so, do not update the time stamps.
>>  */
>> -   if (trace_flags & TRACE_ITER_SLEEP_TIME)
>> +   if (global_trace_flags() & TRACE_ITER_SLEEP_TIME)
>> return;
>>
>> timestamp = trace_clock_local();
>> diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
>> index 7974ba2..7add8bc 100644
>> --- a/kernel/trace/trace.c
>> +++ b/kernel/trace/trace.c
>> @@ -386,11 +386,16 @@ static inline void trace_access_lock_init(void)
>>
>>  #endif
>>
>> -/* trace_flags holds trace_options default values */
>> -unsigned long trace_flags = TRACE_ITER_PRINT_PARENT | TRACE_ITER_PRINTK |
>> -   TRACE_ITER_ANNOTATE | TRACE_ITER_CONTEXT_INFO | 
>> TRACE_ITER_SLEEP_TIME |
>> -   TRACE_ITER_GRAPH_TIME | TRACE_ITER_RECORD_CMD | TRACE_ITER_OVERWRITE 
>> |
>> -   TRACE_ITER_IRQ_INFO | TRACE_ITER_MARKERS | TRACE_ITER_FUNCTION;
>> +/* Sets default values for a tracer's trace_options */
>> +static inline void init_trace_flags(unsigned long *trace_flags)
>> +{
>> +   *trace_flags = 

Re: [PATCH] tracing: Allow instances to have independent trace flags/trace options.

2014-02-14 Thread Bharath Ravi
Hi Steven,

What are your thoughts on this patch?
--
Bharath Ravi |  rbhar...@google.com


On Thu, Jan 23, 2014 at 11:46 AM, Bharath Ravi rbhar...@google.com wrote:
 Hi Steven,

 This patch allows instances to have their own independent trace
 options (as opposed to the current globally shared trace options)

 Does this look like a reasonable change?
 Bharath Ravi |  rbhar...@google.com


 On Fri, Nov 22, 2013 at 10:51 AM, Bharath Ravi rbhar...@google.com wrote:
 Currently, the trace options are global, and shared among all
 instances. This change divides the set of trace options into global
 options and instance specific options. Instance specific options may be
 set independently by an instance without affecting either the global
 tracer or other instances. Global options are viewable and modifiable
 only from the global tracer, preventing tracers from modifying shared
 flags.

 Currently, only the overwrite flag is a per-instance flag. Others may
 be supported as and when instances are modified to support more tracers.

 As a side-effect, the global trace_flags variable is replaced by
 instance specific trace_flags in trace_array. References to the old
 global flags variable are replaced with accessors to the global_tracer's
 trace_flags.

 Signed-off-by: Bharath Ravi rbhar...@google.com
 ---
  kernel/trace/blktrace.c  |   5 +-
  kernel/trace/ftrace.c|   4 +-
  kernel/trace/trace.c | 131 
 +--
  kernel/trace/trace.h |  51 +++---
  kernel/trace/trace_events.c  |   2 +-
  kernel/trace/trace_functions_graph.c |  10 +--
  kernel/trace/trace_irqsoff.c |   3 +-
  kernel/trace/trace_kdb.c |   6 +-
  kernel/trace/trace_output.c  |   8 +--
  kernel/trace/trace_printk.c  |   8 +--
  kernel/trace/trace_sched_wakeup.c|   3 +-
  kernel/trace/trace_syscalls.c|   2 +-
  12 files changed, 149 insertions(+), 84 deletions(-)

 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
 index b8b8560..0d71009 100644
 --- a/kernel/trace/blktrace.c
 +++ b/kernel/trace/blktrace.c
 @@ -1350,7 +1350,7 @@ static enum print_line_t print_one_line(struct 
 trace_iterator *iter,

 t  = te_blk_io_trace(iter-ent);
 what   = t-action  ((1  BLK_TC_SHIFT) - 1);
 -   long_act   = !!(trace_flags  TRACE_ITER_VERBOSE);
 +   long_act   = !!(global_trace_flags()  TRACE_ITER_VERBOSE);
 log_action = classic ? blk_log_action_classic : blk_log_action;

 if (t-action == BLK_TN_MESSAGE) {
 @@ -1411,12 +1411,15 @@ static enum print_line_t 
 blk_tracer_print_line(struct trace_iterator *iter)

  static int blk_tracer_set_flag(u32 old_flags, u32 bit, int set)
  {
 +   unsigned long trace_flags = global_trace_flags();
 /* don't output context-info for blk_classic output */
 if (bit == TRACE_BLK_OPT_CLASSIC) {
 if (set)
 trace_flags = ~TRACE_ITER_CONTEXT_INFO;
 else
 trace_flags |= TRACE_ITER_CONTEXT_INFO;
 +
 +   set_global_trace_flags(trace_flags);
 }
 return 0;
  }
 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
 index 03cf44a..c356d5d 100644
 --- a/kernel/trace/ftrace.c
 +++ b/kernel/trace/ftrace.c
 @@ -911,7 +911,7 @@ static void profile_graph_return(struct ftrace_graph_ret 
 *trace)

 calltime = trace-rettime - trace-calltime;

 -   if (!(trace_flags  TRACE_ITER_GRAPH_TIME)) {
 +   if (!(global_trace_flags()  TRACE_ITER_GRAPH_TIME)) {
 int index;

 index = trace-depth;
 @@ -4836,7 +4836,7 @@ ftrace_graph_probe_sched_switch(void *ignore,
  * Does the user want to count the time a function was asleep.
  * If so, do not update the time stamps.
  */
 -   if (trace_flags  TRACE_ITER_SLEEP_TIME)
 +   if (global_trace_flags()  TRACE_ITER_SLEEP_TIME)
 return;

 timestamp = trace_clock_local();
 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
 index 7974ba2..7add8bc 100644
 --- a/kernel/trace/trace.c
 +++ b/kernel/trace/trace.c
 @@ -386,11 +386,16 @@ static inline void trace_access_lock_init(void)

  #endif

 -/* trace_flags holds trace_options default values */
 -unsigned long trace_flags = TRACE_ITER_PRINT_PARENT | TRACE_ITER_PRINTK |
 -   TRACE_ITER_ANNOTATE | TRACE_ITER_CONTEXT_INFO | 
 TRACE_ITER_SLEEP_TIME |
 -   TRACE_ITER_GRAPH_TIME | TRACE_ITER_RECORD_CMD | TRACE_ITER_OVERWRITE 
 |
 -   TRACE_ITER_IRQ_INFO | TRACE_ITER_MARKERS | TRACE_ITER_FUNCTION;
 +/* Sets default values for a tracer's trace_options */
 +static inline void init_trace_flags(unsigned long *trace_flags)
 +{
 +   *trace_flags = TRACE_ITER_PRINT_PARENT | TRACE_ITER_PRINTK |
 +   TRACE_ITER_ANNOTATE | TRACE_ITER_CONTEXT_INFO |
 +   TRACE_ITER_SLEEP_TIME | TRACE_ITER_GRAPH_TIME |
 +

Re: [PATCH] tracing: Allow instances to have independent trace flags/trace options.

2014-01-23 Thread Bharath Ravi
Hi Steven,

This patch allows instances to have their own independent trace
options (as opposed to the current globally shared trace options)

Does this look like a reasonable change?
Bharath Ravi |  rbhar...@google.com


On Fri, Nov 22, 2013 at 10:51 AM, Bharath Ravi  wrote:
> Currently, the trace options are global, and shared among all
> instances. This change divides the set of trace options into global
> options and instance specific options. Instance specific options may be
> set independently by an instance without affecting either the global
> tracer or other instances. Global options are viewable and modifiable
> only from the global tracer, preventing tracers from modifying shared
> flags.
>
> Currently, only the "overwrite" flag is a per-instance flag. Others may
> be supported as and when instances are modified to support more tracers.
>
> As a side-effect, the global trace_flags variable is replaced by
> instance specific trace_flags in trace_array. References to the old
> global flags variable are replaced with accessors to the global_tracer's
> trace_flags.
>
> Signed-off-by: Bharath Ravi 
> ---
>  kernel/trace/blktrace.c  |   5 +-
>  kernel/trace/ftrace.c|   4 +-
>  kernel/trace/trace.c | 131 
> +--
>  kernel/trace/trace.h |  51 +++---
>  kernel/trace/trace_events.c  |   2 +-
>  kernel/trace/trace_functions_graph.c |  10 +--
>  kernel/trace/trace_irqsoff.c |   3 +-
>  kernel/trace/trace_kdb.c |   6 +-
>  kernel/trace/trace_output.c  |   8 +--
>  kernel/trace/trace_printk.c  |   8 +--
>  kernel/trace/trace_sched_wakeup.c|   3 +-
>  kernel/trace/trace_syscalls.c|   2 +-
>  12 files changed, 149 insertions(+), 84 deletions(-)
>
> diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
> index b8b8560..0d71009 100644
> --- a/kernel/trace/blktrace.c
> +++ b/kernel/trace/blktrace.c
> @@ -1350,7 +1350,7 @@ static enum print_line_t print_one_line(struct 
> trace_iterator *iter,
>
> t  = te_blk_io_trace(iter->ent);
> what   = t->action & ((1 << BLK_TC_SHIFT) - 1);
> -   long_act   = !!(trace_flags & TRACE_ITER_VERBOSE);
> +   long_act   = !!(global_trace_flags() & TRACE_ITER_VERBOSE);
> log_action = classic ? _log_action_classic : _log_action;
>
> if (t->action == BLK_TN_MESSAGE) {
> @@ -1411,12 +1411,15 @@ static enum print_line_t blk_tracer_print_line(struct 
> trace_iterator *iter)
>
>  static int blk_tracer_set_flag(u32 old_flags, u32 bit, int set)
>  {
> +   unsigned long trace_flags = global_trace_flags();
> /* don't output context-info for blk_classic output */
> if (bit == TRACE_BLK_OPT_CLASSIC) {
> if (set)
> trace_flags &= ~TRACE_ITER_CONTEXT_INFO;
> else
> trace_flags |= TRACE_ITER_CONTEXT_INFO;
> +
> +   set_global_trace_flags(trace_flags);
> }
> return 0;
>  }
> diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
> index 03cf44a..c356d5d 100644
> --- a/kernel/trace/ftrace.c
> +++ b/kernel/trace/ftrace.c
> @@ -911,7 +911,7 @@ static void profile_graph_return(struct ftrace_graph_ret 
> *trace)
>
> calltime = trace->rettime - trace->calltime;
>
> -   if (!(trace_flags & TRACE_ITER_GRAPH_TIME)) {
> +   if (!(global_trace_flags() & TRACE_ITER_GRAPH_TIME)) {
> int index;
>
> index = trace->depth;
> @@ -4836,7 +4836,7 @@ ftrace_graph_probe_sched_switch(void *ignore,
>  * Does the user want to count the time a function was asleep.
>  * If so, do not update the time stamps.
>  */
> -   if (trace_flags & TRACE_ITER_SLEEP_TIME)
> +   if (global_trace_flags() & TRACE_ITER_SLEEP_TIME)
> return;
>
> timestamp = trace_clock_local();
> diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
> index 7974ba2..7add8bc 100644
> --- a/kernel/trace/trace.c
> +++ b/kernel/trace/trace.c
> @@ -386,11 +386,16 @@ static inline void trace_access_lock_init(void)
>
>  #endif
>
> -/* trace_flags holds trace_options default values */
> -unsigned long trace_flags = TRACE_ITER_PRINT_PARENT | TRACE_ITER_PRINTK |
> -   TRACE_ITER_ANNOTATE | TRACE_ITER_CONTEXT_INFO | TRACE_ITER_SLEEP_TIME 
> |
> -   TRACE_ITER_GRAPH_TIME | TRACE_ITER_RECORD_CMD | TRACE_ITER_OVERWRITE |
> -   TRACE_ITER_IRQ_INFO | TRACE_ITER_MARKERS | TRACE_ITER_FUNCTION;
> +/* Sets default values for a tracer's trace_options */
> +static inline void init_trace_flags(unsigned long *trace_flags)
> +{
> +   *trace_flags = TRACE_ITER_PRINT_PARENT | TRACE_ITER_PRINTK |
> +   TRACE_ITER_ANNOTATE | TRACE_ITER_CONTEXT_INFO |
> +   TRACE_ITER_SLEEP_TIME | TRACE_ITER_GRAPH_TIME |
> +   TRACE_ITER_RECORD_CMD | TRACE_ITER_IRQ_INFO |
> +   TRACE_ITER_MARKERS 

Re: [PATCH] tracing: Allow instances to have independent trace flags/trace options.

2014-01-23 Thread Bharath Ravi
Hi Steven,

This patch allows instances to have their own independent trace
options (as opposed to the current globally shared trace options)

Does this look like a reasonable change?
Bharath Ravi |  rbhar...@google.com


On Fri, Nov 22, 2013 at 10:51 AM, Bharath Ravi rbhar...@google.com wrote:
 Currently, the trace options are global, and shared among all
 instances. This change divides the set of trace options into global
 options and instance specific options. Instance specific options may be
 set independently by an instance without affecting either the global
 tracer or other instances. Global options are viewable and modifiable
 only from the global tracer, preventing tracers from modifying shared
 flags.

 Currently, only the overwrite flag is a per-instance flag. Others may
 be supported as and when instances are modified to support more tracers.

 As a side-effect, the global trace_flags variable is replaced by
 instance specific trace_flags in trace_array. References to the old
 global flags variable are replaced with accessors to the global_tracer's
 trace_flags.

 Signed-off-by: Bharath Ravi rbhar...@google.com
 ---
  kernel/trace/blktrace.c  |   5 +-
  kernel/trace/ftrace.c|   4 +-
  kernel/trace/trace.c | 131 
 +--
  kernel/trace/trace.h |  51 +++---
  kernel/trace/trace_events.c  |   2 +-
  kernel/trace/trace_functions_graph.c |  10 +--
  kernel/trace/trace_irqsoff.c |   3 +-
  kernel/trace/trace_kdb.c |   6 +-
  kernel/trace/trace_output.c  |   8 +--
  kernel/trace/trace_printk.c  |   8 +--
  kernel/trace/trace_sched_wakeup.c|   3 +-
  kernel/trace/trace_syscalls.c|   2 +-
  12 files changed, 149 insertions(+), 84 deletions(-)

 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
 index b8b8560..0d71009 100644
 --- a/kernel/trace/blktrace.c
 +++ b/kernel/trace/blktrace.c
 @@ -1350,7 +1350,7 @@ static enum print_line_t print_one_line(struct 
 trace_iterator *iter,

 t  = te_blk_io_trace(iter-ent);
 what   = t-action  ((1  BLK_TC_SHIFT) - 1);
 -   long_act   = !!(trace_flags  TRACE_ITER_VERBOSE);
 +   long_act   = !!(global_trace_flags()  TRACE_ITER_VERBOSE);
 log_action = classic ? blk_log_action_classic : blk_log_action;

 if (t-action == BLK_TN_MESSAGE) {
 @@ -1411,12 +1411,15 @@ static enum print_line_t blk_tracer_print_line(struct 
 trace_iterator *iter)

  static int blk_tracer_set_flag(u32 old_flags, u32 bit, int set)
  {
 +   unsigned long trace_flags = global_trace_flags();
 /* don't output context-info for blk_classic output */
 if (bit == TRACE_BLK_OPT_CLASSIC) {
 if (set)
 trace_flags = ~TRACE_ITER_CONTEXT_INFO;
 else
 trace_flags |= TRACE_ITER_CONTEXT_INFO;
 +
 +   set_global_trace_flags(trace_flags);
 }
 return 0;
  }
 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
 index 03cf44a..c356d5d 100644
 --- a/kernel/trace/ftrace.c
 +++ b/kernel/trace/ftrace.c
 @@ -911,7 +911,7 @@ static void profile_graph_return(struct ftrace_graph_ret 
 *trace)

 calltime = trace-rettime - trace-calltime;

 -   if (!(trace_flags  TRACE_ITER_GRAPH_TIME)) {
 +   if (!(global_trace_flags()  TRACE_ITER_GRAPH_TIME)) {
 int index;

 index = trace-depth;
 @@ -4836,7 +4836,7 @@ ftrace_graph_probe_sched_switch(void *ignore,
  * Does the user want to count the time a function was asleep.
  * If so, do not update the time stamps.
  */
 -   if (trace_flags  TRACE_ITER_SLEEP_TIME)
 +   if (global_trace_flags()  TRACE_ITER_SLEEP_TIME)
 return;

 timestamp = trace_clock_local();
 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
 index 7974ba2..7add8bc 100644
 --- a/kernel/trace/trace.c
 +++ b/kernel/trace/trace.c
 @@ -386,11 +386,16 @@ static inline void trace_access_lock_init(void)

  #endif

 -/* trace_flags holds trace_options default values */
 -unsigned long trace_flags = TRACE_ITER_PRINT_PARENT | TRACE_ITER_PRINTK |
 -   TRACE_ITER_ANNOTATE | TRACE_ITER_CONTEXT_INFO | TRACE_ITER_SLEEP_TIME 
 |
 -   TRACE_ITER_GRAPH_TIME | TRACE_ITER_RECORD_CMD | TRACE_ITER_OVERWRITE |
 -   TRACE_ITER_IRQ_INFO | TRACE_ITER_MARKERS | TRACE_ITER_FUNCTION;
 +/* Sets default values for a tracer's trace_options */
 +static inline void init_trace_flags(unsigned long *trace_flags)
 +{
 +   *trace_flags = TRACE_ITER_PRINT_PARENT | TRACE_ITER_PRINTK |
 +   TRACE_ITER_ANNOTATE | TRACE_ITER_CONTEXT_INFO |
 +   TRACE_ITER_SLEEP_TIME | TRACE_ITER_GRAPH_TIME |
 +   TRACE_ITER_RECORD_CMD | TRACE_ITER_IRQ_INFO |
 +   TRACE_ITER_MARKERS | TRACE_ITER_FUNCTION |
 +   TRACE_ITER_OVERWRITE;
 +}

  static void