Messages in this thread | | | Date | Sun, 5 Dec 1999 11:07:08 +0100 (CET) | From | Ingo Molnar <> | Subject | Re: switch_to function |
| |
On Sun, 5 Dec 1999, Alexander Viro wrote:
> > I read the linux kernel 2.2.13 source code,and find that in > > arch/i386/kernel/process.c switch_to function use inline asm 'ltr' to load > > the new task register which I thought can be loaded automatically when > > 'iretd','call',or 'ljmp' executed. anyone know why it still use 'ltr' here? > > Because TSS gates are _slow_. Doing task switch by hands is much faster.
no, thats not the real reason. It's _not_ faster (definitely not in 2.2), because all kinds of stuff has to be soft-reloaded and ltr isnt very fast either. The real reason for doing soft-reloads is threefold:
- exception handling wrt. segment reloading is simpler. It's conceptually impossible to determine in a simple way what caused an exception during a TSS switch. It's a 'too complex' operation to be described with a simple fault. Soft-switching sorts all the fault sources out nicely.
- the number of TSSs per GDT is limited to 8192, which together with the LDT entry (and a few other descriptors) constrained the maximum number of processes/threads to 4000. Since early 2.3 we have a per-CPU TSS, which is loaded only once at bootup, so there is no ltr cost and no limitation (apart from RAM) on the number of processes/threads.
- since late 2.3 we have another feature: soft-TLB reloading, which optimizes away the TLB-flush of system-threads. TSS task-switching only knows about the 'dont flush if page tables are identical between the previous and next task' optimization.
speed is a secondary reason.
-- mingo
- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/
| |