[En-Nut-Discussion] Re: Timers / Unix Emulation
Matthias Ringwald
mringwal at inf.ethz.ch
Tue Sep 21 12:07:36 CEST 2004
Hi Ole
Actually, I don't know what's happening on linux, but I know how it
could be fixed.
Btw. on mac os x, the timers work as expected. One reason for
differences is
that (at least on my red hat 7.3 box) the pthreads are modelled using
(light-weight)
processes hence you can see all nut/os threads when you do a 'ps'
whereas on the
mac, the pthreads are threads and only one process shows up. Somehow
related,
if you press control-c on mac, the app terminates correctly where on
linux
a segfault happens (which is good enough to stop a program).
ok. about the timer implementation of the unix emulation:
I'm using a pthread that runs a loop which does the following
while ( 1 ) { usleep ( 1 ms ) ; trigger_simulated_IRQ() }
I hope the linux usleep can deal with better granularity than 1 ms.
But this implementation is a big overkill as this triggering is
used by another pthread to process simulated_IRQs in a sequential
order and sends a signal to stop the current application thread
only to adjust the nut/os timer and wake some threads.
A better implementation would be to remove the Timer Tick simulation
and handle waking of threads directly in the nut_timer routine.
For all threads, the wakeup time is know. So one could use this
to sleep exactly until this time (always using the system time)
and wake the thread. waking of threads has to be done atomically,
so here (some/more) care has to be taken.
The atomically access to nut/os data structures is actually one of
the biggest hassles of the nut/os emulation at all.
For the correct implementation of the usart drivers (
where the main problem is to do a blocking read in a thread
without stopping the other threads) I added a hook that is called
when nut/os is switching threads ( and therefore no other thread is
running) and does the waking.
If you want do dig into this, surely I can help and provide
more information
matthias
On 17.09.2004, at 18:41, Ole Reinhardt wrote:
> Hi all,
>
> I'm using the unix emulation to implement l2cap for btnut. I noticed
> that all timers seems to be running 10 times too slow... Will say
> waiting one seconed (NutSleep(1000)) results in about 10 seconds
> waiting.
>
> Is it caused by the large granularity of the linux system timers?
>
>
> Regards,
>
> Ole Reinhardt
>
> --
> kernel concepts Tel: +49-271-771091-14
> Dreisbachstr. 24 Fax: +49-271-771091-19
> D-57250 Netphen E+ : +49-177-7420433
> --
>
>
More information about the En-Nut-Discussion
mailing list