struct msm_bo {
struct fd_bo base;
uint64_t offset;
- /* to avoid excess hashtable lookups, cache the ring this bo was
- * last emitted on (since that will probably also be the next ring
- * it is emitted on)
- */
- unsigned current_submit_seqno;
uint32_t idx;
};
FD_DEFINE_CAST(fd_bo, msm_bo);
(x)->nr_ ## name ++; \
})
+#define READ_ONCE(x) (*(volatile __typeof__(x) *)&(x))
+
#endif /* MSM_PRIV_H_ */
#define INIT_SIZE 0x1000
-static pthread_mutex_t idx_lock = PTHREAD_MUTEX_INITIALIZER;
-
struct msm_submit {
struct fd_submit base;
DECLARE_ARRAY(struct drm_msm_gem_submit_bo, submit_bos);
DECLARE_ARRAY(struct fd_bo *, bos);
- unsigned seqno;
-
/* maps fd_bo to idx in bos table: */
struct hash_table *bo_table;
{
struct msm_bo *msm_bo = to_msm_bo(bo);
uint32_t idx;
- pthread_mutex_lock(&idx_lock);
- if (likely(msm_bo->current_submit_seqno == submit->seqno)) {
- idx = msm_bo->idx;
- } else {
+
+ /* NOTE: it is legal to use the same bo on different threads for
+ * different submits. But it is not legal to use the same submit
+ * from given threads.
+ */
+ idx = READ_ONCE(msm_bo->idx);
+
+ if (unlikely((idx >= submit->nr_submit_bos) ||
+ (submit->submit_bos[idx].handle != bo->handle))) {
uint32_t hash = _mesa_hash_pointer(bo);
struct hash_entry *entry;
_mesa_hash_table_insert_pre_hashed(submit->bo_table, hash, bo,
(void *)(uintptr_t)idx);
}
- msm_bo->current_submit_seqno = submit->seqno;
msm_bo->idx = idx;
}
- pthread_mutex_unlock(&idx_lock);
+
if (flags & FD_RELOC_READ)
submit->submit_bos[idx].flags |= MSM_SUBMIT_BO_READ;
if (flags & FD_RELOC_WRITE)
submit->submit_bos[idx].flags |= MSM_SUBMIT_BO_WRITE;
+
return idx;
}
{
struct msm_submit *msm_submit = calloc(1, sizeof(*msm_submit));
struct fd_submit *submit;
- static unsigned submit_cnt = 0;
- msm_submit->seqno = ++submit_cnt;
msm_submit->bo_table = _mesa_hash_table_create(NULL,
_mesa_hash_pointer, _mesa_key_pointer_equal);
msm_submit->ring_set = _mesa_set_create(NULL,
#define INIT_SIZE 0x1000
-static pthread_mutex_t idx_lock = PTHREAD_MUTEX_INITIALIZER;
-
struct msm_submit_sp {
struct fd_submit base;
DECLARE_ARRAY(struct drm_msm_gem_submit_bo, submit_bos);
DECLARE_ARRAY(struct fd_bo *, bos);
- unsigned seqno;
-
/* maps fd_bo to idx in bos table: */
struct hash_table *bo_table;
{
struct msm_bo *msm_bo = to_msm_bo(bo);
uint32_t idx;
- pthread_mutex_lock(&idx_lock);
- if (likely(msm_bo->current_submit_seqno == submit->seqno)) {
- idx = msm_bo->idx;
- } else {
+
+ /* NOTE: it is legal to use the same bo on different threads for
+ * different submits. But it is not legal to use the same submit
+ * from given threads.
+ */
+ idx = READ_ONCE(msm_bo->idx);
+
+ if (unlikely((idx >= submit->nr_submit_bos) ||
+ (submit->submit_bos[idx].handle != bo->handle))) {
uint32_t hash = _mesa_hash_pointer(bo);
struct hash_entry *entry;
_mesa_hash_table_insert_pre_hashed(submit->bo_table, hash, bo,
(void *)(uintptr_t)idx);
}
- msm_bo->current_submit_seqno = submit->seqno;
msm_bo->idx = idx;
}
- pthread_mutex_unlock(&idx_lock);
+
if (flags & FD_RELOC_READ)
submit->submit_bos[idx].flags |= MSM_SUBMIT_BO_READ;
if (flags & FD_RELOC_WRITE)
submit->submit_bos[idx].flags |= MSM_SUBMIT_BO_WRITE;
if (flags & FD_RELOC_DUMP)
submit->submit_bos[idx].flags |= MSM_SUBMIT_BO_DUMP;
+
return idx;
}
{
struct msm_submit_sp *msm_submit = calloc(1, sizeof(*msm_submit));
struct fd_submit *submit;
- static unsigned submit_cnt = 0;
- msm_submit->seqno = ++submit_cnt;
msm_submit->bo_table = _mesa_hash_table_create(NULL,
_mesa_hash_pointer, _mesa_key_pointer_equal);
// TODO tune size: