Data interaction method of embedded virtualization platform based on shared memory
By dividing shared memory areas in the embedded virtualization platform and using the Szymanski algorithm to achieve mutually exclusive access control, the problem of out-of-control shared memory management in multi-core heterogeneous mode is solved, and the system performance and data interaction stability is improved.
Patent Information
- Application Number
- CN202411706321.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-26
- Publication Date
- 2025-03-07
AI Technical Summary
In the multi-core heterogeneous mode, shared memory management lacks effective management, resulting in out of control of access, and the traditional hard-coded method introduces strong coupling relationships, which is not conducive to system maintenance and expansion.
By dividing the shared memory area into a management information area and a shared data area, initializing the management information area, using the Szymanski algorithm to achieve mutually exclusive access control, and coordinating data exchange between cores, optimizing the application and release of shared memory resources.
Improve system performance, reduce coupling, ensure efficient and stable data interaction, and reduce the risk of memory fragmentation and access out of control.
Smart Images

Figure CN119576607A_ABST
Abstract
Description
Technical Field
[0001] The invention relates to the field of shared memory data interaction, and in particular to a shared memory-based data interaction method for an embedded virtualization platform. Background Art
[0002] In today's technological environment, with the increasing demand for computer system performance and the continuous advancement of hardware technology, multi-core processors are increasingly used in various devices, and the embedded system field is no exception. Multi-core processors integrate multiple processor cores into one chip, which significantly increases the computing resources of the system. For example, in the server field, multi-core processors have become the mainstream configuration, from the common 4-core processor to products with more cores, such as SUN's UltraSPARC T2 processor with 8 cores and Tilera TILE64 processor with 64 cores. In the general x86 multi-core market, AMD's multi-core products are also developing, with the number of processor cores increasing, and the number of processing units available to the operating system on a single node continues to rise.
[0003] In embedded systems, multi-core processors usually work in multi-core heterogeneous mode. In this mode, computing cores are grouped, and different groups run different types of functions. For example, some operating areas run real-time operating systems or bare metal programs to meet functions with high real-time requirements (such as sampling, interpolation, protection logic, etc.), while other operating areas can run non-real-time operating systems (such as Linux) to handle functions with low real-time requirements (such as network communication, interface display, five-protection logic, etc.). Each operating area is highly isolated, including peripherals, operating memory, and data memory, which are all independent of each other. Although this improves the reliability of system operation, it also brings data interaction problems between operating areas.
[0004] The importance of virtualization technology in the computer field is becoming increasingly prominent. Its essence lies in the division and abstraction of software and hardware resources. Introducing virtualization technology in embedded systems can improve development and testing efficiency, save hardware investment costs, and reduce problems caused by hardware failures. For example, through virtualized devices, R&D and testing personnel can debug and test product business functions under restricted conditions, decoupling upper-level application development from hardware. However, virtualization technology in current embedded systems still faces many challenges in data interaction.
[0005] In the data interaction based on shared memory, the traditional method has many shortcomings. For example, in the virtual system represented by Xen, although there are certain methods (such as XenSocket, XenLoop, etc.) for communication between virtual machines based on shared memory, there are still performance overhead issues, such as multiple memory copies and high switching overhead between virtual machines, as well as factors that affect communication performance such as page reversal and control information transmission. At the same time, in terms of shared memory management in multi-core heterogeneous mode, if the use of shared memory by each operating area lacks effective management, it is easy to cause access out of control, and the traditional hard-coding method will introduce a strong coupling relationship, which is not conducive to system maintenance and expansion. Therefore, there is an urgent need for an optimized data interaction method based on shared memory for embedded virtualization platforms to improve system performance, reduce coupling, and ensure the efficiency and stability of data interaction. Summary of the invention
[0006] The main purpose of the present invention is to provide a data interaction method based on shared memory for an embedded virtualization platform, so as to solve the problem that in the shared memory management under the multi-core heterogeneous mode, if the use of shared memory by each operating area lacks effective management, it is easy to cause access out of control, and the traditional hard coding method will introduce a strong coupling relationship, which is not conducive to system maintenance and expansion.
[0007] In order to solve the above technical problems, the technical solution adopted by the present invention is: a data interaction method based on shared memory of an embedded virtualization platform, the method comprising: S1. Divide the shared memory area into a management information area and a shared data area, initialize the management information area, including setting a magic number, configuring a mutually exclusive access flag, and recording usage information of the shared data area; S2. Get the physical start address of the shared memory, verify the availability of the management information area, and ensure that it has been correctly initialized; S3. Select the appropriate data transmission method according to the data size. Small data can be directly transmitted through the inter-core communication register, while large data can be transmitted using shared memory. If you need to apply for shared memory resources, first check the legality of the application, then allocate resources and record relevant information in the management information area; The sender writes data to a specific area of shared memory, and the receiver then reads the data from that area; S4, use Szymanski algorithm to implement mutual exclusive access control to ensure data consistency; Implement synchronization mechanisms based on specific needs, and use inter-core interrupts to coordinate data exchange between different operating areas; S5. After the data interaction is completed, if the shared memory resources are no longer needed, they should be released and the usage information in the management information area should be updated; Notify other related runtime areas or virtual machines as needed to inform them of the status changes of data interaction.
[0008] In the preferred embodiment, the specific steps in step S1 are: S11, in the multi-core processor, a dedicated memory is allocated as a shared memory, and the dedicated memory is divided into a management information area and a shared data area, wherein the management information area is located at the head of the shared memory and contains management information of the shared memory, and the shared data area is used for data interaction among the operation areas; S12, when the main core initializes the management information area of the shared memory, it first clears the magic number to zero, and writes the correct magic number after completing the formal initialization. Other operation areas determine whether the management information area is available by judging whether the magic number is correct; S13. The management information area includes the current remaining free space information and usage status of the shared data area, so as to facilitate the application and allocation of new shared data area resources.
[0009] In the preferred embodiment, the specific steps of steps S11-S13 are: S11.1. A dedicated memory is allocated in the multi-core processor as shared memory, and is divided into a management information area and a shared data area. The management information area is located at the head of the shared memory. In addition to the magic number, the exclusive access flag, the current remaining free information and the usage status of the shared data area in the prior art, the management information area also adds an additional memory block status array. , used to record the status of each memory block in the shared data area; suppose the total size of the shared memory is , the size of the management information area is , then the size of the shared data area is ; Initially divide the shared data area into memory blocks of equal size. memory blocks, each memory block size is ; Memory block status array The length is , initially all element values are 0, indicating that all memory blocks are idle; S12.1: Management information area initialization optimization: When the main core initializes the shared memory management information area, it first clears the magic number to zero, writes the correct magic number after the formal initialization is completed, and initializes the memory block status array at the same time , set all elements to a specific value indicating idleness, and set the exclusive access flag, using the Szymanski algorithm; Other operation areas determine whether the management information area is available by judging whether the magic number is correct. Only when the magic number is correct and the memory block status array After the integrity check is passed, the management information area is considered to be initialized and subsequent operations can be performed; the checksum formula is: ,in and are two pre-selected large prime numbers; the function of this formula is to set the memory block status array Generate a unique checksum value for verification in other operating areas To ensure data integrity and prevent data inconsistency caused by memory errors or malicious tampering; S13.1: Optimization of shared data area resource application allocation: When the operation area has a shared data area resource application demand, first wait to enter the critical area according to the existing technology; After entering the critical area, check the current remaining free information in the shared data area and find the continuous free memory blocks that meet the application size requirements; set The memory size requested is , from the memory block status array Start looking for consecutive elements with value 0, such that ; If a continuous free memory block that meets the conditions is found, it will be allocated; when allocating a memory block, not only the usage record of the shared data area in the management information area should be updated, but also the memory block status array should be updated , set the corresponding element value to a specific value indicating that it has been allocated; the calculation formula for the starting offset of the allocated memory block is: , that is, find the minimum starting offset position that meets the conditions; this formula ensures that when there are enough continuous free memory blocks, the front position is selected for allocation, which is conducive to reducing memory fragmentation; If no continuous free memory blocks that meet the conditions are found, memory defragmentation is performed according to a certain memory defragmentation strategy; the memory defragmentation strategy is as follows: Calculate the current memory fragmentation level , the formula is: , among which When , it indicates that there is a change in the memory block status; The larger the value, the higher the degree of memory fragmentation; if Exceeding a pre-set threshold , the memory defragmentation process is started; the memory defragmentation process includes moving the allocated memory blocks to one end of the memory area, merging adjacent free memory blocks, and updating the memory block status array. and the remaining free information of the shared data area; the process of moving the allocated memory blocks can adopt a bubble sort-like idea, starting from one end of the memory area, and moving the allocated memory blocks one by one to the target end, each time moving a memory block size ; When the running area completes data interaction and needs to release shared memory resources, it also needs to enter the critical area; According to the record information of the released memory resources, calculate the corresponding memory block in the memory block status array The position range in the memory block state array is calculated, and the element values of these positions are reset to specific values indicating free space, and the remaining free space information of the shared data area in the management information area is updated; The starting position formula in is: , the ending position formula is: ,in To release the starting offset of the memory block, To release the size of the memory block, is the size of a single memory block; these formulas accurately locate the position of the memory block that needs to be updated in the array, ensuring the correctness of the memory release operation.
[0010] In the preferred embodiment, the specific steps of step S2 are: S21, each operating area first attempts to obtain the initial value of the shared memory physical start address from the predefined system configuration table ;The system configuration table is partially filled by the main core during initialization, and contains some basic configuration information related to shared memory, but the address may not be completely accurate at this time; Calculate address checksum , where the check function The calculation formula is: ,here Indicates the address, is the address byte length, and is a pre-selected large prime number; the function of this formula is to generate a unique check value for the address, which is used to preliminarily verify the correctness of the address; If the check value If it does not match the predefined check value range, the address search and correction process is initiated; S22, the running area sends an address query request to the main core. After receiving the request, the main core traverses the system memory mapping table, finds the area marked as shared memory, and obtains its accurate physical starting address ; The main core will accurately start at the physical address and the new checksum Send back to the requested runtime; The runtime recalculates the received address If the check value is the same as the received check value If the address matches, it is confirmed that the correct shared memory physical start address is obtained; otherwise, the above query request process is repeated until the correct address is obtained; S23, when waiting for the magic number of the management information area to be correctly judged, each operation area does not simply poll and wait, but adopts a monitoring mechanism based on event triggering; the operation area creates a monitoring thread, which is bound to the hardware interrupt or memory address change event related to the magic number of the management information area; When the listening thread detects a write operation at the memory address where the magic number is located, it immediately obtains the value of the magic number. ; Calculate dynamic checksum of magic number , where the check function The calculation formula is: ,here Represents the magic number, is the magic number byte length, and is a large prime number selected separately; this formula is used to dynamically verify the correctness of the magic number at runtime to prevent the magic number from being tampered with without being discovered due to memory errors and other reasons; If the dynamic check value If the magic number does not match the predefined correct magic number check value and the magic number is not updated to the correct value again within a certain period of time, it is considered that an error may have occurred, the error information is recorded, and an attempt is made to reinitialize the shared memory related configuration; If the dynamic checksum value of the magic number If the predefined magic number check value matches, the operation area enters the first stage of confirmation; in the first stage of confirmation, the operation area waits for a short time interval , get the magic number again and recalculate the checksum for verification; this is to prevent misjudgment when the magic number has just been written but is not yet completely stable; If the checksum is still correct in the first phase of confirmation, the operation area enters the second phase of confirmation. In the second phase of confirmation, the operation area sends a magic number confirmation request to the main core. After receiving the request, the main core checks the integrity of the management information area and returns the confirmation result. Among them, the integrity check of the management information area including magic number, exclusive access flag, shared data area usage information, etc. can be checked. The integrity check can be similar to the checksum calculation method mentioned above, and all relevant information in the management information area is regarded as a byte array for calculation; If the confirmation result returned by the main core indicates that the management information area is complete and correct, the operating area finally determines that the management information area is available and can perform subsequent data interaction operations; otherwise, the operating area attempts to perform corresponding repair operations or report the error to the system administrator based on the error information returned by the main core.
[0011] In the preferred embodiment, the specific steps of step S3 are: S31. In some implementations, if the message transfer size is within 3 or 3 bytes, the inter-core communication register can be used to transmit data. By adding a system call to the operating system, the corresponding transmission mode is selected after the message size is determined. If the inter-core register communication is used, the inter-core communication module interface in the VMM is called; if the message content size is greater than 3 bytes, the shared memory is usually used to transmit data, and the communication interface in the shared memory module is called for data transmission. The shared memory module includes a linked list of allocated and unallocated shared memory blocks, a spin lock, and a synchronization module based on inter-core interrupts, which is used to manage shared memory access; S32, if shared memory is used to transmit data and shared memory resources need to be applied for, wait to enter the key area, check whether there are enough shared data resources, whether the application name is unique and other legal conditions, if the application is legal, allocate shared memory resources, and record the relevant information of the application in the management information area; S33. The sender writes the data into the specified area of the shared memory, and the receiver reads the data from the corresponding area. In the inter-virtual machine communication method based on the combination of inter-core interrupts and shared memory, the inter-virtual machine communication module is responsible for the data writing and reading operations, which are implemented through the interrupt processing module and the communication interface provided to the application, and are transparent to the application.
[0012] In the preferred embodiment, the specific steps of steps S31-S33 are: S31.1. Message size determination and transmission mode decision: When data needs to be transmitted, the size of the message is first calculated. , in bytes; suppose the message data is stored in array In , the message size calculation formula is: ,in For array The length of the message is determined by counting the number of non-zero elements in the array. if , then the inter-core communication register transmission mode is selected; at this time, the operating system triggers the inter-core communication module through a system call, and the message data is directly copied to the inter-core communication register during the system call; let the inter-core communication register be , the copy operation can be expressed as: ,in The value range is arrive ; if , then select the shared memory transmission mode and prepare to apply for shared memory resources; Calculate the minimum contiguous memory block size required for this data transfer ; Assume the shared memory block size is , calculated as: ,in Represents the round-up function; this formula ensures that the requested memory block is large enough to accommodate the message data and is an integer multiple of the memory block size, which is beneficial to memory management; Check the unallocated shared memory block list in the shared memory module and count the total size of consecutive free memory blocks in the list. ; Traverse the linked list, assuming that the linked list nodes represent memory blocks, and the fields in the nodes Indicates the memory block size, Point to the next node, calculated as: ,in is the number of consecutive free memory blocks in the linked list. When it is $null$, it indicates the end of the linked list; if , it means that the current free memory is insufficient and it is necessary to defragment the memory or wait for other running areas to release memory; the memory defragmentation process is as follows: Calculating memory fragmentation , the formula is: ,in is the memory block status array, is the total number of memory blocks; this formula measures the degree of memory fragmentation, and the larger the value, the more severe the fragmentation; if Exceeding a pre-set threshold , the memory defragmentation process is started; the allocated memory blocks are moved to one end of the memory area, adjacent free memory blocks are merged, and the memory block status array is updated and the linked list of unallocated shared memory blocks; the process of moving the allocated memory blocks can adopt the idea of merge operation similar to merge sort, starting from both ends of the memory area, and moving the allocated memory blocks to the middle, each time moving a memory block size ; S32.1. If shared memory transmission is used and there is enough free memory, wait to enter the critical area; After entering the critical area, search for a continuous free memory block that meets the size requirement in the unallocated shared memory block linked list; let the index of the found starting free memory block in the linked list be , the offset is , calculated as: ; This formula determines the starting position of the written data in the shared memory; Write data to the specified area of shared memory. Suppose the shared memory area is , the write operation is expressed as: ,in The value range is arrive ; The management information area records the relevant information of the data write, including the starting offset of the write. , Data size and write timestamp ;Write information recorded in a structure array In , let the array index be , the recording method is: , , ; The receiver obtains the notification of data writing completion through the interrupt processing mechanism of the inter-virtual machine communication module; The receiver reads data from the corresponding area of the shared memory according to the pre-agreed communication protocol; suppose the receiver reads data and stores it in the array In , the read operation is represented as: ,in The value range is arrive ; After the reading is completed, the receiver can send a confirmation signal to the sender to indicate that the data has been successfully received; the confirmation signal can be implemented through an inter-core interrupt or a specific flag bit in the shared memory; S33.1. If it is determined in S31 that a shared memory resource needs to be applied for and the application conditions are met after the preparation stage, the resource application is formally carried out; Allocate a continuous memory block from the unallocated shared memory block list, and the allocation size is calculated previously ; Update the linked list of unallocated shared memory blocks and remove the allocated memory block from the linked list; set the starting node of the allocated memory block in the linked list to , the update list operation is expressed as: , otherwise update the linked list head pointer; In memory block status array In , mark the corresponding allocated memory block position as allocated, and set the starting index of the allocated memory block in the memory block status array to , the marking operation is expressed as: ,in The value range is arrive , Indicates the number of allocated memory blocks; In the shared data area usage record in the management information area, add the resource information of this application, including the resource offset and resource size and the unique identifier of the application ; Assume that the shared data area usage record structure in the management information area is $Usage$, and the operation of adding a record is expressed as: , , ; Update the remaining free space information in the management information area, including the starting offset and size of the remaining free space; set the starting offset of the remaining free space to , the size is , calculated as follows: If the allocated memory block is the first memory block in the list of unallocated shared memory blocks, then ,otherwise ; ,in is the total size of the continuous free memory blocks previously counted; the operation of updating the remaining free information is represented by: updating the corresponding field in the management information area to the new and value.
[0013] In the preferred embodiment, in step S4: Use the Szymanski algorithm to implement mutually exclusive access of the running area to the shared memory management information area, ensuring that only one running area can access the management information area at the same time, ensuring data consistency; In the inter-virtual machine communication mode based on the combination of inter-core interrupts and shared memory, a synchronization module is implemented based on inter-core interrupts to coordinate data interaction between different virtual machines or running areas to ensure the correctness and integrity of data transmission.
[0014] In the preferred embodiment, the specific steps of step S4 are: S41. The steps of using the Szymanski algorithm are as follows: in addition to the flag register allocated to each operation area by the original Szymanski algorithm, an auxiliary status register is added to each operation area. ; Auxiliary status register Each bit of the register represents the access rights of the operation area to different parts of the management information area ( The length is , determined according to the division structure of the management information area, if it is divided into A key part, ; Initialize the auxiliary status register All bits of are 0, indicating that the running area does not have any access rights at the beginning; When the operation area needs to access the management information area, it first checks whether the corresponding flag register value meets the mutual exclusion condition, using the rules in the Szymanski algorithm; The flag register is ,like If the value of satisfies the mutually exclusive condition, proceed to the next step; otherwise, wait until the condition is met; Determine the part of the management information area that needs to be accessed based on the access requirements and calculate the corresponding auxiliary status bit index ; For example, if you want to access the magic number part, determine it according to the pre-defined mapping relationship ; If you want to access the shared data area usage information section, make sure ; The run zone checks its auxiliary status register No. Place value; if , indicating that the current running area can obtain access rights to the management information area, set $A[j]$ to 1, and perform data access operations; if , indicating that other operating areas are accessing this part and the current operating area needs to wait; during the waiting process, the operating area can periodically check the auxiliary status register until access rights can be obtained; When the operation area completes access to a part of the management information area, the corresponding auxiliary status register The bit value is reset to 0 to release access rights; S42, Inter-core interrupt-based synchronization module: Assign an initial interrupt priority to each virtual machine or runtime area , the priority value range is , is the total number of operating zones in the system; the initial priority can be set based on factors such as the importance of the operating zone or the expected frequency of data interaction; The system maintains an interrupt priority adjustment factor matrix , whose elements Indicates the operating area For operation area The degree of data dependence can be determined by analyzing historical data interaction records. For example, if the running area Frequently waiting for the running area The data can continue to execute, then If there is little data interaction between the two, then The value of is low; Periodically (every time interval ) Adjust the factor matrix according to the interrupt priority Recalculate the interrupt priority of each operation area; the new interrupt priority calculation formula is: ,in is the total number of running zones in the system, is the weight factor; the function of this formula is to comprehensively consider the data dependency and historical priority between the operating areas, dynamically adjust the interrupt priority, and ensure the efficiency of data interaction; Define a unique interrupt vector for each possible data interaction event , Indicates the event type; the length of the interrupt vector is , The encoding method can be determined based on the number of event types in the system and the encoding requirements. The encoding method can use a hash function-like method to map the key information related to the event into a unique vector value. When a running area triggers a data interaction event, it sends the corresponding interrupt vector to the target running area. ; The target operation area sets an interrupt vector listener. When an interrupt vector is received, the event type and related information are parsed according to the value of the interrupt vector; Based on the information parsed from the interrupt vector, the target operation area determines how to respond to the data interaction request; Among them, if it is a shared memory write completion notification, the target operation area can read the latest data from the shared memory according to the pre-agreed protocol; if it is a data read request, the target operation area can prepare the corresponding data and send it back to the source operation area; S43, data interaction process combining mutually exclusive access and synchronization control: When the running area needs to perform data interaction (, first obtain access rights to the shared memory management information area in the manner optimized by the above-mentioned Szymanski algorithm, including checking the flag register and the auxiliary status register to determine whether the relevant information can be accessed; After obtaining access rights, the operation area prepares data according to data interaction requirements; For the operation of writing data to shared memory, after the operation area completes the data writing, it generates the corresponding interrupt vector according to the information such as data type and target operation area. , and trigger the inter-core interrupt to send a notification to the target running area; For the operation of reading shared memory data, the operation area first sends an interrupt vector with read request information. To the target operation area, and then wait for the target operation area to prepare data and send it back; during the waiting process, the operation area can perform appropriate waiting scheduling according to its own interrupt priority; After receiving the interrupt vector, the target operation area parses the event type according to the interrupt vector; if it is a write notification, the target operation area reads the data from the shared memory in the manner described above and performs corresponding processing; if it is a read request, the target operation area prepares the requested data, writes the data to the specified location of the shared memory, and sends an interrupt vector indicating that the data is ready To the source operation area; After the source operation area receives the interrupt vector indicating that the data is ready, it reads the data prepared by the target operation area from the shared memory and continues the subsequent data processing flow.
[0015] In the preferred embodiment, in step S5: Release shared memory resources: When data interaction is completed, if the shared memory resources are no longer needed, the resource release operation can be performed to update the usage information of the shared data area in the management information area, such as marking the corresponding memory block as free; Notify relevant parties: In some cases, after data interaction is completed, it may be necessary to notify other relevant operating areas or virtual machines, such as sending notification signals through inter-core interrupts, to inform the other party that the data is ready or the data interaction is completed, so that the other party can perform subsequent processing.
[0016] In the preferred embodiment, the specific scheme in step S5 is: S51, releasing shared memory resources: when it is determined that the shared memory resources are to be released, firstly, the memory block range to be released is determined according to the recorded shared memory usage information; assuming that the shared memory usage information structure is , which contains the offset where the resource is located and resource size ; Assume the memory block size is , calculate the starting index of the memory block that needs to be released and end index , the calculation formula is: , ; This formula accurately determines the location range of the memory block to be released in the memory block status array based on the known offset and size information; Traverse the memory block status array , will be arrive The element value of is reset to a specific value indicating free; let the length of the memory block status array be , the update operation is expressed as: ,in The value range is arrive ; Update the unallocated shared memory block linked list; search the unallocated shared memory block linked list and find a suitable location to insert the released memory block; set the released memory block to , whose size is , the previous node is , the next node is ; If the linked list is empty, the released memory block is directly used as the head of the linked list; if the released memory block should be inserted into the head of the linked list, that is, its starting offset is less than the starting offset of the head node of the linked list, then the head pointer of the linked list is updated; otherwise, traverse the linked list to find a suitable insertion position. The insertion operation is expressed as: , ; S52, in the shared data area usage record in the management information area, delete or mark the resource record released this time as invalid; set the shared data area usage record array in the management information area to , traverse the array to find the record item corresponding to the released resource, mark it as invalid or delete it directly; Update the remaining free space information in the management information area, including the starting offset and size of the remaining free space; calculate the new starting offset of the remaining free space and size ; If the released memory block is the last block in the shared memory, that is, the remaining free area after release is at the end of the memory, then is the starting address of the shared memory, The size of the released memory block plus the size of the remaining free area; otherwise, The starting offset of the next memory block to release the memory block. The size of the released memory block plus the size of the original remaining free area or only the size of the released memory block; the operation of updating the remaining free information is represented by: updating the corresponding field in the management information area to the new and value; S53, notify the relevant parties: in order to more richly and accurately notify the relevant parties of the completion of different types of data interaction, the encoding of the interrupt vector is extended; the interrupt vector The length is , divided into multiple fields; Bits are used to indicate the notification type. The bit is used to indicate the source runtime or virtual machine ID. Bits are used to represent additional information related to the notification; Define the notification type encoding rules; Among them, 0000 indicates that data writing is completed, 0001 indicates that data reading is completed, and 0010 indicates an interaction error, etc. The source operation area or virtual machine identifier is encoded using a unique number assigned by the system; additional information is encoded according to the specific meaning; The data size can be encoded in binary to represent the actual size, and the interaction result code can define different values to represent success, failure or other specific status; S54: When it is necessary to notify the relevant parties, an interrupt vector is generated according to the specific situation of the data interaction. ; Among them, if the data is written and the data size is , the source operation area is identified as , the interaction is successful, the interrupt vector generated The first 4 digits are 0000, and the middle 8 digits are The last 4 digits are The binary encoding of Send interrupt vectors to the target runtime or virtual machine through the inter-core interrupt mechanism ; The target operation area or virtual machine sets the interrupt vector listener. When receiving the interrupt vector, first parse the various fields of the interrupt vector; Set the received interrupt vector to , parse the notification type field , indicating that from the 0th to the bit, source operation area identification field , additional information field ; According to the parsed notification type, the target operating area or virtual machine performs corresponding processing operations; if the notification type is data writing completion, the target operating area can read the latest data from the shared memory according to the source operating area identifier and additional information; if the notification type is interaction error, the target operating area can record the error information and adopt corresponding error handling strategies.
[0017] The present invention provides a data interaction method based on shared memory of an embedded virtualization platform. By reasonably dividing the shared memory into the management information area and the shared data area, and recording the usage information of the shared data area in detail (such as remaining free information, usage status, etc.), memory resource management can be performed more accurately. When applying for memory, the memory block that meets the requirements can be quickly located to reduce memory fragmentation. For example, when calculating the starting offset of the memory application and judging the continuity of the memory block, the rationality of memory allocation is ensured according to the relevant formula, thereby improving the overall memory utilization.
[0018] The optimized memory release operation can timely update the memory block status array, the unallocated shared memory block linked list, and the remaining free information in the management information area, so that the released memory blocks can be quickly reused, further improving the memory management efficiency.
[0019] The improved Szymanski algorithm adds an auxiliary status register to accurately control the access rights of the operation area to different parts of the management information area, ensuring that only one operation area can access key information at the same time, effectively avoiding data conflicts and inconsistencies, and ensuring data reliability.
[0020] Based on the optimization of the synchronization module between core interrupts, the interrupt priority is dynamically adjusted to ensure that important or highly dependent data interactions are given priority. At the same time, the data interaction status is accurately notified to the relevant parties through a unique interrupt vector, making the collaborative work between various operating areas or virtual machines more orderly and enhancing the stability of the entire system during the data interaction process.
[0021] In the data interaction preparation phase, the shared memory physical start address acquisition and management information area availability judgment mechanism are optimized to reduce waiting time and error judgment and speed up the data interaction process. For example, an event-triggered monitoring mechanism and a multi-stage confirmation mechanism are used to avoid unnecessary polling and waiting and improve system response speed.
[0022] In the transmission mode selection phase, the inter-core communication register or shared memory transmission is intelligently selected according to the message size to avoid unnecessary overhead when transmitting large messages. At the same time, resource application and data writing and reading operations in the shared memory transmission process are optimized to improve data transmission efficiency. For example, the appropriate memory block size is calculated to apply for memory, reducing the time cost of memory allocation and data transmission.
[0023] The decentralized shared memory management solution enables each operating zone to apply for and obtain shared memory resources on a peer-to-peer basis, reducing the direct dependencies between operating zones and lowering the system coupling. For example, each operating zone accesses shared memory through a unified interface and mechanism, decoupling from the specific implementation details of other operating zones.
[0024] Standardized memory management interfaces and operating specifications shield the differences between different processors, making the interaction between upper-level software and hardware more concise and unified, reducing the overall complexity of the system and facilitating system maintenance and expansion.
[0025] The algorithm design takes into account the transmission requirements of messages of different sizes, multiple operating area environments, and the processing of different data interaction events. It can flexibly respond to complex and changeable application scenarios in embedded systems and meet various functional requirements, such as realizing the coordinated work of high real-time functions and low real-time functions in relay protection equipment, and supporting data interaction between different software systems in virtualized devices. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] The present invention will be further described below in conjunction with the accompanying drawings and embodiments: Figure 1 It is a flow chart of the data interaction method of the shared memory of the present invention; Figure 2 is a flow chart of the method of step S1 of the present invention; Figure 3 is a flow chart of the method of step S3 of the present invention; Figure 4 is a flow chart of the method of step S4 of the present invention; Figure 5 It is a flow chart of the method of step S5 of the present invention. DETAILED DESCRIPTION
[0027] Example 1 like Figure 1-5 As shown, a data interaction method based on shared memory of an embedded virtualization platform comprises: S1. Divide the shared memory area into a management information area and a shared data area, initialize the management information area, including setting a magic number, configuring a mutually exclusive access flag, and recording usage information of the shared data area; S2. Get the physical start address of the shared memory, verify the availability of the management information area, and ensure that it has been correctly initialized; S3. Select the appropriate data transmission method according to the data size. Small data can be directly transmitted through the inter-core communication register, while large data can be transmitted using shared memory. If you need to apply for shared memory resources, first check the legality of the application, then allocate resources and record relevant information in the management information area; The sender writes data to a specific area of shared memory, and the receiver then reads the data from that area; S4, use Szymanski algorithm to implement mutual exclusive access control to ensure data consistency; Implement synchronization mechanisms based on specific needs, and use inter-core interrupts to coordinate data exchange between different operating areas; S5. After the data interaction is completed, if the shared memory resources are no longer needed, they should be released and the usage information in the management information area should be updated; Notify other related runtime areas or virtual machines as needed to inform them of the status changes of data interaction.
[0028] Example 2 Further illustrate with reference to Example 1, Figure 1-5 In the preferred embodiment, the specific steps in step S1 are: In the data interaction scenario based on shared memory on the embedded virtualization platform, in order to more efficiently manage shared memory resources, especially when multiple running areas frequently apply for and release memory blocks, reduce memory fragmentation, improve memory utilization, and ensure the stability and efficiency of data interaction.
[0029] S11, in the multi-core processor, a dedicated memory is allocated as a shared memory, and the dedicated memory is divided into a management information area and a shared data area, wherein the management information area is located at the head of the shared memory and contains management information of the shared memory, and the shared data area is used for data interaction among the operation areas; S12, when the main core initializes the management information area of the shared memory, it first clears the magic number to zero, and writes the correct magic number after completing the formal initialization. Other operation areas determine whether the management information area is available by judging whether the magic number is correct; S13. The management information area includes the current remaining free space information and usage status of the shared data area, so as to facilitate the application and allocation of new shared data area resources.
[0030] In the preferred embodiment, the specific steps of steps S11-S13 are: S11.1. A dedicated memory is allocated in the multi-core processor as shared memory, and is divided into a management information area and a shared data area. The management information area is located at the head of the shared memory. In addition to the magic number, the exclusive access flag, the current remaining free information and the usage status of the shared data area in the prior art, the management information area also adds an additional memory block status array. , used to record the status of each memory block in the shared data area; suppose the total size of the shared memory is , the size of the management information area is , then the size of the shared data area is ; Initially divide the shared data area into memory blocks of equal size. memory blocks, each memory block size is ; Memory block status array The length is , initially all element values are 0, indicating that all memory blocks are idle; S12.1: Management information area initialization optimization: When the main core initializes the shared memory management information area, it first clears the magic number to zero, writes the correct magic number after the formal initialization is completed, and initializes the memory block status array at the same time , set all elements to a specific value indicating idleness, and set the exclusive access flag, using the Szymanski algorithm; Other operation areas determine whether the management information area is available by judging whether the magic number is correct. Only when the magic number is correct and the memory block status array After the integrity check is passed, the management information area is considered to be initialized and subsequent operations can be performed; the checksum formula is: ,in and are two pre-selected large prime numbers; the function of this formula is to set the memory block status array Generate a unique checksum value for verification in other operating areas To ensure data integrity and prevent data inconsistency caused by memory errors or malicious tampering; S13.1: Optimization of shared data area resource application allocation: When the operation area has a shared data area resource application demand, first wait to enter the critical area according to the existing technology; After entering the critical area, check the current remaining free information in the shared data area and find the continuous free memory blocks that meet the application size requirements; set The memory size requested is , from the memory block status array Start looking for consecutive elements with value 0, such that ; If a continuous free memory block that meets the conditions is found, it will be allocated; when allocating a memory block, not only the usage record of the shared data area in the management information area should be updated, but also the memory block status array should be updated , set the corresponding element value to a specific value indicating that it has been allocated; the calculation formula for the starting offset of the allocated memory block is: , that is, find the minimum starting offset position that meets the conditions; this formula ensures that when there are enough continuous free memory blocks, the front position is selected for allocation, which is conducive to reducing memory fragmentation; If no continuous free memory blocks that meet the conditions are found, memory defragmentation is performed according to a certain memory defragmentation strategy; the memory defragmentation strategy is as follows: Calculate the current memory fragmentation level , the formula is: , among which When , it indicates that there is a change in the memory block status; The larger the value, the higher the degree of memory fragmentation; if Exceeding a pre-set threshold , the memory defragmentation process is started; the memory defragmentation process includes moving the allocated memory blocks to one end of the memory area, merging adjacent free memory blocks, and updating the memory block status array. and the remaining free information of the shared data area; the process of moving the allocated memory blocks can adopt a bubble sort-like idea, starting from one end of the memory area, and moving the allocated memory blocks one by one to the target end, each time moving a memory block size ; When the running area completes data interaction and needs to release shared memory resources, it also needs to enter the critical area; According to the record information of the released memory resources, calculate the corresponding memory block in the memory block status array The position range in the memory block state array is calculated, and the element values of these positions are reset to specific values indicating free space, and the remaining free space information of the shared data area in the management information area is updated; The starting position formula in is: , the ending position formula is: ,in To release the starting offset of the memory block, To release the size of the memory block, is the size of a single memory block; these formulas accurately locate the position of the memory block that needs to be updated in the array, ensuring the correctness of the memory release operation.
[0031] In the best case, that is, the requested memory size is exactly equal to the free memory block size and no memory defragmentation is required, the time complexity of the memory request operation mainly depends on the process of finding the free memory block that meets the conditions, and its time complexity is ,in The number of memory blocks in the shared data area.
[0032] In the worst case (i.e., when memory defragmentation is required), the time complexity is higher. The time complexity of moving allocated memory blocks during memory defragmentation is ,in is the number of allocated memory blocks, is the total number of memory blocks in the shared data area. Therefore, the time complexity of the entire algorithm in the worst case is .
[0033] The time complexity of the memory release operation is relatively low, mainly depending on the calculation of the position range of the released memory block in the memory block status array. The time complexity is ,in To release the size of the memory block, The size of a single memory block.
[0034] In addition to the space occupied by the shared memory itself, the algorithm also needs to store management information (including magic number, exclusive access flag, shared data area usage information, memory block status array, etc.). The space complexity is ,in To manage the size of the information area, this extra space overhead is relatively small compared to the overall size of the shared memory.
[0035] Through the above algorithm optimization, in the process of data interaction based on shared memory in the embedded virtualization platform, shared memory resources can be managed more effectively, memory utilization and data interaction efficiency can be improved, and system stability and reliability can be enhanced. In actual applications, the parameters in the algorithm (such as memory block size, fragmentation threshold, etc.) can be adjusted and optimized according to the specific hardware platform and business requirements.
[0036] Example 3 Further illustrate with reference to Example 1, Figure 1-5In the preferred embodiment, the specific steps of step S2 are: During the data interaction preparation stage of the embedded virtualization platform, ensure that each operating area can efficiently, accurately and stably obtain the physical start address of the shared memory and determine the availability of the management information area. At the same time, optimize the waiting mechanism, reduce unnecessary waiting time overhead, and improve the overall performance of the system.
[0037] S21, each operating area first attempts to obtain the initial value of the shared memory physical start address from the predefined system configuration table ;The system configuration table is partially filled by the main core during initialization, and contains some basic configuration information related to shared memory, but the address may not be completely accurate at this time; Calculate address checksum , where the check function The calculation formula is: ,here Indicates the address, is the address byte length, and is a pre-selected large prime number; the function of this formula is to generate a unique check value for the address, which is used to preliminarily verify the correctness of the address; If the check value If it does not match the predefined check value range, the address search and correction process is initiated; S22, the running area sends an address query request to the main core. After receiving the request, the main core traverses the system memory mapping table, finds the area marked as shared memory, and obtains its accurate physical starting address ; The main core will accurately start at the physical address and the new checksum Send back to the requested runtime; The runtime recalculates the received address If the check value is the same as the received check value If the address matches, it is confirmed that the correct shared memory physical start address is obtained; otherwise, the above query request process is repeated until the correct address is obtained; S23, when waiting for the magic number of the management information area to be correctly judged, each operation area does not simply poll and wait, but adopts a monitoring mechanism based on event triggering; the operation area creates a monitoring thread, which is bound to the hardware interrupt or memory address change event related to the magic number of the management information area; When the listening thread detects a write operation at the memory address where the magic number is located, it immediately obtains the value of the magic number. ; Calculate dynamic checksum of magic number , where the check function The calculation formula is: ,here Represents the magic number, is the magic number byte length, and is a large prime number selected separately; this formula is used to dynamically verify the correctness of the magic number at runtime to prevent the magic number from being tampered with without being discovered due to memory errors and other reasons; If the dynamic check value If the magic number does not match the predefined correct magic number check value and the magic number is not updated to the correct value again within a certain period of time, it is considered that an error may have occurred, the error information is recorded, and an attempt is made to reinitialize the shared memory related configuration; If the dynamic checksum value of the magic number If the predefined magic number check value matches, the operation area enters the first stage of confirmation; in the first stage of confirmation, the operation area waits for a short time interval , get the magic number again and recalculate the checksum for verification; this is to prevent misjudgment when the magic number has just been written but is not yet completely stable; If the checksum is still correct in the first phase of confirmation, the operation area enters the second phase of confirmation. In the second phase of confirmation, the operation area sends a magic number confirmation request to the main core. After receiving the request, the main core checks the integrity of the management information area and returns the confirmation result. Among them, the integrity check of the management information area including magic number, exclusive access flag, shared data area usage information, etc. can be checked. The integrity check can be similar to the checksum calculation method mentioned above, and all relevant information in the management information area is regarded as a byte array for calculation; If the confirmation result returned by the main core indicates that the management information area is complete and correct, the operating area finally determines that the management information area is available and can perform subsequent data interaction operations; otherwise, the operating area attempts to perform corresponding repair operations or report the error to the system administrator based on the error information returned by the main core.
[0038] In the best case of obtaining the physical start address of the shared memory (that is, the initial address obtained from the system configuration table is correct), the time complexity is , because only one address check calculation is required. In the worst case (i.e., multiple queries to the main core are required and waiting for replies), the time complexity mainly depends on the communication delay with the main core and the time it takes for the main core to find the correct address. Assume that the round-trip time for communication with the main core is , the main core search address time is , at most Query ( is a small constant that depends on the system configuration and error probability), the worst-case time complexity is .
[0039] In terms of determining the availability of the management information area, in the best case (i.e. the magic number is checked correctly once and the management information area is complete), the time complexity is (Only a few checksums and short waiting times are calculated). In the worst case (i.e., the magic number is wrong multiple times and multiple interactions with the main core are required for integrity confirmation), assuming that the round-trip time for integrity confirmation communication with the main core is $t'$, Integrity verification attempts ( is a small constant, depending on the system stability and error probability), then the time complexity is , where $T'$ is the time for the main core to perform integrity check.
[0040] The extra space mainly used by the algorithm during operation is to store address check values, magic number check values and related temporary variables. The space complexity is relatively low. ,in This is constant space associated with checksum calculations and temporary variables.
[0041] Through the above algorithm optimization, the physical start address of the shared memory can be obtained more reliably and efficiently in the data interaction preparation stage and the availability of the management information area can be determined, thereby improving the data interaction efficiency and system stability of the embedded virtualization platform and reducing data interaction problems caused by address errors or abnormal management information areas. In practical applications, the parameters in the algorithm (such as prime number value, timeout time, waiting interval, etc.) can be adjusted and optimized according to the specific hardware platform and system requirements.
[0042] Example 4 Further illustrate with reference to Example 1, Figure 1-5 In the preferred embodiment, the specific steps of step S3 are as follows: In the data interaction process based on shared memory in the embedded virtualization platform, the transmission mode selection is optimized for messages of different sizes, the efficiency of shared memory resource application and management is improved, the data is accurately written and read, and the reliability and performance of the system are enhanced.
[0043] S31. In some implementations, if the message transfer size is within 3 or 3 bytes, the inter-core communication register can be used to transmit data. By adding a system call to the operating system, the corresponding transmission mode is selected after the message size is determined. If the inter-core register communication is used, the inter-core communication module interface in the VMM is called; if the message content size is greater than 3 bytes, the shared memory is usually used to transmit data, and the communication interface in the shared memory module is called for data transmission. The shared memory module includes a linked list of allocated and unallocated shared memory blocks, a spin lock, and a synchronization module based on inter-core interrupts, which is used to manage shared memory access; S32, if shared memory is used to transmit data and shared memory resources need to be applied for, wait to enter the key area, check whether there are enough shared data resources, whether the application name is unique and other legal conditions, if the application is legal, allocate shared memory resources, and record the relevant information of the application in the management information area; S33. The sender writes the data into the specified area of the shared memory, and the receiver reads the data from the corresponding area. In the inter-virtual machine communication method based on the combination of inter-core interrupts and shared memory, the inter-virtual machine communication module is responsible for the data writing and reading operations, which are implemented through the interrupt processing module and the communication interface provided to the application, and are transparent to the application.
[0044] In the preferred embodiment, the specific steps of steps S31-S33 are: S31.1. Message size determination and transmission mode decision: When data needs to be transmitted, the size of the message is first calculated. , in bytes; suppose the message data is stored in array In , the message size calculation formula is: ,in For array The length of the message is determined by counting the number of non-zero elements in the array. if , then the inter-core communication register transmission mode is selected; at this time, the operating system triggers the inter-core communication module through a system call, and the message data is directly copied to the inter-core communication register during the system call; let the inter-core communication register be , the copy operation can be expressed as: ,in The value range is arrive ; if , then select the shared memory transmission mode and prepare to apply for shared memory resources; Calculate the minimum contiguous memory block size required for this data transfer ; Assume the shared memory block size is , calculated as: ,in Represents the round-up function; this formula ensures that the requested memory block is large enough to accommodate the message data and is an integer multiple of the memory block size, which is beneficial to memory management; Check the unallocated shared memory block list in the shared memory module and count the total size of consecutive free memory blocks in the list. ; Traverse the linked list, assuming that the linked list nodes represent memory blocks, and the fields in the nodes Indicates the memory block size, Point to the next node, calculated as: ,in is the number of consecutive free memory blocks in the linked list. When it is $null$, it indicates the end of the linked list; if , it means that the current free memory is insufficient and it is necessary to defragment the memory or wait for other running areas to release memory; the memory defragmentation process is as follows: Calculating memory fragmentation , the formula is: ,in is the memory block status array, is the total number of memory blocks; this formula measures the degree of memory fragmentation, and the larger the value, the more severe the fragmentation; if Exceeding a pre-set threshold , the memory defragmentation process is started; the allocated memory blocks are moved to one end of the memory area, adjacent free memory blocks are merged, and the memory block status array is updated and the linked list of unallocated shared memory blocks; the process of moving the allocated memory blocks can adopt the idea of merge operation similar to merge sort, starting from both ends of the memory area, and moving the allocated memory blocks to the middle, each time moving a memory block size ; S32.1. If shared memory transmission is used and there is enough free memory, wait to enter the critical area; After entering the critical area, search for a continuous free memory block that meets the size requirement in the unallocated shared memory block linked list; let the index of the found starting free memory block in the linked list be , the offset is , calculated as: ; This formula determines the starting position of the written data in the shared memory; Write data to the specified area of shared memory. Suppose the shared memory area is , the write operation is expressed as: ,in The value range is arrive ; The management information area records the relevant information of the data write, including the starting offset of the write. , Data size and write timestamp ;Write information recorded in a structure array In , let the array index be , the recording method is: , , ; The receiver obtains the notification of data writing completion through the interrupt processing mechanism of the inter-virtual machine communication module; The receiver reads data from the corresponding area of the shared memory according to the pre-agreed communication protocol; suppose the receiver reads data and stores it in the array In , the read operation is represented as: ,in The value range is arrive ; After the reading is completed, the receiver can send a confirmation signal to the sender to indicate that the data has been successfully received; the confirmation signal can be implemented through an inter-core interrupt or a specific flag bit in the shared memory; S33.1. If it is determined in S31 that a shared memory resource needs to be applied for and the application conditions are met after the preparation stage, the resource application is formally carried out; Allocate a continuous memory block from the unallocated shared memory block list, and the allocation size is calculated previously ; Update the linked list of unallocated shared memory blocks and remove the allocated memory block from the linked list; set the starting node of the allocated memory block in the linked list to , the update list operation is expressed as: , otherwise update the linked list head pointer; In memory block status array In , mark the corresponding allocated memory block position as allocated, and set the starting index of the allocated memory block in the memory block status array to , the marking operation is expressed as: ,in The value range is arrive , Indicates the number of allocated memory blocks; In the shared data area usage record in the management information area, add the resource information of this application, including the resource offset and resource size and the unique identifier of the application ; Assume that the shared data area usage record structure in the management information area is $Usage$, and the operation of adding a record is expressed as: , , ; Update the remaining free space information in the management information area, including the starting offset and size of the remaining free space; set the starting offset of the remaining free space to , the size is , calculated as follows: If the allocated memory block is the first memory block in the list of unallocated shared memory blocks, then ,otherwise ; ,in is the total size of the continuous free memory blocks previously counted; the operation of updating the remaining free information is represented by: updating the corresponding field in the management information area to the new and value.
[0045] In the transmission mode selection phase, the time complexity of calculating the message size is ,in is the length of the message data array. The time complexity of determining the transmission method is If shared memory transmission is selected and memory defragmentation is required, the time complexity of the memory defragmentation process is high. In the worst case (i.e., memory fragmentation is very serious), the time complexity is ,in is the total number of memory blocks, The memory block size.
[0046] When writing data into shared memory, the time complexity of waiting to enter the critical area depends on the system concurrency. Assuming the average waiting time is The worst-case time complexity of finding a free memory block is ,in is the length of the unallocated shared memory block linked list. The time complexity of writing data is ,in is the message size. The time complexity of recording information to the management information area is .
[0047] In the data reading shared memory stage, the time complexity of receiving notification depends on the interrupt processing mechanism. Assuming the average processing time is The time complexity of reading data is The time complexity of sending the confirmation signal (if any) is .
[0048] In the shared memory resource application phase, the time complexity of allocating memory blocks and updating linked lists is in the worst case: , the time complexity of updating the memory block status array is , the time complexity of updating the management information area information is .
[0049] The main additional space occupied by the algorithm during operation includes a temporary array (size is ), an array of structures used to record information in the management information area (assuming that at most The space complexity is ), temporary variables used to calculate checksums, etc. (the space complexity is constant ). Therefore, the total space complexity is .
[0050] Through the above algorithm optimization, in the process of data interaction based on shared memory in the embedded virtualization platform, the transmission method can be selected more flexibly and efficiently, the shared memory resources can be reasonably managed, and data writing and reading operations can be performed accurately, thereby improving the data processing capability and overall performance of the system, while adapting to different application scenarios and system load conditions. In actual applications, the parameters in the algorithm (such as memory block size, fragmentation threshold, message size judgment threshold, etc.) can be further optimized and adjusted according to the specific hardware platform, system requirements and business characteristics.
[0051] Example 5 Further illustrate with reference to Example 1, Figure 1-5 The structure shown, in the preferred embodiment, in step S4: During the data interaction process of the embedded virtualization platform, the mutual exclusive access mechanism of the shared memory management information area is strengthened to ensure data consistency. At the same time, the synchronization module based on inter-core interrupts is optimized to improve the efficiency and accuracy of data interaction between different virtual machines or running areas to adapt to complex system environments and diverse data interaction requirements.
[0052] Use the Szymanski algorithm to implement mutually exclusive access of the running area to the shared memory management information area, ensuring that only one running area can access the management information area at the same time, ensuring data consistency; In the inter-virtual machine communication mode based on the combination of inter-core interrupts and shared memory, a synchronization module is implemented based on inter-core interrupts to coordinate data interaction between different virtual machines or running areas to ensure the correctness and integrity of data transmission.
[0053] In the preferred embodiment, the specific steps of step S4 are: S41. The steps of using the Szymanski algorithm are as follows: in addition to the flag register allocated to each operation area by the original Szymanski algorithm, an auxiliary status register is added to each operation area. ; Auxiliary status register Each bit of the register represents the access rights of the operation area to different parts of the management information area ( The length is , determined according to the division structure of the management information area, if it is divided into A key part, ; Initialize the auxiliary status register All bits of are 0, indicating that the running area does not have any access rights at the beginning; When the operation area needs to access the management information area, it first checks whether the corresponding flag register value meets the mutual exclusion condition, using the rules in the Szymanski algorithm; The flag register is ,like If the value of satisfies the mutually exclusive condition, proceed to the next step; otherwise, wait until the condition is met; Determine the part of the management information area that needs to be accessed based on the access requirements and calculate the corresponding auxiliary status bit index ; For example, if you want to access the magic number part, determine it according to the pre-defined mapping relationship ; If you want to access the shared data area usage information section, make sure ; The run zone checks its auxiliary status register No. Place value; if , indicating that the current running area can obtain access rights to the management information area, set $A[j]$ to 1, and perform data access operations; if , indicating that other operating areas are accessing this part and the current operating area needs to wait; during the waiting process, the operating area can periodically check the auxiliary status register until access rights can be obtained; When the operation area completes access to a part of the management information area, the corresponding auxiliary status register The bit value is reset to 0 to release access rights; S42, Inter-core interrupt-based synchronization module: Assign an initial interrupt priority to each virtual machine or runtime area , the priority value range is , is the total number of operating zones in the system; the initial priority can be set based on factors such as the importance of the operating zone or the expected frequency of data interaction; The system maintains an interrupt priority adjustment factor matrix , whose elements Indicates the operating area For operation area The degree of data dependence can be determined by analyzing historical data interaction records. For example, if the running area Frequently waiting for the running area The data can continue to execute, then If there is little data interaction between the two, then The value of is low; Periodically (every time interval ) Adjust the factor matrix according to the interrupt priority Recalculate the interrupt priority of each operation area; the new interrupt priority calculation formula is: ,in is the total number of running zones in the system, is the weight factor; the function of this formula is to comprehensively consider the data dependency and historical priority between the operating areas, dynamically adjust the interrupt priority, and ensure the efficiency of data interaction; Define a unique interrupt vector for each possible data interaction event , Indicates the event type; the length of the interrupt vector is , The encoding method can be determined based on the number of event types in the system and the encoding requirements. The encoding method can use a hash function-like method to map the key information related to the event into a unique vector value. When a running area triggers a data interaction event, it sends the corresponding interrupt vector to the target running area. ; The target operation area sets an interrupt vector listener. When an interrupt vector is received, the event type and related information are parsed according to the value of the interrupt vector; Based on the information parsed from the interrupt vector, the target operation area determines how to respond to the data interaction request; Among them, if it is a shared memory write completion notification, the target operation area can read the latest data from the shared memory according to the pre-agreed protocol; if it is a data read request, the target operation area can prepare the corresponding data and send it back to the source operation area; S43, data interaction process combining mutually exclusive access and synchronization control: When the running area needs to perform data interaction (, first obtain access rights to the shared memory management information area in the manner optimized by the above-mentioned Szymanski algorithm, including checking the flag register and the auxiliary status register to determine whether the relevant information can be accessed; After obtaining access rights, the operation area prepares data according to data interaction requirements; For the operation of writing data to shared memory, after the operation area completes the data writing, it generates the corresponding interrupt vector according to the information such as data type and target operation area. , and trigger the inter-core interrupt to send a notification to the target running area; For the operation of reading shared memory data, the operation area first sends an interrupt vector with read request information. To the target operation area, and then wait for the target operation area to prepare data and send it back; during the waiting process, the operation area can perform appropriate waiting scheduling according to its own interrupt priority; After receiving the interrupt vector, the target operation area parses the event type according to the interrupt vector; if it is a write notification, the target operation area reads the data from the shared memory in the manner described above and performs corresponding processing; if it is a read request, the target operation area prepares the requested data, writes the data to the specified location of the shared memory, and sends an interrupt vector indicating that the data is ready To the source operation area; After the source operation area receives the interrupt vector indicating that the data is ready, it reads the data prepared by the target operation area from the shared memory and continues the subsequent data processing flow.
[0054] In the mutually exclusive access part optimized by the Szymanski algorithm, the time complexity of checking the flag register and the auxiliary status register is in the worst case ( is the length of the auxiliary status register). The time complexity of operations after obtaining access rights (such as data preparation, etc.) depends on the specific operations. Assume that The time complexity of releasing access rights is .
[0055] In the synchronization module based on inter-core interrupts, the time complexity of calculating interrupt priority is (in is the total number of running areas, because it is necessary to traverse the entire interrupt priority adjustment factor matrix ), the time interval for regularly adjusting the priority is , so the average time complexity for each data interaction event is The time complexity of sending and processing interrupt vectors mainly depends on the interrupt processing mechanism and hardware performance. Assuming the average processing time is In the data interaction process, the time complexity of waiting for scheduling according to the interrupt priority depends on the specific scheduling algorithm and priority distribution. Assuming the worst case is (in is the upper limit of waiting time).
[0056] Considering the entire data interaction process, in the worst case, the time complexity is .
[0057] The additional space occupied by the algorithm during operation mainly includes the auxiliary status registers added to each operation area (the space complexity is ,in is the auxiliary status register length, is the total number of running areas), interrupt priority adjustment factor matrix (The space complexity is ) and space for storing interrupt vectors and related temporary variables (the space complexity is ,in is the interrupt vector length, is the temporary variable space). Therefore, the total space complexity is .
[0058] Through the above algorithm optimization, the mutually exclusive access to the shared memory management information area can be more effectively achieved during the data interaction process of the embedded virtualization platform. At the same time, the synchronization module based on inter-core interrupts can better coordinate the data interaction between different virtual machines or operating areas, improve the system's performance, reliability and data processing capabilities, and adapt to the data interaction needs in a complex multi-operating area environment. In actual applications, the parameters in the algorithm (such as initial interrupt priority, weight factor, time interval) can be adjusted according to the specific hardware platform, system scale and business characteristics. etc.) for further optimization and adjustment.
[0059] Example 6 Further illustrate with reference to Example 1, Figure 1-5 In the structure shown, in the preferred scheme, in step S5: after the data interaction based on shared memory of the embedded virtualization platform is completed, the shared memory resources are released efficiently and accurately to ensure the accuracy and efficiency of memory management, while optimizing the mechanism for notifying relevant parties and improving the overall coordination and response speed of the system to adapt to the data interaction needs in complex multi-operating areas or multi-virtual machine environments.
[0060] Release shared memory resources: When data interaction is completed, if the shared memory resources are no longer needed, the resource release operation can be performed to update the usage information of the shared data area in the management information area, such as marking the corresponding memory block as free; Notify relevant parties: In some cases, after data interaction is completed, it may be necessary to notify other relevant operating areas or virtual machines, such as sending notification signals through inter-core interrupts, to inform the other party that the data is ready or the data interaction is completed, so that the other party can perform subsequent processing.
[0061] In the preferred embodiment, the specific scheme in step S5 is: S51, releasing shared memory resources: when it is determined that the shared memory resources are to be released, firstly, the memory block range to be released is determined according to the recorded shared memory usage information; assuming that the shared memory usage information structure is , which contains the offset where the resource is located and resource size ; Assume the memory block size is , calculate the starting index of the memory block that needs to be released and end index , the calculation formula is: , ; This formula accurately determines the location range of the memory block to be released in the memory block status array based on the known offset and size information; Traverse the memory block status array , will be arrive The element value of is reset to a specific value indicating free; let the length of the memory block status array be , the update operation is expressed as: ,in The value range is arrive ; Update the unallocated shared memory block linked list; search the unallocated shared memory block linked list and find a suitable location to insert the released memory block; set the released memory block to , whose size is , the previous node is , the next node is ; If the linked list is empty, the released memory block is directly used as the head of the linked list; if the released memory block should be inserted into the head of the linked list, that is, its starting offset is less than the starting offset of the head node of the linked list, then the head pointer of the linked list is updated; otherwise, traverse the linked list to find a suitable insertion position. The insertion operation is expressed as: , ; S52, in the shared data area usage record in the management information area, delete or mark the resource record released this time as invalid; set the shared data area usage record array in the management information area to , traverse the array to find the record item corresponding to the released resource, mark it as invalid or delete it directly; Update the remaining free space information in the management information area, including the starting offset and size of the remaining free space; calculate the new starting offset of the remaining free space and size ; If the released memory block is the last block in the shared memory, that is, the remaining free area after release is at the end of the memory, then is the starting address of the shared memory, The size of the released memory block plus the size of the remaining free area; otherwise, The starting offset of the next memory block to release the memory block. The size of the released memory block plus the size of the original remaining free area or only the size of the released memory block; the operation of updating the remaining free information is represented by: updating the corresponding field in the management information area to the new and value; S53, notify the relevant parties: in order to more richly and accurately notify the relevant parties of the completion of different types of data interaction, the encoding of the interrupt vector is extended; the interrupt vector The length is , divided into multiple fields; Bits are used to indicate the notification type. The bit is used to indicate the source runtime or virtual machine ID. Bits are used to represent additional information related to the notification; Define the notification type encoding rules; Among them, 0000 indicates that data writing is completed, 0001 indicates that data reading is completed, and 0010 indicates an interaction error, etc. The source operation area or virtual machine identifier is encoded using a unique number assigned by the system; additional information is encoded according to the specific meaning; The data size can be encoded in binary to represent the actual size, and the interaction result code can define different values to represent success, failure or other specific status; S54: When it is necessary to notify the relevant parties, an interrupt vector is generated according to the specific situation of the data interaction. ; Among them, if the data is written and the data size is , the source operation area is identified as , the interaction is successful, the interrupt vector generated The first 4 digits are 0000, and the middle 8 digits are The last 4 digits are The binary encoding of Send interrupt vectors to the target runtime or virtual machine through the inter-core interrupt mechanism ; The target operation area or virtual machine sets the interrupt vector listener. When receiving the interrupt vector, first parse the various fields of the interrupt vector; Set the received interrupt vector to , parse the notification type field , indicating that from the 0th to the bit, source operation area identification field , additional information field ; According to the parsed notification type, the target operating area or virtual machine performs corresponding processing operations; if the notification type is data writing completion, the target operating area can read the latest data from the shared memory according to the source operating area identifier and additional information; if the notification type is interaction error, the target operating area can record the error information and adopt corresponding error handling strategies.
[0062] In the part of releasing shared memory resources, the time complexity of calculating the index of the memory block to be released is The time complexity of traversing the memory block status array for marking is (in is the size of the memory block to be released, is the memory block size). The time complexity of updating the unallocated shared memory block list is in the worst case (in is the length of the linked list). The time complexity of updating the usage information and remaining free information of the management information area is (in is the operation complexity of the management information area record number or related data structure). Therefore, the total time complexity of releasing shared memory resources is in the worst case .
[0063] In the part of notifying the relevant parties, the time complexity of generating the interrupt vector is The time complexity of sending interrupt vectors depends on the inter-core interrupt mechanism. Assuming the average sending time is The time complexity of the receiver parsing the interrupt vector is (in is the interrupt vector length). The time complexity of executing the corresponding processing operation according to the notification type depends on the specific operation. Assume that Therefore, the total time complexity of notifying relevant parties is .
[0064] The main additional space occupied by the algorithm during operation includes temporary space for storing interrupt vectors (space complexity is ) and a small amount of temporary pointer and variable space that may be required when updating the unallocated shared memory block list and management information area (the space complexity is constant ). Therefore, the total space complexity is .
[0065] Through the above algorithm optimization, after the data interaction based on shared memory is completed on the embedded virtualization platform, the shared memory resources can be released more efficiently, the relevant parties can be notified accurately, the memory management efficiency of the system and the collaborative working ability between the operation areas can be improved, and the stability and reliability of the system can be enhanced. In practical applications, the parameters in the algorithm (such as interrupt vector length, encoding rules, linked list structure, etc.) can be further optimized and adjusted according to the specific hardware platform, system requirements and business characteristics.
[0066] The above embodiments are only preferred technical solutions of the present invention and should not be regarded as limiting the present invention. The protection scope of the present invention shall be the technical solutions recorded in the claims, including equivalent replacement solutions of the technical features in the technical solutions recorded in the claims. That is, equivalent replacement improvements within this scope are also within the protection scope of the present invention.
Claims
1. A data interaction method based on shared memory for an embedded virtualization platform, characterized in that: The method includes: S1. Divide the shared memory area into a management information area and a shared data area, initialize the management information area, including setting a magic number, configuring a mutually exclusive access flag, and recording usage information of the shared data area; S2. Get the physical start address of the shared memory, verify the availability of the management information area, and ensure that it has been correctly initialized; S3. Select the appropriate data transmission method according to the data size. Small data can be directly transmitted through the inter-core communication register, while large data can be transmitted using shared memory. If you need to apply for shared memory resources, first check the legality of the application, then allocate resources and record relevant information in the management information area; The sender writes data to a specific area of shared memory, and the receiver then reads the data from that area; S4, use Szymanski algorithm to implement mutual exclusive access control to ensure data consistency; Implement synchronization mechanisms based on specific needs, and use inter-core interrupts to coordinate data exchange between different operating areas; S5. After the data interaction is completed, if the shared memory resources are no longer needed, they should be released and the usage information in the management information area should be updated; Notify other related runtime areas or virtual machines as needed to inform them of the status changes of data interaction.
2. According to claim 1, a data interaction method based on shared memory for an embedded virtualization platform is characterized by: The specific steps in step S1 are: S11, in the multi-core processor, a dedicated memory is allocated as a shared memory, and the dedicated memory is divided into a management information area and a shared data area, wherein the management information area is located at the head of the shared memory and contains management information of the shared memory, and the shared data area is used for data interaction among the operation areas; S12, when the main core initializes the management information area of the shared memory, it first clears the magic number to zero, and writes the correct magic number after completing the formal initialization. Other operation areas determine whether the management information area is available by judging whether the magic number is correct; S13. The management information area includes the current remaining free space information and usage status of the shared data area, so as to facilitate the application and allocation of new shared data area resources.
3. According to the data interaction method of the embedded virtualization platform based on shared memory as described in claim 1, it is characterized by: step The specific steps of S11-S13 are: S11.
1. A dedicated memory is allocated in the multi-core processor as shared memory, and is divided into a management information area and a shared data area. The management information area is located at the head of the shared memory. In addition to the magic number, the exclusive access flag, the current remaining free information and the usage status of the shared data area in the prior art, the management information area also adds an additional memory block status array. , used to record the status of each memory block in the shared data area; suppose the total size of the shared memory is , the size of the management information area is , then the size of the shared data area is ; Initially divide the shared data area into memory blocks of equal size. memory blocks, each memory block size is ; Memory block status array The length is , initially all element values are 0, indicating that all memory blocks are idle; S12.1: Management information area initialization optimization: When the main core initializes the shared memory management information area, it first clears the magic number to zero, writes the correct magic number after the formal initialization is completed, and initializes the memory block status array at the same time , set all elements to a specific value indicating idleness, and set the exclusive access flag, using the Szymanski algorithm; Other operation areas determine whether the management information area is available by judging whether the magic number is correct. Only when the magic number is correct and the memory block status array After the integrity check is passed, the management information area is considered to be initialized and subsequent operations can be performed; the checksum formula is: ,in and are two pre-selected large prime numbers; the function of this formula is to set the memory block status array Generate a unique checksum value for verification in other operating areas To ensure data integrity and prevent data inconsistency caused by memory errors or malicious tampering; S13.1: Optimization of shared data area resource application allocation: When the operation area has a shared data area resource application demand, it first waits to enter the critical area according to the existing technology; After entering the critical area, check the current remaining free information of the shared data area and find the continuous free memory blocks that meet the application size requirements; set up The memory size requested is , from the memory block status array Start looking for consecutive elements with value 0, such that ; If a continuous free memory block that meets the conditions is found, it will be allocated; when allocating a memory block, not only the usage record of the shared data area in the management information area should be updated, but also the memory block status array should be updated , set the corresponding element value to a specific value indicating that it has been allocated; the calculation formula for the starting offset of the allocated memory block is: , that is, find the minimum starting offset position that meets the conditions; this formula ensures that when there are enough continuous free memory blocks, the front position is selected for allocation, which is conducive to reducing memory fragmentation; If no continuous free memory blocks that meet the conditions are found, memory defragmentation is performed according to a certain memory defragmentation strategy; the memory defragmentation strategy is as follows: Calculate the current memory fragmentation level , the formula is: , among which When , it indicates that there is a change in the memory block status; The larger the value, the higher the degree of memory fragmentation; if Exceeding a pre-set threshold , the memory defragmentation process is started; the memory defragmentation process includes moving the allocated memory blocks to one end of the memory area, merging adjacent free memory blocks, and updating the memory block status array. and the remaining free information of the shared data area; the process of moving the allocated memory blocks can adopt a bubble sort-like idea, starting from one end of the memory area, and moving the allocated memory blocks one by one to the target end, each time moving a memory block size ; When the running area completes data interaction and needs to release shared memory resources, it also needs to enter the critical area; According to the record information of the released memory resources, calculate the corresponding memory block in the memory block status array The position range in the memory block state array is calculated, and the element values of these positions are reset to specific values indicating free space, and the remaining free space information of the shared data area in the management information area is updated; The formula for the starting position in is: , the ending position formula is: ,in To release the starting offset of the memory block, To release the size of the memory block, is the size of a single memory block; these formulas accurately locate the position of the memory block that needs to be updated in the array, ensuring the correctness of the memory release operation.
4. According to claim 1, a data interaction method based on shared memory for an embedded virtualization platform is characterized by: The specific steps of step S2 are: S21, each operation area first attempts to obtain the initial value of the shared memory physical start address from the predefined system configuration table ;The system configuration table is partially filled by the main core during initialization, and contains some basic configuration information related to shared memory, but the address may not be completely accurate at this time; Calculate address checksum , where the check function The calculation formula is: ,here Indicates the address, is the address byte length, and is a pre-selected large prime number; the function of this formula is to generate a unique check value for the address, which is used to preliminarily verify the correctness of the address; If the check value If it does not match the predefined check value range, the address search and correction process is initiated; S22, the running area sends an address query request to the main core. After receiving the request, the main core traverses the system memory mapping table, finds the area marked as shared memory, and obtains its accurate physical starting address ; The main core will accurately start at the physical address and the new checksum Send back to the requested runtime; The runtime recalculates the received address If the check value is the same as the received check value If the address matches, it is confirmed that the correct shared memory physical start address is obtained; otherwise, the above query request process is repeated until the correct address is obtained; S23, when waiting for the magic number of the management information area to be correctly judged, each operation area does not simply poll and wait, but adopts a monitoring mechanism based on event triggering; the operation area creates a monitoring thread, which is bound to the hardware interrupt or memory address change event related to the magic number of the management information area; When the listening thread detects a write operation at the memory address where the magic number is located, it immediately obtains the value of the magic number. ; Calculate dynamic checksum of magic number , where the check function The calculation formula is: ,here Represents the magic number, is the magic number byte length, and is a large prime number selected separately; this formula is used to dynamically verify the correctness of the magic number at runtime to prevent the magic number from being tampered with without being discovered due to memory errors and other reasons; If the dynamic check value If the magic number does not match the predefined correct magic number check value and the magic number is not updated to the correct value again within a certain period of time, it is considered that an error may have occurred, the error information is recorded, and an attempt is made to reinitialize the shared memory related configuration; If the dynamic checksum value of the magic number If the predefined magic number check value matches, the operation area enters the first stage of confirmation; in the first stage of confirmation, the operation area waits for a short time interval , get the magic number again and recalculate the checksum for verification; this is to prevent misjudgment when the magic number has just been written but is not yet completely stable; If the checksum is still correct in the first phase of confirmation, the operation area enters the second phase of confirmation. In the second phase of confirmation, the operation area sends a magic number confirmation request to the main core. After receiving the request, the main core checks the integrity of the management information area and returns the confirmation result. Among them, the integrity check of the management information area including magic number, exclusive access flag, shared data area usage information, etc. can be checked. The integrity check can be similar to the checksum calculation method mentioned above, and all relevant information in the management information area is regarded as a byte array for calculation; If the confirmation result returned by the main core indicates that the management information area is complete and correct, the operating area finally determines that the management information area is available and can perform subsequent data interaction operations; otherwise, the operating area attempts to perform corresponding repair operations or report the error to the system administrator based on the error information returned by the main core.
5. According to claim 1, a data interaction method based on shared memory for an embedded virtualization platform is characterized by: The specific steps of step S3 are: S31. In some implementations, if the message transfer size is within 3 or 3 bytes, the inter-core communication register can be used to transmit data. By adding a system call to the operating system, the corresponding transmission mode is selected after the message size is determined. If the inter-core register communication is used, the inter-core communication module interface in the VMM is called; if the message content size is greater than 3 bytes, the shared memory is usually used to transmit data, and the communication interface in the shared memory module is called for data transmission. The shared memory module includes a linked list of allocated and unallocated shared memory blocks, a spin lock, and a synchronization module based on inter-core interrupts, which is used to manage shared memory access; S32, if shared memory is used to transmit data and shared memory resources need to be applied for, wait to enter the key area, check whether there are enough shared data resources, whether the application name is unique and other legal conditions, if the application is legal, allocate shared memory resources, and record the relevant information of the application in the management information area; S33. The sender writes the data into the specified area of the shared memory, and the receiver reads the data from the corresponding area. In the inter-virtual machine communication method based on the combination of inter-core interrupts and shared memory, the inter-virtual machine communication module is responsible for the data writing and reading operations, which are implemented through the interrupt processing module and the communication interface provided to the application, and are transparent to the application.
6. According to claim 1, a data interaction method based on shared memory for an embedded virtualization platform is characterized by: The specific steps of steps S31-S33 are: S31.
1. Message size determination and transmission mode decision: When data needs to be transmitted, the message size is first calculated. , in bytes; suppose the message data is stored in array In , the message size calculation formula is: ,in For array The length of the message is determined by counting the number of non-zero elements in the array. if , then the inter-core communication register transmission mode is selected; at this time, the operating system triggers the inter-core communication module through a system call, and the message data is directly copied to the inter-core communication register during the system call; let the inter-core communication register be , the copy operation can be expressed as: ,in The value range is arrive ; if , then select the shared memory transmission mode and prepare to apply for shared memory resources; Calculate the minimum contiguous memory block size required for this data transfer ; Assume the shared memory block size is , calculated as: ,in represents the ceiling function; This formula ensures that the requested memory block is large enough to accommodate the message data and is an integer multiple of the memory block size, which is beneficial for memory management; Check the unallocated shared memory block list in the shared memory module and count the total size of consecutive free memory blocks in the list. ; Traverse the linked list, assuming that the linked list nodes represent memory blocks, and the fields in the nodes Indicates the memory block size, Point to the next node, calculated as: ,in is the number of consecutive free memory blocks in the linked list. When it is $null$, it indicates the end of the linked list; if , it means that the current free memory is insufficient and it is necessary to defragment the memory or wait for other running areas to release memory; the memory defragmentation process is as follows: Calculating memory fragmentation , the formula is: ,in is the memory block status array, is the total number of memory blocks; this formula measures the degree of memory fragmentation, and the larger the value, the more severe the fragmentation; if Exceeding a pre-set threshold , the memory defragmentation process is started; the allocated memory blocks are moved to one end of the memory area, adjacent free memory blocks are merged, and the memory block status array is updated and the linked list of unallocated shared memory blocks; the process of moving the allocated memory blocks can adopt the idea of merge operation similar to merge sort, starting from both ends of the memory area, and moving the allocated memory blocks to the middle, each time moving a memory block size ; S32.
1. If shared memory transmission is used and there is enough free memory, wait to enter the critical area; After entering the critical area, search for a continuous free memory block that meets the size requirement in the unallocated shared memory block linked list; let the index of the found starting free memory block in the linked list be , the offset is , calculated as: ; This formula determines the starting position of the written data in the shared memory; Write data to the specified area of shared memory. Suppose the shared memory area is , the write operation is expressed as: ,in The value range is arrive ; The management information area records the relevant information of the data write, including the starting offset of the write. , Data size and write timestamp ;Write information recorded in a structure array In , let the array index be , the recording method is: , , ; The receiver obtains the notification of data writing completion through the interrupt processing mechanism of the inter-virtual machine communication module; The receiver reads data from the corresponding area of the shared memory according to the pre-agreed communication protocol; suppose the receiver reads data and stores it in the array In , the read operation is represented as: ,in The value range is arrive ; After the reading is completed, the receiver can send a confirmation signal to the sender to indicate that the data has been successfully received; the confirmation signal can be implemented through an inter-core interrupt or a specific flag bit in the shared memory; S33.
1. If it is determined in S31 that a shared memory resource needs to be applied for and the application conditions are met after the preparation stage, the resource application is formally carried out; Allocate a continuous memory block from the unallocated shared memory block list, and the allocation size is calculated previously ; Update the unallocated shared memory block linked list and remove the allocated memory block from the linked list; set the starting node of the allocated memory block in the linked list to , the update list operation is expressed as: , otherwise update the linked list head pointer; In memory block status array In , mark the corresponding allocated memory block position as allocated, and set the starting index of the allocated memory block in the memory block status array to , the marking operation is expressed as: ,in The value range is arrive , Indicates the number of allocated memory blocks; In the shared data area usage record in the management information area, add the resource information of this application, including the resource offset and resource size and the unique identifier of the application ; Assume that the shared data area usage record structure in the management information area is $Usage$, and the operation of adding a record is expressed as: , , ; Update the remaining free space information in the management information area, including the starting offset and size of the remaining free space; set the starting offset of the remaining free space to , the size is , calculated as follows: If the allocated memory block is the first memory block in the list of unallocated shared memory blocks, then ,otherwise ; ,in is the total size of the continuous free memory blocks previously counted; the operation of updating the remaining free information is represented by: updating the corresponding field in the management information area to the new and value.
7. The method for data interaction based on shared memory of an embedded virtualization platform according to claim 1, characterized in that: In step S4: Use the Szymanski algorithm to implement mutually exclusive access of the running area to the shared memory management information area, ensuring that only one running area can access the management information area at the same time to ensure data consistency; In the inter-virtual machine communication mode based on the combination of inter-core interrupts and shared memory, a synchronization module is implemented based on inter-core interrupts to coordinate data interaction between different virtual machines or running areas to ensure the correctness and integrity of data transmission.
8. The method for data interaction based on shared memory of an embedded virtualization platform according to claim 7, characterized in that: The specific steps of step S4 are: S41, the steps of using the Szymanski algorithm are as follows: in addition to the flag register allocated to each operation area by the original Szymanski algorithm, an auxiliary status register is added to each operation area ; Auxiliary status register Each bit of the register represents the access rights of the operation area to different parts of the management information area; set the auxiliary status register The length is , determined according to the division structure of the management information area, if it is divided into A key part, ; Initialize the auxiliary status register All bits of are 0, indicating that the running area does not have any access rights at the beginning; When the operation area needs to access the management information area, it first checks whether the corresponding flag register value meets the mutual exclusion condition, using the rules in the Szymanski algorithm; The flag register is ,like If the value of satisfies the mutually exclusive condition, proceed to the next step; Otherwise, wait until the condition is met; Determine the part of the management information area that needs to be accessed based on the access requirements and calculate the corresponding auxiliary status bit index ; For example, if you want to access the magic number part, determine it according to the pre-defined mapping relationship ; If you want to access the shared data area usage information section, make sure ; The run zone checks its auxiliary status register No. Place value; if , indicating that the current running area can obtain access rights to the management information area, set $A[j]$ to 1, and perform data access operations; if , indicating that other running areas are accessing this part and the current running area needs to wait; During the waiting process, the operation area can periodically check the auxiliary status register until access rights can be obtained; When the operation area completes access to a part of the management information area, the corresponding auxiliary status register The bit value is reset to 0 to release access rights; S42, Inter-core interrupt-based synchronization module: Assign an initial interrupt priority to each virtual machine or runtime area , the priority value range is , is the total number of operating zones in the system; the initial priority can be set based on factors such as the importance of the operating zone or the expected frequency of data interaction; The system maintains an interrupt priority adjustment factor matrix , whose elements Indicates the operating area For operation area The degree of data dependence; The degree of data dependency can be determined by analyzing historical data interaction records. For example, if the running area Frequently waiting for the running area The data can continue to execute, then If there is little data interaction between the two, then The value of is low; Periodically adjust the factor matrix based on interrupt priority Recalculate the interrupt priority of each operation area; the new interrupt priority calculation formula is: ,in is the total number of running zones in the system, is the weight factor; the function of this formula is to comprehensively consider the data dependency and historical priority between the operating areas, dynamically adjust the interrupt priority, and ensure the efficiency of data interaction; Define a unique interrupt vector for each possible data interaction event , Indicates the event type; the length of the interrupt vector is , The encoding method can be determined based on the number of event types in the system and the encoding requirements. The encoding method can use a hash function-like method to map the key information related to the event into a unique vector value. When a running area triggers a data interaction event, it sends the corresponding interrupt vector to the target running area. ; The target operation area sets an interrupt vector listener. When an interrupt vector is received, the event type and related information are parsed according to the value of the interrupt vector; Based on the information parsed from the interrupt vector, the target operation area determines how to respond to the data interaction request; Among them, if it is a shared memory write completion notification, the target operation area can read the latest data from the shared memory according to the pre-agreed protocol; if it is a data read request, the target operation area can prepare the corresponding data and send it back to the source operation area; S43, data interaction process combining mutually exclusive access and synchronization control: When the running area needs to perform data interaction (, first obtain access rights to the shared memory management information area in the manner optimized by the above-mentioned Szymanski algorithm, including checking the flag register and the auxiliary status register to determine whether the relevant information can be accessed; After obtaining access rights, the operation area prepares data according to data interaction requirements; For the operation of writing data to shared memory, after the operation area completes the data writing, it generates the corresponding interrupt vector according to the information such as data type and target operation area. , and trigger the inter-core interrupt to send a notification to the target running area; For the operation of reading shared memory data, the operation area first sends an interrupt vector with read request information. To the target operation area, and then wait for the target operation area to prepare data and send it back; during the waiting process, the operation area can perform appropriate waiting scheduling according to its own interrupt priority; After receiving the interrupt vector, the target operation area parses the event type according to the interrupt vector; if it is a write notification, the target operation area reads the data from the shared memory in the manner described above and performs corresponding processing; if it is a read request, the target operation area prepares the requested data, writes the data to the specified location of the shared memory, and sends an interrupt vector indicating that the data is ready To the source operation area; After the source operation area receives the interrupt vector indicating that the data is ready, it reads the data prepared by the target operation area from the shared memory and continues the subsequent data processing flow.
9. According to claim 1, a data interaction method based on shared memory for an embedded virtualization platform, Its characteristics are: in step S5: Release shared memory resources: When data interaction is completed, if the shared memory resources are no longer needed, the resource release operation can be performed to update the usage information of the shared data area in the management information area, such as marking the corresponding memory block as free; Notify relevant parties: In some cases, after data interaction is completed, it may be necessary to notify other relevant operating areas or virtual machines, such as sending notification signals through inter-core interrupts, to inform the other party that the data is ready or the data interaction is completed, so that the other party can perform subsequent processing.
10. The method for data interaction based on shared memory of an embedded virtualization platform according to claim 9, characterized in that: The specific scheme in step S5 is: S51, releasing shared memory resources: when it is determined that the shared memory resources are to be released, firstly, the memory block range to be released is determined according to the recorded shared memory usage information; assuming that the shared memory usage information structure is , which contains the offset where the resource is located and resource size ; Assume the memory block size is , calculate the starting index of the memory block that needs to be released and end index , the calculation formula is: , ; This formula accurately determines the location range of the memory block that needs to be released in the memory block status array based on the known offset and size information; Traverse the memory block status array , will be arrive The element value of is reset to a specific value indicating free; let the length of the memory block status array be , the update operation is expressed as: ,in The value range is arrive ; Update the unallocated shared memory block linked list; search the unallocated shared memory block linked list and find a suitable location to insert the released memory block; set the released memory block to , whose size is , the previous node is , the next node is ; If the linked list is empty, the released memory block is directly used as the head of the linked list; if the released memory block should be inserted into the head of the linked list, that is, its starting offset is less than the starting offset of the head node of the linked list, then the head pointer of the linked list is updated; otherwise, traverse the linked list to find a suitable insertion position. The insertion operation is expressed as: , ; S52, in the shared data area usage record in the management information area, delete or mark the resource record released this time as invalid; set the shared data area usage record array in the management information area to , traverse the array to find the record item corresponding to the released resource, mark it as invalid or delete it directly; Update the remaining free space information in the management information area, including the starting offset and size of the remaining free space; calculate the new starting offset of the remaining free space and size ; If the released memory block is the last block in the shared memory, that is, the remaining free area after release is at the end of the memory, then is the starting address of the shared memory, The size of the released memory block plus the size of the original remaining free area; otherwise, The starting offset of the next memory block to release the memory block. The size of the released memory block plus the size of the original remaining free area or only the size of the released memory block; the operation of updating the remaining free information is represented by: updating the corresponding field in the management information area to the new and value; S53, notify the relevant parties: in order to more richly and accurately notify the relevant parties of the completion of different types of data interaction, the encoding of the interrupt vector is extended; the interrupt vector The length is , divided into multiple fields; Bits are used to indicate the notification type. The bit is used to indicate the source runtime or virtual machine ID. Bits are used to represent additional information related to the notification; Define the notification type encoding rules; Among them, 0000 indicates that data writing is completed, 0001 indicates that data reading is completed, and 0010 indicates an interaction error, etc. The source operation area or virtual machine identifier is encoded using a unique number assigned by the system; additional information is encoded according to the specific meaning; The data size can be encoded in binary to represent the actual size, and the interaction result code can define different values to represent success, failure or other specific status; S54: When it is necessary to notify the relevant parties, an interrupt vector is generated according to the specific situation of the data interaction. ; Among them, if the data is written and the data size is , the source operation area is identified as , the interaction is successful, the interrupt vector generated The first 4 digits are 0000, and the middle 8 digits are The last 4 digits are The binary encoding of Send interrupt vectors to the target runtime or virtual machine through the inter-core interrupt mechanism ; The target operation area or virtual machine sets the interrupt vector listener. When receiving the interrupt vector, first parse the various fields of the interrupt vector; Set the received interrupt vector to , parse the notification type field , indicating that from the 0th to the bit, source operation area identification field , additional information fields ; According to the parsed notification type, the target operating area or virtual machine performs corresponding processing operations; if the notification type is data writing completion, the target operating area can read the latest data from the shared memory according to the source operating area identifier and additional information; if the notification type is interaction error, the target operating area can record the error information and adopt corresponding error handling strategies.
Citation Information
Cited By
Communication management machine system based on domestic single-chip microcomputer
CN119807129A
XDMA-based random trigger type data stream transmission method and device
CN120029950A
Virtual machine recovery method and device based on shared memory, medium and program product
CN120743439A