minigbm: mediatek: Pass ALLOC_SINGLE_PAGES for linear scanout buffer

To improve the efficiency of allocating high-resolution video decoder,
pass a flag to notify the kernel DMA framework to allocate linear
scanout buffers with single pages, so the allocation is more likely to
success when the available large chunk memory is constrained.

BUG=b:352229429
TEST=emerge-geralt libdrm minigbm

Cq-Depend: chromium:5689126
Change-Id: I21f2745cb5bdb7eaf7f50482c4c091791d13bbcc
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/5706152
Reviewed-by: Chen-Yu Tsai <wenst@chromium.org>
Tested-by: Fei Shao <fshao@chromium.org>
Commit-Queue: Fei Shao <fshao@chromium.org>
This commit is contained in:
Fei Shao 2024-07-12 18:31:14 +08:00 committed by Chromeos LUCI
parent c06a7dbe71
commit cd5aef63a7

View file

@ -210,6 +210,7 @@ static int mediatek_bo_create_with_modifiers(struct bo *bo, uint32_t width, uint
const bool is_camera_write = bo->meta.use_flags & BO_USE_CAMERA_WRITE;
const bool is_hw_video_encoder = bo->meta.use_flags & BO_USE_HW_VIDEO_ENCODER;
const bool is_linear = bo->meta.use_flags & BO_USE_LINEAR;
const bool is_protected = bo->meta.use_flags & BO_USE_PROTECTED;
const bool is_scanout = bo->meta.use_flags & BO_USE_SCANOUT;
/*
@ -346,6 +347,22 @@ static int mediatek_bo_create_with_modifiers(struct bo *bo, uint32_t width, uint
gem_create.flags |= DRM_MTK_GEM_CREATE_FLAG_RESTRICTED;
}
/*
* For linear scanout buffers, the read/write pattern is usually linear i.e. each address is
* accessed sequentially, and there are fewer chances that an address will be repeatedly
* accessed.
* This behavior leads to less TLB dependency and cache misses i.e. no need to translate the
* same virtual address to a physical address multiple times.
*
* With that premise, it's safe to allow the DMA framework to fulfill such allocation
* requests with non-continuous smaller chunks of memory (e.g., 4KiB single pages) which
* are generally easier to allocate compared to large continuous chunks of memory, improving
* memory allocation efficiency and reduce the risk of allocation failures, especially when
* available memory budget is low or on memory-constrained devices.
*/
if (is_linear && is_scanout)
gem_create.flags |= DRM_MTK_GEM_CREATE_FLAG_ALLOC_SINGLE_PAGES;
gem_create.size = bo->meta.total_size;
ret = drmIoctl(bo->drv->fd, DRM_IOCTL_MTK_GEM_CREATE, &gem_create);