All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@kernel.org>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>,
	Adrian Hunter <adrian.hunter@intel.com>,
	linux-kernel@vger.kernel.org, "Kleen,
	Andi" <andi.kleen@intel.com>,
	"Shishkin, Alexander" <alexander.shishkin@intel.com>
Subject: Re: PERF_EVENT_IOC_SET_OUTPUT
Date: Wed, 2 Oct 2013 14:29:01 +0200	[thread overview]
Message-ID: <20131002122900.GA27811@gmail.com> (raw)
In-Reply-To: <20131002112730.GQ3081@twins.programming.kicks-ass.net>


* Peter Zijlstra <peterz@infradead.org> wrote:

> On Wed, Oct 02, 2013 at 12:29:56PM +0200, Frederic Weisbecker wrote:
> > On Wed, Oct 02, 2013 at 12:03:50PM +0200, Peter Zijlstra wrote:
> > > On Tue, Oct 01, 2013 at 10:11:56PM +0300, Adrian Hunter wrote:
> > > > Hi
> > > > 
> > > > It does not seem possible to use set-output between
> > > > task contexts of different types (e.g. a software event
> > > > to a hardware event)
> > > > 
> > > > If you look at perf_event_set_output():
> > > > 
> > > >           /*
> > > >            * If its not a per-cpu rb, it must be the same task.
> > > >            */
> > > >           if (output_event->cpu == -1 && output_event->ctx != event->ctx)
> > > >                   goto out;
> > > > 
> > > > ctx (perf_event_context) won't be the same for events
> > > > of different types.  Is this restriction necessary?
> > > 
> > > Hmm.. so last night I wrote me a big reply saying we couldn't do it;
> > > then this morning I reconsidered and thing that something like:
> > > 
> > >   output_event->ctx->task != event->ctx->task
> > > 
> > > should actually work.
> > > 
> > > The reason it should be OK I think is because perf_mmap() will refuse to
> > > create a buffer for inherited events that have ->cpu == -1.
> > > 
> > > My initial response was going to say that it wouldn't be possible
> > > because __perf_event_task_sched_out() could 'break' one ctx while still
> > > swapping the other, at which point the buffer would have to service two
> > > different tasks, potentially from different CPUs and with the buffers
> > > not actually being SMP safe that's a problem.
> > 
> > I don't get what you mean with breaking or swapping a ctx. But I can 
> > confirm that perf_mmap() won't allow a buffer to be remotely accessed 
> > from another CPU. Now there may be other issues than locality which 
> > I'm missing :)
> 
> The way we 'optimize' context switches between tasks with identical 
> contexts is to simply swap the context and leave the hardware alone.

Btw., this does not seem to be working very well when the perf context is 
inherited:

Baseline kernel with no perf context:

  aldebaran:~> taskset 1 perf stat --null perf bench sched pipe
  # Running sched/pipe benchmark...
  # Executed 1000000 pipe operations between two tasks

     Total time: 5.024 [sec]

       5.024951 usecs/op
         199006 ops/sec

with inherited perf contexts:

  aldebaran:~> taskset 1 perf stat perf bench sched pipe
  # Running sched/pipe benchmark...
  # Executed 1000000 pipe operations between two tasks

     Total time: 17.869 [sec]

      17.869061 usecs/op
          55962 ops/sec

+12.8 usecs of perf switching fat per context switch, on a non-debug 
kernel on a 2.8GHz CPU :-/

We should declare a hard feature stop until that is improved.

Thanks,

	Ingo

  parent reply	other threads:[~2013-10-02 12:29 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-01 19:11 PERF_EVENT_IOC_SET_OUTPUT Adrian Hunter
2013-10-02 10:03 ` PERF_EVENT_IOC_SET_OUTPUT Peter Zijlstra
2013-10-02 10:29   ` PERF_EVENT_IOC_SET_OUTPUT Frederic Weisbecker
2013-10-02 11:27     ` PERF_EVENT_IOC_SET_OUTPUT Peter Zijlstra
2013-10-02 11:43       ` PERF_EVENT_IOC_SET_OUTPUT Frederic Weisbecker
2013-10-02 12:29       ` Ingo Molnar [this message]
2013-10-02 12:40         ` PERF_EVENT_IOC_SET_OUTPUT Peter Zijlstra
2013-10-03  6:43           ` PERF_EVENT_IOC_SET_OUTPUT Ingo Molnar
2013-10-07 16:42             ` PERF_EVENT_IOC_SET_OUTPUT Peter Zijlstra
2013-10-29 14:08               ` [tip:perf/core] perf: Fix the perf context switch optimization tip-bot for 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=20131002122900.GA27811@gmail.com \
    --to=mingo@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@intel.com \
    --cc=andi.kleen@intel.com \
    --cc=fweisbec@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --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 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.