CN117008909A - Linux kernel optimization processing method and device, storage medium and electronic device - Google Patents

Linux kernel optimization processing method and device, storage medium and electronic device Download PDF

Info

Publication number
CN117008909A
CN117008909A CN202210453841.2A CN202210453841A CN117008909A CN 117008909 A CN117008909 A CN 117008909A CN 202210453841 A CN202210453841 A CN 202210453841A CN 117008909 A CN117008909 A CN 117008909A
Authority
CN
China
Prior art keywords
optimization
kernel
configuration table
fine
optimizing
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202210453841.2A
Other languages
Chinese (zh)
Inventor
贺洪军
曹继承
叶明�
李禄财
程圣宇
郭耀
王远鹏
陈向群
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Peking University
ZTE Corp
Original Assignee
Peking University
ZTE Corp
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Peking University, ZTE Corp filed Critical Peking University
Priority to CN202210453841.2A priority Critical patent/CN117008909A/en
Priority to PCT/CN2023/091320 priority patent/WO2023208140A1/en
Publication of CN117008909A publication Critical patent/CN117008909A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/44Encoding
    • G06F8/443Optimisation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • G06F8/71Version control; Configuration management

Landscapes

  • Engineering & Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Computer Security & Cryptography (AREA)
  • Devices For Executing Special Programs (AREA)
  • Stored Programmes (AREA)

Abstract

The embodiment of the application provides a Linux kernel optimization processing method, a device, a storage medium and an electronic device, wherein the method comprises the following steps: generating a fine optimization configuration table according to the user configuration table; performing targeted instrumentation on the kernel source codes, and running a target program to obtain kernel feedback information; according to the fine optimization configuration table and the kernel feedback information, the kernel source code is optimized to obtain an optimized kernel, the problems that in the related art, the granularity of an acting object for optimizing the kernel source code is coarse, the compiling optimization capability of a modern compiler cannot be fully exerted, and the range of compiling optimization cannot be flexibly controlled can be solved, the compiler plug-in is adopted to automatically complete the optimization process, the acting range of Linux kernel feedback optimization can be freely controlled, and the running performance of an application program is additionally improved on the basis of not modifying the application program.

Description

