Re: [patch 00/13] Syslets, "Threadlets", generic AIO support, v3

Ingo Molnar
2007-03-02T20:37:06Z

* Davide Libenzi <davidel@xmailserver.org> wrote:

> I think that the "dirty" FPU context must, at least, follow the new
> head. That's what the userspace sees, and you don't want an async_exec
> to re-emerge with a different FPU context.

well. I think there's some confusion about terminology, so please let me
describe everything in detail. This is how execution goes:

outer loop() {
call_threadlet();
}

this all runs in the 'head' context. call_threadlet() always switches to
the 'threadlet stack'. The 'outer context' runs in the 'head stack'. If,
while executing the threadlet function, we block, then the
threadlet-thread gets to keep the task (the threadlet stack and also the
FPU), and blocks - and we pick a 'new head' from the thread pool and
continue executing in that context - right after the call_threadlet()
function, in the 'old' head's stack. I.e. it's as if we returned
immediately from call_threadlet(), with a return code that signals that
the 'threadlet went async'.

now, the FPU state that was when the threadlet blocked is totally
meaningless to the 'new head' - that FPU state is from the middle of the
threadlet execution.

and here is where thinking about threadlets as a function call and not
as an asynchronous context helps alot: the classic gcc convention for
FPU use & function calls should apply: gcc does not call an external
function with an in-use FPU stack/register, it always neatly unuses it,
as no FPU register is callee-saved, all are caller-saved.

> So, IMO, if the USEDFPU bit is set, we need to sync the dirty FPU
> context with an early unlazy_fpu(), *and* copy the sync'd FPU context
> to the new head. This should really be a fork of the dirty FPU context
> IMO, and should only happen if the USEDFPU bit is set.

why? The only effect this will have is a slowdown :) The FPU context
from the middle of the threadlet function is totally meaningless to the
'new head'. It might be anything. (although in practice system calls are
almost never called with a truly in-use FPU.)

Ingo