WO2015035870A1 - Multiple cpu scheduling method and device - Google Patents

Multiple cpu scheduling method and device Download PDF

Info

Publication number
WO2015035870A1
WO2015035870A1 PCT/CN2014/085818 CN2014085818W WO2015035870A1 WO 2015035870 A1 WO2015035870 A1 WO 2015035870A1 CN 2014085818 W CN2014085818 W CN 2014085818W WO 2015035870 A1 WO2015035870 A1 WO 2015035870A1
Authority
WO
WIPO (PCT)
Prior art keywords
time
cpu
threads
cpus
running
Prior art date
Application number
PCT/CN2014/085818
Other languages
French (fr)
Chinese (zh)
Inventor
罗治凡
彭钰
陈幼珍
Original Assignee
华为终端有限公司
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 华为终端有限公司 filed Critical 华为终端有限公司
Publication of WO2015035870A1 publication Critical patent/WO2015035870A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F1/00Details not covered by groups G06F3/00 - G06F13/00 and G06F21/00
    • G06F1/26Power supply means, e.g. regulation thereof
    • G06F1/32Means for saving power
    • G06F1/3203Power management, i.e. event-based initiation of a power-saving mode
    • G06F1/3234Power saving characterised by the action undertaken
    • G06F1/329Power saving characterised by the action undertaken by task scheduling
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5027Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/48Program initiating; Program switching, e.g. by interrupt
    • G06F9/4806Task transfer initiation or dispatching
    • G06F9/4843Task transfer initiation or dispatching by program, e.g. task dispatcher, supervisor, operating system
    • G06F9/4881Scheduling strategies for dispatcher, e.g. round robin, multi-level priority queues
    • G06F9/4893Scheduling strategies for dispatcher, e.g. round robin, multi-level priority queues taking into account power or heat criteria
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Definitions

  • the present invention relates to communication technologies, and in particular, to a multi-CPU scheduling method and apparatus.
  • the application of multi-processor technology for example, Symmetrical Multi-Processing (SMP) technology
  • SMP Symmetrical Multi-Processing
  • many terminals adopt multi-processor technology.
  • the image drawing thread is mainly used as a multi-processor of the terminal, which has a great influence on the power consumption of the multi-processor.
  • one drawing thread may jump on different CPUs, which may cause the drawing thread to be affected by other threads on each CPU, making scheduling uneven, which may increase the overall power consumption of the multiprocessor.
  • the embodiment of the invention provides a multi-CPU scheduling method, so that a drawing thread is processed on a running CPU, which can reduce multi-CPU power consumption.
  • a first aspect of the embodiments of the present invention provides a multi-CPU scheduling method, including:
  • the other M-1 drawing threads of the M drawing threads and the other N-1 CPUs of the N running CPUs are acquired;
  • the M-1 is greater than the N-1
  • the one-to-one binding of the N-1 drawing threads is processed on the N-1 running CPUs, and the MN drawing threads are bound to the Processing on MN CPUs on N-1 running CPUs.
  • the method further includes:
  • the maximum drawing time is compared with a time threshold, and the frequency of the N running CPUs is adjusted according to the comparison result.
  • the comparing the maximum drawing time with a time threshold includes:
  • the drawing time is after the frequency of the N running CPUs is decreased, the drawing thread Drawing time
  • the estimated drawing time is compared with a screen refresh time, and if the estimated drawing time is less than the screen refresh time, the frequency of the N running CPUs is decreased.
  • the comparing the maximum mapping time with a time threshold includes:
  • a second aspect of the embodiments of the present invention provides a multi-CPU scheduling apparatus, including:
  • the obtaining module is configured to acquire one of the M drawing threads and one of the N running CPUs, where M is an integer greater than 0, and N is an integer greater than 0;
  • a binding module configured to bind one of the M drawing threads to one CPU of the N running CPUs.
  • the acquiring module is configured to acquire other M-1 drawing threads of M drawing threads and other N-1 CPUs of N running CPUs;
  • the binding module is configured to:
  • the M-1 is greater than the N-1
  • the one-to-one binding of the N-1 drawing threads is processed on the N-1 running CPUs, and the MN drawing threads are bound to the N-1 running CPU M-N CPU processing.
  • the acquiring module is configured to: acquire, among the M drawing threads whose CPU usage is greater than a threshold One drawing thread and/or other M-1 drawing threads of the M drawing threads.
  • the method further includes:
  • a maximum drawing time obtaining module configured to acquire a drawing time of the M drawing threads, compare the M drawing times, and obtain a maximum drawing time thereof;
  • a comparison module configured to compare the maximum drawing time with a time threshold, and adjust a frequency of the N running CPUs according to the comparison result.
  • the comparing module is configured to acquire an estimated drawing time if the maximum drawing time is less than the time threshold
  • the estimated drawing time is a drawing time of the drawing thread after the frequency of the N running CPUs is decreased;
  • the comparing module is configured to compare the estimated drawing time with a screen refresh time
  • an adjustment module configured to reduce a frequency of the N running CPUs if the estimated drawing time is less than the screen refresh time.
  • the comparing module is configured to: when the maximum drawing time is greater than the time threshold, Screen refresh time comparison;
  • the adjusting module is configured to increase a frequency of the N running CPUs if the maximum drawing time is greater than the screen refresh time.
  • the multi-CPU scheduling method provided by the embodiment of the present invention binds one of the M drawing threads to the one by acquiring one of the M drawing threads and one of the N running CPUs. Processing on one of the N running CPUs. Under the premise of not affecting the performance of the system, the resources of each CPU are fully utilized, which can prevent the drawing thread from jumping between CPUs and reduce the power consumption of multiple CPUs.
  • FIG. 1 is a schematic flowchart of a multi-CPU scheduling method according to Embodiment 1 of the present invention
  • 2a is a schematic diagram of a multi-CPU scheduling in the prior art
  • 2b is a schematic diagram showing the effects of the first embodiment and the second embodiment of the multi-CPU scheduling method according to the present invention
  • FIG. 3 is a schematic flowchart of a multi-CPU scheduling method according to Embodiment 1 and Embodiment 2;
  • FIG. 4 is a schematic diagram of CPU usage of a multi-CPU scheduling method according to Embodiment 2 of the present invention.
  • FIG. 5 is a schematic flowchart of a multi-CPU frequency modulation method according to Embodiment 3 of the present invention.
  • FIG. 6 is a schematic diagram showing the effect of a feasible implementation manner of a multi-CPU scheduling method in Embodiment 2 and Embodiment 3 according to the present invention
  • FIG. 7 is a schematic diagram showing a comparison of a feasible implementation manner of a multi-CPU scheduling method according to Embodiment 2 and Embodiment 3 of the present invention.
  • FIG. 8 is a schematic structural diagram of a multi-CPU scheduling apparatus according to Embodiment 4 of the present invention.
  • FIG. 9 is a schematic structural diagram of a multi-CPU scheduling apparatus according to Embodiment 5 of the present invention.
  • FIG. 10 is a schematic structural diagram of a terminal according to Embodiment 6 of the present invention.
  • the process of running the program is called a process, and a process can include one or more threads, where the thread is an operating system capable of scheduling operations.
  • the smallest unit is the actual operating unit in the process.
  • a standard thread consists of a thread ID, a current instruction pointer, a register set, and a stack.
  • One thread can create and revoke another thread, and multiple threads in the same process can execute concurrently.
  • Each program has at least one thread. If the program has only one thread, the thread is the program itself.
  • the drawing thread related to image processing has a very significant influence on the CPU frequency in the terminal device, and the human eye has a visual persistence.
  • the picture is considered to be coherent.
  • the drawing time of the drawing thread is mainly determined by the CPU frequency.
  • Most CPUs of the terminal device will have a higher CPU frequency than the actual working. Therefore, in a terminal device with multiple CPUs, the CPU that needs to process the drawing thread is required.
  • the executor of the first embodiment may be any multi-processor, such as Symmetrical Multi-Processing (Symmetrical Multi-Processing). :SMP), and terminal devices that can process images, such as smartphones, tablets, and the like.
  • the execution entity of the multi-CPU scheduling method may be one CPU of the plurality of CPUs of the terminal device, and may be determined according to a CPU scheduling program. For example, in most CPU operating systems, CPU scheduling is performed according to the priority of the process, the CPU affinity of the process, etc.
  • the CPU scheduler executes the CPU scheduling process at the time of execution, and some operating systems bind the CPU scheduling process to CPU_0.
  • some operating system default CPU scheduling processes can be operated on all CPUs.
  • the CPU affinity can bind the thread to a specified CPU in the multi-CPU for as long as possible, so that the thread does not jump between the CPUs.
  • One of the CPU scheduling processes is based on the CPU affinity of the process. Specifically, the CPU affinity setting of the process can be implemented by using the CPU affinity mask, and the Process Identifier (PID) of a process is used to bind the process corresponding to the PID to a specific process.
  • PID Process Identifier
  • the process is migrated to the specific CPU, and the operation of binding the process to the CPU according to the CPU affinity is implemented. For example, if the CPU affinity of the CPU scheduling process is set to CPU_0 according to the PID, then the CPU scheduling process only operates on CPU_0; if the CPU affinity of the CPU scheduling process defaults to all CPUs, then the CPU scheduling process is also the same. Other threads participate in scheduling, and migration operations can be performed on all CPUs.
  • the multi-CPU scheduling method in the following embodiments of the present invention is implemented by the CPU scheduling process, and the terminal device also assigns a PID to it. The initial CPU affinity of the CPU scheduling process defaults to all CPUs.
  • the embodiment related to CPU frequency adjustment involved in the following embodiments of the present invention is implemented by a CPU frequency modulation program, which is a CPU frequency modulation process when executed, and the CPU frequency modulation process also participates in CPU scheduling. So executed in the CPU In the process, the CPU frequency modulation process also performs operations on the corresponding CPU according to the scheduling result of the CPU scheduling process. If the CPU frequency modulation process sets its own CPU affinity to CPU_0, then the CPU scheduling process will dispatch the CPU frequency modulation process to CPU_0, that is, the CPU frequency modulation process is processed by CPU_0.
  • a multi-CPU scheduling method includes:
  • Step 100 Obtain one of the M drawing threads and one of the N running CPUs, where M is an integer greater than 0, and N is an integer greater than 0.
  • the actual operating unit of the drawing process is a drawing thread.
  • a thread processed by the CPU when a thread calls a terminal device to store and draw.
  • the related function when the related function is used, it can be determined that the thread is a drawing thread.
  • the number M of drawing threads is obtained by acquiring the PID of the drawing thread.
  • the number of running CPUs N the number of running CPUs N can be obtained through a preset program, and the specific program is not limited herein.
  • the running CPU can be the CPU that is processing the thread or the CPU that allows the processing thread.
  • the terminal can be set by the operating system to specify the number of CPUs to be specifically operated. For example, CPU_2 and CPU_3 are not working, that is, the terminal is not processed.
  • the process that the terminal needs to process, and only the CPU_0, CPU_1 to process the process, for this terminal, the running CPU is CPU_0, CPU_1, the number of which is 2.
  • Step 101 Bind one of the M drawing threads to one CPU of the N running CPUs for processing.
  • the solution for binding one of the M drawing threads to one of the N running CPUs may be implemented by setting a CPU affinity of the drawing thread.
  • the drawing thread may be bound to a specific CPU by using the PID of the drawing thread. If the drawing thread is not on the specific CPU at this time, the drawing thread is migrated to the specific CPU, and the CPU is implemented according to the CPU.
  • Affinity binds a process to an operation on the CPU. For example, if the CPU affinity of the drawing thread is set to CPU_0 according to the PID of one of the M drawing threads, the drawing thread operates only on CPU_0.
  • the process of binding one of the M drawing threads to one of the N running CPUs is described below by using a specific example, for example, when the number of drawing threads is 2 , that is, there are drawing thread 1 and drawing thread 2, and the number of running CPUs is 4, including CPU_0, CPU_1, CPU_2, CPU_3, and the drawing thread 1 is bound by setting the CPU affinity of drawing thread 1 to CPU_0.
  • CPU_0 a scheme is implemented in which one of the M drawing threads is bound to one of the N running CPUs. This ensures that other non-drawing threads will not affect CPU_0 processing drawing thread 1, and drawing thread 1 will not migrate between different CPUs, thus reducing the extra due to migration of drawing thread 1 without binding between different CPUs. Power consumption.
  • the multi-CPU scheduling method provided by the embodiment of the present invention obtains one of the M drawing threads and one of the N running CPUs, where M is an integer greater than 0, and N is an integer greater than 0.
  • M is an integer greater than
  • N is an integer greater than 0.
  • One of the M drawing threads is bound to be processed on one of the N running CPUs. Under the premise of not affecting the performance of the system, avoiding the migration of the drawing thread on multiple running CPUs causes additional power consumption, thereby reducing the overall power consumption of the multiple CPUs.
  • the remaining M-1 drawing threads perform similar binding processing.
  • the following describes the binding method of the remaining M-1 drawing threads through the second embodiment:
  • Case 3 When the M-1 is greater than the N-1, the N-1 drawing threads are bound one to one. Processing on the N-1 running CPUs, and M-N drawing threads are bound to the M-N CPUs on the N-1 running CPUs for processing.
  • the drawing thread 2 is bound to any one of CPU_1, CPU_2, and CPU_3, and If the drawing thread 2 is bound to CPU_1, preferably, the CPU affinity of other non-drawing threads is set to CPU_2 or CPU_3, that is, other non-drawing threads can be processed on CPU_2 or CPU_3, which has the advantage of avoiding other non- The drawing thread is migrated to CPU_1 to avoid affecting CPU_1 processing drawing thread 2, thereby reducing the CPU power consumption of multiple running groups as a whole.
  • the number of drawing threads is 4, that is, there are drawing thread 1, drawing thread 2, drawing thread 3, drawing thread 4, and the number of running CPUs is 4, including CPU_0, CPU_1, CPU_2, CPU_3, among them.
  • the thread is bound to CPU_1, for example, the drawing thread 2 is bound to CPU_1, and the drawing thread 3, the drawing thread 4, and other non-drawing threads are processed on the corresponding CPU according to their initial CPU affinity, here Not limited.
  • FIG. 2a is a schematic diagram of a multi-CPU scheduling in the prior art, as shown in FIG. 2a.
  • the terminal device migrates the threads between multiple CPUs through thread scheduling to achieve equalization of the CPU usage.
  • the prior art thread migration scheme cannot effectively achieve the CPU usage balance, and when the CPU is When the workload is heavy, multiple migration threads will increase the CPU workload and CPU cache utilization will decrease.
  • FIG. 2b is a schematic diagram of the effect of the first embodiment and the second embodiment of the multi-CPU scheduling method provided by the present invention.
  • the M drawing threads are obtained according to the number M of drawing threads and the number of CPUs running N.
  • One of the drawing thread bindings is processed on one of the N running CPUs.
  • the drawing thread does not migrate between multiple CPUs.
  • other M-1 drawing threads of M drawing threads and other N-1 CPUs of N running CPUs are acquired.
  • the thread numbers in Figure 2b are: 1, 2, 3, 4 of four drawing threads.
  • the four drawing threads are not migrated, so that the drawing threads that have a greater influence on the CPU frequency can be evenly distributed on different CPUs, ensuring that one CPU is not bound to other CPUs.
  • the effect of the drawing thread, for each drawing thread bound on the CPU the CPU is more efficient at processing the drawing thread bound to it.
  • the overall frequency requirement of the multi-CPU of the terminal device can be down-regulated, thereby reducing the power consumption of the terminal device.
  • one possible determining manner of the number M of drawing threads in the first embodiment and the second embodiment is: acquiring one of the M drawing threads whose CPU usage is greater than a threshold and/or the M The other M-1 drawing threads of the drawing thread. For example, if the current multi-CPU processes a total of 7 drawing threads, and the number of drawing threads whose CPU usage is greater than the threshold is 4, then M is 4.
  • FIG. 3 is a schematic flowchart diagram of the multi-CPU scheduling method according to the first embodiment and the second embodiment.
  • the drawing thread becomes heavy, and the condition for deciding whether or not to perform the CPU frequency adjustment can be a heavy task. Therefore, the thread cumbersomeness can be determined by obtaining the CPU usage of the drawing thread.
  • the CPU usage of the drawing thread is changed from the CPU usage threshold (abbreviation: threshold) to less than the CPU usage threshold (referred to as: If the threshold is greater than the CPU usage threshold, the number of drawing threads whose CPU usage is greater than the threshold and the number of running CPUs are obtained.
  • a preferred implementation manner is as follows: when the CPU usage of the drawing thread is changed from the CPU usage threshold to the CPU usage threshold, or the CPU usage threshold is greater than the CPU usage threshold.
  • An identifier is added to the drawing thread in which the above two cases occur, and the number M of drawing threads larger than the threshold is determined by the identifier.
  • the threshold is a preset decimal number. Since the CPU model and operating system used by different terminal devices are different, the specific value of the threshold can be set according to different CPU models and operating systems. limited.
  • the execution body of the CPU scheduling method may be one of a plurality of CPUs of the terminal device, and may be determined according to a CPU scheduler.
  • one possible implementation manner includes:
  • Step 100a If the CPU usage of the drawing thread changes from less than the threshold to greater than the threshold, or if the CPU usage of the drawing thread changes from greater than the threshold to less than the threshold, acquiring the M drawing threads whose CPU usage is greater than the threshold One drawing thread and/or other M-1 drawing threads of the M drawing threads and N running CPUs.
  • calculating the CPU usage of all the drawing threads comparing the CPU usage of all the drawing threads with the threshold, when the CPU usage of the drawing thread changes from less than the threshold to greater than the threshold, or the CPU usage of the drawing thread
  • the operation of acquiring the number M of the drawing threads whose CPU usage is greater than the threshold value and the number of running CPUs N is obtained, and further, the M drawing threads have been After a drawing thread binding is processed on one of the N running CPUs, the obtained M is decremented by one.
  • the number of drawing threads M is reduced by K, and the drawing thread binding strategy is determined according to the MK drawing threads; or, if K drawing threads are If the CPU usage changes from less than the threshold to greater than the threshold, the number of drawing threads is increased by M. K, determine the drawing thread binding strategy according to M+K drawing threads.
  • the K value is an integer greater than or equal to zero, and if the CPU usage of the K drawing threads changes from greater than the threshold to less than the threshold, the K value must be less than or equal to an integer of the M value.
  • the embodiment of the present invention expresses the heavyness of the thread by the CPU usage of the thread.
  • Each CPU can identify the executing thread, and calculate the execution time of the thread on the CPU for a period of time.
  • the execution time is longer than the total time to obtain the CPU usage of the thread, namely:
  • the total time is the sum of the times of n clock cycles of the CPU, where n is an integer greater than zero; and the threshold in the above is a preset decimal number, which is used for CPU usage with one thread.
  • the threshold can be set to 0.6.
  • the CPU usage of a drawing thread is calculated to be 0.7, it is obvious that the CPU usage of the drawing thread is greater than the threshold, indicating that the drawing thread is heavy.
  • the CPU usage of a thread is less than the threshold, it indicates that the thread is less heavy.
  • FIG. 4 is a schematic diagram of CPU usage of a multi-CPU scheduling method according to Embodiment 2 of the present invention. As shown in FIG. 4, taking two running CPUs (CPU_0, CPU_1) as an example, CPU_1 and CPU_1 run thread 1 and thread. 2 and thread 3, wherein the CPU usage of the thread 1 during the time T (n clock cycles) is calculated, and the terminal device is uniformly based on a CPU, and then:
  • t1 and t3 represent the execution time of the thread 1 on the CPU_0
  • t3 represents the execution time of the thread 1 on the migration to the CPU_1.
  • the CPU usage calculation method of the drawing thread is similar. For example: If the threshold is 0.3. There are 4 drawing threads, wherein: the CPU usage of drawing thread 1 is 0.8, the CPU usage of drawing thread 2 is 0.35, the CPU usage of drawing thread 3 is 0.3, and the CPU usage of drawing thread 4 is 0.1. Therefore, the CPU usage of two drawing threads 1 and 2 exceeds the threshold of 0.3, and then the value of M is 2.
  • the following may occur: a. Create a thread or delete a thread, then judge the created new thread or delete the created thread. Whether the thread is a drawing thread, and if so, the value of M is updated; b.
  • the number of drawing threads is dynamically calculated, if the CPU usage of the drawing thread whose previous CPU usage has not changed has changed, then if the drawing thread of the drawing thread changes If the occupancy rate changes from greater than the threshold to less than the threshold, then M-1, if the occupancy rate of the drawing thread changes from less than the threshold to greater than the threshold, then M+1; if the number of running CPUs changes, reacquire N .
  • the method further includes:
  • Step 102 Obtain other M-1 drawing threads of the M drawing threads and other N-1 CPUs of the N running CPUs, and determine a drawing thread binding policy according to the M-1 and the N-1.
  • the drawing thread binding policy may include at least the following three cases:
  • Case 1 When the M-1 is smaller than the N-1, the one-to-one binding of the M-1 drawing threads is processed on the M-1 running CPUs.
  • the non-drawing thread may be set to be processed by N-M running CPUs on N-M running CPUs.
  • Case 2 When the M-1 is equal to the N-1, the one-to-one binding of the M-1 drawing threads is processed on the N-1 running CPUs. Additionally, preferably, the non-drawing thread may be in an initial affinity state.
  • Case 3 When the M-1 is greater than the N-1, the one-to-one binding of the N-1 drawing threads is processed on the N-1 running CPUs, and the MN drawing threads are bound. Processing on MN CPUs on the N-1 running CPUs. Additionally, preferably, the non-drawing thread may be in an initial affinity state.
  • Step 103 Bind the M-1 drawing threads one-to-one to the N-1 CPUs for processing according to a drawing thread binding policy.
  • the M-1 drawing threads are bound one-to-one on the N-1 CPUs for processing.
  • the method further includes:
  • Step 104 Obtain one of the M drawing threads whose CPU usage is greater than a threshold and/or other M-1 drawing threads of the M drawing threads.
  • Step 105 Obtain a drawing time of the M drawing threads, and compare the M drawing times to obtain a maximum drawing time.
  • the drawing thread of the CPU process when the drawing thread of the CPU process is drawn, the drawing thread will call the drawing function, and the time required for the drawing function operation is the drawing time.
  • a feasible way to obtain the drawing time is to draw a point at the beginning and end of the drawing function, obtain the start and end time, and then calculate the time difference between the end of the drawing and the start to get the drawing time.
  • Step 106 Compare the maximum drawing time with a time threshold.
  • Step 107 Obtain an estimated drawing time.
  • the estimated drawing time is the drawing time of the drawing thread after the frequency of the N running CPUs is lowered by one level.
  • the estimated drawing time can be obtained by the following formula (1):
  • Estimated plot time maximum plot time ⁇ current CPU frequency / small first-level CPU frequency (1)
  • the estimated drawing time is calculated by the formula (1) for the maximum drawing time of the M drawing times, and the estimated drawing time is the estimated drawing thread having the maximum drawing time.
  • reducing the frequency of the CPU operating at one level is to reduce the frequency as a whole for the frequencies of the N operating CPUs. For example, before reducing the running CPU frequency, the N running CPU frequencies are all 800MHZ. After reducing the CPU frequency of the first-level operation, the N running CPU frequencies are all 600MHZ.
  • Step 108 Compare the estimated drawing time with the screen refresh time. If the estimated drawing time is less than the screen refresh time, reduce the frequency of the N running CPUs.
  • the operating CPU frequency is lowered.
  • the maximum drawing time is continued at the time threshold.
  • the CPU frequency adjustment is not required until the time threshold ⁇ maximum drawing time ⁇ screen refresh time is satisfied.
  • the maximum drawing time is 11ms, at which time the CPU frequencies of N running are 800MHZ, and the CPU frequency of the smaller one is 600MHZ (requires description, N runs)
  • the CPU frequency is still at 800 MHz.
  • the estimated plot time calculated according to formula (1) is about 15 ms.
  • the screen refresh time Tr is 16.6 ms.
  • the estimated plot time is 15 ms.
  • the screen refresh time Tr16.6ms reduces the frequency of N running CPUs by one level.
  • the frequency of the N running CPUs is lowered from 800 MHz to 600 MHz.
  • the drawing time is reacquired, and the operations of the above steps 105 to 108 are repeated until the time threshold ⁇ maximum drawing time ⁇ screen refresh time is satisfied, and the CPU frequency adjustment is not required.
  • the maximum drawing time is 14 ms, at which time the CPU frequencies of N running are 800 MHz, and the CPU frequency of the smaller one is 600 MHz (required, N runs)
  • the CPU frequency is still at 800 MHz.
  • the estimated plot time calculated according to formula (1) is about 18 ms.
  • the screen refresh time Tr is 16.6 ms.
  • the plot time > screen refresh time Tr16 is estimated. 6ms, obviously, if the CPU frequency is lowered by one level at this time, the image file displayed by the terminal device will be stuck. Then even if the current maximum drawing time of 14ms is less than the time threshold, the N CPU frequencies can not be adjusted to 600MHZ, but remain 800MHZ.
  • Step 109 Compare the maximum drawing time with the screen refresh time. If the maximum drawing time is greater than the screen refresh time, the frequency of the N running CPUs is increased.
  • the N running CPUs may be The frequency is increased by one level, so that the drawing time can be reduced at a higher CPU frequency, and the condition that the drawing time is less than the screen refresh time is satisfied, thereby avoiding the occurrence of image jamming.
  • the embodiment related to CPU frequency adjustment involved in this embodiment may be implemented by a CPU frequency modulation program.
  • FIG. 5 is provided in Embodiment 3 of the present invention.
  • Step 200 Obtain drawing time of M drawing threads, and compare M drawing times to obtain a maximum drawing time, where M is an integer greater than 0.
  • Step 201 Compare the maximum drawing time with a time threshold.
  • Step 202 Obtain an estimated drawing time.
  • the method for obtaining the estimated drawing time is referred to the second embodiment, and details are not described herein again.
  • Step 203 Compare the estimated drawing time with the screen refresh time. If the estimated drawing time is less than the screen refresh time, reduce the frequency of the N running CPUs.
  • step 203 if the estimated drawing time is less than the screen refresh time, the frequency of the N running CPUs is lowered, so that when the user is guaranteed to view the image, there is no feeling of stuttering, and the power consumption of the multiple CPUs can also be reduced.
  • Step 204 Compare the maximum drawing time with the screen refresh time. If the maximum drawing time is greater than the screen refresh time, increase the frequency of the N running CPUs.
  • Step 204 is adopted. If the maximum drawing time is greater than the screen refresh time, the frequency of the N running CPUs is increased, so that the user does not feel stuck when viewing the image.
  • FIG. 6 is a schematic diagram showing the effect of a feasible implementation manner of the multi-CPU scheduling method in the second embodiment and the third embodiment
  • FIG. 7 is a second embodiment of the present invention.
  • a comparison diagram of a feasible implementation manner of the multi-CPU scheduling method in the third embodiment referring to FIG. 6, where T1 is the drawing time of one drawing thread, and T2 is the screen refresh time of the CPU processing the drawing thread, by adopting the present
  • T1 is the drawing time of one drawing thread
  • T2 is the screen refresh time of the CPU processing the drawing thread
  • the CPU frequency is as shown in the waveform of the CPU frequency (solid line) for which the CPU frequency is not adjusted, and the CPU frequency waveform (dotted line) after the CPU frequency adjustment processing is obviously flatter.
  • the resource utilization of the CPU frequency is also more sufficient, and the CPU frequency resource is not wasted.
  • the frequency of the CPU after the CPU frequency adjustment processing is not going to be high or low, and most of the time is kept at a lower frequency, and the CPU frequency adjustment processing is performed. Does not affect the refresh frame rate of the screen. It can be seen from these two diagrams that the screen refresh CPU frequency modulation scheme can reduce the idle time of the CPU without affecting the system performance (the screen refresh rate is unchanged), make full use of the CPU resources, and enable the CPU to work more often. At lower frequencies.
  • the number M of drawing threads may be the number of drawing threads whose CPU usage is greater than the CPU occupancy threshold in all drawing threads.
  • FIG. 8 is a schematic structural diagram of a multi-CPU scheduling apparatus according to Embodiment 4 of the present invention. As shown in FIG. 8, the multi-CPU scheduling apparatus includes: an obtaining module 10 and a binding module 11.
  • the obtaining module 10 is configured to acquire one of the M drawing threads and one of the N running CPUs, where M is an integer greater than 0, and N is an integer greater than 0.
  • the binding module 11 is configured to bind one of the M drawing threads to one CPU of the N running CPUs.
  • the binding module 11 implements a scheme of binding the drawing threads one-to-one on each CPU for processing by setting the CPU affinity of the drawing thread.
  • the CPU affinity has been described in detail in the first embodiment, and details are not described herein again.
  • the multi-CPU scheduling method acquires the number of drawing threads and the number of running CPUs by the acquiring module, and then the binding module according to the number of drawing threads and the number of running CPUs, when the drawing threads When the number is less than or equal to the number of running CPUs, each drawing thread is bound one-to-one on each running CPU for processing. Under the premise of not affecting the performance of the system, the resources of each CPU are fully utilized, so that the multi-CPU of the terminal device works at a lower frequency as a whole, thereby reducing power consumption.
  • the obtaining module 10 is further configured to acquire other M-1 drawing threads of the M drawing threads and other N-1 CPUs of the N running CPUs.
  • the binding module 11 is configured to bind the M-1 drawing threads one-to-one to the M-1 running CPUs when the M-1 is smaller than the N-1. Processed on; or
  • the M-1 is greater than the N-1
  • the one-to-one binding of the N-1 drawing threads is processed on the N-1 running CPUs, and the MN drawing threads are bound to the Processing on MN CPUs on N-1 running CPUs.
  • the obtaining module 10 is further configured to: acquire one of the M drawing threads whose CPU usage is greater than a threshold, and/or other M-1 drawing threads of the M drawing threads.
  • FIG. 9 is a schematic structural diagram of a multi-CPU scheduling apparatus according to Embodiment 5 of the present invention, as shown in FIG.
  • the CPU scheduling device further includes: a maximum drawing time acquiring module 12, a comparing module 13, and an adjusting module 14.
  • a maximum drawing time obtaining module 12 configured to acquire a drawing time of the M drawing threads, and The M plot times are compared to obtain the maximum plot time.
  • step 102 of the foregoing embodiment 2 how to obtain the drawing time of the drawing thread and how to obtain the maximum drawing time are described in detail, and details are not described herein again.
  • the comparison module 13 is configured to compare the maximum drawing time with a time threshold.
  • the comparison module 13 is configured to compare the maximum drawing time with a time threshold, and adjust the frequency of the N running CPUs according to the comparison result.
  • the time threshold is described in detail in step 103 of Embodiment 2 above, and the estimated drawing time is obtained by the above formula (1), and details are not described herein again.
  • the comparing module 13 is further configured to: if the maximum drawing time is less than the time threshold, obtain an estimated drawing time;
  • the comparison module 13 is configured to compare the estimated drawing time with a screen refresh time.
  • the adjustment module 14 is configured to reduce the frequency of the N running CPUs if the estimated drawing time is less than the screen refresh time.
  • the frequency may be reduced overall for the frequencies of the N CPUs.
  • the comparison module 13 is further configured to compare the maximum drawing time with the screen refresh time if the maximum drawing time is greater than the time threshold.
  • the adjustment module 14 is configured to increase the frequency of the N running CPUs if the maximum drawing time is greater than the screen refresh time. For example, the frequency of N running CPUs can be increased by one level.
  • the frequency of the N running CPUs can be increased by one level, thereby making the CPU higher. At the frequency, the drawing time can be reduced to meet the condition that the drawing time is less than the screen refresh time, thereby avoiding the occurrence of image jamming.
  • Embodiment 6 of the present invention provides a terminal, which can be used to perform Embodiment 1 to Embodiment 3 of the present invention.
  • FIG. 10 is a schematic structural diagram of a terminal according to Embodiment 6 of the present invention
  • FIG. 10 is a schematic structural diagram of a terminal 500 according to Embodiment 6 of the present invention.
  • the terminal may be a terminal device including a mobile phone, a tablet computer, a PDA (Personal Digital Assistant), a POS (Point of Sales), an in-vehicle computer, etc., and the terminal is a mobile phone as an example, and FIG. 10 shows A block diagram of a partial structure of a mobile phone 500 related to a terminal provided by an embodiment of the present invention.
  • the mobile phone 500 includes an RF (Radio Frequency) circuit 510, a memory 520, an input unit 530, a display unit 540, a sensor 550, an audio circuit 560, a WiFi (Wireless Fidelity) module 570, and a processor 580. And power supply 590 and other components.
  • RF Radio Frequency
  • the structure of the mobile phone shown in FIG. 10 is only an example of implementation, and does not constitute a limitation on the mobile phone, and may include more or less components than those illustrated, or combine some components, or Different parts are arranged.
  • the components of the mobile phone 500 will be specifically described below with reference to FIG. 10:
  • the RF circuit 510 can be used for receiving and transmitting signals during and after the transmission or reception of information, in particular, after receiving the downlink information of the base station, and processing it to the processor 580; in addition, transmitting the uplink data to the base station.
  • RF circuits include, but are not limited to, an antenna, at least one amplifier, a transceiver, a coupler, an LNA (Low Noise Amplifier), a duplexer, and the like.
  • RF circuitry 510 can also communicate with the network and other devices via wireless communication.
  • the wireless communication may use any communication standard or protocol, including but not limited to GSM (Global System of Mobile communication), GPRS (General Packet Radio Service), CDMA (Code Division Multiple Access). , Code Division Multiple Access), WCDMA (Wideband Code Division Multiple Access), LTE (Long Term Evolution), e-mail, SMS (Short Messaging Service), and the like.
  • the memory 520 can be used to store software programs, and the processor 580 executes various functional applications and data processing of the mobile phone 500 by running software programs stored in the memory 520.
  • the memory 520 may mainly include a storage program area and a storage data area, wherein the storage program area may store an operating system, an application required for at least one function (such as a sound playing function, an image playing function, etc.), and the like;
  • the data area can store data (such as audio data, phone book, etc.) created according to the use of the mobile phone 500.
  • memory 520 can include high speed random access memory, and can also include non-volatile memory, such as at least one magnetic disk storage device, flash memory device, or other volatile solid state storage device.
  • the input unit 530 can be configured to receive input numeric or character information and to generate key signal inputs related to user settings and function control of the handset 500.
  • the input unit 530 may include a touch panel 531 and other input devices 532.
  • the touch panel 531 also referred to as a touch screen, can collect touch operations on or near the user (such as the user using a finger, a stylus, or the like on the touch panel 531 or near the touch panel 531. Operation), and drive the corresponding connecting device according to a preset program.
  • the touch panel 531 can include two parts: a touch detection device and a touch controller.
  • the touch detection device detects the touch orientation of the user, and detects a signal brought by the touch operation, and transmits the signal to the touch controller; the touch controller receives the touch information from the touch detection device, converts the touch information into contact coordinates, and sends the touch information.
  • the processor 580 is provided and can receive commands from the processor 580 and execute them.
  • the touch panel 531 can be implemented in various types such as resistive, capacitive, infrared, and surface acoustic waves.
  • the input unit 530 may also include other input devices 532. Specifically, other input devices 532 may include, but are not limited to, one or more of a physical keyboard, function keys (such as volume control buttons, switch buttons, etc.), trackballs, mice, joysticks, and the like.
  • the display unit 540 can be used to display information input by the user or information provided to the user and various menus of the mobile phone 500.
  • the display unit 540 can include a display panel 541.
  • the display panel 541 can be configured in the form of an LCD (Liquid Crystal Display), an OLED (Organic Light-Emitting Diode), or the like.
  • the touch panel 531 can cover the display panel 541. When the touch panel 531 detects a touch operation on or near it, the touch panel 531 transmits to the processor 580 to determine the type of the touch event, and then the processor 580 according to the touch event. The type provides a corresponding visual output on display panel 541.
  • the touch panel 531 and the display panel 541 are two independent components to implement the input and input functions of the mobile phone 500, in some embodiments, the touch panel 531 can be integrated with the display panel 541. And realize the input of the mobile phone 500 and Output function.
  • the handset 500 can also include at least one type of sensor 550, such as a light sensor, motion sensor, and other sensors.
  • the light sensor may include an ambient light sensor and a proximity sensor, wherein the ambient light sensor may adjust the brightness of the display panel 541 according to the brightness of the ambient light, and the proximity sensor may close the display panel 541 when the mobile phone 500 moves to the ear. / or backlight.
  • the accelerometer sensor can detect the magnitude of acceleration in all directions (usually three axes). When it is stationary, it can detect the magnitude and direction of gravity. It can be used to identify the gesture of the mobile phone (such as horizontal and vertical screen switching, related Game, magnetometer attitude calibration), vibration recognition related functions (such as pedometer, tapping), etc.
  • the mobile phone 500 can also be configured with gyroscopes, barometers, hygrometers, thermometers, infrared sensors and other sensors, here Let me repeat.
  • Audio circuit 560, speaker 561, and microphone 562 can provide an audio interface between the user and handset 500.
  • the audio circuit 560 can transmit the converted electrical data of the received audio data to the speaker 561, and convert it into a sound signal output by the speaker 561.
  • the microphone 562 converts the collected sound signal into an electrical signal, and the audio circuit 560 is used by the audio circuit 560. After receiving, it is converted into audio data, and then processed by the audio data output processor 580, sent to the other mobile phone via the RF circuit 510, or outputted to the memory 520 for further processing.
  • WiFi is a short-range wireless transmission technology
  • the mobile phone 500 can help users to send and receive emails, browse web pages, and access streaming media through the WiFi module 570, which provides wireless broadband Internet access for users.
  • FIG. 10 shows the WiFi module 570, it can be understood that it does not belong to the essential configuration of the mobile phone 500, and may be omitted as needed within the scope of not changing the essence of the invention.
  • Processor 580 is the control center of handset 500, which connects various portions of the entire handset using various interfaces and lines, by running or executing software programs and/or modules stored in memory 520, and recalling data stored in memory 520, The various functions and processing data of the mobile phone 500 are performed to perform overall monitoring of the mobile phone.
  • the processor 580 may include one or more processing units; preferably, the processor 580 may integrate an application processor and a modem processor, where the application processes The main processing system, user interface and applications, etc., the modem processor mainly deals with wireless communication. It will be appreciated that the above described modem processor may also not be integrated into the processor 580.
  • the handset 500 also includes a power source 590 (such as a battery) that supplies power to the various components.
  • a power source 590 such as a battery
  • the power source can be logically coupled to the processor 580 via a power management system to manage functions such as charging, discharging, and power management through the power management system.
  • the mobile phone 500 may further include a camera, a Bluetooth module, and the like, and details are not described herein again.
  • the terminal includes a processor 580 having the following functions:
  • the processor 580 is configured to acquire one of the M drawing threads and one of the N running CPUs, where M is an integer greater than 0, and N is an integer greater than 0.
  • the processor 580 is one of the multi-processors.
  • the possible implementation manners of obtaining the number M of the drawing threads and the number of running CPUs N have been described in detail in the first embodiment, and are not described herein again.
  • the processor 580 is configured to bind one of the M drawing threads to one CPU of the N running CPUs.
  • the processor 580 implements a scheme of binding one of the M drawing threads to one of the N running CPUs by setting a CPU affinity of the drawing thread.
  • the CPU affinity has been described in detail in the first embodiment, and details are not described herein again.
  • the memory 520 included in the terminal has the following functions: a CPU scheduler, a CPU frequency modulation program, and a drawing-related function stored in the present invention, in preparation for the processor to run the CPU scheduling process, and the CPU. Called when the FM process and the drawing thread.
  • the multi-CPU scheduling method acquires the number of drawing threads and the number of running CPUs by the processor, and then the number of drawing threads according to the number of drawing threads and the number of running CPUs by the processor.
  • each drawing thread is bound one-to-one on each CPU for processing.
  • the resources of each CPU are fully utilized, so that the multi-CPU of the terminal device works at a lower frequency as a whole, thereby reducing power consumption.
  • the processor 580 is further configured to acquire other M-1 drawing threads of the M drawing threads. And other N-1 CPUs of N running CPUs.
  • processor 580 is specifically configured to:
  • the M-1 is greater than the N-1
  • the one-to-one binding of the N-1 drawing threads is processed on the N-1 running CPUs, and the MN drawing threads are bound to the Processing on MN CPUs on N-1 running CPUs.
  • a multi-CPU frequency modulation scheme may also be performed, and The solution may perform the frequency adjustment of the N running CPUs on the premise that the processor 580 binds one of the drawing threads and/or the M-1 drawing threads in the M, and may also implement the method in the third embodiment.
  • the processor 580 is configured to acquire one of the M drawing threads whose CPU usage is greater than a threshold, and/or other M-1 drawing threads of the M drawing threads, and obtain the The drawing time of the M drawing threads, and comparing the M drawing times, and obtaining the maximum drawing time among them.
  • the processor 580 is configured to compare the maximum drawing time with a time threshold, and adjust a frequency of the N running CPUs according to the comparison result.
  • the processor 580 is specifically configured to: if the maximum drawing time is less than the time threshold, obtain an estimated drawing time.
  • the time threshold is described in detail in step 103 of Embodiment 2 above, and the estimated drawing time is obtained by the above formula (1), and details are not described herein again.
  • Estimating the plot time can be a plot time for the plot thread after the frequency of the N running CPUs is reduced by one.
  • the processor 580 is further configured to compare the estimated drawing time with the screen refresh time.
  • the processor 580 is configured to reduce the frequency of the N running CPUs if the estimated drawing time is less than the screen refresh time.
  • reducing the frequency of the running CPU is to reduce the frequency of the entire frequency of the N operating CPUs.
  • the processor 580 is further configured to compare the maximum drawing time with the screen refresh time if the maximum drawing time is greater than the time threshold.
  • the processor 580 is configured to increase the frequency of the N running CPUs if the maximum drawing time is greater than the screen refresh time.
  • the frequency of the N running CPUs can be increased by one level, thereby making the CPU higher. At the frequency, the drawing time can be reduced to meet the condition that the drawing time is less than the screen refresh time, thereby avoiding the occurrence of image jamming.
  • the aforementioned program can be stored in a computer readable storage medium.
  • the program when executed, performs the steps including the foregoing method embodiments; and the foregoing storage medium includes various media that can store program codes, such as a ROM, a RAM, a magnetic disk, or an optical disk.

Abstract

A method and a device for scheduling of multiple CPUs, the method comprising: obtaining one graphics thread from among a number M of graphics threads, and one CPU from among a number N of operating CPUs, M being an integer greater than zero and N being an integer greater than zero; binding the one graphics thread so obtained to the one CPU so obtained for processing. With no impact upon system performance, the resources of each CPU are thus fully utilized while overall power consumption of the multiple CPUs is decreased.

Description

多CPU调度方法及装置Multi-CPU scheduling method and device
本申请要求于2013年9月13日提交中国专利局,申请号为201310419550.2、发明名称为“多CPU调度方法及装置”的中国专利申请,其全部内容通过引用结合在本申请中。This application claims the Chinese Patent Application No. 20131041955, filed on Sep. 13, 2013, the entire disclosure of which is hereby incorporated by reference.
技术领域Technical field
本发明涉及通信技术,尤其涉及一种多CPU调度方法及装置。The present invention relates to communication technologies, and in particular, to a multi-CPU scheduling method and apparatus.
背景技术Background technique
随着中央处理器CPU技术的不断发展,多处理器技术,例如,对称多处理器(Symmetrical Multi-Processing,简称:SMP)技术的应用也越来越普及。目前许多终端均采用了多处理器技术,现有终端多处理器处理的线程中,图像绘制线程作为终端的多处理器主要处理的一类线程,对多处理器的功耗有很大影响。With the continuous development of CPU technology of the central processing unit, the application of multi-processor technology, for example, Symmetrical Multi-Processing (SMP) technology, is becoming more and more popular. At present, many terminals adopt multi-processor technology. Among the threads processed by the existing terminal multi-processor, the image drawing thread is mainly used as a multi-processor of the terminal, which has a great influence on the power consumption of the multi-processor.
在实际情况中,一条绘图线程可能在不同的CPU上跳变,从而导致该绘图线程可能受到各个CPU上的其他线程的影响,使得调度不均,可能增大多处理器的整体功耗。In the actual situation, one drawing thread may jump on different CPUs, which may cause the drawing thread to be affected by other threads on each CPU, making scheduling uneven, which may increase the overall power consumption of the multiprocessor.
发明内容Summary of the invention
本发明实施例提供一种多CPU调度方法,使得一个绘图线程在一个运行的CPU上处理,可以降低多CPU功耗。The embodiment of the invention provides a multi-CPU scheduling method, so that a drawing thread is processed on a running CPU, which can reduce multi-CPU power consumption.
本发明实施例的第一方面是提供一种多CPU调度方法,包括:A first aspect of the embodiments of the present invention provides a multi-CPU scheduling method, including:
获取M个绘图线程中的一个绘图线程以及N个运行的CPU中的一个CPU,其中M为大于0的整数,N为大于0的整数;Obtaining one of the M drawing threads and one of the N running CPUs, where M is an integer greater than 0, and N is an integer greater than 0;
将所述M个绘图线程中的一个绘图线程绑定在所述N个运行的CPU中的一个CPU上处理。 Binding one of the M drawing threads to one of the N running CPUs for processing.
结合第一方面,在第一种可能的实现方式中,获取M个绘图线程的其他M-1个绘图线程以及N个运行的CPU的其他N-1个CPU;With reference to the first aspect, in the first possible implementation, the other M-1 drawing threads of the M drawing threads and the other N-1 CPUs of the N running CPUs are acquired;
当所述M-1小于所述N-1时,则将所述M-1个绘图线程一对一的绑定在M-1个运行的CPU上处理;或者When the M-1 is smaller than the N-1, the one-to-one binding of the M-1 drawing threads is processed on the M-1 running CPUs; or
当所述M-1等于所述N-1时,将所述M-1个绘图线程一对一的绑定在所述N-1个运行的CPU上处理;或者When the M-1 is equal to the N-1, the one-to-one binding of the M-1 drawing threads is processed on the N-1 running CPUs; or
当所述M-1大于所述N-1时,将N-1个绘图线程一对一的绑定在所述N-1个运行的CPU上处理,将M-N个绘图线程绑定在所述N-1个运行的CPU上的M-N个CPU上处理。When the M-1 is greater than the N-1, the one-to-one binding of the N-1 drawing threads is processed on the N-1 running CPUs, and the MN drawing threads are bound to the Processing on MN CPUs on N-1 running CPUs.
结合第一方面以及第一方面的第一种可能的实现方式,在第二种可能的实现方式中,With reference to the first aspect and the first possible implementation of the first aspect, in a second possible implementation manner,
获取CPU占用率大于阈值的所述M个绘图线程中的一个绘图线程和/或所述M个绘图线程的其他M-1个绘图线程。Obtaining one of the M drawing threads whose CPU usage is greater than a threshold and/or other M-1 drawing threads of the M drawing threads.
结合第一方面的第一种可能的实现方式以及第一方面的第二种可能的实现方式,在第三种可能的实现方式中,所述方法还包括:With reference to the first possible implementation of the first aspect, and the second possible implementation of the first aspect, in a third possible implementation, the method further includes:
获取所述M个绘图线程的绘图时间,并对所述M个绘图时间进行比较,获取其中的最大绘图时间;Obtaining a drawing time of the M drawing threads, and comparing the M drawing times to obtain a maximum drawing time thereof;
将所述最大绘图时间与时间阈值进行比较,根据比较结果调整所述N个运行的CPU的频率。The maximum drawing time is compared with a time threshold, and the frequency of the N running CPUs is adjusted according to the comparison result.
结合第一方面的第三种可能的实现方式,在第四种可能的实现方式中,所述将所述最大绘图时间与时间阈值进行比较,包括:In conjunction with the third possible implementation of the first aspect, in a fourth possible implementation, the comparing the maximum drawing time with a time threshold includes:
若所述最大绘图时间小于所述时间阈值,则获取估算绘图时间;If the maximum drawing time is less than the time threshold, obtaining an estimated drawing time;
所述估算绘图时间为所述N个运行的CPU的频率降低后,所述绘图线程 的绘图时间;The drawing time is after the frequency of the N running CPUs is decreased, the drawing thread Drawing time
将所述估算绘图时间与屏幕刷新时间进行比较,若所述估算绘图时间小于所述屏幕刷新时间,则将所述N个运行的CPU的频率降低。The estimated drawing time is compared with a screen refresh time, and if the estimated drawing time is less than the screen refresh time, the frequency of the N running CPUs is decreased.
结合第一方面的第三种可能的实现方式,在第五种可能的实现方式中,所述将所述最大绘图时间与时间阈值进行比较,包括:In conjunction with the third possible implementation of the first aspect, in a fifth possible implementation, the comparing the maximum mapping time with a time threshold includes:
若所述最大绘图时间大于所述时间阈值,则将所述最大绘图时间与屏幕刷新时间比较;If the maximum drawing time is greater than the time threshold, comparing the maximum drawing time with a screen refresh time;
若所述最大绘图时间大于所述屏幕刷新时间,则将所述N个运行的CPU的频率调高。If the maximum drawing time is greater than the screen refresh time, the frequency of the N running CPUs is increased.
本发明实施例的第二方面是提供一种多CPU调度装置,包括:A second aspect of the embodiments of the present invention provides a multi-CPU scheduling apparatus, including:
获取模块,用于获取M个绘图线程中的一个绘图线程以及N个运行的CPU中的一个CPU,其中M为大于0的整数,N为大于0的整数;The obtaining module is configured to acquire one of the M drawing threads and one of the N running CPUs, where M is an integer greater than 0, and N is an integer greater than 0;
绑定模块,用于将所述M个绘图线程中的一个绘图线程绑定在所述N个运行的CPU中的一个CPU上处理。And a binding module, configured to bind one of the M drawing threads to one CPU of the N running CPUs.
结合第二方面,在第一种可能的实现方式中,所述获取模块,用于获取M个绘图线程的其他M-1个绘图线程以及N个运行的CPU的其他N-1个CPU;With reference to the second aspect, in a first possible implementation, the acquiring module is configured to acquire other M-1 drawing threads of M drawing threads and other N-1 CPUs of N running CPUs;
所述绑定模块,用于:The binding module is configured to:
当所述M-1小于所述N-1时,则将所述M-1个绘图线程一对一的绑定在M-1个运行的CPU上处理;或者When the M-1 is smaller than the N-1, the one-to-one binding of the M-1 drawing threads is processed on the M-1 running CPUs; or
当所述M-1等于所述N-1时,将所述M-1个绘图线程一对一的绑定在所述N-1个运行的CPU上处理;或者When the M-1 is equal to the N-1, the one-to-one binding of the M-1 drawing threads is processed on the N-1 running CPUs; or
当所述M-1大于所述N-1时,将N-1个绘图线程一对一的绑定在所述N-1个运行的CPU上处理,将M-N个绘图线程绑定在所述N-1个运行的CPU上的 M-N个CPU上处理。When the M-1 is greater than the N-1, the one-to-one binding of the N-1 drawing threads is processed on the N-1 running CPUs, and the MN drawing threads are bound to the N-1 running CPU M-N CPU processing.
结合第二方面以及第二方面的第一种可能的实现方式,在第二种可能的实现方式中,所述获取模块,用于:获取CPU占用率大于阈值的所述M个绘图线程中的一个绘图线程和/或所述M个绘图线程的其他M-1个绘图线程。With reference to the second aspect, and the first possible implementation manner of the second aspect, in a second possible implementation manner, the acquiring module is configured to: acquire, among the M drawing threads whose CPU usage is greater than a threshold One drawing thread and/or other M-1 drawing threads of the M drawing threads.
结合第二方面的第一种可能的实现方式以及第二方面的第二种可能的实现方式,在第三种可能的实现方式中,还包括:With reference to the first possible implementation of the second aspect and the second possible implementation of the second aspect, in a third possible implementation manner, the method further includes:
最大绘图时间获取模块,用于获取所述M个绘图线程的绘图时间,并对所述M个绘图时间进行比较,获取其中的最大绘图时间;a maximum drawing time obtaining module, configured to acquire a drawing time of the M drawing threads, compare the M drawing times, and obtain a maximum drawing time thereof;
比较模块,用于将所述最大绘图时间与时间阈值进行比较,根据比较结果调整所述N个运行的CPU的频率。And a comparison module, configured to compare the maximum drawing time with a time threshold, and adjust a frequency of the N running CPUs according to the comparison result.
结合第二方面的第三种可能的实现方式,在第四种可能的实现方式中,所述比较模块,用于若所述最大绘图时间小于所述时间阈值,则获取估算绘图时间;With reference to the third possible implementation of the second aspect, in a fourth possible implementation, the comparing module is configured to acquire an estimated drawing time if the maximum drawing time is less than the time threshold;
所述估算绘图时间为所述N个运行的CPU的频率降低后,所述绘图线程的绘图时间;The estimated drawing time is a drawing time of the drawing thread after the frequency of the N running CPUs is decreased;
所述比较模块,用于将所述估算绘图时间与屏幕刷新时间进行比较;The comparing module is configured to compare the estimated drawing time with a screen refresh time;
调节模块,用于若所述估算绘图时间小于所述屏幕刷新时间,则将所述N个运行的CPU的频率降低。And an adjustment module, configured to reduce a frequency of the N running CPUs if the estimated drawing time is less than the screen refresh time.
结合第二方面的第三种可能的实现方式,在第五种可能的实现方式中,所述比较模块,用于若所述最大绘图时间大于所述时间阈值,则将所述最大绘图时间与屏幕刷新时间比较;In conjunction with the third possible implementation of the second aspect, in a fifth possible implementation, the comparing module is configured to: when the maximum drawing time is greater than the time threshold, Screen refresh time comparison;
所述调节模块,用于若所述最大绘图时间大于所述屏幕刷新时间,则将所述N个运行的CPU的频率调高。 The adjusting module is configured to increase a frequency of the N running CPUs if the maximum drawing time is greater than the screen refresh time.
本发明实施例提供的多CPU调度方法,通过获取M个绘图线程中的一个绘图线程以及N个运行的CPU中的一个CPU,将所述M个绘图线程中的一个绘图线程绑定在所述N个运行的CPU中的一个CPU上处理。在不影响系统性能的前提下,充分利用了各个CPU的资源,可以防止绘图线程在各个CPU之间跳变,降低了多CPU的功耗。The multi-CPU scheduling method provided by the embodiment of the present invention binds one of the M drawing threads to the one by acquiring one of the M drawing threads and one of the N running CPUs. Processing on one of the N running CPUs. Under the premise of not affecting the performance of the system, the resources of each CPU are fully utilized, which can prevent the drawing thread from jumping between CPUs and reduce the power consumption of multiple CPUs.
附图说明DRAWINGS
为了更清楚地说明本发明实施例或现有技术中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图做一简单地介绍,显而易见地,下面描述中的附图是本发明的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动性的前提下,还可以根据这些附图获得其他的附图。In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, a brief description of the drawings used in the embodiments or the prior art description will be briefly described below. Obviously, the drawings in the following description It is a certain embodiment of the present invention, and other drawings can be obtained from those skilled in the art without any inventive labor.
图1为本发明实施例一提供的多CPU调度方法的流程示意图;1 is a schematic flowchart of a multi-CPU scheduling method according to Embodiment 1 of the present invention;
图2a为现有技术多CPU调度示意图;2a is a schematic diagram of a multi-CPU scheduling in the prior art;
图2b为本发明提供的实施例一以及实施例二多CPU调度方法的效果示意图;2b is a schematic diagram showing the effects of the first embodiment and the second embodiment of the multi-CPU scheduling method according to the present invention;
图3为提供的实施例一以及实施例二的多CPU调度方法的流程示意图;3 is a schematic flowchart of a multi-CPU scheduling method according to Embodiment 1 and Embodiment 2;
图4为本发明实施例二提供的多CPU调度方法的CPU占用率示意图;4 is a schematic diagram of CPU usage of a multi-CPU scheduling method according to Embodiment 2 of the present invention;
图5为本发明实施例三提供的多CPU调频方法流程示意图;FIG. 5 is a schematic flowchart of a multi-CPU frequency modulation method according to Embodiment 3 of the present invention; FIG.
图6为本发明提供的实施例二及实施例三中多CPU调度方法的一种可行的实现方式的效果示意图;FIG. 6 is a schematic diagram showing the effect of a feasible implementation manner of a multi-CPU scheduling method in Embodiment 2 and Embodiment 3 according to the present invention;
图7为本发明提供的实施例二及实施例三中多CPU调度方法的一种可行的实现方式的对比示意图;FIG. 7 is a schematic diagram showing a comparison of a feasible implementation manner of a multi-CPU scheduling method according to Embodiment 2 and Embodiment 3 of the present invention;
图8为本发明实施例四提供的多CPU调度装置结构示意图; 8 is a schematic structural diagram of a multi-CPU scheduling apparatus according to Embodiment 4 of the present invention;
图9为本发明实施例五提供的多CPU调度装置结构示意图;9 is a schematic structural diagram of a multi-CPU scheduling apparatus according to Embodiment 5 of the present invention;
图10为本发明实施例六提供的终端结构示意图。FIG. 10 is a schematic structural diagram of a terminal according to Embodiment 6 of the present invention.
具体实施方式detailed description
为使本发明实施例的目的、技术方案和优点更加清楚,下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例是本发明一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本发明保护的范围。The technical solutions in the embodiments of the present invention will be clearly and completely described in conjunction with the drawings in the embodiments of the present invention. It is a partial embodiment of the invention, and not all of the embodiments. All other embodiments obtained by those skilled in the art based on the embodiments of the present invention without creative efforts are within the scope of the present invention.
随着终端设备的发展,终端设备的CPU需要运行越来越多的程序,程序运行的过程称为进程,并且一个进程中可以包含一个或者多个线程,其中线程是操作系统能够进行运算调度的最小单位,是进程中的实际运作单位。一个标准的线程由线程ID,当前指令指针,寄存器集合和堆栈组成。一个线程可以创建和撤消另一个线程,同一进程中的多个线程之间可以并发执行。每一个程序都至少有一个线程,若程序只有一个线程,则该线程就是程序本身。在CPU处理的诸多线程中,与图像处理相关的绘图线程对于终端设备中的CPU频率具有非常明显的影响,人类眼睛存在视觉暂留,如果画面帧率高于60fps,就会认为画面是连贯的,大多数处理图形的CPU刷新画面的次数为每秒60次,则其屏幕刷新一次的时间,即屏幕刷新时间为1÷60=16.6ms,所以终端设备的CPU在处理绘图线程时,每次只要在屏幕刷新时间16.6ms前绘制完图像,用户在观看该图像时就不会有卡顿的感觉。绘图线程的图像绘制时间长短主要由CPU频率大小决定的,而大多数终端设备的CPU频率都会比实际工作需要的频率大,因此,在具有多CPU的终端设备中对于需要处理绘图线程的CPU来说,其需要较大的频率来完成绘图线程的处理,而对于没有处理绘图线程的CPU,该CPU处理的其他线程对CPU频率的要求不高,因此不处理绘图线程 的CPU就会有很多的空闲时间。本发明的各个实施例就是基于上述绘图线程的特性,提供一种多CPU调度方法及装置,下面通过下文中的各个实施例对于本发明的技术方案进行说明。With the development of terminal devices, the CPU of the terminal device needs to run more and more programs. The process of running the program is called a process, and a process can include one or more threads, where the thread is an operating system capable of scheduling operations. The smallest unit is the actual operating unit in the process. A standard thread consists of a thread ID, a current instruction pointer, a register set, and a stack. One thread can create and revoke another thread, and multiple threads in the same process can execute concurrently. Each program has at least one thread. If the program has only one thread, the thread is the program itself. Among the many threads processed by the CPU, the drawing thread related to image processing has a very significant influence on the CPU frequency in the terminal device, and the human eye has a visual persistence. If the frame rate is higher than 60 fps, the picture is considered to be coherent. Most of the CPUs that process graphics refresh the screen 60 times per second, then the screen refresh time, that is, the screen refresh time is 1÷60=16.6ms, so the CPU of the terminal device processes the drawing thread each time. As long as the image is drawn before the screen refresh time of 16.6 ms, the user will not feel stuck when viewing the image. The drawing time of the drawing thread is mainly determined by the CPU frequency. Most CPUs of the terminal device will have a higher CPU frequency than the actual working. Therefore, in a terminal device with multiple CPUs, the CPU that needs to process the drawing thread is required. Said that it requires a large frequency to complete the processing of the drawing thread, and for the CPU that does not process the drawing thread, the other threads processed by the CPU do not have high CPU frequency requirements, so the drawing thread is not processed. The CPU will have a lot of free time. Various embodiments of the present invention provide a multi-CPU scheduling method and apparatus based on the characteristics of the above-described drawing thread. The technical solutions of the present invention are described below through various embodiments below.
图1为本发明实施例一提供的多CPU调度方法的流程示意图,需要说明的是实施例一的执行主体可以是任意一种具有多处理器,例如对称多处理器(Symmetrical Multi-Processing,简称:SMP),并且可以对图像进行处理的终端设备,例如,智能手机、平板电脑等。具体的,对于一个具有多处理器的终端设备,多CPU调度方法的执行主体可以为该终端设备的多个CPU中的一个CPU,具体可以根据CPU调度程序来决定。例如,大多数的CPU操作系统中都会根据进程的优先级、进程的CPU亲和性等进行CPU调度,CPU调度程序在执行时即为CPU调度进程,有些操作系统将CPU调度进程绑定在CPU_0上,也有些操作系统默认CPU调度进程可在所有的CPU上进行运算。其中,CPU亲和性即可以将线程绑定在多CPU中某个指定的CPU上尽量长时间运行,使该线程不在各个CPU之间进行跳变。CPU调度进程的其中一条依据就是进程的CPU亲和性。具体的,可以通过CPU亲和性掩码来实现对一个进程的CPU亲和性的设置,利用一个进程的进程识别符(Process Identifier,简称:PID),将该PID对应的进程绑定在特定的CPU上,若该进程此时不在该特定的CPU上,则将该进程迁移到该特定的CPU上,实现根据CPU亲和性将进程绑定在CPU上的操作。例如,根据PID将CPU调度进程的CPU亲和性设置为CPU_0,那么CPU调度进程就只在CPU_0上运算;若是CPU调度进程的CPU亲和性默认为是所有的CPU,那么CPU调度进程也同其它线程一样参与调度,可在所有的CPU上进行迁移运算。本发明下述实施例中的多CPU调度方法即通过该CPU调度进程实现,终端设备也会给它分配PID,该CPU调度进程最初的CPU亲和性默认是所有的CPU。进一步的,本发明下述实施例中涉及的有关CPU频率调节的实施例是通过CPU调频程序实现的,该CPU调频程序在执行时即为CPU调频进程,该CPU调频进程同样也参与CPU调度。所以在CPU执行过 程中,该CPU调频进程也会根据CPU调度进程的调度结果在相应的CPU上进行运算。若是CPU调频进程设置自身的CPU亲和性为CPU_0,那么CPU调度进程就会将CPU调频进程调度到CPU_0上,即CPU调频进程由CPU_0进行处理。1 is a schematic flowchart of a multi-CPU scheduling method according to Embodiment 1 of the present invention. It should be noted that the executor of the first embodiment may be any multi-processor, such as Symmetrical Multi-Processing (Symmetrical Multi-Processing). :SMP), and terminal devices that can process images, such as smartphones, tablets, and the like. Specifically, for a terminal device having multiple processors, the execution entity of the multi-CPU scheduling method may be one CPU of the plurality of CPUs of the terminal device, and may be determined according to a CPU scheduling program. For example, in most CPU operating systems, CPU scheduling is performed according to the priority of the process, the CPU affinity of the process, etc. The CPU scheduler executes the CPU scheduling process at the time of execution, and some operating systems bind the CPU scheduling process to CPU_0. On the other hand, some operating system default CPU scheduling processes can be operated on all CPUs. Among them, the CPU affinity can bind the thread to a specified CPU in the multi-CPU for as long as possible, so that the thread does not jump between the CPUs. One of the CPU scheduling processes is based on the CPU affinity of the process. Specifically, the CPU affinity setting of the process can be implemented by using the CPU affinity mask, and the Process Identifier (PID) of a process is used to bind the process corresponding to the PID to a specific process. On the CPU, if the process is not on the specific CPU at this time, the process is migrated to the specific CPU, and the operation of binding the process to the CPU according to the CPU affinity is implemented. For example, if the CPU affinity of the CPU scheduling process is set to CPU_0 according to the PID, then the CPU scheduling process only operates on CPU_0; if the CPU affinity of the CPU scheduling process defaults to all CPUs, then the CPU scheduling process is also the same. Other threads participate in scheduling, and migration operations can be performed on all CPUs. The multi-CPU scheduling method in the following embodiments of the present invention is implemented by the CPU scheduling process, and the terminal device also assigns a PID to it. The initial CPU affinity of the CPU scheduling process defaults to all CPUs. Further, the embodiment related to CPU frequency adjustment involved in the following embodiments of the present invention is implemented by a CPU frequency modulation program, which is a CPU frequency modulation process when executed, and the CPU frequency modulation process also participates in CPU scheduling. So executed in the CPU In the process, the CPU frequency modulation process also performs operations on the corresponding CPU according to the scheduling result of the CPU scheduling process. If the CPU frequency modulation process sets its own CPU affinity to CPU_0, then the CPU scheduling process will dispatch the CPU frequency modulation process to CPU_0, that is, the CPU frequency modulation process is processed by CPU_0.
下面参照图1,一种多CPU调度方法,包括:Referring to FIG. 1, a multi-CPU scheduling method includes:
步骤100、获取M个绘图线程中的一个绘图线程以及N个运行的CPU中的一个CPU,其中M为大于0的整数,N为大于0的整数。Step 100: Obtain one of the M drawing threads and one of the N running CPUs, where M is an integer greater than 0, and N is an integer greater than 0.
需要说明的是,如上文所述,当一个绘图程序在执行时即为绘图进程,而绘图进程的实际运作单位为绘图线程,对于CPU处理的线程,当某一线程调用终端设备存储的与绘图相关的函数时,就可以确定该线程为绘图线程,进一步的,通过获取绘图线程的PID来获取绘图线程的个数M。而对于运行的CPU个数N,可以通过预先设定的程序来获取运行的CPU个数N,此处对于具体的程序不做限定。其中,运行的CPU可以是正在处理线程的CPU或者允许处理线程的CPU。例如,对于一个具有四个CPU(CPU_0、CPU_1、CPU_2、CPU_3)的终端,可以通过操作系统对该终端进行设置来规定具体运行的CPU数量,例如,设置CPU_2、CPU_3不工作,即不处理该终端需要处理的进程,而仅由CPU_0、CPU_1来处理进程,则对于该终端来说,运行的CPU为CPU_0、CPU_1,其个数为2。It should be noted that, as described above, when a drawing program is executed, it is a drawing process, and the actual operating unit of the drawing process is a drawing thread. For a thread processed by the CPU, when a thread calls a terminal device to store and draw. When the related function is used, it can be determined that the thread is a drawing thread. Further, the number M of drawing threads is obtained by acquiring the PID of the drawing thread. For the number of running CPUs N, the number of running CPUs N can be obtained through a preset program, and the specific program is not limited herein. Among them, the running CPU can be the CPU that is processing the thread or the CPU that allows the processing thread. For example, for a terminal with four CPUs (CPU_0, CPU_1, CPU_2, CPU_3), the terminal can be set by the operating system to specify the number of CPUs to be specifically operated. For example, CPU_2 and CPU_3 are not working, that is, the terminal is not processed. The process that the terminal needs to process, and only the CPU_0, CPU_1 to process the process, for this terminal, the running CPU is CPU_0, CPU_1, the number of which is 2.
步骤101、将所述M个绘图线程中的一个绘图线程绑定在所述N个运行的CPU中的一个CPU上处理。Step 101: Bind one of the M drawing threads to one CPU of the N running CPUs for processing.
其中,可以通过设置绘图线程的CPU亲和性实现将所述M个绘图线程中的一个绘图线程绑定在所述N个运行的CPU中的一个CPU上处理的方案。具体可以利用该绘图线程的PID,将该绘图线程绑定在特定的CPU上,若该绘图线程此时不在该特定的CPU上,则将该绘图线程迁移到该特定的CPU上,实现根据CPU亲和性将进程绑定在CPU上的操作。例如,根据M个绘图线程中的一个绘图线程的PID将该绘图线程的CPU亲和性设置为CPU_0,那么该绘图线程就只在CPU_0上运算。 The solution for binding one of the M drawing threads to one of the N running CPUs may be implemented by setting a CPU affinity of the drawing thread. Specifically, the drawing thread may be bound to a specific CPU by using the PID of the drawing thread. If the drawing thread is not on the specific CPU at this time, the drawing thread is migrated to the specific CPU, and the CPU is implemented according to the CPU. Affinity binds a process to an operation on the CPU. For example, if the CPU affinity of the drawing thread is set to CPU_0 according to the PID of one of the M drawing threads, the drawing thread operates only on CPU_0.
进一步的,对于将所述M个绘图线程中的一个绘图线程绑定在所述N个运行的CPU中的一个CPU上处理,下面通过具体的例子进行说明,例如,当绘图线程个数为2,即有绘图线程1以及绘图线程2,运行的CPU个数为4,其中包括CPU_0、CPU_1、CPU_2、CPU_3时,通过将绘图线程1的CPU亲和性设置为CPU_0,将绘图线程1绑定在CPU_0上,即实现了将所述M个绘图线程中的一个绘图线程绑定在所述N个运行的CPU中的一个CPU上处理的方案。从而保证其他非绘图线程不会影响CPU_0处理绘图线程1,并且绘图线程1也不会在不同的CPU之间进行迁移,从而降低了由于绘图线程1不绑定在不同CPU之间迁移造成的额外功耗。Further, the process of binding one of the M drawing threads to one of the N running CPUs is described below by using a specific example, for example, when the number of drawing threads is 2 , that is, there are drawing thread 1 and drawing thread 2, and the number of running CPUs is 4, including CPU_0, CPU_1, CPU_2, CPU_3, and the drawing thread 1 is bound by setting the CPU affinity of drawing thread 1 to CPU_0. On CPU_0, a scheme is implemented in which one of the M drawing threads is bound to one of the N running CPUs. This ensures that other non-drawing threads will not affect CPU_0 processing drawing thread 1, and drawing thread 1 will not migrate between different CPUs, thus reducing the extra due to migration of drawing thread 1 without binding between different CPUs. Power consumption.
本发明实施例提供的多CPU调度方法,通过获取M个绘图线程中的一个绘图线程以及N个运行的CPU中的一个CPU,其中M为大于0的整数,N为大于0的整数,将所述M个绘图线程中的一个绘图线程绑定在所述N个运行的CPU中的一个CPU上处理。在不影响系统性能的前提下,避免绘图线程在多个运行的CPU上迁移造成额外功耗,进而降低了多CPU整体的功耗。The multi-CPU scheduling method provided by the embodiment of the present invention obtains one of the M drawing threads and one of the N running CPUs, where M is an integer greater than 0, and N is an integer greater than 0. One of the M drawing threads is bound to be processed on one of the N running CPUs. Under the premise of not affecting the performance of the system, avoiding the migration of the drawing thread on multiple running CPUs causes additional power consumption, thereby reducing the overall power consumption of the multiple CPUs.
进一步的,在针对上述获取M个绘图线程中的一个绘图线程进行相应的绑定处理之后,或,在针对上述获取M个绘图线程中的一个绘图线程进行相应的绑定处理时,还可以对剩余M-1个绘图线程进行类似的绑定处理,下面通过实施例二对剩余M-1个绘图线程的绑定方法进行说明:Further, after performing corresponding binding processing for acquiring one of the M drawing threads, or performing corresponding binding processing for acquiring one of the M drawing threads for the foregoing, The remaining M-1 drawing threads perform similar binding processing. The following describes the binding method of the remaining M-1 drawing threads through the second embodiment:
首先,获取M个绘图线程的其他M-1个绘图线程以及N个运行的CPU的其他N-1个CPU。将M-1与N-1进行比较,根据比较结果,可以分为以下至少三种情况进行具体的操作:First, get the other M-1 drawing threads of the M drawing threads and the other N-1 CPUs of the N running CPUs. Comparing M-1 with N-1, according to the comparison result, it can be divided into at least three cases to perform specific operations:
情况一:当所述M-1小于所述N-1时,则将所述M-1个绘图线程一对一的绑定在M-1个运行的CPU上处理;或者Case 1: When the M-1 is smaller than the N-1, the one-to-one binding of the M-1 drawing threads is processed on the M-1 running CPUs; or
情况二:当所述M-1等于所述N-1时,将所述M-1个绘图线程一对一的绑定在所述N-1个运行的CPU上处理;或者Case 2: when the M-1 is equal to the N-1, the one-to-one binding of the M-1 drawing threads is processed on the N-1 running CPUs; or
情况三:当所述M-1大于所述N-1时,将N-1个绘图线程一对一的绑定 在所述N-1个运行的CPU上处理,将M-N个绘图线程绑定在所述N-1个运行的CPU上的M-N个CPU上处理。Case 3: When the M-1 is greater than the N-1, the N-1 drawing threads are bound one to one. Processing on the N-1 running CPUs, and M-N drawing threads are bound to the M-N CPUs on the N-1 running CPUs for processing.
进一步的,针对情况一,例如绘图线程个数为2,即有绘图线程1以及绘图线程2,运行的CPU个数为4,其中包括CPU_0、CPU_1、CPU_2、CPU_3,当其中一个绘图线程1已经绑定在CPU_0后,此时M-1=1,N-1=3,显然M-1小于N-1,则将绘图线程2绑定在CPU_1、CPU_2、CPU_3中的任意一个上,并且,假如将绘图线程2绑定在CPU_1,优选的,将其他非绘图线程的CPU亲和性设置为CPU_2或CPU_3,即其他非绘图线程可在CPU_2或CPU_3上进行处理,这样的好处在于避免其他非绘图线程迁移到CPU_1上,避免影响CPU_1处理绘图线程2,从而在整体上降低多个运行的CPU功耗。Further, for case 1, for example, the number of drawing threads is 2, that is, there are drawing thread 1 and drawing thread 2, and the number of running CPUs is 4, including CPU_0, CPU_1, CPU_2, CPU_3, when one of the drawing threads 1 has Bind to CPU_0, at this time, M-1=1, N-1=3. Obviously, if M-1 is smaller than N-1, the drawing thread 2 is bound to any one of CPU_1, CPU_2, and CPU_3, and If the drawing thread 2 is bound to CPU_1, preferably, the CPU affinity of other non-drawing threads is set to CPU_2 or CPU_3, that is, other non-drawing threads can be processed on CPU_2 or CPU_3, which has the advantage of avoiding other non- The drawing thread is migrated to CPU_1 to avoid affecting CPU_1 processing drawing thread 2, thereby reducing the CPU power consumption of multiple running groups as a whole.
针对情况二,例如绘图线程个数为4,即有绘图线程1、绘图线程2、绘图线程3、绘图线程4,运行的CPU个数为4,其中包括CPU_0、CPU_1、CPU_2、CPU_3,当其中一个绘图线程1已经绑定在CPU_0后,此时M-1=3,N-1=3,显然M-1等于N-1,则将绘图线程2绑定在CPU_1上,将绘图线程3绑定在CPU_2上,将绘图线程4绑定在CPU_3上,从而将所有绘图线程一对一地绑定在所有运行的CPU上,使得各个运行的CPU的功耗均衡,从而在整体上降低了多个运行的CPU的功耗,而其他非绘图线程根据其最初的CPU亲和性,在相应的CPU上进行处理,或者也可以在不同的CPU之间进行迁移,此处不做限定。For case 2, for example, the number of drawing threads is 4, that is, there are drawing thread 1, drawing thread 2, drawing thread 3, drawing thread 4, and the number of running CPUs is 4, including CPU_0, CPU_1, CPU_2, CPU_3, among them. A drawing thread 1 has been bound to CPU_0, at this time M-1=3, N-1=3, obviously M-1 is equal to N-1, then the drawing thread 2 is bound to CPU_1, and the drawing thread 3 is tied. Set on CPU_2, bind drawing thread 4 to CPU_3, so that all drawing threads are bound one-to-one on all running CPUs, so that the power consumption of each running CPU is balanced, thus reducing overall The power consumption of a running CPU, while other non-drawing threads are processed on the corresponding CPU according to their initial CPU affinity, or can also be migrated between different CPUs, which is not limited herein.
针对情况三,例如绘图线程个数为4,即有绘图线程1、绘图线程2、绘图线程3、绘图线程4,运行的CPU个数为2,其中包括CPU_0、CPU_1,当其中一个绘图线程1已经绑定在CPU_0后,此时M-1=3,N-1=1,显然M-1大于N-1,则此时将绘图线程2、绘图线程3、绘图线程4中的任意一个绘图线程绑定在CPU_1上,例如将绘图线程2绑定在CPU_1上,而绘图线程3、绘图线程4以及其他非绘图线程根据其最初的CPU亲和性,在相应的CPU上进行处理,此处不做限定。For case three, for example, the number of drawing threads is 4, that is, there are drawing thread 1, drawing thread 2, drawing thread 3, drawing thread 4, and the number of running CPUs is 2, including CPU_0, CPU_1, when one of the drawing threads 1 Already bound to CPU_0, at this time M-1=3, N-1=1, obviously M-1 is greater than N-1, then drawing any one of drawing thread 2, drawing thread 3, drawing thread 4 The thread is bound to CPU_1, for example, the drawing thread 2 is bound to CPU_1, and the drawing thread 3, the drawing thread 4, and other non-drawing threads are processed on the corresponding CPU according to their initial CPU affinity, here Not limited.
请参阅图2a,图2a为现有技术多CPU调度示意图,如图2a所示,现有 技术中,终端设备通过线程调度将线程在多个CPU之间进行迁移来实现CPU占用率的均衡,但是采用现有技术线程迁移的方案并不能有效的实现CPU占用率的均衡,并且当CPU的工作负荷较重时,多次的迁移线程会更加增大CPU的工作负荷,CPU的缓存利用率也会降低。Please refer to FIG. 2a. FIG. 2a is a schematic diagram of a multi-CPU scheduling in the prior art, as shown in FIG. 2a. In the technology, the terminal device migrates the threads between multiple CPUs through thread scheduling to achieve equalization of the CPU usage. However, the prior art thread migration scheme cannot effectively achieve the CPU usage balance, and when the CPU is When the workload is heavy, multiple migration threads will increase the CPU workload and CPU cache utilization will decrease.
图2b为本发明提供的实施例一以及实施例二多CPU调度方法的效果示意图,如图2b所示,根据绘图线程的个数M以及运行的CPU个数N,将所述M个绘图线程中的一个绘图线程绑定在所述N个运行的CPU中的一个CPU上处理。终端设备在进行线程调度时,绘图线程不会在多个CPU之间进行迁移,进一步的,获取M个绘图线程的其他M-1个绘图线程以及N个运行的CPU的其他N-1个CPU,并对该其他M-1个绘图线程进行绑定,从而实现对M个绘图线程的绑定方案。例如,图2b中线程号为:1、2、3、4的四个绘图线程。在进行线程调度之后,该四个绘图线程均未发生迁移,这样使得对CPU频率影响较大的绘图线程能够均衡的分配在不同的CPU上,保证了一个CPU不受绑定在其他CPU上的绘图线程的影响,对于每一个CPU上被绑定的绘图线程,CPU对于其上绑定的绘图线程处理更加高效。进一步的,当每一个CPU都采用本发明实施例的方案对绘图线程进行绑定处理后,终端设备的多CPU整体的频率需求就能够进行下调,这样可以降低终端设备的功耗。2b is a schematic diagram of the effect of the first embodiment and the second embodiment of the multi-CPU scheduling method provided by the present invention. As shown in FIG. 2b, the M drawing threads are obtained according to the number M of drawing threads and the number of CPUs running N. One of the drawing thread bindings is processed on one of the N running CPUs. When the terminal device performs thread scheduling, the drawing thread does not migrate between multiple CPUs. Further, other M-1 drawing threads of M drawing threads and other N-1 CPUs of N running CPUs are acquired. And bind the other M-1 drawing threads to implement the binding scheme for the M drawing threads. For example, the thread numbers in Figure 2b are: 1, 2, 3, 4 of four drawing threads. After the thread scheduling, the four drawing threads are not migrated, so that the drawing threads that have a greater influence on the CPU frequency can be evenly distributed on different CPUs, ensuring that one CPU is not bound to other CPUs. The effect of the drawing thread, for each drawing thread bound on the CPU, the CPU is more efficient at processing the drawing thread bound to it. Further, after each CPU performs the binding processing on the drawing thread by using the solution of the embodiment of the present invention, the overall frequency requirement of the multi-CPU of the terminal device can be down-regulated, thereby reducing the power consumption of the terminal device.
优选的,对于实施例一及实施例二中绘图线程个数M的一种可能的确定方式为:获取CPU占用率大于阈值的所述M个绘图线程中的一个绘图线程和/或所述M个绘图线程的其他M-1个绘图线程。例如,当前多CPU总共处理7个绘图线程,而其中CPU占用率大于阈值的绘图线程个数为4个,则M为4。Preferably, one possible determining manner of the number M of drawing threads in the first embodiment and the second embodiment is: acquiring one of the M drawing threads whose CPU usage is greater than a threshold and/or the M The other M-1 drawing threads of the drawing thread. For example, if the current multi-CPU processes a total of 7 drawing threads, and the number of drawing threads whose CPU usage is greater than the threshold is 4, then M is 4.
进一步的,图3为提供的实施例一以及实施例二的多CPU调度方法的流程示意图。在终端设备不断更新画面时,绘图线程就会变得繁重,而决定是否要进行CPU频率调整的条件可以是任务的繁重程度。因此,可以通过得到绘图线程的CPU占用率从而确定线程繁重程度。当发现有绘图线程的CPU占用率从大于CPU占用率阈值变(简称:阈值)成小于CPU占用率阈值(简称: 阈值),或,是从小于CPU占用率阈值变成大于CPU占用率阈值时,则获取CPU占用率大于阈值的绘图线程的个数以及运行的CPU个数。其一种优选的实现方式为:当发现有绘图线程的CPU占用率从大于CPU占用率阈值变成小于CPU占用率阈值,或,是从小于CPU占用率阈值变成大于CPU占用率阈值时,对发生上述两种情况的绘图线程添加标识,通过该标识确定大于阈值的绘图线程的个数M。并且,阈值为一预先设置的小数,由于不同的终端设备所使用的CPU型号以及操作系统不尽相同,因此对于该阈值的具体数值可以根据不同的CPU型号以及操作系统进行设置,此处不予限定。Further, FIG. 3 is a schematic flowchart diagram of the multi-CPU scheduling method according to the first embodiment and the second embodiment. When the terminal device constantly updates the screen, the drawing thread becomes heavy, and the condition for deciding whether or not to perform the CPU frequency adjustment can be a heavy task. Therefore, the thread cumbersomeness can be determined by obtaining the CPU usage of the drawing thread. When the CPU usage of the drawing thread is changed from the CPU usage threshold (abbreviation: threshold) to less than the CPU usage threshold (referred to as: If the threshold is greater than the CPU usage threshold, the number of drawing threads whose CPU usage is greater than the threshold and the number of running CPUs are obtained. A preferred implementation manner is as follows: when the CPU usage of the drawing thread is changed from the CPU usage threshold to the CPU usage threshold, or the CPU usage threshold is greater than the CPU usage threshold. An identifier is added to the drawing thread in which the above two cases occur, and the number M of drawing threads larger than the threshold is determined by the identifier. Moreover, the threshold is a preset decimal number. Since the CPU model and operating system used by different terminal devices are different, the specific value of the threshold can be set according to different CPU models and operating systems. limited.
下面参照图3,对根据绘图线程的CPU占用率实现每一个绘图线程一对一地绑定在每一CPU上进行处理的方案进行详细说明,其中,对于一个具有多处理器的终端设备,多CPU调度方法的执行主体可以为该终端设备的多个CPU中的一个CPU,具体可以根据CPU调度程序来决定。针对图1中的步骤100,其一种可行的实现方式包括:Referring to FIG. 3, a scheme for implementing one-to-one binding on each CPU for processing each drawing thread according to the CPU usage of the drawing thread is described in detail, wherein, for a terminal device having multiple processors, more The execution body of the CPU scheduling method may be one of a plurality of CPUs of the terminal device, and may be determined according to a CPU scheduler. For a step 100 in FIG. 1, one possible implementation manner includes:
步骤100a、若有绘图线程的CPU占用率从小于阈值变为大于阈值,或者,绘图线程的CPU占用率从大于阈值变为小于阈值,则获取CPU占用率大于阈值的所述M个绘图线程中的一个绘图线程和/或所述M个绘图线程的其他M-1个绘图线程以及N个运行的CPU。Step 100a: If the CPU usage of the drawing thread changes from less than the threshold to greater than the threshold, or if the CPU usage of the drawing thread changes from greater than the threshold to less than the threshold, acquiring the M drawing threads whose CPU usage is greater than the threshold One drawing thread and/or other M-1 drawing threads of the M drawing threads and N running CPUs.
具体的,计算所有绘图线程的CPU占用率;将所有绘图线程的CPU占用率与阈值进行比较,当发生有绘图线程的CPU占用率从小于阈值变为大于阈值,或者,绘图线程的CPU占用率从大于阈值变为小于阈值这一触发条件时,则获取CPU占用率大于阈值的绘图线程的个数M以及运行的CPU个数N的操作,进一步的,已经将所述M个绘图线程中的一个绘图线程绑定在所述N个运行的CPU中的一个CPU上处理后,则将对获得的M减1。Specifically, calculating the CPU usage of all the drawing threads; comparing the CPU usage of all the drawing threads with the threshold, when the CPU usage of the drawing thread changes from less than the threshold to greater than the threshold, or the CPU usage of the drawing thread When the trigger condition is changed from the threshold value to the threshold value, the operation of acquiring the number M of the drawing threads whose CPU usage is greater than the threshold value and the number of running CPUs N is obtained, and further, the M drawing threads have been After a drawing thread binding is processed on one of the N running CPUs, the obtained M is decremented by one.
优选的,若K个绘图线程的CPU占用率从大于阈值变为小于阈值,则将绘图线程个数M减K,根据M-K个绘图线程确定绘图线程绑定策略;或者,若K个绘图线程的CPU占用率从小于阈值变为大于阈值,则将绘图线程个数M加 K,根据M+K个绘图线程确定绘图线程绑定策略。需要说明的是,K值为大于等于零的整数,并且若K个绘图线程的CPU占用率从大于阈值变为小于阈值时,该K值一定小于等于M值的整数。Preferably, if the CPU usage of the K drawing threads changes from greater than the threshold to less than the threshold, the number of drawing threads M is reduced by K, and the drawing thread binding strategy is determined according to the MK drawing threads; or, if K drawing threads are If the CPU usage changes from less than the threshold to greater than the threshold, the number of drawing threads is increased by M. K, determine the drawing thread binding strategy according to M+K drawing threads. It should be noted that the K value is an integer greater than or equal to zero, and if the CPU usage of the K drawing threads changes from greater than the threshold to less than the threshold, the K value must be less than or equal to an integer of the M value.
进一步的,本发明实施例以线程的CPU占用率大小来表示线程的繁重程度。每个CPU都可以识别出正在执行的线程,统计出一段时间里该线程在该CPU上的执行时间,执行时间比上总的时间即可得到线程的CPU占用率,即:Further, the embodiment of the present invention expresses the heavyness of the thread by the CPU usage of the thread. Each CPU can identify the executing thread, and calculate the execution time of the thread on the CPU for a period of time. The execution time is longer than the total time to obtain the CPU usage of the thread, namely:
线程的CPU占用率=执行时间/总的时间CPU usage of thread = execution time / total time
需要说明的是,总的时间为CPU的n个时钟周期的时间之和,其中n为大于零的整数;而上文中的阈值为一预先设置的小数,其用于与一个线程的CPU占用率比较,例如,阈值可以设置为0.6,当某一绘图线程的CPU占用率经过计算为0.7时,显然该绘图线程的CPU占用率大于阈值,则说明该绘图线程的繁重程度较大。类似的,当一个线程的CPU占用率小于阈值时,则说明该线程的繁重程度较小。It should be noted that the total time is the sum of the times of n clock cycles of the CPU, where n is an integer greater than zero; and the threshold in the above is a preset decimal number, which is used for CPU usage with one thread. For example, the threshold can be set to 0.6. When the CPU usage of a drawing thread is calculated to be 0.7, it is obvious that the CPU usage of the drawing thread is greater than the threshold, indicating that the drawing thread is heavy. Similarly, when the CPU usage of a thread is less than the threshold, it indicates that the thread is less heavy.
图4为本发明实施例二提供的多CPU调度方法的CPU占用率示意图,如图4所示,以两个运行的CPU(CPU_0、CPU_1)为例,CPU_0、CPU_1上运行了线程1、线程2以及线程3,其中,计算线程1在时间T(n个时钟周期)这段时间的CPU占用率,终端设备统一以一个CPU为基准,则有:4 is a schematic diagram of CPU usage of a multi-CPU scheduling method according to Embodiment 2 of the present invention. As shown in FIG. 4, taking two running CPUs (CPU_0, CPU_1) as an example, CPU_1 and CPU_1 run thread 1 and thread. 2 and thread 3, wherein the CPU usage of the thread 1 during the time T (n clock cycles) is calculated, and the terminal device is uniformly based on a CPU, and then:
线程1的CPU占用率=(t1+t2+t3)/TCPU usage of thread 1 = (t1 + t2 + t3) / T
其中,由于线程1可能在两个CPU之间发生迁移,参照图4可知,其中t1与t3表示该线程1在CPU_0上的执行时间,t3表示该线程1在迁移到CPU_1上的执行时间。绘图线程的CPU占用率计算方法也是类似的。例如:假如阈值为0.3。现有4个绘图线程,其中:绘图线程1的CPU占用率为0.8,绘图线程2的CPU占用率为0.35,绘图线程3的CPU占用率为0.3,绘图线程4的CPU占用率为0.1。因此有两个绘图线程1和2的CPU占用率超过阈值0.3,那么此时M的值为2。Wherein, since the thread 1 may migrate between the two CPUs, it can be seen from FIG. 4 that t1 and t3 represent the execution time of the thread 1 on the CPU_0, and t3 represents the execution time of the thread 1 on the migration to the CPU_1. The CPU usage calculation method of the drawing thread is similar. For example: If the threshold is 0.3. There are 4 drawing threads, wherein: the CPU usage of drawing thread 1 is 0.8, the CPU usage of drawing thread 2 is 0.35, the CPU usage of drawing thread 3 is 0.3, and the CPU usage of drawing thread 4 is 0.1. Therefore, the CPU usage of two drawing threads 1 and 2 exceeds the threshold of 0.3, and then the value of M is 2.
另外,在实时获取CPU占用率发生变化的绘图线程个数M时,还可能发生如下情况:a、创建线程或者删除线程,则判断创建的新线程或者删除的 线程是否为绘图线程,若是,则更新M的数值;b、动态计算绘图线程个数M时,若有之前CPU占用率没有变化的绘图线程的CPU占用率发生了变化,则若该绘图线程的占用率从大于阈值变成了小于阈值,则M-1,若该绘图线程的占用率从小于阈值变成了大于阈值,则M+1;如果运行的CPU个数发生变化,则重新获取N。In addition, when the number of drawing threads whose CPU usage changes are acquired in real time, the following may occur: a. Create a thread or delete a thread, then judge the created new thread or delete the created thread. Whether the thread is a drawing thread, and if so, the value of M is updated; b. When the number of drawing threads is dynamically calculated, if the CPU usage of the drawing thread whose previous CPU usage has not changed has changed, then if the drawing thread of the drawing thread changes If the occupancy rate changes from greater than the threshold to less than the threshold, then M-1, if the occupancy rate of the drawing thread changes from less than the threshold to greater than the threshold, then M+1; if the number of running CPUs changes, reacquire N .
参照图3,其中,在图1中的步骤101之后,还包括:Referring to FIG. 3, after step 101 in FIG. 1, the method further includes:
步骤102、获取M个绘图线程的其他M-1个绘图线程以及N个运行的CPU的其他N-1个CPU,并根据所述M-1以及所述N-1确定绘图线程绑定策略。Step 102: Obtain other M-1 drawing threads of the M drawing threads and other N-1 CPUs of the N running CPUs, and determine a drawing thread binding policy according to the M-1 and the N-1.
具体的,参照上文本发明实施例二,绘图线程绑定策略可以包括至少以下三种情况:Specifically, referring to the second embodiment of the present invention, the drawing thread binding policy may include at least the following three cases:
情况一:当所述M-1小于所述N-1时,则将所述M-1个绘图线程一对一的绑定在M-1个运行的CPU上处理。另外,优选的,可以设置所述非绘图线程在N-M个运行的CPU上,由N-M个运行的CPU进行处理。Case 1: When the M-1 is smaller than the N-1, the one-to-one binding of the M-1 drawing threads is processed on the M-1 running CPUs. In addition, preferably, the non-drawing thread may be set to be processed by N-M running CPUs on N-M running CPUs.
情况二:当所述M-1等于所述N-1时,将所述M-1个绘图线程一对一的绑定在所述N-1个运行的CPU上处理。另外,优选的,非绘图线程可以为最初的亲和性状态。Case 2: When the M-1 is equal to the N-1, the one-to-one binding of the M-1 drawing threads is processed on the N-1 running CPUs. Additionally, preferably, the non-drawing thread may be in an initial affinity state.
情况三:当所述M-1大于所述N-1时,将N-1个绘图线程一对一的绑定在所述N-1个运行的CPU上处理,将M-N个绘图线程绑定在所述N-1个运行的CPU上的M-N个CPU上处理。另外,优选的,非绘图线程可以为最初的亲和性状态。Case 3: When the M-1 is greater than the N-1, the one-to-one binding of the N-1 drawing threads is processed on the N-1 running CPUs, and the MN drawing threads are bound. Processing on MN CPUs on the N-1 running CPUs. Additionally, preferably, the non-drawing thread may be in an initial affinity state.
步骤103、根据绘图线程绑定策略,将所述M-1个绘图线程一对一地绑定在所述N-1个CPU上进行处理。Step 103: Bind the M-1 drawing threads one-to-one to the N-1 CPUs for processing according to a drawing thread binding policy.
具体的,在实施例一将所述M个绘图线程中的一个绘图线程绑定在所述N个运行的CPU中的一个CPU上处理之后,再根据步骤101a中的情况一、情况二以及情况三,将所述M-1个绘图线程一对一地绑定在所述N-1个CPU上进行处理。 Specifically, in the first embodiment, after one of the M drawing threads is bound to one of the N running CPUs, according to the situation one, the second case and the situation in step 101a. Third, the M-1 drawing threads are bound one-to-one on the N-1 CPUs for processing.
优选的,参照图3,在步骤103之后,还包括:Preferably, referring to FIG. 3, after step 103, the method further includes:
步骤104、获取CPU占用率大于阈值的所述M个绘图线程中的一个绘图线程和/或所述M个绘图线程的其他M-1个绘图线程。Step 104: Obtain one of the M drawing threads whose CPU usage is greater than a threshold and/or other M-1 drawing threads of the M drawing threads.
步骤105、获取M个绘图线程的绘图时间,并对M个绘图时间进行比较,获取其中的最大绘图时间。Step 105: Obtain a drawing time of the M drawing threads, and compare the M drawing times to obtain a maximum drawing time.
具体的,在CPU处理的绘图线程绘图时,绘图线程都会调用到绘图函数,绘图函数运算需要的时间就是绘图时间。获取绘图时间的方法一种可行的实现方式为:在绘图函数的起始与结束的地方打点,获取起始与结束的时间,再计算绘图结束与起始的时间差即可得到绘图时间。Specifically, when the drawing thread of the CPU process is drawn, the drawing thread will call the drawing function, and the time required for the drawing function operation is the drawing time. A feasible way to obtain the drawing time is to draw a point at the beginning and end of the drawing function, obtain the start and end time, and then calculate the time difference between the end of the drawing and the start to get the drawing time.
步骤106、将最大绘图时间与时间阈值进行比较。Step 106: Compare the maximum drawing time with a time threshold.
具体的,时间阈值可以根据需要进行配置,例如时间阈值=屏幕刷新时间×70%。若最大绘图时间小于时间阈值,执行步骤107;若最大绘图时间大于时间阈值,则执行步骤109。Specifically, the time threshold can be configured as needed, such as time threshold = screen refresh time x 70%. If the maximum drawing time is less than the time threshold, step 107 is performed; if the maximum drawing time is greater than the time threshold, step 109 is performed.
步骤107、获取估算绘图时间。Step 107: Obtain an estimated drawing time.
具体的,估算绘图时间为N个运行的CPU的频率降低一级后,绘图线程的绘图时间。其中,估算绘图时间可以通过如下公式(1)获得:Specifically, the estimated drawing time is the drawing time of the drawing thread after the frequency of the N running CPUs is lowered by one level. Among them, the estimated drawing time can be obtained by the following formula (1):
估算绘图时间=最大绘图时间×当前CPU的频率/小一级CPU的频率(1)Estimated plot time = maximum plot time × current CPU frequency / small first-level CPU frequency (1)
需要说明的是,由公式(1)可知,该估算绘图时间为M个绘图时间中的最大绘图时间经过公式(1)计算得到的,该估算绘图时间为估算的具有该最大绘图时间的绘图线程1在降低一级运行的CPU的频率后的绘图时间。另外,降低一级运行的CPU的频率,是针对N个运行的CPU的频率整体降低频率。例如,在降低运行的CPU频率前,N个运行的CPU频率的均为800MHZ,降低一级运行的CPU频率后,则N个运行的CPU频率均为600MHZ。It should be noted that, as shown by the formula (1), the estimated drawing time is calculated by the formula (1) for the maximum drawing time of the M drawing times, and the estimated drawing time is the estimated drawing thread having the maximum drawing time. 1 Plot time after reducing the frequency of the CPU running at one level. In addition, reducing the frequency of the CPU operating at one level is to reduce the frequency as a whole for the frequencies of the N operating CPUs. For example, before reducing the running CPU frequency, the N running CPU frequencies are all 800MHZ. After reducing the CPU frequency of the first-level operation, the N running CPU frequencies are all 600MHZ.
步骤108、将估算绘图时间与屏幕刷新时间进行比较,若估算绘图时间小于屏幕刷新时间,则将N个运行的CPU的频率降低。 Step 108: Compare the estimated drawing time with the screen refresh time. If the estimated drawing time is less than the screen refresh time, reduce the frequency of the N running CPUs.
若估算绘图时间仍小于屏幕刷新时间,则降低运行的CPU频率一级,此处需要说明的是,在降低一级CPU频率之后,参照上述步骤105至108,继续将最大绘图时间于时间阈值进行比较,直到满足时间阈值<最大绘图时间<屏幕刷新时间,则不需要再进行CPU频率调节。下面根据具体的场景,对于上述步骤107及108进行说明:If the estimated drawing time is still less than the screen refresh time, the operating CPU frequency is lowered. Here, after lowering the first-level CPU frequency, referring to the above steps 105 to 108, the maximum drawing time is continued at the time threshold. For comparison, the CPU frequency adjustment is not required until the time threshold <maximum drawing time <screen refresh time is satisfied. The following steps 107 and 108 are described according to specific scenarios:
场景一,例如:通过比较M个绘图线程的绘图时间,获得其中最大绘图时间是11ms,此时N个运行的CPU频率均为800MHZ,小一级的CPU频率为600MHZ(需要说明,N个运行的CPU频率当前还处在800MHZ),根据公式(1)计算得到的估算绘图时间约为15ms,参照上文可知,屏幕刷新时间Tr为16.6ms,根据步骤108的比较,可知估算绘图时间15ms<屏幕刷新时间Tr16.6ms,则将N个运行的CPU的频率降低一级。即将N个运行的CPU的频率从800MHZ下调至600MHZ。并在CPU频率为600MHZ时,重新获取绘图时间,重复上述步骤105至108的操作,直到满足时间阈值<最大绘图时间<屏幕刷新时间,则不需要再进行CPU频率调节。 Scene 1, for example, by comparing the drawing times of M drawing threads, the maximum drawing time is 11ms, at which time the CPU frequencies of N running are 800MHZ, and the CPU frequency of the smaller one is 600MHZ (requires description, N runs) The CPU frequency is still at 800 MHz. The estimated plot time calculated according to formula (1) is about 15 ms. Referring to the above, the screen refresh time Tr is 16.6 ms. According to the comparison of step 108, the estimated plot time is 15 ms. The screen refresh time Tr16.6ms reduces the frequency of N running CPUs by one level. The frequency of the N running CPUs is lowered from 800 MHz to 600 MHz. When the CPU frequency is 600 MHz, the drawing time is reacquired, and the operations of the above steps 105 to 108 are repeated until the time threshold <maximum drawing time <screen refresh time is satisfied, and the CPU frequency adjustment is not required.
场景二,例如:通过比较M个绘图线程的绘图时间,获得其中最大绘图时间是14ms,此时N个运行的CPU频率均为800MHZ,小一级的CPU频率为600MHZ(需要说明,N个运行的CPU频率当前还处在800MHZ),根据公式(1)计算得到的估算绘图时间大约是18ms,参照上文可知,屏幕刷新时间Tr为16.6ms,则此时估算绘图时间>屏幕刷新时间Tr16.6ms,显然,此时如果将CPU频率降低一级,会造成终端设备显示的图像文件出现卡顿现象。那么即使当前的最大绘图时间14ms是小于时间阈值的,N个CPU频率也不可再调至600MHZ,而是保持800MHZ。 Scenario 2, for example, by comparing the drawing times of M drawing threads, the maximum drawing time is 14 ms, at which time the CPU frequencies of N running are 800 MHz, and the CPU frequency of the smaller one is 600 MHz (required, N runs) The CPU frequency is still at 800 MHz. The estimated plot time calculated according to formula (1) is about 18 ms. Referring to the above, the screen refresh time Tr is 16.6 ms. At this time, the plot time > screen refresh time Tr16 is estimated. 6ms, obviously, if the CPU frequency is lowered by one level at this time, the image file displayed by the terminal device will be stuck. Then even if the current maximum drawing time of 14ms is less than the time threshold, the N CPU frequencies can not be adjusted to 600MHZ, but remain 800MHZ.
步骤109、将最大绘图时间与屏幕刷新时间比较,若最大绘图时间大于屏幕刷新时间,则N个运行的CPU的频率调高。Step 109: Compare the maximum drawing time with the screen refresh time. If the maximum drawing time is greater than the screen refresh time, the frequency of the N running CPUs is increased.
优选的,若最大绘图时间大于屏幕刷新时间,此时为了避免由于最大绘图时间大于屏幕刷新时间而造成的图像卡顿现象,可以将N个运行的CPU的 频率调高一级,从而使得在较高的CPU频率下,绘图时间能够降低,满足绘图时间小于屏幕刷新时间的条件,从而避免图像卡顿现象的出现。另外,本实施例中涉及的有关CPU频率调节的实施例可以是通过CPU调频程序实现的。Preferably, if the maximum drawing time is greater than the screen refresh time, in order to avoid the image jamming caused by the maximum drawing time being greater than the screen refresh time, the N running CPUs may be The frequency is increased by one level, so that the drawing time can be reduced at a higher CPU frequency, and the condition that the drawing time is less than the screen refresh time is satisfied, thereby avoiding the occurrence of image jamming. In addition, the embodiment related to CPU frequency adjustment involved in this embodiment may be implemented by a CPU frequency modulation program.
参照图5,上述实施例二中多CPU的调频方案可以独立执行,不需要在对M个绘图线程进行绑定后再执行上文中的多CPU的调频方案,图5为本发明实施例三提供的多CPU调频方法流程示意图,其中,该多CPU调频方法可以由多CPU中的一个CPU执行。如图5所示,该多CPU调频方法包括如下步骤:Referring to FIG. 5, the frequency modulation scheme of the multiple CPUs in the foregoing embodiment 2 can be performed independently, and the frequency modulation scheme of the multiple CPUs in the above is not required after the binding of the M graphics threads. FIG. 5 is provided in Embodiment 3 of the present invention. A schematic diagram of a multi-CPU frequency modulation method, wherein the multi-CPU frequency modulation method can be executed by one CPU of a plurality of CPUs. As shown in FIG. 5, the multi-CPU frequency modulation method includes the following steps:
步骤200、获取M个绘图线程的绘图时间,并对M个绘图时间进行比较,获取其中的最大绘图时间,其中M为大于0的整数。Step 200: Obtain drawing time of M drawing threads, and compare M drawing times to obtain a maximum drawing time, where M is an integer greater than 0.
步骤201、将最大绘图时间与时间阈值进行比较。Step 201: Compare the maximum drawing time with a time threshold.
具体的,时间阈值可以根据需要进行配置,例如时间阈值=屏幕刷新时间×70%。若最大绘图时间小于时间阈值,执行步骤202;若最大绘图时间大于时间阈值,则执行步骤204。Specifically, the time threshold can be configured as needed, such as time threshold = screen refresh time x 70%. If the maximum drawing time is less than the time threshold, step 202 is performed; if the maximum drawing time is greater than the time threshold, step 204 is performed.
步骤202、获取估算绘图时间。Step 202: Obtain an estimated drawing time.
具体的,估算绘图时间的获取方式参照实施例二,此处不再赘述。Specifically, the method for obtaining the estimated drawing time is referred to the second embodiment, and details are not described herein again.
步骤203、将估算绘图时间与屏幕刷新时间进行比较,若估算绘图时间小于屏幕刷新时间,则将N个运行的CPU的频率降低。Step 203: Compare the estimated drawing time with the screen refresh time. If the estimated drawing time is less than the screen refresh time, reduce the frequency of the N running CPUs.
采用步骤203,若估算绘图时间小于屏幕刷新时间,将N个运行的CPU的频率降低,这样在保证用户观看图像时就不会有卡顿的感觉的同时,还可以降低多CPU的功耗。In step 203, if the estimated drawing time is less than the screen refresh time, the frequency of the N running CPUs is lowered, so that when the user is guaranteed to view the image, there is no feeling of stuttering, and the power consumption of the multiple CPUs can also be reduced.
步骤204、将最大绘图时间与屏幕刷新时间比较,若最大绘图时间大于屏幕刷新时间,则将N个运行的CPU的频率调高。Step 204: Compare the maximum drawing time with the screen refresh time. If the maximum drawing time is greater than the screen refresh time, increase the frequency of the N running CPUs.
采用步骤204,若最大绘图时间大于屏幕刷新时间,将N个运行的CPU的频率调高,这样用户在观看图像时就不会有卡顿的感觉。Step 204 is adopted. If the maximum drawing time is greater than the screen refresh time, the frequency of the N running CPUs is increased, so that the user does not feel stuck when viewing the image.
需要说明的是,图6为本发明提供的实施例二及实施例三中多CPU调度方法的一种可行的实现方式的效果示意图,图7为本发明提供的实施例二及 实施例三中多CPU调度方法的一种可行的实现方式的对比示意图,参照图6,其中T1为一个绘图线程的绘图时间,而T2为处理该绘图线程的CPU的屏幕刷新时间,通过采用本发明实施例的CPU频率调节方案,可以很明显的发现在调节之后,T2与T1之间的差值显著缩短,即CPU频率资源的利用率有显著提高,参照图7,对于没有采用本发明实施例二及实施例三技术方案的CPU,其CPU频率如未作CPU频率调节的CPU频率的波形(实线)所示,而经过CPU频率调节处理后的CPU频率波形图(虚线)显然更加平整,对于CPU频率的资源利用也更加充分,不会造成CPU频率资源的浪费。采取本发明提供的实施例二及实施例三中的CPU频率调节方案后,CPU频率调节处理后CPU的频率不会忽高忽低,大多时候是保持在较低频率上,CPU频率调节处理并不影响屏幕的刷新帧率。由这两图可知采用屏幕刷新CPU调频这一方案,能在不影响系统性能条件下(屏幕刷新帧率不变),减少CPU的空闲时间,充分利用CPU资源,使CPU能在更多时候工作在较低频率上。It is to be noted that FIG. 6 is a schematic diagram showing the effect of a feasible implementation manner of the multi-CPU scheduling method in the second embodiment and the third embodiment, and FIG. 7 is a second embodiment of the present invention. A comparison diagram of a feasible implementation manner of the multi-CPU scheduling method in the third embodiment, referring to FIG. 6, where T1 is the drawing time of one drawing thread, and T2 is the screen refresh time of the CPU processing the drawing thread, by adopting the present According to the CPU frequency adjustment scheme of the embodiment of the invention, it can be clearly found that after the adjustment, the difference between T2 and T1 is significantly shortened, that is, the utilization rate of the CPU frequency resource is significantly improved. Referring to FIG. 7, for the implementation of the present invention. In the CPU of the second embodiment and the third embodiment, the CPU frequency is as shown in the waveform of the CPU frequency (solid line) for which the CPU frequency is not adjusted, and the CPU frequency waveform (dotted line) after the CPU frequency adjustment processing is obviously flatter. The resource utilization of the CPU frequency is also more sufficient, and the CPU frequency resource is not wasted. After adopting the CPU frequency adjustment scheme in the second embodiment and the third embodiment provided by the present invention, the frequency of the CPU after the CPU frequency adjustment processing is not going to be high or low, and most of the time is kept at a lower frequency, and the CPU frequency adjustment processing is performed. Does not affect the refresh frame rate of the screen. It can be seen from these two diagrams that the screen refresh CPU frequency modulation scheme can reduce the idle time of the CPU without affecting the system performance (the screen refresh rate is unchanged), make full use of the CPU resources, and enable the CPU to work more often. At lower frequencies.
需要说明的是,上述各实施例以及各个可能的实现方式中,绘图线程个数M可以为全部绘图线程中CPU占用率大于CPU占用率阈值的绘图线程个数。It should be noted that, in each of the above embodiments and each possible implementation manner, the number M of drawing threads may be the number of drawing threads whose CPU usage is greater than the CPU occupancy threshold in all drawing threads.
图8为本发明实施例四提供的多CPU调度装置结构示意图,如图8所示,该多CPU调度装置,包括:获取模块10、绑定模块11。FIG. 8 is a schematic structural diagram of a multi-CPU scheduling apparatus according to Embodiment 4 of the present invention. As shown in FIG. 8, the multi-CPU scheduling apparatus includes: an obtaining module 10 and a binding module 11.
获取模块10,用于获取M个绘图线程中的一个绘图线程以及N个运行的CPU中的一个CPU,其中M为大于0的整数,N为大于0的整数。The obtaining module 10 is configured to acquire one of the M drawing threads and one of the N running CPUs, where M is an integer greater than 0, and N is an integer greater than 0.
具体的,获取绘图线程的个数M以及运行的CPU个数N可能的实现方式,上文实施例一中已经进行了详细说明,此处不再赘述。Specifically, the possible implementation manners of obtaining the number M of the drawing threads and the number of running CPUs N have been described in detail in the first embodiment, and are not described herein again.
绑定模块11,用于将所述M个绘图线程中的一个绘图线程绑定在所述N个运行的CPU中的一个CPU上处理。The binding module 11 is configured to bind one of the M drawing threads to one CPU of the N running CPUs.
具体的,绑定模块11通过设置绘图线程的CPU亲和性实现将绘图线程一对一地绑定在每一CPU上进行处理的方案。CPU亲和性上文实施例一中已经进行了详细说明,此处不再赘述。 Specifically, the binding module 11 implements a scheme of binding the drawing threads one-to-one on each CPU for processing by setting the CPU affinity of the drawing thread. The CPU affinity has been described in detail in the first embodiment, and details are not described herein again.
本发明实施例提供的多CPU调度方法,通过获取模块获取绘图线程的个数以及运行的CPU个数,再由绑定模块根据绘图线程的个数以及运行的CPU个数,当绘图线程的个数小于或等于运行的CPU个数时,将每一个绘图线程一对一地绑定在每一运行的CPU上进行处理。在不影响系统性能的前提下,充分利用了各个CPU的资源,使终端设备的多CPU整体工作在更低的频率上,降低了功耗。The multi-CPU scheduling method provided by the embodiment of the present invention acquires the number of drawing threads and the number of running CPUs by the acquiring module, and then the binding module according to the number of drawing threads and the number of running CPUs, when the drawing threads When the number is less than or equal to the number of running CPUs, each drawing thread is bound one-to-one on each running CPU for processing. Under the premise of not affecting the performance of the system, the resources of each CPU are fully utilized, so that the multi-CPU of the terminal device works at a lower frequency as a whole, thereby reducing power consumption.
优选的,获取模块10,还用于获取M个绘图线程的其他M-1个绘图线程以及N个运行的CPU的其他N-1个CPU。Preferably, the obtaining module 10 is further configured to acquire other M-1 drawing threads of the M drawing threads and other N-1 CPUs of the N running CPUs.
参照上文实施例二,绑定模块11用于当所述M-1小于所述N-1时,将所述M-1个绘图线程一对一的绑定在M-1个运行的CPU上处理;或者Referring to the second embodiment, the binding module 11 is configured to bind the M-1 drawing threads one-to-one to the M-1 running CPUs when the M-1 is smaller than the N-1. Processed on; or
当所述M-1等于所述N-1时,将所述M-1个绘图线程一对一的绑定在所述N-1个运行的CPU上处理;或者When the M-1 is equal to the N-1, the one-to-one binding of the M-1 drawing threads is processed on the N-1 running CPUs; or
当所述M-1大于所述N-1时,将N-1个绘图线程一对一的绑定在所述N-1个运行的CPU上处理,将M-N个绘图线程绑定在所述N-1个运行的CPU上的M-N个CPU上处理。When the M-1 is greater than the N-1, the one-to-one binding of the N-1 drawing threads is processed on the N-1 running CPUs, and the MN drawing threads are bound to the Processing on MN CPUs on N-1 running CPUs.
进一步的,获取模块10还用于:获取CPU占用率大于阈值的所述M个绘图线程中的一个绘图线程和/或所述M个绘图线程的其他M-1个绘图线程。Further, the obtaining module 10 is further configured to: acquire one of the M drawing threads whose CPU usage is greater than a threshold, and/or other M-1 drawing threads of the M drawing threads.
优选的,在完成M个绘图线程中的一个绘图线程的绑定,和/或M个绘图线程中的其他M-1个绘图线程的绑定之后,还可以进行多CPU的调频方案,并且该方案可以基于绑定模块11在对M中的一个绘图线程和/或M-1个绘图线程进行绑定的前提下进行N个运行的CPU的频率调节,也可以参照上文实施例三的方式实现,具体的,为了执行该多CPU的调频方案,参照图9,在图8的基础上,图9为本发明实施例五提供的多CPU调度装置结构示意图,如图9所示,该多CPU调度装置,还包括:最大绘图时间获取模块12、比较模块13、调节模块14。Preferably, after completing the binding of one of the M drawing threads, and/or the binding of the other M-1 drawing threads of the M drawing threads, a multi-CPU frequency modulation scheme may also be performed, and the The solution may perform the frequency adjustment of the N running CPUs on the premise that the binding module 11 binds one of the drawing threads and/or the M-1 drawing threads in the M, and may also refer to the manner of the third embodiment above. Specifically, in order to perform the multi-CPU frequency modulation scheme, referring to FIG. 9, on the basis of FIG. 8, FIG. 9 is a schematic structural diagram of a multi-CPU scheduling apparatus according to Embodiment 5 of the present invention, as shown in FIG. The CPU scheduling device further includes: a maximum drawing time acquiring module 12, a comparing module 13, and an adjusting module 14.
最大绘图时间获取模块12,用于获取所述M个绘图线程的绘图时间,并 对所述M个绘图时间进行比较,获取其中的最大绘图时间。a maximum drawing time obtaining module 12, configured to acquire a drawing time of the M drawing threads, and The M plot times are compared to obtain the maximum plot time.
具体的,在上文实施例二的步骤102中对如何获取绘图线程绘图时间以及如何获取最大绘图时间进行了详细的说明,此处不再赘述。Specifically, in the step 102 of the foregoing embodiment 2, how to obtain the drawing time of the drawing thread and how to obtain the maximum drawing time are described in detail, and details are not described herein again.
比较模块13,用于将最大绘图时间与时间阈值进行比较。The comparison module 13 is configured to compare the maximum drawing time with a time threshold.
进一步的,比较模块13,用于将所述最大绘图时间与时间阈值进行比较,根据比较结果调整所述N个运行的CPU的频率。Further, the comparison module 13 is configured to compare the maximum drawing time with a time threshold, and adjust the frequency of the N running CPUs according to the comparison result.
具体的,在上文实施例二的步骤103中对时间阈值进行了详细的说明,估算绘图时间通过上文中的公式(1)获得,此处均不再赘述。Specifically, the time threshold is described in detail in step 103 of Embodiment 2 above, and the estimated drawing time is obtained by the above formula (1), and details are not described herein again.
进一步的,比较模块13,还用于若所述最大绘图时间小于所述时间阈值,则获取估算绘图时间;Further, the comparing module 13 is further configured to: if the maximum drawing time is less than the time threshold, obtain an estimated drawing time;
估算绘图时间为N个运行的CPU的频率降低后,绘图线程的绘图时间。其中,可以将N个运行的CPU的频率降低一级。Estimate the plot time for the drawing time of the drawing thread after the frequency of the N running CPUs is reduced. Among them, the frequency of N running CPUs can be reduced by one level.
比较模块13,用于将所述估算绘图时间与屏幕刷新时间进行比较。The comparison module 13 is configured to compare the estimated drawing time with a screen refresh time.
调节模块14,用于若估算绘图时间小于屏幕刷新时间,则将N个运行的CPU的频率降低。The adjustment module 14 is configured to reduce the frequency of the N running CPUs if the estimated drawing time is less than the screen refresh time.
需要说明的是,降低CPU的频率,可以是针对N个CPU的频率整体降低频率。It should be noted that, to reduce the frequency of the CPU, the frequency may be reduced overall for the frequencies of the N CPUs.
优选的,比较模块13,还用于若最大绘图时间大于时间阈值,则将最大绘图时间与屏幕刷新时间比较。Preferably, the comparison module 13 is further configured to compare the maximum drawing time with the screen refresh time if the maximum drawing time is greater than the time threshold.
调节模块14,用于若最大绘图时间大于屏幕刷新时间,则将N个运行的CPU的频率调高。例如,可以将N个运行的CPU的频率调高一级。The adjustment module 14 is configured to increase the frequency of the N running CPUs if the maximum drawing time is greater than the screen refresh time. For example, the frequency of N running CPUs can be increased by one level.
若最大绘图时间大于屏幕刷新时间,此时为了避免由于最大绘图时间大于屏幕刷新时间而造成的图像卡顿现象,可以将N个运行的CPU的频率调高一级,从而使得在较高的CPU频率下,绘图时间能够降低,满足绘图时间小于屏幕刷新时间的条件,从而避免图像卡顿现象的出现。If the maximum drawing time is greater than the screen refresh time, in order to avoid image jamming caused by the maximum drawing time being greater than the screen refresh time, the frequency of the N running CPUs can be increased by one level, thereby making the CPU higher. At the frequency, the drawing time can be reduced to meet the condition that the drawing time is less than the screen refresh time, thereby avoiding the occurrence of image jamming.
本发明实施例六提供一种终端,可用于执行本发明实施例一至实施例三 中所述的方法。图10为本发明实施例六提供的终端结构示意图,图10示出了本发明实施例六提供的终端500的结构。 Embodiment 6 of the present invention provides a terminal, which can be used to perform Embodiment 1 to Embodiment 3 of the present invention. The method described in the above. FIG. 10 is a schematic structural diagram of a terminal according to Embodiment 6 of the present invention, and FIG. 10 is a schematic structural diagram of a terminal 500 according to Embodiment 6 of the present invention.
该终端可以为包括手机、平板电脑、PDA(Personal Digital Assistant,个人数字助理)、POS(Point of Sales,销售终端)、车载电脑等终端设备,以终端为手机为例,图10示出的是与本发明实施例提供的终端相关的手机500的部分结构的框图。参考图10,手机500包括RF(Radio Frequency,射频)电路510、存储器520、输入单元530、显示单元540、传感器550、音频电路560、WiFi(wireless fidelity,无线保真)模块570、处理器580、以及电源590等部件。本领域技术人员可以理解,图10中示出的手机结构只做实现方式的举例,并不构成对手机的限定,可以包括比图示更多或更少的部件,或者组合某些部件,或者不同的部件布置。The terminal may be a terminal device including a mobile phone, a tablet computer, a PDA (Personal Digital Assistant), a POS (Point of Sales), an in-vehicle computer, etc., and the terminal is a mobile phone as an example, and FIG. 10 shows A block diagram of a partial structure of a mobile phone 500 related to a terminal provided by an embodiment of the present invention. Referring to FIG. 10, the mobile phone 500 includes an RF (Radio Frequency) circuit 510, a memory 520, an input unit 530, a display unit 540, a sensor 550, an audio circuit 560, a WiFi (Wireless Fidelity) module 570, and a processor 580. And power supply 590 and other components. It can be understood by those skilled in the art that the structure of the mobile phone shown in FIG. 10 is only an example of implementation, and does not constitute a limitation on the mobile phone, and may include more or less components than those illustrated, or combine some components, or Different parts are arranged.
下面结合图10对手机500的各个构成部件进行具体的介绍:The components of the mobile phone 500 will be specifically described below with reference to FIG. 10:
RF电路510可用于收发信息或通话过程中,信号的接收和发送,特别地,将基站的下行信息接收后,给处理器580处理;另外,将上行的数据发送给基站。通常,RF电路包括但不限于天线、至少一个放大器、收发信机、耦合器、LNA(Low Noise Amplifier,低噪声放大器)、双工器等。此外,RF电路510还可以通过无线通信与网络和其他设备通信。所述无线通信可以使用任一通信标准或协议,包括但不限于GSM(Global System of Mobile communication,全球移动通讯系统)、GPRS(General Packet Radio Service,通用分组无线服务)、CDMA(Code Division Multiple Access,码分多址)、WCDMA(Wideband Code Division Multiple Access,宽带码分多址)、LTE(Long Term Evolution,长期演进)、电子邮件、SMS(Short Messaging Service,短消息服务)等。The RF circuit 510 can be used for receiving and transmitting signals during and after the transmission or reception of information, in particular, after receiving the downlink information of the base station, and processing it to the processor 580; in addition, transmitting the uplink data to the base station. Generally, RF circuits include, but are not limited to, an antenna, at least one amplifier, a transceiver, a coupler, an LNA (Low Noise Amplifier), a duplexer, and the like. In addition, RF circuitry 510 can also communicate with the network and other devices via wireless communication. The wireless communication may use any communication standard or protocol, including but not limited to GSM (Global System of Mobile communication), GPRS (General Packet Radio Service), CDMA (Code Division Multiple Access). , Code Division Multiple Access), WCDMA (Wideband Code Division Multiple Access), LTE (Long Term Evolution), e-mail, SMS (Short Messaging Service), and the like.
存储器520可用于存储软件程序,处理器580通过运行存储在存储器520的软件程序,从而执行手机500的各种功能应用以及数据处理。存储器520可主要包括存储程序区和存储数据区,其中,存储程序区可存储操作系统、至少一个功能所需的应用程序(比如声音播放功能、图像播放功能等)等;存储 数据区可存储根据手机500的使用所创建的数据(比如音频数据、电话本等)等。此外,存储器520可以包括高速随机存取存储器,还可以包括非易失性存储器,例如至少一个磁盘存储器件、闪存器件、或其他易失性固态存储器件。The memory 520 can be used to store software programs, and the processor 580 executes various functional applications and data processing of the mobile phone 500 by running software programs stored in the memory 520. The memory 520 may mainly include a storage program area and a storage data area, wherein the storage program area may store an operating system, an application required for at least one function (such as a sound playing function, an image playing function, etc.), and the like; The data area can store data (such as audio data, phone book, etc.) created according to the use of the mobile phone 500. Moreover, memory 520 can include high speed random access memory, and can also include non-volatile memory, such as at least one magnetic disk storage device, flash memory device, or other volatile solid state storage device.
输入单元530可用于接收输入的数字或字符信息,以及产生与手机500的用户设置以及功能控制有关的键信号输入。具体地,输入单元530可包括触控面板531以及其他输入设备532。触控面板531,也称为触摸屏,可收集用户在其上或附近的触摸操作(比如用户使用手指、触笔等任何适合的物体或附件在触控面板531上或在触控面板531附近的操作),并根据预先设定的程式驱动相应的连接装置。可选的,触控面板531可包括触摸检测装置和触摸控制器两个部分。其中,触摸检测装置检测用户的触摸方位,并检测触摸操作带来的信号,将信号传送给触摸控制器;触摸控制器从触摸检测装置上接收触摸信息,并将它转换成触点坐标,再送给处理器580,并能接收处理器580发来的命令并加以执行。此外,可以采用电阻式、电容式、红外线以及表面声波等多种类型实现触控面板531。除了触控面板531,输入单元530还可以包括其他输入设备532。具体地,其他输入设备532可以包括但不限于物理键盘、功能键(比如音量控制按键、开关按键等)、轨迹球、鼠标、操作杆等中的一种或多种。The input unit 530 can be configured to receive input numeric or character information and to generate key signal inputs related to user settings and function control of the handset 500. Specifically, the input unit 530 may include a touch panel 531 and other input devices 532. The touch panel 531, also referred to as a touch screen, can collect touch operations on or near the user (such as the user using a finger, a stylus, or the like on the touch panel 531 or near the touch panel 531. Operation), and drive the corresponding connecting device according to a preset program. Optionally, the touch panel 531 can include two parts: a touch detection device and a touch controller. Wherein, the touch detection device detects the touch orientation of the user, and detects a signal brought by the touch operation, and transmits the signal to the touch controller; the touch controller receives the touch information from the touch detection device, converts the touch information into contact coordinates, and sends the touch information. The processor 580 is provided and can receive commands from the processor 580 and execute them. In addition, the touch panel 531 can be implemented in various types such as resistive, capacitive, infrared, and surface acoustic waves. In addition to the touch panel 531, the input unit 530 may also include other input devices 532. Specifically, other input devices 532 may include, but are not limited to, one or more of a physical keyboard, function keys (such as volume control buttons, switch buttons, etc.), trackballs, mice, joysticks, and the like.
显示单元540可用于显示由用户输入的信息或提供给用户的信息以及手机500的各种菜单。显示单元540可包括显示面板541,可选的,可以采用LCD(Liquid Crystal Display,液晶显示器)、OLED(Organic Light-Emitting Diode,有机发光二极管)等形式来配置显示面板541。进一步的,触控面板531可覆盖显示面板541,当触控面板531检测到在其上或附近的触摸操作后,传送给处理器580以确定触摸事件的类型,随后处理器580根据触摸事件的类型在显示面板541上提供相应的视觉输出。虽然在图10中,触控面板531与显示面板541是作为两个独立的部件来实现手机500的输入和输入功能,但是在某些实施例中,可以将触控面板531与显示面板541集成而实现手机500的输入和 输出功能。The display unit 540 can be used to display information input by the user or information provided to the user and various menus of the mobile phone 500. The display unit 540 can include a display panel 541. Alternatively, the display panel 541 can be configured in the form of an LCD (Liquid Crystal Display), an OLED (Organic Light-Emitting Diode), or the like. Further, the touch panel 531 can cover the display panel 541. When the touch panel 531 detects a touch operation on or near it, the touch panel 531 transmits to the processor 580 to determine the type of the touch event, and then the processor 580 according to the touch event. The type provides a corresponding visual output on display panel 541. Although in FIG. 10, the touch panel 531 and the display panel 541 are two independent components to implement the input and input functions of the mobile phone 500, in some embodiments, the touch panel 531 can be integrated with the display panel 541. And realize the input of the mobile phone 500 and Output function.
手机500还可包括至少一种传感器550,比如光传感器、运动传感器以及其他传感器。具体地,光传感器可包括环境光传感器及接近传感器,其中,环境光传感器可根据环境光线的明暗来调节显示面板541的亮度,接近传感器可在手机500移动到耳边时,关闭显示面板541和/或背光。作为运动传感器的一种,加速计传感器可检测各个方向上(一般为三轴)加速度的大小,静止时可检测出重力的大小及方向,可用于识别手机姿态的应用(比如横竖屏切换、相关游戏、磁力计姿态校准)、振动识别相关功能(比如计步器、敲击)等;至于手机500还可配置的陀螺仪、气压计、湿度计、温度计、红外线传感器等其他传感器,在此不再赘述。The handset 500 can also include at least one type of sensor 550, such as a light sensor, motion sensor, and other sensors. Specifically, the light sensor may include an ambient light sensor and a proximity sensor, wherein the ambient light sensor may adjust the brightness of the display panel 541 according to the brightness of the ambient light, and the proximity sensor may close the display panel 541 when the mobile phone 500 moves to the ear. / or backlight. As a kind of motion sensor, the accelerometer sensor can detect the magnitude of acceleration in all directions (usually three axes). When it is stationary, it can detect the magnitude and direction of gravity. It can be used to identify the gesture of the mobile phone (such as horizontal and vertical screen switching, related Game, magnetometer attitude calibration), vibration recognition related functions (such as pedometer, tapping), etc. As for the mobile phone 500 can also be configured with gyroscopes, barometers, hygrometers, thermometers, infrared sensors and other sensors, here Let me repeat.
音频电路560、扬声器561,传声器562可提供用户与手机500之间的音频接口。音频电路560可将接收到的音频数据转换后的电信号,传输到扬声器561,由扬声器561转换为声音信号输出;另一方面,传声器562将收集的声音信号转换为电信号,由音频电路560接收后转换为音频数据,再将音频数据输出处理器580处理后,经RF电路510以发送给比如另一手机,或者将音频数据输出至存储器520以便进一步处理。 Audio circuit 560, speaker 561, and microphone 562 can provide an audio interface between the user and handset 500. The audio circuit 560 can transmit the converted electrical data of the received audio data to the speaker 561, and convert it into a sound signal output by the speaker 561. On the other hand, the microphone 562 converts the collected sound signal into an electrical signal, and the audio circuit 560 is used by the audio circuit 560. After receiving, it is converted into audio data, and then processed by the audio data output processor 580, sent to the other mobile phone via the RF circuit 510, or outputted to the memory 520 for further processing.
WiFi属于短距离无线传输技术,手机500通过WiFi模块570可以帮助用户收发电子邮件、浏览网页和访问流式媒体等,它为用户提供了无线的宽带互联网访问。虽然图10示出了WiFi模块570,但是可以理解的是,其并不属于手机500的必须构成,完全可以根据需要在不改变发明的本质的范围内而省略。WiFi is a short-range wireless transmission technology, and the mobile phone 500 can help users to send and receive emails, browse web pages, and access streaming media through the WiFi module 570, which provides wireless broadband Internet access for users. Although FIG. 10 shows the WiFi module 570, it can be understood that it does not belong to the essential configuration of the mobile phone 500, and may be omitted as needed within the scope of not changing the essence of the invention.
处理器580是手机500的控制中心,利用各种接口和线路连接整个手机的各个部分,通过运行或执行存储在存储器520内的软件程序和/或模块,以及调用存储在存储器520内的数据,执行手机500的各种功能和处理数据,从而对手机进行整体监控。可选的,处理器580可包括一个或多个处理单元;优选的,处理器580可集成应用处理器和调制解调处理器,其中,应用处理 器主要处理操作系统、用户界面和应用程序等,调制解调处理器主要处理无线通信。可以理解的是,上述调制解调处理器也可以不集成到处理器580中。 Processor 580 is the control center of handset 500, which connects various portions of the entire handset using various interfaces and lines, by running or executing software programs and/or modules stored in memory 520, and recalling data stored in memory 520, The various functions and processing data of the mobile phone 500 are performed to perform overall monitoring of the mobile phone. Optionally, the processor 580 may include one or more processing units; preferably, the processor 580 may integrate an application processor and a modem processor, where the application processes The main processing system, user interface and applications, etc., the modem processor mainly deals with wireless communication. It will be appreciated that the above described modem processor may also not be integrated into the processor 580.
手机500还包括给各个部件供电的电源590(比如电池),优选的,电源可以通过电源管理系统与处理器580逻辑相连,从而通过电源管理系统实现管理充电、放电、以及功耗管理等功能。The handset 500 also includes a power source 590 (such as a battery) that supplies power to the various components. Preferably, the power source can be logically coupled to the processor 580 via a power management system to manage functions such as charging, discharging, and power management through the power management system.
尽管未示出,手机500还可以包括摄像头、蓝牙模块等,在此不再赘述。Although not shown, the mobile phone 500 may further include a camera, a Bluetooth module, and the like, and details are not described herein again.
在本发明实施例中,该终端所包括处理器580具有以下功能:In the embodiment of the present invention, the terminal includes a processor 580 having the following functions:
处理器580,用于获取M个绘图线程中的一个绘图线程以及N个运行的CPU中的一个CPU,其中M为大于0的整数,N为大于0的整数。The processor 580 is configured to acquire one of the M drawing threads and one of the N running CPUs, where M is an integer greater than 0, and N is an integer greater than 0.
具体的,需要说明的是,对于多处理器的终端,则该处理器580为多处理器中的一个处理器。获取绘图线程的个数M以及运行的CPU个数N可能的实现方式,上文实施例一中已经进行了详细说明,此处不再赘述。Specifically, it should be noted that, for a multi-processor terminal, the processor 580 is one of the multi-processors. The possible implementation manners of obtaining the number M of the drawing threads and the number of running CPUs N have been described in detail in the first embodiment, and are not described herein again.
处理器580,用于将所述M个绘图线程中的一个绘图线程绑定在所述N个运行的CPU中的一个CPU上处理。The processor 580 is configured to bind one of the M drawing threads to one CPU of the N running CPUs.
具体的,处理器580通过设置绘图线程的CPU亲和性实现将所述M个绘图线程中的一个绘图线程绑定在所述N个运行的CPU中的一个CPU上处理的方案。CPU亲和性上文实施例一中已经进行了详细说明,此处不再赘述。Specifically, the processor 580 implements a scheme of binding one of the M drawing threads to one of the N running CPUs by setting a CPU affinity of the drawing thread. The CPU affinity has been described in detail in the first embodiment, and details are not described herein again.
在本发明实施例中,该终端所包括存储器520具有以下功能:用于存储于本发明相关的CPU调度程序、CPU调频程序以及与绘图相关的函数,以备处理器在运行CPU调度进程、CPU调频进程以及绘图线程时调用。In the embodiment of the present invention, the memory 520 included in the terminal has the following functions: a CPU scheduler, a CPU frequency modulation program, and a drawing-related function stored in the present invention, in preparation for the processor to run the CPU scheduling process, and the CPU. Called when the FM process and the drawing thread.
本发明实施例提供的多CPU调度方法,通过处理器获取绘图线程的个数以及运行的CPU个数,再由处理器根据绘图线程的个数以及运行的CPU个数,当绘图线程的个数小于或等于运行的CPU个数时,将每一个绘图线程一对一地绑定在每一CPU上进行处理。在不影响系统性能的前提下,充分利用了各个CPU的资源,使终端设备的多CPU整体工作在更低的频率上,降低了功耗。The multi-CPU scheduling method provided by the embodiment of the present invention acquires the number of drawing threads and the number of running CPUs by the processor, and then the number of drawing threads according to the number of drawing threads and the number of running CPUs by the processor. When the number of CPUs is less than or equal to each other, each drawing thread is bound one-to-one on each CPU for processing. Under the premise of not affecting the performance of the system, the resources of each CPU are fully utilized, so that the multi-CPU of the terminal device works at a lower frequency as a whole, thereby reducing power consumption.
优选的,处理器580,还用于获取M个绘图线程的其他M-1个绘图线程以 及N个运行的CPU的其他N-1个CPU。Preferably, the processor 580 is further configured to acquire other M-1 drawing threads of the M drawing threads. And other N-1 CPUs of N running CPUs.
进一步的,处理器580,具体用于:Further, the processor 580 is specifically configured to:
当所述M-1小于所述N-1时,则将所述M-1个绘图线程一对一的绑定在M-1个运行的CPU上处理;或者When the M-1 is smaller than the N-1, the one-to-one binding of the M-1 drawing threads is processed on the M-1 running CPUs; or
当所述M-1等于所述N-1时,将所述M-1个绘图线程一对一的绑定在所述N-1个运行的CPU上处理;或者When the M-1 is equal to the N-1, the one-to-one binding of the M-1 drawing threads is processed on the N-1 running CPUs; or
当所述M-1大于所述N-1时,将N-1个绘图线程一对一的绑定在所述N-1个运行的CPU上处理,将M-N个绘图线程绑定在所述N-1个运行的CPU上的M-N个CPU上处理。When the M-1 is greater than the N-1, the one-to-one binding of the N-1 drawing threads is processed on the N-1 running CPUs, and the MN drawing threads are bound to the Processing on MN CPUs on N-1 running CPUs.
进一步的,在完成M个绘图线程中的一个绘图线程的绑定,和/或M个绘图线程中的其他M-1个绘图线程的绑定之后,还可以进行多CPU的调频方案,并且该方案可以基于处理器580在对M中的一个绘图线程和/或M-1个绘图线程进行绑定的前提下进行N个运行的CPU的频率调节,也可以参照上文实施例三的方式实现,具体的,处理器580,用于获取CPU占用率大于阈值的所述M个绘图线程中的一个绘图线程和/或所述M个绘图线程的其他M-1个绘图线程,并获取所述M个绘图线程的绘图时间,并对所述M个绘图时间进行比较,获取其中的最大绘图时间。Further, after completing binding of one drawing thread of the M drawing threads, and/or binding of other M-1 drawing threads of the M drawing threads, a multi-CPU frequency modulation scheme may also be performed, and The solution may perform the frequency adjustment of the N running CPUs on the premise that the processor 580 binds one of the drawing threads and/or the M-1 drawing threads in the M, and may also implement the method in the third embodiment. Specifically, the processor 580 is configured to acquire one of the M drawing threads whose CPU usage is greater than a threshold, and/or other M-1 drawing threads of the M drawing threads, and obtain the The drawing time of the M drawing threads, and comparing the M drawing times, and obtaining the maximum drawing time among them.
具体的,需要说明的是,上文实施例二中已经对CPU占用率以及阈值以及如何获取绘图线程绘图时间以及如何获取最大绘图时间进行了详细的说明,此处不再赘述。Specifically, it should be noted that, in the foregoing Embodiment 2, the CPU usage and the threshold, how to obtain the drawing time of the drawing thread, and how to obtain the maximum drawing time have been described in detail, and details are not described herein again.
处理器580,用于将所述最大绘图时间与时间阈值进行比较,根据比较结果调整所述N个运行的CPU的频率。The processor 580 is configured to compare the maximum drawing time with a time threshold, and adjust a frequency of the N running CPUs according to the comparison result.
进一步的,处理器580,具体用于若所述最大绘图时间小于所述时间阈值,则获取估算绘图时间。Further, the processor 580 is specifically configured to: if the maximum drawing time is less than the time threshold, obtain an estimated drawing time.
具体的,在上文实施例二的步骤103中对时间阈值进行了详细的说明,估算绘图时间通过上文中的公式(1)获得,此处均不再赘述。 Specifically, the time threshold is described in detail in step 103 of Embodiment 2 above, and the estimated drawing time is obtained by the above formula (1), and details are not described herein again.
估算绘图时间可以为N个运行的CPU的频率降低一级后,绘图线程的绘图时间。Estimating the plot time can be a plot time for the plot thread after the frequency of the N running CPUs is reduced by one.
处理器580,还用于将估算绘图时间与屏幕刷新时间进行比较。The processor 580 is further configured to compare the estimated drawing time with the screen refresh time.
处理器580,用于若估算绘图时间小于屏幕刷新时间,则将N个运行的CPU的频率降低。The processor 580 is configured to reduce the frequency of the N running CPUs if the estimated drawing time is less than the screen refresh time.
需要说明的是,降低运行的CPU的频率,是针对N个运行的CPU的频率整体降低频率。It should be noted that reducing the frequency of the running CPU is to reduce the frequency of the entire frequency of the N operating CPUs.
优选的,处理器580,还用于若最大绘图时间大于时间阈值,则将最大绘图时间与屏幕刷新时间比较。Preferably, the processor 580 is further configured to compare the maximum drawing time with the screen refresh time if the maximum drawing time is greater than the time threshold.
处理器580,用于若最大绘图时间大于屏幕刷新时间,则将N个运行的CPU的频率调高。The processor 580 is configured to increase the frequency of the N running CPUs if the maximum drawing time is greater than the screen refresh time.
若最大绘图时间大于屏幕刷新时间,此时为了避免由于最大绘图时间大于屏幕刷新时间而造成的图像卡顿现象,可以将N个运行的CPU的频率调高一级,从而使得在较高的CPU频率下,绘图时间能够降低,满足绘图时间小于屏幕刷新时间的条件,从而避免图像卡顿现象的出现。If the maximum drawing time is greater than the screen refresh time, in order to avoid image jamming caused by the maximum drawing time being greater than the screen refresh time, the frequency of the N running CPUs can be increased by one level, thereby making the CPU higher. At the frequency, the drawing time can be reduced to meet the condition that the drawing time is less than the screen refresh time, thereby avoiding the occurrence of image jamming.
本领域普通技术人员可以理解:实现上述各方法实施例的全部或部分步骤可以通过程序指令相关的硬件来完成。前述的程序可以存储于一计算机可读取存储介质中。该程序在执行时,执行包括上述各方法实施例的步骤;而前述的存储介质包括:ROM、RAM、磁碟或者光盘等各种可以存储程序代码的介质。One of ordinary skill in the art will appreciate that all or part of the steps to implement the various method embodiments described above may be accomplished by hardware associated with the program instructions. The aforementioned program can be stored in a computer readable storage medium. The program, when executed, performs the steps including the foregoing method embodiments; and the foregoing storage medium includes various media that can store program codes, such as a ROM, a RAM, a magnetic disk, or an optical disk.
最后应说明的是:以上各实施例仅用以说明本发明的技术方案,而非对其限制;尽管参照前述各实施例对本发明进行了详细的说明,本领域的普通技术人员应当理解:其依然可以对前述各实施例所记载的技术方案进行修改,或者对其中部分或者全部技术特征进行等同替换;而这些修改或者替换,并不使相应技术方案的本质脱离本发明各实施例技术方案的范围。 Finally, it should be noted that the above embodiments are merely illustrative of the technical solutions of the present invention, and are not intended to be limiting; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art will understand that The technical solutions described in the foregoing embodiments may be modified, or some or all of the technical features may be equivalently replaced; and the modifications or substitutions do not deviate from the technical solutions of the embodiments of the present invention. range.

Claims (18)

  1. 一种多CPU调度方法,其特征在于,包括:A multi-CPU scheduling method, comprising:
    获取M个绘图线程中的一个绘图线程以及N个运行的CPU中的一个CPU,其中M为大于0的整数,N为大于0的整数;Obtaining one of the M drawing threads and one of the N running CPUs, where M is an integer greater than 0, and N is an integer greater than 0;
    将所述M个绘图线程中的一个绘图线程绑定在所述N个运行的CPU中的一个CPU上处理。Binding one of the M drawing threads to one of the N running CPUs for processing.
  2. 根据权利要求1所述的方法,其特征在于,获取M个绘图线程的其他M-1个绘图线程以及N个运行的CPU的其他N-1个CPU;The method according to claim 1, wherein the other M-1 drawing threads of the M drawing threads and the other N-1 CPUs of the N running CPUs are acquired;
    当所述M-1小于所述N-1时,则将所述M-1个绘图线程一对一的绑定在M-1个运行的CPU上处理;或者When the M-1 is smaller than the N-1, the one-to-one binding of the M-1 drawing threads is processed on the M-1 running CPUs; or
    当所述M-1等于所述N-1时,将所述M-1个绘图线程一对一的绑定在所述N-1个运行的CPU上处理;或者When the M-1 is equal to the N-1, the one-to-one binding of the M-1 drawing threads is processed on the N-1 running CPUs; or
    当所述M-1大于所述N-1时,将N-1个绘图线程一对一的绑定在所述N-1个运行的CPU上处理,将M-N个绘图线程绑定在所述N-1个运行的CPU上的M-N个CPU上处理。When the M-1 is greater than the N-1, the one-to-one binding of the N-1 drawing threads is processed on the N-1 running CPUs, and the MN drawing threads are bound to the Processing on MN CPUs on N-1 running CPUs.
  3. 根据权利要求1或2所述的方法,其特征在于,Method according to claim 1 or 2, characterized in that
    获取CPU占用率大于阈值的所述M个绘图线程中的一个绘图线程和/或所述M个绘图线程的其他M-1个绘图线程。Obtaining one of the M drawing threads whose CPU usage is greater than a threshold and/or other M-1 drawing threads of the M drawing threads.
  4. 根据权利要求2或3所述的方法,其特征在于,所述方法还包括:The method according to claim 2 or 3, wherein the method further comprises:
    获取所述M个绘图线程的绘图时间,并对所述M个绘图时间进行比较,获取其中的最大绘图时间;Obtaining a drawing time of the M drawing threads, and comparing the M drawing times to obtain a maximum drawing time thereof;
    将所述最大绘图时间与时间阈值进行比较,根据比较结果调整所述N个运行的CPU的频率。The maximum drawing time is compared with a time threshold, and the frequency of the N running CPUs is adjusted according to the comparison result.
  5. 根据权利要求4所述的方法,其特征在于,所述将所述最大绘图时间与时间阈值进行比较,包括:The method of claim 4 wherein said comparing said maximum drawing time to a time threshold comprises:
    若所述最大绘图时间小于所述时间阈值,则获取估算绘图时间; If the maximum drawing time is less than the time threshold, obtaining an estimated drawing time;
    所述估算绘图时间为所述N个运行的CPU的频率降低后,所述绘图线程的绘图时间;The estimated drawing time is a drawing time of the drawing thread after the frequency of the N running CPUs is decreased;
    将所述估算绘图时间与屏幕刷新时间进行比较,若所述估算绘图时间小于所述屏幕刷新时间,则将所述N个运行的CPU的频率降低。The estimated drawing time is compared with a screen refresh time, and if the estimated drawing time is less than the screen refresh time, the frequency of the N running CPUs is decreased.
  6. 根据权利要求4所述的方法,其特征在于,所述将所述最大绘图时间与时间阈值进行比较,包括:The method of claim 4 wherein said comparing said maximum drawing time to a time threshold comprises:
    若所述最大绘图时间大于所述时间阈值,则将所述最大绘图时间与屏幕刷新时间比较;If the maximum drawing time is greater than the time threshold, comparing the maximum drawing time with a screen refresh time;
    若所述最大绘图时间大于所述屏幕刷新时间,则将所述N个运行的CPU的频率调高。If the maximum drawing time is greater than the screen refresh time, the frequency of the N running CPUs is increased.
  7. 一种多CPU调度装置,其特征在于,包括:A multi-CPU scheduling device, comprising:
    获取模块,用于获取M个绘图线程中的一个绘图线程以及N个运行的CPU中的一个CPU,其中M为大于0的整数,N为大于0的整数;The obtaining module is configured to acquire one of the M drawing threads and one of the N running CPUs, where M is an integer greater than 0, and N is an integer greater than 0;
    绑定模块,用于将所述M个绘图线程中的一个绘图线程绑定在所述N个运行的CPU中的一个CPU上处理。And a binding module, configured to bind one of the M drawing threads to one CPU of the N running CPUs.
  8. 根据权利要求7所述的装置,其特征在于,所述获取模块,用于获取M个绘图线程的其他M-1个绘图线程以及N个运行的CPU的其他N-1个CPU;The apparatus according to claim 7, wherein the obtaining module is configured to acquire other M-1 drawing threads of the M drawing threads and other N-1 CPUs of the N running CPUs;
    所述绑定模块,用于:The binding module is configured to:
    当所述M-1小于所述N-1时,则将所述M-1个绘图线程一对一的绑定在M-1个运行的CPU上处理;或者When the M-1 is smaller than the N-1, the one-to-one binding of the M-1 drawing threads is processed on the M-1 running CPUs; or
    当所述M-1等于所述N-1时,将所述M-1个绘图线程一对一的绑定在所述N-1个运行的CPU上处理;或者When the M-1 is equal to the N-1, the one-to-one binding of the M-1 drawing threads is processed on the N-1 running CPUs; or
    当所述M-1大于所述N-1时,将N-1个绘图线程一对一的绑定在所述N-1个运行的CPU上处理,将M-N个绘图线程绑定在所述N-1个运行的CPU上的M-N个CPU上处理。When the M-1 is greater than the N-1, the one-to-one binding of the N-1 drawing threads is processed on the N-1 running CPUs, and the MN drawing threads are bound to the Processing on MN CPUs on N-1 running CPUs.
  9. 根据权利要求7或8所述的装置,其特征在于,所述获取模块,用于: 获取CPU占用率大于阈值的所述M个绘图线程中的一个绘图线程和/或所述M个绘图线程的其他M-1个绘图线程。The device according to claim 7 or 8, wherein the obtaining module is configured to: Obtaining one of the M drawing threads whose CPU usage is greater than a threshold and/or other M-1 drawing threads of the M drawing threads.
  10. 根据权利要求8或9所述的装置,其特征在于,还包括:The device according to claim 8 or 9, further comprising:
    最大绘图时间获取模块,用于获取所述M个绘图线程的绘图时间,并对所述M个绘图时间进行比较,获取其中的最大绘图时间;a maximum drawing time obtaining module, configured to acquire a drawing time of the M drawing threads, compare the M drawing times, and obtain a maximum drawing time thereof;
    比较模块,用于将所述最大绘图时间与时间阈值进行比较,根据比较结果调整所述N个运行的CPU的频率。And a comparison module, configured to compare the maximum drawing time with a time threshold, and adjust a frequency of the N running CPUs according to the comparison result.
  11. 根据权利要求10所述的装置,其特征在于,所述比较模块,用于若所述最大绘图时间小于所述时间阈值,则获取估算绘图时间;The device according to claim 10, wherein the comparing module is configured to acquire an estimated drawing time if the maximum drawing time is less than the time threshold;
    所述估算绘图时间为所述N个运行的CPU的频率降低后,所述绘图线程的绘图时间;The estimated drawing time is a drawing time of the drawing thread after the frequency of the N running CPUs is decreased;
    所述比较模块,用于将所述估算绘图时间与屏幕刷新时间进行比较;The comparing module is configured to compare the estimated drawing time with a screen refresh time;
    调节模块,用于若所述估算绘图时间小于所述屏幕刷新时间,则将所述N个运行的CPU的频率降低。And an adjustment module, configured to reduce a frequency of the N running CPUs if the estimated drawing time is less than the screen refresh time.
  12. 根据权利要求10所述的装置,其特征在于,所述比较模块,用于若所述最大绘图时间大于所述时间阈值,则将所述最大绘图时间与屏幕刷新时间比较;The device according to claim 10, wherein the comparing module is configured to compare the maximum drawing time with a screen refresh time if the maximum drawing time is greater than the time threshold;
    所述调节模块,用于若所述最大绘图时间大于所述屏幕刷新时间,则将所述N个运行的CPU的频率调高。The adjusting module is configured to increase a frequency of the N running CPUs if the maximum drawing time is greater than the screen refresh time.
  13. 一种终端,其特征在于,包括多个处理器和存储器,其中,A terminal, comprising: a plurality of processors and a memory, wherein
    所述存储器,用于存储所述多个处理器中第一处理器运行所需的程序;The memory is configured to store a program required for the first processor to operate in the plurality of processors;
    所述第一处理器运行所述存储器的程序,用于获取M个绘图线程中的一个绘图线程以及N个运行的CPU中的一个CPU,其中M为大于0的整数,N为大于0的整数,以及用于将所述M个绘图线程中的一个绘图线程绑定在所述N个运行的CPU中的一个CPU上处理。The first processor runs the program of the memory, and is used to acquire one of the M drawing threads and one of the N running CPUs, where M is an integer greater than 0, and N is an integer greater than 0 And processing for binding one of the M drawing threads to one of the N running CPUs.
  14. 根据权利要求13所述的终端,其特征在于,所述第一处理器,用户获 取M个绘图线程的其他M-1个绘图线程以及N个运行的CPU的其他N-1个CPU;The terminal according to claim 13, wherein said first processor is obtained by a user Take other M-1 drawing threads of M drawing threads and other N-1 CPUs of N running CPUs;
    当所述M-1小于所述N-1时,所述第一处理器,用于将所述M-1个绘图线程一对一的绑定在M-1个运行的CPU上处理;或者When the M-1 is smaller than the N-1, the first processor is configured to perform one-to-one binding of the M-1 drawing threads on the M-1 running CPUs; or
    当所述M-1等于所述N-1时,所述第一处理器,用于将所述M-1个绘图线程一对一的绑定在所述N-1个运行的CPU上处理;或者When the M-1 is equal to the N-1, the first processor is configured to process the one-to-one binding of the M-1 drawing threads on the N-1 running CPUs. ;or
    当所述M-1大于所述N-1时,所述第一处理器,用于将N-1个绘图线程一对一的绑定在所述N-1个运行的CPU上处理,将M-N个绘图线程绑定在所述N-1个运行的CPU上的M-N个CPU上处理。When the M-1 is greater than the N-1, the first processor is configured to perform one-to-one binding of N-1 drawing threads on the N-1 running CPUs, and MN drawing thread bindings are processed on MN CPUs on the N-1 running CPUs.
  15. 根据权利要求13或14所述的终端,其特征在于,所述第一处理器,用于获取CPU占用率大于阈值的所述M个绘图线程中的一个绘图线程和/或所述M个绘图线程的其他M-1个绘图线程。The terminal according to claim 13 or 14, wherein the first processor is configured to acquire one of the M drawing threads whose CPU usage is greater than a threshold and/or the M drawing The other M-1 drawing threads of the thread.
  16. 根据权利要求14或15所述的终端,其特征在于,所述第一处理器,用于:The terminal according to claim 14 or 15, wherein the first processor is configured to:
    获取所述M个绘图线程的绘图时间,并对所述M个绘图时间进行比较,获取其中的最大绘图时间;Obtaining a drawing time of the M drawing threads, and comparing the M drawing times to obtain a maximum drawing time thereof;
    将所述最大绘图时间与时间阈值进行比较,根据比较结果调整所述N个运行的CPU的频率。The maximum drawing time is compared with a time threshold, and the frequency of the N running CPUs is adjusted according to the comparison result.
  17. 根据权利要求16所述的终端,其特征在于,所述将所述最大绘图时间与时间阈值进行比较,包括:The terminal according to claim 16, wherein the comparing the maximum drawing time with a time threshold comprises:
    若所述最大绘图时间小于所述时间阈值,所述第一处理器用于获取估算绘图时间;And if the maximum drawing time is less than the time threshold, the first processor is configured to obtain an estimated drawing time;
    所述估算绘图时间为所述N个运行的CPU的频率降低后,所述绘图线程的绘图时间;The estimated drawing time is a drawing time of the drawing thread after the frequency of the N running CPUs is decreased;
    将所述估算绘图时间与屏幕刷新时间进行比较,若所述估算绘图时间小于所述屏幕刷新时间,所述第一处理器用于将所述N个运行的CPU的频率降低。The estimated drawing time is compared with a screen refresh time, and if the estimated drawing time is less than the screen refresh time, the first processor is configured to reduce the frequency of the N running CPUs.
  18. 根据权利要求16所述的终端,其特征在于,所述将所述最大绘图时间 与时间阈值进行比较,包括:The terminal according to claim 16, wherein said maximum drawing time is Compare with time thresholds, including:
    若所述最大绘图时间大于所述时间阈值,所述第一处理器用于将所述最大绘图时间与屏幕刷新时间比较;If the maximum drawing time is greater than the time threshold, the first processor is configured to compare the maximum drawing time with a screen refresh time;
    若所述最大绘图时间大于所述屏幕刷新时间,所述第一处理器用于将所述N个运行的CPU的频率调高。 If the maximum drawing time is greater than the screen refresh time, the first processor is configured to increase the frequency of the N running CPUs.
