EmbeddedRelated.com
Forums

Want a 1ms tick from Linux without modifying Linux Kernel

Started by Like2Learn December 6, 2010
I need to develop an embedded application running on Linux, to be more
specific, Wind River Linux 4.0 is my favorite for now. My application
requires a timer, or scheduler, which is required to tick my
application for about every 1ms. I say "about" because there is no
strict timing requirements, and either 1.01ms or 0.98ms would be
acceptable. In my application, written in C++, I will implement
OBSERVER pattern and Listener paradigm to get a full-featured
scheduler to dispatch events to processes at variable rates, say 5ms,
10ms, etc.

I would like to know if I can accomplish the above design without
modifying the linux kernel, since under GPL, having a kernel module in
my application will cause my application to be GPLed. At this moment I
don't want to go that far yet. If there is something in the kernel
already available, and can tick my application every 1ms, I would like
to use it directly in my application. I hope this way will save me
from the GPL license issue. Any thoughts? Thank you in advance!
Em 6/12/2010 22:33, Like2Learn escreveu:
> I need to develop an embedded application running on Linux, to be more > specific, Wind River Linux 4.0 is my favorite for now. My application > requires a timer, or scheduler, which is required to tick my > application for about every 1ms. I say "about" because there is no > strict timing requirements, and either 1.01ms or 0.98ms would be > acceptable. In my application, written in C++, I will implement > OBSERVER pattern and Listener paradigm to get a full-featured > scheduler to dispatch events to processes at variable rates, say 5ms, > 10ms, etc. >
[snipped]� this version of Linux has HRTs what are the resolutions available? -- Cesar Rabak GNU/Linux User 52247. Get counted: http://counter.li.org/
Like2Learn wrote:
> I need to develop an embedded application running on Linux, to be more > specific, Wind River Linux 4.0 is my favorite for now. My application > requires a timer, or scheduler, which is required to tick my > application for about every 1ms. I say "about" because there is no > strict timing requirements, and either 1.01ms or 0.98ms would be > acceptable. In my application, written in C++, I will implement > OBSERVER pattern and Listener paradigm to get a full-featured > scheduler to dispatch events to processes at variable rates, say 5ms, > 10ms, etc. > > I would like to know if I can accomplish the above design without > modifying the linux kernel, since under GPL, having a kernel module in > my application will cause my application to be GPLed. At this moment I > don't want to go that far yet. If there is something in the kernel > already available, and can tick my application every 1ms, I would like > to use it directly in my application. I hope this way will save me > from the GPL license issue. Any thoughts? Thank you in advance!
If it is close to standard Linux check the timer resolution. If it will handle 1ms resolution use setitimer() and handle the SIGALRM signal when it expires. If you just want to wait use nanosleep() The base time unit is 1usec but actual implementations may be more coarse than that.
On Mon, 06 Dec 2010 16:33:34 -0800, Like2Learn wrote:

> I need to develop an embedded application running on Linux, to be more > specific, Wind River Linux 4.0 is my favorite for now. My application > requires a timer, or scheduler, which is required to tick my application > for about every 1ms. I say "about" because there is no strict timing > requirements, and either 1.01ms or 0.98ms would be acceptable. In my > application, written in C++, I will implement OBSERVER pattern and > Listener paradigm to get a full-featured scheduler to dispatch events to > processes at variable rates, say 5ms, 10ms, etc. > > I would like to know if I can accomplish the above design without > modifying the linux kernel, since under GPL, having a kernel module in > my application will cause my application to be GPLed. At this moment I > don't want to go that far yet. If there is something in the kernel > already available, and can tick my application every 1ms, I would like > to use it directly in my application. I hope this way will save me from > the GPL license issue. Any thoughts? Thank you in advance!
No, applications running on top of a linux kernel do not have to be GPL, and it doesn't matter if you've modified the linux kernel, or added a kernel module. Anyway, before you start modifying the kernel, check out setitimer(), poll () or select().
On Dec 6, 7:14=A0pm, Dennis <den...@nowhere.net> wrote:
> Like2Learn wrote: > > I need to develop an embedded application running on Linux, to be more > > specific, Wind River Linux 4.0 is my favorite for now. My application > > requires a timer, or scheduler, which is required to tick my > > application for about every 1ms. I say "about" because there is no > > strict timing requirements, and either 1.01ms or 0.98ms would be > > acceptable. In my application, written in C++, I will implement > > OBSERVER pattern and Listener paradigm to get a full-featured > > scheduler to dispatch events to processes at variable rates, say 5ms, > > 10ms, etc. > > > I would like to know if I can accomplish the above design without > > modifying the linux kernel, since under GPL, having a kernel module in > > my application will cause my application to be GPLed. At this moment I > > don't want to go that far yet. If there is something in the kernel > > already available, and can tick my application every 1ms, I would like > > to use it directly in my application. I hope this way will save me > > from the GPL license issue. Any thoughts? Thank you in advance! > > If it is close to standard Linux check the timer resolution. If it will > handle 1ms resolution use setitimer() and handle the SIGALRM signal when > it expires. If you just want to wait use nanosleep() > > The base time unit is 1usec but actual implementations may be more > coarse than that.- Hide quoted text - > > - Show quoted text -
This sounds a good solution since I don't have to poll the timer with the SIGALRM signal. Thanks!
Like2Learn wrote:
> On Dec 6, 7:14 pm, Dennis <den...@nowhere.net> wrote: >> If it is close to standard Linux check the timer resolution. If it will >> handle 1ms resolution use setitimer() and handle the SIGALRM signal when >> it expires. If you just want to wait use nanosleep() > This sounds a good solution since I don't have to poll the timer with > the SIGALRM signal. Thanks!
SIGALRM is what you do it you *don't* want to poll the timer. You do need to use the advanced sigaction API though, not just signal(), or you change the semantics of other system calls that might be running. nanosleep works fine if you don't need to be doing anything else while waiting for the time to expire. Remember that you will miss ticks (be activated late, etc), so if you want to avoid accumulating timing errors, you need to check gettimeofday each time you pause to decide how long to sleep. Clifford Heath
On Dec 6, 5:33=A0pm, Like2Learn <like2le...@live.ca> wrote:
> I need to develop an embedded application running on Linux, to be more > specific, Wind River Linux 4.0 is my favorite for now. My application > requires a timer, or scheduler, which is required to tick my > application for about every 1ms. I say "about" because there is no > strict timing requirements, and either 1.01ms or 0.98ms would be > acceptable. In my application, written in C++, I will implement > OBSERVER pattern and Listener paradigm to get a full-featured > scheduler to dispatch events to processes at variable rates, say 5ms, > 10ms, etc. > > I would like to know if I can accomplish the above design without > modifying the linux kernel, since under GPL, having a kernel module in > my application will cause my application to be GPLed. At this moment I > don't want to go that far yet. If there is something in the kernel > already available, and can tick my application every 1ms, I would like > to use it directly in my application. I hope this way will save me > from the GPL license issue. Any thoughts? Thank you in advance!
How about epoll or epoll_wait? It will trigger a signal after timeout. I am not sure if it is based on the polling mechanism, if so I won't touch it. I think polling takes more resource and slow down the performance 9possibly I am superstitious). I am actually looking for a software interrupt-like.