WO2023246044A1 - 调度方法及装置、芯片、电子设备及存储介质 - Google Patents

调度方法及装置、芯片、电子设备及存储介质 Download PDF

Info

Publication number
WO2023246044A1
WO2023246044A1 PCT/CN2022/141218 CN2022141218W WO2023246044A1 WO 2023246044 A1 WO2023246044 A1 WO 2023246044A1 CN 2022141218 W CN2022141218 W CN 2022141218W WO 2023246044 A1 WO2023246044 A1 WO 2023246044A1
Authority
WO
WIPO (PCT)
Prior art keywords
interrupt
task
queue
priority
service message
Prior art date
Application number
PCT/CN2022/141218
Other languages
English (en)
French (fr)
Inventor
张文泰
Original Assignee
哲库科技(北京)有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 哲库科技(北京)有限公司 filed Critical 哲库科技(北京)有限公司
Publication of WO2023246044A1 publication Critical patent/WO2023246044A1/zh

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/48Program initiating; Program switching, e.g. by interrupt
    • G06F9/4806Task transfer initiation or dispatching
    • G06F9/4812Task transfer initiation or dispatching by interrupt, e.g. masked
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/546Message passing systems or structures, e.g. queues

Definitions

  • the present application relates to the technical field of task scheduling, and in particular to a scheduling method, a scheduling device, a chip, an electronic device and a non-volatile computer-readable storage medium.
  • the operation processes of real-time operating systems based on software implementation and task scheduling include: operating system clock cycle maintenance, task polling, ready table operations, task scheduling and interrupt response.
  • the scheduling function based on hardware multi-threading is implemented in hardware. Due to the ability to generate independent instruction streams at the same time, compared with a real-time operating system based on software, the system reduces the number of ready table operations, task polling and tasks. Scheduling operations, hardware task scheduling is more efficient.
  • the embodiments of the present application provide a scheduling method, a scheduling device, a chip, an electronic device, and a non-volatile computer-readable storage medium.
  • the embodiment of this application provides a scheduling method.
  • the scheduling method includes: when sending a message to be processed to the corresponding target service message queue, controlling the interrupt controller to generate a first interrupt signal of the interrupt source corresponding to the target service message queue, and according to the first The first interrupt priority level of the interrupt source corresponding to an interrupt signal and the second interrupt priority level of the interrupt source corresponding to the current service message queue currently processed determine the scheduling strategy of the message to be processed; after receiving the second interrupt signal
  • the task scheduling policy is determined based on the task priorities of all task queues, and the interrupt priority of the interrupt source corresponding to the second interrupt signal is lower than the interrupt priority of the interrupt source corresponding to the first interrupt signal.
  • the embodiment of the present application provides a scheduling device.
  • the scheduling device includes a first determination module and a second determination module.
  • the first determination module is configured to control the interrupt controller to generate a first interrupt signal of an interrupt source corresponding to the target service message queue when the message to be processed is sent to the corresponding target service message queue, and the first interrupt signal is generated according to the target service message queue.
  • the first interrupt priority of the interrupt source corresponding to the first interrupt signal and the second interrupt priority of the interrupt source corresponding to the current service message queue currently being processed determine the scheduling strategy of the message to be processed; the second determination module Used to determine a task scheduling strategy based on the task priorities of all task queues when a second interrupt signal is received, and the interrupt priority of the interrupt source corresponding to the second interrupt signal is lower than that of the first interrupt signal.
  • the interrupt priority level of the interrupt source used to determine a task scheduling strategy based on the task priorities of all task queues when a second interrupt signal is received, and the interrupt priority of the interrupt source corresponding to the second interrupt signal is lower than that of the first interrupt signal.
  • An embodiment of the present application provides a chip, which is connected to an interrupt controller of an electronic device.
  • the chip is used to control the interrupt controller to generate a message when sending a message to be processed to a corresponding target service message queue.
  • the first interrupt signal of the interrupt source corresponding to the target service message queue, and according to the first interrupt priority level of the interrupt source corresponding to the first interrupt signal and the second interrupt source corresponding to the current service message queue currently processed The interrupt priority determines the scheduling strategy of the message to be processed;
  • the processor of the electronic device is configured to determine the task scheduling strategy according to the task priorities of all task queues when receiving the second interrupt signal, and the second
  • the interrupt priority level of the interrupt source corresponding to the interrupt signal is lower than the interrupt priority level of the interrupt source corresponding to the first interrupt signal.
  • An embodiment of the present application provides an electronic device.
  • the electronic device includes a processor, and the processor is configured to control an interrupt controller to generate a first interrupt of an interrupt source corresponding to the target service message queue when a message to be processed is sent to the corresponding target service message queue. signal, and determine the scheduling strategy of the message to be processed based on the first interrupt priority of the interrupt source corresponding to the first interrupt signal and the second interrupt priority of the interrupt source corresponding to the current service message queue currently being processed; in When a second interrupt signal is received, the task scheduling strategy is determined based on the task priorities of all task queues. The interrupt priority of the interrupt source corresponding to the second interrupt signal is lower than that of the interrupt source corresponding to the first interrupt signal. Interrupt priority.
  • Embodiments of the present application provide a non-volatile computer-readable storage medium on which a computer program is stored.
  • the computer program implements the scheduling method when executed by the processor.
  • the scheduling method includes: when sending a message to be processed to the corresponding target service message queue, controlling the interrupt controller to generate a first interrupt signal of the interrupt source corresponding to the target service message queue, and according to the first The first interrupt priority level of the interrupt source corresponding to an interrupt signal and the second interrupt priority level of the interrupt source corresponding to the current service message queue currently processed determine the scheduling strategy of the message to be processed; after receiving the second interrupt signal
  • the task scheduling policy is determined based on the task priorities of all task queues, and the interrupt priority of the interrupt source corresponding to the second interrupt signal is lower than the interrupt priority of the interrupt source corresponding to the first interrupt signal.
  • Figure 1 is a schematic flowchart of a scheduling method in some embodiments of the present application.
  • Figure 2 is an interrupt priority planning diagram of the hardware scheduler and software scheduler in some embodiments of the present application
  • Figure 3 is a schematic flowchart of a scheduling method in some embodiments of the present application.
  • Figure 4 is a schematic flowchart of a scheduling method in some embodiments of the present application.
  • Figure 5 is a schematic flowchart of a scheduling method in some embodiments of the present application.
  • Figure 6 is a schematic diagram of the principle of a scheduling method in some embodiments of the present application.
  • Figure 7 is a schematic flowchart of a scheduling method in some embodiments of the present application.
  • Figure 8 is a schematic flowchart of a scheduling method in some embodiments of the present application.
  • Figure 9 is a schematic diagram of the principle of a scheduling method in some embodiments of the present application.
  • Figure 10 is a schematic flowchart of a scheduling method in some embodiments of the present application.
  • Figure 11 is a schematic flowchart of a scheduling method in some embodiments of the present application.
  • Figure 12 is a schematic diagram of the principle of a scheduling method in some embodiments of the present application.
  • Figure 13 is a schematic flowchart of a scheduling method in some embodiments of the present application.
  • Figure 14 is a schematic flowchart of a scheduling method in some embodiments of the present application.
  • Figure 15 is a schematic flowchart of a scheduling method in some embodiments of the present application.
  • Figure 16 is a module schematic diagram of a scheduling device in some embodiments of the present application.
  • Figure 17 is a schematic plan view of an electronic device according to certain embodiments of the present application.
  • Figure 18 is a schematic diagram of the interaction between a non-volatile computer-readable storage medium and a processor according to certain embodiments of the present application.
  • the scheduling method of this application includes: when sending a message to be processed to the corresponding target service message queue, controlling the interrupt controller to generate the first interrupt signal of the interrupt source corresponding to the target service message queue, and controlling the first interrupt signal according to the first interrupt signal.
  • the first interrupt priority of the corresponding interrupt source and the second interrupt priority of the interrupt source corresponding to the current service message queue currently being processed determine the scheduling strategy of the message to be processed; in the case of receiving the second interrupt signal, based on all
  • the task priority of the task queue determines the task scheduling policy, and the interrupt priority of the interrupt source corresponding to the second interrupt signal is lower than the interrupt priority of the interrupt source corresponding to the first interrupt signal.
  • the scheduling policy of the message to be processed is determined based on the first interrupt priority of the interrupt source corresponding to the first interrupt signal and the second interrupt priority of the interrupt source corresponding to the current service message queue currently being processed, including : When the first interrupt priority is greater than the second interrupt priority, suspend the messages in the current service message queue and process the messages in the target service message queue; when the first interrupt priority is less than or equal to the second interrupt priority In this case, continue processing the messages in the current service message queue.
  • the scheduling policy of the message to be processed is determined based on the first interrupt priority of the interrupt source corresponding to the first interrupt signal and the second interrupt priority of the interrupt source corresponding to the current service message queue currently being processed, including : Determine the scheduling strategy for the messages to be processed based on the first interrupt priority, the second interrupt priority and whether the interrupt source corresponding to the current service message queue supports preemption.
  • the scheduling strategy for the message to be processed is determined based on the first interrupt priority, the second interrupt priority and whether the interrupt source corresponding to the current service message queue supports preemption, including: when the first interrupt priority is greater than the When the second interrupt priority is and the interrupt source corresponding to the current service message queue supports preemption, the messages in the current service message queue are suspended and the messages in the target service message queue are processed; when the first interrupt priority is less than or equal to the second interrupt priority level or the interrupt source corresponding to the current service message queue prohibits preemption, continue to process messages in the current service message queue.
  • suspending messages in the current service message queue includes: saving status information of a processor processing the current service message queue.
  • determining the task scheduling strategy based on the task priorities of all task queues includes: polling the task priorities of all task queues to determine the highest priority target task queue; in the current task queue currently being processed If it is not the target task queue, suspend the current task queue and process the target task queue; if the current task queue is the target task queue, continue to process the current task queue.
  • suspending the current task queue currently being processed includes: saving context information of the current task queue in the system and status information of the processor processing the current task queue.
  • the scheduling method also includes, after the target task queue is processed, re-polling the task priorities of all task queues to re-determine the target task queue; based on the re-determined context information and status information of the target task queue Resume processing of the retargeted task queue.
  • the scheduling method further includes maintaining status information of each task queue, the status information includes ready, executing, suspended, stopped and completed; polling the task priorities of all task queues to determine the highest priority Target task queue, including: polling the task priorities of all ready task queues to determine the highest priority target task queue.
  • the scheduling method also includes, when processing the task queue, if a first interrupt signal is received, suspending the task queue to process messages in the target service message queue corresponding to the first interrupt signal.
  • the second interrupt signal includes an external hardware interrupt, a system timing interrupt and a hangable request interrupt.
  • the interrupt priority of the hangable request interrupt is lower than the interrupt priority of the interrupt signal corresponding to the task queue.
  • the scheduling method also includes : When processing external hardware interrupts, if a system scheduled interrupt is received, a suspendable request interrupt is generated, so that after the external hardware interrupt is processed, task switching processing is performed. Task switching processing includes polling all tasks in the task queue. Priority to determine the highest priority target task queue and switch to the target task queue for processing.
  • the scheduling method further includes, in the case of processing the task queue, calling a first preset message interface to send the message to the target service message queue; and in the case of processing the service message queue, calling the second preset message interface. Set up a message interface to send messages to the task queue.
  • the scheduling device of the present application includes a first determination module and a second determination module.
  • the first determination module is used to control the interrupt controller to generate a first interrupt signal of an interrupt source corresponding to the target service message queue when the message to be processed is sent to the corresponding target service message queue, and to respond to the first interrupt signal according to the first interrupt signal.
  • the first interrupt priority of the interrupt source and the second interrupt priority of the interrupt source corresponding to the current service message queue currently being processed determine the scheduling strategy of the message to be processed;
  • the second determination module is used to determine the scheduling strategy of the message to be processed;
  • the second determination module is used to determine the scheduling strategy of the message to be processed.
  • the task scheduling policy is determined based on the task priorities of all task queues, and the interrupt priority of the interrupt source corresponding to the second interrupt signal is lower than the interrupt priority of the interrupt source corresponding to the first interrupt signal.
  • the chip of this application is connected to the interrupt controller of the electronic device.
  • the chip is used to control the interrupt controller to generate the first interrupt source corresponding to the target service message queue when the message to be processed is sent to the corresponding target service message queue.
  • interrupt signal and determine the scheduling strategy of the message to be processed based on the first interrupt priority of the interrupt source corresponding to the first interrupt signal and the second interrupt priority of the interrupt source corresponding to the current service message queue currently being processed; processing of electronic equipment
  • the controller is configured to determine a task scheduling strategy based on the task priorities of all task queues when a second interrupt signal is received.
  • the interrupt priority of the interrupt source corresponding to the second interrupt signal is lower than the interrupt source of the interrupt source corresponding to the first interrupt signal. priority.
  • the electronic device of the present application includes a processor, and the processor is configured to control the interrupt controller to generate the first interrupt signal of the interrupt source corresponding to the target service message queue when the message to be processed is sent to the corresponding target service message queue, and According to the first interrupt priority of the interrupt source corresponding to the first interrupt signal and the second interrupt priority of the interrupt source corresponding to the current service message queue currently processed, the scheduling strategy of the message to be processed is determined; after receiving the second interrupt signal In this case, the task scheduling policy is determined based on the task priorities of all task queues, and the interrupt priority of the interrupt source corresponding to the second interrupt signal is lower than the interrupt priority of the interrupt source corresponding to the first interrupt signal.
  • the processor is also configured to suspend messages in the current service message queue and process messages in the target service message queue when the first interrupt priority is greater than the second interrupt priority; If the priority is less than or equal to the second interrupt priority, continue processing the messages in the current service message queue.
  • the processor is also configured to determine a scheduling policy for the message to be processed based on the first interrupt priority, the second interrupt priority, and whether the interrupt source corresponding to the current service message queue supports preemption.
  • the processor is also configured to suspend messages in the current service message queue and process them when the first interrupt priority is greater than the second interrupt priority and the interrupt source corresponding to the current service message queue supports preemption. Messages in the target service message queue; when the first interrupt priority is less than or equal to the second interrupt priority or the interrupt source corresponding to the current service message queue prohibits preemption, continue processing the messages in the current service message queue.
  • the processor is also configured to save status information of the processor processing the current service message queue.
  • the processor is also configured to poll the task priorities of all task queues to determine the highest priority target task queue; if the current task queue currently being processed is not the target task queue, suspend current task queue, and process the target task queue; if the current task queue is the target task queue, continue to process the current task queue.
  • the processor is also used to save context information of the current task queue in the system and status information of the processor processing the current task queue.
  • the processor is also configured to re-poll the task priorities of all task queues after the target task queue is processed to re-determine the target task queue; based on the re-determined context information and status of the target task queue Information resumes processing of retargeted task queues.
  • the processor is also configured to maintain status information of each task queue, the status information includes ready, executing, suspended, stopped and completed; poll the task priorities of all ready task queues to determine the highest Priority target task queue.
  • the processor is further configured to, when processing the task queue, if a first interrupt signal is received, suspend the task queue to process messages in the target service message queue corresponding to the first interrupt signal.
  • the second interrupt signal includes an external hardware interrupt, a system timing interrupt and a hangable request interrupt.
  • the interrupt priority of the hangable request interrupt is lower than the interrupt priority of the interrupt signal corresponding to the task queue.
  • the processor also uses In the case of processing external hardware interrupts, if a system scheduled interrupt is received, a suspendable request interrupt is generated, so that after the external hardware interrupt is processed, task switching processing is performed. Task switching processing includes polling all tasks in the task queue. Priority to determine the highest priority target task queue and switch to the target task queue for processing.
  • the processor is also configured to call a first preset message interface to send a message to the target service message queue when processing a task queue; and to call a second preset message interface when processing a service message queue.
  • Default message interface to send messages to task queue.
  • the non-volatile computer-readable storage medium of the present application includes a computer program.
  • the computer program is executed by one or more processors, the scheduling method of any of the above embodiments is implemented.
  • a message is a piece of business logic. By processing the message, specific operations of the system can be completed.
  • the message includes description information and a message body.
  • the description information is used to parse and process the message, and the message body contains the actual content of the message.
  • the control process in a complex system consists of a set of tasks, and the running of the tasks is completed through the processor and task scheduler.
  • the system can be a complex communication system, industrial control system or automobile central control system.
  • the control process includes the execution of tasks with different functions. These tasks are responsible for processing messages related to the transaction operation of the system. That is, the processing of each task represents the processing of one or more messages related to the task. deal with.
  • Service message queue corresponds to the system's tasks. For example, one service message queue corresponds to one task.
  • the service message queue is used to store messages and is completed by sending messages from the service message queue to the corresponding message processing entity for processing in turn. Task.
  • Task queue corresponds to the tasks of the system. For example, one task queue corresponds to one task.
  • the task queue is used to store messages and complete the task by sending the messages in the task queue to the corresponding message processing entity for processing in sequence.
  • Message processing entity An object used to process messages in a processor.
  • a processor can have one or more message processing entities, and multiple message processing entities can process multiple messages at the same time.
  • Interrupt controller After the message is sent to the service message queue, it can trigger the interrupt signal of the interrupt source corresponding to the service message queue and route the interrupt signal to the corresponding processor. The processor will prioritize the interrupt of the interrupt source corresponding to the interrupt signal. level, determine whether to interrupt the currently processed service message queue to process the service message queue corresponding to the interrupt signal. The interrupt controller can also respond to external hardware interrupts and generate corresponding interrupt signals.
  • Interrupt priority In order for the system to respond to and handle all interrupts that occur in a timely manner, the system divides interrupt sources into several levels based on the importance and urgency of the event causing the interrupt, called interrupt priority.
  • the scheduling method in the implementation of this application includes:
  • Step 011 When the message to be processed is sent to the corresponding target service message queue, control the interrupt controller to generate the first interrupt signal of the interrupt source corresponding to the target service message queue, and determine the interrupt source corresponding to the first interrupt signal.
  • the first interrupt priority level and the second interrupt priority level of the interrupt source corresponding to the current service message queue currently being processed determine the scheduling policy of the message to be processed.
  • each task will be performed.
  • the system will continuously send messages and complete specific tasks by processing each message.
  • the pending message will first be sent to the target service message queue corresponding to the task to which it belongs. It can be understood that each message has a corresponding target service message queue according to the task to which it belongs. .
  • the corresponding interrupt source of the target service message queue in the interrupt controller After the message to be processed is sent to the target service message queue, the corresponding interrupt source of the target service message queue in the interrupt controller generates the first interrupt signal, that is, there is a corresponding relationship between the service message queue and the interrupt source.
  • Each service message queue It can correspond to at least one interrupt source.
  • the service message queue has a one-to-one correspondence with the interrupt source, which can simplify the business logic.
  • each service message queue corresponds to multiple interrupt sources, that is, multiple messages in the service message queue can serve different services respectively.
  • Interrupt source the service message queue is bound and associated with the interrupt source.
  • the priority of the service message queue is determined based on the interrupt priority of the interrupt source bound to the service message queue. It can be understood that the interrupt priority of one or more interrupt sources bound to the service message queue is the same to ensure that one When serving the message queue, it can be processed sequentially according to the queue order to prevent the same service message queue from having messages corresponding to interrupt sources with different interrupt priorities, thereby avoiding the situation where messages with low interrupt priority are processed preferentially.
  • the interrupt source corresponding to the message among the multiple interrupt sources bound to the target service message queue can be triggered to generate the first interrupt signal; or, because at least one of the interrupt sources corresponding to the service message queue
  • the interrupt priorities of the interrupt sources are the same, and this application schedules tasks based on the interrupt priority. Therefore, after the pending message is sent to the target service message queue, it only needs to trigger multiple interrupts bound to the target service message queue.
  • Task scheduling can be realized by generating an interrupt signal from any interrupt source in the source. For example, by operating the interrupt pending status register corresponding to the interrupt source in the interrupt controller, the corresponding first interrupt signal is directly triggered, thereby not relying on external interrupt signal triggering.
  • the interrupt mechanism of the system's own interrupt controller can be used to implement task scheduling.
  • the scheduling strategy of the message to be processed such as whether to interrupt the current service, can be determined based on the first interrupt priority of the interrupt source corresponding to the first interrupt signal and the second interrupt priority of the interrupt source corresponding to the current service message queue currently being processed. Message queue processing to process the target service message queue, or to continue processing the current service message queue without interruption.
  • Step 012 When receiving the second interrupt signal, determine the task scheduling strategy based on the task priorities of all task queues.
  • the interrupt priority of the interrupt source corresponding to the second interrupt signal is lower than that of the interrupt source corresponding to the first interrupt signal. Interrupt priority.
  • interrupts are the cornerstone of embedded systems. Without interrupts, the system will not be able to respond to external events in a timely manner. Therefore, this application designs independent external event interrupt sources for the hardware scheduler and software scheduler, and integrates them into their respective schedulers according to their respective design requirements. Similarly, the setting of interrupt priority will also directly affect the response sequence and speed of the embedded processor when processing multiple concurrent events. In the allocation of interrupt priorities in this application, while considering the external interrupt priority setting, it is also necessary to consider the priority of the hardware interrupt generated by the software in the hardware scheduler (that is, the service message queue triggers the interrupt controller to generate the corresponding first interrupt signal). Unified planning with interrupt priorities in the software scheduler. Please refer to Figure 2, which shows a typical interrupt priority setting in the hardware scheduler and software scheduler of this application.
  • the following is an example of how to plan software and hardware interrupt resources and set software and hardware interrupt priorities according to specific business and system design in the hybrid scheduler of this application with reference to Table 1.
  • the interrupt priority of the hardware scheduler is overall higher than the interrupt priority of the software scheduler.
  • the hardware scheduler is used to design and complete high-priority systems with higher real-time requirements.
  • the software scheduler is used to complete relatively low-priority task processing in the system that does not require high real-time performance and some external upper-level business interactions.
  • the interrupt priority of the interrupt source corresponding to the second interrupt signal generated by the software scheduled interrupt is lower than the interrupt priority of the interrupt source corresponding to the first interrupt signal.
  • the real-time requirements of the task corresponding to the second interrupt signal are lower, so Software scheduling can be performed through the system's own software scheduling mechanism, without the need to design special hardware for scheduling, thereby reducing the difficulty and cost of designing a hardware scheduler, and the software scheduler can implement richer tasks.
  • the hardware scheduler for hardware scheduling provides a basic preemptible scheduling design based on message triggering, and more abundant scheduler applications in complex scenarios, such as semaphores, mutually exclusive semaphores, and timing services , priority inheritance, priority preemption threshold, task suspension, task recovery, etc., can be implemented through the software scheduler.
  • the interrupt may change the task priorities of different task queues in the system, before task scheduling, task polling needs to be performed again.
  • Determine the task priorities of all task queues each task queue can correspond to one task
  • determine the task scheduling strategy based on the task priorities of all task queues, for example, process the task queue with the highest task priority.
  • step 011 may include:
  • Step 0111 When the first interrupt priority is greater than the second interrupt priority, suspend the messages in the current service message queue and process the messages in the target service message queue;
  • Step 0112 If the first interrupt priority is less than or equal to the second interrupt priority, continue processing the messages of the current service message queue.
  • the size of the first interrupt priority corresponding to the message to be processed and the second interrupt priority corresponding to the current service message queue can be determined.
  • the first interrupt priority is greater than In the case of the second interrupt priority, it means that the pending message needs to be processed first. Therefore, the current service message queue can be suspended at this time, and then the target service message queue where the pending message is located can be processed.
  • suspending the current service message queue refers to pausing the processing of the current service message queue and saving the status information of the current service message queue, so as to facilitate the resumption of the processing of the current service message queue after the target service message queue is processed.
  • Saving the status of the current service message queue can be achieved by pushing the register of the current service message queue onto the stack, that is, pushing the relevant status of the processor processing the current service message queue onto the stack. Since this application uses interrupt control based on existing hardware The scheduler function designed and implemented based on the server technology eliminates the software's management of the task context of the operating system. Therefore, compared with the traditional real-time operating system scheduler based on software implementation, both task scheduling overhead and interrupt response delay can be reduced. less. Please refer to Table 2. When pushing the stack in this application, only the processor register is pushed onto the stack, and there is no need to push the entire context of the operating system, so the overhead of stacking is reduced.
  • Interrupt signal reaches processor 3 clock cycles
  • Processor gets first instruction 8cycles Processor register push 15cycles Operating system context push 40cycles
  • the processor when there are multiple pending messages in the service message queue at the same time, the processor will not linearly accumulate hardware overhead.
  • the hardware overhead generated by the service message queue for interrupt events is one-time, that is, the service message
  • the messages to be processed in the queue are pushed or popped out of the stack at one time until all messages in the service message queue are processed and exited.
  • the first interrupt priority is less than or equal to the second interrupt priority, it means that the pending message does not need to be processed first, so it is necessary to wait for the message processing of the current service message queue to be completed before the pending message can be processed. At this time, let the messages to be processed wait in the target service message queue and continue to process the messages in the current service message queue, thereby realizing task scheduling through the interrupt priority corresponding to the service message queue.
  • step 011 may include:
  • Step 0113 Determine the scheduling policy for the message to be processed based on the first interrupt priority, the second interrupt priority and whether the interrupt source corresponding to the current service message queue supports preemption.
  • each interrupt source has the following attributes:
  • Interrupt priority target processor Whether to support preemption Destination service message queue Destination message processing entity
  • the interrupt priority is used to indicate the priority of the interrupt source when interrupting.
  • the target processor indicates that the message corresponding to the interrupt source should be processed by the corresponding processor of the electronic device. Whether preemption is supported indicates the service message corresponding to the interrupt source.
  • the destination service message queue represents the identification information of the service message queue bound to the interrupt source.
  • Each service message queue has unique identification information
  • the destination message processing entity is Represents the identification information of the message processing entity used to process the service message queue corresponding to the interrupt source.
  • the message processing entity also has unique identification information.
  • the interrupt source corresponding to the current service message queue (or specifically the message currently being processed) supports preemption. If it supports preemption, In the case of , determine whether the first interrupt priority is greater than the second interrupt priority, so that if the first interrupt priority is greater than the second interrupt priority, suspend the messages in the current service message queue and process the target service message queue message; and when the first interrupt priority is less than or equal to the second interrupt priority or the interrupt source corresponding to the current service message queue (or specifically the message currently being processed) prohibits preemption, continue to process the current service message queue. information.
  • the high-priority service message queue (that is, the interrupt source bound to the service message queue has a higher interrupt priority) will be prohibited from preempting the service message queue currently being processed, thus To protect the consistency of resources in the system.
  • the scheduling method before sending the pending message to the target service message queue, the scheduling method also includes:
  • Step 010 Obtain the message descriptor corresponding to the message to be processed from the idle message queue.
  • the message descriptor includes the message identifier and the message body address;
  • the messages distributed by the system require message application to allocate corresponding resources (such as memory, etc.) for the specific information of the message.
  • the message application process mainly involves applying for the message descriptor and message body of the message.
  • the message descriptor contains description information used to describe the overall information of the message. The description information is used to correctly parse and process the message.
  • the message body is used to store the actual content of the message, which can include specific data content passed between tasks in the control system.
  • an idle message queue is designed specifically for storing message descriptors and message bodies.
  • the idle message queue may include a message descriptor queue and a message body queue.
  • the message descriptor queue is used to store message descriptors (descriptor address N in Figure 6 (N is an integer and greater than 3 )), the message body queue is used to store the message body (the message body address M in Figure 6 (M is an integer and greater than 3)).
  • the message descriptor in the message descriptor queue actually stores a description.
  • the process of applying for a message descriptor is the process of storing the description information describing the overall message information into the memory address corresponding to the message descriptor.
  • the content of the message body of the message can be empty. In this case, there is no need to apply for the message body.
  • the message descriptor can be obtained by directly encapsulating the descriptor address, thereby sending the pending message with the message descriptor to the corresponding target service message.
  • the queue can be processed.
  • the process of applying for the message body is the process of storing the specific data content of the message into the memory address corresponding to the message body.
  • the address of the message descriptor and the message body address can be encapsulated to obtain the message descriptor, so that the pending message with the message descriptor can be sent to the corresponding target service.
  • Message queue to facilitate the processing of pending messages by message processing entities.
  • the information in the message descriptor can facilitate the message processing entity to parse and process the message.
  • the message identifier is used by the message processing entity to find the processing function that processes the specific data content in the message body address.
  • the message size and type are The basic information of the message, the message source address and the message destination address can point to different service message queues respectively, thereby realizing communication between different service message queues.
  • the address information of the message body in the memory (i.e., the message body address in Table 3) will be maintained in the message descriptor, thereby flexibly supporting the copying and sending of the message body in the system.
  • the system can apply for multiple message descriptors.
  • the multiple message descriptors may only have different message destination addresses.
  • the body address is the same, thereby reducing the performance degradation caused by sending the same message content multiple times in a real-time system and needing to copy the specific data content of the message body multiple times.
  • the idle message queue in this application can initialize the address of each message descriptor in the message descriptor queue and the address of each message body in the message body queue after the system is started. That is to say, the address and message body address of each message descriptor in the message descriptor are allocated resources in advance, so there is no need to allocate memory resources every time a message is requested, which is beneficial to improving The efficiency of message application, thereby improving the efficiency of message sending.
  • the idle message queue of this application is stored in the first queue register of the electronic device, and the service message queue is stored in the second queue register.
  • the service message queue is stored in the second queue register.
  • step 0111 Process messages in the target service message queue, including:
  • Step 01111 Send the message to be processed with the message descriptor to the corresponding message processing entity, so that the message processing entity obtains the preset processing function corresponding to the message identifier and the message content corresponding to the message body address, and processes it according to the preset processing function Message content.
  • the interrupt controller After sending the pending message with the message descriptor to the target service message queue, the interrupt controller generates an interrupt signal of the interrupt source corresponding to the target service message queue, and at the interrupt source corresponding to the interrupt signal
  • the first interrupt priority is greater than the second interrupt priority of the interrupt source corresponding to the current service message queue currently being processed, the messages in the current service message queue can be suspended and the messages in the target service message queue can be processed.
  • the message processing entity first obtains the message identifier in the message descriptor according to the address of the message descriptor, thereby obtaining the preset processing function bound to the message identifier, and then obtains the message body address in the message descriptor. , and obtain the specific data content of the message body, and finally process the specific data content according to the preset processing function, thereby completing the processing of the message to be processed.
  • the message descriptor can contain the message source address and the message destination address to respectively represent the source service message queue for sending the message and the destination service message queue for receiving the message, thereby realizing communication between different service message queues. Therefore, when the message processing entity processes the message body according to the preset processing function, if it needs to communicate with the destination service message queue, the message processing entity sends a message to the destination service message queue, so that the interrupt controller generates a message related to the destination service message.
  • the interrupt signal of the interrupt source corresponding to the queue is used to process the interrupt and realize communication between service message queues.
  • tasks corresponding to different service message queues are not isolated.
  • the execution of one task may require other tasks to be executed first. For example, when processing message 1 of the current service message queue (i.e., the source service message queue), additional tasks are required.
  • a destination service message queue processes message 2 first. Therefore, the current service message queue can apply for message 2 and send it to the destination service message queue to trigger an interrupt to process message 2 first. After completing the processing of message 2, exit the interrupt again. Process message 1.
  • step 0111 Process messages in the target service message queue, including:
  • Step 01112 After the pending message is processed, release the pending message with the message descriptor to the idle message queue.
  • the message descriptor of the message to be processed should no longer occupy system resources.
  • the message descriptor of the message to be processed needs to be released from the target service message queue to the idle message queue again.
  • releasing the message descriptor of the pending message to the idle message queue may specifically include deleting the information stored in the address of the message descriptor and the information stored in the address of the message body to free up memory space, and Push the message descriptor to the idle message queue again, for example, push the address of the message descriptor to the end of the message descriptor queue, and push the message body address to the end of the message body queue.
  • the idle message queue can Realize the application allocation and recycling of messages.
  • messages in the service message queue are sent to the corresponding message processing entity for processing in sequence.
  • the message processing entity Corresponds to at least one service message queue.
  • the number of message processing entities in the processor is limited, and the number of service message queues can be determined according to the interrupt priority setting of the system.
  • the number of service message queues is generally much larger than the number of message processing entities.
  • service message queues 1-Z are arranged according to interrupt priority from low to high.
  • Service message queues 1 and 2 correspond to message processing entities.
  • Service message queues 3 to Z (Z is an integer and greater than 3) correspond to service message entity 2.
  • the message processing entity 1 processing service message queues 1 and 2 as an example. If no pending messages are received, the messages in service message queues 2 and 1 will be sent to the corresponding message processing in order from high to low according to the interrupt priority. Processing is performed in entity 1, so that message processing entity 1 first processes messages in service message queue 2, and then processes messages in service message queue 1. After receiving a message to be processed and triggering an interrupt, it will be determined whether the interrupt priority of the target service message queue corresponding to the message to be processed is greater than the interrupt priority of the current service message queue currently being processed. For example, the current service message queue is service message queue 1, and the target service message queue is service message queue 2. Since the interrupt priority of service message queue 2 is greater than the interrupt priority of service message queue 1, message processing entity 1 will hang. Service message queue 1, thereby processing the target service message queue.
  • the scheduling method of the embodiment of the present application realizes task scheduling by using the system's own interrupt controller, which greatly reduces the system cost. While consuming software and hardware overhead, it simplifies system design and improves system reliability.
  • the hardware scheduler design in this application can support priority preemption and communication between service message queues; priority preemption is prohibited to achieve resource consistency protection; and can realize scheduling functions such as application, allocation and release of message resources,
  • priority preemption is prohibited to achieve resource consistency protection; and can realize scheduling functions such as application, allocation and release of message resources,
  • scheduling functions such as application, allocation and release of message resources
  • step 012 includes:
  • Step 0121 Poll the task priorities of all task queues to determine the highest priority target task queue
  • Step 0122 If the current task queue currently being processed is not the target task queue, suspend the current task queue and process the target task queue;
  • Step 0123 If the current task queue is the target task queue, continue processing the current task queue.
  • the current task queue currently being processed needs to be suspended first, specifically to save the context information and processing of the current task queue in the system.
  • the status information of the processor of the current task queue so that when continuing to process the current task queue, the processing can be resumed from the breakpoint of the current task queue, without affecting the task operations that have been executed by the current task queue, and preventing task switching every time
  • the suspended task queue is executed again, it needs to be executed from the beginning, which affects the task execution efficiency.
  • scheduling methods also include:
  • Step 014 After the target task queue is processed, re-poll the task priorities of all task queues to re-determine the target task queue;
  • Step 015 Resume the processing of the redetermined target task queue according to the context information and status information of the redetermined target task queue.
  • the task priority of the task queue may also change. Therefore, task polling needs to be performed again to re-determine the highest-priority target task queue.
  • the redetermined target task queue is generally the current task queue that was previously suspended. Therefore, when processing the target task queue, it is necessary to obtain the context information and status information of the redetermined target task queue, so that according to the context information and status The information restores the processing of the redetermined target task queue, so that the redetermined target task queue can continue processing at the suspended breakpoint, ensuring task execution efficiency.
  • the software scheduler When scheduling software tasks, the software scheduler will maintain the status information of each task queue in real time.
  • the status of the task queue includes ready, executing, suspended, stopped and completed.
  • the status information of the task queue will be here. Switch between five states.
  • the suspended state is restored to the ready state to process the task queue; when the task queue is stopped, it means that the tasks corresponding to the task queue no longer need to be executed; when the task queue is completed, it means that the tasks corresponding to the task queue have been completed.
  • the status information of each task queue is maintained in real time through the software scheduler, which facilitates task scheduling. When performing task polling, you only need to poll tasks in the ready state, thereby reducing the computing power consumed by task polling and improving task scheduling efficiency.
  • scheduling methods also include:
  • Step 016 When processing the task queue, if the first interrupt signal is received, the task queue is suspended to process the messages in the target service message queue corresponding to the first interrupt signal.
  • tasks when executed, they are all executed through the message processing entity in the processor. Tasks scheduled by the hardware scheduler and software scheduler can be executed through the message processing entity.
  • the processor does not have an idle message processing entity, If the message processing entity is processing the task queue scheduled by the software scheduler, since the interrupt priority of the hardware scheduler is always greater than the interrupt priority of the software scheduler, if the first interrupt signal is received at this time, it will Suspend the task queue to execute messages in the target service message queue corresponding to the first interrupt signal, and prioritize tasks scheduled by the hardware scheduler. In this way, it is ensured that tasks scheduled by the hardware scheduler with high real-time requirements can preempt the execution of tasks scheduled by the software scheduler, which can improve task scheduling efficiency.
  • the second interrupt signal includes external hardware interrupt, system timing interrupt and suspendable request interrupt.
  • the interrupt priority of the suspendable request interrupt is lower than the interrupt priority of the interrupt signal corresponding to the task queue.
  • the scheduling method also includes:
  • Step 017 When processing external hardware interrupts, if a system scheduled interrupt is received, a suspendable request interrupt is generated, so that after the external hardware interrupt is processed, task switching processing is performed. Task switching processing includes polling all task queues. Task priority to determine the highest priority target task queue and switch to the target task queue for processing.
  • the software scheduler is based on software-implemented priority preemption that requires the scheduler to manage the context of the task.
  • the software scheduler regularly updates the task priority of the task queue through the system scheduled interrupt. Specifically, when a system scheduled interrupt arrives, the operating system will perform the following operations:
  • Task polling The scheduler updates the current task ready list (that is, obtains the task queue in the ready state), and selects the highest priority task that can currently be scheduled based on the task priority of each task;
  • Task switching Pop the highest-priority task off the stack and restore the context information of the task to the processor's register. After the interrupt returns, jump to the breakpoint of the highest-priority task to continue execution.
  • the task polling and task switching required for system scheduled interrupts will also be executed when task scheduling is performed after the external hardware interrupt is completed. Therefore, during the process of processing external hardware interrupts, if a system scheduled interrupt is received, only Save tasks and schedule updates, and trigger a hangable request interrupt with a lower interrupt priority (lower than the interrupt priority corresponding to the task queue) to suspend task polling and task switching in the system's scheduled interrupts. In external hardware After the interrupt processing is completed, the task switching process is performed, that is, the above-mentioned task polling and task switching are performed. Compared with the existing software task scheduling, the system scheduled interrupt requires one task polling and one task switching.
  • scheduling methods also include:
  • Step 018 In the case of processing the task queue, call the first default message interface to send the message to the target service message queue;
  • Step 019 In the case of processing the service message queue, call the second preset message interface to send the message to the task queue.
  • both the hardware scheduler and the software scheduler have message sending interfaces to facilitate inter-thread communication between the tasks of the hardware scheduler and the software scheduler.
  • the hardware scheduler is provided with a first preset message interface.
  • the first preset message interface can be called to send a message to the target service message queue in the hardware scheduler so that the task queue can be scheduled through the hardware scheduler.
  • the server implements the processing of some messages with high real-time performance.
  • the software scheduler is also provided with a second preset message interface. During the process of the target service message queue being processed, the second preset message interface can also be called to send messages to the corresponding task queue, thereby sending some messages to the corresponding task queue.
  • Messages with low real-time requirements are distributed to the software scheduler for scheduling and processing, realizing communication between the task queue and the service message queue, ensuring that messages with high real-time requirements can always be processed with priority.
  • the embodiment of the present application also provides a scheduling device 10.
  • the scheduling device 10 may include:
  • the first determination module 11 is used to control the interrupt controller to generate the first interrupt signal of the interrupt source corresponding to the target service message queue when the message to be processed is sent to the corresponding target service message queue, and to determine the first interrupt signal according to the first interrupt.
  • the first interrupt priority of the interrupt source corresponding to the signal and the second interrupt priority of the interrupt source corresponding to the current service message queue currently being processed determine the scheduling strategy of the message to be processed;
  • the second determination module 12 is configured to determine a task scheduling strategy based on the task priorities of all task queues when a second interrupt signal is received.
  • the interrupt priority of the interrupt source corresponding to the second interrupt signal is lower than the first interrupt signal.
  • the interrupt priority of the corresponding interrupt source is lower than the first interrupt signal.
  • the first determination module 11 is specifically used for:
  • the first determination module 11 is also specifically used for:
  • the scheduling policy of the message to be processed is determined according to the first interrupt priority, the second interrupt priority and whether the interrupt source corresponding to the current service message queue supports preemption.
  • the first determination module 11 is also specifically used for:
  • the first determination module 11 is also configured to save the status information of the processor that processes the current service message queue.
  • the second determination module 12 is specifically used for:
  • the second determination module 12 is also specifically configured to: save the context information of the current task queue in the system and the status information of the processor that processes the current task queue.
  • the scheduling device 10 also includes:
  • the third determination module 13 is configured to re-poll the task priorities of all task queues to re-determine the target task queue after the target task queue is processed;
  • the recovery module 14 is configured to resume the processing of the redetermined target task queue according to the context information and status information of the redetermined target task queue.
  • the scheduling device 10 also includes:
  • the maintenance module 15 is used to maintain the status information of each task queue.
  • the status information includes ready, execution, suspension, stop and completion.
  • the second determination module 12 is also specifically configured to poll the task priorities of all ready task queues to determine the highest priority target task queue.
  • the scheduling device 10 also includes:
  • the preemption module 16 is configured to, when processing the task queue, if a first interrupt signal is received, suspend the task queue to process messages in the target service message queue corresponding to the first interrupt signal.
  • the scheduling device 10 also includes:
  • the suspension module 17 is used to generate a suspendable request interrupt when an external hardware interrupt is processed, if a system scheduled interrupt is received, so that after the external hardware interrupt is processed, task switching processing is performed, and the task switching processing includes polling.
  • the task priorities of all task queues are determined to determine the highest priority target task queue and switched to the target task queue for processing.
  • the scheduling device 10 also includes:
  • the calling module 18 is used to call the first preset message interface to send messages to the target service message queue when processing the task queue; and to call the second preset message interface to send the message to the target service message queue when processing the service message queue. Send a message to the task queue.
  • Each module in the above-mentioned scheduling device 10 can be implemented in whole or in part by software, hardware, and combinations thereof.
  • Each of the above modules can be embedded in or independent of the processor of the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.
  • the chip 40 according to the embodiment of the present application is disposed in the electronic device 100 and connected to the interrupt controller 50 of the electronic device 100 .
  • the chip 40 is used to execute the steps of the scheduling method of any implementation of the above hardware scheduler, specifically step 011, step 0111, step 0112, step 0113, step 01111, step 01112, step 010 and step 019. For the sake of simplicity, I won’t go into details here.
  • the electronic device 100 includes a processor 30 .
  • the processor 30 is configured to execute the scheduling method in any of the above embodiments. For the sake of simplicity, details will not be described again here.
  • the electronic device 100 may be a mobile phone, a smart phone, a personal digital assistant (PDA), a tablet computer and a video game device, a portable terminal (such as a notebook computer), or a larger-sized device (such as a desktop computer and a computer). TV), or any other type of device that includes a TOF camera.
  • PDA personal digital assistant
  • a tablet computer and a video game device such as a notebook computer
  • portable terminal such as a notebook computer
  • a larger-sized device such as a desktop computer and a computer.
  • TV any other type of device that includes a TOF camera.
  • the hardware scheduler and software scheduler of the present application may be deployed in the same embedded processor without being subject to deployment constraints. It can also be deployed in a distributed processor based on the overall system design and based on the real-time requirements of different processors in the system, completing the system's scheduling and execution of different real-time tasks for different types of embedded processors. At the same time, it can also deploy software and hardware schedulers in different cores of the same embedded processor.
  • the embodiment of the present application also provides a computer-readable storage medium 300, on which a computer program 310 is stored.
  • a computer program 310 is stored on which a computer program 310 is stored.
  • the scheduling of any of the above embodiments is implemented.
  • the steps of the method will not be repeated here.
  • Computer program 310 includes computer program code.
  • Computer program code can be in the form of source code, object code, executable file or some intermediate form, etc.
  • Computer-readable storage media can include: any entity or device that can carry computer program code, recording media, USB flash drives, mobile hard drives, magnetic disks, optical disks, computer memory, read-only memory (ROM, Read-Only Memory), random access memory Access memory (RAM, Random Access Memory), and software distribution media, etc.

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Data Exchanges In Wide-Area Networks (AREA)
  • Bus Control (AREA)

