CPU (Central Processing Unit) kernel call stack acquisition method and device based on user mode command
By generating the kernel call stack in the user state to obtain commands and sending inter-core interrupt requests, the problem of user states in the ARM64 architecture cannot directly access kernel state information, and the kernel state CPU call stack is obtained without causing business interruption. Information improves debugging and analysis efficiency.
Patent Information
- Application Number
- CN202410982671.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-22
- Publication Date
- 2024-12-10
AI Technical Summary
In the ARM64 architecture, user-state programs cannot directly access kernel-state information, which leads to traditional methods that need to enter the KDB environment, resulting in all CPUs being suspended, which may cause business interruptions and affect system debugging, performance analysis and troubleshooting efficiency.
By generating the kernel call stack in the user state, sending inter-core interrupt requests, using the preset interface to obtain the kernel call stack data, and storing it in a character array, it realizes the kernel without causing long-term business interruptions to be obtained The current call stack information of the state CPU.
It improves the efficiency of system debugging, performance analysis and troubleshooting, avoids business interruptions, and realizes a method of quickly obtaining the CPU core call stack information.
Smart Images

Figure CN119105846A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer information processing, and in particular to a method and device for obtaining a kernel call stack of a CPU based on user-mode commands. Background Art
[0002] In the ARM64 architecture, the management of function calls relies on a carefully designed stack mechanism. The core of this mechanism lies in two key registers: the frame pointer (FP) and the stack pointer (SP). The FP register points to the bottom of the current function stack frame, while the SP register points to the top of the stack. This design allows technicians to efficiently pass parameters and return values between function calls.
[0003] Specifically, whenever a function is called, its return address (stored in the link register LR) is pushed into the stack. By accessing the FP register, technicians can find the LR value stored in the stack, which is the return address of the function. In addition, the stack also stores the FP register value of the previous level function, which points to the bottom of the stack of the previous level function. Using this chain structure, technicians can backtrack step by step to find each function in the entire function call chain and its corresponding stack frame information. This process is called stack backtracing, which is crucial for debugging, performance analysis, and troubleshooting.
[0004] In a multi-processor system, some hardware devices may need to share interrupt handling tasks across multiple processors. In order to cope with this demand, the IPI (Inter-Processor Interrupt) mechanism is introduced. When a processor receives an interrupt request, it can use IPI to send this request to other processors in the system to trigger the corresponding interrupt handler.
[0005] In a complex system environment, understanding the tasks and call stack information currently being executed by the CPU is crucial for problem analysis and location. However, a common difficulty is that user-mode programs cannot directly access kernel-mode information. The traditional approach is to enter the KDB (kernel debugger) environment and execute commands such as bt or btc to view the CPU call stack. However, this method has a significant disadvantage: it causes all CPUs to enter a suspended state, which may cause business interruptions.
[0006] Therefore, a new method and device for obtaining the kernel call stack of a CPU based on user-mode commands is needed.
[0007] The above information disclosed in the Background section is only for enhancement of understanding of the background of the present application and therefore it may contain information that does not constitute the prior art that is already known to a person of ordinary skill in the art. Summary of the invention
[0008] In view of this, the present application provides a method and device for obtaining the kernel call stack of the CPU based on user-mode commands, which can obtain the current call stack information of the kernel-mode CPU under the ARM64 architecture through maintainable commands in user mode without causing long-term business interruption, thereby improving the efficiency of system debugging, performance analysis and troubleshooting.
[0009] Other features and advantages of the present application will become apparent from the following detailed description, or may be learned in part by the practice of the present application.
[0010] According to one aspect of the present application, a method for obtaining a kernel call stack of a CPU based on a user-mode command is proposed, the method comprising: generating a kernel call stack obtaining command by inputting parameters in a user mode; determining a target CPU according to the kernel call stack obtaining command; executing the kernel call stack obtaining command to send an IPI inter-core interrupt request to the target CPU; based on the IPI inter-core interrupt request, the target CPU obtains kernel call stack data through a preset interface; storing the data in a preset character array; and executing the kernel call stack obtaining command again to obtain kernel call stack data from the preset character array.
[0011] In an exemplary embodiment of the present application, a kernel call stack acquisition command is generated in user mode by inputting parameters, including: creating a maintainable command as an entry to the CPU kernel call stack in user mode; generating a kernel call stack acquisition command by inputting parameters and the maintainable command.
[0012] In an exemplary embodiment of the present application, determining the target CPU according to the kernel call stack acquisition command includes: judging the validity of input parameters in the kernel call stack acquisition command; and determining the target CPU when the input parameters are valid.
[0013] In an exemplary embodiment of the present application, executing the kernel call stack acquisition command to send an IPI inter-core interrupt request to the target CPU includes: executing the kernel call stack acquisition command; sending an IPI inter-core interrupt request to the target CPU to trigger a non-maskable interrupt operation; and the target CPU performing an interrupt processing process.
[0014] In an exemplary embodiment of the present application, executing the kernel call stack acquisition command to send an IPI inter-core interrupt request to the target CPU also includes: transmitting a global variable tag, wherein the global variable tag identifies that the interrupt operation is triggered by the kernel call stack acquisition command.
[0015] In an exemplary embodiment of the present application, based on the IPI inter-core interrupt request, the target CPU obtains the data of the kernel call stack through a preset interface, including: when obtaining global variable parameters at the preset interface, obtaining the identifier of the target CPU; obtaining the value of the register based on the identifier of the target CPU, the register including FP, SP, and pc registers; and obtaining the data of the kernel call stack through the value of the register.
[0016] In an exemplary embodiment of the present application, the data of the kernel call stack is obtained through the value of the register, including: tracking the stack frame of the kernel call stack through the value of the register; expanding the stack frame layer by layer; obtaining the value of the PC register of each layer to generate the data of the kernel call stack.
[0017] In an exemplary embodiment of the present application, storing the data in a preset character array further includes: restoring the global variable mark.
[0018] In an exemplary embodiment of the present application, the kernel call stack acquisition command is executed again to obtain the kernel call stack data from the preset character array, including: setting a sleep interval time; after the sleep interval time, executing the kernel call stack acquisition command again; obtaining the kernel call stack data from the preset character array.
[0019] According to one aspect of the present application, a kernel call stack acquisition device for a CPU based on user-mode commands is proposed, and the device includes: a command module, which is used to generate a kernel call stack acquisition command by inputting parameters in user mode; a target module, which is used to determine a target CPU according to the kernel call stack acquisition command; a request module, which is used to execute the kernel call stack acquisition command to send an IPI inter-core interrupt request to the target CPU; a data module, which is used to request the target CPU to obtain kernel call stack data through a preset interface based on the IPI inter-core interrupt request; a storage module, which is used to store the data in a preset character array; and an execution module, which is used to execute the kernel call stack acquisition command again to obtain kernel call stack data from the preset character array.
[0020] According to one aspect of the present application, an electronic device is proposed, which includes: one or more processors; a storage device for storing one or more programs; when the one or more programs are executed by the one or more processors, the one or more processors implement the method as described above.
[0021] According to one aspect of the present application, a computer-readable medium is provided, on which a computer program is stored. When the program is executed by a processor, the method described above is implemented.
[0022] According to the method and device for obtaining the kernel call stack of a CPU based on user-mode commands of the present application, a kernel call stack obtaining command is generated by inputting parameters in the user mode; a target CPU is determined according to the kernel call stack obtaining command; the kernel call stack obtaining command is executed to send an IPI inter-core interrupt request to the target CPU; based on the IPI inter-core interrupt request, the target CPU obtains kernel call stack data through a preset interface; the data is stored in a preset character array; and the kernel call stack obtaining command is executed again to obtain kernel call stack data from the preset character array. In this way, the current call stack information of the kernel-mode CPU under the ARM64 architecture can be obtained through a maintainable command in the user mode without causing long-term business interruption, thereby improving the efficiency of system debugging, performance analysis and troubleshooting.
[0023] It should be understood that the foregoing general description and the following detailed description are exemplary only and are not restrictive of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] The above and other objects, features and advantages of the present application will become more apparent by describing in detail the exemplary embodiments thereof with reference to the accompanying drawings. The accompanying drawings described below are only some embodiments of the present application, and it is clear to a person skilled in the art that other accompanying drawings can be obtained from these accompanying drawings without creative effort.
[0025] Figure 1 The present invention is a flowchart of a method for obtaining a kernel call stack of a CPU based on user mode commands according to an exemplary embodiment.
[0026] Figure 2 The present invention is a flowchart of a method for obtaining a kernel call stack of a CPU based on user mode commands according to an exemplary embodiment.
[0027] Figure 3 The present invention is a flowchart of a method for obtaining a kernel call stack of a CPU based on user mode commands according to another exemplary embodiment.
[0028] Figure 4 The present invention is a flowchart of a method for obtaining a kernel call stack of a CPU based on user mode commands according to another exemplary embodiment.
[0029] Figure 5 The invention is a block diagram showing a device for obtaining a kernel call stack of a CPU based on user mode commands according to an exemplary embodiment.
[0030] Figure 6 It is a block diagram of an electronic device according to an exemplary embodiment.
[0031] Figure 7It is a block diagram of a computer-readable medium according to an exemplary embodiment. DETAILED DESCRIPTION
[0032] Example embodiments will now be described more fully with reference to the accompanying drawings. However, example embodiments can be implemented in many forms and should not be construed as limited to the embodiments set forth herein; rather, these embodiments are provided so that this application will be comprehensive and complete and will fully convey the concepts of the example embodiments to those skilled in the art. The same reference numerals in the figures represent the same or similar parts, and thus their repeated description will be omitted.
[0033] In addition, described feature, structure or characteristic can be combined in one or more embodiments in any suitable manner. In the following description, many specific details are provided to provide a full understanding of the embodiments of the present application. However, those skilled in the art will appreciate that the technical scheme of the present application can be put into practice without one or more of the specific details, or other methods, components, devices, steps, etc. can be adopted. In other cases, known methods, devices, realizations or operations are not shown or described in detail to avoid blurring the various aspects of the application.
[0034] The block diagrams shown in the accompanying drawings are merely functional entities and do not necessarily correspond to physically independent entities. That is, these functional entities may be implemented in software form, or in one or more hardware modules or integrated circuits, or in different networks and / or processor devices and / or microcontroller devices.
[0035] The flowcharts shown in the accompanying drawings are only exemplary and do not necessarily include all the contents and operations / steps, nor must they be executed in the order described. For example, some operations / steps can be decomposed, and some operations / steps can be combined or partially combined, so the actual execution order may change according to actual conditions.
[0036] It should be understood that although the terms first, second, third, etc. may be used herein to describe various components, these components should not be limited by these terms. These terms are used to distinguish one component from another component. Therefore, the first component discussed below can be referred to as the second component without departing from the teachings of the concepts of the present application. As used herein, the term "and / or" includes any one of the associated listed items and all combinations of one or more.
[0037] Those skilled in the art will appreciate that the drawings are merely schematic diagrams of example embodiments, and the modules or processes in the drawings are not necessarily necessary for implementing the present application, and therefore cannot be used to limit the scope of protection of the present application.
[0038] The technical abbreviations involved in this application are explained as follows:
[0039] IPI: (Inter-Processor Interrupt), inter-processor interrupt is a special type of interrupt, that is, in a multi-processor system, if the interrupt processor requires action from other processors, an interrupt behavior issued by one processor to another processor.
[0040] NMI: non-maskable interrupt. NMI is usually used to notify the operating system that an unrecoverable hardware error has occurred, usually including: chip error, memory ECC check error, bus data corruption, etc.
[0041] Generic Interrupt Controller(GIC): Generic Interrupt Controller (GIC) is an interrupt controller architecture for ARM processor-based systems.
[0042] Function stack: When a function is executed, it needs enough memory space to store parameters, local variables, and return values. This space corresponds to the stack. The stack area grows from high address to low address, and it is first in, last out. The stack space allocated to the function is called the function stack frame.
[0043] FP register, the main function of FP register is to trace back the stack and find the calling relationship of the subroutine, also known as backtrace. In the ARM architecture, the record of FP register (Frame Pointer Register) changes when each level of the subroutine is called, and is saved to the stack level by level. Finally, the calling relationship of each level can be inferred through the value of FP register. This mechanism allows the system to track and restore the execution flow when needed, especially playing an important role in processing function call stack and error handling.
[0044] SP register, stack register SP (stack pointer) is used to store the offset address of the stack.
[0045] KDB is a kernel debugger for Linux systems. It is developed by SGI and is an open source debugging tool that complies with the GPL license. It is embedded in the Linux kernel and provides debugging tools for kernel and driver programmers. KDB is suitable for debugging program codes in kernel space, such as debugging device drivers and kernel modules.
[0046] Figure 1 The flowchart of a method for obtaining a kernel call stack of a CPU based on user-mode commands according to an exemplary embodiment is shown. The method 10 for obtaining a kernel call stack of a CPU based on user-mode commands at least includes steps S102 to S112.
[0047] like Figure 1 As shown, in S102, a kernel call stack acquisition command is generated in user mode by inputting parameters. For example, a maintainable command as an entry to the CPU kernel call stack is created in user mode; and a kernel call stack acquisition command is generated by inputting parameters and the maintainable command.
[0048] More specifically, a maintainable command show cpu-stack(all|cpu-id) can be implemented in user state as an entry for the user state to obtain the current task call stack of each CPU in kernel state. The maintainable command can distinguish and obtain the current task call stack of the target CPU core or all CPU cores by inputting parameters cpuid and allcpu.
[0049] In S104, the target CPU is determined according to the kernel call stack acquisition command. For example, the validity of the input parameters in the kernel call stack acquisition command may be first determined; when the input parameters are valid, the target CPU is determined.
[0050] More specifically, the validity of the parameters can be determined through maintainable commands. If the cpuid entered by the user exceeds the total number of cpu cores of the device, the program will exit early and prompt the user for the valid range of cpuid.
[0051] In S106, the kernel call stack acquisition command is executed to send an IPI inter-core interrupt request to the target CPU. For example, the kernel call stack acquisition command may be executed; an IPI inter-core interrupt request may be sent to the target CPU to trigger a non-maskable interrupt operation; and the target CPU performs an interrupt processing flow.
[0052] For example, a global variable tag may be transmitted, wherein the global variable tag identifies that the interrupt operation is triggered by the kernel call stack acquisition command.
[0053] In actual applications, after determining the validity of the parameters, the maintenance command program can enter the first system call, send an ipi inter-core interrupt request to the operating system kernel, and trigger an nmi operation.
[0054] More specifically, in the arm64 architecture, the kernel executes arch_send_nmi_irq_single_ipi to send the message to the target CPU, and the target CPU starts to enter the interrupt processing process through gic_handle_irq, and the interface that actually responds to the ipi inter-core interrupt request is handle_IPI. During the process of sending the inter-core interrupt, a global variable flag arm64_stack_flag is transmitted to identify this inter-core interrupt request as a maintainable command trigger.
[0055] In S108, the target CPU obtains the data of the kernel call stack through a preset interface based on the IPI inter-core interrupt request. For example, when obtaining global variable parameters through the preset interface, the identifier of the target CPU is obtained; the value of the register is obtained based on the identifier of the target CPU, and the register includes FP, SP, and pc registers; and the data of the kernel call stack is obtained through the value of the register.
[0056] The original handle_IPI in the CPU will respond to different IPI interrupts based on the passed parameters ipinr and pt_regs.
[0057] In one embodiment of the present application, in order to respond to the interrupt request triggered by the maintainable command, the handle_IPI interface can be rectified. After the rectification, the rectification code can be entered through the global variable identifier transmitted by the first system call.
[0058] More specifically, for example, the target CPU can be obtained through smp_processor_id, so only the parameter pt_regs is needed, and the values of the fp, sp, and pc registers can be obtained through the parameter pt_regs, and the value of the stack frame pointer (fp) can be tracked through unwind_frame. The function of the unwind_frame function is to expand the stack frame layer by layer, and through this function, the stack frame of the function that calls the current function can be traced back. In this way, the information of each function on the call chain can be obtained.
[0059] In S110, the data is stored in a preset character array. For example, the global variable flag can be restored. For example, the value of the pc register of each layer can be saved in the global variable arm64_stack_record character array, and the global variable flag arm64_stack_flag can be restored to avoid affecting the process of other interrupts entering handle_IPI.
[0060] In S112, the kernel call stack acquisition command is executed again to acquire kernel call stack data from the preset character array. For example, a sleep interval time may be set; after the sleep interval time, the kernel call stack acquisition command is executed again; and kernel call stack data is acquired from the preset character array.
[0061] More specifically, the sleep time is set to 50ms, and the second system call can be automatically initiated after the 50ms sleep interval of the first system call, so as to obtain the value of the arm64_stack_record character array from the kernel state to the user state, and then print out the call stack information.
[0062] According to the kernel call stack acquisition method of the CPU based on user-mode commands of the present application, a kernel call stack acquisition command is generated by inputting parameters in the user mode; a target CPU is determined according to the kernel call stack acquisition command; the kernel call stack acquisition command is executed to send an IPI inter-core interrupt request to the target CPU; based on the IPI inter-core interrupt request, the target CPU obtains kernel call stack data through a preset interface; the data is stored in a preset character array; and the kernel call stack acquisition command is executed again to obtain kernel call stack data from the preset character array. In this way, the current call stack information of the kernel-mode CPU under the ARM64 architecture can be obtained through a maintainable command in the user mode without causing long-term business interruption, thereby improving the efficiency of system debugging, performance analysis and troubleshooting.
[0063] It should be clearly understood that the present application describes how to form and use specific examples, but the principles of the present application are not limited to any details of these examples. On the contrary, based on the teaching of the content disclosed in the present application, these principles can be applied to many other embodiments.
[0064] Figure 2 The present invention is a flowchart of a method for obtaining a kernel call stack of a CPU based on user mode commands according to another exemplary embodiment. Figure 2 The process 20 shown is for Figure 1 An overall description of the process shown.
[0065] like Figure 2 As shown, in S202, a request is generated through a user mode command line.
[0066] In S204, a target CPU or all CPUs are designated.
[0067] In S206, the CPU identification is checked.
[0068] In S208, it is prompted that the input is incorrect.
[0069] In S210, the system is called for the first time.
[0070] In S212, IPI interrupt instructions are sent to all target CPUs in sequence.
[0071] In S214 , the kernel obtains the target CPU call stack.
[0072] In S216, the second system call is made.
[0073] In S218, call stack information is obtained.
[0074] In S220, exit.
[0075] This application aims to solve the challenge of locating CPU-related problems when the KDB tool cannot be used during the operation of arm64 architecture devices. The method of obtaining the kernel call stack of the CPU based on user-mode commands in this application allows specific commands to be executed in user mode to directly obtain the kernel call stack of the target CPU. This mechanism enables users to quickly determine the specific business logic currently being processed by the target CPU.
[0076] In order to efficiently derive the kernel call stack of the target CPU, this application optimizes the processing flow to ensure that the entire process takes a very short time, so as to be able to quickly respond to normal NMI (non-maskable interrupt) or continuously process multiple requests to obtain the kernel call stack, thereby not interfering with the normal operation of the system.
[0077] When executing the operation of obtaining the target CPU kernel call stack and then displaying the stack information in user mode, the present application sets a sleep interval. This design is to ensure that there is enough time to complete the derivation and storage process of the stack information, to avoid the stack information derivation being incomplete due to insufficient time, and thus to prevent the user from receiving blank stack information, thereby ensuring the accuracy and completeness of the information.
[0078] Figure 3 The present invention is a flowchart of a method for obtaining a kernel call stack of a CPU based on user mode commands according to another exemplary embodiment. Figure 3 The process 30 shown is for Figure 2 A detailed description of "executing the kernel call stack to obtain a command to send an IPI inter-core interrupt request to the target CPU" in the process shown.
[0079] like Figure 3 As shown, in S302, the kernel call stack acquisition command is executed.
[0080] In S304, an IPI inter-core interrupt request is sent to the target CPU to trigger a non-maskable interrupt operation.
[0081] More specifically, the system sends an IPI (Inter-Processor Interrupt) request to the target CPU. This IPI request is designed to trigger a non-maskable interrupt operation, which means that no matter what state the target CPU is currently in (except for some special sleep or stop states), it must respond to this interrupt. The purpose of this is to ensure that the current execution flow of the target CPU can be interrupted so that subsequent kernel call stack acquisition operations can be performed in a safe context.
[0082] In S306, the target CPU performs an interrupt processing flow. When the target CPU receives an IPI request and triggers an interrupt, it will suspend the current execution flow and enter the interrupt processing flow. This flow includes saving the current context (such as register values, program counters, etc.) so that execution can be resumed after the interrupt is processed. During the interrupt processing, the system checks the global variables or interrupt vector table to determine the specific interrupt type, and executes the corresponding interrupt service routine (ISR) accordingly.
[0083] In S308, a global variable tag is transmitted, where the global variable tag identifies that the interrupt operation is triggered by the kernel call stack acquisition command.
[0084] The global variable flag may be, for example, arm64_stack_flag, which enables the CPU interface to correctly perform the kernel call stack acquisition operation in subsequent steps. By setting this flag, the interrupt handler can distinguish whether this is a normal hardware interrupt or a special software-triggered interrupt for acquiring call stack information.
[0085] Figure 4 The present invention is a flowchart of a method for obtaining a kernel call stack of a CPU based on user mode commands according to another exemplary embodiment. Figure 4 The process 40 shown is for Figure 2 A detailed description of "requesting the target CPU to obtain kernel call stack data through a preset interface based on the IPI inter-core interrupt" in the process shown.
[0086] like Figure 4 As shown, in S402, when the preset interface obtains the global variable parameters, the identification of the target CPU is obtained. The preset interface is the handle_IPI interface, which is mainly used as a processing function of the inter-core interrupt (IPI), responsible for receiving and processing IPI interrupt requests from other processor cores. These requests may include stopping the processor, rescheduling tasks, executing specific functions, and other types. Through the handle_IPI interface, the kernel can coordinate activities between multiple processor cores to ensure the overall performance and stability of the system.
[0087] When a processor core receives an IPI interrupt from another core, it first reads the interrupt number (IRQ number) through the interrupt controller (such as GICv3). Based on the interrupt number, the kernel recognizes that this is an IPI interrupt and calls the handle_IPI function to handle it.
[0088] For example, a global variable (such as arm64_stack_flag) can be set to indicate whether the call chain should be recorded. When handle_IPI is called, arm64_stack_flag is checked first. If arm64_stack_flag indicates that the call chain should be recorded, continue; otherwise, handle the interrupt according to the normal process.
[0089] In S404, the register values are obtained based on the identifier of the target CPU, and the registers include FP, SP, and PC registers. For example, the stack frame of the kernel call stack can be tracked through the register values; the stack frame is expanded layer by layer; and the PC register value of each layer is obtained to generate the data of the kernel call stack.
[0090] More specifically, smp_processor_id() can be used to obtain the ID of the current CPU, and the register information in the current interrupt context, especially the values of the fp (frame pointer), sp (stack pointer) and pc (program counter / instruction pointer) registers, can also be obtained through the pt_regs parameter, for example.
[0091] In one embodiment, the stack frame can be tracked using the unwind_frame function (or a similar function that actually exists in the kernel). This function will expand the stack frame layer by layer based on the current fp and sp register values, and possible debugging information (such as a symbol table).
[0092] In S406, the data of the kernel call stack is obtained through the value of the register. For example, in each layer of the stack frame, the value of the pc register is obtained, which represents the return address of the function corresponding to the stack frame or the address of the currently executed instruction.
[0093] It is also possible to, for example, save the value of the pc register of each stack frame to the global character array arm64_stack_record. This usually involves converting the address into a readable format (such as a hexadecimal string) and appending it to the array.
[0094] It is worth mentioning that after recording the call chain, arm64_stack_flag is restored to its original state to avoid affecting other interrupt processing processes.
[0095] Those skilled in the art will appreciate that all or part of the steps for implementing the above embodiments are implemented as a computer program executed by a CPU. When the computer program is executed by the CPU, the above functions defined by the above method provided in the present application are executed. The program may be stored in a computer-readable storage medium, which may be a read-only memory, a disk, or an optical disk, etc.
[0096] In addition, it should be noted that the above figures are only schematic illustrations of the processes included in the method according to the exemplary embodiments of the present application, and are not intended to be limiting. It is easy to understand that the processes shown in the above figures do not indicate or limit the time sequence of these processes. In addition, it is also easy to understand that these processes can be performed synchronously or asynchronously, for example, in multiple modules.
[0097] The following is an embodiment of the device of the present application, which can be used to execute the embodiment of the method of the present application. For details not disclosed in the embodiment of the device of the present application, please refer to the embodiment of the method of the present application.
[0098] Figure 5 1 is a block diagram of a device for acquiring a CPU kernel call stack based on user-mode commands according to an exemplary embodiment. Figure 5 As shown, the CPU kernel call stack acquisition device 50 based on user mode commands includes: a command module 502 , a target module 504 , a request module 506 , a data module 508 , a storage module 510 , and an execution module 512 .
[0099] The command module 502 is used to generate a kernel call stack acquisition command by inputting parameters in the user state; the command module 502 is also used to create a maintainable command as an entry to the CPU kernel call stack in the user state; and generate a kernel call stack acquisition command by inputting parameters and maintainable commands.
[0100] The target module 504 is used to determine the target CPU according to the kernel call stack acquisition command; the target module 504 is also used to determine the validity of the input parameters in the kernel call stack acquisition command; when the input parameters are valid, the target CPU is determined.
[0101] The request module 506 is used to execute the kernel call stack acquisition command to send an IPI inter-core interrupt request to the target CPU; the request module 506 is also used to execute the kernel call stack acquisition command; send an IPI inter-core interrupt request to the target CPU to trigger a non-maskable interrupt operation; the target CPU performs an interrupt processing flow. The request module 506 is also used to transmit a global variable tag, and the global variable tag identifies that the interrupt operation is triggered by the kernel call stack acquisition command.
[0102] The data module 508 is used to request the target CPU to obtain the data of the kernel call stack through a preset interface based on the IPI inter-core interrupt; the data module 508 is also used to obtain the identifier of the target CPU when obtaining global variable parameters at the preset interface; obtain the value of the register based on the identifier of the target CPU, and the register includes FP, SP, and pc registers; and obtain the data of the kernel call stack through the value of the register.
[0103] The storage module 510 is used to store the data in a preset character array; the storage module 510 is also used to restore the global variable flag.
[0104] The execution module 512 is used to execute the kernel call stack acquisition command again to obtain the kernel call stack data from the preset character array. The execution module 512 is also used to set a sleep interval time; after the sleep interval time, execute the kernel call stack acquisition command again; and obtain the kernel call stack data from the preset character array.
[0105] According to the kernel call stack acquisition device of the CPU based on user-mode commands of the present application, a kernel call stack acquisition command is generated by inputting parameters in the user mode; a target CPU is determined according to the kernel call stack acquisition command; the kernel call stack acquisition command is executed to send an IPI inter-core interrupt request to the target CPU; based on the IPI inter-core interrupt request, the target CPU obtains kernel call stack data through a preset interface; the data is stored in a preset character array; and the kernel call stack acquisition command is executed again to obtain kernel call stack data from the preset character array. In this way, the current call stack information of the kernel-mode CPU under the ARM64 architecture can be obtained through a maintainable command in the user mode without causing long-term business interruption, thereby improving the efficiency of system debugging, performance analysis and troubleshooting.
[0106] In general, the method for obtaining the kernel call stack of the CPU based on user-mode commands disclosed in the present invention is also a method for obtaining the arm64 multi-core cpu call stack through IPI.
[0107] Figure 6 It is a block diagram of an electronic device according to an exemplary embodiment.
[0108] Refer to the following Figure 6 The electronic device 600 according to this embodiment of the present application is described. Figure 6 The electronic device 600 shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0109] like Figure 6 As shown, the electronic device 600 is in the form of a general computing device. The components of the electronic device 600 may include, but are not limited to: at least one processing unit 610, at least one storage unit 620, a bus 630 connecting different system components (including the storage unit 620 and the processing unit 610), a display unit 640, etc.
[0110] The storage unit stores a program code, which can be executed by the processing unit 610, so that the processing unit 610 performs the steps described in this specification according to various exemplary embodiments of the present application. For example, the processing unit 610 can perform the following steps: Figure 1 , Figure 2 , Figure 3 , Figure 4 Follow the steps shown in .
[0111] The storage unit 620 may include a readable medium in the form of a volatile storage unit, such as a random access memory unit (RAM) 6201 and / or a cache memory unit 6202 , and may further include a read-only memory unit (ROM) 6203 .
[0112] The storage unit 620 may also include a program / utility 6204 having a set (at least one) of program modules 6205, such program modules 6205 including but not limited to: an operating system, one or more application programs, other program modules and program data, each of which or some combination may include the implementation of a network environment.
[0113] Bus 630 may represent one or more of several types of bus structures, including a memory unit bus or memory unit controller, a peripheral bus, an accelerated graphics port, a processing unit, or a local bus using any of a variety of bus architectures.
[0114] The electronic device 600 may also communicate with one or more external devices 600' (e.g., keyboards, pointing devices, Bluetooth devices, etc.) to enable a user to communicate with the electronic device 600, and / or any device (e.g., routers, modems, etc.) that the electronic device 600 can communicate with one or more other computing devices. Such communication may be performed via an input / output (I / O) interface 650. In addition, the electronic device 600 may also communicate with one or more networks (e.g., a local area network (LAN), a wide area network (WAN), and / or a public network, such as the Internet) via a network adapter 660. The network adapter 660 may communicate with other modules of the electronic device 600 via a bus 630. It should be understood that, although not shown in the figure, other hardware and / or software modules may be used in conjunction with the electronic device 600, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.
[0115] Through the above description of the implementation, it is easy for those skilled in the art to understand that the example implementation described here can be implemented by software, or by combining software with necessary hardware. Figure 7As shown, the technical solution according to the implementation mode of the present application can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.) or on a network, and includes a number of instructions to enable a computing device (which can be a personal computer, a server, or a network device, etc.) to execute the above method according to the implementation mode of the present application.
[0116] The software product may be any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. The readable storage medium may be, for example, but not limited to, a system, device or component of electricity, magnetism, light, electromagnetic, infrared, or semiconductor, or any combination thereof. More specific examples (non-exhaustive list) of readable storage media include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof.
[0117] The computer readable storage medium may include a data signal propagated in a baseband or as part of a carrier wave, wherein a readable program code is carried. This propagated data signal may take a variety of forms, including but not limited to an electromagnetic signal, an optical signal, or any suitable combination of the above. The readable storage medium may also be any readable medium other than a readable storage medium, which may send, propagate, or transmit a program for use by an instruction execution system, an apparatus, or a device or used in combination with it. The program code contained on the readable storage medium may be transmitted with any appropriate medium, including but not limited to wireless, wired, optical cable, RF, etc., or any suitable combination of the above.
[0118] Program code for performing the operations of the present application may be written in any combination of one or more programming languages, including object-oriented programming languages such as Java, C++, etc., and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user computing device, partially on the user device, as a separate software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server. In the case of a remote computing device, the remote computing device may be connected to the user computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computing device (e.g., using an Internet service provider to connect through the Internet).
[0119] The above-mentioned computer-readable medium carries one or more programs. When the above-mentioned one or more programs are executed by a device, the computer-readable medium realizes the following functions: generating a kernel call stack acquisition command by inputting parameters in user mode; determining a target CPU according to the kernel call stack acquisition command; executing the kernel call stack acquisition command to send an IPI inter-core interrupt request to the target CPU; based on the IPI inter-core interrupt request, the target CPU acquires kernel call stack data through a preset interface; storing the data in a preset character array; and executing the kernel call stack acquisition command again to acquire kernel call stack data from the preset character array.
[0120] Those skilled in the art will appreciate that the above modules can be distributed in the device according to the description of the embodiment, or can be changed accordingly and only used in one or more devices different from the embodiment. The modules of the above embodiments can be combined into one module, or further divided into multiple sub-modules.
[0121] Through the description of the above embodiments, it is easy for those skilled in the art to understand that the example embodiments described here can be implemented by software, or by software combined with necessary hardware. Therefore, the technical solution according to the embodiment of the present application can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.) or on a network, including several instructions to enable a computing device (which can be a personal computer, a server, a mobile terminal, or a network device, etc.) to execute the method according to the embodiment of the present application.
[0122] The exemplary embodiments of the present application are specifically shown and described above. It should be understood that the present application is not limited to the detailed structures, configurations or implementations described herein; on the contrary, the present application is intended to cover various modifications and equivalent configurations included in the spirit and scope of the appended claims.
Claims
1. A method for obtaining the kernel call stack of a CPU based on user-mode commands, It is characterized in that include: Generate kernel call stack acquisition command by inputting parameters in user mode; Obtaining commands according to the kernel call stack to determine the target CPU; Execute the kernel call stack acquisition command to send an IPI inter-core interrupt request to the target CPU; Based on the IPI inter-core interrupt request, the target CPU obtains the data of the kernel call stack through a preset interface; Storing the data in a preset character array; The kernel call stack acquisition command is executed again to acquire kernel call stack data from the preset character array.
2. The method according to claim 1, It is characterized in that Generate kernel call stack acquisition commands by inputting parameters in user mode, including: Create a maintainable command in user mode as the entry point to the CPU kernel call stack; Generate kernel call stack acquisition commands by inputting parameters and maintainable commands.
3. The method according to claim 1, It is characterized in that Obtaining a command according to the kernel call stack to determine a target CPU includes: Determine the validity of input parameters in the kernel call stack acquisition command; If the input parameters are valid, the target CPU is determined.
4. The method according to claim 1, It is characterized in that Executing the kernel call stack acquisition command to send an IPI inter-core interrupt request to the target CPU includes: Execute the kernel call stack to obtain a command; Sending an IPI inter-core interrupt request to the target CPU to trigger a non-maskable interrupt operation; The target CPU performs an interrupt processing flow.
5. The method according to claim 4, It is characterized in that Executing the kernel call stack acquisition command to send an IPI inter-core interrupt request to the target CPU also includes: A global variable tag is transmitted, wherein the global variable tag identifies that the interrupt operation is triggered by the kernel call stack acquisition command.
6. The method according to claim 1, It is characterized in that The target CPU obtains the data of the kernel call stack through a preset interface based on the IPI inter-core interrupt request, including: When obtaining global variable parameters through a preset interface, obtaining the identifier of the target CPU; Acquire register values based on the identifier of the target CPU, the registers including FP, SP, and pc registers; The data of the kernel call stack is obtained through the value of the register.
7. The method according to claim 6, It is characterized in that The data of the kernel call stack is obtained through the value of the register, including: Tracking the stack frame of the kernel call stack through the value of the register; Expand the stack frame layer by layer; The value of the PC register of each layer is obtained to generate data of the kernel call stack.
8. The method according to claim 1, It is characterized in that Storing the data in a preset character array also includes: Reset global variable flags.
9. The method according to claim 1, It is characterized in that Executing the kernel call stack acquisition command again to acquire kernel call stack data from the preset character array includes: Set the sleep interval; After the sleep interval, executing the kernel call stack acquisition command again; The data of the kernel call stack is obtained from the preset character array.
10. A CPU kernel call stack acquisition device based on user mode commands, It is characterized in that include: The command module is used to generate kernel call stack acquisition commands by inputting parameters in user mode; A target module, used for obtaining commands according to the kernel call stack to determine the target CPU; A request module, used for executing the kernel call stack acquisition command to send an IPI inter-core interrupt request to the target CPU; A data module, used for requesting the target CPU to obtain the data of the kernel call stack through a preset interface based on the IPI inter-core interrupt; A storage module, used for storing the data in a preset character array; The execution module is used to execute the kernel call stack acquisition command again to obtain the kernel call stack data from the preset character array.
Citation Information
Cited By
Fault analysis method and device, medium and program product
CN120704936A
Interrupt source switching method and device, electronic equipment and computer readable storage medium
CN121070572A
