Skip to content

Commit 2624dd1

Browse files
amingriyuealexdeucher
authored andcommitted
drm/amdgpu: add timeline support in amdgpu CS v3
syncobj wait/signal operation is appending in command submission. v2: separate to two kinds in/out_deps functions v3: fix checking for timeline syncobj Signed-off-by: Chunming Zhou <david1.zhou@amd.com> Cc: Tobias Hector <Tobias.Hector@amd.com> Cc: Jason Ekstrand <jason@jlekstrand.net> Cc: Dave Airlie <airlied@redhat.com> Cc: Chris Wilson <chris@chris-wilson.co.uk> Cc: Lionel Landwerlin <lionel.g.landwerlin@intel.com> Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
1 parent ecc4946 commit 2624dd1

3 files changed

Lines changed: 144 additions & 26 deletions

File tree

‎drivers/gpu/drm/amd/amdgpu/amdgpu.h‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,12 @@ struct amdgpu_cs_chunk {
436436
void *kdata;
437437
};
438438

439+
struct amdgpu_cs_post_dep {
440+
struct drm_syncobj *syncobj;
441+
struct dma_fence_chain *chain;
442+
u64 point;
443+
};
444+
439445
struct amdgpu_cs_parser {
440446
struct amdgpu_device *adev;
441447
struct drm_file *filp;
@@ -465,8 +471,8 @@ struct amdgpu_cs_parser {
465471
/* user fence */
466472
struct amdgpu_bo_list_entry uf_entry;
467473

468-
unsigned num_post_dep_syncobjs;
469-
struct drm_syncobj **post_dep_syncobjs;
474+
unsigned num_post_deps;
475+
struct amdgpu_cs_post_dep *post_deps;
470476
};
471477

472478
static inline u32 amdgpu_get_ib_value(struct amdgpu_cs_parser *p,

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

Lines changed: 128 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,8 @@ static int amdgpu_cs_parser_init(struct amdgpu_cs_parser *p, union drm_amdgpu_cs
215215
case AMDGPU_CHUNK_ID_SYNCOBJ_IN:
216216
case AMDGPU_CHUNK_ID_SYNCOBJ_OUT:
217217
case AMDGPU_CHUNK_ID_SCHEDULED_DEPENDENCIES:
218+
case AMDGPU_CHUNK_ID_SYNCOBJ_TIMELINE_WAIT:
219+
case AMDGPU_CHUNK_ID_SYNCOBJ_TIMELINE_SIGNAL:
218220
break;
219221

220222
default:
@@ -804,9 +806,11 @@ static void amdgpu_cs_parser_fini(struct amdgpu_cs_parser *parser, int error,
804806
ttm_eu_backoff_reservation(&parser->ticket,
805807
&parser->validated);
806808

807-
for (i = 0; i < parser->num_post_dep_syncobjs; i++)
808-
drm_syncobj_put(parser->post_dep_syncobjs[i]);
809-
kfree(parser->post_dep_syncobjs);
809+
for (i = 0; i < parser->num_post_deps; i++) {
810+
drm_syncobj_put(parser->post_deps[i].syncobj);
811+
kfree(parser->post_deps[i].chain);
812+
}
813+
kfree(parser->post_deps);
810814

811815
dma_fence_put(parser->fence);
812816

@@ -1117,13 +1121,18 @@ static int amdgpu_cs_process_fence_dep(struct amdgpu_cs_parser *p,
11171121
}
11181122

11191123
static int amdgpu_syncobj_lookup_and_add_to_sync(struct amdgpu_cs_parser *p,
1120-
uint32_t handle)
1124+
uint32_t handle, u64 point,
1125+
u64 flags)
11211126
{
1122-
int r;
11231127
struct dma_fence *fence;
1124-
r = drm_syncobj_find_fence(p->filp, handle, 0, 0, &fence);
1125-
if (r)
1128+
int r;
1129+
1130+
r = drm_syncobj_find_fence(p->filp, handle, point, flags, &fence);
1131+
if (r) {
1132+
DRM_ERROR("syncobj %u failed to find fence @ %llu (%d)!\n",
1133+
handle, point, r);
11261134
return r;
1135+
}
11271136

11281137
r = amdgpu_sync_fence(p->adev, &p->job->sync, fence, true);
11291138
dma_fence_put(fence);
@@ -1134,46 +1143,118 @@ static int amdgpu_syncobj_lookup_and_add_to_sync(struct amdgpu_cs_parser *p,
11341143
static int amdgpu_cs_process_syncobj_in_dep(struct amdgpu_cs_parser *p,
11351144
struct amdgpu_cs_chunk *chunk)
11361145
{
1146+
struct drm_amdgpu_cs_chunk_sem *deps;
11371147
unsigned num_deps;
11381148
int i, r;
1139-
struct drm_amdgpu_cs_chunk_sem *deps;
11401149

11411150
deps = (struct drm_amdgpu_cs_chunk_sem *)chunk->kdata;
11421151
num_deps = chunk->length_dw * 4 /
11431152
sizeof(struct drm_amdgpu_cs_chunk_sem);
1153+
for (i = 0; i < num_deps; ++i) {
1154+
r = amdgpu_syncobj_lookup_and_add_to_sync(p, deps[i].handle,
1155+
0, 0);
1156+
if (r)
1157+
return r;
1158+
}
1159+
1160+
return 0;
1161+
}
1162+
11441163

1164+
static int amdgpu_cs_process_syncobj_timeline_in_dep(struct amdgpu_cs_parser *p,
1165+
struct amdgpu_cs_chunk *chunk)
1166+
{
1167+
struct drm_amdgpu_cs_chunk_syncobj *syncobj_deps;
1168+
unsigned num_deps;
1169+
int i, r;
1170+
1171+
syncobj_deps = (struct drm_amdgpu_cs_chunk_syncobj *)chunk->kdata;
1172+
num_deps = chunk->length_dw * 4 /
1173+
sizeof(struct drm_amdgpu_cs_chunk_syncobj);
11451174
for (i = 0; i < num_deps; ++i) {
1146-
r = amdgpu_syncobj_lookup_and_add_to_sync(p, deps[i].handle);
1175+
r = amdgpu_syncobj_lookup_and_add_to_sync(p,
1176+
syncobj_deps[i].handle,
1177+
syncobj_deps[i].point,
1178+
syncobj_deps[i].flags);
11471179
if (r)
11481180
return r;
11491181
}
1182+
11501183
return 0;
11511184
}
11521185

11531186
static int amdgpu_cs_process_syncobj_out_dep(struct amdgpu_cs_parser *p,
11541187
struct amdgpu_cs_chunk *chunk)
11551188
{
1189+
struct drm_amdgpu_cs_chunk_sem *deps;
11561190
unsigned num_deps;
11571191
int i;
1158-
struct drm_amdgpu_cs_chunk_sem *deps;
1192+
11591193
deps = (struct drm_amdgpu_cs_chunk_sem *)chunk->kdata;
11601194
num_deps = chunk->length_dw * 4 /
11611195
sizeof(struct drm_amdgpu_cs_chunk_sem);
11621196

1163-
p->post_dep_syncobjs = kmalloc_array(num_deps,
1164-
sizeof(struct drm_syncobj *),
1165-
GFP_KERNEL);
1166-
p->num_post_dep_syncobjs = 0;
1197+
p->post_deps = kmalloc_array(num_deps, sizeof(*p->post_deps),
1198+
GFP_KERNEL);
1199+
p->num_post_deps = 0;
11671200

1168-
if (!p->post_dep_syncobjs)
1201+
if (!p->post_deps)
11691202
return -ENOMEM;
11701203

1204+
11711205
for (i = 0; i < num_deps; ++i) {
1172-
p->post_dep_syncobjs[i] = drm_syncobj_find(p->filp, deps[i].handle);
1173-
if (!p->post_dep_syncobjs[i])
1206+
p->post_deps[i].syncobj =
1207+
drm_syncobj_find(p->filp, deps[i].handle);
1208+
if (!p->post_deps[i].syncobj)
11741209
return -EINVAL;
1175-
p->num_post_dep_syncobjs++;
1210+
p->post_deps[i].chain = NULL;
1211+
p->post_deps[i].point = 0;
1212+
p->num_post_deps++;
11761213
}
1214+
1215+
return 0;
1216+
}
1217+
1218+
1219+
static int amdgpu_cs_process_syncobj_timeline_out_dep(struct amdgpu_cs_parser *p,
1220+
struct amdgpu_cs_chunk
1221+
*chunk)
1222+
{
1223+
struct drm_amdgpu_cs_chunk_syncobj *syncobj_deps;
1224+
unsigned num_deps;
1225+
int i;
1226+
1227+
syncobj_deps = (struct drm_amdgpu_cs_chunk_syncobj *)chunk->kdata;
1228+
num_deps = chunk->length_dw * 4 /
1229+
sizeof(struct drm_amdgpu_cs_chunk_syncobj);
1230+
1231+
p->post_deps = kmalloc_array(num_deps, sizeof(*p->post_deps),
1232+
GFP_KERNEL);
1233+
p->num_post_deps = 0;
1234+
1235+
if (!p->post_deps)
1236+
return -ENOMEM;
1237+
1238+
for (i = 0; i < num_deps; ++i) {
1239+
struct amdgpu_cs_post_dep *dep = &p->post_deps[i];
1240+
1241+
dep->chain = NULL;
1242+
if (syncobj_deps[i].point) {
1243+
dep->chain = kmalloc(sizeof(*dep->chain), GFP_KERNEL);
1244+
if (!dep->chain)
1245+
return -ENOMEM;
1246+
}
1247+
1248+
dep->syncobj = drm_syncobj_find(p->filp,
1249+
syncobj_deps[i].handle);
1250+
if (!dep->syncobj) {
1251+
kfree(dep->chain);
1252+
return -EINVAL;
1253+
}
1254+
dep->point = syncobj_deps[i].point;
1255+
p->num_post_deps++;
1256+
}
1257+
11771258
return 0;
11781259
}
11791260

@@ -1187,19 +1268,33 @@ static int amdgpu_cs_dependencies(struct amdgpu_device *adev,
11871268

11881269
chunk = &p->chunks[i];
11891270

1190-
if (chunk->chunk_id == AMDGPU_CHUNK_ID_DEPENDENCIES ||
1191-
chunk->chunk_id == AMDGPU_CHUNK_ID_SCHEDULED_DEPENDENCIES) {
1271+
switch (chunk->chunk_id) {
1272+
case AMDGPU_CHUNK_ID_DEPENDENCIES:
1273+
case AMDGPU_CHUNK_ID_SCHEDULED_DEPENDENCIES:
11921274
r = amdgpu_cs_process_fence_dep(p, chunk);
11931275
if (r)
11941276
return r;
1195-
} else if (chunk->chunk_id == AMDGPU_CHUNK_ID_SYNCOBJ_IN) {
1277+
break;
1278+
case AMDGPU_CHUNK_ID_SYNCOBJ_IN:
11961279
r = amdgpu_cs_process_syncobj_in_dep(p, chunk);
11971280
if (r)
11981281
return r;
1199-
} else if (chunk->chunk_id == AMDGPU_CHUNK_ID_SYNCOBJ_OUT) {
1282+
break;
1283+
case AMDGPU_CHUNK_ID_SYNCOBJ_OUT:
12001284
r = amdgpu_cs_process_syncobj_out_dep(p, chunk);
12011285
if (r)
12021286
return r;
1287+
break;
1288+
case AMDGPU_CHUNK_ID_SYNCOBJ_TIMELINE_WAIT:
1289+
r = amdgpu_cs_process_syncobj_timeline_in_dep(p, chunk);
1290+
if (r)
1291+
return r;
1292+
break;
1293+
case AMDGPU_CHUNK_ID_SYNCOBJ_TIMELINE_SIGNAL:
1294+
r = amdgpu_cs_process_syncobj_timeline_out_dep(p, chunk);
1295+
if (r)
1296+
return r;
1297+
break;
12031298
}
12041299
}
12051300

@@ -1210,8 +1305,17 @@ static void amdgpu_cs_post_dependencies(struct amdgpu_cs_parser *p)
12101305
{
12111306
int i;
12121307

1213-
for (i = 0; i < p->num_post_dep_syncobjs; ++i)
1214-
drm_syncobj_replace_fence(p->post_dep_syncobjs[i], p->fence);
1308+
for (i = 0; i < p->num_post_deps; ++i) {
1309+
if (p->post_deps[i].chain && p->post_deps[i].point) {
1310+
drm_syncobj_add_point(p->post_deps[i].syncobj,
1311+
p->post_deps[i].chain,
1312+
p->fence, p->post_deps[i].point);
1313+
p->post_deps[i].chain = NULL;
1314+
} else {
1315+
drm_syncobj_replace_fence(p->post_deps[i].syncobj,
1316+
p->fence);
1317+
}
1318+
}
12151319
}
12161320

12171321
static int amdgpu_cs_submit(struct amdgpu_cs_parser *p,

‎include/uapi/drm/amdgpu_drm.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,8 @@ struct drm_amdgpu_gem_va {
528528
#define AMDGPU_CHUNK_ID_SYNCOBJ_OUT 0x05
529529
#define AMDGPU_CHUNK_ID_BO_HANDLES 0x06
530530
#define AMDGPU_CHUNK_ID_SCHEDULED_DEPENDENCIES 0x07
531+
#define AMDGPU_CHUNK_ID_SYNCOBJ_TIMELINE_WAIT 0x08
532+
#define AMDGPU_CHUNK_ID_SYNCOBJ_TIMELINE_SIGNAL 0x09
531533

532534
struct drm_amdgpu_cs_chunk {
533535
__u32 chunk_id;
@@ -608,6 +610,12 @@ struct drm_amdgpu_cs_chunk_sem {
608610
__u32 handle;
609611
};
610612

613+
struct drm_amdgpu_cs_chunk_syncobj {
614+
__u32 handle;
615+
__u32 flags;
616+
__u64 point;
617+
};
618+
611619
#define AMDGPU_FENCE_TO_HANDLE_GET_SYNCOBJ 0
612620
#define AMDGPU_FENCE_TO_HANDLE_GET_SYNCOBJ_FD 1
613621
#define AMDGPU_FENCE_TO_HANDLE_GET_SYNC_FILE_FD 2

0 commit comments

Comments
 (0)