CN102662742B - Lock-based thread management method and thread management device - Google Patents

Lock-based thread management method and thread management device Download PDF

Info

Publication number
CN102662742B
CN102662742B CN201210104321.7A CN201210104321A CN102662742B CN 102662742 B CN102662742 B CN 102662742B CN 201210104321 A CN201210104321 A CN 201210104321A CN 102662742 B CN102662742 B CN 102662742B
Authority
CN
China
Prior art keywords
lock
thread
time
contention
behavior monitoring
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Expired - Fee Related
Application number
CN201210104321.7A
Other languages
Chinese (zh)
Other versions
CN102662742A (en
Inventor
刘仪阳
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Huawei Technologies Co Ltd
Original Assignee
Huawei Technologies Co Ltd
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 Huawei Technologies Co Ltd filed Critical Huawei Technologies Co Ltd
Priority to CN201210104321.7A priority Critical patent/CN102662742B/en
Publication of CN102662742A publication Critical patent/CN102662742A/en
Application granted granted Critical
Publication of CN102662742B publication Critical patent/CN102662742B/en
Expired - Fee Related legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Landscapes

  • Debugging And Monitoring (AREA)

Abstract

The invention discloses a lock-based thread management method and a lock-based thread management device. The thread management method comprises the following steps: judging whether lock action monitoring needs to be implemented, and if so, obtaining first lock contention degree information; determining a thread to be migrated according to the first lock contention degree information; and migrating the thread to a determined target processor. As the technical means that whether lock action monitoring needs to be implemented is decided through dynamic judgment are adopted, the problem that system processing resources are occupied excessively when lock action monitoring is implemented continuously can be avoided, and therefore the processing performance of the system can not be greatly influenced in the process of lock-based thread management.

Description

A kind of thread management method and device based on lock
Technical field
The present invention relates to a kind of field of computer technology, relate in particular to a kind of thread management method and device based on lock.
Background technology
Along with the development of computer technology, multinuclear or many core frameworks have become the main flow trend of current computing environment.But the performance of computing machine is not along with computer system check figure object increases and presents linear growth, even sometimes occur that, along with check figure object increases, performance is but along with the phenomenon declining.This phenomenon is referred to as core scaling concern.
Wherein, lock competition is one of factor of restriction system parallel-expansion on multicore architecture.While there is lock concussion when special, the performance loss of system is very large.Corresponding lock concussion refers to that a lot of threads compete same lock at the same time, and does not discharge CPU, thereby causes waiting for that the time of lock is far longer than the time of holder lock.
For overcoming the problems referred to above, the technological means adopting is at present: first, under multiple different simulation application scene, monitoring obtains lock competition development trend and focus lock respectively, and lock concussion critical point relevant information, to obtain the lock that may lock race problem (as lock concussion) under each different simulation application scene.Afterwards, each thread of lock Real-Time Monitoring based on locking race problem in practical application scene, in the lock competition of corresponding lock, acquire a certain degree but before there is not lock concussion, by this thread migration in one group of core, the serious thread of competition lock is operated in one group of core, the performance impact of bringing to reduce lock competition.
In realizing process of the present invention, inventor finds that in prior art, at least there are the following problems:
Above-mentioned prior art need to be passed through the different application scenarios of simulation, and the lock applicable cases in the application scenarios of simulation is carried out to monitoring analysis, and to know in advance the lock that may occur locking race problem, implementation procedure is comparatively complicated.
And, in each application scenarios of reality, normally the above-mentioned lock of locking race problem that may occur obtaining is in advance monitored in real time, to can carry out corresponding thread migration processing when there is lock race problem, this lasting real-time monitor procedure will take a large amount of processing resources, affects the handling property of system.
Summary of the invention
The object of this invention is to provide a kind of thread management method and device based on lock, with the lock behavior monitoring of avoiding continuing, cause taking processing resources a large amount of in system, thereby improve the handling property of system.
The object of the invention is to be achieved through the following technical solutions:
A thread management method based on lock, comprising:
Judging whether to need execution to lock after behavior monitoring, if determine, needing to carry out and lock behavior monitoring, obtaining the first lock degree of contention information;
According to described the first lock degree of contention information, determine the thread that need to carry out migration operation, and by described thread migration to definite target processor.
A thread management device based on lock, comprising:
Monitoring judging unit, for judging whether to need to carry out lock behavior monitoring;
The first lock degree of contention information acquisition unit, while needing to carry out lock behavior monitoring for determining at described monitoring judging unit, obtains the first lock degree of contention information;
Thread migration operating unit, determines the thread that need to carry out migration operation for the lock degree of contention information obtaining according to described the first lock degree of contention information acquisition unit, and by described thread migration to definite target processor.
As seen from the above technical solution provided by the invention, a kind of thread management method and device based on lock that the embodiment of the present invention provides, specifically adopted and passed through the execution whether technological means that dynamically judgement determines to lock behavior monitoring, to avoid appearance because continuing to carry out the excessive problem that takies system processing resource that lock behavior monitoring causes.Thereby can be so that in the thread management process based on lock, the handling property of system can not be much affected.
Accompanying drawing explanation
In order to be illustrated more clearly in the technical scheme of the embodiment of the present invention, below the accompanying drawing of required use during embodiment is described is briefly described, apparently, accompanying drawing in the following describes is only some embodiments of the present invention, for those of ordinary skill in the art, do not paying under the prerequisite of creative work, can also obtain other accompanying drawings according to these accompanying drawings.
The processing procedure schematic diagram of the method that Fig. 1 provides for the embodiment of the present invention;
The implementation procedure schematic diagram that judges whether to carry out lock behavior monitoring that Fig. 2 provides for the embodiment of the present invention;
The thread process process schematic diagram based on spin lock that Fig. 3 provides for the embodiment of the present invention;
The processing procedure schematic diagram that the thread that Fig. 4 A provides for the embodiment of the present invention switches;
The applied environment schematic diagram of the dispatching zone partitioning technology that Fig. 4 B provides for the embodiment of the present invention;
The structural representation one of the device that Fig. 5 A provides for the embodiment of the present invention;
The structural representation two of the device that Fig. 5 B provides for the embodiment of the present invention;
The structural representation three of the device that Fig. 5 C provides for the embodiment of the present invention.
Embodiment
Below in conjunction with the accompanying drawing in the embodiment of the present invention, the technical scheme in the embodiment of the present invention is clearly and completely described, obviously, described embodiment is only the present invention's part embodiment, rather than whole embodiment.Based on embodiments of the invention, those of ordinary skills, not making the every other embodiment obtaining under creative work prerequisite, belong to protection scope of the present invention.
The embodiment of the present invention, can realize dynamic decision and whether start lock behavior monitoring, and according to lock degree of contention information, dynamically judges whether to carry out thread migration in monitor procedure, thereby has overcome the problem that prior art exists.
Below in conjunction with accompanying drawing, the embodiment of the present invention is described in further detail.
A kind of thread management method based on lock that the embodiment of the present invention provides, as shown in Figure 1, specifically can comprise:
Step 11, judging whether needs to carry out lock behavior monitoring, if needed, execution step 12, to carry out corresponding lock behavior monitoring operation, otherwise, execution step 13;
Judge whether accordingly to need the step of carrying out lock behavior monitoring can comprise following any mode:
Mode one: obtain the lock contention parameter information in predetermined amount of time, and according to this lock contention parameter information acquisition the second lock degree of contention information, according to described the second lock degree of contention information, judge whether to need to carry out lock behavior monitoring again, if this second lock degree of contention information indicates current lock competition to reach predetermined extent, determine and need to carry out lock behavior monitoring; This mode can be set as that predetermined time interval repeats or the time point of appointment repeats, with predetermined time interval repeated using which one or at the time point of appointment, repeat which one, to carry out the step that judges whether accordingly to need to carry out lock behavior monitoring;
Mode two: obtain the lock contention parameter information in predetermined amount of time, and determine the execution time of locking behavior monitoring according to lock contention parameter information, according to this execution time and current time information, judge whether to carry out lock behavior monitoring again, if current time information is consistent with the described execution time, determines and need to carry out lock behavior monitoring; This mode can be set as that predetermined time interval repeats or the time point of appointment repeats, or, also can be after having determined first the execution time of lock behavior monitoring, when arriving the execution time of once locking behavior monitoring, repeat which two, to carry out the step that judges whether accordingly to need to carry out lock behavior monitoring at every turn;
Mode three: obtain the lock contention parameter information in predetermined amount of time, and determine that according to lock contention parameter information carrying out lock behavior monitoring needs elapsed time sheet jump wheel number, with the wheel number that jumps according to corresponding timeslice, judge whether to carry out lock behavior monitoring, if current elapsed time sheet wheel number reaches described execution lock behavior monitoring, need the elapsed time sheet wheel number that jumps, determine and need to carry out lock behavior monitoring; This mode can be set as that predetermined time interval repeats row or the time point of appointment repeats, or, also can be after having determined first the timeslice that needs execution lock behavior monitoring, while once needing to carry out the timeslice of locking behavior monitoring, repeat which three on each arrival, to carry out the step that judges whether accordingly to need to carry out lock behavior monitoring;
In above-mentioned three kinds of modes, the time point of corresponding appointment repeats and specifically can be, but not limited to comprise: when this execution judges whether that needs are carried out the step of locking behavior monitoring, specify the time point once repeating, for example, according to the lock contention parameter information of obtaining, specify the time point next time repeating, determine the time point of corresponding appointment.
Wherein, lock contention parameter information in above-mentioned processing procedure can be, but not limited to comprise: the time while starting attempt the time of holder lock and successfully obtain lock, thread is scheduled for and on processor, starts time of carrying out and the processor at thread place is seized the time of leaving processor by other threads, and obtains the time of lock and discharge at least one in time of lock.
Wherein, corresponding the second lock degree of contention information can include but not limited to: lock the stand-by period, hold at least one in free and the actual execution time of thread in current slot; The corresponding lock stand-by period is that the time when starting to attempt holder lock and the time while successfully obtaining lock are definite, holding is to determine time according to obtaining the time of lock and discharging lock if having time, and the actual execution time of corresponding thread in current slot refers to that thread is scheduled for and on processor, start time of carrying out and the processor at thread place is seized the time interval between the time of leaving processor by other threads.
Step 12, if determine and need to carry out lock behavior monitoring according to the judgement of step 11, records the first lock degree of contention information, and performs step 14;
Wherein, corresponding the first lock degree of contention information can include but not limited to: lock the stand-by period, hold at least one in free and the actual execution time of thread in current slot; And this first lock degree of contention information can be identical information with above-mentioned the second lock degree of contention information, also can be different information, for example, the first lock degree of contention information can adopt the lock stand-by period, and the second lock degree of contention information can adopt the actual execution time of thread in current slot, or the first lock degree of contention information and the second lock degree of contention information all adopt the lock stand-by period;
Step 13, does not need to carry out lock behavior monitoring if judgement is determined, this operating process finishes;
It should be noted that, if the operation of corresponding lock behavior monitoring, always in executing state, also comprises the processing of lock stop behavior monitoring operation in this step before this step.
Step 14, determines the thread that need to carry out migration operation according to the first lock degree of contention information of record;
Step 15, need to carry out the thread migration of migration operation to definite target processor;
In this step, corresponding target processor can be determined by following step:
Determine the present dispatching zone of thread that need to carry out migration operation, and in this definite dispatching zone, select to determine target processor corresponding to this thread, in transition process, based on dispatching zone, select the processor moving to, thereby can avoid the thread in different dispatching zones of competing same class lock to be migrated on same group of CPU or logic CPU, cause, in the process of load balance, affecting the performance of system.
In the embodiment of the present invention, for guaranteeing to meet thread process operation in dispatching zone, can according to the lock degree of contention of current thread, adjust the dispatching zone at current thread place, concrete adjustment mode can comprise:
Whether the lock degree of contention that judges current thread surpasses predetermined value, if, improve the load balance rank that this thread is corresponding, otherwise, reduce the load balance rank that this thread is corresponding, wherein, different load balance rank correspondences different dispatching zones, and the processor that the present dispatching zone of the higher thread of load balance rank comprises is more.Thereby make, in the process of migration, can realize load balance based on dispatching zone perception, to improve the handling property of system.
By above-mentioned processing procedure, can, on multi-core platform, can to thread, reasonably manage based on lock, thereby guarantee system extendability, make the increase along with check figure, the performance of system still can be guaranteed, and can avoid producing lock concussion, avoid taking the CPU long period.
What below the mode three of take in above-mentioned steps 11 is provided judges whether that needing the implementation of execution lock behavior monitoring is example, specific implementation process to step 11 is described, as shown in Figure 2, judge that accordingly the no step of carrying out lock behavior monitoring that needs specifically can comprise:
Step 21, in the front-wheel timeslice, current thread judges in last round of timeslice, whether to have carried out lock behavior monitoring, if so, steps performed 22, otherwise execution step 26.
Step 22, the lock degree of contention information of the last round of timeslice of calculative determination, and judge whether the lock degree of contention of lock degree of contention information indication is greater than default threshold value, if so, performs step 23, otherwise execution step 24.
Step 23, determines that the lock degree of contention of last round of timeslice is greater than default threshold value, and it is 0 that lock behavior monitoring timeslice jump wheel number is set, and then performs step 25;
Wherein, lock accordingly behavior monitoring execution time sheet jump wheel number, for record, from next timeslice, start to calculate, need to skip how many wheel timeslices, just carry out and lock behavior monitoring, initial value is 0.
Step 24, determines that last round of lock degree of contention is not more than default threshold value, adjusts corresponding lock behavior monitoring timeslice jump wheel number;
Particularly, judge whether lock behavior monitoring timeslice jump wheel number is 0, if 0, it is 1 that lock behavior monitoring timeslice jump wheel number is set; If lock behavior monitoring timeslice is jumped, wheel number is greater than 0 and be less than 128 (this value is variable, and user can set according to time situation, can be 2 power side), and it is original 2 times that the lock behavior monitoring timeslice wheel number that jumps is set; If lock behavior monitoring timeslice is jumped, wheel number is not less than 128, and it is 128 that lock behavior monitoring timeslice jump wheel number is set, and performs step afterwards 21.
Step 25, arranges lock behavior monitoring zone bit, according to this zone bit, will carry out lock behavior monitoring in epicycle timeslice, after completing lock behavior monitoring, removes lock behavior monitoring zone bit, and in lower whorl timeslice repeated execution of steps 21;
In this step, also need, going back setup times sheet wheel number variable is zero, so that again add up elapsed time sheet wheel number, as the follow-up basis for estimation of whether carrying out lock behavior monitoring; Corresponding timeslice wheel number variable, after lock behavior last time detects, has moved how many wheel timeslices for record, and initial value is 0.
Step 26: whether the value that judges timeslice wheel number variable record is consistent with corresponding lock behavior monitoring execution time sheet jump wheel number, if, it is 0 that lock behavior monitoring timeslice jump wheel number is set, and perform step 25, otherwise, timeslice is taken turns to number variable and add 1, in epicycle timeslice, do not carry out lock behavior monitoring, and in lower whorl timeslice repeated execution of steps 21.
It should be noted that, in the system of the application embodiment of the present invention, acquiescence, when thread starts, all needs to carry out corresponding lock behavior monitoring operation, afterwards, in follow-up timeslice, just can carry out above-mentioned steps 21 and subsequent process and judge processing to whether carrying out lock behavior monitoring.
By above-mentioned processing procedure, can reasonably start the operating process of corresponding lock behavior monitoring, thereby can avoid because continue to carry out the problem that lock behavior monitoring causes affecting system performance in system.
The thread of take below need to obtain certain spin lock as example, and the corresponding thread management process based on lock is described.Particularly, as shown in Figure 3, corresponding processing procedure can comprise:
Step 31, the migration that judges thread indicates whether set, if set represents to carry out migration operation to this thread execution step 32, otherwise execution step 33;
In this step, the migration sign of corresponding thread is to determine whether set by the lock behavior monitoring process of carrying out before, the lock behavior monitoring process of carrying out even determines that according to lock degree of contention information this thread need to carry out migration operation, by the migration flag set of this thread.
Step 32, it is the CPU (processor) of to_cpu (target CPU) that this thread is moved to definite ID (sign) number, and performs step 33;
Step 33, current thread judges whether to need to carry out lock behavior monitoring, if needed, performs step 34, otherwise, execution step 35;
In this step, specifically can adopt following either type to realize:
(1) obtain the lock contention parameter information in predetermined amount of time, and determine the second lock degree of contention parameter information according to this lock contention parameter information, according to this second lock degree of contention parameter information, judge whether to need to carry out lock behavior monitoring again, if this second lock degree of contention information indicates current lock competition to reach predetermined extent, determine and need to carry out lock behavior monitoring; For example, the lock contention parameter information in corresponding predetermined amount of time can be the lock contention parameter information of several timeslices of past;
(2) if determined before the execution time of lock behavior monitoring, consistent with the execution time of lock behavior monitoring at current time information, determine and need to carry out lock behavior monitoring; The execution time of this lock behavior monitoring can be determined according to the lock contention parameter information of obtaining in predetermined amount of time, for example, if this lock contention parameter information indicates current lock degree of contention higher, can by lock execution time of behavior monitoring and arrange the interval time between current time smaller, otherwise, can be larger by what arrange corresponding interval time; Carrying out lock behavior monitoring needs elapsed time sheet jump wheel number, takes turns number judge whether to carry out lock behavior monitoring to jump according to corresponding timeslice, if current elapsed time sheet wheel number reaches described execution lock behavior monitoring, needs elapsed time sheet jump wheel number,
(3) if determine to carry out before lock behavior monitoring, need the elapsed time sheet wheel number that jumps, current elapsed time sheet wheel number reaches described execution lock behavior monitoring needs the elapsed time sheet wheel number that jumps, just determine and need to carry out lock behavior monitoring; This execution lock behavior monitoring needs elapsed time sheet to jump wheel number specifically can be definite according to the lock contention parameter information of obtaining in predetermined amount of time;
By any mode in above-mentioned three kinds of modes, can determine whether to start lock behavior monitoring and operate, or, also can in the process of carrying out the operation of lock behavior monitoring, determine whether lock stop behavior monitoring operates;
Particularly, in this step, can adopt above either type to judge whether to need to carry out lock behavior monitoring, or, also can adopt above either type to judge whether to need, after execution lock behavior monitoring, corresponding lock behavior monitoring zone bit is set, so that can directly judge whether to carry out lock behavior monitoring according to corresponding lock behavior monitoring zone bit in this step;
Step 34, records current time as the very first time, and performs step 35;
Step 35, obtains spin lock, and performs step 36;
Step 36, judges whether to carry out lock behavior monitoring, if so, performs step 37, otherwise, execution step 38;
Step 37, obtains current time as the second time, by the very first time comparison of this second time and the acquisition of step 34 record, calculates the lock stand-by period, and performs step 38;
In this step, the information recording that determines this lock whether for the lock stand-by period calculate obtaining is in array lock_info, and array lock_info locks the longest some lock information of stand-by period for recording current thread implementation;
Step 38, carries out critical section operation, obtains the current thread of spin lock and carries out the operation that this spin lock is corresponding, performs step afterwards 39;
Step 39, discharges spin lock, and performs step 310;
Step 310, judges whether need to carry out lock behavior monitoring (as the whether set of judgement lock behavior monitoring zone bit), if so, determines and needs to carry out lock behavior monitoring, performs step 311, otherwise execution step 312;
In this step, can directly utilize 33 judged result, or, also can determine whether to need to carry out lock behavior monitoring by corresponding lock behavior monitoring zone bit.
Step 311, obtains current time, with the second time comparison that step 37 obtains, calculates and holds if having time, and the information recording that determines this lock whether is in array lock_info, performs step afterwards 312;
Wherein, array lock_info holds the longest free some lock information for recording current thread implementation.
Step 312, judges that moving back to of thread indicates whether set, if set performs step 313, otherwise lock behavior monitoring and thread migration flow process finish;
Step 313, moves back to original CPU (being that ID is the CPU of from_cpu) by thread, and lock behavior monitoring and thread migration flow process finish.
Based on above-mentioned processing procedure, can be obtained from the process of revolving lock at thread, according to for whether needing the judged result of carrying out lock behavior monitoring to determine whether to carry out corresponding lock behavior monitoring, rather than constantly corresponding spin lock is monitored, thereby can avoid monitor procedure to take in large quantities the processing resource of system, the handling property of system can be a greater impact because of the execution of lock behavior monitoring.
By take the implementation procedure of carrying out realizing in the process of context switching the thread management based on lock at thread, describe as example below.Suppose to switch to thread B from thread A, will to whether continuing, carry out the monitoring of lock row by thread A, and whether the rank of load balance satisfy the demands and carry out decision-making, as shown in Figure 4 A, specifically can comprise:
Step 41, current thread, it is the end time that thread A records current time sheet, the processor that is thread A place is seized the time of leaving processor by other threads, and calculate the physical length of current time sheet, according between the thread A of record be scheduled for the time of carrying out of starting on processor, and the processor at this thread A place seized by other threads the time of leaving processor and determines the actual execution time of thread A in current slot, performs step afterwards 42;
Step 42, determine whether to start lock behavior monitoring, if need to start lock behavior monitoring, start lock behavior monitoring, by lock behavior monitoring, obtain lock contention parameter information, and then can be identified for judging whether to carry out according to corresponding lock contention parameter information the lock degree of contention information (the second lock degree of contention information as previously described) of thread migration, otherwise do not start lock behavior monitoring, perform step afterwards 43;
Step 43, judges whether the definite lock degree of contention of the first lock degree of contention information of current thread is greater than degree of contention threshold value, if, migration position is set, in next timeslice, carries out thread migration operation, perform step afterwards 44, otherwise, execution step 47;
Wherein, in this step, corresponding the first lock degree of contention information can be utilized lock stand-by period summation or the average or weighted average calculation acquisition of recording in array lock_info, or, utilize in array lock_info, record hold free summation or average or weighted average calculation obtains;
Step 44, judges whether the lock degree of contention of current thread is greater than load balance adjustment threshold value, if so, performs step 45, otherwise, execution step 46.
Step 45, improve load balance rank, be about to the upper strata dispatching zone that load balance rank is set to the corresponding dispatching zone of original load balance rank, to expand the number (being the thread CPU that can move or the number of logic CPU) of the core that this thread can move, and perform step 47;
Step 46, reduces load balance rank, is about to the dispatching zone that load balance rank is set to the low one-level of the corresponding dispatching zone of original load balance rank, to reduce CPU that this thread can move or the number of logic CPU, if current, be basic dispatching zone, no longer adjust, perform step afterwards 47;
Step 47, execution thread blocked operation, is about to thread A and swaps out, and thread B changes to, and with what realize thread, has up and down a hand-off process, performs step afterwards 48;
Step 48, is the initial value of thread B sheet writing time, and thread B is scheduled for the time that starts execution on processor, and for calculating the actual execution time of current time sheet, this treatment scheme finishes.
For ease of the load balance level to mentioning in above-mentioned steps 45 and step 46, other is understood, and will be illustrated other concept of load balance level below.Particularly, with 4 nodes, and every node comprises CPU in two things, the NUMA that comprises 4 logic CPU on each physical cpu (Non-Uniform Memory Access, non-uniform memory access) framework is example, corresponding load balance level other can be, but not limited to be divided into: basic dispatching zone, schedule level one territory and second-level dispatching territory, the concept of each dispatching zone is as follows:
Basic dispatching zone, can be for belonging to all logic CPU of a physical cpu, and corresponding to minimum load balance rank, for example, each physical cpu all can be called a basic dispatching zone;
Schedule level one territory, can be for belonging to all logic CPU on a NUMA, corresponding load balance rank (can be called accordingly one-level load balance grade) is than the high one-level of minimum load balance rank, and for example, each node can become a schedule level one territory;
Second-level dispatching territory, can be the logic CPU on all nodes of 1 jumping for the nodal distance moving with current thread, and corresponding load balance rank is secondary loads balance level, for example, as shown in Figure 4 B, node node1 and can form a second-level dispatching territory by node node 0 and the node 2 of 1 jumping with it, in like manner node node 1,2,3, node node 2,3, and 0, node node 0,1,3 also can form a second-level dispatching territory;
The dispatching zone of different brackets can also be formed according to the distance of the nodal distance comprising with NUMA framework, as three grades of dispatching zones, level Four dispatching zone etc.;
Highest dispatching zone, can comprise all logic CPU of current system.
It should be noted that, other divides a just example above-mentioned load balance level, does not form the unique restriction to the embodiment of the present invention.Those skilled in the art know and in the embodiment of the present invention, adopt other other dividing mode of load balance level can meet equally the corresponding load balance demand based on dispatching zone.And, in above-mentioned explanation, only take NUMA framework as example, obviously, the embodiment of the present invention also can be applied in other frameworks that have similar demand.
Realization by above-described embodiment can be found out, owing to having adopted dynamic decision whether to lock the means of behavior monitoring, thereby can reduce the performance cost of system.And, in lock perception thread migration, by the load balancing strategy of dispatching zone perception, effectively reduce the performance cost that thread moves between different N UMA node.
One of ordinary skill in the art will appreciate that all or part of flow process realizing in above-described embodiment method, to come the hardware that instruction is relevant to complete by computer program, described program can be stored in a computer read/write memory medium, this program, when carrying out, can comprise as the flow process of the embodiment of above-mentioned each side method.Wherein, described storage medium can be magnetic disc, CD, read-only store-memory body (Read-Only Memory, ROM) or random store-memory body (Random Access Memory, RAM) etc.
The embodiment of the present invention also provides a kind of thread management device based on lock, and its specific implementation structure as shown in Figure 5A, can comprise following processing unit:
Monitoring judging unit 51, for judging whether to need to carry out lock behavior monitoring, for dynamically judge whether to carry out lock behavior monitoring according to current lock race condition;
Lock degree of contention information recording unit 52, while needing to carry out lock behavior monitoring for determining at monitoring judging unit 51, record lock degree of contention information;
Thread migration operating unit 53, for determining the thread that need to carry out migration operation according to the lock degree of contention information of lock degree of contention information recording unit 52 records, and by described thread migration to definite target processor.
Alternatively, as shown in Figure 5 B, judge whether the difference of the technological means that needs execution lock behavior monitoring adopts according to monitoring judging unit 51, this device can also comprise following processing unit:
Lock contention parameter information acquisition unit 54, for obtaining the lock contention parameter information in predetermined amount of time; And the second lock degree of contention information acquisition unit 55, for lock contention parameter information acquisition the second lock degree of contention information of obtaining according to lock contention parameter information acquisition unit 54, and the second lock degree of contention information is offered to monitoring judging unit 51, using and judge whether to need to carry out the foundation of locking behavior monitoring as monitoring judging unit 51, if monitoring judging unit 51 is determined corresponding the second lock degree of contention information and is indicated current lock competition to reach predetermined extent, determine and need to carry out lock behavior monitoring, otherwise, do not need to carry out lock behavior monitoring;
Or,
Monitoring period acquiring unit 56, for obtaining the lock contention parameter information in predetermined amount of time, and determine the execution time of locking behavior monitoring according to this lock contention parameter information, again the execution time of lock behavior monitoring is offered to above-mentioned monitoring judging unit 51, using and judge whether to carry out the foundation of locking behavior monitoring as monitoring judging unit 51, if monitoring judging unit determines that current time information is consistent with the execution time of this lock behavior monitoring, determine and need to carry out lock behavior monitoring, otherwise, do not need to carry out lock behavior monitoring;
Or,
Monitoring period sheet wheel number determining unit 57, for obtaining the lock contention parameter information in predetermined amount of time, and determine that according to this lock contention parameter information carrying out lock behavior monitoring needs elapsed time sheet jump wheel number, using and judge whether to carry out the foundation of locking behavior monitoring as monitoring judging unit 51, if monitor judging unit 51, determine that current elapsed time sheet wheel number reaches execution lock behavior monitoring and needs elapsed time sheet jump wheel number, determine and need to carry out lock behavior monitoring, otherwise, do not need to carry out lock behavior monitoring.
It should be noted that, above-mentioned lock contention parameter information can be, but not limited to comprise: the time while starting attempt the time of holder lock and successfully obtain lock, thread is scheduled for and on processor, starts time of carrying out and the processor at thread place is seized the time of leaving processor by other threads, and obtains the time of lock and discharge at least one in time of lock; Wherein, time when starting to attempt the time of holder lock and successfully obtaining lock can be determined the corresponding lock stand-by period, according to thread, be scheduled for the processor that starts time of carrying out and thread place on processor and by other threads, seized the time of leaving processor and can determine the actual execution time of thread in current slot, according to the time of obtaining the time of lock and discharging lock can determine hold accordingly free;
Above-mentioned the first lock degree of contention information can be, but not limited to comprise: lock the stand-by period, hold at least one in free and the actual execution time of thread in current slot; Corresponding the second lock degree of contention information can be, but not limited to comprise: lock the stand-by period, hold at least one in free and the actual execution time of thread in current slot; And corresponding the first lock degree of contention information and the second lock degree of contention information can be identical, also can be different.
Alternatively, this device can also comprise target processor determining unit 58, for determining the present dispatching zone of thread that need to carry out migration operation, and in this definite dispatching zone, select to determine the target processor (as CPU or logic CPU etc.) of this thread so that thread migration operating unit 53 by corresponding thread migration to determined target processor in definite dispatching zone.
Preferably, for ease of above-mentioned target processor determining unit 58, for current thread, select to determine rational target processor, this device can also comprise:
Lock degree of contention judging unit 59, for judging whether the lock degree of contention of current thread surpasses predetermined value;
Dispatching zone adjustment unit 510, for when above-mentioned lock degree of contention judging unit 59 determines that the lock degree of contention of current thread surpasses predetermined value, improve the load balance rank that this thread is corresponding, otherwise, reduce the load balance rank that this thread is corresponding, wherein, different load balance rank correspondences different dispatching zones, and the processor that the present dispatching zone of the higher thread of load balance rank comprises is more;
By load balance level other adjustment corresponding to this thread, can be so that above-mentioned target processor determining unit 58 can be for needing the thread of migration to determine corresponding target processor in rational dispatching zone.
It should be noted that, the specific implementation of the function that in said apparatus embodiment, each processing unit is realized is described in embodiment before, and the specific implementation of each function of describing in embodiment before those skilled in the art know is also applicable in this device, therefore be no longer repeated in this description at this.
Realization by said apparatus embodiment can be found out because this device has adopted dynamic decision, whether lock the technological means of behavior monitoring, thereby can reduce the performance cost of system, improve the performance of system.And in lock perception thread migration, this device can also pass through the load balancing strategy of dispatching zone perception, imitates and reduces the performance cost that thread moves between different processor node.
The above; be only the present invention's embodiment preferably, but protection scope of the present invention is not limited to this, is anyly familiar with in technical scope that those skilled in the art disclose in the present invention; the variation that can expect easily or replacement, within all should being encompassed in protection scope of the present invention.Therefore, protection scope of the present invention should be as the criterion with the protection domain of claims.

Claims (6)

1. the thread management method based on lock, is characterized in that, comprising:
Judging whether to need execution to lock after behavior monitoring, if determine, needing to carry out and lock behavior monitoring, obtaining the first lock degree of contention information;
According to described the first lock degree of contention information, determine the thread that need to carry out migration operation, and by described thread migration to definite target processor;
The step of determining described target processor comprises:
Determine the present dispatching zone of thread that need to carry out migration operation, and in this definite dispatching zone, select to determine the target processor of this thread;
Describedly judge whether that step that need to carry out lock behavior monitoring comprises:
Obtain the lock contention parameter information in predetermined amount of time, and according to described lock contention parameter information acquisition the second lock degree of contention information, according to described the second lock degree of contention information, judge whether to need to carry out lock behavior monitoring again, if described the second lock degree of contention information indicates current lock competition to reach predetermined extent, determine and need to carry out lock behavior monitoring;
Or,
Obtain the lock contention parameter information in predetermined amount of time, and according to the execution time of the definite lock of described lock contention parameter information behavior monitoring, according to described execution time and current time information, judge whether to carry out lock behavior monitoring again, if current time information is consistent with the described execution time, determines and need to carry out lock behavior monitoring;
Or,
Obtain the lock contention parameter information in predetermined amount of time, and determine that according to described lock contention parameter information carrying out lock behavior monitoring needs elapsed time sheet jump wheel number, with the wheel number that jumps according to described timeslice, judge whether to carry out lock behavior monitoring, if current elapsed time sheet wheel number reaches described execution lock behavior monitoring, need the elapsed time sheet wheel number that jumps, determine and need to carry out lock behavior monitoring.
2. method according to claim 1, is characterized in that,
Described lock contention parameter information comprises: the time while starting attempt the time of holder lock and successfully obtain lock, and/or, thread is scheduled for and on processor, starts time of carrying out and the processor at thread place is seized the time of leaving processor by other threads, and/or, obtain the time of lock and discharge the time of locking;
Described the first lock degree of contention information comprises: the lock stand-by period, and/or, hold if having time, and/or, the actual execution time of thread in current slot;
Described the second lock degree of contention information comprises: the lock stand-by period, and/or, hold if having time, and/or, the actual execution time of thread in current slot.
3. method according to claim 1, is characterized in that, the method also comprises:
Whether the lock degree of contention that judges current thread surpasses predetermined value, if, improve the load balance rank that this thread is corresponding, otherwise, reduce the load balance rank that this thread is corresponding, wherein, different load balance rank correspondences different dispatching zones, and the processor that the present dispatching zone of the higher thread of described load balance rank comprises is more.
4. the thread management device based on lock, is characterized in that, comprising:
Monitoring judging unit, for judging whether to need to carry out lock behavior monitoring;
The first lock degree of contention information acquisition unit, while needing to carry out lock behavior monitoring for determining at described monitoring judging unit, obtains the first lock degree of contention information;
Thread migration operating unit, determines the thread that need to carry out migration operation for the lock degree of contention information obtaining according to described the first lock degree of contention information acquisition unit, and by described thread migration to definite target processor;
This device also comprises:
Target processor determining unit, for determining the present dispatching zone of thread that need to carry out migration operation, and in this definite dispatching zone, selects to determine the target processor of this thread;
Lock contention parameter information acquisition unit, for obtaining the lock contention parameter information in predetermined amount of time; And the second lock degree of contention information acquisition unit, for lock contention parameter information acquisition the second lock degree of contention information of obtaining according to described lock contention parameter information acquisition unit, and described the second lock degree of contention information is offered to described monitoring judging unit, using and judge whether to need to carry out the foundation of locking behavior monitoring as monitoring judging unit, if described monitoring judging unit is determined the second lock degree of contention information and is indicated current lock competition to reach predetermined extent, determines and need to carry out lock behavior monitoring;
Or,
Monitoring period acquiring unit, for obtaining the lock contention parameter information in predetermined amount of time, and according to the execution time of the definite lock of described lock contention parameter information behavior monitoring, again offered to described monitoring judging unit the execution time of described lock behavior monitoring, using and judge whether to carry out the foundation of locking behavior monitoring as monitoring judging unit, if monitoring judging unit determines that current time information is consistent with the described execution time, determine and need to carry out lock behavior monitoring;
Or,
Monitoring period sheet wheel number determining unit, for obtaining the lock contention parameter information in predetermined amount of time, and determine that according to described lock contention parameter information carrying out lock behavior monitoring needs elapsed time sheet jump wheel number, using and judge whether to carry out the foundation of locking behavior monitoring as described monitoring judging unit, if described monitoring judging unit determines that current elapsed time sheet wheel number reaches described execution lock behavior monitoring and needs the elapsed time sheet wheel number that jumps, determine and need to carry out lock behavior monitoring.
5. device according to claim 4, is characterized in that,
Described lock contention parameter information comprises: the time while starting attempt the time of holder lock and successfully obtain lock, and/or, thread is scheduled for and on processor, starts time of carrying out and the processor at thread place is seized the time of leaving processor by other threads, and/or, obtain the time of lock and discharge the time of locking;
Described the first lock degree of contention information comprises: the lock stand-by period, and/or, hold if having time, and/or, the actual execution time of thread in current slot;
Described the second lock degree of contention information comprises: the lock stand-by period, and/or, hold if having time, and/or, the actual execution time of thread in current slot.
6. device according to claim 4, is characterized in that, this device also comprises:
Lock degree of contention judging unit, for judging whether the lock degree of contention of current thread surpasses predetermined value;
Dispatching zone adjustment unit, be used for when described lock degree of contention judging unit determines that the lock degree of contention of current thread surpasses predetermined value, improve the load balance rank that this thread is corresponding, otherwise, reduce the load balance rank that this thread is corresponding, wherein, different load balance rank correspondences different dispatching zones, and the processor that the present dispatching zone of the higher thread of described load balance rank comprises is more.
CN201210104321.7A 2012-04-11 2012-04-11 Lock-based thread management method and thread management device Expired - Fee Related CN102662742B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201210104321.7A CN102662742B (en) 2012-04-11 2012-04-11 Lock-based thread management method and thread management device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201210104321.7A CN102662742B (en) 2012-04-11 2012-04-11 Lock-based thread management method and thread management device

Publications (2)

Publication Number Publication Date
CN102662742A CN102662742A (en) 2012-09-12
CN102662742B true CN102662742B (en) 2014-09-17

Family

ID=46772241

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201210104321.7A Expired - Fee Related CN102662742B (en) 2012-04-11 2012-04-11 Lock-based thread management method and thread management device

Country Status (1)

Country Link
CN (1) CN102662742B (en)

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107515789A (en) * 2016-06-15 2017-12-26 阿里巴巴集团控股有限公司 Lock the analysis method and equipment of competition
CN108897622A (en) * 2018-06-29 2018-11-27 郑州云海信息技术有限公司 A kind of dispatching method and relevant apparatus of task run
CN110688102B (en) * 2019-09-29 2022-03-22 北京浪潮数据技术有限公司 Method, system, device and storage medium for capturing execution result of asynchronous interface

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102222015A (en) * 2010-04-13 2011-10-19 三星电子(中国)研发中心 System and method for detecting deadlock in multithreaded program
CN102388367A (en) * 2011-08-17 2012-03-21 华为技术有限公司 Processor management method, lock competitive management device and computer system

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102222015A (en) * 2010-04-13 2011-10-19 三星电子(中国)研发中心 System and method for detecting deadlock in multithreaded program
CN102388367A (en) * 2011-08-17 2012-03-21 华为技术有限公司 Processor management method, lock competitive management device and computer system

Also Published As

Publication number Publication date
CN102662742A (en) 2012-09-12

Similar Documents

Publication Publication Date Title
US8782649B2 (en) Real-time scheduling of task sets and determination of task sets based on verified weight, cache hit radio of the tasks and available processing cores
CN102096601A (en) Virtual machine migration management method and system
CN103023969A (en) Cloud platform scheduling method and system
CN107145388B (en) Task scheduling method and system under multi-task environment
CN110018914A (en) Message collection method and device based on shared drive
CN102662742B (en) Lock-based thread management method and thread management device
US20170060441A1 (en) Memory Controller for Heterogeneous Computer
CN104977860B (en) Use the control device of multi-core processor execution sequence program
US20180046489A1 (en) Storage medium, method, and device
CN106469018A (en) The load monitoring method and apparatus of distributed memory system
CN107844187A (en) Power consumption management method, device and electronic equipment
KR101458028B1 (en) Apparatus and method for parallel processing
CN104572301A (en) Resource distribution method and system
US20230305880A1 (en) Cluster distributed resource scheduling method, apparatus and device, and storage medium
CN106155794B (en) A kind of event dispatcher method and device applied in multi-threaded system
CN105991667A (en) Method and device for correcting resource prediction error
CN104850423B (en) The method for identifying the application program launching stage under Android system
US8316375B2 (en) Load-balancing of processes based on inertia
CN105045648A (en) Physical host resource state forecasting method under IaaS cloud environment
CN112198817B (en) Unmanned aerial vehicle control method, device, equipment, unmanned aerial vehicle and medium
CN105378652B (en) Thread shared resource distribution method and device
US20120042322A1 (en) Hybrid Program Balancing
CN114301805B (en) Method and device for determining number of devices and electronic device
CN108595249A (en) A kind of virtual machine method for scheduling task and electronic equipment
CN105162844B (en) A kind of method and device of task distribution

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
C14 Grant of patent or utility model
GR01 Patent grant
CF01 Termination of patent right due to non-payment of annual fee

Granted publication date: 20140917

Termination date: 20180411

CF01 Termination of patent right due to non-payment of annual fee