PCT/CN2014/085818 2013-09-13 2014-09-03 Multiple cpu scheduling method and device WO2015035870A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201310419550.2A CN104460934A (en) 2013-09-13 2013-09-13 Scheduling method and device for multi central processing units (CPU)
CN201310419550.2 2013-09-13

Publications (1)

Publication Number Publication Date
WO2015035870A1 true WO2015035870A1 (en) 2015-03-19

Family

ID=52665057

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2014/085818 WO2015035870A1 (en) 2013-09-13 2014-09-03 Multiple cpu scheduling method and device

Country Status (2)

Country Link
CN (1) CN104460934A (en)
WO (1) WO2015035870A1 (en)

Families Citing this family (12)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106254058B (en) * 2015-06-12 2019-06-11 华为技术有限公司 A kind of method and device for the frequency adjusting server
CN105786571A (en) * 2016-02-29 2016-07-20 珠海市魅族科技有限公司 Mobile terminal and control method thereof
CN106095052B (en) * 2016-05-31 2018-03-27 广东欧珀移动通信有限公司 Control the method and device of CPU power consumption
CN106292838B (en) * 2016-07-27 2020-08-25 联想(北京)有限公司 Control method, processor and electronic equipment
CN107479976A (en) * 2017-08-14 2017-12-15 郑州云海信息技术有限公司 A kind of multiprogram example runs lower cpu resource distribution method and device simultaneously
CN108803509A (en) * 2018-05-31 2018-11-13 广东盛哲科技有限公司 A kind of polymorphic type CPU compatibilities industrial controller system
CN111045814B (en) * 2018-10-11 2023-12-08 华为技术有限公司 Resource scheduling method and terminal equipment
CN109600396A (en) * 2019-01-23 2019-04-09 浙江安点科技有限责任公司 Realize the firewall system of highly reliable safety
CN112114975B (en) * 2020-10-28 2023-06-27 Oppo广东移动通信有限公司 Processor frequency adjusting method and device, storage medium and electronic equipment
CN113190315B (en) * 2021-04-29 2022-11-25 安徽华米健康医疗有限公司 Display refreshing method and device
CN113220463B (en) * 2021-05-31 2022-09-06 中科曙光国际信息产业有限公司 Binding strategy inference method and device, electronic equipment and storage medium
CN114442792A (en) * 2022-02-09 2022-05-06 北京小米移动软件有限公司 Method and device for adjusting operating frequency of processor and storage medium

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101097514A (en) * 2006-06-27 2008-01-02 国际商业机器公司 Managing execution of mixed workloads in a simultaneous multi-threaded (smt) enabled system
CN101322111A (en) * 2005-04-07 2008-12-10 杉桥技术公司 Multithreading processor with each threading having multiple concurrent assembly line
CN101324851A (en) * 2007-06-12 2008-12-17 华为技术有限公司 Method and apparatus of thread scheduling

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8074051B2 (en) * 2004-04-07 2011-12-06 Aspen Acquisition Corporation Multithreaded processor with multiple concurrent pipelines per thread
CN101634953A (en) * 2008-07-22 2010-01-27 国际商业机器公司 Method and device for calculating search space, and method and system for self-adaptive thread scheduling

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101322111A (en) * 2005-04-07 2008-12-10 杉桥技术公司 Multithreading processor with each threading having multiple concurrent assembly line
CN101097514A (en) * 2006-06-27 2008-01-02 国际商业机器公司 Managing execution of mixed workloads in a simultaneous multi-threaded (smt) enabled system
CN101324851A (en) * 2007-06-12 2008-12-17 华为技术有限公司 Method and apparatus of thread scheduling

