Skip to contentSkip to conversation

x86: dish of assorted hpet patches

PATCH Applied Andreas Herrmann 2 participants 6 messages Feb 20, 2009 – Feb 24, 2009

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover x86: dish of assorted hpet patches

- to print HPET registers during setup,
- to fix a real issue with HZ_1000 kernels on an SB400 system (and to potentially fix a similar issue with SB600).

Tested on ICH7 and on AMD SB400, AMD SB600.

Please apply.

Thanks,
Andreas

Signature · 5 lines
Operating | Advanced Micro Devices GmbH
  System  | Karl-Hammerschmidt-Str. 34, 85609 Dornach b. München, Germany
 Research | Geschäftsführer: Jochen Polster, Thomas M. McCoy, Giuliano Meroni
  Center  | Sitz: Dornach, Gemeinde Aschheim, Landkreis München
  (OSRC)  | Registergericht München, HRB Nr. 43632
#1 lore raw

PATCH 1/3 x86: hpet: print HPET registers during setup (if hpet=verbose is used)

Impact: provide verbose HPET information

---
 Documentation/kernel-parameters.txt |    4 ++-
 arch/x86/kernel/hpet.c              |   45 +++++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+), 1 deletions(-)
Documentation/kernel-parameters.txt +3 -1
index b182626..01379a8 100644
@@ -492,10 +492,12 @@ and is between 256 and 4096 characters. It is defined in the file
 			Default: 64
 
 	hpet=		[X86-32,HPET] option to control HPET usage
-			Format: { enable (default) | disable | force }
+			Format: { enable (default) | disable | force |
+				verbose }
 			disable: disable HPET and use PIT instead
 			force: allow force enabled of undocumented chips (ICH4,
 			VIA, nVidia)
+			verbose: show contents of HPET registers during setup
 
 	com20020=	[HW,NET] ARCnet - COM20020 chipset
 			Format:
arch/x86/kernel/hpet.c +45 -0

93 lines not on this page · raw message

Signature · 1 line
1.6.1.3
#2 lore raw

PATCH 2/3 x86: hpet: provide separate functions to stop and start the counter

In reply to Andreas Herrmann

By splitting up existing hpet_start_counter function.

---
 arch/x86/kernel/hpet.c |   22 ++++++++++++++++------
 1 files changed, 16 insertions(+), 6 deletions(-)
arch/x86/kernel/hpet.c +16 -6
index 84450b1..20acc6a 100644
@@ -231,27 +231,37 @@ static struct clock_event_device hpet_clockevent = {
 	.rating		= 50,
 };
 
-static void hpet_start_counter(void)
+static void hpet_stop_counter(void)
 {
 	unsigned long cfg = hpet_readl(HPET_CFG);
-
 	cfg &= ~HPET_CFG_ENABLE;
 	hpet_writel(cfg, HPET_CFG);
 	hpet_writel(0, HPET_COUNTER);
 	hpet_writel(0, HPET_COUNTER + 4);
+}
+
+static void hpet_start_counter(void)
+{
+	unsigned long cfg = hpet_readl(HPET_CFG);
 	cfg |= HPET_CFG_ENABLE;
 	hpet_writel(cfg, HPET_CFG);
 }
 
+static void hpet_restart_counter(void)
+{
+	hpet_stop_counter();
+	hpet_start_counter();
+}
+
 static void hpet_resume_device(void)
 {
 	force_hpet_resume();
 }
 
-static void hpet_restart_counter(void)
+static void hpet_resume_counter(void)
 {
 	hpet_resume_device();
-	hpet_start_counter();
+	hpet_restart_counter();
 }
 
 static void hpet_enable_legacy_int(void)
