CN104932933B - A kind of method and device obtaining spin lock - Google Patents

A kind of method and device obtaining spin lock Download PDF

Info

Publication number
CN104932933B
CN104932933B CN201410109467.XA CN201410109467A CN104932933B CN 104932933 B CN104932933 B CN 104932933B CN 201410109467 A CN201410109467 A CN 201410109467A CN 104932933 B CN104932933 B CN 104932933B
Authority
CN
China
Prior art keywords
queue
task
spin
spin lock
lock
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.)
Active
Application number
CN201410109467.XA
Other languages
Chinese (zh)
Other versions
CN104932933A (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.)
XFusion Digital 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 CN201410109467.XA priority Critical patent/CN104932933B/en
Publication of CN104932933A publication Critical patent/CN104932933A/en
Application granted granted Critical
Publication of CN104932933B publication Critical patent/CN104932933B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Landscapes

  • Multi Processors (AREA)

Abstract

The embodiment of the present invention provide it is a kind of obtain spin lock method and device, be related to field of computer technology, can reduce due to multiple tasks compete shared resource and caused by system performance loss, to improve the performance of system.This method may include:Receive the task of acquisition request spin lock;The task is stored in queue queue;According to position of the task in queue queue, determine the spin-waiting time of the task, so that the task is at the end of the spin-waiting time, it attempts to obtain spin lock, wherein, position of the task in queue queue preserves the sequencing into queue queue for characterizing the task, first preserves the position of the task into queue queue before rear preserve to the position of the task in queue queue.

Description