Also Published As

Publication number Publication date
CN104460934A (en) 2015-03-25

Similar Documents

Publication Publication Date Title
WO2015035870A1 (en) Multiple cpu scheduling method and device
CN107391259B (en) Resource processing method and device, computer readable storage medium and mobile terminal
WO2017206916A1 (en) Method for determining kernel running configuration in processor and related product
WO2017206902A1 (en) Application control method and related device
US10444822B2 (en) Method for managing central processing unit and related products
CN109960584A (en) CPU frequency modulation control method, terminal and computer readable storage medium
CN106406924B (en) Control method and device for starting and quitting picture of application program and mobile terminal
WO2017206915A1 (en) Method for determining kernel running configuration in processor and related product
CN109976611B (en) Terminal device control method and terminal device
WO2019129092A1 (en) Frame rate-lowered photographing method, mobile terminal and storage medium
US20190109767A1 (en) Network bandwidth management method, terminal and computer storage medium
WO2019128537A1 (en) Application freezing method, and computer device and computer-readable storage medium
WO2017206853A1 (en) Swiping response acceleration method and related products
CN110704191A (en) Game optimization method, game optimization device and mobile terminal
WO2017206918A1 (en) Terminal awakening accelerating method and related product
JP2014529146A (en) Method and apparatus for controlling a central processing unit
WO2015081880A1 (en) Method, device and system for processing cluster service attribute
WO2019128571A1 (en) Resource management method and device, mobile terminal, as well as computer readable storage medium
WO2017206901A1 (en) Process control method and related device
WO2019072179A1 (en) Application running control method and apparatus
CN107688497B (en) Memory regulation and control method, equipment and computer readable storage medium
CN107193551B (en) Method and device for generating image frame
WO2017206903A1 (en) Application control method and related device
CN110677456A (en) Resource allocation method and equipment
WO2018219117A1 (en) Component display method and related product

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 14844840

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 14844840

Country of ref document: EP

Kind code of ref document: A1