CN1664789A - Method for real-time CPU occupation rate detection of operating systems - Google Patents

Method for real-time CPU occupation rate detection of operating systems Download PDF

Info

Publication number
CN1664789A
CN1664789A CN 200410026409 CN200410026409A CN1664789A CN 1664789 A CN1664789 A CN 1664789A CN 200410026409 CN200410026409 CN 200410026409 CN 200410026409 A CN200410026409 A CN 200410026409A CN 1664789 A CN1664789 A CN 1664789A
Authority
CN
China
Prior art keywords
time
cpu usage
cpu
variable
value
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.)
Granted
Application number
CN 200410026409
Other languages
Chinese (zh)
Other versions
CN1324477C (en
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.)
ZTE Corp
Original Assignee
ZTE Corp
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 ZTE Corp filed Critical ZTE Corp
Priority to CNB2004100264097A priority Critical patent/CN1324477C/en
Publication of CN1664789A publication Critical patent/CN1664789A/en
Application granted granted Critical
Publication of CN1324477C publication Critical patent/CN1324477C/en
Anticipated expiration legal-status Critical
Expired - Fee Related legal-status Critical Current

Links

Images

Abstract

This invention relates to a method for testing real-time operating system CPU utility ratio, characterized by the following steps: initializing relevant variable when starting system; testing CPU processing speed to get reference value; starting free task, operating infinite loop and recording the circulating times; when at the set time, checking whether reaching said CPU utility ratio's calculation level, executing other task if not; when reaching the level, measuring and calculating by the following formula: 1000-((total circulation executing time* free task executing circulation times)/(total circulation times* statistic time)) * 1000 to figure out CPU utility ratio. The method doesn't need any other complex additional operation, and is easy to understand, use and is of high adaptability.

Description

A kind of method that detects the real time operating system CPU usage
Technical field
The present invention relates to the field that a kind of real time operating system that adopts task scheduling mechanism is carried out the bitcom exploitation, relate in particular to a kind of detection method of the CPU usage based on real time operating system.
Background technology
In the embedded software developing process, when a plurality of task runs are on a Target Board, each task need take the CPU operation according to certain rule, therefore by detection to CPU usage, can detect system sometime the section in busy not busy situation, thereby influencing each other between the attribute of adjustment task self, minimizing task finally makes system reach comparatively desirable throughput value; And when some fault takes place in system, by also can reach the purpose of debugging to the detection of CPU usage.
The CPU usage detection method of generally using is to carry out frequency method with the married statistics task of real time operating system at present, the method will be moved counting to task, and the Hook Function will move counting and just need The Realtime Operating System Nucleus to provide task to switch task the time, because the diversity of the realization of real time operating system, if it does not provide the method for such incision kernel, just can't realize the statistics of CPU usage.
It is the CPU usage detection method of utilizing real time operating system self to provide that prior art also has a kind of method, as: the spy function that the vxworks system provides.But show in the practice and use this function can in system, additionally increase a task that priority is very high, the quantity of information of its system's implementation status in showing the fixed time section is too much simultaneously, and more complicated is hard to understand, and the time that has wherein comprised the switching of interruption and kernel is counted numerical value such as statistics.And when the time point of statistics was in the kernel handoff procedure, the value under detected CPU usage value and other situation differed greatly, and the general CPU usage situation that often only need know application itself of application person.Therefore there is above-mentioned defective in prior art, needs further improvement.
Summary of the invention
The object of the present invention is to provide a kind of method that detects the real time operating system CPU usage, at the various real time operating system environment that are widely used in embedded development at present, a kind of CPU usage detection method based on this environment is proposed, this method does not influence the operation of real time operating system self, and it just can realize detecting the occupancy of CPU by the processing speed that calculates concrete CPU.
Technical scheme of the present invention is as follows:
A kind of method that detects the real time operating system CPU usage, it may further comprise the steps:
A) the relevant variable of initialization when system start-up;
B) carry out the CPU processing speed and detect, obtain reference value;
C) start idle task bring into operation infinite loop and record cycle index;
D) the timed task time then, check the calculation level whether arrived described CPU usage, then do not carry out other affairs;
During e) to described CPU usage calculation level, according to following formula:
CPU usage=1000-((global cycle execution time * idle task is carried out cycle index)/(global cycle number of times * timing statistics)) * 1000
Calculate described CPU usage.
Described method, wherein, described method comprises that also described system increases protection mechanism at the execution circulation time, closes interruption; Cycle index to judgement before open interruption, cancellation protection is so that system clock interrupts being handled.
Described method, wherein, described CPU usage value can by with the comparison of history value, acquisition system operation CPU usage peak value so far.
Described method, wherein, described system also is provided with the time of an output CPU usage situation, then the described CPU usage value of information is outputed on the corresponding display device in this time.
Described method, wherein, the variable that initialization is relevant during described system start-up comprises total cycle time variable, idle task loop counting variable, timing statistics variable, current C PU occupancy value variable and CPU usage peak value variable.
A kind of method that detects the real time operating system CPU usage provided by the present invention, because the user only need adjust the value of global cycle number of times as required when the first time, and it is just passable to add computing in the timed task of system, without any need for the extra operation of other complexity; And the code that the inventive method realizes is very brief, and highly versatile is applicable to the real time operating system of various employing task schedulings; The inventive method is as a unit independently, can add system at any time or peels off from system, and its computation process is less to the total system Effect on Performance.The inventive method has simply, the high advantage of dirigibility.
Description of drawings
Detection principle schematic when Fig. 1 a is the system initialization of the inventive method;
Fig. 1 b is the operating detection schematic diagram of the inventive method system;
Fig. 2 is the main flow synoptic diagram of the inventive method;
Fig. 3 is the CPU processing speed calculation flow chart of the inventive method;
Fig. 4 is that the idle task of the inventive method is carried out schematic flow sheet;
Fig. 5 is the CPU usage calculation process synoptic diagram of the inventive method.
Embodiment
Below in conjunction with accompanying drawing, the inventive method is described in detail by specific embodiment:
At first explanation uses the inventive method to detect the principle of CPU usage.
In real time operating system, the CPU processing power in the unit interval is certain, just can the CPU processing speed be measured in the original position of system initialization according to this point, and represents it by a metric.As shown in Figure 1a, calculating at that time, CPU handles the employed time of limited number of cycles of specifying the global cycle number of times, that is: carried out the limited number of cycles of specifying the global cycle number of times, obtain global cycle execution time T, the unit of measurement of this time is exactly the time of day (timeticks) of this real time operating system, also is the timing reference value.Global cycle number of times/global cycle execution time just can the representation unit time in the processing speed of CPU when all busy, and show in global cycle in the execution time that CPU handles global cycle time circulation for several times at most.Generally speaking, the global cycle execution time that requires to obtain is one second, and requires to be provided with the value of global cycle number of times according to this.For different CPU, because the difference of its processing speed, the value of global cycle number of times should corresponding change.The CPU processing speed is fast more, and this value is just big more.
The operation that when CPU is relatively not busy, is scheduled of idle task in the real time operating system.In this task, can add up the number of times that infinite loop is carried out.Like this, be similar to the CPU usage timing statistics of global cycle execution time at timed task, as the time T 1 shown among Fig. 1 b, then, the value of the cycle index that idle task is carried out has at this moment just shown the execution ratio of this task in the timing statistics section, shown in Fig. 1 b.The passing ratio formula:
(global cycle number of times * CPU idle ratio)/global cycle execution time=
Idle task is carried out the calculating of cycle index/timing statistics (formula 1), and the ratio that just can obtain the CPU free time in timing statistics is:
The idle ratio of CPU=(global cycle execution time * idle task is carried out cycle index)/
(global cycle number of times * timing statistics)
The CPU running status is 1 in the timing statistics if establish, and then the busy ratio of CPU is:
The CPU idle ratio of ratio=1-CPU of having much to do
The last CPU usage that calculates that just can be similar to is:
CPU usage=1000-((global cycle execution time * idle task is carried out cycle index)/
(global cycle number of times * timing statistics)) * 1000 (formula 2)
Consider with the characteristic (not having the floating-point operation function) of CPU based on communication in order to reduce sum of errors in this formula, the value that obtains has been amplified 1000 times, promptly kept 4 significance bits of result of calculation value as some CPU.
By top description,, just must make the value of global cycle execution time approaching with the value of timing statistics as far as possible as can be seen in order to make result of calculation more accurate.Therefore according to the difference of CPU, need proofread and correct the global cycle number of times at the system debug initial stage.
The main process flow diagram of the inventive method as shown in Figure 2 because the singularity of real time operating system concurrent processing, what this process flow diagram showed is a discontinuous processing procedure.
At first after the system start-up operation, at initial phase, the variablees such as total cycle time variable, idle task loop counting variable, timing statistics variable, current C PU occupancy value variable and CPU usage peak value variable that will use the calculating CPU usage carry out initialization; Calculate the CPU processing speed then, and preserve total cycle time; Start idle task.Afterwards, give real time operating system, by the higher task run of operating system scheduling priority with control.When system was idle, the minimum idle task of meeting running priority level was carried out the infinite loop counting.When system clock was timed to, meeting run timing task if the timing statistics of CPU usage has arrived, was just carried out the calculating of CPU usage.
The process flow diagram of key step below is described:
1, calculates the CPU processing speed
The system that it should be noted that this moment may be owing to be subjected to extraneous interference, as interrupting etc., causes result calculated unusual.Must interrupt as closing this moment carrying out circulation time increase protection mechanism; Cycle index to judgement before open interruption, cancellation protection is so that system clock interrupts being handled.The correctness of twice register system time before and after so promptly can guaranteeing can guarantee that also the process of whole circulation counting is not subjected to extraneous interference.
As shown in Figure 3, be the described CPU processing procedure of the inventive method, at first cycle count zero clearing, the beginning cycle count, and write down current system time; Begin to carry out circulation then, every circulation primary, described cycle count adds 1, arrives until predetermined cycle index; End loop, and the system time during end of record (EOR); The system time that successively obtains subtracted each other obtain circulating the used time, and to be scaled with the timeticks be the time value of unit; Obtain the global cycle execution time after at last this time value being revised according to system overhead.
The described global cycle execution time that correction obtains according to system overhead, be meant shared time of extra process of register system time, switch interrupts protection etc. when whole calculating CPU processing speed.The method of revising is to deduct a value on the execution time in the global cycle that obtains, and this value need be fixed according to the system call processing time of real time operating system, specifically can be with reference to the handbook of this real time operating system.
2, start idle task
The infinite loop of in idle task, carrying out, its recycle design must be when calculating the CPU processing speed recycle design consistent, with the comparability of the cycle index value that guarantees to obtain.As shown in Figure 4, carry out infinite loop during idle task until breaking or the task preemption CPU of high priority.
3, calculate CPU usage
The timing accuracy of system's timed task is according to the needs of system applies and fixed, is traditionally arranged to be in the real-time software Application and Development between 10 milliseconds to 100 milliseconds, and over-burden for then described too soon CPU, does not then meet the requirement of quick response too slowly.Like this, the timing statistics of CPU usage is the multiple of this timing accuracy generally just, by count the calculation level that just can obtain CPU usage, just timing statistics in timed task.
As shown in Figure 5, the inventive method to the calculation process of CPU usage is: when system's timed task was timed to, computing time, counting added 1; Then to whether then detecting computing time, as do not arrive, wait for then that system is regularly thought to be timed to next time; As arrive, then calculate the occupancy of described CPU, then can be by of the comparison of this value with history value, acquisition system operation CPU usage peak value so far.
In order to satisfy the needs of system debug etc., the time of an output CPU usage situation can be set, then the described CPU usage value of information is outputed on the corresponding display device in this time, as printer or display screen.
If the requirement of cycle calculations is arranged, can be after obtaining current C PU occupancy value and peak value, with idle task loop counting variable, the zero clearing of timing statistics variable, so just can the next timed task time then, carry out the calculating of next round by the flow process of Fig. 5.
Should be understood that; the method of detection real time operating system CPU usage of the present invention; in above-mentioned specific embodiment, describe in detail; yet for those of ordinary skills; can carry out various possible improvement or replacement according to technical scheme of the present invention and design thereof, and all these improvement or replacement all should belong to the protection domain of claims of the present invention.

Claims (5)

1, a kind of method that detects the real time operating system CPU usage, it may further comprise the steps:
A) the relevant variable of initialization when system start-up;
B) carry out the CPU processing speed and detect, obtain reference value;
C) start idle task bring into operation infinite loop and record cycle index;
D) the timed task time then, check the calculation level whether arrived described CPU usage, then do not carry out other affairs;
During e) to described CPU usage calculation level, according to following formula:
CPU usage=1000-((global cycle execution time * idle task is carried out cycle index)/(global cycle number of times * timing statistics)) * 1000 calculates described CPU usage.
2, method according to claim 1 is characterized in that, described method comprises that also described system increases protection mechanism at the execution circulation time, closes interruption; Cycle index to judgement before open interruption, cancellation protection is so that system clock interrupts being handled.
3, method according to claim 2 is characterized in that, described CPU usage value can by with the comparison of history value, acquisition system operation CPU usage peak value so far.
4, method according to claim 3 is characterized in that, described system also is provided with the time of an output CPU usage situation, then the described CPU usage value of information is outputed on the corresponding display device in this time.
5, according to the described method of the arbitrary claim of claim 1~4, it is characterized in that the variable that initialization is relevant during described system start-up comprises total cycle time variable, idle task loop counting variable, timing statistics variable, current C PU occupancy value variable and CPU usage peak value variable.
CNB2004100264097A 2004-03-04 2004-03-04 Method for real-time CPU occupation rate detection of operating systems Expired - Fee Related CN1324477C (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CNB2004100264097A CN1324477C (en) 2004-03-04 2004-03-04 Method for real-time CPU occupation rate detection of operating systems

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CNB2004100264097A CN1324477C (en) 2004-03-04 2004-03-04 Method for real-time CPU occupation rate detection of operating systems

Publications (2)

Publication Number Publication Date
CN1664789A true CN1664789A (en) 2005-09-07
CN1324477C CN1324477C (en) 2007-07-04

Family

ID=35035893

Family Applications (1)

Application Number Title Priority Date Filing Date
CNB2004100264097A Expired - Fee Related CN1324477C (en) 2004-03-04 2004-03-04 Method for real-time CPU occupation rate detection of operating systems

Country Status (1)

Country Link
CN (1) CN1324477C (en)

Cited By (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102200943A (en) * 2010-03-25 2011-09-28 腾讯科技(深圳)有限公司 Method and equipment for automatically detecting CPU utilization rate based on background
CN104572414A (en) * 2014-12-23 2015-04-29 深圳市邦彦信息技术有限公司 Method and system for detecting CPU (Central Processing Unit) occupancy rate of vxWorks
CN106708709A (en) * 2015-07-30 2017-05-24 中兴通讯股份有限公司 CPU occupancy rate detection method and device
CN106897203A (en) * 2017-03-29 2017-06-27 北京经纬恒润科技有限公司 A kind of cpu load rate computational methods and device
CN107368402A (en) * 2017-07-10 2017-11-21 中国第汽车股份有限公司 The method for calculating cpu busy percentage
CN112540886A (en) * 2020-11-26 2021-03-23 北京和利时系统工程有限公司 CPU load value detection method and device
CN112559276A (en) * 2019-09-10 2021-03-26 武汉斗鱼网络科技有限公司 CPU utilization monitoring method and device
CN112764934A (en) * 2021-01-29 2021-05-07 上海弘积信息科技有限公司 Method for calculating CPU utilization rate of load balancing equipment

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US4631363A (en) * 1981-06-01 1986-12-23 At&T Bell Laboratories Method and apparatus for incremental load simulation
US4905171A (en) * 1987-11-09 1990-02-27 International Business Machines Corporation Workstation controller performance monitor
JPH0498540A (en) * 1990-08-17 1992-03-31 Nec Corp Processor load monitoring system
DE4425348C1 (en) * 1994-07-18 1995-10-12 Siemens Ag Control of load-shedding procedure of real=time computer
KR100390645B1 (en) * 2001-07-27 2003-07-07 삼성전자주식회사 Method for reducing current in mobile telecommunication terminal system

Cited By (12)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102200943A (en) * 2010-03-25 2011-09-28 腾讯科技(深圳)有限公司 Method and equipment for automatically detecting CPU utilization rate based on background
CN102200943B (en) * 2010-03-25 2014-12-03 腾讯科技(深圳)有限公司 Method and equipment for automatically detecting CPU utilization rate based on background
CN104572414A (en) * 2014-12-23 2015-04-29 深圳市邦彦信息技术有限公司 Method and system for detecting CPU (Central Processing Unit) occupancy rate of vxWorks
WO2016101740A1 (en) * 2014-12-23 2016-06-30 邦彦技术股份有限公司 Method and system for detecting cpu occupancy rate of vxworks
CN106708709A (en) * 2015-07-30 2017-05-24 中兴通讯股份有限公司 CPU occupancy rate detection method and device
CN106897203A (en) * 2017-03-29 2017-06-27 北京经纬恒润科技有限公司 A kind of cpu load rate computational methods and device
CN107368402A (en) * 2017-07-10 2017-11-21 中国第汽车股份有限公司 The method for calculating cpu busy percentage
CN112559276A (en) * 2019-09-10 2021-03-26 武汉斗鱼网络科技有限公司 CPU utilization monitoring method and device
CN112559276B (en) * 2019-09-10 2022-05-13 武汉斗鱼网络科技有限公司 CPU utilization monitoring method and device
CN112540886A (en) * 2020-11-26 2021-03-23 北京和利时系统工程有限公司 CPU load value detection method and device
CN112764934A (en) * 2021-01-29 2021-05-07 上海弘积信息科技有限公司 Method for calculating CPU utilization rate of load balancing equipment
CN112764934B (en) * 2021-01-29 2024-01-30 上海弘积信息科技有限公司 Calculation method for CPU utilization rate of load balancing equipment

Also Published As

Publication number Publication date
CN1324477C (en) 2007-07-04

Similar Documents

Publication Publication Date Title
US8312255B2 (en) System and method for branch misprediction prediction using a mispredicted branch table having entry eviction protection
CN1098487C (en) Method and apparatus for affecting subsequent instruction processing in data processor
US10949260B2 (en) Execution time prediction for energy-efficient computer systems
EP2629197B1 (en) Simulation device, method, and program
Haneda et al. Automatic selection of compiler options using non-parametric inferential statistics
CN1324477C (en) Method for real-time CPU occupation rate detection of operating systems
RU2009109242A (en) METHOD AND DEVICE FOR PERFORMING PROCESSOR INSTRUCTIONS BASED ON DYNAMICALLY VARIABLE DELAY
CN1726469A (en) Processor virtualization mechanism via an enhanced restoration of hard architected states
CN101344865B (en) CPU occupancy rate measuring method and apparatus
CN101876933A (en) Analysis system and method for CPU utilization rate
CN1323412A (en) Scheduling instructions with different latencies
CN1449168A (en) Single line serial interface protocol
US20060190711A1 (en) Method and apparatus for managing a return stack
CN1235142C (en) Embedded sorftware task endless loop monitoring method
CN1877545A (en) Method for testing energy consumption of dynamic software in embedded system simulator
Uzelac et al. Real-time unobtrusive program execution trace compression using branch predictor events
CN1755614A (en) Timer realizing method
CN106598693B (en) Delay strategy-based energy consumption and load sensitive virtual machine integration method
CN1512325A (en) Prediction by using calculating history
CN1740973A (en) A real-time task management and scheduling method
WO2012145997A1 (en) Apparatus for implementing value-associated indirect jump prediction
CN1295614C (en) Testing software timing method
Gottschlag et al. Mechanism to mitigate avx-induced frequency reduction
CN1831756A (en) Microprocessor
CN1508683A (en) Method for detecting occupied rate of CPU in multi-task real-time operation system

Legal Events

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
CF01 Termination of patent right due to non-payment of annual fee

Granted publication date: 20070704

Termination date: 20150304

EXPY Termination of patent right or utility model