Abstract

一种调度方法、调度装置(10)、芯片(40)、电子设备(100)及存储介质(300)。方法包括:(011)在待处理消息发送到对应的目标服务消息队列时,控制中断控制器产生对应的第一中断信号,根据第一中断优先级和当前的第二中断优先级,确定调度策略;(012)在接收到第二中断信号时,根据任务队列的任务优先级确定任务调度策略。

Description

调度方法及装置、芯片、电子设备及存储介质
优先权信息
本申请请求2022年6月23日向中国国家知识产权局提交的、专利申请号为2022107260216的专利申请的优先权和权益,并且通过参照将其全文并入此处。
技术领域
本申请涉及任务调度技术领域,特别涉及一种调度方法、调度装置、芯片、电子设备及非易失性计算机可读存储介质。
背景技术
基于软件实现的实时操作系统与任务调度相关的操作过程包括:操作系统时钟周期维护,任务轮询,就绪表操作,任务调度和中断响应。基于硬件多线程的调度功能是在硬件中实现的,由于具备同时生成相互独立的指令流的能力,相比于基于软件实现的实时操作系统,系统中减少了就绪表操作,任务轮询和任务调度的操作,硬件的任务调度效率较高。
发明内容
本申请实施方式提供了一种调度方法、调度装置、芯片、电子设备及非易失性计算机可读存储介质。
本申请实施例提供一种调度方法。所述调度方法包括:在将待处理消息发送到对应的目标服务消息队列的情况下,控制中断控制器产生与所述目标服务消息队列对应的中断源的第一中断信号,并根据所述第一中断信号对应的中断源的第一中断优先级和当前处理的当前服务消息队列对应的中断源的第二中断优先级,确定所述待处理消息的调度策略;在接收到第二中断信号的情况下,根据所有任务队列的任务优先级确定任务调度策略,所述第二中断信号对应的中断源的中断优先级低于所述第一中断信号对应的中断源的中断优先级。
本申请实施方式提供一种调度装置。所述调度装置包括第一确定模块和第二确定模块。所述第一确定模块用于在将待处理消息发送到对应的目标服务消息队列的情况下,控制中断控制器产生与所述目标服务消息队列对应的中断源的第一中断信号,并根据所述第一中断信号对应的中断源的第一中断优先级和当前处理的当前服务消息队列对应的中断源的第二中断优先级,确定所述待处理消息的调度策略;所述第二确定模块用于在接收到第二中断信号的情况下,根据所有任务队列的任务优先级确定任务调度策略,所述第二中断信号对应的中断源的中断优先级低于所述第一中断信号对应的中断源的中断优先级。
本申请实施方式提供一种芯片,所述芯片与电子设备的中断控制器连接,所述芯片用于在将待处理消息发送到对应的目标服务消息队列的情况下,控制所述中断控制器产生与所述目标服务消息队列对应的中断源的第一中断信号,并根据所述第一中断信号对应的中断源的第一中断优先级和当前处理的当前服务消息队列对应的中断源的第二中断优先级,确定所述待处理消息的调度策略;所述电子设备的处理器用于在接收到第二中断信号的情况下,根据所有任务队列的任务优先级确定任务调度策略,所述第二中断信号对应的中断源的中断优先级低于所述第一中断信号对应的中断源的中断优先级。
本申请实施方式提供一种电子设备。所述电子设备包括处理器,所述处理器用于在将待处理消息发送到对应的目标服务消息队列的情况下,控制中断控制器产生与所述目标服务消息队列对应的中断源的第一中断信号,并根据所述第一中断信号对应的中断源的第一中断优先级和当前处理的当前服务消息队列对应的中断源的第二中断优先级,确定所述待处理消息的调度策略;在接收到第二中断信号的情况下,根据所有任务队列的任务优先级确定任务调度策略,所述第二中断信号对应的中断源的中断优先级低于所述第一中断信号对应的中断源的中断优先级。
本申请实施方式提供一种非易失性计算机可读存储介质,其上存储有计算机程序。该计算机程序被处理器执行时实现调度方法。所述调度方法包括:在将待处理消息发送到对应的目标服务消息队列的情况下,控制中断控制器产生与所述目标服务消息队列对应的中断源的第一中断信号,并根据所述第一中断信号对应的中断源的第一中断优先级和当前处理的当前服务消息队列对应的中断源的第二中断优先级,确定所述待处理消息的调度策略;在接收到第二中断信号的情况下,根据所有任务队列的任务优先级确定任务调度策略,所述第二中断信号对应的中断源的中断优先级低于所述第一中断信号对应的中断源的中断优先级。
本申请实施方式的附加方面和优点将在下面的描述中部分给出,部分将从下面的描述中变得明显,或通过本申请的实践了解到。
附图说明
本申请的上述和/或附加的方面和优点可以从结合下面附图对实施方式的描述中将变得明显和容易理解,其中:
图1是本申请某些实施方式的调度方法的流程示意图;
图2是本申请某些实施方式的硬件调度器和软件调度器的中断优先级规划图;
图3是本申请某些实施方式的调度方法的流程示意图;
图4是本申请某些实施方式的调度方法的流程示意图;
图5是本申请某些实施方式的调度方法的流程示意图;
图6是本申请某些实施方式的调度方法的原理示意图;
图7是本申请某些实施方式的调度方法的流程示意图;
图8是本申请某些实施方式的调度方法的流程示意图;
图9是本申请某些实施方式的调度方法的原理示意图;
图10是本申请某些实施方式的调度方法的流程示意图;
图11是本申请某些实施方式的调度方法的流程示意图;
图12是本申请某些实施方式的调度方法的原理示意图;
图13是本申请某些实施方式的调度方法的流程示意图;
图14是本申请某些实施方式的调度方法的流程示意图;
图15是本申请某些实施方式的调度方法的流程示意图;
图16是本申请某些实施方式的调度装置的模块示意图;
图17是本申请某些实施方式的电子设备的平面示意图;及
图18是本申请某些实施方式的非易失性计算机可读存储介质与处理器的交互示意图。
具体实施方式
下面详细描述本申请的实施方式,实施方式的示例在附图中示出,其中,相同或类似的标号自始至终表示相同或类似的元件或具有相同或类似功能的元件。下面通过参考附图描述的实施方式是示例性的,仅用于解释本申请的实施方式,而不能理解为对本申请的实施方式的限制。
本申请的调度方法包括:在将待处理消息发送到对应的目标服务消息队列的情况下,控制中断控制器产生与目标服务消息队列对应的中断源的第一中断信号,并根据第一中断信号对应的中断源的第一中断优先级和当前处理的当前服务消息队列对应的中断源的第二中断优先级,确定待处理消息的调度策略;在接收到第二中断信号的情况下,根据所有任务队列的任务优先级确定任务调度策略,第二中断信号对应的中断源的中断优先级低于第一中断信号对应的中断源的中断优先级。
在某些实施方式中,根据第一中断信号对应的中断源的第一中断优先级和当前处理的当前服务消息队列对应的中断源的第二中断优先级,确定待处理消息的调度策略,包括:在第一中断优先级大于第二中断优先级的情况下,挂起当前服务消息队列的消息,并处理目标服务消息队列的消息;在第一中断优先级小于或等于第二中断优先级的情况下,继续处理当前服务消息队列的消息。
在某些实施方式中,根据第一中断信号对应的中断源的第一中断优先级和当前处理的当前服务消 息队列对应的中断源的第二中断优先级,确定待处理消息的调度策略,包括:根据第一中断优先级、第二中断优先级和当前服务消息队列对应的中断源是否支持抢占,确定待处理消息的调度策略。
在某些实施方式中,根据第一中断优先级、第二中断优先级和当前服务消息队列对应的中断源是否支持抢占,确定待处理消息的调度策略,包括:在第一中断优先级大于第二中断优先级且当前服务消息队列对应的中断源支持抢占的情况下,挂起当前服务消息队列的消息,并处理目标服务消息队列的消息;在第一中断优先级小于或等于第二中断优先级或当前服务消息队列对应的中断源禁止抢占的情况下,继续处理当前服务消息队列的消息。
在某些实施方式中,挂起当前服务消息队列的消息,包括:保存处理当前服务消息队列的处理器的状态信息。
在某些实施方式中,根据所有任务队列的任务优先级确定任务调度策略,包括:轮询所有任务队列的任务优先级,以确定最高优先级的目标任务队列;在当前正在处理的当前任务队列不是目标任务队列的情况下,挂起当前任务队列,并处理目标任务队列;在当前任务队列是目标任务队列的情况下,继续处理当前任务队列。
在某些实施方式中,挂起当前正在处理的当前任务队列,包括:保存系统中当前任务队列的上下文信息以及处理当前任务队列的处理器的状态信息。
在某些实施方式中,调度方法还包括在目标任务队列处理完成后,重新轮询所有任务队列的任务优先级,以重新确定目标任务队列;根据重新确定的目标任务队列的上下文信息及状态信息恢复重新确定的目标任务队列的处理。
在某些实施方式中,调度方法还包括维护每个任务队列的状态信息,状态信息包括就绪、执行、挂起、停止和完成;轮询所有任务队列的任务优先级,以确定最高优先级的目标任务队列,包括:轮询所有就绪的任务队列的任务优先级,以确定最高优先级的目标任务队列。
在某些实施方式中,调度方法还包括在处理任务队列的情况下,若接收到第一中断信号,则挂起任务队列,以处理第一中断信号对应的目标服务消息队列的消息。
在某些实施方式中,第二中断信号包括外部硬件中断、系统定时中断和可悬挂请求中断,可悬挂请求中断的中断优先级低于任务队列对应的中断信号的中断优先级,调度方法还包括:在处理外部硬件中断的情况下,若接收到系统定时中断,则产生可悬挂请求中断,以使得外部硬件中断被处理完后,进行任务切换处理,任务切换处理包括轮询所有任务队列的任务优先级,以确定最高优先级的目标任务队列,并切换到目标任务队列进行处理。
在某些实施方式中,调度方法还包括在处理任务队列的情况下,调用第一预设消息接口,以发送消息到目标服务消息队列;及在处理服务消息队列的情况下,调用第二预设消息接口,以发送消息到任务队列。
本申请的调度装置包括第一确定模块和第二确定模块。第一确定模块用于在将待处理消息发送到对应的目标服务消息队列的情况下,控制中断控制器产生与目标服务消息队列对应的中断源的第一中断信号,并根据第一中断信号对应的中断源的第一中断优先级和当前处理的当前服务消息队列对应的中断源的第二中断优先级,确定待处理消息的调度策略;第二确定模块用于在接收到第二中断信号的情况下,根据所有任务队列的任务优先级确定任务调度策略,第二中断信号对应的中断源的中断优先级低于第一中断信号对应的中断源的中断优先级。
本申请的芯片与电子设备的中断控制器连接,芯片用于在将待处理消息发送到对应的目标服务消息队列的情况下,控制中断控制器产生与目标服务消息队列对应的中断源的第一中断信号,并根据第一中断信号对应的中断源的第一中断优先级和当前处理的当前服务消息队列对应的中断源的第二中断优先级,确定待处理消息的调度策略;电子设备的处理器用于在接收到第二中断信号的情况下,根据所有任务队列的任务优先级确定任务调度策略,第二中断信号对应的中断源的中断优先级低于第一中断信号对应的中断源的中断优先级。
本申请的电子设备包括处理器,处理器用于在将待处理消息发送到对应的目标服务消息队列的情况下,控制中断控制器产生与目标服务消息队列对应的中断源的第一中断信号,并根据第一中断信号对应的中断源的第一中断优先级和当前处理的当前服务消息队列对应的中断源的第二中断优先级,确定待处理消息的调度策略;在接收到第二中断信号的情况下,根据所有任务队列的任务优先级确定任 务调度策略,第二中断信号对应的中断源的中断优先级低于第一中断信号对应的中断源的中断优先级。
在某些实施方式中,处理器还用于在第一中断优先级大于第二中断优先级的情况下,挂起当前服务消息队列的消息,并处理目标服务消息队列的消息;在第一中断优先级小于或等于第二中断优先级的情况下,继续处理当前服务消息队列的消息。
在某些实施方式中,处理器还用于根据第一中断优先级、第二中断优先级和当前服务消息队列对应的中断源是否支持抢占,确定待处理消息的调度策略。
在某些实施方式中,处理器还用于在第一中断优先级大于第二中断优先级且当前服务消息队列对应的中断源支持抢占的情况下,挂起当前服务消息队列的消息,并处理目标服务消息队列的消息;在第一中断优先级小于或等于第二中断优先级或当前服务消息队列对应的中断源禁止抢占的情况下,继续处理当前服务消息队列的消息。
在某些实施方式中,处理器还用于保存处理当前服务消息队列的处理器的状态信息。
在某些实施方式中,处理器还用于轮询所有任务队列的任务优先级,以确定最高优先级的目标任务队列;在当前正在处理的当前任务队列不是目标任务队列的情况下,挂起当前任务队列,并处理目标任务队列;在当前任务队列是目标任务队列的情况下,继续处理当前任务队列。
在某些实施方式中,处理器还用于保存系统中当前任务队列的上下文信息以及处理当前任务队列的处理器的状态信息。
在某些实施方式中,处理器还用于在目标任务队列处理完成后,重新轮询所有任务队列的任务优先级,以重新确定目标任务队列;根据重新确定的目标任务队列的上下文信息及状态信息恢复重新确定的目标任务队列的处理。
在某些实施方式中,处理器还用于维护每个任务队列的状态信息,状态信息包括就绪、执行、挂起、停止和完成;轮询所有就绪的任务队列的任务优先级,以确定最高优先级的目标任务队列。
在某些实施方式中,处理器还用于在处理任务队列的情况下,若接收到第一中断信号,则挂起任务队列,以处理第一中断信号对应的目标服务消息队列的消息。
在某些实施方式中,第二中断信号包括外部硬件中断、系统定时中断和可悬挂请求中断,可悬挂请求中断的中断优先级低于任务队列对应的中断信号的中断优先级,处理器还用于在处理外部硬件中断的情况下,若接收到系统定时中断,则产生可悬挂请求中断,以使得外部硬件中断被处理完后,进行任务切换处理,任务切换处理包括轮询所有任务队列的任务优先级,以确定最高优先级的目标任务队列,并切换到目标任务队列进行处理。
在某些实施方式中,处理器还用于在处理任务队列的情况下,调用第一预设消息接口,以发送消息到目标服务消息队列;及在处理服务消息队列的情况下,调用第二预设消息接口,以发送消息到任务队列。
本申请的非易失性计算机可读存储介质包括计算机程序,当计算机程序被一个或多个处理器执行时,实现上述任一实施方式的调度方法。
下面首先对本申请出现的名词进行解释:
消息:消息为一段业务逻辑,通过对消息的处理,能够完成系统的特定操作,消息包括描述信息和消息体,描述信息用于解析和处理消息,消息体则包含消息的实际内容。
复杂系统中的控制过程由一组任务组成,任务的运行通过处理器和任务的调度器完成。这其中系统可以是一个复杂的通信系统、工业控制系统或者汽车中央控制系统。通常情况下,控制过程包括执行拥有不同功能的任务,这些任务负责处理与系统事务操作有关的消息,也即是说,每个任务的处理,即表示对该任务有关的一个或多个消息的处理。
服务消息队列:服务消息队列对应系统的任务,如一个服务消息队列对应一个任务,服务消息队列用于存放消息,并通过发送服务消息队列的消息到对应的消息处理实体中依次进行处理,从而完成任务。
任务队列:任务队列对应系统的任务,如一个任务队列对应一个任务,任务队列用于存放消息,并通过发送任务队列的消息到对应的消息处理实体中依次进行处理,从而完成任务。
消息处理实体:为处理器中,用于处理消息的对象,一个处理器可以具有一个或多个消息处理实体,多个消息处理实体可同时处理多个消息。
中断控制器:能够在消息发送到服务消息队列后,触发服务消息队列对应的中断源的中断信号,并将中断信号路由到对应的处理器,由处理器根据中断信号对应的中断源的中断优先级,确定是否中断当前处理的服务消息队列,以处理中断信号对应的服务消息队列。中断控制器还能够响应外部硬件中断产生对应的中断信号。
中断优先级:为使系统能及时响应并处理发生的所有中断,系统根据引起中断事件的重要性和紧迫程度,将中断源分为若干个级别,称作中断优先级。
请参阅图1,本申请实施方式的调度方法包括:
步骤011:在将待处理消息发送到对应的目标服务消息队列的情况下,控制中断控制器产生与目标服务消息队列对应的中断源的第一中断信号,并根据第一中断信号对应的中断源的第一中断优先级和当前处理的当前服务消息队列对应的中断源的第二中断优先级,确定待处理消息的调度策略。
具体地,在系统运行过程中,会执行各种不同的任务,每个任务在执行过程中,系统会不断发送消息,通过处理一个个消息,完成特定的任务。在接收到一个待处理消息的情况下,会先将待处理消息发送到所属的任务对应的目标服务消息队列中,可以理解,每个消息根据所属任务的不同,均存在对应的目标服务消息队列。
在待处理消息发送到目标服务消息队列之后,目标服务消息队列在中断控制器中对应的中断源即产生第一中断信号,即服务消息队列与中断源是存在对应关系的,每个服务消息队列可对应至少一个中断源,如服务消息队列与中断源一一对应,可简化业务逻辑,或者每个服务消息队列对应多个中断源,即服务消息队列中的多个消息可以是分别服务于不同中断源,服务消息队列与中断源绑定关联。
服务消息队列的优先级根据与服务消息队列绑定的中断源的中断优先级来确定,可以理解,服务消息队列绑定的一个或多个中断源的中断优先级是相同的,以保证处理一个服务消息队列时,能够根据队列顺序依次进行处理,防止同一个服务消息队列存在对应不同中断优先级的中断源的消息,从而避免低中断优先级的消息反而被优先处理的情况。
在待处理消息发送到目标服务消息队列后,即可触发目标服务消息队列绑定的多个中断源中,与消息对应的中断源产生第一中断信号;或者,由于服务消息队列对应的至少一个中断源的中断优先级是相同的,而本申请是基于中断优先级进行任务调度的,因此,在待处理消息发送到目标服务消息队列后,只需触发目标服务消息队列绑定的多个中断源中任意一个中断源产生中断信号即可实现任务调度。例如,通过操作中断控制器中与中断源对应的中断挂起状态寄存器直接触发产生相应的第一中断信号从而不依赖于外部的中断信号触发。
在产生第一中断信号后,即可利用系统自带的中断控制器的中断机制,实现任务调度。可根据第一中断信号对应的中断源的第一中断优先级和当前正在进行处理的当前服务消息队列对应的中断源的第二中断优先级,确定待处理消息的调度策略,如是否中断当前服务消息队列的处理,以处理目标服务消息队列,或者不进行中断,继续当前服务消息队列的处理。
可以理解,能够触发服务消息队列在中断控制器中对应的中断源产生第一中断信号的待处理消息的任务的实时性要求均较高,是需要进行硬件调度以提高调度效率的,因此,通过系统自带的硬件中断控制器基于中断优先级进行任务调度,能够保证任务调度效率的同时,降低硬件调度的成本。
步骤012:在接收到第二中断信号的情况下,根据所有任务队列的任务优先级确定任务调度策略,第二中断信号对应的中断源的中断优先级低于第一中断信号对应的中断源的中断优先级。
具体地,中断是嵌入式系统的基石,如果没有中断,那么系统将无法及时的响应外部事件。因此,本申请针对硬件调度器和软件调度器设计独立的外部事件中断源,分别按照各自的设计需求统一集成到各自的调度器中。同样地,中断优先级的设置也将直接影响嵌入式处理器对于处理多个并发事件时的响应先后与快慢。本申请的中断优先级的分配在考虑外部中断优先级设置的同时,还需要考虑硬件调度器中的软件产生硬件中断(即服务消息队列触发中断控制器产生对应的第一中断信号)的优先级与软件调度器中的中断优先级的统一规划。请参阅图2,给出了一种本申请的硬件调度器和软件调度器中典型的中断的优先级设置。
下面结合表1举例说明在本申请的混合调度器中,如何根据具体的业务与系统设计,规划软硬件中断的资源以及设置软硬件中断优先级。表1中的中断优先级的数值越小,表示对应的中断优先级越高。从表1中的中断映射可以看出,硬件调度器的中断优先级整体高于软件调度器的中断优先级,同 时,硬件调度器是用来设计完成系统中实时性要求较高的高优先级的任务处理,软件调度器是用来完成系统中实时性要求不高的优先级相对较低的任务处理以及一些对外的上层业务交互。
Figure PCTCN2022141218-appb-000001
表1
对于进行软件调度的中断产生的第二中断信号对应的中断源的中断优先级低于第一中断信号对应的中断源的中断优先级,第二中断信号对应的任务的实时性要求较低,故可通过系统自带的软件调度机制进行软件调度,无需设计专门的硬件去调度,从而降低了硬件调度器的设计难度和成本,且软件调度器能够实现更为丰富的任务。
针对一些复杂但实时性要求较低的任务而言,对于调度效率的要求并不高,基于硬件进行调度会导致硬件的设计难度以及成本较大的问题,亟需一种设计难度以及成本均较低,且能够兼容复杂任务的调度的方案。
本申请实施方式中,进行硬件调度的硬件调度器提供了基本的基于消息触发的可抢占式调度设计,而复杂场景下更加丰富的调度器应用,比如,信号量,互斥信号量,定时服务,优先级继承,优先级抢占门限,任务挂起,任务恢复等,可通过软件调度器实现。
在接收到第二中断信号的情况下,由于中断(具体为中断回调函数)可能会改变系统中不同任务队列的任务优先级,因此,在进行任务调度前,都需要重新进行任务轮询,以确定所有任务队列(每个任务队列可对应一个任务)的任务优先级,最后根据所有任务队列的任务优先级来确定任务调度策略,例如,处理任务优先级最高的任务队列。
请参阅图3,可选地,步骤011可包括:
步骤0111:在第一中断优先级大于第二中断优先级的情况下,挂起当前服务消息队列的消息,并处理目标服务消息队列的消息;
步骤0112:在第一中断优先级小于或等于第二中断优先级的情况下,继续处理当前服务消息队列的消息。
具体地,在确定待处理消息的调度策略时,可判断待处理消息对应的第一中断优先级和当前服务消息队列对应的第二中断优先级彼此之间的大小,在第一中断优先级大于第二中断优先级的情况下,说明待处理消息需要优先被处理,因此,此时可挂起当前服务消息队列,然后处理待处理消息所在的目标服务消息队列。其中,挂起当前服务消息队列指的是暂停当前服务消息队列的处理,并保存当前服务消息队列的状态信息,从而方便处理完目标服务消息队列后,再次恢复当前服务消息队列的处理。
保存当前服务消息队列的状态可以通过将当前服务消息队列进行寄存器压栈操作来实现,即将处理当前服务消息队列的处理器的相关状态进行压栈即可,由于本申请采用基于现有硬件中断控制器技术而设计实现的调度器功能,取消了软件对于操作系统的任务上下文的管理,因此相比于传统基于软件实现的实时操作系统的调度器,无论从任务调度开销还是中断响应时延都得以较少。请参阅表2,本申请在压栈时,只需进行处理器寄存器压栈即可,而无需进行操作系统整体的上下文压栈,压栈的开销得以减小。
中断信号到达处理器 3时钟周期(cycles)
处理器获取第一条指令 8cycles
处理器寄存器压栈 15cycles
操作系统上下文压栈 40cycles
中断回调函数处理 处理程序有关
操作系统上下文出栈 40cycles
处理器寄存器出栈 15cycles
中断返回 300cycles
表2中断过程处理器开销
本申请的硬件调度器对中断响应时延将降低(1–(3+8+15)/(3+8+15+40))*100%=66%,即减少了操作系统上下文压栈的时间消耗,中断处理的处理器开销将降低(1–(3+8+15+15)/(3+8+15+15+40+40+300))*100%=90%,即减少了操作系统上下文压栈和出栈、以及中断返回所需的时间,调度就绪任务需要的处理器开销将降低(1–(3+8+15+15)/300)=86%。更进一步的,本申请对于服务消息队列中同时存在多个待处理消息的情况下,处理器将不会线性累计硬件开销,服务消息队列针对中断事件产生的硬件开销是一次性的,即服务消息队列中的待处理消息一次性压栈或出栈,直至服务消息队列里的全部消息处理完成后中断退出。随着系统内部控制任务的消息交互的频率越高,所能节省的硬件开销也就越大。
以硬件多线程为例,为了提高线程间实时切换的性能,需要为每一个硬件线程提供一套独立的处理器专用寄存器组,用来保存硬件线程在运行过程中的上下文状态和数据。相比于单个硬件线程的技术方案,虽然在硬件线程切换过程中减少软件处理寄存器压栈出栈的开销,但却复制了一组独立的处理器专用寄存器,同时增加了处理器设计的复杂度。而本申请由于采用基于现有硬件中断控制器技术而设计实现的调度器功能,不需要增加额外的专有硬件逻辑用以提高系统调度性能,减少了大量的处理器资源,从而降低了芯片的面积与功耗。本申请提出的技术方案充分考虑了降低专用硬件资源与软件调度器对系统产生的开销,在性能与系统软硬件资源利用方面实现了更好的平衡。
而在第一中断优先级小于或等于第二中断优先级的情况下,说明待处理消息并不需要优先被处理,因此需要等待当前服务消息队列的消息处理完成后,才能够处理待处理消息,此时让待处理消息在目标服务消息队列中等待,继续处理当前服务消息队列的消息即可,从而通过服务消息队列对应的中断优先级,实现任务调度。
请参阅图4,可选地,步骤011可包括:
步骤0113:根据第一中断优先级、第二中断优先级和当前服务消息队列对应的中断源是否支持抢占,确定待处理消息的调度策略。
具体地,由于对于系统中互斥资源的保护与原子操作的部分而言,在进行对应的任务与处理时,是不能够被打断的,因此,不同中断源需要事先定义好相关属性,请参阅表3,每个中断源均具有如下属性:
中断优先级
目标处理器
是否支持抢占
目的服务消息队列
目的消息处理实体
表3中断源属性
其中,中断优先级用于表示中断源在进行中断时的优先级,目标处理器则表示中断源对应的消息应由电子设备的对应的处理器处理,是否支持抢占则表示中断源对应的服务消息队列在被处理时,是否能够被其他服务消息队列抢占,目的服务消息队列则表示中断源绑定的服务消息队列的标识信息,每个服务消息队列均存在唯一的标识信息,目的消息处理实体则表示用于处理中断源对应的服务消息队列的消息处理实体的标识信息,消息处理实体也存在唯一的标识信息。
因此,在进行第一中断优先级和第二中断优先级之间的大小判断之前,可先确定当前服务消息队列(或具体为当前正在处理的消息)对应的中断源是否支持抢占,在支持抢占的情况下,判断第一中断优先级是否大于第二中断优先级,从而在第一中断优先级大于第二中断优先级的情况下,挂起当前服务消息队列的消息,并处理目标服务消息队列的消息;而在第一中断优先级小于或等于第二中断优先级或当前服务消息队列(或具体为当前正在处理的消息)对应的中断源禁止抢占的情况下,继续处理当前服务消息队列的消息。如此,通过设置中断源的是否支持抢占的属性后,高优先级服务消息队列(即服务消息队列绑定的中断源的中断优先级较高)将被禁止抢占当前正在处理的服务消息队列,从而实现对于系统中资源一致性的保护。
请参阅图5,在发送待处理消息到的目标服务消息队列之前,调度方法还包括:
步骤010:从空闲消息队列中获取待处理消息对应的消息描述符,消息描述符包括消息标识和消息体地址;
具体地,系统分发的消息需要进行消息的申请,以为消息的具体信息分配对应的资源(如内存等),消息的申请流程主要是申请消息的消息描述符和消息体。消息描述符中包含用来说明消息总体信息的描述信息,描述信息用于对消息进行正确的解析和处理。消息体则是用来存放消息的实际内容,内容中可包含控制系统中任务间传递的具体数据内容。
本申请中,设计了专门用于存放消息描述符和消息体的空闲消息队列。
请参阅图6,可选地,空闲消息队列可包括消息描述符队列和消息体队列,消息描述符队列用于存放消息描述符(如图6中的描述符地址N(N为整数且大于3)),消息体队列则用于存放消息体(如图6中的消息体地址M(M为整数且大于3))。
在进行消息申请时,可从消息描述符队列中申请消息描述符(如将消息描述符队列中位于队首的消息描述符出栈),消息描述符队列中的消息描述符实际为存储有描述信息的内存地址,申请消息描述符的过程即为将说明消息总体信息的描述信息存储到消息描述符对应的内存地址中的过程。
消息的消息体的内容可以为空,此时则不需要申请消息体,直接将描述符地址封装即可得到消息描述符,从而将带有消息描述符的待处理消息发送到对应的目标服务消息队列进行处理即可。
而在消息的消息体存在具体数据内容时,则需要申请消息体,可从消息体队列中申请消息体,如将消息体队列中位于队首的消息体出栈,消息体队列中的消息体实际为存储有消息体具体数据内容的内存地址,因此,申请消息体的过程即为将消息的具体数据内容存储到消息体对应的内存地址中的过程。
在申请得到消息描述符的地址和消息体地址后,即可将消息描述符的地址和消息体地址封装得到消息描述符,从而可将带有消息描述符的待处理消息发送到对应的目标服务消息队列,从而方便消息处理实体对待处理消息的处理。
消息描述符的具体包含的内容如下表4:
消息标识
消息大小
消息类型
消息源地址
消息目的地址
消息体地址
表4消息描述符内容
其中,消息描述符中的信息能够方便消息处理实体进行消息的解析和处理,如其中的消息标识用于消息处理实体找到处理消息体地址中的具体数据内容的处理函数,消息大小和类型则是消息的基本信息,消息源地址和消息目标地址则可分别指向不同的服务消息队列,从而实现不同服务消息队列之间的通信。
此外,消息体在内存中的地址信息(即表3中的消息体地址)将在消息描述符中维护,从而可以灵活的支持系统中对于消息体的拷贝与发送。例如,当一条消息需要被多次拷贝发送到不同的服务消息队列中处理时,系统可以申请多个消息描述符,多个消息描述符可能仅是消息目的地址不同,多个 消息描述符中消息体地址是相同的,从而减少实时系统中由于多次发送相同消息内容,而需要多次拷贝消息体的具体数据内容而产生的性能下降。
可选地,本申请中的空闲消息队列可以在系统启动后,初始化消息描述符队列中每个消息描述符的地址、及消息体队列中的每个消息体地址。也即是说,消息描述符中的每个消息描述符的地址和消息体地址都是提前分配好资源的,从而无需在每次申请消息的时候,再进行内存资源的分配,从而有利于提高消息申请的效率,进而提高消息发送的效率。
可选地,本申请的空闲消息队列存储在电子设备的第一队列寄存器中,服务消息队列则存在第二队列寄存器中,第二队列寄存器有多个,每个第二队列寄存器存储一个或多个服务消息队列,由于寄存器是在保存在通用内存中,不会对处理器的硬件资源产生额外的开销,同时又可以提高寄存器压栈与出栈的性能。
请参阅图7,可选地,步骤0111:处理目标服务消息队列的消息,包括:
步骤01111:发送带有消息描述符的待处理消息到对应的消息处理实体,以使得消息处理实体获取消息标识对应的预设处理函数及消息体地址对应的消息内容,并根据预设处理函数处理消息内容。
具体地,在将带有消息描述符的待处理消息发送到目标服务消息队列后,此时中断控制器产生与目标服务消息队列对应的中断源的中断信号,在中断信号对应的中断源的第一中断优先级大于当前正在处理的当前服务消息队列对应的中断源的第二中断优先级的情况下,可挂起当前服务消息队列的消息,并处理目标服务消息队列的消息。
在处理时,可根据中断源属性首先确定目标服务消息队列对应的消息处理实体,然后发送带有消息描述符的待处理消息到对应的消息处理实体进行消息处理即可。在进行消息处理时,消息处理实体首先根据消息描述符的地址,获取到消息描述符中的消息标识,从而获取与消息标识绑定的预设处理函数,然后获取消息描述符中的消息体地址,并获取到消息体的具体数据内容,最后根据预设处理函数对该具体数据内容进行处理,从而完成待处理消息的处理。
前述已经提到消息描述符中可包含消息源地址和消息目的地址,以分别表示发送消息的源服务消息队列,以及接收消息的目的服务消息队列,从而实现不同服务消息队列之间的通信。因此,在消息处理实体根据预设处理函数处理消息体的情况下,若需要与目的服务消息队列进行通信,则消息处理实体发送消息到目的服务消息队列,以使得中断控制器产生与目的服务消息队列对应的中断源的中断信号,从而进行中断处理,实现服务消息队列之间的通信。
可以理解,不同服务消息队列对应的任务之间并不是孤立的,一个任务的执行可能需要其他任务先执行,例如,在处理当前服务消息队列(即源服务消息队列)的消息1时,需要另外一个目的服务消息队列先处理消息2,因此,当前服务消息队列可申请消息2并发送到目的服务消息队列中,以触发中断来先处理消息2,在完成消息2的处理后,则退出中断再次处理消息1。
请参阅图8,可选地,步骤0111:处理目标服务消息队列的消息,包括:
步骤01112:在待处理消息被处理完的情况下,释放带有消息描述符的待处理消息到空闲消息队列。
具体地,在待处理消息被处理完的情况下,待处理消息的消息描述符就不应该再占用系统资源,如待处理消息的消息描述符需要从目标服务消息队列中再次释放到空闲消息队列,释放待处理消息的消息描述符到空闲消息队列具体可以是,将消息描述符中的消息描述符的地址中存储的信息以及消息体地址中存储的信息均删除,以腾出内存空间,并将消息描述符再次入栈到空闲消息队列,例如将消息描述符的地址入栈到消息描述符队列的队尾,将消息体地址入栈到消息体队列的队尾,如此,空闲消息队列能够实现消息的申请分配以及回收。
可选地,在未接收到待处理消息的情况下,根据每个服务消息队列对应的中断源的中断优先级,依次发送服务消息队列的消息到对应的消息处理实体中进行处理,消息处理实体对应至少一个服务消息队列。
可以理解,处理器中的消息处理实体的数量是有限的,而服务消息队列的数量则可根据系统的中断优先级的设置来确定,如本申请中,服务消息队列的数量一般远大于消息处理实体的数量,因此,一个消息处理实体可对应多个服务消息队列,如图9所示,服务消息队列1-Z按照中断优先级从低到高排列,服务消息队列1和2对应消息处理实体1,服务消息队列3到Z(Z为整数且大于3)则对应服务消息实体2。
以消息处理实体1处理服务消息队列1和2为例,在未接收到待处理消息的情况下,会按照中断优先级从高到低依次发送服务消息队列2和1的消息到对应的消息处理实体1中进行处理,使得消息处理实体1先处理服务消息队列2的消息,再处理服务消息队列1的消息。而在接收到待处理消息,触发中断后,则会判断待处理消息对应的目标服务消息队列的中断优先级是否大于当前处理的当前服务消息队列的中断优先级。例如,当前服务消息队列为服务消息队列1,目标服务消息队列为服务消息队列2,则由于服务消息队列2的中断优先级大于服务消息队列1的中断优先级,则消息处理实体1会挂起服务消息队列1,从而处理目标服务消息队列。
本申请实施方式的调度方法,相较于现有的软件操作系统和硬件多线程的实时可抢占多任务处理功能而言,通过利用系统自带的中断控制器实现任务调度,大量的减少了系统消耗的软硬件开销的同时,简化了系统设计,提高了系统的可靠性。
且本申请中的硬件调度器设计,可支持服务消息队列间的优先级抢占及通信;优先级抢占禁止,以实现资源一致性保护;并可以实现消息资源的申请、分配与释放等调度功能,同时由于本申请的服务消息队列中的待处理消息是一次性压栈或出栈,系统运行时开销的占比将随着系统内部控制任务间消息交互频率的上升而降低。
请参阅图10,步骤012包括:
步骤0121:轮询所有任务队列的任务优先级,以确定最高优先级的目标任务队列;
步骤0122:在当前正在处理的当前任务队列不是目标任务队列的情况下,挂起当前任务队列,并处理目标任务队列;
步骤0123:在当前任务队列是目标任务队列的情况下,继续处理当前任务队列。
具体地,在进行软件任务调度时,每次在中断进入时,由于中断会影响任务队列的任务优先级,因此,进行任务切换前,需要重新进行任务轮询,根据所有任务队列的任务优先级,以确定最高优先级的目标任务队列。
若当前正在处理的当前任务队列不是目标任务队列,则需要进行任务切换,在进行任务切换时,需要先挂起当前正在处理的当前任务队列,具体为保存系统中当前任务队列的上下文信息以及处理当前任务队列的处理器的状态信息,从而方便在后续继续处理当前任务队列时,能够从当前任务队列的断点处恢复处理,不影响当前任务队列已经执行的任务操作,防止每次进行任务切换后,再次执行被挂起的任务队列时,都需要重头开始执行,影响任务执行效率。
而在当前任务队列即为目标任务队列时,则不需要对当前任务队列进行挂起,而是继续执行当前任务队列即可,从而根据任务优先级实现软件任务调度。
请参阅图11,调度方法还包括:
步骤014:在目标任务队列处理完成后,重新轮询所有任务队列的任务优先级,以重新确定目标任务队列;
步骤015:根据重新确定的目标任务队列的上下文信息及状态信息恢复重新确定的目标任务队列的处理。
具体地,在最高优先级的目标任务队列被处理完成,中断退出后,任务队列的任务优先级可能也会发生变化,因此,需要再次进行任务轮询,以重新确定最高优先级的目标任务队列,重新确定的目标任务队列一般为之前被挂起的当前任务队列,因此,在处理目标任务队列时,需要获取到重新确定的目标任务队列的上下文信息及状态信息,从而根据该上下文信息及状态信息恢复重新确定的目标任务队列的处理,使得重新确定的目标任务队列能够在被挂起的断点处继续处理,保证任务执行效率。
请参阅图12,在进行软件任务调度时,软件调度器会实时维护每个任务队列的状态信息,任务队列的状态包括就绪、执行、挂起、停止和完成,任务队列的状态信息会在这五个状态之间进行切换。在任务队列就绪时,表示任务队列能够随时被处理;在任务队列被处理时即表示任务队列状态为执行;在任务队列被挂起时,任务队列的上下文信息和状态信息被存储,以方便从挂起状态恢复到就绪状态,从而进行任务队列的处理;在任务队列被停止时,说明任务队列对应的任务不再需要执行;在任务队列被完成时,表示任务队列对应的任务已执行完成。通过软件调度器实时维护每个任务队列的状态信息,从而有利于任务调度。在进行任务轮询时,可只需要轮询就绪状态的任务即可,从而减少了任务轮询消耗的计算力,提高了任务调度效率。
请参阅图13,调度方法还包括:
步骤016:在处理任务队列的情况下,若接收到第一中断信号,则挂起任务队列,以处理第一中断信号对应的目标服务消息队列的消息。
具体地,任务在执行时,均是通过处理器中的消息处理实体进行的,硬件调度器和软件调度器调度的任务均可通过消息处理实体执行,当处理器没有空闲的消息处理实体的情况下,若消息处理实体正在处理由软件调度器调度的任务队列,则由于硬件调度器的中断优先级始终大于软件调度器的中断优先级,因此,若此时接收到第一中断信号,则会将任务队列挂起,从而执行第一中断信号对应的目标服务消息队列的消息,优先处理硬件调度器调度的任务。如此,保证了实时性要求较高的硬件调度器调度的任务能够抢占软件调度器调度的任务执行,可提高任务调度效率。
请参阅图14,第二中断信号包括外部硬件中断、系统定时中断和可悬挂请求中断,可悬挂请求中断的中断优先级低于任务队列对应的中断信号的中断优先级,调度方法还包括:
步骤017:在处理外部硬件中断的情况下,若接收到系统定时中断,则产生可悬挂请求中断,以使得外部硬件中断被处理完后,进行任务切换处理,任务切换处理包括轮询所有任务队列的任务优先级,以确定最高优先级的目标任务队列,并切换到目标任务队列进行处理。
具体地,软件调度器是基于软件实现的优先级抢占需要调度器对任务的上下文进行管理。为了保证每个任务队列的任务优先级的准确性,软件调度器通过系统定时中断,来定时更新任务队列的任务优先级,具体的,当一个系统定时中断到达后,操作系统将执行以下操作:
1.保存任务:将处理器的寄存器压入当前被中断的任务对应的堆栈中(即保存系统中当前被中断的任务队列的上下文信息以及处理当前任务队列的处理器的状态信息);
2.定时更新:更新系统定时器计时值;
3.任务轮询:调度器对于当前任务就绪列表进行更新(即获取处于就绪状态的任务队列),根据每个任务的任务优先级,选出当前可以被调度的最高优先级的任务;
4.任务切换:将最高优先级的任务出栈,并恢复该任务的上下文信息到处理器的寄存器中,中断返回后,跳转到最高优先级的任务的断点处继续执行。
由上述任务调度流程可以看出,操作系统在执行任务的优先级轮询过程中需要执行必要的任务上下文保存与恢复操作,这些操作将对操作系统的实时性产生性能影响。
而系统定时中断所需进行的任务轮询以及任务切换在外部硬件中断被完成后进行任务调度时也会被执行,因此,在处理外部硬件中断的过程中,若接收到系统定时中断,可仅进行保存任务和定时更新,并触发一个中断优先级较低(低于任务队列对应的中断优先级)的可悬挂请求中断,来暂缓执行系统定时中断中的任务轮询和任务切换,在外部硬件中断处理完成后,再进行任务切换处理,即进行上述任务轮询以及任务切换,相较于现有的软件任务调度中,系统定时中断需要一次任务轮询和一次任务切换,任务队列完成后还需要再做一次任务轮询和一次任务切换而言,由于系统定时中断中的任务轮询和任务切换被暂缓到任务队列完成后执行,省去了一次任务轮询和一次任务切换的计算力消耗,不仅提升了系统的任务调度效率,而且在不影响任务调度准确性的前提下,能够保证外部硬件中断始终优先处理。
请参阅图15,调度方法还包括:
步骤018:在处理任务队列的情况下,调用第一预设消息接口,以发送消息到目标服务消息队列;及
步骤019:在处理服务消息队列的情况下,调用第二预设消息接口,以发送消息到任务队列。
具体地,硬件调度器和软件调度器中均具有消息发送接口,以方便硬件调度器和软件调度器的任务之间进行线程间通信。例如,硬件调度器中设置有第一预设消息接口,任务队列在被处理的过程中,能够调用第一预设消息接口,向硬件调度器中的目标服务消息队列发送消息,以通过硬件调度器实现一些实时性较高的消息的处理。同样地,软件调度器中也设置有第二预设消息接口,在目标服务消息队列被处理的过程中,也能够调用第二预设消息接口,来向对应的任务队列发送消息,从而将一些实时性要求不高的消息分发给软件调度器进行调度处理,实现任务队列和服务消息队列之间的通信,保证实时性要求高的消息始终能够被优先处理。
为便于更好的实施本申请实施例的调度方法,本申请实施例还提供一种调度装置10。请参阅图16, 该调度装置10可以包括:
第一确定模块11,用于在将待处理消息发送到对应的目标服务消息队列的情况下,控制中断控制器产生与目标服务消息队列对应的中断源的第一中断信号,并根据第一中断信号对应的中断源的第一中断优先级和当前处理的当前服务消息队列对应的中断源的第二中断优先级,确定待处理消息的调度策略;
第二确定模块12,用于在接收到第二中断信号的情况下,根据所有任务队列的任务优先级确定任务调度策略,第二中断信号对应的中断源的中断优先级低于第一中断信号对应的中断源的中断优先级。
第一确定模块11具体用于:
在第一中断优先级大于第二中断优先级的情况下,挂起当前服务消息队列的消息,并处理目标服务消息队列的消息;
在第一中断优先级小于或等于第二中断优先级的情况下,继续处理当前服务消息队列的消息。
第一确定模块11具体还用于:
根据第一中断优先级、第二中断优先级和当前服务消息队列对应的中断源是否支持抢占,确定待处理消息的调度策略。
第一确定模块11具体还用于:
在第一中断优先级大于第二中断优先级且当前服务消息队列对应的中断源支持抢占的情况下,挂起当前服务消息队列的消息,并处理目标服务消息队列的消息;
在第一中断优先级小于或等于第二中断优先级或当前服务消息队列对应的中断源禁止抢占的情况下,继续处理当前服务消息队列的消息。
第一确定模块11具体还用于保存处理当前服务消息队列的处理器的状态信息。
第二确定模块12具体用于:
轮询所有任务队列的任务优先级,以确定最高优先级的目标任务队列;
在当前正在处理的当前任务队列不是目标任务队列的情况下,挂起当前任务队列,并处理目标任务队列;
在当前任务队列是目标任务队列的情况下,继续处理当前任务队列。
第二确定模块12具体还用于:保存系统中当前任务队列的上下文信息以及处理当前任务队列的处理器的状态信息。
调度装置10还包括:
第三确定模块13,用于在目标任务队列处理完成后,重新轮询所有任务队列的任务优先级,以重新确定目标任务队列;
恢复模块14,用于根据重新确定的目标任务队列的上下文信息及状态信息恢复重新确定的目标任务队列的处理。
调度装置10还包括:
维护模块15,用于维护每个任务队列的状态信息,状态信息包括就绪、执行、挂起、停止和完成。
第二确定模块12具体还用于轮询所有就绪的任务队列的任务优先级,以确定最高优先级的目标任务队列。
调度装置10还包括:
抢占模块16,用于在处理任务队列的情况下,若接收到第一中断信号,则挂起任务队列,以处理第一中断信号对应的目标服务消息队列的消息。
调度装置10还包括:
悬挂模块17,用于在处理外部硬件中断的情况下,若接收到系统定时中断,则产生可悬挂请求中断,以使得外部硬件中断被处理完后,进行任务切换处理,任务切换处理包括轮询所有任务队列的任务优先级,以确定最高优先级的目标任务队列,并切换到目标任务队列进行处理。
调度装置10还包括:
调用模块18,用于在处理任务队列的情况下,调用第一预设消息接口,以发送消息到目标服务消息队列;及在处理服务消息队列的情况下,调用第二预设消息接口,以发送消息到任务队列。
上述调度装置10中的各个模块可全部或部分通过软件、硬件及其组合来实现。上述各个模块可以 以硬件形式内嵌于或独立于计算机设备中的处理器中,也可以以软件形式存储于计算机设备中的存储器中,以便于处理器调用执行上述各个模块对应的操作。
请参阅图17,本申请实施方式的芯片40设置在电子设备100内,并与电子设备100的中断控制器50连接。芯片40用于执行上述硬件调度器的任意一种实施方式的调度方法的步骤,具体为步骤011、步骤0111、步骤0112、步骤0113、步骤01111、步骤01112、步骤010和步骤019,为了简洁,在此不再赘述。
请再次参阅图17,本申请实施方式的电子设备100包括处理器30。处理器30用于执行上述任意一种实施方式的调度方法,为了简洁,在此不再赘述。
其中,电子设备100可以是移动电话,智能电话,个人数字助理(personal digital assistants,PDA),平板电脑和视频游戏设备,便携式终端(例如笔记本电脑),或较大尺寸的设备(例如台式计算机和电视),或者其他任何类型的包括TOF相机的设备。
其中,本申请的硬件调度器和软件调度器可以不受限于部署约束在同一个嵌入式处理器中。它同时可以基于系统总体的设计,针对系统中不同处理器的实时性需求部署在一个分布式的处理器中,完成系统对于不同类型嵌入式处理器对于不同实时性任务的调度执行。同时,它也可以将软硬件调度器分别部署在同一个嵌入式处理器的不同内核中。
请参阅图18,本申请实施方式还提供了一种计算机可读存储介质300,其上存储有计算机程序310,计算机程序310被处理器30执行的情况下,实现上述任意一种实施方式的调度方法的步骤,为了简洁,在此不再赘述。
可以理解,计算机程序310包括计算机程序代码。计算机程序代码可以为源代码形式、对象代码形式、可执行文件或某些中间形式等。计算机可读存储介质可以包括:能够携带计算机程序代码的任何实体或装置、记录介质、U盘、移动硬盘、磁碟、光盘、计算机存储器、只读存储器(ROM,Read-Only Memory)、随机存取存储器(RAM,Random Access Memory)、以及软件分发介质等。
在本说明书的描述中,参考术语“一个实施方式”、“一些实施方式”、“示意性实施方式”、“示例”、“具体示例”或“一些示例”等的描述意指结合所述实施方式或示例描述的具体特征、结构、材料或者特点包含于本申请的至少一个实施方式或示例中。在本说明书中,对上述术语的示意性表述不一定指的是相同的实施方式或示例。而且,描述的具体特征、结构、材料或者特点可以在任何的一个或多个实施方式或示例中以合适的方式结合。此外,在不相互矛盾的情况下,本领域的技术人员可以将本说明书中描述的不同实施例或示例以及不同实施例或示例的特征进行结合和组合。
流程图中或在此以其他方式描述的任何过程或方法描述可以被理解为,表示包括一个或更多个用于实现特定逻辑功能或过程的步骤的可执行指令的代码的模块、片段或部分,并且本申请的优选实施方式的范围包括另外的实现,其中可以不按所示出或讨论的顺序,包括根据所涉及的功能按基本同时的方式或按相反的顺序,来执行功能,这应被本申请的实施例所属技术领域的技术人员所理解。
尽管上面已经示出和描述了本申请的实施方式,可以理解的是,上述实施方式是示例性的,不能理解为对本申请的限制,本领域的普通技术人员在本申请的范围内可以对上述实施方式进行变化、修改、替换和变型。

