* [PATCH v1 01/13] lib/sw_sync: Add helper functions for managing synchronization primitives
2016-08-23 17:56 [PATCH v1 00/13] Implement sw_sync test robert.foss
@ 2016-08-23 17:56 ` robert.foss
2016-08-23 22:05 ` [Mesa-dev] " Eric Engestrom
2016-08-23 17:56 ` [PATCH v1 02/13] tests/sw_sync: Add sw_sync test robert.foss
` (13 subsequent siblings)
14 siblings, 1 reply; 24+ messages in thread
From: robert.foss @ 2016-08-23 17:56 UTC (permalink / raw)
To: intel-gfx, mesa-dev, Gustavo Padovan, Daniel Stone,
Daniel Vetter, Marius Vlad
Cc: Gustavo Padovan
From: Robert Foss <robert.foss@collabora.com>
Base functions to help testing the Sync File Framework (explicit fencing
mechanism ported from Android).
These functions allow you to create, use and destroy timelines and fences.
Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
Signed-off-by: Robert Foss <robert.foss@collabora.com>
---
lib/Makefile.sources | 2 +
lib/sw_sync.c | 238 +++++++++++++++++++++++++++++++++++++++++++++++++++
lib/sw_sync.h | 49 +++++++++++
3 files changed, 289 insertions(+)
create mode 100644 lib/sw_sync.c
create mode 100644 lib/sw_sync.h
diff --git a/lib/Makefile.sources b/lib/Makefile.sources
index bac9a7f..3dc7c3c 100644
--- a/lib/Makefile.sources
+++ b/lib/Makefile.sources
@@ -61,6 +61,8 @@ lib_source_list = \
rendercopy_gen8.c \
rendercopy_gen9.c \
rendercopy.h \
+ sw_sync.c \
+ sw_sync.h \
intel_reg_map.c \
intel_iosf.c \
igt_kms.c \
diff --git a/lib/sw_sync.c b/lib/sw_sync.c
new file mode 100644
index 0000000..c4e7d07
--- /dev/null
+++ b/lib/sw_sync.c
@@ -0,0 +1,238 @@
+/*
+ * Copyright 2012 Google, Inc
+ * Copyright © 2016 Collabora, Ltd.
+ *
+ * Based on the implementation from the Android Open Source Project
+ *
+ * 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.
+ *
+ * Authors:
+ * Robert Foss <robert.foss@collabora.com>
+ */
+
+#ifndef ANDROID
+#define _GNU_SOURCE
+#else
+#include <libgen.h>
+#endif
+#include <fcntl.h>
+#include <poll.h>
+#include <stdint.h>
+#include <linux/sync_file.h>
+#include <sys/ioctl.h>
+
+#include "sw_sync.h"
+#include "drmtest.h"
+#include "ioctl_wrappers.h"
+
+#ifndef SW_SYNC_IOC_INC
+struct sw_sync_create_fence_data {
+ __u32 value;
+ char name[32];
+ __s32 fence;
+};
+
+#define SW_SYNC_IOC_MAGIC 'W'
+#define SW_SYNC_IOC_CREATE_FENCE _IOWR(SW_SYNC_IOC_MAGIC, 0,\
+ struct sw_sync_create_fence_data)
+#define SW_SYNC_IOC_INC _IOW(SW_SYNC_IOC_MAGIC, 1, __u32)
+#endif
+
+int sw_sync_fd_is_valid(int fd)
+{
+ int status;
+
+ if (fd == -1)
+ return 0;
+
+ status = fcntl(fd, F_GETFD, 0);
+ return status >= 0;
+}
+
+static
+void sw_sync_fd_close(int fd)
+{
+ if (fd == -1)
+ return;
+
+ if (fcntl(fd, F_GETFD, 0) < 0)
+ return;
+
+ close(fd);
+}
+
+int sw_sync_timeline_create(void)
+{
+ int fd = open("/dev/sw_sync", O_RDWR);
+
+ if (!sw_sync_fd_is_valid(fd))
+ fd = open("/sys/kernel/debug/sync/sw_sync", O_RDWR);
+
+ igt_assert(sw_sync_fd_is_valid(fd));
+
+ return fd;
+}
+
+void sw_sync_timeline_destroy(int fd)
+{
+ return sw_sync_fd_close(fd);
+}
+
+void sw_sync_fence_destroy(int fd)
+{
+ return sw_sync_fd_close(fd);
+}
+
+int sw_sync_fence_create(int fd, int32_t seqno)
+{
+ struct sw_sync_create_fence_data data = {};
+
+ data.value = seqno;
+ if (fd >= 0) {
+ do_ioctl(fd, SW_SYNC_IOC_CREATE_FENCE, &data);
+ return data.fence;
+ } else {
+ do_ioctl_err(fd, SW_SYNC_IOC_CREATE_FENCE, &data, EBADF);
+ return -1;
+ }
+}
+
+void sw_sync_timeline_inc(int fd, uint32_t count)
+{
+ uint32_t arg = count;
+
+ if (fd == 0 || fd == -1)
+ return;
+
+ do_ioctl(fd, SW_SYNC_IOC_INC, &arg);
+}
+
+int sw_sync_merge(int fd1, int fd2)
+{
+ struct sync_merge_data data = {};
+ int err;
+
+ data.fd2 = fd2;
+
+ err = ioctl(fd1, SYNC_IOC_MERGE, &data);
+ if (err < 0)
+ return err;
+
+ sw_sync_fd_is_valid(data.fence);
+
+ return data.fence;
+}
+
+int sw_sync_wait(int fence, int timeout)
+{
+ struct pollfd fds;
+ int ret;
+
+ fds.fd = fence;
+ fds.events = POLLIN | POLLERR;
+
+ ret = poll(&fds, 1, timeout);
+
+ sw_sync_fd_close(fence);
+
+ return ret;
+}
+
+static struct sync_file_info *sync_file_info(int fd)
+{
+ struct sync_file_info *info;
+ struct sync_fence_info *fence_info;
+ int err, num_fences;
+
+ info = malloc(sizeof(*info));
+ if (info == NULL)
+ return NULL;
+
+ memset(info, 0, sizeof(*info));
+ err = ioctl(fd, SYNC_IOC_FILE_INFO, info);
+ if (err < 0) {
+ free(info);
+ return NULL;
+ }
+
+ num_fences = info->num_fences;
+
+ if (num_fences) {
+ info->flags = 0;
+ info->num_fences = num_fences;
+
+ fence_info = calloc(num_fences, sizeof(struct sync_fence_info));
+ if (!fence_info)
+ free(info);
+ return NULL;
+
+ info->sync_fence_info = (uint64_t)(unsigned long) (fence_info);
+
+ err = ioctl(fd, SYNC_IOC_FILE_INFO, info);
+ if (err < 0) {
+ free(fence_info);
+ free(info);
+ return NULL;
+ }
+ }
+
+ return info;
+}
+
+static void sync_file_info_free(struct sync_file_info *info)
+{
+ free((void *)(uintptr_t)info->sync_fence_info);
+ free(info);
+}
+
+int sw_sync_fence_size(int fd)
+{
+ int count;
+ struct sync_file_info *info = sync_file_info(fd);
+
+ if (!info)
+ return 0;
+
+ count = info->num_fences;
+
+ sync_file_info_free(info);
+
+ return count;
+}
+
+int sw_sync_fence_count_with_status(int fd, int status)
+{
+ int i, count = 0;
+ struct sync_fence_info *fenceInfo = NULL;
+ struct sync_file_info *info = sync_file_info(fd);
+
+ if (!info)
+ return -1;
+
+ fenceInfo = (struct sync_fence_info *)(uintptr_t)info->sync_fence_info;
+ for (i = 0 ; i < info->num_fences ; i++) {
+ if (fenceInfo[i].status == status)
+ count++;
+ }
+
+ sync_file_info_free(info);
+
+ return count;
+}
diff --git a/lib/sw_sync.h b/lib/sw_sync.h
new file mode 100644
index 0000000..b179adf
--- /dev/null
+++ b/lib/sw_sync.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2012 Google, Inc
+ * Copyright © 2016 Collabora, Ltd.
+ *
+ * Based on the implementation from the Android Open Source Project
+ *
+ * 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.
+ *
+ * Authors:
+ * Robert Foss <robert.foss@collabora.com>
+ */
+
+#ifndef SW_SYNC_H
+#define SW_SYNC_H
+
+#define SW_SYNC_FENCE_STATUS_ERROR (-1)
+#define SW_SYNC_FENCE_STATUS_ACTIVE (0)
+#define SW_SYNC_FENCE_STATUS_SIGNALED (1)
+
+int sw_sync_fd_is_valid(int fd);
+int sw_sync_timeline_create(void);
+void sw_sync_timeline_destroy(int timeline);
+void sw_sync_fence_destroy(int fence);
+int sw_sync_fence_create(int fd, int32_t seqno);
+void sw_sync_timeline_inc(int fd, uint32_t count);
+int sw_sync_merge(int fd1, int fd2);
+int sw_sync_wait(int fence, int timeout);
+int sw_sync_fence_size(int fd);
+int sw_sync_fence_count_with_status(int fd, int status);
+
+#endif
+
--
2.7.4
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
^ permalink raw reply related [flat|nested] 24+ messages in thread
* Re: [Mesa-dev] [PATCH v1 01/13] lib/sw_sync: Add helper functions for managing synchronization primitives
2016-08-23 17:56 ` [PATCH v1 01/13] lib/sw_sync: Add helper functions for managing synchronization primitives robert.foss
@ 2016-08-23 22:05 ` Eric Engestrom
0 siblings, 0 replies; 24+ messages in thread
From: Eric Engestrom @ 2016-08-23 22:05 UTC (permalink / raw)
To: robert.foss
Cc: Daniel Stone, intel-gfx, Gustavo Padovan, mesa-dev, Gustavo Padovan
On Tue, Aug 23, 2016 at 01:56:03PM -0400, robert.foss@collabora.com wrote:
> From: Robert Foss <robert.foss@collabora.com>
>
> Base functions to help testing the Sync File Framework (explicit fencing
> mechanism ported from Android).
> These functions allow you to create, use and destroy timelines and fences.
>
> Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
> Signed-off-by: Robert Foss <robert.foss@collabora.com>
> ---
> lib/Makefile.sources | 2 +
> lib/sw_sync.c | 238 +++++++++++++++++++++++++++++++++++++++++++++++++++
> lib/sw_sync.h | 49 +++++++++++
> 3 files changed, 289 insertions(+)
> create mode 100644 lib/sw_sync.c
> create mode 100644 lib/sw_sync.h
>
[snip]
> +int sw_sync_fd_is_valid(int fd)
> +{
> + int status;
> +
> + if (fd == -1)
`-1` seems too specific. While open() will return -1 on error, any
negative fd is invalid, so I'd test for `<0` here instead.
> + return 0;
> +
> + status = fcntl(fd, F_GETFD, 0);
> + return status >= 0;
> +}
> +
> +static
> +void sw_sync_fd_close(int fd)
> +{
> + if (fd == -1)
> + return;
> +
> + if (fcntl(fd, F_GETFD, 0) < 0)
> + return;
Why not replace these two tests with a simple
if (sw_sync_fd_is_valid(fd))
> +
> + close(fd);
> +}
> +
> +int sw_sync_timeline_create(void)
> +{
> + int fd = open("/dev/sw_sync", O_RDWR);
> +
> + if (!sw_sync_fd_is_valid(fd))
> + fd = open("/sys/kernel/debug/sync/sw_sync", O_RDWR);
I tend to prefer for hard-coded paths to be in a #define at the top, but
I don't know what the policy for that is in IGT.
> +
> + igt_assert(sw_sync_fd_is_valid(fd));
> +
> + return fd;
> +}
> +
[snip]
> +static struct sync_file_info *sync_file_info(int fd)
> +{
> + struct sync_file_info *info;
> + struct sync_fence_info *fence_info;
> + int err, num_fences;
> +
> + info = malloc(sizeof(*info));
> + if (info == NULL)
> + return NULL;
> +
> + memset(info, 0, sizeof(*info));
You could replace malloc() + memset(0) with calloc(), as you're doing
a few lines below.
> + err = ioctl(fd, SYNC_IOC_FILE_INFO, info);
> + if (err < 0) {
> + free(info);
> + return NULL;
> + }
> +
> + num_fences = info->num_fences;
> +
> + if (num_fences) {
> + info->flags = 0;
> + info->num_fences = num_fences;
> +
> + fence_info = calloc(num_fences, sizeof(struct sync_fence_info));
sizeof(*fence_info)
> + if (!fence_info)
> + free(info);
> + return NULL;
Missing braces
> +
> + info->sync_fence_info = (uint64_t)(unsigned long) (fence_info);
> +
> + err = ioctl(fd, SYNC_IOC_FILE_INFO, info);
> + if (err < 0) {
> + free(fence_info);
> + free(info);
> + return NULL;
> + }
> + }
> +
> + return info;
> +}
[snip]
Cheers,
Eric
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
^ permalink raw reply [flat|nested] 24+ messages in thread
* [PATCH v1 02/13] tests/sw_sync: Add sw_sync test
2016-08-23 17:56 [PATCH v1 00/13] Implement sw_sync test robert.foss
2016-08-23 17:56 ` [PATCH v1 01/13] lib/sw_sync: Add helper functions for managing synchronization primitives robert.foss
@ 2016-08-23 17:56 ` robert.foss
2016-08-23 22:12 ` [Mesa-dev] " Eric Engestrom
2016-08-23 17:56 ` [PATCH v1 03/13] tests/sw_sync: Add subtest test_alloc_fence robert.foss
` (12 subsequent siblings)
14 siblings, 1 reply; 24+ messages in thread
From: robert.foss @ 2016-08-23 17:56 UTC (permalink / raw)
To: intel-gfx, mesa-dev, Gustavo Padovan, Daniel Stone,
Daniel Vetter, Marius Vlad
Cc: Gustavo Padovan
From: Robert Foss <robert.foss@collabora.com>
Add initial tests for sw_sync.
Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
Signed-off-by: Robert Foss <robert.foss@collabora.com>
---
lib/sw_sync.c | 13 ++++++-------
lib/sw_sync.h | 2 +-
tests/Makefile.sources | 1 +
tests/sw_sync.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 59 insertions(+), 8 deletions(-)
create mode 100644 tests/sw_sync.c
diff --git a/lib/sw_sync.c b/lib/sw_sync.c
index c4e7d07..e3d5f85 100644
--- a/lib/sw_sync.c
+++ b/lib/sw_sync.c
@@ -150,8 +150,6 @@ int sw_sync_wait(int fence, int timeout)
ret = poll(&fds, 1, timeout);
- sw_sync_fd_close(fence);
-
return ret;
}
@@ -179,9 +177,10 @@ static struct sync_file_info *sync_file_info(int fd)
info->num_fences = num_fences;
fence_info = calloc(num_fences, sizeof(struct sync_fence_info));
- if (!fence_info)
+ if (!fence_info) {
free(info);
return NULL;
+ }
info->sync_fence_info = (uint64_t)(unsigned long) (fence_info);
@@ -217,18 +216,18 @@ int sw_sync_fence_size(int fd)
return count;
}
-int sw_sync_fence_count_with_status(int fd, int status)
+int sw_sync_fence_count_status(int fd, int status)
{
int i, count = 0;
- struct sync_fence_info *fenceInfo = NULL;
+ struct sync_fence_info *fence_info = NULL;
struct sync_file_info *info = sync_file_info(fd);
if (!info)
return -1;
- fenceInfo = (struct sync_fence_info *)(uintptr_t)info->sync_fence_info;
+ fence_info = (struct sync_fence_info *)(uintptr_t)info->sync_fence_info;
for (i = 0 ; i < info->num_fences ; i++) {
- if (fenceInfo[i].status == status)
+ if (fence_info[i].status == status)
count++;
}
diff --git a/lib/sw_sync.h b/lib/sw_sync.h
index b179adf..1092608 100644
--- a/lib/sw_sync.h
+++ b/lib/sw_sync.h
@@ -43,7 +43,7 @@ void sw_sync_timeline_inc(int fd, uint32_t count);
int sw_sync_merge(int fd1, int fd2);
int sw_sync_wait(int fence, int timeout);
int sw_sync_fence_size(int fd);
-int sw_sync_fence_count_with_status(int fd, int status);
+int sw_sync_fence_count_status(int fd, int status);
#endif
diff --git a/tests/Makefile.sources b/tests/Makefile.sources
index 72a58ad..0ba769f 100644
--- a/tests/Makefile.sources
+++ b/tests/Makefile.sources
@@ -125,6 +125,7 @@ TESTS_progs_M = \
prime_mmap_kms \
prime_self_import \
prime_vgem \
+ sw_sync \
template \
vgem_basic \
vgem_slow \
diff --git a/tests/sw_sync.c b/tests/sw_sync.c
new file mode 100644
index 0000000..d2d4c42
--- /dev/null
+++ b/tests/sw_sync.c
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2012 Google, Inc
+ * Copyright © 2016 Collabora, Ltd.
+ *
+ * Based on the implementation from the Android Open Source Project
+ *
+ * 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.
+ *
+ * Authors:
+ * Robert Foss <robert.foss@collabora.com>
+ */
+
+#include <stdint.h>
+
+#include "sw_sync.h"
+#include "igt.h"
+#include "igt_aux.h"
+
+IGT_TEST_DESCRIPTION("Test SW Sync Framework");
+
+static void test_alloc_timeline(void)
+{
+ int timeline;
+
+ timeline = sw_sync_timeline_create();
+ sw_sync_timeline_destroy(timeline);
+}
+
+igt_main
+{
+ igt_subtest("alloc_timeline")
+ test_alloc_timeline();
+}
+
--
2.7.4
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
^ permalink raw reply related [flat|nested] 24+ messages in thread
* Re: [Mesa-dev] [PATCH v1 02/13] tests/sw_sync: Add sw_sync test
2016-08-23 17:56 ` [PATCH v1 02/13] tests/sw_sync: Add sw_sync test robert.foss
@ 2016-08-23 22:12 ` Eric Engestrom
0 siblings, 0 replies; 24+ messages in thread
From: Eric Engestrom @ 2016-08-23 22:12 UTC (permalink / raw)
To: robert.foss
Cc: Daniel Stone, intel-gfx, Gustavo Padovan, mesa-dev, Gustavo Padovan
On Tue, Aug 23, 2016 at 01:56:04PM -0400, robert.foss@collabora.com wrote:
> From: Robert Foss <robert.foss@collabora.com>
>
> Add initial tests for sw_sync.
>
> Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
> Signed-off-by: Robert Foss <robert.foss@collabora.com>
> ---
> lib/sw_sync.c | 13 ++++++-------
> lib/sw_sync.h | 2 +-
> tests/Makefile.sources | 1 +
> tests/sw_sync.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++
> 4 files changed, 59 insertions(+), 8 deletions(-)
> create mode 100644 tests/sw_sync.c
>
> diff --git a/lib/sw_sync.c b/lib/sw_sync.c
> index c4e7d07..e3d5f85 100644
> --- a/lib/sw_sync.c
> +++ b/lib/sw_sync.c
> @@ -150,8 +150,6 @@ int sw_sync_wait(int fence, int timeout)
>
> ret = poll(&fds, 1, timeout);
>
> - sw_sync_fd_close(fence);
> -
> return ret;
> }
>
> @@ -179,9 +177,10 @@ static struct sync_file_info *sync_file_info(int fd)
> info->num_fences = num_fences;
>
> fence_info = calloc(num_fences, sizeof(struct sync_fence_info));
> - if (!fence_info)
> + if (!fence_info) {
> free(info);
> return NULL;
> + }
Oh, I see you fixed it here.
I would fold all these lib/ hunks from this patch into the previous
patch though, they don't belong in "Add sw_sync test" IMO, and having
them as a separate patch between the two would mean knowingly
introducing bugs in one commit and fixing them in the next.
>
> info->sync_fence_info = (uint64_t)(unsigned long) (fence_info);
>
> @@ -217,18 +216,18 @@ int sw_sync_fence_size(int fd)
> return count;
> }
>
> -int sw_sync_fence_count_with_status(int fd, int status)
> +int sw_sync_fence_count_status(int fd, int status)
> {
> int i, count = 0;
> - struct sync_fence_info *fenceInfo = NULL;
> + struct sync_fence_info *fence_info = NULL;
> struct sync_file_info *info = sync_file_info(fd);
>
> if (!info)
> return -1;
>
> - fenceInfo = (struct sync_fence_info *)(uintptr_t)info->sync_fence_info;
> + fence_info = (struct sync_fence_info *)(uintptr_t)info->sync_fence_info;
> for (i = 0 ; i < info->num_fences ; i++) {
> - if (fenceInfo[i].status == status)
> + if (fence_info[i].status == status)
> count++;
> }
>
> diff --git a/lib/sw_sync.h b/lib/sw_sync.h
> index b179adf..1092608 100644
> --- a/lib/sw_sync.h
> +++ b/lib/sw_sync.h
> @@ -43,7 +43,7 @@ void sw_sync_timeline_inc(int fd, uint32_t count);
> int sw_sync_merge(int fd1, int fd2);
> int sw_sync_wait(int fence, int timeout);
> int sw_sync_fence_size(int fd);
> -int sw_sync_fence_count_with_status(int fd, int status);
> +int sw_sync_fence_count_status(int fd, int status);
>
> #endif
>
> diff --git a/tests/Makefile.sources b/tests/Makefile.sources
> index 72a58ad..0ba769f 100644
> --- a/tests/Makefile.sources
> +++ b/tests/Makefile.sources
> @@ -125,6 +125,7 @@ TESTS_progs_M = \
> prime_mmap_kms \
> prime_self_import \
> prime_vgem \
> + sw_sync \
> template \
> vgem_basic \
> vgem_slow \
> diff --git a/tests/sw_sync.c b/tests/sw_sync.c
> new file mode 100644
> index 0000000..d2d4c42
> --- /dev/null
> +++ b/tests/sw_sync.c
> @@ -0,0 +1,51 @@
> +/*
> + * Copyright 2012 Google, Inc
> + * Copyright © 2016 Collabora, Ltd.
> + *
> + * Based on the implementation from the Android Open Source Project
> + *
> + * 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.
> + *
> + * Authors:
> + * Robert Foss <robert.foss@collabora.com>
> + */
> +
> +#include <stdint.h>
> +
> +#include "sw_sync.h"
> +#include "igt.h"
> +#include "igt_aux.h"
> +
> +IGT_TEST_DESCRIPTION("Test SW Sync Framework");
> +
> +static void test_alloc_timeline(void)
> +{
> + int timeline;
> +
> + timeline = sw_sync_timeline_create();
> + sw_sync_timeline_destroy(timeline);
> +}
> +
> +igt_main
> +{
> + igt_subtest("alloc_timeline")
> + test_alloc_timeline();
> +}
> +
> --
> 2.7.4
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
^ permalink raw reply [flat|nested] 24+ messages in thread
* [PATCH v1 03/13] tests/sw_sync: Add subtest test_alloc_fence
2016-08-23 17:56 [PATCH v1 00/13] Implement sw_sync test robert.foss
2016-08-23 17:56 ` [PATCH v1 01/13] lib/sw_sync: Add helper functions for managing synchronization primitives robert.foss
2016-08-23 17:56 ` [PATCH v1 02/13] tests/sw_sync: Add sw_sync test robert.foss
@ 2016-08-23 17:56 ` robert.foss
2016-08-23 17:56 ` [PATCH v1 04/13] tests/sw_sync: Add subtest test_alloc_fence_invalid_timeline robert.foss
` (11 subsequent siblings)
14 siblings, 0 replies; 24+ messages in thread
From: robert.foss @ 2016-08-23 17:56 UTC (permalink / raw)
To: intel-gfx, mesa-dev, Gustavo Padovan, Daniel Stone,
Daniel Vetter, Marius Vlad
From: Robert Foss <robert.foss@collabora.com>
Add subtest alloc_fence that verifies that it's possible to allocate a fence
on a timeline.
Signed-off-by: Robert Foss <robert.foss@collabora.com>
---
tests/sw_sync.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/tests/sw_sync.c b/tests/sw_sync.c
index d2d4c42..a8c8ca4 100644
--- a/tests/sw_sync.c
+++ b/tests/sw_sync.c
@@ -43,9 +43,25 @@ static void test_alloc_timeline(void)
sw_sync_timeline_destroy(timeline);
}
+static void test_alloc_fence(void)
+{
+ int in_fence;
+ int timeline;
+
+ timeline = sw_sync_timeline_create();
+ in_fence = sw_sync_fence_create(timeline, 0);
+
+ sw_sync_fence_destroy(in_fence);
+ sw_sync_timeline_destroy(timeline);
+}
+
+
igt_main
{
igt_subtest("alloc_timeline")
test_alloc_timeline();
+
+ igt_subtest("alloc_fence")
+ test_alloc_fence();
}
--
2.7.4
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH v1 04/13] tests/sw_sync: Add subtest test_alloc_fence_invalid_timeline
2016-08-23 17:56 [PATCH v1 00/13] Implement sw_sync test robert.foss
` (2 preceding siblings ...)
2016-08-23 17:56 ` [PATCH v1 03/13] tests/sw_sync: Add subtest test_alloc_fence robert.foss
@ 2016-08-23 17:56 ` robert.foss
2016-08-23 17:56 ` [PATCH v1 05/13] tests/sw_sync: Add subtest test_alloc_merge_fence robert.foss
` (10 subsequent siblings)
14 siblings, 0 replies; 24+ messages in thread
From: robert.foss @ 2016-08-23 17:56 UTC (permalink / raw)
To: intel-gfx, mesa-dev, Gustavo Padovan, Daniel Stone,
Daniel Vetter, Marius Vlad
From: Robert Foss <robert.foss@collabora.com>
This subtests tests that creating fences on negative timelines fail.
Signed-off-by: Robert Foss <robert.foss@collabora.com>
---
tests/sw_sync.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/tests/sw_sync.c b/tests/sw_sync.c
index a8c8ca4..102647d 100644
--- a/tests/sw_sync.c
+++ b/tests/sw_sync.c
@@ -55,6 +55,10 @@ static void test_alloc_fence(void)
sw_sync_timeline_destroy(timeline);
}
+static void test_alloc_fence_invalid_timeline(void)
+{
+ sw_sync_fence_create(-1, 0);
+}
igt_main
{
@@ -63,5 +67,8 @@ igt_main
igt_subtest("alloc_fence")
test_alloc_fence();
+
+ igt_subtest("alloc_fence_invalid_timeline")
+ test_alloc_fence_invalid_timeline();
}
--
2.7.4
_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH v1 05/13] tests/sw_sync: Add subtest test_alloc_merge_fence
2016-08-23 17:56 [PATCH v1 00/13] Implement sw_sync test robert.foss
` (3 preceding siblings ...)
2016-08-23 17:56 ` [PATCH v1 04/13] tests/sw_sync: Add subtest test_alloc_fence_invalid_timeline robert.foss
@ 2016-08-23 17:56 ` robert.foss
2016-08-23 17:56 ` [PATCH v1 06/13] tests/sw_sync: Add subtest test_sync_wait robert.foss
` (9 subsequent siblings)
14 siblings, 0 replies; 24+ messages in thread
From: robert.foss @ 2016-08-23 17:56 UTC (permalink / raw)
To: intel-gfx, mesa-dev, Gustavo Padovan, Daniel Stone,
Daniel Vetter, Marius Vlad
From: Robert Foss <robert.foss@collabora.com>
This subtest verifies that merging two fences works in the simples possible
case.
Signed-off-by: Robert Foss <robert.foss@collabora.com>
---
tests/sw_sync.c | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/tests/sw_sync.c b/tests/sw_sync.c
index 102647d..851430e 100644
--- a/tests/sw_sync.c
+++ b/tests/sw_sync.c
@@ -60,6 +60,26 @@ static void test_alloc_fence_invalid_timeline(void)
sw_sync_fence_create(-1, 0);
}
+static void test_alloc_merge_fence(void)
+{
+ int in_fence[2];
+ int fence_merge;
+ int timeline[2];
+
+ timeline[0] = sw_sync_timeline_create();
+ timeline[1] = sw_sync_timeline_create();
+
+ in_fence[0] = sw_sync_fence_create(timeline[0], 1);
+ in_fence[1] = sw_sync_fence_create(timeline[1], 1);
+ fence_merge = sw_sync_merge(in_fence[1], in_fence[0]);
+
+ sw_sync_fence_destroy(in_fence[0]);
+ sw_sync_fence_destroy(in_fence[1]);
+ sw_sync_fence_destroy(fence_merge);
+ sw_sync_timeline_destroy(timeline[0]);
+ sw_sync_timeline_destroy(timeline[1]);
+}
+
igt_main
{
igt_subtest("alloc_timeline")
@@ -70,5 +90,8 @@ igt_main
igt_subtest("alloc_fence_invalid_timeline")
test_alloc_fence_invalid_timeline();
+
+ igt_subtest("alloc_merge_fence")
+ test_alloc_merge_fence();
}
--
2.7.4
_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH v1 06/13] tests/sw_sync: Add subtest test_sync_wait
2016-08-23 17:56 [PATCH v1 00/13] Implement sw_sync test robert.foss
` (4 preceding siblings ...)
2016-08-23 17:56 ` [PATCH v1 05/13] tests/sw_sync: Add subtest test_alloc_merge_fence robert.foss
@ 2016-08-23 17:56 ` robert.foss
2016-08-23 17:56 ` [PATCH v1 07/13] tests/sw_sync: Add subtest test_sync_merge robert.foss
` (8 subsequent siblings)
14 siblings, 0 replies; 24+ messages in thread
From: robert.foss @ 2016-08-23 17:56 UTC (permalink / raw)
To: intel-gfx, mesa-dev, Gustavo Padovan, Daniel Stone,
Daniel Vetter, Marius Vlad
From: Robert Foss <robert.foss@collabora.com>
This subtest verifies that waiting on fences works properly.
Signed-off-by: Robert Foss <robert.foss@collabora.com>
---
tests/sw_sync.c | 38 ++++++++++++++++++++++++++++++++++++++
1 file changed, 38 insertions(+)
diff --git a/tests/sw_sync.c b/tests/sw_sync.c
index 851430e..07e9638 100644
--- a/tests/sw_sync.c
+++ b/tests/sw_sync.c
@@ -80,6 +80,41 @@ static void test_alloc_merge_fence(void)
sw_sync_timeline_destroy(timeline[1]);
}
+static void test_sync_wait(void)
+{
+ int fence, ret;
+ int timeline;
+
+ timeline = sw_sync_timeline_create();
+ fence = sw_sync_fence_create(timeline, 5);
+
+ /* Wait on fence until timeout */
+ ret = sw_sync_wait(fence, 0);
+ igt_assert_f(ret == 0, "Failure waiting on fence until timeout\n");
+
+ /* Advance timeline from 0 -> 1 */
+ sw_sync_timeline_inc(timeline, 1);
+
+ /* Wait on fence until timeout */
+ ret = sw_sync_wait(fence, 0);
+ igt_assert_f(ret == 0, "Failure waiting on fence until timeout\n");
+
+ /* Signal the fence */
+ sw_sync_timeline_inc(timeline, 4);
+
+ /* Wait successfully */
+ ret = sw_sync_wait(fence, 0);
+ igt_assert_f(ret > 0, "Failure waiting on fence\n");
+
+ /* Go even further, and confirm wait still succeeds */
+ sw_sync_timeline_inc(timeline, 10);
+ ret = sw_sync_wait(fence, 0);
+ igt_assert_f(ret > 0, "Failure waiting ahead\n");
+
+ sw_sync_fence_destroy(fence);
+ sw_sync_timeline_destroy(timeline);
+}
+
igt_main
{
igt_subtest("alloc_timeline")
@@ -93,5 +128,8 @@ igt_main
igt_subtest("alloc_merge_fence")
test_alloc_merge_fence();
+
+ igt_subtest("sync_wait")
+ test_sync_wait();
}
--
2.7.4
_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH v1 07/13] tests/sw_sync: Add subtest test_sync_merge
2016-08-23 17:56 [PATCH v1 00/13] Implement sw_sync test robert.foss
` (5 preceding siblings ...)
2016-08-23 17:56 ` [PATCH v1 06/13] tests/sw_sync: Add subtest test_sync_wait robert.foss
@ 2016-08-23 17:56 ` robert.foss
2016-08-23 17:56 ` [PATCH v1 08/13] tests/sw_sync: Add subtest test_sync_merge_same robert.foss
` (7 subsequent siblings)
14 siblings, 0 replies; 24+ messages in thread
From: robert.foss @ 2016-08-23 17:56 UTC (permalink / raw)
To: intel-gfx, mesa-dev, Gustavo Padovan, Daniel Stone,
Daniel Vetter, Marius Vlad
From: Robert Foss <robert.foss@collabora.com>
Add subtest test_sync_merge that tests merging fences and the validity of the
resulting merged fence.
Signed-off-by: Robert Foss <robert.foss@collabora.com>
---
tests/sw_sync.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 67 insertions(+)
diff --git a/tests/sw_sync.c b/tests/sw_sync.c
index 07e9638..00ac44b 100644
--- a/tests/sw_sync.c
+++ b/tests/sw_sync.c
@@ -115,6 +115,70 @@ static void test_sync_wait(void)
sw_sync_timeline_destroy(timeline);
}
+static void test_sync_merge(void)
+{
+ int in_fence[3];
+ int fence_merge;
+ int timeline;
+ int active, signaled;
+
+ timeline = sw_sync_timeline_create();
+ in_fence[0] = sw_sync_fence_create(timeline, 1);
+ in_fence[1] = sw_sync_fence_create(timeline, 2);
+ in_fence[2] = sw_sync_fence_create(timeline, 3);
+
+ fence_merge = sw_sync_merge(in_fence[0], in_fence[1]);
+ fence_merge = sw_sync_merge(in_fence[2], fence_merge);
+
+ /* confirm all fences have one active point (even d) */
+ active = sw_sync_fence_count_status(in_fence[0],
+ SW_SYNC_FENCE_STATUS_ACTIVE);
+ igt_assert_f(active == 1, "in_fence[0] has too many active fences\n");
+ active = sw_sync_fence_count_status(in_fence[1],
+ SW_SYNC_FENCE_STATUS_ACTIVE);
+ igt_assert_f(active == 1, "in_fence[1] has too many active fences\n");
+ active = sw_sync_fence_count_status(in_fence[2],
+ SW_SYNC_FENCE_STATUS_ACTIVE);
+ igt_assert_f(active == 1, "in_fence[2] has too many active fences\n");
+ active = sw_sync_fence_count_status(fence_merge,
+ SW_SYNC_FENCE_STATUS_ACTIVE);
+ igt_assert_f(active == 1, "fence_merge has too many active fences\n");
+
+ /* confirm that fence_merge is not signaled until the max of fence 0,1,2 */
+ sw_sync_timeline_inc(timeline, 1);
+ signaled = sw_sync_fence_count_status(in_fence[0],
+ SW_SYNC_FENCE_STATUS_SIGNALED);
+ active = sw_sync_fence_count_status(fence_merge,
+ SW_SYNC_FENCE_STATUS_ACTIVE);
+ igt_assert_f(signaled == 1, "in_fence[0] did not signal\n");
+ igt_assert_f(active == 1, "fence_merge signaled too early\n");
+
+ sw_sync_timeline_inc(timeline, 1);
+ signaled = sw_sync_fence_count_status(in_fence[1],
+ SW_SYNC_FENCE_STATUS_SIGNALED);
+ active = sw_sync_fence_count_status(fence_merge,
+ SW_SYNC_FENCE_STATUS_ACTIVE);
+ igt_assert_f(signaled == 1, "in_fence[1] did not signal\n");
+ igt_assert_f(active == 1, "fence_merge signaled too early\n");
+
+ sw_sync_timeline_inc(timeline, 1);
+ signaled = sw_sync_fence_count_status(in_fence[2],
+ SW_SYNC_FENCE_STATUS_SIGNALED);
+ igt_assert_f(signaled == 1, "in_fence[2] did not signal\n");
+ signaled = sw_sync_fence_count_status(fence_merge,
+ SW_SYNC_FENCE_STATUS_SIGNALED);
+ active = sw_sync_fence_count_status(fence_merge,
+ SW_SYNC_FENCE_STATUS_ACTIVE);
+ igt_assert_f(active == 0 && signaled == 1,
+ "fence_merge did not signal\n");
+
+ sw_sync_fence_destroy(in_fence[0]);
+ sw_sync_fence_destroy(in_fence[1]);
+ sw_sync_fence_destroy(in_fence[2]);
+ sw_sync_fence_destroy(fence_merge);
+ sw_sync_timeline_destroy(timeline);
+}
+
igt_main
{
igt_subtest("alloc_timeline")
@@ -131,5 +195,8 @@ igt_main
igt_subtest("sync_wait")
test_sync_wait();
+
+ igt_subtest("sync_merge")
+ test_sync_merge();
}
--
2.7.4
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH v1 08/13] tests/sw_sync: Add subtest test_sync_merge_same
2016-08-23 17:56 [PATCH v1 00/13] Implement sw_sync test robert.foss
` (6 preceding siblings ...)
2016-08-23 17:56 ` [PATCH v1 07/13] tests/sw_sync: Add subtest test_sync_merge robert.foss
@ 2016-08-23 17:56 ` robert.foss
2016-08-23 17:56 ` [PATCH v1 09/13] tests/sw_sync: Add subtest test_sync_multi_consumer robert.foss
` (6 subsequent siblings)
14 siblings, 0 replies; 24+ messages in thread
From: robert.foss @ 2016-08-23 17:56 UTC (permalink / raw)
To: intel-gfx, mesa-dev, Gustavo Padovan, Daniel Stone,
Daniel Vetter, Marius Vlad
From: Robert Foss <robert.foss@collabora.com>
This subtest verifies merging a fence with itself does not fail.
Signed-off-by: Robert Foss <robert.foss@collabora.com>
---
tests/sw_sync.c | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/tests/sw_sync.c b/tests/sw_sync.c
index 00ac44b..db03f48 100644
--- a/tests/sw_sync.c
+++ b/tests/sw_sync.c
@@ -179,6 +179,30 @@ static void test_sync_merge(void)
sw_sync_timeline_destroy(timeline);
}
+static void test_sync_merge_same(void)
+{
+ int in_fence[2];
+ int timeline;
+ int signaled;
+
+ timeline = sw_sync_timeline_create();
+ in_fence[0] = sw_sync_fence_create(timeline, 1);
+ in_fence[1] = sw_sync_merge(in_fence[0], in_fence[0]);
+
+ signaled = sw_sync_fence_count_status(in_fence[0],
+ SW_SYNC_FENCE_STATUS_SIGNALED);
+ igt_assert_f(signaled == 0, "fence signaled too early\n");
+
+ sw_sync_timeline_inc(timeline, 1);
+ signaled = sw_sync_fence_count_status(in_fence[0],
+ SW_SYNC_FENCE_STATUS_SIGNALED);
+ igt_assert_f(signaled == 1, "fence did not signal\n");
+
+ sw_sync_fence_destroy(in_fence[0]);
+ sw_sync_fence_destroy(in_fence[1]);
+ sw_sync_timeline_destroy(timeline);
+}
+
igt_main
{
igt_subtest("alloc_timeline")
@@ -198,5 +222,8 @@ igt_main
igt_subtest("sync_merge")
test_sync_merge();
+
+ igt_subtest("sync_merge_same")
+ test_sync_merge_same();
}
--
2.7.4
_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH v1 09/13] tests/sw_sync: Add subtest test_sync_multi_consumer
2016-08-23 17:56 [PATCH v1 00/13] Implement sw_sync test robert.foss
` (7 preceding siblings ...)
2016-08-23 17:56 ` [PATCH v1 08/13] tests/sw_sync: Add subtest test_sync_merge_same robert.foss
@ 2016-08-23 17:56 ` robert.foss
2016-08-23 17:56 ` [PATCH v1 10/13] tests/sw_sync: Add subtest test_sync_multi_consumer_producer robert.foss
` (5 subsequent siblings)
14 siblings, 0 replies; 24+ messages in thread
From: robert.foss @ 2016-08-23 17:56 UTC (permalink / raw)
To: intel-gfx, mesa-dev, Gustavo Padovan, Daniel Stone,
Daniel Vetter, Marius Vlad
From: Robert Foss <robert.foss@collabora.com>
This subtest verifies the access ordering of multiple consumer threads.
Signed-off-by: Robert Foss <robert.foss@collabora.com>
---
tests/sw_sync.c | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 103 insertions(+)
diff --git a/tests/sw_sync.c b/tests/sw_sync.c
index db03f48..0c9c923 100644
--- a/tests/sw_sync.c
+++ b/tests/sw_sync.c
@@ -27,6 +27,8 @@
* Robert Foss <robert.foss@collabora.com>
*/
+#include <pthread.h>
+#include <semaphore.h>
#include <stdint.h>
#include "sw_sync.h"
@@ -35,6 +37,15 @@
IGT_TEST_DESCRIPTION("Test SW Sync Framework");
+typedef struct {
+ int timeline;
+ uint32_t thread_id;
+ uint32_t nbr_threads;
+ uint32_t nbr_iterations;
+ volatile uint32_t * volatile counter;
+ sem_t *sem;
+} data_t;
+
static void test_alloc_timeline(void)
{
int timeline;
@@ -203,6 +214,95 @@ static void test_sync_merge_same(void)
sw_sync_timeline_destroy(timeline);
}
+static void * test_sync_multi_consumer_thread(void *arg)
+{
+ data_t *data = arg;
+ int thread_id = data->thread_id;
+ int nbr_threads = data->nbr_threads;
+ int timeline = data->timeline;
+ int iterations = data->nbr_iterations;
+ int ret, i;
+
+ for (i = 0; i < iterations; i++) {
+ int next_point = i * nbr_threads + thread_id;
+ int fence = sw_sync_fence_create(timeline, next_point);
+
+ ret = sw_sync_wait(fence, 1000);
+ if (ret <= 0)
+ {
+ return (void *) 1;
+ }
+
+ if (*(data->counter) != next_point)
+ {
+ return (void *) 1;
+ }
+
+ sem_post(data->sem);
+ sw_sync_fence_destroy(fence);
+ }
+ return NULL;
+}
+
+static void test_sync_multi_consumer(void)
+{
+ const uint32_t nbr_threads = 8;
+ const uint32_t nbr_iterations = 1 << 14;
+ data_t data_arr[nbr_threads];
+ pthread_t thread_arr[nbr_threads];
+ sem_t sem;
+ int timeline;
+ volatile uint32_t counter = 0;
+ uintptr_t thread_ret = 0;
+ data_t data;
+ int i, ret;
+
+ sem_init(&sem, 0, 0);
+ timeline = sw_sync_timeline_create();
+
+ data.nbr_iterations = nbr_iterations;
+ data.nbr_threads = nbr_threads;
+ data.counter = &counter;
+ data.timeline = timeline;
+ data.sem = &sem;
+
+ /* Start sync threads. */
+ for (i = 0; i < nbr_threads; i++)
+ {
+ data_arr[i] = data;
+ data_arr[i].thread_id = i;
+ ret = pthread_create(&thread_arr[i], NULL,
+ test_sync_multi_consumer_thread,
+ (void *) &(data_arr[i]));
+ igt_assert_eq(ret, 0);
+ }
+
+ /* Produce 'content'. */
+ for (i = 0; i < nbr_threads * nbr_iterations; i++)
+ {
+ sem_wait(&sem);
+
+ counter++;
+ sw_sync_timeline_inc(timeline, 1);
+ }
+
+ /* Wait for threads to complete. */
+ for (i = 0; i < nbr_threads; i++)
+ {
+ uintptr_t local_thread_ret;
+ pthread_join(thread_arr[i], (void **)&local_thread_ret);
+ thread_ret |= local_thread_ret;
+ }
+
+ sw_sync_timeline_destroy(timeline);
+ sem_destroy(&sem);
+
+ igt_assert_f(counter == nbr_threads * nbr_iterations,
+ "Counter has unexpected value.\n");
+
+ igt_assert_f(thread_ret == 0, "A sync thread reported failure.\n");
+}
+
igt_main
{
igt_subtest("alloc_timeline")
@@ -225,5 +325,8 @@ igt_main
igt_subtest("sync_merge_same")
test_sync_merge_same();
+
+ igt_subtest("sync_multi_consumer")
+ test_sync_multi_consumer();
}
--
2.7.4
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH v1 10/13] tests/sw_sync: Add subtest test_sync_multi_consumer_producer
2016-08-23 17:56 [PATCH v1 00/13] Implement sw_sync test robert.foss
` (8 preceding siblings ...)
2016-08-23 17:56 ` [PATCH v1 09/13] tests/sw_sync: Add subtest test_sync_multi_consumer robert.foss
@ 2016-08-23 17:56 ` robert.foss
2016-08-23 17:56 ` [PATCH v1 11/13] tests/sw_sync: Add subtest test_sync_random_merge robert.foss
` (4 subsequent siblings)
14 siblings, 0 replies; 24+ messages in thread
From: robert.foss @ 2016-08-23 17:56 UTC (permalink / raw)
To: intel-gfx, mesa-dev, Gustavo Padovan, Daniel Stone,
Daniel Vetter, Marius Vlad
From: Robert Foss <robert.foss@collabora.com>
This test verifies that stressing the kernel by creating multiple
consumer/producer threads that wait on a single timeline to be incremented
by another conumer/producer thread does not fail.
And that the order amongst the threads is maintained.
Signed-off-by: Robert Foss <robert.foss@collabora.com>
---
tests/sw_sync.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 83 insertions(+)
diff --git a/tests/sw_sync.c b/tests/sw_sync.c
index 0c9c923..0e67ad5 100644
--- a/tests/sw_sync.c
+++ b/tests/sw_sync.c
@@ -303,6 +303,86 @@ static void test_sync_multi_consumer(void)
igt_assert_f(thread_ret == 0, "A sync thread reported failure.\n");
}
+static void * test_sync_multi_consumer_producer_thread(void *arg)
+{
+ data_t *data = arg;
+ int thread_id = data->thread_id;
+ int nbr_threads = data->nbr_threads;
+ int timeline = data->timeline;
+ int iterations = data->nbr_iterations;
+ int ret, i;
+
+ for (i = 0; i < iterations; i++) {
+ int next_point = i * nbr_threads + thread_id;
+ int fence = sw_sync_fence_create(timeline, next_point);
+
+ ret = sw_sync_wait(fence, 1000);
+ if (ret <= 0)
+ {
+ return (void *) 1;
+ }
+
+ if (*(data->counter) != next_point)
+ {
+ return (void *) 1;
+ }
+
+ (*data->counter)++;
+
+ /* Kick off the next thread. */
+ sw_sync_timeline_inc(timeline, 1);
+
+ sw_sync_fence_destroy(fence);
+ }
+ return NULL;
+}
+
+static void test_sync_multi_consumer_producer(void)
+{
+ const uint32_t nbr_threads = 8;
+ const uint32_t nbr_iterations = 1 << 14;
+ data_t data_arr[nbr_threads];
+ pthread_t thread_arr[nbr_threads];
+ int timeline;
+ volatile uint32_t counter = 0;
+ uintptr_t thread_ret = 0;
+ data_t data;
+ int i, ret;
+
+ timeline = sw_sync_timeline_create();
+
+ data.nbr_iterations = nbr_iterations;
+ data.nbr_threads = nbr_threads;
+ data.counter = &counter;
+ data.timeline = timeline;
+
+ /* Start consumer threads. */
+ for (i = 0; i < nbr_threads; i++)
+ {
+ data_arr[i] = data;
+ data_arr[i].thread_id = i;
+ ret = pthread_create(&thread_arr[i], NULL,
+ test_sync_multi_consumer_producer_thread,
+ (void *) &(data_arr[i]));
+ igt_assert_eq(ret, 0);
+ }
+
+ /* Wait for threads to complete. */
+ for (i = 0; i < nbr_threads; i++)
+ {
+ uintptr_t local_thread_ret;
+ pthread_join(thread_arr[i], (void **)&local_thread_ret);
+ thread_ret |= local_thread_ret;
+ }
+
+ sw_sync_timeline_destroy(timeline);
+
+ igt_assert_f(counter == nbr_threads * nbr_iterations,
+ "Counter has unexpected value.\n");
+
+ igt_assert_f(thread_ret == 0, "A sync thread reported failure.\n");
+}
+
igt_main
{
igt_subtest("alloc_timeline")
@@ -328,5 +408,8 @@ igt_main
igt_subtest("sync_multi_consumer")
test_sync_multi_consumer();
+
+ igt_subtest("sync_multi_consumer_producer")
+ test_sync_multi_consumer_producer();
}
--
2.7.4
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH v1 11/13] tests/sw_sync: Add subtest test_sync_random_merge
2016-08-23 17:56 [PATCH v1 00/13] Implement sw_sync test robert.foss
` (9 preceding siblings ...)
2016-08-23 17:56 ` [PATCH v1 10/13] tests/sw_sync: Add subtest test_sync_multi_consumer_producer robert.foss
@ 2016-08-23 17:56 ` robert.foss
2016-08-23 22:38 ` Eric Engestrom
2016-08-23 17:56 ` [PATCH v1 12/13] tests/sw_sync: Add subtest test_sync_multi_timeline_wait robert.foss
` (3 subsequent siblings)
14 siblings, 1 reply; 24+ messages in thread
From: robert.foss @ 2016-08-23 17:56 UTC (permalink / raw)
To: intel-gfx, mesa-dev, Gustavo Padovan, Daniel Stone,
Daniel Vetter, Marius Vlad
From: Robert Foss <robert.foss@collabora.com>
This subtest verifies that creating many timelines and merging random fences
from each timeline with eachother results in merged fences that are fully
functional.
Signed-off-by: Robert Foss <robert.foss@collabora.com>
---
tests/sw_sync.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 73 insertions(+)
diff --git a/tests/sw_sync.c b/tests/sw_sync.c
index 0e67ad5..8e5a7c9 100644
--- a/tests/sw_sync.c
+++ b/tests/sw_sync.c
@@ -383,6 +383,76 @@ static void test_sync_multi_consumer_producer(void)
igt_assert_f(thread_ret == 0, "A sync thread reported failure.\n");
}
+static void test_sync_random_merge(void)
+{
+ int i, size, ret;
+ const int nbr_timeline = 32;
+ const int nbr_merge = 1024;
+ int fence_map[nbr_timeline];
+ int timeline_arr[nbr_timeline];
+ int fence, tmpfence, merged;
+ int timeline, timeline_offset, sync_pt;
+
+ srand(time(NULL));
+
+ for (i = 0; i < nbr_timeline; i++)
+ timeline_arr[i] = sw_sync_timeline_create();
+
+ memset(fence_map, -1, sizeof(fence_map));
+
+ sync_pt = rand();
+ fence = sw_sync_fence_create(timeline_arr[0], sync_pt);
+
+ fence_map[0] = sync_pt;
+
+ /* Randomly create syncpoints out of a fixed set of timelines,
+ * and merge them together.
+ */
+ for (i = 0; i < nbr_merge; i++) {
+ /* Generate syncpoint. */
+ timeline_offset = rand() % nbr_timeline;
+ timeline = timeline_arr[timeline_offset];
+ sync_pt = rand();
+
+ /* Keep track of the latest sync_pt in each timeline. */
+ if (fence_map[timeline_offset] == -1)
+ fence_map[timeline_offset] = sync_pt;
+ else if (fence_map[timeline_offset] < sync_pt)
+ fence_map[timeline_offset] = sync_pt;
+
+ /* Merge. */
+ tmpfence = sw_sync_fence_create(timeline, sync_pt);
+ merged = sw_sync_merge(tmpfence, fence);
+ sw_sync_fence_destroy(tmpfence);
+ sw_sync_fence_destroy(fence);
+ fence = merged;
+ }
+
+ size = 0;
+ for (i = 0; i < nbr_timeline; i++)
+ if (fence_map[i] != -1)
+ size++;
+
+ /* Trigger the merged fence. */
+ for (i = 0; i < nbr_timeline; i++) {
+ if (fence_map[i] != -1) {
+ ret = sw_sync_wait(fence, 0);
+ igt_assert_f(ret == 0,
+ "Failure waiting on fence until timeout\n");
+ /* Increment the timeline to the last sync_pt */
+ sw_sync_timeline_inc(timeline_arr[i], fence_map[i]);
+ }
+ }
+
+ /* Check that the fence is triggered. */
+ ret = sw_sync_wait(fence, 0);
+ igt_assert_f(ret > 0, "Failure triggering fence\n");
+
+ sw_sync_fence_destroy(fence);
+ for (i = 0; i < nbr_timeline; i++)
+ sw_sync_timeline_destroy(timeline_arr[i]);
+}
+
igt_main
{
igt_subtest("alloc_timeline")
@@ -411,5 +481,8 @@ igt_main
igt_subtest("sync_multi_consumer_producer")
test_sync_multi_consumer_producer();
+
+ igt_subtest("sync_random_merge")
+ test_sync_random_merge();
}
--
2.7.4
_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev
^ permalink raw reply related [flat|nested] 24+ messages in thread
* Re: [PATCH v1 11/13] tests/sw_sync: Add subtest test_sync_random_merge
2016-08-23 17:56 ` [PATCH v1 11/13] tests/sw_sync: Add subtest test_sync_random_merge robert.foss
@ 2016-08-23 22:38 ` Eric Engestrom
0 siblings, 0 replies; 24+ messages in thread
From: Eric Engestrom @ 2016-08-23 22:38 UTC (permalink / raw)
To: robert.foss; +Cc: Daniel Stone, intel-gfx, Gustavo Padovan, mesa-dev
On Tue, Aug 23, 2016 at 01:56:13PM -0400, robert.foss@collabora.com wrote:
> From: Robert Foss <robert.foss@collabora.com>
>
> This subtest verifies that creating many timelines and merging random fences
> from each timeline with eachother results in merged fences that are fully
> functional.
>
> Signed-off-by: Robert Foss <robert.foss@collabora.com>
> ---
> tests/sw_sync.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 73 insertions(+)
>
> diff --git a/tests/sw_sync.c b/tests/sw_sync.c
> index 0e67ad5..8e5a7c9 100644
> --- a/tests/sw_sync.c
> +++ b/tests/sw_sync.c
> @@ -383,6 +383,76 @@ static void test_sync_multi_consumer_producer(void)
> igt_assert_f(thread_ret == 0, "A sync thread reported failure.\n");
> }
>
> +static void test_sync_random_merge(void)
> +{
> + int i, size, ret;
> + const int nbr_timeline = 32;
> + const int nbr_merge = 1024;
> + int fence_map[nbr_timeline];
> + int timeline_arr[nbr_timeline];
> + int fence, tmpfence, merged;
> + int timeline, timeline_offset, sync_pt;
> +
> + srand(time(NULL));
> +
> + for (i = 0; i < nbr_timeline; i++)
> + timeline_arr[i] = sw_sync_timeline_create();
> +
> + memset(fence_map, -1, sizeof(fence_map));
This sets each byte to -1, which happens to be the same as an int -1,
but I don't really like it: this is only true for two special values, -1
and 0, and would become a bug if it was ever changed.
I'd much prefer if you simply set:
fence_map[i] = -1;
in the loop you already have just above.
BTW, seeing how many times you set and test for -1 as the "invalid fd
sentinel", how about a:
#define INVALID_FD (-1)
and use that token throughout the code? I think it would improve
readability as well
> +
> + sync_pt = rand();
> + fence = sw_sync_fence_create(timeline_arr[0], sync_pt);
> +
> + fence_map[0] = sync_pt;
> +
> + /* Randomly create syncpoints out of a fixed set of timelines,
> + * and merge them together.
> + */
> + for (i = 0; i < nbr_merge; i++) {
> + /* Generate syncpoint. */
> + timeline_offset = rand() % nbr_timeline;
> + timeline = timeline_arr[timeline_offset];
> + sync_pt = rand();
> +
> + /* Keep track of the latest sync_pt in each timeline. */
> + if (fence_map[timeline_offset] == -1)
> + fence_map[timeline_offset] = sync_pt;
> + else if (fence_map[timeline_offset] < sync_pt)
> + fence_map[timeline_offset] = sync_pt;
> +
> + /* Merge. */
> + tmpfence = sw_sync_fence_create(timeline, sync_pt);
> + merged = sw_sync_merge(tmpfence, fence);
> + sw_sync_fence_destroy(tmpfence);
> + sw_sync_fence_destroy(fence);
> + fence = merged;
> + }
> +
> + size = 0;
> + for (i = 0; i < nbr_timeline; i++)
> + if (fence_map[i] != -1)
> + size++;
> +
> + /* Trigger the merged fence. */
> + for (i = 0; i < nbr_timeline; i++) {
> + if (fence_map[i] != -1) {
> + ret = sw_sync_wait(fence, 0);
> + igt_assert_f(ret == 0,
> + "Failure waiting on fence until timeout\n");
> + /* Increment the timeline to the last sync_pt */
> + sw_sync_timeline_inc(timeline_arr[i], fence_map[i]);
> + }
> + }
> +
> + /* Check that the fence is triggered. */
> + ret = sw_sync_wait(fence, 0);
> + igt_assert_f(ret > 0, "Failure triggering fence\n");
> +
> + sw_sync_fence_destroy(fence);
> + for (i = 0; i < nbr_timeline; i++)
> + sw_sync_timeline_destroy(timeline_arr[i]);
> +}
> +
> igt_main
> {
> igt_subtest("alloc_timeline")
> @@ -411,5 +481,8 @@ igt_main
>
> igt_subtest("sync_multi_consumer_producer")
> test_sync_multi_consumer_producer();
> +
> + igt_subtest("sync_random_merge")
> + test_sync_random_merge();
> }
>
> --
> 2.7.4
_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev
^ permalink raw reply [flat|nested] 24+ messages in thread
* [PATCH v1 12/13] tests/sw_sync: Add subtest test_sync_multi_timeline_wait
2016-08-23 17:56 [PATCH v1 00/13] Implement sw_sync test robert.foss
` (10 preceding siblings ...)
2016-08-23 17:56 ` [PATCH v1 11/13] tests/sw_sync: Add subtest test_sync_random_merge robert.foss
@ 2016-08-23 17:56 ` robert.foss
2016-08-23 17:56 ` [PATCH v1 13/13] tests/sw_sync: Add subtest test_sync_multi_producer_single_consumer robert.foss
` (2 subsequent siblings)
14 siblings, 0 replies; 24+ messages in thread
From: robert.foss @ 2016-08-23 17:56 UTC (permalink / raw)
To: intel-gfx, mesa-dev, Gustavo Padovan, Daniel Stone,
Daniel Vetter, Marius Vlad
From: Robert Foss <robert.foss@collabora.com>
This subtest verifies that waiting, timing out on a wait and that counting
fences in various states works.
Signed-off-by: Robert Foss <robert.foss@collabora.com>
---
tests/sw_sync.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 66 insertions(+)
diff --git a/tests/sw_sync.c b/tests/sw_sync.c
index 8e5a7c9..9ff5088 100644
--- a/tests/sw_sync.c
+++ b/tests/sw_sync.c
@@ -214,6 +214,69 @@ static void test_sync_merge_same(void)
sw_sync_timeline_destroy(timeline);
}
+static void test_sync_multi_timeline_wait(void)
+{
+ int timeline[3];
+ int in_fence[3];
+ int fence_merge;
+ int active, signaled, ret;
+
+ timeline[0] = sw_sync_timeline_create();
+ timeline[1] = sw_sync_timeline_create();
+ timeline[2] = sw_sync_timeline_create();
+
+ in_fence[0] = sw_sync_fence_create(timeline[0], 5);
+ in_fence[1] = sw_sync_fence_create(timeline[1], 5);
+ in_fence[2] = sw_sync_fence_create(timeline[2], 5);
+
+ fence_merge = sw_sync_merge(in_fence[0], in_fence[1]);
+ fence_merge = sw_sync_merge(in_fence[2], fence_merge);
+
+ /* Confirm fence isn't signaled */
+ active = sw_sync_fence_count_status(fence_merge,
+ SW_SYNC_FENCE_STATUS_ACTIVE);
+ igt_assert_f(active == 3, "Fence signaled too early\n");
+
+ ret = sw_sync_wait(fence_merge, 0);
+ igt_assert_f(ret == 0, "Failure waiting on fence until timeout\n");
+
+ sw_sync_timeline_inc(timeline[0], 5);
+ active = sw_sync_fence_count_status(fence_merge,
+ SW_SYNC_FENCE_STATUS_ACTIVE);
+ signaled = sw_sync_fence_count_status(fence_merge,
+ SW_SYNC_FENCE_STATUS_SIGNALED);
+ igt_assert_f(active == 2 && signaled == 1,
+ "Fence did not signal properly\n");
+
+ sw_sync_timeline_inc(timeline[1], 5);
+ active = sw_sync_fence_count_status(fence_merge,
+ SW_SYNC_FENCE_STATUS_ACTIVE);
+ signaled = sw_sync_fence_count_status(fence_merge,
+ SW_SYNC_FENCE_STATUS_SIGNALED);
+ igt_assert_f(active == 1 && signaled == 2,
+ "Fence did not signal properly\n");
+
+ sw_sync_timeline_inc(timeline[2], 5);
+ active = sw_sync_fence_count_status(fence_merge,
+ SW_SYNC_FENCE_STATUS_ACTIVE);
+ signaled = sw_sync_fence_count_status(fence_merge,
+ SW_SYNC_FENCE_STATUS_SIGNALED);
+ igt_assert_f(active == 0 && signaled == 3,
+ "Fence did not signal properly\n");
+
+ /* confirm you can successfully wait */
+ ret = sw_sync_wait(fence_merge, 100);
+ igt_assert_f(ret > 0, "Failure waiting on signaled fence\n");
+
+ sw_sync_fence_destroy(in_fence[0]);
+ sw_sync_fence_destroy(in_fence[1]);
+ sw_sync_fence_destroy(in_fence[2]);
+ sw_sync_fence_destroy(fence_merge);
+ sw_sync_timeline_destroy(timeline[0]);
+ sw_sync_timeline_destroy(timeline[1]);
+ sw_sync_timeline_destroy(timeline[2]);
+}
+
static void * test_sync_multi_consumer_thread(void *arg)
{
data_t *data = arg;
@@ -476,6 +539,9 @@ igt_main
igt_subtest("sync_merge_same")
test_sync_merge_same();
+ igt_subtest("sync_multi_timeline_wait")
+ test_sync_multi_timeline_wait();
+
igt_subtest("sync_multi_consumer")
test_sync_multi_consumer();
--
2.7.4
_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH v1 13/13] tests/sw_sync: Add subtest test_sync_multi_producer_single_consumer
2016-08-23 17:56 [PATCH v1 00/13] Implement sw_sync test robert.foss
` (11 preceding siblings ...)
2016-08-23 17:56 ` [PATCH v1 12/13] tests/sw_sync: Add subtest test_sync_multi_timeline_wait robert.foss
@ 2016-08-23 17:56 ` robert.foss
2016-08-23 22:56 ` [Mesa-dev] [PATCH v1 00/13] Implement sw_sync test Eric Engestrom
2016-08-24 6:01 ` Daniel Vetter
14 siblings, 0 replies; 24+ messages in thread
From: robert.foss @ 2016-08-23 17:56 UTC (permalink / raw)
To: intel-gfx, mesa-dev, Gustavo Padovan, Daniel Stone,
Daniel Vetter, Marius Vlad
From: Robert Foss <robert.foss@collabora.com>
This subtest runs a single consumer thread and multiple producer thread that
are synchronized using multiple timelines.
Signed-off-by: Robert Foss <robert.foss@collabora.com>
---
tests/sw_sync.c | 139 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 139 insertions(+)
diff --git a/tests/sw_sync.c b/tests/sw_sync.c
index 9ff5088..2accdee 100644
--- a/tests/sw_sync.c
+++ b/tests/sw_sync.c
@@ -446,6 +446,142 @@ static void test_sync_multi_consumer_producer(void)
igt_assert_f(thread_ret == 0, "A sync thread reported failure.\n");
}
+static int test_mspc_wait_on_fence(int fence)
+{
+ int error, active;
+
+ do {
+ error = sw_sync_fence_count_status(fence,
+ SW_SYNC_FENCE_STATUS_ERROR);
+ igt_assert_f(error == 0, "Error occurred on fence\n");
+ active = sw_sync_fence_count_status(fence,
+ SW_SYNC_FENCE_STATUS_ACTIVE);
+ } while (active);
+
+ return 0;
+}
+
+static struct {
+ int iterations;
+ int threads;
+ int counter;
+ int cons_timeline;
+ int *prod_timeline;
+ pthread_mutex_t lock;
+} test_mpsc_data;
+
+static int mpsc_producer_thread(void *d)
+{
+ int id = (long)d;
+ int fence, i;
+ int *prod_timeline = test_mpsc_data.prod_timeline;
+ int cons_timeline = test_mpsc_data.cons_timeline;
+ int iterations = test_mpsc_data.iterations;
+
+ for (i = 0; i < iterations; i++) {
+ fence = sw_sync_fence_create(cons_timeline, i);
+
+ /* Wait for the consumer to finish. Use alternate
+ * means of waiting on the fence
+ */
+ if ((iterations + id) % 8 != 0) {
+ igt_assert_f(sw_sync_wait(fence, -1) > 0,
+ "Failure waiting on fence\n");
+ } else {
+ igt_assert_f(test_mspc_wait_on_fence(fence) == 0,
+ "Failure waiting on fence\n");
+ }
+
+ /* Every producer increments the counter, the consumer
+ * checks and erases it
+ */
+ pthread_mutex_lock(&test_mpsc_data.lock);
+ test_mpsc_data.counter++;
+ pthread_mutex_unlock(&test_mpsc_data.lock);
+
+ sw_sync_timeline_inc(prod_timeline[id], 1);
+ sw_sync_fence_destroy(fence);
+ }
+
+ return 0;
+}
+
+static int mpsc_consumer_thread(void)
+{
+ int fence, merged, tmp, it, i;
+ int *prod_timeline = test_mpsc_data.prod_timeline;
+ int cons_timeline = test_mpsc_data.cons_timeline;
+ int iterations = test_mpsc_data.iterations;
+ int n = test_mpsc_data.threads;
+
+ for (it = 1; it <= iterations; it++) {
+ fence = sw_sync_fence_create(prod_timeline[0], it);
+ for (i = 1; i < n; i++) {
+ tmp = sw_sync_fence_create(prod_timeline[i], it);
+ merged = sw_sync_merge(tmp, fence);
+ sw_sync_fence_destroy(tmp);
+ sw_sync_fence_destroy(fence);
+ fence = merged;
+ }
+
+ /* Make sure we see an increment from every producer thread.
+ * Vary the means by which we wait.
+ */
+ if (iterations % 8 != 0) {
+ igt_assert_f(sw_sync_wait(fence, -1) == 0,
+ "Producers did not increment as expected\n");
+ } else {
+ igt_assert_f(test_mspc_wait_on_fence(fence) == 0,
+ "Failure waiting on fence\n");
+ }
+
+ igt_assert_f(test_mpsc_data.counter == n * it,
+ "Counter value mismatch\n");
+
+ /* Release the producer threads */
+ sw_sync_timeline_inc(cons_timeline, 1);
+ sw_sync_fence_destroy(fence);
+ }
+
+ return 0;
+}
+
+/* IMPORTANT NOTE: if you see this test failing on your system, it may be
+ * due to a shortage of file descriptors. Please ensure your system has
+ * a sensible limit for this test to finish correctly.
+ */
+static void test_sync_multi_producer_single_consumer(void)
+{
+ int iterations = 1 << 12;
+ int n = 5;
+ int prod_timeline[n];
+ int cons_timeline;
+ pthread_t threads[n];
+ long i;
+
+ cons_timeline = sw_sync_timeline_create();
+ for (i = 0; i < n; i++)
+ prod_timeline[i] = sw_sync_timeline_create();
+
+ test_mpsc_data.prod_timeline = prod_timeline;
+ test_mpsc_data.cons_timeline = cons_timeline;
+ test_mpsc_data.iterations = iterations;
+ test_mpsc_data.threads = n;
+ test_mpsc_data.counter = 0;
+ pthread_mutex_init(&test_mpsc_data.lock, NULL);
+
+ for (i = 0; i < n; i++) {
+ pthread_create(&threads[i], NULL, (void * (*)(void *))
+ mpsc_producer_thread,
+ (void *)i);
+ }
+
+ mpsc_consumer_thread();
+
+ for (i = 0; i < n; i++)
+ pthread_join(threads[i], NULL);
+}
+
static void test_sync_random_merge(void)
{
int i, size, ret;
@@ -548,6 +684,9 @@ igt_main
igt_subtest("sync_multi_consumer_producer")
test_sync_multi_consumer_producer();
+ igt_subtest("sync_multi_producer_single_consumer")
+ test_sync_multi_producer_single_consumer();
+
igt_subtest("sync_random_merge")
test_sync_random_merge();
}
--
2.7.4
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
^ permalink raw reply related [flat|nested] 24+ messages in thread
* Re: [Mesa-dev] [PATCH v1 00/13] Implement sw_sync test
2016-08-23 17:56 [PATCH v1 00/13] Implement sw_sync test robert.foss
` (12 preceding siblings ...)
2016-08-23 17:56 ` [PATCH v1 13/13] tests/sw_sync: Add subtest test_sync_multi_producer_single_consumer robert.foss
@ 2016-08-23 22:56 ` Eric Engestrom
2016-08-24 20:27 ` Robert Foss
2016-08-24 6:01 ` Daniel Vetter
14 siblings, 1 reply; 24+ messages in thread
From: Eric Engestrom @ 2016-08-23 22:56 UTC (permalink / raw)
To: robert.foss; +Cc: Daniel Stone, intel-gfx, Gustavo Padovan, mesa-dev
On Tue, Aug 23, 2016 at 01:56:02PM -0400, robert.foss@collabora.com wrote:
> From: Robert Foss <robert.foss@collabora.com>
>
> This series implements the sw_sync test and the lib/sw_sync helper functions
> for said test.
>
> Gustavo Padovans sw_sync series was just de-staged in
> gregkh-staging/staging-next [1], and this test is targeted at verifying the
> functionality implemented in that series.
>
> The sw_sync subtests range from very basic tests of the sw_sync functionality,
> to stress testing and randomized tests.
>
> [1] http://git.kernel.org/cgit/linux/kernel/git/gregkh/staging.git/
>
> Robert Foss (13):
> lib/sw_sync: Add helper functions for managing synchronization
> primitives
> tests/sw_sync: Add sw_sync test
> tests/sw_sync: Add subtest test_alloc_fence
> tests/sw_sync: Add subtest test_alloc_fence_invalid_timeline
> tests/sw_sync: Add subtest test_alloc_merge_fence
> tests/sw_sync: Add subtest test_sync_wait
> tests/sw_sync: Add subtest test_sync_merge
> tests/sw_sync: Add subtest test_sync_merge_same
> tests/sw_sync: Add subtest test_sync_multi_consumer
> tests/sw_sync: Add subtest test_sync_multi_consumer_producer
> tests/sw_sync: Add subtest test_sync_random_merge
> tests/sw_sync: Add subtest test_sync_multi_timeline_wait
> tests/sw_sync: Add subtest test_sync_multi_producer_single_consumer
>
> lib/Makefile.sources | 2 +
> lib/sw_sync.c | 237 +++++++++++++++++
> lib/sw_sync.h | 49 ++++
> tests/Makefile.sources | 1 +
> tests/sw_sync.c | 693 +++++++++++++++++++++++++++++++++++++++++++++++++
> 5 files changed, 982 insertions(+)
> create mode 100644 lib/sw_sync.c
> create mode 100644 lib/sw_sync.h
> create mode 100644 tests/sw_sync.c
>
> --
> 2.7.4
Thanks for your work!
I sent some specific comments directly to a few patches, but everything
else looks good to me.
With the issues raised in patches 1 & 2 fixed (and with or without my
suggestions), the whole series is:
Reviewed-by: Eric Engestrom <eric@engestrom.ch>
Cheers,
Eric
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [Mesa-dev] [PATCH v1 00/13] Implement sw_sync test
2016-08-23 22:56 ` [Mesa-dev] [PATCH v1 00/13] Implement sw_sync test Eric Engestrom
@ 2016-08-24 20:27 ` Robert Foss
0 siblings, 0 replies; 24+ messages in thread
From: Robert Foss @ 2016-08-24 20:27 UTC (permalink / raw)
To: Eric Engestrom; +Cc: Daniel Stone, intel-gfx, Gustavo Padovan, mesa-dev
On 2016-08-23 06:56 PM, Eric Engestrom wrote:
> On Tue, Aug 23, 2016 at 01:56:02PM -0400, robert.foss@collabora.com wrote:
>> From: Robert Foss <robert.foss@collabora.com>
>>
>> This series implements the sw_sync test and the lib/sw_sync helper functions
>> for said test.
>>
>> Gustavo Padovans sw_sync series was just de-staged in
>> gregkh-staging/staging-next [1], and this test is targeted at verifying the
>> functionality implemented in that series.
>>
>> The sw_sync subtests range from very basic tests of the sw_sync functionality,
>> to stress testing and randomized tests.
>>
>> [1] http://git.kernel.org/cgit/linux/kernel/git/gregkh/staging.git/
>>
>> Robert Foss (13):
>> lib/sw_sync: Add helper functions for managing synchronization
>> primitives
>> tests/sw_sync: Add sw_sync test
>> tests/sw_sync: Add subtest test_alloc_fence
>> tests/sw_sync: Add subtest test_alloc_fence_invalid_timeline
>> tests/sw_sync: Add subtest test_alloc_merge_fence
>> tests/sw_sync: Add subtest test_sync_wait
>> tests/sw_sync: Add subtest test_sync_merge
>> tests/sw_sync: Add subtest test_sync_merge_same
>> tests/sw_sync: Add subtest test_sync_multi_consumer
>> tests/sw_sync: Add subtest test_sync_multi_consumer_producer
>> tests/sw_sync: Add subtest test_sync_random_merge
>> tests/sw_sync: Add subtest test_sync_multi_timeline_wait
>> tests/sw_sync: Add subtest test_sync_multi_producer_single_consumer
>>
>> lib/Makefile.sources | 2 +
>> lib/sw_sync.c | 237 +++++++++++++++++
>> lib/sw_sync.h | 49 ++++
>> tests/Makefile.sources | 1 +
>> tests/sw_sync.c | 693 +++++++++++++++++++++++++++++++++++++++++++++++++
>> 5 files changed, 982 insertions(+)
>> create mode 100644 lib/sw_sync.c
>> create mode 100644 lib/sw_sync.h
>> create mode 100644 tests/sw_sync.c
>>
>> --
>> 2.7.4
>
> Thanks for your work!
>
> I sent some specific comments directly to a few patches, but everything
> else looks good to me.
>
> With the issues raised in patches 1 & 2 fixed (and with or without my
> suggestions), the whole series is:
> Reviewed-by: Eric Engestrom <eric@engestrom.ch>
>
> Cheers,
> Eric
>
Thanks for the quick feedback!
All of the suggested changes have been fixed for v2, which is upcoming.
Rob.
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v1 00/13] Implement sw_sync test
2016-08-23 17:56 [PATCH v1 00/13] Implement sw_sync test robert.foss
` (13 preceding siblings ...)
2016-08-23 22:56 ` [Mesa-dev] [PATCH v1 00/13] Implement sw_sync test Eric Engestrom
@ 2016-08-24 6:01 ` Daniel Vetter
2016-08-24 13:51 ` Robert Foss
2016-08-24 20:41 ` Gustavo Padovan
14 siblings, 2 replies; 24+ messages in thread
From: Daniel Vetter @ 2016-08-24 6:01 UTC (permalink / raw)
To: robert.foss; +Cc: Daniel Stone, intel-gfx, Gustavo Padovan, mesa-dev
On Tue, Aug 23, 2016 at 01:56:02PM -0400, robert.foss@collabora.com wrote:
> From: Robert Foss <robert.foss@collabora.com>
>
> This series implements the sw_sync test and the lib/sw_sync helper functions
> for said test.
>
> Gustavo Padovans sw_sync series was just de-staged in
> gregkh-staging/staging-next [1], and this test is targeted at verifying the
> functionality implemented in that series.
>
> The sw_sync subtests range from very basic tests of the sw_sync functionality,
> to stress testing and randomized tests.
>
> [1] http://git.kernel.org/cgit/linux/kernel/git/gregkh/staging.git/
This seems to be patches against igt (but the series is lacking the i-g-t-
subject tag per CONTRIBUTING). I'm ok with that, but I thought the idea
was to merge these testcases into the kernel's selftests? Did the plan
change?
-Daniel
>
> Robert Foss (13):
> lib/sw_sync: Add helper functions for managing synchronization
> primitives
> tests/sw_sync: Add sw_sync test
> tests/sw_sync: Add subtest test_alloc_fence
> tests/sw_sync: Add subtest test_alloc_fence_invalid_timeline
> tests/sw_sync: Add subtest test_alloc_merge_fence
> tests/sw_sync: Add subtest test_sync_wait
> tests/sw_sync: Add subtest test_sync_merge
> tests/sw_sync: Add subtest test_sync_merge_same
> tests/sw_sync: Add subtest test_sync_multi_consumer
> tests/sw_sync: Add subtest test_sync_multi_consumer_producer
> tests/sw_sync: Add subtest test_sync_random_merge
> tests/sw_sync: Add subtest test_sync_multi_timeline_wait
> tests/sw_sync: Add subtest test_sync_multi_producer_single_consumer
>
> lib/Makefile.sources | 2 +
> lib/sw_sync.c | 237 +++++++++++++++++
> lib/sw_sync.h | 49 ++++
> tests/Makefile.sources | 1 +
> tests/sw_sync.c | 693 +++++++++++++++++++++++++++++++++++++++++++++++++
> 5 files changed, 982 insertions(+)
> create mode 100644 lib/sw_sync.c
> create mode 100644 lib/sw_sync.h
> create mode 100644 tests/sw_sync.c
>
> --
> 2.7.4
>
--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v1 00/13] Implement sw_sync test
2016-08-24 6:01 ` Daniel Vetter
@ 2016-08-24 13:51 ` Robert Foss
2016-08-24 20:41 ` Gustavo Padovan
1 sibling, 0 replies; 24+ messages in thread
From: Robert Foss @ 2016-08-24 13:51 UTC (permalink / raw)
To: Daniel Vetter; +Cc: mesa-dev, intel-gfx, Daniel Stone, Gustavo Padovan
On 2016-08-24 02:01 AM, Daniel Vetter wrote:
> On Tue, Aug 23, 2016 at 01:56:02PM -0400, robert.foss@collabora.com wrote:
>> From: Robert Foss <robert.foss@collabora.com>
>>
>> This series implements the sw_sync test and the lib/sw_sync helper functions
>> for said test.
>>
>> Gustavo Padovans sw_sync series was just de-staged in
>> gregkh-staging/staging-next [1], and this test is targeted at verifying the
>> functionality implemented in that series.
>>
>> The sw_sync subtests range from very basic tests of the sw_sync functionality,
>> to stress testing and randomized tests.
>>
>> [1] http://git.kernel.org/cgit/linux/kernel/git/gregkh/staging.git/
>
> This seems to be patches against igt (but the series is lacking the i-g-t-
> subject tag per CONTRIBUTING). I'm ok with that, but I thought the idea
> was to merge these testcases into the kernel's selftests? Did the plan
> change?
> -Daniel
Of course igt should've been added.
I think a some miscommunication must've happened :)
The kernel's selftests already does some of these tests, but apart from
the sw_sync test, more subtests in kms_atomic and another test
(kms_fence) are on scheduled for upstreaming. Since the kernel isn't
really a great place for a testing framework, collecting all of this
functionality in one place might make more sense.
>
>>
>> Robert Foss (13):
>> lib/sw_sync: Add helper functions for managing synchronization
>> primitives
>> tests/sw_sync: Add sw_sync test
>> tests/sw_sync: Add subtest test_alloc_fence
>> tests/sw_sync: Add subtest test_alloc_fence_invalid_timeline
>> tests/sw_sync: Add subtest test_alloc_merge_fence
>> tests/sw_sync: Add subtest test_sync_wait
>> tests/sw_sync: Add subtest test_sync_merge
>> tests/sw_sync: Add subtest test_sync_merge_same
>> tests/sw_sync: Add subtest test_sync_multi_consumer
>> tests/sw_sync: Add subtest test_sync_multi_consumer_producer
>> tests/sw_sync: Add subtest test_sync_random_merge
>> tests/sw_sync: Add subtest test_sync_multi_timeline_wait
>> tests/sw_sync: Add subtest test_sync_multi_producer_single_consumer
>>
>> lib/Makefile.sources | 2 +
>> lib/sw_sync.c | 237 +++++++++++++++++
>> lib/sw_sync.h | 49 ++++
>> tests/Makefile.sources | 1 +
>> tests/sw_sync.c | 693 +++++++++++++++++++++++++++++++++++++++++++++++++
>> 5 files changed, 982 insertions(+)
>> create mode 100644 lib/sw_sync.c
>> create mode 100644 lib/sw_sync.h
>> create mode 100644 tests/sw_sync.c
>>
>> --
>> 2.7.4
>>
>
_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v1 00/13] Implement sw_sync test
2016-08-24 6:01 ` Daniel Vetter
2016-08-24 13:51 ` Robert Foss
@ 2016-08-24 20:41 ` Gustavo Padovan
2016-08-25 6:56 ` Daniel Vetter
1 sibling, 1 reply; 24+ messages in thread
From: Gustavo Padovan @ 2016-08-24 20:41 UTC (permalink / raw)
To: Daniel Vetter; +Cc: mesa-dev, intel-gfx, Daniel Stone
2016-08-24 Daniel Vetter <daniel@ffwll.ch>:
> On Tue, Aug 23, 2016 at 01:56:02PM -0400, robert.foss@collabora.com wrote:
> > From: Robert Foss <robert.foss@collabora.com>
> >
> > This series implements the sw_sync test and the lib/sw_sync helper functions
> > for said test.
> >
> > Gustavo Padovans sw_sync series was just de-staged in
> > gregkh-staging/staging-next [1], and this test is targeted at verifying the
> > functionality implemented in that series.
> >
> > The sw_sync subtests range from very basic tests of the sw_sync functionality,
> > to stress testing and randomized tests.
> >
> > [1] http://git.kernel.org/cgit/linux/kernel/git/gregkh/staging.git/
>
> This seems to be patches against igt (but the series is lacking the i-g-t-
> subject tag per CONTRIBUTING). I'm ok with that, but I thought the idea
> was to merge these testcases into the kernel's selftests? Did the plan
> change?
We still have the tests for kernel's selftests and the plan is to
upstream them but I think getting complete tests explicit fencing
infrastructure in i-g-t is good idea too. We work on more complex tests
in there and leave kselftest with the basic tests from the initial
patchset for the sw_sync kselftest.
Gustavo
_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v1 00/13] Implement sw_sync test
2016-08-24 20:41 ` Gustavo Padovan
@ 2016-08-25 6:56 ` Daniel Vetter
0 siblings, 0 replies; 24+ messages in thread
From: Daniel Vetter @ 2016-08-25 6:56 UTC (permalink / raw)
To: Gustavo Padovan; +Cc: Daniel Stone, intel-gfx, mesa-dev
On Wed, Aug 24, 2016 at 04:41:02PM -0400, Gustavo Padovan wrote:
> 2016-08-24 Daniel Vetter <daniel@ffwll.ch>:
>
> > On Tue, Aug 23, 2016 at 01:56:02PM -0400, robert.foss@collabora.com wrote:
> > > From: Robert Foss <robert.foss@collabora.com>
> > >
> > > This series implements the sw_sync test and the lib/sw_sync helper functions
> > > for said test.
> > >
> > > Gustavo Padovans sw_sync series was just de-staged in
> > > gregkh-staging/staging-next [1], and this test is targeted at verifying the
> > > functionality implemented in that series.
> > >
> > > The sw_sync subtests range from very basic tests of the sw_sync functionality,
> > > to stress testing and randomized tests.
> > >
> > > [1] http://git.kernel.org/cgit/linux/kernel/git/gregkh/staging.git/
> >
> > This seems to be patches against igt (but the series is lacking the i-g-t-
> > subject tag per CONTRIBUTING). I'm ok with that, but I thought the idea
> > was to merge these testcases into the kernel's selftests? Did the plan
> > change?
>
> We still have the tests for kernel's selftests and the plan is to
> upstream them but I think getting complete tests explicit fencing
> infrastructure in i-g-t is good idea too. We work on more complex tests
> in there and leave kselftest with the basic tests from the initial
> patchset for the sw_sync kselftest.
I'm perfectly happy if i-g-t becomes the canonical location for all things
gfx (kernel) testing. Just wondered whether we have a change of plans here
or not.
-Daniel
--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev
^ permalink raw reply [flat|nested] 24+ messages in thread
* [PATCH v1 01/13] lib/sw_sync: Add helper functions for managing synchronization primitives
2016-08-23 17:53 robert.foss
@ 2016-08-23 17:53 ` robert.foss
0 siblings, 0 replies; 24+ messages in thread
From: robert.foss @ 2016-08-23 17:53 UTC (permalink / raw)
To: Gustavo Padovan, Daniel Stone, Daniel Vetter, Marius Vlad
Cc: intel-gfx, Gustavo Padovan
From: Robert Foss <robert.foss@collabora.com>
Base functions to help testing the Sync File Framework (explicit fencing
mechanism ported from Android).
These functions allow you to create, use and destroy timelines and fences.
Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
Signed-off-by: Robert Foss <robert.foss@collabora.com>
---
lib/Makefile.sources | 2 +
lib/sw_sync.c | 238 +++++++++++++++++++++++++++++++++++++++++++++++++++
lib/sw_sync.h | 49 +++++++++++
3 files changed, 289 insertions(+)
create mode 100644 lib/sw_sync.c
create mode 100644 lib/sw_sync.h
diff --git a/lib/Makefile.sources b/lib/Makefile.sources
index bac9a7f..3dc7c3c 100644
--- a/lib/Makefile.sources
+++ b/lib/Makefile.sources
@@ -61,6 +61,8 @@ lib_source_list = \
rendercopy_gen8.c \
rendercopy_gen9.c \
rendercopy.h \
+ sw_sync.c \
+ sw_sync.h \
intel_reg_map.c \
intel_iosf.c \
igt_kms.c \
diff --git a/lib/sw_sync.c b/lib/sw_sync.c
new file mode 100644
index 0000000..c4e7d07
--- /dev/null
+++ b/lib/sw_sync.c
@@ -0,0 +1,238 @@
+/*
+ * Copyright 2012 Google, Inc
+ * Copyright © 2016 Collabora, Ltd.
+ *
+ * Based on the implementation from the Android Open Source Project
+ *
+ * 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.
+ *
+ * Authors:
+ * Robert Foss <robert.foss@collabora.com>
+ */
+
+#ifndef ANDROID
+#define _GNU_SOURCE
+#else
+#include <libgen.h>
+#endif
+#include <fcntl.h>
+#include <poll.h>
+#include <stdint.h>
+#include <linux/sync_file.h>
+#include <sys/ioctl.h>
+
+#include "sw_sync.h"
+#include "drmtest.h"
+#include "ioctl_wrappers.h"
+
+#ifndef SW_SYNC_IOC_INC
+struct sw_sync_create_fence_data {
+ __u32 value;
+ char name[32];
+ __s32 fence;
+};
+
+#define SW_SYNC_IOC_MAGIC 'W'
+#define SW_SYNC_IOC_CREATE_FENCE _IOWR(SW_SYNC_IOC_MAGIC, 0,\
+ struct sw_sync_create_fence_data)
+#define SW_SYNC_IOC_INC _IOW(SW_SYNC_IOC_MAGIC, 1, __u32)
+#endif
+
+int sw_sync_fd_is_valid(int fd)
+{
+ int status;
+
+ if (fd == -1)
+ return 0;
+
+ status = fcntl(fd, F_GETFD, 0);
+ return status >= 0;
+}
+
+static
+void sw_sync_fd_close(int fd)
+{
+ if (fd == -1)
+ return;
+
+ if (fcntl(fd, F_GETFD, 0) < 0)
+ return;
+
+ close(fd);
+}
+
+int sw_sync_timeline_create(void)
+{
+ int fd = open("/dev/sw_sync", O_RDWR);
+
+ if (!sw_sync_fd_is_valid(fd))
+ fd = open("/sys/kernel/debug/sync/sw_sync", O_RDWR);
+
+ igt_assert(sw_sync_fd_is_valid(fd));
+
+ return fd;
+}
+
+void sw_sync_timeline_destroy(int fd)
+{
+ return sw_sync_fd_close(fd);
+}
+
+void sw_sync_fence_destroy(int fd)
+{
+ return sw_sync_fd_close(fd);
+}
+
+int sw_sync_fence_create(int fd, int32_t seqno)
+{
+ struct sw_sync_create_fence_data data = {};
+
+ data.value = seqno;
+ if (fd >= 0) {
+ do_ioctl(fd, SW_SYNC_IOC_CREATE_FENCE, &data);
+ return data.fence;
+ } else {
+ do_ioctl_err(fd, SW_SYNC_IOC_CREATE_FENCE, &data, EBADF);
+ return -1;
+ }
+}
+
+void sw_sync_timeline_inc(int fd, uint32_t count)
+{
+ uint32_t arg = count;
+
+ if (fd == 0 || fd == -1)
+ return;
+
+ do_ioctl(fd, SW_SYNC_IOC_INC, &arg);
+}
+
+int sw_sync_merge(int fd1, int fd2)
+{
+ struct sync_merge_data data = {};
+ int err;
+
+ data.fd2 = fd2;
+
+ err = ioctl(fd1, SYNC_IOC_MERGE, &data);
+ if (err < 0)
+ return err;
+
+ sw_sync_fd_is_valid(data.fence);
+
+ return data.fence;
+}
+
+int sw_sync_wait(int fence, int timeout)
+{
+ struct pollfd fds;
+ int ret;
+
+ fds.fd = fence;
+ fds.events = POLLIN | POLLERR;
+
+ ret = poll(&fds, 1, timeout);
+
+ sw_sync_fd_close(fence);
+
+ return ret;
+}
+
+static struct sync_file_info *sync_file_info(int fd)
+{
+ struct sync_file_info *info;
+ struct sync_fence_info *fence_info;
+ int err, num_fences;
+
+ info = malloc(sizeof(*info));
+ if (info == NULL)
+ return NULL;
+
+ memset(info, 0, sizeof(*info));
+ err = ioctl(fd, SYNC_IOC_FILE_INFO, info);
+ if (err < 0) {
+ free(info);
+ return NULL;
+ }
+
+ num_fences = info->num_fences;
+
+ if (num_fences) {
+ info->flags = 0;
+ info->num_fences = num_fences;
+
+ fence_info = calloc(num_fences, sizeof(struct sync_fence_info));
+ if (!fence_info)
+ free(info);
+ return NULL;
+
+ info->sync_fence_info = (uint64_t)(unsigned long) (fence_info);
+
+ err = ioctl(fd, SYNC_IOC_FILE_INFO, info);
+ if (err < 0) {
+ free(fence_info);
+ free(info);
+ return NULL;
+ }
+ }
+
+ return info;
+}
+
+static void sync_file_info_free(struct sync_file_info *info)
+{
+ free((void *)(uintptr_t)info->sync_fence_info);
+ free(info);
+}
+
+int sw_sync_fence_size(int fd)
+{
+ int count;
+ struct sync_file_info *info = sync_file_info(fd);
+
+ if (!info)
+ return 0;
+
+ count = info->num_fences;
+
+ sync_file_info_free(info);
+
+ return count;
+}
+
+int sw_sync_fence_count_with_status(int fd, int status)
+{
+ int i, count = 0;
+ struct sync_fence_info *fenceInfo = NULL;
+ struct sync_file_info *info = sync_file_info(fd);
+
+ if (!info)
+ return -1;
+
+ fenceInfo = (struct sync_fence_info *)(uintptr_t)info->sync_fence_info;
+ for (i = 0 ; i < info->num_fences ; i++) {
+ if (fenceInfo[i].status == status)
+ count++;
+ }
+
+ sync_file_info_free(info);
+
+ return count;
+}
diff --git a/lib/sw_sync.h b/lib/sw_sync.h
new file mode 100644
index 0000000..b179adf
--- /dev/null
+++ b/lib/sw_sync.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2012 Google, Inc
+ * Copyright © 2016 Collabora, Ltd.
+ *
+ * Based on the implementation from the Android Open Source Project
+ *
+ * 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.
+ *
+ * Authors:
+ * Robert Foss <robert.foss@collabora.com>
+ */
+
+#ifndef SW_SYNC_H
+#define SW_SYNC_H
+
+#define SW_SYNC_FENCE_STATUS_ERROR (-1)
+#define SW_SYNC_FENCE_STATUS_ACTIVE (0)
+#define SW_SYNC_FENCE_STATUS_SIGNALED (1)
+
+int sw_sync_fd_is_valid(int fd);
+int sw_sync_timeline_create(void);
+void sw_sync_timeline_destroy(int timeline);
+void sw_sync_fence_destroy(int fence);
+int sw_sync_fence_create(int fd, int32_t seqno);
+void sw_sync_timeline_inc(int fd, uint32_t count);
+int sw_sync_merge(int fd1, int fd2);
+int sw_sync_wait(int fence, int timeout);
+int sw_sync_fence_size(int fd);
+int sw_sync_fence_count_with_status(int fd, int status);
+
+#endif
+
--
2.7.4
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
^ permalink raw reply related [flat|nested] 24+ messages in thread