From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.redhat.com (mail.redhat.com [199.183.24.239]) by listman.redhat.com (Postfix) with ESMTP id 8FF512F00B for ; Fri, 5 Oct 2001 06:31:45 -0400 (EDT) Received: (from mail@localhost) by mail.redhat.com (8.11.0/8.8.7) id f95AVjE05594 for axp-list@listman.redhat.com; Fri, 5 Oct 2001 06:31:45 -0400 Received: from jurassic.park.msu.ru (jurassic.park.msu.ru [195.208.223.243]) by mail.redhat.com (8.11.0/8.8.7) with ESMTP id f95AVig05588 for ; Fri, 5 Oct 2001 06:31:44 -0400 Received: (from ink@localhost) by jurassic.park.msu.ru (8.11.2/8.11.2) id f95AVVC10485 for axp-list@redhat.com; Fri, 5 Oct 2001 14:31:31 +0400 Date: Fri, 5 Oct 2001 14:31:30 +0400 From: Ivan Kokshaysky To: axp-list@redhat.com Subject: Re: Hangs with 100baseTX, RedHat 7.1, kernel 2.4.x and AlphaPC 164 Message-ID: <20011005143130.A10419@jurassic.park.msu.ru> References: <055501c14ce7$08153b10$2df958c1@mpb> <20011004112846.A8133@linux04.mro.cpqcorp.net> <3BBCB6E3.F2E5C0@alpha.lists.logout.sh> <20011004182610.A8689@linux04.mro.cpqcorp.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <20011004182610.A8689@linux04.mro.cpqcorp.net>; from Jay.Estabrook@compaq.com on Thu, Oct 04, 2001 at 06:26:10PM -0400 X-Loop: axp-list@redhat.com Sender: axp-list-admin@redhat.com Errors-To: axp-list-admin@redhat.com X-BeenThere: axp-list@redhat.com X-Mailman-Version: 2.0.1 Precedence: bulk Reply-To: axp-list@redhat.com List-Help: List-Post: List-Subscribe: , List-Id: Linux and Red Hat on Alpha processors List-Unsubscribe: , List-Archive: 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();