Claims (27)

  1. 一种调度方法,其特征在于,包括:
    在将待处理消息发送到对应的目标服务消息队列的情况下,控制中断控制器产生与所述目标服务消息队列对应的中断源的第一中断信号,并根据所述第一中断信号对应的中断源的第一中断优先级和当前处理的当前服务消息队列对应的中断源的第二中断优先级,确定所述待处理消息的调度策略;
    在接收到第二中断信号的情况下,根据所有任务队列的任务优先级确定任务调度策略,所述第二中断信号对应的中断源的中断优先级低于所述第一中断信号对应的中断源的中断优先级。
  2. 根据权利要求1所述的调度方法,其特征在于,所述根据所述第一中断信号对应的中断源的第一中断优先级和当前处理的当前服务消息队列对应的中断源的第二中断优先级,确定所述待处理消息的调度策略,包括:
    在所述第一中断优先级大于所述第二中断优先级的情况下,挂起所述当前服务消息队列的消息,并处理所述目标服务消息队列的消息;
    在所述第一中断优先级小于或等于所述第二中断优先级的情况下,继续处理所述当前服务消息队列的消息。
  3. 根据权利要求1所述的调度方法,其特征在于,所述根据所述第一中断信号对应的中断源的第一中断优先级和当前处理的当前服务消息队列对应的中断源的第二中断优先级,确定所述待处理消息的调度策略,包括:
    根据所述第一中断优先级、所述第二中断优先级和所述当前服务消息队列对应的中断源是否支持抢占,确定所述待处理消息的调度策略。
  4. 根据权利要求3所述的调度方法,其特征在于,所述根据所述第一中断优先级、所述第二中断优先级和所述当前服务消息队列对应的中断源是否支持抢占,确定所述待处理消息的调度策略,包括:
    在所述第一中断优先级大于所述第二中断优先级且所述当前服务消息队列对应的中断源支持抢占的情况下,挂起所述当前服务消息队列的消息,并处理所述目标服务消息队列的消息;
    在所述第一中断优先级小于或等于所述第二中断优先级或所述当前服务消息队列对应的中断源禁止抢占的情况下,继续处理所述当前服务消息队列的消息。
  5. 根据权利要求2或4所述的调度方法,其特征在于,所述挂起所述当前服务消息队列的消息,包括:
    保存处理所述当前服务消息队列的处理器的状态信息。
  6. 根据权利要求1所述的调度方法,其特征在于,所述根据所有任务队列的任务优先级确定任务调度策略,包括:
    轮询所有任务队列的任务优先级,以确定最高优先级的目标任务队列;
    在当前正在处理的当前任务队列不是所述目标任务队列的情况下,挂起当前任务队列,并处理所述目标任务队列;
    在所述当前任务队列是所述目标任务队列的情况下,继续处理所述当前任务队列。
  7. 根据权利要求6所述的调度方法,其特征在于,所述挂起当前正在处理的当前任务队列,包括:
    保存系统中所述当前任务队列的上下文信息以及处理所述当前任务队列的处理器的状态信息。
  8. 根据权利要求7所述的调度方法,其特征在于,还包括:
    在所述目标任务队列处理完成后,重新轮询所有任务队列的任务优先级,以重新确定所述目标任务队列;
    根据重新确定的所述目标任务队列的上下文信息及状态信息恢复重新确定的所述目标任务队列的处理。
  9. 根据权利要求6所述的调度方法,其特征在于,还包括:
    维护每个任务队列的状态信息,所述状态信息包括就绪、执行、挂起、停止和完成;
    所述轮询所有任务队列的任务优先级,以确定最高优先级的目标任务队列,包括:
    轮询所有就绪的任务队列的任务优先级,以确定最高优先级的所述目标任务队列。
  10. 根据权利要求1所述的调度方法,其特征在于,还包括:
    在处理所述任务队列的情况下,若接收到所述第一中断信号,则挂起所述任务队列,以处理所述 第一中断信号对应的所述目标服务消息队列的消息。
  11. 根据权利要求1所述的调度方法,其特征在于,所述第二中断信号包括外部硬件中断、系统定时中断和可悬挂请求中断,所述可悬挂请求中断的中断优先级低于所述任务队列对应的中断信号的中断优先级,所述调度方法还包括:
    在处理所述外部硬件中断的情况下,若接收到所述系统定时中断,则产生所述可悬挂请求中断,以使得所述外部硬件中断被处理完后,进行任务切换处理,所述任务切换处理包括轮询所有任务队列的任务优先级,以确定最高优先级的目标任务队列,并切换到所述目标任务队列进行处理。
  12. 根据权利要求1所述的调度方法,其特征在于,还包括:
    在处理所述任务队列的情况下,调用第一预设消息接口,以发送消息到所述目标服务消息队列;及
    在处理服务消息队列的情况下,调用第二预设消息接口,以发送消息到所述任务队列。
  13. 一种调度装置,其特征在于,所述装置包括:
    第一确定模块,用于在将待处理消息发送到对应的目标服务消息队列的情况下,控制中断控制器产生与所述目标服务消息队列对应的中断源的第一中断信号,并根据所述第一中断信号对应的中断源的第一中断优先级和当前处理的当前服务消息队列对应的中断源的第二中断优先级,确定所述待处理消息的调度策略;
    第二确定模块,用于在接收到第二中断信号的情况下,根据所有任务队列的任务优先级确定任务调度策略,所述第二中断信号对应的中断源的中断优先级低于所述第一中断信号对应的中断源的中断优先级。
  14. 一种芯片,其特征在于,所述芯片与电子设备的中断控制器连接,所述芯片用于在将待处理消息发送到对应的目标服务消息队列的情况下,控制所述中断控制器产生与所述目标服务消息队列对应的中断源的第一中断信号,并根据所述第一中断信号对应的中断源的第一中断优先级和当前处理的当前服务消息队列对应的中断源的第二中断优先级,确定所述待处理消息的调度策略;所述电子设备的处理器用于在接收到第二中断信号的情况下,根据所有任务队列的任务优先级确定任务调度策略,所述第二中断信号对应的中断源的中断优先级低于所述第一中断信号对应的中断源的中断优先级。
  15. 一种电子设备,其特征在于,包括处理器,所述处理器用于在将待处理消息发送到对应的目标服务消息队列的情况下,控制中断控制器产生与所述目标服务消息队列对应的中断源的第一中断信号,并根据所述第一中断信号对应的中断源的第一中断优先级和当前处理的当前服务消息队列对应的中断源的第二中断优先级,确定所述待处理消息的调度策略;在接收到第二中断信号的情况下,根据所有任务队列的任务优先级确定任务调度策略,所述第二中断信号对应的中断源的中断优先级低于所述第一中断信号对应的中断源的中断优先级。
  16. 根据权利要求15所述的电子设备,其特征在于,所述处理器还用于在所述第一中断优先级大于所述第二中断优先级的情况下,挂起所述当前服务消息队列的消息,并处理所述目标服务消息队列的消息;在所述第一中断优先级小于或等于所述第二中断优先级的情况下,继续处理所述当前服务消息队列的消息。
  17. 根据权利要求15所述的电子设备,其特征在于,所述处理器还用于根据所述第一中断优先级、所述第二中断优先级和所述当前服务消息队列对应的中断源是否支持抢占,确定所述待处理消息的调度策略。
  18. 根据权利要求17所述的电子设备,其特征在于,所述处理器还用于在所述第一中断优先级大于所述第二中断优先级且所述当前服务消息队列对应的中断源支持抢占的情况下,挂起所述当前服务消息队列的消息,并处理所述目标服务消息队列的消息;在所述第一中断优先级小于或等于所述第二中断优先级或所述当前服务消息队列对应的中断源禁止抢占的情况下,继续处理所述当前服务消息队列的消息。
  19. 根据权利要求16或18所述的电子设备,其特征在于,所述处理器还用于保存处理所述当前服务消息队列的处理器的状态信息。
  20. 根据权利要求15所述的电子设备,其特征在于,所述处理器还用于轮询所有任务队列的任务优先级,以确定最高优先级的目标任务队列;在当前正在处理的当前任务队列不是所述目标任务队列 的情况下,挂起当前任务队列,并处理所述目标任务队列;在所述当前任务队列是所述目标任务队列的情况下,继续处理所述当前任务队列。
  21. 根据权利要求20所述的电子设备,其特征在于,所述处理器还用于保存系统中所述当前任务队列的上下文信息以及处理所述当前任务队列的处理器的状态信息。
  22. 根据权利要求21所述的电子设备,其特征在于,所述处理器还用于在所述目标任务队列处理完成后,重新轮询所有任务队列的任务优先级,以重新确定所述目标任务队列;根据重新确定的所述目标任务队列的上下文信息及状态信息恢复重新确定的所述目标任务队列的处理。
  23. 根据权利要求20所述的电子设备,其特征在于,所述处理器还用于维护每个任务队列的状态信息,所述状态信息包括就绪、执行、挂起、停止和完成;轮询所有就绪的任务队列的任务优先级,以确定最高优先级的所述目标任务队列。
  24. 根据权利要求15所述的电子设备,其特征在于,所述处理器还用于在处理所述任务队列的情况下,若接收到所述第一中断信号,则挂起所述任务队列,以处理所述第一中断信号对应的所述目标服务消息队列的消息。
  25. 根据权利要求15所述的电子设备,其特征在于,所述第二中断信号包括外部硬件中断、系统定时中断和可悬挂请求中断,所述可悬挂请求中断的中断优先级低于所述任务队列对应的中断信号的中断优先级,所述处理器还用于在处理所述外部硬件中断的情况下,若接收到所述系统定时中断,则产生所述可悬挂请求中断,以使得所述外部硬件中断被处理完后,进行任务切换处理,所述任务切换处理包括轮询所有任务队列的任务优先级,以确定最高优先级的目标任务队列,并切换到所述目标任务队列进行处理。
  26. 根据权利要求15所述的电子设备,其特征在于,所述处理器还用于在处理所述任务队列的情况下,调用第一预设消息接口,以发送消息到所述目标服务消息队列;及在处理服务消息队列的情况下,调用第二预设消息接口,以发送消息到所述任务队列。
  27. 一种计算机程序的非易失性计算机可读存储介质,其特征在于,当所述计算机程序被一个或多个处理器执行时,实现权利要求1-12中任一项所述的调度方法。
