Skip to contentSkip to conversation

AMD Family10h IBS support for oProfile driver

PATCH In review Barry Kasindorf 2 participants 2 messages Feb 8, 2008 x86

lore
Share & tools
lore
#0 lore raw

PATCH 2/3 AMD Family10h IBS support for oProfile driver

---
 kernel/apic_64.c           |    1
 oprofile/op_model_athlon.c |  245 ++++++++++++++++++++++++++++++++++++++++++++-
 oprofile/op_x86_model.h    |   37 ++++++
 3 files changed, 281 insertions(+), 2 deletions(-)
arch/x86/kernel/apic_32.c +24 -0
index 1e417df..7dbe8b0 100644
@@ -224,6 +224,30 @@ static void __setup_APIC_LVTT(unsigned int clocks, int oneshot, int irqen)
 	if (!oneshot)
 		apic_write_around(APIC_TMICT, clocks/APIC_DIVISOR);
 }
+#define APIC_EILVT_LVTOFF_MCE 0
+#define APIC_EILVT_LVTOFF_IBS 1
+
+static void setup_APIC_eilvt(u8 lvt_off, u8 vector, u8 msg_type, u8 mask)
+{
+	unsigned long reg = (lvt_off << 4) + APIC_EILVT0;
+	unsigned int  v   = (mask << 16) | (msg_type << 8) | vector;
+
+	apic_write(reg, v);
+}
+
+u8 setup_APIC_eilvt_mce(u8 vector, u8 msg_type, u8 mask)
+{
+	setup_APIC_eilvt(APIC_EILVT_LVTOFF_MCE, vector, msg_type, mask);
+	return APIC_EILVT_LVTOFF_MCE;
+}
+
+u8 setup_APIC_eilvt_ibs(u8 vector, u8 msg_type, u8 mask)
+{
+	setup_APIC_eilvt(APIC_EILVT_LVTOFF_IBS, vector, msg_type, mask);
+	return APIC_EILVT_LVTOFF_IBS;
+}
+EXPORT_SYMBOL(setup_APIC_eilvt_ibs);
+
 
 /*
  * Program the next event, relative to now
arch/x86/kernel/apic_64.c +1 -0
index 286a396..bced2a6 100644
@@ -219,6 +219,7 @@ u8 setup_APIC_eilvt_ibs(u8 vector, u8 msg_type, u8 mask)
 	setup_APIC_eilvt(APIC_EILVT_LVTOFF_IBS, vector, msg_type, mask);
 	return APIC_EILVT_LVTOFF_IBS;
 }
+EXPORT_SYMBOL(setup_APIC_eilvt_ibs);
 
 /*
  * Program the next event, relative to now
arch/x86/oprofile/op_model_athlon.c +245 -2

292 lines not on this page · raw message

arch/x86/oprofile/op_x86_model.h +37 -0
index 45b605f..0c5960a 100644
@@ -26,6 +26,39 @@ struct op_msrs {
 	struct op_msr * controls;
 };
 
+struct ibs_fetch_sample {
+	/* MSRC001_1031 IBS Fetch Linear Address Register */
+	unsigned int ibs_fetch_lin_addr_low;
+	unsigned int ibs_fetch_lin_addr_high;
+	/* MSRC001_1030 IBS Fetch Control Register */
+	unsigned int ibs_fetch_ctl_low;
+	unsigned int ibs_fetch_ctl_high;
+	/* MSRC001_1032 IBS Fetch Physical Address Register */
+	unsigned int ibs_fetch_phys_addr_low;
+	unsigned int ibs_fetch_phys_addr_high;
+};
+
+struct ibs_op_sample {
+	/* MSRC001_1034 IBS Op Logical Address Register (IbsRIP) */
+	unsigned int ibs_op_rip_low;
+	unsigned int ibs_op_rip_high;
+	/* MSRC001_1035 IBS Op Data Register */
+	unsigned int ibs_op_data1_low;
+	unsigned int ibs_op_data1_high;
+	/* MSRC001_1036 IBS Op Data 2 Register */
+	unsigned int ibs_op_data2_low;
+	unsigned int ibs_op_data2_high;
+	/* MSRC001_1037 IBS Op Data 3 Register */
+	unsigned int ibs_op_data3_low;
+	unsigned int ibs_op_data3_high;
+	/* MSRC001_1038 IBS DC Linear Address Register (IbsDcLinAd) */
+	unsigned int ibs_dc_linear_low;
+	unsigned int ibs_dc_linear_high;
+	/* MSRC001_1039 IBS DC Physical Address Register (IbsDcPhysAd) */
+	unsigned int ibs_dc_phys_low;
+	unsigned int ibs_dc_phys_high;
+};
+
 struct pt_regs;
 
 /* The model vtable abstracts the differences between
@@ -48,4 +81,8 @@ extern struct op_x86_model_spec const op_p4_spec;
 extern struct op_x86_model_spec const op_p4_ht2_spec;
 extern struct op_x86_model_spec const op_athlon_spec;
 
+/* setup AMD Family 10H IBS IRQ if needed */
+extern void setup_ibs_nmi(void);
+/* clearp AMD Family 10H IBS IRQ if needed */
+extern void clear_ibs_nmi(void);
 #endif /* OP_X86_MODEL_H */
