Static Ftrace adaptation method and dynamic Ftrace adaptation method based on SW processor

By inserting static and dynamic jump piles on the Shenwei processor, the problem that the Shenwei processor cannot track kernel functions is solved, and the efficiency and stability of kernel function tracking is improved. It is suitable for systems with high performance sensitivity and real-time performance.

CN120508495APending Publication Date: 2025-08-19WUXI ADVANCED TECH RES INST
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510514366.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-23
Publication Date
2025-08-19

AI Technical Summary

Technical Problem

Shenwei processors cannot effectively track kernel functions and debug and analyze them in the Linux kernel, resulting in complex Ftrace adaptation and poor performance, affecting the development of the software ecosystem.

Method used

By inserting static and dynamic jump piles when the compiler compiles the kernel, the instruction set and register management mechanism of the Shenwei processor are used to accurately intercept and track kernel functions. The static jump pile is composed of ldl Ra, disp(Rb), ldl Ra, disp(Rb), call Ra, Rb instructions, and the dynamic jump pile is composed of ldl Ra, disp(Rb), call Ra, Rb, and nop instructions, and is flexibly switched during the system initialization stage.

Benefits of technology

It improves the efficiency and stability of kernel function tracking, reduces system overhead, and is suitable for embedded systems with high performance sensitivity and real-time requirements, real-time tracking control is realized.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120508495A_ABST
    Figure CN120508495A_ABST
Patent Text Reader

Abstract

The invention discloses a static Ftrace adaptation method and a dynamic Ftrace adaptation method based on a SW processor, and belongs to the technical field of computer system structures.In the process that a first kernel function calls a second kernel function, the static Ftrace adaptation method comprises the step that a static jump pile is inserted in front of an entry address of the second kernel function. The dynamic Ftrace adaptation method comprises the steps that a dynamic jump pile is inserted in front of an entry address of a second kernel function, an ftracemakecalall function is called to modify the dynamic jump pile into a null instruction, the null instruction is dynamically processed in response to user configuration processing, and if the second function is set as a tracking target, the null instruction is modified into the dynamic jump pile and executed; and if the second function is not set as the tracking target, executing the null instruction. The problem that an existing SW processor cannot track a kernel function and perform kernel debugging analysis is solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to a static Ftrace adaptation method and a dynamic Ftrace adaptation method based on a Shenwei processor, belonging to the technical field of computer architecture. Background Art

[0002] In today's computer technology landscape, independent research and development of processor architectures and the improvement of the software ecosystem are crucial for national information security and the independent development of the industry. The Shenwei series of processors is a significant achievement of my country's independent research and development. Based on the independently developed SW64 architecture, it boasts completely independent intellectual property rights. Promoting the development of the Shenwei series of processors, operating systems, and software ecosystems is of great significance for my country's efforts to break free from its dependence on foreign chip technology and achieve chip independence. Furthermore, within the Linux kernel, Ftrace (Function Tracer) plays a key role as a lightweight debugging and performance analysis tool. Ftrace was introduced in Linux 2.6.27 in 2008. Its general code provides general algorithms for file system interaction, stack tracebacks, and information logging. Its primary function is to trace the call and execution flow of kernel functions. It is divided into static Ftrace and dynamic Ftrace. Static Ftrace injects tracepoints into functions during kernel compilation, a process known as static instrumentation. Dynamic Ftrace injects tracepoints into functions in real time by modifying instruction segments during kernel runtime, a process known as dynamic instrumentation. With these two instrumentation methods, Ftrace can record information such as function calls, interrupt events, scheduling behaviors, and output the results to the virtual file system.

[0003] While Ftrace has considerable versatility and practicality for Linux kernel debugging and performance analysis, the implementation of Ftrace's underlying mechanisms, such as static instrumentation, dynamic instrumentation, and instruction replacement, faces numerous challenges due to significant differences in hardware characteristics, instruction sets, and hardware / software interfaces across processor architectures. Currently, these mechanisms require architecture-specific kernel code and architecture-specific compilers. This complicates and hinders the adaptation and application of Ftrace on diverse processor architectures, necessitating the lack of a universal, cross-architecture efficient implementation mechanism. For processors with proprietary architectures, such as the Shenwei series, fully utilizing Ftrace's capabilities requires significant time and effort to develop architecture-specific kernel code and specialized compilers. This not only increases development costs but can also impact Ftrace's effectiveness and performance on Shenwei processors, limiting its role in driving the Shenwei processor software ecosystem. Summary of the Invention

