Linux2.6 support for fast system calls of new CPUs

Source: Internet
Author: User
Tags intel pentium
Linux2.6's support for new CPU fast system calls-Linux general technology-Linux programming and kernel information. The following is a detailed description. This article analyzes the implementation of the Intel CPU quick System Call Command SYSENTER/SYSEXIT introduced in Linux 2.6. Linux drivers and kernel developers can use this mechanism in their own code to improve system performance by understanding the mechanism of fast System Call commands, it also avoids some limitations caused by the fast System Call method (such as nested system calls in system calls ).

   Preface

In the Linux 2.4 kernel, the user-state Ring3 code requests the kernel-state Ring0 code to complete some functions through the system call, and the system calls the Soft Interrupt command (int 0x80). In x86 protection mode, when processing INT interrupt commands, the CPU first extracts the corresponding door descriptor from the interrupt description table IDT to determine the category of the door descriptor, then, check the level CPL of the gate descriptor DPL and INT command callers. When CPL is actually called by the system, the Ring3 enters Ring0, which wastes a lot of CPU cycles, for example, system calls must be directed from Ring3 to Ring0 (except for the INT command called by the kernel, most of which are performed by the Hacker kernel module). The level before and after permission escalation is fixed, CPL must be 3, and the DPL of INT 80 must be 3, so that the CPU checks the DPL of the gate Descriptor and the CPL of the caller is completely unnecessary. Because of this, Intel x86 CPU starts to support the new system call command sysenter/sysexit after PII 300 (Family 6, Model 3, Stepping 3. The sysenter command is used to enter Ring0 from Ring3, And the SYSEXIT command is used to return Ring3 from Ring0. Because there is no handle for privileged-level checks and there is no operation on the stack, the execution speed is much faster than INT n/IRET.

Performance Comparison of Different system call methods:

The following is a comparison of the performance of sysenter/sysexit commands and INT n/IRET commands on Intel Pentium CPU from the Internet:

Table 1: System Call performance test hardware: Intel? Pentium? Iii cpu, 450 MHz Processor Family: 6 Model: 7 Stepping: 2

Time spent by the user mode core time spent by the user mode
System Call 9.833 microseconds 6.833 microseconds Based on sysenter/sysexit commands
17.500 microseconds 7.000 microseconds

Data source: [1]



(400) {this. resized = true; this. width = 400; this. alt = 'click here to open new window';} "onmouseover =" if (this. resized) this. style. cursor = 'hand'; "onclick =" window. open ('HTTP: // linux.ccidnet.com/col/attachment/2006/10/886031.jpg'); ">

Data source: [2]

Table 2: Comparison of INT 0x80 and SYSENTER execution speeds on various CPUs

CPU Int0x80 sysenter
Athlon XP 1600 + 277 169
800 MHz mode 1 athlon 279 170
2.8 GHz p4 northwood ht 1152 442

The above data is the average data source for the CPU clock cycle consumed by 100000 getppid () system calls [3].

Since the launch of this technology, people have been considering adding support for such commands in Linux. In the Kernel.org mail list, A large number of emails with the topic "Intel P6 vs P7 system call performance" discussed the necessity of using such commands. The reason listed in the email is that Intel has problems in the design of Pentium 4, system calls that interrupt the execution of Pentium 4 are 5 to 5 more than the CPU clock cycles consumed by Pentium 3 and AMD Athlon ~ 10 times. Therefore, on the Pentium 4 platform, it is imperative to use sysenter/sysexit commands to execute system calls.

Sysenter/sysexit System Call mechanism:

Section 4.8.7 describes the sysenter/sysexit instructions in Intel's software developer Manual (Vol.2B, Vol.3. As described in the Manual, the sysenter command can be used for user code at privileged level 3 to call system kernel code at privileged level 0, while the SYSEXIT command is used for system code at privileged level 0 to return to user space. The sysenter command can be called at the three privileged levels of 3, 2, and 1 (only privileged level 3 is used in Linux), while the SYSEXIT command can only be called at the privileged level of 0.

The system that executes the sysenter command must meet two conditions: 1. The target Ring 0 code segment must be a 4 GB readable and executable non-consistent code segment in Flat Mode. 2. The target RING0 stack segment must be a 4 GB readable and writable extended stack segment in Flat Mode.
Related Article

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.