public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>, LKML <linux-kernel@vger.kernel.org>,
	Arnaldo Carvalho de Melo <acme@redhat.com>,
	Paul Mackerras <paulus@samba.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	Masami Hiramatsu <mhiramat@redhat.com>,
	Jason Baron <jbaron@redhat.com>
Subject: Re: [PATCH 1/4] tracing: Use the perf recursion protection from trace event
Date: Sun, 22 Nov 2009 12:00:14 +0100	[thread overview]
Message-ID: <1258887614.28730.353.camel@laptop> (raw)
In-Reply-To: <1258863695-10464-1-git-send-email-fweisbec@gmail.com>

On Sun, 2009-11-22 at 05:21 +0100, Frederic Weisbecker wrote:
> diff --git a/kernel/perf_event.c b/kernel/perf_event.c
> index 718fa93..aba8227 100644
> --- a/kernel/perf_event.c
> +++ b/kernel/perf_event.c
> @@ -3880,34 +3880,42 @@ static void perf_swevent_ctx_event(struct perf_event_context *ctx,
>         }
>  }
>  
> -static int *perf_swevent_recursion_context(struct perf_cpu_context *cpuctx)
> +/*
> + * Must be called with preemption disabled
> + */
> +int perf_swevent_get_recursion_context(int **recursion)
>  {
> +       struct perf_cpu_context *cpuctx = &__get_cpu_var(perf_cpu_context);
> +
>         if (in_nmi())
> -               return &cpuctx->recursion[3];
> +               *recursion = &cpuctx->recursion[3];
> +       else if (in_irq())
> +               *recursion = &cpuctx->recursion[2];
> +       else if (in_softirq())
> +               *recursion = &cpuctx->recursion[1];
> +       else
> +               *recursion = &cpuctx->recursion[0];
>  
> -       if (in_irq())
> -               return &cpuctx->recursion[2];
> +       if (**recursion)
> +               return -1;
>  
> -       if (in_softirq())
> -               return &cpuctx->recursion[1];
> +       (**recursion)++;
>  
> -       return &cpuctx->recursion[0];
> +       return 0;
>  }

You lost the barrier();

> -static void do_perf_sw_event(enum perf_type_id type, u32 event_id,
> -                                   u64 nr, int nmi,
> -                                   struct perf_sample_data *data,
> -                                   struct pt_regs *regs)
> +void perf_swevent_put_recursion_context(int *recursion)
>  {
> -       struct perf_cpu_context *cpuctx = &get_cpu_var(perf_cpu_context);
> -       int *recursion = perf_swevent_recursion_context(cpuctx);
> -       struct perf_event_context *ctx;
> -
> -       if (*recursion)
> -               goto out;
> +       (*recursion)--;
> +}

And here as well.

Furthermore, its much cleaner if you simply use
get_cpu_var(perf_cpu_context) in get_recursion_context, and
put_cpu_var() in put_recursion_context.

That way you put the preempt_disable where it belongs, instead of:

> +static void do_perf_sw_event(enum perf_type_id type, u32 event_id,
> +                                   u64 nr, int nmi,
> +                                   struct perf_sample_data *data,
> +                                   struct pt_regs *regs)
> +{
> +       int *recursion;
> +
> +       preempt_disable();
> +
> +       if (perf_swevent_get_recursion_context(&recursion))
> +               goto out;
> +
> +       __do_perf_sw_event(type, event_id, nr, nmi, data, regs);
>  
> +       perf_swevent_put_recursion_context(recursion);
>  out:
> -       put_cpu_var(perf_cpu_context);
> +       preempt_enable();
>  } 

mucking about like here, also it cleans up the code in that you don't
have to drag that recursion variable around like so.


  parent reply	other threads:[~2009-11-22 11:00 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-22  4:21 [PATCH 1/4] tracing: Use the perf recursion protection from trace event Frederic Weisbecker
2009-11-22  4:21 ` [PATCH 2/4] tracing: Forget about the nmi buffer from syscall events Frederic Weisbecker
2009-11-22  8:43   ` [tip:perf/core] tracing: Forget about the NMI buffer for " tip-bot for Frederic Weisbecker
2009-11-22  4:21 ` [PATCH 3/4] hw-breakpoints: Remove x86 specific headers from core file Frederic Weisbecker
2009-11-22  8:43   ` [tip:perf/core] " tip-bot for Frederic Weisbecker
2009-11-22  4:21 ` [PATCH 4/4] hw-breakpoints: Separate the kernel part from breakpoint headers Frederic Weisbecker
2009-11-22  8:43   ` [tip:perf/core] " tip-bot for Frederic Weisbecker
2009-11-22  4:26 ` [PATCH 1/4 v2] tracing: Use the perf recursion protection from trace event Frederic Weisbecker
2009-11-22  8:42   ` [tip:perf/core] " tip-bot for Frederic Weisbecker
2009-11-22 11:24   ` [tip:perf/core] perf_events: Fix modular build tip-bot for Ingo Molnar
2009-11-22 11:00 ` Peter Zijlstra [this message]
2009-11-22 11:22   ` [PATCH 1/4] tracing: Use the perf recursion protection from trace event Ingo Molnar
2009-11-22 11:24     ` Peter Zijlstra
2009-11-22 16:37   ` Frederic Weisbecker
2009-11-22 16:50     ` Peter Zijlstra

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=1258887614.28730.353.camel@laptop \
    --to=peterz@infradead.org \
    --cc=acme@redhat.com \
    --cc=fweisbec@gmail.com \
    --cc=jbaron@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhiramat@redhat.com \
    --cc=mingo@elte.hu \
    --cc=paulus@samba.org \
    --cc=rostedt@goodmis.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