#1 lore raw
Quoted 24 lines
---
 kernel/apic_64.c           |    1
 oprofile/op_model_athlon.c |  245 
 ++++++++++++++++++++++++++++++++++++++++++++-
 oprofile/op_x86_model.h    |   37 ++++++
 3 files changed, 281 insertions(+), 2 deletions(-)
arch/x86/kernel/apic_32.c +6 -0
index 1e417df..7dbe8b0 100644
@@ -224,6 +224,30 @@ static void __setup_APIC_LVTT(unsigned int clocks, int 
 oneshot, int irqen)
 	if (!oneshot)
 		apic_write_around(APIC_TMICT, clocks/APIC_DIVISOR);
 }
+#define APIC_EILVT_LVTOFF_MCE 0
+#define APIC_EILVT_LVTOFF_IBS 1
+
+static void setup_APIC_eilvt(u8 lvt_off, u8 vector, u8 msg_type, u8 mask)
+{
+	unsigned long reg = (lvt_off << 4) + APIC_EILVT0;

arch/x86/kernel/apic_32.c static void __setup_APIC_LVTT(unsigned int clocks, int · line 243

Quoted 10 lines
arch/x86/kernel/apic_32.c +10 -0
+	unsigned int  v   = (mask << 16) | (msg_type << 8) | vector;
+
+	apic_write(reg, v);
+}
+
+u8 setup_APIC_eilvt_mce(u8 vector, u8 msg_type, u8 mask)
+{
+	setup_APIC_eilvt(APIC_EILVT_LVTOFF_MCE, vector, msg_type, mask);
+	return APIC_EILVT_LVTOFF_MCE;
+}

There are no users of this global symbol - can we kill it?

arch/x86/kernel/apic_32.c static void __setup_APIC_LVTT(unsigned int clocks, int oneshot, int irqen) · line 249

Quoted 7 lines
arch/x86/kernel/apic_32.c +7 -0
+
+u8 setup_APIC_eilvt_ibs(u8 vector, u8 msg_type, u8 mask)
+{
+	setup_APIC_eilvt(APIC_EILVT_LVTOFF_IBS, vector, msg_type, mask);
+	return APIC_EILVT_LVTOFF_IBS;
+}
+EXPORT_SYMBOL(setup_APIC_eilvt_ibs);

Please document all new EXPORT_SYMBOLS with kernel-doc comments. GPL export?

arch/x86/kernel/apic_64.c u8 setup_APIC_eilvt_ibs(u8 vector, u8 msg_type, u8 mask) · line 222

Quoted 13 lines
arch/x86/kernel/apic_32.c +1 -0
+
 
 /*

* Program the next event, relative to now

arch/x86/kernel/apic_64.c +1 -0
index 286a396..bced2a6 100644
@@ -219,6 +219,7 @@ u8 setup_APIC_eilvt_ibs(u8 vector, u8 msg_type, u8 mask)
 	setup_APIC_eilvt(APIC_EILVT_LVTOFF_IBS, vector, msg_type, mask);
 	return APIC_EILVT_LVTOFF_IBS;
 }
+EXPORT_SYMBOL(setup_APIC_eilvt_ibs);

Is this new export properly documented?

arch/x86/kernel/apic_64.c line 16

Quoted 12 lines
arch/x86/kernel/apic_64.c +5 -1
+++ b/arch/x86/oprofile/op_model_athlon.c
@@ -8,9 +8,13 @@
  * @author John Levon
  * @author Philippe Elie
  * @author Graydon Hoare
- */
+ * @author Barry Kasindorf
+*/
 
 #include <linux/oprofile.h>
+#include <linux/device.h>
+#include <linux/pci.h>

Alphabetic order is preferred.

arch/x86/kernel/apic_64.c line 50

Quoted 10 lines
arch/x86/kernel/apic_64.c +3 -0
+
 #include <asm/ptrace.h>
 #include <asm/msr.h>
 #include <asm/nmi.h>
@@ -42,8 +46,69 @@
 #define CTRL_SET_HOST_ONLY(val, h) (val |= ((h & 1) << 9))
 #define CTRL_SET_GUEST_ONLY(val, h) (val |= ((h & 1) << 8))
 
+/* high dword IbsFetchCtl[bit 49] */
+#define IBS_FETCH_VALID_BIT		0x00020000

Then define it as (1 << 49) ?

arch/x86/kernel/apic_64.c line 59

Quoted 9 lines
arch/x86/kernel/apic_64.c +9 -0
+ * Add an AMD IBS  sample. This may be called from any context. Pass
+ * smp_processor_id() as cpu. Passes IBS registers as a unsigned int[8]
+ */
+void oprofile_add_ibs_op_sample(struct pt_regs * const regs,
+				unsigned int * const ibs_op);
+
+void oprofile_add_ibs_fetch_sample(struct pt_regs * const regs,
+				unsigned int * const ibs_fetch);
+

These prototypes looks like they belong in a .h file. Did sparse accept them?

arch/x86/kernel/apic_64.c line 61

Quoted 3 lines
arch/x86/kernel/apic_64.c +1 -1
 static unsigned long reset_value[NUM_COUNTERS];
-
+extern int ibs_allowed;		/* AMD Family 10h+ */

This extern certainly does belong in a .h file.

arch/x86/kernel/apic_64.c line 68

Quoted 8 lines
arch/x86/kernel/apic_64.c +7 -0
+/*
+ *	Enable AMD extended PCI config space thru IO
+ *	save previous state
+ */
+static void
+	Enable_Extended_PCI_Config(void)
+{

AnySpecificReasonForPascalCasing?
And keep function definotion on one line.

arch/x86/kernel/apic_64.c line 81

Quoted 13 lines
arch/x86/kernel/apic_64.c +13 -0
+	unsigned int low, high;
+	rdmsr(NB_CFG_MSR, low, high);
+	Extended_PCI_Enabled = high  & ENABLE_CF8_EXT_CFG_MASK;
+	high |= ENABLE_CF8_EXT_CFG_MASK;
+	wrmsr(NB_CFG_MSR, low, high);
+}
+
+/*
+ *	Disable AMD extended PCI config space thru IO
+ *	restore to previous state
+ */
+static void
+	Disable_Extended_PCI_Config(void)

A_New_Style_For_Naming???

Quoted 6 lines
arch/x86/kernel/apic_64.c +6 -0
+{
+	unsigned int low, high;
+	rdmsr(NB_CFG_MSR, low, high);
+	high &= ~ENABLE_CF8_EXT_CFG_MASK;
+	high |= Extended_PCI_Enabled;
+	wrmsr(NB_CFG_MSR, low, high);

arch/x86/kernel/apic_64.c line 97

Quoted 10 lines
arch/x86/kernel/apic_64.c +10 -0
+}
+/*
+ * Modified to use AMD extended PCI config space thru IO
+ * these 2 I/Os should be atomic but there is no easy way to do that.
+ * Should use the MMio version, will when it is fixed
+ */
+
+static void
+	PCI_Extended_Write(struct pci_dev *dev, unsigned int offset,
+						 unsigned long val)

Again.

arch/x86/kernel/apic_64.c line 101

Quoted 4 lines
arch/x86/kernel/apic_64.c +3 -0
+
+		/**** Be sure to run loop until NULL is returned to
+		decrement reference count on any pci_dev structures returned 
 ****/

USe kernel style:
/*
* Bla
*/
And resubmit without line wraps.