lexszero
16.12.2011 23:13 nyapad
At every process switch, the hardware context of the process being replaced must be saved somewhere. It cannot be saved on the TSS, as in the original Intel design, because Linux uses a single TSS for each processor, instead of one for every process.
Recommended by:
@asmer: воистину говно. Интересно, почему?
интересно, какого хуя?
Old versions of Linux took advantage of the hardware support offered by the 80x86 architecture and performed a process switch through a far jmp instruction[*] to the selector of the Task State Segment Descriptor of the next process. While executing the instruction, the CPU performs a hardware context switch by automatically saving the old hardware context and loading a new one. But Linux 2.6 uses software to
perform a process switch for the following reasons:
[*] far jmp instructions modify both the cs and eip registers, while simple jmp instructions modify only eip.
• Step-by-step switching performed through a sequence of mov instructions allows better control over the validity of the data being loaded. In particular, it is possible to check the values of the ds and es segmentation registers, which might have been forged by a malicious user. This type of checking is not possible when using a single far jmp instruction.
• The amount of time required by the old approach and the new approach is about the same. However, it is not possible to optimize a hardware context switch, while there might be room for improving the current switching code.
спасибо. странно, что загрузка/выгрузка контекста силами проца и кодом по времени близка.
думаю, что пачка mov-ов транслируется в примерно тот же микрокод, что и вкомбаенированная говнофича. ну и вообще, собственно сохранение-восстановление регистров занимает достаточно мало времени по сравнению с лазанью по потрохам скедьюлера, еблей MMU етц.