Synchronization mechanisms based on counters
First Claim
1. A computer implemented method, comprising:
- maintaining a plurality of counters in memory including a lock counter and an unlock counter to synchronize a plurality of requests for a lock, the lock counter indicating a cumulative number of the requests, and the unlock counter indicating a cumulative number of a portion of the requests having released the lock, the requests stored with sequence numbers to wait for the lock, the sequence numbers counted via the lock counter, each request uniquely identified via one of the sequence numbers;
selecting at least one of the requests stored to grant the lock according to the sequence numbers, wherein the lock counter has a current count when the at least one request is selected, wherein the sequence numbers stored with the requests include consecutive sequence numbers less than the current count; and
performing the synchronized operations for the selected requests.
2 Assignments
0 Petitions
Accused Products
Abstract
A method and apparatus which maintain a plurality of counters to synchronize a plurality of requests for a lock independent of interlocks. The plurality of counters include a lock counter and an unlock counter. The requests wait in a wait queue maintained separately from the counters without direct access between the counters and the wait queue. The lock counter indicates a cumulative number of lock requests to acquire the lock. The unlock counter indicates a cumulative number of unlock requests to release the lock acquired. One or more requests waiting for the lock are selected according to the counters to be granted with the lock when the lock is released. A request corresponds to a task performing synchronized operations when granted with the lock.
-
Citations
70 Claims
-
1. A computer implemented method, comprising:
-
maintaining a plurality of counters in memory including a lock counter and an unlock counter to synchronize a plurality of requests for a lock, the lock counter indicating a cumulative number of the requests, and the unlock counter indicating a cumulative number of a portion of the requests having released the lock, the requests stored with sequence numbers to wait for the lock, the sequence numbers counted via the lock counter, each request uniquely identified via one of the sequence numbers; selecting at least one of the requests stored to grant the lock according to the sequence numbers, wherein the lock counter has a current count when the at least one request is selected, wherein the sequence numbers stored with the requests include consecutive sequence numbers less than the current count; and performing the synchronized operations for the selected requests. - View Dependent Claims (2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13)
-
-
14. A machine-readable non-transitory storage medium having instructions, when executed by a machine, cause the machine to perform a method, the method comprising:
-
maintaining a plurality of counters in memory including a lock counter and an unlock counter to synchronize a plurality of requests for a lock, the lock counter indicating a cumulative number of the requests, and the unlock counter indicating a cumulative number of a portion of the requests having released the lock, the requests stored with sequence numbers to wait for the lock, the sequence numbers counted via the lock counter, each request uniquely identified via one of the sequence numbers; selecting at least one of the requests stored to grant the lock according to the sequence numbers, wherein the lock counter has a current count when the at least one request is selected, wherein the sequence numbers stored with the requests include consecutive sequence numbers less than the current count; and performing the synchronized operations for the selected requests.
-
-
15. An apparatus comprising a processor and a memory storing executable code including a synchronization library, a kernel library and an interface module, the processor coupled to the memory to execute the executable code, the processor configured to:
-
maintain a plurality of counters in memory via the synchronization library in a user mode, the counters including a lock counter and an unlock counter to synchronize a plurality of requests for a lock, the lock counter indicating a cumulative number of the requests, and the unlock counter indicating a cumulative number of a portion of the requests having released the lock, the requests stored with sequence numbers to wait for the lock, the sequence numbers counted via the lock counter, each request uniquely identified via one of the sequence numbers, select at least one of the requests to grant a lock via the kernel library in a kernel mode according to the sequence numbers, wherein the lock counter has a current count when the at least one request is selected, wherein the sequence numbers stored with the requests include consecutive sequence numbers less than the current count, and perform the synchronized operations via the interface module for the selected requests.
-
-
16. A computer implemented method, comprising:
-
maintaining one or more counters to synchronize a plurality of requests for a lock, the counters having a state indicating values of the counters, the requests stored with sequence numbers to wait for the lock, the sequenced numbers counted via the state of the counters, each request uniquely identified via one of the sequence numbers; calling a first kernel interface with a first state of the counters to wait for the lock for a particular one of the requests, the counters having the first state when the first kernel interface was called, the particular request associated with a particular one of the sequence numbers, the first state including the particular sequence number, wherein the first kernel interface returns when the lock is granted, wherein the counters have a second state when the lock is granted, the second state including a current sequence number, wherein the sequence numbers stored with the requests include consecutive sequence numbers less than the current sequence number; updating the counters atomically based on the second state of the counters returned from the first kernel interface; and performing synchronized operations subsequent to the update of the counters. - View Dependent Claims (17, 18, 19, 20, 21, 24, 25, 26, 27, 28, 32, 33, 34)
-
-
22. A computer implemented method, comprising:
-
maintaining one or more counters to synchronize a plurality of requests for a lock, the counters having a state indicating values of the counters; calling a first kernel interface with a first state to wait for the lock; updating the counters atomically based on a second state of the counters returned from the first kernel interface; and performing synchronized operations subsequent to the update of the counters, wherein the updated counters have an update state, wherein the update comprises; retrieving a current state of the counter, and determining the update state based on the second state and the current state of the counters, wherein the counters include status flags, wherein the status flags include an exclusive flag indicating whether the lock is granted exclusively to at most one request, wherein the status flags include a wait flag indicating whether there are remaining ones of the requests waiting for the lock, wherein the determination includes a transition table mapping the current state and the second state to the update state of the counters. - View Dependent Claims (23)
-
-
29. A computer implemented method, comprising:
-
maintaining one or more counters to synchronize a plurality of requests for a lock, the counters having a state indicating values of the counters; calling a first kernel interface with a first state to wait for the lock; updating the counters atomically based on a second state of the counters returned from the first kernel interface; performing synchronized operations subsequent to the update of the counters, wherein the counters include a lock counter, wherein the state includes a lock count for the lock counter, and wherein the maintenance comprises; retrieving a lock count from the lock counter, and updating the lock counter atomically counting up from the current lock count, wherein the counters include an unlock counter, the maintenance further comprising; retrieving a current state from the counters subsequent to performing the synchronized operations, the current state including a current unlock count corresponding to the unlock counter, and updating the unlock counter atomically counting up from the current unlock count; determining whether there are requests waiting for the lock; and resetting the lock and unlock counters if there is no request waiting for the lock, wherein the current state includes a current lock count for the lock counter, wherein determining whether there are requests waiting for the lock is based on a relationship between the current lock count and the current unlock count, wherein resetting the lock and unlock counters comprises; updating the unlock counter from the current unlock count to a predetermined initial value, performing a first atomic operation to update the lock counter from the current lock count to the predetermined initial value, and if the first atomic operation is not successful, restoring the unlock counter from the predetermined initial value based on the current unlock count. - View Dependent Claims (30, 31)
-
-
35. A machine-readable non-transitory storage medium having instructions, when executed by a machine, cause the machine to perform a method, the method comprising:
-
maintaining one or more counters in memory to synchronize a plurality of requests for a lock, the counters having a state indicating values of the counters, the requests stored with sequence numbers to wait for the lock, the sequence numbers counted via the state of the counters, each request uniquely identified via one of the sequence numbers; calling a first kernel interface with a first state of the counters to wait for the lock for a particular one of the requests, the counters having the first state when the first kernel interface was called, the particular request stored with a particular one of the sequence numbers, the first state including the particular sequence number, wherein the first kernel interface returns when the lock is granted, wherein the counters have a second state when the lock is granted, the second state including a current sequence number, wherein the sequence numbers stored with the requests include consecutive sequence numbers less than the current sequence number; updating the counters atomically based on the second state of the counters returned from the first kernel interface; and performing synchronized operations subsequent to the update of the counters.
-
-
36. An apparatus comprising a processor and a memory storing executable code including a user library and an interface module, the processor coupled to the memory to execute the executable code, the processor configured to:
-
maintain one or more counters in memory via the user library to synchronize a plurality of requests for a lock, the counters having a state indicating values of the counters, the requests stored with sequence numbers to wait for the lock, the sequence numbers counted via the state of the counters, each request uniquely identified via one of the sequence numbers, the user library comprising; a lock handler module configured to call a first kernel interface with a first state to wait for the lock for a particular one of the requests, the counters having the first state when the first kernel interface was called, the particular request stored with a particular one of the sequence numbers, the first state including the particular sequence number, wherein the first kernel interface returns when the lock is granted, wherein the counters have a second state when the lock is granted, the second state including a current sequence number, wherein the sequence numbers stored with the requests include consecutive sequence numbers less than the current sequence number, and an unlock handler module configured to update the counters atomically based on the second state of the counters returned from the first kernel interface, and perform synchronized operations via the interface module subsequent to the update of the counters.
-
-
37. A computer implemented method, comprising:
-
maintaining one or more counters in memory to synchronize a plurality of lock requests, the lock requests stored with sequence numbers to wait for a lock, the sequence numbers counted via the counters, each lock request uniquely identified via one of the sequence numbers corresponding to a lock count indicating a cumulative number of the lock requests already initiated for the lock when the lock request is received in a wait queue; in response to receiving an unlock request to release the lock, the unlock request including a current lock count of the counters when the unlock request is received, comparing the current lock count with the sequence numbers to determine whether to expect additional lock requests for the lock, wherein no additional lock requests for the lock is expected if the sequence numbers stored with the requests include consecutive sequence numbers less than the current lock count; selecting one or more of the lock requests from the wait queue to grant the lock if no additional lock requests for the lock is expected; and performing synchronized operations for the selected lock requests. - View Dependent Claims (38, 39, 40, 47, 60)
-
-
41. A computer implemented method, comprising
maintaining one or more counters in memory to synchronize a plurality of lock requests, each lock request being associated with a lock count indicating a cumulative number of the lock requests initiated for a lock when the lock request is received in a wait queue; -
in response to receiving an unlock request to release the lock, comparing a state of the counters with the unlock request to determine whether to expect additional lock requests; selecting one or more of the lock requests from the wait queue to grant the lock if no additional lock requests is expected; and performing synchronized operations for the selected lock requests, wherein the counters include one or more sequence counters including a target sequence counter for identifying the additional lock requests expected, wherein the counters include a wait counter indicating a number of the additional lock requests expected, and wherein the state includes a target count and a wait count corresponding to the target sequence counter and the wait counter, and wherein the maintenance comprises; in response to receiving a lock request including a lock count, determining if the lock request is one of the additional requests expected; and inserting the lock request to the wait queue if the lock request is not one of the additional requests expected. - View Dependent Claims (42, 43, 44, 45, 46)
-
-
48. A computer implemented method, comprising:
-
maintaining one or more counters in memory to synchronize a plurality of lock requests, each lock request being associated with a lock count indicating a cumulative number of the lock requests initiated for a lock when the lock request is received in a wait queue; in response to receiving an unlock request to release the lock, comparing a state of the counters with the unlock request to determine whether to expect additional lock requests; selecting one or more of the lock requests from the wait queue to grant the lock if no additional lock requests is expected; performing synchronized operations for the selected lock requests, wherein the counters include one or more sequence counters including a target sequence counter for identifying the additional lock requests expected, wherein the counters include a wait counter indicating a number of the additional lock requests expected, and wherein the state includes a target count and a wait count corresponding to the target sequence counter and the wait counter, wherein each lock request in the wait queue is associated with a sequence number corresponding to the lock count of the lock request, the sequence number indicating a consecutive order within the wait queue; in response to receiving an unlock request to release the lock, determining whether the unlock request is a spurious request; and determining the number of the additional lock requests expected if the unlock request is not a spurious request. - View Dependent Claims (49, 50, 51, 52, 57, 58, 59)
-
-
53. The method of 52, further comprising:
updating the counters according to the unlock request and the number of the additional lock requests expected. - View Dependent Claims (54, 55, 56)
-
61. A machine-readable non-transitory storage medium having instructions, when executed by a machine, cause the machine to perform a method, the method comprising:
-
maintaining one or more counters in memory to synchronize a plurality of lock requests, the lock requests stored with sequence numbers to wait for the lock, the sequence numbers counted via the counters, each lock request uniquely identified via one of the sequence numbers corresponding to a lock count indicating a cumulative number of the lock requests already initiated for a lock when the lock request is received in a wait queue; in response to receiving an unlock request to release the lock, the unlock request including a current lock count of the counters when the unlock request is received, comparing the current lock count with the sequence numbers to determine whether to expect additional lock requests for the lock, wherein no additional lock requests for the lock is expected if the sequence numbers stored with the requests include consecutive sequence numbers less than the current lock count; selecting one or more of the lock requests from the wait queue to grant the lock if no additional lock requests for the lock is expected; and performing synchronized operations for the selected lock requests.
-
-
62. An apparatus comprising a processor and a memory storing executable code including a kernel library and an interface module, the processor coupled to the memory to execute the executable code, the processor configured to:
-
store one or more lock requests in a wait queue, the lock requests stored with sequence numbers counted via the counters, each lock request uniquely identified via one of the sequence numbers corresponding to a lock count indicating a cumulative number of the lock requests already initiated for a lock wherein the lock request is received in the wait queue; maintain one or more counters in memory via the kernel library to synchronize the lock requests, wherein the sequence numbers correspond to different lock counts counted via the counters; in response to receiving an unlock request to release the lock, the unlock request including a current lock count of the counters when the unlock request is received, compare the current lock count with the sequence numbers via the kernel library to determine whether to expect additional lock requests for the lock, wherein no additional lock requests for the lock is expected if the sequence numbers stored with the requests include consecutive sequence numbers less than the current lock count; select one or more of the lock requests from the wait queue via the kernel library to grant the lock if no additional lock requests for the lock is expected; and perform synchronized operations via the interface module subsequent to the update of the counters.
-
-
63. A computer implemented method, comprising:
-
counting up a lock counter in memory atomically to wait for a lock for a particular task to synchronize operations among a plurality of tasks including the particular task, the tasks stored with sequence numbers to wait for the lock, the sequence numbers counted via the lock counter, each task uniquely identified via one of the sequence numbers, the particular task stored with a particular one of the sequence numbers, wherein the lock counter is counted up to a particular value corresponding to the particular sequence number; when the lock is granted for the particular task, performing the synchronized operations for at least one of the plurality of tasks, wherein the lock counter has a current value when the lock is granted, and wherein the sequence numbers stored with the tasks include consecutive sequence numbers less than the current value; and counting up an unlock counter in the memory atomically subsequent to the synchronized operations. - View Dependent Claims (64, 65, 66, 67, 68, 69, 70)
-
Specification