2009-09-02 14:06:20

by Metzger, Markus T

[permalink] [raw]
Subject: [patch 1/3] x86, perf_counter, bts: fail if BTS is not available

---------------------------------------------------------------------
Intel GmbH
Dornacher Strasse 1
85622 Feldkirchen/Muenchen Germany
Sitz der Gesellschaft: Feldkirchen bei Muenchen
Geschaeftsfuehrer: Douglas Lusk, Peter Gleissner, Hannes Schwaderer
Registergericht: Muenchen HRB 47456 Ust.-IdNr.
VAT Registration No.: DE129385895
Citibank Frankfurt (BLZ 502 109 00) 600119052

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.


Attachments:
tip.master.perf_counter.fail_when_not_available.patch (1.81 kB)
(No filename) (642.00 B)
Download all attachments

2009-09-04 07:58:52

by Metzger, Markus T

[permalink] [raw]
Subject: [tip:perfcounters/core] x86, perf_counter, bts: Fail if BTS is not available

Commit-ID: 747b50aaf728987732e6ff3ba10aba4acc4e0277
Gitweb: http://git.kernel.org/tip/747b50aaf728987732e6ff3ba10aba4acc4e0277
Author: [email protected] <[email protected]>
AuthorDate: Wed, 2 Sep 2009 16:04:46 +0200
Committer: Ingo Molnar <[email protected]>
CommitDate: Fri, 4 Sep 2009 09:26:39 +0200

x86, perf_counter, bts: Fail if BTS is not available

Reserve PERF_COUNT_HW_BRANCH_INSTRUCTIONS with sample_period ==
1 for BTS tracing and fail, if BTS is not available.

Signed-off-by: Markus Metzger <[email protected]>
Acked-by: Peter Zijlstra <[email protected]>
LKML-Reference: <[email protected]>
Signed-off-by: Ingo Molnar <[email protected]>


---
arch/x86/kernel/cpu/perf_counter.c | 25 +++++++++++--------------
1 files changed, 11 insertions(+), 14 deletions(-)

diff --git a/arch/x86/kernel/cpu/perf_counter.c b/arch/x86/kernel/cpu/perf_counter.c
index 396e35d..2f41874 100644
--- a/arch/x86/kernel/cpu/perf_counter.c
+++ b/arch/x86/kernel/cpu/perf_counter.c
@@ -769,7 +769,7 @@ static int reserve_bts_hardware(void)
int cpu, err = 0;

if (!bts_available())
- return -EOPNOTSUPP;
+ return 0;

get_online_cpus();

@@ -914,7 +914,7 @@ static int __hw_perf_counter_init(struct perf_counter *counter)
if (!reserve_pmc_hardware())
err = -EBUSY;
else
- reserve_bts_hardware();
+ err = reserve_bts_hardware();
}
if (!err)
atomic_inc(&active_counters);
@@ -979,6 +979,13 @@ static int __hw_perf_counter_init(struct perf_counter *counter)
if (config == -1LL)
return -EINVAL;

+ /*
+ * Branch tracing:
+ */
+ if ((attr->config == PERF_COUNT_HW_BRANCH_INSTRUCTIONS) &&
+ (hwc->sample_period == 1) && !bts_available())
+ return -EOPNOTSUPP;
+
hwc->config |= config;

return 0;
@@ -1355,19 +1362,9 @@ static int x86_pmu_enable(struct perf_counter *counter)

idx = fixed_mode_idx(counter, hwc);
if (idx == X86_PMC_IDX_FIXED_BTS) {
- /*
- * Try to use BTS for branch tracing. If that is not
- * available, try to get a generic counter.
- */
- if (unlikely(!cpuc->ds))
- goto try_generic;
-
- /*
- * Try to get the fixed counter, if that is already taken
- * then try to get a generic counter:
- */
+ /* BTS is already occupied. */
if (test_and_set_bit(idx, cpuc->used_mask))
- goto try_generic;
+ return -EAGAIN;

hwc->config_base = 0;
hwc->counter_base = 0;