# US 11,914,972 B2 · Element ordering handling in a ring buffer

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

- Number: US 11,914,972 B2
- Document ID: US11914972B2
- Status: Granted
- Kind: B2
- Application number: 17/756,580
- Filed: 2020-11-13
- Published: 2023-01-05
- Granted: 2024-02-27
- Earliest claimed: 2019-11-29
- Assignees: Arm Limited
- Applicants: Arm Limited
- Inventors: Eric Ola Harald Liljedahl; Samuel Thomas Lee
- Web page: https://patentgrep.com/patent/US11914972B2

## CPC

- G06F 5/12: Means for monitoring the fill level; Means for resolving contention, i.e. conflicts between simultaneous enqueue and dequeue operations
- G06F 9/526: {Mutual exclusion algorithms}
- G06F 5/085: {in which the data is recirculated}
- G06F 9/30021: {Compare instructions, e.g. Greater-Than, Equal-To, MINMAX}
- G06F 9/3004: {to perform operations on memory}
- G06F 9/30043: {LOAD or STORE instructions; Clear instruction}
- G06F 9/30094: {Condition code generation, e.g. Carry, Zero flag}
- G06F 9/3856: {Reordering of instructions, e.g. using queues or age tags}
- G06F 9/544: {Buffers; Shared memory; Pipes}
- G06F 2209/521: Atomic
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)

## Abstract

Data processing apparatuses, methods of data processing, complementary instructions and programs related to ring buffer administration are disclosed. An enqueuing operation performs an atomic compare-and-swap oper-ation to store a first processed data item indication to an enqueuing-target slot in the ring buffer contingent on an in-order marker not being present there and, when successful, determines that a ready-to-dequeue condition is true for the first processed data item indication. A dequeuing operation, when the ready-to-de-queue condition for a dequeuing-target slot is true, comprises writing a null data item to the dequeuing-target slot and, when dequeuing in-order, further comprises, dependent on whether a next contiguous slot has null content, determining a retirement condition and, when the retirement condition is true, performing a retirement process on the next contiguous slot comprising making the next con-tiguous slot available to a subsequent enqueuing operation. Further subsequent slots may also be retired.

## Claims

### Claim 1

A data processing apparatus comprising:
ring buffer storage circuitry to store components of a ring buffer comprising multiple slots to hold queued data items; and
data processing circuitry to perform an enqueuing operation to add one or more processed data item indications to the ring buffer and to perform a dequeuing operation to remove one or more processed data item indications from the ring buffer,
wherein the enqueuing operation comprises performing an atomic compare-and-swap operation to store a first processed data item indication to an enqueuing-target slot in the ring buffer contingent on an in-order marker not being present in the enqueuing-target slot and, when the in-order marker is present in the enqueuing-target slot, determining a ready-to-dequeue condition to be true for the first processed data item indication, and
wherein the dequeuing operation comprises, when the ready-to-dequeue condition for a dequeuing-target slot is true:
writing a null data item to the dequeuing-target slot; and
when removing the one or more processed data item indications from the ring buffer in-order, the dequeuing operation further comprises:
a) dependent on whether a next contiguous slot has null content, determining a retirement condition and, when the retirement condition is true, performing a retirement process on the next contiguous slot comprising making the next contiguous slot available to a subsequent enqueuing operation;
b) repeating step a) through subsequent slots until for a reached slot the retirement condition is not true;
c) performing an atomic compare-and-swap operation to store the in-order marker to the reached slot contingent on content of the reached slot; and
d) when the atomic compare-and-swap operation to store the in-order marker to the reached slot fails, performing the retirement process on the reached slot and returning to step a), wherein the next contiguous slot is now treated as a slot which contiguously follows the reached slot.

### Claim 2 (depends on 1)

The data processing apparatus as claimed in claim 1, wherein the ring buffer is arranged as a reorder buffer, wherein the data processing circuitry is arranged to perform the enqueuing operation to add the one or more processed data item indications to the ring buffer when the processing of the data items is complete, and not to perform the dequeuing operation to remove the one or more processed data item indications from the ring buffer unless the one or more processed data item indications are in-order.

### Claim 3 (depends on 1)

The data processing apparatus as claimed in claim 1, wherein the data processing circuitry is responsive to the ready-to-dequeue condition being true for the first processed data item indication to commence the dequeuing operation with the dequeuing-target slot being where the first processed data item indication is to be found.

### Claim 4 (depends on 2)

The data processing apparatus as claimed in claim 2, wherein in the dequeuing operation the retirement condition is determined to be true when the next contiguous slot does not have null content,
and wherein making the next contiguous slot available to the subsequent enqueuing operation comprises retiring the next contiguous slot and writing null content to the next contiguous slot.

### Claim 5 (depends on 2)

The data processing apparatus as claimed in claim 2, wherein in the dequeuing operation the performing the atomic compare-and-swap operation to store the in-order marker to the reached slot is contingent on the reached slot having null content.

### Claim 6 (depends on 1)

The data processing apparatus as claimed in claim 1, wherein the ring buffer is arranged as a FIFO queue, and wherein the data processing circuitry is arranged to support multiple concurrent enqueuing processes to perform enqueuing operations and to support multiple concurrent dequeuing processes to perform dequeuing operations.

### Claim 7 (depends on 6)

The data processing apparatus as claimed in claim 6, wherein the data processing circuitry is arranged to allocate a unique set of enqueuing slots to each of the multiple concurrent enqueuing processes and to allocate a unique set of dequeuing slots to each of the multiple concurrent dequeuing processes.

### Claim 8 (depends on 7)

The data processing apparatus as claimed in claim 7, wherein the enqueuing-target slot is a first slot of the unique set of enqueuing slots and the enqueuing operation comprises writing processed data item indications to the unique set of enqueuing slots other than enqueuing-target slot before performing the atomic compare-and-swap operation to store the first processed data item indication to the enqueuing-target slot.

### Claim 9 (depends on 8)

The data processing apparatus as claimed in claim 8, wherein, when the in-order marker is present in the enqueuing-target slot and the ready-to-dequeue condition is true for the first processed data item indication, the enqueuing operation further comprises a further step of writing the first processed data item indication to the enqueuing-target slot.

### Claim 10 (depends on 7)

The data processing apparatus as claimed in claim 7, wherein the dequeuing process further comprises:
reading the content of the unique set of dequeuing slots;
writing the null data item to the unique set of dequeuing slots other than the dequeuing-target slot; and
performing an atomic compare-and-swap operation to store the null data item to the dequeuing-target slot in the ring buffer contingent on an in-order marker not being present in the dequeuing-target slot and,
when the in-order marker is present in the dequeuing-target slot, determining that the content of the unique set of dequeuing slots is being removed from the ring buffer in-order, and
when the in-order marker is not present in the dequeuing-target slot, determining that the content of the unique set of dequeuing slots is being removed from the ring buffer out-of-order and concluding the dequeuing process.

### Claim 11 (depends on 10)

The data processing apparatus as claimed in claim 10, wherein, when removing the content of the unique set of dequeuing slots in-order, in the dequeuing operation the retirement condition is determined to be true when the next contiguous slot has null content,
and wherein making the next contiguous slot available to the subsequent enqueuing operation comprising retiring a set of next contiguous slots which have null content.

### Claim 12 (depends on 7)

The data processing apparatus as claimed in claim 7, wherein in the dequeuing operation the performing the atomic compare-and-swap operation to store the in-order marker to the reached slot is contingent on the reached slot not having data null content.

### Claim 13 (depends on 1)

The data processing apparatus as claimed in claim 1, wherein the data processing circuitry is arranged to perform an initialisation operation to store the in-order marker to a defined first slot of the ring buffer and to store null data content to all of the multiple slots of the ring buffer.

### Claim 14 (depends on 1)

The data processing apparatus as claimed in claim 1, wherein the in-order marker comprises an enqueue in-order marker and a dequeue in-order marker.

### Claim 15 (depends on 1)

The data processing apparatus as claimed in claim 1, wherein the null data content is a null pointer.

### Claim 16 (depends on 1)

The data processing apparatus as claimed in claim 1, wherein the processed data item indications are memory aligned such that at least one lower order bit of the processed data item indications is functionally irrelevant to the processed data item indications, and the in-order marker is represented by the at least one lower order bit.

### Claim 17 (depends on 1)

The data processing apparatus as claimed in claim 1, further comprising a cache associated with the data processing circuitry, wherein the data processing circuitry is arranged to perform a swizzle operation on a set of lower order bits of sequence numbers used to enumerate the multiple slots of the ring buffer to generate the memory addresses of the multiple slots, wherein a size of the set of lower order bits is selected in dependence on a cache line size of the cache.

### Claim 18 (depends on 1)

The data processing apparatus as claimed in claim 1, wherein the dequeuing operation further comprises, when the atomic compare-and-swap operation to store the in-order marker to the reached slot succeeds, incrementing a head pointer indicative of a current head slot of the multiple slots of the ring buffer by a total number of slots retired in the dequeuing operation.

### Claim 19 (depends on 18)

The data processing apparatus as claimed in claim 18, wherein incrementing the head pointer is an atomic compare-and-swap-max operation, wherein success of the atomic compare-and-swap-max operation is contingent on a write-attempt value of the head pointer being greater than a current value of the head pointer.

### Claim 20 (depends on 18)

The data processing apparatus as claimed in claim 18, wherein incrementing the head pointer is an atomic sequence number compare-and-swap-max operation, wherein success of the atomic sequence number compare-and-swap-max operation is contingent on a write-attempt value of the head pointer being greater than a current value of the head pointer wherein a wrap-around enumeration of the multiple slots of the ring buffer wraps around from a numerically largest sequence number to a numerically smallest sequence number, and wherein the atomic sequence number compare-and-swap-max operation is arranged to determine that the write-attempt value is greater than the current value when the write-attempt value is ahead of the current value in the wrap-around enumeration by less than half of the numerically largest sequence number.

### Claim 21

A method of data processing comprising:
storing components of a ring buffer comprising multiple slots to hold queued data items;
performing an enqueuing operation to add one or more processed data item indications to the ring buffer;
performing a dequeuing operation to remove one or more processed data item indications from the ring buffer,
wherein the enqueuing operation comprises performing an atomic compare-and-swap operation to store a first processed data item indication to an enqueuing-target slot in the ring buffer contingent on an in-order marker not being present in the enqueuing-target slot and, when the in-order marker is present in the enqueuing-target slot, determining a ready-to-dequeue condition to be true for the first processed data item indication, and
wherein the dequeuing operation compnses, when the ready-to-dequeue condition for a dequeuing-target slot is true:
writing a null data item to the dequeuing-target slot; and
when removing the one or more processed data item indications from the ring buffer in-order, the dequeuing operation further comprises:
a) dependent on whether a next contiguous slot has null content, determining a retirement condition and, when the retirement condition is true, performing a retirement process on the next contiguous slot comprising making the next contiguous slot available to a subsequent enqueuing operation;
b) repeating step a) through subsequent slots until for a reached slot the retirement condition is not true;
c) performing an atomic compare-and-swap operation to store the in-order marker to the reached slot contingent on content of the reached slot; and
d) when the atomic compare-and-swap operation to store the in-order marker to the reached slot fails, performing the retirement process on the reached slot and returning to step a), wherein the next contiguous slot is now treated as a slot which contiguously follows the reached slot.
