Adaptive I2C communication scheduling method based on priority queue and Q-Learning
By combining priority queues and Q-Learning algorithms in I2C communication, priority is dynamically adjusted, and the unfair resource allocation and response delay caused by fixed priority scheduling in multi-master environment are solved, and efficient response and optimized scheduling of the system are achieved. efficiency.
Patent Information
- Application Number
- CN202411334780.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-24
- Publication Date
- 2024-12-20
AI Technical Summary
In the multi-master I2C communication environment, traditional fixed priority scheduling leads to unfair resource allocation and delayed system response, and cannot dynamically adapt to load changes and device request changes, resulting in system performance being unable to be optimized.
Adaptive I2C communication scheduling method based on priority queues and Q-Learning is adopted, and priority is dynamically adjusted through priority queue initialization and Q-Learning algorithm, request processing order is optimized, and scheduling strategies are adjusted based on real-time feedback using reinforcement learning mechanism.
It improves system efficiency and response capabilities in multi-master environments, realizes optimization of scheduling efficiency, and can efficiently handle requests in high-load and multi-task environments, significantly reducing latency.
Smart Images

Figure CN119172331A_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the technical field of communication protocol and data structure design, in particular to an adaptive I2C communication scheduling method based on priority queue and Q-Learning. Background Art
[0002] In embedded systems, I2C (Inter-Integrated Circuit) is a widely used communication protocol for connecting microcontrollers and various peripheral devices. I2C supports multi-master and multi-slave communication, which means that multiple master devices can access the same slave device at the same time. However, in a multi-master environment, communication scheduling and priority management are key challenges. Traditional fixed priority scheduling may lead to unfair resource allocation and system response delay problems.
[0003] In order to overcome the response delay problem caused by fixed priority scheduling, a multi-master device I2C communication scheduling scheme has emerged in the prior art, which adopts priority queue and fixed priority strategy, and the scheduling efficiency relies on static priority allocation and a simple arbitration mechanism; however, these methods cannot dynamically adapt to load changes and changes in device requests, resulting in the inability to optimize system performance in high-load or multi-tasking environments; there is a lack of intelligent scheduling mechanism, and it is impossible to make dynamic adjustments based on real-time data.
[0004] Up to now, the existing technology adopts fixed priority or polling mechanism, which is difficult to dynamically adapt to the request changes of multiple master devices. In actual operation, it is easy to cause delays in processing high-frequency or urgent requests, resulting in unfair resource allocation and low system efficiency. Summary of the invention
[0005] In order to solve the above technical problems, the present invention provides an adaptive I2C communication scheduling method based on priority queue and Q-Learning. By combining the priority queue and the adaptive learning algorithm, the I2C communication scheduling is dynamically optimized, the request processing order is optimized, and the system efficiency and responsiveness in a multi-master device environment are improved, thereby solving the technical problem of low scheduling efficiency under the I2C multi-master request condition in the embedded system.
[0006] An adaptive I2C communication scheduling method based on priority queue and Q-Learning includes the following specific architecture designs:
[0007] Step 1: Initialization of the priority queue;
[0008] ① Initialize the request information of each master device and set the identifier and priority information;
[0009] ② Use heap as the implementation data structure of priority queue;
[0010] ③ Create an empty heap and insert the requests of different tasks into the heap in order according to the priority;
[0011] As an example, the priority determination refers to a method of sorting the requests for different tasks according to their importance or urgency.
[0012] Step 2: Request processing;
[0013] ① Get the best request: Pop out the request with the highest priority (i.e., the root node), assign the I2C bus to the request with the highest priority, and then re-sort the stack and cycle in sequence;
[0014] ② After the request is processed, the processed request is saved in a new queue, and the processing result and system feedback information are recorded;
[0015] As an example, the system feedback information includes: processing time and success or failure.
[0016] Step 3: Cycle scheduling;
[0017] A predetermined time interval (i.e., a cyclic scheduling period) is set for the system, and the processed requests are periodically taken out from the new queue, and the priority is adjusted, and then the adjusted requests are reinserted into the priority queue for sorting;
[0018] Step 4: Q-Learning optimization;
[0019] The Q-Learning algorithm is used to continuously optimize the scheduling strategy and dynamically adjust the priority. The priority in the priority queue is updated based on feedback to ensure that important requests are processed first. At the same time, by learning from historical data, the parameters of Q-Learning are adjusted to optimize the learning effect of the Q-Learning algorithm.
[0020] The specific operations are:
[0021] State definition (state, s): System state includes: communication load, queue length and delay;
[0022] Action definition (action, α): defines the action to adjust the request priority;
[0023] Reward function: Design a reward function to evaluate the effectiveness of the scheduling strategy;
[0024] Q value update: After each cyclic scheduling cycle, the Q value is updated according to the actual effect;
[0025] As an example, the Q value is updated according to the actual effect using the following formula:
[0026]
[0027] Among them, α is the learning rate, γ is the discount factor, r is the reward value, s is the current state, a is the current action, s′ is the next state, and a′ is the next action.
[0028] As an example, the communication load is: the number of requests in the priority queue.
[0029] As an example, the effect of the scheduling strategy is to reduce delays and conflicts.
[0030] As an example, the reward function is used in such a way that a positive reward is given if the adjusted schedule reduces processing delay.
[0031] As an example, the parameters of Q-Learning include: learning rate and discount factor.
[0032] Beneficial effects of the present invention:
[0033] The present invention realizes adaptive optimization of I2C communication scheduling in embedded systems by combining priority queues and Q-Learning algorithms; utilizing the reinforcement learning mechanism of Q-Learning, the system can automatically adjust request priorities according to real-time feedback, thereby improving scheduling efficiency and system response speed.
[0034] This intelligent scheduling method enables the system to demonstrate higher adaptability and optimization capabilities in complex practical applications, and has a high degree of dynamic response to dynamically changing actual processing requests. Especially under frequent requests, compared with existing technologies, it can demonstrate higher efficiency and stability in processing.
[0035] The overall architecture design of the present invention is scientific, reliable and suitable for promotion. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] Figure 1 The figure is a schematic diagram of the overall process architecture of an adaptive I2C communication scheduling method based on priority queue and Q-Learning of the present invention. DETAILED DESCRIPTION
[0037] Below, reference Figure 1 As shown, an adaptive I2C communication scheduling method based on priority queue and Q-Learning includes the following specific architecture designs:
[0038] Step 1: Initialization of the priority queue;
[0039] ① Initialize the request information of each master device and set the identifier and priority information;
[0040] ② Use heap as the implementation data structure of priority queue;
[0041] ③ Create an empty heap and insert the requests of different tasks into the heap in order according to the priority;
[0042] As an example, the priority determination refers to a method of sorting the requests for different tasks according to their importance or urgency.
[0043] Step 2: Request processing;
[0044] ① Get the best request: Pop out the request with the highest priority (i.e., the root node), assign the I2C bus to the request with the highest priority, and then re-sort the stack and cycle in sequence;
[0045] ② After the request is processed, the processed request is saved in a new queue, and the processing result and system feedback information are recorded;
[0046] As an example, the system feedback information includes: processing time and success or failure.
[0047] Step 3: Cycle scheduling;
[0048] A predetermined time interval (i.e., a cyclic scheduling period) is set for the system, and the processed requests are periodically taken out from the new queue, and the priority is adjusted, and then the adjusted requests are reinserted into the priority queue for sorting;
[0049] Step 4: Q-Learning optimization;
[0050] The Q-Learning algorithm is used to continuously optimize the scheduling strategy and dynamically adjust the priority. The priority in the priority queue is updated based on feedback to ensure that important requests are processed first. At the same time, by learning from historical data, the parameters of Q-Learning are adjusted to optimize the learning effect of the Q-Learning algorithm.
[0051] The specific operations are:
[0052] State definition (state, s): System state includes: communication load, queue length and delay;
[0053] Action definition (action, α): defines the action to adjust the request priority;
[0054] Reward function: Design a reward function to evaluate the effectiveness of the scheduling strategy;
[0055] Q value update: After each cyclic scheduling cycle, the Q value is updated according to the actual effect;
[0056] As an example, the Q value is updated according to the actual effect using the following formula:
[0057]
[0058] Among them, α is the learning rate, γ is the discount factor, r is the reward value, s is the current state, a is the current action, s′ is the next state, and a′ is the next action.
[0059] As an example, the communication load is: the number of requests in the priority queue.
[0060] As an example, the effect of the scheduling strategy is to reduce delays and conflicts.
[0061] As an example, the reward function is used in such a way that a positive reward is given if the adjusted schedule reduces processing delay.
[0062] As an example, the parameters of Q-Learning include: learning rate and discount factor.
[0063] In order to better apply the present invention, the application of the present invention to electronic devices and readable storage media is now illustrated by way of specific implementation structures.
[0064] Embodiment 1:
[0065] An electronic device comprises: a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, an adaptive I2C communication scheduling method based on priority queue and Q-Learning of the present invention can be implemented.
[0066] Embodiment 2:
[0067] A readable storage medium stores a computer program. When the computer program is executed by a processor, an adaptive I2C communication scheduling method based on priority queue and Q-Learning of the present invention can be implemented.
[0068] As an example, for the I2C communication scheduling problem of multiple master devices, in addition to the priority queue combined with the Q-Learning reinforcement learning method of the present invention, you can also consider using a scheduling algorithm based on time slice rotation or a dynamic allocation strategy based on a prediction model; although these alternatives can also optimize communication scheduling to a certain extent and avoid the delay problem caused by fixed priority, however, the above solutions are usually difficult to balance the system load and cannot effectively adapt to frequently changing requests under high load conditions.
[0069] The present invention realizes adaptive optimization of I2C communication scheduling in embedded systems by combining priority queues and Q-Learning algorithms; utilizing the reinforcement learning mechanism of Q-Learning, the system can automatically adjust request priorities according to real-time feedback, thereby improving scheduling efficiency and system response speed; this intelligent scheduling method enables the system to exhibit higher adaptability and optimization capabilities in complex practical applications, and has high dynamic response means for dynamically changing actual processing requests; the overall architecture design of the present invention is scientific, reliable, and suitable for promotion.
[0070] The above are only preferred embodiments of the present invention. It should be understood that the description of the above embodiments is only used to help understand the method and core ideas of the present invention, and is not used to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, etc. made within the ideas and principles of the present invention should be included in the scope of protection of the present invention.
Claims
1. An adaptive I2C communication scheduling method based on priority queue and Q-Learning, characterized in that: include: Step 1: Initialization of the priority queue; ① Initialize the request information of each master device and set the identifier and priority information; ② Use heap as the implementation data structure of priority queue; ③ Create an empty heap and insert the requests of different tasks into the heap in order according to the priority; Step 2: Request processing; ① Get the best request: pop out the request with the highest priority, assign the I2C bus to the request with the highest priority, and then re-sort the stack and cycle in sequence; ② After the request is processed, the processed request is saved in a new queue, and the processing result and system feedback information are recorded; Step 3: Cycle scheduling; A predetermined time interval is set for the system, and the processed requests are periodically taken out from the new queue, and the priority is adjusted, and then the adjusted requests are reinserted into the priority queue for sorting; Step 4: Q-Learning optimization; The Q-Learning algorithm is used to continuously optimize the scheduling strategy and dynamically adjust the priority. The priority in the priority queue is updated based on feedback to ensure that important requests are processed first. At the same time, by learning from historical data, the parameters of Q-Learning are adjusted to optimize the learning effect of the Q-Learning algorithm.
2. According to claim 1, an adaptive I2C communication scheduling method based on priority queue and Q-Learning is characterized in that: The priority determination refers to a method of sorting the requests of different tasks according to their importance or urgency.
3. According to claim 1, an adaptive I2C communication scheduling method based on priority queue and Q-Learning is characterized in that: The system feedback information includes: processing time and success or failure.
4. The adaptive I2C communication scheduling method based on priority queue and Q-Learning according to claim 1, characterized in that: The specific operations of the Q-Learning optimization are: State definition: System state includes: communication load, queue length and delay; Action definition: defines the action to adjust the request priority; Reward function: Design a reward function to evaluate the effectiveness of the scheduling strategy; Q value update: After each cyclic scheduling cycle, the Q value is updated according to the actual effect.
5. The adaptive I2C communication scheduling method based on priority queue and Q-Learning according to claim 4 is characterized in that: The Q value is updated according to the actual effect using the following formula: Among them, α is the learning rate, γ is the discount factor, r is the reward value, s is the current state, a is the current action, s′ is the next state, and a′ is the next action.
6. The adaptive I2C communication scheduling method based on priority queue and Q-Learning according to claim 4, characterized in that: The communication load is: the number of requests in the priority queue; the effect of the scheduling strategy is: reducing delays and conflicts.
7. The adaptive I2C communication scheduling method based on priority queue and Q-Learning according to claim 4, characterized in that: The reward function is used in such a way that a positive reward is given if the adjusted schedule reduces the processing delay.
8. The adaptive I2C communication scheduling method based on priority queue and Q-Learning according to claim 4, characterized in that: The parameters of the Q-Learning include: a learning rate and a discount factor.
9. An electronic device, characterized in that: include: A memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the technical solution of an adaptive I2C communication scheduling method based on priority queue and Q-Learning as described in any one of claims 1 to 8 can be implemented.
10. A readable storage medium, characterized in that: A computer program is stored, and when the computer program is executed by a processor, the technical solution of an adaptive I2C communication scheduling method based on priority queue and Q-Learning described in any one of claims 1 to 8 can be implemented.
