User: Password:
|
|
Subscribe / Log in / New account

KHB: Synthesis: An Efficient Implementation of Fundamental Operating Systems Services

KHB: Synthesis: An Efficient Implementation of Fundamental Operating Systems Services

Posted Feb 27, 2008 17:30 UTC (Wed) by pphaneuf (subscriber, #23480)
Parent article: KHB: Synthesis: An Efficient Implementation of Fundamental Operating Systems Services

The trick of changing between two algorithms is pretty awesome, and something more or less like that could easily be done with many pieces of code in the kernel. I did similar things in user-space C++ code, by using callbacks for some things, where I basically encoded part of the state in the function pointer itself (in state A, point at do_state_A, in state B, point at do_state_B, something like that), which was kind of ugly in C++, as it basically was hand-coded virtual methods, so that I could change them at runtime (and per object).

But in the kernel, we're already implementing virtual methods by hand, and on top of it, we don't use per-class virtual method tables, but rather embed them in each objects already, which is exactly what we need! It's just that they are usually initialized once at object creation, we'd just need to use some atomic CAS to update a function pointer when some algorithm changes.

The trick part is when more than one method needs to change. Damn, I actually expect this would be common, too. Argh.

Oh well, it's pretty cool!


(Log in to post comments)

KHB: Synthesis: An Efficient Implementation of Fundamental Operating Systems Services

Posted Feb 27, 2008 21:58 UTC (Wed) by zlynx (subscriber, #2285) [Link]

Your solution is not as ugly as another I've seen in C++ where the programmer used placement
new to reconstruct the object with a different derived type (but the same base type) in-place.

Now, that was scary.

KHB: Synthesis: An Efficient Implementation of Fundamental Operating Systems Services

Posted Feb 27, 2008 22:51 UTC (Wed) by pphaneuf (subscriber, #23480) [Link]

My way is ugly. That way is insane.

Still, I wish it was possible to manipulate vptrs and vtbls more in C++. Things like having two different implementations of a virtual method with the same signature inherited from two parents would make sense, for example (say, the "draw" methods you get while deriving from both Drawable and Cowboy).

KHB: Synthesis: An Efficient Implementation of Fundamental Operating Systems Services

Posted Feb 28, 2008 20:59 UTC (Thu) by nix (subscriber, #2304) [Link]

Insane?

Oh.

So, er, I should be ashamed that I did almost exactly that (via a custom 
allocator layered atop big mmap()ed hunks) in C about a year ago? (Well, 
it was more like a twisted sort of RCU: I'd construct a new instance that 
was a copy of the old one with a zero reference count, then changing 
pointers in the new instance's VMT-analogue, translating the object's data 
into a new representation at the same time. The old instance got 
reference-zapped when nobody was executing methods via those pointers 
anymore.)

(yes, there were pressing reasons. It was a bundle of fun, as well. :) )


Copyright © 2017, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds