From: Peter Zijlstra <a.p.zijlstra@chello.nl>
To: Stephane Eranian <eranian@google.com>, Ingo Molnar <mingo@elte.hu>
Cc: linux-kernel@vger.kernel.org, Peter Zijlstra <a.p.zijlstra@chello.nl>
Subject: [PATCH 5/7] perf, x86: Less disastrous PEBS/BTS buffer allocation failure
Date: Tue, 19 Oct 2010 15:43:01 +0200 [thread overview]
Message-ID: <20101019134808.404167262@chello.nl> (raw)
In-Reply-To: 20101019134256.087045503@chello.nl
[-- Attachment #1: perf-perf-event-improve-ds-3.patch --]
[-- Type: text/plain, Size: 4086 bytes --]
Currently PEBS/BTS buffers are allocated when we instantiate the first
event, when this fails everything fails.
This is a problem because esp. BTS tries to allocate a rather large
buffer (64K), which can easily fail.
This patches changes the logic such that when either buffer allocation
fails, we simply don't allow events that would use these facilities,
but continue functioning for all other events.
This logic comes from a much larger patch proposed by Stephane.
Suggested-by: Stephane Eranian <eranian@google.com>
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
LKML-Reference: <new-submission>
---
arch/x86/kernel/cpu/perf_event.c | 5 +-
arch/x86/kernel/cpu/perf_event_intel_ds.c | 58 ++++++++++++++++++++++--------
2 files changed, 47 insertions(+), 16 deletions(-)
Index: linux-2.6/arch/x86/kernel/cpu/perf_event.c
===================================================================
--- linux-2.6.orig/arch/x86/kernel/cpu/perf_event.c
+++ linux-2.6/arch/x86/kernel/cpu/perf_event.c
@@ -238,6 +238,7 @@ struct x86_pmu {
* Intel DebugStore bits
*/
int bts, pebs;
+ int bts_active, pebs_active;
int pebs_record_size;
void (*drain_pebs)(struct pt_regs *regs);
struct event_constraint *pebs_constraints;
@@ -478,7 +479,7 @@ static int x86_setup_perfctr(struct perf
if ((attr->config == PERF_COUNT_HW_BRANCH_INSTRUCTIONS) &&
(hwc->sample_period == 1)) {
/* BTS is not supported by this architecture. */
- if (!x86_pmu.bts)
+ if (!x86_pmu.bts_active)
return -EOPNOTSUPP;
/* BTS is currently only allowed for user-mode. */
@@ -497,7 +498,7 @@ static int x86_pmu_hw_config(struct perf
int precise = 0;
/* Support for constant skid */
- if (x86_pmu.pebs) {
+ if (x86_pmu.pebs_active) {
precise++;
/* Support for IP fixup */
Index: linux-2.6/arch/x86/kernel/cpu/perf_event_intel_ds.c
===================================================================
--- linux-2.6.orig/arch/x86/kernel/cpu/perf_event_intel_ds.c
+++ linux-2.6/arch/x86/kernel/cpu/perf_event_intel_ds.c
@@ -193,36 +193,66 @@ static void release_ds_buffers(void)
static int reserve_ds_buffers(void)
{
- int cpu, err = 0;
+ int bts_err = 0, pebs_err = 0;
+ int cpu;
+
+ x86_pmu.bts_active = 0;
+ x86_pmu.pebs_active = 0;
if (!x86_pmu.bts && !x86_pmu.pebs)
return 0;
+ if (!x86_pmu.bts)
+ bts_err = 1;
+
+ if (!x86_pmu.pebs)
+ pebs_err = 1;
+
get_online_cpus();
for_each_possible_cpu(cpu) {
- if (alloc_ds_buffer(cpu))
- break;
+ if (alloc_ds_buffer(cpu)) {
+ bts_err = 1;
+ pebs_err = 1;
+ }
- if (alloc_bts_buffer(cpu))
- break;
+ if (!bts_err && alloc_bts_buffer(cpu))
+ bts_err = 1;
+
+ if (!pebs_err && alloc_pebs_buffer(cpu))
+ pebs_err = 1;
- if (alloc_pebs_buffer(cpu))
+ if (bts_err && pebs_err)
break;
+ }
+
+ if (bts_err) {
+ for_each_possible_cpu(cpu)
+ release_bts_buffer(cpu);
+ }
- err = 0;
+ if (pebs_err) {
+ for_each_possible_cpu(cpu)
+ release_pebs_buffer(cpu);
}
- if (err)
- release_ds_buffers();
- else {
+ if (bts_err && pebs_err) {
+ for_each_possible_cpu(cpu)
+ release_ds_buffer(cpu);
+ } else {
+ if (x86_pmu.bts && !bts_err)
+ x86_pmu.bts_active = 1;
+
+ if (x86_pmu.pebs && !pebs_err)
+ x86_pmu.pebs_active = 1;
+
for_each_online_cpu(cpu)
init_debug_store_on_cpu(cpu);
}
put_online_cpus();
- return err;
+ return 0;
}
/*
@@ -287,7 +317,7 @@ static int intel_pmu_drain_bts_buffer(vo
if (!event)
return 0;
- if (!ds)
+ if (!x86_pmu.bts_active)
return 0;
at = (struct bts_record *)(unsigned long)ds->bts_buffer_base;
@@ -557,7 +587,7 @@ static void intel_pmu_drain_pebs_core(st
struct pebs_record_core *at, *top;
int n;
- if (!ds || !x86_pmu.pebs)
+ if (!x86_pmu.pebs_active)
return;
at = (struct pebs_record_core *)(unsigned long)ds->pebs_buffer_base;
@@ -599,7 +629,7 @@ static void intel_pmu_drain_pebs_nhm(str
u64 status = 0;
int bit, n;
- if (!ds || !x86_pmu.pebs)
+ if (!x86_pmu.pebs_active)
return;
at = (struct pebs_record_nhm *)(unsigned long)ds->pebs_buffer_base;
next prev parent reply other threads:[~2010-10-19 13:56 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-19 13:42 [PATCH 0/7] perf,x86: PEBS/BTS buffer allocation changes Peter Zijlstra
2010-10-19 13:42 ` [PATCH 1/7] perf, x86: Extract PEBS/BTS buffer free routines Peter Zijlstra
2010-10-22 13:02 ` [tip:perf/urgent] " tip-bot for Peter Zijlstra
2010-10-19 13:42 ` [PATCH 2/7] perf, x86: Extract PEBS/BTS allocation functions Peter Zijlstra
2010-10-22 13:02 ` [tip:perf/urgent] " tip-bot for Peter Zijlstra
2010-10-19 13:42 ` [PATCH 3/7] perf, x86: Extract DS alloc/free functions Peter Zijlstra
2010-10-22 13:03 ` [tip:perf/urgent] " tip-bot for Peter Zijlstra
2010-10-19 13:43 ` [PATCH 4/7] perf, x86: Fixup the precise_ip computation Peter Zijlstra
2010-10-22 13:03 ` [tip:perf/urgent] " tip-bot for Peter Zijlstra
2010-10-22 13:04 ` [tip:perf/urgent] perf, x86: Less disastrous PEBS/BTS buffer allocation failure tip-bot for Peter Zijlstra
2010-10-19 13:43 ` Peter Zijlstra [this message]
2010-10-19 13:43 ` [PATCH 6/7] perf, x86: Clean up reserve_ds_buffers() signature Peter Zijlstra
2010-10-22 13:04 ` [tip:perf/urgent] " tip-bot for Peter Zijlstra
2010-10-19 13:43 ` [PATCH 7/7] perf, x86: Use NUMA aware allocations for PEBS/BTS/DS allocations Peter Zijlstra
2010-10-22 13:04 ` [tip:perf/urgent] " tip-bot for Peter Zijlstra
2010-10-21 11:35 ` [PATCH 0/7] perf,x86: PEBS/BTS buffer allocation changes Peter Zijlstra
2010-10-21 11:45 ` Stephane Eranian
2010-10-21 14:30 ` Stephane Eranian
2010-10-21 14:34 ` Peter Zijlstra
2010-10-21 14:35 ` 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=20101019134808.404167262@chello.nl \
--to=a.p.zijlstra@chello.nl \
--cc=eranian@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
/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