High-real-time scheduling method based on kernel modification and program design

By modifying the kernel of the Kylin operating system to employ spinlock mutual exclusion and interrupt threading, and combining this with a specific scheduling strategy to create high-priority tasks, the problem of insufficient real-time scheduling capability of the Kylin system in aerospace launches was solved, achieving higher real-time performance and reliability.

CN121785736APending Publication Date: 2026-04-03XICHANG SATELLITE LAUNCH CENT
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-12-25
Publication Date
2026-04-03

AI Technical Summary

Technical Problem

The existing Kylin operating system lacks high real-time scheduling capabilities in fields such as aerospace launches, making it difficult to effectively handle the reliability requirements of high-frequency, high-throughput missions.

Method used

By modifying the kernel and designing the program, using spinlock mutex and interrupt threading methods, and combining the SCHED_FIFO, SCHED_RR and SCHED_DEADLINE scheduling policies, high-priority real-time tasks are created, and scheduling optimization is performed in the Linux system kernel to ensure that real-time tasks can be preemptively executed.

Benefits of technology

The real-time performance and reliability of the Kylin system and its operating program have been improved, enabling it to better handle high-frequency, high-throughput tasks and meet the high reliability requirements of space launches.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121785736A_ABST
    Figure CN121785736A_ABST
Patent Text Reader

Abstract

The invention discloses a high-real-time scheduling method based on kernel modification and program design. The high-real-time scheduling method comprises the following steps: selecting a scheduling strategy; s2, creating a thread: setting a scheduling strategy and a priority in a thread attribute; s3, creating a high-priority real-time task: uploading the set thread attribute to a kernel scheduler of the Linux system; s4, activating a real-time task: scheduling the task to a ready queue of a scheduler; s5, judging whether the task strategy priority can preempt the task strategy on the current CPU or not, if not, entering the step S6, and if yes, entering the step S7; s6, migrating the task to other CPU cores capable of executing scheduling immediately; s7, activating the task, and searching the next task to be executed; s8, judging whether a task is executed on the current CPU or not, if yes, entering the step S9, and if not, entering the step S10; s9, scheduling real-time task queue jumping, and clearing the currently executed task; and S10, context (task) switching and task running.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of high real-time operating system technology, specifically, it relates to a high real-time scheduling method based on kernel modification and program design. Background Technology

[0002] Currently, in important fields such as aerospace launch, the requirements for independent control of equipment are becoming increasingly stringent. As a result, the use of the domestically developed Kylin operating system based on Linux is becoming more and more widespread. At the same time, aerospace launch has high reliability requirements, which places even more stringent demands on the operating system and the applications running on it. The high real-time scheduling capability of the Kylin system needs to withstand the test of reliable processing of high-frequency, high-throughput tasks. In order to improve the high real-time scheduling capability of the Kylin system and effectively process real-time tasks, this paper proposes a high real-time scheduling technology for the Kylin system based on kernel modification and program design. Summary of the Invention

[0003] To address the lack of high real-time scheduling capabilities in existing operating systems, this invention provides a high real-time scheduling method based on kernel modification and program design.

[0004] To achieve the above-mentioned technical objectives, the technical solution adopted by the present invention is as follows: A high real-time scheduling method based on kernel modification and program design includes the following steps: S1. Select the scheduling strategy; S2. Create a thread: Set the scheduling policy and priority in the thread properties; S3. Create a high-priority real-time task: Upload the set thread attributes to the Linux system kernel scheduler; S4. Activate real-time task: Schedule the task to the queue of tasks ready by the scheduler. S5. Determine whether the task policy priority can preempt the task policy on the current CPU. If not, proceed to step S6; if yes, proceed to step S7. S6. The task is migrated to another CPU core that can immediately execute the schedule; S7. Activate the task and find the next task to be executed. S8. Determine if there is a task being executed on the CPU. If yes, proceed to step S9; otherwise, proceed to step S10. S9. Schedule real-time tasks to jump the queue and clear currently executing tasks; S10, Context (task) switch, task execution.

