Data area structure, program hot update method and program hot update system

By dividing the data area into a basic area and a reserved area, and operating only on the reserved area, the stability problem of hot updates of the data area in the real-time system is solved, realizing a hot update mechanism without copying or replacement, thus improving the stability and efficiency of the system.

CN121560367APending Publication Date: 2026-02-24SHANGHAI EMPOWER TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511801997.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-12-02
Publication Date
2026-02-24

AI Technical Summary

Technical Problem

Existing technologies cannot effectively handle hot updates of data areas in real-time systems, resulting in low stability of hot updates.

Method used

The data area is divided into a basic area and a reserved area. The basic area stores the original basic variables, and the reserved area stores the newly added variables. Operations are only performed on the reserved area to avoid rebuilding the entire data area and achieve a hot update mechanism without copying or replacing.

Benefits of technology

It improves the stability of hot updates, meets the requirements of hard real-time periodic tasks, avoids program downtime and data transfer, and ensures the stability and efficiency of program operation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121560367A_ABST
    Figure CN121560367A_ABST
Patent Text Reader

Abstract

The invention provides a data area structure, a program hot update method and a program hot update system, and relates to the technical field of computers. The data area structure comprises a basic area and a reserved area; wherein the basic area is used for storing an original basic variable; the original basic variable is determined based on a program deployed for the first time; the reserved area is used for dynamically storing new variables different from the original basic variables and historical variables stored in the reserved area in the program to be subjected to hot update. According to the method, the data area is divided into the basic area and the reserved area, so that during hot updating, only the reserved area is operated, variables in the basic area are not changed, the whole data area is not reconstructed, and the hot updating stability is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and more specifically, to a data area structure, a program hot update method, and a program hot update system. Background Technology

[0002] In the internet industry, it is often necessary to repair and update released programs to ensure system stability and user experience.

[0003] Currently, common hot update techniques mainly fall into three categories: script-based hot updates, dual-process hot updates, and dynamic library replacement. Script-based hot updates rely on interpreted execution, which cannot meet the deterministic and low-latency requirements of hard real-time tasks. Dual-process hot updates involve process switching, resource migration, and state reconstruction, making them difficult to implement in real-time multi-task, multi-priority scheduling environments and potentially compromising time determinism. While dynamic library replacement can be used for function logic updates in real-time systems, it requires allocating a completely new data area conforming to the new layout and copying and converting data from the old data area to the new one when data changes, thus failing to effectively handle hot updates of the data area.

[0004] In summary, in real-time systems, existing technologies cannot effectively handle hot updates of data areas, resulting in low stability of hot updates. Summary of the Invention

[0005] The purpose of this application is to provide a data area structure, a program hot update method, and a program hot update system, which divide the data area into a basic area and a reserved area, so that during hot update, only the reserved area is operated on, and the variables in the basic area are not changed, and there is no overall data area reconstruction, thereby improving the stability of hot update.

[0006] In a first aspect, embodiments of this application provide a data area structure, which includes a basic area and a reserved area; wherein, the basic area is used to store original basic variables; the original basic variables are determined based on the program deployed for the first time; the reserved area is used to dynamically store new variables that are different from the original basic variables and the historical variables already stored in the reserved area in the program to be hot-updated.

[0007] In this embodiment, the data area is divided into a basic area and a reserved area. The basic area stores the original basic variables in the program during its initial deployment, while the reserved area stores newly added variables. Since operations are only performed on the reserved area, the variables in the basic area are not modified, and there is no overall data area reconstruction, a hot update mechanism without copying or replacement of the data area is achieved, improving the stability of hot updates.

[0008] In some embodiments, the original underlying variables and their storage location in the underlying region remain unchanged during hot updates.

[0009] In this embodiment, the original basic variables stored in the basic area remain unchanged during hot updates, preventing pointer invalidation in the running program and improving program stability. Furthermore, since the data structure of the basic area remains constant, operations are only performed on the reserved area, eliminating the need for system downtime or data transfer during hot updates, thus meeting the requirements of hard real-time periodic tasks.

[0010] In some embodiments, the base area and the reserved area constitute a continuous data area, and the base area and the reserved area are separated by a special variable; the special variable is used to determine the storage address of the new variable when storing the new variable in the reserved area.

[0011] In this embodiment, the basic region and the reserved region are a continuous data area. To distinguish between the basic region and the reserved region, a special variable is set between them for separation, facilitating data access. Furthermore, the special variable serves as an alignment anchor point for the reserved region, making it easier to determine the storage address of new variables within the reserved region.

[0012] In some embodiments, the areas in the reserved area where no variables are stored are filled with preset fill data.

[0013] This application embodiment automatically fills unused space in the reserved area with placeholder data, maintaining the regularity and stability of the memory layout of the reserved area, improving the stability of the data area structure, and thus improving the stability of hot updates.

[0014] In some embodiments, the new variable includes a data type; the operation logic for storing the new variable in the reserved area is as follows: based on the data type, determine the number of bytes occupied by the new variable and the natural alignment requirement; obtain the current end address of the reserved area; calculate the target storage start address that meets the alignment requirement of the new variable according to the natural alignment requirement and the current end address; based on the target storage start address, write the new variable into the corresponding position in the reserved area according to the number of bytes.

[0015] This application's embodiments determine the number of bytes to be occupied and the natural alignment requirements based on the data type of the new variable, and then write it to the corresponding position in the reserved area according to the number of bytes and the natural alignment requirements. This maintains the regularity and stability of the memory layout in the reserved area, improves the stability of the data area structure, and thus improves the stability of hot updates.

[0016] Secondly, embodiments of this application provide a method for hot-updating a program. The method includes: reading an initial configuration file and a program to be hot-updated; wherein the initial configuration file includes an original basic variable list and an initial reserved variable list; the program to be hot-updated includes a current variable set; if it is determined that there is a new variable in the current variable set that is not included in either the original basic variable list or the initial reserved variable list, then the initial reserved variable list is updated based on the new variable to generate a reserved variable list; and the initial configuration file is updated based on the reserved variable list to generate a new configuration file; wherein the new configuration file is used to hot-update the program to be hot-updated.

[0017] In this embodiment, the initial configuration file includes an original list of basic variables and an initial list of reserved variables, while the program to be hot-updated includes the current set of variables. If it is determined that there are new variables in the current set that are not included in either the original list of basic variables or the initial list of reserved variables, it indicates that there are new variables in the program to be hot-updated that were not previously present. To ensure the normal execution of the program to be hot-updated, these new variables need to be stored first, so that the program can correctly read the corresponding variable data during execution.

[0018] To avoid pointer invalidation in the running program due to operations on the original base variables, the new variable is stored in the initial reserved variable list, thus forming a new configuration file for hot updates. Since operations are only performed on the reserved area, without changing variables in the base area or rebuilding the entire data area, a hot update mechanism without copying or replacing the data area is achieved, improving the stability of hot updates.

[0019] In some embodiments, the new variable includes a data type; updating the initial reserved variable list based on the new variable to generate a reserved variable list includes: determining the number of bytes occupied by the new variable and the natural alignment requirement based on the data type; obtaining the current end address of the initial reserved variable list; calculating the target storage start address that meets the alignment requirement of the new variable according to the natural alignment requirement and the current end address; and writing the new variable into the corresponding position of the initial reserved variable list according to the number of bytes based on the target storage start address to generate the reserved variable list.

[0020] This application embodiment determines the number of bytes to be occupied and the natural alignment requirements based on the data type of the new variable, and then writes it to the corresponding position in the initial reserved variable list according to the number of bytes and the natural alignment requirements. Since this storage method conforms to the CPU's data access reading method, it improves the CPU's access speed and access stability, thereby improving the efficiency and stability of hot updates.

[0021] In some embodiments, updating the initial reserved variable list based on the new variables to generate a reserved variable list includes: if it is determined that there are historical variables in the initial reserved variable list that are not included in the current variable set, then the historical variables are deleted to obtain a basic reserved variable list; and updating the basic reserved variable list based on the new variables to generate a reserved variable list.

[0022] This application embodiment releases reserved slots by deleting historical variables that meet the requirements from the initial reserved variable list, allowing the reserved variable list to be used cyclically and improving the memory utilization of the reserved area.

[0023] In some embodiments, the new variable includes a data type; updating the basic reserved variable list based on the new variable to generate a reserved variable list includes: if it is determined that the data types of the new variable and the historical variable are the same, then the new variable is written into the position of the historical variable to update the basic reserved variable list and generate a reserved variable list.

[0024] In this embodiment, if it is determined that the data type of the new variable is the same as the data type of the deleted historical variable, the new variable is stored in the location of the deleted historical variable. This not only improves the memory utilization of the reserved area, but also meets the natural alignment requirements of data storage, improves access stability, and thus improves the stability of hot updates.

[0025] In some embodiments, if it is determined that there is a new variable in the current variable set that is not included in the original basic variable list and the initial reserved variable list, then the initial reserved variable list is updated based on the new variable to generate the reserved variable list. The method further includes: if it is determined that the used storage space of the reserved variable list is greater than a preset memory threshold, then the current hot update process is terminated.

[0026] In this embodiment of the application, if the used storage space of the reserved variable list is greater than the preset memory threshold after adding a new variable, indicating that the memory space of the reserved area is overflowing, the hot update is terminated, so that the running program can continue to run stably and improve system stability.

[0027] In some embodiments, the method further includes: if it is determined that the used storage space of the reserved variable list is less than a preset memory threshold, then using preset filling data to fill the remaining space of the reserved variable list.

[0028] This application embodiment automatically fills unused space in the reserved variable list with placeholder data, maintaining the layout regularity and stability of the reserved variable list, improving the stability of the data area structure, and thus improving the stability of hot updates.

[0029] Thirdly, embodiments of this application provide a program hot update system, which includes a host computer and a slave computer; wherein, the host computer is deployed with the data area structure of any embodiment of the first aspect, and the slave computer runs a real-time system; the host computer and the slave computer are connected in communication; the host computer is used to execute the method steps of any embodiment of the second aspect, and to send a new configuration file and a program to be hot-updated to the slave computer; the slave computer is used to perform hot updates on the real-time system based on the new configuration file and the program to be hot-updated.

[0030] Fourthly, embodiments of this application provide an electronic device, including: a processor and a memory, the memory storing machine-readable instructions executable by the processor, the machine-readable instructions being able to perform the method steps of any embodiment of the second aspect when executed by the processor.

[0031] Fifthly, embodiments of this application provide a computer-readable storage medium, including: computer program instructions stored on the computer-readable storage medium, wherein the computer program instructions are executed by a processor to perform the method steps of any embodiment of the second aspect.

[0032] In a sixth aspect, embodiments of this application provide a computer program product, including: computer program instructions, which are executed by a processor to perform the method steps of any embodiment of the second aspect.

[0033] Other features and advantages of this application will be set forth in the following description and will be apparent in part from the description or may be learned by practicing embodiments of this application. Attached Figure Description

[0034] To more clearly illustrate the technical solutions of the embodiments of this application, the accompanying drawings used in the embodiments of this application will be briefly introduced below. It should be understood that the following drawings only show some embodiments of this application and should not be regarded as a limitation of the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.

[0035] Figure 1 A schematic diagram of a data area structure provided in an embodiment of this application; Figure 2 A schematic diagram of a program hot update system provided in an embodiment of this application; Figure 3 A flowchart illustrating a program hot update method provided in an embodiment of this application; Figure 4 This is a schematic diagram of the electronic device structure provided in an embodiment of this application. Detailed Implementation

[0036] The embodiments of the technical solution of this application will now be described in detail with reference to the accompanying drawings. These embodiments are only used to more clearly illustrate the technical solution of this application and are therefore merely examples, and should not be used to limit the scope of protection of this application.

[0037] It should be noted that all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application pertains; the terminology used herein is for the purpose of describing particular embodiments only and is not intended to limit this application; the terms “comprising” and “having”, and any variations thereof, in the specification, claims, and foregoing description of the drawings are intended to cover non-exclusive inclusion.

[0038] In the description of the embodiments of this application, technical terms such as "first" and "second" are used only to distinguish different objects and should not be construed as indicating or implying relative importance or implicitly specifying the number, specific order, or primary and secondary relationship of the indicated technical features. In the description of the embodiments of this application, "multiple" means two or more, unless otherwise explicitly defined.

[0039] In the internet industry, it's often necessary to patch and update released programs to ensure system stability and user experience. Hot update technology is a commonly used update method. Hot update technology is a software upgrade technique that dynamically updates the code, resources, or configuration of an application without interrupting its normal service, making the updates take effect immediately.

[0040] Currently, common hot update technologies mainly include three categories: script-based hot update, dual-process hot update, and dynamic library replacement.

[0041] Script-based hot updates rely on interpreted languages ​​(such as Lua) to dynamically load logic. This hot update method is suitable for games or non-real-time business systems, but it cannot meet the requirements of hard real-time tasks for determinism and low latency.

[0042] Dual-process hot updates achieve a complete program update by starting a new process to replace the old one, and are commonly used in web services or general applications. However, because the update process involves process switching, resource migration, and state reconstruction, it is difficult to implement in a real-time multi-tasking, multi-priority scheduling environment, and may compromise time determinism.

[0043] Dynamic library replacement loads a new version of a dynamic link library (such as a .so file) at runtime to replace the original function implementation. While this can be used for function logic updates in real-time systems, when data changes, a completely new data area conforming to the new layout needs to be allocated, and the data in the old data area needs to be copied and converted to the new data area. If a new data area is not created, it is very easy for pointers to become dangling or point to illegal memory, or for memory areas shared with other processes (such as shared memory segments) to become invalid due to structural changes. Therefore, it cannot effectively handle hot updates of data areas.

[0044] In summary, in real-time systems, existing technologies cannot effectively handle hot updates of data areas, resulting in low stability of hot updates.

[0045] To address the aforementioned issues, this application provides a data area structure that divides the data area into a basic area and a reserved area. This allows for hot updates to be performed only on the reserved area, without altering variables in the basic area, and without requiring the reconstruction of the entire data area, thus improving the stability of hot updates.

[0046] Figure 1 This is a schematic diagram of a data area structure provided in an embodiment of this application, such as... Figure 1 As shown, the data area structure 10 includes a basic area 101 and a reserved area 102; wherein, the basic area 101 is used to store the original basic variables; the original basic variables are determined based on the program deployed for the first time; the reserved area 102 is used to dynamically store new variables that are different from the original basic variables and the historical variables already stored in the reserved area in the program to be hot-updated.

[0047] To support hot updates of data areas in real-time systems, this application designs a persistent data area structure whose lifecycle spans the initial deployment of the program and subsequent hot updates. This data area is logically divided into two parts: Basic Region 101: A fixed-size structure used to store the original basic variables defined when the program is first deployed and which need to be maintained during hot updates. These variables (such as serial numbers, device configurations, runtime counters, etc.) are the core state of the system, and their layout is determined at compile time.

[0048] Reserved area 102: Also known as the dynamic storage area, this is a contiguous block of memory used as a variable heap, specifically for dynamically storing newly introduced variables during hot updates. These variables did not exist in the old version of the program and were introduced by the hot update package.

[0049] When deploying the application for the first time, the persistent data area structure needs to be created and initialized in static memory or heap.

[0050] For the initialization of base region 101, the original base variables defined during the initial deployment and required to maintain their state during hot updates are stored in their corresponding locations within base region 101. Furthermore, the original base variables and their storage locations within base region 101 remain unchanged during the hot update process. This method avoids pointer invalidation in the running program, improving program stability. Moreover, since the data structure of base region 101 remains constant, and operations are only performed on reserved region 102, the system does not need to be shut down or data transferred during hot updates, meeting the requirements of hard real-time periodic tasks.

[0051] Initialization of reserved area 102: Each byte of reserved area 102 is filled with preset padding data, such as 0xFE. This ensures that the initial state of the entire data area is consistent and known. The preset padding data indicates that the corresponding slot in reserved area 102 is free and can be used to store new variables.

