linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* RE: Bogomips and loops_per_jiffy
@ 2002-05-08 16:53 Jean-Denis Boyer
  2002-05-08 17:43 ` Benjamin Herrenschmidt
  2002-05-08 18:06 ` Troy Benjegerdes
  0 siblings, 2 replies; 23+ messages in thread
From: Jean-Denis Boyer @ 2002-05-08 16:53 UTC (permalink / raw)
  To: 'Troy Benjegerdes'
  Cc: trini, mgreer, 'Jim Thompson', linuxppc-embedded

[-- Attachment #1: Type: text/plain, Size: 762 bytes --]


Troy,
with the patch, now, it completely hangs.
The reason is that in timer_interrupt()

	while ((next_dec = tb_ticks_per_jiffy - tb_delta(&jiffy_stamp)) < 0)
{  

Now that next_dec is unsigned, this condition is always false.

Here is another patch I suggest to replace yours.
Its in attachement to this email.
I tested it, and it seems OK.

I did not include your modification made to the type of local variables in
function do_settimeofday().
I do not see how it is related to our problem.


--------------------------------------------
 Jean-Denis Boyer, B.Eng., System Architect
 Mediatrix Telecom Inc.
 4229 Garlock Street
 Sherbrooke (Québec)
 J1L 2C8  CANADA
 (819)829-8749 x241
--------------------------------------------


[-- Attachment #2: patch.time.2 --]
[-- Type: application/octet-stream, Size: 1113 bytes --]

--- Kernel.orig/arch/ppc/kernel/time.c	Mon Apr 22 12:19:05 2002
+++ Kernel/arch/ppc/kernel/time.c	Wed May  8 12:46:57 2002
@@ -99,8 +99,8 @@
 EXPORT_SYMBOL(rtc_lock);
 
 /* Timer interrupt helper function */
-static inline int tb_delta(unsigned *jiffy_stamp) {
-	int delta;
+static inline unsigned tb_delta(unsigned *jiffy_stamp) {
+	unsigned delta;
 	if (__USE_RTC()) {
 		delta = get_rtcl();
 		if (delta < *jiffy_stamp) *jiffy_stamp -= 1000000000;
@@ -150,7 +150,7 @@
  */
 int timer_interrupt(struct pt_regs * regs)
 {
-	int next_dec;
+	unsigned next_dec;
 	unsigned long cpu = smp_processor_id();
 	unsigned jiffy_stamp = last_jiffy_stamp(cpu);
 	extern void do_IRQ(struct pt_regs *);
@@ -160,7 +160,13 @@
 
 	hardirq_enter(cpu);
 	
-	while ((next_dec = tb_ticks_per_jiffy - tb_delta(&jiffy_stamp)) < 0) {
+	while(1) {
+		unsigned delta = tb_delta(&jiffy_stamp);
+		if(tb_ticks_per_jiffy >= delta) {
+			next_dec = tb_ticks_per_jiffy - delta;
+			break;
+		}
+
 		jiffy_stamp += tb_ticks_per_jiffy;
 		if (!user_mode(regs))
 			ppc_do_profile(instruction_pointer(regs));

^ permalink raw reply	[flat|nested] 23+ messages in thread
* RE: Bogomips and loops_per_jiffy
@ 2002-05-10 14:54 Jean-Denis Boyer
  2002-05-10 20:15 ` Gabriel Paubert
  0 siblings, 1 reply; 23+ messages in thread
From: Jean-Denis Boyer @ 2002-05-10 14:54 UTC (permalink / raw)
  To: 'Gabriel Paubert'
  Cc: 'Troy Benjegerdes', 'Benjamin Herrenschmidt',
	'linuxppc-embedded@lists.linuxppc.org',
	'Paul Mackerras'


Gabriel, (sorry to all for the previous incomplete mail!)

> I don't yet understand this explanation. Jiffy stamp is
> initialized in time_init, in the line:
>
> last_jiffy_stamp(0) = tb_last_stamp = stamp;
>
> and then jiffy_stamp is simply a temporary copy of
> last_jiffy_stamp in the interrupt handler.

Mmmm! You are right! I was annoyed of always getting the message,
 "Warning: real time clock seems stuck!"
and it also caused a 1-2 seconds delay before getting something printed to
the serial port on boot up. So I set the value of ppc_md.get_rtc_time to
NULL, since I have no RTC. That is why I never enter this code in time_init.
It correctly removed the annoying message, but brought this insidious bug.

Regards,

--------------------------------------------
 Jean-Denis Boyer, B.Eng., System Architect
 Mediatrix Telecom Inc.
 4229 Garlock Street
 Sherbrooke (Québec)
 J1L 2C8  CANADA
 (819)829-8749 x241
--------------------------------------------

** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/

^ permalink raw reply	[flat|nested] 23+ messages in thread
* RE: Bogomips and loops_per_jiffy
@ 2002-05-10 14:46 Jean-Denis Boyer
  0 siblings, 0 replies; 23+ messages in thread
From: Jean-Denis Boyer @ 2002-05-10 14:46 UTC (permalink / raw)
  To: 'Gabriel Paubert'
  Cc: Troy Benjegerdes, Benjamin Herrenschmidt, linuxppc-embedded,
	Paul Mackerras


Gabriel,


Warning: real time clock seems stuck!
> -----Original Message-----
> From: Gabriel Paubert [mailto:paubert@iram.es]
> Sent: 10 mai, 2002 10:29
> To: Jean-Denis Boyer
> Cc: Troy Benjegerdes; Benjamin Herrenschmidt;
> linuxppc-embedded@lists.linuxppc.org; Paul Mackerras
> Subject: RE: Bogomips and loops_per_jiffy
>
>
>
>
> On Fri, 10 May 2002, Jean-Denis Boyer wrote:
>
> >
> > Grabiel,
> >
> > > I'm afraid that this is a symptom of lost timekeeping
> > > after reading the RTC and that you simply cure the symptom.
> >
> > My platform uses an 8260 processor, and AFAIK there is no
> RTC. The function
> > __USE_RTC() returns 0.
>
> OOPs, sorry for the confusion, by RTC I meant the chip with a battery
> which keeps time across reboots and that we read to initially set the
> system time.
>
> 	Gabriel.
>
>

** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/

^ permalink raw reply	[flat|nested] 23+ messages in thread
* RE: Bogomips and loops_per_jiffy
@ 2002-05-10 14:15 Petersen, David (MED, GEMS-IT)
  0 siblings, 0 replies; 23+ messages in thread
From: Petersen, David (MED, GEMS-IT) @ 2002-05-10 14:15 UTC (permalink / raw)
  To: 'Jean-Denis Boyer', 'Gabriel Paubert'
  Cc: Troy Benjegerdes, Benjamin Herrenschmidt, linuxppc-embedded,
	Paul Mackerras


	On the 8xx processors that I use the tb is not reset by Hard or
Soft reset (per Motorla manual), therefore it is required to set the tb
to achieve consistant operation. My system will hang periodically and
whenever it does the initial decrementer value has been set to a huge
value eg 0xFD842356.



-----Original Message-----
From: Jean-Denis Boyer [mailto:jdboyer@mediatrix.com]
Sent: Friday, May 10, 2002 9:11 AM
To: 'Gabriel Paubert'
Cc: Troy Benjegerdes; Benjamin Herrenschmidt;
linuxppc-embedded@lists.linuxppc.org; Paul Mackerras
Subject: RE: Bogomips and loops_per_jiffy



Grabiel,

> I'm afraid that this is a symptom of lost timekeeping
> after reading the RTC and that you simply cure the symptom.

My platform uses an 8260 processor, and AFAIK there is no RTC. The
function
__USE_RTC() returns 0.

> Better set the TB to a large value to force the problem and
> see if you can reproduce it.

That's exactly the way I reproduced it!... and why I initially proposed
the
fix set_tb(0,0).

If you add a set_tb(0, 0x90000000) at the beginning of time_init, you
will
fall right into it.

The problem occurs only when the TBL is initially over 0x80000000. Then,
when compared against jiffy_stamp (unsigned, initially 0), and
transformed
into a signed integer, it returns a negative delta, causing the while
loop
in the time_interrupt to be left, and the decrementer set to a very high
value.

Yes, pratically, it will never happen at run time. Anyway, the
decrementer
and the time base count at the same rate, so they share the same
constraints.

At boot time, however, it is platform specific... usually, after a cold
boot, the TB is reset to 0. But after a warm reset, this is not
necessarily
true. Does the boot load resets the time base? The boot loader can also
take
a long time to get the kernel in place and jump to it, for example after
a
heavy hardware testing (RAM and peripherals), or an inefficient TFTP
download... Well, any weird reason you can imagine that slows down the
boot
time only by a few minutes. ;-)

Regards,

--------------------------------------------
 Jean-Denis Boyer, B.Eng., System Architect
 Mediatrix Telecom Inc.
 4229 Garlock Street
 Sherbrooke (Québec)
 J1L 2C8  CANADA
 (819)829-8749 x241
--------------------------------------------


** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/

^ permalink raw reply	[flat|nested] 23+ messages in thread
* RE: Bogomips and loops_per_jiffy
@ 2002-05-10 14:10 Jean-Denis Boyer
  2002-05-10 14:23 ` Allen Curtis
                   ` (2 more replies)
  0 siblings, 3 replies; 23+ messages in thread
From: Jean-Denis Boyer @ 2002-05-10 14:10 UTC (permalink / raw)
  To: 'Gabriel Paubert'
  Cc: Troy Benjegerdes, Benjamin Herrenschmidt, linuxppc-embedded,
	Paul Mackerras


Grabiel,

> I'm afraid that this is a symptom of lost timekeeping
> after reading the RTC and that you simply cure the symptom.

My platform uses an 8260 processor, and AFAIK there is no RTC. The function
__USE_RTC() returns 0.

> Better set the TB to a large value to force the problem and
> see if you can reproduce it.

That's exactly the way I reproduced it!... and why I initially proposed the
fix set_tb(0,0).

If you add a set_tb(0, 0x90000000) at the beginning of time_init, you will
fall right into it.

The problem occurs only when the TBL is initially over 0x80000000. Then,
when compared against jiffy_stamp (unsigned, initially 0), and transformed
into a signed integer, it returns a negative delta, causing the while loop
in the time_interrupt to be left, and the decrementer set to a very high
value.

Yes, pratically, it will never happen at run time. Anyway, the decrementer
and the time base count at the same rate, so they share the same
constraints.

At boot time, however, it is platform specific... usually, after a cold
boot, the TB is reset to 0. But after a warm reset, this is not necessarily
true. Does the boot load resets the time base? The boot loader can also take
a long time to get the kernel in place and jump to it, for example after a
heavy hardware testing (RAM and peripherals), or an inefficient TFTP
download... Well, any weird reason you can imagine that slows down the boot
time only by a few minutes. ;-)

Regards,

--------------------------------------------
 Jean-Denis Boyer, B.Eng., System Architect
 Mediatrix Telecom Inc.
 4229 Garlock Street
 Sherbrooke (Québec)
 J1L 2C8  CANADA
 (819)829-8749 x241
--------------------------------------------

** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/

^ permalink raw reply	[flat|nested] 23+ messages in thread
* RE: Bogomips and loops_per_jiffy
@ 2002-05-08 18:30 Jean-Denis Boyer
  0 siblings, 0 replies; 23+ messages in thread
From: Jean-Denis Boyer @ 2002-05-08 18:30 UTC (permalink / raw)
  To: 'Benjamin Herrenschmidt'
  Cc: 'Troy Benjegerdes', linuxppc-embedded, paulus,
	Gabriel Paubert


Benjamin,

> I'd rather
> change the test from >= to > (which in the old could would mean
> changing the while (... < 0 to <= 0) as I see no reason to trigger
> a new decrementer interrupt in ... 0 ticks !

I think I did not change the previous 'while' logic.
It said:
    while ( diff < 0 )

Now it says:
    while ( 1 ) {
        if ( diff >= 0 )
            break;

Previously, the while could be left for a next_dec of 0.
But I agree with you: it could be changed.
Why leaving the loop just to set the decrementer to 0!?

--------------------------------------------
 Jean-Denis Boyer, B.Eng., System Architect
 Mediatrix Telecom Inc.
 4229 Garlock Street
 Sherbrooke (Québec)
 J1L 2C8  CANADA
 (819)829-8749 x241
--------------------------------------------

** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/

^ permalink raw reply	[flat|nested] 23+ messages in thread
* RE: Bogomips and loops_per_jiffy
@ 2002-05-06 21:17 Jean-Denis Boyer
  2002-05-08  0:48 ` Troy Benjegerdes
  0 siblings, 1 reply; 23+ messages in thread
From: Jean-Denis Boyer @ 2002-05-06 21:17 UTC (permalink / raw)
  To: 'Jim Thompson'; +Cc: linuxppc-embedded


Jim,

I have found a fix for the hanging "Calibrating delay loop...".

I added the following line at the beginning of
the function "time_init" in arch/ppc/kernel/time.c

  set_tb(0, 0);

This resets the time base register and avoids the timer interrupt
to set the second decrementer value to a very large one.
It happens only when the TBL is large.

This is a quick fix. Because I think it should work
for any value of TB. It looks like that part of the code
does not correctly support the overflow.

Looking through the code, I wonder why the return value of
the function "tb_delta" is signed.


--------------------------------------------
 Jean-Denis Boyer, B.Eng., System Architect
 Mediatrix Telecom Inc.
 4229 Garlock Street
 Sherbrooke (Québec)
 J1L 2C8  CANADA
 (819)829-8749 x241
--------------------------------------------


> -----Original Message-----
> From: Jean-Denis Boyer [mailto:jdboyer@mediatrix.com]
> Sent: 22 avril, 2002 11:58
> To: 'Jim Thompson'
> Cc: linuxppc-embedded@lists.linuxppc.org
> Subject: RE: Bogomips and loops_per_jiffy
>
>
>
> Jim
>
> > I've noticed that about half the time, the kernels I build
> take what I
> > think is a long time (> 20 seconds) in calibrate_delay().
>
> I have exactly the same problem with my custom board using an 8260.
> At every 5-10 times I start the kernel, it hangs on
> 'Calibrating delay loop...' for about 1 minute, and then yields
> the same result (130.66 BogoMips).
>
> I begun to try to debug that problem, but without any success yet. :-(
> I've searched through the mailing lists, but did not find anything of
> interest.
>
> This problem is very annoying and I really want to fix it!
>
>
> --------------------------------------------
>  Jean-Denis Boyer, B.Eng., System Architect
>  Mediatrix Telecom Inc.
>  4229 Garlock Street
>  Sherbrooke (Québec)
>  J1L 2C8  CANADA
>  (819)829-8749 x241
> --------------------------------------------
>

** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/

^ permalink raw reply	[flat|nested] 23+ messages in thread
* RE: Bogomips and loops_per_jiffy
@ 2002-04-22 15:57 Jean-Denis Boyer
  0 siblings, 0 replies; 23+ messages in thread
From: Jean-Denis Boyer @ 2002-04-22 15:57 UTC (permalink / raw)
  To: 'Jim Thompson'; +Cc: linuxppc-embedded


Jim

> I've noticed that about half the time, the kernels I build take what I
> think is a long time (> 20 seconds) in calibrate_delay().

I have exactly the same problem with my custom board using an 8260.
At every 5-10 times I start the kernel, it hangs on
'Calibrating delay loop...' for about 1 minute, and then yields
the same result (130.66 BogoMips).

I begun to try to debug that problem, but without any success yet. :-(
I've searched through the mailing lists, but did not find anything of
interest.

This problem is very annoying and I really want to fix it!


--------------------------------------------
 Jean-Denis Boyer, B.Eng., System Architect
 Mediatrix Telecom Inc.
 4229 Garlock Street
 Sherbrooke (Québec)
 J1L 2C8  CANADA
 (819)829-8749 x241
--------------------------------------------

** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/

^ permalink raw reply	[flat|nested] 23+ messages in thread
* Bogomips and loops_per_jiffy
@ 2002-04-19 11:57 Jim Thompson
  0 siblings, 0 replies; 23+ messages in thread
From: Jim Thompson @ 2002-04-19 11:57 UTC (permalink / raw)
  To: linuxppc-embedded


I've noticed that about half the time, the kernels I build take what I
think is a long time (> 20 seconds) in calibrate_delay().

That is, there is quite a pause between
    Calibrating delay loop...
and (the answer, of sorts)
    133.12 BogoMIPS

    => bootm ff800000
    ## Booting image at ff800000 ...
       Image Name:   Musenki kernel 2.4.19pre1
       Image Type:   PowerPC Linux Kernel Image (gzip compressed)
       Data Size:    674330 Bytes = 658 kB = 0 MB
       Load Address: 00000000
       Entry Point:  00000000
       Verifying Checksum ... OK
       Uncompressing Kernel Image ... OK
    Memory BAT mapping: BAT2=32Mb, BAT3=0Mb, residual: 0Mb
    Linux version 2.4.19pre1 (jim@ford) (gcc version 2.95.4 20011002 (Debian prerelease)) #4 Fri Apr 19 05:58:00 CDT 2002
    Musenki M3/M1: See www.musenki.com for details
    On node 0 totalpages: 8192
    zone(0): 8192 pages.
    zone(1): 0 pages.
    zone(2): 0 pages.
    Kernel command line: root=/dev/nfs rw nfsroot=192.168.0.8:/usr/local/m1_nfsroot ip=192.168.0.42:192.168.0.8:192.168.0.1:255.255.255.0:fuckme::off
    OpenPIC Version 1.2 (1 CPUs and 138 IRQ sources) at fc040000
    time_init: decrementer frequency = 25.000000 MHz
    Calibrating delay loop... 133.12 BogoMIPS
    Memory: 30452k available (1200k kernel code, 480k data, 88k init, 0k highmem)
    Dentry-cache hash table entries: 4096 (order: 3, 32768 bytes)
    Inode-cache hash table entries: 2048 (order: 2, 16384 bytes)
    Mount-cache hash table entries: 512 (order: 0, 4096 bytes)
    Buffer-cache hash table entries: 1024 (order: 0, 4096 bytes)
    Page-cache hash table entries: 8192 (order: 3, 32768 bytes)
    POSIX conformance testing by UNIFIX
    PCI: Probing PCI hardware
    [...]

I, as on so many other machines in arch/ppc/platforms/, set

	loops_per_jiffy = 50000000 / HZ;

as the first line of musenki_setup_arch(), though I've tried
"100000000 / HZ;" with no difference in effect.

Interestingly, loops_per_jiffy is apparently over-written when
calibrate_delay() is called:

    void __init calibrate_delay(void)
    {
	    unsigned long ticks, loopbit;
	    int lps_precision = LPS_PREC;

	    loops_per_jiffy = (1<<12);

	    printk("Calibrating delay loop... ");
	    while (loops_per_jiffy <<= 1) {
		    /* wait for "start of" clock tick */
		    ticks = jiffies;
		    while (ticks == jiffies)
			    /* nothing */;
		    /* Go .. */
		    ticks = jiffies;
		    __delay(loops_per_jiffy);
		    ticks = jiffies - ticks;
		    if (ticks)
			    break;
	    }

    /* Do a binary approximation to get loops_per_jiffy set to equal one clock
       (up to lps_precision bits) */
	    loops_per_jiffy >>= 1;
	    loopbit = loops_per_jiffy;
	    while ( lps_precision-- && (loopbit >>= 1) ) {
		    loops_per_jiffy |= loopbit;
		    ticks = jiffies;
		    while (ticks == jiffies);
		    ticks = jiffies;
		    __delay(loops_per_jiffy);
		    if (jiffies != ticks)   /* longer than 1 tick */
			    loops_per_jiffy &= ~loopbit;
	    }

    /* Round the value and print it */
	    printk("%lu.%02lu BogoMIPS\n",
		    loops_per_jiffy/(500000/HZ),
		    (loops_per_jiffy/(5000/HZ)) % 100);
    }



anyone have a clue to offer?

Jim


** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/

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

end of thread, other threads:[~2002-05-11  2:08 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-05-08 16:53 Bogomips and loops_per_jiffy Jean-Denis Boyer
2002-05-08 17:43 ` Benjamin Herrenschmidt
2002-05-08 22:13   ` Gabriel Paubert
2002-05-09 15:08     ` Troy Benjegerdes
2002-05-09 16:16       ` Gabriel Paubert
2002-05-08 18:06 ` Troy Benjegerdes
  -- strict thread matches above, loose matches on Subject: below --
2002-05-10 14:54 Jean-Denis Boyer
2002-05-10 20:15 ` Gabriel Paubert
2002-05-10 21:16   ` Benjamin Herrenschmidt
2002-05-11  2:08     ` Gabriel Paubert
2002-05-10 14:46 Jean-Denis Boyer
2002-05-10 14:15 Petersen, David (MED, GEMS-IT)
2002-05-10 14:10 Jean-Denis Boyer
2002-05-10 14:23 ` Allen Curtis
2002-05-10 15:06   ` Jerry Van Baren
2002-05-10 14:27 ` Gabriel Paubert
2002-05-10 14:29 ` Gabriel Paubert
2002-05-10 14:39   ` Allen Curtis
2002-05-08 18:30 Jean-Denis Boyer
2002-05-06 21:17 Jean-Denis Boyer
2002-05-08  0:48 ` Troy Benjegerdes
2002-04-22 15:57 Jean-Denis Boyer
2002-04-19 11:57 Jim Thompson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).