[0005] Furthermore, in step S2, the Linux system kernel scheduler is used to modify the operating system kernel. By modifying the configuration policy of the operating system kernel, real-time modifications are made to ensure that real-time tasks can be preemptively executed with priority while avoiding being preempted by other tasks. Modifying the operating system kernel includes spinlock mutexing and interrupt threading.

[0006] Furthermore, spinlock mutexing was implemented, and the spinlocks in the kernel were redefined using PI-enabled RT Mutex, making them preemptible. The RT Mutex supports a priority inheritance mechanism, meaning that when a low-priority task holds a lock, if a high-priority real-time task attempts to acquire the lock, the system automatically and temporarily increases the priority of the low-priority task.

[0007] Furthermore, interrupt threading involves placing the execution of the upper half of the interrupt into a kernel thread. Interrupt handling participates in CPU scheduling as a medium-priority real-time task, thus allowing interrupt handling to be preempted by higher-priority real-time tasks. The upper half of an interrupt refers to the CPU responding directly to the interrupt signal immediately after a hardware interrupt occurs. After the interrupt response, the scheduler will immediately suspend the current task and start interrupt handling. During interrupt handling, the CPU cannot sleep or preempt.

[0008] Furthermore, the scheduling policies include SCHED_FIFO, SCHED_RR, and SCHED_DEADLINE; in SCHED_FIFO and SCHED_RR, higher priority tasks preempt lower priority tasks, and tasks can also be preempted by SCHED_DEADLINE or higher priority scheduling tasks. The SCHED_FIFO strategy follows the first-in-first-out principle for tasks of the same priority, and the first task to arrive will occupy the CPU indefinitely. The SCHED_RR strategy executes tasks of the same priority in turn, with each task having a CPU time slice. Tasks that have used up their time slices are reordered to the end of the queue. The SCHED_DEADLINE scheduling strategy does not require prioritization of task priority and directly ensures that more urgent tasks are scheduled first.

[0009] Furthermore, when setting thread attributes in step S2, that is, when creating a program thread, a certain scheduling strategy and priority are set in the attributes of the program thread. When the thread is created, the Linux system kernel scheduler will classify it into the corresponding scheduling class, and the real-time task wake-up and scheduling will be carried out according to the set scheduling strategy. The corresponding scheduling classes include SCHED_FIFO and SCHED_RR, which belong to the rt_sched_class scheduling class, and SCHED_DEADLINE, which belongs to the dl_sched_class scheduling class. The scheduling class is a set of functions that are encapsulated and callable in the Linux kernel, which define different task scheduling behaviors and priority rules.

[0010] Furthermore, when creating a high-priority real-time task, the application creates and activates the real-time task by calling system functions; the creation of the real-time task transmits the scheduling policy and priority set in the thread attributes to the Linux system kernel scheduler, and the kernel scheduler schedules the task according to the set scheduling policy.

[0011] Furthermore, when a real-time task is activated, it is scheduled to run on a CPU. If the current CPU core cannot be scheduled immediately, the real-time task is migrated to another CPU core that can be scheduled immediately.

[0012] Furthermore, in step S8, if a task is already being executed on the CPU, the TIF_NEED_RESCHED flag of the currently executing task will be cleared, and then steps S9 and S10 will be entered. After a context switch is performed by calling a system function, the task running on the CPU will be switched.

[0013] Furthermore, when the TIF_NEED_RESCHED flag is set, the task is considered a higher priority task and will be executed in the next step. The context switch is that the real-time task is set as the task to be executed in the next step.

[0014] Compared with the prior art, the present invention has the following advantages: By selecting scheduling strategies, setting thread attributes, creating and activating real-time tasks, and scheduling real-time tasks to jump the queue, higher reliability and stronger real-time performance can be achieved on Linux systems and real-time programs running on the system, effectively improving the processing capabilities of the system and programs. Attached Figure Description

[0015] Figure 1 This is an overall flowchart of a high real-time scheduling method based on kernel modification and program design in an embodiment of the present invention; Figure 2 This is a flowchart of spinlock mutual exclusion in an embodiment of the present invention; Figure 3 This is a flowchart illustrating the interruption of threading in an embodiment of the present invention. Detailed Implementation

