Multiprocessor synchronization method, device, terminal equipment and storage medium
By using the baseline time-consuming value in multi-processor devices to optimize the sending time of synchronization commands, the problem of long synchronization time-consuming between processors is solved and the synchronization efficiency is improved.
Patent Information
- Application Number
- CN202111115431.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-09-23
- Publication Date
- 2024-09-10
- Estimated Expiration
- 2041-09-23
AI Technical Summary
Synchronization between processors in existing multi-processor devices takes a long time and is greatly affected by the preset time interval setting, resulting in low synchronization efficiency.
When the power-on running time of the second processor is the same as the pre-stored baseline time-consuming value, the first processor and the second processor send synchronization commands to each other, and the baseline time-consuming value is determined based on the time-consuming time measured at least twice, Ensure the accuracy and efficiency of synchronization commands.
It reduces the time-consuming synchronization between processors, improves synchronization efficiency, and meets the needs of actual synchronization scenarios.
Smart Images

Figure CN113821469B
Abstract
Description
Technical Field
[0001] The present application belongs to the field of data processing technology, and in particular, relates to a synchronization method, apparatus, terminal equipment and storage medium for multiple processors. Background Art
[0002] In embedded devices, multiple processors are used to work together. For example, in a device including dual processors, one processor is used as a master processor and the other processor is used as a slave processor, and the two processors work together.
[0003] At present, the two processors in the device can be synchronized by the master processor powering on the slave processor and continuously initiating synchronization commands at preset time intervals. After receiving the response from the slave processor, the two parties begin to exchange data. This method is greatly affected by the preset time interval setting. When the preset time interval setting is not appropriate, the synchronization between the processors will take a long time. Summary of the invention
[0004] The embodiments of the present application provide a multi-processor synchronization method, apparatus, terminal device and storage medium, aiming to solve the problem of long synchronization time between processors in existing multi-processor devices.
[0005] In a first aspect, an embodiment of the present application provides a multi-processor synchronization method, which is applied to a terminal device, wherein the terminal device includes a first processor and a second processor, and the method includes:
[0006] After the first processor is initialized, the second processor is powered on;
[0007] When the power-on operation time of the second processor is the same as the pre-stored reference time value, the first processor and the second processor send a first synchronization command to each other; wherein the reference time value is determined based on at least two time durations obtained from at least two measurements, and the time duration is the time from the power-on of the second processor to the successful communication between the first processor and the second processor;
[0008] When the first processor receives the first response signal returned by the second processor based on the first synchronization command, or receives the first synchronization command sent by the second processor, it is determined that the first processor and the second processor are synchronized successfully, so that data can be exchanged between the first processor and the second processor.
[0009] In one embodiment, the method further comprises:
[0010] When the first processor and the second processor are respectively initialized, the first processor and the second processor send the first synchronization command to each other at every preset time interval.
[0011] In one embodiment, determining the reference time-consuming value based on at least two time-consuming durations obtained from at least two measurements includes:
[0012] When the first processor and the second processor are respectively initialized, they send a second synchronization command to each other at a preset time interval;
[0013] When the first processor receives the second response signal returned based on the second synchronization command or the second synchronization command sent by the second processor, it is determined that the first processor and the second processor communicate successfully;
[0014] Taking the time from powering on the second processor to the successful communication as the elapsed time obtained by one measurement;
[0015] The benchmark time-consuming value is determined based on the time-consuming duration obtained from each measurement and preset rules.
[0016] In one embodiment, determining the benchmark time-consuming value based on the time-consuming duration obtained from each measurement and a preset rule includes:
[0017] The time-consuming duration obtained by each measurement is uploaded to a server, and the server is used to store the time-consuming duration, and when the number of the time-consuming durations reaches a first preset threshold, the time-consuming duration with the highest frequency among at least two time-consuming durations is determined as the benchmark time-consuming value;
[0018] Receive the benchmark time-consuming value returned by the server.
[0019] In one embodiment, determining the benchmark time-consuming value based on the time-consuming duration obtained from each measurement and a preset rule includes:
[0020] The time-consuming duration obtained by each measurement is uploaded to a server, and the server is used to store the time-consuming duration until there is a target time-consuming duration whose upload times reach a second preset threshold value among at least two of the time-consuming durations, and the target time-consuming duration is determined as the benchmark time-consuming value;
[0021] Receive the benchmark time-consuming value returned by the server.
[0022] In one embodiment, the duration from powering on the second processor to the successful communication is taken as the consuming time obtained by one measurement, including:
[0023] The duration from powering on the second processor to the successful communication is rounded to the integer to determine the duration obtained by one measurement.
[0024] In one embodiment, uploading the time duration obtained from each measurement to a server includes:
[0025] The time duration obtained from each measurement and the identifier of the terminal device are uploaded to a server, and the server is used to store the identifier and the time duration in association with each other, and when the number of the time durations associated with the identifier reaches the first preset threshold, the time duration with the highest frequency among at least two time durations associated with the identifier is determined as the benchmark time value.
[0026] In a second aspect, an embodiment of the present application provides a multi-processor synchronization device, which is applied to a terminal device, wherein the terminal device includes a first processor and a second processor:
[0027] The synchronization device comprises:
[0028] A power-on module, used to power on the second processor after the first processor is initialized;
[0029] A first synchronization command sending module, configured to cause the first processor and the second processor to send a first synchronization command to each other when the power-on operation time of the second processor is the same as a pre-stored reference time value; wherein the reference time value is determined based on at least two time durations obtained from at least two measurements, and the time duration is the time duration from the power-on of the second processor to the successful communication between the first processor and the second processor;
[0030] A synchronization determination module is used to determine that the first processor and the second processor are synchronized successfully when the first processor receives a first response signal returned by the second processor based on the first synchronization command, or receives a first synchronization command sent by the second processor, so as to enable data exchange between the first processor and the second processor.
[0031] In one embodiment, the synchronization device further comprises:
[0032] The second synchronization command sending module is used to send the first synchronization command to the first processor and the second processor at preset time intervals when the first processor and the second processor are respectively initialized.
[0033] In one embodiment, the synchronization device further includes a reference time value determination module, and the reference time value determination module includes:
[0034] A synchronization unit, configured to send a second synchronization command to each other at a preset time interval when the first processor and the second processor are respectively initialized;
[0035] a successful communication determination unit, configured to determine that the first processor and the second processor have successfully communicated when the first processor receives a second response signal returned based on the second synchronization command or the second synchronization command sent by the second processor;
[0036] a time-consuming duration determining unit, configured to use the time from powering on the second processor to the successful communication as the time-consuming duration obtained by one measurement;
[0037] The reference time-consuming value determining unit is used to determine the reference time-consuming value based on the time-consuming duration obtained from each measurement and a preset rule.
[0038] In one embodiment, the benchmark time-consuming value determining unit includes:
[0039] A first determining subunit is used to upload the time duration obtained by each measurement to a server, and the server is used to store the time duration, and when the number of the time durations reaches a first preset threshold, determine the time duration with the highest frequency among at least two time durations as the benchmark time duration value;
[0040] The first receiving subunit is used to receive the benchmark time consumption value returned by the server.
[0041] In one embodiment, the benchmark time-consuming value determining unit includes:
[0042] A second determining subunit is configured to upload the time-consuming duration obtained by each measurement to a server, and the server is configured to store the time-consuming duration until at least two of the time-consuming durations have a target time-consuming duration whose upload times reach a second preset threshold, and the target time-consuming duration is determined as the benchmark time-consuming value;
[0043] The second receiving subunit is used to receive the benchmark time consumption value returned by the server.
[0044] In one embodiment, the time-consuming duration determining unit is specifically used to:
[0045] The duration from powering on the second processor to the successful communication is rounded to the integer to determine the duration obtained by one measurement.
[0046] In one embodiment, the first determining subunit is specifically configured to:
[0047] The time duration obtained from each measurement and the identifier of the terminal device are uploaded to a server, and the server is used to store the identifier and the time duration in association with each other, and when the number of the time durations associated with the identifier reaches the first preset threshold, the time duration with the highest frequency among at least two time durations associated with the identifier is determined as the benchmark time value.
[0048] In a third aspect, an embodiment of the present application provides a terminal device comprising a memory, multiple processors, and a computer program stored in the memory and executable on the multiple processors, wherein the steps of the multi-processor synchronization method in the above-mentioned first aspect are implemented when the multiple processors execute the computer program.
[0049] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the multi-processor synchronization method in the first aspect are implemented.
[0050] The first aspect of the embodiment of the present application has the following beneficial effects compared with the prior art: the terminal device includes a first processor and a second processor, and when the power-on running time of the second processor is the same as the pre-stored benchmark time value, the first processor and the second processor send a first synchronization command to each other, and since the benchmark time value is determined based on at least two time durations obtained from at least two measurements, the time duration is the time duration from the power-on of the second processor to the successful communication between the first processor and the second processor, that is, the benchmark time value is a time value obtained based on actual measurements, and therefore sending synchronization commands to each other based on the benchmark time value can better meet actual synchronization scenarios, and can enable the first processor to receive the first response signal returned by the second processor based on the first synchronization command, or receive the first synchronization command sent by the second processor more quickly, and when receiving the first response signal or the first synchronization command, it is determined that the synchronization of the first processor and the second processor is successful, thereby reducing the time duration for synchronization between processors in a multi-processor device. BRIEF DESCRIPTION OF THE DRAWINGS
[0051] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are merely embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0052] Figure 1 It is a flowchart of a multi-processor synchronization method provided in Embodiment 1 of the present application;
[0053] Figure 2 It is a structural block diagram of a terminal device provided in Embodiment 1 of the present application;
[0054] Figure 3 It is a flowchart of a multi-processor synchronization method provided in Embodiment 2 of the present application;
[0055] Figure 4It is a flowchart of a multi-processor synchronization method provided in Embodiment 3 of the present application;
[0056] Figure 5 This is a flowchart of step S304 of the multi-processor synchronization method provided in the third embodiment of the present application;
[0057] Figure 6 This is another flowchart diagram of step S304 of the multi-processor synchronization method provided in the third embodiment of the present application;
[0058] Figure 7 This is a structural block diagram of a terminal device provided in Embodiment 4 of the present application;
[0059] Figure 8 It is a structural diagram of the terminal device provided in Example 5 of the present application. DETAILED DESCRIPTION
[0060] In the following description, specific details such as specific system module structures, technologies, etc. are provided for the purpose of illustration rather than limitation, so as to provide a thorough understanding of the embodiments of the present application. However, it should be clear to those skilled in the art that the present application may also be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known system modules, devices, circuits, and methods are omitted to prevent unnecessary details from obstructing the description of the present application.
[0061] It should be understood that the order of execution of the steps in the following method embodiments does not necessarily mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of each embodiment.
[0062] The present embodiment provides a multi-processor synchronization method, which can be applied to a terminal device, wherein the terminal device includes a first processor and a second processor, and the terminal device can be an embedded device, a diagnostic device, a tablet computer, a wearable device, an in-vehicle device, an augmented reality (AR) / virtual reality (VR) device, a notebook computer, an ultra-mobile personal computer (UMPC), a netbook, a personal digital assistant (PDA), a mobile phone, or other various terminal devices capable of data processing, wherein the terminal device is connected to a server for communication, and the server can be an independent server or a cloud server providing cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, etc. The present application embodiment does not impose any restrictions on the specific type of the device.
[0063] In order to illustrate the technical solution of the present invention, a specific embodiment is provided below for illustration.
[0064] Embodiment 1
[0065] This embodiment provides a multi-processor synchronization method, which is applied to a terminal device, wherein the terminal device includes a first processor and a second processor. Figure 1 As shown, the synchronization method of the multi-processor includes:
[0066] Step S101: After the first processor is initialized, the second processor is powered on.
[0067] Specifically, the first processor is any one of at least two processors included in the terminal device, and the second processor is any one of the at least two processors and is different from the first processor. When the first processor is initialized, the second processor can be powered on by the first processor.
[0068] For example, in one application scenario, Figure 2 The terminal device shown includes a processor 1 and a processor 2, wherein the processor 1 is a main processor and the processor 2 is a microprocessor. For example, the processor 1 is a main CPU, i.e., a central processing unit (CPU), and the processor 2 is an MCU, i.e., a microcontroller unit (MCU), also known as a single-chip microcomputer. The main CPU and the MCU work together, and both parties can communicate through a serial port to exchange data. After the main CPU is initialized, the MCU is powered on by the main CPU.
[0069] Step S102, when the power-on running time of the second processor is the same as the pre-stored benchmark time value, the first processor and the second processor send a first synchronization command to each other; wherein the benchmark time value is determined based on at least two time durations obtained based on at least two measurements, and the time duration is the time from the power-on of the second processor to the successful communication between the first processor and the second processor.
[0070] Specifically, after the first processor powers on the second processor, when the power-on operation time of the second processor is the same as the pre-stored benchmark time value, the first processor sends a synchronization command to the second processor, and the second processor also sends a synchronization command to the first processor, and the synchronization command herein is referred to as the first synchronization command. Among them, the benchmark time value is a benchmark time value determined based on at least two time durations obtained from at least two historical measurements, and the time duration obtained from each measurement can be understood as the time from the power-on of the second processor to the successful communication between the first processor and the second processor.
[0071] Step S103, when the first processor receives the first response signal returned by the second processor based on the first synchronization command, or receives the first synchronization command sent by the second processor, it is determined that the first processor and the second processor are synchronized successfully, so that data can be exchanged between the first processor and the second processor.
[0072] Specifically, when the power-on running time of the second processor is the same as the benchmark time value, the first processor sends a first synchronization command to the second processor. If the second processor receives the synchronization command, it will return a response signal to the first processor, which is called a first response signal. When the power-on running time of the second processor is the same as the benchmark time value, the second processor will also send a first synchronization command to the first processor. When the first processor first receives the first response signal returned by the second processor based on the first synchronization command, it determines that the first processor and the second processor are successfully synchronized at this time. Or when the first processor first receives the first synchronization command sent by the second processor, it also determines that the first processor and the second processor are successfully synchronized at this time. After the first processor and the second processor are successfully synchronized, data interaction can be performed between the first processor and the second processor according to the synchronization information included in the synchronization instruction.
[0073] The terminal device in the embodiment of the present application includes a first processor and a second processor. When the power-on running time of the second processor is the same as the pre-stored benchmark time value, the first processor and the second processor send a first synchronization command to each other. Since the benchmark time value is determined based on at least two time durations obtained based on at least two measurements, the time duration is the time from the power-on of the second processor to the successful communication between the first processor and the second processor, that is, the benchmark time value is a time value obtained according to actual measurements. Therefore, sending synchronization commands to each other based on the benchmark time value can better meet the actual synchronization scenario, and can enable the first processor to receive the first response signal returned by the second processor based on the first synchronization command, or receive the first synchronization command sent by the second processor more quickly, and when receiving the first response signal or the first synchronization command, it is determined that the synchronization of the first processor and the second processor is successful, thereby reducing the time duration of synchronization between processors in a multi-processor device.
[0074] Embodiment 2
[0075] This embodiment is a further explanation of the first embodiment. For details of the same or similar parts as the first embodiment, please refer to the relevant description of the first embodiment, which will not be repeated here. Figure 3 As shown, the synchronization method of the multi-processor includes:
[0076] Step S201: After the first processor is initialized, the second processor is powered on.
[0077] Step S202, when the power-on running time of the second processor is the same as the pre-stored benchmark time value, the first processor and the second processor send a first synchronization command to each other; wherein the benchmark time value is determined based on at least two time durations obtained based on at least two measurements, and the time duration is the time from the power-on of the second processor to the successful communication between the first processor and the second processor.
[0078] Step S203: When the first processor and the second processor are respectively initialized, the first processor and the second processor send the first synchronization command to each other at a preset time interval.
[0079] Specifically, when the first processor is initialized, the first processor starts to send the first synchronization command to the second processor at a preset time interval. If the preset time interval is 2 seconds, when the first processor is initialized, the first synchronization command is sent for the first time, and then the first synchronization command is sent every 2 seconds. Similarly, when the second processor is initialized, the second processor starts to send the first synchronization command to the first processor at a preset time interval. If the preset time interval is 2 seconds, when the second processor is initialized, the first synchronization command is sent for the first time, and then the first synchronization command is sent every 2 seconds.
[0080] If the first processor sends a synchronization command when initialization is completed, the first processor obtains the current power-on running time as tc, records the pre-stored benchmark time value as dt, and records the preset time interval as: tset. If dt-tc is less than the preset time interval tset, the synchronization command is sent after the delay time is tsleep=dt-tc, otherwise the synchronization command is sent after the delay time tsleep=tset.
[0081] Step S204, when the first processor receives the first response signal returned by the second processor based on the first synchronization command, or receives the first synchronization command sent by the second processor, it is determined that the first processor and the second processor are synchronized successfully, so that data can be exchanged between the first processor and the second processor.
[0082] Specifically, the same or similar parts of step S201, step S202, and step S204 as the above-mentioned step S101, step S102, and step S103, respectively, can be referred to the relevant descriptions in step S101, step S102, and step S103, which will not be repeated here. It is worth noting that in this embodiment, step S202 and step S203 are not in order and can be executed simultaneously.
[0083] In this embodiment, when the power-on running time of the second processor is the same as the pre-stored benchmark time value, the first processor and the second processor send the first synchronization command to each other, and when the first processor and the second processor are respectively initialized, the first processor and the second processor send the first synchronization command to each other at every preset time interval. This allows the first processor and the second processor to successfully communicate more quickly, thereby further reducing the time required for synchronization between the first processor and the second processor.
[0084] Embodiment 3
[0085] This embodiment is a further explanation of the first embodiment. For details of the same or similar parts as the first embodiment, please refer to the relevant description of the first embodiment, which will not be repeated here. Figure 4 As shown, the step S101 determines the reference time value based on at least two time durations obtained from at least two measurements, including steps S301 to S304:
[0086] Step S301: When the first processor and the second processor are initialized, they send a second synchronization command to each other at a preset time interval.
[0087] Specifically, when there is no pre-stored reference time value in the terminal device, when the first processor is initialized, the second synchronization command is sent to the second processor at a preset time interval. When the second processor is initialized, the second synchronization command is sent to the first processor at a preset time interval.
[0088] Step S302: When the first processor receives a second response signal returned based on the second synchronization command or the second synchronization command sent by the second processor, it is determined that the first processor and the second processor communicate successfully.
[0089] Specifically, the first processor sends a second synchronization command to the second processor, and the second processor returns a corresponding response signal upon receiving the second synchronization command, which is called a second response signal. When the first processor receives the second response signal, it is determined that the first processor and the second processor are communicating successfully. The second processor also sends a second synchronization command to the first processor, and when the first processor receives the second synchronization command, it is determined that the first processor and the second processor are communicating successfully. It can be the moment when the first processor receives the earliest of the two signals, the second response signal and the second synchronization command, and determines that the first processor and the second processor are communicating successfully at this moment.
[0090] For example, when the first processor is initialized, the second processor is powered on through the first processor, and the second synchronization command is sent to the second processor through the first processor; when the second processor is initialized, the second synchronization command is sent to the first processor through the second processor; if the first processor and the second processor receive the second synchronization command, they will return the corresponding response command, and the first processor will determine that the synchronization is successful and start data communication at the time corresponding to the earliest received signal of the second response signal and the second synchronization command. If the first processor preferentially receives the second response command returned based on the second synchronization command, it is determined that the synchronization is successful and data communication is started; if the first processor preferentially receives the second synchronization command sent by the second processor, it is determined that the synchronization is successful and data communication is started.
[0091] Step S303: the time from the power-on of the second processor to the successful communication is used as the consuming time obtained by one measurement.
[0092] Specifically, when determining successful communication, the time length from when the second processor is powered on to when the successful communication is determined is used as the time length obtained by the current measurement.
[0093] In one embodiment, taking the time from powering on the second processor to the successful communication as the elapsed time obtained by one measurement includes: rounding the time from powering on the second processor to the successful communication to determine it as the elapsed time obtained by one measurement.
[0094] Specifically, the duration from powering on the second processor to the successful communication can be rounded up with a preset unit, and the rounded duration is determined as the duration obtained by the current measurement. In a specific application scenario, the duration can be rounded up with a preset unit, for example, if the preset unit is 100 milliseconds and the duration is 1560 milliseconds, it is recorded as 1600 milliseconds.
[0095] Step S304, determining the reference time-consuming value based on the time-consuming duration obtained from each measurement and preset rules.
[0096] Specifically, after each startup, the time required for the first processor and the second processor to successfully communicate is recorded, and the benchmark time value is determined according to the recorded multiple time durations and preset rules.
[0097] Since the time from powering on the second processor to the successful communication is used as the time duration obtained by one measurement, the time duration obtained can be automatically determined without manual statistics, and the benchmark time duration value is determined based on the time duration obtained by each measurement and a preset rule. The calculated benchmark time duration value is closer to the actual synchronization time between processors, so that the synchronization command is sent based on the benchmark time duration value, so that the probability of synchronization between processors is higher, and the synchronization time duration can be further reduced.
[0098] In one embodiment, Figure 5 As shown, step S304 includes step S3041 to step S3042:
[0099] Step S3041, uploading the time-consuming duration obtained by each measurement to a server, the server is used to store the time-consuming duration, and when the number of the time-consuming durations reaches a first preset threshold, determining the time-consuming duration with the highest frequency among at least two time-consuming durations as the benchmark time-consuming value.
[0100] Specifically, after each startup, the time required for the first processor and the second processor to successfully communicate is recorded, and the terminal device establishes a communication connection with the server. The time required for the successful communication between the two processors of the terminal device can be uploaded to the server through the communication module in the terminal device. When the server receives the time sent by the terminal device, it stores the time. If the total number of multiple time durations reported by the server is greater than the first preset threshold, the time duration with the highest frequency (i.e., the highest probability) among the multiple time durations is determined as the benchmark time value, and the benchmark time value is returned to the terminal device.
[0101] Step S3042: Receive the benchmark time value returned by the server.
[0102] Specifically, after the server determines the benchmark time consumption value, the server returns the benchmark time consumption value to the terminal device. When the terminal device receives the benchmark time consumption value, it can be stored in the first processor and the second processor respectively.
[0103] For example, the specific server can return the benchmark timing value to the first processor of the terminal device, and the first processor sends the benchmark timing value to the second processor. Both processors to be synchronized store the benchmark timing value; if the total number of reported time durations is less than or equal to the first preset threshold, the server returns zero to the first processor of the terminal device. When the first processor receives zero, it determines that the benchmark timing value has not yet been obtained and does not save it.
[0104] The device autonomously reports the time consumption to the server, and the server uses the most frequently counted time consumption as the benchmark time consumption value to feed back to the processor in the terminal device for storage. Therefore, the calculated benchmark time consumption value is highly accurate, so that synchronization commands can be sent based on the benchmark time consumption value for synchronization, which can reduce the synchronization time consumption.
[0105] In another embodiment, Figure 6 As shown, step S304 includes step S3043 to step S3044:
[0106] Step S3043, uploading the time-consuming duration obtained by each measurement to the server, and the server is used to store the time-consuming duration until there is a target time-consuming duration whose upload times reach a second preset threshold among at least two of the time-consuming durations, and the target time-consuming duration is determined as the benchmark time-consuming value.
[0107] Specifically, after each startup, the time required for the corresponding first processor and the second processor to successfully communicate is recorded, and the terminal device establishes a communication connection with the server. The time required for the successful communication between the two processors of the terminal device can be uploaded to the server through the communication module in the terminal device. When the server receives the time required sent by the terminal device, it stores the time required. If the server detects that the total number of uploads of a certain time required time first reaches greater than the second preset threshold, the time required time is used as the benchmark time required value, and the benchmark time required value is returned to the terminal device.
[0108] Step S3044, receiving the benchmark time value returned by the server.
[0109] Specifically, after the server determines the benchmark time consumption value, the server returns the benchmark time consumption value to the terminal device. After the terminal device receives the benchmark time consumption value, it stores it in the first processor and the second processor respectively.
[0110] The device autonomously reports the time consumption to the server, and the server determines the target time consumption as the benchmark time consumption value when it counts that there is a target time consumption among multiple time consumption durations with the number of uploads reaching a second preset threshold. The most likely time consumption for successful synchronization can be used as the benchmark time consumption value, which can further reduce the synchronization time consumption.
[0111] In one embodiment, uploading the time duration obtained from each measurement to a server includes: uploading the time duration obtained from each measurement and an identifier of the terminal device to a server, the server being configured to store the identifier and the time duration in association with each other, and when the number of the time durations associated with the identifier reaches the first preset threshold, determining the time duration with the highest frequency among at least two time durations associated with the identifier as the benchmark time value.
[0112] Specifically, the time duration is measured after each startup, and a communication connection is established with the server. The terminal device identifier (such as product model) and the time duration required for synchronization between the two processors can be uploaded to the server through the communication module in the terminal device. When the server receives the time duration and device identifier sent by the terminal device, the time duration and the device identifier are associated and stored. The server can receive the time durations of multiple terminal devices with the same identifier. If the total number of time durations stored by the same type of terminal devices is greater than the preset first threshold, the time duration with the highest frequency (i.e., the highest probability) among the multiple time durations is determined as the benchmark time duration value, and the benchmark time duration value is returned to the terminal device, and the two synchronized processors both store the benchmark time duration value; if the total number of data reported for the identifier is less than or equal to the threshold, the server returns zero to the terminal device, and the terminal device receives the zero value without saving it.
[0113] If the terminal device successfully communicates with the server, the terminal device uploads the device model and the time taken for this synchronization. The server receives the data of the reported device model and the time taken for this synchronization. The server adds 1 to the number of reports of the corresponding device model and the number of corresponding time taken for the corresponding device. For example, if the device model uploaded by the terminal device is model A and the time taken for this synchronization is 3 seconds, the number of reports corresponding to model A device is added by 1, and the number of times corresponding to the time taken for model A device is added by 1.
[0114] For example, in one application scenario, Figure 2The terminal device shown includes processor 1 and processor 2, processor 1 is the main processor, and processor 2 is a microprocessor. For example, processor 1 is the main CPU, i.e., the central processing unit (CPU), and processor 2 is the MCU, i.e., the microcontroller unit (MCU), also known as a single-chip microcomputer. The main CPU and the MCU work together, and the two parties can communicate through the serial port to exchange data. After the main CPU powers on the MCU, it can continuously initiate synchronization commands at a certain time interval (e.g., 2 seconds). When the main CPU receives the response from the MCU, the two parties start to communicate (it can also be that the MCU powers on the main CPU and the MCU sends the synchronization command. The principle is the same and will not be repeated here). In this way, unreasonable time interval setting will cause a waste of time. For example, the main CPU sends a synchronization command every two seconds, and the time it takes to initialize the MCU is 2.5 seconds. Then, because the MCU has not been initialized yet, the command of the 0th and 2nd seconds will not be answered until the 4th second, and then the communication between the two parties begins. Through the above example, in fact, communication can be achieved when the time it takes to initialize the MCU is 2.5 seconds, which obviously wastes 1.5 seconds.
[0115] Therefore, when the terminal device does not pre-store the benchmark time value, after the terminal device is started, the main CPU and MCU can each initiate a second synchronization command after initialization is completed. When the main CPU receives the response or the second synchronization command of the MCU, it records the time taken from the power-on of the MCU to the current time (when the main CPU receives the response or the synchronization command of the MCU), and uploads the time and product model to the server. The server records the number of times the time taken for this model has been uploaded. After each successful startup, the main CPU reports the product model and time taken, and the server saves the data. If the total number of reported data for this model is greater than the threshold, the time taken with the highest probability is returned, otherwise it returns 0. When the value of the time taken returned by the main CPU is not 0, the time taken is saved as the benchmark time taken value, and the benchmark time taken value is sent to the MCU. After the main CPU saves the benchmark timing value, the synchronization between the main CPU and the MCU can be to send a synchronization command at a preset time interval after the initialization of the main CPU and the MCU is completed, and also send a synchronization command when the power-on running time of the second processor is equal to the benchmark timing value. It is easier to receive the synchronization command for synchronization, thereby further reducing the time required for synchronization between the main CPU and the MCU.
[0116] Embodiment 4
[0117] Corresponding to the multi-processor synchronization method described in the above embodiment, Figure 7The structural block diagram of the multi-processor synchronization device provided by the embodiment of the present application is shown. For the convenience of explanation, only the part related to the embodiment of the present application is shown. The synchronization device is applied to a terminal device, the terminal device includes a first processor and a second processor, and the multi-processor synchronization device 700 includes:
[0118] A power-on module 701, used to power on the second processor after the first processor is initialized;
[0119] A first synchronization command sending module 702, configured to cause the first processor and the second processor to send a first synchronization command to each other when the power-on operation time of the second processor is the same as a pre-stored reference time value; wherein the reference time value is determined based on at least two time durations obtained from at least two measurements, and the time duration is the time duration from the power-on of the second processor to the successful communication between the first processor and the second processor;
[0120] The synchronization determination module 703 is used to determine that the first processor and the second processor are synchronized successfully when the first processor receives a first response signal returned by the second processor based on the first synchronization command, or receives a first synchronization command sent by the second processor, so as to enable data exchange between the first processor and the second processor.
[0121] In one embodiment, the synchronization device further comprises:
[0122] The second synchronization command sending module is used to send the first synchronization command to the first processor and the second processor at preset time intervals when the first processor and the second processor are respectively initialized.
[0123] In one embodiment, the synchronization device further includes a reference time value determination module, and the reference time value determination module includes:
[0124] A synchronization unit, configured to send a second synchronization command to each other at a preset time interval when the first processor and the second processor are respectively initialized;
[0125] a successful communication determination unit, configured to determine that the first processor and the second processor have successfully communicated when the first processor receives a second response signal returned based on the second synchronization command or the second synchronization command sent by the second processor;
[0126] a time-consuming duration determining unit, configured to use the time from powering on the second processor to the successful communication as the time-consuming duration obtained by one measurement;
[0127] The reference time-consuming value determining unit is used to determine the reference time-consuming value based on the time-consuming duration obtained from each measurement and a preset rule.
[0128] In one embodiment, the benchmark time-consuming value determining unit includes:
[0129] A first determining subunit is used to upload the time duration obtained by each measurement to a server, and the server is used to store the time duration, and when the number of the time durations reaches a first preset threshold, determine the time duration with the highest frequency among at least two time durations as the benchmark time duration value;
[0130] The first receiving subunit is used to receive the benchmark time consumption value returned by the server.
[0131] In one embodiment, the benchmark time-consuming value determining unit includes:
[0132] A second determining subunit is configured to upload the time-consuming duration obtained by each measurement to a server, and the server is configured to store the time-consuming duration until at least two of the time-consuming durations have a target time-consuming duration whose upload times reach a second preset threshold, and the target time-consuming duration is determined as the benchmark time-consuming value;
[0133] The second receiving subunit is used to receive the benchmark time consumption value returned by the server.
[0134] In one embodiment, the time-consuming duration determining unit is specifically used to:
[0135] The duration from powering on the second processor to the successful communication is rounded to the integer to determine the duration obtained by one measurement.
[0136] In one embodiment, the first determining subunit is specifically configured to:
[0137] The time duration obtained from each measurement and the identifier of the terminal device are uploaded to a server, and the server is used to store the identifier and the time duration in association with each other, and when the number of the time durations associated with the identifier reaches the first preset threshold, the time duration with the highest frequency among at least two time durations associated with the identifier is determined as the benchmark time value.
[0138] The terminal device in the embodiment of the present application includes a first processor and a second processor. When the power-on running time of the second processor is the same as the pre-stored benchmark time value, the first processor and the second processor send a first synchronization command to each other. Since the benchmark time value is determined based on at least two time durations obtained based on at least two measurements, the time duration is the time from the power-on of the second processor to the successful communication between the first processor and the second processor, that is, the benchmark time value is a time value obtained according to actual measurements. Therefore, sending synchronization commands to each other based on the benchmark time value can better meet the actual synchronization scenario, and can enable the first processor to receive the first response signal returned by the second processor based on the first synchronization command, or receive the first synchronization command sent by the second processor more quickly, and when receiving the first response signal or the first synchronization command, it is determined that the synchronization of the first processor and the second processor is successful, thereby reducing the time duration for synchronization between processors in a multi-processor device.
[0139] Embodiment 5
[0140] like Figure 8 , which is a schematic diagram of the structure of a terminal device provided in an embodiment of the present application. The terminal device 800 includes: a processor 8011, a processor 8012, a memory 802, and a computer program 803 stored in the memory 802 and executable on the processor 8011 and the processor 8012. For example, the processor 8011 and the processor 8012 may be the first processor and the second processor, respectively.
[0141] Exemplarily, the computer program 803 may be divided into one or more units / modules, which are stored in the memory 802 and executed by the processor 8011 or the processor 8012 to complete the present application. The one or more units / modules may be a series of computer program instruction segments capable of completing specific functions, which are used to describe the execution process of the computer program 803 in the terminal device 800.
[0142] The terminal device 800 may include, but is not limited to, a processor 8011, a processor 8012, and a memory 802. Those skilled in the art will appreciate that Figure 8 It is only an example of the terminal device 800 and does not constitute a limitation of the terminal device 800. It may include more or fewer components than shown in the figure, or a combination of certain components, or different components. For example, the terminal device 800 may also include input and output devices, network access devices, buses, etc.
[0143] The processor 8011 and the processor 8012 may be a central processing unit (CPU), or other general-purpose processors, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc.
[0144] The memory 802 may be an internal storage unit of the terminal device 800, such as a hard disk or memory of the terminal device 800. The memory 802 may also include both an internal storage unit of the terminal device 800 and an external storage device. The memory 802 is used to store the computer program and other programs and data required by the terminal device 800. The memory 802 may also be used to temporarily store data that has been output or is to be output.
[0145] Those skilled in the art can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example for illustration. In actual applications, the above-mentioned functions can be assigned to different functional units and modules as needed, that is, the internal structure of the above-mentioned device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiment can be integrated into a processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of this application. The specific working process of the units and modules in the above-mentioned maintenance case generation device can refer to the corresponding process in the aforementioned method embodiment, which will not be repeated here.
[0146] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0147] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0148] In the embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the above modules or units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system module, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0149] The units described above as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the embodiments of the present application.
[0150] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0151] If the above-mentioned integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present application implements all or part of the processes in the above-mentioned embodiment method, and can also be completed by instructing the relevant hardware through a computer program. The above-mentioned computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned various method embodiments when executed by the processor. Among them, the above-mentioned computer program includes computer program code, and the above-mentioned computer program code can be in source code form, object code form, executable file or some intermediate form. The above-mentioned computer-readable medium may include: any entity or device capable of carrying the above-mentioned computer program code, recording medium, U disk, mobile hard disk, disk, optical disk, computer memory, read-only memory (ROM, Read-Only Memory), random access memory (RAM, RandomAccess Memory), electric carrier signal, telecommunication signal and software distribution medium. It should be noted that the content contained in the above-mentioned computer-readable medium can be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media do not include electric carrier signals and telecommunication signals. The embodiments described above are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, a person skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application, and should all be included in the protection scope of the present application.
Claims
1. A multi-processor synchronization method, characterized in that: Applied to a terminal device, the terminal device includes a first processor and a second processor, and the method includes: After the first processor is initialized, the second processor is powered on; When the first processor and the second processor are each initialized, they send a second synchronization command to each other at a preset interval, and when the first processor receives a second response signal returned based on the second synchronization command or the second synchronization command sent by the second processor, it is determined that the first processor and the second processor have successfully communicated; The time from powering on the second processor to the successful communication is used as a time consumption obtained by one measurement, and a benchmark time consumption value is determined based on the time consumption obtained by each measurement and a preset rule; When the power-on running time of the second processor is the same as the pre-stored reference time value, the first processor and the second processor send a first synchronization command to each other; When the first processor receives the first response signal returned by the second processor based on the first synchronization command, or receives the first synchronization command sent by the second processor, it is determined that the synchronization between the first processor and the second processor is successful, so that data interaction is performed between the first processor and the second processor.
2. The synchronization method according to claim 1, wherein: The method further comprises: When the first processor and the second processor are respectively initialized, the first processor and the second processor send the first synchronization command to each other at every preset time interval.
3. The synchronization method according to claim 1, wherein: The determining of the benchmark time-consuming value based on the time-consuming duration obtained from each measurement and a preset rule includes: Uploading the time duration obtained from each measurement to a server, the server being configured to store the time duration and, when the number of the time durations reaches a first preset threshold, determining the time duration with the highest frequency among at least two time durations as the benchmark time duration value; Receive the benchmark time value returned by the server.
4. The synchronization method according to claim 1, wherein: The determining of the benchmark time-consuming value based on the time-consuming duration obtained from each measurement and a preset rule includes: Uploading the measured time duration each time to a server, the server being configured to store the measured time duration until at least two of the measured time durations have a target time duration whose upload times reach a second preset threshold, and determining the target time duration as the benchmark time duration value; Receive the benchmark time value returned by the server.
5. The synchronization method according to claim 1, wherein: The time duration from powering on the second processor to the successful communication is taken as a measured time duration, including: The duration from powering on the second processor to the successful communication is rounded up to determine the duration obtained from one measurement.
6. The synchronization method according to claim 3, characterized in that The uploading of the time duration obtained from each measurement to the server includes: The time duration obtained from each measurement and the identifier of the terminal device are uploaded to a server, and the server is used to store the identifier and the time duration in association with each other, and when the number of the time durations associated with the identifier reaches the first preset threshold, the time duration with the highest frequency among the at least two time durations associated with the identifier is determined as the benchmark time duration value.
7. A multi-processor synchronization device, characterized in that: Applied to a terminal device, the terminal device comprising a first processor and a second processor: The synchronization device comprises: A power-on module, used to power on the second processor after the first processor is initialized; a first synchronization command sending module, configured to cause the first processor and the second processor to send a first synchronization command to each other when the power-on running time of the second processor is the same as a pre-stored reference time value; a synchronization determination module, configured to determine, when the first processor receives a first response signal returned by the second processor based on the first synchronization command, or receives a first synchronization command sent by the second processor, that the first processor and the second processor are successfully synchronized, so as to enable data exchange between the first processor and the second processor; A benchmark time-consuming value determination module, wherein the benchmark time-consuming value determination module includes: A synchronization unit is used to send a second synchronization command to each other at preset time intervals when the first processor and the second processor are each initialized; a successful communication judgment unit is used to determine that the first processor and the second processor have successfully communicated when the first processor receives a second response signal returned based on the second synchronization command or the second synchronization command sent by the second processor; a time-consuming duration determination unit is used to take the time from the power-on of the second processor to the successful communication as the time-consuming duration obtained by a single measurement; a benchmark time-consuming value determination unit is used to determine the benchmark time-consuming value based on the time-consuming duration obtained by each measurement and a preset rule.
8. A terminal device comprising a memory, a plurality of processors, and a computer program stored in the memory and executable on the processors, wherein: When the plurality of processors execute the computer program, the method according to any one of claims 1 to 6 is implemented.
9. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.
