CN113419917A - CPU load rate calculation method for tasks and interrupts of embedded operating system - Google Patents
CPU load rate calculation method for tasks and interrupts of embedded operating system Download PDFInfo
- Publication number
- CN113419917A CN113419917A CN202110698191.3A CN202110698191A CN113419917A CN 113419917 A CN113419917 A CN 113419917A CN 202110698191 A CN202110698191 A CN 202110698191A CN 113419917 A CN113419917 A CN 113419917A
- Authority
- CN
- China
- Prior art keywords
- task
- time
- interrupt
- current
- running time
- 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
Links
- 238000004364 calculation method Methods 0.000 title claims abstract description 16
- 238000000034 method Methods 0.000 claims description 13
- 238000010586 diagram Methods 0.000 description 10
- 230000009286 beneficial effect Effects 0.000 description 1
- 230000000694 effects Effects 0.000 description 1
- 238000010998 test method Methods 0.000 description 1
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/30—Monitoring
- G06F11/3003—Monitoring arrangements specially adapted to the computing system or computing system component being monitored
- G06F11/3013—Monitoring arrangements specially adapted to the computing system or computing system component being monitored where the computing system is an embedded system, i.e. a combination of hardware and software dedicated to perform a certain function in mobile devices, printers, automotive or aircraft systems
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/30—Monitoring
- G06F11/3003—Monitoring arrangements specially adapted to the computing system or computing system component being monitored
- G06F11/302—Monitoring arrangements specially adapted to the computing system or computing system component being monitored where the computing system component is a software system
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/30—Monitoring
- G06F11/3051—Monitoring arrangements for monitoring the configuration of the computing system or of the computing system component, e.g. monitoring the presence of processing resources, peripherals, I/O links, software programs
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements 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/46—Multiprogramming arrangements
- G06F9/48—Program initiating; Program switching, e.g. by interrupt
- G06F9/4806—Task transfer initiation or dispatching
- G06F9/4812—Task transfer initiation or dispatching by interrupt, e.g. masked
Abstract
The invention discloses a CPU load rate calculation method for tasks and interrupts of an embedded operating system, which comprises the following steps: (1) running a task/interrupt starting program when the task/interrupt starts to realize task switching in data and update corresponding data; (2) if the task is a CPU load calculation task, a CPU load rate calculation program is also required to be called to calculate the CPU occupancy rates of all tasks/interrupts and the CPU load rate of the core; (3) and before the task/interrupt is finished, a task/interrupt finishing program is required to be called to calculate the running time of the time and the running time after the CPU load rate test, and the longest running time and the shortest running time are updated simultaneously. The invention can acquire the CPU load rate of tasks and interrupts in the multi-core operating system and calculate the longest running time and the shortest running time of the tasks and the interrupts in real time.
Description
Technical Field
The invention relates to the technical field of embedded systems, in particular to a CPU load rate calculation method for tasks and interrupts of an embedded operating system.
Background
An embedded operating system refers to an operating system for embedding. An embedded operating system is a wide range of system software, and generally comprises hardware-related underlying driver software, a system kernel, a device driver interface, a communication protocol and the like. The embedded operating system is responsible for the allocation of all the software and hardware resources of the embedded system, task scheduling, control and coordination of concurrent activities.
The CPU load rate of the embedded operating system is an important index of the embedded system, and the utilization rate of the system to the CPU and the expandability of the system are reflected. In particular, in a multi-core operating system, it is necessary to coordinate the distribution of tasks and interrupts according to the load factor of the CPU.
The current common CPU load rate test method is to count the idle tasks of the operating system and calculate the CPU load rate according to the CPU occupancy rate of the idle tasks. This method can only reflect the entire CPU load rate, and cannot be accurate to the CPU load rate of each task and interrupt. If all tasks and the load rate of the interrupt CPU can be obtained in real time, when the load rate of the CPU has problems, the system is timely enabled to enter a safe state, and the safety of the system can be improved.
Disclosure of Invention
The technical problem to be solved by the present invention is to provide a method for calculating the task and interrupt CPU load rate of an embedded operating system, which can obtain the task and interrupt CPU load rate in a multi-core operating system, and calculate the longest time and the shortest time of the task and interrupt operation in real time.
In order to solve the above technical problem, the present invention provides a method for calculating the CPU load rate of tasks and interrupts of an embedded operating system, comprising the steps of:
(1) running a task/interrupt starting program when the task/interrupt starts to realize task switching in data and update corresponding data;
(2) if the task is a CPU load calculation task, a CPU load rate calculation program is also required to be called to calculate the CPU occupancy rates of all tasks/interrupts and the CPU load rate of the core;
(3) and before the task/interrupt is finished, a task/interrupt finishing program is required to be called to calculate the running time of the time and the running time after the CPU load rate test, and the longest running time and the shortest running time are updated simultaneously.
Preferably, in step (1), the running of the task/interrupt start program when the task/interrupt starts is specifically: turning off interrupts, preventing data access from conflicting with other tasks/interrupts of the same core; setting the starting time of the task as the current time, wherein the time is from a high-precision timer in a controller; setting the suspended task/interrupt number of the task/interrupt as the current task/interrupt number in the core data, and setting the current task/interrupt number in the core data as the task/interrupt number; the current running time of the suspended task/interrupt is increased by the difference value between the current time and the starting time, the test running time of the suspended task/interrupt is increased by the difference value between the current time and the starting time, and the interrupt is opened.
Preferably, in the step (2), if the task is a CPU load calculation task, the CPU load rate calculation program also needs to be called to calculate the CPU occupancy rates of all tasks/interrupts and the CPU load rate of the core specifically includes: turning off interrupts, preventing data access from conflicting with other tasks/interrupts of the same core; acquiring current time, wherein the time is from a high-precision timer in a controller; the test time in the nuclear data is equal to the current time minus the test starting time, the current running time of the task is increased by the difference value between the current time and the starting time of the task, the test running time of the task is increased by the difference value between the current time and the starting time of the task, and the starting time of the task is equal to the current time; calculating that the CPU occupancy rate of all tasks/interrupts is equal to the test running time of the tasks divided by the test running time in the core data; setting the test running time in all task/interrupt data as 0, wherein the CPU load rate is equal to the sum of all non-idle task/interrupt CPU occupancy rates; and setting the test starting time in the core data as the current time, and opening the interrupt.
Preferably, in step (3), a task/interrupt end program needs to be called before the task/interrupt is ended to calculate the current running time and the running time after the CPU load factor test, and the updating the longest running time and the shortest running time at the same time specifically includes: turning off interrupts, preventing data access from conflicting with other tasks/interrupts of the same core; acquiring current time, wherein the time is from a high-precision timer in a controller, the difference between the current time and the starting time is increased for the current running time, if the current running time is longer than the longest running time, the longest running time is set to be equal to the current running time, if the current running time is shorter than the shortest running time, the shortest running time is set to be equal to the current running time, and the difference between the current time and the starting time is increased for the task/interrupted test running time; and setting the current task/interrupt number in the core data to be the suspended task/interrupt number in the task data, setting the starting time in the suspended task/interrupt data to be the current time, and opening the interrupt.
The invention has the beneficial effects that: the invention can calculate the CPU load rate of each task in the embedded operating system and calculate the CPU load rate of each interrupt in the embedded operating system, can be applied to various different embedded operating systems and multi-core embedded operating systems, and has small calculation amount and high efficiency.
Drawings
Fig. 1 is a schematic diagram of the implementation principle of the present invention.
FIG. 2 is a diagram illustrating a non-idle task/interrupt execution process according to the present invention.
FIG. 3 is a diagram illustrating a task/interrupt start procedure according to the present invention.
FIG. 4 is a diagram illustrating a task/interrupt end program execution process according to the present invention.
FIG. 5 is a diagram illustrating the process of executing the CPU load factor calculation program according to the present invention.
Detailed Description
A CPU load rate calculation method for embedded operating system tasks and interrupts comprises the following steps:
(1) running a task/interrupt starting program when the task/interrupt starts to realize task switching in data and update corresponding data;
(2) if the task is a CPU load calculation task, a CPU load rate calculation program is also required to be called to calculate the CPU occupancy rates of all tasks/interrupts and the CPU load rate of the core;
(3) and before the task/interrupt is finished, a task/interrupt finishing program is required to be called to calculate the running time of the time and the running time after the CPU load rate test, and the longest running time and the shortest running time are updated simultaneously.
Fig. 1 shows a schematic diagram of the implementation of the present invention. 1 is the storage space of the controller, which can be the memory media of the on-chip RAM, off-chip RAM, EEPROM, etc. of the single chip. 2 is all data used in the present invention, the data is in units of CPU cores, and each core has an independent block of data. And 3 is data for storing all tasks and interrupts in one CPU core in units of task/interrupt. And 4, the general data of the CPU core is used for recording the running task/interrupt number, the starting time of the CPU load rate test, the running time of the CPU load rate test and the calculated CPU load rate. And 5, data of one task/interrupt, which records the number of the task/interrupt suspended by the task/interrupt, the starting time of the task/interrupt, the running time, the running starting time of the CPU load rate test, the longest running time, the shortest running time and the CPU occupancy rate.
Referring to fig. 2, a schematic diagram of the non-idle task/interrupt execution process according to the present invention is shown, when a task/interrupt starts, a task/interrupt start program is first run, the start time is recorded, and then the task/interrupt program is run. If the task is a CPU load calculation task, a CPU load rate calculation program is also required to be called to calculate the CPU occupancy rates of all tasks/interrupts and the CPU load rate of the core. And before the task/interrupt is finished, a task/interrupt finishing program is required to be called to calculate the running time of the time and the running time after the CPU load rate test, and the longest running time and the shortest running time are updated simultaneously.
Fig. 3 is a schematic diagram of the task/interrupt start program execution process of the present invention, and the main purpose is to implement task switching in data and update corresponding data. Entering the program turns off the interrupt first, preventing data access from conflicting with other tasks/interrupts of the same core. The start time of this task is set to the current time, which may come from a high precision timer in the controller. The suspended task/interrupt number of the task/interrupt is set as the current task/interrupt number in the core data, and the current task/interrupt number in the core data is set as the task/interrupt number. The current running time of the suspended task/interrupt is increased by the difference value between the current time and the starting time, and the test running time of the suspended task/interrupt is increased by the difference value between the current time and the starting time. The interrupt is then turned on and the program is exited.
Fig. 4 is a schematic diagram illustrating the task/interrupt end program execution process of the present invention, and the main purpose is to switch tasks and update related data. Entering the program turns off the interrupt first, preventing data access from conflicting with other tasks/interrupts of the same core. The current time is obtained, which may be from a high precision timer in the controller. And increasing the difference between the current time and the starting time for the current running time, setting the longest running time to be equal to the current running time if the current running time is longer than the longest running time, and setting the shortest running time to be equal to the current running time if the current running time is shorter than the shortest running time. The test run time of the task/interrupt is increased by the difference between the current time and the start time. The current task/interrupt number in the core data is set to the suspended task/interrupt number in this task data. The start time in the suspended task/interrupt data is set to the current time. And opening the interrupt and exiting the program.
Fig. 5 is a schematic diagram of the execution process of the CPU load rate calculation program of the present invention, which is mainly used for calculating the CPU occupancy and CPU load rate of all tasks/interrupts. The entering program first turns off the interrupt, preventing data access from conflicting with other tasks/interrupts of the same core. The current time is obtained, which may be from a high precision timer in the controller. The test time in the core data is equal to the current time minus the test start time. The difference value between the current time and the start time of the task is increased for the current running time of the task, the difference value between the current time and the start time of the task is increased for the test running time of the task, and the start time of the task is equal to the current time. The CPU occupancy to compute all tasks/interrupts is equal to the test run time of the task divided by the test run time in the core data. The test run time in all task/interrupt data is set to 0. The CPU load rate is equal to the sum of all non-idle tasks/interrupt CPU occupancy. And setting the test starting time in the core data as the current time. And opening the interrupt and exiting the program.
Claims (5)
1. A CPU load rate calculation method for embedded operating system task and interrupt is characterized by comprising the following steps:
(1) running a task/interrupt starting program when the task/interrupt starts to realize task switching in data and update corresponding data;
(2) if the task is a CPU load calculation task, a CPU load rate calculation program is also required to be called to calculate the CPU occupancy rates of all tasks/interrupts and the CPU load rate of the core;
(3) and before the task/interrupt is finished, a task/interrupt finishing program is required to be called to calculate the running time of the time and the running time after the CPU load rate test, and the longest running time and the shortest running time are updated simultaneously.
2. The method for calculating the CPU load rate of tasks and interrupts of an embedded operating system according to claim 1, wherein in step (1), running a task/interrupt start program when a task/interrupt starts is specifically: turning off interrupts, preventing data access from conflicting with other tasks/interrupts of the same core; setting the starting time of the task as the current time, wherein the time is from a high-precision timer in a controller; setting the suspended task/interrupt number of the task/interrupt as the current task/interrupt number in the core data, and setting the current task/interrupt number in the core data as the task/interrupt number; the current running time of the suspended task/interruption is increased by the difference value between the current time and the starting time; the test run time of the suspended task/interrupt is increased by the difference between the current time and the start time, and the interrupt is turned on.
3. The embedded os task and interrupted CPU load rate calculation method according to claim 1, wherein in step (2), if the task is a CPU load calculation task, it further needs to invoke a CPU load rate calculation program to calculate the CPU occupancy rates of all tasks/interrupts and the CPU load rate of the core specifically: turning off interrupts, preventing data access from conflicting with other tasks/interrupts of the same core; acquiring current time; the test time in the core data is equal to the current time minus the test start time; the difference value between the current time and the start time of the task is increased in the current running time of the task, the difference value between the current time and the start time of the task is increased in the test running time of the task, and the start time of the task is equal to the current time; calculating that the CPU occupancy rate of all tasks/interrupts is equal to the test running time of the tasks divided by the test running time in the core data; setting the test running time in all task/interrupt data as 0, wherein the CPU load rate is equal to the sum of all non-idle task/interrupt CPU occupancy rates; and setting the test starting time in the core data as the current time, and opening the interrupt.
4. The method for calculating the CPU load rate of tasks and interrupts of an embedded operating system according to claim 1, wherein in step (3), a task/interrupt end program needs to be called before the task/interrupt ends to calculate the current running time and the running time after the CPU load rate test, and the updating of the longest running time and the shortest running time at the same time is specifically: turning off interrupts, preventing data access from conflicting with other tasks/interrupts of the same core; acquiring current time; the difference between the current time and the starting time is increased for the current running time, if the current running time is longer than the longest running time, the longest running time is set to be equal to the current running time, if the current running time is shorter than the shortest running time, the shortest running time is set to be equal to the current running time, and the difference between the current time and the starting time is increased for the task/interrupted test running time; and setting the current task/interrupt number in the core data to be the suspended task/interrupt number in the task data, setting the starting time in the suspended task/interrupt data to be the current time, and opening the interrupt.
5. The embedded operating system task and interrupted CPU load rate calculation method of claim 3 or 4, characterized in that the current time is obtained from a high precision timer in the controller.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202110698191.3A CN113419917A (en) | 2021-06-23 | 2021-06-23 | CPU load rate calculation method for tasks and interrupts of embedded operating system |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202110698191.3A CN113419917A (en) | 2021-06-23 | 2021-06-23 | CPU load rate calculation method for tasks and interrupts of embedded operating system |
Publications (1)
Publication Number | Publication Date |
---|---|
CN113419917A true CN113419917A (en) | 2021-09-21 |
Family
ID=77716318
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202110698191.3A Pending CN113419917A (en) | 2021-06-23 | 2021-06-23 | CPU load rate calculation method for tasks and interrupts of embedded operating system |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN113419917A (en) |
Citations (9)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN1403912A (en) * | 2001-09-06 | 2003-03-19 | Lg电子株式会社 | Method and apparatus for measuring task occupancy of centhal processor in real-time system |
CN101145125A (en) * | 2006-09-11 | 2008-03-19 | 中兴通讯股份有限公司 | Method for measuring task CPU occupancy rate in multitasking operation system |
CN101178688A (en) * | 2007-11-29 | 2008-05-14 | 中兴通讯股份有限公司 | CPU occupancy rate detection method and system of system task |
CN102110043A (en) * | 2010-12-30 | 2011-06-29 | 上海顶竹通讯技术有限公司 | Method and device for computing CPU occupancy rate |
CN103164321A (en) * | 2013-03-20 | 2013-06-19 | 华为技术有限公司 | Occupancy rate measuring method and device of central processing unit |
KR20150002270A (en) * | 2013-06-28 | 2015-01-07 | 삼성전자주식회사 | Method and its apparatus for task load balancing for multicore system |
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 |
CN111427758A (en) * | 2020-03-17 | 2020-07-17 | 北京百度网讯科技有限公司 | Task calculation amount determining method and device and electronic equipment |
-
2021
- 2021-06-23 CN CN202110698191.3A patent/CN113419917A/en active Pending
Patent Citations (9)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN1403912A (en) * | 2001-09-06 | 2003-03-19 | Lg电子株式会社 | Method and apparatus for measuring task occupancy of centhal processor in real-time system |
CN101145125A (en) * | 2006-09-11 | 2008-03-19 | 中兴通讯股份有限公司 | Method for measuring task CPU occupancy rate in multitasking operation system |
CN101178688A (en) * | 2007-11-29 | 2008-05-14 | 中兴通讯股份有限公司 | CPU occupancy rate detection method and system of system task |
CN102110043A (en) * | 2010-12-30 | 2011-06-29 | 上海顶竹通讯技术有限公司 | Method and device for computing CPU occupancy rate |
CN103164321A (en) * | 2013-03-20 | 2013-06-19 | 华为技术有限公司 | Occupancy rate measuring method and device of central processing unit |
KR20150002270A (en) * | 2013-06-28 | 2015-01-07 | 삼성전자주식회사 | Method and its apparatus for task load balancing for multicore system |
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 |
CN111427758A (en) * | 2020-03-17 | 2020-07-17 | 北京百度网讯科技有限公司 | Task calculation amount determining method and device and electronic equipment |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
JP3801630B2 (en) | Fuel injection control method for an internal combustion engine in a vehicle | |
CN106569891B (en) | Method and device for scheduling and executing tasks in storage system | |
CN103389913B (en) | A kind of Real-time Interrupt Processing method for linux system | |
CN104536834A (en) | Method for authorizing lock permission and distributed lock manager | |
JP5379862B2 (en) | Simulation method, system and program | |
EP3327573B1 (en) | Multi-processor and multi-processor system | |
JP4241462B2 (en) | Control unit and microcomputer | |
CN110134504A (en) | A kind of operating system demand layer Formal Modeling and device based on finite state machine | |
US20090113439A1 (en) | Method and Apparatus for Processing Data | |
CN101169737A (en) | Task switching control method and computer system | |
CN103293967A (en) | Multi-task control method for intelligent meter reading terminal | |
CN101770398A (en) | Operating system kernel | |
CN110928657A (en) | Embedded system certainty analysis method | |
CN114327929A (en) | Priority processing method, device, scheduler and multi-core system based on AMP architecture | |
CN113419917A (en) | CPU load rate calculation method for tasks and interrupts of embedded operating system | |
KR100981017B1 (en) | Method for re-defining priority and managing ready queue in system having static task define function and system for executing the method | |
CN116880986A (en) | Task scheduling method and device, vehicle-mounted controller, electronic equipment and storage medium | |
US9618988B2 (en) | Method and apparatus for managing a thermal budget of at least a part of a processing system | |
US7603673B2 (en) | Method and system for reducing context switch times | |
JP2000056989A (en) | Task designing method | |
CN107423206A (en) | A kind of method and device for weighing the system management interrupt time | |
CN109932997B (en) | Programmable logic controller kernel system | |
US6920513B2 (en) | Bus management techniques | |
CN114633705A (en) | Vehicle control device with synchronous drive program | |
KR20190118521A (en) | Method and device for error handling in a communication between distributed software components |
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 |