[0004] The purpose of the present invention is to provide a static Ftrace adaptation method and a dynamic Ftrace adaptation method based on the Shenwei processor, which solves the problem that the current Shenwei processor cannot trace kernel functions and perform kernel debugging analysis by reconstructing the internal instructions of the static jump stub or the dynamic jump stub.

[0005] In order to solve the above technical problems, the present invention is implemented by adopting the following technical solutions.

[0006] In a first aspect, the present invention provides a static Ftrace adaptation method based on a Shenwei processor, in which a first kernel function calls a second kernel function, the method comprises: When the compiler compiles the kernel, the entry address of the second kernel function is obtained; Insert a static jump stub before the entry address of the second kernel function; The static jump stub includes the ldih Ra, disp(Rb) instruction, the ldl Ra, disp(Rb) instruction, and the callRa, Rb instruction, which are used to jump to the ftrace_caller function. The ftrace_caller function is used to execute the reserved general registers and restored general registers of the Shenwei processor, load the parameters of the ftrace_handler function, and jump to the ftrace_handler function; The ftrace_handler function is used to return the entry address of the second kernel function after executing Ftrace.

[0007] Furthermore, the ldih Ra, disp(Rb) instruction is used to write the result of shifting the offset disp left by 16 bits and adding it to the value of the first general register Rb into the second general register Ra; The ldl Ra, disp(Rb) instruction is used to add the offset disp to the value of the first general register Rb to obtain a new address, and then read the new address and write it into the second general register Ra; The call Ra, Rb instruction is used to load the next instruction into the second general register Ra and then jump to the target address pointed to by the first general register Rb.

[0008] Furthermore, the steps of executing the reserved general registers and the restored general registers of the Shenwei processor, loading the parameters of the ftrace_handler function, and jumping to the ftrace_handler function include: Save the return address register $26 and frame register $fp of the first kernel function; Save the Ftrace target address register $28 and frame register $fp of the second kernel function; Save other general-purpose registers; Load the parameters of the ftrace_handler function; Jump to ftrace_handler function; The target address register $28 is only used for call Ra, Rb instructions of static stubs.

[0009] Furthermore, after executing Ftrace, the entry address of the second kernel function is returned, including: Restore other general registers; Restore the Ftrace target address register $28 and frame register $fp of the second kernel function; Restore the return address register $26 and frame register $fp of the first kernel function; Returns the entry address of the second kernel function.

[0010] Furthermore, the process of the first kernel function calling the second kernel function includes: Execute the first kernel function to call the second kernel function; Inside the second kernel function, execute the ldih Ra, disp(Rb) and ldl Ra, disp(Rb) instructions to load the global pointer register; Save the stack of the first kernel function and write the data in some general registers to the memory; Execute the second kernel function; Restoring the stack of the first kernel function, reading data of some general registers from the memory, and loading the data into some general registers; Execute other instructions of the first kernel function.

[0011] In a second aspect, the present invention provides a dynamic Ftrace adaptation method based on a Shenwei processor, in which a first kernel function calls a second kernel function, the method includes: When the compiler compiles the kernel, the entry address of the second kernel function is obtained; Insert a dynamic jump stub before the entry address of the second kernel function; During the system initialization phase, the ftrace_make_call function is called to modify the dynamic jump stub to a null instruction; During the system operation phase, the null instruction is dynamically processed in response to user configuration processing: If the second function is set as the tracing target, the null instruction is modified into a dynamic jump stub and executed; If the second function is not set as a trace target, executing the null instruction; The dynamic jump stub includes an ldl Ra, disp(Rb) instruction, a call Ra, Rb instruction, and a nop instruction, for jumping to the ftrace_caller function; The ftrace_caller function is used to execute the reserved general registers and restored general registers of the Shenwei processor, load the parameters of the ftrace_handler function, and jump to the ftrace_handler function; The ftrace_handler function is used to return the entry address of the second kernel function after executing Ftrace.