@@ -738,7 +748,7 @@ static struct clocksource clocksource_hpet = {
 	.mask		= HPET_MASK,
 	.shift		= HPET_SHIFT,
 	.flags		= CLOCK_SOURCE_IS_CONTINUOUS,
-	.resume		= hpet_restart_counter,
+	.resume		= hpet_resume_counter,
 #ifdef CONFIG_X86_64
 	.vread		= vread_hpet,
 #endif
@@ -750,7 +760,7 @@ static int hpet_clocksource_register(void)
 	cycle_t t1;
 
 	/* Start the counter */
-	hpet_start_counter();
+	hpet_restart_counter();
 
 	/* Verify whether hpet counter works */
 	t1 = read_hpet();
Signature · 1 line
1.6.1.3
#3 lore raw

PATCH 3/3 x86: hpet: stop HPET_COUNTER when programming periodic mode

In reply to Andreas Herrmann

Impact: fix system hang on some systems operating with HZ_1000

On a system that stalled with HZ_1000, the first value written to T0_CMP (when the main counter was not stopped) did not trigger an interrupt. Instead after the main counter wrapped around (after several minutes) an interrupt was triggered and afterwards the periodic interrupt took effect.

This can be fixed by implementing HPET spec recommendation for programming the periodic mode (i.e. stopping the main counter).

---
 arch/x86/kernel/hpet.c |   13 +++----------
 1 files changed, 3 insertions(+), 10 deletions(-)
arch/x86/kernel/hpet.c +3 -10
index 20acc6a..46be008 100644
@@ -309,29 +309,22 @@ static int hpet_setup_msi_irq(unsigned int irq);
 static void hpet_set_mode(enum clock_event_mode mode,
 			  struct clock_event_device *evt, int timer)
 {
-	unsigned long cfg, cmp, now;
+	unsigned long cfg;
 	uint64_t delta;
 
 	switch (mode) {
 	case CLOCK_EVT_MODE_PERIODIC:
+		hpet_stop_counter();
 		delta = ((uint64_t)(NSEC_PER_SEC/HZ)) * evt->mult;
 		delta >>= evt->shift;
-		now = hpet_readl(HPET_COUNTER);
-		cmp = now + (unsigned long) delta;
 		cfg = hpet_readl(HPET_Tn_CFG(timer));
 		/* Make sure we use edge triggered interrupts */
 		cfg &= ~HPET_TN_LEVEL;
 		cfg |= HPET_TN_ENABLE | HPET_TN_PERIODIC |
 		       HPET_TN_SETVAL | HPET_TN_32BIT;
 		hpet_writel(cfg, HPET_Tn_CFG(timer));
-		/*
-		 * The first write after writing TN_SETVAL to the
-		 * config register sets the counter value, the second
-		 * write sets the period.
-		 */
-		hpet_writel(cmp, HPET_Tn_CMP(timer));
-		udelay(1);
 		hpet_writel((unsigned long) delta, HPET_Tn_CMP(timer));
+		hpet_start_counter();
 		hpet_print_config();
 		break;
 
Signature · 1 line
1.6.1.3
#4 lore raw

Re: [PATCH 3/3] x86: hpet: stop HPET_COUNTER when programming periodic mode

Quoted 11 lines · Andreas Herrmann

Impact: fix system hang on some systems operating with HZ_1000

On a system that stalled with HZ_1000, the first value written to T0_CMP (when the main counter was not stopped) did not trigger an interrupt. Instead after the main counter wrapped around (after several minutes) an interrupt was triggered and afterwards the periodic interrupt took effect.

This can be fixed by implementing HPET spec recommendation for programming the periodic mode (i.e. stopping the main counter).

Hi Ingo,

Please don't push this commit to Linus' tree.
Currently it's in tip:timers/hpet.

The patch didn't fix the problem that Mark Hounshell was reporting.

But first of all the patch might have side-effects as all hpet timers that are affect when the main counter is stopped and reset. And furthermore I have learned that there might have been hpet implementations that require the second write (w/o HPET_TN_SETVAL bit) to happen.

I am looking for a different solution.

Thanks,

Andreas

Applied
#5 lore raw
In reply to Andreas Herrmann
Quoted 5 lines · Andreas Herrmann

- to print HPET registers during setup,
- to fix a real issue with HZ_1000 kernels on an SB400 system (and to potentially fix a similar issue with SB600).

Tested on ICH7 and on AMD SB400, AMD SB600.

applied to tip:timers/hpet, thanks Andreas!

Btw, maybe the HZ_1000 bugfix could be the fix for a weirdness i'm seeing very rarely on one of my testsystems:

[    8.850706] bus: 'pci': driver_probe_device: matched device 0000:04:00.0 with driver e1000e
[    8.850706] bus: 'pci': really_probe: probing driver e1000e with device 0000:04:00.0
[  177.308165] e1000e 0000:04:00.0: PCI INT A -> GSI 17 (level, low) -> IRQ 17
[  177.668182] e1000e 0000:04:00.0: setting latency timer to 64

there's almost 3 minutes between those lines printed, although it should have taken milliseconds!

Ingo