A hybrid polling method, device, equipment and readable storage medium
By obtaining the number of instructions from the host machine and dynamically adjusting the hybrid polling mode, the problem that the hybrid polling algorithm in the prior art cannot switch between high and low load conditions is solved, thereby reducing system energy consumption and improving performance.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-15
- Publication Date
- 2026-03-24
AI Technical Summary
Existing hybrid polling algorithms cannot effectively switch between high and low load conditions, resulting in wasted CPU resources and increased energy consumption, and failing to meet high throughput requirements.
By obtaining the number of instructions to be processed from the host machine, setting polling and interrupt thresholds, dynamically switching between polling and interrupt modes, judging system load changes based on the number of instructions, and precisely controlling the switching timing of hybrid polling.
It achieves improved system efficiency by reducing system power consumption, minimizing CPU resource waste and heat dissipation issues while maintaining performance advantages.
Smart Images

Figure CN115686863B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of computers, in particular to a hybrid polling method, device and equipment and readable storage medium. BACKGROUND
[0002] With the rapid development and progress of computer storage and network hardware technologies, the bottleneck of computer systems gradually shifts from hardware to CPU. The main purpose of interrupt technology when it was designed and used was to save CPU computing resources. However, with the increase of throughput of external devices and the decrease of corresponding delay, the overhead brought by processing interrupts to the CPU has gradually become one of the factors affecting high-performance systems.
[0003] However, the polling mode does not have the overhead brought by processing interrupts to the CPU. However, since the rate of external devices such as storage or network is lower than the processing rate of the CPU, and the polling mode will 100% occupy the CPU time slice, resulting in a large number of idle operations of the CPU in polling, thereby wasting CPU resources and causing more hardware cooling problems.
[0004] In the hybrid polling mode, the system adopts the efficient polling mode in the high-load mode to obtain higher system performance, and in the low-load period, the CPU, FPGA and other computing hardware are allowed to adopt the interrupt mode or sleep for a period of time. The switching algorithm of the hybrid polling mode determines the efficiency of the hybrid polling algorithm.
[0005] In the existing algorithms, the hybrid polling algorithm suitable for ultra-low delay storage devices mainly aims to obtain lower I / O delay time, and cannot meet the demand of high throughput of the device; the hybrid polling interrupt used in the network predicts that the device will remain in a high-load working state in a future period of time according to the received data packet rate, and cannot obtain good results in some burst traffic background.
[0006] In summary, how to effectively solve the problems such as hybrid polling switching is a technical problem that needs to be solved by the technical personnel in the field at present. SUMMARY
[0007] The purpose of the present application is to provide a hybrid polling method, device, equipment and readable storage medium, which obtains the number of instructions to be processed in the host computer to determine the system load change, so that the timing of hybrid polling switching and polling is more accurate, thereby reducing the system energy consumption while maintaining the performance advantage.
[0008] To solve the above technical problems, the present application provides the following technical solutions:
[0009] A hybrid polling method, comprising:
[0010] acquiring a number of instructions to be sent from a host computer;
[0011] determining whether the number of instructions is greater than a polling threshold;
[0012] if yes, entering a polling mode to process the instructions generated by the host computer;
[0013] if no, entering an interrupt mode to process the instructions.
[0014] Preferably, the entering the polling mode to process the instructions generated by the host computer comprises:
[0015] processing the instructions in the polling mode;
[0016] counting a number of processed instructions in a current polling cycle;
[0017] after the current polling cycle, determining whether the number of processed instructions is greater than an interrupt threshold;
[0018] if yes, continuing to keep the polling mode to process the instructions;
[0019] if no, entering the interrupt mode to process the instructions.
[0020] Preferably, the counting the number of processed instructions in the current polling cycle comprises:
[0021] counting a number of recycled instructions sent to the host computer in the current polling cycle;
[0022] determining the number of recycled instructions as the number of processed instructions.
[0023] Preferably, the method further comprises:
[0024] adjusting a polling frequency or a polling time to adjust a length of a polling cycle.
[0025] Preferably, the acquiring the number of instructions to be sent from the host computer comprises:
[0026] acquiring the number of instructions in the polling mode or the interrupt mode.
[0027] Preferably, the entering the interrupt mode to process the instructions comprises:
[0028] acquiring the instructions sent from the host computer and switching a context;
[0029] after the context switching, processing the instructions.
[0030] Preferably, the entering the polling mode to process the instructions generated by the host computer comprises:
[0031] polling the host computer, obtaining instructions generated by the host computer, and processing the instructions.
[0032] A hybrid polling device comprises:
[0033] an instruction number obtaining module, configured to obtain a number of instructions to be sent from the host computer;
[0034] a judging module, configured to judge whether the number of instructions is greater than a polling threshold value;
[0035] an instruction processing module, configured to enter a polling mode to process the instructions generated by the host computer if the number of instructions is greater than the polling threshold value, and enter an interrupt mode to process the instructions if the number of instructions is not greater than the polling threshold value.
[0036] An electronic device comprises:
[0037] a memory, configured to store a computer program;
[0038] a processor, configured to implement the steps of the hybrid polling method when executing the computer program.
[0039] A readable storage medium, on which a computer program is stored, the computer program is executed by a processor to implement the steps of the hybrid polling method.
[0040] According to the method provided in the embodiments of the present application, the number of instructions to be sent from the host computer is obtained, it is judged whether the number of instructions is greater than a polling threshold value, the polling mode is entered to process the instructions generated by the host computer if the number of instructions is greater than the polling threshold value, and the interrupt mode is entered to process the instructions if the number of instructions is not greater than the polling threshold value.
[0041] In the present application, the number of instructions to be sent from the host computer is obtained first. Since the instructions to be sent are the instructions to be processed, the system load change condition can be judged more accurately based on the number of instructions. Specifically, the polling threshold value can be set, the polling mode is entered to process the instructions generated by the host computer if the number of instructions is greater than the polling threshold value, and the interrupt mode is entered to process the instructions generated by the host computer if the number of instructions is not greater than the polling threshold value. That is, in the present application, the number of instructions to be processed on the I / O path is obtained to judge the system load change condition, so that the timing of the hybrid polling interrupt switching is more accurate, and the system energy consumption is reduced while the performance advantage is maintained.
[0042] Correspondingly, the embodiments of the present application further provide a hybrid polling device, an electronic device and a readable storage medium corresponding to the hybrid polling method, which have the above technical effects and will not be described here. BRIEF DESCRIPTION OF DRAWINGS
[0043] In order to make the technical scheme of the present application or the related art clearer, the accompanying drawings needed in the embodiment or the related art description will be briefly introduced. Obviously, the accompanying drawings in the following description only constitute some embodiments of the present application, and all other embodiments obtained by those of ordinary skill in the art without creative work based on the accompanying drawings also belong to the protection scope of the present application.
[0044] Figure 1 Flow chart for implementing a hybrid polling method in an embodiment of the present application;
[0045] Figure 2 Schematic diagram of a hybrid polling for a low-latency device;
[0046] Figure 3 Schematic diagram of a hybrid interrupt polling mode;
[0047] Figure 4 Schematic diagram of a system architecture in an embodiment of the present application;
[0048] Figure 5 Schematic diagram of a specific implementation of a hybrid polling method in an embodiment of the present application;
[0049] Figure 6 Schematic diagram of a structure of a hybrid polling device in an embodiment of the present application;
[0050] Figure 7 Schematic diagram of a structure of an electronic device in an embodiment of the present application;
[0051] Figure 8 Schematic diagram of a specific structure of an electronic device in an embodiment of the present application. DETAILED DESCRIPTION
[0052] In order to make the technical scheme of the present application or the related art clearer, the accompanying drawings needed in the embodiment or the related art description will be briefly introduced. Obviously, the accompanying drawings in the following description only constitute some embodiments of the present application, and all other embodiments obtained by those of ordinary skill in the art without creative work based on the accompanying drawings also belong to the protection scope of the present application.
[0053] Please refer to Figure 1 , Figure 1 Flow chart for implementing a hybrid polling method in an embodiment of the present application, which can be applied to a peripheral system of a host computer, such as an embedded system. The method will be described in detail below by taking an application to an embedded system as an example. For the application in other peripheral systems, reference can be made to this, and will not be listed one by one here. Specifically, to implement the method, the following steps are included:
[0054] S101, obtaining the number of instructions to be sent from the host computer.
[0055] The host computer storage system generates instructions such as storage instructions that need to be processed by the embedded system, and inserts the instructions into the tail of the sending instruction queue for processing.
[0056] The embedded system can obtain the number of instructions to be sent from the host computer. It should be noted that the number of instructions here refers to the number of instructions generated by the host computer and needing to be processed by the embedded system but not yet sent to the embedded system or not yet actively pulled by the embedded system.
[0057] That is, the number of instructions in the embodiment of the application refers to the number of instructions that the embedded system will need to process, rather than the number of instructions currently being processed, nor the number of instructions that have been processed.
[0058] Specifically, in one specific embodiment of the application, obtaining the number of instructions to be sent from the host computer includes: obtaining the number of instructions in a polling mode or an interrupt mode. That is, in the application, the number of instructions to be sent from the host computer can be obtained in a polling mode or in an interrupt mode.
[0059] S102, determining whether the number of instructions is greater than a polling threshold.
[0060] Since the number of instructions corresponds to instructions to be processed, the number of instructions can be used to evaluate whether the load to be faced is high. Specifically, in the embodiment of the application, a polling threshold is set to measure the load state represented by the number of instructions. The specific value of the polling threshold can be determined according to the instructions corresponding to the high load. The lowest number of instructions required for processing in the high load state can be used as the polling threshold, or the energy consumption of the interrupt mode can be counted to obtain a corresponding relationship curve between the number of instructions and the energy consumption, and based on the curve, the number of instructions corresponding to the high energy consumption or the energy consumption turning point is found, and the number is determined as the polling threshold. For example, the polling threshold can be valued between 30 and 50, and of course the size of the polling threshold can also be set and adjusted according to the actual system processing performance and requirements.
[0061] After obtaining the determination result, different processing strategies can be used to process the instructions according to different determination results. Specifically, if the determination result is yes, step S103 is executed; if the determination result is no, step S104 is executed.
[0062] S103, entering a polling mode to process the instructions generated by the host computer.
[0063] When it is determined that the number of instructions is greater than the polling threshold, it indicates that the amount of instructions to be processed is high load, and in the high load case, the interrupt mode cannot quickly process the instructions, and repeated switching of context information also consumes additional resources, so the polling mode can be entered to process the instructions generated by the host.
[0064] It should be noted that the entry into the polling mode can be divided into two cases, one is that the current mode is the interrupt mode, and the polling mode is entered, that is, the interrupt mode is switched to the polling mode; the second is that the current mode is the polling mode, and the polling mode is entered, that is, the polling mode is maintained.
[0065] In an embodiment of the present application, the polling mode is entered to process the instructions generated by the host, including: polling the host to obtain the instructions generated by the host, and processing the instructions. In the polling mode, the embedded system actively polls the host to obtain the instructions generated by the host, and then processes the instructions. In the polling mode, context switching is not required.
[0066] Specifically, for the polling mode, how to process the instructions generated by the host can be specifically referred to the specific definition and implementation of the polling mode, and the processing program corresponding to the instructions, which will not be repeated here.
[0067] S104, enter the interrupt mode to process the instructions.
[0068] When it is determined that the number of instructions is not greater than the polling threshold, it indicates that the amount of instructions to be processed is not high load. If the polling mode is used, there will be a high idle operation, which will cause waste of CPU resources and system heat dissipation problems, so the interrupt mode can be entered to process the instructions generated by the host.
[0069] It should be noted that the entry into the interrupt mode can be divided into two cases, one is that the current mode is the polling mode, and the polling mode is entered, that is, the polling mode is switched to the interrupt mode; the second is that the current mode is the interrupt mode, and the interrupt mode is entered, that is, the interrupt mode is maintained.
[0070] In an embodiment of the present application, in an embodiment of the present application, the interrupt mode is entered to process the instructions, including:
[0071] Step 1, obtaining the instructions sent by the host and switching the context;
[0072] Step 2, after completing the context switching, processing the instructions.
[0073] For ease of description, the above two steps will be combined for description.
[0074] In the interrupt mode, the embedded system acquires the instruction sent by the host computer, and after acquiring the instruction, informs the embedded CPU to switch context, calls the interrupt processing program, and processes the instruction.
[0075] Specifically, for entering the interrupt mode, how to process the instruction generated by the host computer can be specifically referred to the specific definition and implementation of the interrupt mode and the processing program corresponding to the instruction, which will not be described here.
[0076] The method provided by the embodiment of the application acquires the number of instructions to be sent from the host computer, judges whether the number of instructions is greater than a polling threshold, if yes, enters the polling mode to process the instruction generated by the host computer, and if no, enters the interrupt mode to process the instruction.
[0077] In the application, first, the number of instructions to be sent is acquired from the host computer. Since the instructions to be sent are instructions to be processed, the system load change condition can be more accurately judged based on the number of instructions. Specifically, a polling threshold can be set, when the number of instructions is greater than the polling threshold, it is determined to enter the polling mode, and the instruction generated by the host computer is processed in the polling mode; when the number of instructions is not greater than the polling threshold, it is determined to enter the interrupt mode, and the instruction generated by the host computer is processed in the interrupt mode. That is, in the application, the number of instructions waiting to be processed on the I / O path is acquired to judge the system load change condition, so that the timing of the hybrid polling switching interrupt is more accurate, and thus the system energy consumption is reduced while the performance advantage is maintained.
[0078] It should be noted that based on the above embodiment, the application embodiment also provides a corresponding improvement scheme. The steps involved in the preferred / modified embodiment can be mutually referred to between the above embodiment or corresponding steps, and the corresponding beneficial effects can also be mutually referred to. In the preferred / modified embodiment of the application, it will not be described here.
[0079] In a specific embodiment of the application, the processed instructions can also be counted in the polling mode, so as to determine whether to exit the polling mode. Specifically, after entering the polling mode in step S103 to process the instruction generated by the host computer, it can specifically include:
[0080] Step one, processing the instruction in the polling mode;
[0081] Step two, counting the number of processed instructions in the current polling period;
[0082] Step three, after the current polling period ends, judging whether the number of processed instructions is greater than an interrupt threshold;
[0083] Step four, if yes, continue to keep the polling mode, process the instruction;
[0084] Step five, if no, enter the interrupt mode, process the instruction.
[0085] For the convenience of description, the above five steps will be described in combination.
[0086] In the polling mode, the specific process of processing the instruction can refer to the description above. In the current polling cycle, the processing quantity of the processed instruction can be counted. Due to the polling mode, there may be idle operation, so the processing quantity of the processed instruction is counted, and based on the processing quantity, it can be inferred whether the current polling mode causes additional resource waste.
[0087] Specifically, after the current polling cycle ends, it can be judged whether the processing quantity is greater than the interrupt threshold, if yes, it indicates that the current idle operation is less, which belongs to the high load state, at this time, it is not necessary to switch to the interrupt mode, and the polling mode can be continued to process the instruction; if no, it indicates that the current idle operation is more, which does not belong to the high load state, at this time, it is not necessary to continue to keep the polling mode, but switch to the interrupt mode to process the instruction, thereby reducing resource waste.
[0088] Among them, the interrupt threshold can be set and adjusted according to actual needs, for example, the interrupt threshold can be set to 10.
[0089] Among them, the polling times or the polling time are adjusted to adjust the time length of the polling cycle. That is, a polling cycle corresponds to the polling times and the polling time, based on adjusting the polling times or the polling time, the time length of the polling cycle (time length=polling times and polling time) can be adjusted. The specific time length that needs to be adjusted to how long can be set and adjusted according to actual needs, which is not limited by the embodiment.
[0090] Among them, step two counts the processing quantity of the processed instruction in the current polling cycle, including:
[0091] Step 1, count the recycling quantity of the recycling instruction sent to the host in the current polling cycle;
[0092] Step 2, determine the recycling quantity as the processing quantity.
[0093] That is, the embedded device (embedded system) can interact with the host through the PCIe protocol. The host allows storage of application programs, inserts storage instructions into the to-be-processed queue (sending queue), and the embedded system obtains the to-be-processed instructions from the host through the FPGA preprocessing module and sends them to the embedded CPU polling processing module for processing. When the storage instruction processing is completed, the recycling instruction is generated and sent to the host recycling queue through the FPGA for recycling processing.
[0094] That is, the set of recycling instructions is the processed instructions, and based on the number of recycling instructions, it can be indicated whether the current system load is suitable for continuing to maintain polling.
[0095] In order to enable those skilled in the art to better understand the hybrid polling method provided by the embodiments of the present application, the hybrid polling method will be described in detail below in conjunction with specific application scenarios and related technologies.
[0096] By obtaining the speed of CPU processing data packets, it is predicted whether to start the polling mode. If it is judged that the throughput speed of the device in the future period of time is low, the interrupt mode or sleep for a period of time is performed; if it is predicted that the future throughput reaches a certain threshold, the polling is started to obtain higher performance advantage.
[0097] The specific implementation scheme is:
[0098] Scheme a: please refer to Figure 2 , Figure 2 is a schematic diagram of hybrid polling for low-latency devices. With the development of NVMe SSD hardware technology, the ultra-low latency of storage hardware has become one of the indicators that delay-sensitive applications value very much. The efficient hybrid polling algorithm on the ultra-latency device is based on the average latency time of the storage device to predict the sleep interval of the hybrid polling algorithm, so as to start the polling work before the I / O returns, as shown in Figure 2 . This algorithm can reduce CPU utilization by 5%-40% and provide up to 10% faster I / O latency.
[0099] The characteristics of scheme a: ultra-low latency devices mainly aim to obtain lower I / O latency time, and cannot meet the demand of high throughput of the device.
[0100] Scheme b: please refer to Figure 3 , Figure 3 is a schematic diagram of a hybrid interrupt polling mode. Using a hybrid polling mode in a network device is a common performance optimization method. In this mode, the network system uses the interrupt mode to process data packets in the low network load condition, and uses the polling mode in the high load mode. The method of judging the load is to judge the number of data packets processed by one interrupt ISR (interrupt service routine), as shown inFigure 3 If greater than a certain threshold, the system switches to polling mode, otherwise remains in interrupt mode.
[0101] The feature of this scheme b: the hybrid polling interrupt used in the network, according to the received data packet rate to predict the future period of time the device will remain in a high load state, in some burst traffic background can not get very good results.
[0102] In energy-sensitive hardware, the energy loss or heat dissipation problem caused by using the polling mode is very serious. For example, in embedded chips, using the polling mode software to process data requires more powerful computing devices and higher-end heat dissipation equipment. Hybrid polling can solve the heat dissipation and energy loss problems of energy-sensitive devices, but the switching polling algorithm determines the overall efficiency of the system.
[0103] From the above, to solve the above problems, the present application proposes an adaptive hybrid polling algorithm based on waiting for processing data, which can effectively reduce the energy waste problem caused by polling of computing hardware on embedded storage devices, thereby reducing cost and improving efficiency.
[0104] In the present application, the embedded device interacts with the host computer through the PCIe protocol. The host computer allows the storage application to insert the storage instruction into the to-be-processed queue (illustrated as the sending queue), and the embedded system obtains the to-be-processed instruction from the host computer through the FPGA (Field-programmable gate array, field programmable gate array) preprocessing module, and sends it to the CPU polling processing module for processing. When the storage instruction processing is completed, the recycling instruction is generated and sent to the host computer recycling queue through the FPGA for recycling processing.
[0105] Unlike the network I / O processing path, the recycling queue instruction of the storage path comes from the sending queue (to-be-processed queue) in the system, so the number of sending queue commands or the number of flying commands on the storage I / O processing path can be used to determine whether the system load is suitable for polling.
[0106] For details, please refer to Figure 4 and Figure 5 , Figure 4 is a system architecture schematic diagram in an embodiment of the present application, Figure 5 is a specific implementation schematic diagram of a hybrid polling method in an embodiment of the present application. The specific steps are described as follows:
[0107] 1. The host computer storage system generates a storage instruction and inserts it into the tail of the sending instruction queue for processing;
[0108] 2. The FPGA hardware pulls the to-be-processed instruction in the HOSTQ and obtains the number of waiting commands (same as instructions).
[0109] 3. If the number of waiting commands is less than the threshold a (polling threshold), the embedded system still keeps the interrupt mode, and the command is processed by the interrupt thread;
[0110] 4. If the number of waiting commands is greater than or equal to the threshold a, the system switches to the polling mode to process the command by polling;
[0111] 5. The system polls the send queue command in the polling period, and the length of time can be changed by configuring the polling number (loop_count) or setting the polling time (loop_time);
[0112] 6. When each polling period ends, whether the current is in the high load mode is determined by judging the number of processed commands;
[0113] 7. If the number of processed commands is greater than the threshold b (interrupt threshold), it is considered that the current is in the high load mode, and the system continues the polling mode, otherwise, it returns to step 2;
[0114] 8. The system exits.
[0115] That is, in the present application, the number of waiting queues on the I / O path is obtained to determine the system load change, so that the timing of switching the interrupt of the hybrid polling algorithm is more accurate, thereby reducing the system energy consumption while maintaining the performance advantage.
[0116] Experiments have verified that the hybrid polling method provided by the embodiments of the present application effectively reduces the energy consumption problem of the computing device in the low load mode, so that the heat dissipation is significantly reduced, and the high throughput and low delay performance close to the polling mode can be obtained in the high load.
[0117] Corresponding to the above method embodiments, the embodiments of the present application also provide a hybrid polling device, and the hybrid polling device described below can be referred to each other.
[0118] Referring to Figure 6 , the device includes the following modules:
[0119] The instruction number acquisition module 101 is configured to acquire the number of instructions to be sent from the host computer;
[0120] The judgment module 102 is configured to determine whether the number of instructions is greater than the polling threshold;
[0121] The instruction processing module 103 is configured to enter the polling mode to process the instructions generated by the host computer if yes, and enter the interrupt mode to process the instructions if no.
[0122] The device provided in the embodiment of the application is applied to obtain the number of instructions to be sent from the host computer, determine whether the number of instructions is greater than a polling threshold, enter a polling mode to process the instructions generated by the host computer if yes, and enter an interrupt mode to process the instructions if no.
[0123] In the application, the number of instructions to be sent is first obtained from the host computer. Since the instructions to be sent are the instructions to be processed, the system load change can be more accurately determined based on the number of instructions. Specifically, the polling threshold can be set, when the number of instructions is greater than the polling threshold, it is determined to enter the polling mode and process the instructions generated by the host computer in the polling mode, and when the number of instructions is not greater than the polling threshold, it is determined to enter the interrupt mode and process the instructions generated by the host computer in the interrupt mode. That is, in the application, the number of instructions waiting to be processed on the I / O path is obtained to determine the system load change, so that the timing of the hybrid polling switching interrupt is more accurate, thereby reducing the system energy consumption while maintaining the performance advantage.
[0124] In one specific embodiment of the application, the instruction processing module 103 is specifically configured to process the instructions in the polling mode.
[0125] The number of processed instructions in the current polling cycle is counted.
[0126] After the current polling cycle ends, it is determined whether the number of processed instructions is greater than an interrupt threshold.
[0127] If yes, the polling mode is continued to process the instructions.
[0128] If no, the interrupt mode is entered to process the instructions.
[0129] In one specific embodiment of the application, the instruction processing module 103 is specifically configured to count the number of recycled instructions sent to the host computer in the current polling cycle.
[0130] The number of recycled instructions is determined as the number of processed instructions.
[0131] In one specific embodiment of the application, it further comprises:
[0132] The polling adjustment module is configured to adjust the polling times or the polling time to adjust the time length of the polling cycle.
[0133] In one specific embodiment of the application, the instruction number obtaining module 101 is specifically configured to obtain the number of instructions in the polling mode or the interrupt mode.
[0134] In one specific embodiment of the application, the instruction processing module 103 is specifically configured to obtain the instructions sent by the host computer and switch the context.
[0135] After the context switch is completed, the instruction is processed.
[0136] In an embodiment of the present application, the instruction processing module 103 is specifically configured to poll the host computer, acquire an instruction generated by the host computer, and process the instruction.
[0137] Corresponding to the above method embodiments, the embodiments of the present application also provide an electronic device. The electronic device described below can be mutually corresponding with reference to the above-described hybrid polling method.
[0138] Referring to Figure 7 As shown in the figure, the electronic device includes:
[0139] The memory 332 is configured to store a computer program.
[0140] The processor 322 is configured to execute the computer program to implement the steps of the hybrid polling method of the above method embodiments.
[0141] Specifically, please refer to Figure 8 , Figure 8 A specific structural diagram of an electronic device provided by the embodiment is shown in the figure. The electronic device can have a large difference due to different configurations or performances, and can include one or more than one processor (central processing unit, CPU) 322 (for example, one or more than one processor) and a memory 332. The memory 332 stores one or more than one computer application program 342 or data 344. The memory 332 can be temporary storage or persistent storage. The program stored in the memory 332 can include one or more than one module (not shown in the figure), and each module can include a series of instruction operations in the data processing device. Further, the central processing unit 322 can be configured to communicate with the memory 332 and execute a series of instruction operations in the memory 332 on the electronic device 301.
[0142] The electronic device 301 can also include one or more than one power supply 326, one or more than one wired or wireless network interface 350, one or more than one input / output interface 358, and / or one or more than one operating system 341.
[0143] The steps in the above-described hybrid polling method can be implemented by the structure of the electronic device.
[0144] Corresponding to the above method embodiments, the embodiments of the present application also provide a readable storage medium. The readable storage medium described below can be mutually corresponding with reference to the above-described hybrid polling method.
[0145] A readable storage medium, a computer program is stored on the readable storage medium, and the computer program is executed by a processor to implement the steps of the hybrid polling method of the method embodiment.
[0146] The readable storage medium can be a U disk, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, or various readable storage media that can store program codes.
[0147] The embodiments in the specification are described in a progressive manner, and each embodiment focuses on the difference from other embodiments. The same or similar parts of each embodiment can be referred to each other. For the device disclosed in the embodiments, since it corresponds to the method disclosed in the embodiments, the description is relatively simple, and the related parts can be referred to the method part.
[0148] Those skilled in the art can further realize that the units and algorithm steps of each example described in combination with the embodiments disclosed in the present text can be realized in electronic hardware, computer software or combination of both. In order to clearly show the interchangeability of hardware and software, the components and steps of each example have been described in the above description. Whether the functions are realized in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to realize the described functions for each specific application, but such implementation should not be considered beyond the scope of the present application.
[0149] The steps of the method or algorithm described in combination with the embodiments disclosed in the present text can be directly implemented by hardware, software module executed by a processor, or combination of both. The software module can be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable magnetic disk, a CD-ROM, or any other form of storage medium known in the art.
[0150] Finally, it should be noted that in the present text, relationships such as first and second are merely used to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between the entities or operations. Moreover, the term includes, contains or any other variant is intended to cover non-exclusive inclusion, so that the process, method, article or device including a series of elements not only includes those elements, but also includes other elements not explicitly listed or inherent to such process, method, article or device.
[0151] The principles and implementation manners of the present application are described by using specific examples in the present text, and the above example descriptions are only used for helping to understand the method of the present application and its core idea; meanwhile, for the general technical personnel in the art, according to the idea of the present application, the specific implementation manners and application ranges will have changes, and on the basis of the above, the content of the present description should not be understood as the limitation of the present application.
Claims
1. A hybrid polling method, characterized in that, Peripheral systems used on the host machine include: Obtain the number of instructions to be sent from the host machine; the number of instructions is the number of instructions that the embedded system will need to process. Determine whether the number of instructions is greater than the polling threshold; If so, then enter polling mode and process the instructions generated by the host machine; If not, then enter interrupt mode to process the instruction; wherein, entering polling mode to process the instruction generated by the host machine includes: polling the host machine to obtain the instruction generated by the host machine and processing the instruction; The step of entering polling mode and processing instructions generated by the host machine includes: In the polling mode, the instructions are processed; The number of instructions processed within the current polling cycle is counted. After the current polling cycle ends, determine whether the number of processes exceeds the interruption threshold; If so, continue in the polling mode and process the instruction; If not, then enter the interrupt mode and process the instruction; The number of instructions processed within the current polling cycle includes: The number of recycling commands sent to the host machine during the current polling cycle is counted. The quantity recovered is determined as the quantity processed; Adjust the number of polls or the polling time to adjust the length of the polling cycle; The number of instructions to be sent obtained from the host machine includes: The number of instructions is obtained in either the polling mode or the interrupt mode. The process of entering interrupt mode and handling the instructions includes: Obtain the instructions sent by the host machine and switch the context; After the context switch is completed, the instruction is processed.
2. A hybrid polling device, characterized in that, Peripheral systems used on the host machine include: The instruction count acquisition module is used to obtain the number of instructions to be sent from the host machine; The judgment module is used to determine whether the number of instructions is greater than the polling threshold; An instruction processing module is configured to, if yes, enter polling mode to process instructions generated by the host machine; otherwise, enter interrupt mode to process the instructions. Entering polling mode to process instructions generated by the host machine includes: polling the host machine to obtain instructions generated by the host machine and processing the instructions. Entering polling mode to process instructions generated by the host machine also includes: processing the instructions in the polling mode; counting the number of instructions processed within the current polling cycle; and determining whether the number of instructions processed exceeds the interrupt limit after the current polling cycle ends. If the threshold is met, the polling mode is maintained and the instruction is processed; otherwise, the interrupt mode is entered and the instruction is processed. The process of counting the number of instructions processed within the current polling cycle includes: counting the number of recycling instructions sent to the host machine within the current polling cycle; determining the recycling number as the processing number; adjusting the polling count or polling time to adjust the length of the polling cycle. Entering the interrupt mode and processing the instruction includes: acquiring the instruction sent by the host machine and switching the context; processing the instruction after completing the context switch. The instruction count acquisition module is specifically used to acquire the instruction count in the polling mode or the interrupt mode.
3. An electronic device, characterized in that, include: Memory, used to store computer programs; A processor, configured to implement the steps of the hybrid polling method as described in claim 1 when executing the computer program.
4. A readable storage medium, characterized in that, The readable storage medium stores a computer program that, when executed by a processor, implements the steps of the hybrid polling method as described in claim 1.
Citation Information
Patent Citations
Automatic switching method of message process mode
CN1956438A