Linux kernel optimization processing method and device, storage medium and electronic device
Technical Field
The embodiment of the application relates to the field of software, in particular to a Linux kernel optimization processing method and device, a storage medium and an electronic device.
Background
In many industrial scenarios where software performance requirements are high, a Linux operating system typically runs only specific applications. If the kernel of the operating system can be optimized according to the pertinence of the application program, the running performance of the application program can be further improved on the basis of not modifying the application program. The common Linux kernel optimization method at present is feedback type compiling optimization, but the whole kernel source codes share the same set of compiling optimization parameters, the granularity of an optimized acting object is thicker, and the compiling optimization capability of a modern compiler cannot be fully exerted. Meanwhile, a user cannot conveniently specify certain modules, files and even functions in the kernel source code, do not participate in optimization, and cannot flexibly control the range of compiling optimization.
Aiming at the problems that the granularity of an acting object of kernel source code optimization in the related technology is coarse, the compiling optimization capability of a modern compiler cannot be fully exerted, and the range of compiling optimization cannot be flexibly controlled, no solution is proposed.
Disclosure of Invention
The embodiment of the application provides a Linux kernel optimization processing method, a device, a storage medium and an electronic device, which at least solve the problems that the granularity of an action object of kernel source code optimization in the related technology is thicker, the compiling optimization capability of a modern compiler cannot be fully exerted, and the range of compiling optimization cannot be flexibly controlled.
According to one embodiment of the application, there is provided a Linux kernel optimization processing method, including:
generating a fine optimization configuration table according to the user configuration table;
performing targeted instrumentation on the kernel source codes, and running a target program to obtain kernel feedback information;
and optimizing the kernel source code according to the fine optimization configuration table and the kernel feedback information to obtain an optimized kernel.
In an embodiment, according to the fine optimization configuration table and the kernel feedback information, performing optimization processing on kernel source codes to obtain an optimized kernel includes:
generating an optimized parameter combination according to the kernel feedback information;
and optimizing the module, file or function of the kernel according to the fine optimization configuration table and the optimization parameter combination.
In one embodiment, optimizing the module, file or function of the kernel according to the fine optimization configuration table and the optimization parameter combination includes:
reading the fine optimization configuration table and determining the optimization range of the kernel source code;
if the optimization level is a module, the minimum unit of the optimization range is a module, and the optimization parameter combination is applied to optimize all C/C++ files contained in the kernel module in the fine optimization configuration table;
if the optimization level is a file, the minimum unit of the optimization range is a file, and the optimization parameter combination is applied to optimize all C/C++ files in the fine optimization configuration table;
and if the optimization level is a function, the minimum unit of the optimization range is a function, and the optimization parameter combination is applied to optimize the functions of all C/C++ files in the fine optimization configuration table to participate in optimization.
In an embodiment, the optimizing the C/c++ files included in the kernel module in the fine optimization configuration table by using the optimization parameter combination includes: C/C++ files contained in the modules which do not participate in optimization are not subject to instrumentation and optimization, and C/C++ files contained in other modules except the modules which do not participate in optimization are subject to instrumentation and optimization;
the optimizing parameter combination is applied to optimize all C/C++ files in the fine optimizing configuration table, and the optimizing processing comprises the following steps: the C/C++ files which do not participate in optimization are not subject to instrumentation and optimization, and the rest C/C++ files except the C/C++ files which do not participate in optimization are subject to instrumentation and optimization;
the optimizing parameter combination is applied to optimize the functions of all C/C++ files participating in optimization in the fine optimizing configuration table, and the optimizing processing comprises the following steps: and performing instrumentation and optimization on the functions which do not participate in optimization of the C/C++ files and the C/C++ files which participate in optimization, and performing instrumentation and optimization on the other functions except the functions which do not participate in optimization of the C/C++ files and the functions which do not participate in optimization.
In one embodiment, generating the fine optimization configuration table from the user configuration table comprises:
when kernel hot spot information is sampled, traversing all C/C++ files of top-level directories corresponding to all hot spot functions, and generating the fine optimization configuration table according to the kernel hot spot information and the user configuration table;
and when the kernel hot spot information is not sampled, traversing all C/C++ files of the kernel source codes, and generating the fine optimization configuration table according to a user configuration table.
In one embodiment, generating the fine optimization configuration table from the kernel hotspot information and the user configuration table comprises:
operating an object program, and obtaining the kernel hot spot information by using a hot spot sampling tool;
and extracting information of the user configuration table according to the optimization level, removing C/C++ files which do not participate in optimization, and recording functions which do not participate in optimization aiming at each C/C++ file which participate in optimization to form the fine optimization configuration table.
In an embodiment, performing targeted instrumentation on the kernel source code, and running the target program, where obtaining the kernel feedback information includes:
transplanting or creating a data stream instrumentation code into the kernel source code, and adapting functions and data interfaces of the kernel;
and combining the control flow instrumentation information and the data flow instrumentation information to obtain the kernel feedback information.
In an embodiment, after the targeted instrumentation is performed on the kernel source code and the target program is operated, the method further includes:
and writing the kernel feedback information into a kernel feedback information file by calling a debugFS interface.
According to another embodiment of the present application, there is also provided a Linux kernel optimization processing device, including:
the generating module is used for generating a fine optimization configuration table according to the user configuration table;
the instrumentation module is used for performing targeted instrumentation on the kernel source codes, running a target program and obtaining kernel feedback information;
and the optimizing module is used for optimizing the kernel source code according to the fine optimizing configuration table and the kernel feedback information to obtain an optimized kernel.
In an embodiment, the optimization module includes:
the generation sub-module is used for generating an optimized parameter combination according to the kernel feedback information;
and the optimizing sub-module is used for optimizing the module, the file or the function of the kernel according to the fine optimizing configuration table and the optimizing parameter combination.
In an embodiment, the optimization submodule includes:
the determining unit is used for reading the fine optimization configuration table and determining the optimization range of the kernel source code;
the first optimizing unit is used for optimizing all C/C++ files contained in the kernel module in the fine optimizing configuration table by applying the optimizing parameter combination if the optimizing level is a module and the minimum unit of the optimizing range is a module;
the second optimizing unit is used for optimizing all C/C++ files in the fine optimizing configuration table by applying the optimizing parameter combination if the optimizing level is a file and the minimum unit of the optimizing range is a file;
and the third optimizing unit is used for optimizing the functions of all the C/C++ files in the fine optimizing configuration table by applying the optimizing parameter combination if the optimizing level is a function and the minimum unit of the optimizing range is a function.
In an embodiment, the first optimizing unit is further configured to perform instrumentation and optimization on C/c++ files included in the modules that do not participate in optimization, where the C/c++ files included in the other modules except for the modules that do not participate in optimization are subject to instrumentation and optimization;
the second optimizing unit is further used for performing instrumentation and optimization on the C/C++ files which do not participate in optimization, and performing instrumentation and optimization on the rest of C/C++ files except the C/C++ files which do not participate in optimization;
the third optimizing unit is further configured to perform instrumentation and optimization on functions that do not participate in optimization between the C/c++ files that do not participate in optimization and the C/c++ files that do not participate in optimization, where the functions that do not participate in optimization and the functions that do not participate in optimization are other than the functions that do not participate in optimization.
In an embodiment, the generating module includes:
the first generation sub-module is used for traversing all C/C++ files of the top-level catalogs corresponding to all hot spot functions when the kernel hot spot information is sampled, and generating the fine optimization configuration table according to the kernel hot spot information and the user configuration table;
and the second generation sub-module is used for traversing all C/C++ files of the kernel source codes when the kernel hot spot information is not sampled, and generating the fine optimization configuration table according to a user configuration table.
In an embodiment, the first generating sub-module is further configured to
Operating an object program, and obtaining the kernel hot spot information by using a hot spot sampling tool;
and extracting information of the user configuration table according to the optimization level, removing C/C++ files which do not participate in optimization, and recording functions which do not participate in optimization aiming at each C/C++ file which participate in optimization to form the fine optimization configuration table.
In an embodiment, the pile inserting module is further configured to
Transplanting or creating a data stream instrumentation code into the kernel source code, and adapting functions and data interfaces of the kernel;
and combining the control flow instrumentation information and the data flow instrumentation information to obtain the kernel feedback information.
In an embodiment, the device further comprises:
and the writing module is used for writing the kernel feedback information into a kernel feedback information file by calling a debugFS interface.
According to a further embodiment of the application, there is also provided a computer-readable storage medium having stored therein a computer program, wherein the computer program is arranged to perform the steps of any of the method embodiments described above when run.
According to a further embodiment of the application, there is also provided an electronic device comprising a memory having stored therein a computer program and a processor arranged to run the computer program to perform the steps of any of the method embodiments described above.
According to the embodiment of the application, a fine optimization configuration table is generated according to the user configuration table; performing targeted instrumentation on the kernel source codes, and running a target program to obtain kernel feedback information; according to the fine optimization configuration table and the kernel feedback information, the kernel source code is optimized to obtain an optimized kernel, the problems that in the related art, the granularity of an acting object for optimizing the kernel source code is coarse, the compiling optimization capability of a modern compiler cannot be fully exerted, and the range of compiling optimization cannot be flexibly controlled can be solved, the compiler plug-in is adopted to automatically complete the optimization process, the acting range of Linux kernel feedback optimization can be freely controlled, and the running performance of an application program is additionally improved on the basis of not modifying the application program.
Drawings
FIG. 1 is a block diagram of a hardware structure of a mobile terminal of a Linux kernel optimization processing method according to an embodiment of the application;
FIG. 2 is a flow chart of a Linux kernel optimization processing method according to an embodiment of the application;
FIG. 3 is an overall framework and flowchart of feedback guidance based Linux kernel fine optimization in accordance with the present embodiment;
FIG. 4 is a schematic diagram of the interior of a compiler plug-in according to the present embodiment;
FIG. 5 is a schematic diagram of the use of a perf hotspot sampling tool according to the present embodiment;
fig. 6 is a flowchart of generating a fine optimization configuration table according to the present embodiment;
fig. 7 is a schematic diagram of a fine optimization configuration table according to the present embodiment;
fig. 8 is a block diagram of a Linux kernel optimization processing apparatus according to the present embodiment.
Detailed Description
Embodiments of the present application will be described in detail below with reference to the accompanying drawings in conjunction with the embodiments.
It should be noted that the terms "first," "second," and the like in the description and the claims of the present application and the above figures are used for distinguishing between similar objects and not necessarily for describing a particular sequential or chronological order.
The method embodiments provided in the embodiments of the present application may be performed in a mobile terminal, a computer terminal or similar computing device. Taking a mobile terminal as an example, fig. 1 is a block diagram of a hardware structure of the mobile terminal according to the Linux kernel optimization processing method of an embodiment of the present application, as shown in fig. 1, the mobile terminal may include one or more (only one is shown in fig. 1) processors 102 (the processors 102 may include, but are not limited to, a microprocessor MCU or a processing device such as a programmable logic device FPGA) and a memory 104 for storing data, where the mobile terminal may further include a transmission device 106 for a communication function and an input/output device 108. It will be appreciated by those skilled in the art that the structure shown in fig. 1 is merely illustrative and not limiting of the structure of the mobile terminal described above. For example, the mobile terminal may also include more or fewer components than shown in fig. 1, or have a different configuration than shown in fig. 1.
The memory 104 may be used to store a computer program, for example, a software program of an application software and a module, such as a computer program corresponding to a Linux kernel optimization processing method in an embodiment of the present application, and the processor 102 executes various functional applications and service chain address pool slicing processing by running the computer program stored in the memory 104, that is, implements the method described above. Memory 104 may include high-speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 104 may further include memory remotely located relative to the processor 102, which may be connected to the mobile terminal via a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
The transmission means 106 is arranged to receive or transmit data via a network. Specific examples of the network described above may include a wireless network provided by a communication provider of the mobile terminal. In one example, the transmission device 106 includes a network adapter (Network Interface Controller, simply referred to as NIC) that can connect to other network devices through a base station to communicate with the internet. In one example, the transmission device 106 may be a Radio Frequency (RF) module, which is used to communicate with the internet wirelessly.
In this embodiment, a Linux kernel optimization processing method running on the mobile terminal or the network architecture is provided, and fig. 2 is a flowchart of the Linux kernel optimization processing method according to an embodiment of the present application, as shown in fig. 2, where the flowchart includes the following steps:
step S202, generating a fine optimization configuration table according to a user configuration table;
step S204, performing targeted instrumentation on the kernel source codes, and running a target program to obtain kernel feedback information;
and S206, optimizing the kernel source code according to the fine optimization configuration table and the kernel feedback information to obtain an optimized kernel.
Generating a fine optimization configuration table according to the user configuration table through the steps S202 to S206; performing targeted instrumentation on the kernel source codes, and running a target program to obtain kernel feedback information; according to the fine optimization configuration table and the kernel feedback information, the kernel source code is optimized to obtain an optimized kernel, the problems that in the related art, the granularity of an acting object for optimizing the kernel source code is coarse, the compiling optimization capability of a modern compiler cannot be fully exerted, and the range of compiling optimization cannot be flexibly controlled can be solved, the compiler plug-in is adopted to automatically complete the optimization process, the acting range of Linux kernel feedback optimization can be freely controlled, and the running performance of an application program is additionally improved on the basis of not modifying the application program.
The embodiment can be applied to smart phones, supercomputers, server clusters of data centers, linux kernels and the like. And a fine Linux kernel optimization strategy with feedback guidance is adopted, so that an application program running on the kernel obtains better performance. This optimization technique is generic, that is, different application scenarios and applications can use this technique to improve Linux kernel performance.
In this embodiment, the step S206 may specifically include: generating an optimized parameter combination according to the kernel feedback information; and optimizing the module, the file or the function of the kernel according to the fine optimization configuration table and the optimization parameter combination, wherein the optimizing can comprise the following steps: reading the fine optimization configuration table and determining the optimization range of the kernel source code;
if the optimization level is a module, the minimum unit of the optimization range is a module, the optimization parameter combination is applied to optimize all C/C++ files contained in the kernel module in the fine optimization configuration table, and specifically, C/C++ files contained in the modules which do not participate in optimization are not subjected to instrumentation and optimization, and C/C++ files contained in other modules except the modules which do not participate in optimization are subjected to instrumentation and optimization;
if the optimization level is a file, the minimum unit of the optimization range is a file, the optimization parameter combination is applied to optimize all C/C++ files in the fine optimization configuration table, and specifically, C/C++ files which do not participate in optimization are not subjected to instrumentation and optimization, and other C/C++ files except the C/C++ files which do not participate in optimization are subjected to instrumentation and optimization;
if the optimization level is a function, the minimum unit of the optimization range is a function, the optimization parameter combination is applied to optimize all functions of the C/C++ files in the fine optimization configuration table, and specifically, the functions of the C/C++ files which do not participate in optimization and the C/C++ files which do not participate in optimization are not subject to instrumentation and optimization, and the rest functions except the functions of the C/C++ files which do not participate in optimization and the functions of the C/C++ files which do not participate in optimization are subject to instrumentation and optimization.
In this embodiment, the step S202 may specifically include:
when kernel hot spot information is sampled, traversing all C/C++ files of a top-level directory corresponding to all hot spot functions, generating the fine optimization configuration table according to the kernel hot spot information and the user configuration table, specifically, running a target program, and obtaining the kernel hot spot information by using a hot spot sampling tool; extracting information of the user configuration table according to the optimization level, removing C/C++ files which do not participate in optimization, and recording functions which do not participate in optimization aiming at each C/C++ file which participate in optimization to form the fine optimization configuration table;
and when the kernel hot spot information is not sampled, traversing all C/C++ files of the kernel source codes, and generating the fine optimization configuration table according to a user configuration table.
In this embodiment, the step S204 may specifically include: transplanting or newly creating a data stream instrumentation code into the kernel source code, specifically, transplanting the data stream instrumentation code of a user-state libgcov open source library into the kernel source code, or newly creating the data stream instrumentation code, and adapting functions and data interfaces of a kernel; and combining the control flow instrumentation information and the data flow instrumentation information to obtain the kernel feedback information.
Further, the kernel feedback information is written into a kernel feedback information file by calling a debugFS interface.
FIG. 3 is an overall framework and flowchart of feedback-guided Linux kernel refinement based optimization according to the present embodiment, typically involving a three-pass compilation kernel process, as shown in FIG. 3. And compiling the kernel for the first time, running the target program, and obtaining kernel hot spot information by using a hot spot sampling tool. And compiling the kernel for the second time, generating a fine optimization configuration table by a compiler according to the user configuration table and the kernel hot spot information, performing targeted instrumentation on the kernel source code, and operating a target program to obtain kernel feedback information. And compiling the kernel for the third time, performing targeted optimization on the kernel source code according to the fine optimization configuration table and the kernel feedback information, and outputting an optimized kernel. The method specifically comprises the following steps:
step 1, modifying a gcov subsystem of a Linux kernel source code to enable the gcov subsystem to support data stream instrumentation, combining control stream instrumentation information and data stream instrumentation information to generate kernel feedback information, and storing the kernel feedback information on a disk.
Step 2, a compiler plug-in is manufactured, and the plug-in comprises three parts:
the optimization level controls whether the kernel optimization is module level, file level, or function level, specified by a command line parameter.
And generating an optimization parameter, and automatically generating an optimization parameter combination according to the kernel feedback information.
And (3) optimizing parameter application, namely applying optimizing parameter combination according to the designated optimizing level and the generated fine optimizing configuration table. If the optimization level is a module level, then the minimum granularity of the optimization parameter combination is the kernel module. Optimization for file level and function level, and so on.
And step 3, compiling the kernel source code for the first time by using a compiler with plug-in, and running a specific application program on the compiled Linux operating system.
And 4, acquiring function information operated in the kernel by using a hot spot sampling tool, and extracting the function arranged in front as the kernel hot spot according to the time-consuming duty ratio sequence. Specifically, two modes can be adopted, namely, the functions with the time consumption ratio exceeding a certain threshold value are regarded as hot spot functions, the threshold value can be set manually, and the default value is adopted when the threshold value is not set; secondly, the function with the time consumption accounting for the front is regarded as a hot spot function, the threshold value of the front percentage can be set manually, and the default value is adopted when the threshold value is not set. The threshold is specified by a command line parameter.
And 5, extracting user configuration information from the user configuration table, constructing the user configuration table, wherein the table comprises default configuration items and supplementary configuration items, the default configuration items comprise modules, files and function information which cannot be inserted in kernel source codes, and the kernels cannot normally run after the kernel is inserted in the positions. The user can specify the kernel module, the file and the function information which do not participate in compiling optimization through the supplementary configuration items. The default configuration item is built in the system, and the supplementary configuration item is determined by a user according to actual conditions to be filled in or not.
And 6, generating a fine optimization configuration table according to the kernel hot spot information and the user configuration information. Notably, the fine optimization configuration table may also be generated using only user configuration information.
And 7, performing targeted instrumentation on the kernel source codes according to the fine optimization configuration table, and compiling the kernel source codes for the second time by using a compiler with a plug-in.
And 8, running a specific application program on the compiled Linux operating system, and writing the control flow and data flow instrumentation information in the step 1 into a kernel feedback information file through a debugFS interface of the kernel.
And 9, compiling the kernel source code for the third time by using a compiler with a plug-in according to the fine optimization configuration table in the step 6 and the kernel feedback information file in the step 8, so as to realize fine feedback guidance optimization and generate an optimized version kernel suitable for a specific application program.
Step 1 is a gcov subsystem for modifying Linux-4.19 kernel source code. Because the original gcov subsystem only supports control flow instrumentation and not data flow instrumentation. Transplanting the data stream instrumentation code of the user-state libgcov open source library into the kernel source code, adapting the function and the data interface of the kernel, combining the control stream instrumentation information and the data stream instrumentation information to obtain kernel feedback information, and writing the kernel feedback information into a kernel feedback information file by calling a debugFS interface. This portion of the migration code is presented in the form of a patch, i.e., the ability to instrumentation and information consolidation of the core data stream is given by patching. The method of transplanting codes from the libgcov open source library does not limit the scope of the step 1 of the present application, but provides a typical example, and the ability of inserting piles and merging information is given to the data stream of the kernel gcov subsystem by other methods, which is also within the scope of the present application.
Fig. 4 is a schematic diagram of the inside of the compiler plug-in according to the present embodiment, and as shown in fig. 4, mainly includes three modules:
(1) The optimization level control module: the module inputs a command line parameter optlveel, takes one of a module, a file and a function as a default, and transmits the parameter to the optimized parameter application module.
(2) And an optimization parameter generation module: automatically generating an optimization parameter combination "-fpprofile-use-fpprofile-correction-Wno-error = coverage-mismatch-fpprofile-dir=/path/to/profile", wherein/path/to/profile refers to the location of the input kernel feedback information file on the disk. The module communicates the values of the optimization parameter combinations to the optimization parameter application module.
(3) And the optimization parameter application module: reading a fine optimization configuration table, determining an optimization range of kernel source codes, and applying optimization parameter combinations to all C/C++ files contained in kernel modules in the fine optimization configuration table if the optimization level is a module; if the optimization level is a file, applying optimization parameter combinations to all C/C++ files in the fine optimization configuration table; if the optimization level is a function, applying an optimization parameter combination to the functions participating in optimization in all C/C++ files in the fine optimization configuration table.
FIG. 5 is a schematic diagram of using the perf hotspot sampling tool according to the present embodiment, as shown in FIG. 5, with collected function time consuming duty cycle ranking information while running the MySQL application. Wherein "kernel" in the "type" column indicates that the corresponding function is located in the Linux kernel, "libslang.so.2.3.1" and "libc-2.27.so" indicate that the corresponding function is located in the external dynamic library. And taking the kernel function with the time consumption accounting for 50% of the ranking as a hot spot, and storing the hot spot into a kernel hot spot file.
FIG. 6 is a flowchart for generating a fine optimization configuration table according to the present embodiment, as shown in FIG. 6, when kernel hotspot information is sampled, all C/C++ files of the top-level directory corresponding to all hotspot functions are traversed; when the kernel hot spot information is not sampled, all C/C++ files of the whole Linux kernel source code are traversed. And extracting information of the user configuration table according to the optimization level, and removing C/C++ files which do not participate in optimization to form a fine optimization configuration table. If the optimization level is a module, the minimum unit of the kernel source code optimization range is a module, namely, C/C++ files contained in the modules which do not participate in optimization are not inserted and optimized, and the rest modules are inserted and optimized. If the optimization level is a file, the minimum unit of the optimization range is the file, the C/C++ files which do not participate in optimization are not subject to the instrumentation optimization, and the rest files are subject to the instrumentation optimization. And if the optimization level is a function, the minimum unit of the optimization range is a function, the C/C++ files which do not participate in optimization are not subjected to instrumentation optimization, and if the files which participate in optimization contain functions which are not optimized, the corresponding functions are not subjected to instrumentation optimization, and the other functions are subjected to instrumentation and optimization. The fine optimization configuration table may be organized in various manners, in which a file and a function are used as units, fig. 7 is a schematic diagram of the fine optimization configuration table according to this embodiment, and as shown in fig. 7, a column of "file names" is the C/c++ file names of all the functions participating in optimization after filtering, a column of "excluding function names" records the functions not participating in instrumentation and optimization in the corresponding file, and a blank indicates that all the functions of the corresponding file are to be instrumented and optimized.
According to the fine optimization configuration table, the GCC-9.2.0 compiler builds the Linux KERNEL of the instrumented version, and before building, the CONFIG_GCOV_KERNEL and CONFIG_GCOV_PROFILE_ALL options need to be opened to enable the KERNEL GCOV subsystem.
And running a target program on the constructed Linux operating system to obtain feedback information of the kernel, and storing the feedback information on a disk in a file form.
The GCC-9.2.0 compiler is used again to build the Linux KERNEL, and the CONFIG_GCOV_KERNEL and CONFIG_GCOV_PROFILE_ALL options before closing are needed for the compilation at this time to disable the KERNEL GCOV subsystem. And outputting the kernel of the optimized version by the compiler according to the fine optimization configuration table and the kernel feedback information file and the module, the file and the function of the kernel which are optimized in a targeted manner.
The fine feedback type optimization process is executed through the terminal command line, and the modules, files and function information which do not participate in the optimization are provided through the user configuration table file.
According to another embodiment of the present application, there is further provided a Linux kernel optimization processing device, and fig. 8 is a block diagram of the Linux kernel optimization processing device according to the present embodiment, as shown in fig. 8, where the device includes:
a generating module 82, configured to generate a fine optimization configuration table according to the user configuration table;
the instrumentation module 84 is configured to perform targeted instrumentation on the kernel source code, and operate a target program to obtain kernel feedback information;
and the optimizing module 86 is configured to perform optimizing processing on the kernel source code according to the fine optimizing configuration table and the kernel feedback information, so as to obtain an optimized kernel.
In one embodiment, the optimization module 86 includes:
the generation sub-module is used for generating an optimized parameter combination according to the kernel feedback information;
and the optimizing sub-module is used for optimizing the module, the file or the function of the kernel according to the fine optimizing configuration table and the optimizing parameter combination.
In an embodiment, the optimization submodule includes:
the determining unit is used for reading the fine optimization configuration table and determining the optimization range of the kernel source code;
the first optimizing unit is used for optimizing all C/C++ files contained in the kernel module in the fine optimizing configuration table by applying the optimizing parameter combination if the optimizing level is a module and the minimum unit of the optimizing range is a module;
the second optimizing unit is used for optimizing all C/C++ files in the fine optimizing configuration table by applying the optimizing parameter combination if the optimizing level is a file and the minimum unit of the optimizing range is a file;
and the third optimizing unit is used for optimizing the functions of all the C/C++ files in the fine optimizing configuration table by applying the optimizing parameter combination if the optimizing level is a function and the minimum unit of the optimizing range is a function.
In an embodiment, the first optimizing unit is further configured to perform instrumentation and optimization on C/c++ files included in the modules that do not participate in optimization, where the C/c++ files included in the other modules except for the modules that do not participate in optimization are subject to instrumentation and optimization;
the second optimizing unit is further used for performing instrumentation and optimization on the C/C++ files which do not participate in optimization, and performing instrumentation and optimization on the rest of C/C++ files except the C/C++ files which do not participate in optimization;
the third optimizing unit is further configured to perform instrumentation and optimization on functions that do not participate in optimization between the C/c++ files that do not participate in optimization and the C/c++ files that do not participate in optimization, where the functions that do not participate in optimization and the functions that do not participate in optimization are other than the functions that do not participate in optimization.
In one embodiment, the generating module 82 includes:
the first generation sub-module is used for traversing all C/C++ files of the top-level catalogs corresponding to all hot spot functions when the kernel hot spot information is sampled, and generating the fine optimization configuration table according to the kernel hot spot information and the user configuration table;
and the second generation sub-module is used for traversing all C/C++ files of the kernel source codes when the kernel hot spot information is not sampled, and generating the fine optimization configuration table according to a user configuration table.
In an embodiment, the first generating sub-module is further configured to
Operating an object program, and obtaining the kernel hot spot information by using a hot spot sampling tool;
and extracting information of the user configuration table according to the optimization level, removing C/C++ files which do not participate in optimization, and recording functions which do not participate in optimization aiming at each C/C++ file which participate in optimization to form the fine optimization configuration table.
In one embodiment, the stake-inserting module 84 is also used for
Transplanting or creating a data stream instrumentation code into the kernel source code, and adapting functions and data interfaces of the kernel;
and combining the control flow instrumentation information and the data flow instrumentation information to obtain the kernel feedback information.
In an embodiment, the device further comprises:
and the writing module is used for writing the kernel feedback information into a kernel feedback information file by calling a debugFS interface.
Embodiments of the present application also provide a computer readable storage medium having a computer program stored therein, wherein the computer program is arranged to perform the steps of any of the method embodiments described above when run.
In one exemplary embodiment, the computer readable storage medium may include, but is not limited to: a usb disk, a Read-Only Memory (ROM), a random access Memory (Random Access Memory, RAM), a removable hard disk, a magnetic disk, or an optical disk, or other various media capable of storing a computer program.
An embodiment of the application also provides an electronic device comprising a memory having stored therein a computer program and a processor arranged to run the computer program to perform the steps of any of the method embodiments described above.
In an exemplary embodiment, the electronic apparatus may further include a transmission device connected to the processor, and an input/output device connected to the processor.
Specific examples in this embodiment may refer to the examples described in the foregoing embodiments and the exemplary implementation, and this embodiment is not described herein.
It will be appreciated by those skilled in the art that the modules or steps of the application described above may be implemented in a general purpose computing device, they may be concentrated on a single computing device, or distributed across a network of computing devices, they may be implemented in program code executable by computing devices, so that they may be stored in a storage device for execution by computing devices, and in some cases, the steps shown or described may be performed in a different order than that shown or described herein, or they may be separately fabricated into individual integrated circuit modules, or multiple modules or steps of them may be fabricated into a single integrated circuit module. Thus, the present application is not limited to any specific combination of hardware and software.
The above description is only of the preferred embodiments of the present application and is not intended to limit the present application, but various modifications and variations can be made to the present application by those skilled in the art. Any modification, equivalent replacement, improvement, etc. made within the principle of the present application should be included in the protection scope of the present application.

