Re: [Intel-gfx] [PATCH i-g-t v2 1/2] lib/dmabuf_sync_file: move common stuff into lib
Hi Matt, On 2022-12-05 at 17:11:44 +, Matthew Auld wrote: > On 05/12/2022 16:31, Kamil Konieczny wrote: > > Hi Matt, > > > > after re-reading I have few more nits. > > > > On 2022-12-02 at 12:02:41 +, Matthew Auld wrote: > > > So we can use this across different tests. > > > > > > v2 > > >- Add docs for everything (Petri) > > >- Add missing copyright and fix headers slightly (Kamil) > > > > > > Signed-off-by: Matthew Auld > > > Cc: Kamil Konieczny > > > Cc: Petri Latvala > > > Cc: Andrzej Hajda > > > Cc: Nirmoy Das > > > --- > > > .../igt-gpu-tools/igt-gpu-tools-docs.xml | 1 + > > > lib/dmabuf_sync_file.c| 211 ++ > > > lib/dmabuf_sync_file.h| 26 +++ > > > lib/meson.build | 1 + > > > tests/dmabuf_sync_file.c | 133 +-- > > > 5 files changed, 243 insertions(+), 129 deletions(-) > > > create mode 100644 lib/dmabuf_sync_file.c > > > create mode 100644 lib/dmabuf_sync_file.h > > > > > > diff --git a/docs/reference/igt-gpu-tools/igt-gpu-tools-docs.xml > > > b/docs/reference/igt-gpu-tools/igt-gpu-tools-docs.xml > > > index 1ce842f4..102c8a89 100644 > > > --- a/docs/reference/igt-gpu-tools/igt-gpu-tools-docs.xml > > > +++ b/docs/reference/igt-gpu-tools/igt-gpu-tools-docs.xml > > > @@ -15,6 +15,7 @@ > > > > > > API Reference > > > + > > > > > > > > > > > > diff --git a/lib/dmabuf_sync_file.c b/lib/dmabuf_sync_file.c > > > new file mode 100644 > > > index ..bcce2486 > > > --- /dev/null > > > +++ b/lib/dmabuf_sync_file.c > > > @@ -0,0 +1,211 @@ > > > +// SPDX-License-Identifier: MIT > > > +/* > > > + * Copyright © 2022 Intel Corporation > > > + */ > > > + > > > +#include "igt.h" > > > +#include "igt_vgem.h" > > > +#include "sw_sync.h" > > > + > > > +#include "dmabuf_sync_file.h" > > > + > > > +/** > > > + * SECTION: dmabuf_sync_file > > > + * @short_description: DMABUF importing/exporting fencing support library > > > + * @title: DMABUF Sync File > > > + * @include: dmabuf_sync_file.h > > > + */ > > > + > > > +struct igt_dma_buf_sync_file { > > > + __u32 flags; > > > + __s32 fd; > > > +}; > > > + > > > +#define IGT_DMA_BUF_IOCTL_EXPORT_SYNC_FILE _IOWR(DMA_BUF_BASE, 2, struct > > > igt_dma_buf_sync_file) > > > +#define IGT_DMA_BUF_IOCTL_IMPORT_SYNC_FILE _IOW(DMA_BUF_BASE, 3, struct > > > igt_dma_buf_sync_file) > > > + > > > +/** > > > + * has_dmabuf_export_sync_file: > > > + * @fd: The open drm fd > > > + * > > > + * Check if the kernel supports exporting a sync file from dmabuf. > > > + */ > > > +bool has_dmabuf_export_sync_file(int fd) > > > +{ > > > + struct vgem_bo bo; > > > + int dmabuf, ret; > > > + struct igt_dma_buf_sync_file arg; > > > + > > > + bo.width = 1; > > > + bo.height = 1; > > > + bo.bpp = 32; > > > + vgem_create(fd, ); > > > + > > > + dmabuf = prime_handle_to_fd(fd, bo.handle); > > > + gem_close(fd, bo.handle); > > > + > > > + arg.flags = DMA_BUF_SYNC_WRITE; > > > + arg.fd = -1; > > > + > > > + ret = igt_ioctl(dmabuf, IGT_DMA_BUF_IOCTL_EXPORT_SYNC_FILE, ); > > > + close(dmabuf); > > > + igt_assert(ret == 0 || errno == ENOTTY); > > > > imho we should not explode here, it was ok in test but in lib > > we should just return false in case of unexpected error, you can > > add igt_debug if you think it will help. > > This may lead to change in place where you use it, like > > igt_require(has_dmabuf_export_sync_file(fd)); > > Yup, makes sense. Will fix. > > > > > > + > > > + return ret == 0; > > > +} > > > + > > > +/** > > > + * dmabuf_export_sync_file: > > > + * @dmabuf: The dmabuf fd > > > + * @flags: The flags to control the behaviour > > > + * > > > + * Take a snapshot of the current dma-resv fences in the dmabuf, and > > > export as a > > > + * syncfile. The @flags should at least specify either > > > DMA_BUF_SYNC_WRITE or > > > + * DMA_BUF_SYNC_READ, depending on if we care about the read or write > > > fences. > > > + */ > > > +int dmabuf_export_sync_file(int dmabuf, uint32_t flags) > > > > As you do not check for errors so this should be > > int __dmabuf_export_sync_file(int dmabuf, uint32_t flags) > > do_ioctl() is doing an igt_assert_eq(ioctl(...), 0). Or what do you mean by > not checking for errors? You are right, sorry, I readed it as igt_ioctl so please do not follow my comment here. Regards, Kamil > > > > > > +{ > > > + struct igt_dma_buf_sync_file arg; > > > + > > > + arg.flags = flags; > > > + arg.fd = -1; > > > + do_ioctl(dmabuf, IGT_DMA_BUF_IOCTL_EXPORT_SYNC_FILE, ); > > > + > > > + return arg.fd; > > > +} > > > + > > > +/** > > > + * has_dmabuf_import_sync_file: > > > + * @fd: The open drm fd > > > + * > > > + * Check if the kernel supports importing a sync file into a dmabuf. > > > + */ > > > +bool has_dmabuf_import_sync_file(int fd) > > > +{ > > > + struct vgem_bo bo; > > > + int dmabuf, timeline, fence, ret; > > > + struct igt_dma_buf_sync_file
Re: [Intel-gfx] [PATCH i-g-t v2 1/2] lib/dmabuf_sync_file: move common stuff into lib
On 05/12/2022 16:31, Kamil Konieczny wrote: Hi Matt, after re-reading I have few more nits. On 2022-12-02 at 12:02:41 +, Matthew Auld wrote: So we can use this across different tests. v2 - Add docs for everything (Petri) - Add missing copyright and fix headers slightly (Kamil) Signed-off-by: Matthew Auld Cc: Kamil Konieczny Cc: Petri Latvala Cc: Andrzej Hajda Cc: Nirmoy Das --- .../igt-gpu-tools/igt-gpu-tools-docs.xml | 1 + lib/dmabuf_sync_file.c| 211 ++ lib/dmabuf_sync_file.h| 26 +++ lib/meson.build | 1 + tests/dmabuf_sync_file.c | 133 +-- 5 files changed, 243 insertions(+), 129 deletions(-) create mode 100644 lib/dmabuf_sync_file.c create mode 100644 lib/dmabuf_sync_file.h diff --git a/docs/reference/igt-gpu-tools/igt-gpu-tools-docs.xml b/docs/reference/igt-gpu-tools/igt-gpu-tools-docs.xml index 1ce842f4..102c8a89 100644 --- a/docs/reference/igt-gpu-tools/igt-gpu-tools-docs.xml +++ b/docs/reference/igt-gpu-tools/igt-gpu-tools-docs.xml @@ -15,6 +15,7 @@ API Reference + diff --git a/lib/dmabuf_sync_file.c b/lib/dmabuf_sync_file.c new file mode 100644 index ..bcce2486 --- /dev/null +++ b/lib/dmabuf_sync_file.c @@ -0,0 +1,211 @@ +// SPDX-License-Identifier: MIT +/* + * Copyright © 2022 Intel Corporation + */ + +#include "igt.h" +#include "igt_vgem.h" +#include "sw_sync.h" + +#include "dmabuf_sync_file.h" + +/** + * SECTION: dmabuf_sync_file + * @short_description: DMABUF importing/exporting fencing support library + * @title: DMABUF Sync File + * @include: dmabuf_sync_file.h + */ + +struct igt_dma_buf_sync_file { + __u32 flags; + __s32 fd; +}; + +#define IGT_DMA_BUF_IOCTL_EXPORT_SYNC_FILE _IOWR(DMA_BUF_BASE, 2, struct igt_dma_buf_sync_file) +#define IGT_DMA_BUF_IOCTL_IMPORT_SYNC_FILE _IOW(DMA_BUF_BASE, 3, struct igt_dma_buf_sync_file) + +/** + * has_dmabuf_export_sync_file: + * @fd: The open drm fd + * + * Check if the kernel supports exporting a sync file from dmabuf. + */ +bool has_dmabuf_export_sync_file(int fd) +{ + struct vgem_bo bo; + int dmabuf, ret; + struct igt_dma_buf_sync_file arg; + + bo.width = 1; + bo.height = 1; + bo.bpp = 32; + vgem_create(fd, ); + + dmabuf = prime_handle_to_fd(fd, bo.handle); + gem_close(fd, bo.handle); + + arg.flags = DMA_BUF_SYNC_WRITE; + arg.fd = -1; + + ret = igt_ioctl(dmabuf, IGT_DMA_BUF_IOCTL_EXPORT_SYNC_FILE, ); + close(dmabuf); + igt_assert(ret == 0 || errno == ENOTTY); imho we should not explode here, it was ok in test but in lib we should just return false in case of unexpected error, you can add igt_debug if you think it will help. This may lead to change in place where you use it, like igt_require(has_dmabuf_export_sync_file(fd)); Yup, makes sense. Will fix. + + return ret == 0; +} + +/** + * dmabuf_export_sync_file: + * @dmabuf: The dmabuf fd + * @flags: The flags to control the behaviour + * + * Take a snapshot of the current dma-resv fences in the dmabuf, and export as a + * syncfile. The @flags should at least specify either DMA_BUF_SYNC_WRITE or + * DMA_BUF_SYNC_READ, depending on if we care about the read or write fences. + */ +int dmabuf_export_sync_file(int dmabuf, uint32_t flags) As you do not check for errors so this should be int __dmabuf_export_sync_file(int dmabuf, uint32_t flags) do_ioctl() is doing an igt_assert_eq(ioctl(...), 0). Or what do you mean by not checking for errors? +{ + struct igt_dma_buf_sync_file arg; + + arg.flags = flags; + arg.fd = -1; + do_ioctl(dmabuf, IGT_DMA_BUF_IOCTL_EXPORT_SYNC_FILE, ); + + return arg.fd; +} + +/** + * has_dmabuf_import_sync_file: + * @fd: The open drm fd + * + * Check if the kernel supports importing a sync file into a dmabuf. + */ +bool has_dmabuf_import_sync_file(int fd) +{ + struct vgem_bo bo; + int dmabuf, timeline, fence, ret; + struct igt_dma_buf_sync_file arg; + + bo.width = 1; + bo.height = 1; + bo.bpp = 32; + vgem_create(fd, ); + + dmabuf = prime_handle_to_fd(fd, bo.handle); + gem_close(fd, bo.handle); + + timeline = sw_sync_timeline_create(); + fence = sw_sync_timeline_create_fence(timeline, 1); + sw_sync_timeline_inc(timeline, 1); + + arg.flags = DMA_BUF_SYNC_RW; + arg.fd = fence; + + ret = igt_ioctl(dmabuf, IGT_DMA_BUF_IOCTL_IMPORT_SYNC_FILE, ); + close(dmabuf); + close(fence); + igt_assert(ret == 0 || errno == ENOTTY); Same here, return false instead of assert. + + return ret == 0; +} + +/** + * dmabuf_import_sync_file: + * @dmabuf: The dmabuf fd + * @flags: The flags to control the behaviour + * @sync_fd: The sync file (i.e our fence) to import + * + * Import the sync file @sync_fd, into the dmabuf.
Re: [Intel-gfx] [PATCH i-g-t v2 1/2] lib/dmabuf_sync_file: move common stuff into lib
Hi Matt, after re-reading I have few more nits. On 2022-12-02 at 12:02:41 +, Matthew Auld wrote: > So we can use this across different tests. > > v2 > - Add docs for everything (Petri) > - Add missing copyright and fix headers slightly (Kamil) > > Signed-off-by: Matthew Auld > Cc: Kamil Konieczny > Cc: Petri Latvala > Cc: Andrzej Hajda > Cc: Nirmoy Das > --- > .../igt-gpu-tools/igt-gpu-tools-docs.xml | 1 + > lib/dmabuf_sync_file.c| 211 ++ > lib/dmabuf_sync_file.h| 26 +++ > lib/meson.build | 1 + > tests/dmabuf_sync_file.c | 133 +-- > 5 files changed, 243 insertions(+), 129 deletions(-) > create mode 100644 lib/dmabuf_sync_file.c > create mode 100644 lib/dmabuf_sync_file.h > > diff --git a/docs/reference/igt-gpu-tools/igt-gpu-tools-docs.xml > b/docs/reference/igt-gpu-tools/igt-gpu-tools-docs.xml > index 1ce842f4..102c8a89 100644 > --- a/docs/reference/igt-gpu-tools/igt-gpu-tools-docs.xml > +++ b/docs/reference/igt-gpu-tools/igt-gpu-tools-docs.xml > @@ -15,6 +15,7 @@ > > > API Reference > + > > > > diff --git a/lib/dmabuf_sync_file.c b/lib/dmabuf_sync_file.c > new file mode 100644 > index ..bcce2486 > --- /dev/null > +++ b/lib/dmabuf_sync_file.c > @@ -0,0 +1,211 @@ > +// SPDX-License-Identifier: MIT > +/* > + * Copyright © 2022 Intel Corporation > + */ > + > +#include "igt.h" > +#include "igt_vgem.h" > +#include "sw_sync.h" > + > +#include "dmabuf_sync_file.h" > + > +/** > + * SECTION: dmabuf_sync_file > + * @short_description: DMABUF importing/exporting fencing support library > + * @title: DMABUF Sync File > + * @include: dmabuf_sync_file.h > + */ > + > +struct igt_dma_buf_sync_file { > + __u32 flags; > + __s32 fd; > +}; > + > +#define IGT_DMA_BUF_IOCTL_EXPORT_SYNC_FILE _IOWR(DMA_BUF_BASE, 2, struct > igt_dma_buf_sync_file) > +#define IGT_DMA_BUF_IOCTL_IMPORT_SYNC_FILE _IOW(DMA_BUF_BASE, 3, struct > igt_dma_buf_sync_file) > + > +/** > + * has_dmabuf_export_sync_file: > + * @fd: The open drm fd > + * > + * Check if the kernel supports exporting a sync file from dmabuf. > + */ > +bool has_dmabuf_export_sync_file(int fd) > +{ > + struct vgem_bo bo; > + int dmabuf, ret; > + struct igt_dma_buf_sync_file arg; > + > + bo.width = 1; > + bo.height = 1; > + bo.bpp = 32; > + vgem_create(fd, ); > + > + dmabuf = prime_handle_to_fd(fd, bo.handle); > + gem_close(fd, bo.handle); > + > + arg.flags = DMA_BUF_SYNC_WRITE; > + arg.fd = -1; > + > + ret = igt_ioctl(dmabuf, IGT_DMA_BUF_IOCTL_EXPORT_SYNC_FILE, ); > + close(dmabuf); > + igt_assert(ret == 0 || errno == ENOTTY); imho we should not explode here, it was ok in test but in lib we should just return false in case of unexpected error, you can add igt_debug if you think it will help. This may lead to change in place where you use it, like igt_require(has_dmabuf_export_sync_file(fd)); > + > + return ret == 0; > +} > + > +/** > + * dmabuf_export_sync_file: > + * @dmabuf: The dmabuf fd > + * @flags: The flags to control the behaviour > + * > + * Take a snapshot of the current dma-resv fences in the dmabuf, and export > as a > + * syncfile. The @flags should at least specify either DMA_BUF_SYNC_WRITE or > + * DMA_BUF_SYNC_READ, depending on if we care about the read or write fences. > + */ > +int dmabuf_export_sync_file(int dmabuf, uint32_t flags) As you do not check for errors so this should be int __dmabuf_export_sync_file(int dmabuf, uint32_t flags) > +{ > + struct igt_dma_buf_sync_file arg; > + > + arg.flags = flags; > + arg.fd = -1; > + do_ioctl(dmabuf, IGT_DMA_BUF_IOCTL_EXPORT_SYNC_FILE, ); > + > + return arg.fd; > +} > + > +/** > + * has_dmabuf_import_sync_file: > + * @fd: The open drm fd > + * > + * Check if the kernel supports importing a sync file into a dmabuf. > + */ > +bool has_dmabuf_import_sync_file(int fd) > +{ > + struct vgem_bo bo; > + int dmabuf, timeline, fence, ret; > + struct igt_dma_buf_sync_file arg; > + > + bo.width = 1; > + bo.height = 1; > + bo.bpp = 32; > + vgem_create(fd, ); > + > + dmabuf = prime_handle_to_fd(fd, bo.handle); > + gem_close(fd, bo.handle); > + > + timeline = sw_sync_timeline_create(); > + fence = sw_sync_timeline_create_fence(timeline, 1); > + sw_sync_timeline_inc(timeline, 1); > + > + arg.flags = DMA_BUF_SYNC_RW; > + arg.fd = fence; > + > + ret = igt_ioctl(dmabuf, IGT_DMA_BUF_IOCTL_IMPORT_SYNC_FILE, ); > + close(dmabuf); > + close(fence); > + igt_assert(ret == 0 || errno == ENOTTY); Same here, return false instead of assert. > + > + return ret == 0; > +} > + > +/** > + * dmabuf_import_sync_file: > + * @dmabuf: The dmabuf fd > + * @flags: The flags to control the behaviour > + * @sync_fd: The sync file (i.e our fence) to import > + * > + * Import the sync
[Intel-gfx] [PATCH i-g-t v2 1/2] lib/dmabuf_sync_file: move common stuff into lib
So we can use this across different tests. v2 - Add docs for everything (Petri) - Add missing copyright and fix headers slightly (Kamil) Signed-off-by: Matthew Auld Cc: Kamil Konieczny Cc: Petri Latvala Cc: Andrzej Hajda Cc: Nirmoy Das --- .../igt-gpu-tools/igt-gpu-tools-docs.xml | 1 + lib/dmabuf_sync_file.c| 211 ++ lib/dmabuf_sync_file.h| 26 +++ lib/meson.build | 1 + tests/dmabuf_sync_file.c | 133 +-- 5 files changed, 243 insertions(+), 129 deletions(-) create mode 100644 lib/dmabuf_sync_file.c create mode 100644 lib/dmabuf_sync_file.h diff --git a/docs/reference/igt-gpu-tools/igt-gpu-tools-docs.xml b/docs/reference/igt-gpu-tools/igt-gpu-tools-docs.xml index 1ce842f4..102c8a89 100644 --- a/docs/reference/igt-gpu-tools/igt-gpu-tools-docs.xml +++ b/docs/reference/igt-gpu-tools/igt-gpu-tools-docs.xml @@ -15,6 +15,7 @@ API Reference + diff --git a/lib/dmabuf_sync_file.c b/lib/dmabuf_sync_file.c new file mode 100644 index ..bcce2486 --- /dev/null +++ b/lib/dmabuf_sync_file.c @@ -0,0 +1,211 @@ +// SPDX-License-Identifier: MIT +/* + * Copyright © 2022 Intel Corporation + */ + +#include "igt.h" +#include "igt_vgem.h" +#include "sw_sync.h" + +#include "dmabuf_sync_file.h" + +/** + * SECTION: dmabuf_sync_file + * @short_description: DMABUF importing/exporting fencing support library + * @title: DMABUF Sync File + * @include: dmabuf_sync_file.h + */ + +struct igt_dma_buf_sync_file { + __u32 flags; + __s32 fd; +}; + +#define IGT_DMA_BUF_IOCTL_EXPORT_SYNC_FILE _IOWR(DMA_BUF_BASE, 2, struct igt_dma_buf_sync_file) +#define IGT_DMA_BUF_IOCTL_IMPORT_SYNC_FILE _IOW(DMA_BUF_BASE, 3, struct igt_dma_buf_sync_file) + +/** + * has_dmabuf_export_sync_file: + * @fd: The open drm fd + * + * Check if the kernel supports exporting a sync file from dmabuf. + */ +bool has_dmabuf_export_sync_file(int fd) +{ + struct vgem_bo bo; + int dmabuf, ret; + struct igt_dma_buf_sync_file arg; + + bo.width = 1; + bo.height = 1; + bo.bpp = 32; + vgem_create(fd, ); + + dmabuf = prime_handle_to_fd(fd, bo.handle); + gem_close(fd, bo.handle); + + arg.flags = DMA_BUF_SYNC_WRITE; + arg.fd = -1; + + ret = igt_ioctl(dmabuf, IGT_DMA_BUF_IOCTL_EXPORT_SYNC_FILE, ); + close(dmabuf); + igt_assert(ret == 0 || errno == ENOTTY); + + return ret == 0; +} + +/** + * dmabuf_export_sync_file: + * @dmabuf: The dmabuf fd + * @flags: The flags to control the behaviour + * + * Take a snapshot of the current dma-resv fences in the dmabuf, and export as a + * syncfile. The @flags should at least specify either DMA_BUF_SYNC_WRITE or + * DMA_BUF_SYNC_READ, depending on if we care about the read or write fences. + */ +int dmabuf_export_sync_file(int dmabuf, uint32_t flags) +{ + struct igt_dma_buf_sync_file arg; + + arg.flags = flags; + arg.fd = -1; + do_ioctl(dmabuf, IGT_DMA_BUF_IOCTL_EXPORT_SYNC_FILE, ); + + return arg.fd; +} + +/** + * has_dmabuf_import_sync_file: + * @fd: The open drm fd + * + * Check if the kernel supports importing a sync file into a dmabuf. + */ +bool has_dmabuf_import_sync_file(int fd) +{ + struct vgem_bo bo; + int dmabuf, timeline, fence, ret; + struct igt_dma_buf_sync_file arg; + + bo.width = 1; + bo.height = 1; + bo.bpp = 32; + vgem_create(fd, ); + + dmabuf = prime_handle_to_fd(fd, bo.handle); + gem_close(fd, bo.handle); + + timeline = sw_sync_timeline_create(); + fence = sw_sync_timeline_create_fence(timeline, 1); + sw_sync_timeline_inc(timeline, 1); + + arg.flags = DMA_BUF_SYNC_RW; + arg.fd = fence; + + ret = igt_ioctl(dmabuf, IGT_DMA_BUF_IOCTL_IMPORT_SYNC_FILE, ); + close(dmabuf); + close(fence); + igt_assert(ret == 0 || errno == ENOTTY); + + return ret == 0; +} + +/** + * dmabuf_import_sync_file: + * @dmabuf: The dmabuf fd + * @flags: The flags to control the behaviour + * @sync_fd: The sync file (i.e our fence) to import + * + * Import the sync file @sync_fd, into the dmabuf. The @flags should at least + * specify DMA_BUF_SYNC_WRITE or DMA_BUF_SYNC_READ, depending on if we are + * importing the @sync_fd as a read or write fence. + */ +void dmabuf_import_sync_file(int dmabuf, uint32_t flags, int sync_fd) +{ + struct igt_dma_buf_sync_file arg; + + arg.flags = flags; + arg.fd = sync_fd; + do_ioctl(dmabuf, IGT_DMA_BUF_IOCTL_IMPORT_SYNC_FILE, ); +} + +/** + * dmabuf_import_timeline_fence: + * @dmabuf: The dmabuf fd + * @flags: The flags to control the behaviour + * @timeline: The sync file timeline where the new fence is created + * @seqno: The sequence number to use for the fence + * + * Create a new fence as part of @timeline, and import as a sync file into the + * dmabuf. The @flags