[0016] To facilitate understanding by those skilled in the art, the present invention will be further described below with reference to embodiments and accompanying drawings. The content mentioned in the embodiments is not intended to limit the present invention.

[0017] like Figure 1 As shown, this embodiment provides a high real-time scheduling method based on kernel modification and program design, including the following steps: S1. Select the scheduling strategy; S2. Create a thread: Set the scheduling policy and priority in the thread properties; S3. Create a high-priority real-time task: Upload the set thread attributes to the Linux system kernel scheduler; S4. Activate real-time task: Schedule the task to the queue of tasks ready by the scheduler. S5. Determine whether the task policy priority can preempt the task policy on the current CPU. If not, proceed to step S6; if yes, proceed to step S7. S6. The task is migrated to another CPU core that can immediately execute the schedule; S7. Activate the task and find the next task to be executed. S8. Determine if there is a task being executed on the CPU. If yes, proceed to step S9; otherwise, proceed to step S10. S9. Schedule real-time tasks to jump the queue and clear currently executing tasks; S10, Context (task) switch, task execution.

[0018] This invention is applied to the data interaction computer and data interaction software running on the Kylin system installed in the aerospace telemetry and control system. The data interaction software needs to respond quickly to the high-frequency interrupt signals of the time code card installed on the data interaction computer. The time code card continuously provides an accurate 5-millisecond interrupt signal, and the error of the interrupt signal given by the time code card is required to be no more than 1 millisecond within 24 hours. Therefore, the real-time requirements of the Kylin system and the data interaction software are relatively high.

[0019] In step S2, the Linux system kernel scheduler is used to modify the operating system kernel. By modifying the configuration policy of the operating system kernel, real-time modifications are made to ensure that real-time tasks can be preemptively executed with priority while avoiding being preempted by other tasks. Modifications to the operating system kernel include spinlock mutexing and interrupt threading.

[0020] Spinlock mutexing: The spinlock in the kernel is redefined using RT Mutex that supports PI, making the spinlock preemptible; The RT Mutex supports a priority inheritance mechanism, which means that when a low-priority task holds a lock, if a high-priority real-time task attempts to acquire the lock, the system automatically and temporarily increases the priority of the low-priority task to reduce blocking time and thus improve the real-time performance of the high-priority task.

[0021] like Figure 2 As shown, the data interaction software initiates task A to attempt to acquire a timecode card interrupt signal. Task A is assigned high priority, but at this time, the Kylin system CPU thread is occupied by task B, a medium-priority task of software B. Task B executes a spinlock, preventing task preemption. Therefore, task A of the data interaction software can only wait. After adopting a spinlock mutual exclusion strategy, task B is allowed to be preempted, and task A of the data interaction software can be executed with priority. The data interaction software is executing task A while acquiring a timecode card interrupt signal. Task A is assigned high priority, but at this time, an external device interface connected to the data interaction computer via USB becomes loose, frequently disconnecting and reconnecting, generating a large number of hardware interrupt signals, i.e., task B, which has the highest priority, causing task A to be frequently paused. After adopting an interrupt threading strategy, task B only has medium priority, and task A can still execute normally.

[0022] Furthermore, interrupt threading involves placing the execution of the upper half of the interrupt into a kernel thread. Interrupt handling participates in CPU scheduling as a medium-priority real-time task, thus allowing interrupt handling to be preempted by higher-priority real-time tasks. The upper half of an interrupt refers to the CPU responding directly to the interrupt signal immediately after a hardware interrupt occurs. After the interrupt response, the scheduler will immediately suspend the current task and start interrupt handling. During interrupt handling, the CPU cannot sleep or preempt.

