[gst-devel] 0.9 proposals

David Given dg at cowlark.com
Fri Dec 3 02:58:05 CET 2004

On Thursday 02 December 2004 22:23, Martin Soto wrote:
> The test were set up to switch back and forth one million times, that
> is, a total of two million switches per program run. The final lines
> (with the *) are the mean values. As you can see, we have about a 5-fold
> increase in both elapsed and system time when using gthreads. In the Pth
> case, user and system time almost add up to elapsed time. In the
> gthreads case there's a big difference. Does anyone have a good
> explanation for that?

I work for a company that produces an embedded OS that can run layered on top 
of another OS. The way we do this is to run the entire OS inside a single 
host OS user process, complete with our own scheduler. So we come up with 
this kind of thing quite frequently.

What we've basically discovered is that on most platforms, particularly Intel, 
context switches are slow. Really slow. If we can avoid making a system call, 
we almost always get a performance boost, even if it results in quite a lot 
of extra complexity. This applies across the board to most MMU-based 
operating systems: Linux and Windows, mostly, although we've seen it 

In my experience, a well-designed cothreads model should be able to run 
completely in user space and make a context switch by simply changing stack 
pointers and jumping. A preemptive kernel thread system will be robust and 
portable, but will be significantly slower. A preemptive threading system 
that runs in user space will be somewhere in between.

Note that trying to do this last leads to a whole new nightmare; some 
architectures, such as the PowerPC, simply cannot perform a complete context 
switch atomically in user mode, so that you still need to perform a system 
call. Cothreads avoid all this.


I like cothreads.

+- David Given --McQ-+ "What appears to be a sloppy or meaningless use of
|  dg at cowlark.com    | words may well be a completely correct use of words
| (dg at tao-group.com) | to express sloppy or meaningless ideas." ---
+- www.cowlark.com --+ Anonymous Diplomat

More information about the gstreamer-devel mailing list