public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Stephane Eranian <eranian@google.com>
Cc: linux-kernel@vger.kernel.org, mingo@elte.hu, acme@redhat.com,
	ming.m.lin@intel.com, andi@firstfloor.org,
	robert.richter@amd.com, ravitillo@lbl.gov, will.deacon@arm.com,
	paulus@samba.org, benh@kernel.crashing.org, rth@twiddle.net,
	ralf@linux-mips.org, davem@davemloft.net, lethal@linux-sh.org
Subject: Re: [PATCH 09/12] perf_events: add hook to flush branch_stack on context switch (v2)
Date: Fri, 09 Dec 2011 10:00:18 +0100	[thread overview]
Message-ID: <1323421218.17673.37.camel@twins> (raw)
In-Reply-To: <CABPqkBTw2c=EXRzcnfmR9RjYXNcRVkOB1BzmsF==rd=mp-QXgA@mail.gmail.com>

On Thu, 2011-12-08 at 14:06 -0800, Stephane Eranian wrote:
> > That's not regardless of the TOS. If the TOS was a full u64 you wouldn't
> > need the TID (which would be good, since the hardware has no such
> > concept).
> >
> Maybe I missed the trick but I don't quite see how a 64-bit TOS would
> solve the TID
> problem. It's not about the wraparound issue, i.e., not like the
> sampling buffer indexes.
> Could you describe the trick again? 

LBR 0
.
.
.        <-- TOS % n
.
LBR n-1


So the LBR is an array of n entries which is written to in a cyclic
fashion. The Top-Of-Stack or TOS indicates the last written entry and we
can read n entries backwards from there.

Something like:

  tos = rdmsr(lbr_tos);
  for (i = 0; i < n; i++) {
	idx = (tos - i) % n;

	from = rdmsr(lbr_from + idx);
	to   = rdmsr(lbr_to   + idx);
  }

Now the hardware keeps (TOS % n) by limiting the bits in the counter (n
= 2^m etc..), if it wouldn't do that, we could sample the TOS on ctxsw
and modify the read to:

  tos = rdmsr(lbr_tos)
  for (i = 0; i < n && (tos - i) > ctxsw_tos; i++) {
	idx = (tos - i) % n;

	...
  }

This would ensure we never read back past the context-switch. But we
need the extra bits for this to work, since with the current limited
(TOS % n) bits we get into trouble as soon as the ctxsw was more than n
branches ago (which is something very likely).

[ With 16 bits we'd get into trouble when the ctxsw was 65536 branch
ago, which is still quite possible, at 32 bits we'd need 4G branches,
which is rather unlikely, with 64 bits the sun will have died or so.. ]

Also note we can make this extra condition conditional on the event
being a task event, so that the cpu events always consume all n entries.



  reply	other threads:[~2011-12-09  9:01 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-14 12:37 [PATCH 00/12] perf_events: add support for sampling taken branches (v2) Stephane Eranian
2011-10-14 12:37 ` [PATCH 01/12] perf_events: add generic taken branch sampling support (v2) Stephane Eranian
2011-12-05 21:06   ` Peter Zijlstra
2011-12-06 19:42     ` Stephane Eranian
2011-12-05 22:14   ` Peter Zijlstra
2011-12-06 19:27     ` Stephane Eranian
2011-10-14 12:37 ` [PATCH 02/12] perf_events: add Intel LBR MSR definitions (v2) Stephane Eranian
2011-10-14 12:37 ` [PATCH 03/12] perf_events: add Intel X86 LBR sharing logic (v2) Stephane Eranian
2011-10-14 12:37 ` [PATCH 04/12] perf_events: sync branch stack sampling with X86 precise_sampling (v2) Stephane Eranian
2011-10-14 12:37 ` [PATCH 05/12] perf_events: add LBR mappings for PERF_SAMPLE_BRANCH filters (v2) Stephane Eranian
2011-12-05 22:35   ` Peter Zijlstra
2011-12-07  4:22     ` Stephane Eranian
2011-10-14 12:37 ` [PATCH 06/12] perf_events: implement PERF_SAMPLE_BRANCH for Intel X86 (v2) Stephane Eranian
2011-10-14 12:37 ` [PATCH 07/12] perf_events: add LBR software filter support " Stephane Eranian
2011-12-05 22:29   ` Peter Zijlstra
2011-10-14 12:37 ` [PATCH 08/12] perf_events: disable PERF_SAMPLE_BRANCH_* when not supported (v2) Stephane Eranian
2011-10-14 12:37 ` [PATCH 09/12] perf_events: add hook to flush branch_stack on context switch (v2) Stephane Eranian
2011-12-05 21:10   ` Peter Zijlstra
2011-12-05 21:37   ` Peter Zijlstra
2011-12-07 18:25     ` Stephane Eranian
2011-12-08 10:49       ` Peter Zijlstra
2011-12-08 18:04         ` Stephane Eranian
2011-12-08 18:13           ` Peter Zijlstra
2011-12-08 22:06             ` Stephane Eranian
2011-12-09  9:00               ` Peter Zijlstra [this message]
2011-10-14 12:37 ` [PATCH 10/12] perf: add code to support PERF_SAMPLE_BRANCH_STACK (v2) Stephane Eranian
2011-10-14 12:37 ` [PATCH 11/12] perf: add support for sampling taken branch to perf record (v2) Stephane Eranian
2011-10-14 12:37 ` [PATCH 12/12] perf: add support for taken branch sampling to perf report (v2) Stephane Eranian
2011-12-04 20:11 ` [PATCH 00/12] perf_events: add support for sampling taken branches (v2) Stephane Eranian
2011-12-05 15:27   ` Peter Zijlstra
2011-12-05 22:39 ` Peter Zijlstra
2011-12-06  9:49   ` Will Deacon
2011-12-06 11:03     ` Peter Zijlstra
2011-12-06 19:14       ` Stephane Eranian
2011-12-06 19:20         ` Peter Zijlstra
2011-12-06 19:22           ` Stephane Eranian

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=1323421218.17673.37.camel@twins \
    --to=peterz@infradead.org \
    --cc=acme@redhat.com \
    --cc=andi@firstfloor.org \
    --cc=benh@kernel.crashing.org \
    --cc=davem@davemloft.net \
    --cc=eranian@google.com \
    --cc=lethal@linux-sh.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ming.m.lin@intel.com \
    --cc=mingo@elte.hu \
    --cc=paulus@samba.org \
    --cc=ralf@linux-mips.org \
    --cc=ravitillo@lbl.gov \
    --cc=robert.richter@amd.com \
    --cc=rth@twiddle.net \
    --cc=will.deacon@arm.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox