Fibers and inp()/outp() in Tango (was: Coming IO features in Tango)

Ingo Oeser ioe-news at rameria.de
Mon Jul 30 03:19:46 PDT 2007


Hi Sean,

first of all: I've set the Followup-To to digitalmars.D. since we are not 
announcing anything here anymore :-)
I've also changed the subject a little.

Sean Kelly wrote:
>>>> Are fibers able to take advantage of the machine's cache any better
>>>> than swapping threads (with their dramatically larger stack space) in
>>>> and out?
>>> Probably not.  But context switching fibers is much faster than context
>>> switching threads, which is a selling point in some cases.
>> 
>> So better improve the threading support :-)
> 
> Well, it's more an OS limitation than anything.

So you give the library user a tool to workaround these issues
in his platform agnostic code? Hope he will use a version(Limited_OS)
then :-)

>> Did you measure your claim? Did you dirty the caches
>> (aka "use the state of the state machine"), before context switching?
> Nope.  But Mikola Lysenko, the author of StackThreads on which Tango
> fibers are based performed some tests when developing coroutines and his
> StackThreads were substantially faster for multiplexing tasks.

Didn't find his measurements either (using Google, Mikola Lysenko 
StackThreads). Do you have a pointer somewhere? Did he bother to measure
that on Linux, which is known for low context switching latency?

> Though perhaps some of this difference was because StackThreads 
> don't need mutexes to share data.

The same thing can be done with per-thread data. Obvious implementation
would be a property accessible only by the owning thread. If the
property is a AA, we have the POSIX thread local storage there.

First solution to (performance) problems with shared data is to not
share the data at all, but to keep it local or replicate it periodically. 
That scales quite good.

Second solution is to make more finegrained locks.

Third solution is looking at optimising your locking primitives.

Order usually matters in applying these solutions, since effort raises from
first to third.

Oh, and looking at the implementation, I see currently MORE global state
in Tango due to Fibers. I mean the hacks for "Context".

>> Only dirty hack left is inpl()/outpl() and friends. They are simply not
>> available on many architectures and are getting unimportant on PC due to
>> MMIO. A modern language like D should handle them as special address
>> space, which is a nice feature for a compiler and required for some
>> micro controllers and some DSPs. In C this is supported via CPP-hacks :-/
> 
> I'll have to read up on these instructions.  Hadn't heard of them before.

inp() and out() implement the X86 port IO facilities. These are oneliners
in assembler and implementation would differ depending on ring 0 (direct 
operation) and ring 3 (OS call). They might be useful for writing device 
drivers in D. If you write device drivers, they ARE ALREADY OS specific.
And each OS has already much better defined abstractions of these routines.

So I would just drop them in Tango. May be depreciate first.


Best Regards

Ingo Oeser



More information about the Digitalmars-d-announce mailing list