Re: [Intel-gfx] [PATCH i-g-t 1/4] lib: Add some syncobj helpers (v2)
On Mon, Aug 28, 2017 at 02:10:12PM -0700, Jason Ekstrand wrote: > Signed-off-by: Jason Ekstrandgtkdocs would be lovely for this, if I can motivate you ... Thanks, Daniel > --- > lib/Makefile.sources | 2 + > lib/igt_syncobj.c| 207 > +++ > lib/igt_syncobj.h| 71 ++ > 3 files changed, 280 insertions(+) > create mode 100644 lib/igt_syncobj.c > create mode 100644 lib/igt_syncobj.h > > diff --git a/lib/Makefile.sources b/lib/Makefile.sources > index 53fdb54..692fe30 100644 > --- a/lib/Makefile.sources > +++ b/lib/Makefile.sources > @@ -83,6 +83,8 @@ lib_source_list = \ > uwildmat/uwildmat.c \ > igt_kmod.c \ > igt_kmod.h \ > + igt_syncobj.c \ > + igt_syncobj.h \ > $(NULL) > > .PHONY: version.h.tmp > diff --git a/lib/igt_syncobj.c b/lib/igt_syncobj.c > new file mode 100644 > index 000..5caef2a > --- /dev/null > +++ b/lib/igt_syncobj.c > @@ -0,0 +1,207 @@ > +/* > + * Copyright © 2017 Intel Corporation > + * > + * Permission is hereby granted, free of charge, to any person obtaining a > + * copy of this software and associated documentation files (the "Software"), > + * to deal in the Software without restriction, including without limitation > + * the rights to use, copy, modify, merge, publish, distribute, sublicense, > + * and/or sell copies of the Software, and to permit persons to whom the > + * Software is furnished to do so, subject to the following conditions: > + * > + * The above copyright notice and this permission notice (including the next > + * paragraph) shall be included in all copies or substantial portions of the > + * Software. > + * > + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR > + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, > + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL > + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER > + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING > + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER > DEALINGS > + * IN THE SOFTWARE. > + */ > + > +#include > +#include > + > +#include "igt.h" > +#include "igt_syncobj.h" > + > +static int > +__syncobj_create(int fd, uint32_t *handle, uint32_t flags) > +{ > + struct drm_syncobj_create create = { 0 }; > + int err = 0; > + > + create.flags = flags; > + if (drmIoctl(fd, DRM_IOCTL_SYNCOBJ_CREATE, )) > + err = -errno; > + *handle = create.handle; > + return err; > +} > + > +uint32_t > +syncobj_create(int fd, uint32_t flags) > +{ > + uint32_t handle; > + igt_assert_eq(__syncobj_create(fd, , flags), 0); > + igt_assert(handle); > + return handle; > +} > + > +static int > +__syncobj_destroy(int fd, uint32_t handle) > +{ > + struct drm_syncobj_destroy destroy = { 0 }; > + int err = 0; > + > + destroy.handle = handle; > + if (drmIoctl(fd, DRM_IOCTL_SYNCOBJ_DESTROY, )) > + err = -errno; > + return err; > +} > + > +void > +syncobj_destroy(int fd, uint32_t handle) > +{ > + igt_assert_eq(__syncobj_destroy(fd, handle), 0); > +} > + > +int > +__syncobj_handle_to_fd(int fd, struct drm_syncobj_handle *args) > +{ > + int err = 0; > + if (drmIoctl(fd, DRM_IOCTL_SYNCOBJ_HANDLE_TO_FD, args)) > + err = -errno; > + return err; > +} > + > +int > +syncobj_handle_to_fd(int fd, uint32_t handle, uint32_t flags) > +{ > + struct drm_syncobj_handle args = { 0 }; > + args.handle = handle; > + args.flags = flags; > + igt_assert_eq(__syncobj_handle_to_fd(fd, ), 0); > + igt_assert(args.fd >= 0); > + return args.fd; > +} > + > +int > +__syncobj_fd_to_handle(int fd, struct drm_syncobj_handle *args) > +{ > + int err = 0; > + if (drmIoctl(fd, DRM_IOCTL_SYNCOBJ_FD_TO_HANDLE, args)) > + err = -errno; > + return err; > +} > + > +uint32_t > +syncobj_fd_to_handle(int fd, int syncobj_fd, uint32_t flags) > +{ > + struct drm_syncobj_handle args = { 0 }; > + args.fd = syncobj_fd; > + args.flags = flags; > + igt_assert_eq(__syncobj_fd_to_handle(fd, ), 0); > + igt_assert(args.handle > 0); > + return args.handle; > +} > + > +void > +syncobj_import_sync_file(int fd, uint32_t handle, int sync_file) > +{ > + struct drm_syncobj_handle args = { 0 }; > + args.handle = handle; > + args.fd = sync_file; > + args.flags = DRM_SYNCOBJ_FD_TO_HANDLE_FLAGS_IMPORT_SYNC_FILE; > + igt_assert_eq(__syncobj_fd_to_handle(fd, ), 0); > +} > + > +int > +__syncobj_wait(int fd, struct local_syncobj_wait *args) > +{ > + int err = 0; > + if (drmIoctl(fd, LOCAL_IOCTL_SYNCOBJ_WAIT, args)) > + err = -errno; > + return err; > +} > + > +int > +syncobj_wait_err(int fd, uint32_t *handles, uint32_t count, > +
[Intel-gfx] [PATCH i-g-t 1/4] lib: Add some syncobj helpers (v2)
Signed-off-by: Jason Ekstrand--- lib/Makefile.sources | 2 + lib/igt_syncobj.c| 207 +++ lib/igt_syncobj.h| 71 ++ 3 files changed, 280 insertions(+) create mode 100644 lib/igt_syncobj.c create mode 100644 lib/igt_syncobj.h diff --git a/lib/Makefile.sources b/lib/Makefile.sources index 53fdb54..692fe30 100644 --- a/lib/Makefile.sources +++ b/lib/Makefile.sources @@ -83,6 +83,8 @@ lib_source_list = \ uwildmat/uwildmat.c \ igt_kmod.c \ igt_kmod.h \ + igt_syncobj.c \ + igt_syncobj.h \ $(NULL) .PHONY: version.h.tmp diff --git a/lib/igt_syncobj.c b/lib/igt_syncobj.c new file mode 100644 index 000..5caef2a --- /dev/null +++ b/lib/igt_syncobj.c @@ -0,0 +1,207 @@ +/* + * Copyright © 2017 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include +#include + +#include "igt.h" +#include "igt_syncobj.h" + +static int +__syncobj_create(int fd, uint32_t *handle, uint32_t flags) +{ + struct drm_syncobj_create create = { 0 }; + int err = 0; + + create.flags = flags; + if (drmIoctl(fd, DRM_IOCTL_SYNCOBJ_CREATE, )) + err = -errno; + *handle = create.handle; + return err; +} + +uint32_t +syncobj_create(int fd, uint32_t flags) +{ + uint32_t handle; + igt_assert_eq(__syncobj_create(fd, , flags), 0); + igt_assert(handle); + return handle; +} + +static int +__syncobj_destroy(int fd, uint32_t handle) +{ + struct drm_syncobj_destroy destroy = { 0 }; + int err = 0; + + destroy.handle = handle; + if (drmIoctl(fd, DRM_IOCTL_SYNCOBJ_DESTROY, )) + err = -errno; + return err; +} + +void +syncobj_destroy(int fd, uint32_t handle) +{ + igt_assert_eq(__syncobj_destroy(fd, handle), 0); +} + +int +__syncobj_handle_to_fd(int fd, struct drm_syncobj_handle *args) +{ + int err = 0; + if (drmIoctl(fd, DRM_IOCTL_SYNCOBJ_HANDLE_TO_FD, args)) + err = -errno; + return err; +} + +int +syncobj_handle_to_fd(int fd, uint32_t handle, uint32_t flags) +{ + struct drm_syncobj_handle args = { 0 }; + args.handle = handle; + args.flags = flags; + igt_assert_eq(__syncobj_handle_to_fd(fd, ), 0); + igt_assert(args.fd >= 0); + return args.fd; +} + +int +__syncobj_fd_to_handle(int fd, struct drm_syncobj_handle *args) +{ + int err = 0; + if (drmIoctl(fd, DRM_IOCTL_SYNCOBJ_FD_TO_HANDLE, args)) + err = -errno; + return err; +} + +uint32_t +syncobj_fd_to_handle(int fd, int syncobj_fd, uint32_t flags) +{ + struct drm_syncobj_handle args = { 0 }; + args.fd = syncobj_fd; + args.flags = flags; + igt_assert_eq(__syncobj_fd_to_handle(fd, ), 0); + igt_assert(args.handle > 0); + return args.handle; +} + +void +syncobj_import_sync_file(int fd, uint32_t handle, int sync_file) +{ + struct drm_syncobj_handle args = { 0 }; + args.handle = handle; + args.fd = sync_file; + args.flags = DRM_SYNCOBJ_FD_TO_HANDLE_FLAGS_IMPORT_SYNC_FILE; + igt_assert_eq(__syncobj_fd_to_handle(fd, ), 0); +} + +int +__syncobj_wait(int fd, struct local_syncobj_wait *args) +{ + int err = 0; + if (drmIoctl(fd, LOCAL_IOCTL_SYNCOBJ_WAIT, args)) + err = -errno; + return err; +} + +int +syncobj_wait_err(int fd, uint32_t *handles, uint32_t count, +uint64_t abs_timeout_nsec, uint32_t flags) +{ + struct local_syncobj_wait wait; + + wait.handles = to_user_pointer(handles); + wait.timeout_nsec = abs_timeout_nsec; + wait.count_handles = count; + wait.flags = flags; + wait.first_signaled = 0; + wait.pad = 0; + + return __syncobj_wait(fd, ); +}
[Intel-gfx] [PATCH i-g-t 1/4] lib: Add some syncobj helpers (v2)
Signed-off-by: Jason Ekstrand--- lib/Makefile.sources | 2 + lib/igt_syncobj.c| 207 +++ lib/igt_syncobj.h| 71 ++ 3 files changed, 280 insertions(+) create mode 100644 lib/igt_syncobj.c create mode 100644 lib/igt_syncobj.h diff --git a/lib/Makefile.sources b/lib/Makefile.sources index 53fdb54..692fe30 100644 --- a/lib/Makefile.sources +++ b/lib/Makefile.sources @@ -83,6 +83,8 @@ lib_source_list = \ uwildmat/uwildmat.c \ igt_kmod.c \ igt_kmod.h \ + igt_syncobj.c \ + igt_syncobj.h \ $(NULL) .PHONY: version.h.tmp diff --git a/lib/igt_syncobj.c b/lib/igt_syncobj.c new file mode 100644 index 000..5caef2a --- /dev/null +++ b/lib/igt_syncobj.c @@ -0,0 +1,207 @@ +/* + * Copyright © 2017 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include +#include + +#include "igt.h" +#include "igt_syncobj.h" + +static int +__syncobj_create(int fd, uint32_t *handle, uint32_t flags) +{ + struct drm_syncobj_create create = { 0 }; + int err = 0; + + create.flags = flags; + if (drmIoctl(fd, DRM_IOCTL_SYNCOBJ_CREATE, )) + err = -errno; + *handle = create.handle; + return err; +} + +uint32_t +syncobj_create(int fd, uint32_t flags) +{ + uint32_t handle; + igt_assert_eq(__syncobj_create(fd, , flags), 0); + igt_assert(handle); + return handle; +} + +static int +__syncobj_destroy(int fd, uint32_t handle) +{ + struct drm_syncobj_destroy destroy = { 0 }; + int err = 0; + + destroy.handle = handle; + if (drmIoctl(fd, DRM_IOCTL_SYNCOBJ_DESTROY, )) + err = -errno; + return err; +} + +void +syncobj_destroy(int fd, uint32_t handle) +{ + igt_assert_eq(__syncobj_destroy(fd, handle), 0); +} + +int +__syncobj_handle_to_fd(int fd, struct drm_syncobj_handle *args) +{ + int err = 0; + if (drmIoctl(fd, DRM_IOCTL_SYNCOBJ_HANDLE_TO_FD, args)) + err = -errno; + return err; +} + +int +syncobj_handle_to_fd(int fd, uint32_t handle, uint32_t flags) +{ + struct drm_syncobj_handle args = { 0 }; + args.handle = handle; + args.flags = flags; + igt_assert_eq(__syncobj_handle_to_fd(fd, ), 0); + igt_assert(args.fd >= 0); + return args.fd; +} + +int +__syncobj_fd_to_handle(int fd, struct drm_syncobj_handle *args) +{ + int err = 0; + if (drmIoctl(fd, DRM_IOCTL_SYNCOBJ_FD_TO_HANDLE, args)) + err = -errno; + return err; +} + +uint32_t +syncobj_fd_to_handle(int fd, int syncobj_fd, uint32_t flags) +{ + struct drm_syncobj_handle args = { 0 }; + args.fd = syncobj_fd; + args.flags = flags; + igt_assert_eq(__syncobj_fd_to_handle(fd, ), 0); + igt_assert(args.handle > 0); + return args.handle; +} + +void +syncobj_import_sync_file(int fd, uint32_t handle, int sync_file) +{ + struct drm_syncobj_handle args = { 0 }; + args.handle = handle; + args.fd = sync_file; + args.flags = DRM_SYNCOBJ_FD_TO_HANDLE_FLAGS_IMPORT_SYNC_FILE; + igt_assert_eq(__syncobj_fd_to_handle(fd, ), 0); +} + +int +__syncobj_wait(int fd, struct local_syncobj_wait *args) +{ + int err = 0; + if (drmIoctl(fd, LOCAL_IOCTL_SYNCOBJ_WAIT, args)) + err = -errno; + return err; +} + +int +syncobj_wait_err(int fd, uint32_t *handles, uint32_t count, +uint64_t abs_timeout_nsec, uint32_t flags) +{ + struct local_syncobj_wait wait; + + wait.handles = to_user_pointer(handles); + wait.timeout_nsec = abs_timeout_nsec; + wait.count_handles = count; + wait.flags = flags; + wait.first_signaled = 0; + wait.pad = 0; + + return __syncobj_wait(fd, ); +}