[0052] It should be noted that the memory size of the reserved area 102 can be adaptively set according to the actual situation. In one embodiment, the reserved area 102 is set to 128 bytes.

[0053] When a hot update is required, the new code after the hot update accesses the base region 101 through a fixed pointer or reference. Since the memory layout of the base region 101 is strictly compatible when compiling new and old versions, it can be read and written directly, and its state is preserved.

[0054] When the new code after a hot update includes a new variable, such as `new_config`, this new variable is stored at the end of reserved area 102. During the hot update, the value of this new variable is read by accessing its location within reserved area 102.

[0055] It should be noted that if the variables in the hot-updated program have undergone extensive changes, the hot-updated program will be redeployed as the first deployment program, and the data area structure will be reinitialized to avoid storing a large number of variables in the reserved area, causing the reserved area to overflow and resulting in hot update failure.

[0056] In this embodiment, the data area is divided into a basic area and a reserved area. The basic area stores the original basic variables in the program during its initial deployment, while the reserved area stores newly added variables. Since operations are only performed on the reserved area, the variables in the basic area are not modified, and there is no overall data area reconstruction, a hot update mechanism without copying or replacement of the data area is achieved, improving the stability of hot updates.

[0057] In some embodiments, the base area 101 and the reserved area 102 constitute a continuous data area, and the base area 101 and the reserved area 102 are separated by a special variable; the special variable is used to determine the storage address of the new variable when storing the new variable in the reserved area 102.

[0058] In the above implementation process, the basic region 101 and the reserved region 102 can be a continuous data area in static memory. In order to distinguish between the basic region 101 and the reserved region 102 and to correctly store new variables in the reserved region 102, a special variable is introduced at the end of the basic region 101 to separate the basic region 101 and the reserved region 102.

[0059] The special variable marks the end of the basic region 101 and the beginning of the reserved region 102. Therefore, this special variable can serve as the anchor point for the starting address of the reserved region 102, thereby determining the storage address of the new variable in the reserved region 102.

[0060] Specifically, the special variable serves as a fixed reference point for the reserved area 102. When a new variable needs to be stored in the reserved area 102, the system does not need to calculate the complex total size of the basic area 101. Instead, it can directly start from the end address of the special variable to perform subsequent alignment and allocation calculations, thereby efficiently and accurately determining the storage address of the new variable.

[0061] In one implementation, the special variable is typically set as a placeholder variable "Var__" of data type LREAL. The reason is that among all supported data types, LREAL (occupying 8 bytes) usually has the strictest alignment requirements (e.g., 8-byte alignment). Since 8 bytes is the maximum width of a data type, using it as a dividing anchor ensures that the variable itself and its ending address are located on a well-aligned boundary. Using the data type with the maximum width and alignment requirements as a benchmark establishes a unified and highly compatible foundation for memory management across the entire reserved area.

[0062] In this embodiment, the basic region and the reserved region are a continuous data area. To distinguish between the basic region and the reserved region, a special variable is set between them for separation, facilitating data access. Furthermore, the special variable serves as an alignment anchor point for the reserved region, making it easier to determine the storage address of new variables within the reserved region.

[0063] In some embodiments, the areas in the reserved area 102 where no variables are stored are filled with preset fill data.

[0064] This application embodiment automatically fills the unused space of the reserved area 102 with placeholder data, maintains the regularity and stability of the memory layout of the reserved area 102, improves the stability of the data area structure, and thus improves the stability of hot update.

[0065] In some embodiments, the new variable includes a data type; the operation logic for storing the new variable in the reserved area 102 is as follows: based on the data type, determine the number of bytes occupied by the new variable and the natural alignment requirement; obtain the current end address of the reserved area 102; calculate the target storage start address that meets the alignment requirement of the new variable according to the natural alignment requirement and the current end address; based on the target storage start address, write the new variable into the corresponding position in the reserved area 102 according to the number of bytes.

[0066] In the above implementation process, a data type is a collection of values ​​and a set of operations defined on that collection. It is used to classify data and standardize its storage method in memory and the operations that can be executed.

[0067] Common data types and their byte counts include: Boolean (BOOL, 1 byte), short integer (SINT, 1 byte), integer (INT, 2 bytes), double-word long integer (DINT, 4 bytes), long integer (LINT, 8 bytes), single-precision floating-point number (REAL, 4 bytes), and double-precision floating-point number (LREAL, 8 bytes).

[0068] Each variable has a corresponding data type, which determines the number of bytes the variable occupies during storage and the natural alignment requirements.

[0069] Natural alignment requirements refer to the constraints that the starting memory address of a specific data type must satisfy when stored within the context of computer memory access. This condition stipulates that the starting memory address of a variable of this type must be an integer multiple of the alignment modulus determined by the data width (in bytes) of its data type. The data width refers to the number of consecutive bytes required to store an instance of this type.

[0070] For example, data types with a 1-byte data width (such as BOOL, SINT) have a natural alignment requirement of 1 byte, meaning their starting address can be any value.

[0071] Data types with a 2-byte data width (such as INT) have a natural alignment requirement of 2 bytes, meaning their starting address must be a multiple of 2.

[0072] Data types with a 4-byte data width (such as DINT, REAL) have a natural alignment requirement of 4 bytes, meaning their starting address must be a multiple of 4.

[0073] Data types with an 8-byte data width (such as LINT, LREAL) have a natural alignment requirement of 8 bytes, meaning their starting address must be a multiple of 8.

[0074] To help you understand how to store new variables in the reserved area, here is an example: Scenario: The memory address ending in the currently reserved region 102 is 0x0002. A new variable of type LREAL (8 bytes, requiring 8-byte alignment) needs to be written to it. The alignment calculation logic is as follows: The current end address of the reserved area is 0x0002.

[0075] The alignment requirement for the new variable LREAL is 8 bytes.

[0076] Since 0x0002 is not a multiple of 8, the next aligned address needs to be calculated: (0x0002+(8-1))&~(8-1)=(0x0009)&~(0x0007)=0x0008.

[0077] The required padding is calculated as follows: 0x0008 - 0x0002 = 6 bytes.

[0078] Starting from 0x0002, write 6 bytes of padding (e.g., Var__) sequentially, and update the current end address to 0x0008.

[0079] At this point, the new variable is written into the 8 bytes starting from 0x0008.

[0080] For example: Step 1: Place INT; The current end address of the reserved area is 0x0000; INT requires 2-byte alignment. 0x0000%2=0, which meets the requirement; Operation: Directly place INT; The current end address of the reserved area after occupation: 0x0000 + 2 = 0x0002; Memory layout: [INT][INT].

[0081] Step 2: Place LREAL; The current end address of the reserved area is 0x0002; LREAL requires 8-byte alignment. 0x0002%8=2, which does not meet the requirement; Operation: Padding is required until the next 8-byte aligned address 0x0008. The number of bytes to pad = 0x0008 - 0x0002 = 6 bytes. These 6 bytes are padded using the Var__ delimiter. The current end address of the reserved area after filling is 0x0008; Operation: Place LREAL; Address after being occupied: 0x0008 + 8 = 0x0010; Memory layout: [INT][INT][Pad][Pad][Pad][Pad][Pad][Pad][LREAL][LREAL][LREAL][LREAL][LREAL][LREAL][LREAL][LREAL][LREAL]; where [Pad] represents bytes filled with Var__.

[0082] Step 3: Place the SINT; The current end address of the reserved area is 0x0010; SINT requires 1-byte alignment. 0x0010%1=0, which meets the requirement; Operation: Place SINT directly; The current end address of the reserved area after occupation: 0x0010 + 1 = 0x0011; Memory layout: ... (preceding LREAL) [SINT].

[0083] This application embodiment determines the number of bytes to be occupied and the natural alignment requirements based on the data type of the new variable, and then writes it to the corresponding position in the reserved area according to the number of bytes and the natural alignment requirements. Since this storage method conforms to the CPU's data access reading method, it improves the CPU's access speed and access stability, thereby improving the efficiency and stability of hot updates.

[0084] Figure 2 This is a schematic diagram of a program hot update system provided in an embodiment of this application, as shown below. Figure 2 As shown, the system 20 includes a host computer 201 and a slave computer 202; wherein, the host computer 201 is deployed with the data area structure of any of the above-described data area structure embodiments, and the slave computer 202 runs a real-time system; the host computer 201 and the slave computer 202 are communicatively connected; the host computer 201 is used to execute the method steps of any of the following program hot update method embodiments, and to send a new configuration file and a program to be hot-updated to the slave computer 202; the slave computer 202 is used to perform a hot update on the real-time system based on the new configuration file and the program to be hot-updated.

[0085] Figure 3 This application provides a flowchart illustrating a program hot update method, which runs on a host computer. Figure 3 As shown, the method includes: Step S301: Read the initial configuration file and the program to be hot-updated; wherein, the initial configuration file includes the original basic variable list and the initial reserved variable list; the program to be hot-updated includes the current variable set.

[0086] The initial configuration file is used to describe the data layout of the current data area structure.

[0087] It should be noted that when deploying the relevant programs of the real-time system on the lower-level machine for the first time, the initial configuration file describes the initial data layout of the data area structure.

[0088] The initial configuration file includes a list of original basic variables and a list of initial reserved variables. The list of original basic variables characterizes the data in the basic regions of the data area structure, while the list of initial reserved variables characterizes the data in the reserved regions of the data area structure. During real-time system initialization, the list of initial reserved variables is populated with pre-set data.

[0089] For example, the structure of the initial configuration file is as follows: { "POU name / structure name / Global":{ "base":{ / / List of original basic variables "varList":[ {"varname":"var1","type":"DINT"}, {"varname":"var2","type":"DINT"},...] }, / / Initial list of reserved variables "placeholder":{ "usedVarList":[ {"varname":"new_var3","type":"DINT"}, {"varname":"new_var4","type":"DINT"},...], "capacity":128 / / Reserved space capacity } } } Hot-updateable programs refer to software components, code modules, data configuration files, or functional units that are designed to accept dynamic updates during the continuous operation of the target system.

[0090] In the above implementation process, the user writes the initial configuration file and the initial deployment program of the real-time system on the host computer, and sends them to the slave computer for real-time system initialization. After initialization, the initial configuration file is saved on the slave computer.

[0091] When a hot update is needed for the first time, the user writes the program to be hot-updated on the host computer and reads the initial configuration file from the slave computer. The host computer parses the program to be hot-updated and the initial configuration file to obtain the original list of basic variables, the initial list of reserved variables, and the current set of variables.

[0092] Step S302: If it is determined that there is a new variable in the current variable set that is not included in the original basic variable list or the initial reserved variable list, then the initial reserved variable list is updated based on the new variable to generate a reserved variable list.

[0093] Step S303: Based on the reserved variable list, update the initial configuration file to generate a new configuration file, which is used to perform hot updates on the program to be hot-updated.

[0094] In the above implementation process, the host computer traverses the original basic variable list, the initial reserved variable list, and the current variable set obtained by parsing. If it is determined that there is a new variable in the current variable set that is not included in the original basic variable list or the initial reserved variable list, the new variable is stored in the initial reserved variable list to generate the reserved variable list.

[0095] For the hot update process to execute correctly, a new configuration file needs to be generated based on the newly generated list of reserved variables and the original list of basic variables.

[0096] Subsequently, the host computer sends the new configuration file and the hot update program to the slave computer. The slave computer saves the received new configuration file and runs the hot update program to perform the hot update process based on the variables defined in the new configuration file.

[0097] The specific hot update process performed by the lower-level machine is as follows: The lower-level machine listens for and loads the new version of the function library (the program to be hot-updated) through a preset long-cycle thread, and caches the new function pointer of the new version of the function library; after the current real-time cycle is completed, the global function pointer is pointed to the new function pointer; at the beginning of the next real-time cycle, the new function pointer is called to execute the control logic in the new version of the function library and perform hot update.

[0098] It should be noted that if this is not the first hot update, the initial configuration file read is the new configuration file generated after the last hot update.

[0099] In this embodiment, the initial configuration file includes an original list of basic variables and an initial list of reserved variables, while the program to be hot-updated includes the current set of variables. If it is determined that there are new variables in the current set that are not included in either the original list of basic variables or the initial list of reserved variables, it indicates that there are new variables in the program to be hot-updated that were not previously present. To ensure the normal execution of the program to be hot-updated, these new variables need to be stored first, so that the program can correctly read the corresponding variable data during execution.

[0100] To avoid pointer invalidation in the running program due to operations on the original base variables, the new variable is stored in the initial reserved variable list, thus forming a new configuration file for hot updates. Since operations are only performed on the reserved area, without changing variables in the base area or rebuilding the entire data area, a hot update mechanism without copying or replacing the data area is achieved, improving the stability of hot updates.

[0101] In some embodiments, the new variable includes a data type; updating the initial reserved variable list based on the new variable to generate a reserved variable list includes: determining the number of bytes occupied by the new variable and the natural alignment requirement based on the data type; obtaining the current end address of the initial reserved variable list; calculating the target storage start address that meets the alignment requirement of the new variable according to the natural alignment requirement and the current end address; and writing the new variable into the corresponding position of the initial reserved variable list according to the number of bytes based on the target storage start address to generate the reserved variable list.

[0102] For the process of writing the new variable to the corresponding position in the initial reserved variable list, please refer to the above-described "Operation Logic for Storing New Variables in the Reserved Area" example, which will not be repeated here.

[0103] This application embodiment determines the number of bytes to be occupied and the natural alignment requirements based on the data type of the new variable, and then writes it to the corresponding position in the initial reserved variable list according to the number of bytes and the natural alignment requirements. Since this storage method conforms to the CPU's data access reading method, it improves the CPU's access speed and access stability, thereby improving the efficiency and stability of hot updates.

[0104] In some embodiments, updating the initial reserved variable list based on the new variables to generate a reserved variable list includes: if it is determined that there are historical variables in the initial reserved variable list that are not included in the current variable set, then the historical variables are deleted to obtain a basic reserved variable list; and updating the basic reserved variable list based on the new variables to generate a reserved variable list.

[0105] As can be seen from the above embodiments, the size of the reserved area is a pre-set fixed value. Although this method prevents variables in both the basic area and the reserved area from being overwritten, reducing the risk of crashes due to pointers, frequent hot updates can quickly fill the reserved area if many new variables are added. This prevents the new variables from being saved in the next hot update, causing the next hot update to fail.

[0106] Therefore, in order to make reasonable use of the memory space in the reserved area, variables that existed in the last hot update but do not exist in the current hot update are deleted, thereby freeing up the space in the reserved area.

[0107] For example, if the initial reserved variable list includes ABCDE, and the current variable set of the program to be hot-updated includes BCDEF, then "A" is in the initial reserved variable list but not in the current variable set. Therefore, "A" needs to be deleted. Additionally, "F" is a new variable and needs to be added to the initial reserved variable list.

[0108] This application embodiment releases reserved slots by deleting historical variables that meet the requirements from the initial reserved variable list, allowing the reserved variable list to be used cyclically and improving the memory utilization of the reserved area.

[0109] In some embodiments, the new variable includes a data type; updating the basic reserved variable list based on the new variable to generate a reserved variable list includes: if it is determined that the data types of the new variable and the historical variable are the same, then the new variable is written into the position of the historical variable to update the basic reserved variable list and generate a reserved variable list.

[0110] In the above implementation process, if the data type of the new variable in the program to be hot-updated is the same as the data type of the deleted historical variable, the new variable is directly stored in the storage location of the deleted historical variable.

[0111] In one implementation, if the data type of the new variable in the program to be hot-updated is different from the data type of the deleted historical variable, the new variable is written to the corresponding position in the reserved variable list based on the above-mentioned "operation logic of storing new variables in reserved areas".

[0112] In one implementation, after generating the reserved variable list, a memory compression process is performed on the reserved area to move the allocated variables in the reserved memory area to the lower memory address to merge fragmented free memory blocks and form a continuous free space.

[0113] In this embodiment, if it is determined that the data type of the new variable is the same as the data type of the deleted historical variable, the new variable is stored in the location of the deleted historical variable. This not only improves the memory utilization of the reserved area, but also meets the natural alignment requirements of data storage, improves access stability, and thus improves the stability of hot updates.

[0114] In some embodiments, if it is determined that there is a new variable in the current variable set that is not included in the original basic variable list and the initial reserved variable list, then the initial reserved variable list is updated based on the new variable to generate the reserved variable list. The method further includes: if it is determined that the used storage space of the reserved variable list is greater than a preset memory threshold, then the current hot update process is terminated.

[0115] In the above implementation process, considering that the reserved area is only a dynamic auxiliary area for the basic area, its memory size should be smaller than the memory size of the basic area.

[0116] Therefore, after multiple hot updates, there may be a situation where the reserved area memory overflows. If it is determined that the used storage space of the reserved variable list is greater than the preset memory threshold, the hot update process should be terminated. That is, the host computer should not send the new configuration file and the program to be hot updated to the slave computer, so that the slave computer can still run the existing program normally.

[0117] To ensure the system can be optimized properly, the optimized system can be redeployed as a whole.

[0118] In this embodiment of the application, if the used storage space of the reserved variable list is greater than the preset memory threshold after adding a new variable, indicating that the memory space of the reserved area is overflowing, the hot update is terminated, so that the running program can continue to run stably and improve system stability.

[0119] In some embodiments, the method further includes: if it is determined that the used storage space of the reserved variable list is less than a preset memory threshold, then using preset filling data to fill the remaining space of the reserved variable list.

[0120] This application embodiment automatically fills unused space in the reserved variable list with placeholder data, maintaining the layout regularity and stability of the reserved variable list, improving the stability of the data area structure, and thus improving the stability of hot updates.

[0121] To further understand the above-described hot update process, a flowchart for hot updates of a real-time system is presented. Hot updates of a real-time system include data area hot updates and function updates.

[0122] The process of hot updating the data area by the host computer is as follows: (1) Load the initial configuration file and read its contents into the following list: baseVarList: The original list of basic variables; usedHolderVarList: Initial list of reserved variables (the list of currently used reserved variables).

[0123] (2) Read the program to be hot-updated and cache the variables in the program to be hot-updated in the current variable collection tempVarDict. The key of this collection is the variable name and the value is the content, for example: {"var1":{"varname":"var1","type":"DINT"}}.

[0124] (3) Retain unchanged variables: Traverse the current variable set tempVarDict, the original base variable list baseVarList, and the initial reserved variable list usedHolderVarList; if a variable in the current variable set tempVarDict is already in the original base variable list baseVarList or the initial reserved variable list usedHolderVarList, then do not operate on the variable and keep its position unchanged.

[0125] (4) Handling new variables: Iterate through the current variable set tempVarDict, the original base variable list baseVarList, and the initial reserved variable list usedHolderVarList; if there is a new variable in the current variable set tempVarDict that is not included in either the original base variable list baseVarList or the initial reserved variable list usedHolderVarList, then write the new variable into the initial reserved variable list usedHolderVarList to update it. For the specific writing method, please refer to the above embodiment of "Operation Logic for Storing New Variables in the Reserved Area", which will not be repeated here.

[0126] (5) Determine whether to suspend hot update: Determine the relationship between the used storage space of the newly generated reserved variable list and the preset memory threshold MaxHolderSize (which can be set to 128 bytes).

[0127] If the used storage space of the reserved variable list is determined to be greater than the preset memory threshold, the hot update process will be terminated. For example, programs to be hot-updated, such as the latest version of the function library libpou3.so, will not be distributed.

[0128] If it is determined that the used storage space of the reserved variable list is less than the preset memory threshold, then the remaining space of the reserved variable list is filled with preset fill data.

[0129] (6) Update configuration file: Generate a new configuration file based on the newly generated list of reserved variables. In the new configuration file, the original basic variable list remains unchanged.

[0130] The process of hot updating functions executed by the lower-level machine is as follows: (1) Use dynamic link libraries (such as libpouX.so) to manage function logic.

[0131] (2) A long-cycle thread is responsible for detecting whether there are programs waiting to be hot-updated, such as the higher version of the function library libpou3.so, which is currently running libpou2.so.

[0132] (3) Real-time cycle threads and long-cycle threads interact through a global function pointer shared between threads: If the long-cycle thread detects the existence of a new version of the function library, it caches the pointer of the new version of the function library. After the current real-time cycle ends, at the beginning of the next cycle, the real-time cycle thread will replace the main function pointer, then call the new function pointer, execute the control logic in the new version of the function library, and perform hot update.

[0133] In summary, the beneficial effects of this application are as follows: (1) Zero copy, zero replacement: avoids rebuilding the entire data area and improves the efficiency of hot update.

[0134] (2) Address stability: The address of all variables (including newly added ones) remains unchanged during their lifetime, which is convenient for pointer reference.

[0135] (3) Strong compatibility: The pure software layer method is applicable to various program units such as structures, function blocks, and global variables.

[0136] (4) Real-time performance: Function and data updates are separated, and function switching is completed at the cycle boundary to ensure real-time performance.

[0137] Figure 4 This is a schematic diagram of the electronic device structure provided in the embodiments of this application, such as... Figure 4 As shown, the electronic device includes a processor 401, a memory 402, and a bus 403; wherein the processor 401 and the memory 402 communicate with each other via the bus 403. The processor 401 is used to call program instructions in the memory 402 to execute the methods provided in the above-described method embodiments.

[0138] Processor 401 can be an integrated circuit chip with signal processing capabilities. The processor 401 can be a general-purpose processor, including a Central Processing Unit (CPU), a Network Processor (NP), etc.; it can also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field Programmable Gate Array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. It can implement or execute the various methods, steps, and logic block diagrams disclosed in the embodiments of this application. The general-purpose processor can be a microprocessor or any conventional processor.

[0139] The memory 402 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as Static Random Access Memory (SRAM), Electrically Erasable Programmable Read-Only Memory (EEPROM), Erasable Programmable Read Only Memory (EPROM), Programmable Red-Only Memory (PROM), Read-Only Memory (ROM), magnetic storage, flash memory, magnetic disk, or optical disk.

[0140] This application provides a computer program product, including: computer program instructions, which are executed by a processor to perform the methods provided in the above-described method embodiments.

[0141] This application provides a computer-readable storage medium, including: computer program instructions stored on the computer-readable storage medium, which, when executed by a processor, perform the methods provided in the above-described method embodiments.

[0142] Computer-readable storage media can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as Static Random Access Memory (SRAM), Electrically Erasable Programmable Read-Only Memory (EEPROM), Erasable Programmable Read Only Memory (EPROM), Programmable Red-Only Memory (PROM), Read-Only Memory (ROM), magnetic storage, flash memory, magnetic disk, or optical disk.

[0143] In the embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. The apparatus embodiments described above are merely illustrative. For example, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. Furthermore, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Additionally, the displayed or discussed mutual couplings, direct couplings, or communication connections may be through some communication interfaces; indirect couplings or communication connections between devices or units may be electrical, mechanical, or other forms.

[0144] Furthermore, the units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0145] Furthermore, the functional modules in the various embodiments of this application can be integrated together to form an independent part, or each module can exist independently, or two or more modules can be integrated to form an independent part.

[0146] The above description is merely an embodiment of this application and is not intended to limit the scope of protection of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of protection of this application.

Claims

1. A data area structure, characterized in that, The data area structure includes a basic area and a reserved area; The basic area is used to store the original basic variables; the original basic variables are determined based on the program deployed for the first time. The reserved area is used to dynamically store new variables that are different from the original basic variables and the historical variables already stored in the reserved area, which are to be updated in the program.

2. The data area structure according to claim 1, characterized in that, in, The original base variables and their storage location in the base region remain unchanged during the hot update process.

3. The data area structure according to any one of claims 1-2, characterized in that, in, The basic region and the reserved region constitute a continuous data area, and the basic region and the reserved region are separated by a special variable; The special variable is used to determine the storage address of the new variable when storing it in the reserved area.

4. A method for hot updating a program, characterized in that, The method includes: Read the initial configuration file and the program to be hot-updated; wherein, the initial configuration file includes the original basic variable list and the initial reserved variable list; the program to be hot-updated includes the current variable set; If it is determined that there is a new variable in the current variable set that is not included in the original basic variable list and the initial reserved variable list, then the initial reserved variable list is updated based on the new variable to generate a reserved variable list; Based on the reserved variable list, the initial configuration file is updated to generate a new configuration file; wherein, the new configuration file is used to perform a hot update on the program to be hot-updated.

5. The method according to claim 4, characterized in that, in, The new variables include data types; updating the initial reserved variable list based on the new variables to generate a new reserved variable list includes: Based on the data type, determine the number of bytes occupied by the new variable and the natural alignment requirements; Obtain the current end address of the initial reserved variable list; Based on the natural alignment requirements and the current end address, calculate the target storage start address that satisfies the new variable alignment requirements; Based on the target storage starting address, the new variable is written into the corresponding position of the initial reserved variable list according to the number of bytes, thereby generating the reserved variable list.

6. The method according to claim 4, characterized in that, The step of updating the initial reserved variable list based on the new variable to generate a new reserved variable list includes: If it is determined that there are historical variables in the initial reserved variable list that are not included in the current variable set, then the historical variables are deleted to obtain the basic reserved variable list; The basic reserved variable list is updated based on the new variable to generate the reserved variable list.

7. The method according to claim 6, characterized in that, in, The new variables include data types; updating the basic reserved variable list based on the new variables to generate the reserved variable list includes: If it is determined that the new variable and the historical variable have the same data type, the new variable is written to the position of the historical variable to update the basic reserved variable list and generate the reserved variable list.

8. The method according to any one of claims 4-7, characterized in that, If it is determined that there exists a new variable in the current variable set that is not included in either the original basic variable list or the initial reserved variable list, then the initial reserved variable list is updated based on the new variable to generate a reserved variable list. The method further includes: If the used storage space of the reserved variable list is determined to be greater than the preset memory threshold, the hot update process will be terminated.

9. The method according to claim 8, characterized in that, The method further includes: If it is determined that the used storage space of the reserved variable list is less than the preset memory threshold, then the remaining space of the reserved variable list is filled with preset fill data.

10. A program hot update system, characterized in that, The system includes a host computer and a slave computer; The host computer is equipped with the data area structure described in any one of claims 1-3, and the slave computer runs a real-time system; the host computer and the slave computer are connected in communication. The host computer is used to execute the method described in any one of claims 4-9, and to send a new configuration file and a hot-update program to the slave computer. The lower-level machine is used to perform hot updates on the real-time system based on the new configuration file and the program to be hot-updated.