I schedule threads. That is, if a switch keeps in the same process, then CR3 is kept untouched, so that the new thread can benefits of already-present-data in TLB cache and can execute faster. When a switch happens to go to another process, then CR3 is modified (implicitly, by hardware task switching, iirc).Brendan wrote: Hi,
Does your scheduler schedule processes or threads, and how big will your TLS areas be?Pype.Clicker wrote:I suppose if i'm to use that trick, i'd rather tune the switching code so that the very page (or table) that contains thread-local variables will be replaced (but still not touching CR3 to avoid full TLB flush) as needed ...
There's something similar to your 'priority classes' too (indirectly and untested since i have no multi-cpu machine at hand), by the amount of TSS a process is allotted. E.g. if a process owns only one TSS, then it cannot have two threads running simultaneously, even if the machine has 16 CPUs. If the process owns 4 TSSes, then it can use up to 4/16 CPUs simultaneously. Yet you _could_ start several processes, each with their own set of TSS, all working together (and optionally sharing memory) as the web server you described.
However, usually, webserver writers want threads not only to take advantage of multiple CPUs, but mainly to compensate the I/O latency and keep the CPU busy while there is disk access or network delays. That suggests to have more threads than CPUs and as low overhead for thread switching within the same app. as possible ...
And i keep thinking that your model (as much thread-local state as possible, "process" area is mainly for code and things that _must_ be shared) looks much more like pre-forked multiprocess with shared memory model than it looks like the usual "multithreat" model.I schedule threads, and for my OS I recommend using the TLS areas for as much as possible - process space should only be used for the executable file, and any data that is shared by all threads (which should be almost nothing if good OOP practices are used).
Not meaning that it's silly to do it ... it's just not exactly what threads have been looking like for the past 10 years