PCT/CN2022/141218 2022-06-23 2022-12-23 调度方法及装置、芯片、电子设备及存储介质 WO2023246044A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202210726021.6A CN115237556A (zh) 2022-06-23 2022-06-23 调度方法及装置、芯片、电子设备及存储介质
CN202210726021.6 2022-06-23

Publications (1)

Publication Number Publication Date
WO2023246044A1 true WO2023246044A1 (zh) 2023-12-28

Family

ID=83668814

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2022/141218 WO2023246044A1 (zh) 2022-06-23 2022-12-23 调度方法及装置、芯片、电子设备及存储介质

Country Status (2)

Country Link
CN (1) CN115237556A (zh)
WO (1) WO2023246044A1 (zh)

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115237556A (zh) * 2022-06-23 2022-10-25 哲库科技(北京)有限公司 调度方法及装置、芯片、电子设备及存储介质
CN115167996A (zh) * 2022-06-23 2022-10-11 哲库科技(北京)有限公司 调度方法及装置、芯片、电子设备及存储介质
CN116483549B (zh) * 2023-06-25 2023-09-19 清华大学 智能相机系统的任务调度方法、装置、相机及存储介质
CN117369987A (zh) * 2023-08-22 2024-01-09 华为技术有限公司 一种计算装置及相关任务执行调度方法

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20030208521A1 (en) * 2002-05-02 2003-11-06 International Business Machines Corporation System and method for thread scheduling with weak preemption policy
US20050015768A1 (en) * 2002-12-31 2005-01-20 Moore Mark Justin System and method for providing hardware-assisted task scheduling
CN104915254A (zh) * 2014-12-31 2015-09-16 杰瑞石油天然气工程有限公司 一种嵌入式系统的多任务调度方法及系统
CN114579285A (zh) * 2022-04-29 2022-06-03 武汉深之度科技有限公司 一种任务运行系统、方法及计算设备
CN115237556A (zh) * 2022-06-23 2022-10-25 哲库科技(北京)有限公司 调度方法及装置、芯片、电子设备及存储介质

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20030208521A1 (en) * 2002-05-02 2003-11-06 International Business Machines Corporation System and method for thread scheduling with weak preemption policy
US20050015768A1 (en) * 2002-12-31 2005-01-20 Moore Mark Justin System and method for providing hardware-assisted task scheduling
CN104915254A (zh) * 2014-12-31 2015-09-16 杰瑞石油天然气工程有限公司 一种嵌入式系统的多任务调度方法及系统
CN114579285A (zh) * 2022-04-29 2022-06-03 武汉深之度科技有限公司 一种任务运行系统、方法及计算设备
CN115237556A (zh) * 2022-06-23 2022-10-25 哲库科技(北京)有限公司 调度方法及装置、芯片、电子设备及存储介质

Also Published As

Publication number Publication date
CN115237556A (zh) 2022-10-25

Similar Documents

Publication Publication Date Title
WO2023246044A1 (zh) 调度方法及装置、芯片、电子设备及存储介质
WO2023246042A1 (zh) 调度方法及装置、芯片、电子设备及存储介质
US8505012B2 (en) System and method for scheduling threads requesting immediate CPU resource in the indexed time slot
JP6199477B2 (ja) ゲストオペレーティングシステムおよび仮想プロセッサとともにハイパーバイザを使用するシステムおよび方法
KR100628492B1 (ko) 실시간 동작 수행방법 및 시스템
US7464379B2 (en) Method and system for performing real-time operation
US7925869B2 (en) Instruction-level multithreading according to a predetermined fixed schedule in an embedded processor using zero-time context switching
US8161453B2 (en) Method and apparatus for implementing task management of computer operations
EP1548592B1 (en) Information processing device, process control method, and computer program
US20050015768A1 (en) System and method for providing hardware-assisted task scheduling
US20090271549A1 (en) Interrupt handling using simultaneous multi-threading
US20070033384A1 (en) Real-time embedded simple monitor method and computer product
US9122521B2 (en) Enabling multiple operating systems to run concurrently using barrier task priority
EP3770759A1 (en) Wake-up and scheduling of functions with context hints
KR101791182B1 (ko) 컴퓨터 시스템 인터럽트 핸들링
WO2023241307A1 (zh) 管理线程的方法及装置
JP2015141584A (ja) 情報処理装置、情報処理方法およびプログラム
US20130263144A1 (en) System Call Queue Between Visible and Invisible Computing Devices
Parikh et al. Performance parameters of RTOSs; comparison of open source RTOSs and benchmarking techniques
WO2004061663A2 (en) System and method for providing hardware-assisted task scheduling
JP7188472B2 (ja) コンピュータ、スケジューリング方法、及び、プログラム
EP4287024A1 (en) Multi-core processor, multi-core processor processing method, and related device
CN114911597A (zh) 一种运行系统的切换方法及计算设备
CN111767120A (zh) 基于消息与事件的多任务处理单元的调度方法与装置
Rutten et al. Eclipse Processor Scheduling

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 22947779

Country of ref document: EP

Kind code of ref document: A1