Red Hat axp-list: Linux on Alpha (1995-2022)
 help / color / mirror / Atom feed
From: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
To: axp-list@redhat.com
Subject: Re: Hangs with 100baseTX, RedHat 7.1, kernel 2.4.x and AlphaPC 164
Date: Fri, 5 Oct 2001 14:31:30 +0400	[thread overview]
Message-ID: <20011005143130.A10419@jurassic.park.msu.ru> (raw)
In-Reply-To: <20011004182610.A8689@linux04.mro.cpqcorp.net>; from Jay.Estabrook@compaq.com on Thu, Oct 04, 2001 at 06:26:10PM -0400

On Thu, Oct 04, 2001 at 06:26:10PM -0400, Jay Estabrook wrote:
> I think maybe Ivan has some patches that do a better job in that area,
> and I know he's going to submit them soon. Maybe he'll post them here
> for some additional testing... :-) :-)

Sure, especially because my latest patch doesn't work on a pc164,
as Richard reported. :-(
So I would return to my previous thought - compare the measured frequency
with one reported in the hwrpb and return failure if we see twofold or higher
difference. Also emergency timeout added, as you suggested.

Ivan.

--- 2.4.10/arch/alpha/kernel/time.c	Fri Oct  5 13:43:01 2001
+++ linux/arch/alpha/kernel/time.c	Fri Oct  5 13:53:20 2001
@@ -170,28 +170,28 @@ common_init_rtc(void)
 }
 
 /*
- * Calibrate CPU clock using legacy 8254 timer/counter. Stolen from
- * arch/i386/time.c.
+ * Calibrate CPU clock using legacy 8254 programmable interval timer.
+ * Based on arch/i386/time.c.
  */
 
-#define CALIBRATE_LATCH	(52 * LATCH)
-#define CALIBRATE_TIME	(52 * 1000020 / HZ)
+#define CALIBRATE_LATCH	0xffff
+#define TIMEOUT_COUNT	0x100000
 
 static unsigned long __init
-calibrate_cc_with_pic(void)
+calibrate_cc_with_pit(void)
 {
-	int cc;
-	unsigned long count = 0;
+	int cc, count = 0;
+	unsigned long freq, hwrpbfreq = hwrpb->cycle_freq;
 
 	/* Set the Gate high, disable speaker */
 	outb((inb(0x61) & ~0x02) | 0x01, 0x61);
 
 	/*
-	 * Now let's take care of CTC channel 2
+	 * Now let's take care of PIT channel 2
 	 *
-	 * Set the Gate high, program CTC channel 2 for mode 0,
+	 * Set the Gate high, program PIT channel 2 for mode 0,
 	 * (interrupt on terminal count mode), binary count,
-	 * load 5 * LATCH count, (LSB and MSB) to begin countdown.
+	 * load CALIBRATE_LATCH count (LSB and MSB) to begin countdown.
 	 */
 	outb(0xb0, 0x43);		/* binary, mode 0, LSB/MSB, Ch 2 */
 	outb(CALIBRATE_LATCH & 0xff, 0x42);	/* LSB of count */
@@ -200,29 +200,23 @@ calibrate_cc_with_pic(void)
 	cc = rpcc();
 	do {
 		count++;
-	} while ((inb(0x61) & 0x20) == 0);
+	} while (!(inb(0x61) & 0x20) && count < TIMEOUT_COUNT);
 	cc = rpcc() - cc;
 
-	/* Error: ECTCNEVERSET */
-	if (count <= 1)
-		goto bad_ctc;
-
-	/* Error: ECPUTOOFAST */
-	if (count >> 32)
-		goto bad_ctc;
-
-	/* Error: ECPUTOOSLOW */
-	if (cc <= CALIBRATE_TIME)
-		goto bad_ctc;
+	/* Error: EPITNEVERSET or ECPUTOOFAST */
+	if (count <= 1 || count == TIMEOUT_COUNT)
+		goto bad_pit;
+
+	freq = ((long)cc * CLOCK_TICK_RATE) / (CALIBRATE_LATCH + 1);
+
+	/* CPU cycle frequency reported in the hwrpb is often bogus.
+	   However, even in the worst case the difference shouldn't
+	   exceed 30-40%, so we can still use hwrpb value to validate
+	   the frequency we've found with PIT. */
+	if ((max(freq, hwrpbfreq) + 1) / (min(freq, hwrpbfreq) + 1) < 2)
+		return freq;
 
-	return ((long)cc * 1000000) / CALIBRATE_TIME;
-
-	/*
-	 * The CTC wasn't reliable: we got a hit on the very first read,
-	 * or the CPU was so fast/slow that the quotient wouldn't fit in
-	 * 32 bits..
-	 */
- bad_ctc:
+ bad_pit:
 	return 0;
 }
 
@@ -249,7 +243,7 @@ time_init(void)
 
 	/* Calibrate CPU clock -- attempt #1.  */
 	if (!est_cycle_freq)
-		est_cycle_freq = calibrate_cc_with_pic();
+		est_cycle_freq = calibrate_cc_with_pit();
 
 	cc1 = rpcc_after_update_in_progress();
 




  parent reply	other threads:[~2001-10-05 10:31 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-10-04 15:12 Hangs with 100baseTX, RedHat 7.1, kernel 2.4.x and AlphaPC 164 Mads Peter Bach
2001-10-04 15:28 ` Jay Estabrook
2001-10-04 19:21   ` Mads Peter Bach
2001-10-04 22:26     ` Jay Estabrook
2001-10-04 23:02       ` Mads Peter Bach
2001-10-05 10:31       ` Ivan Kokshaysky [this message]
2001-10-07  7:48         ` Richard Henderson
2001-10-07 17:29           ` Jay Estabrook
2001-10-08  7:28             ` Richard Henderson
2001-10-08 14:39               ` Ivan Kokshaysky
2001-10-04 17:09 ` Michal Jaegermann
2001-10-04 18:30   ` Jay Estabrook
  -- strict thread matches above, loose matches on Subject: below --
2001-10-05 13:17 Jemiolo, John
read-only archive

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