[go: up one dir, main page]

CN121029364A - A method for IPI interrupt threading in embedded edge soft real-time systems - Google Patents

A method for IPI interrupt threading in embedded edge soft real-time systems

Info

Publication number
CN121029364A
CN121029364A CN202511543843.0A CN202511543843A CN121029364A CN 121029364 A CN121029364 A CN 121029364A CN 202511543843 A CN202511543843 A CN 202511543843A CN 121029364 A CN121029364 A CN 121029364A
Authority
CN
China
Prior art keywords
interrupt
ipi
kernel
thread
threading
Prior art date
Legal status (The legal status 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 status listed.)
Pending
Application number
CN202511543843.0A
Other languages
Chinese (zh)
Inventor
王新蕊
史杰
董雪梅
胡明珏
罗凯伦
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
China Ordnance Equipment Group Ordnance Equipment Research Institute
Original Assignee
China Ordnance Equipment Group Ordnance Equipment Research Institute
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 China Ordnance Equipment Group Ordnance Equipment Research Institute filed Critical China Ordnance Equipment Group Ordnance Equipment Research Institute
Priority to CN202511543843.0A priority Critical patent/CN121029364A/en
Publication of CN121029364A publication Critical patent/CN121029364A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; 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 OR CALCULATING; 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/52Program synchronisation; Mutual exclusion, e.g. by means of semaphores
    • G06F9/526Mutual exclusion algorithms

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Debugging And Monitoring (AREA)

Abstract

本发明提出一种嵌入式边缘软实时系统IPI中断线程化的方法,涉及Linux内核中断子系统技术领域,包括:设置IPI中断的线程化标志,调用中断注册接口函数;在中断注册接口函数中删除对IPI中断所属中断类型的判断限制,强制生成内核线程;当对IPI中断进行一级中断回调处理返回的处理结果是继续由线程处理时唤醒二级内核线程,由二级内核线程执行IPI中断注册的中断处理函数。在RT内核驱动中使用IPI中断时,本发明使得在中断处理函数和进程上下文中使用自旋锁保护共享资源的情况下,可以正常处理;本发明将在RT内核和非RT内核之间切换对驱动代码的影像降到最小,在RT内核中不用改动中断处理的代码及其互斥机制。

This invention proposes a method for threading IPI interrupts in embedded edge soft real-time systems, relating to the technical field of Linux kernel interrupt subsystems. The method includes: setting a threading flag for the IPI interrupt and calling an interrupt registration interface function; removing the restriction on the interrupt type of the IPI interrupt within the interrupt registration interface function, thus forcibly generating a kernel thread; and waking up a secondary kernel thread when the processing result of the first-level interrupt callback handling for the IPI interrupt is that it should continue to be handled by a thread, with the secondary kernel thread executing the interrupt handling function registered for the IPI interrupt. When using IPI interrupts in RT kernel drivers, this invention allows for normal processing even when spinlocks are used to protect shared resources in the interrupt handling function and process context. This invention minimizes the impact of switching between RT and non-RT kernels on the driver code, and does not require modification of the interrupt handling code and its mutual exclusion mechanism in the RT kernel.

Description

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.

Claims (6)

1.一种嵌入式边缘软实时系统IPI中断线程化的方法,其特征在于,所述方法包括:1. A method for IPI interrupt threading in an embedded edge soft real-time system, characterized in that the method includes: 步骤1,设置IPI中断的线程化标志,并调用中断注册接口函数;Step 1: Set the threading flag for the IPI interrupt and call the interrupt registration interface function; 步骤2,在中断注册接口函数中删除对IPI中断所属中断类型的判断限制,强制生成二级内核线程;Step 2: Remove the restriction on the interrupt type of the IPI interrupt in the interrupt registration interface function, and force the generation of a secondary kernel thread; 步骤3,当对IPI中断进行一级中断回调处理返回的处理结果是继续由线程处理时唤醒二级内核线程,由二级内核线程执行IPI中断注册的中断处理函数。Step 3: When the processing result of the first-level interrupt callback handling of the IPI interrupt is that it continues to be handled by the thread, the second-level kernel thread is awakened and the second-level kernel thread executes the interrupt handling function registered by the IPI interrupt. 2.如权利要求1所述的方法,其特征在于,步骤1中,IPI中断的线程化标志通过如下方式设置:在IPI中断注册的情况下,当驱动程序判断所定义的宏表示当前内核是RT内核时,对要线程化的IPI中断设置允许线程化的标志。2. The method as described in claim 1, wherein in step 1, the threading flag of the IPI interrupt is set in the following manner: when the IPI interrupt is registered, and the driver determines that the defined macro indicates that the current kernel is an RT kernel, the threading flag of the IPI interrupt to be threaded is set. 3.如权利要求2所述的方法,其特征在于,所设置的允许线程化的标志不改变IPI中断所属中断类型的属性。3. The method as described in claim 2, wherein the set thread-enabled flag does not change the attribute of the interrupt type to which the IPI interrupt belongs. 4.如权利要求1-3任一项所述的方法,其特征在于,所调用的中断注册接口函数为在RT内核中通用中断注册的接口函数。4. The method according to any one of claims 1-3, wherein the interrupt registration interface function called is a general interrupt registration interface function in the RT kernel. 5.如权利要求1所述的方法,其特征在于,步骤2还包括:把IPI中断注册的中断处理函数保存到中断结构体对应的字段中。5. The method as described in claim 1, wherein step 2 further includes: saving the interrupt handling function registered by the IPI interrupt into the field corresponding to the interrupt structure. 6.如权利要求5所述的方法,其特征在于,步骤3具体为:内核增加对中断结构体中是否存在二级内核线程的函数指针的判断,当一级中断回调处理返回需要继续调用二级内核线程的标志并且中断结构体中存在二级内核线程的函数指针时唤醒IPI中断的二级内核线程,IPI中断注册的中断处理函数在二级内核线程中执行,自旋锁在中断上下文和进程上下文中进行调度切换。6. The method as described in claim 5, wherein step 3 specifically comprises: the kernel adding a judgment on whether there is a function pointer of a secondary kernel thread in the interrupt structure; when the primary interrupt callback process returns a flag indicating that the secondary kernel thread needs to be called again and there is a function pointer of a secondary kernel thread in the interrupt structure, the secondary kernel thread of the IPI interrupt is awakened; the interrupt handling function registered by the IPI interrupt is executed in the secondary kernel thread; and the spinlock is scheduled and switched between the interrupt context and the process context.
CN202511543843.0A 2025-10-28 2025-10-28 A method for IPI interrupt threading in embedded edge soft real-time systems Pending CN121029364A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202511543843.0A CN121029364A (en) 2025-10-28 2025-10-28 A method for IPI interrupt threading in embedded edge soft real-time systems

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202511543843.0A CN121029364A (en) 2025-10-28 2025-10-28 A method for IPI interrupt threading in embedded edge soft real-time systems

Publications (1)

Publication Number Publication Date
CN121029364A true CN121029364A (en) 2025-11-28

Family

ID=97770713

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202511543843.0A Pending CN121029364A (en) 2025-10-28 2025-10-28 A method for IPI interrupt threading in embedded edge soft real-time systems

Country Status (1)

Country Link
CN (1) CN121029364A (en)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8327187B1 (en) * 2009-09-21 2012-12-04 Tilera Corporation Low-overhead operating systems
CN105718309A (en) * 2014-09-16 2016-06-29 财团法人工业技术研究院 Method and system for interrupt processing in virtual environment
US20160335136A1 (en) * 2015-05-12 2016-11-17 International Business Machines Corporation TASKS_RCU Detection Of Tickless User Mode Execution As A Quiescent State
WO2024065829A1 (en) * 2022-09-30 2024-04-04 Intel Corporation User interrupt moderation for user inter-processor-interrupts
CN120353568A (en) * 2024-02-18 2025-07-22 谢文韬 Computing resource allocation method, system, equipment and medium for multi-core system

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8327187B1 (en) * 2009-09-21 2012-12-04 Tilera Corporation Low-overhead operating systems
CN105718309A (en) * 2014-09-16 2016-06-29 财团法人工业技术研究院 Method and system for interrupt processing in virtual environment
US20160335136A1 (en) * 2015-05-12 2016-11-17 International Business Machines Corporation TASKS_RCU Detection Of Tickless User Mode Execution As A Quiescent State
WO2024065829A1 (en) * 2022-09-30 2024-04-04 Intel Corporation User interrupt moderation for user inter-processor-interrupts
CN120353568A (en) * 2024-02-18 2025-07-22 谢文韬 Computing resource allocation method, system, equipment and medium for multi-core system

Similar Documents

Publication Publication Date Title
CA2213371C (en) Process executing method and resource accessing method in computer system
CN109918141B (en) Thread execution method, device, terminal and storage medium
EP1682981B1 (en) System for invoking a privileged function in a device
US5893157A (en) Blocking symbol control in a computer system to serialize accessing a data resource by simultaneous processor requests
EP0351401A1 (en) Multiprocessing method and arrangement
US7076637B2 (en) System for providing transitions between operating modes of a device
US20030233485A1 (en) Event queue
CN113010275B (en) Interrupt processing method and device
Craig Formal refinement for operating system kernels
CN115269139A (en) Dual-operating-system mixed real-time task scheduling method and system based on trusted area
CN111984428A (en) A method, device and device for implementing spin lock during resource access
US7552434B2 (en) Method of performing kernel task upon initial execution of process at user level
CN117850995A (en) Coroutine scheduling method, coroutine scheduling device and storage medium
CN121029364A (en) A method for IPI interrupt threading in embedded edge soft real-time systems
CN113821790B (en) Implementation method of industrial trusted computing dual-system architecture based on Trustzone
EP2256627A2 (en) Queuing for locks on data
TWI676935B (en) Circuitry system for processing interrupt priority
JP7587911B2 (en) Information processing device and information processing method
Kim et al. Perfecting preemption threshold scheduling for object-oriented real-time system design: From the perspective of real-time synchronization
CN114327828B (en) Lock-free concurrent access method, device, equipment and medium for shared data
CN112559054B (en) Method and computing system for synchronizing instructions
Mejia-Alvarez et al. Interrupt handling architectures
US20250328646A1 (en) Techniques for validating safety agreement compliance using sboms
JPH10247161A (en) Memory management system
US7788529B2 (en) Method for safely interrupting blocked work in a server

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination