Feature request: ability to use libeio with multiple event loops

Jorge jorge at jorgechamorro.com
Thu Dec 22 10:08:44 CET 2011


On 22/12/2011, at 08:05, Hongli Lai wrote:
> 
> It's true that the second program adds an extra layer of indirection
> (the 'data' variable). However:
> 1. If the data is accessed frequently then both the pointer and the
> ThreadData that it points to should be cached by the CPU cache, making
> the indirection very cheap.
> 2. Suppose the system has two cores and N = 4, so two processes or two
> threads will be scheduled on a single core. A context switch to
> another thread on the same core should be cheaper because 1) the MMU
> register does not have to swapped and 2) no existing TLB entries have
> to be invalidated.
> 
> I think that (1) and (2) are sufficiently beneficial that the program
> should run faster overall, even with the extra indirection. Do you not
> think so?

Fwiw, I do think so too. The threads' context switches are cheaper, when they happen from/to threads belonging to the same process.

The only argument I see in favor of multiple processes is that as processes don't share memory (not usually, not in general, except for clone()d processes in Linux, or shm_ blocks), a process' thread running in a core usually can't/won't invalidate the caches of another process' thread running in another core, something that can happen -easily or not, that depends on the code that's executing- when there's several cores running threads that belong to the same process, because all of them share the same memory space.
-- 
Jorge.


More information about the libev mailing list