Project Home
Project Home
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - ClockCycles Misbehaving: (12 Items)
   
ClockCycles Misbehaving  
Hello,

I am seeing some weird behavior when I run ClockCycles tightly in a loop. ClockCycles should always return increasing 
values, but sometimes it returns a value that's less than the previously returned value.

For example - 

	ThreadCtl(_NTO_TCTL_RUNMASK,(int*) 0x1);
	perror(NULL);

	start = ClockCycles();
	while(1)
	{
		stop = ClockCycles();

		if(start > stop)
		{
			diff = start - stop;
			printf("??? start-%llu, stop-%llu,diff-%llu, iteration - %d\n",start,stop,diff,iter);
			break;
		}
		start = stop;
		iter++;
	}


The iteration at which it happens is widely random. Ranging from 50 to 30000. 

Could this be because of a wrong setup in init_qtime.c inside startup code ? 
Re: ClockCycles Misbehaving  
Are you running a SMP system (>1 CPU or core)? Pidin info output will
confirm.
Andy

On 11-09-28 3:24 PM, "Rohit Nair" <community-noreply@qnx.com> wrote:

>Hello,
>
>I am seeing some weird behavior when I run ClockCycles tightly in a loop.
>ClockCycles should always return increasing values, but sometimes it
>returns a value that's less than the previously returned value.
>
>For example - 
>
>	ThreadCtl(_NTO_TCTL_RUNMASK,(int*) 0x1);
>	perror(NULL);
>
>	start = ClockCycles();
>	while(1)
>	{
>		stop = ClockCycles();
>
>		if(start > stop)
>		{
>			diff = start - stop;
>			printf("??? start-%llu, stop-%llu,diff-%llu, iteration -
>%d\n",start,stop,diff,iter);
>			break;
>		}
>		start = stop;
>		iter++;
>	}
>
>
>The iteration at which it happens is widely random. Ranging from 50 to
>30000. 
>
>Could this be because of a wrong setup in init_qtime.c inside startup
>code ? 
>
>
>
>
>_______________________________________________
>
>OSTech
>http://community.qnx.com/sf/go/post89124
>
Re: ClockCycles Misbehaving  
What cpu/board is this running on?

Rohit Nair wrote:
> Hello,
> 
> I am seeing some weird behavior when I run ClockCycles tightly in a loop. ClockCycles should always return increasing 
values, but sometimes it returns a value that's less than the previously returned value.
> 
> For example - 
> 
> 	ThreadCtl(_NTO_TCTL_RUNMASK,(int*) 0x1);
> 	perror(NULL);
> 
> 	start = ClockCycles();
> 	while(1)
> 	{
> 		stop = ClockCycles();
> 
> 		if(start > stop)
> 		{
> 			diff = start - stop;
> 			printf("??? start-%llu, stop-%llu,diff-%llu, iteration - %d\n",start,stop,diff,iter);
> 			break;
> 		}
> 		start = stop;
> 		iter++;
> 	}
> 
> 
> The iteration at which it happens is widely random. Ranging from 50 to 30000. 
> 
> Could this be because of a wrong setup in init_qtime.c inside startup code ? 
> 
> 
> 
> 
> _______________________________________________
> 
> OSTech
> http://community.qnx.com/sf/go/post89124
> 
Re: ClockCycles Misbehaving  
Either you have 2 or more processors or it just simply wrapping (3 minutes wrapping time on mips)

On 09/28/2011 03:24 PM, Rohit Nair wrote:
> Hello,
> 
> I am seeing some weird behavior when I run ClockCycles tightly in a loop. ClockCycles should always return increasing 
values, but sometimes it returns a value that's less than the previously returned value.
> 
> For example - 
> 
> 	ThreadCtl(_NTO_TCTL_RUNMASK,(int*) 0x1);
> 	perror(NULL);
> 
> 	start = ClockCycles();
> 	while(1)
> 	{
> 		stop = ClockCycles();
> 
> 		if(start > stop)
> 		{
> 			diff = start - stop;
> 			printf("??? start-%llu, stop-%llu,diff-%llu, iteration - %d\n",start,stop,diff,iter);
> 			break;
> 		}
> 		start = stop;
> 		iter++;
> 	}
> 
> 
> The iteration at which it happens is widely random. Ranging from 50 to 30000. 
> 
> Could this be because of a wrong setup in init_qtime.c inside startup code ? 
> 
> 
> 
> 
> _______________________________________________
> 
> OSTech
> http://community.qnx.com/sf/go/post89124
> 
Re: ClockCycles Misbehaving  
But shouldn't the ThreadCtl call fix affinity to CPU0 ? 
Re: ClockCycles Misbehaving  
What is the return value of ThreadCtl() call? I wonder if it failed?

Does the strange behaviour persist when starting the process with on -C0
to fix to CPU0?
e.g.

# on -C0 ./testapp

Andy

On 11-09-28 3:50 PM, "Rohit Nair" <community-noreply@qnx.com> wrote:

>But shouldn't the ThreadCtl call fix affinity to CPU0 ?
>
>
>
>
>_______________________________________________
>
>OSTech
>http://community.qnx.com/sf/go/post89128
>
Re: ClockCycles Misbehaving  
ThreadCtl returns 0. The behavior persists even if I start with 'on -C0'.

> What is the return value of ThreadCtl() call? I wonder if it failed?
> 
> Does the strange behaviour persist when starting the process with on -C0
> to fix to CPU0?
> e.g.
> 
> # on -C0 ./testapp
> 
> Andy
> 
> On 11-09-28 3:50 PM, "Rohit Nair" <community-noreply@qnx.com> wrote:
> 
> >But shouldn't the ThreadCtl call fix affinity to CPU0 ?
> >
> >
> >
> >
> >_______________________________________________
> >
> >OSTech
> >http://community.qnx.com/sf/go/post89128
> >


RE: ClockCycles Misbehaving  
It's already bind to the first CPU.


-----Original Message-----
From: Elena Laskavaia [mailto:community-noreply@qnx.com] 
Sent: Wednesday, September 28, 2011 3:45 PM
To: ostech-core_os
Subject: Re: ClockCycles Misbehaving

Either you have 2 or more processors or it just simply wrapping (3 minutes wrapping time on mips)

On 09/28/2011 03:24 PM, Rohit Nair wrote:
> Hello,
> 
> I am seeing some weird behavior when I run ClockCycles tightly in a loop. ClockCycles should always return increasing 
values, but sometimes it returns a value that's less than the previously returned value.
> 
> For example - 
> 
> 	ThreadCtl(_NTO_TCTL_RUNMASK,(int*) 0x1);
> 	perror(NULL);
> 
> 	start = ClockCycles();
> 	while(1)
> 	{
> 		stop = ClockCycles();
> 
> 		if(start > stop)
> 		{
> 			diff = start - stop;
> 			printf("??? start-%llu, stop-%llu,diff-%llu, iteration - %d\n",start,stop,diff,iter);
> 			break;
> 		}
> 		start = stop;
> 		iter++;
> 	}
> 
> 
> The iteration at which it happens is widely random. Ranging from 50 to 30000. 
> 
> Could this be because of a wrong setup in init_qtime.c inside startup code ? 
> 
> 
> 
> 
> _______________________________________________
> 
> OSTech
> http://community.qnx.com/sf/go/post89124
> 



_______________________________________________

OSTech
http://community.qnx.com/sf/go/post89127
RE: ClockCycles Misbehaving  
Of What type are the variables start and stop?

> -----Message d'origine-----
> De : Rohit Nair [mailto:community-noreply@qnx.com]
> Envoyé : 28 septembre 2011 15:24
> À : ostech-core_os
> Objet : ClockCycles Misbehaving
> 
> Hello,
> 
> I am seeing some weird behavior when I run ClockCycles tightly in a loop.
> ClockCycles should always return increasing values, but sometimes it returns
> a value that's less than the previously returned value.
> 
> For example -
> 
> 	ThreadCtl(_NTO_TCTL_RUNMASK,(int*) 0x1);
> 	perror(NULL);
> 
> 	start = ClockCycles();
> 	while(1)
> 	{
> 		stop = ClockCycles();
> 
> 		if(start > stop)
> 		{
> 			diff = start - stop;
> 			printf("??? start-%llu, stop-%llu,diff-%llu, iteration -
> %d\n",start,stop,diff,iter);
> 			break;
> 		}
> 		start = stop;
> 		iter++;
> 	}
> 
> 
> The iteration at which it happens is widely random. Ranging from 50 to
> 30000.
> 
> Could this be because of a wrong setup in init_qtime.c inside startup code ?
> 
> 
> 
> 
> _______________________________________________
> 
> OSTech
> http://community.qnx.com/sf/go/post89124
> 
Re: RE: ClockCycles Misbehaving  
It's uint64_t.
> 
> Of What type are the variables start and stop?
> 
> > -----Message d'origine-----
> > De : Rohit Nair [mailto:community-noreply@qnx.com]
> > Envoyé : 28 septembre 2011 15:24
> > À : ostech-core_os
> > Objet : ClockCycles Misbehaving
> > 
> > Hello,
> > 
> > I am seeing some weird behavior when I run ClockCycles tightly in a loop.
> > ClockCycles should always return increasing values, but sometimes it returns
> 
> > a value that's less than the previously returned value.
> > 
> > For example -
> > 
> > 	ThreadCtl(_NTO_TCTL_RUNMASK,(int*) 0x1);
> > 	perror(NULL);
> > 
> > 	start = ClockCycles();
> > 	while(1)
> > 	{
> > 		stop = ClockCycles();
> > 
> > 		if(start > stop)
> > 		{
> > 			diff = start - stop;
> > 			printf("??? start-%llu, stop-%llu,diff-%llu, iteration -
> > %d\n",start,stop,diff,iter);
> > 			break;
> > 		}
> > 		start = stop;
> > 		iter++;
> > 	}
> > 
> > 
> > The iteration at which it happens is widely random. Ranging from 50 to
> > 30000.
> > 
> > Could this be because of a wrong setup in init_qtime.c inside startup code ?
> 
> > 
> > 
> > 
> > 
> > _______________________________________________
> > 
> > OSTech
> > http://community.qnx.com/sf/go/post89124
> > 


Re: ClockCycles Misbehaving  
So why do you think it is not wrapping around? (what cpu type is that?)

On 28/09/2011 7:23 PM, Rohit Nair wrote:
> It's uint64_t.
>> Of What type are the variables start and stop?
>>
>>> -----Message d'origine-----
>>> De : Rohit Nair [mailto:community-noreply@qnx.com]
>>> Envoyé : 28 septembre 2011 15:24
>>> À : ostech-core_os
>>> Objet : ClockCycles Misbehaving
>>>
>>> Hello,
>>>
>>> I am seeing some weird behavior when I run ClockCycles tightly in a loop.
>>> ClockCycles should always return increasing values, but sometimes it returns
>>> a value that's less than the previously returned value.
>>>
>>> For example -
>>>
>>> 	ThreadCtl(_NTO_TCTL_RUNMASK,(int*) 0x1);
>>> 	perror(NULL);
>>>
>>> 	start = ClockCycles();
>>> 	while(1)
>>> 	{
>>> 		stop = ClockCycles();
>>>
>>> 		if(start>  stop)
>>> 		{
>>> 			diff = start - stop;
>>> 			printf("??? start-%llu, stop-%llu,diff-%llu, iteration -
>>> %d\n",start,stop,diff,iter);
>>> 			break;
>>> 		}
>>> 		start = stop;
>>> 		iter++;
>>> 	}
>>>
>>>
>>> The iteration at which it happens is widely random. Ranging from 50 to
>>> 30000.
>>>
>>> Could this be because of a wrong setup in init_qtime.c inside startup code ?
>>>
>>>
>>>
>>> _______________________________________________
>>>
>>> OSTech
>>> http://community.qnx.com/sf/go/post89124
>>>
>
>
>
>
>
> _______________________________________________
>
> OSTech
> http://community.qnx.com/sf/go/post89137
Re: ClockCycles Misbehaving  
Hi, 

if this is an ARM CPU, you perhaps have  bug in the timer_value callout.
On ARM ClockCycles is emulated by the kernel.

We had the same issue on an at91sam6263 board in march 2010.
We fixed the callout and sent the patch  to the support portal.
It  was tracked under PR#75223. 

-Michael