A polling method, device and computer readable storage medium
By recording the sleep duration of I/O communication and optimizing the polling strategy, the problems of polling idle and real-time when obtaining I/O communication results are solved, and the efficiency and real-time nature of polling are improved.
Patent Information
- Application Number
- CN202210042551.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-01-14
- Publication Date
- 2024-12-27
- Estimated Expiration
- 2042-01-14
AI Technical Summary
When obtaining I/O communication results, existing CPU-side software programs are prone to poor real-time problems of polling idles and timing/period polling, and cannot effectively distinguish the complexity of I/O communication tasks.
By reading the information of the I/O communication results, we judge whether the communication is completed, and record the sleep time from initiation to completion as the default sleep time for the next communication, and optimize the polling strategy to reduce polling idles and improve real-time performance.
It realizes the reduction of polling idle situations, and improves the real-time performance of timed polling, and can promptly detect changes in device status.
Smart Images

Figure CN114443151B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a polling method, device and computer-readable storage medium. Background Art
[0002] When the computer is working, the software program running on the CPU (Central Processing Unit) side needs to communicate with the peripheral devices through I / O (Input / Output) (also called I / O interaction) to transfer data or perform control functions. After the CPU-side software program initiates I / O communication, the peripheral devices need some time to process and wait for the CPU-side software program to obtain the processing results. In other words, when the operation of the peripheral device on a piece of data has not been completed, the data result obtained by the CPU-side software program must be invalid. Therefore, the CPU-side software program is required to obtain the result of I / O communication at the right time. The results of I / O communication generally include three types: completed I / O communication, uncompleted I / O communication, and I / O communication error.
[0003] There are generally three ways for the existing CPU-side software program to obtain the results of I / O communication at the right time, namely: the CPU-side software program obtains the results of I / O communication at the right time by polling the status register of the peripheral device, the CPU-side software program receives the interrupt signal sent by the peripheral device to the CPU to obtain the results of I / O communication at the right time, and the CPU-side software program obtains the results of I / O communication at the right time by polling the peripheral status register and receiving the interrupt signal sent by the peripheral device to the CPU. The above three methods cannot distinguish the complexity of the I / O communication task. When performing the polling operation, there will be a situation where the polling is idle in real-time polling and the real-time performance of the timing / periodic polling is poor.
[0004] In view of the above problems, it is a problem that those skilled in the art are trying their best to solve to find a polling method that does not cause polling idling and has good real-time performance. Summary of the invention
[0005] The purpose of the present application is to provide a polling method, device and computer-readable storage medium, which are used to reduce the situation of polling idling while improving real-time performance.
[0006] In order to solve the above technical problems, the present application provides a polling method, comprising:
[0007] Read information representing I / O communication results;
[0008] Determine whether the I / O communication is completed based on the information;
[0009] If the I / O communication is completed, the sleep duration from the initiation of the I / O communication to the completion of the I / O communication is recorded, wherein the sleep duration is used as the default sleep duration for the next I / O communication;
[0010] If the I / O communication is not completed, the process returns to the step of reading the information representing the result of the I / O communication.
[0011] Preferably, before reading the information representing the I / O communication result, the method further includes:
[0012] Create a timing array. The timing array is a collection of time values recorded in the order in which they appear and the time values in the timing array are initialized to 0.
[0013] Preferably, if the I / O communication is completed, the sleep duration from initiation of the I / O communication to completion of the I / O communication is recorded, including:
[0014] Replace the first time value in the timing array with the sleep duration;
[0015] Determine whether the sleep duration is the same in the preset I / O communication times;
[0016] If yes, a preset coefficient is set and a default sleep duration is calculated according to the preset coefficient, wherein the coefficient is less than 1;
[0017] If not, the sleep duration is updated to the default sleep duration, wherein the updated default sleep duration is used as the default sleep duration for the next I / O communication.
[0018] Preferably, after determining whether the sleep duration is the same in the preset I / O communication times and before updating the sleep duration to the default sleep duration, the method further includes:
[0019] Calculate the fluctuation range of all time values in the timing array;
[0020] Determine whether the sleep duration is within the fluctuation range;
[0021] If yes, then enter the step of updating the sleep duration to the default sleep duration;
[0022] If not, the process returns to the step of reading the information representing the I / O communication result.
[0023] Preferably, if the I / O communication is not completed, the method returns to the step before reading the information representing the I / O communication result, and further includes:
[0024] Determine whether the I / O communication has been put into sleep for the first time;
[0025] If the first sleep has been performed, determine whether there is a reference sleep duration;
[0026] If the first sleep is not performed, sleep is performed according to the default sleep duration and returns to the step of reading the information representing the I / O communication result;
[0027] Among them, judging whether there is a reference sleep duration includes:
[0028] If there is a reference sleep duration, sleeping according to the reference sleep duration and returning to the step of reading information representing the I / O communication result;
[0029] If there is no reference sleep duration, the system enters the step of sleeping according to the default sleep duration and returns to the step of reading the information representing the I / O communication result.
[0030] Preferably, before reading the information representing the I / O communication result and after creating the timing array, the method further includes:
[0031] Initialize the default sleep duration, wherein the default sleep duration after initialization is 0.
[0032] Preferably, the method further comprises: when an error is determined according to the information representing the I / O communication result, performing error reporting processing.
[0033] In order to solve the above technical problems, the present application also provides a polling device, including:
[0034] A reading module, used to read information representing I / O communication results;
[0035] A judgment module, used for judging whether the I / O communication is completed according to the information;
[0036] A recording module, for recording the sleep duration from initiation of the I / O communication to completion of the I / O communication if the I / O communication is completed, wherein the sleep duration is used as the default sleep duration for the next I / O communication;
[0037] The return module is used to return to the step of reading information representing the result of the I / O communication if the I / O communication is not completed.
[0038] In order to solve the above technical problems, the present application also provides a polling device, including:
[0039] Memory for storing computer programs;
[0040] A processor is used to implement the steps of the polling method mentioned above when executing a computer program.
[0041] In order to solve the above technical problems, the present application also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the polling method mentioned above are implemented.
[0042] A polling method provided by the present application includes: reading information representing the result of I / O communication; judging whether the I / O communication is completed according to the information; if the I / O communication is completed, recording the sleep duration from initiating the I / O communication to completing the I / O communication and using the sleep duration as the default sleep duration for the next I / O communication; if the I / O communication is not completed, returning to the step of reading the information representing the result of I / O communication. By recording the sleep duration from initiating the I / O communication to completing the I / O communication, the specific duration for completing an I / O communication can be known. At this time, the next I / O communication can sleep according to the specific duration, thereby reducing the situation of polling idling and improving the situation where the timed polling cannot detect the change of the device status in time.
[0043] The present application also provides a polling device and a computer-readable storage medium, with the same effects as above. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] In order to more clearly illustrate the embodiments of the present application, the following is a brief introduction to the drawings required for use in the embodiments. Obviously, the drawings described below are only some 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.
[0045] Figure 1 A flowchart of a polling method provided in an embodiment of the present application;
[0046] Figure 2 A flowchart of a polling method for completed I / O communication provided in an embodiment of the present application;
[0047] Figure 3 A flowchart of a polling method for unfinished I / O communication provided in an embodiment of the present application;
[0048] Figure 4 A flowchart of a polling method for I / O communication errors provided in an embodiment of the present application;
[0049] Figure 5 A structural diagram of a polling device provided in an embodiment of the present application;
[0050] Figure 6 A structural diagram of another polling device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0051] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0052] The core of the present application is to provide a polling method, device and computer-readable storage medium, which can reduce the situation of polling idling and improve the situation that timed polling cannot timely discover changes in device status.
[0053] In order to enable those skilled in the art to better understand the present application, the present application is further described in detail below in conjunction with the accompanying drawings and specific implementation methods.
[0054] When the computer is working, the software program running on the central processing unit (CPU) side needs to communicate with the peripheral devices for input / output (I / O), also known as I / O interaction, to achieve the function of transferring data or performing control. After the CPU-side software program initiates I / O communication, the peripheral device needs a period of time to process and wait for the CPU-side software program to obtain the processing result. In other words: when the peripheral device has not completed the operation on a piece of data, the data result obtained by the CPU-side software program must be invalid. Therefore, the CPU-side software program is required to obtain the result of I / O communication at the right time. The results of I / O communication generally include three types: completed I / O communication, uncompleted I / O communication, and I / O communication error.
[0055] There are generally three ways for existing CPU-side software programs to obtain the results of I / O communication at the appropriate time, namely: the CPU-side software program obtains the results of I / O communication at the appropriate time by polling the status register of the peripheral device, the CPU-side software program receives the interrupt signal sent by the peripheral device to the CPU to obtain the results of I / O communication at the appropriate time, and the CPU-side software program obtains the results of I / O communication at the appropriate time by polling the peripheral device and receiving the interrupt signal sent by the peripheral device to the CPU.
[0056] The status register is used to store the result of the current I / O communication of the computer. When the CPU-side software program finds that the I / O communication has been completed by querying the content in the status register, it is considered that the I / O communication has been completed and it is the right time to obtain the I / O result.
[0057] When the state of a peripheral device changes, an interrupt signal is generated and sent to the CPU. At this time, the CPU-side software program no longer polls the peripheral device, but waits for the interrupt signal sent by the peripheral device to the CPU. During this period, the CPU can execute other software programs. In this way, devices with low I / O communication frequency and devices that do not require frequent I / O communication generally adopt the method of waiting for the interrupt signal sent by the peripheral device to the CPU. This operation enables the CPU to execute other programs when the interrupt signal is not received. When the CPU receives an interrupt signal sent by a peripheral device, it executes the interrupt service program corresponding to the interrupt signal, and resumes the execution of the previously interrupted program after executing the interrupt service program. When the CPU receives an interrupt signal sent by a peripheral device, the CPU must perform the above operations. If the interrupt method is used for very frequent I / O communication at this time, the CPU will generate additional power consumption. Therefore, the method of waiting for the interrupt signal sent by the peripheral device to the CPU is only suitable for devices with low I / O communication frequency and devices that do not require frequent I / O communication.
[0058] Devices with high I / O communication frequency generally have frequent I / O communication requirements. CPU-side software programs often use polling to obtain the status changes of the status register of peripheral devices and then conduct I / O communication with them. The CPU-side software program performs polling operations, reads the contents of the status register and determines whether its contents indicate that the I / O communication has been completed. If it indicates that it has been completed, the result of the I / O communication is obtained. Otherwise, the polling action is immediately performed again (also known as real-time polling) or the polling action is performed again after a fixed period (timing / periodic polling). Among them, real-time polling is always performed regardless of whether the status of the peripheral device changes. If the polling is idle, CPU resources are consumed. Timing / periodic polling can choose to sleep during the interval between two queries to let the CPU execute other software programs. It can be seen that there are fewer additional overheads than the interrupt method, but the real-time performance is poor.
[0059] For the CPU-side software program to obtain the result of I / O communication at the right time by polling the peripheral device and the interrupt signal sent by the peripheral device to the CPU, this method requires the hardware to generate an interrupt signal and contain a status register, which is too demanding on the hardware, and the hardware cost increases exponentially. Initially, the CPU-side software program does not perform I / O communication with the peripheral device. At this time, the CPU does not receive an interrupt signal and can execute other software programs. When the CPU receives an interrupt signal sent by the peripheral device and the CPU-side software program performs I / O communication with the peripheral device, it switches to a polling operation to process the I / O communication between the CPU-side software program and the peripheral device. If there is no I / O communication for a period of time, the polling is stopped and the CPU waits for the peripheral device to send the next interrupt signal. This method cannot distinguish the complexity of the I / O communication task. When performing the polling operation, the above-mentioned real-time polling idle situation and the poor real-time performance of the timing / periodic polling will occur.
[0060] In view of the above problems, the present application provides a polling method. Figure 1 This is a flow chart of a polling method provided in an embodiment of the present application. Figure 1 As shown, the polling method includes:
[0061] S10: Read the information in the status register that is used to represent the I / O communication result.
[0062] S11: Determine whether the status register has completed the I / O communication based on the information.
[0063] S12: Record the sleep time from when the status register initiates the I / O communication to when the status register completes the I / O communication, and sleep according to the sleep time.
[0064] It should be noted that after executing step S11, if the status register completes the I / O communication, step S12 is entered; if the status register does not complete the I / O communication, step S10 is returned. The status register mentioned in this embodiment refers to the status register of the peripheral device, not the CPU. The status register mainly stores information about the current working status of the peripheral device, such as: busy (I / O communication is in progress, that is, I / O communication is not completed), completed (I / O communication has been completed), idle (I / O communication is not in progress, which can be understood as the previous I / O communication has been completed or I / O communication has not yet been performed), error (error caused by multiple possibilities).
[0065] The polling method mentioned in this embodiment records the sleep time from initiating I / O communication to completing I / O communication to obtain the specific time to complete one I / O communication. At this time, the next I / O communication can sleep according to the specific time, thereby reducing the situation of polling idling and improving the situation where scheduled polling cannot detect changes in device status in time.
[0066] Figure 2 A flowchart of a polling method for completing I / O communication provided in an embodiment of the present application. Based on the above embodiment, as a more preferred embodiment, Figure 2 As shown, before reading the information in the status register used to characterize the I / O communication result, the following steps are also included:
[0067] S20: Create a timing array.
[0068] The timing array is a collection of time values recorded in the order in which the time values appear, and the time values in the timing array are initialized to 0.
[0069] In this embodiment, it is first necessary to create a timing array, which is a timing array that can record multiple time values and is initialized to all 0. The timing array can be regarded as a set, and the time values recorded in the timing array can be regarded as elements in the set. All the recorded time values are stored in the timing array for easy management and subsequent comparison. It should be noted that the time value recorded in the timing array is the duration of performing an I / O communication and obtaining the I / O communication result. And the number of recorded time values is equal to the number of times the I / O communication is performed. For example, the timing array is set to record 3 time values, and all 3 time values are assigned to 0 at the beginning, and the duration of waiting for the I / O result for the last 3 times can be recorded later. It should be noted that if multiple timing arrays are set in order to improve the efficiency of I / O communication, in this embodiment, there is no limit on the maximum number of time values that can be stored in the timing array, which can be 1 or 100, but for the normal operation of the computer, a suitable number of time values should be selected, generally set to 5 or 10.
[0070] When the information representing the result of the I / O communication is read and the result of the I / O communication is represented as completed, based on the above embodiment, as a more preferred embodiment, if the I / O communication is completed, the sleep duration from initiating the I / O communication to completing the I / O communication is recorded, including:
[0071] S21: Replace the first time value in the timing array with the sleep duration.
[0072] S22: Determine whether the sleep duration is the same in the preset I / O communication times.
[0073] S23: Setting a preset coefficient and calculating a default sleep duration according to the preset coefficient.
[0074] S24: Update the sleep duration to the default sleep duration.
[0075] It should be noted that, when it is determined that the sleep duration is the same in the preset I / O communication times, a preset coefficient is set and a default sleep duration is calculated according to the preset coefficient, wherein the coefficient is less than 1.
[0076] When it is determined that the sleep duration is different in the preset I / O communication times, the sleep duration is updated to a default sleep duration, wherein the updated default sleep duration is used as the default sleep duration for the next I / O communication.
[0077] In the present embodiment, it should be noted that the coefficient mentioned here can be 0.9, 0.8, or 0.5, but the specific values of the coefficients mentioned are only a few embodiments among many embodiments, and do not mean that the values of the coefficients can only be 0.9, 0.8, or 0.5. The sleep duration can be calculated by the formula: default sleep duration = sleep duration * coefficient. And sleep according to the calculated default duration. Since the coefficient is a number less than 1, the default sleep duration is less than the sleep duration. In the present embodiment, since the coefficient is a number less than 1, the default sleep duration can be gradually determined in small step units to determine the duration of an I / O communication, and then determine the specific value of the sleep duration.
[0078] Based on the above embodiment, as a more preferred embodiment, after determining whether the sleep duration is the same in the preset I / O communication times and before updating the sleep duration to the default sleep duration, it also includes:
[0079] S25: Calculate the fluctuation range of all time values in the timing array.
[0080] S26: Determine whether the sleep duration is within the fluctuation range.
[0081] If yes, go to step S25.
[0082] If not, the process returns to step S10.
[0083] In this embodiment, it should be noted that there are two ways to calculate the fluctuation range of all time values in the timing array. The first way is that in the above embodiment, it is mentioned that 3 groups of time values are recorded in the timing array. Therefore, in this embodiment, 3 time values in the timing array are taken as an example, and the 3 groups of time values are obtained as 10us, 15us, and 20us respectively. For 10us, its range is set to 8-12us, for 15us, its range is set to 13-17us, and for 20us, its range is set to 18-22us. According to the three groups of ranges, a fluctuation range suitable for multiple time values is set to ±2us for each time value. The second way is that in the above embodiment, it is mentioned that 3 groups of time values are recorded in the timing array. Therefore, in this embodiment, 3 time values in the timing array are taken as an example, and the 3 groups of durations are obtained as 10us, 15us, and 20us respectively. The average value of the 3 groups of durations is taken as 15us, and the range of the average value 15us is set to 13-17us. At this time, only the average value of the duration is required to be in the range of 13-17us to meet the requirements. It can be seen that after taking the average time value, its fluctuation range is the average value of the time value ±2us. In this embodiment, there is no requirement for the method of calculating the fluctuation range, as long as the obtained fluctuation range can cover the time value within a reasonable range. It should be noted that the above-mentioned each time value ±2us and the average value ±2us are only one of many embodiments, and the fluctuation range can also be each time value ±3us and the average value ±3us, and can also be each time value ±0.1us and the average value ±0.1us.
[0084] Figure 3 A flowchart of a polling method for unfinished I / O communication provided in an embodiment of the present application. When the information representing the result of the I / O communication is read as unfinished, based on the above embodiment, as a more preferred embodiment, Figure 3 As shown, if the I / O communication is not completed, returning to the step of generating information representing the result of the I / O communication, further comprising:
[0085] S30: Determine whether the I / O communication has performed the first sleep.
[0086] S31: Determine whether there is a reference sleep duration.
[0087] S32: Sleeping according to the default sleep duration.
[0088] If the first sleep has been performed, the process proceeds to step S31 ; if the first sleep has not been performed, the process proceeds to step S10 according to the default sleep duration.
[0089] Among them, judging whether there is a reference sleep duration includes:
[0090] S33: Sleeping according to the reference sleep duration.
[0091] S34: Sleeping according to the default sleep duration.
[0092] If there is a reference sleep duration, sleep is performed according to the reference sleep duration and the process returns to step S10; if there is no reference sleep duration, sleep is performed according to the default sleep duration and the process returns to step S10.
[0093] In this embodiment, the reference sleep duration is a sleep duration set in advance, and the reference sleep duration is usually shorter than the sleep duration mentioned above. By judging whether the I / O communication has performed the first sleep, it is determined whether the current I / O communication can sleep according to the default sleep duration. After the first sleep, it is judged whether there is a reference sleep duration. If there is a reference sleep duration, sleep is performed according to the reference sleep duration. It can save computer power consumption to a certain extent.
[0094] Figure 4 A flowchart of a polling method for I / O communication errors provided in an embodiment of the present application. Based on the above embodiment, as a more preferred embodiment, Figure 4 As shown, before reading the information representing the result of I / O communication and after creating the timing array, it also includes:
[0095] S35: Initialize the default sleep duration, wherein the initialized default sleep duration is 0.
[0096] In the above embodiment, the sleep duration is assigned to the default sleep duration, which is equivalent to an update of the default sleep duration; in addition, in the step of calculating the default sleep duration according to the preset coefficient, sleeping is performed according to the calculated default sleep duration, which is equivalent to updating the initialized default sleep duration. It can be seen that the default sleep duration is changing, so the default sleep duration needs to be initialized.
[0097] Based on the above embodiment, as a more preferred embodiment, it also includes:
[0098] S40: When an error is determined based on the information representing the I / O communication result, an error reporting process is performed to promptly remind the technician that the I / O communication is wrong.
[0099] The overall application process of the polling method is as follows:
[0100] Create a timing array that can record multiple time values, initialize them all, and after initialization, all the time values are 0. This timing array is subsequently used to record the duration of waiting for I / O communication results for the most recent multiple I / O communications. For example, this timing array can record 3 elements, all of which are initialized at the beginning and assigned a value of 0, and then the duration of waiting for I / O communication results for the most recent three times can be recorded.
[0101] Initialize the default sleep duration to 0.
[0102] The steps mentioned above that need to be initialized all occur during the system initialization phase, and before I / O communication is performed. After the I / O communication is initiated, the information representing the result of the I / O communication is read.
[0103] Perform different processing according to the information representing the I / O communication results:
[0104] When the information representing the result of the I / O communication indicates that the I / O communication is not completed, then:
[0105] It is necessary to determine whether the first sleep of this I / O communication is about to be performed. If the first sleep has been performed and the reference sleep duration is not equal to 0 (the reference sleep duration of the previous I / O communication is valid, such as 20us), the first sleep is performed according to the reference sleep duration (20us), otherwise the sleep is performed according to the default sleep duration (pre-given unit sleep duration, such as 1us). During the sleep period, the operating system will schedule other software programs to run on the CPU.
[0106] At this time, if there is no previous reference sleep time (for example, when I / O communication occurs for the first time), polling is performed with a very short default sleep time as the period. When the information representing the I / O communication result is queried, indicating that the I / O communication has been completed, the next I / O communication will be performed and the sleep time will be calculated. It should be noted that the sleep time can be obtained by timing with a timing device, or by calculating the formula: sleep time = default sleep time * number of polling times.
[0107] If the first sleep of this I / O communication is to be performed and there is a reference sleep time for the previous I / O communication, the reference sleep time is used directly; if it is not the first sleep of this I / O communication, it means that the reference sleep time is not enough for this I / O communication, and it is necessary to perform multiple pollings with a very short default sleep time as the polling cycle until the information representing the I / O communication result is queried to indicate that the I / O communication has been completed. After the next I / O communication is performed, the operation of reading the information representing the I / O communication result is performed again.
[0108] When the information representing the result of the I / O communication indicates that the I / O communication has been completed:
[0109] The information recording the I / O communication from initiation to polling to characterizing the I / O communication result indicates the sleep duration when the I / O communication has been completed. It should be noted that the sleep duration can be obtained by timing with a timing device, or by summing up the default sleep duration experienced by this I / O communication.
[0110] The sleep duration obtained above is put into the timing array, and the oldest time value in the timing array is replaced to ensure that the timing array always records the sleep duration of the most recent I / O communications.
[0111] Determine whether the latest time values in the timing array are the same. If they are the same, it means that the recent I / O communications have only performed the first sleep and obtained the results of the I / O communication. At this time, it can be considered that the recent I / O communication tasks have become lighter than before, and the reference sleep time can be slightly shortened to make the first sleep of the next I / O communication slightly shorter. This can be achieved by setting a coefficient less than 1. For example, the sleep time of the recent I / O communications is 20us, and the coefficient is set to 0.9. According to the above-mentioned formula: default sleep time = sleep time * coefficient, it is calculated that the default sleep time at this time = 20us * 0.9 = 18us, then the first sleep of the next I / O communication is 18us. At this time, the default sleep time is updated to 18us. If they are different, it means that the weight of the recent I / O communication tasks has fluctuated, and the reference sleep time should not be shortened.
[0112] Calculate the reasonable upper and lower fluctuation range of all time values in the timing array. If the sleep duration is within the calculated fluctuation range, it means that the weight of this I / O communication task is similar to the weight of the previous multiple I / O communication tasks, and the sleep duration is updated as the reference sleep duration for the next I / O communication. If the sleep duration is not within the fluctuation range, it means that this I / O communication task may suddenly become very heavy or very light. It may be a sudden temporary I / O communication task or sudden environmental interference, resulting in a dramatic fluctuation in the time consumption. It is uncertain whether such fluctuations will occur multiple times in a row. Therefore, the reference sleep duration is not updated at this time.
[0113] When the current I / O communication is completely completed, if there is another I / O communication, it is necessary to wait for the result of the I / O communication and read the information representing the result of the I / O communication to start the next I / O communication polling.
[0114] When the information characterizing the result of the I / O communication indicates that an error has occurred, then:
[0115] Perform error processing, such as retrying the I / O communication or resetting the status register.
[0116] In the above embodiments, the polling method is described in detail, and the present application also provides corresponding embodiments of the polling device.
[0117] Figure 5 This is a structural diagram of a polling device provided in an embodiment of the present application. Figure 5 As shown, the present application also provides a polling device, including:
[0118] A reading module 50, used to read information representing the I / O communication result;
[0119] A judging module 51, used to judge whether the I / O communication is completed according to the information;
[0120] A recording module 52, for recording the sleep duration from initiation of the I / O communication to completion of the I / O communication if the I / O communication is completed, wherein the sleep duration is used as the default sleep duration for the next I / O communication;
[0121] The return module 53 is used to return to the step of reading the information representing the result of the I / O communication if the I / O communication is not completed.
[0122] Since the embodiments of the apparatus part correspond to the embodiments of the method part, please refer to the description of the embodiments of the method part for the embodiments of the apparatus part, which will not be repeated here.
[0123] Figure 6 This is a structural diagram of another polling device provided in an embodiment of the present application. Figure 6 As shown, the polling device includes:
[0124] A memory 60, for storing computer programs;
[0125] The processor 61 is used to implement the steps of the polling method mentioned in the above embodiment when executing the computer program.
[0126] The polling device provided in this embodiment may include but is not limited to a smart phone, a tablet computer, a laptop computer, or a desktop computer.
[0127] Among them, the processor 61 may include one or more processing cores, such as a 4-core processor, an 8-core processor, etc. The processor 61 can be implemented in at least one hardware form of DSP (Digital Signal Processor), FPGA (Field-Programmable Gate Array), and PLA (Programmable Logic Array). The processor 61 may also include a main processor and a coprocessor. The main processor is a processor for processing data in the awake state, also known as a CPU; the coprocessor is a low-power processor for processing data in the standby state. In some embodiments, the processor 61 may be integrated with a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content to be displayed on the display screen. In some embodiments, the processor 61 may also include an AI (Artificial Intelligence) processor, which is used to process computing operations related to machine learning.
[0128] The memory 60 may include one or more computer-readable storage media, which may be non-transitory. The memory 60 may also include a high-speed random access memory, and a non-volatile memory, such as one or more disk storage devices, flash memory storage devices. In this embodiment, the memory 60 is at least used to store the following computer program, wherein, after the computer program is loaded and executed by the processor 61, the relevant steps of the polling method disclosed in any of the aforementioned embodiments can be implemented. In addition, the resources stored in the memory 60 may also include an operating system and data, etc., and the storage method may be temporary storage or permanent storage. Among them, the operating system may include Windows, Unix, Linux, etc.
[0129] In some embodiments, the polling device may further include a display screen, an input / output interface, a communication interface, a power supply, and a communication bus.
[0130] Those skilled in the art will understand that Figure 6 The structure shown in the figure does not constitute a limitation of the polling device, and may include more or less components than shown in the figure.
[0131] The polling device provided in the embodiment of the present application includes a memory 60 and a processor 61. When the processor 61 executes the program stored in the memory, it can implement the above-mentioned polling method.
[0132] Finally, the present application also provides an embodiment corresponding to a computer-readable storage medium. The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps recorded in the above method embodiment are implemented.
[0133] It is understandable that if the method in the above embodiment 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 technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), disk or optical disk and other media that can store program code.
[0134] The above is a detailed introduction to a polling method, device and computer-readable storage medium provided by the present application. The various embodiments in the specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same and similar parts between the embodiments can refer to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can refer to the method part description. It should be pointed out that for ordinary technicians in this technical field, without departing from the principles of the present application, several improvements and modifications can be made to the present application, and these improvements and modifications also fall within the scope of protection of the claims of the present application.
[0135] It should also be noted that, in this specification, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "comprise", "include" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the statement "comprises a ..." does not exclude the presence of other identical elements in the process, method, article or device including the element.
Claims
1. A polling method, characterized in that: include: Read information representing I / O communication results; Determining whether the I / O communication is completed according to the information; If the I / O communication is completed, the sleep duration from initiating the I / O communication to completing the I / O communication is recorded, wherein the sleep duration is used as the default sleep duration for the next I / O communication; If the I / O communication is not completed, returning to the step of reading the information representing the result of the I / O communication; Before reading the information representing the I / O communication result, the method further includes: Creating a timing array, wherein the timing array is a collection of time values recorded in the order in which the time values appear and the time values in the timing array are initialized to 0; wherein the number of the timing arrays is multiple, and the number of time values stored in the timing array has a maximum value; If the I / O communication is completed, recording the sleep duration from initiating the I / O communication to completing the I / O communication includes: Replace the time value that first appears in the timing array with the sleep duration; Determine whether the sleep durations in the preset I / O communication times are the same; If yes, a preset coefficient is set and the default sleep duration is calculated according to the preset coefficient, wherein the coefficient is less than 1; If not, updating the sleep duration to the default sleep duration, wherein the updated default sleep duration is used as the default sleep duration for the next I / O communication; After determining whether the sleep duration is the same in the preset I / O communication times and before updating the sleep duration to the default sleep duration, the method further includes: Calculating the fluctuation range of all the time values in the timing array; wherein the fluctuation range is calculated by: respectively setting the range of each time value in the timing array, and setting the fluctuation range according to the range of each time value; or obtaining the average value of each time value in the timing array, and setting the fluctuation range according to the average value; Determining whether the sleep duration is within the fluctuation range; If yes, then entering the step of updating the sleep duration to the default sleep duration; If not, return to the step of reading the information representing the I / O communication result; If the I / O communication is not completed, returning to the step of reading the information representing the I / O communication result, further comprising: Determine whether the I / O communication has performed the first sleep; If the first sleep has been performed, determine whether there is a reference sleep duration; If the first sleep is not performed, sleeping according to the default sleep duration and returning to the step of reading the information representing the I / O communication result; The determining whether there is a reference sleep duration includes: If there is the reference sleep duration, sleeping according to the reference sleep duration and returning to the step of reading the information representing the I / O communication result; If there is no reference sleep duration, entering the step of sleeping according to the default sleep duration and returning to the step of reading the information representing the I / O communication result; Before reading the information representing the I / O communication result and after creating the timing array, the method further includes: Initializing the default sleep duration, wherein the default sleep duration after initialization is 0; The method further includes: when an error is determined according to the information representing the I / O communication result, performing error reporting processing.
2. A polling device, characterized in that: include: A reading module, used to read information representing I / O communication results; A judging module, used for judging whether the I / O communication is completed according to the information; a recording module, configured to record the sleep duration from initiating the I / O communication to completing the I / O communication if the I / O communication is completed, wherein the sleep duration is used as the default sleep duration for the next I / O communication; A return module, configured to return to the step of reading the information representing the result of the I / O communication if the I / O communication is not completed; Before reading the information representing the I / O communication result, the method further includes: Creating a timing array, wherein the timing array is a collection of time values recorded in the order in which the time values appear and the time values in the timing array are initialized to 0; wherein the number of the timing arrays is multiple, and the number of time values stored in the timing array has a maximum value; If the I / O communication is completed, recording the sleep duration from initiating the I / O communication to completing the I / O communication includes: Replace the time value that first appears in the timing array with the sleep duration; Determine whether the sleep durations in the preset I / O communication times are the same; If yes, a preset coefficient is set and the default sleep duration is calculated according to the preset coefficient, wherein the coefficient is less than 1; If not, updating the sleep duration to the default sleep duration, wherein the updated default sleep duration is used as the default sleep duration for the next I / O communication; After determining whether the sleep duration is the same in the preset I / O communication times and before updating the sleep duration to the default sleep duration, the method further includes: Calculating the fluctuation range of all the time values in the timing array; wherein the fluctuation range is calculated by: respectively setting the range of each time value in the timing array, and setting the fluctuation range according to the range of each time value; or obtaining the average value of each time value in the timing array, and setting the fluctuation range according to the average value; Determining whether the sleep duration is within the fluctuation range; If yes, then entering the step of updating the sleep duration to the default sleep duration; If not, return to the step of reading the information representing the I / O communication result; If the I / O communication is not completed, returning to the step of reading the information representing the I / O communication result, further comprising: Determine whether the I / O communication has performed the first sleep; If the first sleep has been performed, determine whether there is a reference sleep duration; If the first sleep is not performed, sleeping according to the default sleep duration and returning to the step of reading the information representing the I / O communication result; The determining whether there is a reference sleep duration includes: If there is the reference sleep duration, sleeping according to the reference sleep duration and returning to the step of reading the information representing the I / O communication result; If there is no reference sleep duration, entering the step of sleeping according to the default sleep duration and returning to the step of reading the information representing the I / O communication result; Before reading the information representing the I / O communication result and after creating the timing array, the method further includes: Initializing the default sleep duration, wherein the default sleep duration after initialization is 0; The method further includes: when an error is determined according to the information representing the I / O communication result, performing error reporting processing.
3. A polling device, characterized in that: include: Memory for storing computer programs; A processor, configured to implement the steps of the polling method as claimed in claim 1 when executing the computer program.
4. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the polling method according to claim 1 are implemented.