Jump to content
  • Advertisement
Sign in to follow this  
cowboygun

Want a 1ms tick from Linux without modifying Linux Kernel

This topic is 2869 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts


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!

Share this post


Link to post
Share on other sites
Advertisement
My out-of-the-box Debian and Ubuntu Linux systems have timeout on epoll_wait (and thus probably on everything else too, but I didn't test that explicitly) working at accurracies in the microsecond (micro, not milli) range without having to refer to any special RT stuff.

So, a millisecond should be no issue at all (assuming every "normal" Linux works more or less the same).

Share this post


Link to post
Share on other sites
Quote:
Original post by samoth
My out-of-the-box Debian and Ubuntu Linux systems have timeout on epoll_wait (and thus probably on everything else too, but I didn't test that explicitly) working at accurracies in the microsecond (micro, not milli) range without having to refer to any special RT stuff.

So, a millisecond should be no issue at all (assuming every "normal" Linux works more or less the same).


What is the *granularity* of epoll_wait? If you call epoll_wait 100μs apart, will it wait for 100μs or will it wait somewhere between 0 and 20ms (like Windows do)?

Share this post


Link to post
Share on other sites
The former.

I tested that once when I had the exact same question (how to block somewhat reliably for 1ms) as the OP, and found that this is really nothing to worry about.

While I don't remember whether I ran the tests over 1 second, or 10 seconds, 100 seconds, or whatever time, the baseline was that if you ask it to block for 1μs a million times, the total time will add up to slightly over a second (as opposed to 2000 seconds). So, in wall time, you get pretty much exactly what you asked for, plus some syscall overhead. Which honestly, I found absolutely stunning.

Share this post


Link to post
Share on other sites
Using epoll() is overkill when you could just use timerfd_create() can friends for a nanosecond-level timer. Of course, you can multiplex a timerfd through epoll(), poll(), select(), or do a blocking read() in a thread (whatever your favorite multiplexing poison is), but using timerfd you can have multiple timers pending and leave the dispatch to the kernel, yielding simpler code and lower system overhead.

Share this post


Link to post
Share on other sites
Quote:
Original post by Sneftel
Google "RT-PREEMPT".

Is it an overkill to turn the Linux into a fully preemptible kernel? I only need a 1ms tick. I hope something really simple. Thank you anyway.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!