A method for embedded edge soft real-time system ipi interrupt threading

By setting the threading flag for IPI interrupts and generating secondary kernel threads in the Linux kernel, the data inconsistency problem caused by the lack of threading of IPI interrupts is solved, and the stability and compatibility of using IPI interrupts in the RT kernel are achieved.

CN121029364BActive Publication Date: 2026-02-17WEAPON EQUIP RES INST OF CHINA NAT WEAPON EQUIP GRP
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202511543843.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-10-28
Publication Date
2026-02-17
Estimated Expiration
2045-10-28

AI Technical Summary

Technical Problem

In the Linux kernel after the PREEMPT_RT patch, the IPI interrupt handler function was not threaded, which caused data inconsistency issues when using spinlocks to protect shared resources in interrupt handling and process context, leading to system instability.

Method used

By setting the threading flag for IPI interrupts, calling the general interrupt registration interface function, removing the per-CPU type judgment restriction, generating a secondary kernel thread, and waking up the secondary kernel thread to execute the interrupt handling function when the primary interrupt callback returns, the threading of IPI interrupts is realized.

Benefits of technology

In RT kernel drivers, using IPI interrupts avoids direct scheduling and switching out of interrupt handlers, ensuring that spinlocks can be used normally in process context, maintaining system stability, and reducing code changes between RT and non-RT kernels.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121029364B_ABST
    Figure CN121029364B_ABST
Patent Text Reader

Abstract

The application provides a method for IPI interrupt thread in embedded edge soft real-time system, relates to the technical field of Linux kernel interrupt subsystem, and comprises the following steps: setting a thread flag of the IPI interrupt, and calling an interrupt registration interface function; removing the judgment limitation of the interrupt type to which the IPI interrupt belongs in the interrupt registration interface function, and forcibly generating a kernel thread; when the processing result returned by the first-level interrupt callback processing of the IPI interrupt is to continue processing by the thread, awakening the second-level kernel thread, and executing the interrupt processing function registered by the IPI interrupt by the second-level kernel thread. When the IPI interrupt is used in the RT kernel driver, the application can be normally processed in the case that the spin lock is used to protect the shared resource in the interrupt processing function and the process context; and the application minimizes the influence of the switching between the RT kernel and the non-RT kernel on the driver code, and the interrupt processing code and the mutual exclusion mechanism thereof do not need to be changed in the RT kernel.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of Linux kernel interrupt subsystem, and particularly relates to a method for IPI interrupt threading of an embedded edge soft real-time system. BACKGROUND

[0002] After the Linux edge kernel is patched with PREEMPT_RT, the Linux edge kernel becomes a soft real-time kernel, at this time, most of the interrupt registration interrupt processing functions are automatically changed into threaded functions, but the RT patch does not thread the IPI (Inter-Processor Interrupt) interrupt processing function, because most of the IPI interrupts are used by the kernel, and the interrupt must be processed immediately after the interrupt occurs, and cannot be delayed, so the IPI interrupt cannot be threaded.

[0003] As shown in Figure 1 , when the kernel driver performs certain services, the IPI interrupt that is not used by the kernel may be used, for example, in a mixed deployment service, the IPI interrupt is used to notify the peer core that data needs to be received. In the driver, the interrupt context and the process context access the shared resources by mutual exclusion through the spin lock spin_lock_irqsave.

[0004] The RT kernel rewrites the spin lock spin_lock_irqsave, the interface does not close the interrupt, and the IPI interrupt cannot be threaded, if the process context gets the lock first, when the interrupt occurs, the interrupt processing function is locked to the real-time spin, and the scheduling is cut out, in this case, the normal process of context switching is damaged, the kernel appears inconsistent data, and the system is unstable. SUMMARY

[0005] Therefore, the present application provides a method for IPI interrupt threading of an embedded edge soft real-time system, the method comprises:

[0006] Step 1, setting the threading flag of the IPI interrupt, and calling the interrupt registration interface function;

[0007] Step 2, deleting the judgment limit of the interrupt type to which the IPI interrupt belongs in the interrupt registration interface function, and forcibly generating a secondary kernel thread;

[0008] Step 3, when the processing result returned by the primary interrupt callback processing of the IPI interrupt is to continue processing by the thread, the secondary kernel thread is woken up, and the interrupt processing function registered by the IPI interrupt is executed by the secondary kernel thread.

[0009] Further, in step 1, the threadable flag of the IPI interrupt is set by the following way: in the case of IPI interrupt registration, when the driver judges that the defined macro indicates that the current kernel is an RT kernel, the threadable flag of the IPI interrupt to be threaded is set.

[0010] Further, the set threadable flag does not change the attribute of the interrupt type to which the IPI interrupt belongs.

[0011] Further, the called interrupt registration interface function is the interface function of general interrupt registration in the RT kernel.

[0012] Further, step 2 further comprises: saving the interrupt processing function of the registered IPI interrupt into the field corresponding to the interrupt structure.

[0013] Further, step 3 is specifically: the kernel adds the judgment of whether the secondary kernel thread function pointer exists in the interrupt structure, when the primary interrupt callback processing returns the flag of needing to continue to call the secondary kernel thread and the secondary kernel thread function pointer exists in the interrupt structure, the secondary kernel thread of the IPI interrupt is woken up, the interrupt processing function of the registered IPI interrupt is executed in the secondary kernel thread, and the spin lock is scheduled to switch between the interrupt context and the process context.

[0014] The technical scheme of the present application has the following beneficial technical effects:

[0015] 1. In the RT kernel driver, when the interrupt using IPI is used, the case of using the spin lock to protect the shared resource in the interrupt processing function and the process context can be normally processed without problems.

[0016] 2. The influence of the switching between the RT kernel and the non-RT kernel on the driver code is minimized, so that in the RT kernel, the interrupt processing code and the mutual exclusion mechanism do not need to be changed. BRIEF DESCRIPTION OF DRAWINGS

[0017] In order to more clearly illustrate the technical scheme in the specific embodiments of the present application, the following will briefly introduce the drawings needed to be used in the specific embodiments. Obviously, the drawings in the following description are some embodiments of the present application, and other drawings can also be obtained by those skilled in the art without creative labor.

[0018] Figure 1 It is an IPI interrupt processing flowchart in the RT Linux kernel of the prior art;

[0019] Figure 2 It is an IPI interrupt processing flowchart after threading in the RT Linux kernel of the present application;

[0020] Figure 3 A flow chart of the process of IPI interrupt registration in the RT Linux kernel of the present application;

[0021] Figure 4 A flow chart of the process inside the IPI interrupt registration function in the RT Linux kernel of the present application;

[0022] Figure 5 A flow chart of the process when the IPI interrupt occurs in the RT Linux kernel of the present application. DETAILED DESCRIPTION

[0023] In order to make the objects, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be described clearly and completely below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only some of the embodiments of the present application, but not all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work fall within the protection scope of the present application.

[0024] In some cases, a specific IPI interrupt needs to be threaded, so that if the process context obtains the lock first, then the IPI interrupt comes, the threaded kernel thread will be woken up, so that the switching between the two thread contexts will not be a problem.

[0025] As shown in Figure 2 the method for IPI interrupt threading in the soft real-time Linux kernel of the present application includes:

[0026] 1. Setting the threading flag of the IPI, and calling the registration interface function of the general interrupt.

[0027] 2. The IPI interrupt belongs to the per-cpu (each cpu has an independent) type of interrupt, so in the interrupt registration interface function, the per-cpu type judgment limit needs to be removed, so that the subsequent interrupt threading process can continue.

[0028] 3. After the IPI interrupt occurs, when the interrupt of the IPI is processed, if the first-level processing returns to continue to be processed by the thread, the second-level thread is woken up, and thereafter the processing function of the IPI interrupt will be executed in the second-level thread.

[0029] Each step will be described in detail below.

[0030] As shown in Figure 3As shown in the figure, when the IPI interrupt is registered, a judgment is added in the driver, if the CONFIG_PREEMPT_RT macro is defined, indicating that the current kernel is an RT kernel, then the flag that can be threaded needs to be set for the IPI interrupt to be threaded, the flag does not change the percpu type physical property of the IPI interrupt, only affects the software processing process;

[0031] In the RT kernel, the IPI interrupt registration calls the interface of the normal interrupt registration.

[0032] As shown in the figure, the judgment limitation of the IPI percpu type in the interrupt registration function is removed, so that the subsequent process can continue. Figure 4

[0033] In the subsequent process, because the interrupt can be threaded has been set in the front, so the forced threading process is taken, the kernel thread is generated, and the IPI registered interrupt processing function is saved to the field corresponding to the interrupt structure.

[0034] As shown in the figure, a judgment is added in the kernel function for processing the IPI domain, if the first interrupt callback processing returns the flag that needs to continue to call the second thread, and the second thread function pointer exists in the interrupt structure, then the second kernel thread of the interrupt is woken up, and the processing function of the interrupt registration will be executed in the kernel thread, so that the spin lock can be scheduled and switched in the two process contexts. Figure 5

[0035] As can be known from the above introduction, the IPI interrupt that cannot be threaded in the RT kernel is threaded, so that when some additional IPI interrupts are used (non-system use), in the case that the spin lock is obtained in the process context first, after the interrupt occurs, the interrupt context will not be directly scheduled out of the interrupt, but the interrupt processing function is postponed to be processed in the second kernel thread of the interrupt.

[0036] Please note that the technical features of the above embodiments can be combined in any way, in order to make the description simple, not all possible combinations of the technical features in the above embodiments are described, however, as long as the combination of the technical features does not exist contradictory, it should be considered that it is within the scope of the description. The above embodiments only express several implementation ways of the present application, the description is more specific and detailed, but it should not be understood as the limitation of the patent scope. It should be noted that for those skilled in the art, without departing from the concept of the present application, some modifications and improvements can be made, which are within the scope of the present application. Therefore, the patent protection scope of the present application should be subject to the appended claims.​​

Claims

1. A method of embedded edge soft real-time system IPI interrupt threading, comprising: The method comprises: Step 1, setting a thread flag of the IPI interrupt, and calling an interrupt registration interface function; Step 2, removing a judgment limit of an interrupt type to which the IPI interrupt belongs in the interrupt registration interface function, and forcibly generating a secondary kernel thread; Step 3, when a processing result returned by a primary interrupt callback processing of the IPI interrupt is that the IPI interrupt is to be processed by a thread, waking up the secondary kernel thread, and executing an interrupt processing function registered by the IPI interrupt by the secondary kernel thread; In step 1, the thread flag of the IPI interrupt is set by the following way: in the case of registering the IPI interrupt, when a driver judges that a defined macro represents that a current kernel is an RT kernel, setting a thread-allowed flag of the IPI interrupt to be threaded; Step 3 specifically comprises: the kernel adds a judgment of whether a function pointer of the secondary kernel thread exists in an interrupt structure body, when a flag returned by the primary interrupt callback processing needs to continue to call the secondary kernel thread and the function pointer of the secondary kernel thread exists in the interrupt structure body, waking up the secondary kernel thread of the IPI interrupt, executing the interrupt processing function registered by the IPI interrupt in the secondary kernel thread, and scheduling switching of a spin lock in an interrupt context and a process context.

2. The method of claim 1, wherein, The set thread-allowed flag does not change an attribute of the interrupt type to which the IPI interrupt belongs.

3. The method of claim 1 or 2, wherein, The called interrupt registration interface function is an interface function of general interrupt registration in the RT kernel.

4. The method of claim 1, wherein, Step 2 further comprises: saving the interrupt processing function registered by the IPI interrupt to a field corresponding to the interrupt structure body.

Citation Information

Patent Citations

  • Method and system for handling interrupts in a virtualized environment

    CN105718309A

  • Computing resource allocation method, system and equipment for multi-core system and medium

    CN120353568A