LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 07-18-2012, 10:34 AM   #1
crosstalk
Member
 
Registered: Jul 2010
Distribution: Gentoo, Debian, Mint, Xubuntu
Posts: 150

Rep: Reputation: 35
Are system calls ever realtime-safe?


We are maintaining and developing a 1kHz control system for a robot. This system needs to be hard realtime. To achieve this, we are running our software under an RT-PREEMPT kernel.

However, I have heard that system calls are never realtime-safe in Linux -- in other words, there are no system calls guaranteed to never take a large amount of time. This doesn't make sense to me -- how could, say, clock_gettime() ever take a large amount of time if our thread has the highest realtime priority (and is the only thread at this priority)?

We are aware that many system calls -- such as networking, file IO, and malloc() -- generally aren't realtime safe. I am asking about the system calls that seem vital to basic operation of a program.

Are system calls ever realtime safe? If not, why?

Note: I have already asked this on StackOverflow, but have not gotten any satisfactorily confident or explanitory answers.

Thank you for any help.
 
Old 07-18-2012, 10:48 AM   #2
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,610
Blog Entries: 4

Rep: Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905
The Linux kernel does not guarantee that a process which is engaged in a system call will receive control within a specified time. It also does not guarantee that the fact that any process is engaged in a system call will not deprive some other process (or system activity) from being scheduled within a specified time.

Linux is not ... by design is not ... a RTOS.

I believe that you can either design a real-time operating system or a general-purpose one. These are fundamentally-conflicting design choices such that you cannot simultaneously, meaningfully have both.

Last edited by sundialsvcs; 07-18-2012 at 10:49 AM.
 
1 members found this post helpful.
Old 07-18-2012, 10:59 AM   #3
crosstalk
Member
 
Registered: Jul 2010
Distribution: Gentoo, Debian, Mint, Xubuntu
Posts: 150

Original Poster
Rep: Reputation: 35
Quote:
Originally Posted by sundialsvcs View Post
The Linux kernel does not guarantee that a process which is engaged in a system call will receive control within a specified time.
That is unfortunate. I guess we'll have to live with the knowledge that our system could possibly miss a deadline (fortunately, our system is resilient against the occasional missed deadline... but we'd prefer hard realtime) -- much of our system depends on Linux-only libraries and toolkits.

Quote:
It also does not guarantee that the fact that any process is engaged in a system call will not deprive some other process (or system activity) from being scheduled within a specified time.
I'm fairly sure that RT-PREEMPT, however, guarantees that a high-priority realtime task will preempt any lower-priority thread within some (unspecified but small) amount of time, regardless of that thread's execution state.

Quote:
Linux is not ... by design is not ... a RTOS.

I believe that you can either design a real-time operating system or a general-purpose one. These are fundamentally-conflicting design choices such that you cannot simultaneously, meaningfully have both.
I agree with this to an extent... but by changing some of those design choices it seems like RT-PREEMPT reverses most of the determinism-inhibiting effects of Linux's focus as a general-purpose OS.

Thank you for answering.
 
Old 07-18-2012, 01:04 PM   #4
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,610
Blog Entries: 4

Rep: Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905
Linux does have certain features which tilt toward the needs of "timing is really important" situations ... but please recognize that even these are sometimes pretty intrusive. When you start using features like RT-PREEMPT, other processes (upon which your task might also very much depend) can get starved.

Probably the best thing you can do is to equip your machine with the fastest CPU hardware you can afford, then make sure that the machine has nothing else to do with its time than to control your robot. Then, as you did, plan your setup to be resilient against the occasional missed deadline.
 
Old 07-18-2012, 01:35 PM   #5
crosstalk
Member
 
Registered: Jul 2010
Distribution: Gentoo, Debian, Mint, Xubuntu
Posts: 150

Original Poster
Rep: Reputation: 35
Quote:
Originally Posted by sundialsvcs View Post
Linux does have certain features which tilt toward the needs of "timing is really important" situations ... but please recognize that even these are sometimes pretty intrusive. When you start using features like RT-PREEMPT, other processes (upon which your task might also very much depend) can get starved.
We're well aware of what we depend on (for this reason). Frankly, if our code approaches 100% processor usage, we'd prefer to starve other processes (even our own non-realtime tasks) before we miss a cycle.

Quote:
Probably the best thing you can do is to equip your machine with the fastest CPU hardware you can afford, then make sure that the machine has nothing else to do with its time than to control your robot. Then, as you did, plan your setup to be resilient against the occasional missed deadline.
We're actually using cpu groups to free up a core soley for our tasks. All other tasks go to another core on the system. In other words, we're already doing exactly what you're suggesting.

One thing I don't think I've asked as clearly as I should have is why?

Do you (or anyone else) have any idea why no system calls are realtime-safe?

Thank you for your responses.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how does java calls the system calls which are written in c babu198649 Linux - General 3 12-05-2011 03:40 AM
Backup System historical v.s realtime metallica1973 Linux - Server 6 08-25-2009 10:48 PM
64Studio realtime kernel and debian lenny realtime module buid error? stratotak Linux - Newbie 0 01-30-2009 10:57 PM
A near realtime file system mirror application Chowroc Linux - Networking 6 02-22-2008 01:03 PM
How can I output realtime system resources to a label or textarea? JAVA randomx Programming 6 07-15-2004 06:41 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 04:46 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration