WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Timer resolution  (Read 7576 times)

Offline Tuftec

  • Full Member
  • ***
  • Posts: 111
Timer resolution
« on: June 07, 2011, 12:49:46 AM »
Does anyone know how to change the timer resolution under Tiny Core?
I am trying to work with a Real Time version of Tiny Core. It appears that the default timer resolution is only 3.3ms on my system (1Ghz X86 CPU).
I would like to change this to something smaller, like 100uS or even 10uS.

Is there some easy way to change this? Maybe a boot option?


Offline Arslan S.

  • Hero Member
  • *****
  • Posts: 825
Re: Timer resolution
« Reply #1 on: June 07, 2011, 01:47:22 AM »
for high resolution timer you need to use clock_gettime() and clock_nanosleep() like in this example
https://rt.wiki.kernel.org/index.php/RT_PREEMPT_HOWTO#A_Realtime_.22Hello_World.22_Example

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11727
Re: Timer resolution
« Reply #2 on: June 07, 2011, 01:51:15 AM »
Hi Tuftec
You might want to be a little more specific about what you are trying to do. Are you referring to the
scheduler, interrupt timing, calling a timer from a program?

I see Arslan S. just posted, you might want to add  gettimeofday  to his list.

Offline Tuftec

  • Full Member
  • ***
  • Posts: 111
Re: Timer resolution
« Reply #3 on: June 07, 2011, 03:02:28 AM »
I am calling clock_nanosleep() from within a real time program, with the rt patched Tiny Core kernel.
I am finding that the sleep time is limited to a multiple of the jiffie time, which is 3.333ms. I was trying to sleep for only 100us.
 

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11727
Re: Timer resolution
« Reply #4 on: June 07, 2011, 03:21:23 AM »
Hi Tuftec
You probably have to increase the priority of your task, otherwise you will be competing for time with
the other running tasks on an equal or less than equal basis.
 

Offline Tuftec

  • Full Member
  • ***
  • Posts: 111
Re: Timer resolution
« Reply #5 on: June 07, 2011, 03:29:04 AM »
My task is running at a priority of 99.
It does not appear to be competing with other tasks in the system.
The task runs consistently but will only sleep for 3.3ms. Even when I specify a sleep time of 100000.
I want it to sleep for a shorter time.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11727
Re: Timer resolution
« Reply #6 on: June 07, 2011, 04:06:20 AM »
Hi Tuftec
According to the link Arslan S. posted kernel tasks run at a priority of 50. Maybe you can't run at a
priority higher than that? You could also attach a file with the code you are testing, maybe someone
with some experience in this area will spot something.

Offline Tuftec

  • Full Member
  • ***
  • Posts: 111
Re: Timer resolution
« Reply #7 on: June 07, 2011, 04:16:45 AM »
Here is a copy of the test code that I am running.
It is a modification of another piece of code I found that generates square waves on a parrallel port.
I just modified for my embedded computer hardware.
 

Offline Arslan S.

  • Hero Member
  • *****
  • Posts: 825
Re: Timer resolution
« Reply #8 on: June 07, 2011, 04:43:07 AM »
long time ago i have setup real time kernel for tc 2.x tested it on a mobile p4 platform with a similar parallel port square wave program, verified results with an oscilloscope connected at the parallel port pins

i remember successful results for a period of 100us

did you try cylictest program to see if everything is ok ?
it is available in rt-tests.tcz extension

Code: [Select]
sudo cyclictest -i 1000 -n -t -p 80base interval of thread is 1000us, use clock_nanosleep, start one thread per cpu, highest thread priority is 80

one more thing high resolution timer is also availabe in standart tc kernel
« Last Edit: June 07, 2011, 04:48:25 AM by Arslan S. »

Offline Tuftec

  • Full Member
  • ***
  • Posts: 111
Re: Timer resolution
« Reply #9 on: June 07, 2011, 07:35:09 AM »
I tried running cylictest. I am not really sure what all the numbers that it outputs actually mean.

Things like this
T: 0 ( 3129) P:80 I:1000 C:  22703 Min:   1745 Act:52963515 Avg:26482632 Max:52963515

I thought the clock_nanosleep() call uses the High Resulution Timers. That is where I detected the issue. the HRTs seem to only work down to resolutions of 3333116 nanoseconds.


Offline Arslan S.

  • Hero Member
  • *****
  • Posts: 825
Re: Timer resolution
« Reply #10 on: June 07, 2011, 08:09:01 AM »
that's the latency between actual and expected sampling time values in us (micro seconds)
what is computer specs you are running ?

Offline Tuftec

  • Full Member
  • ***
  • Posts: 111
Re: Timer resolution
« Reply #11 on: June 07, 2011, 08:32:55 AM »
If I run the cyclictest with no options it reports that the High Resolution Timers not available.

System is embedded system on chip.
1Ghz clock, equiv to 586 style processor. 600Mhz RAM bus speed.


Offline Arslan S.

  • Hero Member
  • *****
  • Posts: 825
Re: Timer resolution
« Reply #12 on: June 07, 2011, 09:30:28 AM »
i think your system does not have hr timer, it is not the tiny core linux kernel

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11057
Re: Timer resolution
« Reply #13 on: June 07, 2011, 09:31:25 AM »
Wait, one of the Xcore86 / DMP / Sis etc cheapos? I really doubt they support better timers, high res ones need hardware support.
The only barriers that can stop you are the ones you create yourself.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11727
Re: Timer resolution
« Reply #14 on: June 07, 2011, 12:24:59 PM »
Hi Tuftec
It does not look promising, but as an act of desperation you can try  hpet=force  or one of the other
hpet boot codes list here.
http://www.mjmwired.net/kernel/Documentation/kernel-parameters.txt