A data synchronization method and related apparatus
Patent Information
- Application Number
- CN202510576289.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-30
- Publication Date
- 2026-10-30
AI Technical Summary
[0004]但是,在相关技术中,针对于不同的处理单元之间需要共享的数据,为了保证共享数据的一致性,共享数据往往是只存储于所有处理单元都能够访问的全局存储介质中,导致处理单元访问共享数据时的效率较低
[0042]上述第二方面至第七方面的有益效果可以参考上述第一方面的介绍,在此不再赘述。
Smart Images

Figure CN123011545A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a data synchronization method and related apparatus. Background Technology
[0002] With the rapid development of computer technology, modern computers widely use multi-core architectures to perform data processing. In a multi-core architecture, a computer typically includes multiple processing units that can perform data processing in parallel.
[0003] Furthermore, in a multi-core architecture, to improve data processing efficiency, different processing units often use different local storage media to cache data, and different processing units exchange data using global storage media. Generally speaking, the speed at which a processing unit accesses local storage media is higher than the speed at which it accesses global storage media; therefore, processing units often cache frequently used data on local storage media.
[0004] However, in related technologies, for data that needs to be shared between different processing units, in order to ensure the consistency of the shared data, the shared data is often only stored in a global storage medium that can be accessed by all processing units, resulting in low efficiency when processing units access the shared data. Summary of the Invention
[0005] This application provides a data synchronization method that can improve the efficiency of processing units accessing shared data.
[0006] Firstly, a data synchronization method is provided, applied to an execution device having a global storage medium and a local storage medium. The data synchronization method includes: when a first instance running in a first processing unit requests access to shared data, the execution device acquires a target lock for the first instance. The target lock is a lock corresponding to the shared data located on the global storage medium, and the target lock is used to control the instance's access to the shared data. That is, the shared data stored on the global storage medium is managed by the target lock; therefore, when the first instance requests access to the shared data, the execution device needs to acquire the target lock for the first instance first. The first instance can be, for example, an entity such as a thread or a process.
[0007] If the first instance obtains the target lock, the execution device copies the shared data from the global storage medium to the first local storage medium used by the first processing unit, so that the first processing unit can access the shared data on the first local storage medium, wherein the first processing unit accesses the first local storage medium at a higher speed than it accesses the global storage medium.
[0008] When the target lock is released in the first instance, the execution device copies the updated shared data from the first local storage medium to the global storage medium. For example, the execution device can use the updated shared data to overwrite the original shared data on the global storage medium, thereby updating the shared data on the global storage medium.
[0009] In this scheme, by combining locks with shared data on the global storage medium, instances on a processing unit are allowed to copy shared data from the global storage medium to the local storage medium for processing when they acquire the lock, effectively improving the efficiency of shared data access. Furthermore, when an instance on a processing unit releases the lock, it also flushes the updated shared data from the local storage medium back to the global local storage medium to ensure the consistency of the shared data. Since locks can control instance access to shared data on the global storage medium, the combination of locks and shared data ensures the consistency of shared data across different processing units, preventing different processing units from accessing different shared data.
[0010] In one possible implementation, the data synchronization method is applied to an architecture comprising multiple sets of processing units, where each processing unit in the set can access a global storage medium, and different sets of processing units use different local storage media, with the first processing unit being a processing unit in the set of processing units.
[0011] In one possible implementation, if the second instance is unable to acquire the target lock, the execution device blocks the second instance when the second instance running in the second processing unit requests access to shared data located on the global storage medium.
[0012] In other words, when the first instance holds the target lock, the execution device can block the second instance because the second instance cannot acquire the target lock (at this time, the second instance is often suspended from execution and waits for the target lock to be released), meaning that the second instance cannot access the shared data in the global storage medium.
[0013] In this solution, when the lock corresponding to the shared data is already held by an instance, the lock is used to restrict other instances from accessing the shared data in the global storage medium. This can minimize the possibility that instances running on processing units with different local storage media will access different data content for the same shared data object, thereby ensuring the consistency of the shared data.
[0014] In one possible implementation, after the first instance releases the target lock and the second instance acquires the target lock, the execution device copies the updated shared data from the global storage medium to the second local storage medium corresponding to the second processing unit, so that the second processing unit can access the updated shared data on the second local storage medium.
[0015] In one possible implementation, the target lock is a read-write lock. If the first instance acquires the read lock on the target lock, the shared data stored on the global storage medium can be copied to a local storage medium other than the first local storage medium. That is, other instances running on other processing units can also acquire the read lock on the target lock, thereby triggering the copying of the shared data on the global storage medium to other local storage media.
[0016] In this solution, by combining read-write locks with shared data, multiple instances can read shared data simultaneously and efficiently, while ensuring the consistency of shared data across different local storage media, thus meeting the diverse software operation needs of users.
[0017] In one possible implementation, the read-write lock is a multi-read, single-write lock. Once the first instance acquires the write lock on the target lock, the shared data stored on the global storage medium is no longer allowed to be copied to a local storage medium other than the first local storage medium. That is, other instances running on other processing units cannot acquire the read and write locks on the target lock, and therefore cannot trigger the copying of shared data from the global storage medium to other local storage media.
[0018] In this solution, the target lock is implemented by using a multi-read single-write lock, which enables multiple instances to access shared data on the global storage medium simultaneously, and only one instance can modify the shared data on the global storage medium at any given time. This ensures that while improving the access efficiency of shared data, the consistency of shared data on different local storage media is guaranteed.
[0019] In one possible implementation, the read-write lock is a multi-read multi-write lock, where if the first instance acquires the write lock in the target lock, the shared data stored on the global storage medium is allowed to be copied to a local storage medium other than the first local storage medium.
[0020] In one possible implementation, a cache record table corresponding to the shared data is also stored on the global storage medium. The cache record table is used to indicate the validity status of the shared data cached on different local storage media.
[0021] If the first instance obtains the target lock and the cache record table indicates that the shared data cached on the first local storage medium is invalid, the execution device copies the shared data from the global storage medium to the first local storage medium corresponding to the first processing unit.
[0022] If the first instance obtains the target lock and the cache record table indicates that the shared data cached on the first local storage medium is valid, the execution device does not need to copy the shared data from the global storage medium to the first local storage medium corresponding to the first processing unit.
[0023] In this solution, by setting up a cache record table on the global storage medium to indicate whether the shared data cached on each local storage medium is valid, the consistency of the shared data used on the global storage medium and the local storage medium can be guaranteed, and frequent updates of the shared data on the local storage medium can be avoided, thereby reducing the resource consumption of the device.
[0024] In one possible implementation, after copying the updated shared data from the first local storage medium to the global storage medium, a device update cache record table is performed to obtain an updated cache record table. The updated cache record table is used to indicate that shared data cached on local storage media other than the first local storage medium is invalid.
[0025] In this solution, when an instance releases a write lock, the updated shared data in the local storage medium is flushed back to the global storage medium. The validity of the shared data already cached on other local storage media is also modified in the cache record table. This ensures that when other instances in the CC domain request access to the shared data, the latest shared data can be copied to the local storage medium, thus guaranteeing the consistency of shared data on different local storage media.
[0026] In one possible implementation, the target lock is a mutex lock. Once the first instance acquires the target lock, the shared data stored on the global storage medium is no longer allowed to be copied to a local storage medium other than the first local storage medium. That is, after the target lock is held by one instance, other instances are no longer allowed to access the shared data protected by the target lock.
[0027] Secondly, a data synchronization device is provided, comprising: a lock request module, configured to request a target lock for a first instance running in a first processing unit when the first instance requests access to shared data, the target lock being a lock corresponding to the shared data located on a global storage medium, the target lock being used to control the instance's access to the shared data; a processing module, configured to copy the shared data from the global storage medium to a first local storage medium used by the first processing unit when the first instance obtains the target lock, so that the first processing unit can access the shared data on the first local storage medium, wherein the speed at which the first processing unit accesses the first local storage medium is higher than the speed at which it accesses the global storage medium; and the processing module further configured to copy the updated shared data from the first local storage medium to the global storage medium when the first instance releases the target lock.
[0028] In one possible implementation, the data synchronization device is applied to an architecture comprising multiple sets of processing units, each of which can access a global storage medium, and different sets of processing units use different local storage media, wherein the first processing unit is a processing unit among the multiple sets of processing units.
[0029] In one possible implementation, the processing module is further configured to block the second instance when the second instance running on the second processing unit requests access to shared data located on the global storage medium, provided that the first processing unit holds the target lock, wherein the first processing unit and the second processing unit use different local storage media.
[0030] In one possible implementation, the processing module is further configured to copy the updated shared data from the global storage medium to the second local storage medium corresponding to the second processing unit after the first instance releases the target lock and the second instance acquires the target lock.
[0031] In one possible implementation, the target lock is a read-write lock. If the first instance obtains the read lock in the target lock, the shared data stored on the global storage medium is allowed to be copied to a local storage medium other than the first local storage medium.
[0032] In one possible implementation, the read-write lock is a multi-read single-write lock. If the first instance obtains the write lock in the target lock, the shared data stored on the global storage medium is no longer allowed to be copied to a local storage medium other than the first local storage medium.
[0033] In one possible implementation, the read-write lock is a multi-read multi-write lock, where if the first instance acquires the write lock in the target lock, the shared data stored on the global storage medium is allowed to be copied to a local storage medium other than the first local storage medium.
[0034] In one possible implementation, the global storage medium also stores a cache record table corresponding to the shared data. The cache record table is used to indicate the validity status of the shared data cached on different local storage media. The processing module is also used to copy the shared data from the global storage medium to the first local storage medium corresponding to the first processing unit when the first instance obtains the target lock and the cache record table indicates that the shared data cached on the first local storage medium is invalid.
[0035] In one possible implementation, after copying the updated shared data from the first local storage medium to the global storage medium, the processing module is further configured to update the cache record table to obtain an updated cache record table; wherein the updated cache record table is used to indicate that the shared data cached on a local storage medium other than the first local storage medium is invalid.
[0036] In one possible implementation, the target lock is a mutex lock. If the first instance obtains the target lock, the shared data stored on the global storage medium is no longer allowed to be copied to a local storage medium other than the first local storage medium.
[0037] A third aspect of this application provides a data synchronization apparatus, which may include a processor and a memory coupled together. The memory stores program instructions, and when the program instructions stored in the memory are executed by the processor, the method described in the first aspect or any implementation thereof is implemented. For details regarding the steps of the various possible implementations of the first aspect executed by the processor, please refer to the first aspect; further details will not be repeated here.
[0038] The fourth aspect of this application provides a computer-readable storage medium storing a computer program that, when run on a computer, causes the computer to perform the method of any implementation of the first aspect described above.
[0039] The fifth aspect of this application provides a circuit system including a processing circuit configured to perform the method of any implementation of the first aspect described above.
[0040] The sixth aspect of this application provides a computer program product that, when run on a computer, causes the computer to perform any implementation of the first aspect described above.
[0041] A seventh aspect of this application provides a chip system including a processor for implementing the functions involved in any implementation of the first aspect, such as processing data and / or information involved in the methods described above. In one possible design, the chip system further includes a memory for storing necessary program instructions and data. This chip system may be composed of chips or may include chips and other discrete devices.
[0042] The beneficial effects of the second to seventh aspects mentioned above can be referred to the introduction of the first aspect above, and will not be repeated here. Attached Figure Description
[0043] Figure 1 A schematic diagram of an application scenario provided in this application;
[0044] Figure 2A flowchart illustrating a data synchronization method provided in this application;
[0045] Figure 3 A schematic diagram illustrating an example of accessing shared data by requesting a lock, as provided in this application;
[0046] Figure 4 This application provides a schematic diagram illustrating an instance of releasing the lock and flushing shared data.
[0047] Figure 5 A schematic diagram illustrating the process of requesting and releasing a mutex lock for the purposes of this application;
[0048] Figure 6 A schematic diagram illustrating the implementation of a target lock and a cache record table provided in this application;
[0049] Figure 7 A schematic diagram of a read lock in an example application of a multi-read single-write lock provided in this application;
[0050] Figure 8 A schematic diagram illustrating the release of a read lock in a multi-read single-write lock as provided in this application;
[0051] Figure 9 A schematic diagram illustrating the release of a write lock in a multi-read single-write lock as provided in this application;
[0052] Figure 10 A schematic diagram of the structure of a data synchronization device provided in this application;
[0053] Figure 11 A schematic diagram of the structure of an execution device provided in this application;
[0054] Figure 12 This is a schematic diagram of the structure of a computer-readable storage medium provided in this application. Detailed Implementation
[0055] To make the objectives, technical solutions, and advantages of this application clearer, the embodiments of this application are described below with reference to the accompanying drawings. Obviously, the described embodiments are merely some, and not all, of the embodiments of this application. Those skilled in the art will understand that, with the emergence of new application scenarios, the technical solutions provided by the embodiments of this application are also applicable to similar technical problems.
[0056] The terms "first," "second," etc., used in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such descriptions can be used interchangeably where appropriate to allow embodiments to be implemented in a sequence other than that illustrated or described in this application. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or device that includes a series of steps or modules is not necessarily limited to those explicitly listed, but may include other steps or modules not explicitly listed or inherent to such processes, methods, products, or devices. The naming or numbering of steps appearing in this application does not imply that the steps in the method flow must be performed in the chronological / logical order indicated by the naming or numbering. The execution order of named or numbered process steps can be changed according to the desired technical purpose, as long as the same or similar technical effect is achieved. The division of units in this application is a logical division. In practical applications, there may be other division methods. For example, multiple units may be combined or integrated into another system, or some features may be ignored or not executed. In addition, the shown or discussed mutual coupling, direct coupling, or communication connection may be through some interface, and the indirect coupling or communication connection between units may be electrical or other similar forms, none of which are limited in this application. Furthermore, the units or sub-units described as separate components may or may not be physically separated, may or may not be physical units, or may be distributed among multiple circuit units. Some or all of the units can be selected to achieve the purpose of the solution in this application according to actual needs.
[0057] To facilitate understanding, some technical terms used in this application will be introduced below.
[0058] (1) Lock
[0059] A lock is an abstract control structure used to restrict access to shared resources in a concurrent environment. When a thread or process acquires a lock, other threads / processes must wait for the lock to be released before accessing the resource, thus avoiding data inconsistency issues. Common locks generally include mutex locks and read-write locks.
[0060] (2) Mutex lock
[0061] A mutex is a common synchronization mechanism used to ensure that only one thread can access a shared resource at any given time. Mutexes provide two main operations: locking and unlocking. When a thread needs to access a shared resource, it must first acquire the mutex; after the thread has finished accessing the shared resource, it must release the mutex to allow other threads to access the shared resource.
[0062] (3) Read-write lock
[0063] Generally, a read-write lock refers to a multi-read, single-write lock. That is, a read-write lock allows multiple threads to read a shared resource simultaneously, but only one thread can write to the shared resource at a time. This locking mechanism is suitable for scenarios where read operations far outnumber write operations because it improves concurrency performance. A read-write lock includes two states: read mode and write mode. When multiple threads attempt to access a shared resource in read mode, if no thread is currently accessing it in write mode, these read operations can be performed concurrently; however, write operations are exclusive, and only one thread can perform a write operation at a time.
[0064] Please see Figure 1 , Figure 1 This is a schematic diagram of an application scenario provided in this application. (For example...) Figure 1 As shown, the data synchronization method provided in this application can be applied to terminal device 10, which can be, for example, a personal computer, laptop, smart car, smartphone, smartwatch, server, or IoT device with a multi-core architecture. Terminal device 10 includes multiple processing units (e.g., processing unit 101 and processing unit 102). Furthermore, different processing units may use different local storage media. For example, processing unit 101 uses local storage media 103, and processing unit 102 uses local storage media 104. Of course, different processing units may also use the same local storage media; for example, processing unit 101 may also share local storage media 103 with other processing units.
[0065] When processing units on terminal device 10 use local storage media, terminal device 10 can often be divided into multiple coherent cache (CC) domains. For example, a CC domain may include one processing unit, such as a CC domain containing only one processing core. A CC domain may also include multiple processing units, such as multiple processing cores in a cluster within a System on Chip (SoC). Processing units within the same CC domain use the same local storage media (e.g., local cache), and the local storage media within the same CC domain have data consistency (i.e., data consistency can be maintained through hardware), while the local storage media of different CC domains do not have data consistency. Therefore, for a given data object, different processing units within the same CC domain can access the same data content at the same time, while different processing units within different CC domains may access different data content.
[0066] The terminal device 10 also has a global storage medium 105, which is a storage medium that can be used by all processing units. That is, all processing units on the terminal device 10 can access the global storage medium 105.
[0067] Please see Figure 2 , Figure 2 This is a flowchart illustrating a data synchronization method provided in this application. Figure 2 As shown, the data synchronization method can be implemented by software or operating system in the execution device, and the execution flow of the data synchronization method includes the following steps 201-203.
[0068] Step 201: When the first instance running in the first processing unit requests access to shared data, a target lock is requested for the first instance. The target lock is the lock corresponding to the shared data located on the global storage medium. The target lock is used to control the instance's access to the shared data.
[0069] In this application, the first instance runs on the first processing unit, and the first instance can be an entity such as a thread or a process. Furthermore, during its execution, the first instance requests access to shared data stored on a global storage medium. Since the shared data stored on the global storage medium is managed by a target lock, the execution device needs to acquire the target lock for the first instance before it requests access to the shared data. That is, for any instance, it needs to acquire the target lock corresponding to the shared data before accessing it.
[0070] The global storage medium can be, for example, a global cache or global memory that can be used by multiple processing units in the execution device.
[0071] Furthermore, the data synchronization method provided in this application can be applied to an architecture comprising multiple processing unit sets, each processing unit set including one or more processing units. Processing units in multiple processing unit sets can all access the global storage medium, and different processing unit sets use different local storage media. The first processing unit is a processing unit within multiple processing unit sets. Simply put, a processing unit set can be understood as a processing unit within a single CC domain, as described above. Therefore, processing units within the same processing unit set (i.e., processing units within the same CC domain) will use the same local storage medium, while processing units in different processing unit sets (i.e., processing units in different CC domains) will use different local storage media.
[0072] Step 202: If the first instance obtains the target lock, the shared data is copied from the global storage medium to the first local storage medium used by the first processing unit, so that the first processing unit can access the shared data on the first local storage medium, wherein the speed at which the first processing unit accesses the first local storage medium is higher than the speed at which it accesses the global storage medium.
[0073] When the first instance has acquired the target lock, it can access the shared data from the global storage medium. For example, the first processing unit running the first instance can copy the shared data from the global storage medium to a register to enable the first instance to access the shared data. Simultaneously, since the shared data is not cached on the first local storage medium used by the first processing unit running the first instance, the execution device can copy the shared data from the global storage medium to the first local storage medium used by the first processing unit. In this way, when the first instance subsequently uses the shared data, it no longer needs to retrieve it from the global storage medium but can directly obtain it from the first local storage medium, thereby improving the efficiency of shared data access. For instance, while the first instance holds the target lock, it may need to access the shared data multiple times; copying the shared data to the first local storage medium improves the efficiency of each access.
[0074] The first local storage medium may be, for example, a local cache or local memory that can be used by the first processing unit in the execution device.
[0075] Of course, after the shared data is copied to the first local storage medium, if other instances running on the first processing unit also acquire the target lock, then the other instances can also obtain the shared data by directly accessing the first local storage medium without having to obtain the shared data from the global storage medium.
[0076] In summary, after the shared data is copied to the first local storage medium, the processing unit using the first local storage medium can access the shared data by accessing the first local storage medium, thereby improving the access efficiency of the shared data.
[0077] For example, please refer to Figure 3 , Figure 3 This illustration illustrates an example of accessing shared data via a lock request, as provided in this application. Figure 3 As shown, the terminal device includes multiple CC domains (e.g., CC domain 1-CC domain N), and CC domain 1 includes a first processing unit and a first local storage medium. Optionally, in addition to the first processing unit, CC domain 1 may also include other processing units.
[0078] exist Figure 3 In the example shown, firstly, when the first instance running in the first processing unit needs to access shared data on the global storage medium, a target lock corresponding to the shared data is first acquired for the first instance. Then, after the first instance acquires the target lock, the shared data is synchronized from the global storage medium to the first local storage medium in CC domain 1. Secondly, while holding the target lock, the first instance on the first processing unit can directly access the shared data on the first local storage medium to improve the efficiency of accessing the shared data.
[0079] Step 203: If the first instance releases the target lock, copy the updated shared data from the first local storage medium to the global storage medium.
[0080] In this application, while the first instance holds the target lock, it may modify the shared data cached on the first local storage medium. This results in the first local storage medium storing the updated shared data, while the global storage medium stores the original shared data. Therefore, when the first instance releases the target lock, if the shared data was updated by the first instance while cached on the first local storage medium, the execution device needs to copy the updated shared data from the first local storage medium to the global storage medium to maintain the consistency of the shared data. For example, the execution device can use the updated shared data to overwrite the original shared data on the global storage medium, thereby updating the shared data on the global storage medium.
[0081] Optionally, during the period when the first instance modifies the shared data, the execution device can record the scope and content of the modifications to the shared data through hardware or software. In this way, when the execution device needs to update the shared data on the global storage medium based on the updated shared data on the first local storage medium, the execution device no longer needs to copy the entire updated shared data from the first local storage medium to the global storage medium; instead, it only needs to copy the modified portion of the shared data, thereby improving the synchronization efficiency of the shared data.
[0082] For example, please refer to Figure 4 , Figure 4 This is a schematic diagram illustrating an example of releasing a lock and flushing shared data provided in this application. For example... Figure 4 As shown, when the first instance on the first processing unit prepares to release the target lock, it triggers a data flush, meaning the updated shared data on the first local storage medium needs to be synchronized to the global storage medium. Then, the updated shared data on the first local storage medium is synchronized to the global storage medium, thus updating the shared data stored on the global storage medium. Finally, the first instance on the first processing unit releases the target lock so that other instances requesting access to the shared data can acquire the target lock.
[0083] In summary, this application combines locks with shared data, maintaining the consistency of shared data across different CC domains through the lock acquisition and release process. When an instance within a CC domain acquires a lock, the lock restricts access to the shared data by instances in other CC domains, allowing the shared data to be cached from the global storage medium to the local storage medium within the CC domain, thereby improving the efficiency of shared data access. Furthermore, when an instance within a CC domain releases the lock, the updated shared data is flushed back to the global storage medium, ensuring the consistency of the shared data so that instances in other CC domains can access the latest version of the shared data from the global storage medium when they acquire the lock.
[0084] It should be noted that if the first instance does not modify the shared data cached on the first local storage medium while the first instance holds the target lock, then when the first instance releases the target lock, since the shared data stored on the first local storage medium and the global storage medium are the same, the execution device does not need to copy the shared data on the first local storage medium to the global storage medium.
[0085] Furthermore, the above describes the access process for a single piece of shared data. In practical applications, the global storage medium can store one or more pieces of shared data, and each piece of shared data can have a corresponding lock. This allows instances on the processing unit to access any piece of shared data by referring to steps 201-203 above.
[0086] Optionally, if the second instance fails to acquire the target lock, the second instance running in the second processing unit may block when it requests access to shared data located on the global storage medium. The first and second processing units may use different local storage media.
[0087] In other words, when the first instance holds the target lock, the execution device can block the second instance because the second instance cannot acquire the target lock (at this time, the second instance is often suspended from execution and waits for the target lock to be released). This means the second instance cannot access the shared data in the global storage medium. Furthermore, when the second instance is blocked, the execution device will not trigger the synchronization of the shared data in the global storage medium to the local storage medium used by the second processing unit.
[0088] In this way, when the lock corresponding to the shared data is already held by an instance, the lock restricts other instances' access to the shared data in the global storage medium. This can minimize the possibility that instances running on processing units with different local storage media will access different data content for the same shared data object, thereby ensuring the consistency of the shared data.
[0089] Optionally, after the first instance releases the target lock and the second instance acquires the target lock, the execution device copies the updated shared data from the global storage medium to the second local storage medium corresponding to the second processing unit, so that the second instance can access the latest version of the shared data on the second local storage medium.
[0090] To facilitate understanding, the following will describe how instances running on the processing unit achieve access to shared data when various types of locks are combined with shared data.
[0091] Implementation method 1, the target lock is a mutex lock.
[0092] When the target lock is a mutex lock, the target lock can only be held by one instance. That is, once the target lock is held by one instance, other instances are no longer allowed to access the shared data protected by the target lock.
[0093] Therefore, once the first instance obtains the target lock, other instances besides the first instance no longer have permission to access the shared data on the global storage medium. Consequently, the shared data stored on the global storage medium is no longer allowed to be copied to a local storage medium other than the first local storage medium.
[0094] In this way, by setting the target lock as a mutex lock, it can be ensured that shared data on the global storage medium will not be synchronized to other local storage media when it is accessed by a certain instance synchronized to the local storage medium. This avoids caching different data content on different local storage media and thus ensures the consistency of shared data on different local storage media.
[0095] For example, please refer to Figure 5 , Figure 5 This is a schematic diagram illustrating an example of requesting and releasing a mutex lock, provided for the purposes of this application. Figure 5 As shown in (a), when the first instance running in the first processing unit needs to access shared data on the global storage medium, it first requests a mutex lock corresponding to the shared data. After the first instance obtains the mutex lock, the shared data is synchronized from the global storage medium to the first local storage medium in CC domain 1, so that the first instance on the first processing unit can directly access the shared data on the first local storage medium while holding the mutex lock, thereby improving the access efficiency of the shared data. Furthermore, while the first instance holds the mutex lock, when the second instance running in the second processing unit in CC domain N requests to access the shared data on the global storage medium, it will be blocked because it cannot obtain the mutex lock, thus preventing it from accessing the shared data on the global storage medium and thus preventing the shared data on the global storage medium from being cached on the second local storage medium in CC domain N.
[0096] like Figure 5 As shown in (b), when the first instance on the first processing unit prepares to release the mutex, it triggers a data flush, meaning the updated shared data on the first local storage medium needs to be synchronized to the global storage medium. Then, the updated shared data on the first local storage medium is synchronized to the global storage medium to update the shared data stored therein. Afterward, the first instance on the first processing unit releases the mutex, allowing other instances requesting access to the shared data to acquire the target lock. Then, after the first instance releases the mutex, the second instance can acquire the mutex and synchronize the updated shared data from the global storage medium to the second local storage medium in the CC domain N, so that the second instance on the second processing unit can directly access the shared data on the second local storage medium while holding the mutex.
[0097] Implementation method 2, the target lock is a read-write lock.
[0098] It should be noted that when the target lock is a read-write lock, there can be several different implementations of the read-write lock.
[0099] Case 1: The read-write lock is a multi-read, single-write lock.
[0100] The multi-read single-write lock allows multiple instances to hold read locks simultaneously, meaning multiple instances can access shared data on the global storage medium at the same time. Furthermore, only one instance can hold a write lock at a time, and read and write locks are mutually exclusive. That is, if one instance holds a write lock, other instances cannot hold read locks; conversely, if one instance holds a read lock, other instances cannot hold write locks.
[0101] For example, if the target lock is a multi-read single-write lock, and the first instance acquires a read lock on the target lock, the shared data stored on the global storage medium can be copied to a local storage medium other than the first local storage medium. That is, other instances running on other processing units can also acquire a read lock on the target lock, thereby triggering the copying of shared data on the global storage medium to other local storage media.
[0102] For example, while the first instance is acquiring a read lock on the target lock, a second instance running on the second processing unit acquires a read lock on the target lock, triggering a copy of the shared storage on the global storage medium to the second local storage medium used by the second processing unit. This allows the second instance to continuously and quickly access the shared data while holding the read lock. At this time, since both the first and second instances hold read locks, neither instance modifies the shared data, thus allowing the shared data on the global storage medium to be simultaneously copied to different local storage media for use.
[0103] Optionally, if the target lock is a multi-read, single-write lock, and the first instance acquires the write lock on the target lock, the shared data stored on the global storage medium is no longer allowed to be copied to a local storage medium other than the first local storage medium. That is, other instances running on other processing units cannot acquire the read and write locks on the target lock, and therefore cannot trigger the copying of the shared data on the global storage medium to other local storage media.
[0104] For example, if a second instance requests access to shared data on the global storage medium when the first instance acquires the write lock in the target lock, the second instance will be blocked. That is, the second instance needs to wait for the target lock to be released, so the second instance cannot access the shared data on the global storage medium temporarily.
[0105] In other words, when the first instance requests to modify shared data on the global storage medium, the first instance will acquire the write lock in the target lock, thereby ensuring that only the first instance can hold the target lock at the same time. This ensures that the shared data on the global storage medium will not be copied to other local storage media by other instances, effectively guaranteeing the consistency of shared data on different local storage media.
[0106] In this solution, the target lock is implemented by using a multi-read single-write lock, which enables multiple instances to access shared data on the global storage medium simultaneously, and only one instance can modify the shared data on the global storage medium at any given time. This ensures that while improving the access efficiency of shared data, the consistency of shared data on different local storage media is guaranteed.
[0107] Understandably, when the target lock includes both read and write locks, if an instance requests a read lock, it typically will not modify the shared data cached on the local storage medium; conversely, if an instance requests a write lock, it will modify the shared data cached on the local storage medium. If shared data is cached on a local storage medium due to an instance's access request, the cached shared data on the local storage medium may remain consistent with the shared data on the global storage medium because no instance requests modification of the shared data there. Conversely, the cached shared data on the local storage medium may become inconsistent with the shared data on the global storage medium because other instances have modified it. Therefore, to ensure the consistency of shared data used on the global and local storage media and to avoid frequent updates to shared data on the local storage medium, this application proposes setting up a cache record table on the global storage medium to indicate whether the shared data cached on each local storage medium is valid.
[0108] For example, the global storage medium also stores a cache record table corresponding to the shared data, which is used to indicate the validity status of the shared data cached on different local storage media.
[0109] If the first instance acquires the target lock and the cache record table indicates that the shared data cached on the first local storage medium is invalid, the execution device copies the shared data from the global storage medium to the first local storage medium corresponding to the first processing unit. That is, the shared data cached on the first local storage medium is not actually consistent with the shared data stored on the global storage medium (for example, the shared data stored on the global storage medium has been updated). Therefore, the execution device needs to copy the shared data from the global storage medium to the first local storage medium to ensure that the first local storage medium can cache the latest version of the shared data.
[0110] If the first instance acquires the target lock and the cache record table indicates that the shared data cached on the first local storage medium is valid, the execution device does not need to copy the shared data from the global storage medium to the first local storage medium corresponding to the first processing unit. That is, the shared data cached on the first local storage medium is actually consistent with the shared data stored on the global storage medium. Therefore, the first instance can directly access the shared data cached on the first local storage medium without having to copy the shared data from the global storage medium to the first local storage medium.
[0111] The cache record table can be implemented in the form of a bitmap, array, or linked list, etc., and this application does not impose any specific limitations on it. Furthermore, the cache record table can indicate the validity of shared data cached on the local storage medium by recording the value of a flag bit or a version number.
[0112] For example, please refer to Figure 6 , Figure 6 This is a schematic diagram illustrating the implementation of a target lock and a cache record table provided in this application. Figure 6 As shown, the shared data on the global storage medium corresponds to a multi-read single-write lock and a cache record table. The cache record table includes flag bits, and the values of these flag bits indicate the validity of the shared data cached on the local storage medium within each CC domain. For example, if the terminal device includes N CC domains, and each CC domain includes an independent local storage medium, the cache record table includes N flag bits, and each flag bit corresponds to one of the CC domains (i.e., multiple CC domains correspond one-to-one with multiple flag bits). When a flag bit is 0, it means that the shared data cached on the local storage medium in the CC domain corresponding to that flag bit is invalid. For example, Figure 6 A value of 0 for the second flag indicates that the shared data cached on the local storage medium in CC domain 2 is invalid. A value of 1 for a flag indicates that the shared data cached on the local storage medium in the corresponding CC domain is valid. For example, Figure 6 The value of the first flag bit is 1, which means that the shared data cached on the local storage medium in CC domain 1 is valid.
[0113] Of course, when the cache record table indicates the validity of shared data cached on the local storage medium by recording the version number of the shared data, the cache record table can record the version number of the shared data cached on each local storage medium. If the version number of the shared data cached on the local storage medium is not the latest version number, then it means that the shared data cached on that local storage medium is invalid; if the version number of the shared data cached on the local storage medium is the latest version number, then it means that the shared data cached on that local storage medium is valid.
[0114] Optionally, if the first instance acquires a write lock on the target lock and updates the shared data on the first local storage medium, when the first instance releases the target lock, the execution device copies the updated shared data from the first local storage medium to the global storage medium, and then continues to update the cache record table to obtain an updated cache record table. The updated cache record table is used to indicate that shared data cached on local storage media other than the first local storage medium is invalid.
[0115] In other words, if the first instance requests a write lock and updates the shared data cached on the first local storage medium, then after the execution device flushes the updated shared data from the first local storage medium to the global storage medium, it needs to synchronously modify the cache record table. This is because the shared data on the global storage medium has already been updated, thus the shared data on other local storage media is effectively invalid.
[0116] In this solution, when an instance releases a write lock, the updated shared data in the local storage medium is flushed back to the global storage medium. The validity of the shared data already cached on other local storage media is also modified in the cache record table. This ensures that when other instances in the CC domain request access to the shared data, the latest shared data can be copied to the local storage medium, thus guaranteeing the consistency of shared data on different local storage media.
[0117] Specifically, please refer to Figure 7 , Figure 7 This is a schematic diagram of a read lock in a multi-read single-write lock provided in this application. Figure 7As shown, assuming the execution device includes CC domains 1-N, and different CC domains use different local storage media (e.g., local storage media 1-local storage media N), when an instance running on processing unit 1 in CC domain 1 requests to read shared data, it first acquires a read lock on the shared data on the global storage media for that instance. Then, the execution device queries the cache record table corresponding to the shared data to determine whether the shared data already cached on local storage media 1 in CC domain 1 needs to be invalidated. If the query of the cache record table confirms that the shared data already cached on local storage media 1 needs to be invalidated, the execution device invalidates the shared data already cached on the local storage media (e.g., reclaims the storage space on the local storage media used to store invalid shared data). Furthermore, the execution device synchronizes the shared data on the global storage media to local storage media 1 so that instances on processing unit 1 can subsequently access the shared data from local storage media 1 efficiently. In addition, after synchronizing the shared data on the global storage media to local storage media 1, the execution device can update the cache record table to record that the shared data cached on local storage media 1 in CC domain 1 is valid.
[0118] Of course, if the execution device finds that the shared data cached on local storage medium 1 is valid, then the execution device no longer needs to synchronize the shared data from the global storage medium to local storage medium 1, nor does it need to update the cache record table. Furthermore, the instance on processing unit 1 can directly access the shared data on local storage medium 1.
[0119] In other words, by setting up a cache record table for shared data on the global storage medium, different versions of shared data can be cached on different local storage media. The shared data on the local storage media is only updated when an instance within the CC domain actually needs to access it. This avoids the need to update all cached shared data on the local storage media every time the shared data on the global storage medium is updated, reducing the resource consumption for ensuring data consistency. For example, suppose an instance in CC domain 1 triggers the caching of shared data from the global storage medium to local storage medium 1 at time point 1. Then, after time point 1, even if instances in other CC domains trigger updates to the shared data on the global storage medium multiple times, the shared data cached on local storage medium 1 of CC domain 1 will not be updated frequently. Instead, it will only be triggered when an instance in CC domain 1 requests access to the shared data again and acquires the lock, at which point the updated versions of the shared data in the global storage medium will be synchronized to local storage medium 1.
[0120] Furthermore, when the latest version of the shared data is already cached on the local storage medium, an instance in the CC domain can directly and continuously access the shared data from the local storage medium after acquiring the lock, without having to repeatedly synchronize the shared data from the global storage medium to the local storage medium.
[0121] It should be noted that when an instance on the processing unit requests a write lock in a multi-read single-write lock, the process executed by the execution device is similar to the process executed when an instance on the processing unit requests a read lock. The only difference is that the lock requested by the instance is different, which will not be elaborated here.
[0122] Please see Figure 8 , Figure 8 This is a schematic diagram illustrating the release of a read lock in a multi-read, single-write lock, as provided in this application. Figure 8 As shown, when an instance running on processing unit 1 in CC domain 1 needs to release a read lock that it has already acquired, it can directly execute the read lock release procedure. Furthermore, since the instance is acquiring a read lock, it will only read the shared data after acquiring the lock and will not modify the shared data. This ensures that the shared data cached in local storage medium 1 is the same as the shared data stored in global storage medium. Therefore, the execution device does not need to flush the shared data from local storage medium 1 to global storage medium.
[0123] Please see Figure 9 , Figure 9 This is a schematic diagram illustrating the release of a write lock in a multi-read, single-write lock, as provided in this application. Figure 9 As shown, when an instance running in processing unit 1 needs to release a write lock, it first triggers a flush of the updated shared data on local storage medium 1 to the global storage medium. After copying the updated shared data from local storage medium 1 to the global storage medium to replace the original shared data, the execution device continues to update the cache record table so that the cache record table can record invalid shared data cached on local storage media in CC domains other than CC domain 1. Finally, the execution device releases the write lock for the instance running in processing unit 1 so that other instances can acquire read or write locks.
[0124] Case 2: The read-write lock is a multi-read, multi-write lock.
[0125] When a read-write lock is a multi-read, multi-write lock, the execution device allows multiple instances to hold read locks simultaneously, or multiple instances to hold write locks simultaneously, or multiple instances to hold read locks or write locks separately (i.e., read locks and write locks are not mutually exclusive). In this case, if the first instance acquires the write lock in the target lock, the shared data stored on the global storage medium can be copied to a local storage medium other than the first local storage medium. That is, after the first instance acquires the write lock, other instances can also continue to acquire read locks or write locks, thereby triggering the copying of shared data on the global storage medium to other local storage media.
[0126] For example, in scenarios where the execution device instances do not have high requirements for the accuracy of shared data but have high requirements for access efficiency, combining read-write locks with shared data can ensure the efficiency of each instance accessing the shared data as much as possible.
[0127] When the read-write lock is a multi-read multi-write lock, the acquisition and release process of the multi-read multi-write lock is similar to that of the multi-read single-write lock. Furthermore, the multi-read multi-write lock can also have a corresponding cache record table, as detailed in the above embodiments. The difference between the multi-read multi-write lock and the multi-read single-write lock is that in the multi-read multi-write lock, the write lock and read lock are not mutually exclusive, and the write lock can be held by multiple instances simultaneously.
[0128] The methods provided in the embodiments of this application have been described in detail above. Next, the device for performing the above methods provided in the embodiments of this application will be described.
[0129] Please see Figure 10 , Figure 10 This is a schematic diagram of a data synchronization device provided in this application. Figure 10 As shown, the data synchronization device includes: a lock request module 1001, used to request a target lock for the first instance when the first instance running in the first processing unit requests access to shared data. The target lock is a lock corresponding to the shared data located on the global storage medium, and the target lock is used to control the instance's access to the shared data; a processing module 1002, used to copy the shared data from the global storage medium to the first local storage medium used by the first processing unit when the first instance obtains the target lock, so that the first processing unit can access the shared data on the first local storage medium, wherein the speed at which the first processing unit accesses the first local storage medium is higher than the speed at which it accesses the global storage medium; the processing module 1002 is also used to copy the updated shared data from the first local storage medium to the global storage medium when the first instance releases the target lock.
[0130] In one possible implementation, the apparatus is applied to an architecture comprising multiple sets of processing units, wherein the processing units in the multiple sets of processing units can access a global storage medium, and different sets of processing units use different local storage media, wherein the first processing unit is a processing unit in the multiple sets of processing units.
[0131] In one possible implementation, the processing module 1002 is further configured to block the second instance when the second instance running in the second processing unit requests access to shared data located on the global storage medium if the second instance is unable to acquire the target lock.
[0132] In one possible implementation, the processing module 1002 is further configured to copy the updated shared data from the global storage medium to the second local storage medium corresponding to the second processing unit after the first instance releases the target lock and the second instance acquires the target lock.
[0133] In one possible implementation, the target lock is a read-write lock. If the first instance obtains the read lock in the target lock, the shared data stored on the global storage medium is allowed to be copied to a local storage medium other than the first local storage medium.
[0134] In one possible implementation, the read-write lock is a multi-read single-write lock. If the first instance obtains the write lock in the target lock, the shared data stored on the global storage medium is no longer allowed to be copied to a local storage medium other than the first local storage medium.
[0135] In one possible implementation, the read-write lock is a multi-read multi-write lock, where if the first instance acquires the write lock in the target lock, the shared data stored on the global storage medium is allowed to be copied to a local storage medium other than the first local storage medium.
[0136] In one possible implementation, the global storage medium also stores a cache record table corresponding to the shared data. The cache record table is used to indicate the validity status of the shared data cached on different local storage media. The processing module 1002 is also used to copy the shared data from the global storage medium to the first local storage medium corresponding to the first processing unit when the first instance obtains the target lock and the cache record table indicates that the shared data cached on the first local storage medium is invalid.
[0137] In one possible implementation, after copying the updated shared data from the first local storage medium to the global storage medium, the processing module 1002 is further used to update the cache record table to obtain an updated cache record table; wherein the updated cache record table is used to indicate that the shared data cached on a local storage medium other than the first local storage medium is invalid.
[0138] In one possible implementation, the target lock is a mutex lock. If the first instance obtains the target lock, the shared data stored on the global storage medium is no longer allowed to be copied to a local storage medium other than the first local storage medium.
[0139] Please see Figure 11 , Figure 11 This is a schematic diagram of the structure of an execution device provided in this application. Figure 11 As shown, the execution device 1100 can specifically manifest as a smartphone, personal computer, laptop computer, tablet computer, smart car, or server, etc., without limitation. Specifically, the execution device 1100 includes: a receiver 1101, a transmitter 1102, a processor 1103, local memory 1104, and global memory 1105. The execution device 1100 can have multiple processors 1103. Figure 11 Only one processor is shown in the diagram; the number of local memories 1104 in execution device 1100 can be multiple. Figure 11 Only one local memory is shown. Furthermore, a local memory and one or more processors constitute a CC domain, thereby enabling execution device 1100 to include multiple CC domains. Processor 1103 may include application processor 11031 and communication processor 11032. In some embodiments of this application, receiver 1101, transmitter 1102, processor 1103, and local memory 1104 may be connected via a bus or other means.
[0140] Local memory 1104 may include read-only memory (ROM) and random access memory (RAM), and provides instructions and data to processor 1103. A portion of local memory 1104 may also include non-volatile random access memory (NVRAM). Local memory 1104 stores processor and operation instructions, executable modules, or data structures, or subsets thereof, or extended sets thereof, wherein operation instructions may include various operation instructions for implementing various operations.
[0141] Processor 1103 controls the operation of the execution device. In specific applications, the various components of the execution device are coupled together through a bus system, which may include not only the data bus, but also power buses, control buses, and status signal buses. However, for clarity, all buses are referred to as the bus system in the diagram.
[0142] The methods disclosed in the embodiments of this application described above can be applied to processor 1103, or implemented by processor 1103. Processor 1103 can be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the integrated logic circuit of the hardware in processor 1103 or by instructions in the form of software. The processor 1103 described above can be a CPU, GPU, NPU, digital signal processor (DSP), microprocessor or microcontroller, and may further include application-specific integrated circuit (ASIC), field-programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.
[0143] The processor 1103 can implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of this application. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the methods disclosed in the embodiments of this application can be directly implemented by a hardware decoding processor, or implemented by a combination of hardware and software modules in the decoding processor. The software modules can reside in random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, or other mature storage media in the art. This storage medium is located in local memory 1104. The processor 1103 reads information from local memory 1104 and, in conjunction with its hardware, completes the steps of the above methods.
[0144] Receiver 1101 can be used to receive input digital or character information, and to generate signal inputs related to the settings and function control of the execution device. Transmitter 1102 can be used to output digital or character information through the first interface; transmitter 1102 can also be used to send instructions to the disk group through the first interface to modify the data in the disk group; transmitter 1102 may also include a display device such as a display screen.
[0145] The execution device provided in this application embodiment can specifically be a chip, which includes a processing unit and a communication unit. The processing unit can be, for example, a processor, and the communication unit can be, for example, an input / output interface, pins, or circuits. The processing unit can execute computer execution instructions stored in the storage unit to cause the chip in the execution device to execute the methods described in the above embodiments. Optionally, the storage unit can be an internal storage unit within the chip, such as a register or cache. Alternatively, the storage unit can be an external storage unit located within the wireless access device, such as a read-only memory or other types of static storage devices capable of storing static information and instructions, such as random access memory.
[0146] Please refer to Figure 12 , Figure 12 This is a schematic diagram of a computer-readable storage medium provided in this application. This application also provides a computer-readable storage medium in some embodiments, wherein the above-described... Figure 2 The disclosed method can be implemented as computer program instructions encoded in a machine-readable format on a computer-readable storage medium or on other non-transitory media or articles of art.
[0147] Figure 12 A conceptual partial view of an example computer-readable storage medium arranged according to at least one embodiment shown herein is illustrated schematically. The example computer-readable storage medium includes a computer program for executing computer processes on a computing device.
[0148] In one embodiment, the computer-readable storage medium 1200 is provided using a signal bearer medium 1201. The signal bearer medium 1201 may include one or more program instructions 1202, which, when executed by one or more processors, can provide the above-mentioned... Figure 2 The described function or part of the function.
[0149] In some examples, signal carrying medium 1201 may include computer-readable medium 1203, such as, but not limited to, hard disk drive, compact disc (CD), digital video disc (DVD), digital magnetic tape, memory, ROM or RAM, etc.
[0150] In some embodiments, the signal-bearing medium 1201 may comprise a computer-recordable medium 1204, such as, but not limited to, a memory, a read / write (R / W) CD, a R / W DVD, etc. In some embodiments, the signal-bearing medium 1201 may comprise a communication medium 1205, such as, but not limited to, digital and / or analog communication media (e.g., fiber optic cables, waveguides, wired communication links, wireless communication links, etc.). Therefore, for example, the signal-bearing medium 1201 may be transmitted by a wireless communication medium 1205 (e.g., a wireless communication medium conforming to the IEEE 802.X standard or other transmission protocols).
[0151] One or more program instructions 1202 may be, for example, computer-executable instructions or logical implementation instructions. In some examples, the computing device may be configured to provide various operations, functions, or actions in response to one or more program instructions 1202 conveyed to the computing device via a computer-readable medium 1203, a computer-recordable medium 1204, and / or a communication medium 1205.
[0152] It should also be noted that the device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. In addition, in the accompanying drawings of the device embodiments provided in this application, the connection relationship between modules indicates that they have a communication connection, which can be implemented as one or more communication buses or signal lines.
[0153] Through the above description of the embodiments, those skilled in the art can clearly understand that this application can be implemented by means of software plus necessary general-purpose hardware, or it can be implemented by special-purpose hardware including application-specific integrated circuits, special-purpose CPUs, special-purpose memory, special-purpose components, etc. Generally, any function performed by a computer program can be easily implemented by corresponding hardware, and the specific hardware structure used to implement the same function can also be diverse, such as analog circuits, digital circuits, or special-purpose circuits. However, for this application, software program implementation is more often the preferred implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a readable storage medium, such as a computer floppy disk, USB flash drive, mobile hard disk, ROM, RAM, magnetic disk, or optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, training equipment, or network device, etc.) to execute the methods of the various embodiments of this application.
[0154] In the above embodiments, implementation can be achieved, in whole or in part, through software, hardware, firmware, or any combination thereof. When implemented in software, it can be implemented, in whole or in part, as a computer program product.
[0155] A computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the flow or function according to the embodiments of this application is generated. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium or transferred from one computer-readable storage medium to another. For example, computer instructions may be transferred from one website, computer, training device, or data center to another website, computer, training device, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium may be any available medium that a computer can store or a data storage device such as a training device or data center that integrates one or more available media. The available media may be magnetic media (e.g., floppy disks, hard disks, magnetic tapes), optical media (e.g., DVDs), or semiconductor media (e.g., solid-state drives (SSDs)).
Claims
1. A data synchronization method, characterized in that, include: When a first instance running in the first processing unit requests access to shared data, a target lock is requested for the first instance. The target lock is a lock corresponding to the shared data located on the global storage medium. The target lock is used to control the instance's access to the shared data. If the first instance obtains the target lock, the shared data is copied from the global storage medium to the first local storage medium used by the first processing unit, so that the first processing unit can access the shared data on the first local storage medium, wherein the speed at which the first processing unit accesses the first local storage medium is higher than the speed at which it accesses the global storage medium. If the first instance releases the target lock, the updated shared data is copied from the first local storage medium to the global storage medium.
2. The method according to claim 1, characterized in that, The method is applied to an architecture comprising multiple sets of processing units, wherein the processing units in the multiple sets of processing units can access the global storage medium, and different sets of processing units use different local storage media, wherein the first processing unit is a processing unit in the multiple sets of processing units.
3. The method according to claim 1 or 2, characterized in that, The method further includes: If the second instance is unable to acquire the target lock, the second instance is blocked when it requests access to the shared data located on the global storage medium.
4. The method according to claim 3, characterized in that, The method further includes: After the first instance releases the target lock If the second instance obtains the target lock, it copies the updated shared data from the global storage medium to the second local storage medium corresponding to the second processing unit.
5. The method according to any one of claims 1-4, characterized in that, The target lock is a read-write lock. If the first instance obtains a read lock from the target lock, the shared data stored on the global storage medium is allowed to be copied to a local storage medium other than the first local storage medium.
6. The method according to claim 5, characterized in that, The read-write lock is a multi-read single-write lock. If the first instance obtains the write lock in the target lock, the shared data stored on the global storage medium is no longer allowed to be copied to a local storage medium other than the first local storage medium.
7. The method according to claim 5, characterized in that, The read-write lock is a multi-read multi-write lock. If the first instance obtains the write lock in the target lock, the shared data stored on the global storage medium is allowed to be copied to a local storage medium other than the first local storage medium.
8. The method according to any one of claims 5-7, characterized in that, The global storage medium also stores a cache record table corresponding to the shared data, which is used to indicate the validity status of the shared data cached on different local storage media. When the first instance obtains the target lock, copying the shared data from the global storage medium to the first local storage medium corresponding to the first processing unit includes: If the first instance obtains the target lock and the cache record table indicates that the shared data cached on the first local storage medium is invalid, the shared data is copied from the global storage medium to the first local storage medium corresponding to the first processing unit.
9. The method according to claim 8, characterized in that, After copying the updated shared data from the first local storage medium to the global storage medium, the method further includes: Update the cache record table to obtain the updated cache record table; The updated cache record table is used to indicate that shared data cached on local storage media other than the first local storage medium is invalid.
10. The method according to any one of claims 1-4, characterized in that, The target lock is a mutex lock. If the first instance obtains the target lock, the shared data stored on the global storage medium is no longer allowed to be copied to a local storage medium other than the first local storage medium.
11. A data synchronization device, characterized in that, include: The lock request module is used to request a target lock for the first instance when the first instance running in the first processing unit requests access to shared data. The target lock is a lock corresponding to the shared data located on the global storage medium. The target lock is used to control the instance's access to the shared data. The processing module is configured to copy the shared data from the global storage medium to the first local storage medium used by the first processing unit when the first instance obtains the target lock, so that the first processing unit can access the shared data on the first local storage medium, wherein the speed at which the first processing unit accesses the first local storage medium is higher than the speed at which it accesses the global storage medium. The processing module is further configured to copy the updated shared data from the first local storage medium to the global storage medium when the first instance releases the target lock.
12. The apparatus according to claim 11, characterized in that, The device is applied to an architecture comprising multiple sets of processing units, wherein the processing units in the multiple sets of processing units can access the global storage medium, and different sets of processing units use different local storage media, wherein the first processing unit is a processing unit in the multiple sets of processing units.
13. The apparatus according to claim 11 or 12, characterized in that, The processing module is further configured to block the second instance when the second instance running in the second processing unit requests access to the shared data located on the global storage medium if the second instance is unable to acquire the target lock, wherein the first processing unit and the second processing unit use different local storage media.
14. The apparatus according to claim 13, characterized in that, The processing module is further configured to copy the updated shared data from the global storage medium to the second local storage medium corresponding to the second processing unit after the first instance releases the target lock and the second instance obtains the target lock.
15. The apparatus according to any one of claims 11-14, characterized in that, The target lock is a read-write lock. If the first instance obtains a read lock from the target lock, the shared data stored on the global storage medium is allowed to be copied to a local storage medium other than the first local storage medium.
16. The apparatus according to claim 15, characterized in that, The read-write lock is a multi-read single-write lock. If the first instance obtains the write lock in the target lock, the shared data stored on the global storage medium is no longer allowed to be copied to a local storage medium other than the first local storage medium.
17. The apparatus according to claim 15, characterized in that, The read-write lock is a multi-read multi-write lock. If the first instance obtains the write lock in the target lock, the shared data stored on the global storage medium is allowed to be copied to a local storage medium other than the first local storage medium.
18. The apparatus according to any one of claims 15-17, characterized in that, The global storage medium also stores a cache record table corresponding to the shared data, which is used to indicate the validity status of the shared data cached on different local storage media. The processing module is further configured to copy the shared data from the global storage medium to the first local storage medium corresponding to the first processing unit when the first instance obtains the target lock and the cache record table indicates that the shared data cached on the first local storage medium is invalid.
19. The apparatus according to claim 18, characterized in that, After copying the updated shared data from the first local storage medium to the global storage medium, the processing module is further configured to update the cache record table to obtain the updated cache record table; The updated cache record table is used to indicate that shared data cached on local storage media other than the first local storage medium is invalid.
20. The apparatus according to any one of claims 11-14, characterized in that, The target lock is a mutex lock. If the first instance obtains the target lock, the shared data stored on the global storage medium is no longer allowed to be copied to a local storage medium other than the first local storage medium.
21. A data synchronization device, characterized in that, The device includes a memory and a processor; the memory stores code, and the processor is configured to execute the code, wherein when the code is executed, the device performs the method as described in any one of claims 1 to 10.
22. A computer storage medium, characterized in that, The computer storage medium stores instructions that, when executed by the computer, cause the computer to perform the method according to any one of claims 1 to 10.
23. A computer program product, characterized in that, The computer program product stores instructions that, when executed by a computer, cause the computer to perform the method described in any one of claims 1 to 10.
