From: Kamil Konieczny <kamil.konieczny@linux.intel.com>
To: igt-dev@lists.freedesktop.org
Cc: intel-gfx@lists.freedesktop.org,
Matthew Auld <matthew.auld@intel.com>,
Nirmoy Das <nirmoy.das@intel.com>
Subject: Re: [igt-dev] [PATCH i-g-t 1/2] lib/dmabuf_sync_file: move common stuff into lib
Date: Fri, 2 Dec 2022 11:48:01 +0100 [thread overview]
Message-ID: <Y4nX4VIFCgk3CilX@kamilkon-desk1> (raw)
In-Reply-To: <20221201164944.327019-1-matthew.auld@intel.com>
Hi Matthew,
On 2022-12-01 at 16:49:43 +0000, Matthew Auld wrote:
> So we can use this across different tests.
>
> Signed-off-by: Matthew Auld <matthew.auld@intel.com>
> Cc: Kamil Konieczny <kamil.konieczny@linux.intel.com>
> Cc: Andrzej Hajda <andrzej.hajda@intel.com>
> Cc: Nirmoy Das <nirmoy.das@intel.com>
> ---
> lib/dmabuf_sync_file.c | 138 +++++++++++++++++++++++++++++++++++++++
> lib/dmabuf_sync_file.h | 19 ++++++
> lib/meson.build | 1 +
> tests/dmabuf_sync_file.c | 135 ++------------------------------------
> 4 files changed, 164 insertions(+), 129 deletions(-)
> create mode 100644 lib/dmabuf_sync_file.c
> create mode 100644 lib/dmabuf_sync_file.h
>
> diff --git a/lib/dmabuf_sync_file.c b/lib/dmabuf_sync_file.c
> new file mode 100644
> index 00000000..24e0f96d
> --- /dev/null
> +++ b/lib/dmabuf_sync_file.c
> @@ -0,0 +1,138 @@
> +// SPDX-License-Identifier: MIT
Add also copyright here, like in lib/intel_allocator.c
(I changed year):
/*
* Copyright © 2022 Intel Corporation
*/
> +
> +#ifdef __linux__
> +#include <linux/dma-buf.h>
> +#endif
> +#include <sys/poll.h>
> +
> +#include "igt.h"
> +#include "igt_vgem.h"
> +#include "sw_sync.h"
> +
> +#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)
> +
> +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, &bo);
> +
> + 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, &arg);
> + close(dmabuf);
> + igt_assert(ret == 0 || errno == ENOTTY);
> +
> + return ret == 0;
> +}
> +
> +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, &arg);
> +
> + return arg.fd;
> +}
> +
> +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, &bo);
> +
> + 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, &arg);
> + close(dmabuf);
> + close(fence);
> + igt_assert(ret == 0 || errno == ENOTTY);
> +
> + return ret == 0;
> +}
> +
> +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, &arg);
> +}
> +
> +void
> +dmabuf_import_timeline_fence(int dmabuf, uint32_t flags,
> + int timeline, uint32_t seqno)
> +{
> + int fence;
> +
> + fence = sw_sync_timeline_create_fence(timeline, seqno);
> + dmabuf_import_sync_file(dmabuf, flags, fence);
> + close(fence);
> +}
> +
> +bool dmabuf_busy(int dmabuf, uint32_t flags)
> +{
> + struct pollfd pfd = { .fd = dmabuf };
> +
> + /* If DMA_BUF_SYNC_WRITE is set, we don't want to set POLLIN or
> + * else poll() may return a non-zero value if there are only read
> + * fences because POLLIN is ready even if POLLOUT isn't.
> + */
> + if (flags & DMA_BUF_SYNC_WRITE)
> + pfd.events |= POLLOUT;
> + else if (flags & DMA_BUF_SYNC_READ)
> + pfd.events |= POLLIN;
> +
> + return poll(&pfd, 1, 0) == 0;
> +}
> +
> +bool sync_file_busy(int sync_file)
> +{
> + struct pollfd pfd = { .fd = sync_file, .events = POLLIN };
> + return poll(&pfd, 1, 0) == 0;
> +}
> +
> +bool dmabuf_sync_file_busy(int dmabuf, uint32_t flags)
> +{
> + int sync_file;
> + bool busy;
> +
> + sync_file = dmabuf_export_sync_file(dmabuf, flags);
> + busy = sync_file_busy(sync_file);
> + close(sync_file);
> +
> + return busy;
> +}
> diff --git a/lib/dmabuf_sync_file.h b/lib/dmabuf_sync_file.h
> new file mode 100644
> index 00000000..08da8150
> --- /dev/null
> +++ b/lib/dmabuf_sync_file.h
> @@ -0,0 +1,19 @@
> +/* SPDX-License-Identifier: MIT */
Same here, add copyright.
> +
> +#ifndef DMABUF_SYNC_FILE_H
> +#define DMABUF_SYNC_FILE_H
> +
> +#include <stdbool.h>
> +#include <stdint.h>
> +
> +bool has_dmabuf_export_sync_file(int fd);
> +bool has_dmabuf_import_sync_file(int fd);
> +int dmabuf_export_sync_file(int dmabuf, uint32_t flags);
> +void dmabuf_import_sync_file(int dmabuf, uint32_t flags, int sync_fd);
> +void dmabuf_import_timeline_fence(int dmabuf, uint32_t flags,
> + int timeline, uint32_t seqno);
> +bool dmabuf_busy(int dmabuf, uint32_t flags);
> +bool sync_file_busy(int sync_file);
> +bool dmabuf_sync_file_busy(int dmabuf, uint32_t flags);
> +
> +#endif
> diff --git a/lib/meson.build b/lib/meson.build
> index cef2d0ff..896d5733 100644
> --- a/lib/meson.build
> +++ b/lib/meson.build
> @@ -1,5 +1,6 @@
> lib_sources = [
> 'drmtest.c',
> + 'dmabuf_sync_file.c',
> 'huc_copy.c',
> 'i915/gem.c',
> 'i915/gem_context.c',
> diff --git a/tests/dmabuf_sync_file.c b/tests/dmabuf_sync_file.c
> index 2179a76d..f59be125 100644
> --- a/tests/dmabuf_sync_file.c
> +++ b/tests/dmabuf_sync_file.c
> @@ -1,140 +1,17 @@
> // SPDX-License-Identifier: MIT
Same here, add copyright.
>
> +#ifdef __linux__
> +#include <linux/dma-buf.h>
> +#endif
> +#include <sys/poll.h>
> +
These two includes above should be in dmabuf_sync_file.h
Regards,
Kamil
> #include "igt.h"
> #include "igt_vgem.h"
> #include "sw_sync.h"
> -
> -#include <linux/dma-buf.h>
> -#include <sys/poll.h>
> +#include "dmabuf_sync_file.h"
>
> IGT_TEST_DESCRIPTION("Tests for sync_file support in dma-buf");
>
> -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)
> -
> -static 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, &bo);
> -
> - 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, &arg);
> - close(dmabuf);
> - igt_assert(ret == 0 || errno == ENOTTY);
> -
> - return ret == 0;
> -}
> -
> -static 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, &arg);
> -
> - return arg.fd;
> -}
> -
> -static 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, &bo);
> -
> - 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, &arg);
> - close(dmabuf);
> - close(fence);
> - igt_assert(ret == 0 || errno == ENOTTY);
> -
> - return ret == 0;
> -}
> -
> -static 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, &arg);
> -}
> -
> -static void
> -dmabuf_import_timeline_fence(int dmabuf, uint32_t flags,
> - int timeline, uint32_t seqno)
> -{
> - int fence;
> -
> - fence = sw_sync_timeline_create_fence(timeline, seqno);
> - dmabuf_import_sync_file(dmabuf, flags, fence);
> - close(fence);
> -}
> -
> -static bool dmabuf_busy(int dmabuf, uint32_t flags)
> -{
> - struct pollfd pfd = { .fd = dmabuf };
> -
> - /* If DMA_BUF_SYNC_WRITE is set, we don't want to set POLLIN or
> - * else poll() may return a non-zero value if there are only read
> - * fences because POLLIN is ready even if POLLOUT isn't.
> - */
> - if (flags & DMA_BUF_SYNC_WRITE)
> - pfd.events |= POLLOUT;
> - else if (flags & DMA_BUF_SYNC_READ)
> - pfd.events |= POLLIN;
> -
> - return poll(&pfd, 1, 0) == 0;
> -}
> -
> -static bool sync_file_busy(int sync_file)
> -{
> - struct pollfd pfd = { .fd = sync_file, .events = POLLIN };
> - return poll(&pfd, 1, 0) == 0;
> -}
> -
> -static bool dmabuf_sync_file_busy(int dmabuf, uint32_t flags)
> -{
> - int sync_file;
> - bool busy;
> -
> - sync_file = dmabuf_export_sync_file(dmabuf, flags);
> - busy = sync_file_busy(sync_file);
> - close(sync_file);
> -
> - return busy;
> -}
> -
> static void test_export_basic(int fd)
> {
> struct vgem_bo bo;
> --
> 2.38.1
>
next prev parent reply other threads:[~2022-12-02 10:48 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-01 16:49 [igt-dev] [PATCH i-g-t 1/2] lib/dmabuf_sync_file: move common stuff into lib Matthew Auld
2022-12-01 16:49 ` [igt-dev] [PATCH i-g-t 2/2] tests/i915/gem_exec_balancer: exercise dmabuf import Matthew Auld
2022-12-01 20:00 ` [igt-dev] ✗ Fi.CI.BAT: failure for series starting with [i-g-t,1/2] lib/dmabuf_sync_file: move common stuff into lib Patchwork
2022-12-01 21:08 ` [igt-dev] ✓ Fi.CI.BAT: success for series starting with [i-g-t,1/2] lib/dmabuf_sync_file: move common stuff into lib (rev2) Patchwork
2022-12-02 9:50 ` [igt-dev] [PATCH i-g-t 1/2] lib/dmabuf_sync_file: move common stuff into lib Petri Latvala
2022-12-02 10:48 ` Kamil Konieczny [this message]
2022-12-02 11:44 ` [igt-dev] ✓ Fi.CI.IGT: success for series starting with [i-g-t,1/2] lib/dmabuf_sync_file: move common stuff into lib (rev2) Patchwork
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=Y4nX4VIFCgk3CilX@kamilkon-desk1 \
--to=kamil.konieczny@linux.intel.com \
--cc=igt-dev@lists.freedesktop.org \
--cc=intel-gfx@lists.freedesktop.org \
--cc=matthew.auld@intel.com \
--cc=nirmoy.das@intel.com \
/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