struct amdgpu_bo {
/* Protected by tbo.reserved */
struct ttm_buffer_object tbo;
}
struct ttm_buffer_object {
struct drm_gem_object base;
...
}
/**
* struct drm_gem_object - GEM buffer object
*
* This structure defines the generic parts for GEM buffer objects, which are
* mostly around handling mmap and userspace handles.
*
* Buffer objects are often abbreviated to BO.
*/
struct drm_gem_object {
/**
* @resv:
*
* Pointer to reservation object associated with the this GEM object.
*
* Normally (@resv == &@_resv) except for imported GEM objects.
*/
struct dma_resv *resv;
/**
* @_resv:
*
* A reservation object for this GEM object.
*
* This is unused for imported GEM objects.
*/
struct dma_resv _resv;
}
/**
* struct dma_resv_list - a list of shared fences
* @rcu: for internal use
* @shared_count: table of shared fences
* @shared_max: for growing shared fence table
* @shared: shared fence table
*/
struct dma_resv_list {
struct rcu_head rcu;
u32 shared_count, shared_max;
struct dma_fence __rcu *shared[];
};
/**
* struct dma_resv - a reservation object manages fences for a buffer
* @lock: update side lock
* @seq: sequence count for managing RCU read-side synchronization
* @fence_excl: the exclusive fence, if there is one currently
* @fence: list of current shared fences
*/
struct dma_resv {
struct ww_mutex lock;
seqcount_t seq;
struct dma_fence __rcu *fence_excl;
struct dma_resv_list __rcu *fence;
};
-
dma_resv的使用场景如下:
这里使用面向对象的方式建立dma_resv <- drm_gem_object <- ttm_buffer_object <- amdgpu_bo联系. -
当访问amdgpu_bo的时候:
-
WW-mutex 负责 dma_resv对象本身的线程安全访问,Fence 负责对资源缓冲区amdgpu_bo 的操作时序同步.
-
WW-mutex管能不能进门(是否能操作 dma_resv),Fence 管 进门后该按什么顺序做事(操作 amdgpu_bo 的时序). 没有 WW-mutex, 多线程修改 dma_resv 会导致数据错乱,交叉请求锁会导致死锁;没有 Fence, 即使拿到了 dma_resv 的锁,GPU/CPU 异步操作也会因为顺序混乱导致数据错误比如 CPU 写一半,GPU 就开始读). 两者联合才实现了 DRM 中 “多线程 / 进程安全、无死锁、时序正确” 的缓冲区并发访问.
-
881

被折叠的 条评论
为什么被折叠?