[0023] The scheduling policy can be selected from SCHED_FIFO, SCHED_RR and SCHED_DEADLINE; in SCHED_FIFO and SCHED_RR, high-priority tasks preempt low-priority tasks, and can also be preempted by SCHED_DEADLINE or higher-priority scheduled tasks. The SCHED_FIFO strategy follows the first-in-first-out principle for tasks of the same priority, and the first task to arrive will occupy the CPU indefinitely. The SCHED_RR strategy executes tasks of the same priority in turn, with each task having a CPU time slice. Tasks that have used up their time slices are reordered to the end of the queue. The SCHED_DEADLINE scheduling strategy does not require prioritization of task priority and directly ensures that more urgent tasks are scheduled first.

[0024] like Figure 3As shown, when designing the data interaction software, a scheduling policy is selected from SCHED_FIFO and SCHED_RR. Using the glibc library adopted by the Kylin system, the scheduling policy and priority are set in the thread attributes when creating a thread. Then, the data interaction software creates a high-priority real-time task A using the pthread_create function. This involves acquiring a timecode card interrupt signal and passing the set thread attributes to the Kylin system kernel scheduler. The scheduler then categorizes the task into the rt_sched_class scheduling class. Task A is placed in the scheduler's ready queue rt_rq. It is then determined whether task A can preempt the currently executing CPU task. If the current CPU core cannot be scheduled immediately, the real-time task is attempted to be migrated to another CPU core that can be scheduled immediately, and then task A is activated. Using the __schedule scheduling interface in the scheduler, after finding the next task to be executed, if a task is already being executed on the current CPU, the TIF_NEED_RESCHED flag of the currently executing task is first cleared. Then, the context switch is performed using the context_switch function to complete the task switching on the CPU, and finally, task A is executed.

[0025] When setting thread attributes in step S2, that is, when creating a program thread, a certain scheduling strategy and priority are set in the attributes of the program thread. When the thread is created, the Linux system kernel scheduler will classify it into the corresponding scheduling class. When real-time tasks are woken up and scheduled, the set scheduling strategy will be used. The corresponding scheduling classes include SCHED_FIFO and SCHED_RR, which belong to the rt_sched_class scheduling class, and SCHED_DEADLINE, which belongs to the dl_sched_class scheduling class. The scheduling class is a set of functions that are encapsulated and callable in the Linux kernel, which define different task scheduling behaviors and priority rules.

[0026] When creating a high-priority real-time task, the application creates and activates the real-time task by calling a system function. The creation of the real-time task transmits the scheduling policy and priority set in the thread attributes to the Linux system kernel scheduler, which then schedules the task according to the set scheduling policy.

[0027] When a real-time task is activated, it is scheduled to run on a CPU. If the current CPU core cannot be scheduled immediately, the real-time task is migrated to another CPU core that can be scheduled immediately.

[0028] In step S8, if a task is already being executed on the CPU, the TIF_NEED_RESCHED flag of the currently executing task will be cleared. Then, steps S9 and S10 will be performed, and the context switch will be completed by calling system functions to switch the task running on the CPU.

[0029] When the TIF_NEED_RESCHED flag is set, the task is considered a higher priority task and will be executed in the next step. The context switch means that the real-time task is set as the task to be executed next.

[0030] Compared with the prior art, the present invention has the following advantages: By selecting scheduling strategies, setting thread attributes, creating and activating real-time tasks, and scheduling real-time tasks to jump the queue, higher reliability and stronger real-time performance can be achieved on Linux systems and real-time programs running on the system, effectively improving the processing capabilities of the system and programs.

[0031] The above provides a detailed description of a high real-time scheduling method based on kernel modification and program design provided in this application. The specific embodiments are described only to aid in understanding the method and its core ideas. It should be noted that those skilled in the art can make various improvements and modifications to this application without departing from its principles, and these improvements and modifications also fall within the protection scope of the claims of this application.

Claims

1. A high real-time scheduling method based on kernel modification and program design, characterized in that, Including the following steps: S1. Select the scheduling strategy; S2. Create a thread: Set the scheduling policy and priority in the thread properties; S3. Create a high-priority real-time task: Upload the set thread attributes to the Linux system kernel scheduler; S4. Activate real-time task: Schedule the task to the queue of tasks ready by the scheduler. S5. Determine whether the task policy priority can preempt the task policy on the current CPU. If not, proceed to step S6; if yes, proceed to step S7. S6. The task is migrated to another CPU core that can immediately execute the schedule; S7. Activate the task and find the next task to be executed. S8. Determine if there is a task being executed on the CPU. If yes, proceed to step S9; otherwise, proceed to step S10. S9. Schedule real-time tasks to jump the queue and clear currently executing tasks; S10, Context switch, task execution.

2. The high real-time scheduling method based on kernel modification and program design according to claim 1, characterized in that, In step S2, the Linux system kernel scheduler is used to modify the operating system kernel. By modifying the configuration policy of the operating system kernel, real-time modifications are made to ensure that real-time tasks can be preemptively executed with priority while avoiding being preempted by other tasks. Modifications to the operating system kernel include spinlock mutexing and interrupt threading.

3. The high real-time scheduling method based on kernel modification and program design according to claim 2, characterized in that, Spinlock mutexing: The kernel redefined spinlocks using RT Mutex that supports PI, making spinlocks preemptible. The RT Mutex supports a priority inheritance mechanism. When a low-priority task holds a lock, if a high-priority real-time task attempts to acquire the lock, the system automatically and temporarily increases the priority of the low-priority task.

4. The high real-time scheduling method based on kernel modification and program design according to claim 3, characterized in that, Interrupt threading places the execution of the interrupt top half into a kernel thread, and interrupt handling participates in CPU scheduling as a medium-priority real-time task, so that interrupt handling can be preempted by higher-priority real-time tasks. The upper half of an interrupt refers to the CPU responding directly to the interrupt signal immediately after a hardware interrupt occurs. After the interrupt response, the scheduler will immediately suspend the current task and start interrupt handling. During interrupt handling, the CPU cannot sleep or preempt.

5. A high real-time scheduling method based on kernel modification and program design according to claim 4, characterized in that, The scheduling policy can be selected from SCHED_FIFO, SCHED_RR and SCHED_DEADLINE; in SCHED_FIFO and SCHED_RR, high-priority tasks preempt low-priority tasks, and can also be preempted by SCHED_DEADLINE or higher-priority scheduled tasks. The SCHED_FIFO strategy follows the first-in-first-out principle for tasks of the same priority, and the first task to arrive will occupy the CPU indefinitely. The SCHED_RR strategy executes tasks of the same priority in turn, with each task having a CPU time slice. Tasks that have used up their time slices are reordered to the end of the queue. The SCHED_DEADLINE scheduling policy does not require prioritization of task priority; it directly ensures that more urgent tasks are scheduled first.

6. The high real-time scheduling method based on kernel modification and program design according to claim 5, characterized in that, When setting thread attributes in step S2, a certain scheduling strategy and priority are set in the attributes of the program thread. When the thread is created, the Linux system kernel scheduler will classify it into the corresponding scheduling class. When real-time tasks are woken up and scheduled, the set scheduling strategy will be used. The corresponding scheduling classes include SCHED_FIFO and SCHED_RR, which belong to the rt_sched_class scheduling class, and SCHED_DEADLINE, which belongs to the dl_sched_class scheduling class. The scheduling class is a set of functions that are encapsulated and callable in the Linux kernel, which define different task scheduling behaviors and priority rules.

7. A high real-time scheduling method based on kernel modification and program design according to claim 6, characterized in that, When creating a high-priority real-time task, the application creates and activates the real-time task by calling a system function. The creation of the real-time task transmits the scheduling policy and priority set in the thread attributes to the Linux system kernel scheduler, which then schedules the task according to the set scheduling policy.

8. A high real-time scheduling method based on kernel modification and program design according to claim 7, characterized in that, When a real-time task is activated, it is scheduled to run on a CPU. If the current CPU core cannot be scheduled immediately, the real-time task is migrated to another CPU core that can be scheduled immediately.

9. A high real-time scheduling method based on kernel modification and program design according to claim 8, characterized in that, In step S8, if a task is already being executed on the CPU, the TIF_NEED_RESCHED flag of the currently executing task will be cleared. Then, steps S9 and S10 will be performed, and the context switch will be completed by calling system functions to switch the task running on the CPU.