From: Robert Richter <robert.richter@amd.com>
To: Ingo Molnar <mingo@elte.hu>
Cc: LKML <linux-kernel@vger.kernel.org>,
oprofile-list <oprofile-list@lists.sourceforge.net>,
Robert Richter <robert.richter@amd.com>
Subject: [PATCH 09/23] x86/oprofile: remove MSR macros for AMD cpus
Date: Fri, 12 Jun 2009 14:35:26 +0200 [thread overview]
Message-ID: <1244810140-20595-10-git-send-email-robert.richter@amd.com> (raw)
In-Reply-To: <1244810140-20595-1-git-send-email-robert.richter@amd.com>
The macros CTRL_READ() and CTRL_WRITE() make the code hard to read and
maintain. This patch replaces them by rdmsr()/wrmsr() functions and
simplifies the code.
Signed-off-by: Robert Richter <robert.richter@amd.com>
---
arch/x86/oprofile/op_model_amd.c | 29 ++++++++++++-----------------
1 files changed, 12 insertions(+), 17 deletions(-)
diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
index 4b9254a..c6181c2 100644
--- a/arch/x86/oprofile/op_model_amd.c
+++ b/arch/x86/oprofile/op_model_amd.c
@@ -26,12 +26,7 @@
#define NUM_COUNTERS 4
#define NUM_CONTROLS 4
-#define CTR_READ(l, h, msrs, c) do {rdmsr(msrs->counters[(c)].addr, (l), (h)); } while (0)
-#define CTR_WRITE(l, msrs, c) do {wrmsr(msrs->counters[(c)].addr, -(unsigned int)(l), -1); } while (0)
#define CTR_OVERFLOWED(n) (!((n) & (1U<<31)))
-
-#define CTRL_READ(l, h, msrs, c) do {rdmsr(msrs->controls[(c)].addr, (l), (h)); } while (0)
-#define CTRL_WRITE(l, h, msrs, c) do {wrmsr(msrs->controls[(c)].addr, (l), (h)); } while (0)
#define CTRL_CLEAR_LO(x) (x &= (1<<21))
#define CTRL_CLEAR_HI(x) (x &= 0xfffffcf0)
#define CTRL_SET_EVENT_LOW(val, e) (val |= (e & 0xff))
@@ -101,17 +96,17 @@ static void op_amd_setup_ctrs(struct op_msrs const * const msrs)
for (i = 0 ; i < NUM_CONTROLS; ++i) {
if (unlikely(!CTRL_IS_RESERVED(msrs, i)))
continue;
- CTRL_READ(low, high, msrs, i);
+ rdmsr(msrs->controls[i].addr, low, high);
CTRL_CLEAR_LO(low);
CTRL_CLEAR_HI(high);
- CTRL_WRITE(low, high, msrs, i);
+ wrmsr(msrs->controls[i].addr, low, high);
}
/* avoid a false detection of ctr overflows in NMI handler */
for (i = 0; i < NUM_COUNTERS; ++i) {
if (unlikely(!CTR_IS_RESERVED(msrs, i)))
continue;
- CTR_WRITE(1, msrs, i);
+ wrmsr(msrs->counters[i].addr, -1, -1);
}
/* enable active counters */
@@ -119,9 +114,9 @@ static void op_amd_setup_ctrs(struct op_msrs const * const msrs)
if ((counter_config[i].enabled) && (CTR_IS_RESERVED(msrs, i))) {
reset_value[i] = counter_config[i].count;
- CTR_WRITE(counter_config[i].count, msrs, i);
+ wrmsr(msrs->counters[i].addr, -(unsigned int)counter_config[i].count, -1);
- CTRL_READ(low, high, msrs, i);
+ rdmsr(msrs->controls[i].addr, low, high);
CTRL_CLEAR_LO(low);
CTRL_CLEAR_HI(high);
CTRL_SET_ENABLE(low);
@@ -133,7 +128,7 @@ static void op_amd_setup_ctrs(struct op_msrs const * const msrs)
CTRL_SET_HOST_ONLY(high, 0);
CTRL_SET_GUEST_ONLY(high, 0);
- CTRL_WRITE(low, high, msrs, i);
+ wrmsr(msrs->controls[i].addr, low, high);
} else {
reset_value[i] = 0;
}
@@ -267,10 +262,10 @@ static int op_amd_check_ctrs(struct pt_regs * const regs,
for (i = 0 ; i < NUM_COUNTERS; ++i) {
if (!reset_value[i])
continue;
- CTR_READ(low, high, msrs, i);
+ rdmsr(msrs->counters[i].addr, low, high);
if (CTR_OVERFLOWED(low)) {
oprofile_add_sample(regs, i);
- CTR_WRITE(reset_value[i], msrs, i);
+ wrmsr(msrs->counters[i].addr, -(unsigned int)reset_value[i], -1);
}
}
@@ -286,9 +281,9 @@ static void op_amd_start(struct op_msrs const * const msrs)
int i;
for (i = 0 ; i < NUM_COUNTERS ; ++i) {
if (reset_value[i]) {
- CTRL_READ(low, high, msrs, i);
+ rdmsr(msrs->controls[i].addr, low, high);
CTRL_SET_ACTIVE(low);
- CTRL_WRITE(low, high, msrs, i);
+ wrmsr(msrs->controls[i].addr, low, high);
}
}
@@ -307,9 +302,9 @@ static void op_amd_stop(struct op_msrs const * const msrs)
for (i = 0 ; i < NUM_COUNTERS ; ++i) {
if (!reset_value[i])
continue;
- CTRL_READ(low, high, msrs, i);
+ rdmsr(msrs->controls[i].addr, low, high);
CTRL_SET_INACTIVE(low);
- CTRL_WRITE(low, high, msrs, i);
+ wrmsr(msrs->controls[i].addr, low, high);
}
op_amd_stop_ibs();
--
1.6.3.1
next prev parent reply other threads:[~2009-06-12 13:03 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-06-12 12:35 [PATCH 0/23] updates for oprofile Robert Richter
2009-06-12 12:35 ` [PATCH 01/23] Revert "oprofile: discover counters for op ppro too" Robert Richter
2009-06-12 12:35 ` [PATCH 02/23] x86/oprofile: moving arch_perfmon counter setup to op_x86_model_spec.init Robert Richter
2009-06-12 19:24 ` [PATCH] x86/oprofile: fix initialization of arch_perfmon for core_i7 Robert Richter
2009-06-12 12:35 ` [PATCH 03/23] x86/oprofile: minor style changes in struct op_x86_model_spec Robert Richter
2009-06-12 12:35 ` [PATCH 04/23] oprofile: remove irq_flags in struct op_entry Robert Richter
2009-06-12 12:35 ` [PATCH 05/23] oprofile: remove obselete include headers Robert Richter
2009-06-12 12:35 ` [PATCH 06/23] x86/oprofile: remove #ifdefs in ibs functions Robert Richter
2009-06-12 12:35 ` [PATCH 07/23] x86/oprofile: simplify AMD cpu init code Robert Richter
2009-06-12 12:35 ` [PATCH 08/23] x86/oprofile: move common macros to op_x86_model.h Robert Richter
2009-06-12 12:35 ` Robert Richter [this message]
2009-06-12 12:35 ` [PATCH 10/23] x86/oprofile: remove MSR macros for ppro cpus Robert Richter
2009-06-12 12:35 ` [PATCH 11/23] x86/oprofile: remove MSR macros for p4 cpus Robert Richter
2009-06-12 12:35 ` [PATCH 12/23] x86/oprofile: fix and cleanup CTRL_SET_* macros Robert Richter
2009-06-12 12:35 ` [PATCH 13/23] x86/oprofile: remove unused macros for AMD virtualization profiling Robert Richter
2009-06-12 12:35 ` [PATCH 14/23] x86/oprofile: pass the model to setup_ctrs() functions Robert Richter
2009-06-12 12:35 ` [PATCH 15/23] x86/oprofile: replace macros to calculate control register Robert Richter
2009-06-12 12:35 ` [PATCH 16/23] x86/oprofile: replace CTR_OVERFLOWED macros Robert Richter
2009-06-12 12:35 ` [PATCH 17/23] x86/oprofile: replace CTRL_SET_*ACTIVE macros Robert Richter
2009-06-12 12:35 ` [PATCH 18/23] x86/oprofile: replace CTR*_IS_RESERVED macros Robert Richter
2009-06-12 12:35 ` [PATCH 19/23] x86/oprofile: use 64 bit wrmsr functions Robert Richter
2009-06-22 7:49 ` Andi Kleen
2009-06-22 8:07 ` Andi Kleen
2009-06-12 12:35 ` [PATCH 20/23] x86/oprofile: use 64 bit values to save MSR states Robert Richter
2009-06-12 12:35 ` [PATCH 21/23] x86/oprofile: remove some local variables in MSR save/restore functions Robert Richter
2009-06-12 12:35 ` [PATCH 22/23] x86/oprofile: use 64 bit values in IBS functions Robert Richter
2009-06-12 12:35 ` [PATCH 23/23] x86/oprofile: introduce oprofile_add_data64() Robert Richter
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=1244810140-20595-10-git-send-email-robert.richter@amd.com \
--to=robert.richter@amd.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=oprofile-list@lists.sourceforge.net \
/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
Powered by JetHome