Skip to contentSkip to conversation

fork() blocking rt-threads?

DISCUSSION [email protected] 5 participants 6 messages Oct 16, 2009 – Oct 19, 2009

lore
Share & tools
lore
#0 lore raw

Hi,
I'm a Linux audio user and following the rt kernel development closely (only as a user).
I've experienced something that might be relevant for all of us.

When loading the plug-in 'lv2fil' in one of our most relevant Linux audio applications, ardour, and opening the ui, fork() was used. This usually blocks the rt thread long enough to wreak havoc to the underlying rt audio server jack.

What's relevant here is the ill effect of fork() and that tests showed that vfork() works a lot better.
One ticket associated with this is:
http://nedko.arnaudov.name/soft/lv2fil/trac/ticket/9

Ardour also uses some gtk function (to open a page in the default webbrowser) that uses fork() and causes the same problem.

Again, it seems the problem stems from the fork() implementation and is present at least in 2.6.21.x through 2.6.31.x(-rt).
I'm quite sure this doesn't only affect us audio people.

I hope this information is of help and someone will look into it.

Best regards,
Philipp Überbacher
--
To unsubscribe from this list: send the line "unsubscribe linux-rt-users" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#1 lore raw

On Fri, Oct 16, 2009 at 04:25:21PM +0200, [email protected] wrote:

| Hi,
| I'm a Linux audio user and following the rt kernel development closely
| (only as a user).
| I've experienced something that might be relevant for all of us.
| 
| When loading the plug-in 'lv2fil' in one of our most relevant
| Linux audio applications, ardour, and opening the ui, fork() was used.
| This usually blocks the rt thread long enough to wreak havoc to the
| underlying rt audio server jack.
| 
| What's relevant here is the ill effect of fork() and that tests
| showed that vfork() works a lot better.
| One ticket associated with this is:
| http://nedko.arnaudov.name/soft/lv2fil/trac/ticket/9
| 
| Ardour also uses some gtk function (to open a page in the
| default webbrowser) that uses fork() and causes the same problem.
| 
| Again, it seems the problem stems from the fork() implementation and is
| present at least in 2.6.21.x through 2.6.31.x(-rt).
| I'm quite sure this doesn't only affect us audio people.
| 
| I hope this information is of help and someone will look into it.

Do you know how people benchmarked fork, vfork and clone? Is it easier than reproducing the issue you observed?

Another question that comes to mind is: was Ardour running with a realtime priority too? Higher or lower prio than jack's?

Regards,
Luis

Signature · 2 lines
[ Luis Claudio R. Goncalves                    Bass - Gospel - RT ]
[ Fingerprint: 4FDD B8C4 3C59 34BD 8BE9  2696 7203 D980 A448 C8F8 ]
#2 lore raw
Quoted 25 lines · Luis Claudio R. Goncalves

On Fri, Oct 16, 2009 at 04:25:21PM +0200, [email protected] wrote:

| Hi,
| I'm a Linux audio user and following the rt kernel development closely
| (only as a user).
| I've experienced something that might be relevant for all of us.
| 
| When loading the plug-in 'lv2fil' in one of our most relevant
| Linux audio applications, ardour, and opening the ui, fork() was used.
| This usually blocks the rt thread long enough to wreak havoc to the
| underlying rt audio server jack.
| 
| What's relevant here is the ill effect of fork() and that tests
| showed that vfork() works a lot better.
| One ticket associated with this is:
| http://nedko.arnaudov.name/soft/lv2fil/trac/ticket/9
| 
| Ardour also uses some gtk function (to open a page in the
| default webbrowser) that uses fork() and causes the same problem.
| 
| Again, it seems the problem stems from the fork() implementation and is
| present at least in 2.6.21.x through 2.6.31.x(-rt).
| I'm quite sure this doesn't only affect us audio people.
| 
| I hope this information is of help and someone will look into it.
Quoted 2 lines

Do you know how people benchmarked fork, vfork and clone? Is it easier than reproducing the issue you observed?

I did some benchmarks, IIRC, vfork was slower than fork; clone and clone2 were giving xruns and were not faster.

Quoted 2 lines

Another question that comes to mind is: was Ardour running with a realtime priority too? Higher or lower prio than jack's?

Ardour process has realtime thread(s) started by libjack.

If someone is interested, lv2fil code has disabled code for measuring fork-and-like execution time.

Signature · 1 line
Nedko Arnaudov <GnuPG KeyID: DE1716B0>
#3 lore raw
Quoted 4 lines · Nedko Arnaudov
Quoted 2 lines

Another question that comes to mind is: was Ardour running with a realtime priority too? Higher or lower prio than jack's?

Ardour process has realtime thread(s) started by libjack.

AFAICT, fork() is inherently unusable from any thread of a process with realtime threads. It locks the page tables and the process structure of the parent among other things.

Anyone know if posix_spawn() is supported by any major distro's glibc?
Apparently it was developed to solve this exact problem.

http://www.opengroup.org/onlinepubs/009695399/functions/posix_spawn.html

Lee

#4 lore raw
Quoted 6 lines · On Sun, 18 Oct 2009 02:11:22 -0400 Lee Revell <[email protected]> wrote:
Quoted 4 lines · Nedko Arnaudov
Quoted 2 lines

Another question that comes to mind is: was Ardour running with a realtime priority too? Higher or lower prio than jack's?

Ardour process has realtime thread(s) started by libjack.

Quoted 9 lines

AFAICT, fork() is inherently unusable from any thread of a process with realtime threads. It locks the page tables and the process structure of the parent among other things.

Anyone know if posix_spawn() is supported by any major distro's glibc?
Apparently it was developed to solve this exact problem.

http://www.opengroup.org/onlinepubs/009695399/functions/posix_spawn.html

Just tried it on a RHEL5.4 and Fedora 11 system. The pthread_spawn(3P) function is implemented using vfork(2) under the covers. Makes sense, since the stated intent is to work without VM.

Still, anyone wanting to create processes/threads in a realtime environment needs to do that stuff up front, since there's a ton of work required to make a scheduleable entity. Whether you're just creating a pthread or you're generating a full-up process, memory will have to be allocated and locks taken. Not sure I'd depend on *anything* to do the right thing for me...

Clark

#5 lore raw
Quoted 10 lines · Clark Williams

Just tried it on a RHEL5.4 and Fedora 11 system. The pthread_spawn(3P) function is implemented using vfork(2) under the covers. Makes sense, since the stated intent is to work without VM.

Still, anyone wanting to create processes/threads in a realtime environment needs to do that stuff up front, since there's a ton of work required to make a scheduleable entity. Whether you're just creating a pthread or you're generating a full-up process, memory will have to be allocated and locks taken.  Not sure I'd depend on *anything* to do the right thing for me...

Interesting.

Last time I tested it, pthread creation could be realtime safe, if you allocate and mlock() a pool of memory beforehand and use pthread_setstack on the preallocated and pre-locked memory.

However I for one did not think that any system call from a non-realtime thread will cause realtime threads of the same process to get blocked. I can't think of any other action that does that.

Regarding the Ardour help menu issue, does this mean that using gtk APIs from a non RT thread of a process with RT threads is unsafe?

Lee
--
To unsubscribe from this list: send the line "unsubscribe linux-rt-users" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html