A kind of method and device obtaining spin lock
Technical field
The present invention relates to field of computer technology more particularly to a kind of method and devices obtaining spin lock.
Background technology
With the development of CPU multinuclears and concurrent technique, using the more of NC (Node Controller, Node Controller) In node large size NUMA (Non Uniform Memory Access Achitecture, nonuniform memory access) system, in order to The consistency for ensureing shared resource carries out the control of eventful business concurrent operations usually using the mechanism of spin lock.
In the prior art, application can be obtained multiple tasks one chained list of composition of spin lock by server, and multiple In the caching of processor where task, a local variable that is identical and being protected by spin lock is preserved, to server It can indicate that multiple task is periodically attempted to obtain the spin lock according to preset time interval, to access this Ground variable.
However, in the method for above-mentioned acquisition spin lock, regardless of whether taking turns to it obtains the spin lock, the task in chained list It can periodically attempt to obtain the spin lock, with the increase of the task quantity in chained list, application will be caused to obtain spin lock Number it is more, and increase system performance loss.
Invention content
The embodiment of the present invention provides a kind of method and device obtaining spin lock, can reduce since multiple tasks compete Shared resource and caused by system performance loss, to improve the performance of system.
In order to achieve the above objectives, the embodiment of the present invention adopts the following technical scheme that:
In a first aspect, the embodiment of the present invention provides a kind of method obtaining spin lock, including:
Receive the task of acquisition request spin lock;
The task is stored in queue queue;
According to position of the task in the queue queue, the spin-waiting time of the task is determined, so that The task is attempted to obtain the spin lock at the end of spin-waiting time;
Wherein, position of the task in the queue queue is preserved for characterizing the task to the queue queue In sequencing, first preserve to the position of the task in the queue queue and preserved to the task in the queue queue rear Position before.
In the first possible realization method of first aspect, the method further includes:
According to default detection cycle, whether the spin-waiting time for periodically detecting the task terminates.
In conjunction with the possible realization method of the first of first aspect above-mentioned or first aspect, in second of possible realization In mode, when the task is at the end of the spin-waiting time, after attempting the acquisition spin lock, the method is also wrapped It includes:
If the task obtains the spin lock failure, position of the task in the queue queue is redefined It sets;
According to position of the task redefined in the queue queue, the spin etc. of the task is redefined The time is waited for, so that the task, which at the end of the spin-waiting time redefined, reattempts to, obtains the spin Lock.
In conjunction with the possible realization method of the first of first aspect above-mentioned or first aspect to second of possible realization Any one of mode realization method, in the third possible realization method, the method further includes:
When the task positioned at queue queue's stem discharges the spin lock, the task is updated in the queuing team Position in row.
The third possible realization method with reference to first aspect, it is described to work as position in the 4th kind of possible realization method When the task of queue queue's stem discharges the spin lock, position of the task in the queue queue is updated, It specifically includes:
When the task positioned at queue queue's stem discharges the spin lock, by the task in the queue queue In location updating be the task position of the previous task in the queue queue.
In conjunction with the possible realization method of the first of first aspect above-mentioned or first aspect to the 4th kind of possible realization Any one of mode realization method, it is described that the task is stored in queue queue in the 5th kind of possible realization method In, it specifically includes:
The task is added to the tail portion of the queue queue.
Second aspect, the embodiment of the present invention provide a kind of server, including:
Receiving unit, the task for receiving acquisition request spin lock;
Determination unit, the task for receiving the receiving unit are stored in queue queue;
Determination unit, position of the task in the queue queue for being preserved according to the storage unit, really The spin-waiting time of the fixed task, so that the task at the end of spin-waiting time, is attempted described in acquisition Spin lock, wherein position of the task in the queue queue is preserved for characterizing the task to the queue queue In sequencing, first preserve to the position of the task in the queue queue and preserved to the task in the queue queue rear Position before.
In the first possible realization method of second aspect, the server further includes detection unit,
The detection unit, for according to detection cycle is preset, periodically detecting the described of the determination unit determination Whether the spin-waiting time of task terminates.
In conjunction with the possible realization method of the first of second aspect above-mentioned or second aspect, in second of possible realization In mode,
The determination unit is additionally operable to when the task is at the end of the spin-waiting time, and trial acquisition is described certainly After rotation lock, if the task obtains the spin lock failure, position of the task in the queue queue is redefined It sets, and the position according to the task redefined in the queue queue, redefines the spin-waiting of the task Time, so that the task, which at the end of the spin-waiting time redefined, reattempts to, obtains the spin lock.
In conjunction with the possible realization method of the first of second aspect above-mentioned or second aspect to second of possible realization Any one of mode realization method, in the third possible realization method, the server further includes updating unit,
The updating unit, for when the task positioned at queue queue's stem discharges the spin lock, updating institute State position of the task of storage unit preservation in the queue queue.
In conjunction with the third possible realization method of second aspect, in the 4th kind of possible realization method,
The updating unit is specifically used for when discharging the spin lock positioned at the task of queue queue's stem, will Location updating of the task in the queue queue is position of the previous task of the task in the queue queue It sets.
In conjunction with the possible realization method of the first of second aspect above-mentioned or second aspect to the 4th kind of possible realization Any one of mode realization method, in the 5th kind of possible realization method,
The storage unit is added to the queue queue specifically for the task for receiving the receiving unit Tail portion.
The embodiment of the present invention provides a kind of method and device obtaining spin lock, by receiving acquisition request spin lock Task, and the task is stored in queue queue, and the position according to the task in queue queue, determine the task The spin-waiting time, so that the task at the end of spin-waiting time, is attempted to obtain spin lock, wherein the task is being arranged Position in team's queue preserves the sequencing into queue queue for characterizing the task, first preserves appointing into queue queue The position of business is before rear preserve to the position of the task in queue queue.It with this solution, can be according to received task Position in queue queue calculates the spin-waiting time of the task, that is, attempts the time interval for obtaining spin lock, so that The spin-waiting time that application obtains multiple tasks of spin lock obtains dynamically adjusting, so that preserved in queue queue The spin-waiting time of the multiple tasks of acquisition request spin lock can obtain dynamic according to its position in queue queue Therefore adjustment solves multiple tasks in the prior art and attempts to obtain asking for spin lock every preset time interval Topic, can reduce due to multiple tasks compete shared resource and caused by system performance loss, to improve the performance of system.
Description of the drawings
Fig. 1 is a kind of flow chart one of method obtaining spin lock provided in an embodiment of the present invention;
Fig. 2 is a kind of flowchart 2 of method obtaining spin lock provided in an embodiment of the present invention;
Fig. 3 is the structural schematic diagram one of server provided in an embodiment of the present invention;
Fig. 4 is the structural schematic diagram two of server provided in an embodiment of the present invention;
Fig. 5 is the structural schematic diagram three of server provided in an embodiment of the present invention;
Fig. 6 is the structural schematic diagram four of server provided in an embodiment of the present invention.
Specific implementation mode
Below in conjunction with the accompanying drawings to it is provided in an embodiment of the present invention it is a kind of obtain spin lock method and device carry out in detail Description.
Embodiment one
The embodiment of the present invention provides a kind of method obtaining spin lock, as shown in Figure 1, this method may include:
S101, server receive the task of acquisition request spin lock.
Illustratively, if some task need to access the shared resource of spin lock protection, which need to ask to server The spin lock is obtained, server can receive the task first.
It should be noted that spin lock is a kind of lock to prevent multiprocessor from concurrently introducing, it is a large amount of in kernel (for uniprocessor, prevent concurrent can simply use in interrupt processing from closing interruption applied to the part such as interrupt processing Mode, do not need spin lock).At any time, spin lock can only at most be held by a task, if a task attempts to ask The spin lock for obtaining and having been held by some other tasks is sought, then when server may indicate that the task according to its spin-waiting Between, cycle is attempted to obtain the spin lock, and the spin lock is waited for can be used again.If the spin lock is not held by other any one tasks Have, then the task of the acquisition request spin lock can directly obtain the spin lock, in order to access the shared of spin lock protection Resource.
The task of acquisition request spin lock is stored in queue queue by S102, server.
After server receives the task of acquisition request spin lock, which can be stored in queue queue by server In.
Specifically, after server receives the task of acquisition request spin lock, server can preserve the task to row The tail portion of team's queue, and determine position of the task in queue queue.
Further, before server preserves the task of acquisition request spin lock into queue queue, in queue queue The task of other acquisition request spin locks can be preserved, the task of other acquisition request spin locks can also not preserved, if The task of other acquisition request spin locks is preserved in the queue queue, i.e. queue queue is not empty queue, then server can incite somebody to action The task received is added to the tail portion of the queue queue, and receives according to server all tasks in queue queue Sequencing determines position of the task in the queue queue;If other acquisition requests are not preserved in the queue queue certainly The task of lock is revolved, then the task can be added in queue queue by server, and determine that the task is positioned at queue queue's stem Task.
The position of S103, server according to the task of acquisition request spin lock in queue queue determines the task oneself The stand-by period is revolved, so that the task at the end of spin-waiting time, is attempted to obtain spin lock, wherein the task is being lined up Position in queue preserves the sequencing into queue queue for characterizing the task, first preserves the task into queue queue Position preserved to before the position of the task in queue queue rear.
After the task of acquisition request spin lock is stored in queue queue by server, server can exist according to the task Position in queue queue determines the spin-waiting time of the task, so that the task is tasted at the end of the spin-waiting time Examination obtains spin lock, wherein position of the task in queue queue preserves the elder generation into queue queue for characterizing the task Sequence afterwards first preserves the position of the task into queue queue before rear preserve to the position of the task in queue queue.
It attempts to obtain spin lock it should be noted that the spin-waiting time of the task of acquisition request spin lock is the task Time interval, and within the spin-waiting time of the task task state be spin-waiting state.
Further, it attempts to obtain the secondary of spin lock during spin to reduce the task of acquisition request spin lock Number, server can be by the spin-waiting times of the task according to its position in queue queue, i.e. serial number is adjusted into Mobile state, For example, the product of serial number and prefixed time interval of the task in queue queue can be determined as the spin of the task by server Stand-by period, the spin-waiting time of the task can also advantageously reduce the task according to other and attempt to obtain during spin The method for taking the number of spin lock is adjusted, and the present invention is not limited.
Further, before the task that server receives the acquisition request spin lock, if being preserved in the queue queue The task of other acquisition request spin locks, the then position that server can be according to the task in queue queue, the task determined The spin-waiting time be not zero, which can enter spin-waiting state, and server can be per between at regular intervals Whether terminate every the spin-waiting time for periodically detecting the task, at the end of the spin-waiting time of the task, this Business need to be attempted to obtain spin lock, if spin lock has not been obtained in the task, i.e., the task obtains spin lock failure, then server need to be sentenced Whether disconnected position of the task in queue queue is updated, i.e., server redefines the task in queue queue Position, and according to position of the task in queue queue is redefined, the spin-waiting time of the task is redefined, so as to In the task at the end of spin-waiting time redefined, acquisition spin lock is reattempted to, and so on, until the task For the task of queue queue's stem, i.e., the spin-waiting time for the task that server determines is zero, and the task its from At the end of revolving the stand-by period, which can get spin lock;If the spin of other acquisition requests is not preserved in the queue queue The spin-waiting time of the task of lock, then position of the server according to the task in queue queue, the task determined is zero, Then the task is not necessarily to enter spin-waiting state, you can is directly obtained spin lock.
Specifically, the process of position of the task about update acquisition request spin lock in queue queue will be follow-up real Example is applied to be described in detail.
The embodiment of the present invention provides a kind of method obtaining spin lock, and acquisition request spin lock is received by server Task, and the task is stored in queue queue, and the position according to the task in queue queue, determine the task The spin-waiting time, so that the task at the end of spin-waiting time, is attempted to obtain spin lock, wherein the task is being arranged Position in team's queue preserves the sequencing into queue queue for characterizing the task, first preserves appointing into queue queue The position of business is before rear preserve to the position of the task in queue queue.With this solution, server can be according to receiving Position of the task in queue queue, calculate the spin-waiting time of the task, that is, attempt the time interval for obtaining spin lock, It is adjusted so that the spin-waiting time of the task obtains dynamic, so that the acquisition request spin lock preserved in queue queue Multiple tasks the spin-waiting time can be obtained according to its position in queue queue dynamic adjust, therefore, solve Multiple tasks are every preset time interval is attempted to obtain spin lock the problem of in the prior art, can reduce due to Multiple tasks compete shared resource and caused by system performance loss, to improve the performance of system.
Embodiment two
The embodiment of the present invention provides a kind of method obtaining spin lock, as shown in Fig. 2, this method may include:
S201, server receive the task of acquisition request spin lock.
Illustratively, if some task need to access the shared resource of spin lock protection, which need to ask to server The spin lock is obtained, server can receive the task first.
It should be noted that spin lock is a kind of lock to prevent multiprocessor from concurrently introducing, it is a large amount of in kernel (for uniprocessor, prevent concurrent can simply use in interrupt processing from closing interruption applied to the part such as interrupt processing Mode, do not need spin lock).At any time, spin lock can only at most be held by a task, if a task attempts to ask The spin lock for obtaining and having been held by some other tasks is sought, then when server may indicate that the task according to its spin-waiting Between, cycle is attempted to obtain the spin lock, and the spin lock is waited for can be used again.If the spin lock is not held by other any one tasks Have, then the task of the acquisition request spin lock can directly obtain the spin lock, in order to access the shared of spin lock protection Resource.
The task of acquisition request spin lock is added to the tail portion of queue queue by S202, server.
After server receives the task of acquisition request spin lock, which can be added to queue queue by server Tail portion, and determine position of the task in queue queue.
Further, the queue queue in the embodiment of the present invention is a kind of FIFO (First In First Out, advanced elder generation Go out) linear list, only allow in its stem, i.e., queue head carries out the operation of deletion task, and in its tail portion be inserted into and appoint The operation of business.
Further, in order to ensure that the multiple tasks of spin lock to be obtained receive multiple task according to server Sequence obtains spin lock, and therefore, after server receives first task, first task can be added to queue queue by server Tail portion, and so on, so as to ensure the task of the spin lock to be obtained preserved in queue queue according to the sequence of FIFO Obtain spin lock.
Further, before the task of acquisition request spin lock is added to queue queue tail portion by server, queue queue In can preserve the tasks of other acquisition request spin locks, the task of other acquisition request spin locks can also not preserved, If preserving the task of other acquisition request spin locks in the queue queue, i.e., queue queue is not empty queue, then server can The task received is added to the tail portion of the queue queue, and receives all tasks in queue queue according to server Sequencing, determine position of the task in the queue queue;If other acquisition requests are not preserved in the queue queue The task of spin lock, then the task can be added in queue queue by server, and determine that the task is positioned at queue queue head The task in portion.
It should be noted that position of the task of acquisition request spin lock in queue queue can be lined up with the task Serial number in queue indicates, if serial number zero of the task in queue queue, then it represents that the task is queue queue's stem Task;If serial number of the task in queue queue is not zero, then it represents that the task is not the task of queue queue's stem.
Further, serial number of the task of acquisition request spin lock in queue queue can be absolute sequence number, can also For opposite serial number.If the serial number of all tasks in queue queue is started from scratch number with incremental sequence, which exists Serial number absolute sequence number in queue queue;If the serial number of all tasks in queue queue is with incremental sequence, but is not Start from scratch number, then serial number of the task in queue queue is with respect to serial number, at this point, sequence of the task in queue queue Number it is the difference of absolute sequence number and offset of the task in queue queue, the offset is according to all in queue queue The numerical value that the coding rule of business determines.
The position of S203, server according to the task of acquisition request spin lock in queue queue determines the task oneself The stand-by period is revolved, so that the task at the end of spin-waiting time, is attempted to obtain spin lock, wherein the task is being lined up Position in queue preserves the sequencing into queue queue for characterizing the task, first preserves the task into queue queue Position preserved to before the position of the task in queue queue rear.
After the task of acquisition request spin lock is added to the tail portion of queue queue by server, server can be according to this It is engaged in the position in queue queue, the spin-waiting time of the task being determined, so that the task terminates in the spin-waiting time When, it attempts to obtain spin lock, wherein position of the task in queue queue is preserved for characterizing the task into queue queue Sequencing, first preserve the position of the task into queue queue it is rear preserve to the position of the task in queue queue it Before.
It attempts to obtain spin lock it should be noted that the spin-waiting time of the task of acquisition request spin lock is the task Time interval, and within the spin-waiting time of the task task state be spin-waiting state.
Further, it attempts to obtain the secondary of spin lock during spin to reduce the task of acquisition request spin lock Number, server can be by the spin-waiting times of the task according to its position in queue queue, i.e. serial number is adjusted into Mobile state, For example, the product of serial number and prefixed time interval of the task in queue queue can be determined as the spin of the task by server Stand-by period, the spin-waiting time of the task can also advantageously reduce the task according to other and attempt to obtain during spin The method for taking the number of spin lock is adjusted, and the present invention is not limited.
For example, if prefixed time interval is delta (t), in the prior art, acquisition request spin lock in chained list is appointed The spin-waiting time of business is set as delta (t), i.e., the task of the acquisition request spin lock in chained list can be tasted every delta (t) Examination obtains spin lock, and the task in order to reduce acquisition request spin lock is attempted to obtain the number of spin lock, and the present invention at least may be used To provide two kinds of implementations:
(1) in the present invention, server can be by the task of the acquisition request spin lock in queue queue in queue queue Serial number and the product of prefixed time interval are determined as the spin-waiting time of the task, if serial number of the task in queue queue For que_seri, then the spin-waiting time of the task can be que_seri*delta (t), since the task is in queue queue In serial number take positive integer, then the present invention compared with the existing technology, the spin-waiting time of the task is increased to from delta (t) Que_seri*delta (t), compared with the existing technology to the present invention, the task of acquisition request spin lock attempt to obtain spin lock Number then reduce.
(2) present invention can also preset a maximum value MAX, when the task of acquisition request spin lock is in queue queue When serial number is less than or equal to the maximum value, server can by serial number of the task of acquisition request spin lock in queue queue with it is pre- If the product of time interval, it is determined as the spin-waiting time of the task, if serial number que_ of the task in queue queue Seri, then the spin-waiting time of the task can be que_seri*delta (t);When the task of acquisition request spin lock is being arranged When serial number in team's queue is more than the maximum value, the product of the maximum value and prefixed time interval can be determined as this by server The spin-waiting time of business, i.e. the spin-waiting time of the task can be MAX*delta (t).
Further, before the task that server receives the acquisition request spin lock, if being preserved in the queue queue The task of other acquisition request spin locks, the then position that server can be according to the task in queue queue, the task determined The spin-waiting time be not zero, which can enter spin-waiting state, and server can be per between at regular intervals Whether terminate every the spin-waiting time for periodically detecting the task, at the end of the spin-waiting time of the task, this Business need to be attempted to obtain spin lock, if spin lock has not been obtained in the task, i.e., the task obtains spin lock failure, then server need to be sentenced Whether disconnected position of the task in queue queue is updated, i.e., server redefines the task in queue queue Position, and according to position of the task in queue queue is redefined, the spin-waiting time of the task is redefined, so as to In the task at the end of spin-waiting time redefined, acquisition spin lock is reattempted to, and so on, until the task For the task of queue queue's stem, i.e., the spin-waiting time for the task that server determines is zero, and the task its from At the end of revolving the stand-by period, which can get spin lock;If the spin of other acquisition requests is not preserved in the queue queue The spin-waiting time of the task of lock, then position of the server according to the task in queue queue, the task determined is zero, Then the task is not necessarily to enter spin-waiting state, you can is directly obtained spin lock.
S204, server periodically detect the spin etc. of the task of acquisition request spin lock according to default detection cycle When the time whether to the end of.
After the task of acquisition request spin lock is added to queue queue tail portion by server, server can determine the task Position in queue queue, if the task is not the task of queue queue's stem, which can enter spin-waiting state, The task enters after spin-waiting state, and server can periodically detect the spin of the task according to default detection cycle Whether the stand-by period terminates.
Further, if server detects that the spin-waiting time of the task of acquisition request spin lock terminates, this Business can be attempted to obtain spin lock;If server detects that the spin-waiting time of the task of acquisition request spin lock is not finished, The task still maintains spin-waiting state.
If the task of S205, acquisition request spin lock obtains spin lock failure, server redefines the task and is arranging Position in team's queue.
When the task of acquisition request spin lock is at the end of the spin-waiting time, attempt after obtaining spin lock, if this Business obtains spin lock failure, then server can redefine position of the task in queue queue.
Further, terminate when the spin-waiting time of the task of acquisition request spin lock, and the task is queue queue When serial number zero in queue queue of the task of stem, the i.e. task, which obtains spin lock success;When acquisition request from The spin-waiting time for revolving the task of lock terminates, and the task is not the task of queue queue's stem, i.e. the task is being lined up team When serial number in row is not zero, which obtains spin lock failure.
The position of S206, server according to the task of the acquisition request spin lock redefined in queue queue, again The spin-waiting time of the task is determined, so that the task reattempts at the end of the spin-waiting time redefined Obtain spin lock.
After server redefines position of the task of acquisition request spin lock in queue queue, server can basis Position of the task redefined in queue queue, redefines the spin-waiting time of the task, so that the task At the end of the spin-waiting time redefined, acquisition spin lock is reattempted to.
Further, if the task for the acquisition request spin lock that server redefines is the task of queue queue's stem, Then server can be directly obtained spin lock at the end of the task spin-waiting time;If the request that server redefines The obtaining spin lock of the task is not the task of queue queue's stem, then the task can be attempted to obtain at the end of the spin-waiting time Spin lock is taken, until the task is the task of queue queue's stem, and at the end of the spin-waiting time of the task, the task Spin lock can be got.
S207, when positioned at queue queue's stem task discharge spin lock when, server update acquisition request spin lock Position of the task in queue queue.
After the spin-waiting time that server determines the task of acquisition request spin lock, server can be detected periodically Whether the task of queue queue's stem discharges spin lock, when the task positioned at queue queue's stem discharges spin lock, server Renewable position of the task in queue queue.
Specifically, when the task positioned at queue queue's stem discharges spin lock, server can be by acquisition request spin lock Location updating of the task in queue queue be position of the previous task of the task in queue queue.
For example, after the task of acquisition request spin lock is added to queue queue by server, the server update task The process of position in queue queue may include:If server detects that the task of queue queue's stem releases spin Lock, then other positions of all tasks in the queue queue after the task of queue queue's stem are both needed to carry out by server Update, server can update position of all tasks of other after the task of queue queue's stem in the queue queue For its position of the previous task in queue queue, therefore, the location updating that server can be by the task in queue queue For position of the previous task in queue queue of the task, i.e. server can be by serial number of the task in queue queue more It is newly serial number of the previous task of the task in queue queue, if the updated task is not appointing for queue queue's stem Business, the position that server can be according to the updated task in queue queue, when determining the spin-waiting of the task next time Between, in order to which the task enters spin-waiting state next time;If server detects that the task of queue queue's stem is held always There is spin lock, then server can keep position of the first task in queue queue, i.e. serial number constant.
The method provided in an embodiment of the present invention for obtaining spin lock can be applied in NUMA system, in can also being applied to Disconnected, process scheduling, memory management, file system or distributed file system synchronization mechanism etc. can apply the field of spin lock Scape can also use spin lock scene applied to other, and the present invention is not limited.
The embodiment of the present invention provides a kind of method obtaining spin lock, and acquisition request spin lock is received by server Task, and the task is stored in queue queue, and the position according to the task in queue queue, determine the task The spin-waiting time, so that the task at the end of spin-waiting time, is attempted to obtain spin lock, wherein the task is being arranged Position in team's queue preserves the sequencing into queue queue for characterizing the task, first preserves appointing into queue queue The position of business is before rear preserve to the position of the task in queue queue.With this solution, server can be according to receiving Position of the task in queue queue, calculate the spin-waiting time of the task, that is, attempt the time interval for obtaining spin lock, It is adjusted so that the spin-waiting time of the task obtains dynamic, so that the acquisition request spin lock preserved in queue queue Multiple tasks the spin-waiting time can be obtained according to its position in queue queue dynamic adjust, therefore, solve Multiple tasks are every preset time interval is attempted to obtain spin lock the problem of in the prior art, can reduce due to Multiple tasks compete shared resource and caused by system performance loss, to improve the performance of system.
Embodiment three
As shown in figure 3, the embodiment of the present invention provides a kind of server 1, which may include:
Receiving unit 10, the task for receiving acquisition request spin lock.
Storage unit 11, the task for receiving the receiving unit 10 are stored in queue queue;
Determination unit 12, position of the task in the queue queue for being preserved according to the storage unit 11 It sets, determines the spin-waiting time of the task, so that the task at the end of spin-waiting time, is attempted to obtain The spin lock, wherein position of the task in the queue queue is preserved for characterizing the task to the queuing Sequencing in queue is first preserved to the position of the task in the queue queue in rear preserve to the queue queue Before the position of task.
Optionally, as shown in figure 4, the server 1 further includes detection unit 13, the detection unit 13 is used for basis Whether default detection cycle, the spin-waiting time for periodically detecting the task of the determination of the determination unit 12 terminate.
Optionally, the determination unit 12 is additionally operable to work as the task at the end of spin-waiting time, attempts to obtain After taking the spin lock, if the task obtains the spin lock failure, the task is redefined in the queuing team Position in row, and the position according to the task redefined in the queue queue, redefine the task The spin-waiting time, so that the task, which at the end of the spin-waiting time redefined, reattempts to, obtains institute State spin lock.
Optionally, as shown in figure 5, the server 1 further includes updating unit 14, the updating unit 14, for working as position When the task of queue queue's stem discharges the spin lock, the task of the preservation of the storage unit 11 is updated in institute State the position in queue queue.
Optionally, the updating unit 14, specifically for working as described in the task release positioned at queue queue's stem certainly Rotation lock when, by location updating of the task in the queue queue be the task previous task in the queuing team Position in row.
Optionally, the storage unit 11 is added to institute specifically for the task for receiving the receiving unit 10 State the tail portion of queue queue.
The embodiment of the present invention provides a kind of server, which receives the task of acquisition request spin lock, and should Task is stored in queue queue, and the position according to the task in queue queue, when determining the spin-waiting of the task Between, so that the task at the end of spin-waiting time, is attempted to obtain spin lock, wherein the task is in queue queue Position preserves the sequencing into queue queue for characterizing the task, and the position for first preserving the task into queue queue exists Before the position for preserving the task into queue queue afterwards.With this solution, server can arranged according to received task Position in team's queue calculates the spin-waiting time of the task, that is, attempts the time interval for obtaining spin lock, so that this The spin-waiting time of business obtains dynamic and adjusts, so that the multiple tasks of the acquisition request spin lock preserved in queue queue The spin-waiting time can be obtained according to its position in queue queue dynamic adjust, therefore, solve the prior art Middle multiple tasks every preset time interval attempt obtain spin lock the problem of, can reduce since multiple tasks are competing Strive shared resource and caused by system performance loss, to improve the performance of system.
Example IV
As shown in fig. 6, the embodiment of the present invention provides a kind of server, which may include:Processor 15, memory 16, system bus 17 and user interface 18, wherein
It is connected by system bus 17 between processor 15, memory 16 and communication interface 18 and completes mutual lead to Letter.
Processor 15 may be single or multiple core central processing unit, be either specific integrated circuit or be configured as reality Apply one or more integrated circuits of the embodiment of the present invention.
Memory 16 can be high-speed RAM (Random Access Memory, random access memory), or non- Volatile memory (non-volatile memory), for example, at least a magnetic disk storage.
Memory 16 is used for the instruction of storage server.Specifically, the instruction of server may include software program and soft Part code.
Specifically, processor 15 can be used for receiving appointing for acquisition request spin lock from user interface 18 by system bus 17 Business, and the task is stored in queue queue, and the position according to the task in the queue queue, determine institute The spin-waiting time of task is stated, so that the task at the end of spin-waiting time, is attempted to obtain the spin Lock, wherein position of the task in the queue queue is preserved for characterizing the task into the queue queue Sequencing is first preserved to the position of the task in the queue queue and is preserved to the position of the task in the queue queue rear Before setting;The memory 16 can be used for storing the software code of the task and the control processor 15 completes above-mentioned steps Software program so that the processor 15 can by executing above-mentioned software program and calling above-mentioned software code, to Complete above-mentioned steps.
Optionally, the processor 15 is additionally operable to, according to detection cycle is preset, periodically detect the spin of the task Whether the stand-by period terminates.
Optionally, the processor 15 is additionally operable to when the task is at the end of the spin-waiting time, and trial obtains After the spin lock, if the task obtains the spin lock failure, the task is redefined in the queue queue In position, and the position according to the task redefined in the queue queue, redefine the task from The stand-by period is revolved, so that the task reattempts at the end of the spin-waiting time redefined described in acquisition Spin lock.
Optionally, the processor 15 is additionally operable to discharge the spin lock when the task positioned at queue queue's stem When, update position of the task in the queue queue.
Optionally, the processor 15 is specifically used for discharging the spin when the task positioned at queue queue's stem When lock, by location updating of the task in the queue queue be the task previous task in the queue queue In position.
Optionally, the processor 15, specifically for the task to be added to the tail portion of the queue queue.
The embodiment of the present invention provides a kind of server, which receives the task of acquisition request spin lock, and should Task is stored in queue queue, and the position according to the task in queue queue, when determining the spin-waiting of the task Between, so that the task at the end of spin-waiting time, is attempted to obtain spin lock, wherein the task is in queue queue Position preserves the sequencing into queue queue for characterizing the task, and the position for first preserving the task into queue queue exists Before the position for preserving the task into queue queue afterwards.With this solution, server can arranged according to received task Position in team's queue calculates the spin-waiting time of the task, that is, attempts the time interval for obtaining spin lock, so that this The spin-waiting time of business obtains dynamic and adjusts, so that the multiple tasks of the acquisition request spin lock preserved in queue queue The spin-waiting time can be obtained according to its position in queue queue dynamic adjust, therefore, solve the prior art Middle multiple tasks every preset time interval attempt obtain spin lock the problem of, can reduce since multiple tasks are competing Strive shared resource and caused by system performance loss, to improve the performance of system.
It is apparent to those skilled in the art that for convenience and simplicity of description, only with above-mentioned each function The division progress of module, can be as needed and by above-mentioned function distribution by different function moulds for example, in practical application Block is completed, i.e., the internal structure of device is divided into different function modules, to complete all or part of work(described above Energy.The specific work process of the system, apparatus, and unit of foregoing description can refer to corresponding in preceding method embodiment Journey, details are not described herein.
In several embodiments provided herein, it should be understood that disclosed system, device and method can be with It realizes by another way.For example, the apparatus embodiments described above are merely exemplary, for example, the module or The division of unit, only a kind of division of logic function, formula that in actual implementation, there may be another division manner, such as multiple units Or component can be combined or can be integrated into another system, or some features can be ignored or not executed.Another point, institute Display or the mutual coupling, direct-coupling or communication connection discussed can be by some interfaces, device or unit INDIRECT COUPLING or communication connection can be electrical, machinery or other forms.
The unit illustrated as separating component may or may not be physically separated, aobvious as unit The component shown may or may not be physical unit, you can be located at a place, or may be distributed over multiple In network element.Some or all of unit therein can be selected according to the actual needs to realize the mesh of this embodiment scheme 's.
In addition, each functional unit in each embodiment of the present invention can be integrated in a processing unit, it can also It is that each unit physically exists alone, it can also be during two or more units be integrated in one unit.Above-mentioned integrated list The form that hardware had both may be used in member is realized, can also be realized in the form of SFU software functional unit.
If the integrated unit is realized in the form of SFU software functional unit and sells or use as independent product When, it can be stored in a computer read/write memory medium.Based on this understanding, technical scheme of the present invention is substantially The all or part of the part that contributes to existing technology or the technical solution can be in the form of software products in other words It embodies, which is stored in a storage medium, including some instructions are used so that a computer It is each that equipment (can be personal computer, server or the network equipment etc.) or processor (processor) execute the present invention The all or part of step of embodiment the method.And storage medium above-mentioned includes:USB flash disk, mobile hard disk, read-only memory Various Jie that can store program code such as (ROM, Read-Only Memory), random access memory, magnetic disc or CD Matter.
The above description is merely a specific embodiment, but scope of protection of the present invention is not limited thereto, any Those familiar with the art in the technical scope disclosed by the present invention, can easily think of the change or the replacement, and should all contain Lid is within protection scope of the present invention.Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.

Claims (12)

1. a kind of method obtaining spin lock, which is characterized in that including:
Receive the task of acquisition request spin lock;
The task is stored in queue queue;
According to position of the task in the queue queue, the spin-waiting time of the task is determined, so that described Task is attempted to obtain the spin lock at the end of spin-waiting time;
Wherein, position of the task in the queue queue is preserved for characterizing the task into the queue queue Sequencing is first preserved to the position of the task in the queue queue and is preserved to the position of the task in the queue queue rear Before setting.
2. the method according to claim 1 for obtaining spin lock, which is characterized in that the method further includes:
According to default detection cycle, whether the spin-waiting time for periodically detecting the task terminates.
3. the method according to claim 1 or 2 for obtaining spin lock, which is characterized in that when the task is in the spin At the end of stand-by period, attempt after obtaining the spin lock, the method further includes:
If the task obtains the spin lock failure, position of the task in the queue queue is redefined;
According to position of the task redefined in the queue queue, when redefining the spin-waiting of the task Between, so that the task, which at the end of the spin-waiting time redefined, reattempts to, obtains the spin lock.
4. the method according to claim 1 or 2 for obtaining spin lock, which is characterized in that the method further includes:
When the task positioned at queue queue's stem discharges the spin lock, the task is updated in the queue queue Position.
5. the method according to claim 4 for obtaining spin lock, which is characterized in that described first when being located at the queue queue When the task in portion discharges the spin lock, position of the task in the queue queue is updated, is specifically included:
When the task positioned at queue queue's stem discharges the spin lock, by the task in the queue queue Location updating is position of the previous task of the task in the queue queue.
6. the method according to claim 1 for obtaining spin lock, which is characterized in that described that the task is stored in queuing In queue, specifically include:
The task is added to the tail portion of the queue queue.
7. a kind of server, which is characterized in that including:
Receiving unit, the task for receiving acquisition request spin lock;
Storage unit, the task for receiving the receiving unit are stored in queue queue;
Determination unit, position of the task in the queue queue for being preserved according to the storage unit, determines institute The spin-waiting time of task is stated, so that the task at the end of spin-waiting time, is attempted to obtain the spin Lock, wherein position of the task in the queue queue is preserved for characterizing the task into the queue queue Sequencing is first preserved to the position of the task in the queue queue and is preserved to the position of the task in the queue queue rear Before setting.
8. server according to claim 7, which is characterized in that the server further includes detection unit,
The detection unit, for according to detection cycle is preset, periodically detecting the task that the determination unit determines The spin-waiting time whether terminate.
9. server according to claim 7 or 8, which is characterized in that
The determination unit is additionally operable to when the task is at the end of the spin-waiting time, and trial obtains the spin lock Later, if the task obtains the spin lock failure, position of the task in the queue queue is redefined, and According to position of the task redefined in the queue queue, the spin-waiting time of the task is redefined, So that the task, which at the end of the spin-waiting time redefined, reattempts to, obtains the spin lock.
10. server according to claim 7 or 8, which is characterized in that the server further includes updating unit,
The updating unit, for when the task positioned at queue queue's stem discharges the spin lock, updating the guarantor Position of the task that memory cell preserves in the queue queue.
11. server according to claim 10, which is characterized in that
The updating unit is specifically used for when discharging the spin lock positioned at the task of queue queue's stem, will be described Location updating of the task in the queue queue is position of the previous task of the task in the queue queue.
12. server according to claim 7, which is characterized in that
The storage unit is added to the tail of the queue queue specifically for the task for receiving the receiving unit Portion.
CN201410109467.XA 2014-03-21 2014-03-21 A kind of method and device obtaining spin lock Active CN104932933B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201410109467.XA CN104932933B (en) 2014-03-21 2014-03-21 A kind of method and device obtaining spin lock

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201410109467.XA CN104932933B (en) 2014-03-21 2014-03-21 A kind of method and device obtaining spin lock

Publications (2)

Publication Number Publication Date
CN104932933A CN104932933A (en) 2015-09-23
CN104932933B true CN104932933B (en) 2018-11-13

Family

ID=54120108

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201410109467.XA Active CN104932933B (en) 2014-03-21 2014-03-21 A kind of method and device obtaining spin lock

Country Status (1)

Country Link
CN (1) CN104932933B (en)

Families Citing this family (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106020333B (en) * 2016-05-20 2019-03-05 京信通信系统(中国)有限公司 Multi-core timer implementing method and multiple nucleus system
CN107783843B (en) * 2016-08-31 2021-08-06 中国移动通信有限公司研究院 Cloud data processing method and device
CN109558241A (en) * 2018-11-13 2019-04-02 锐捷网络股份有限公司 A kind of method and device obtaining spin lock
CN112306703A (en) * 2019-07-29 2021-02-02 华为技术有限公司 Critical region execution method and device in NUMA system
CN112306698A (en) * 2019-07-29 2021-02-02 华为技术有限公司 Critical region execution method and device in NUMA system
US11379456B2 (en) * 2020-10-01 2022-07-05 Oracle International Corporation Efficient adjustment of spin-locking parameter values
US11868261B2 (en) 2021-07-20 2024-01-09 Oracle International Corporation Prediction of buffer pool size for transaction processing workloads
CN115934370A (en) * 2022-12-23 2023-04-07 科东(广州)软件科技有限公司 Spin lock acquisition method, device, equipment and storage medium

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102317918A (en) * 2009-02-17 2012-01-11 松下电器产业株式会社 Exclusive control method of resource and exclusive controller of resource
CN102566979A (en) * 2011-12-02 2012-07-11 华为技术有限公司 Method, device and multi-core processor system for realizing self-adaptive lock
CN103262030A (en) * 2010-12-16 2013-08-21 英特尔公司 A fast and linearizable concurrent priority queue via dynamic aggregation of operations
CN103324269A (en) * 2013-06-13 2013-09-25 中国科学院计算技术研究所 Method and system for reducing multithread program power consumption

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7051026B2 (en) * 2002-07-31 2006-05-23 International Business Machines Corporation System and method for monitoring software locks

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102317918A (en) * 2009-02-17 2012-01-11 松下电器产业株式会社 Exclusive control method of resource and exclusive controller of resource
CN103262030A (en) * 2010-12-16 2013-08-21 英特尔公司 A fast and linearizable concurrent priority queue via dynamic aggregation of operations
CN102566979A (en) * 2011-12-02 2012-07-11 华为技术有限公司 Method, device and multi-core processor system for realizing self-adaptive lock
CN103324269A (en) * 2013-06-13 2013-09-25 中国科学院计算技术研究所 Method and system for reducing multithread program power consumption

Also Published As

Publication number Publication date
CN104932933A (en) 2015-09-23

Similar Documents

Publication Publication Date Title
CN104932933B (en) A kind of method and device obtaining spin lock
CN105103144B (en) For the device and method of the self adaptive control of memory
US9400617B2 (en) Hardware-assisted DMA transfer with dependency table configured to permit-in parallel-data drain from cache without processor intervention when filled or drained
US20160364334A1 (en) Managing coherent memory between an accelerated processing device and a central processing unit
CN107526546B (en) Spark distributed computing data processing method and system
US8453150B2 (en) Multithread application-aware memory scheduling scheme for multi-core processors
US8255920B2 (en) Time management control method for computer system, and computer system
CN102981864B (en) Signal conditioning package and information processing method
EP3217406B1 (en) Memory management method and device, and memory controller
CN106547612A (en) A kind of multi-task processing method and device
CN105335306B (en) A kind of internal memory control method and device
US9043806B2 (en) Information processing device and task switching method
US10691601B2 (en) Cache coherence management method and node controller
EP2936317A1 (en) In-place change between transient and persistent state for data structures in non-volatile memory
WO2019028682A1 (en) Multi-system shared memory management method and device
CN107704310A (en) A kind of method, apparatus and equipment for realizing container cluster management
CN115033352A (en) Task scheduling method, device and equipment for multi-core processor and storage medium
CN113760543A (en) Resource management method and device, electronic equipment and computer readable storage medium
US10042659B1 (en) Caching virtual contexts for sharing of physical instances of a hardware resource
CN109521970B (en) Data processing method and related equipment
US20130238871A1 (en) Data processing method and apparatus, pci-e bus system, and server
CN104050189B (en) The page shares processing method and processing device
CN114995770B (en) Data processing method, device, equipment, system and readable storage medium
CN105224258B (en) The multiplexing method and system of a kind of data buffer zone
CN111694787A (en) Chip starting method, network equipment and machine readable storage medium

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant
TR01 Transfer of patent right
TR01 Transfer of patent right

Effective date of registration: 20211221

Address after: 450046 Floor 9, building 1, Zhengshang Boya Plaza, Longzihu wisdom Island, Zhengdong New Area, Zhengzhou City, Henan Province

Patentee after: xFusion Digital Technologies Co., Ltd.

Address before: 518129 Bantian HUAWEI headquarters office building, Longgang District, Guangdong, Shenzhen

Patentee before: HUAWEI TECHNOLOGIES Co.,Ltd.