技术领域technical field
本发明涉及计算机领域,特别是涉及一种信号量等待接口定时方法及装置。The invention relates to the field of computers, in particular to a timing method and device for a semaphore waiting interface.
背景技术Background technique
实时操作系统提供的信号量等待(pend)接口是实现多任务同步执行的重要策略。在现有技术中,一般该接口有一个时间参数,该时间参数说明了该接口等待信号量的时间长度,即,如果在时间参数设置的时间长度内信号量都没有到来,该接口将返回一个等待信号量超时的返回值,其中,判断是否等待信号量超时的行为需要依赖操作系统本身的时钟管理系统。The semaphore wait (pend) interface provided by the real-time operating system is an important strategy to realize the synchronous execution of multiple tasks. In the prior art, generally the interface has a time parameter, which indicates the length of time the interface waits for the semaphore, that is, if the semaphore does not arrive within the time length set by the time parameter, the interface will return a The return value of waiting for the semaphore to time out, wherein the behavior of judging whether to wait for the semaphore to time out needs to rely on the clock management system of the operating system itself.
目前的嵌入式操作系统都采用固定时间片的方法来维护操作系统本身的时钟,利用中央处理器(Central ProcessingUnit,简称为CPU)上的硬件定时器周期产生一个中断,在中断服务程序内更新系统时间,并判断信号量是否等待超时。从操作系统时钟管理机制来看,用于维护操作系统时钟的硬件定时器中断周期,决定了系统定时的精度。出于对整个CPU系统性能的考虑,如果操作系统时钟的精度太高,势必需要缩短硬件定时器的中断周期,频繁响应中断对系统性能会带来很大的影响,因此,嵌入式实时操作系统的时钟精度不能很高。The current embedded operating system uses a fixed time slice method to maintain the clock of the operating system itself, and uses the hardware timer cycle on the central processing unit (Central Processing Unit, referred to as CPU) to generate an interrupt, and update the system in the interrupt service routine. Time, and determine whether the semaphore waits for a timeout. From the perspective of the operating system clock management mechanism, the interrupt period of the hardware timer used to maintain the operating system clock determines the accuracy of the system timing. For the consideration of the performance of the entire CPU system, if the precision of the operating system clock is too high, it is necessary to shorten the interrupt period of the hardware timer, and frequent response to interrupts will have a great impact on system performance. Therefore, embedded real-time operating systems The clock precision cannot be very high.
图1是现有技术中多任务处理使用信号量等待接口的处理流程图,如图1所示,包括如下处理:Fig. 1 is the processing flowchart of multitasking processing using semaphore waiting interface in the prior art, as shown in Fig. 1, including following processing:
步骤1,任务开始TaskEntry();Step 1, the task starts TaskEntry();
步骤2,将调用的信号量等待接口Pend(Mbx TimerOut)的时间参数设置为定时器超时时间,其中,Mbx表示该任务需要等待的信号量,TimerOut表示定时器超时时间;Step 2, set the time parameter of the called semaphore waiting interface Pend (Mbx TimerOut) as the timer timeout period, where Mbx indicates the semaphore that the task needs to wait for, and TimerOut indicates the timer timeout period;
步骤3,判断获取的信号量Mbx是否超时,如果判断为是,执行步骤4,否则,执行步骤5;Step 3, judging whether the acquired semaphore Mbx has timed out, if it is judged to be yes, execute step 4, otherwise, execute step 5;
步骤4,根据获取的信号量Mbx进行业务处理;Step 4, perform business processing according to the acquired semaphore Mbx;
步骤5,结束操作,并执行步骤2。Step 5, end the operation and go to step 2.
由于操作系统时钟本身精度的限制,操作系统提供的信号量等待接口的时间参数的精度不能很高。在有些对时序要求非常高的场合,例如,长期演进(Long TermEvolution,简称为LTE)通信系统基站侧基带的处理,协议任务运行的周期为1ms,那么用于该任务的等待信号量接口时间参数精度至少达到us级,在信号量没有及时到来的情况下退出本子帧的处理,不至于影响下个子帧的处理,而操作系统的时钟精度是无法满足该要求的。Due to the limitation of the accuracy of the operating system clock itself, the accuracy of the time parameter of the semaphore waiting interface provided by the operating system cannot be very high. In some occasions that have very high timing requirements, for example, in the baseband processing of the base station side of the Long Term Evolution (LTE) communication system, the cycle of the protocol task running is 1ms, then the waiting semaphore interface time parameter for this task is The accuracy should be at least us level. If the semaphore does not arrive in time, the processing of this subframe will not be affected, and the processing of the next subframe will not be affected. However, the clock accuracy of the operating system cannot meet this requirement.
发明内容Contents of the invention
本发明提供一种信号量等待接口定时方法及装置,以解决现有技术中由于操作系统时钟本身精度的限制而导致信号量等待接口定时精度低的问题。The invention provides a timing method and device for a semaphore waiting interface to solve the problem in the prior art that the timing accuracy of the semaphore waiting interface is low due to the limitation of the accuracy of the operating system clock itself.
本发明提供一种信号量等待接口定时方法,包括:The present invention provides a semaphore waiting interface timing method, comprising:
步骤1,在预定任务调用信号量等待接口时,使能硬件定时器,对硬件定时器的定时时间、以及信号量等待接口的参数进行设置;Step 1, when the scheduled task calls the semaphore waiting interface, enable the hardware timer, and set the timing time of the hardware timer and the parameters of the semaphore waiting interface;
步骤2,通过信号量等待接口获取信号量,根据信号量的值判断信号量是在定时时间到时之前获取的正常信号量还是在硬件定时器中断之后获取的中断信号量;Step 2, obtain the semaphore through the semaphore waiting interface, and judge whether the semaphore is a normal semaphore obtained before the timer expires or an interrupt semaphore obtained after the hardware timer is interrupted according to the value of the semaphore;
步骤3,在判断获取的信号量为正常信号量的情况下,关闭硬件定时器,根据正常信号量进行任务处理,并执行步骤1,在判断获取的信号量为中断信号量的情况下,直接执行步骤1。Step 3, in the case of judging that the obtained semaphore is a normal semaphore, close the hardware timer, perform task processing according to the normal semaphore, and perform step 1, and in the case of judging that the obtained semaphore is an interrupt semaphore, directly Go to step 1.
本发明还提供了一种信号量等待接口定时装置,包括:The present invention also provides a semaphore waiting interface timing device, comprising:
接口调用模块,用于调用信号量等待接口;The interface calling module is used to call the semaphore waiting interface;
使能模块,用于在接口调用模块调用信号量等待接口时,使能硬件定时器,对硬件定时器的定时时间、以及信号量等待接口的参数进行设置;The enabling module is used to enable the hardware timer when the interface calling module calls the semaphore waiting interface, and set the timing time of the hardware timer and the parameters of the semaphore waiting interface;
信号量判断模块,用于通过信号量等待接口获取信号量,根据信号量的值判断信号量是在定时时间到时之前获取的正常信号量还是在硬件定时器中断之后获取的中断信号量;The semaphore judging module is used to obtain the semaphore through the semaphore waiting interface, and judge whether the semaphore is a normal semaphore obtained before the timing time expires or an interrupt semaphore obtained after the hardware timer is interrupted according to the value of the semaphore;
处理模块,用于在信号量判断模块判断获取的信号量为正常信号量的情况下,关闭硬件定时器,根据正常信号量进行任务处理,并调用接口调用模块,在信号量判断模块判断获取的信号量为中断信号量的情况下,直接调用接口调用模块。The processing module is used to close the hardware timer when the semaphore judging module judges that the obtained semaphore is a normal semaphore, perform task processing according to the normal semaphore, and call the interface calling module, and judge the obtained semaphore by the semaphore judging module When the semaphore is an interrupt semaphore, directly call the interface calling module.
本发明有益效果如下:The beneficial effects of the present invention are as follows:
通过将操作系统提供的信号量等待接口和CPU的硬件定时器资源配合使用,解决了现有技术中由于操作系统时钟本身精度的限制而导致信号量等待接口定时精度低的问题,提高了信号量等待接口定时的精确度,在不增加系统额外负担的情况下,满足了一些对时序要求非常严格的应用场合。By using the semaphore waiting interface provided by the operating system in conjunction with the hardware timer resources of the CPU, the problem of low timing accuracy of the semaphore waiting interface in the prior art due to the limitation of the precision of the operating system clock itself is solved, and the semaphore is improved. The timing accuracy of the wait interface satisfies some applications that have very strict timing requirements without increasing the system's additional burden.
附图说明Description of drawings
图1是现有技术中多任务处理在使用信号量等待接口时的处理流程图;Fig. 1 is the processing flowchart of multitasking processing in the prior art when using semaphore to wait for an interface;
图2是本发明实施例的信号量等待接口定时方法的流程图;Fig. 2 is the flowchart of the semaphore waiting interface timing method of the embodiment of the present invention;
图3是本发明实施例的信号量等待接口定时方法的详细处理的流程图;Fig. 3 is the flow chart of the detailed processing of the semaphore waiting interface timing method of the embodiment of the present invention;
图4是本发明实施例的硬件定时器中断服务程序处理流程图;Fig. 4 is the processing flowchart of the hardware timer interrupt service routine of the embodiment of the present invention;
图5是本发明实施例的信号量队列的示意图;Fig. 5 is the schematic diagram of the semaphore queue of the embodiment of the present invention;
图6是本发明实施例的信号量等待接口定时装置的结构示意图。FIG. 6 is a schematic structural diagram of a timing device for a semaphore waiting interface according to an embodiment of the present invention.
具体实施方式detailed description
为了解决现有技术中由于操作系统时钟本身精度的限制而导致信号量等待接口定时精度低的问题,在不影响系统整体性能的前提下,本发明提供了一种信号量等待接口定时方法及装置,尤其适用于类似LTE系统等对时序要求非常高的应用场合。以下结合附图以及实施例,对本发明进行进一步详细说明。应当理解,此处所描述的具体实施例仅仅用以解释本发明,并不限定本发明。In order to solve the problem of low timing accuracy of the semaphore waiting interface in the prior art due to the limitation of the precision of the operating system clock itself, without affecting the overall performance of the system, the present invention provides a timing method and device for the semaphore waiting interface , especially suitable for applications with very high timing requirements such as LTE systems. The present invention will be described in further detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described here are only used to explain the present invention, not to limit the present invention.
方法实施例method embodiment
根据本发明的实施例,提供了一种信号量等待接口定时方法,图2是本发明实施例的信号量等待接口定时方法的流程图,如图2所示,根据本发明实施例的信号量等待接口定时方法包括如下处理:According to an embodiment of the present invention, a semaphore waiting interface timing method is provided. FIG. 2 is a flow chart of the semaphore waiting interface timing method according to an embodiment of the present invention. As shown in FIG. 2 , the semaphore according to an embodiment of the present invention The waiting interface timing method includes the following processing:
步骤201,在预定任务调用信号量等待接口时,使能硬件定时器,对硬件定时器的定时时间、以及信号量等待接口的参数进行设置;其中,信号量等待接口的参数包括:信号量等待接口的时间参数、以及信号量等待接口的信号量参数。Step 201, when the predetermined task calls the semaphore waiting interface, enable the hardware timer, set the timing time of the hardware timer and the parameters of the semaphore waiting interface; wherein, the parameters of the semaphore waiting interface include: semaphore waiting The time parameter of the interface, and the semaphore parameter of the semaphore waiting interface.
优选地,在执行步骤201之前,需要计算预定任务在本次任务处理中能够用于等待信号量的最长时间。Preferably, before step 201 is executed, it is necessary to calculate the maximum time that the scheduled task can use to wait for the semaphore in the current task processing.
在步骤201中,对硬件定时器的定时时间、以及信号量等待接口的参数进行设置具体包括:1、将硬件定时器的定时时间设置为预定任务等待信号量的最长时间;2、将信号量等待接口的时间参数设置为永久等待,并将信号量等待接口的信号量参数设置为预定任务本次任务处理需要的信号量。In step 201, setting the timing time of the hardware timer and the parameters of the semaphore waiting interface specifically includes: 1. The timing time of the hardware timer is set as the longest time for the scheduled task to wait for the semaphore; 2. The time parameter of the semaphore waiting interface is set to wait forever, and the semaphore parameter of the semaphore waiting interface is set to the semaphore required for the current task processing of the scheduled task.
步骤202,通过信号量等待接口获取信号量(该信号量为上述预定任务等待的信号量),根据信号量的值判断信号量是在定时时间到时之前获取的正常信号量还是在硬件定时器中断之后获取的中断信号量;Step 202, obtain the semaphore through the semaphore waiting interface (the semaphore is the semaphore waiting for the above-mentioned predetermined task), and judge according to the value of the semaphore whether the semaphore is a normal semaphore obtained before the timer expires or a hardware timer The interrupt semaphore obtained after the interrupt;
执行步骤202之前,硬件定时器(硬件定时器的中断服务程序)在定时时间到时后需要触发中断,将中断信号量的值设置为不同于正常信号量的值,并将中断信号量通过信号量等待接口通知(post)给预定任务。Before executing step 202, the hardware timer (the interrupt service routine of the hardware timer) needs to trigger an interrupt after the timing time expires, set the value of the interrupt semaphore to a value different from the normal semaphore, and pass the interrupt semaphore through the signal The amount waits for the interface to notify (post) to the scheduled task.
步骤203,在判断获取的信号量为正常信号量的情况下,关闭硬件定时器,根据正常信号量进行任务处理,并执行步骤201,在判断获取的信号量为中断信号量的情况下,退出任务本次循环的处理,直接执行步骤201。Step 203, when judging that the acquired semaphore is a normal semaphore, close the hardware timer, perform task processing according to the normal semaphore, and execute step 201, and exit when judging that the acquired semaphore is an interrupt semaphore For the processing of the task cycle this time, step 201 is directly performed.
以下结合附图,对本发明实时的上述技术方案进行详细说明。The real-time above-mentioned technical solution of the present invention will be described in detail below in conjunction with the accompanying drawings.
图3是本发明实施例的信号量等待接口定时方法的详细处理的流程图,如图3所示,本发明实施例将CPU的硬件定时器和操作系统提供的信号量等待接口结合使用,达到精确判断信号量等待超时的目的。具体包括如下处理:Fig. 3 is the flow chart of detailed processing of the semaphore waiting interface timing method of the embodiment of the present invention, as shown in Fig. 3, the embodiment of the present invention combines the hardware timer of CPU and the semaphore waiting interface that operating system provides, reaches Accurately determine the purpose of semaphore waiting timeout. Specifically include the following processing:
步骤1,任务开始TaskEntry(),该任务在等待信号量之前,首先计算本次处理能用于等待信号量的最长时间Ts;Step 1, the task starts TaskEntry(), before the task waits for the semaphore, it first calculates the longest time Ts that can be used to wait for the semaphore in this processing;
步骤2,使能硬件定时器,并根据该最长时间Ts设置硬件定时器的定时时间(TimeOut);Step 2, enable the hardware timer, and set the timing time (TimeOut) of the hardware timer according to the maximum time Ts;
步骤3,调用操作系统提供的信号量等待接口Pend(Mbx,forever),将该接口的时间参数设置为永久等待(forever),将信号量等待接口的信号量参数设置为预定任务本次任务处理需要的信号量(Mbx);Step 3: Call the semaphore waiting interface Pend (Mbx, forever) provided by the operating system, set the time parameter of the interface as forever (forever), and set the semaphore parameter of the semaphore waiting interface as the scheduled task for this task processing The required semaphore (Mbx);
步骤4,在操作系统的调度下,CPU开始处理其它多任务程序,该任务所等待的信号量有可能在Ts时间段内到来,也有可能在Ts时间段内该信号量没有到来,如果Ts时间段内该信号量没有到来,那么硬件定时器会在Ts时间后触发中断,post信号量给该任务,硬件定时器中断服务程序处理流程如图4所示,TimerIsr()为硬件定时器服务中断程序,Post(Mbx)表示通知该信号量。Step 4, under the scheduling of the operating system, the CPU starts to process other multitasking programs. The semaphore that the task is waiting for may arrive within the Ts time period, or the semaphore may not arrive within the Ts time period. If the Ts time period If the semaphore does not arrive in the segment, the hardware timer will trigger an interrupt after Ts time, post the semaphore to the task, and the processing flow of the hardware timer interrupt service program is shown in Figure 4. TimerIsr() is the hardware timer service interrupt Program, Post(Mbx) means to notify the semaphore.
无论该任务所等待的信号量在Ts时间段内到来,或者在Ts时间段内该信号量没有到来,都会将该任务激活使其进入活动(running)状态,该任务将继续之后的处理。图5是本发明实施例的信号量队列的示意图,如图5所示,信号量队列中有可能包括:硬件定时器超时的中断信号量、或者正常信号量,因此,任务根据信号量的返回值来区分该信号量到底是任务所需要的信号量还是超时中断post的信号量,根据这两种情况决定后续的处理流程:如果该信号量是该任务所需要的信号量,执行步骤5;如果该信号量是硬件定时器超时中断post的信号量,说明该任务等待所需要的信号量超时,执行步骤7;Regardless of whether the semaphore that the task is waiting for arrives within the Ts time period, or the semaphore does not arrive within the Ts time period, the task will be activated to enter the active (running) state, and the task will continue subsequent processing. Fig. 5 is the schematic diagram of the semaphore queue of the embodiment of the present invention, as shown in Fig. 5, may include in the semaphore queue: the interrupt semaphore of hardware timer overtime, or normal semaphore, therefore, task returns according to semaphore value to distinguish whether the semaphore is the semaphore required by the task or the semaphore that interrupts the post over time, and determine the subsequent processing flow according to these two situations: if the semaphore is the semaphore required by the task, perform step 5; If the semaphore is the semaphore of the hardware timer timeout interrupt post, it means that the task waits for the required semaphore to time out, and execute step 7;
步骤5,关闭该硬件定时器,执行步骤6;Step 5, close the hardware timer, and execute step 6;
步骤6,处理业务任务,处理完毕后返回主流程准备下个周期的处理;Step 6, process business tasks, and return to the main process to prepare for the next cycle of processing after processing;
步骤7,不对业务任务进行处理,直接返回主流程开始下个周期的处理。Step 7, do not process the business task, directly return to the main process to start the next cycle of processing.
下面以LTE系统为例,对本发明实施例的上述技术方案进行举例说明。The LTE system is taken as an example below to illustrate the technical solution of the embodiment of the present invention.
LTE基带协议业务的处理周期为1ms,协议任务必须要在第10个标志(symbol)符号中断到达之后才能开始处理,任务能够容忍等待信号量的时间最长为0.4ms。根据本发明实施例的技术方案,在进入处理任务后,首先设置一个硬件定时器,定时长度设置为0.4ms,然后调用操作系统提供的pend信号量接口,等待时长设置为永久等待。判断pend信号量的值,确定该信号量是来源于第10个symbol符号中断post的信号量,或者是硬件定时器中断psot的超时信号量。如果是symbol符号中断信号量时,表明本子帧信号量在规定时间内到达,可以对本子帧的数据进行处理;如果是硬件定时器超时信号量,表明任务所需要的信号量已经超时,需要退出本子帧的处理,准备进行下个子帧的处理。The processing period of the LTE baseband protocol service is 1ms, and the protocol task can only be processed after the 10th symbol (symbol) interrupt arrives. The maximum time that the task can tolerate waiting for the semaphore is 0.4ms. According to the technical scheme of the embodiment of the present invention, after entering the processing task, a hardware timer is first set, and the timing length is set to 0.4ms, and then the pend semaphore interface provided by the operating system is called, and the waiting time is set to permanent waiting. Determine the value of the pend semaphore, and determine whether the semaphore is the semaphore from the 10th symbol interrupt post, or the timeout semaphore from the hardware timer interrupt psot. If it is a symbol symbol interrupt semaphore, it indicates that the semaphore of this subframe arrives within the specified time, and the data of this subframe can be processed; if it is a hardware timer timeout semaphore, it indicates that the semaphore required by the task has timed out and needs to exit The processing of this subframe prepares for the processing of the next subframe.
综上所述,借助于本发明实施例的技术方案,通过将操作系统提供的信号量等待接口和CPU的硬件定时器资源配合使用,解决了现有技术中由于操作系统时钟本身精度的限制而导致信号量等待接口定时精度低的问题,提高了信号量等待接口定时的精确度,在不增加系统额外负担的情况下,满足了一些对时序要求非常严格的应用场合。To sum up, with the help of the technical solution of the embodiment of the present invention, by using the semaphore waiting interface provided by the operating system in conjunction with the hardware timer resource of the CPU, the problems in the prior art due to the limitation of the precision of the operating system clock itself are solved. The problem of low timing accuracy of the semaphore waiting interface improves the timing accuracy of the semaphore waiting interface, and satisfies some applications that have very strict timing requirements without adding additional burden to the system.
装置实施例Device embodiment
根据本发明的实施例,提供了一种信号量等待接口定时装置,图6是本发明实施例的信号量等待接口定时装置的结构示意图,如图6所示,根据本发明实施例的信号量等待接口定时装置包括:接口调用模块60、使能模块62、信号量判断模块64、以及处理模块66,以下对本发明实施例的各个模块进行详细的说明。According to an embodiment of the present invention, a semaphore waiting interface timing device is provided. FIG. 6 is a schematic structural diagram of a semaphore waiting interface timing device according to an embodiment of the present invention. As shown in FIG. 6, the semaphore according to an embodiment of the present invention The waiting interface timing device includes: an interface calling module 60 , an enabling module 62 , a semaphore judging module 64 , and a processing module 66 , and each module in the embodiment of the present invention will be described in detail below.
接口调用模块60,用于调用信号量等待接口;The interface calling module 60 is used to call the semaphore waiting interface;
使能模块62,用于在接口调用模块60调用信号量等待接口时,使能硬件定时器,对硬件定时器的定时时间、以及信号量等待接口的参数进行设置;其中,信号量等待接口的参数包括:信号量等待接口的时间参数、以及信号量等待接口的信号量参数。Enabling module 62, for when interface calling module 60 calls semaphore waiting interface, enable hardware timer, the timing time of hardware timer and the parameter of semaphore waiting interface are set; Wherein, semaphore waiting interface The parameters include: a time parameter of the semaphore waiting interface, and a semaphore parameter of the semaphore waiting interface.
优选地,本发明实施例还包括:计算模块,用于计算预定任务在本次任务处理中能够用于等待信号量的最长时间。Preferably, the embodiment of the present invention further includes: a calculation module, configured to calculate the maximum time that the scheduled task can wait for the semaphore in the current task processing.
使能模块62具体包括:第一设置子模块,用于将硬件定时器的定时时间设置为预定任务等待信号量的最长时间;第二设置子模块,用于将信号量等待接口的时间参数设置为永久等待,并将信号量等待接口的信号量参数设置为预定任务本次任务处理需要的信号量。The enabling module 62 specifically includes: a first setting submodule, which is used to set the timing time of the hardware timer as the longest time for a predetermined task to wait for the semaphore; a second setting submodule, which is used to set the semaphore to wait for the time parameter of the interface Set it to wait forever, and set the semaphore parameter of the semaphore waiting interface to the semaphore required by the scheduled task for this task processing.
上述硬件定时器具体用于:在定时时间到时后触发中断,将中断信号量的值设置为不同于正常信号量的值,并将中断信号量通过信号量等待接口通知给预定任务。The above-mentioned hardware timer is specifically used for: triggering an interrupt after the timing expires, setting the value of the interrupt semaphore to a value different from that of the normal semaphore, and notifying the interrupt semaphore to a scheduled task through the semaphore waiting interface.
信号量判断模块64,用于通过信号量等待接口获取信号量,根据信号量的值判断信号量是在定时时间到时之前获取的正常信号量还是在硬件定时器中断之后获取的中断信号量;The semaphore judging module 64 is used to obtain the semaphore through the semaphore waiting interface, and judges whether the semaphore is a normal semaphore obtained before the timing time expires or an interrupt semaphore obtained after the hardware timer interrupts according to the value of the semaphore;
处理模块66,用于在信号量判断模块64判断获取的信号量为正常信号量的情况下,关闭硬件定时器,根据正常信号量进行任务处理,并调用接口调用模块60,在信号量判断模块64判断获取的信号量为中断信号量的情况下,直接调用接口调用模块60。The processing module 66 is used to close the hardware timer when the semaphore judging module 64 judges that the acquired semaphore is a normal semaphore, perform task processing according to the normal semaphore, and call the interface calling module 60. In the semaphore judging module 64 In the case of judging that the obtained semaphore is an interrupt semaphore, directly call the interface calling module 60 .
以下结合附图,对本发明实时的上述技术方案进行详细说明。The real-time above-mentioned technical solution of the present invention will be described in detail below in conjunction with the accompanying drawings.
图3是本发明实施例的信号量等待接口定时方法的详细处理的流程图,如图3所示,本发明实施例将CPU的硬件定时器和操作系统提供的信号量等待接口结合使用,达到精确判断信号量等待超时的目的。具体包括如下处理:Fig. 3 is the flow chart of detailed processing of the semaphore waiting interface timing method of the embodiment of the present invention, as shown in Fig. 3, the embodiment of the present invention combines the hardware timer of CPU and the semaphore waiting interface that operating system provides, reaches Accurately determine the purpose of semaphore waiting timeout. Specifically include the following processing:
步骤1,任务开始TaskEntry(),该任务在等待信号量之前,首先计算本次处理能用于等待信号量的最长时间Ts;Step 1, the task starts TaskEntry(), before the task waits for the semaphore, it first calculates the longest time Ts that can be used to wait for the semaphore in this processing;
步骤2,使能硬件定时器,并根据该最长时间Ts设置硬件定时器的定时时间(TimeOut);Step 2, enable the hardware timer, and set the timing time (TimeOut) of the hardware timer according to the maximum time Ts;
步骤3,调用操作系统提供的信号量等待接口Pend(Mbx,forever),将该接口的时间参数设置为永久等待(forever),将信号量等待接口的信号量参数设置为预定任务本次任务处理需要的信号量(Mbx);Step 3: Call the semaphore waiting interface Pend (Mbx, forever) provided by the operating system, set the time parameter of the interface as forever (forever), and set the semaphore parameter of the semaphore waiting interface as the scheduled task for this task processing The required semaphore (Mbx);
步骤4,在操作系统的调度下,CPU开始处理其它多任务程序,该任务所等待的信号量有可能在Ts时间段内到来,也有可能在Ts时间段内该信号量没有到来,如果Ts时间段内该信号量没有到来,那么硬件定时器会在Ts时间后触发中断,post信号量给该任务,硬件定时器中断服务程序处理流程如图4所示,TimerIsr()为硬件定时器服务中断程序,Post(Mbx)表示通知该信号量。Step 4, under the scheduling of the operating system, the CPU starts to process other multitasking programs. The semaphore that the task is waiting for may arrive within the Ts time period, or the semaphore may not arrive within the Ts time period. If the Ts time period If the semaphore does not arrive in the segment, the hardware timer will trigger an interrupt after Ts time, post the semaphore to the task, and the processing flow of the hardware timer interrupt service program is shown in Figure 4. TimerIsr() is the hardware timer service interrupt Program, Post(Mbx) means to notify the semaphore.
无论该任务所等待的信号量在Ts时间段内到来,或者在Ts时间段内该信号量没有到来,都会将该任务激活使其进入活动(running)状态,该任务将继续之后的处理。图5是本发明实施例的信号量队列的示意图,如图5所示,信号量队列中有可能包括:硬件定时器超时的中断信号量、或者正常信号量,因此,任务根据信号量的返回值来区分该信号量到底是任务所需要的信号量还是超时中断post的信号量,根据这两种情况决定后续的处理流程:如果该信号量是该任务所需要的信号量,执行步骤5;如果该信号量是硬件定时器超时中断post的信号量,说明该任务等待所需要的信号量超时,执行步骤7;Regardless of whether the semaphore that the task is waiting for arrives within the Ts time period, or the semaphore does not arrive within the Ts time period, the task will be activated to enter the active (running) state, and the task will continue subsequent processing. Fig. 5 is the schematic diagram of the semaphore queue of the embodiment of the present invention, as shown in Fig. 5, may include in the semaphore queue: the interrupt semaphore of hardware timer overtime, or normal semaphore, therefore, task returns according to semaphore value to distinguish whether the semaphore is the semaphore required by the task or the semaphore that interrupts the post over time, and determine the subsequent processing flow according to these two situations: if the semaphore is the semaphore required by the task, perform step 5; If the semaphore is the semaphore of the hardware timer timeout interrupt post, it means that the task waits for the required semaphore to time out, and execute step 7;
步骤5,关闭该硬件定时器,执行步骤6;Step 5, close the hardware timer, and execute step 6;
步骤6,处理业务任务,处理完毕后返回主流程准备下个周期的处理;Step 6, process business tasks, and return to the main process to prepare for the next cycle of processing after processing;
步骤7,不对业务任务进行处理,直接返回主流程开始下个周期的处理。Step 7, do not process the business task, directly return to the main process to start the next cycle of processing.
下面以LTE系统为例,对本发明实施例的上述技术方案进行举例说明。The LTE system is taken as an example below to illustrate the technical solution of the embodiment of the present invention.
LTE基带协议业务的处理周期为1ms,协议任务必须要在第10个标志(symbol)符号中断到达之后才能开始处理,任务能够容忍等待信号量的时间最长为0.4ms。根据本发明实施例的技术方案,在进入处理任务后,首先设置一个硬件定时器,定时长度设置为0.4ms,然后调用操作系统提供的pend信号量接口,等待时长设置为永久等待。判断pend信号量的值,确定该信号量是来源于第10个symbol符号中断post的信号量,或者是硬件定时器中断psot的超时信号量。如果是symbol符号中断信号量时,表明本子帧信号量在规定时间内到达,可以对本子帧的数据进行处理;如果是硬件定时器超时信号量,表明任务所需要的信号量已经超时,需要退出本子帧的处理,准备进行下个子帧的处理。The processing period of the LTE baseband protocol service is 1ms, and the protocol task can only be processed after the 10th symbol (symbol) interrupt arrives. The maximum time that the task can tolerate waiting for the semaphore is 0.4ms. According to the technical scheme of the embodiment of the present invention, after entering the processing task, a hardware timer is first set, and the timing length is set to 0.4ms, and then the pend semaphore interface provided by the operating system is called, and the waiting time is set to permanent waiting. Determine the value of the pend semaphore, and determine whether the semaphore is the semaphore from the 10th symbol interrupt post, or the timeout semaphore from the hardware timer interrupt psot. If it is a symbol symbol interrupt semaphore, it indicates that the semaphore of this subframe arrives within the specified time, and the data of this subframe can be processed; if it is a hardware timer timeout semaphore, it indicates that the semaphore required by the task has timed out and needs to exit The processing of this subframe prepares for the processing of the next subframe.
综上所述,借助于本发明实施例的技术方案,通过将操作系统提供的信号量等待接口和CPU的硬件定时器资源配合使用,解决了现有技术中由于操作系统时钟本身精度的限制而导致信号量等待接口定时精度低的问题,提高了信号量等待接口定时的精确度,在不增加系统额外负担的情况下,满足了一些对时序要求非常严格的应用场合。To sum up, with the help of the technical solution of the embodiment of the present invention, by using the semaphore waiting interface provided by the operating system in conjunction with the hardware timer resource of the CPU, the problems in the prior art due to the limitation of the precision of the operating system clock itself are solved. The problem of low timing accuracy of the semaphore waiting interface improves the timing accuracy of the semaphore waiting interface, and satisfies some applications that have very strict timing requirements without adding additional burden to the system.
尽管为示例目的,已经公开了本发明的优选实施例,本领域的技术人员将意识到各种改进、增加和取代也是可能的,因此,本发明的范围应当不限于上述实施例。Although preferred embodiments of the present invention have been disclosed for illustrative purposes, those skilled in the art will appreciate that various modifications, additions and substitutions are possible, and therefore, the scope of the present invention should not be limited to the above-described embodiments.
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201210170486.4ACN103455310B (en) | 2012-05-29 | 2012-05-29 | Timing method and device for semaphore pend interface |
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201210170486.4ACN103455310B (en) | 2012-05-29 | 2012-05-29 | Timing method and device for semaphore pend interface |
| Publication Number | Publication Date |
|---|---|
| CN103455310A CN103455310A (en) | 2013-12-18 |
| CN103455310Btrue CN103455310B (en) | 2017-02-08 |
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN201210170486.4AExpired - Fee RelatedCN103455310B (en) | 2012-05-29 | 2012-05-29 | Timing method and device for semaphore pend interface |
| Country | Link |
|---|---|
| CN (1) | CN103455310B (en) |
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN107370639A (en)* | 2017-08-14 | 2017-11-21 | 苏州众天力信息科技有限公司 | A kind of more scenery control methods of gateway based on trapezoidal temporal algorithm |
| CN109189582B (en)* | 2018-07-20 | 2020-09-15 | 新华三技术有限公司合肥分公司 | Method and device for detecting reason of semaphore timeout |
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US5500809A (en)* | 1992-08-31 | 1996-03-19 | Sharp Kabushiki Kaisha | Microcomputer system provided with mechanism for controlling operation of program |
| CN1414747A (en)* | 2002-05-08 | 2003-04-30 | 华为技术有限公司 | Method of implementing base data message receiving |
| CN1635485A (en)* | 2003-12-26 | 2005-07-06 | 华为技术有限公司 | Timeout Adaptive Method During Remote Synchronous Call |
| CN1873615A (en)* | 2006-01-20 | 2006-12-06 | 华为技术有限公司 | Method for servicing task of timer |
| CN101272564A (en)* | 2008-04-17 | 2008-09-24 | 中兴通讯股份有限公司 | Soft real-time timing device module and method for soft real-time timing device scheduling |
| CN101276295A (en)* | 2008-03-19 | 2008-10-01 | 北京星网锐捷网络技术有限公司 | Method for real-time operating system to avoid interrupt occupying excess CPU resources |
| CN102043667A (en)* | 2010-11-25 | 2011-05-04 | 深圳市科陆电子科技股份有限公司 | Task scheduling method for embedded operating system |
| CN102404404A (en)* | 2011-09-07 | 2012-04-04 | 航天科工仿真技术有限责任公司 | Distributed WEB application and remote equipment message communication method |
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| JPS63123218A (en)* | 1986-11-12 | 1988-05-27 | Nec Corp | Timer/counter circuit |
| CN1755614A (en)* | 2004-09-29 | 2006-04-05 | 华为技术有限公司 | How to implement the timer |
| CN100395702C (en)* | 2006-09-30 | 2008-06-18 | 华为技术有限公司 | A timer implementation method |
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US5500809A (en)* | 1992-08-31 | 1996-03-19 | Sharp Kabushiki Kaisha | Microcomputer system provided with mechanism for controlling operation of program |
| CN1414747A (en)* | 2002-05-08 | 2003-04-30 | 华为技术有限公司 | Method of implementing base data message receiving |
| CN1635485A (en)* | 2003-12-26 | 2005-07-06 | 华为技术有限公司 | Timeout Adaptive Method During Remote Synchronous Call |
| CN1873615A (en)* | 2006-01-20 | 2006-12-06 | 华为技术有限公司 | Method for servicing task of timer |
| CN101276295A (en)* | 2008-03-19 | 2008-10-01 | 北京星网锐捷网络技术有限公司 | Method for real-time operating system to avoid interrupt occupying excess CPU resources |
| CN101272564A (en)* | 2008-04-17 | 2008-09-24 | 中兴通讯股份有限公司 | Soft real-time timing device module and method for soft real-time timing device scheduling |
| CN102043667A (en)* | 2010-11-25 | 2011-05-04 | 深圳市科陆电子科技股份有限公司 | Task scheduling method for embedded operating system |
| CN102404404A (en)* | 2011-09-07 | 2012-04-04 | 航天科工仿真技术有限责任公司 | Distributed WEB application and remote equipment message communication method |
| Publication number | Publication date |
|---|---|
| CN103455310A (en) | 2013-12-18 |
| Publication | Publication Date | Title |
|---|---|---|
| CN103984596B (en) | The dispatching method and device of a kind of On-board software | |
| EP2701074B1 (en) | Method, device, and system for performing scheduling in multi-processor core system | |
| US8504753B2 (en) | Suspendable interrupts for processor idle management | |
| CN101546277B (en) | Multiple core processor platform and multiple core processor synchronization method | |
| US20060010446A1 (en) | Method and system for concurrent execution of multiple kernels | |
| CN104156264B (en) | A kind of base band signal process tasks in parallel real-time scheduling method based on many GPU | |
| CN102043667A (en) | Task scheduling method for embedded operating system | |
| CN106030559A (en) | Syncronization of interrupt processing to reduce power consumption | |
| CN111475312B (en) | Message-driven method and device based on real-time operating system | |
| CN110928657B (en) | Deterministic Analysis Methods for Embedded Systems | |
| KR100959548B1 (en) | Interrupt Scheduling Method | |
| CN104536835A (en) | Self-adaption task scheduling method in hot backup real-time control system | |
| CN114661449A (en) | Task scheduling method, embedded system, and computer-readable storage medium | |
| CN103455310B (en) | Timing method and device for semaphore pend interface | |
| CN104679583A (en) | Method and device for dynamically adjusting clock interruption | |
| US11243603B2 (en) | Power management of an event-based processing system | |
| US9785586B2 (en) | Electronic computer and interrupt control method | |
| US9436627B2 (en) | Detection of abnormal operation caused by interrupt processing | |
| CN108292236B (en) | Information processing method and device | |
| WO2012065432A1 (en) | Method for implementing timer in multi-core system and multi-core system | |
| CA2767782C (en) | Suspendable interrupts for processor idle management | |
| US10949367B2 (en) | Method for handling kernel service request for interrupt routines in multi-core environment and electronic device thereof | |
| CN101349975B (en) | Method for implementing interrupt bottom semi-section mechanism in embedded operation system | |
| CN118819758A (en) | Task processing method, device, electronic device and storage medium | |
| CN104104969B (en) | Video interception method and device |
| Date | Code | Title | Description |
|---|---|---|---|
| C06 | Publication | ||
| PB01 | Publication | ||
| C10 | Entry into substantive examination | ||
| SE01 | Entry into force of request for substantive examination | ||
| C14 | Grant of patent or utility model | ||
| GR01 | Patent grant | ||
| TR01 | Transfer of patent right | Effective date of registration:20201217 Address after:215163 8 Jinfeng Road, science and Technology City, Suzhou high tech Zone, Jiangsu Patentee after:Suzhou Medical Device Industry Development Co.,Ltd. Address before:518057 Ministry of justice, Zhongxing building, South Science and technology road, Nanshan District hi tech Industrial Park, Shenzhen, Guangdong Patentee before:ZTE Corp. | |
| TR01 | Transfer of patent right | ||
| PE01 | Entry into force of the registration of the contract for pledge of patent right | Denomination of invention:Signal waiting interface timing method and device Effective date of registration:20211209 Granted publication date:20170208 Pledgee:Suzhou jinhesheng Holding Co.,Ltd. Pledgor:Suzhou Medical Device Industry Development Co.,Ltd. Registration number:Y2021320010540 | |
| PE01 | Entry into force of the registration of the contract for pledge of patent right | ||
| EE01 | Entry into force of recordation of patent licensing contract | Application publication date:20131218 Assignee:Suzhou jinhesheng Holding Co.,Ltd. Assignor:Suzhou Medical Device Industry Development Co.,Ltd. Contract record no.:X2021320010049 Denomination of invention:Signal waiting interface timing method and device Granted publication date:20170208 License type:Exclusive License Record date:20211209 | |
| EE01 | Entry into force of recordation of patent licensing contract | ||
| CP01 | Change in the name or title of a patent holder | Address after:215163 8 Jinfeng Road, science and Technology City, Suzhou high tech Zone, Jiangsu Patentee after:Suzhou Medical Device Industry Development Group Co.,Ltd. Address before:215163 8 Jinfeng Road, science and Technology City, Suzhou high tech Zone, Jiangsu Patentee before:Suzhou Medical Device Industry Development Co.,Ltd. | |
| CP01 | Change in the name or title of a patent holder | ||
| PM01 | Change of the registration of the contract for pledge of patent right | ||
| PM01 | Change of the registration of the contract for pledge of patent right | Change date:20230801 Registration number:Y2021320010540 Pledgor after:Suzhou Medical Device Industry Development Group Co.,Ltd. Pledgor before:Suzhou Medical Device Industry Development Co.,Ltd. | |
| PC01 | Cancellation of the registration of the contract for pledge of patent right | Date of cancellation:20230804 Granted publication date:20170208 Pledgee:Suzhou jinhesheng Holding Co.,Ltd. Pledgor:Suzhou Medical Device Industry Development Group Co.,Ltd. Registration number:Y2021320010540 | |
| PC01 | Cancellation of the registration of the contract for pledge of patent right | ||
| EM01 | Change of recordation of patent licensing contract | Change date:20230824 Contract record no.:X2021320010049 Assignor after:Suzhou Medical Device Industry Development Group Co.,Ltd. Assignor before:Suzhou Medical Device Industry Development Co.,Ltd. | |
| EM01 | Change of recordation of patent licensing contract | ||
| EC01 | Cancellation of recordation of patent licensing contract | Assignee:Suzhou jinhesheng Holding Co.,Ltd. Assignor:Suzhou Medical Device Industry Development Group Co.,Ltd. Contract record no.:X2021320010049 Date of cancellation:20230830 | |
| EC01 | Cancellation of recordation of patent licensing contract | ||
| CF01 | Termination of patent right due to non-payment of annual fee | ||
| CF01 | Termination of patent right due to non-payment of annual fee | Granted publication date:20170208 |