Claims (11)

1. The Linux kernel optimization processing method is characterized by comprising the following steps of:
generating a fine optimization configuration table according to the user configuration table;
performing targeted instrumentation on the kernel source codes, and running a target program to obtain kernel feedback information;
and optimizing the kernel source code according to the fine optimization configuration table and the kernel feedback information to obtain an optimized kernel.
2. The method of claim 1, wherein optimizing the kernel source code according to the fine optimization configuration table and the kernel feedback information to obtain an optimized version kernel comprises:
generating an optimized parameter combination according to the kernel feedback information;
and optimizing the module, file or function of the kernel according to the fine optimization configuration table and the optimization parameter combination.
3. The method of claim 2, wherein optimizing a module, file, or function of a kernel according to the fine optimization configuration table and the optimization parameter combination comprises:
reading the fine optimization configuration table and determining the optimization range of the kernel source code;
if the optimization level is a module, the minimum unit of the optimization range is a module, and the optimization parameter combination is applied to optimize all C/C++ files contained in the kernel module in the fine optimization configuration table;
if the optimization level is a file, the minimum unit of the optimization range is a file, and the optimization parameter combination is applied to optimize all C/C++ files in the fine optimization configuration table;
and if the optimization level is a function, the minimum unit of the optimization range is a function, and the optimization parameter combination is applied to optimize the functions of all C/C++ files in the fine optimization configuration table to participate in optimization.
4. The method of claim 3, wherein the step of,
the optimizing parameter combination is applied to optimize all C/C++ files contained in the kernel module in the fine optimizing configuration table, and the optimizing processing comprises the following steps: C/C++ files contained in the modules which do not participate in optimization are not subject to instrumentation and optimization, and C/C++ files contained in other modules except the modules which do not participate in optimization are subject to instrumentation and optimization;
the optimizing parameter combination is applied to optimize all C/C++ files in the fine optimizing configuration table, and the optimizing processing comprises the following steps: the C/C++ files which do not participate in optimization are not subject to instrumentation and optimization, and the rest C/C++ files except the C/C++ files which do not participate in optimization are subject to instrumentation and optimization;
the optimizing parameter combination is applied to optimize the functions of all C/C++ files participating in optimization in the fine optimizing configuration table, and the optimizing processing comprises the following steps: and performing instrumentation and optimization on the functions which do not participate in optimization of the C/C++ files and the C/C++ files which participate in optimization, and performing instrumentation and optimization on the other functions except the functions which do not participate in optimization of the C/C++ files and the functions which do not participate in optimization.
5. The method of claim 1, wherein generating the fine optimization configuration table from the user configuration table comprises:
when kernel hot spot information is sampled, traversing all C/C++ files of top-level directories corresponding to all hot spot functions, and generating the fine optimization configuration table according to the kernel hot spot information and the user configuration table;
and when the kernel hot spot information is not sampled, traversing all C/C++ files of the kernel source codes, and generating the fine optimization configuration table according to a user configuration table.
6. The method of claim 5, wherein generating the fine optimization configuration table from the kernel hotspot information and the user configuration table comprises:
operating an object program, and obtaining the kernel hot spot information by using a hot spot sampling tool;
and extracting information of the user configuration table according to the optimization level, removing C/C++ files which do not participate in optimization, and recording functions which do not participate in optimization aiming at each C/C++ file which participate in optimization to form the fine optimization configuration table.
7. The method according to any one of claims 1 to 6, wherein performing targeted instrumentation on the kernel source code, running the target program, and obtaining the kernel feedback information includes:
transplanting or creating a data stream instrumentation code into the kernel source code, and adapting functions and data interfaces of the kernel;
and combining the control flow instrumentation information and the data flow instrumentation information to obtain the kernel feedback information.
8. The method of claim 7, wherein after performing targeted instrumentation on the kernel source code and running the target program to obtain the kernel feedback information, the method further comprises:
and writing the kernel feedback information into a kernel feedback information file by calling a debugFS interface.
9. A Linux kernel optimization processing device, characterized in that the device comprises:
the generating module is used for generating a fine optimization configuration table according to the user configuration table;
the instrumentation module is used for performing targeted instrumentation on the kernel source codes, running a target program and obtaining kernel feedback information;
and the optimizing module is used for optimizing the kernel source code according to the fine optimizing configuration table and the kernel feedback information to obtain an optimized kernel.
10. A computer readable storage medium having a computer program stored therein, wherein the computer program is arranged to perform the method of any of claims 1 to 8 when run.
11. An electronic device comprising a memory in which a computer program is stored and a processor arranged to run the computer program to perform the method of any of claims 1 to 8.
CN202210453841.2A 2022-04-27 2022-04-27 Linux kernel optimization processing method and device, storage medium and electronic device Pending CN117008909A (en)

Priority Applications (2)

Application Number Priority Date Filing Date Title
CN202210453841.2A CN117008909A (en) 2022-04-27 2022-04-27 Linux kernel optimization processing method and device, storage medium and electronic device
PCT/CN2023/091320 WO2023208140A1 (en) 2022-04-27 2023-04-27 Linux kernel optimization processing method and apparatus, and storage medium and electronic apparatus

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210453841.2A CN117008909A (en) 2022-04-27 2022-04-27 Linux kernel optimization processing method and device, storage medium and electronic device

Publications (1)

Publication Number Publication Date
CN117008909A true CN117008909A (en) 2023-11-07

Family

ID=88517931

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210453841.2A Pending CN117008909A (en) 2022-04-27 2022-04-27 Linux kernel optimization processing method and device, storage medium and electronic device

Country Status (2)

Country Link
CN (1) CN117008909A (en)
WO (1) WO2023208140A1 (en)

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8533698B2 (en) * 2011-06-13 2013-09-10 Microsoft Corporation Optimizing execution of kernels
CN112527300B (en) * 2019-09-18 2023-06-13 无锡江南计算技术研究所 Multi-target-oriented fine granularity compiling self-optimizing method
CN113297064A (en) * 2020-07-29 2021-08-24 阿里巴巴集团控股有限公司 Code coverage rate testing method, system, equipment and storage medium

