Skip to content

vitalyvch/rng_buf

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
src
 
 
 
 
 
 
 
 

rng_buf

This is an optimized Ring Buffer implementation using the POSIX shared memory trick.

This implementation is much more convenient in use then classical implementations, also there is some benefit in CPU usage.

A circular-buffer implementation is optimized by mapping the underlying buffer to two contiguous regions of virtual memory. (Naturally, the underlying buffer‘s length must then equal some multiple of the system’s page size.) Reading from and writing to the circular buffer may then be carried out with greater efficiency by means of direct memory access; those accesses which fall beyond the end of the first virtual-memory region will automatically wrap around to the beginning of the underlying buffer. When the read offset is advanced into the second virtual-memory region, both offsets—read and write—are decremented by the length of the underlying buffer.

Limitations

This implementation is HW-dependent and was tested for x86_64. You will observe funny effects when HW uses VIVT caches.

If you would like to use it on different HW, you should have done some testing in advance. src/rng_buf_tests could be a start point for it.

Requirements

  1. Support for POSIX shared memory
  2. Proper HW (cache-controller)

Build

 $ cmake . && make

Example

Use src/rng_buf_tests.cc as an example.

About

An optimized Ring Buffer implementation based on the POSIX shared memory trick

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages