DPDK 22.11.6
Data Structures | Macros | Functions
rte_seqcount.h File Reference
#include <stdbool.h>
#include <stdint.h>
#include <rte_atomic.h>
#include <rte_branch_prediction.h>
#include <rte_compat.h>

Go to the source code of this file.

Data Structures

struct  rte_seqcount_t
 

Macros

#define RTE_SEQCOUNT_INITIALIZER   { .sn = 0 }
 

Functions

static __rte_experimental void rte_seqcount_init (rte_seqcount_t *seqcount)
 
static __rte_experimental uint32_t rte_seqcount_read_begin (const rte_seqcount_t *seqcount)
 
static __rte_experimental bool rte_seqcount_read_retry (const rte_seqcount_t *seqcount, uint32_t begin_sn)
 
static __rte_experimental void rte_seqcount_write_begin (rte_seqcount_t *seqcount)
 
static __rte_experimental void rte_seqcount_write_end (rte_seqcount_t *seqcount)
 

Detailed Description

RTE Seqcount

The sequence counter synchronizes a single writer with multiple, parallel readers. It is used as the basis for the RTE sequence lock.

See also
rte_seqlock.h

Definition in file rte_seqcount.h.

Macro Definition Documentation

◆ RTE_SEQCOUNT_INITIALIZER

#define RTE_SEQCOUNT_INITIALIZER   { .sn = 0 }

A static seqcount initializer.

Definition at line 40 of file rte_seqcount.h.

Function Documentation

◆ rte_seqcount_init()

static __rte_experimental void rte_seqcount_init ( rte_seqcount_t seqcount)
inlinestatic
Warning
EXPERIMENTAL: this API may change without prior notice.

Initialize the sequence counter.

Parameters
seqcountA pointer to the sequence counter.

Definition at line 53 of file rte_seqcount.h.

◆ rte_seqcount_read_begin()

static __rte_experimental uint32_t rte_seqcount_read_begin ( const rte_seqcount_t seqcount)
inlinestatic
Warning
EXPERIMENTAL: this API may change without prior notice.

Begin a read-side critical section.

A call to this function marks the beginning of a read-side critical section, for seqcount.

rte_seqcount_read_begin() returns a sequence number, which is later used in rte_seqcount_read_retry() to check if the protected data underwent any modifications during the read transaction.

After (in program order) rte_seqcount_read_begin() has been called, the calling thread reads the protected data, for later use. The protected data read must be copied (either in pristine form, or in the form of some derivative), since the caller may only read the data from within the read-side critical section (i.e., after rte_seqcount_read_begin() and before rte_seqcount_read_retry()), but must not act upon the retrieved data while in the critical section, since it does not yet know if it is consistent.

The protected data may be read using atomic and/or non-atomic operations.

After (in program order) all required data loads have been performed, rte_seqcount_read_retry() should be called, marking the end of the read-side critical section.

If rte_seqcount_read_retry() returns true, the just-read data is inconsistent and should be discarded. The caller has the option to either restart the whole procedure right away (i.e., calling rte_seqcount_read_begin() again), or do the same at some later time.

If rte_seqcount_read_retry() returns false, the data was read atomically and the copied data is consistent.

Parameters
seqcountA pointer to the sequence counter.
Returns
The seqcount sequence number for this critical section, to later be passed to rte_seqcount_read_retry().
See also
rte_seqcount_read_retry()

Definition at line 106 of file rte_seqcount.h.

◆ rte_seqcount_read_retry()

static __rte_experimental bool rte_seqcount_read_retry ( const rte_seqcount_t seqcount,
uint32_t  begin_sn 
)
inlinestatic
Warning
EXPERIMENTAL: this API may change without prior notice.

End a read-side critical section.

A call to this function marks the end of a read-side critical section, for seqcount. The application must supply the sequence number produced by the corresponding rte_seqcount_read_begin() call.

After this function has been called, the caller should not access the protected data.

In case rte_seqcount_read_retry() returns true, the just-read data was modified as it was being read and may be inconsistent, and thus should be discarded.

In case this function returns false, the data is consistent and the set of atomic and non-atomic load operations performed between rte_seqcount_read_begin() and rte_seqcount_read_retry() were atomic, as a whole.

Parameters
seqcountA pointer to the sequence counter.
begin_snThe sequence number returned by rte_seqcount_read_begin().
Returns
true or false, if the just-read seqcount-protected data was inconsistent or consistent, respectively, at the time it was read.
See also
rte_seqcount_read_begin()

Definition at line 151 of file rte_seqcount.h.

◆ rte_seqcount_write_begin()

static __rte_experimental void rte_seqcount_write_begin ( rte_seqcount_t seqcount)
inlinestatic
Warning
EXPERIMENTAL: this API may change without prior notice.

Begin a write-side critical section.

A call to this function marks the beginning of a write-side critical section, after which the caller may go on to modify (both read and write) the protected data, in an atomic or non-atomic manner.

After the necessary updates have been performed, the application calls rte_seqcount_write_end().

Multiple, parallel writers must use some external serialization.

This function is not preemption-safe in the sense that preemption of the calling thread may block reader progress until the writer thread is rescheduled.

Parameters
seqcountA pointer to the sequence counter.
See also
rte_seqcount_write_end()

Definition at line 201 of file rte_seqcount.h.

◆ rte_seqcount_write_end()

static __rte_experimental void rte_seqcount_write_end ( rte_seqcount_t seqcount)
inlinestatic
Warning
EXPERIMENTAL: this API may change without prior notice.

End a write-side critical section.

A call to this function marks the end of the write-side critical section, for seqcount. After this call has been made, the protected data may no longer be modified.

Parameters
seqcountA pointer to the sequence counter.
See also
rte_seqcount_write_begin()

Definition at line 232 of file rte_seqcount.h.