Also Published As

Publication number Publication date
WO2023208140A1 (en) 2023-11-02

Similar Documents

Publication Publication Date Title
CN102520972B (en) Video game development system and method thereof
CN109086215B (en) Embedded software unit test case generation method and system
CN105630488A (en) Docker container technology-based continuous integration realizing method
CN110147225A (en) A kind of code generating method, device and computer equipment, storage medium
CN107632827B (en) Method and device for generating installation package of application
CN108197091B (en) Method, system and related equipment for creating data table
CN102521218B (en) File combining method and file combining device
CN111158680A (en) Page construction method, device, equipment and storage medium
CN108875035B (en) Data storage method of distributed file system and related equipment
CN105512276B (en) Method and device for constructing junk file and electronic equipment
CN115114219A (en) PCI-E topological method, device, equipment and storage medium
CN113407254B (en) Form generation method and device, electronic equipment and storage medium
CN114448972A (en) Distributed storage log compression downloading method, system, terminal and storage medium
CN111026047B (en) Software configuration method and device
CN117008909A (en) Linux kernel optimization processing method and device, storage medium and electronic device
CN108900347B (en) Cluster initialization configuration method, device, system, equipment and readable storage medium
CN113031953A (en) Application program pre-compiling method and device, electronic equipment and server
CN111367916A (en) Data storage method and device
CN105512168A (en) Cluster database composite data loading method and apparatus
CN109582338A (en) BIOS option amending method, device, equipment and storage medium
CN111124378B (en) Code generation method and device
CN114675926A (en) Virtual machine attribute changing method and device, storage medium and electronic device
CN108008981B (en) Method and device for initializing program in system on chip (SoC)
CN111027196A (en) Simulation analysis task processing method and device for power equipment and storage medium
CN115237503B (en) VR-based ecological model building method and system

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication