Thread management method, device and equipment, readable storage medium and vehicle
By detecting and controlling threads with high CPU usage, the system lag problem caused by thread blocking is solved and the smoothness of the vehicle system is improved.
Patent Information
- Application Number
- CN202310313461.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-28
- Publication Date
- 2024-10-01
AI Technical Summary
When the burden on the central processor increases, thread blocking causes the system CPU usage to become unstable, causing system lags, which in turn affects the smoothness of the vehicle system.
By detecting the system CPU usage, the target thread whose thread CPU usage is higher than the threshold is screened out, and when it is in an abnormal state, its CPU usage is controlled within the preset range to avoid thread blocking and occupying system resources.
It effectively avoids excessive system CPU usage caused by thread blocking and improves system fluency and stability.
Smart Images

Figure CN118733233A_ABST
Abstract
Description
Technical Field
[0001] The present application belongs to the field of computer technology, and in particular, relates to a thread management method, device, equipment, readable storage medium and vehicle. Background Art
[0002] In recent years, with the rapid development of computer technology, the requirements for central processing units (CPUs) have become increasingly higher. With the increase in software functions, the burden on the CPU has increased. When a process is abnormal, it is easy for threads to be blocked and occupy system resources, resulting in unstable CPU usage and system freezes. Summary of the invention
[0003] Embodiments of the present application provide a thread management method, apparatus, device, readable storage medium and vehicle to improve the fluency of a vehicle computer system.
[0004] In a first aspect, an embodiment of the present application provides a thread management method, the method comprising:
[0005] When it is detected that the system CPU usage rate of the system within a preset unit time is greater than a first threshold, obtaining the process CPU usage rate of each process in the system within the preset unit time;
[0006] According to the CPU usage rate of the process, a target thread whose thread CPU usage rate is greater than a second threshold is screened out from each of the processes, wherein the process includes at least one thread;
[0007] When the target thread is in an abnormal state, the thread CPU usage rate of the target thread is controlled to be within a preset range.
[0008] In some embodiments, the step of selecting, from each of the processes, target threads whose thread CPU usage is greater than a second threshold according to the process CPU usage, includes:
[0009] Determine the process whose CPU usage is greater than a third threshold as a target process;
[0010] Obtaining the CPU usage of each thread in the target process;
[0011] The thread whose CPU usage is greater than a second threshold is determined as a target thread.
[0012] In some embodiments, before controlling the thread CPU usage of the target thread within a preset range when the target thread is in an abnormal state, the process further includes:
[0013] Obtaining the number of voluntary switching and the number of involuntary switching of the target thread within a second preset unit time;
[0014] When the difference between the voluntary switching number and the involuntary switching number is greater than a fourth threshold, it is determined that the target thread is in an abnormal state.
[0015] In some embodiments, controlling the second usage rate of the target thread to be within a preset range includes:
[0016] Determine the maximum value of the thread CPU usage of the target thread;
[0017] The second usage rate of the target thread is controlled to be less than or equal to the maximum value.
[0018] In some embodiments, obtaining the CPU usage of each process in the system includes:
[0019] Get process CPU data;
[0020] Based on the process CPU data, the process CPU usage of each process of the system is calculated.
[0021] In a second aspect, an embodiment of the present application provides a thread management device, the device comprising:
[0022] A first acquisition module is used to acquire the process CPU usage rate of each process in the system within the preset unit time when it is detected that the system CPU usage rate of the system within the preset unit time is greater than a first threshold;
[0023] A second acquisition module is used to filter out a target thread whose thread CPU usage is greater than a second threshold from each of the processes according to the CPU usage of the process, wherein the process includes at least one thread;
[0024] The control module is used to control the thread CPU usage rate of the target thread to be within a preset range when the target thread is in an abnormal state.
[0025] In a third aspect, an embodiment of the present application provides an electronic device, the device comprising:
[0026] A processor and a memory storing programs or instructions;
[0027] When the processor executes the program or instruction, the method of the first aspect is implemented.
[0028] In a fourth aspect, an embodiment of the present application provides a readable storage medium, on which a program or instruction is stored, and when the program or instruction is executed by a processor, the method of the first aspect described above is implemented.
[0029] In a fifth aspect, an embodiment of the present application provides a vehicle, comprising a thread management device, wherein the thread management device is used to implement the method of the first aspect.
[0030] The thread management method, device, equipment and readable storage medium of the embodiment of the present application can obtain the process CPU usage rate of each process in the system within the preset unit time when it is detected that the system CPU usage rate of the system within the preset unit time is greater than the first threshold; according to the process CPU usage rate, the target thread whose thread CPU usage rate is greater than the second threshold is screened out from each process; when the target thread is in an abnormal state, the thread CPU usage rate of the target thread is controlled to be within a preset range. In this way, it is possible to avoid excessive system CPU usage rate caused by thread blocking and occupying system resources, thereby improving the fluency of the system. BRIEF DESCRIPTION OF THE DRAWINGS
[0031] In order to more clearly illustrate the technical solution of the embodiments of the present application, the following is a brief introduction to the drawings required for use in the embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0032] Figure 1 It is a flowchart of a thread management method provided by an embodiment of the present application;
[0033] Figure 2 is a structural diagram of a thread management device provided by another embodiment of the present application;
[0034] Figure 3 It is a schematic diagram of the structure of an electronic device provided in one embodiment of the present application. DETAILED DESCRIPTION
[0035] The features and exemplary embodiments of various aspects of the present application will be described in detail below. In order to make the purpose, technical solutions and advantages of the present application clearer, the present application will be further described in detail below in conjunction with the accompanying drawings and specific embodiments. It should be understood that the specific embodiments described herein are only intended to explain the present application, rather than to limit the present application. For those skilled in the art, the present application can be implemented without the need for some of these specific details. The following description of the embodiments is only to provide a better understanding of the present application by illustrating the examples of the present application.
[0036] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the statement "include..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0037] Process: refers to an application program running in the system; once a program is running, it is a process; process is the smallest unit of resource allocation. Thread: the basic unit for the system to allocate processor time resources, or a unit execution flow that is independently executed within a process. It is the smallest unit of program execution.
[0038] Thread: It is the smallest unit that the operating system can schedule operations. It is contained in the process and is the actual operation unit in the process. A thread refers to a single sequential control flow in the process. A process can have multiple threads running concurrently, and each thread executes different tasks in parallel.
[0039] The embodiments of the present application provide a thread management method, apparatus, device, storage medium and vehicle for solving the above-mentioned technical problems.
[0040] The following first introduces the thread management method provided in the embodiment of the present application.
[0041] Figure 1 The following is a flow chart of the thread management method provided in the embodiment of the present application. Figure 1 As shown, the following steps S101 to S102 may be included:
[0042] S101, when it is detected that the system CPU usage rate of the system within a preset unit time is greater than a first threshold, obtaining the process CPU usage rate of each process in the system within the preset unit time.
[0043] The system may be an operating system running on any terminal, including but not limited to Android system, Linux system, Microsoft system, etc. The terminal includes but is not limited to a vehicle terminal, a smart phone, a computer, a notebook or a PDA, etc. For example, the system may be a vehicle operating system.
[0044] Each process in the system may include at least one of a system process and a third-party application process, wherein the system process is a process corresponding to an application program that comes with the vehicle system, and the third-party application process is a process corresponding to an application program downloaded from a third party.
[0045] Specifically, first obtain the CPU usage of the monitored object in the current monitoring period, and then compare it with the preset value. If the CPU usage of the system in the preset unit time is greater than the first threshold, it means that the system CPU usage is too high and there may be abnormal threads. Therefore, obtain the CPU usage of each process in the system for the detection of abnormal threads.
[0046] In some embodiments, before S101, the following steps may also be included:
[0047] Get system CPU data;
[0048] Based on the system CPU data, calculate the system CPU usage in the preset unit time.
[0049] Specifically, the system CPU data can be obtained from the system file, and the system CPU usage rate within the preset unit time can be calculated by using the system CPU data within the preset unit time, thereby monitoring the system CPU usage rate.
[0050] In one example, obtaining system CPU data; and calculating the system CPU usage rate of the system within a preset unit time based on the system CPU data may include the following steps:
[0051] Get the / proc / stat file;
[0052] Based on the CPU data in the / proc / stat file, calculate the system CPU usage in the preset unit time.
[0053] Among them, the proc / stat file records the overall statistical information of the system process.
[0054] The CPU data in the / proc / stat file includes at least: user, which indicates the CPU time in user mode; nice, which indicates the CPU time for running low-priority processes; system, which indicates the CPU time in kernel mode; idle, which indicates the idle CPU time; iowait, which indicates the CPU time in IO waiting; irq, which indicates the ratio of hard interrupt time; and sirq, which indicates the ratio of soft interrupt time.
[0055] In this embodiment, the system CPU usage rate of the system within a preset unit time can be calculated through the CPU data in the / proc / stat file, thereby monitoring the system CPU usage rate of the system.
[0056] In some embodiments, the system CPU usage rate of the system within a preset unit time can be calculated as follows:
[0057] The CPU time total_t0 at time t0 is calculated using the following formula (1):
[0058] Total_t0=user_t0+nice_t0+system_t0+idle_t0+iowait_t0+irq_t0+sirq_t0(1)
[0059] Among them, user represents the CPU time in user mode; nice represents the CPU time running low-priority processes; system represents the CPU time in kernel mode; idle represents idle CPU time; iowait represents the CPU time in IO waiting; irq represents hard interrupt time; sirq represents soft interrupt time.
[0060] The system CPU usage rate in the preset unit time (t1 to t2) is calculated by the following formula (2):
[0061] System CPU usage = 100*(total_t2-total_t1-(idle_t2-idle_t1)) / (total_t2-total_t1)(2)
[0062] Among them, total_t1 and total_t2 are the CPU time of the vehicle system at time t1 and t2, which are calculated by the above company (1), and idle_t2 and idle_t1 are the CPU idle time of the system at time t1 and t2.
[0063] Specifically, based on the data obtained from the / proc / stat file, the system CPU usage rate can be calculated using the above formulas (1) and (2).
[0064] In some embodiments, in the above S101, obtaining the CPU usage of each process in the system may include the following steps:
[0065] Get process CPU data;
[0066] Based on the process CPU data, calculate the process CPU usage of each process in the system.
[0067] You can obtain the process CPU data from the system file, and calculate the process CPU usage rate within the preset unit time by using the process CPU data within the preset unit time. In this way, you can monitor the CPU usage rate of each process in the system.
[0068] In one example, obtaining the process usage rate of each process in the vehicle system may include the following steps:
[0069] Get / proc / <pid> / stat file;
[0070] Based on / proc / <pid>The process CPU data in the / stat file is used to calculate the process CPU usage of each process in the system.
[0071] Among them, the proc / pid / stat file is used to save the statistical information of the process, which may include: pid process number; utime, the time the task runs in user mode, in jiffies; stime, the time the task runs in kernel mode, in jiffies; cutime, the accumulated time that all waited-for processes of the task have run in user mode, in jiffies; cstime, the accumulated time that all waited-for processes of the task have run in kernel mode, in jiffies.
[0072] Based on / proc / <pid>The process CPU data in the / stat file is used to calculate the process CPU usage of each process in the system within the preset unit time.
[0073] In some embodiments, the method for calculating the CPU usage of a process may include the following steps:
[0074] The CPU time processCpuTime of the process at time t0 is calculated using the following formula (3):
[0075] processCpuTime_t0= utime_t0 + stime_t0 + cutime_t0 + cstime_t0(3)
[0076] Among them, utime is the time the process runs in user state, stime is the time the process runs in kernel state, cutime is the accumulated time that all waited-for processes of the process have run in user state, and cstime is the accumulated time that all waited-for processes of the process have run in kernel state.
[0077] The CPU usage of the process in the preset unit time is calculated by the following formula (4):
[0078] Process CPU usage = ((processCpuTime_t2-processCpuTime_t1) / (total_t2-total_t1))*100*number of CPU cores (4)
[0079] S102, selecting a target thread from each process according to the CPU usage of the process.
[0080] The thread CPU usage of the target thread is greater than a second threshold, the thread CPU usage is the thread CPU usage of the target thread in a preset unit time, and a process includes at least one thread.
[0081] In some embodiments, the above-mentioned filtering out target threads whose thread CPU usage is greater than a second threshold from each process according to the process CPU usage includes:
[0082] Determine a process whose CPU usage is greater than a third threshold as a target process;
[0083] Get the thread CPU usage of each thread in the target process;
[0084] A thread whose thread CPU usage is greater than a second threshold is determined as a target thread.
[0085] Specifically, after obtaining the process CPU usage rate of each process in the vehicle system within a preset unit time, the process whose process CPU usage rate is greater than the third preset threshold can be determined as the process whose process CPU usage rate exceeds the threshold, that is, the process whose process CPU usage rate is greater than the third preset threshold is determined as the target process, and then the thread CPU usage rate of each thread in the target process is calculated, and the second thread CPU usage rate of each thread is compared with the second preset threshold, so that the thread whose thread CPU usage rate exceeds the threshold can be determined, and the thread whose thread CPU usage rate is greater than the second preset threshold is determined as the target thread.
[0086] In the embodiment, the target process is firstly screened out from the system, and then the target thread is screened out from each thread in the target process, thereby accurately determining the target thread that occupies the CPU exceeding the threshold.
[0087] S103, when the target thread is in an abnormal state, controlling the thread CPU usage of the target thread to be within a preset range.
[0088] In some embodiments, before S103, that is, when the target thread is in an abnormal state, before the thread CPU usage of the target thread is controlled within a preset range, the following steps may also be included:
[0089] Obtain the number of voluntary switching and the number of involuntary switching of the target thread within a second preset unit time;
[0090] In a case where the difference between the voluntary switching number and the involuntary switching number is greater than a fourth threshold, it is determined that the target thread is in an abnormal state.
[0091] The voluntary and involuntary switching times can be obtained from the / proc / pid / tasks / tid / sched file. The number of thread switching times in user / kernel mode is divided into voluntary (voluntary switching) and involuntary (involuntary switching).
[0092] The target thread is a thread in the target process whose thread CPU usage exceeds the second threshold. Therefore, after determining the target thread, it is necessary to determine whether the CPU usage of the target thread is too high because it is in an abnormal state. Therefore, it is necessary to monitor the target thread. Specifically, the number of voluntary switches and the number of involuntary switches of the target thread within the second preset unit time can be obtained first, and then the difference between the number of voluntary switches and the number of involuntary switches is calculated. When the difference is greater than the fourth preset threshold, it means that the target thread has entered an abnormal state, resulting in the target thread's thread CPU usage being too high.
[0093] In this embodiment, whether the target thread is in an abnormal state can be accurately determined by the number of voluntary switching and the number of involuntary switching of the target thread within the second preset unit time.
[0094] In some embodiments, controlling the thread CPU usage of the target thread in S103 to be within a preset range may include the following steps:
[0095] Determine the maximum value of the thread CPU usage of the target thread;
[0096] Control the target thread's CPU usage to be less than or equal to the maximum value.
[0097] The maximum value here is the maximum CPU usage of the abnormal state thread after the abnormal state thread control is pre-set. It can be set according to actual conditions and is not limited in this application.
[0098] Specifically, after determining that the target thread is a thread in an abnormal state, in order to increase the fluency of the system and reduce the CPU usage of the target thread, it is necessary to isolate the target thread and control the CPU usage of the target thread within a preset range.
[0099] In the embodiment of the present application, when it is detected that the system CPU usage rate of the system within a preset unit time is greater than the first threshold, the process CPU usage rate of each process in the system can be obtained; then, at least one target thread in the process whose process CPU usage rate is greater than the second threshold, i.e., the target process, is obtained; when the target thread is in an abnormal state, the thread CPU usage rate of the target thread is controlled to be within a preset range. In this way, when the system CPU usage rate of the system is greater than the first threshold, the thread CPU usage rate of the target thread in the abnormal state can be controlled within a preset range by restricting the target thread in the abnormal state in the system, thereby reducing the system CPU usage when the system CPU usage rate is too high, thereby avoiding excessive system CPU usage rate and improving the fluency of the vehicle system.
[0100] In some embodiments, cgroups may be used to control the thread CPU usage of the target thread to be less than or equal to a maximum value. Cgroups is a mechanism that can limit the resources used by a single process or multiple processes.
[0101] In some embodiments, cpulimit may be used to control the CPU usage of the target thread to be less than or equal to a maximum value. cpulimit is a CPU usage control tool that can control the upper limit of the CPU usage of a thread.
[0102] In one example, the thread management method can be applied to a vehicle computer system, and specifically includes the following steps:
[0103] 1. Get the total CPU of the vehicle computer. If the total CPU exceeds 80%, proceed to the next step. Otherwise, get the total CPU of the system intermittently (that is, when it is detected that the system CPU usage of the vehicle computer system within a preset unit time is greater than the first threshold, get the process CPU usage of each process in the vehicle computer system).
[0104] 2. Get the CPU of all processes. If a single process exceeds 90%, proceed to the next step, otherwise return to the first step (i.e., determine the process whose CPU usage is greater than the third threshold as the target process).
[0105] 3. Get the CPU of all threads of a single process. If the CPU usage of a single thread exceeds 90%, proceed to the next step (i.e., determine the thread whose CPU usage is greater than the second threshold as the target thread).
[0106] 4. Add this thread to the monitoring list. Intermittently obtain / proc / pid / tasks / tid / sched (the number of times the thread switches between user and kernel states, which are divided into voluntary and involuntary switches). Among them, nr_switches is the total number of switches, nr_voluntary_switches is the number of voluntary switches, and nr_involuntary_switches is the number of involuntary switches. If at t2, the increment of nr_involuntary_switches is much larger than nr_voluntary_switches, it is considered that this process has entered a processing procedure similar to a while loop. Then proceed to the next step (that is, when the difference between the number of voluntary switches and the number of involuntary switches is greater than the fourth threshold, it is determined that the target thread is in an abnormal state).
[0107] 5. Create a cgroup isolation group / dev / cpuctl / iso, enter parameters, enter tid into / dev / cpuctl / iso / tasks, enter echo 100000> / dev / cpuctl / iso / cpu.cfs_period_us, echo30000> / dev / cpuctl / iso / cpu.cfs_quota_us, which means to limit the maximum usage of the thread to 30% (that is, control the thread CPU usage of the target thread to be within the preset range: determine the maximum value of the thread CPU usage of the target thread; use cgroups to control the thread CPU usage of the target thread to be less than or equal to the maximum value).
[0108] 6. During the dormant period, clean up the process where the thread is located, kill-9pid. That is, clear the abnormal thread during the dormant period.
[0109] In this embodiment, the process CPU information can be obtained based on monitoring, and the abnormal loop entered in the target thread can be identified based on the process information, the CPU of the target thread can be isolated, and the process can be reset without the user's perception.
[0110] Based on the thread management method provided in the above embodiment, the present application also provides a specific implementation of the thread management device. Please refer to the following embodiment.
[0111] See first Figure 2 The thread management device 200 provided in the embodiment of the present application may include the following modules:
[0112] The first acquisition module 201 is used to acquire the process CPU usage of each process in the system within a preset unit time when it is detected that the system CPU usage of the system within a preset unit time is greater than a first threshold;
[0113] The second acquisition module 202 is used to filter out target threads whose thread CPU usage is greater than a second threshold from each process according to the process CPU usage, and the process includes at least one thread;
[0114] The control module 203 is used to control the thread CPU usage of the target thread to be within a preset range when the target thread is in an abnormal state.
[0115] In some embodiments, the second acquisition module 202 may be specifically used for:
[0116] Determine a process whose CPU usage is greater than a third threshold as a target process;
[0117] Get the thread CPU usage of each thread in the target process;
[0118] A thread whose thread CPU usage is greater than a second threshold is determined as a target thread.
[0119] In some embodiments, the apparatus 200 further includes:
[0120] A determination module, used to obtain the number of voluntary switching and the number of involuntary switching of the target thread within a second preset unit time;
[0121] In a case where the difference between the voluntary switching number and the involuntary switching number is greater than a fourth threshold, it is determined that the target thread is in an abnormal state.
[0122] In some embodiments, the control module 203 is specifically used to:
[0123] Determine the maximum value of the thread CPU usage of the target thread;
[0124] Control the target thread's CPU usage to be less than or equal to the maximum value.
[0125] In some embodiments, the first acquisition module 201 is specifically used to:
[0126] Get process CPU data;
[0127] Based on the process CPU data, calculate the process CPU usage of each process in the system.
[0128] In some embodiments, the second acquisition module 202 is specifically used to:
[0129] Get system CPU data;
[0130] Based on the system CPU data, calculate the system CPU usage in the preset unit time.
[0131] The above-mentioned embodiments of the present application can, when it is detected that the system CPU usage rate of the system within a preset unit time is greater than a first threshold, obtain the process CPU usage rate of each process in the system within the preset unit time; based on the process CPU usage rate, screen out target threads whose thread CPU usage rate is greater than a second threshold from each process; when the target thread is in an abnormal state, control the thread CPU usage rate of the target thread to be within a preset range, thereby avoiding thread blocking and occupying system resources, resulting in excessive system CPU usage rate, and improving the fluency of the system.
[0132] Figure 2 Each module / unit in the device shown has the function of realizing Figure 1 The functions of each step in the process can achieve the corresponding technical effects, which will not be described in detail here for the sake of brevity.
[0133] Based on the thread management device provided in the above embodiment, the present application also provides a vehicle accordingly, the vehicle includes: the above thread management device, the thread management device is used to implement the thread management method provided in the above embodiment.
[0134] Based on the thread management method provided in the above embodiment, the present application also provides a specific implementation method of the electronic device. Please refer to the following embodiment.
[0135] Figure 3 A schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present application is shown.
[0136] The electronic device may include a processor 301 and a memory 302 storing computer program instructions.
[0137] Specifically, the processor 301 may include a central processing unit (CPU), or an application specific integrated circuit (ASIC), or may be configured to implement one or more integrated circuits of the embodiments of the present application.
[0138] The memory 302 may include a large capacity memory for data or instructions. By way of example and not limitation, the memory 302 may include a hard disk drive (HDD), a floppy disk drive, a flash memory, an optical disk, a magneto-optical disk, a magnetic tape, or a universal serial bus (USB) drive or a combination of two or more of these. In one example, the memory 302 may include a removable or non-removable (or fixed) medium, or the memory 402 is a non-volatile solid-state memory. The memory 302 may be inside or outside the integrated gateway disaster recovery device.
[0139] In one example, the memory 302 may be a read-only memory (ROM). In one example, the ROM may be a mask-programmed ROM, a programmable ROM (PROM), an erasable PROM (EPROM), an electrically erasable PROM (EEPROM), an electrically rewritable ROM (EAROM), or a flash memory, or a combination of two or more of these.
[0140] The memory 302 may include a read-only memory (ROM), a random access memory (RAM), a magnetic disk storage medium device, an optical storage medium device, a flash memory device, an electrical, optical or other physical / tangible memory storage device. Thus, typically, the memory includes one or more tangible (non-transitory) computer-readable storage media (e.g., a memory device) encoded with software including computer-executable instructions, and when the software is executed (e.g., by one or more processors), it is operable to perform the operations described with reference to the method according to any embodiment of the present disclosure.
[0141] The processor 301 reads and executes the computer program instructions stored in the memory 302 to implement Figure 1 The method / steps S101 to S104 in the embodiment shown in the figure are achieved Figure 1 The corresponding technical effects achieved by executing the methods / steps in the examples shown are not repeated here for the sake of brevity.
[0142] In one example, the electronic device may further include a communication interface 303 and a bus 310. Figure 3 As shown, the processor 301, the memory 302, and the communication interface 303 are connected via a bus 310 and communicate with each other.
[0143] The communication interface 303 is mainly used to implement communication between various modules, devices, units and / or equipment in the embodiments of the present application.
[0144] Bus 310 includes hardware, software or both, and the components of online data flow billing equipment are coupled to each other. For example, but not limitation, bus may include accelerated graphics port (Accelerated Graphics Port, AGP) or other graphics bus, enhanced industry standard architecture (Extended Industry Standard Architecture, EISA) bus, front side bus (Front Side Bus, FSB), Hyper Transport (Hyper Transport, HT) interconnection, industry standard architecture (Industry Standard Architecture, ISA) bus, infinite bandwidth interconnection, low pin count (LPC) bus, memory bus, micro channel architecture (MCA) bus, peripheral component interconnection (PCI) bus, PCI-Express (PCI-X) bus, serial advanced technology attachment (SATA) bus, video electronics standard association local (VLB) bus or other suitable bus or two or more of these combinations. In appropriate cases, bus 310 may include one or more buses. Although the present application embodiment describes and shows a specific bus, the present application considers any suitable bus or interconnection.
[0145] Based on the thread management device provided in the above embodiment, accordingly, the present application also provides a vehicle, the vehicle comprising: the above thread management device, the thread management device is used to implement the thread management method provided in the above embodiment.
[0146] In addition, in combination with the thread management method in the above embodiment, the embodiment of the present application can provide a computer storage medium for implementation. The computer storage medium stores computer program instructions; when the computer program instructions are executed by a processor, any one of the thread management methods in the above embodiment is implemented.
[0147] In summary, the thread management method, device, vehicle equipment and computer storage medium of the embodiment of the present application, first, when it is detected that the system CPU usage rate of the system in a preset unit time is greater than the first threshold, the process CPU usage rate of each process in the system in the preset unit time is obtained; according to the process CPU usage rate, the target thread whose thread CPU usage rate is greater than the second threshold is screened out from each process; when the target thread is in an abnormal state, the thread CPU usage rate of the target thread is controlled to be within a preset range. When it is detected that the CPU usage rate of the vehicle system in a preset unit time is greater than the first threshold, the first usage rate of each first process in the vehicle system is obtained, the first process is any process in the vehicle system, and the first usage rate is the CPU usage rate of the first process in the preset unit time; at least one target thread in the target process is obtained, the target process is the first process with a first usage rate greater than the second threshold, the second usage rate of the target thread is greater than the third threshold, and the second usage rate is the CPU usage rate of the target thread in the preset unit time; when the target thread is in an abnormal state, the second usage rate of the target thread is controlled to be within a preset range. In this way, it is possible to avoid excessive system CPU usage rate caused by thread blocking and occupying system resources, thereby improving the fluency of the system.
[0148] It should be clear that the present application is not limited to the specific configuration and processing described above and shown in the figures. For the sake of simplicity, a detailed description of the known method is omitted here. In the above embodiments, several specific steps are described and shown as examples. However, the method process of the present application is not limited to the specific steps described and shown, and those skilled in the art can make various changes, modifications and additions, or change the order between the steps after understanding the spirit of the present application.
[0149] The functional blocks shown in the above-described block diagram can be implemented as hardware, software, firmware or a combination thereof. When implemented in hardware, it can be, for example, an electronic circuit, an application-specific integrated circuit (Application Specific Integrated Circuit, ASIC), appropriate firmware, plug-in, function card, etc. When implemented in software, the elements of the present application are programs or code segments used to perform the required tasks. The program or code segment can be stored in a machine-readable medium, or transmitted on a transmission medium or a communication link by a data signal carried in a carrier. "Machine-readable medium" can include any medium capable of storing or transmitting information. Examples of machine-readable media include electronic circuits, semiconductor memory devices, ROM, flash memory, erasable ROM (EROM), floppy disks, CD-ROMs, optical disks, hard disks, optical fiber media, radio frequency (Radio Frequency, RF) links, etc. The code segment can be downloaded via a computer network such as the Internet, an intranet, etc.
[0150] It should also be noted that the exemplary embodiments mentioned in this application describe some methods or systems based on a series of steps or devices. However, this application is not limited to the order of the above steps, that is, the steps can be performed in the order mentioned in the embodiment, or in a different order from the embodiment, or several steps can be performed simultaneously.
[0151] The above reference is according to the method of the embodiment of the present application, the flow chart of the device (system) and the computer program product and / or the block diagram described various aspects of the present application.It should be understood that each square box in the flow chart and / or the block diagram and the combination of each square box in the flow chart and / or the block diagram can be realized by computer program instructions.These computer program instructions can be provided to the processor of a general-purpose computer, a special-purpose computer or other programmable data processing device to produce a machine so that these instructions executed by the processor of the computer or other programmable data processing device enable the realization of the function / action specified in one or more square boxes of the flow chart and / or the block diagram.Such a processor can be but is not limited to a general-purpose processor, a special-purpose processor, a special application processor or a field programmable logic circuit.It can also be understood that each square box in the block diagram and / or the flow chart and the combination of the square boxes in the block diagram and / or the flow chart can also be realized by the dedicated hardware that performs the specified function or action, or can be realized by the combination of dedicated hardware and computer instructions.
[0152] The above is only a specific implementation of the present application. Those skilled in the art can clearly understand that for the convenience and simplicity of description, the specific working processes of the systems, modules and units described above can refer to the corresponding processes in the aforementioned method embodiments, and will not be repeated here. It should be understood that the protection scope of the present application is not limited to this. Any technician familiar with the technical field can easily think of various equivalent modifications or replacements within the technical scope disclosed in this application, and these modifications or replacements should be included in the protection scope of this application.< / pid> < / pid> < / pid>
Claims
1. A thread management method, characterized in that: The method comprises: When it is detected that the system CPU usage rate of the system within a preset unit time is greater than a first threshold, obtaining the process CPU usage rate of each process in the system within the preset unit time; According to the CPU usage rate of the process, a target thread whose thread CPU usage rate is greater than a second threshold is screened out from each of the processes, wherein the process includes at least one thread; When the target thread is in an abnormal state, the thread CPU usage rate of the target thread is controlled to be within a preset range.
2. The method according to claim 1, characterized in that The step of selecting, from each of the processes, target threads whose thread CPU usage is greater than a second threshold according to the process CPU usage, includes: Determine the process whose CPU usage is greater than a third threshold as a target process; Obtaining the CPU usage of each thread in the target process; The thread whose CPU usage is greater than a second threshold is determined as a target thread.
3. The method according to claim 1, characterized in that Before controlling the thread CPU usage of the target thread within a preset range when the target thread is in an abnormal state, the method further includes: Obtaining the number of voluntary switching and the number of involuntary switching of the target thread within a second preset unit time; When the difference between the voluntary switching number and the involuntary switching number is greater than a fourth threshold, it is determined that the target thread is in an abnormal state.
4. The method according to claim 1, characterized in that The controlling the second usage rate of the target thread to be within a preset range includes: Determine the maximum value of the thread CPU usage of the target thread; The second usage rate of the target thread is controlled to be less than or equal to the maximum value.
5. The method according to claim 1, characterized in that The obtaining of the CPU usage of each process in the system includes: Get process CPU data; Based on the process CPU data, the process CPU usage of each process of the system is calculated.
6. The method according to claim 1, characterized in that Before obtaining the process CPU usage of each process in the system when it is detected that the system CPU usage of the system within a preset unit time is greater than a first threshold, the method further includes: Get system CPU data; Based on the system CPU data, a system CPU usage rate of the system within a preset unit time is calculated.
7. A thread management device, characterized in that: The device comprises: A first acquisition module is used to acquire the process CPU usage rate of each process in the system within the preset unit time when it is detected that the system CPU usage rate of the system within the preset unit time is greater than a first threshold; A second acquisition module is used to filter out a target thread whose thread CPU usage is greater than a second threshold from each of the processes according to the CPU usage of the process, wherein the process includes at least one thread; The control module is used to control the thread CPU usage rate of the target thread to be within a preset range when the target thread is in an abnormal state.
8. An electronic device, characterized in that: The device comprises: A processor and a memory storing programs or instructions; When the processor executes the program or the instruction, the method according to any one of claims 1 to 6 is implemented.
9. A readable storage medium, characterized in that: The readable storage medium stores a program or an instruction, and when the program or the instruction is executed by a processor, the method according to any one of claims 1 to 6 is implemented.
10. A vehicle, characterized in that: The vehicle comprises a thread management device, which is used to implement the method according to any one of claims 1 to 6.
Citation Information
Cited By
Processor resource management and control method and system and vehicle-mounted terminal
CN119621336A
