Hermes 0.7.0
Linux game streaming host
Loading...
Searching...
No Matches
platf::dmabuf::mapping_cache_t Class Reference

#include <src/platform/linux/dmabuf_mapping.h>

Public Member Functions

 mapping_cache_t (std::size_t capacity=4)
 mapping_cache_t (const mapping_cache_t &)=delete
mapping_cache_t & operator= (const mapping_cache_t &)=delete
const std::uint8_t * map (int fd, std::size_t required)
void clear ()
std::size_t size () const
std::uint64_t hits () const
std::uint64_t misses () const

Detailed Description

Read-only mappings of the DMA-BUFs a producer rotates through, kept across frames.

Mapping a scanout buffer for every frame costs more than copying it. A drm_gem_shmem export is mapped VM_PFNMAP and faults in one 4 KiB page at a time: about 5 ms of a 6.5 ms 1440p CPU capture, 3600 faults per frame. A compositor rotates through two or three buffers, and Hermes-KMS hands back the same dma_buf for the same framebuffer, so a handful of cached mappings leaves every frame after the first free of faults.

A mapping holds its own reference to the dma_buf, so the inode keying an entry cannot be reused by another buffer while the entry exists. The reference also keeps a buffer the compositor has released alive until the entry is evicted, which is why the cache is small and cleared on reinit.

Definition at line 36 of file dmabuf_mapping.h.

Constructor & Destructor Documentation

◆ mapping_cache_t()

platf::dmabuf::mapping_cache_t::mapping_cache_t ( std::size_t capacity = 4)
inlineexplicit

Definition at line 38 of file dmabuf_mapping.h.

◆ ~mapping_cache_t()

platf::dmabuf::mapping_cache_t::~mapping_cache_t ( )
inline

Definition at line 42 of file dmabuf_mapping.h.

Member Function Documentation

◆ clear()

void platf::dmabuf::mapping_cache_t::clear ( )
inline

Drop every mapping, releasing the buffers they kept alive.

Definition at line 94 of file dmabuf_mapping.h.

◆ hits()

std::uint64_t platf::dmabuf::mapping_cache_t::hits ( ) const
inline

Definition at line 105 of file dmabuf_mapping.h.

◆ map()

const std::uint8_t * platf::dmabuf::mapping_cache_t::map ( int fd,
std::size_t required )
inline

Map the whole DMA-BUF behind fd, or return the mapping made earlier.

Parameters
fdAny descriptor for the DMA-BUF; it is not retained.
requiredBytes from the start of the buffer the caller will read.
Returns
The mapping, or nullptr with errno set. A buffer smaller than required is refused with EINVAL instead of being mapped.

Definition at line 56 of file dmabuf_mapping.h.

◆ misses()

std::uint64_t platf::dmabuf::mapping_cache_t::misses ( ) const
inline

Definition at line 109 of file dmabuf_mapping.h.

◆ size()

std::size_t platf::dmabuf::mapping_cache_t::size ( ) const
inline

Definition at line 101 of file dmabuf_mapping.h.


The documentation for this class was generated from the following file: