How to transition ION to DMA-BUF heaps

目录

DMA-BUF

ION

Call flow

DMA-BUF heaps

Differences between ION and DMA-BUF heaps

Why replace ION with DMA-BUF heaps

Reference

相关代码

DMA-BUF heaps To Replace ION

How to in Kernel Space

How to in User Space

Ueventd

sepolicy

Transition Example

Transition Example(一)

Transition Example(二)

Transition Example(三)

Transition Example(四)

Transition Example(五)

Transition Example(六)

DMA-BUF heaps in 8450

Qcom heaps and sepolicy item

Qcom gralloc

Qcom camera driver

DMA-BUF heaps调用堆栈分析

CSLAlloc  ->...-> dma_heap_buffer_alloc

Gralloc -> ... -> dma_heap_buffer_alloc

小结


DMA-BUF

如这张图所示,这是一条简单的 pipeline 图。

Sensor 出一帧,送给高通的 IFE,然后在送给IPE,IPE会分为三路:

第一路:TARGET_BUFFER 有可能被CPU访问,或者可能被GPU访问。如果这个buffer 是要放回给应用层做显示用的,那么这个buffer 可能会被display 访问。

第二路:送给ASD node 这路,取决于ASD算法是CPU实现的,还是GPU实现的。

第三路:如果FDManager 是高通硬件做的,那么可能会被高通的 cvp 访问,如果是软件算法,那么会被cpu访问。所以,IPE输出的一个 buffer 可能被 CPU,GPU,display,cvp 所共享。

DMA-BUF主要解决CPU和各种外设之间的buffer共享。其次, DMA-BUF 设计之初就是为满足那些大内存访问需求的硬件而设计的,如GPU/DPU/NPU。在这种场景下,如果使用CPU直接去访memory,那么性能会大大降低。
 

ION

• ION是基于DMA-BUF的框架实现的一种内存分配器

Call flow

DMA-BUF heaps

  1. DMA-BUF heaps也是一种基于DMA-BUF框架实现的内存分配器。
  2. DMA-BUF heaps已经upstream到kernel的mainline,而ION待在
    android的staging中好多年,到现在都没有mainline。
  3. 最新的kernel中还upstream了system和cma两个dma-buf heap的
    实现。system_uncached heap正在走upstream的流程

Differences between ION and DMA-BUF heaps

Why replace ION with DMA-BUF heaps

  1. ION太复杂,很难upstream,⽽DMA-BUF heaps结构清晰,实现简单,已经 mainline,由kernel upstream进⾏维护, ABI兼容性可以得到保障。
  2. DMA-BUF heaps中的每个heap都会对应⼀个设备节点,⽅便通过sepolicy进⾏权限控制。
  3. 由于ION⽀持客制化的heap id和heap flag,很难开发统⼀的测试框架。⽽DMA-BUF heap向上接⼝统⼀,不⽀持heap flag,⽅便对heap框架和mainline的heap开发统⼀的测试程序。

Reference

相关代码

DMA-BUF: common/driver/dma-buf/
ION: common/driver/android/staging/ion/
DMA-BUF:heaps: common/driver/dma-buf/dma-heap.c
                     common/driver/dma-buf/heaps/

DMA-BUF heaps To Replace ION

How to in Kernel Space

How to in User Space

Ueventd

sepolicy

Transition Example

如下举例说明如何将一个ion heap(Heap ID: MY_HEAP, Heap Flag: ION_FLAG_MY_FLAG)转成DMA-BUF heap。并且以ClientA为例说明,如何调用libdmabufheap的接口从这个heap中分配buffer。

Transition Example(一)

Transition Example(二)

Transition Example(三)

Transition Example(四)

Transition Example(五)

Transition Example(六)

DMA-BUF heaps in 8450

  1. Qcom heaps and sepolicy item
  2. Qcom gralloc implementation
  3. Qcom camera’s driver

Qcom heaps and sepolicy item

Qcom gralloc

已经完成从libion到libdmabufheap的迁移
path: hardware/qcom/display/gralloc

Qcom camera driver

已经完成从ion到dma-buf heaps的迁移
path: camera-kernel/drivers/cam_req_mgr/cam_mem_mgr.c

DMA-BUF heaps调用堆栈分析

1.在kernel源代码中 include/trace/events/dma_buf.h 加上如下patch:

2.在kernel源代码中 drivers/dma-buf/dma-heap.c 加上如下patch:

CSLAlloc  ->...-> dma_heap_buffer_alloc

Gralloc -> ... -> dma_heap_buffer_alloc

小结

  1. 可以看到在安卓13之后,无论是 CSLAlloc接口申请的 imagebuffer,还是 Gralloc接口申请的 imagebuffer ,底层都是调用 dma_buf heaps,进而去调用 dma_buf 去分配内存的。

  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

repinkply

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值