amdgpu: add sync_file import and export functions
Subsystems (2)
PATCH 1/4 amdgpu: add sync_file import and export functions
From: Marek Olšák <[email protected]>
--- amdgpu/amdgpu.h | 30 ++++++++++++++++++++++++++++++ amdgpu/amdgpu_cs.c | 20 ++++++++++++++++++++ 2 files changed, 50 insertions(+)
amdgpu/amdgpu.h +30 -0
@@ -1383,6 +1383,36 @@ int amdgpu_cs_import_syncobj(amdgpu_device_handle dev, uint32_t *syncobj);/** +* Export kernel sync object to a sync_file. +* +* \param dev - \c [in] device handle +* \param syncobj - \c [in] sync object handle +* \param sync_file_fd - \c [out] sync_file file descriptor. +* +* \return 0 on success\n +* <0 - Negative POSIX Error code +* +*/ +int amdgpu_cs_syncobj_export_sync_file (amdgpu_device_handle dev, +uint32_t syncobj, +int *sync_file_fd); + +/** +* Import kernel sync object from a sync_file. +* +* \param dev - \c [in] device handle +* \param syncobj - \c [in] sync object handle +* \param sync_file_fd - \c [in] sync_file file descriptor. +* +* \return 0 on success\n +* <0 - Negative POSIX Error code +* +*/ +int amdgpu_cs_syncobj_import_sync_file (amdgpu_device_handle dev, +uint32_t syncobj, +int sync_file_fd); + +/** * Submit raw command submission to kernel * * \param dev - \c [in] device handle
amdgpu/amdgpu_cs.c +20 -0
@@ -635,6 +635,26 @@ int amdgpu_cs_import_syncobj(amdgpu_device_handle dev,return drmSyncobjFDToHandle (dev->fd, shared_fd, handle); } +int amdgpu_cs_syncobj_export_sync_file (amdgpu_device_handle dev, +uint32_t syncobj, +int *sync_file_fd) +{ +if (NULL == dev) +return -EINVAL ; + +return drmSyncobjExportSyncFile (dev->fd, syncobj, sync_file_fd); +} + +int amdgpu_cs_syncobj_import_sync_file (amdgpu_device_handle dev, +uint32_t syncobj, +int sync_file_fd) +{ +if (NULL == dev) +return -EINVAL ; + +return drmSyncobjImportSyncFile (dev->fd, syncobj, sync_file_fd); +} + int amdgpu_cs_submit_raw(amdgpu_device_handle dev, amdgpu_context_handle context, amdgpu_bo_list_handle bo_list_handle,
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 1505248992-1898-1-git-send-email-maraeo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
PATCH 2/4 drm: add drmSyncobjWait wrapper
From: Marek Olšák <[email protected]>
--- include/drm/drm.h | 24 ++++++++++++++++++++++++ xf86drm.c | 22 ++++++++++++++++++++++ xf86drm.h | 3 +++ 3 files changed, 49 insertions(+)
include/drm/drm.h +24 -0
@@ -694,6 +694,7 @@ struct drm_prime_handle {struct drm_syncobj_create {__u32 handle; +#define DRM_SYNCOBJ_CREATE_SIGNALED (1 << 0)__u32 flags; };
@@ -712,6 +713,24 @@ struct drm_syncobj_handle {__u32 pad; }; +#define DRM_SYNCOBJ_WAIT_FLAGS_WAIT_ALL (1 << 0) +#define DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT (1 << 1) +struct drm_syncobj_wait { +__u64 handles; +/* absolute timeout */ +__s64 timeout_nsec; +__u32 count_handles; +__u32 flags; +__u32 first_signaled;/* only valid when not waiting all */ +__u32 pad; +}; + +struct drm_syncobj_array { +__u64 handles; +__u32 count_handles; +__u32 pad; +}; +#if defined(__cplusplus) }#endif
@@ -834,6 +853,9 @@ extern "C" {#define DRM_IOCTL_SYNCOBJ_DESTROY DRM_IOWR(0xC0, struct drm_syncobj_destroy)#define DRM_IOCTL_SYNCOBJ_HANDLE_TO_FD DRM_IOWR(0xC1, struct drm_syncobj_handle)#define DRM_IOCTL_SYNCOBJ_FD_TO_HANDLE DRM_IOWR(0xC2, struct drm_syncobj_handle) +#define DRM_IOCTL_SYNCOBJ_WAIT DRM_IOWR(0xC3, struct drm_syncobj_wait) +#define DRM_IOCTL_SYNCOBJ_RESET DRM_IOWR(0xC4, struct drm_syncobj_array) +#define DRM_IOCTL_SYNCOBJ_SIGNAL DRM_IOWR(0xC5, struct drm_syncobj_array)/** * Device specific ioctls should only be in their respective headers
@@ -876,6 +898,7 @@ struct drm_event_vblank { };/* typedef area */ +#ifndef __KERNEL__typedef struct drm_clip_rect drm_clip_rect_t ;typedef struct drm_drawable_info drm_drawable_info_t ;typedef struct drm_tex_region drm_tex_region_t ;
@@ -917,6 +940,7 @@ typedef struct drm_agp_binding drm_agp_binding_t;typedef struct drm_agp_info drm_agp_info_t ;typedef struct drm_scatter_gather drm_scatter_gather_t ;typedef struct drm_set_version drm_set_version_t ; +#endif #if defined(__cplusplus) }
xf86drm.c +22 -0
@@ -4225,3 +4225,25 @@ int drmSyncobjExportSyncFile(int fd, uint32_t handle, int *sync_file_fd) *sync_file_fd = args.fd;return 0 ; } + +int drmSyncobjWait (int fd,uint32_t *handles,unsigned num_handles, +int64_t timeout_nsec,unsigned flags, +uint32_t *first_signaled) +{ +struct drm_syncobj_wait args; +int ret; + +memclear (args); + args.handles = (intptr_t )handles; + args.timeout_nsec = timeout_nsec; + args.count_handles = num_handles; + args.flags = flags; + + ret =drmIoctl (fd,DRM_IOCTL_SYNCOBJ_WAIT , &args); +if (ret <0 ) +return ret; + +if (first_signaled) + *first_signaled = args.first_signaled; +return ret; +}
xf86drm.h +3 -0
@@ -860,6 +860,9 @@ extern int drmSyncobjFDToHandle(int fd, int obj_fd, uint32_t *handle);extern int drmSyncobjImportSyncFile (int fd,uint32_t handle,int sync_file_fd);extern int drmSyncobjExportSyncFile (int fd,uint32_t handle,int *sync_file_fd); +extern int drmSyncobjWait (int fd,uint32_t *handles,unsigned num_handles, +int64_t timeout_nsec,unsigned flags, +uint32_t *first_signaled);#if defined(__cplusplus) }
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 3/4 amdgpu: add amdgpu_cs_syncobj_wait
In reply to a message not in the archiveFrom: Marek Olšák <[email protected]>
--- amdgpu/amdgpu.h | 20 ++++++++++++++++++++ amdgpu/amdgpu_cs.c | 12 ++++++++++++ 2 files changed, 32 insertions(+)
amdgpu/amdgpu.h +20 -0
@@ -1354,6 +1354,26 @@ int amdgpu_cs_destroy_syncobj(amdgpu_device_handle dev, uint32_t syncobj);/** +* Wait for one or all sync objects to signal. +* +* \param dev - \c [in] self-explanatory +* \param handles - \c [in] array of sync object handles +* \param num_handles - \c [in] self-explanatory +* \param timeout_nsec - \c [in] self-explanatory +* \param flags - \c [in] a bitmask of DRM_SYNCOBJ_WAIT_FLAGS_* +* \param first_signaled - \c [in] self-explanatory +* +* \return 0 on success\n +* -ETIME - Timeout +* <0 - Negative POSIX Error code +* +*/ +int amdgpu_cs_syncobj_wait (amdgpu_device_handle dev, +uint32_t *handles,unsigned num_handles, +int64_t timeout_nsec,unsigned flags, +uint32_t *first_signaled); + +/** * Export kernel sync object to shareable fd. * * \param dev - \c [in] device handle
amdgpu/amdgpu_cs.c +12 -0
@@ -615,6 +615,18 @@ int amdgpu_cs_destroy_syncobj(amdgpu_device_handle dev,return drmSyncobjDestroy (dev->fd, handle); } +int amdgpu_cs_syncobj_wait (amdgpu_device_handle dev, +uint32_t *handles,unsigned num_handles, +int64_t timeout_nsec,unsigned flags, +uint32_t *first_signaled) +{ +if (NULL == dev) +return -EINVAL ; + +return drmSyncobjWait (dev->fd, handles, num_handles, timeout_nsec, + flags, first_signaled); +} +int amdgpu_cs_export_syncobj (amdgpu_device_handle dev,uint32_t handle,int *shared_fd)
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Quoted 34 lines · Marek Olšák
From: Marek Olšák <[email protected]>
--- amdgpu/amdgpu.h | 30 ++++++++++++++++++++++++++++++ amdgpu/amdgpu_cs.c | 20 ++++++++++++++++++++ 2 files changed, 50 insertions(+)amdgpu/amdgpu.h +19
-0@@ -1383,6 +1383,36 @@ int amdgpu_cs_import_syncobj(amdgpu_device_handle dev, uint32_t *syncobj);/** +* Export kernel sync object to a sync_file. +* +* \param dev - \c [in] device handle +* \param syncobj - \c [in] sync object handle +* \param sync_file_fd - \c [out] sync_file file descriptor. +* +* \return 0 on success\n +* <0 - Negative POSIX Error code +* +*/ +int amdgpu_cs_syncobj_export_sync_file (amdgpu_device_handle dev, +uint32_t syncobj, +int *sync_file_fd); + +/** +* Import kernel sync object from a sync_file. +* +* \param dev - \c [in] device handle +* \param syncobj - \c [in] sync object handle
amdgpu/amdgpu.h int amdgpu_cs_import_syncobj(amdgpu_device_handle dev, · line 1414
Quoted 10 lines
amdgpu/amdgpu.h +10
-0+* \param sync_file_fd - \c [in] sync_file file descriptor. +* +* \return 0 on success\n +* <0 - Negative POSIX Error code +* +*/ +int amdgpu_cs_syncobj_import_sync_file (amdgpu_device_handle dev, +uint32_t syncobj, +int sync_file_fd); +
Did you run make check? Seems like these (and other newly introduced symbols) are missing from amdgpu-symbol-check.
Thanks
Emil
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 4/4 amdgpu: add amdgpu_cs_fence_to_handle
In reply to Marek OlšákFrom: Marek Olšák <[email protected]>
--- amdgpu/amdgpu.h | 14 ++++++++++++++ amdgpu/amdgpu_cs.c | 22 ++++++++++++++++++++++ include/drm/amdgpu_drm.h | 21 +++++++++++++++++++++ 3 files changed, 57 insertions(+)
amdgpu/amdgpu.h +14 -0
@@ -1433,6 +1433,20 @@ int amdgpu_cs_syncobj_import_sync_file(amdgpu_device_handle dev, int sync_file_fd);/** +* Export an amdgpu fence as a handle (syncobj or fd). +* +* \param what AMDGPU_FENCE_TO_HANDLE_GET_{SYNCOBJ, FD} +* \param out_handle returned handle +* +* \return 0 on success\n +* <0 - Negative POSIX Error code +*/ +int amdgpu_cs_fence_to_handle (amdgpu_device_handle dev, +struct amdgpu_cs_fence *fence, +uint32_t what, +uint32_t *out_handle); + +/** * Submit raw command submission to kernel * * \param dev - \c [in] device handle
amdgpu/amdgpu_cs.c +22 -0
@@ -713,3 +713,25 @@ void amdgpu_cs_chunk_fence_to_dep(struct amdgpu_cs_fence *fence, dep->ctx_id = fence->context->id; dep->handle = fence->fence; } + +int amdgpu_cs_fence_to_handle (amdgpu_device_handle dev, +struct amdgpu_cs_fence *fence, +uint32_t what, +uint32_t *out_handle) +{ +union drm_amdgpu_fence_to_handle fth = {0 }; +int r; + + fth.in.fence.ctx_id = fence->context->id; + fth.in.fence.ip_type = fence->ip_type; + fth.in.fence.ip_instance = fence->ip_instance; + fth.in.fence.ring = fence->ring; + fth.in.fence.seq_no = fence->fence; + fth.in.what = what; + + r =drmCommandWriteRead (dev->fd,DRM_AMDGPU_FENCE_TO_HANDLE , + &fth,sizeof (fth)); +if (r ==0 ) + *out_handle = fth.out.handle; +return r; +}
include/drm/amdgpu_drm.h +21 -0
@@ -52,6 +52,7 @@ extern "C" {#define DRM_AMDGPU_GEM_USERPTR 0x11#define DRM_AMDGPU_WAIT_FENCES 0x12#define DRM_AMDGPU_VM 0x13 +#define DRM_AMDGPU_FENCE_TO_HANDLE 0x15#define DRM_IOCTL_AMDGPU_GEM_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_CREATE, union drm_amdgpu_gem_create)#define DRM_IOCTL_AMDGPU_GEM_MMAP DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_MMAP, union drm_amdgpu_gem_mmap)
@@ -67,6 +68,7 @@ extern "C" {#define DRM_IOCTL_AMDGPU_GEM_USERPTR DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_USERPTR, struct drm_amdgpu_gem_userptr)#define DRM_IOCTL_AMDGPU_WAIT_FENCES DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_WAIT_FENCES, union drm_amdgpu_wait_fences)#define DRM_IOCTL_AMDGPU_VM DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_VM, union drm_amdgpu_vm) +#define DRM_IOCTL_AMDGPU_FENCE_TO_HANDLE DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_FENCE_TO_HANDLE, union drm_amdgpu_fence_to_handle)#define AMDGPU_GEM_DOMAIN_CPU 0x1#define AMDGPU_GEM_DOMAIN_GTT 0x2
@@ -87,6 +89,8 @@ extern "C" {#define AMDGPU_GEM_CREATE_SHADOW (1 << 4)/* Flag that allocating the BO should use linear VRAM */ #define AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS (1 << 5) +/* Flag that BO is always valid in this VM */ +#define AMDGPU_GEM_CREATE_VM_ALWAYS_VALID (1 << 6)struct drm_amdgpu_gem_create_in {/** the requested memory size */
@@ -513,6 +517,20 @@ struct drm_amdgpu_cs_chunk_sem {__u32 handle; }; +#define AMDGPU_FENCE_TO_HANDLE_GET_SYNCOBJ 0 +#define AMDGPU_FENCE_TO_HANDLE_GET_SYNCOBJ_FD 1 +#define AMDGPU_FENCE_TO_HANDLE_GET_SYNC_FILE_FD 2 + +union drm_amdgpu_fence_to_handle { +struct { +struct drm_amdgpu_fence fence; +__u32 what; + } in; +struct { +__u32 handle; + } out; +}; +struct drm_amdgpu_cs_chunk_data {union {struct drm_amdgpu_cs_chunk_ib ib_data;
@@ -764,6 +782,7 @@ struct drm_amdgpu_info_device {__u64 max_memory_clock;/* cu information */ __u32 cu_active_number; +/* NOTE: cu_ao_mask is INVALID, DON'T use it */ __u32 cu_ao_mask;__u32 cu_bitmap[4 ][4 ];/** Render backend pipe mask. One render backend is CB+DB. */
@@ -818,6 +837,8 @@ struct drm_amdgpu_info_device {/* max gs wavefront per vgt*/ __u32 max_gs_waves_per_vgt;__u32 _pad1; +/* always on cu bitmap */ +__u32 cu_ao_bitmap[4 ][4 ]; };struct drm_amdgpu_info_hw_ip {
Signature · 6 lines
2.7.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel