IPI interrupt threading method for embedded edge soft real-time system
Technical Field
The invention relates to the technical field of Linux kernel interrupt subsystems, in particular to a method for threading IPI interrupt of an embedded edge soft real-time system.
Background
The Linux edge kernel becomes a soft real-time kernel after being patched with preempt_rt, at this time, most interrupt processing functions registered by interrupts automatically become threaded, but RT patches do not thread IPI (Inter-Processor Interrupt processor) interrupt processing functions, and most IPI interrupts are used by the kernel, and the interrupts are immediately processed and cannot be delayed after occurrence, so that the threads are not threaded.
As shown in fig. 1, when some services are performed by the kernel driver, an IPI interrupt that is not used by the kernel may be used, for example, in a hybrid deployment service, and the opposite end kernel is notified that there is data to be received by using the IPI interrupt. In the drive, the interrupt context and the process context access the shared resource mutually exclusively through spin lock spin irqsave.
The RT kernel rewrites spin lock_lock_ irqsave, the interface cannot close the interrupt, the IPI interrupt cannot be threaded, if the process context is locked first, after the interrupt occurs, the interrupt processing function locks the real-time spin, scheduling and cutting out can be carried out, in this case, the normal flow of the context switching can be destroyed, the kernel has data inconsistency, and the system is unstable.
Disclosure of Invention
In view of this, the present invention provides a method for threading IPI interrupts of an embedded edge soft real-time system, the method comprising:
Step 1, setting a threading mark of IPI interrupt and calling an interrupt registration interface function;
Step 2, deleting judgment limit on the interrupt type to which the IPI interrupt belongs in the interrupt registration interface function, and forcedly generating a secondary kernel thread;
and step 3, when the processing result returned by the primary interrupt callback processing on the IPI interrupt is that the thread is continuously processed, waking up the secondary kernel thread, and executing the interrupt processing function registered by the IPI interrupt by the secondary kernel thread.
Further, in step 1, the threading flag of the IPI interrupt is set by setting a flag allowing threading for the IPI interrupt to be threaded when the driver determines that the defined macro indicates that the current core is an RT core in the event of IPI interrupt registration.
Further, the set flag allowing threading does not change the attribute of the interrupt type to which the IPI interrupt belongs.
Further, the called interrupt registration interface function is an interface function that is commonly used interrupt registration in the RT kernel.
Further, step2 further includes saving the IPI interrupt registered interrupt handling function to a field corresponding to the interrupt fabric.
Further, in the step 3, the kernel increases the judgment of whether a function pointer of the secondary kernel thread exists in the interrupt structure body, when the primary interrupt callback processing returns a mark for calling the secondary kernel thread continuously and the function pointer of the secondary kernel thread exists in the interrupt structure body, the secondary kernel thread of the IPI interrupt is awakened, an interrupt processing function registered by the IPI interrupt is executed in the secondary kernel thread, and the spin lock performs scheduling switching in an interrupt context and a process context.
The technical scheme of the invention has the following beneficial technical effects:
1. in the RT kernel driver, when the IPI is used for interrupting, the shared resource can be normally processed under the condition of using the spin lock to protect the shared resource in the interrupt processing function and the process context, and no problem occurs.
2. The image of the drive code is switched between the RT core and the non-RT core to be minimized, so that the code of interrupt processing and the mutual exclusion mechanism thereof are not changed in the RT core.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings that are needed in the description of the embodiments will be briefly described below, and it is obvious that the drawings in the following description are some embodiments of the present invention, and other drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
FIG. 1 is a schematic diagram of an IPI interrupt handling flow in a RT Linux kernel of the prior art;
FIG. 2 is a schematic diagram of an interrupt processing flow after IPI interrupt threading in the RT Linux kernel of the present invention;
FIG. 3 is a block diagram of the process flow of IPI interrupt registration in an RT Linux kernel of the present invention;
FIG. 4 is a block diagram illustrating the internal processing flow of the IPI interrupt registration function in the RT Linux kernel of the present invention;
FIG. 5 is a block diagram of the processing flow when an IPI interrupt occurs in the RT Linux kernel of the present invention.
Detailed Description
For the purpose of making the objects, technical solutions and advantages of the embodiments of the present invention more apparent, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention, and it is apparent that the described embodiments are only some embodiments of the present invention, not all embodiments of the present invention. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
In some cases, it is desirable to thread a specific IPI interrupt, so that if the process context Wen Xian gets a lock, then after the IPI interrupt arrives, the kernel thread of the process will be awakened, and thus, switching between the two thread contexts will not be problematic.
As shown in FIG. 2, in the soft real-time Linux kernel of the invention, the IPI interrupt threading method comprises the following steps:
1. The threaded flag of the IPI is set and the registration interface function of the universal interrupt is invoked.
The ipi interrupt belongs to an interrupt of each cpu (each cpu has an independent type), so that in the interrupt registration interface function, judgment limit on each cpu type needs to be removed, so that the flow of subsequent interrupt threading can be continued.
When the IPI interrupt is processed after the IPI interrupt occurs, if the primary processing returns to continue to be processed by the thread, the secondary thread is awakened, and then a processing function of the IPI interrupt is executed in the secondary thread.
Each step is described in detail below.
As shown in fig. 3, during IPI interrupt registration, a judgment is added in a driver, if a config_preempt_rt macro is defined, which indicates that the current kernel is an RT kernel, a flag capable of threading needs to be set for an IPI interrupt to be threaded, and the flag does not change the physical attribute of each cpu type of the IPI interrupt, and only affects the processing procedure of software;
In the RT kernel, IPI interrupt registration invokes the interface of normal interrupt registration.
As shown in fig. 4, the judgment limit on the IPI per cpu type is removed from the interrupt registration function, so that the subsequent flow can continue.
In the subsequent flow, because the interrupt can be threaded before, the forced threading flow is carried out, a kernel thread is generated, and the interrupt processing function registered by the IPI is stored in a field corresponding to the interrupt structure body.
As shown in FIG. 5, the kernel adds a judgment to the function of IPI domain processing, if the primary interrupt callback processing returns a mark for calling the secondary thread continuously, and judges that a function pointer of the secondary thread exists in the interrupt structure, the secondary kernel thread of the interrupt is awakened, and the processing function of interrupt registration is executed in the kernel thread, so that the dispatching switching can be performed in two process contexts by using the spin lock.
As can be seen from the above description, the present invention threads IPI interrupts that the RT core cannot thread, so that when some additional IPI interrupts are used (not used by the system), in the case where the process context first gets spin-locked, after the interrupt occurs, the interrupt context will not be directly scheduled out from the interrupt, but rather the interrupt handling function will be deferred to the secondary core thread of the interrupt for processing.
Note that the technical features of the above embodiments may be arbitrarily combined, and all possible combinations of the technical features in the above embodiments are not described for brevity of description, however, as long as there is no contradiction between the combinations of the technical features, they should be regarded as the scope of the description. The foregoing examples illustrate only a few embodiments of the application, which are described in detail and are not to be construed as limiting the scope of the application. It should be noted that it will be apparent to those skilled in the art that several variations and modifications can be made without departing from the spirit of the application, which are all within the scope of the application. Accordingly, the scope of protection of the present application is to be determined by the appended claims.