ts-7000
[Top] [All Lists]

Re: [ts-7000] Re: Hardware timers in user space, resolution?

To:
Subject: Re: [ts-7000] Re: Hardware timers in user space, resolution?
From: Ilya Goldberg <>
Date: Thu, 24 Sep 2009 15:53:56 -0400
I don't believe you can actually do this in user-space with a  
preemptive kernel.
Using the hardware timer doesn't help you unless all you need is to  
time a 125 us interval every 10ms or so.  If you're doing a periodic  
task every 125 us, there's really no way to do it because this is a  
much finer resolution than the kernel's scheduler (10 ms on a stock  
kernel).

The general answer to FA'd timer questions is:
There is no way to send your process to sleep for a time period  
shorter than the kernel's scheduler resolution (otherwise known as a  
"jiffy").  This is 10ms on the stock TS kernel (and most other  
kernels), and no shorter than 1ms on any "normal" kernel.
Regardless of the parameter you use, usleep() will cause your process  
to sleep for at least one jiffy (10ms).
You can write a busy-loop checking on a hardware timer and consume  
100% of the CPU in the process, but even this loop will be preempted  
by the kernel, which will sleep your process for as long as it wants,  
though generally for no more than one jiffy.

I had a similar issue, and ended up implementing what I needed on an  
AVR (which has gcc support), and communicating more chunky and less  
time-sensitive data to the ARM CPU over RS232 (and as a bonus got to  
use a stock kernel, drivers, and portable software and hardware).
Another option might be to implement something on the FPGA.
A custom kernel driver may be the way to go too.  Depending on what  
you're doing in those 125 us, an 8 kHz interrupt for the kernel might  
be OK.
Heck, there might even be a way to do this with "real-time"  
extensions, but all of these are hacks around the fact that user- 
space can't be used for periodic tasks occurring at a higher  
frequency than the kernel's scheduler.
-I

On Sep 24, 2009, at 2:33 PM, Blair wrote:

> --- In  Jim Jackson <> wrote:
>>
>>
>>
>>
>> On Wed, 23 Sep 2009, Blair wrote:
>>
>>> Question: The T4 hardware timer can run at about 980kHz.  What's the
>>> fastest you can make use of it in a user space app?  I'd like to  
>>> be able
>>> to do a periodic task every 125 microseconds or maybe half that.   
>>> Do I
>>> have to write a kernel driver to do this?
>>
>> This is an FAQ. Please try and search back in the group.
>>
>
> Got anything more definitive to go on?  I've bee searching hardware  
> timer, T4 timer, etc and all I seem to be able to find are comments  
> like "yeah you can do that" without the actual solution.  If this  
> is a FAQ, where is the FAQA (Frequently Asked Question Answer), or  
> ATFAQ (not related to AFLAC).  Source code would be useful.  I've  
> tried the T4timer.c code sample but what I'm seeing is the timeout  
> if-then lines overshooting the desired time by huge amounts.
>
>
>
>
> ------------------------------------
>
> Yahoo! Groups Links
>
>
>



------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/ts-7000/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/ts-7000/join
    (Yahoo! ID required)

<*> To change settings via email:
     
    

<*> To unsubscribe from this group, send an email to:
    

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/

<Prev in Thread] Current Thread [Next in Thread>
Admin

Disclaimer: Neither Andrew Taylor nor the University of NSW School of Computer and Engineering take any responsibility for the contents of this archive. It is purely a compilation of material sent by many people to the birding-aus mailing list. It has not been checked for accuracy nor its content verified in any way. If you wish to get material removed from the archive or have other queries about the archive e-mail Andrew Taylor at this address: andrewt@cse.unsw.EDU.AU