[0012] Furthermore, the empty instructions include three nop instructions, which are used as placeholders.

[0013] Furthermore, the ldl Ra, disp(Rb) instruction is used to add the offset disp to the value of the first general register Rb to obtain a new address, and then read the new address and write it into the second general register Ra; The call Ra, Rb instruction is used to load the next instruction into the second general register Ra and then jump to the target address pointed to by the first general register Rb; The nop instruction is used for placeholder.

[0014] Furthermore, it is characterized in that the steps of executing the reserved general registers and the restored general registers of the Shenwei processor, loading the parameters of the ftrace_handler function, and jumping to the ftrace_handler function include: Save the return address register $26 and frame register $fp of the first kernel function; Save the Ftrace target address register $28 and frame register $fp of the second kernel function; Save other general-purpose registers; Load the parameters of the ftrace_handler function; Jump to ftrace_handler function; The target address register $28 is only used for call Ra, Rb instructions of static stubs.

[0015] Furthermore, after executing Ftrace, the entry address of the second kernel function is returned, including: Restore other general registers; Restore the Ftrace target address register $28 and frame register $fp of the second kernel function; Restore the return address register $26 and frame register $fp of the first kernel function; Returns the entry address of the second kernel function; The target address register $28 is only used for the call Ra, Rb instructions of the dynamic jump stub.

[0016] Compared with the prior art, the present invention has the following beneficial effects: The present invention achieves precise interception and traceless tracing of the kernel function call process of the Shenwei processor by reconstructing and inserting static jump stubs using the ldih Ra, disp(Rb) instruction, the ldl Ra, disp(Rb) instruction, and the call Ra, Rb instruction during the compilation phase. Since the static jump stub is directly embedded before the entry address of the target kernel function, the performance overhead and compatibility risks of dynamic stub insertion at runtime are avoided. At the same time, the unique instruction set and register management mechanism of the Shenwei processor are utilized to ensure the hardware adaptability of the Ftrace function when preserving and restoring the general register state, thereby significantly improving the efficiency and stability of kernel function tracing. The invention is particularly suitable for embedded system scenarios that are sensitive to performance or have high real-time requirements, and realizes the jump from the function entry to ftrace_caller.

[0017] The present invention realizes on-demand activation and efficient control of the kernel function tracing of the Shenwei architecture by reconstructing the dynamic jump piles using the ldl Ra, disp (Rb) instruction, call Ra, Rb instruction and nop instruction during the compilation phase and setting a flexible switching mechanism between the dynamic jump piles and the empty instruction. The dynamic jump piles are replaced with empty instructions during the system initialization phase to avoid performance loss in non-tracing scenarios; and the empty instructions are dynamically modified to jump piles according to the user configuration at runtime, which not only ensures the accurate interception of the tracking target, but also enables tracking by setting the target, significantly reducing the overall system overhead. In addition, combined with the Shenwei processor instruction set and register management mechanism, the hardware compatibility and stability of the dynamic switching process are ensured, and it is particularly suitable for high-performance computing environments that need to frequently adjust the tracking strategy or have limited resources. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] Figure 1 This is a schematic diagram of a process in which a first kernel function calls a second kernel function provided by an embodiment of the present invention; Figure 2 1 is a flow chart of a static Ftrace adaptation method based on a Shenwei processor provided in an embodiment of the present invention; Figure 3 It is a flow chart of a dynamic Ftrace adaptation method based on a Shenwei processor provided in an embodiment of the present invention. DETAILED DESCRIPTION

[0019] The technical solution of the present invention is described in detail below through the accompanying drawings and specific embodiments. It should be understood that the embodiments of the present invention and the specific features in the embodiments are detailed descriptions of the technical solution of the present invention, rather than limitations on the technical solution of the present invention. In the absence of conflict, the embodiments of the present invention and the technical features in the embodiments can be combined with each other.

[0020] Example 1

[0021] This embodiment introduces a static Ftrace adaptation method based on the Shenwei processor, including: Step 1: Obtain the process of the first kernel function calling the second kernel function.

[0022] In this embodiment, the process of the first kernel function calling the second kernel function is as follows: Figure 1 Shown, including: Step 1.1: Execute the first kernel function to call the second kernel function; Step 1.2: Inside the second kernel function, execute the ldih Ra, disp(Rb) and ldl Ra, disp(Rb) instructions to load the global pointer register. Step 1.3: Save the stack of the first kernel function and write the data in some general registers to the memory; Step 1.4: Execute the second kernel function; Step 1.5: Restore the stack of the first kernel function, read some general register data from the memory, and load them into some general registers; Step 1.6: Execute other instructions of the first kernel function.

[0023] Step 2: When the compiler compiles the kernel, the entry address of the second kernel function is obtained, and a static jump stub is inserted before the entry address of the second kernel function.

[0024] In this embodiment, the entry address of the second kernel function is obtained when the compiler compiles the kernel, and a static jump stub is inserted before the entry address of the second kernel function. The static jump stub includes the ldih Ra, disp(Rb) instruction, the ldl Ra, disp(Rb) instruction and the call Ra, Rb instruction, which are used to jump to the ftrace_caller function; the ftrace_caller function is used to execute the reserved general registers and the restored general registers of the Shenwei processor, load the parameters of the ftrace_handler function, and jump to the ftrace_handler function; the ftrace_handler function is used to return to the entry address of the second kernel function after executing Ftrace.

[0025] In this embodiment, the ldih Ra, disp(Rb) instruction is used to write the result of shifting the offset disp left by 16 bits and adding it to the value of the first general register Rb into the second general register Ra. The ldl Ra, disp(Rb) instruction is used to add the offset disp to the value of the first general register Rb to obtain a new address, and then read the new address and write it into the second general register Ra. The call Ra, Rb instruction is used to load the next instruction into the second general register Ra and then jump to the target address pointed to by the first general register Rb.

[0026] In this embodiment, after the static jump stub is inserted, the process of the first kernel function calling the second kernel function is as follows: Figure 2 Shown, including: Step 2.1: Execute the first kernel function to call the second kernel function; Step 2.2: Inside the second kernel function, execute the ldih Ra, disp(Rb) and ldl Ra, disp(Rb) instructions to load the global pointer register. Step 2.3: Get the entry address of the second kernel function, insert a static jump stub before the entry address of the second kernel function, and jump to the ftrace_caller function; Step 2.4: Execute the Shenwei processor's save and restore general registers, and load the parameters of the ftrace_handler function, including: Step 2.4.1: Save the return address register $26 and frame register $fp of the first kernel function; Step 2.4.2: Save the Ftrace target address register $28 and frame register $fp of the second kernel function; Step 2.4.3: Save other general registers; Step 2.4.4: Load the parameters of the ftrace_handler function; Step 2.4.5: Jump to the ftrace_handler function; The target address register $28 is only used for call Ra, Rb instructions of static stubs.

[0027] Step 2.5: After executing Ftrace, the entry address of the second kernel function is returned, including: Step 2.5.1: Restore other general registers; Step 2.5.2: Restore the Ftrace target address register $28 and frame register $fp of the second kernel function; Step 2.5.3: Restore the return address register $26 and frame register $fp of the first kernel function; Step 2.5.4: Return the entry address of the second kernel function; Step 2.6: Save the stack of the first kernel function and write the data in some general registers to the memory; Step 2.7: Execute the second kernel function; Step 2.8: Restore the stack of the first kernel function, read some general register data from the memory, and load them into some general registers; Step 2.9: Execute other instructions of the first kernel function.

[0028] Example 2

[0029] like Figure 2 As shown, based on the same inventive concept as Example 1, this embodiment introduces a dynamic Ftrace adaptation method based on the Shenwei processor, including: Step 1: Obtain the process of the first kernel function calling the second kernel function.

[0030] In this embodiment, the process of the first kernel function calling the second kernel function is as follows: Figure 3 Shown, including: Step 1.1: Execute the first kernel function to call the second kernel function; Step 1.2: Inside the second kernel function, execute the ldih Ra, disp(Rb) and ldl Ra, disp(Rb) instructions to load the global pointer register. Step 1.3: Save the stack of the first kernel function and write the data in some general registers to the memory; Step 1.4: Execute the second kernel function; Step 1.5: Restore the stack of the first kernel function, read some general register data from the memory, and load them into some general registers; Step 1.6: Execute other instructions of the first kernel function.

[0031] Step 2: When the compiler compiles the kernel, the entry address of the second kernel function is obtained, and a dynamic jump stub is inserted before the entry address of the second kernel function.

[0032] In this embodiment, the entry address of the second kernel function is obtained when the compiler compiles the kernel, and a dynamic jump stub is inserted before the entry address of the second kernel function. The dynamic jump stub includes ldl Ra, disp(Rb) instructions, call Ra, Rb instructions and nop instructions, which are used to jump to the ftrace_caller function; the ftrace_caller function is used to execute the reserved general registers and restored general registers of the Shenwei processor, load the parameters of the ftrace_handler function, and jump to the ftrace_handler function; the ftrace_handler function is used to return to the entry address of the second kernel function after executing Ftrace.

[0033] In this embodiment, the empty instructions include three nop instructions, which are used as placeholders.

[0034] In this embodiment, the ldl Ra, disp(Rb) instruction is used to add the offset disp to the value of the first general register Rb to obtain a new address, and then read the new address and write it into the second general register Ra; the call Ra, Rb instruction is used to load the next instruction into the second general register Ra and then jump to the target address pointed to by the first general register Rb; the nop instruction is used for placeholder.

[0035] In this embodiment, after the dynamic jump stub is inserted, the process of the first kernel function calling the second kernel function is as follows: Figure 3 shown.

[0036] If the second function is set as the tracking target, the steps include: Step 3.1: Execute the first kernel function to call the second kernel function; Step 3.2: Inside the second kernel function, execute the ldih Ra, disp(Rb) and ldl Ra, disp(Rb) instructions to load the global pointer register. Step 3.3: Get the entry address of the second kernel function and insert a dynamic jump stub before the entry address of the second kernel function. Step 3.4: During the system initialization phase, call the ftrace_make_call function to modify the dynamic jump stub to a null instruction; Step 3.5: During the system operation phase, dynamically process the null instruction in response to the user configuration: modify the null instruction into a dynamic jump stub and execute it, jumping to the ftrace_caller function.

[0037] Step 3.6: Execute the save and restore general registers of the Shenwei processor and load the parameters of the ftrace_handler function, including: Step 3.6.1: Save the return address register $26 and frame register $fp of the first kernel function; Step 3.6.2: Save the Ftrace target address register $28 and frame register $fp of the second kernel function; Step 3.6.3: Save other general registers; Step 3.6.4: Load the parameters of the ftrace_handler function; Step 3.6.5: Jump to the ftrace_handler function; The target address register $28 is only used for call Ra, Rb instructions of static stubs.

[0038] Step 3.7: After executing Ftrace, the entry address of the second kernel function is returned, including: Step 3.7.1: Restore other general registers; Step 3.7.2: Restore the Ftrace target address register $28 and frame register $fp of the second kernel function; Step 2.5.3: Restore the return address register $26 and frame register $fp of the first kernel function; Step 3.7.4: Return the entry address of the second kernel function; Step 3.8: Save the stack of the first kernel function and write the data in some general registers to the memory; Step 3.9: Execute the second kernel function; Step 3.10: Restore the stack of the first kernel function, read some general register data from the memory, and load them into some general registers; Step 3.11: Execute other instructions of the first kernel function.

[0039] If the second function is not set as the tracking target, the steps include: Step 4.1: Execute the first kernel function to call the second kernel function; Step 4.2: Inside the second kernel function, execute the ldih Ra, disp(Rb) and ldl Ra, disp(Rb) instructions to load the global pointer register. Step 4.3: Get the entry address of the second kernel function and insert a dynamic jump stub before the entry address of the second kernel function. Step 4.4: During the system initialization phase, call the ftrace_make_call function to modify the dynamic jump stub to a null instruction; Step 4.5: During the system operation phase, dynamically processing the null instruction in response to user configuration: executing the null instruction; Step 4.6: Save the stack of the first kernel function and write the data in some general registers to the memory; Step 4.7: Execute the second kernel function; Step 4.8: Restore the stack of the first kernel function, read some general register data from the memory, and load them into some general registers; Step 4.9: Execute other instructions of the first kernel function.

[0040] Example 3

[0041] Based on the same inventive concept as other embodiments, this embodiment introduces a computer-readable storage medium on which computer instructions are stored. When the computer instructions are executed by a processor, the steps of the method of the above-mentioned embodiment 1 or 2 are implemented.

[0042] Example 4

[0043] Based on the same inventive concept as other embodiments, this embodiment introduces a computer program product, including computer instructions. When the computer instructions are executed by a processor, the steps of the method in the above-mentioned embodiment 1 or 2 are implemented.

[0044] In summary, the present invention realizes accurate interception and traceless tracing of the kernel function call process of the Shenwei processor by reconstructing and inserting static jump piles using ldih Ra, disp(Rb) instructions, ldl Ra, disp(Rb) instructions and call Ra, Rb instructions in the compilation stage. Because the static jump pile is directly embedded in front of the entry address of the target kernel function, the performance overhead and compatibility risk of dynamic insertion at runtime are avoided. At the same time, the unique instruction set and register management mechanism of the Shenwei processor are utilized to ensure the hardware adaptability of the Ftrace function in retaining and restoring the general register state, thereby significantly improving the efficiency and stability of kernel function tracing, and is particularly suitable for embedded system scenarios that are sensitive to performance or have high real-time requirements, and realizes the jump from the function entry to ftrace_caller.

[0045] The present invention realizes on-demand activation and efficient control of the kernel function tracing of the Shenwei architecture by reconstructing the dynamic jump piles using the ldl Ra, disp (Rb) instruction, call Ra, Rb instruction and nop instruction during the compilation phase and setting a flexible switching mechanism between the dynamic jump piles and the empty instruction. The dynamic jump piles are replaced with empty instructions during the system initialization phase to avoid performance loss in non-tracing scenarios; and the empty instructions are dynamically modified to jump piles according to the user configuration at runtime, which not only ensures the accurate interception of the tracking target, but also enables tracking by setting the target, significantly reducing the overall system overhead. In addition, combined with the Shenwei processor instruction set and register management mechanism, the hardware compatibility and stability of the dynamic switching process are ensured, and it is particularly suitable for high-performance computing environments that need to frequently adjust the tracking strategy or have limited resources.

[0046] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, systems, or computer program products. Thus, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0047] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowcharts and / or block diagrams, as well as combinations of processes and / or blocks in the flowcharts and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowcharts and / or block diagrams. Figure 1 a process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0048] These computer program instructions may also be stored in a computer readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 a process or multiple processes and / or boxes Figure 1 The function specified in one or more boxes.

[0049] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operational steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing the instructions executed on the computer or other programmable device for implementing the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.

[0050] The embodiments of the present invention are described above in conjunction with the accompanying drawings, but the present invention is not limited to the above-mentioned specific implementation methods. The above-mentioned specific implementation methods are merely illustrative and not restrictive. Under the guidance of the present invention, ordinary technicians in this field can also make many forms without departing from the scope of protection of the purpose of the present invention and the claims, which are all protected by the present invention.

Claims

1. A static Ftrace adaptation method based on Shenwei processor, characterized in that: In the process of the first kernel function calling the second kernel function, the method includes: When the compiler compiles the kernel, the entry address of the second kernel function is obtained; Insert a static jump stub before the entry address of the second kernel function; The static jump stub includes the ldih Ra, disp(Rb) instruction, the ldl Ra, disp(Rb) instruction, and the call Ra, Rb instruction, which are used to jump to the ftrace_caller function; The ftrace_caller function is used to execute the reserved general registers and restored general registers of the Shenwei processor, load the parameters of the ftrace_handler function, and jump to the ftrace_handler function; The ftrace_handler function is used to return the entry address of the second kernel function after executing Ftrace.

2. The static Ftrace adaptation method based on the Shenwei processor according to claim 1 is characterized in that: The ldih Ra, disp(Rb) instruction is used to write the result of adding the offset disp shifted left by 16 bits to the value of the first general register Rb into the second general register Ra; The ldl Ra, disp(Rb) instruction is used to add the offset disp to the value of the first general register Rb to obtain a new address, and then read the new address and write it into the second general register Ra; The call Ra, Rb instruction is used to load the next instruction into the second general register Ra and then jump to the target address pointed to by the first general register Rb.

3. The static Ftrace adaptation method based on the Shenwei processor according to claim 1 is characterized in that: The steps of executing the reserved general registers and the restored general registers of the Shenwei processor, loading the parameters of the ftrace_handler function, and jumping to the ftrace_handler function include: Save the return address register $26 and frame register $fp of the first kernel function; Save the Ftrace target address register $28 and frame register $fp of the second kernel function; Save other general-purpose registers; Load the parameters of the ftrace_handler function; Jump to ftrace_handler function; The target address register $28 is only used for call Ra, Rb instructions of static stubs.

4. The static Ftrace adaptation method based on the Shenwei processor according to claim 1 is characterized in that: After executing Ftrace, the entry address of the second kernel function is returned, including: Restore other general registers; Restore the Ftrace target address register $28 and frame register $fp of the second kernel function; Restore the return address register $26 and frame register $fp of the first kernel function; Returns the entry address of the second kernel function.

5. The static Ftrace adaptation method based on the Shenwei processor according to claim 1 is characterized in that: The process of the first kernel function calling the second kernel function includes: Execute the first kernel function to call the second kernel function; Inside the second kernel function, execute the ldih Ra, disp(Rb) and ldl Ra, disp(Rb) instructions to load the global pointer register; Save the stack of the first kernel function and write the data in some general registers to the memory; Execute the second kernel function; Restoring the stack of the first kernel function, reading data of some general registers from the memory, and loading the data into some general registers; Execute other instructions of the first kernel function.

6. A dynamic Ftrace adaptation method based on Shenwei processor, characterized in that: When a first kernel function calls a second kernel function, the method includes: When the compiler compiles the kernel, the entry address of the second kernel function is obtained; Insert a dynamic jump stub before the entry address of the second kernel function; During the system initialization phase, the ftrace_make_call function is called to modify the dynamic jump stub to a null instruction; During the system operation phase, the null instruction is dynamically processed in response to user configuration processing: If the second function is set as the tracing target, the null instruction is modified into a dynamic jump stub and executed; If the second function is not set as a trace target, executing the null instruction; The dynamic jump stub includes an ldl Ra, disp(Rb) instruction, a call Ra, Rb instruction, and a nop instruction, for jumping to the ftrace_caller function; The ftrace_caller function is used to execute the reserved general registers and restored general registers of the Shenwei processor, load the parameters of the ftrace_handler function, and jump to the ftrace_handler function; The ftrace_handler function is used to return the entry address of the second kernel function after executing Ftrace.

7. The dynamic Ftrace adaptation method based on the Shenwei processor according to claim 6 is characterized in that: The empty instructions include three nop instructions, which are used as placeholders.

8. The dynamic Ftrace adaptation method based on the Shenwei processor according to claim 6 is characterized in that: The ldl Ra, disp(Rb) instruction is used to add the offset disp to the value of the first general register Rb to obtain a new address, and then read the new address and write it into the second general register Ra; The call Ra, Rb instruction is used to load the next instruction into the second general register Ra and then jump to the target address pointed to by the first general register Rb; The nop instruction is used for placeholder.

9. The dynamic Ftrace adaptation method based on the Shenwei processor according to claim 6 is characterized in that: The steps of executing the reserved general registers and the restored general registers of the Shenwei processor, loading the parameters of the ftrace_handler function, and jumping to the ftrace_handler function include: Save the return address register $26 and frame register $fp of the first kernel function; Save the Ftrace target address register $28 and frame register $fp of the second kernel function; Save other general-purpose registers; Load the parameters of the ftrace_handler function; Jump to ftrace_handler function; The target address register $28 is only used for call Ra, Rb instructions of static stubs.

10. The dynamic Ftrace adaptation method based on the Shenwei processor according to claim 6 is characterized in that: After executing Ftrace, the entry address of the second kernel function is returned, including: Restore other general registers; Restore the Ftrace target address register $28 and frame register $fp of the second kernel function; Restore the return address register $26 and frame register $fp of the first kernel function; Returns the entry address of the second kernel function; The target address register $28 is only used for the call Ra, Rb instructions of the dynamic jump stub.