Linux2.6 Support for new CPUs

Source: Internet
Author: User

This article analyzes the implementation of the Sysenter/sysexit support for the Intel CPU fast system call instruction introduced in Linux 2.6. Linux drivers and kernel developers can use this mechanism in their own code to improve system performance and avoid some of the limitations (such as nested system calls in system calls) that are caused by rapid system invocation by understanding the mechanism of quick system call instructions.

Objective

In the Linux 2.4 kernel, the user state Ring3 code requests the kernel state RING0 code completes some function through the system call, and the system calls through the soft interrupt instruction (int 0x80). In x86 protection mode, when processing an int interrupt instruction, the CPU first takes out the corresponding gate descriptor from the interrupt description table IDT, judges the type of door descriptor, then examines the level of the door descriptor DPL and the level CPL of the int instruction caller, when CPL<=DPL that is, the INT calls The user level is higher than the descriptor specified level, can be successfully invoked, and finally, according to the content of the descriptor, the stack, jump, permission level promotion. After the kernel code has finished executing, call the IRET instruction return, IRET instruction restores the user stack, and jumps the transfer low level code.

In fact, in the event of a system call, the process of entering RING0 by Ring3 wastes a lot of CPU cycles, for example, the system call must be Ring3 into the RING0 (except for the way the kernel invokes the INT instruction, which is mostly owned by the Hacker kernel module), before privilege elevation and After the level is fixed, CPL is definitely 3, and INT 80 of the DPL must also be 3, so the CPU to check the door descriptor DPL and the caller's CPL is completely unnecessary. It is for this reason that the Intel x86 CPU begins to support the new system call instruction Sysenter/sysexit after PII (Family 6,model 3,stepping 3). The sysenter directive is used by the Ring3 to enter the ring0,sysexit instruction to return Ring3 by RING0. Because there is no privilege level check processing, there is no pressure stack operation, so the execution speed is much faster than the INT N/iret.

Performance comparisons for different system invocation modes:

Here are some of the performance comparisons from the internet about Sysenter/sysexit directives and INT N/iret directives on the Intel Pentium CPU:

1: System invoke performance test test hardware:

Intel? Pentium? III CPU, 450 MHz Processor family:6 model:7 stepping:2

Time spent in user mode core mode

System calls based on Sysenter/sysexit directives 9.833 microseconds 6.833 microseconds

System call based on interrupt INT n instruction 17.500 microseconds 7.000 microseconds

2: Comparison of the execution speed of INT 0x80 and Sysenter on various CPUs

CPU int0x80 Sysenter

Athlon XP 1600+ 277 169

800MHz Mode 1 Athlon 279 170

2.8GHZ P4 Northwood HT 1152 442

The above data is the average of CPU clock cycles spent on 100,000-time getppid () system calls

Since the introduction of this technology, people have been considering adding support for this instruction in Linux, and in the kernel.org mailing list, a large number of emails with the theme "Intel P6 vs P7 system call performance" discussed the need for such instructions, The main reasons cited in the case are Intel's Pentium 4 design problem, resulting in Pentium 4 of system calls performed using interrupts 5~10 times more than the CPU clock cycles consumed by Pentium 3 and AMD Athlon. Therefore, on the Pentium 4 platform, it is urgent to execute system call by Sysenter/sysexit instruction.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.