# US 2023/0004346 A1 · 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 2023/0004346 A1
- Document ID: US20230004346A1
- Status: Published application
- Kind: A1
- Application number: 17/756,580
- Filed: 2020-11-13
- Published: 2023-01-05
- 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/US20230004346A1

## 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 at position 1

1-24. (canceled)

### Claim 25

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 26 (depends on 25)

The data processing apparatus as claimed in claim 25, 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 27 (depends on 25)

The data processing apparatus as claimed in claim 25, 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 28 (depends on 26)

The data processing apparatus as claimed in claim 26, 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 29 (depends on 26)

The data processing apparatus as claimed in claim 26, 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 30 (depends on 25)

The data processing apparatus as claimed in claim 25, 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 31 (depends on 30)

The data processing apparatus as claimed in claim 30, 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 32 (depends on 31)

The data processing apparatus as claimed in claim 31, 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 33 (depends on 32)

The data processing apparatus as claimed in claim 32, 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 34 (depends on 31)

The data processing apparatus as claimed in claim 31, 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 35 (depends on 34)

The data processing apparatus as claimed in claim 34, 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 36 (depends on 31)

The data processing apparatus as claimed in claim 31, 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 37 (depends on 25)

The data processing apparatus as claimed in claim 25, 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 38 (depends on 25)

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

### Claim 39 (depends on 25)

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

### Claim 40 (depends on 25)

The data processing apparatus as claimed in claim 25, 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 41 (depends on 25)

The data processing apparatus as claimed in claim 25, 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 42 (depends on 25)

The data processing apparatus as claimed in claim 25, 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 43 (depends on 42)

The data processing apparatus as claimed in claim 42, 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 44 (depends on 42)

The data processing apparatus as claimed in claim 42, 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 45

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 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 46

A data processing apparatus comprising:
instruction decoder circuitry to decode instructions and to generate control signals dependent on the instructions; and
data processing circuitry to perform data processing operations in response to the control signals,
wherein the instruction decoder circuitry is responsive to an atomic sequence number compare-and-swap-max instruction specifying a data item location and a write-attempt value to generate the control signals such that the data processing circuitry seeks to perform a write operation of the write value to the data item location, wherein success of the write operation is contingent on the write-attempt value being greater than a current value at the data item location, wherein values are treated as a wrap-around enumeration of sequence numbers which wraps around from a numerically largest sequence number to a numerically smallest sequence number, and wherein the data processing circuitry is responsive to the control signals 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 47

A method of data processing comprising:
decoding instructions and generating control signals dependent on the instructions;
performing data processing operations in response to the control signals,
wherein the decoding instructions comprises, in response to an atomic sequence number compare-and-swap-max instruction specifying a data item location and a write-attempt value:
generating the control signals such that the performing data processing seeks to perform a write operation of the write value to the data item location, wherein success of the write operation is contingent on the write-attempt value being greater than a current value at the data item location, wherein values are treated as a wrap-around enumeration of sequence numbers which wraps around from a numerically largest sequence number to a numerically smallest sequence number,
and wherein the performing data processing further comprises, in response to the control signals:
determining 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 48

A computer program for controlling a host data processing apparatus to provide an instruction execution environment comprising:
instruction decoder logic to decode instructions and to generate control signals dependent on the instructions; and
data processing logic to perform data processing operations in response to the control signals,
wherein the instruction decoder logic is responsive to an atomic sequence number compare-and-swap-max instruction specifying a data item location and a write-attempt value to generate the control signals such that the data processing logic seeks to perform a write operation of the write value to the data item location, wherein success of the write operation is contingent on the write-attempt value being greater than a current value at the data item location, wherein values are treated as a wrap-around enumeration of sequence numbers which wraps around from a numerically largest sequence number to a numerically smallest sequence number, and wherein the data processing logic is responsive to the control signals 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.
