linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: tip-bot for Reinette Chatre <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: hpa@zytor.com, mingo@kernel.org, peterz@infradead.org,
	tglx@linutronix.de, reinette.chatre@intel.com,
	linux-kernel@vger.kernel.org
Subject: [tip:x86/cache] perf/x86: Add helper to obtain performance counter index
Date: Sat, 29 Sep 2018 00:00:52 -0700	[thread overview]
Message-ID: <tip-1182a49529edde899be4b4f0e1ab76e626976eb6@git.kernel.org> (raw)
In-Reply-To: <b277ffa78a51254f5414f7b1bc1923826874566e.1537377064.git.reinette.chatre@intel.com>

Commit-ID:  1182a49529edde899be4b4f0e1ab76e626976eb6
Gitweb:     https://git.kernel.org/tip/1182a49529edde899be4b4f0e1ab76e626976eb6
Author:     Reinette Chatre <reinette.chatre@intel.com>
AuthorDate: Wed, 19 Sep 2018 10:29:07 -0700
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Fri, 28 Sep 2018 22:48:26 +0200

perf/x86: Add helper to obtain performance counter index

perf_event_read_local() is the safest way to obtain measurements
associated with performance events. In some cases the overhead
introduced by perf_event_read_local() affects the measurements and the
use of rdpmcl() is needed. rdpmcl() requires the index
of the performance counter used so a helper is introduced to determine
the index used by a provided performance event.

The index used by a performance event may change when interrupts are
enabled. A check is added to ensure that the index is only accessed
with interrupts disabled. Even with this check the use of this counter
needs to be done with care to ensure it is queried and used within the
same disabled interrupts section.

This change introduces a new checkpatch warning:
CHECK: extern prototypes should be avoided in .h files
+extern int x86_perf_rdpmc_index(struct perf_event *event);

This warning was discussed and designated as a false positive in
http://lkml.kernel.org/r/20180919091759.GZ24124@hirez.programming.kicks-ass.net

Suggested-by: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: fenghua.yu@intel.com
Cc: tony.luck@intel.com
Cc: acme@kernel.org
Cc: gavin.hindman@intel.com
Cc: jithu.joseph@intel.com
Cc: dave.hansen@intel.com
Cc: hpa@zytor.com
Link: https://lkml.kernel.org/r/b277ffa78a51254f5414f7b1bc1923826874566e.1537377064.git.reinette.chatre@intel.com

---
 arch/x86/events/core.c            | 21 +++++++++++++++++++++
 arch/x86/include/asm/perf_event.h |  1 +
 2 files changed, 22 insertions(+)

diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c
index dfb2f7c0d019..3550d800b030 100644
--- a/arch/x86/events/core.c
+++ b/arch/x86/events/core.c
@@ -1033,6 +1033,27 @@ static inline void x86_assign_hw_event(struct perf_event *event,
 	}
 }
 
+/**
+ * x86_perf_rdpmc_index - Return PMC counter used for event
+ * @event: the perf_event to which the PMC counter was assigned
+ *
+ * The counter assigned to this performance event may change if interrupts
+ * are enabled. This counter should thus never be used while interrupts are
+ * enabled. Before this function is used to obtain the assigned counter the
+ * event should be checked for validity using, for example,
+ * perf_event_read_local(), within the same interrupt disabled section in
+ * which this counter is planned to be used.
+ *
+ * Return: The index of the performance monitoring counter assigned to
+ * @perf_event.
+ */
+int x86_perf_rdpmc_index(struct perf_event *event)
+{
+	lockdep_assert_irqs_disabled();
+
+	return event->hw.event_base_rdpmc;
+}
+
 static inline int match_prev_assignment(struct hw_perf_event *hwc,
 					struct cpu_hw_events *cpuc,
 					int i)
diff --git a/arch/x86/include/asm/perf_event.h b/arch/x86/include/asm/perf_event.h
index 12f54082f4c8..b2cf84c35a6d 100644
--- a/arch/x86/include/asm/perf_event.h
+++ b/arch/x86/include/asm/perf_event.h
@@ -270,6 +270,7 @@ struct perf_guest_switch_msr {
 extern struct perf_guest_switch_msr *perf_guest_get_msrs(int *nr);
 extern void perf_get_x86_pmu_capability(struct x86_pmu_capability *cap);
 extern void perf_check_microcode(void);
+extern int x86_perf_rdpmc_index(struct perf_event *event);
 #else
 static inline struct perf_guest_switch_msr *perf_guest_get_msrs(int *nr)
 {

  reply	other threads:[~2018-09-29  7:01 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-19 17:29 [PATCH V5 0/6] perf and x86/intel_rdt: Fix lack of coordination with perf Reinette Chatre
2018-09-19 17:29 ` [PATCH V5 1/6] perf/core: Add sanity check to deal with pinned event failure Reinette Chatre
2018-09-28 20:48   ` [tip:perf/urgent] " tip-bot for Reinette Chatre
2018-09-19 17:29 ` [PATCH V5 2/6] perf/x86: Add helper to obtain performance counter index Reinette Chatre
2018-09-29  7:00   ` tip-bot for Reinette Chatre [this message]
2018-09-19 17:29 ` [PATCH V5 3/6] x86/intel_rdt: Remove local register variables Reinette Chatre
2018-09-29  7:01   ` [tip:x86/cache] " tip-bot for Reinette Chatre
2018-09-19 17:29 ` [PATCH V5 4/6] x86/intel_rdt: Create required perf event attributes Reinette Chatre
2018-09-29  7:01   ` [tip:x86/cache] " tip-bot for Reinette Chatre
2018-09-19 17:29 ` [PATCH V5 5/6] x86/intel_rdt: Use perf infrastructure for measurements Reinette Chatre
2018-09-20 14:11   ` Peter Zijlstra
2018-09-20 19:02   ` [PATCH V6 " Reinette Chatre
2018-09-29  7:02     ` [tip:x86/cache] " tip-bot for Reinette Chatre
2018-09-19 17:29 ` [PATCH V5 6/6] x86/intel_rdt: Re-enable pseudo-lock measurements Reinette Chatre
2018-10-03 19:57   ` [tip:x86/cache] " tip-bot for Reinette Chatre
2018-09-20 14:11 ` [PATCH V5 0/6] perf and x86/intel_rdt: Fix lack of coordination with perf Peter Zijlstra
2018-09-21 16:49   ` Reinette Chatre
2018-09-27 20:39     ` Thomas Gleixner
2018-09-28  6:58       ` Peter Zijlstra
2018-09-29 14:23         ` Reinette Chatre
2018-09-29 17:56           ` Thomas Gleixner
2018-10-03 19:41             ` Reinette Chatre
2018-10-03 19:45               ` Thomas Gleixner

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=tip-1182a49529edde899be4b4f0e1ab76e626976eb6@git.kernel.org \
    --to=tipbot@zytor.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=reinette.chatre@intel.com \
    --cc=tglx@linutronix.de \
    /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;
as well as URLs for NNTP newsgroup(s).