Sure - the pages weren't in use recently, but that doesn't always mean they won't be in use soon. Also if a CPU is halted (waiting for something to do) it may retain TLB information indefinately (especially if they are marked global).Candy wrote: Pages sent to swap, and unmapped pages of memory mapped files were not in use recently. When they are being mapped, you first load it, then map it and then invlpg yourself. No problemo.
Still not (normally) necessary - when processor 0 switches back to process A it has to reload CR3 (different address space) which will flush anything not marked global.Candy wrote: Theoretical situation about a race condition: You have a process A and a process B, and a process C. A uses 3 pages(0-2), B uses 3 pages (3-5). Process A is reading from all three pages on processor 1, B is reading from all three pages, C has no relevant issues other than not being A. Processor 0 switches from A to C, processor 1 sees B needing a page, unmaps page #2 from space in process A, process not active, no ipi's. Processor 0 switches back to A, still using the old TLB entry mapping page 2 of A to the page in the cache, and thereby overwrites B's data.
You want to signal all processors.
Most people who write multi-threaded processes/applications don't worry about using semaphores/mutexes for shared data or anything - they assume it's single CPU multi-threading. As a simple example, if a multi-threaded application (that doesn't support multi-processor) is the only application that the user is using, then the keyboard driver, mouse driver, VFS, user interface and video driver will/may all be doing something because of it (in my OS all of these things are seperate processes). In addition any process can have idle threads (including the kernel) which only run when there's nothing else to do. This means other CPUs will have plenty to keep them busy, even though the application is only being run on one CPU.Candy wrote:That's very ugly. Multiprocessor things also occur with ALL multithreading programs, and if you don't multithread there's nothing the other processor can do about it. What's the use of the bit?My processes (applications, drivers, etc) have a flag in the executable file header that says if it supports multi-processor. If this flag is clear the scheduler will not allow more than one thread from the process to be running. I expect that most processes will not set this flag. Also if the process only has 1 thread there's no problem. For a very rough estimate I guess that I'll only need to worry about TLBs on other CPUs in process space about %15 of the time.
If the application does support multi-processor then the OS knows that it does use semaphores, mutexes, etc for shared data and it can allow multiple threads belonging to the process to be scheduled on different CPUs at the same time.
With a monolithic kernel all the data used by device drivers, etc would be in kernel space - in this case INVLPG would need to be done on all CPUs. As my device drivers, etc are implemented as seperate processes the INVLPG won't normally be needed on all CPUs, so in general the micro-kernel design reduces the overhead of TLB flushing. My most complete kernel contained less than 30 Kb of code and used around 200 Kb of data. The overhead of IPC and other things is increased though, so I expect the overall overhead of the micro-kernel to be worse. I'm using a micro-kernel for other reasons (sacrificing some performance for other benefits).Candy wrote:What's different between a monolithic kernel and a microkernel that makes you say this? I actually dare say you'll keep getting TLB flushes. You might be different from a traditional monolithic kernel that you don't load the code you never use in the first place. That doesn't make you any better though, all your processes are in separate pages, giving a load of overhead a monolithic kernel can beat easily. (yes, an optimized microkernel can be faster than a non-optimized monolithic kernel, pretty *duh* if you ask me). I'm still going for hybridIn addition it's a micro-kernel (device drivers, VFS, etc are processes) - it's not going to be changing pages as much as a monolithic kernel.
Cheers,
Brendan