From: Dave Airlie <airlied@gmail.com>
To: dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org
Subject: [PATCH libdrm] libdrm_amdgpu: add kernel semaphore support
Date: Thu, 6 Jul 2017 11:17:49 +1000 [thread overview]
Message-ID: <20170706011749.4217-1-airlied@gmail.com> (raw)
From: Dave Airlie <airlied@redhat.com>
This adds kernel semaphore support to the command submission
interface in what should be a backwards compatible manner,
it adds a new command submission API.
Signed-off-by: Dave Airlie <airlied@redhat.com>
---
amdgpu/amdgpu.h | 29 ++++++++++++-
amdgpu/amdgpu_cs.c | 118 +++++++++++++++++++++++++++++++++++++++++++++++++----
2 files changed, 138 insertions(+), 9 deletions(-)
diff --git a/amdgpu/amdgpu.h b/amdgpu/amdgpu.h
index 1901fa8..649b66e 100644
--- a/amdgpu/amdgpu.h
+++ b/amdgpu/amdgpu.h
@@ -369,6 +369,16 @@ struct amdgpu_cs_request {
struct amdgpu_cs_fence_info fence_info;
};
+struct amdgpu_cs_request_syncobj {
+ /*
+ *
+ */
+ uint32_t number_in_syncobj;
+ uint32_t number_out_syncobj;
+ uint32_t *in_syncobj;
+ uint32_t *out_syncobj;
+};
+
/**
* Structure which provide information about GPU VM MC Address space
* alignments requirements
@@ -886,6 +896,12 @@ int amdgpu_cs_submit(amdgpu_context_handle context,
struct amdgpu_cs_request *ibs_request,
uint32_t number_of_requests);
+int amdgpu_cs_submit_syncobj(amdgpu_context_handle context,
+ uint64_t flags,
+ struct amdgpu_cs_request *ibs_request,
+ struct amdgpu_cs_request_syncobj *ibs_syncobj,
+ uint32_t number_of_requests);
+
/**
* Query status of Command Buffer Submission
*
@@ -1328,8 +1344,19 @@ int amdgpu_cs_destroy_semaphore(amdgpu_semaphore_handle sem);
*/
const char *amdgpu_get_marketing_name(amdgpu_device_handle dev);
+
+int amdgpu_cs_create_syncobj(amdgpu_device_handle dev,
+ uint32_t *syncobj);
+int amdgpu_cs_export_syncobj(amdgpu_device_handle dev,
+ uint32_t syncobj,
+ int *shared_fd);
+int amdgpu_cs_import_syncobj(amdgpu_device_handle dev,
+ int shared_fd,
+ uint32_t *syncobj);
+int amdgpu_cs_destroy_syncobj(amdgpu_device_handle dev,
+ uint32_t syncobj);
+
#ifdef __cplusplus
}
#endif
-
#endif /* #ifdef _AMDGPU_H_ */
diff --git a/amdgpu/amdgpu_cs.c b/amdgpu/amdgpu_cs.c
index 868eb7b..339c5f9 100644
--- a/amdgpu/amdgpu_cs.c
+++ b/amdgpu/amdgpu_cs.c
@@ -168,7 +168,8 @@ int amdgpu_cs_query_reset_state(amdgpu_context_handle context,
* \sa amdgpu_cs_submit()
*/
static int amdgpu_cs_submit_one(amdgpu_context_handle context,
- struct amdgpu_cs_request *ibs_request)
+ struct amdgpu_cs_request *ibs_request,
+ struct amdgpu_cs_request_syncobj *syncobj_request)
{
union drm_amdgpu_cs cs;
uint64_t *chunk_array;
@@ -176,10 +177,13 @@ static int amdgpu_cs_submit_one(amdgpu_context_handle context,
struct drm_amdgpu_cs_chunk_data *chunk_data;
struct drm_amdgpu_cs_chunk_dep *dependencies = NULL;
struct drm_amdgpu_cs_chunk_dep *sem_dependencies = NULL;
+ struct drm_amdgpu_cs_chunk_sem *in_syncobj_dependencies = NULL;
+ struct drm_amdgpu_cs_chunk_sem *out_syncobj_dependencies = NULL;
struct list_head *sem_list;
amdgpu_semaphore_handle sem, tmp;
- uint32_t i, size, sem_count = 0;
+ uint32_t i, j, size, sem_count = 0;
bool user_fence;
+ uint32_t sem_size = 0;
int r = 0;
if (ibs_request->ip_type >= AMDGPU_HW_IP_NUM)
@@ -194,7 +198,11 @@ static int amdgpu_cs_submit_one(amdgpu_context_handle context,
}
user_fence = (ibs_request->fence_info.handle != NULL);
- size = ibs_request->number_of_ibs + (user_fence ? 2 : 1) + 1;
+ if (syncobj_request) {
+ sem_size += syncobj_request->number_in_syncobj ? 1 : 0;
+ sem_size += syncobj_request->number_out_syncobj ? 1 : 0;
+ }
+ size = ibs_request->number_of_ibs + (user_fence ? 2 : 1) + 1 + sem_size;
chunk_array = alloca(sizeof(uint64_t) * size);
chunks = alloca(sizeof(struct drm_amdgpu_cs_chunk) * size);
@@ -306,6 +314,45 @@ static int amdgpu_cs_submit_one(amdgpu_context_handle context,
chunks[i].chunk_data = (uint64_t)(uintptr_t)sem_dependencies;
}
+ if (syncobj_request) {
+ if (syncobj_request->number_in_syncobj) {
+ in_syncobj_dependencies = malloc(sizeof(struct drm_amdgpu_cs_chunk_sem) * syncobj_request->number_in_syncobj);
+ if (!in_syncobj_dependencies) {
+ r = -ENOMEM;
+ goto error_unlock;
+ }
+ for (j = 0; j < syncobj_request->number_in_syncobj; j++) {
+ struct drm_amdgpu_cs_chunk_sem *dep = &in_syncobj_dependencies[j];
+ dep->handle = syncobj_request->in_syncobj[j];
+ }
+ i = cs.in.num_chunks++;
+
+ /* dependencies chunk */
+ chunk_array[i] = (uint64_t)(uintptr_t)&chunks[i];
+ chunks[i].chunk_id = AMDGPU_CHUNK_ID_SYNCOBJ_IN;
+ chunks[i].length_dw = sizeof(struct drm_amdgpu_cs_chunk_sem) / 4 * syncobj_request->number_in_syncobj;
+ chunks[i].chunk_data = (uint64_t)(uintptr_t)in_syncobj_dependencies;
+ }
+ if (syncobj_request->number_out_syncobj) {
+ out_syncobj_dependencies = malloc(sizeof(struct drm_amdgpu_cs_chunk_sem) * syncobj_request->number_out_syncobj);
+ if (!out_syncobj_dependencies) {
+ r = -ENOMEM;
+ goto error_unlock;
+ }
+ for (j = 0; j < syncobj_request->number_out_syncobj; j++) {
+ struct drm_amdgpu_cs_chunk_sem *dep = &out_syncobj_dependencies[j];
+ dep->handle = syncobj_request->out_syncobj[j];
+ }
+ i = cs.in.num_chunks++;
+
+ /* dependencies chunk */
+ chunk_array[i] = (uint64_t)(uintptr_t)&chunks[i];
+ chunks[i].chunk_id = AMDGPU_CHUNK_ID_SYNCOBJ_OUT;
+ chunks[i].length_dw = sizeof(struct drm_amdgpu_cs_chunk_sem) / 4 * syncobj_request->number_out_syncobj;
+ chunks[i].chunk_data = (uint64_t)(uintptr_t)out_syncobj_dependencies;
+ }
+ }
+
r = drmCommandWriteRead(context->dev->fd, DRM_AMDGPU_CS,
&cs, sizeof(cs));
if (r)
@@ -317,31 +364,48 @@ error_unlock:
pthread_mutex_unlock(&context->sequence_mutex);
free(dependencies);
free(sem_dependencies);
+ free(in_syncobj_dependencies);
+ free(out_syncobj_dependencies);
return r;
}
-int amdgpu_cs_submit(amdgpu_context_handle context,
- uint64_t flags,
- struct amdgpu_cs_request *ibs_request,
- uint32_t number_of_requests)
+int amdgpu_cs_submit_syncobj(amdgpu_context_handle context,
+ uint64_t flags,
+ struct amdgpu_cs_request *ibs_request,
+ struct amdgpu_cs_request_syncobj *ibs_syncobj,
+ uint32_t number_of_requests)
{
uint32_t i;
int r;
+ bool has_syncobj = ibs_syncobj ? true : false;
if (!context || !ibs_request)
return -EINVAL;
r = 0;
for (i = 0; i < number_of_requests; i++) {
- r = amdgpu_cs_submit_one(context, ibs_request);
+ r = amdgpu_cs_submit_one(context, ibs_request, has_syncobj ? ibs_syncobj : NULL);
if (r)
break;
ibs_request++;
+ if (has_syncobj)
+ ibs_syncobj++;
}
return r;
}
+int amdgpu_cs_submit(amdgpu_context_handle context,
+ uint64_t flags,
+ struct amdgpu_cs_request *ibs_request,
+ uint32_t number_of_requests)
+{
+ return amdgpu_cs_submit_syncobj(context, flags,
+ ibs_request, NULL,
+ number_of_requests);
+}
+
+
/**
* Calculate absolute timeout.
*
@@ -596,3 +660,41 @@ int amdgpu_cs_destroy_semaphore(amdgpu_semaphore_handle sem)
{
return amdgpu_cs_unreference_sem(sem);
}
+
+int amdgpu_cs_create_syncobj(amdgpu_device_handle dev,
+ uint32_t *handle)
+{
+ if (NULL == dev)
+ return -EINVAL;
+
+ return drmSyncobjCreate(dev->fd, 0, handle);
+}
+
+int amdgpu_cs_destroy_syncobj(amdgpu_device_handle dev,
+ uint32_t handle)
+{
+ if (NULL == dev)
+ return -EINVAL;
+
+ return drmSyncobjDestroy(dev->fd, handle);
+}
+
+int amdgpu_cs_export_syncobj(amdgpu_device_handle dev,
+ uint32_t handle,
+ int *shared_fd)
+{
+ if (NULL == dev)
+ return -EINVAL;
+
+ return drmSyncobjHandleToFD(dev->fd, handle, shared_fd);
+}
+
+int amdgpu_cs_import_syncobj(amdgpu_device_handle dev,
+ int shared_fd,
+ uint32_t *handle)
+{
+ if (NULL == dev)
+ return -EINVAL;
+
+ return drmSyncobjFDToHandle(dev->fd, shared_fd, handle);
+}
--
2.9.4
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
next reply other threads:[~2017-07-06 1:17 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-06 1:17 Dave Airlie [this message]
2017-07-06 22:19 ` [PATCH libdrm] libdrm_amdgpu: add kernel semaphore support Dave Airlie
2017-07-07 9:07 ` Christian König
[not found] ` <8a5bb44b-c749-43e1-c58a-6c340bbf5474-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org>
2017-07-11 6:49 ` Dave Airlie
2017-07-11 8:36 ` Christian König
[not found] ` <e8320749-8afb-5d64-93e4-7c64192735c5-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org>
2017-07-11 9:20 ` Dave Airlie
2017-07-11 9:32 ` Christian König
[not found] ` <c8c18534-e831-4e48-603a-f72e0234ba6e-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org>
2017-07-12 8:43 ` Dave Airlie
[not found] ` <CAPM=9tzweASCX=Jf2S6-YEqbCnff94WkDN563TDN55v+F-0sQA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-07-17 3:36 ` Dave Airlie
[not found] ` <CAPM=9twZq965gfWHPhjF-P1W6fAV5=dutH3TRmpGK2mwG7waJg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-07-17 17:02 ` Christian König
[not found] ` <db2890bd-36de-ab34-da99-c3dcd691a5e2-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org>
2017-07-18 3:00 ` Dave Airlie
[not found] ` <CAPM=9tx46kYToSvirxL_TTv5dONe8UmM0MCDmAj=YQpCVhyWtA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-07-18 14:45 ` Marek Olšák
2017-07-17 17:22 ` Marek Olšák
[not found] ` <CAAxE2A6_-UvYJn81-cHwZrdWsULJZ=xH7ShzhRf5o4xg7YQa2A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-07-17 17:35 ` Christian König
[not found] ` <24c27ce4-34ec-41a0-b8af-b63d9fd89ee3-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org>
2017-07-18 2:29 ` zhoucm1
[not found] ` <596D7282.2020502-5C7GfCeVMHo@public.gmane.org>
2017-07-18 13:57 ` Christian König
2017-07-19 1:55 ` zhoucm1
[not found] ` <596EBC0B.5050905-5C7GfCeVMHo@public.gmane.org>
2017-07-19 10:12 ` Michel Dänzer
[not found] ` <CAPM=9tw2jGVmJW=VcE=t1WuOXVdj61Qj4jocZQUVGwmHe4DFGA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-07-11 17:47 ` Marek Olšák
[not found] ` <CAAxE2A5KB7WqP7xFMOxRy=eWCRQvkkY_2dp5SENODU3YGAdz5A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-07-12 8:42 ` Dave Airlie
[not found] ` <20170706011749.4217-1-airlied-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-09-01 15:36 ` Marek Olšák
[not found] ` <CAAxE2A6Fco40WfJy9kt5usntnv2GP92PjRiw9mcUfPrs+jr+Xw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-09-04 19:23 ` Marek Olšák
2017-09-04 21:19 ` Dave Airlie
2017-09-04 21:15 ` Dave Airlie
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170706011749.4217-1-airlied@gmail.com \
--to=airlied@gmail.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=dri-devel@lists.freedesktop.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).