Hot upgrade method, device, equipment, distributed system and storage medium
By adding sleep instructions and jump instructions to the functions to be replaced, combined with stack balance instructions, thermal upgrades to functions in operation are achieved, solving the problem of system downtime caused by thermal upgrades in the existing technology.
Patent Information
- Application Number
- CN202210314421.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-28
- Publication Date
- 2025-02-18
- Estimated Expiration
- 2042-03-28
AI Technical Summary
It is difficult for the prior art to thermally upgrade functions in the running state without the program or service being stopped, resulting in system downtime and other problems.
Jump to the new replacement function by adding a sleep instruction to the function to be replaced and adding a jump instruction to the function header. The tail of the replacement function contains stack balance instructions and jump instructions, which are used to adjust the stack frame size and jump back to the lower half of the original function.
A hot upgrade to functions in execution state is implemented, avoiding the problem of system downtime and ensuring the correct execution of functions.
Smart Images

Figure CN114691181B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of this specification relate to the field of computer technology, and in particular to hot upgrade methods, devices, equipment, distributed systems and storage media. Background Art
[0002] Hot upgrade refers to the purpose of function upgrade by adding, modifying, and deleting related functional modules without stopping the program / service. Some hot upgrade solutions adopt the idea of hot upgrading each function in the computer program to achieve the purpose of not stopping the program. Function hot upgrade refers to replacing the old function with a new function. In some hot upgrade technologies, in order to ensure that the replaced function does not exist on the stack of any process when replacing the function, the stack safety check method is used to check all stack frames of each process. If the replaced old function is on the stack of the process, it means that the replaced function is in the executed state, so the function will not be hot upgraded. If a function in the execution state is replaced, it will cause problems such as system crashes. Therefore, how to hot upgrade a function in the running state has become a technical problem that needs to be solved urgently. Summary of the invention
[0003] To overcome the problems existing in the related art, the embodiments of this specification provide a hot upgrade method, device, equipment and distributed system.
[0004] According to a first aspect of an embodiment of this specification, a thermal upgrade method is provided, comprising:
[0005] Determine a first function to be replaced; wherein the first function includes a first sleep instruction, and the first sleep instruction is used to instruct the processor to suspend execution of the first function;
[0006] After determining that the first function is executed to the first sleep instruction, a first jump instruction is added to the function header of the first function, the first jump instruction is used to instruct the processor to jump to execute a second function used to replace the first function when executing the first function; wherein the tail of the second function includes a stack balancing instruction and a second jump instruction, the stack balancing instruction is used to instruct the processor to execute the second jump instruction after adjusting the size of the stack frame of the second function based on the size of the stack frame of the first function, and the second jump instruction is used to instruct the processor to jump to execute the instructions of the first function after the first sleep instruction.
[0007] According to a second aspect of an embodiment of this specification, a thermal upgrade device is provided, the device comprising:
[0008] A determination module, configured to: determine a first function to be replaced; wherein the first function includes a first sleep instruction, and the first sleep instruction is used to instruct a processor to suspend execution of the first function;
[0009] A replacement module is used to: after determining that the first function is executed to a first sleep instruction, add a first jump instruction to the function header of the first function, the first jump instruction being used to instruct the processor to jump to execute a second function used to replace the first function when executing the first function; wherein the tail of the second function includes a stack balancing instruction and a second jump instruction, the stack balancing instruction being used to instruct the processor to execute the second jump instruction after adjusting the size of the stack frame of the second function based on the size of the stack frame of the first function, and the second jump instruction being used to instruct the processor to jump to execute the instruction of the first function after the first sleep instruction.
[0010] According to a third aspect of an embodiment of this specification, a computer device is provided, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the method embodiment described in the first aspect when executing the computer program.
[0011] According to a fourth aspect of an embodiment of this specification, a distributed system is provided, the distributed system comprising one or more computer devices, the computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the method embodiment described in the first aspect when executing the computer program.
[0012] According to a fifth aspect of the embodiments of this specification, there is provided a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the steps of the method embodiments described in the first aspect.
[0013] The technical solutions provided by the embodiments of this specification may have the following beneficial effects:
[0014] In the embodiment of this specification, for the first function including the first sleep instruction, when the processor runs to the first sleep instruction, the processor will suspend the execution of the first function, and then, in this embodiment, the first jump instruction is added to the function header of the first function, and the first jump instruction is used to jump to the new second function, thereby replacing the first function. When the first function resumes execution from the first sleep instruction, in this embodiment, the second sleep instruction is used to jump back to the first sleep instruction of the first function and continue to execute subsequent instructions, that is, the lower half of the first function is not replaced. Therefore, this embodiment realizes the hot upgrade of the first function in the execution state, even if the kernel module used for hot upgrade is uninstalled, since the lower half of the first function is not replaced, it will not affect the continued resumption of execution of the first function. In addition, since the stack balance instruction is executed before the execution of the second jump instruction, the processor adjusts the size of the stack frame of the second function based on the size of the stack frame of the first function and then executes the second jump instruction, so that the stack frame of the second function can be accurately recovered after the lower half of the first function is executed, and the correct execution of the function after the first function is upgraded is guaranteed.
[0015] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present specification. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the specification and, together with the description, serve to explain the principles of the specification.
[0017] Figure 1A It is a block diagram of a computer device shown in this specification according to an exemplary embodiment.
[0018] Figure 1B The diagram is a schematic diagram of the operation of a system stack during a function call according to an exemplary embodiment of the present specification.
[0019] Figure 2A It is a flow chart of a thermal upgrade method shown in this specification according to an exemplary embodiment.
[0020] Figure 2B It is a flow chart of another thermal upgrade method shown in this specification according to an exemplary embodiment.
[0021] Figure 2C It is a schematic diagram of stack balance between an original function and a new function according to an exemplary embodiment of the present specification.
[0022] Figure 3 It is a block diagram of a thermal upgrade device according to an exemplary embodiment of the present specification. DETAILED DESCRIPTION
[0023] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The implementations described in the following exemplary embodiments do not represent all implementations consistent with this specification. Instead, they are merely examples of devices and methods consistent with some aspects of this specification as detailed in the appended claims.
[0024] The terms used in this specification are for the purpose of describing specific embodiments only and are not intended to limit this specification. The singular forms "a", "the" and "the" used in this specification and the appended claims are also intended to include plural forms unless the context clearly indicates otherwise. It should also be understood that the term "and / or" used herein refers to and includes any or all possible combinations of one or more associated listed items.
[0025] It should be understood that although the terms first, second, third, etc. may be used in this specification to describe various information, this information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of this specification, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".
[0026] First, the process of executing a computer program in a computer device is described by an embodiment. Figure 1A 1 is a schematic diagram of the hardware structure of a computer device provided in an embodiment of the present specification, and the device may include: a processor 101, a memory 102, an input / output interface 103, a communication interface 104, and a bus 105. The processor 101, the memory 102, the input / output interface 103, and the communication interface 104 are connected to each other in communication within the device through the bus 105.
[0027] The processor 101 can be implemented by a general-purpose CPU (Central Processing Unit), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits, etc., for executing relevant programs to implement the technical solutions provided in the embodiments of this specification. The processor 101 can also include a graphics card, etc.
[0028] The memory 102 may be implemented in the form of ROM (Read Only Memory), RAM (Random Access Memory), static storage device, dynamic storage device, etc. The memory 102 may store an operating system and other application programs. When the technical solutions provided in the embodiments of this specification are implemented by software or firmware, the relevant program codes are stored in the memory 102 and are called and executed by the processor 101.
[0029] The input / output interface 103 is used to connect the input / output module to realize information input and output. The input / output module can be configured as a component in the device (not shown in the figure), or it can be externally connected to the device to provide corresponding functions. The input device may include a keyboard, a mouse, a touch screen, a microphone, various sensors, etc., and the output device may include a display, a speaker, a vibrator, an indicator light, etc.
[0030] The communication interface 104 is used to connect a communication module (not shown) to realize communication interaction between the device and other devices. The communication module can realize communication through wired means (such as USB, network cable, etc.) or wireless means (such as mobile network, WIFI, Bluetooth, etc.).
[0031] The bus 105 includes a path that transmits information between various components of the device (eg, the processor 101 , the memory 102 , the input / output interface 103 , and the communication interface 104 ).
[0032] It should be noted that, although the above device only shows the processor 101, the memory 102, the input / output interface 103, the communication interface 104 and the bus 105, in the specific implementation process, the device may also include other components necessary for normal operation. In addition, it can be understood by those skilled in the art that the above device may also only include the components necessary for implementing the embodiments of this specification, and does not necessarily include all the components shown in the figure.
[0033] Among them, the memory is a computer-readable storage medium, which includes permanent and non-permanent, removable and non-removable media, etc., which can be implemented by any method or technology to store information. Information can be computer-readable instructions, data structures, modules of programs or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, read-only compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device.
[0034] The structure of the processor (central processing unit, CPU) can be roughly divided into an arithmetic logic unit, a register unit and a control unit. The arithmetic logic unit can mainly perform related logical operations, such as shift operations and logical operations. In addition, it can also perform fixed-point or floating-point arithmetic operations, address operations, conversion commands, etc. It is a multifunctional arithmetic unit. The control unit is mainly used to analyze instructions and can issue corresponding control signals. The register unit is used to temporarily store instructions, data and addresses. It is a small storage area inside the processor for storing data. The processor usually includes multiple registers, which can be divided into general registers, special registers and control registers by type.
[0035] The source program written in a compiled language can be compiled into an executable file (i.e., a computer program) by a corresponding compiler and then run by a processor; at this time, the computer program in the executable state is called a process. A program is a collection of instructions. A program includes multiple functions, each function includes multiple computer-executable instructions, and there is a calling relationship between functions. Specifically, the executable file of a computer program is loaded into the memory, that is, the memory stores the instruction set, and the processor reads each instruction from the memory and executes it. The memory used by the process can generally be divided into the following four parts according to its function:
[0036] (1) Code area: This area stores computer programs, that is, the instructions of each function. The processor will go to this area to fetch the function instructions and execute them.
[0037] (2) Data area: used to store global variables, etc.
[0038] (3) Heap area: A process can dynamically request a certain amount of memory in the heap area and return it to the heap area after use. Dynamic memory allocation and memory recycling are the characteristics of the heap area.
[0039] (4) Stack area: used to dynamically store the calling relationship between functions to ensure that the called function can resume execution in the parent function when returning. Since function calls are often nested, there will be information about multiple functions in the stack area at the same time. Each unfinished function occupies an independent continuous area (including the parameters, local variables, return address and other related information involved in this function), which is called a stack frame.
[0040] Assume that the code of a source program describes the following three functions: func_B function, func_A function (the func_B function is called within the function), and main function (the func_A function is called within the function).
[0041] When a computer program is running on a computer device, the processor will divide the code area of the memory into three areas to store the instructions of the above three functions respectively.
[0042] Among them, when the processor executes the call to the func_B function in the func_A function, it will jump from the instruction area corresponding to the func_A function in the memory code area to the instruction area corresponding to the func_B function, where it will fetch and execute the instructions of the func_B function; when the func_B function is executed and needs to return, it will jump back to the instruction area corresponding to the func_A function, and then fetch the instructions after the func_B function in the func_A function to continue executing the func_A function.
[0043] When the processor processes the above function call relationship, the precise jumps between functions are completed in cooperation with the system stack (i.e. the aforementioned memory stack area). When a function is called, the system stack will create a new stack frame for this function and push it into the stack. The memory space in this stack frame is exclusively occupied by the function to which it belongs, and is not normally shared with other functions. When the function returns, the stack frame corresponding to the function needs to be recycled, that is, the system stack will pop the stack frame corresponding to the function.
[0044] Taking the above function call example, Figure 1B FIG. 1 is a schematic diagram of the operation of the accompanying system stack during a function call according to an exemplary embodiment of the present specification, specifically:
[0045] When calling func_A in the main function, first push the function return address into its own stack frame, then create a new stack frame for func_A and push it into the system stack.
[0046] When func__A calls func_B, it also pushes the function return address into its own stack frame first, then creates a new stack frame for func_B and pushes it into the system stack.
[0047] When func_B is executed and returns, the stack frame of func_B is popped off the system stack, and the return address in the stack frame of func_A is "exposed" on the top of the stack. At this time, the processor jumps back to the func_A code area to execute according to this return address.
[0048] When func_A is executed and returns, the stack frame of func_A is popped off the system stack, and the return address in the main function stack frame is "exposed" at the top of the stack. At this time, the processor jumps to the main function code area to execute according to this return address.
[0049] Each function has its own stack frame space. The stack frame of the currently running function is always at the top of the stack. The CPU system provides two special registers to identify the stack frame at the top of the system stack.
[0050] (1) The Stack Pointer (SP) register stores a pointer that points to the top of the topmost stack frame on the system stack.
[0051] (2) Base Pointer (BP), which stores a pointer to the bottom of the topmost stack frame of the system stack.
[0052] Among them, BP points to the bottom of the stack frame currently at the top of the system stack, rather than the bottom of the system stack, that is, the "bottom of the stack frame" and the "bottom of the stack" are different concepts.
[0053] The implementation of hot upgrade of some functions is to bypass the execution of the original function in some way and jump to the new function to achieve hot upgrade; for example, a jump instruction is added to the head of the original function, and the jump instruction points to the new function. When the function is executed, it jumps to the new function through the jump instruction. When the new function is executed and returns, it returns to the calling function of the original function to continue execution. Therefore, the original function is skipped and replaced.
[0054] The kernel is the most basic part of the operating system. It is a part of software that provides secure access to computer hardware for many applications. This access is limited, and the kernel determines when and how long a program operates on a certain part of the hardware. It is responsible for managing the system's processes, memory, device drivers, files, and network systems, and determines the system's performance and stability. For the hot upgrade of the kernel program, taking the Linux system as an example, a kernel module for hot upgrade is usually implemented. By inserting the kernel module into the system, the kernel module modifies the instructions in the header of the original function to let it jump to the new function; if the upgrade is to be deleted, the header of the original function can be restored, and the kernel module can be uninstalled as needed. However, the above hot upgrade is usually only for functions that are not in the execution state; stack safety checks are usually performed during the hot upgrade process. Since the stack area stores the stack frames of unfinished functions, the stack safety check specifically checks whether there is a stack frame of the function to be replaced in the stack area to check whether the function to be replaced is being executed by a process / thread. If so, a check failure result is returned, and the function cannot be executed and replaced.
[0055] There is a type of function in the kernel program, which can be called a sleep function. The characteristic of this type of function is that when the process / thread executes a certain instruction of the function (which can be called a sleep point), the function can be suspended, that is, the function is put into a sleep state. For example, this instruction can make the CPU enter the IDLE state (idle mode), or let the processor perform context switching to switch to other processes; after certain conditions are triggered, the processor can resume execution of the function from the sleep point of the function.
[0056] From the above analysis, it can be seen that this type of sleep function has great difficulties; since the function is in a sleep state without completing execution, the function has a stack frame in the stack area, and the last execution point of the process is in the function; if the kernel module used for hot upgrade directly replaces the old function with a new function, the process enters a sleep state after running the new function, and then if the kernel module is uninstalled, all the data of the new function in the memory will be cleared. When the process needs to resume running again, the instructions after the sleep point cannot be found in the memory at this time, so there will be errors or downtime. In order to prevent problems such as errors or downtime, stack safety checks can be used to avoid them. For processes that call sleep functions, when the process is asleep, the top of the stack of the process is the sleep function, so the sleep function cannot be hot upgraded. If you want to wait for the sleep function to be executed, some sleep functions have a long sleep time, so you may have to wait for a long time. Moreover, functions such as the _schedule function of the Linux kernel are usually continuously in the execution state during the operation of the computer device, that is, they are continuously in the stack area and cannot be hot upgraded.
[0057] Based on this, the embodiment of this specification provides a hot upgrade solution, which can perform hot upgrade on the function that has not been executed completely, and will not cause errors or downtime. Next, the embodiment is described in detail.
[0058] like Figure 2A FIG. 1 is a flow chart of a thermal upgrade method according to an exemplary embodiment of the present specification, and includes the following steps:
[0059] In step 202, a first function to be replaced is determined; wherein the first function includes a first sleep instruction, and the first sleep instruction is used to instruct a processor to suspend execution of the first function;
[0060] In step 204, after determining that the first function is executed to the first instruction, a first jump instruction is added to the function header of the first function, the first jump instruction being used to indicate that when executing the first function, a jump is made to execute a second function used to replace the first function; wherein the tail of the second function includes a stack balancing instruction and a second jump instruction, the stack balancing instruction being used to instruct the processor to execute the second jump instruction after adjusting the size of the stack frame of the second function based on the size of the stack frame of the first function, and the second jump instruction being used to instruct the processor to jump to execute the instruction of the first function after the first sleep instruction.
[0061] In some examples, developers can develop a hot upgrade data packet for one or more functions in the kernel program in advance according to the functions that need to be replaced. In this embodiment, the original function that needs to be replaced is referred to as the first function to be replaced, and the new function that replaces the first function is referred to as the second function. The developed data packet for hot upgrade can identify the first function after being loaded by a device (such as a server) having the kernel program, and use the second function in the data packet to replace its function.
[0062] Among them, the first function of this embodiment may include the aforementioned sleep function, and the first function includes a first sleep instruction, that is, the aforementioned sleep point, and the first sleep instruction is used to instruct the processor to suspend the execution of the first function, that is, when the processor runs to the first sleep instruction, the processor suspends the execution of the first function. For example, the first sleep instruction may include an instruction to let the CPU enter the IDLE state (idle mode), or an instruction to let the processor perform context switching, such as controlling the processor to switch to other processes. There are many first functions in actual applications, such as the _schedule function of the Linux kernel.
[0063] As mentioned above, the stack area of the memory records the calling relationship between functions, and each unfinished function occupies an independent continuous area. Based on this, in some examples, the stack area of the memory can be checked to determine the first function and determine that the first function is executed to the first instruction.
[0064] For the sake of ease of illustration, this embodiment refers to the instruction set before the first sleep instruction in the first function as the upper half of the first function, and the instruction set after the first sleep instruction in the first function as the lower half of the first function; it can be understood that the upper half and the lower half are only used to distinguish the names before and after the first sleep instruction in the first function, and are not divided into the upper half and the lower half based on the number of instructions in the function.
[0065] Function hot upgrade involves the replacement of the old function with the new function. In this embodiment, a first jump instruction is added to the function header of the first function, and the first jump instruction is used to jump to the new second function, thereby realizing the replacement of the first function. In practical applications, the process of adding the first jump instruction can be to find the instruction of the first function in the code area of the memory, and modify the first instruction of the first function to the instruction to jump to the second function. Among them, the instructions of the first function stored in the disk of the computer device can also be replaced. In this embodiment, since the first function will resume execution from the first sleep instruction under the set conditions, in order to ensure the normal execution of the first function, although the jump to the new second function in this embodiment is performed, the lower half of the first function is not replaced. When the execution is resumed, the lower half of the first function can be resumed and executed from the first sleep instruction. Therefore, the replacement in this embodiment refers to the replacement of the instructions before the first sleep instruction in the first function, rather than the replacement of the entire first function.
[0066] In some examples, after the kernel module for hot upgrade is loaded, if the first function resumes execution, since the stack frame corresponding to the first function records the information of the first function before the execution is suspended, such as the address of the first sleep instruction in the memory code area, etc., the processor can continue to execute the lower half of the first function after the first sleep instruction. Based on this, even if the kernel module for hot upgrade is uninstalled, since the lower half of the first function has not been replaced, the first function can still continue to execute from the sleep point when it resumes, so it will not affect the continued resumption of execution of the first function.
[0067] In some examples, such as Figure 2B As shown, this specification shows the process of function execution after function hot upgrade according to an exemplary embodiment; after the kernel module for hot upgrade is loaded, if there is a parent function of the first function calling the first function (ie Figure 2BSince the first function header has a first jump instruction, no stack frame is created for the first function. The processor jumps to the second function (i.e. Figure 2B The processor starts executing the second function, creates a stack frame for the second function in the stack area of the memory and pushes it into the system stack. At this time, the stack frame of the second function is at the top of the stack area.
[0068] Among them, since the second function is used to replace the upper part of the first function, the second function is a new function, and the number of its local variables may change, or due to the inconsistency of the compiler version and other reasons, the stack frame size of the second function is ultimately inconsistent with the stack frame size occupied by the upper part of the first function, thereby destroying the stack balance of the first function. The lower part of the first function is not replaced, and the lower part of the first function will recycle the stack after execution. Since the program to which the first function belongs has determined the stack frame size of the first function during compilation, the lower part of the first function will recycle the stack according to the stack frame size of the first function after execution, so as to return to the instruction position when the parent function of the first function calls the first function. If the stack balance is not adjusted, since the stack frame size of the second function is inconsistent with the stack frame size occupied by the upper part of the first function, it will result in the inability to accurately return to the parent function of the first function. Therefore, this embodiment is designed to include a stack balancing instruction in the second function before jumping back to the lower half of the first function. The instruction is used to instruct the processor to adjust the size of the stack frame of the second function based on the size of the stack frame of the first function and then execute the second jump instruction, so that the stack frame of the second function can be accurately recovered after the lower half of the first function is executed.
[0069] like Figure 2C As shown, this specification shows a stack balance adjustment process according to an exemplary embodiment; wherein, Figure 2C The stack frame size of the original function is the size from the bottom of the stack frame to the top of the stack frame (SP); the stack frame size of the new function is the size from the bottom of the stack frame to the top of the original stack. If the sizes of the two are inconsistent, Figure 2C In the example in which the stack frame of the new function is smaller, this embodiment adjusts the stack frame size of the new function to be consistent with the stack frame size of the original function through the stack balancing instruction. Figure 2C The example in which the stack frame size of the new function is smaller than the stack frame of the original function is used for illustration. In actual applications, the stack frame size of the new function may be larger than the stack frame of the original function. The stack frame size of the new function can be reduced to keep it consistent with the stack frame size of the original function. Of course, it is also possible that the stack frame size of the new function is equal to the stack frame size of the original function.
[0070] As an example, the stack balance instruction can be used to update the pointer stored in the stack pointer register according to the predetermined stack frame size of the first function and the stack frame size created when the second function is executed, so that after the instruction of the first function after the first sleep instruction is executed, the stack frame of the second function is recovered according to the pointer stored in the stack pointer register. As an example, the stack frame size of the first function is determined by the compiler during the compilation process of the source program where the first function is located. Based on this, before developing a data packet for hot upgrade, the compiled instruction content can be pre-read to determine the stack frame size of the first function.
[0071] Among them, the pointer stored in the stack pointer register points to the top of the top stack frame of the system stack. When the second function is executed, the pointer stored in the stack pointer register points to the top of the stack frame of the second function. Under the instruction of the stack balance instruction, the processor can determine the difference between the sizes of the first function and the stack frame size of the second function, and then calculate the new address based on the difference between the sizes and the address of the top of the stack frame of the second function, and then update the pointer stored in the stack pointer register, so that after the update, the stack frame pointed to by the pointer in the stack pointer register from the top to the bottom of the stack frame is consistent with the stack frame size of the first function. After adjusting the stack balance, according to the second jump instruction, the processor jumps to the lower half of the first function and continues to execute the instructions of the lower half.
[0072] In some examples, since the upper part of the first function is replaced by the second function, a new usage of local variables may be defined in the second function, and the stack layout of the second function may be inconsistent with that of the first function. In order to prevent the lower part of the first function from accessing incorrect data, in this embodiment, the instructions after the first instruction in the first function do not access the local variables of the first function, that is, the lower part is restricted from directly accessing the local variables allocated on the stack, that is, this embodiment can be used to hot-upgrade the first function whose lower part does not access the local variables, thereby preventing the problem of data access errors after the hot upgrade. Alternatively, in other examples, the use of local variables by the second function can be consistent with the use of local variables by the first function, so that when the lower part of the first function needs to access local variables, it will not access incorrect data.
[0073] The function calling convention describes the technical details of the function parameter passing method and the stack collaboration. Although the principles of implementing function calls are basically the same for different operating systems, different languages, and different compilers, there are still differences in the specific calling conventions, which generally include the parameter passing method, whether the parameter stacking order is from right to left or from left to right, and whether the operation of restoring the stack balance when the function returns is performed in the child function or in the parent function. In some examples, after the second function is executed, it is necessary to jump to the lower half of the first function. Based on this, the function calling convention defined in the second function can be consistent with the function calling convention defined in the first function, such as the parameter passing method, whether the parameter stacking order is from right to left or from left to right, and whether the operation of restoring the stack balance when the function returns is performed in the child function or in the parent function.
[0074] In some examples, the callee saved register of the second function should be consistent with the callee saved register of the first function, so that the stack frame of the second function can be accurately recovered according to the pointer stored in the stack pointer register. Among them, the callee saved registers are also called non-volatile registers. During the program call process, the values in these registers need to be saved and cannot be overwritten; when a program calls these registers, the called registers will first save these values and then call them, and restore the values before the call after the call ends. That is, for the function caller (caller), the data of these registers remains unchanged before and after the function call, and their data save / restore operations are performed in the called function (callee).
[0075] As can be seen from the above embodiment, for the first function including the first sleep instruction, when the processor runs to the first sleep instruction, the processor will suspend the execution of the first function. After that, the first jump instruction is added to the function header of the first function in this embodiment, and the first jump instruction is used to jump to the new second function, thereby replacing the first function. When the first function resumes execution from the first sleep instruction, the second sleep instruction is used to jump back to the first sleep instruction of the first function in this embodiment and continue to execute subsequent instructions, that is, the lower half of the first function is not replaced. Therefore, this embodiment realizes the hot upgrade of the first function in the execution state, even if the kernel module used for hot upgrade is uninstalled, since the lower half of the first function is not replaced, it will not affect the continued resumption of execution of the first function. In addition, since the stack balance instruction is executed before executing the second jump instruction, the processor adjusts the size of the stack frame of the second function based on the size of the stack frame of the first function and then executes the second jump instruction, so that the stack frame of the second function can be accurately recovered after the lower half of the first function is executed, and the correct execution of the function after the first function is upgraded is guaranteed.
[0076] This embodiment utilizes the combination of function separation and stack balance adjustment, and can perform hot upgrades on functions such as sleep functions in the operating system kernel, and the upper half of such functions can be replaced. For example, for the _schedule function of the Linux kernel, the core logic of the function is in the upper half, and the upper half can be replaced by using this embodiment to achieve hot upgrade of the function.
[0077] Corresponding to the aforementioned embodiment of the thermal upgrade method, this specification also provides embodiments of a thermal upgrade device and a computer used therein.
[0078] The hot upgrade method of this embodiment is applied to one or more computer devices, wherein the computer device is a device that can automatically perform numerical calculations and / or information processing according to pre-set or stored instructions, and the hardware of the electronic device includes but is not limited to a microprocessor, an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), a digital signal processor (DSP), an embedded device, etc. The computer device can be any electronic product that can interact with a user, such as a personal computer, a tablet computer, a smart phone, a personal digital assistant (PDA), a game console, an interactive network television (IPTV), an intelligent wearable device, etc. The computer device may also include a network device and / or a user device. Among them, the network device includes, but is not limited to, a single network server, a server group consisting of multiple network servers, or a cloud composed of a large number of hosts or network servers based on cloud computing (Cloud Computing). The network in which the computer device is located includes but is not limited to the Internet, a wide area network, a metropolitan area network, a local area network, a virtual private network (VPN), etc.
[0079] As an example, the embodiments of the thermal upgrade device of this specification can be applied to Figure 1A The computer device shown is, for example, a server or a terminal device. The device embodiment can be implemented by software, or by hardware or a combination of software and hardware. Taking software implementation as an example, as a device in a logical sense, the processor of the file processing in which it is located reads the corresponding computer program instructions in the non-volatile memory into the memory and runs them.
[0080] like Figure 3 As shown, Figure 3 1 is a block diagram of a thermal upgrade device according to an exemplary embodiment of the present specification, the device comprising:
[0081] The determination module 31 is used to: determine a first function to be replaced; wherein the first function includes a first sleep instruction, and the first sleep instruction is used to instruct the processor to suspend execution of the first function;
[0082] A replacement module 32 is used to: after determining that the first function is executed to a first sleep instruction, add a first jump instruction to the function header of the first function, the first jump instruction being used to instruct the processor to jump to execute a second function used to replace the first function when executing the first function; wherein the tail of the second function includes a stack balancing instruction and a second jump instruction, the stack balancing instruction being used to instruct the processor to execute the second jump instruction after adjusting the size of the stack frame of the second function based on the size of the stack frame of the first function, and the second jump instruction being used to instruct the processor to jump to execute the instruction of the first function after the first sleep instruction.
[0083] In some examples, the stack balancing instruction is used to update the pointer stored in the pointer register based on a predetermined stack frame size of the first function and a stack frame size created when the second function is executed, so that after the instructions of the first function after the first sleep instruction are executed, the stack frame of the second function is reclaimed according to the pointer stored in the stack pointer register.
[0084] In some examples, instructions in the first function following the first sleep instruction do not access local variables of the first function.
[0085] In some examples, the function calling convention defined in the second function is consistent with the function calling convention defined in the first function.
[0086] In some examples, the callee saved register of the second function is consistent with the callee saved register of the first function.
[0087] In some examples, the first function comprises a function of a kernel program.
[0088] According to a third aspect of an embodiment of this specification, a computer device is provided, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the method embodiment described in the first aspect when executing the computer program.
[0089] According to a fourth aspect of an embodiment of this specification, a distributed system is provided, the distributed system comprising one or more computer devices, the computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the method embodiment described in the first aspect when executing the computer program.
[0090] According to a fifth aspect of the embodiments of this specification, there is provided a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the steps of the method embodiments described in the first aspect.
[0091] The implementation process of the functions and effects of each module in the above-mentioned thermal upgrade device is specifically described in the implementation process of the corresponding steps in the above-mentioned thermal upgrade method, and will not be repeated here.
[0092] For the device embodiment, since it basically corresponds to the method embodiment, the relevant parts can refer to the partial description of the method embodiment. The device embodiment described above is only schematic, wherein the modules described as separate components may or may not be physically separated, and the components displayed as modules may or may not be physical modules, that is, they may be located in one place, or they may be distributed on multiple network modules. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this specification. A person of ordinary skill in the art can understand and implement it without paying creative labor.
[0093] The above is a description of a specific embodiment of the specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0094] The step division of the above methods is only for clear description. When implemented, they can be combined into one step or some steps can be split and decomposed into multiple steps. As long as they include the same logical relationship, they are all within the protection scope of this patent; adding insignificant modifications to the algorithm or process or introducing insignificant designs without changing the core design of the algorithm and process are all within the protection scope of this application.
[0095] The description of "specific examples" or "some examples" means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of this specification. In this specification, the schematic representation of the above terms does not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described can be combined in any one or more embodiments or examples in a suitable manner.
[0096] It can be known from the above description of the implementation mode that the technicians in this field can clearly understand that the embodiments of this specification can be implemented by means of software plus the necessary general hardware platform. Based on such an understanding, the technical solution of the embodiments of this specification can be essentially or the part that contributes to the prior art can be embodied in the form of a software product, which can be stored in a storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments of this specification.
[0097] The systems, devices, modules or units described in the above embodiments may be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer, which may be in the form of a personal computer, a laptop computer, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email transceiver, a game console, a tablet computer, a wearable device or a combination of any of these devices.
[0098] Those skilled in the art will readily appreciate other embodiments of the specification after considering the specification and practicing the invention claimed herein. The specification is intended to cover any variations, uses or adaptations of the specification that follow the general principles of the specification and include common knowledge or customary techniques in the art that are not claimed in the specification. The specification and examples are to be considered exemplary only, and the true scope and spirit of the specification are indicated by the following claims.
[0099] It should be understood that the present description is not limited to the precise structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present description is limited only by the appended claims.
[0100] The above description is only a preferred embodiment of this specification and is not intended to limit this specification. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of this specification should be included in the scope of protection of this specification.
Claims
1. A thermal upgrade method, comprising: Determine a first function to be replaced that is being executed by a process; wherein the first function is on a stack of the process; the first function includes a first sleep instruction, and the first sleep instruction is used to instruct a processor to suspend execution of the first function; After determining that the first function is executed to the first sleep instruction, a first jump instruction is added to the function header of the first function, the first jump instruction is used to instruct the processor to jump to execute the second function used to replace the first function when executing the first function; wherein the tail of the second function includes a stack balancing instruction and a second jump instruction, the stack balancing instruction is used to instruct the processor to adjust the size of the stack frame of the second function to be consistent with the size of the stack frame of the first function and then execute the second jump instruction, and update the pointer stored in the stack pointer register according to the predetermined stack frame size of the first function and the stack frame size created when the second function is executed, so that after the instructions of the first function after the first sleep instruction are executed, the stack frame of the second function is recovered according to the pointer stored in the stack pointer register; the second jump instruction is used to instruct the processor to jump to execute the instructions of the first function after the first sleep instruction. 2 . The method according to claim 1 , wherein instructions in the first function following the first sleep instruction do not access local variables of the first function.
3. According to the method of claim 1, the function calling convention defined in the second function is consistent with the function calling convention defined in the first function. 4 . The method according to claim 1 , wherein the callee saved register of the second function is consistent with the callee saved register of the first function. The method according to claim 1 , wherein the first function comprises a function of a kernel program.
6. A thermal upgrade device, comprising: A determination module, configured to: determine a first function to be replaced that is being executed by a process; wherein the first function is on a stack of the process; and the first function includes a first sleep instruction, wherein the first sleep instruction is used to instruct a processor to suspend execution of the first function; A replacement module is used to: after determining that the first function is executed to a first sleep instruction, add a first jump instruction to the function header of the first function, the first jump instruction being used to instruct the processor to jump to execute a second function used to replace the first function when executing the first function; wherein the tail of the second function includes a stack balancing instruction and a second jump instruction, the stack balancing instruction being used to instruct the processor to adjust the size of the stack frame of the second function to be consistent with the size of the stack frame of the first function and then execute the second jump instruction, and update the pointer stored in the stack pointer register according to the predetermined stack frame size of the first function and the stack frame size created when the second function is executed, so that after the instructions of the first function after the first sleep instruction are executed, the stack frame of the second function is recovered according to the pointer stored in the stack pointer register; the second jump instruction is used to instruct the processor to jump to execute the instructions of the first function after the first sleep instruction.
7. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 5 are implemented.
8. A distributed system, comprising one or more computer devices, wherein the computer devices comprise a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 5 are implemented.
9. A computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the steps of any one of the methods of claims 1 to 5.
Citation Information
Patent Citations
Data processing method and system, and equipment
CN113672273A