mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* Re: [PATCH] 2.4.1-ac1 UP-APIC/NMI watchdog fixes
@ 2001-02-02 12:28 Petr Vandrovec
  0 siblings, 0 replies; 7+ messages in thread
From: Petr Vandrovec @ 2001-02-02 12:28 UTC (permalink / raw)
  To: Mikael Pettersson; +Cc: alan, linux-kernel, macro, mingo

On  2 Feb 01 at 3:35, Mikael Pettersson wrote:
> On Fri, 2 Feb 2001 01:37:28 +0100, Ingo Molnar wrote:
> > On Thu, 1 Feb 2001, Mikael Pettersson wrote:
> > > * NMI watchdog cleanups: mark setup_apic_nmi_watchdog() as __init,
> > >   fix the K7 init code to not leave any perfctr MSR uninitialised,
> > >   avoid having to check CPU type in NMI handler.
> > >   (Yes, the merged wrmsr(,,-1) is safe for P6.)
> > 
> > thanks Mikael! Did you have a chance to test this on a K7? Does
> > UP-APIC-NMI-watchdog code truly 'just work' now on the K7?
> 
> I wrote the initial patch using the info I gathered for my
> performance-monitoring counters driver. Petr Vandrovec tested
> and debugged it. (Alas, I don't yet have a K7 to play with.)

Yes, it works. There is only problem with VMware - I wrote patch
which disables LVTPC NMI delivery when running VMware (like 
LVT0/1 NMI delivery is disabled on normal SMP/IOAPIC kernel (as VMware
uses its own address space when running emulation, it does not want 
NMI delivery during switching address spaces)) and I found that after 
I reenable delivery, nothing happens :-( Performance counters aparently
just delivery interrupt only for one cycle when counter value is 
FFFFFFFFFFFFFFFF. And apparently setting delivery mode to edge triggered 
does not work for LVTPC (or maybe that disabling LVTPC delivery just causes
all events to be dropped, even in edgemode). So first time when VMware 
runs when NMI should be triggered, you lost it. And as next come after 
2^48 CPU clocks, it disables NMI watchdog almost forever (it is not 
problem on ia32, as 2^32 cycles passes in few seconds after you exit 
from VMware).

As workaround, I tried to program LVTPC as fixed delivery to 2, but this
caused 'invalid vector received' error :-( So for now UP K7 NMI watchdog 
and vmware are incompatible. Maybe I should try to revector it for
SMI delivery, because of SMI handler runs in its own address space. But it
is incompatible with APM and ACPI, so...
                                            Best regards,
                                                Petr Vandrovec
                                                vandrove@vc.cvut.cz
                                                
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

^ permalink raw reply	[flat|nested] 7+ messages in thread
* Re: [PATCH] 2.4.1-ac1 UP-APIC/NMI watchdog fixes
@ 2001-02-02  2:35 Mikael Pettersson
  0 siblings, 0 replies; 7+ messages in thread
From: Mikael Pettersson @ 2001-02-02  2:35 UTC (permalink / raw)
  To: mingo; +Cc: alan, linux-kernel, macro, vandrove

On Fri, 2 Feb 2001 01:37:28 +0100, Ingo Molnar wrote:

> On Thu, 1 Feb 2001, Mikael Pettersson wrote:
> 
> > This patch (against 2.4.1-ac1) contains the following fixes:
> > * UP-APIC linkage fix: nr_ioapics must be moved from io_apic.c to
> >   mpparse.c to permit linking the kernel in pure UP-APIC configs.
> > * NMI watchdog cleanups: mark setup_apic_nmi_watchdog() as __init,
> >   fix the K7 init code to not leave any perfctr MSR uninitialised,
> >   avoid having to check CPU type in NMI handler.
> >   (Yes, the merged wrmsr(,,-1) is safe for P6.)
> 
> thanks Mikael! Did you have a chance to test this on a K7? Does
> UP-APIC-NMI-watchdog code truly 'just work' now on the K7?

I wrote the initial patch using the info I gathered for my
performance-monitoring counters driver. Petr Vandrovec tested
and debugged it. (Alas, I don't yet have a K7 to play with.)

It seems K7 BIOSen keep the local APIC enabled as opposed to
what P6 BIOSen tend to do (at least, Petr's ASUS A7V did),
so in a sense, yes "it just works". The clock denoted by the
event selector is not perfect (it slows down by a factor of
100 when the CPU is idle), but the NMIs do keep coming in.

I might have been able to whip up something better, if AMD
hadn't required an NDA for the K7 BIOS writer's manual. My
regard for them is pretty low right now.

/Mikael
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

^ permalink raw reply	[flat|nested] 7+ messages in thread
* [PATCH] 2.4.1-ac1 UP-APIC/NMI watchdog fixes
@ 2001-02-01 19:28 Mikael Pettersson
  2001-02-02  0:37 ` Ingo Molnar
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Mikael Pettersson @ 2001-02-01 19:28 UTC (permalink / raw)
  To: alan; +Cc: linux-kernel, macro, mingo

This patch (against 2.4.1-ac1) contains the following fixes:
* UP-APIC linkage fix: nr_ioapics must be moved from io_apic.c to
  mpparse.c to permit linking the kernel in pure UP-APIC configs.
* NMI watchdog cleanups: mark setup_apic_nmi_watchdog() as __init,
  fix the K7 init code to not leave any perfctr MSR uninitialised,
  avoid having to check CPU type in NMI handler.
  (Yes, the merged wrmsr(,,-1) is safe for P6.)

Alan, please include this in -ac2.

/Mikael

--- linux-2.4.1-ac1/arch/i386/kernel/io_apic.c.~1~	Thu Feb  1 15:33:35 2001
+++ linux-2.4.1-ac1/arch/i386/kernel/io_apic.c	Thu Feb  1 16:16:11 2001
@@ -38,7 +38,6 @@
 /*
  * # of IRQ routing registers
  */
-int nr_ioapics;
 int nr_ioapic_registers[MAX_IO_APICS];
 
 #if CONFIG_SMP
--- linux-2.4.1-ac1/arch/i386/kernel/mpparse.c.~1~	Thu Feb  1 15:33:35 2001
+++ linux-2.4.1-ac1/arch/i386/kernel/mpparse.c	Thu Feb  1 16:15:41 2001
@@ -48,6 +48,8 @@
 /* MP IRQ source entries */
 int mp_irq_entries;
 
+int nr_ioapics;
+
 int pic_mode;
 unsigned long mp_lapic_addr;
 
--- linux-2.4.1-ac1/arch/i386/kernel/nmi.c.~1~	Thu Feb  1 15:33:35 2001
+++ linux-2.4.1-ac1/arch/i386/kernel/nmi.c	Thu Feb  1 18:07:34 2001
@@ -82,25 +82,35 @@
 /*
  * Activate the NMI watchdog via the local APIC.
  * Original code written by Keith Owens.
+ * AMD K7 code by Mikael Pettersson.
  */
 
+static unsigned int nmi_perfctr_msr;	/* the MSR to reset in NMI handler */
 #define MSR_K7_EVNTSEL0 0xC0010000
 #define MSR_K7_PERFCTR0 0xC0010004
+/* Event 0x76 isn't listed in recent revisions of AMD #22007, and it
+   slows down (but doesn't halt) when the CPU is idle. Unfortunately
+   the K7 doesn't appear to have any other clock-like perfctr event. */
+#define K7_NMI_EVENT	0x76	/* CYCLES_PROCESSOR_IS_RUNNING */
+#define K7_NMI_EVNTSEL	((1<<20)|(3<<16)|K7_NMI_EVENT)	/* INT,OS,USR,<event> */
 
-void setup_apic_nmi_watchdog (void)
+void __init setup_apic_nmi_watchdog (void)
 {
 	int value;
 
 	if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD &&
 	    boot_cpu_data.x86 == 6) {
-		unsigned evntsel = (1<<20)|(3<<16);	/* INT, OS, USR */
-#if 1	/* listed in old docs */
-		evntsel |= 0x76;	/* CYCLES_PROCESSOR_IS_RUNNING */
-#else	/* try this if the above doesn't work */
-		evntsel |= 0xC0;	/* RETIRED_INSTRUCTIONS */
-#endif
-		wrmsr(MSR_K7_EVNTSEL0, 0, 0);
-		wrmsr(MSR_K7_PERFCTR0, 0, 0);
+		unsigned i;
+		unsigned evntsel;
+
+		nmi_perfctr_msr = MSR_K7_PERFCTR0;
+
+		for(i = 0; i < 4; ++i) {
+			wrmsr(MSR_K7_EVNTSEL0+i, 0, 0);
+			wrmsr(MSR_K7_PERFCTR0+i, 0, 0);
+		}
+
+		evntsel = K7_NMI_EVNTSEL;
 		wrmsr(MSR_K7_EVNTSEL0, evntsel, 0);
 		printk("setting K7_PERFCTR0 to %08lx\n", -(cpu_khz/HZ*1000));
 		wrmsr(MSR_K7_PERFCTR0, -(cpu_khz/HZ*1000), -1);
@@ -112,6 +122,8 @@
 		return;
 	}
 
+	nmi_perfctr_msr = MSR_IA32_PERFCTR1;
+
 	/* clear performance counters 0, 1 */
 
 	wrmsr(MSR_IA32_EVNTSEL0, 0, 0);
@@ -190,14 +202,6 @@
 		last_irq_sums[cpu] = sum;
 		alert_counter[cpu] = 0;
 	}
-	if (cpu_has_apic && (nmi_watchdog == NMI_LOCAL_APIC)) {
-		/* XXX: nmi_watchdog should carry this info */
-		unsigned msr;
-		if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD) {
-			wrmsr(MSR_K7_PERFCTR0, -(cpu_khz/HZ*1000), -1);
-		} else {
-			wrmsr(MSR_IA32_PERFCTR1, -(cpu_khz/HZ*1000), 0);
-		}
-	}
+	if (cpu_has_apic && (nmi_watchdog == NMI_LOCAL_APIC))
+		wrmsr(nmi_perfctr_msr, -(cpu_khz/HZ*1000), -1);
 }
-
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2001-02-02 18:47 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-02-02 12:28 [PATCH] 2.4.1-ac1 UP-APIC/NMI watchdog fixes Petr Vandrovec
  -- strict thread matches above, loose matches on Subject: below --
2001-02-02  2:35 Mikael Pettersson
2001-02-01 19:28 Mikael Pettersson
2001-02-02  0:37 ` Ingo Molnar
2001-02-02 14:28 ` Maciej W. Rozycki
2001-02-02 16:28 ` Mikael Pettersson
2001-02-02 18:37   ` Maciej W. Rozycki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®