# US 11,119,831 B2 · Systems and methods for interrupting latency optimized two-phase spinlock

> Agents: this data is available as JSON from the patentgrep API and MCP server — see https://patentgrep.com/llms.txt

- Number: US 11,119,831 B2
- Document ID: US11119831B2
- Status: Granted
- Kind: B2
- Application number: 16/739,445
- Filed: 2020-01-10
- Published: 2021-07-15
- Granted: 2021-09-14
- Earliest claimed: 2020-01-10
- Assignees: Wind River Systems, Inc.
- Applicants: Wind River Systems, Inc.
- Inventors: Kenneth Jonsson; Markus Carlstedt
- Web page: https://patentgrep.com/patent/US11119831B2

## CPC

- G06F 9/52: Program synchronisation; Mutual exclusion, e.g. by means of semaphores
- G06F 9/526: {Mutual exclusion algorithms}
- G06F 9/4831: {with variable priority}
- G06F 9/4887: {involving deadlines, e.g. rate based, periodic}
- G06F 9/5038: {considering the execution order of a plurality of tasks, e.g. taking priority or time dependency constraints into consideration (scheduling strategies G06F9/4881 and subgroups)}
- G06F 9/505: {considering the load}
- G06F 2209/522: Manager
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)

## Abstract

Described is a two-phase spinlock that controls access to a resource from a plurality of threads. The two-phase spinlock receives requests from threads to acquire the resource, places the threads in a first queue associated with a first phase of the two-phase spinlock, determines whether at least one of a predetermined number of slots in a second phase of the two-phase spinlock is available and when the slots are unavailable, processes an interrupt served by a select one of the threads based on a number of attempts by the selected thread to enter the second phase.

## Claims

### Claim 1

A method, comprising:
at a two-phase spinlock that controls access to a resource from a plurality of threads:
receiving requests from threads to acquire the resource;
placing the threads in a first queue associated with a first phase of the two-phase spinlock, wherein the placing the threads in the first queue is based on an atomic fetch-and-add operation;
determining whether at least one of a predetermined number of slots in a second phase of the two-phase spinlock is available; and
when the slots are unavailable, processing an interrupt served by a select one of the threads based on a number of attempts by the selected thread to enter the second phase.

### Claim 2 (depends on 1)

The method of claim 1, wherein the fetch-and-add operation comprises: assigning a respective ticket to each of the threads based on a chronological priority order.

### Claim 3 (depends on 1)

The method of claim 1, further comprising:
determining whether a first counter tracking a first number corresponding to a set of attempts to enter the second phase by a select one of the threads has been exhausted.

### Claim 4 (depends on 2)

The method of claim 2, further comprising:
when the at least one of the predetermined number of slots is available, selecting one of the threads in the first queue to enter the second phase based on the chronological priority order.

### Claim 5 (depends on 3)

The method of claim 3, further comprising:
when the first counter has been exhausted, preventing the interrupt from being served and remaining in the first queue.

### Claim 6 (depends on 3)

The method of claim 3, further comprising:
when the first counter indicates at least one first opportunity for the set of attempts, determining whether a second counter tracking a second number corresponding to each attempt to enter the second phase by the select thread.

### Claim 7 (depends on 6)

The method of claim 6, further comprising:
when the second counter indicates at least one second opportunity for the attempts, decrementing the second counter after the select thread performs the attempt.

### Claim 8 (depends on 6)

The method of claim 6, further comprising:
when the second counter has been exhausted, receiving the interrupt served by the selected thread; and
decrementing the first counter.

### Claim 9 (depends on 8)

The method of claim 8, further comprising:
receiving a further request from the selected thread; and
placing the selected thread in the first queue.

### Claim 10

A method, comprising:
at a two-phase spinlock that controls access to a resource from a plurality of threads, the two-phase spinlock including a first phase including a plurality of first threads:
determining whether a lock to access the resource is available;
when the lock is available, selecting from a plurality of second threads in a second phase of the two-phase spinlock to acquire the lock;
determining an age of the selected second thread;
when the age is not the oldest among the second threads in the second phase, preventing any of the first threads from entering the second phase; and
when the age is the oldest among the second threads in the second phase, selecting an oldest first thread among the first threads to enter the second phase.

### Claim 11 (depends on 10)

The method of claim 10, wherein the determining whether the lock is available is based on a flag being set that indicates an availability of the lock.

### Claim 12 (depends on 10)

The method of claim 10, further comprising:
when the age is not the oldest among the second threads in the second phase and when the lock is available after the selected second thread releases the lock, selecting from the remaining second threads in the second phase to acquire the lock.

### Claim 13 (depends on 10)

The method of claim 10, wherein the selected second thread acquiring the lock is based on an atomic test-and-set operation in which the second threads compete for the lock.

### Claim 14 (depends on 10)

The method of claim 10, wherein the second threads are prevented from serving an interrupt.

### Claim 15

A method, comprising:
at a two-phase spinlock that controls access to a resource from a plurality of threads:
receiving requests from threads to acquire the resource;
placing the threads in a first queue as first threads associated with a first phase of the two-phase spinlock;
determining whether at least one of a predetermined number of slots in a second phase of the two-phase spinlock is available;
when the slots are unavailable, processing an interrupt served by one of the first threads associated with the first phase based on a number of attempts by the one of the first threads to enter the second phase;
when the at least one of the slots is available, selecting one of the first threads to enter the second phase;
determining whether a lock to access the resource is available;
when the lock is available, selecting from a plurality of second threads in the second phase to acquire the lock;
determining an age of the selected second thread;
when the age is not the oldest among the second threads in the second phase, preventing any of the first threads from entering the second phase; and
when the age is the oldest among the second threads in the second phase, selecting an oldest first thread among the first threads to enter the second phase.

### Claim 16 (depends on 15)

The method of claim 15, wherein the selected first thread enters the second phase after the selected second thread has acquired the lock.

### Claim 17 (depends on 15)

The method of claim 15, wherein each of the threads are served within a maximum time duration.

### Claim 18 (depends on 15)

The method of claim 15, wherein the maximum time duration is based on a chronological entry of one of the threads in the first queue, a maximum number of second threads configured to be in the second phase, and a number of the threads having a lower chronological entry.
