From: Csdncannon <csdncannon@gmail.com>
To: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: linuxppc-dev@ozlabs.org, Arnd Bergmann <arnd@arndb.de>
Subject: Re: Continual reading from the PowerPc time base register is not stable
Date: Fri, 26 Mar 2010 10:04:35 +0800 [thread overview]
Message-ID: <43c137a81003251904ged9f17fof65e74bc766167d@mail.gmail.com> (raw)
In-Reply-To: <1269568527.8599.259.camel@pasglop>
[-- Attachment #1.1: Type: text/plain, Size: 4760 bytes --]
Ben
Attached is the previous failing one.
Thanks
Gino
2010/3/26 Benjamin Herrenschmidt <benh@kernel.crashing.org>
> On Fri, 2010-03-26 at 09:11 +0800, Csdncannon wrote:
> > After trying the new code with "isync" and unsigned long long
> > convertion, this problem doesn't happen(I tested for several minutes).
> > But the previous block of codes(lacking of isync) is borrowed from
> > kernel. And if this is a bug of kernel?
>
> There's an outstanding question about that. Some processors make mftb
> context synchronizing but it appears that it may not be the case for all
> of them.
>
> Thus indeed, we -might- need some isync's in some places, it's not
> totally clear to me though.
>
> Can you send the code that fails (without the isync) ? The one you sent
> did have them everywhere.
>
> Cheers,
> Ben.
>
> > Thanks
> > Gino
> >
> > 2010/3/26 Benjamin Herrenschmidt <benh@kernel.crashing.org>
> > On Thu, 2010-03-25 at 23:00 +0800, Csdncannon wrote:
> > > I am really sorry that the previously attached code is
> > wrong, this one
> > > "timebase.c" is the right one, and the "log_timebase" file
> > is the
> > > right log.
> > >
> > > We are using FreeScale PowerPc 8378, kernel 2.6.28 and
> > compiled as
> > > 32-bit.
> >
> >
> > And despite all those sync/isync you can still observe the
> > timebase
> > going backward ? That sounds scary. However, at this stage all
> > I can
> > suggest is getting freescale folks to have a look, as this
> > should really
> > not happen. Maybe there's some setting with that specific SoC
> > that is
> > missing or similar...
> >
> > Cheers,
> > Ben.
> >
> >
> > >
> > > Thanks
> > > Gino
> > >
> > > 2010/3/25 Arnd Bergmann <arnd@arndb.de>
> > > On Thursday 25 March 2010, Benjamin Herrenschmidt
> > wrote:
> > > > On Thu, 2010-03-25 at 10:41 +0800, Csdncannon
> > wrote:
> > > > > In my program, the value of the 64-bit
> > time base
> > > register is
> > > > > read out, and you will find the later value is
> > even
> > > smaller than the
> > > > > earlier value from the log “log_timebase”. While
> > the
> > > kernel depends on
> > > > > the accuracy of the timebase for the
> > compensation of the
> > > lost PIT
> > > > > interrupt, the negative value between two
> > continual
> > > timebase reading
> > > > > will bring to the jump of the jiffies. And this
> > timebase
> > > problem will
> > > > > bring to the instability of the gettimeofday
> > system call.
> > > > >
> > > > > Do you have any idea about this
> > problem, thanks
> > > for your any
> > > > > advice. Attached is the code and log.
> > > >
> > > > This is a concern, it should definitely not
> > happen. What
> > > machine is
> > > > that ? is the code compiled 32-bit or 64-bit ?
> > What kernel
> > > version ?
> > > >
> > > > Arnd, any chance that could relate to the bug
> > you've been
> > > chasing on
> > > > Cell ?
> > >
> > >
> > > We're still busy with the problem analysis on Cell,
> > waiting
> > > for a time
> > > slot to run the next test kernel. So far it seems
> > like the
> > > timebase
> > > is actually synchronized at a significant accuracy
> > on QS22 to
> > > never
> > > cause this problem with correct code, however it is
> > possible
> > > to
> > > observe incorrect timebase values on Cell whenever
> > the mftb
> > > instruction
> > > is not serialized with memory accesses, e.g. by
> > using an isync
> > > in front
> > > of the mftb. On Power6 and other CPUs, that problem
> > will not
> > > happen.
> > >
> > > Arnd
> > >
> >
> >
> >
> >
>
>
>
[-- Attachment #1.2: Type: text/html, Size: 6088 bytes --]
[-- Attachment #2: timebase.c --]
[-- Type: application/octet-stream, Size: 1576 bytes --]
/* TSC sync test
* by: john stultz (johnstul@us.ibm.com)
* (C) Copyright IBM 2003, 2005
* Licensed under the GPL
*/
#include <stdio.h>
#include <sys/time.h>
#include <stdlib.h>
#define CALLS_PER_LOOP 64
volatile unsigned long long getTimeBase()
{
unsigned long upper,lower,upper2;
do {
asm volatile("sync":::"memory");
asm volatile("mftbu %0" : "=r" (upper));
asm volatile("sync":::"memory");
asm volatile("mftbl %0" : "=r" (lower));
asm volatile("sync":::"memory");
asm volatile("mftbu %0" : "=r" (upper2));
asm volatile("sync":::"memory");
}while(upper2!=upper);
return (upper<<32)|lower;
}
int main(int argc, char *argv[])
{
volatile unsigned long long list[CALLS_PER_LOOP];
bool bad[CALLS_PER_LOOP];
int i, inconsistent;
/* timestamp start of test */
system("date");
while(1){
inconsistent = 0;
/* Fill list */
for(i=0; i < CALLS_PER_LOOP; i++)
list[i] = getTimeBase();
/* Check for inconsistencies */
for(i=0; i < CALLS_PER_LOOP-1; i++)
{
if(list[i] > list[i+1])
{
inconsistent = i+1;
bad[i] = true;
}
else{
bad[i] = false;
}
}
/* display inconsistency */
if(inconsistent){
inconsistent--;
for(i=0; i < CALLS_PER_LOOP; i++){
if(bad[i] == true)
printf("--------------------\n");
printf("0x%llx\n",list[i]);
if(bad[i-1] == true && bad[i] == false )
printf("--------------------\n");
}
fflush(0);
/* timestamp inconsistency*/
system("date");
}
}
return 0;
}
next prev parent reply other threads:[~2010-03-26 2:04 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-03-25 2:41 Continual reading from the PowerPc time base register is not stable Csdncannon
2010-03-25 8:21 ` Benjamin Herrenschmidt
2010-03-25 10:05 ` Arnd Bergmann
2010-03-25 15:00 ` Csdncannon
2010-03-25 20:38 ` Benjamin Herrenschmidt
2010-03-26 1:11 ` Csdncannon
2010-03-26 1:22 ` Segher Boessenkool
2010-03-26 2:01 ` Csdncannon
2010-03-26 8:52 ` Segher Boessenkool
2010-03-26 9:01 ` Segher Boessenkool
2010-03-26 12:14 ` Csdncannon
2010-04-06 8:02 ` Csdncannon
2010-03-26 1:55 ` Benjamin Herrenschmidt
2010-03-26 2:04 ` Csdncannon [this message]
2010-03-25 22:00 ` Chris Friesen
2010-03-25 22:57 ` Benjamin Herrenschmidt
2010-03-25 23:37 ` Kumar Gala
2010-03-25 21:37 ` Segher Boessenkool
2010-04-10 3:14 ` Csdncannon
2010-04-22 0:44 ` Kim Phillips
2010-04-22 0:50 ` Benjamin Herrenschmidt
2010-04-22 23:27 ` Kim Phillips
2010-04-23 10:57 ` Csdncannon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=43c137a81003251904ged9f17fof65e74bc766167d@mail.gmail.com \
--to=csdncannon@gmail.com \
--cc=arnd@arndb.de \
--cc=benh@kernel.crashing.org \
--cc=linuxppc-dev@ozlabs.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).