Data caching apparatus, method and electronic device
By adopting a method in RTOS embedded software development that immediately disables the interrupt lock after determining the target address and pauses the low-priority write thread when the high-priority write thread is writing data, the problem of excessive interrupt lock duration is solved, more efficient data caching and transmission are achieved, and the system's real-time performance and resource utilization are improved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- BEIJING ESWIN COMPUTING TECH CO LTD
- Filing Date
- 2022-11-15
- Publication Date
- 2026-07-21
AI Technical Summary
In RTOS embedded software development, the interrupt lock duration is relatively long during the logging process, which affects system real-time performance and processor resource utilization.
By immediately disabling the interrupt lock after determining the target address and pausing low-priority write threads while high-priority write threads are writing data, the lock duration is reduced. Binary log information and a circular buffer area are used to optimize data transmission.
It shortens the interrupt lock duration, improves system real-time performance and processor utilization, and saves cache and serial interface resources.
Smart Images

Figure CN115757305B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of printing log technology, and more particularly to a data caching device, method, and electronic device. Background Technology
[0002] In the process of developing embedded software for a Real-Time Operating System (RTOS), any thread may print log information. The log information can be used to locate problems in the code and obtain the running status of the code.
[0003] Currently, the process of printing log information includes: a write thread stores the log information to be printed in a buffer area; a print thread reads the log information from the buffer area and sends the log information to other devices via a serial port so that other devices can display the log information. In related technologies, the process of a write thread writing log information to the buffer area includes: enabling an interrupt lock, updating the write address, the write thread writing the log information to the buffer area, and closing the interrupt lock. In these related technologies, the lock duration between enabling and closing the interrupt lock includes the time it takes for the write thread to write the log information to the buffer area, thus resulting in a relatively long lock duration. Summary of the Invention
[0004] This invention provides a data caching device, method, and electronic device to address the shortcomings of long lock times in the prior art and to shorten lock times.
[0005] In a first aspect, the present invention provides a data caching method, comprising:
[0006] Enable interrupt lock;
[0007] The target address is determined based on the current address of the cache region and the data length of the first data to be written by the first write thread.
[0008] Close the interrupt lock;
[0009] The first write thread writes the first data to the cache area based on the current address and the target address.
[0010] According to a data caching method provided by the present invention, a first write thread writes the first data to the cache area based on the current address and the target address, comprising:
[0011] When a second write thread writes second data to the cache area, the writing of the second data to the cache area by the second write thread is paused; the priority of the second write thread is lower than the priority of the first write thread.
[0012] The first write thread writes the first data to the cache area based on the current address and the target address.
[0013] According to a data caching method provided by the present invention, the first data includes one or more of the following:
[0014] Log information; the log information is used to display on other devices when it is transmitted via a serial interface;
[0015] The log identifier for the log information; the log identifier is used by the other devices to obtain the log information;
[0016] The log identifier and at least one parameter value corresponding to the log identifier are used by the other devices to obtain the log information.
[0017] According to a data caching method provided by the present invention, when the first data includes the log identifier, the method further includes:
[0018] When a target source code statement is executed in the target source code file, the log identifier is determined based on the target source code file and the target source code statement.
[0019] According to a data caching method provided by the present invention, determining the log identifier based on the target source code file and the target source code statement includes:
[0020] Obtain the target file identifier of the target source code file;
[0021] Obtain the target line identifier of the target source code statement;
[0022] The log identifier is randomly generated based on the target file identifier and the target line identifier.
[0023] According to a data caching method provided by the present invention, when the first data includes the log identifier and the at least one parameter value, the method further includes:
[0024] Obtain at least one parameter value corresponding to the log identifier from the parameter table within the target source code statement.
[0025] According to a data caching method provided by the present invention, the first data has a binary format.
[0026] According to a data caching method provided by the present invention, the cache area is a circular cache area.
[0027] In a second aspect, the present invention provides a data caching device, comprising: a processing module;
[0028] The processing module is used to perform the following operations:
[0029] Enable interrupt lock;
[0030] The target address is determined based on the current address of the cache region and the data length of the first data to be written by the first write thread.
[0031] Close the interrupt lock;
[0032] The first write thread writes the first data to the cache area based on the current address and the target address.
[0033] According to a data caching device provided by the present invention, the processing module is specifically used for:
[0034] When a second write thread writes second data to the cache area, the writing of the second data to the cache area by the second write thread is paused; the priority of the second write thread is lower than the priority of the first write thread.
[0035] The first write thread writes the first data to the cache area based on the current address and the target address.
[0036] According to a data caching device provided by the present invention, the first data includes one or more of the following:
[0037] Log information; the log information is used to display on other devices when it is transmitted via a serial interface;
[0038] The log identifier for the log information; the log identifier is used by the other devices to obtain the log information;
[0039] The log identifier and at least one parameter value corresponding to the log identifier are used by the other devices to obtain the log information.
[0040] According to a data caching device provided by the present invention, when the first data includes the log identifier, the processing module is further configured to:
[0041] When a target source code statement is executed in the target source code file, the log identifier is determined based on the target source code file and the target source code statement.
[0042] According to a data caching device provided by the present invention, the processing module is further specifically used for:
[0043] Obtain the target file identifier of the target source code file;
[0044] Obtain the target line identifier of the target source code statement;
[0045] The log identifier is randomly generated based on the target file identifier and the target line identifier.
[0046] According to a data caching device provided by the present invention, when the first data includes the log identifier and the at least one parameter value, the processing module is further configured to:
[0047] Obtain at least one parameter value corresponding to the log identifier from the parameter table within the target source code statement.
[0048] According to a data caching device provided by the present invention, the first data has a binary format.
[0049] According to a data caching device provided by the present invention, the caching area is a circular caching area.
[0050] The present invention also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements any of the data caching methods described above when executing the program.
[0051] The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements any of the data caching methods described above.
[0052] The present invention also provides a computer program product, including a computer program that, when executed by a processor, implements any of the data caching methods described above.
[0053] The data caching device, method, and electronic device provided by this invention, the lock duration from opening the interrupt lock to closing the interrupt lock, only includes the time required to determine the target address based on the current address and the data length of the first data to be written by the first writing thread, and does not include the complete time for writing log information to the cache area. Moreover, since the time to obtain the target address is short, the lock duration in this invention is short. Attached Figure Description
[0054] To more clearly illustrate the technical solutions in this invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0055] Figure 1 This is a schematic diagram of the architecture for printing log information provided in related technologies;
[0056] Figure 2 A schematic diagram of a data caching method provided by existing technology;
[0057] Figure 3 This is a schematic diagram of the data caching method provided by the present invention;
[0058] Figure 4 This is a flowchart illustrating the data caching method provided by the present invention;
[0059] Figure 5 This is a schematic diagram of the data caching device provided by the present invention.
[0060] Figure 6 This is a schematic diagram of the physical structure of the electronic device provided by the present invention. Detailed Implementation
[0061] To make the objectives, technical solutions, and advantages of this invention clearer, the technical solutions of this invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this invention. All other embodiments obtained by those skilled in the art based on the embodiments of this invention without creative effort are within the scope of protection of this invention.
[0062] Figure 1 This is a schematic diagram of an architecture for printing log information provided in related technologies. As shown in Figure 1, it includes a lower-level machine and a higher-level machine. Both the lower-level machine and the higher-level machine include serial interfaces. The serial interfaces in the lower-level machine and the higher-level machine can communicate with each other.
[0063] The lower-level machine can execute the executable file compiled from the source code file to obtain log information in ASCII format, and then transmit the ASCII-formatted log information to the upper-level machine via its serial interface. The upper-level machine receives and displays the ASCII-formatted log information via its serial interface.
[0064] Before the lower-level machine sends ASCII format log information to the upper-level machine through its serial interface, multiple threads communicate via, for example... Figure 2 The method shown stores log information in ASCII format in a buffer area, so that the printing thread reads the log information in ASCII format from the buffer area and sends the log information in ASCII format to the host computer through the serial interface.
[0065] Figure 2 A diagram illustrating existing data caching methods. (Example) Figure 2 As shown, for example, it includes: thread 1 and thread 2.
[0066] The process of thread 1 writing log information in ASCII format to the buffer area includes:
[0067] Enable interrupt lock;
[0068] Write log information in ASCII format;
[0069] Update the write address;
[0070] Disable interrupt locks.
[0071] The process of thread 2 writing log information in ASCII format to the buffer area includes:
[0072] Enable interrupt lock;
[0073] Write log information in ASCII format;
[0074] Update the write address;
[0075] Disable interrupt locks.
[0076] The update write address is used to instruct the next thread to write log information in ASCII format to the cache area starting from the updated address.
[0077] In the above Figure 2 In this context, the lock duration includes the time spent writing log information to the cache area, which results in a longer lock duration.
[0078] First, combine Figure 3 The data caching method provided by this invention will be described.
[0079] Figure 3 This is a schematic diagram of the data caching method provided by the present invention. For example... Figure 3 As shown, for example, it includes: thread 1 and thread 2.
[0080] The process of thread 1 writing data to the cache area includes:
[0081] Enable interrupt lock;
[0082] Update the write address;
[0083] Disable interrupt lock;
[0084] Write data.
[0085] The process of thread 2 writing data to the cache area includes:
[0086] Enable interrupt lock;
[0087] Update the write address;
[0088] Disable interrupt lock;
[0089] Write data.
[0090] Alternatively, it can be achieved using the following code. Figure 3 The data writing process of thread 1 and thread 2 as described above:
[0091]
[0092] contrast Figure 2 and Figure 3 It can be seen that, Figure 2 The lock duration includes the total time for writing log information to the cache area. Since the process of writing data to the cache area occupies most of the entire lock duration, the lock duration is long, which wastes processor resources and reduces the real-time performance of the system. Figure 3 The lock duration in the code includes the time spent updating the write address. Since the time spent updating the write address is relatively short, therefore... Figure 3 The lock duration is shorter, saving processor resources and improving system real-time performance.
[0093] The following is combined with Figure 4 The data caching method provided by this invention will be described.
[0094] Figure 4 This is a flowchart illustrating the data caching method provided by the present invention. For example... Figure 4 As shown, the method includes:
[0095] Step 401: Enable interrupt lock.
[0096] Optionally, the execution subject of the data caching method provided by the present invention can be an electronic device, or a data caching device installed on the electronic device, which can be implemented by a combination of software and / or hardware.
[0097] Electronic devices can be, for example, lower-level devices.
[0098] Step 402: Determine the target address based on the current address of the cache region and the data length of the first data to be written by the first write thread.
[0099] The current address is the address in the cache area where data can be written.
[0100] The target address is equal to the sum of the current address and the data length.
[0101] The first writing thread is the thread that currently needs to write data to the cache area.
[0102] For example, in the first write thread is Figure 3 In the case of thread 2 shown, the current address is as follows: Figure 3 As shown.
[0103] Step 403: Disable the interrupt lock.
[0104] Step 404: The first write thread writes the first data to the cache area based on the current address and the target address.
[0105] The first write thread writes the first data to the region between the current address and the target address in the cache area.
[0106] In this invention, the lock duration from opening the interrupt lock to closing the interrupt lock includes the duration for determining the target address based on the current address and the data length of the first data. Since the time taken to obtain the target address is relatively short, the lock duration is shortened, CPU resources are saved, and the real-time performance of the system is improved.
[0107] In some embodiments, when a second write thread writes second data to the cache area, the writing of second data to the cache area by the second write thread is paused; the priority of the second write thread is lower than the priority of the first write thread.
[0108] The first write thread writes the first data to the cache area based on the current address and the target address.
[0109] The process of the second write thread writing the second data to the cache area is similar to the process of the first write thread writing the first data to the cache area, and will not be described in detail here.
[0110] The priority of the second write thread and the priority of the first write thread are obtained by the electronic device's operating system based on user configuration.
[0111] The current address is the first address after the end position of the second data in the cache area.
[0112] Unlike existing technologies, which are based on Figure 2 As can be seen, since the process of writing log information to the cache area by a thread is included within the lock duration, multiple threads must write log information to the cache area in sequence. This causes high-priority write threads to be frequently blocked and waiting, resulting in high-priority write threads being unable to write log information to the cache area in a timely manner, affecting the system's processing timing, producing unpredictable results, and reducing processor utilization.
[0113] In this application, based on Figure 3As can be seen, the process of a thread writing data to the cache area is not included in the lock duration. Therefore, when a low-priority second write thread is writing the second data to the cache area, if a high-priority first write thread needs to write the first data to the cache area, the second write thread is suspended and paused from writing the second data to the cache area. This allows the high-priority first write thread to write the first data to the cache area in a timely manner, avoiding the high-priority write thread from being frequently blocked and waiting, ensuring the system's processing order, avoiding unpredictable results, and improving processor utilization.
[0114] Optionally, the first data includes one or more of the following:
[0115] Log information; Log information is used to display on other devices when it is transmitted via a serial interface.
[0116] The log identifier is used by other devices to obtain log information.
[0117] A log identifier and at least one corresponding parameter value are used by other devices to obtain log information.
[0118] Optionally, if the electronic device is a lower-level device, the other devices can be upper-level devices.
[0119] Optionally, the second data includes one or more of the following:
[0120] Log information; Log information is used to display on other devices when it is transmitted via a serial interface.
[0121] The log identifier is used by other devices to obtain log information.
[0122] A log identifier and at least one corresponding parameter value are used by other devices to obtain log information.
[0123] Optionally, the second data and the first data may be the same or different.
[0124] For example, if the second data and the first data are different, one or more of the following are included:
[0125] The log information is different;
[0126] Different log identifiers;
[0127] At least one parameter value is different.
[0128] For example, the first data may be a log identifier, or it may include a log identifier and at least one parameter value.
[0129] Unlike existing technologies, where data written to the buffer area and transmitted via the serial interface are both ASCII-formatted log information, resulting in a large amount of data buffered in the buffer area and a large amount of data transmitted via the serial interface, wasting both buffer storage resources and serial interface transmission resources, this invention allows data written to the buffer area to be a log identifier, or to include a log identifier and at least one parameter value, instead of ASCII-formatted log information. This saves both buffer storage resources and serial interface transmission resources.
[0130] Example 1: If the first data includes log information, the printing thread in the lower-level machine reads the log information from the buffer area and sends the log information to the upper-level machine through the serial interface; after receiving the log information, the upper-level machine displays the log information.
[0131] Example 2: If the first data includes a log identifier, the printing thread in the lower-level machine reads the log identifier from the buffer area and sends the log identifier to the upper-level machine through the serial interface.
[0132] The host computer searches for the target parameter information corresponding to the log identifier in the log rule file, determines the log information based on the target parameter information, and displays the log information.
[0133] The logging rules file includes a mapping relationship between multiple log identifiers and parameter information. The multiple log identifiers are multiple source code statements in the target source code file that include preset function identifiers.
[0134] Alternatively, the log rule file can be obtained using the following method:
[0135] Obtain the target source code file;
[0136] Based on preset function identifiers, the target source code file is scanned to obtain multiple source code statements containing the preset function identifiers, the line identifier of each source code statement, and the parameter information of each source code statement.
[0137] For each source code statement, a log identifier for the source code statement is determined based on the line identifier of the source code statement and the file identifier of the target source code file;
[0138] The logging rules file includes a mapping relationship between the logging identifiers (i.e., the multiple logging identifiers mentioned above) and parameter information of multiple source code statements.
[0139] It should be noted that if the target source code file changes, the log rule file needs to be generated again.
[0140] Alternatively, line identifiers for multiple source code statements can be obtained using the following method:
[0141] Determine the total number of multiple source code statements;
[0142] Based on the total number of source code statements and their sequential order, assign a corresponding line number to each source code statement.
[0143] For each source code statement, the file identifier of the target source code file and the line number of the source code statement are combined to obtain the line identifier of the source code statement.
[0144] For example, if the file identifier is 1 and the total number is 100, the line numbers of multiple source code statements can be 00, 01, 02...99, and the line identifiers of multiple source code statements can be 100, 101, 102...199.
[0145] Optionally, the parameter information in the log rule file may include one or more of the following:
[0146] The string to be displayed;
[0147] At least one format conversion character;
[0148] The total number of at least one format conversion character.
[0149] If the parameter information in the log rule file includes the string to be displayed, the host computer can determine the target parameter information as log information.
[0150] For example, if the target parameter information (i.e. the string to be displayed) is "Hello World", the log information will be "Hello World".
[0151] When the parameter information in the log rule file includes the string to be displayed and at least one format conversion character, the first data also includes at least one parameter value corresponding to the log identifier. The at least one format conversion character in the target parameter information and the at least one parameter value corresponding to the log identifier are in one-to-one correspondence. For each format conversion character, the host computer adds the parameter value corresponding to the format conversion character to the position corresponding to the format conversion character in the string to be displayed in the target parameter information to obtain the log information.
[0152] For example, if the target parameter information includes the string to be displayed (Hello Word, int =, string =, hex =) and at least one format conversion character (%f, %s, %x), the log information will be Hello Word, int = 2022, string = abcd1234, hex = 0xabcdef.
[0153] Optionally, the data caching method provided by the present invention further includes, when the first data includes the log identifier:
[0154] When executing target source code statements in a target source code file, a log identifier is determined based on the target source code file and the target source code statements.
[0155] Optionally, the target source code statement is a source code statement that includes a preset function identifier.
[0156] Specifically, based on the target source code file and target source code statements, log identifiers are determined, including:
[0157] Obtain the target file identifier of the target source code file;
[0158] Obtain the target line identifier of the target source code statement;
[0159] The log identifier is randomly generated based on the target file identifier and the target line identifier.
[0160] Optionally, the target file identifier can be the identifier of the target file read by the lower-level machine during the execution of the target source code file.
[0161] Optionally, the target line identifier is determined by the lower-level machine based on the target file identifier and the total number of all source code statements in the target source code file that need to be logged.
[0162] Optionally, the method for obtaining the target line identifier is similar to the method for obtaining the line identifiers of multiple source code statements, and will not be described in detail here.
[0163] Optionally, the data caching method provided by the present invention, when the first data includes the log identifier and the at least one parameter value, further includes:
[0164] Obtain at least one parameter value corresponding to the log identifier from the parameter table within the target source code statement.
[0165] In the case that the target source code statement is printf(“Hello Word,%d,%c”,2022,abcd), the parameter list is “,2022,abcd”. After splitting the information in the parameter list based on the preset delimiter “,”, at least one parameter value is obtained that includes 2022 and abcd.
[0166] Optionally, the first and second data have a binary format.
[0167] In this invention, the first data and the second data are in binary format, which can reduce the amount of data transmission of the serial interface.
[0168] For example, if the data is a 32-bit integer, and the data transmitted by the serial interface is in ASCII format, then 8 bytes of information need to be transmitted. If the data transmitted by the serial interface is in binary format, then only 4 bytes of information need to be transmitted. Therefore, transmitting the first data in binary format through the serial interface can reduce the amount of data transmitted by the serial interface.
[0169] Optionally, the cache region can be a circular cache region. For example, the circular cache region can be a (First In First Out, FIFO) cache.
[0170] In this invention, the preset cache area is a circular cache area, which allows multiple threads to write a large amount of data to the circular cache area in an instant. Furthermore, with the cooperation of Direct Memory Access (DMA) and an appropriate cache area size, the log printing efficiency is greatly improved and mutual exclusion access is reduced.
[0171] The data caching device provided by the present invention is described below. The data caching device described below and the data caching method described above can be referred to in correspondence.
[0172] Figure 5 This is a schematic diagram of the data caching device provided by the present invention. Figure 5 As shown, the data caching device includes: a processing module 50;
[0173] The processing module 50 is used to perform the following operations:
[0174] Enable interrupt lock;
[0175] The target address is determined based on the current address of the cache region and the data length of the first data to be written by the first write thread.
[0176] Close the interrupt lock;
[0177] The first write thread writes the first data to the cache area based on the current address and the target address.
[0178] According to a data caching device provided by the present invention, when a second write thread writes second data to the cache area, the writing of second data by the second write thread to the cache area is paused; the priority of the second write thread is lower than the priority of the first write thread.
[0179] The first write thread writes the first data to the cache area based on the current address and the target address.
[0180] According to a data caching device provided by the present invention, the first data includes one or more of the following:
[0181] Log information; the log information is used to display on other devices when it is transmitted via a serial interface;
[0182] The log identifier for the log information; the log identifier is used by the other devices to obtain the log information;
[0183] The log identifier and at least one parameter value corresponding to the log identifier are used by the other devices to obtain the log information.
[0184] According to a data caching device provided by the present invention, when the first data includes the log identifier, the processing module 50 is further configured to:
[0185] When a target source code statement is executed in the target source code file, the log identifier is determined based on the target source code file and the target source code statement.
[0186] According to a data caching device provided by the present invention, the processing module 50 is further specifically used for:
[0187] Obtain the target file identifier of the target source code file;
[0188] Obtain the target line identifier of the target source code statement;
[0189] The log identifier is randomly generated based on the target file identifier and the target line identifier.
[0190] According to a data caching device provided by the present invention, when the first data includes the log identifier and the at least one parameter value, the processing module 50 is further configured to:
[0191] Obtain at least one parameter value corresponding to the log identifier from the parameter table within the target source code statement.
[0192] According to a data caching device provided by the present invention, the first data has a binary format.
[0193] According to a data caching device provided by the present invention, the caching area is a circular caching area.
[0194] Figure 6 This is a schematic diagram of the physical structure of the electronic device provided by the present invention. For example... Figure 6As shown, the electronic device may include a processor 610, a communications interface 620, a memory 630, and a communication bus 640, wherein the processor 610, communications interface 620, and memory 630 communicate with each other via the communication bus 640. The processor 610 can invoke logical instructions in the memory 630 to execute a data caching method, which includes: enabling an interrupt lock; determining a target address based on the current address of the cache region and the data length of the first data to be written by the first write thread; disabling the interrupt lock; and writing the first data into the cache region by the first write thread based on the current address and the target address.
[0195] Furthermore, the logical instructions in the aforementioned memory 630 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, essentially, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0196] On the other hand, the present invention also provides a computer program product, the computer program product including a computer program, the computer program being able to be stored on a non-transitory computer-readable storage medium, the computer program being executed by a processor, the computer being able to execute the data caching method provided by the above methods, the method including: enabling an interrupt lock; determining a target address based on the current address of the cache area and the data length of the first data to be written by the first write thread; disabling the interrupt lock; and writing the first data into the cache area by the first write thread based on the current address and the target address.
[0197] In another aspect, the present invention also provides a non-transitory computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements a data caching method provided by the above methods, the method comprising: enabling an interrupt lock; determining a target address based on the current address of the cache region and the data length of the first data to be written by the first write thread; disabling the interrupt lock; and writing the first data into the cache region by the first write thread based on the current address and the target address.
[0198] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.
[0199] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, 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 can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments.
[0200] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A data caching device, characterized in that, include: Processing module; The processing module is used to perform the following operations: Enable interrupt lock; Determine the target address based on the current address of the cache region and the length of the first data to be written by the first write thread. Close the interrupt lock; The first write thread writes the first data to the cache area based on the current address and the target address; The processing module is specifically used for: When a second write thread writes second data to the cache area, the writing of the second data to the cache area by the second write thread is paused; the priority of the second write thread is lower than the priority of the first write thread. The first write thread writes the first data to the cache area based on the current address and the target address; The first data includes a log identifier for log information, the log identifier being used by other devices to obtain the log information; the processing module is further configured to: When executing target source code statements in a target source code file, the log identifier is determined based on the target source code file and the target source code statements; The processing module is also specifically used for: Obtain the target file identifier of the target source code file; Obtain the target line identifier of the target source code statement; The log identifier is randomly generated based on the target file identifier and the target line identifier.
2. The data caching device according to claim 1, characterized in that, The first data also includes one or more of the following: Log information, which is used to display on the other device when the data is transmitted via a serial interface; The log identifier and at least one parameter value corresponding to the log identifier are used by the other devices to obtain the log information.
3. The data caching device according to claim 2, characterized in that, When the first data includes the log identifier and the at least one parameter value, the processing module is further configured to: Obtain at least one parameter value corresponding to the log identifier from the parameter table within the target source code statement.
4. The data caching device according to claim 1, characterized in that, The first data and the second data are in binary format.
5. The data caching device according to claim 1, characterized in that, The cache area is a circular cache area.
6. A data caching method, characterized in that, include: Enable interrupt lock; Determine the target address based on the current address of the cache region and the length of the first data to be written by the first write thread. Close the interrupt lock; The first write thread writes the first data to the cache area based on the current address and the target address; When a second write thread writes second data to the cache area, the second write thread's writing of the second data to the cache area is paused. The priority of the second write thread is lower than that of the first write thread; The first write thread writes the first data to the cache area based on the current address and the target address; The first data includes a log identifier for log information, which is used by other devices to obtain the log information; When executing target source code statements in a target source code file, the log identifier is determined based on the target source code file and the target source code statements; The step of determining the log identifier based on the target source code file and the target source code statements includes: Obtain the target file identifier of the target source code file; Obtain the target line identifier of the target source code statement; The log identifier is randomly generated based on the target file identifier and the target line identifier.
7. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the data caching method as described in claim 6.
8. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the data caching method as described in claim 6.
9. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by the processor, it implements the data caching method as described in claim 6.