Skip to content

Commit b312d8c

Browse files
dma-buf: make fence sequence numbers 64 bit v2
For a lot of use cases we need 64bit sequence numbers. Currently drivers overload the dma_fence structure to store the additional bits. Stop doing that and make the sequence number in the dma_fence always 64bit. For compatibility with hardware which can do only 32bit sequences the comparisons in __dma_fence_is_later only takes the lower 32bits as significant when the upper 32bits are all zero. v2: change the logic in __dma_fence_is_later Signed-off-by: Christian König <christian.koenig@amd.com> Reviewed-by: Chunming Zhou <david1.zhou@amd.com> Link: https://patchwork.freedesktop.org/patch/266927/
1 parent fcc4a00 commit b312d8c

8 files changed

Lines changed: 24 additions & 16 deletions

File tree

‎drivers/dma-buf/dma-fence.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ EXPORT_SYMBOL(dma_fence_wait_any_timeout);
649649
*/
650650
void
651651
dma_fence_init(struct dma_fence *fence, const struct dma_fence_ops *ops,
652-
spinlock_t *lock, u64 context, unsigned seqno)
652+
spinlock_t *lock, u64 context, u64 seqno)
653653
{
654654
BUG_ON(!lock);
655655
BUG_ON(!ops || !ops->get_driver_name || !ops->get_timeline_name);

‎drivers/dma-buf/sw_sync.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ static bool timeline_fence_enable_signaling(struct dma_fence *fence)
172172
static void timeline_fence_value_str(struct dma_fence *fence,
173173
char *str, int size)
174174
{
175-
snprintf(str, size, "%d", fence->seqno);
175+
snprintf(str, size, "%lld", fence->seqno);
176176
}
177177

178178
static void timeline_fence_timeline_value_str(struct dma_fence *fence,

‎drivers/dma-buf/sync_file.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ char *sync_file_get_name(struct sync_file *sync_file, char *buf, int len)
144144
} else {
145145
struct dma_fence *fence = sync_file->fence;
146146

147-
snprintf(buf, len, "%s-%s%llu-%d",
147+
snprintf(buf, len, "%s-%s%llu-%lld",
148148
fence->ops->get_driver_name(fence),
149149
fence->ops->get_timeline_name(fence),
150150
fence->context,
@@ -258,7 +258,7 @@ static struct sync_file *sync_file_merge(const char *name, struct sync_file *a,
258258

259259
i_b++;
260260
} else {
261-
if (pt_a->seqno - pt_b->seqno <= INT_MAX)
261+
if (__dma_fence_is_later(pt_a->seqno, pt_b->seqno))
262262
add_fence(fences, &i, pt_a);
263263
else
264264
add_fence(fences, &i, pt_b);

‎drivers/gpu/drm/amd/amdgpu/amdgpu_sa.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ void amdgpu_sa_bo_dump_debug_info(struct amdgpu_sa_manager *sa_manager,
388388
soffset, eoffset, eoffset - soffset);
389389

390390
if (i->fence)
391-
seq_printf(m, " protected by 0x%08x on context %llu",
391+
seq_printf(m, " protected by 0x%016llx on context %llu",
392392
i->fence->seqno, i->fence->context);
393393

394394
seq_printf(m, "\n");

‎drivers/gpu/drm/i915/i915_sw_fence.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ static void timer_i915_sw_fence_wake(struct timer_list *t)
393393
if (!fence)
394394
return;
395395

396-
pr_notice("Asynchronous wait on fence %s:%s:%x timed out (hint:%pS)\n",
396+
pr_notice("Asynchronous wait on fence %s:%s:%llx timed out (hint:%pS)\n",
397397
cb->dma->ops->get_driver_name(cb->dma),
398398
cb->dma->ops->get_timeline_name(cb->dma),
399399
cb->dma->seqno,

‎drivers/gpu/drm/i915/intel_engine_cs.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1239,7 +1239,7 @@ static void print_request(struct drm_printer *m,
12391239

12401240
x = print_sched_attr(rq->i915, &rq->sched.attr, buf, x, sizeof(buf));
12411241

1242-
drm_printf(m, "%s%x%s [%llx:%x]%s @ %dms: %s\n",
1242+
drm_printf(m, "%s%x%s [%llx:%llx]%s @ %dms: %s\n",
12431243
prefix,
12441244
rq->global_seqno,
12451245
i915_request_completed(rq) ? "!" : "",

‎drivers/gpu/drm/vgem/vgem_fence.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ static void vgem_fence_release(struct dma_fence *base)
5353

5454
static void vgem_fence_value_str(struct dma_fence *fence, char *str, int size)
5555
{
56-
snprintf(str, size, "%u", fence->seqno);
56+
snprintf(str, size, "%llu", fence->seqno);
5757
}
5858

5959
static void vgem_fence_timeline_value_str(struct dma_fence *fence, char *str,
6060
int size)
6161
{
62-
snprintf(str, size, "%u",
62+
snprintf(str, size, "%llu",
6363
dma_fence_is_signaled(fence) ? fence->seqno : 0);
6464
}
6565

‎include/linux/dma-fence.h‎

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ struct dma_fence {
7777
struct list_head cb_list;
7878
spinlock_t *lock;
7979
u64 context;
80-
unsigned seqno;
80+
u64 seqno;
8181
unsigned long flags;
8282
ktime_t timestamp;
8383
int error;
@@ -244,7 +244,7 @@ struct dma_fence_ops {
244244
};
245245

246246
void dma_fence_init(struct dma_fence *fence, const struct dma_fence_ops *ops,
247-
spinlock_t *lock, u64 context, unsigned seqno);
247+
spinlock_t *lock, u64 context, u64 seqno);
248248

249249
void dma_fence_release(struct kref *kref);
250250
void dma_fence_free(struct dma_fence *fence);
@@ -414,9 +414,17 @@ dma_fence_is_signaled(struct dma_fence *fence)
414414
* Returns true if f1 is chronologically later than f2. Both fences must be
415415
* from the same context, since a seqno is not common across contexts.
416416
*/
417-
static inline bool __dma_fence_is_later(u32 f1, u32 f2)
417+
static inline bool __dma_fence_is_later(u64 f1, u64 f2)
418418
{
419-
return (int)(f1 - f2) > 0;
419+
/* This is for backward compatibility with drivers which can only handle
420+
* 32bit sequence numbers. Use a 64bit compare when any of the higher
421+
* bits are none zero, otherwise use a 32bit compare with wrap around
422+
* handling.
423+
*/
424+
if (upper_32_bits(f1) || upper_32_bits(f2))
425+
return f1 > f2;
426+
427+
return (int)(lower_32_bits(f1) - lower_32_bits(f2)) > 0;
420428
}
421429

422430
/**
@@ -548,21 +556,21 @@ u64 dma_fence_context_alloc(unsigned num);
548556
do { \
549557
struct dma_fence *__ff = (f); \
550558
if (IS_ENABLED(CONFIG_DMA_FENCE_TRACE)) \
551-
pr_info("f %llu#%u: " fmt, \
559+
pr_info("f %llu#%llu: " fmt, \
552560
__ff->context, __ff->seqno, ##args); \
553561
} while (0)
554562

555563
#define DMA_FENCE_WARN(f, fmt, args...) \
556564
do { \
557565
struct dma_fence *__ff = (f); \
558-
pr_warn("f %llu#%u: " fmt, __ff->context, __ff->seqno, \
566+
pr_warn("f %llu#%llu: " fmt, __ff->context, __ff->seqno,\
559567
##args); \
560568
} while (0)
561569

562570
#define DMA_FENCE_ERR(f, fmt, args...) \
563571
do { \
564572
struct dma_fence *__ff = (f); \
565-
pr_err("f %llu#%u: " fmt, __ff->context, __ff->seqno, \
573+
pr_err("f %llu#%llu: " fmt, __ff->context, __ff->seqno, \
566574
##args); \
567575
} while (0)
568576

0 commit comments

Comments
 (0)