Linux Kernel Porting-hyper-threading

Source: Internet
Author: User
Article title: Analysis of Linux Kernel Porting-hyper-threading. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

Application 2.6 kernel hyper-threading mode

For most application software developers, most of the differences between Linux 2.4 and 2.6 kernel families have no direct impact on them. Most kernel changes only aim to improve system performance. But there are also exceptions. for some application software, kernel and system changes have a certain impact on their promotion and management of other processes and threads.

The 2.6 kernel provides users with a new and improved hyper-threading mode. This mode is implemented through NPTL (Native POSIX Thread Library. The adoption of the new hyper-threading mode has extraordinary significance for developers, system runtime libraries (such as the gnu c Library), and shared application software libraries. This article will introduce basic hyper-threading concepts, discuss existing Linux hyper-threading modes, and highlight how to modify existing multi-threaded applications in the 2.6 kernel.

Hyper-Threading Technology

In a multi-process operating system such as Linux, generating another process by one process is the most basic concept. The most typical example is a shell program, such as a Bash shell program. It is a standard Linux command interpreter. The shell program executes the corresponding application based on the user's command. it can start multiple commands directly and wait for them to complete. It can also execute multiple commands separately and simultaneously.

A process can usually call a group of fork () and exec () functions to generate a new process. The initial process calls the fork () function to generate a sub-process. The sub-process inherits the entire execution environment of the parent process. The fork () function calls the process ID (PID) of the sub-process to the parent process, and also includes the PID in the sub-process. then, the child process uses the exec () function to call other commands and change the inherited execution environment. At the same time, the parent process can exit quickly or wait for the child process to return to its initial state.

Linux hyper-threading mode

The standard Linux hyperthreading library of all versions earlier than Linux 2.6 is called LinuxThreads. this library can work with the gnu c library of GLIBC 2.0 and be compatible with POSIX.

During the compilation of LinuxThreads and Native POSIX Thread Library (NPTL) source code, the main libraries generated are libpthread. so and libpthread. a. For this reason, the names of LinuxThreads and pthreads can be used in the past. However, after NPTL is introduced, the two are easily confused. This article uses LinuxThreads and NPTL to clearly differentiate two hyperthreading libraries and their functions.

LinuxThreads has different performance, scalability, and availability limits. LinuxThreads uses a compiler to set the number of threads that can be generated by a single process. In addition, it uses a process manager to coordinate the relationships between all threads generated by each process. This will greatly increase the number of threads to establish and eliminate occupied resources. Although almost every thread has an independent process ID, signal processing is still completed in each process. For various reasons, during the implementation of LinuxThreads, the number of threads simultaneously generated and working is often limited. These factors include the asymmetry between the kernel and user space threads, lack of thread synchronization primitives required for inter-thread communication and resource sharing.

Another hyperthread mode in Linux is IBM's next-generation POSIX Thread (NGPT) project. It is an external hyperthreading library that works with the LinuxThreads suite. However, it can provide additional POSIX support and better performance than the standard LinuxThreads suite. The NGPT kit can be used in Linux2.4 and earlier kernels. due to the generation of the new superthread mode, its application scope is getting smaller and smaller.

Since the emergence of the 2.5 kernel, NPTL has gradually replaced LinuxThreads and NGPT. NPTL provides high-performance hyper-threading support for Linux systems, basic features required by multi-threaded enterprise application software, and high-capacity, high-load network and mail servers. NPTL development is part of the 2.5 kernel development process and is integrated with Linux runtime components (such as GLIBC). NPTL with many advantages is the future development direction of Linux threads.

Some Linux system manufacturers (such as Red Hat) have begun to append NPTL to earlier versions of the kernel, and even use an environment variable to create a hyper-threading environment for specific optional processes. In systems that support this function, you can use the following command to set variables:

# Export LD_ASSUME_KERNEL = 2.4.1

For existing applications that originally rely on the LinuxThreads model, it is a clever way to continue working in the NPTL environment, but it is also a matter of privilege. To better utilize NPTL's design and performance advantages, you need to upgrade the code of existing application software using hyper-threading mode.

Application software re-compilation

Although many applications do not need to be re-compiled during the porting process from the 2.4 kernel to the 2.6 kernel, the NPTL additional technology of most multithreading applications needs to be slightly modified.

Those applications that need to be re-compiled may be affected by upgrading the compilation program. These compilers are generally included in the 2.6 kernel-based Linux suite, such as the TimeSys Linux system. TimeSys bundled C and C ++ compilers of GCC 3.3.2 with 2.6 Reference Distributions, and used the upgraded version of binutils to make up for the shortcomings of the standard Linux tool chain.

Using a 2.6-based kernel does not mean that you have used NPTL automatically. To determine the hyperthreading library used by the system, you can run the following command to check the environment variable GNU_LIBPTHREAD_VERSION, as shown below:

       
        # getconf GNU_LIBPTHREAD_VERSIONlinuxthreads-0.10If your system uses the NPTL, the command would return the value of NPTL that your system was using,as in the following example:# getconf GNU_LIBPTHREAD_VERSIONnptl-0.60
       

 

[1] [2] Next page

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.