* [PATCH i-g-t v10 01/21] lib/sw_sync: Add helper functions for managing synchronization primitives
2016-12-07 2:51 [PATCH i-g-t v10 00/21] Implement sw_sync test Robert Foss
@ 2016-12-07 2:51 ` Robert Foss
2016-12-07 2:51 ` [PATCH i-g-t v10 02/21] test/sw_sync: Add sw_sync test Robert Foss
` (19 subsequent siblings)
20 siblings, 0 replies; 24+ messages in thread
From: Robert Foss @ 2016-12-07 2:51 UTC (permalink / raw)
To: intel-gfx, Gustavo Padovan, Daniel Stone, Daniel Vetter,
Marius Vlad, Eric Engestrom, Chris Wilson, Tomeu Vizoso
Cc: Gustavo Padovan
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: Robert Foss <robert.foss@collabora.com>
Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
Reviewed-by: Eric Engestrom <eric@engestrom.ch>
Reviewed-by: Tomeu Vizoso <tomeu.vizoso@collabora.com>
---
lib/Makefile.sources | 2 +
lib/sw_sync.c | 196 +++++++++++++++++++++++++++++++++++++++++++++++++++
lib/sw_sync.h | 44 ++++++++++++
3 files changed, 242 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 e8e277bd..7aaf42f8 100644
--- a/lib/Makefile.sources
+++ b/lib/Makefile.sources
@@ -63,6 +63,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 00000000..a2168f78
--- /dev/null
+++ b/lib/sw_sync.c
@@ -0,0 +1,196 @@
+/*
+ * Copyright © 2016 Collabora, Ltd.
+ *
+ * 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 <stdbool.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 LOCAL_SW_SYNC_IOC_MAGIC 'W'
+#define LOCAL_SW_SYNC_IOC_CREATE_FENCE _IOWR(LOCAL_SW_SYNC_IOC_MAGIC, 0,\
+ struct sw_sync_create_fence_data)
+#define LOCAL_SW_SYNC_IOC_INC _IOW(LOCAL_SW_SYNC_IOC_MAGIC, 1, __u32)
+#endif
+
+/*
+ * Keep the paths for sw_sync in one place until
+ * in the kernel API.
+ */
+#define DEVFS_SW_SYNC "/dev/sw_sync"
+#define DEBUGFS_SW_SYNC "/sys/kernel/debug/sync/sw_sync"
+
+
+static bool sw_sync_fd_is_valid(int fd)
+{
+ int status;
+
+ if (fd < 0)
+ return 0;
+
+ status = fcntl(fd, F_GETFD, 0);
+ return status >= 0;
+}
+
+int sw_sync_timeline_create(void)
+{
+ int fd = open(DEVFS_SW_SYNC, O_RDWR);
+
+ if (fd < 0)
+ fd = open(DEBUGFS_SW_SYNC, O_RDWR);
+
+ igt_assert_f(sw_sync_fd_is_valid(fd), "Created invalid timeline");
+
+ return fd;
+}
+
+int __sw_sync_fence_create(int fd, uint32_t seqno)
+{
+
+ struct sw_sync_create_fence_data data = {0};
+ data.value = seqno;
+
+ if (igt_ioctl(fd, LOCAL_SW_SYNC_IOC_CREATE_FENCE, &data))
+ return -errno;
+
+ return data.fence;
+}
+
+int sw_sync_fence_create(int fd, uint32_t seqno)
+{
+ int fence = __sw_sync_fence_create(fd, seqno);
+ igt_assert_f(sw_sync_fd_is_valid(fence), "Created invalid fence");
+ return fence;
+}
+
+void sw_sync_timeline_inc(int fd, uint32_t count)
+{
+ uint32_t arg = count;
+
+ do_ioctl(fd, LOCAL_SW_SYNC_IOC_INC, &arg);
+}
+
+int 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 -errno;
+
+ return data.fence;
+}
+
+int sync_wait(int fd, int timeout)
+{
+ struct pollfd fds = {0};
+ int ret;
+
+ fds.fd = fd;
+ fds.events = POLLIN;
+
+ do {
+ ret = poll(&fds, 1, timeout);
+ if (ret > 0) {
+ if (fds.revents & (POLLERR | POLLNVAL)) {
+ errno = EINVAL;
+ return -1;
+ }
+ return 0;
+ } else if (ret == 0) {
+ errno = ETIME;
+ return -1;
+ }
+ } while (ret == -1 && (errno == EINTR || errno == EAGAIN));
+
+ return ret;
+}
+
+int sync_fence_count(int fd)
+{
+ struct sync_file_info info = {0};
+
+ if (ioctl(fd, SYNC_IOC_FILE_INFO, &info))
+ return -errno;
+
+ return info.num_fences;
+}
+
+static int __sync_fence_count_status(int fd, int status)
+{
+ struct sync_file_info info = {0};
+ struct sync_fence_info *fence_info;
+ int count;
+ int i;
+
+ if (ioctl(fd, SYNC_IOC_FILE_INFO, &info))
+ return -errno;
+
+ fence_info = calloc(info.num_fences, sizeof(*fence_info));
+ if (!fence_info)
+ return -ENOMEM;
+
+ info.sync_fence_info = (uintptr_t)fence_info;
+ if (ioctl(fd, SYNC_IOC_FILE_INFO, &info)) {
+ count = -errno;
+ } else {
+ count = 0;
+ for (i = 0 ; i < info.num_fences ; i++)
+ if (fence_info[i].status == status)
+ count++;
+ }
+
+ free(fence_info);
+
+ return count;
+}
+
+int sync_fence_count_status(int fd, int status)
+{
+ int count = __sync_fence_count_status(fd, status);
+ igt_assert_f(count >= 0, "No fences with supplied status found");
+ return count;
+}
diff --git a/lib/sw_sync.h b/lib/sw_sync.h
new file mode 100644
index 00000000..cea5a603
--- /dev/null
+++ b/lib/sw_sync.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright © 2016 Collabora, Ltd.
+ *
+ * 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_timeline_create(void);
+int __sw_sync_fence_create(int fd, uint32_t seqno);
+int sw_sync_fence_create(int fd, uint32_t seqno);
+void sw_sync_timeline_inc(int fd, uint32_t count);
+int sync_merge(int fd1, int fd2);
+int sync_wait(int fence, int timeout);
+int sync_fence_count(int fd);
+int sync_fence_count_status(int fd, int status);
+
+#endif
+
--
2.11.0
_______________________________________________
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 i-g-t v10 02/21] test/sw_sync: Add sw_sync test
2016-12-07 2:51 [PATCH i-g-t v10 00/21] Implement sw_sync test Robert Foss
2016-12-07 2:51 ` [PATCH i-g-t v10 01/21] lib/sw_sync: Add helper functions for managing synchronization primitives Robert Foss
@ 2016-12-07 2:51 ` Robert Foss
2016-12-07 2:51 ` [PATCH i-g-t v10 03/21] tests/sw_sync: Add subtest test_alloc_fence Robert Foss
` (18 subsequent siblings)
20 siblings, 0 replies; 24+ messages in thread
From: Robert Foss @ 2016-12-07 2:51 UTC (permalink / raw)
To: intel-gfx, Gustavo Padovan, Daniel Stone, Daniel Vetter,
Marius Vlad, Eric Engestrom, Chris Wilson, Tomeu Vizoso
Cc: Gustavo Padovan
Add initial tests for sw_sync.
Signed-off-by: Robert Foss <robert.foss@collabora.com>
Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
Reviewed-by: Eric Engestrom <eric@engestrom.ch>
Reviewed-by: Tomeu Vizoso <tomeu.vizoso@collabora.com>
---
tests/Makefile.sources | 1 +
tests/sw_sync.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 52 insertions(+)
create mode 100644 tests/sw_sync.c
diff --git a/tests/Makefile.sources b/tests/Makefile.sources
index 65e07922..88480945 100644
--- a/tests/Makefile.sources
+++ b/tests/Makefile.sources
@@ -131,6 +131,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 00000000..42fc1e2b
--- /dev/null
+++ b/tests/sw_sync.c
@@ -0,0 +1,51 @@
+/*
+ * Copyright © 2016 Collabora, Ltd.
+ *
+ * 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 <unistd.h>
+
+#include "igt.h"
+#include "igt_aux.h"
+
+#include "sw_sync.h"
+
+
+IGT_TEST_DESCRIPTION("Test SW Sync Framework");
+
+static void test_alloc_timeline(void)
+{
+ int timeline;
+
+ timeline = sw_sync_timeline_create();
+ close(timeline);
+}
+
+igt_main
+{
+ igt_subtest("alloc_timeline")
+ test_alloc_timeline();
+}
+
--
2.11.0
_______________________________________________
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 i-g-t v10 03/21] tests/sw_sync: Add subtest test_alloc_fence
2016-12-07 2:51 [PATCH i-g-t v10 00/21] Implement sw_sync test Robert Foss
2016-12-07 2:51 ` [PATCH i-g-t v10 01/21] lib/sw_sync: Add helper functions for managing synchronization primitives Robert Foss
2016-12-07 2:51 ` [PATCH i-g-t v10 02/21] test/sw_sync: Add sw_sync test Robert Foss
@ 2016-12-07 2:51 ` Robert Foss
2016-12-07 2:51 ` [PATCH i-g-t v10 04/21] tests/sw_sync: Add subtest test_alloc_fence_invalid_timeline Robert Foss
` (17 subsequent siblings)
20 siblings, 0 replies; 24+ messages in thread
From: Robert Foss @ 2016-12-07 2:51 UTC (permalink / raw)
To: intel-gfx, Gustavo Padovan, Daniel Stone, Daniel Vetter,
Marius Vlad, Eric Engestrom, Chris Wilson, Tomeu Vizoso
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>
Reviewed-by: Eric Engestrom <eric@engestrom.ch>
Reviewed-by: Tomeu Vizoso <tomeu.vizoso@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 42fc1e2b..3db62cd0 100644
--- a/tests/sw_sync.c
+++ b/tests/sw_sync.c
@@ -43,9 +43,25 @@ static void test_alloc_timeline(void)
close(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);
+
+ close(in_fence);
+ close(timeline);
+}
+
+
igt_main
{
igt_subtest("alloc_timeline")
test_alloc_timeline();
+
+ igt_subtest("alloc_fence")
+ test_alloc_fence();
}
--
2.11.0
_______________________________________________
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 i-g-t v10 04/21] tests/sw_sync: Add subtest test_alloc_fence_invalid_timeline
2016-12-07 2:51 [PATCH i-g-t v10 00/21] Implement sw_sync test Robert Foss
` (2 preceding siblings ...)
2016-12-07 2:51 ` [PATCH i-g-t v10 03/21] tests/sw_sync: Add subtest test_alloc_fence Robert Foss
@ 2016-12-07 2:51 ` Robert Foss
2016-12-07 2:51 ` [PATCH i-g-t v10 05/21] tests/sw_sync: Add subtest test_alloc_merge_fence Robert Foss
` (16 subsequent siblings)
20 siblings, 0 replies; 24+ messages in thread
From: Robert Foss @ 2016-12-07 2:51 UTC (permalink / raw)
To: intel-gfx, Gustavo Padovan, Daniel Stone, Daniel Vetter,
Marius Vlad, Eric Engestrom, Chris Wilson, Tomeu Vizoso
This subtests tests that creating fences on negative timelines fail.
Signed-off-by: Robert Foss <robert.foss@collabora.com>
Reviewed-by: Eric Engestrom <eric@engestrom.ch>
Reviewed-by: Tomeu Vizoso <tomeu.vizoso@collabora.com>
---
tests/sw_sync.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/tests/sw_sync.c b/tests/sw_sync.c
index 3db62cd0..1ec88741 100644
--- a/tests/sw_sync.c
+++ b/tests/sw_sync.c
@@ -55,6 +55,11 @@ static void test_alloc_fence(void)
close(timeline);
}
+static void test_alloc_fence_invalid_timeline(void)
+{
+ igt_assert_f(__sw_sync_fence_create(-1, 0) < 0,
+ "Did not fail to create fence on invalid timeline\n");
+}
igt_main
{
@@ -63,5 +68,8 @@ igt_main
igt_subtest("alloc_fence")
test_alloc_fence();
+
+ igt_subtest("alloc_fence_invalid_timeline")
+ test_alloc_fence_invalid_timeline();
}
--
2.11.0
_______________________________________________
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 i-g-t v10 05/21] tests/sw_sync: Add subtest test_alloc_merge_fence
2016-12-07 2:51 [PATCH i-g-t v10 00/21] Implement sw_sync test Robert Foss
` (3 preceding siblings ...)
2016-12-07 2:51 ` [PATCH i-g-t v10 04/21] tests/sw_sync: Add subtest test_alloc_fence_invalid_timeline Robert Foss
@ 2016-12-07 2:51 ` Robert Foss
2016-12-07 2:51 ` [PATCH i-g-t v10 06/21] tests/sw_sync: Add subtest test_sync_busy Robert Foss
` (15 subsequent siblings)
20 siblings, 0 replies; 24+ messages in thread
From: Robert Foss @ 2016-12-07 2:51 UTC (permalink / raw)
To: intel-gfx, Gustavo Padovan, Daniel Stone, Daniel Vetter,
Marius Vlad, Eric Engestrom, Chris Wilson, Tomeu Vizoso
This subtest verifies that merging two fences works in the simples possible
case.
Signed-off-by: Robert Foss <robert.foss@collabora.com>
Reviewed-by: Eric Engestrom <eric@engestrom.ch>
Reviewed-by: Tomeu Vizoso <tomeu.vizoso@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 1ec88741..1af571bb 100644
--- a/tests/sw_sync.c
+++ b/tests/sw_sync.c
@@ -61,6 +61,26 @@ static void test_alloc_fence_invalid_timeline(void)
"Did not fail to create fence on invalid timeline\n");
}
+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 = sync_merge(in_fence[1], in_fence[0]);
+
+ close(in_fence[0]);
+ close(in_fence[1]);
+ close(fence_merge);
+ close(timeline[0]);
+ close(timeline[1]);
+}
+
igt_main
{
igt_subtest("alloc_timeline")
@@ -71,5 +91,8 @@ igt_main
igt_subtest("alloc_fence_invalid_timeline")
test_alloc_fence_invalid_timeline();
+
+ igt_subtest("alloc_merge_fence")
+ test_alloc_merge_fence();
}
--
2.11.0
_______________________________________________
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 i-g-t v10 06/21] tests/sw_sync: Add subtest test_sync_busy
2016-12-07 2:51 [PATCH i-g-t v10 00/21] Implement sw_sync test Robert Foss
` (4 preceding siblings ...)
2016-12-07 2:51 ` [PATCH i-g-t v10 05/21] tests/sw_sync: Add subtest test_alloc_merge_fence Robert Foss
@ 2016-12-07 2:51 ` Robert Foss
2016-12-07 2:51 ` [PATCH i-g-t v10 07/21] tests/sw_sync: Add subtest test_sync_merge Robert Foss
` (14 subsequent siblings)
20 siblings, 0 replies; 24+ messages in thread
From: Robert Foss @ 2016-12-07 2:51 UTC (permalink / raw)
To: intel-gfx, Gustavo Padovan, Daniel Stone, Daniel Vetter,
Marius Vlad, Eric Engestrom, Chris Wilson, Tomeu Vizoso
This subtest verifies that waiting on fences works properly.
Signed-off-by: Robert Foss <robert.foss@collabora.com>
Reviewed-by: Eric Engestrom <eric@engestrom.ch>
Reviewed-by: Tomeu Vizoso <tomeu.vizoso@collabora.com>
---
tests/sw_sync.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 51 insertions(+)
diff --git a/tests/sw_sync.c b/tests/sw_sync.c
index 1af571bb..075791fd 100644
--- a/tests/sw_sync.c
+++ b/tests/sw_sync.c
@@ -29,6 +29,7 @@
#include "igt.h"
#include "igt_aux.h"
+#include "igt_primes.h"
#include "sw_sync.h"
@@ -81,6 +82,53 @@ static void test_alloc_merge_fence(void)
close(timeline[1]);
}
+static void test_sync_busy(void)
+{
+ int fence, ret;
+ int timeline;
+ int seqno;
+
+ timeline = sw_sync_timeline_create();
+ fence = sw_sync_fence_create(timeline, 5);
+
+ /* Make sure that fence has not been signaled yet */
+ ret = sync_wait(fence, 0);
+ igt_assert_f(ret == -1 && errno == ETIME, "Fence signaled early (timeline value 0, fence seqno 5)\n");
+
+ /* Advance timeline from 0 -> 1 */
+ sw_sync_timeline_inc(timeline, 1);
+
+ /* Make sure that fence has not been signaled yet */
+ ret = sync_wait(fence, 0);
+ igt_assert_f(ret == -1 && errno == ETIME, "Fence signaled early (timeline value 1, fence seqno 5)\n");
+
+ /* Advance timeline from 1 -> 5: signaling the fence (seqno 5)*/
+ sw_sync_timeline_inc(timeline, 4);
+ ret = sync_wait(fence, 0);
+ igt_assert_f(ret == 0, "Fence not signaled (timeline value 5, fence seqno 5)\n");
+
+ /* Go even further, and confirm wait still succeeds */
+ sw_sync_timeline_inc(timeline, 5);
+ ret = sync_wait(fence, 0);
+ igt_assert_f(ret == 0, "Fence not signaled (timeline value 10, fence seqno 5)\n");
+
+ seqno = 10;
+ for_each_prime_number(prime, 100) {
+ int fence_prime;
+ seqno += prime;
+
+ fence_prime = sw_sync_fence_create(timeline, seqno);
+ sw_sync_timeline_inc(timeline, prime);
+
+ ret = sync_wait(fence_prime, 0);
+ igt_assert_f(ret == 0, "Fence not signaled during test of prime timeline increments\n");
+ close(fence_prime);
+ }
+
+ close(fence);
+ close(timeline);
+}
+
igt_main
{
igt_subtest("alloc_timeline")
@@ -94,5 +142,8 @@ igt_main
igt_subtest("alloc_merge_fence")
test_alloc_merge_fence();
+
+ igt_subtest("sync_busy")
+ test_sync_busy();
}
--
2.11.0
_______________________________________________
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 i-g-t v10 07/21] tests/sw_sync: Add subtest test_sync_merge
2016-12-07 2:51 [PATCH i-g-t v10 00/21] Implement sw_sync test Robert Foss
` (5 preceding siblings ...)
2016-12-07 2:51 ` [PATCH i-g-t v10 06/21] tests/sw_sync: Add subtest test_sync_busy Robert Foss
@ 2016-12-07 2:51 ` Robert Foss
2016-12-07 2:52 ` [PATCH i-g-t v10 08/21] tests/sw_sync: Add subtest test_sync_merge_same Robert Foss
` (13 subsequent siblings)
20 siblings, 0 replies; 24+ messages in thread
From: Robert Foss @ 2016-12-07 2:51 UTC (permalink / raw)
To: intel-gfx, Gustavo Padovan, Daniel Stone, Daniel Vetter,
Marius Vlad, Eric Engestrom, Chris Wilson, Tomeu Vizoso
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>
Reviewed-by: Eric Engestrom <eric@engestrom.ch>
Reviewed-by: Tomeu Vizoso <tomeu.vizoso@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 075791fd..7780c9e1 100644
--- a/tests/sw_sync.c
+++ b/tests/sw_sync.c
@@ -129,6 +129,70 @@ static void test_sync_busy(void)
close(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 = sync_merge(in_fence[0], in_fence[1]);
+ fence_merge = sync_merge(in_fence[2], fence_merge);
+
+ /* confirm all fences have one active point (even d) */
+ active = 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 = 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 = 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 = 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 = sync_fence_count_status(in_fence[0],
+ SW_SYNC_FENCE_STATUS_SIGNALED);
+ active = 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 = sync_fence_count_status(in_fence[1],
+ SW_SYNC_FENCE_STATUS_SIGNALED);
+ active = 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 = 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 = sync_fence_count_status(fence_merge,
+ SW_SYNC_FENCE_STATUS_SIGNALED);
+ active = sync_fence_count_status(fence_merge,
+ SW_SYNC_FENCE_STATUS_ACTIVE);
+ igt_assert_f(active == 0 && signaled == 1,
+ "fence_merge did not signal\n");
+
+ close(in_fence[0]);
+ close(in_fence[1]);
+ close(in_fence[2]);
+ close(fence_merge);
+ close(timeline);
+}
+
igt_main
{
igt_subtest("alloc_timeline")
@@ -145,5 +209,8 @@ igt_main
igt_subtest("sync_busy")
test_sync_busy();
+
+ igt_subtest("sync_merge")
+ test_sync_merge();
}
--
2.11.0
_______________________________________________
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 i-g-t v10 08/21] tests/sw_sync: Add subtest test_sync_merge_same
2016-12-07 2:51 [PATCH i-g-t v10 00/21] Implement sw_sync test Robert Foss
` (6 preceding siblings ...)
2016-12-07 2:51 ` [PATCH i-g-t v10 07/21] tests/sw_sync: Add subtest test_sync_merge Robert Foss
@ 2016-12-07 2:52 ` Robert Foss
2016-12-07 2:52 ` [PATCH i-g-t v10 09/21] tests/sw_sync: Add subtest test_sync_multi_consumer Robert Foss
` (12 subsequent siblings)
20 siblings, 0 replies; 24+ messages in thread
From: Robert Foss @ 2016-12-07 2:52 UTC (permalink / raw)
To: intel-gfx, Gustavo Padovan, Daniel Stone, Daniel Vetter,
Marius Vlad, Eric Engestrom, Chris Wilson, Tomeu Vizoso
This subtest verifies merging a fence with itself does not fail.
Signed-off-by: Robert Foss <robert.foss@collabora.com>
Reviewed-by: Eric Engestrom <eric@engestrom.ch>
Reviewed-by: Tomeu Vizoso <tomeu.vizoso@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 7780c9e1..c0eade51 100644
--- a/tests/sw_sync.c
+++ b/tests/sw_sync.c
@@ -193,6 +193,30 @@ static void test_sync_merge(void)
close(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] = sync_merge(in_fence[0], in_fence[0]);
+
+ signaled = 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 = sync_fence_count_status(in_fence[0],
+ SW_SYNC_FENCE_STATUS_SIGNALED);
+ igt_assert_f(signaled == 1, "Fence did not signal\n");
+
+ close(in_fence[0]);
+ close(in_fence[1]);
+ close(timeline);
+}
+
igt_main
{
igt_subtest("alloc_timeline")
@@ -212,5 +236,8 @@ igt_main
igt_subtest("sync_merge")
test_sync_merge();
+
+ igt_subtest("sync_merge_same")
+ test_sync_merge_same();
}
--
2.11.0
_______________________________________________
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 i-g-t v10 09/21] tests/sw_sync: Add subtest test_sync_multi_consumer
2016-12-07 2:51 [PATCH i-g-t v10 00/21] Implement sw_sync test Robert Foss
` (7 preceding siblings ...)
2016-12-07 2:52 ` [PATCH i-g-t v10 08/21] tests/sw_sync: Add subtest test_sync_merge_same Robert Foss
@ 2016-12-07 2:52 ` Robert Foss
2016-12-07 2:52 ` [PATCH i-g-t v10 10/21] tests/sw_sync: Add subtest test_sync_multi_consumer_producer Robert Foss
` (11 subsequent siblings)
20 siblings, 0 replies; 24+ messages in thread
From: Robert Foss @ 2016-12-07 2:52 UTC (permalink / raw)
To: intel-gfx, Gustavo Padovan, Daniel Stone, Daniel Vetter,
Marius Vlad, Eric Engestrom, Chris Wilson, Tomeu Vizoso
This subtest verifies the access ordering of multiple consumer threads.
Signed-off-by: Robert Foss <robert.foss@collabora.com>
Reviewed-by: Eric Engestrom <eric@engestrom.ch>
Reviewed-by: Tomeu Vizoso <tomeu.vizoso@collabora.com>
---
tests/sw_sync.c | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 98 insertions(+)
diff --git a/tests/sw_sync.c b/tests/sw_sync.c
index c0eade51..5b6532c2 100644
--- a/tests/sw_sync.c
+++ b/tests/sw_sync.c
@@ -24,6 +24,8 @@
* Robert Foss <robert.foss@collabora.com>
*/
+#include <pthread.h>
+#include <semaphore.h>
#include <stdint.h>
#include <unistd.h>
@@ -36,6 +38,13 @@
IGT_TEST_DESCRIPTION("Test SW Sync Framework");
+typedef struct {
+ int timeline;
+ uint32_t thread_id;
+ volatile uint32_t * volatile counter;
+ sem_t *sem;
+} data_t;
+
static void test_alloc_timeline(void)
{
int timeline;
@@ -217,6 +226,92 @@ static void test_sync_merge_same(void)
close(timeline);
}
+#define MULTI_CONSUMER_THREADS 8
+#define MULTI_CONSUMER_ITERATIONS (1 << 14)
+static void * test_sync_multi_consumer_thread(void *arg)
+{
+ data_t *data = arg;
+ int thread_id = data->thread_id;
+ int timeline = data->timeline;
+ int ret, i;
+
+ for (i = 0; i < MULTI_CONSUMER_ITERATIONS; i++) {
+ int next_point = i * MULTI_CONSUMER_THREADS + thread_id;
+ int fence = sw_sync_fence_create(timeline, next_point);
+
+ ret = sync_wait(fence, 1000);
+ if (ret == -1)
+ {
+ return (void *) 1;
+ }
+
+ if (*(data->counter) != next_point)
+ {
+ return (void *) 1;
+ }
+
+ sem_post(data->sem);
+ close(fence);
+ }
+ return NULL;
+}
+
+static void test_sync_multi_consumer(void)
+{
+
+ data_t data_arr[MULTI_CONSUMER_THREADS];
+ pthread_t thread_arr[MULTI_CONSUMER_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.counter = &counter;
+ data.timeline = timeline;
+ data.sem = &sem;
+
+ /* Start sync threads. */
+ for (i = 0; i < MULTI_CONSUMER_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 < MULTI_CONSUMER_THREADS * MULTI_CONSUMER_ITERATIONS; i++)
+ {
+ sem_wait(&sem);
+
+ counter++;
+ sw_sync_timeline_inc(timeline, 1);
+ }
+
+ /* Wait for threads to complete. */
+ for (i = 0; i < MULTI_CONSUMER_THREADS; i++)
+ {
+ uintptr_t local_thread_ret;
+ pthread_join(thread_arr[i], (void **)&local_thread_ret);
+ thread_ret |= local_thread_ret;
+ }
+
+ close(timeline);
+ sem_destroy(&sem);
+
+ igt_assert_f(counter == MULTI_CONSUMER_THREADS * MULTI_CONSUMER_ITERATIONS,
+ "Counter has unexpected value.\n");
+
+ igt_assert_f(thread_ret == 0, "A sync thread reported failure.\n");
+}
+
igt_main
{
igt_subtest("alloc_timeline")
@@ -239,5 +334,8 @@ igt_main
igt_subtest("sync_merge_same")
test_sync_merge_same();
+
+ igt_subtest("sync_multi_consumer")
+ test_sync_multi_consumer();
}
--
2.11.0
_______________________________________________
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 i-g-t v10 10/21] tests/sw_sync: Add subtest test_sync_multi_consumer_producer
2016-12-07 2:51 [PATCH i-g-t v10 00/21] Implement sw_sync test Robert Foss
` (8 preceding siblings ...)
2016-12-07 2:52 ` [PATCH i-g-t v10 09/21] tests/sw_sync: Add subtest test_sync_multi_consumer Robert Foss
@ 2016-12-07 2:52 ` Robert Foss
2016-12-07 2:52 ` [PATCH i-g-t v10 11/21] tests/sw_sync: Add subtest test_sync_random_merge Robert Foss
` (10 subsequent siblings)
20 siblings, 0 replies; 24+ messages in thread
From: Robert Foss @ 2016-12-07 2:52 UTC (permalink / raw)
To: intel-gfx, Gustavo Padovan, Daniel Stone, Daniel Vetter,
Marius Vlad, Eric Engestrom, Chris Wilson, Tomeu Vizoso
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>
Reviewed-by: Eric Engestrom <eric@engestrom.ch>
Reviewed-by: Tomeu Vizoso <tomeu.vizoso@collabora.com>
---
tests/sw_sync.c | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 90 insertions(+), 5 deletions(-)
diff --git a/tests/sw_sync.c b/tests/sw_sync.c
index 5b6532c2..f32dae5a 100644
--- a/tests/sw_sync.c
+++ b/tests/sw_sync.c
@@ -102,24 +102,28 @@ static void test_sync_busy(void)
/* Make sure that fence has not been signaled yet */
ret = sync_wait(fence, 0);
- igt_assert_f(ret == -1 && errno == ETIME, "Fence signaled early (timeline value 0, fence seqno 5)\n");
+ igt_assert_f(ret == -1 && errno == ETIME,
+ "Fence signaled early (timeline value 0, fence seqno 5)\n");
/* Advance timeline from 0 -> 1 */
sw_sync_timeline_inc(timeline, 1);
/* Make sure that fence has not been signaled yet */
ret = sync_wait(fence, 0);
- igt_assert_f(ret == -1 && errno == ETIME, "Fence signaled early (timeline value 1, fence seqno 5)\n");
+ igt_assert_f(ret == -1 && errno == ETIME,
+ "Fence signaled early (timeline value 1, fence seqno 5)\n");
/* Advance timeline from 1 -> 5: signaling the fence (seqno 5)*/
sw_sync_timeline_inc(timeline, 4);
ret = sync_wait(fence, 0);
- igt_assert_f(ret == 0, "Fence not signaled (timeline value 5, fence seqno 5)\n");
+ igt_assert_f(ret == 0,
+ "Fence not signaled (timeline value 5, fence seqno 5)\n");
/* Go even further, and confirm wait still succeeds */
sw_sync_timeline_inc(timeline, 5);
ret = sync_wait(fence, 0);
- igt_assert_f(ret == 0, "Fence not signaled (timeline value 10, fence seqno 5)\n");
+ igt_assert_f(ret == 0,
+ "Fence not signaled (timeline value 10, fence seqno 5)\n");
seqno = 10;
for_each_prime_number(prime, 100) {
@@ -130,7 +134,8 @@ static void test_sync_busy(void)
sw_sync_timeline_inc(timeline, prime);
ret = sync_wait(fence_prime, 0);
- igt_assert_f(ret == 0, "Fence not signaled during test of prime timeline increments\n");
+ igt_assert_f(ret == 0,
+ "Fence not signaled during test of prime timeline increments\n");
close(fence_prime);
}
@@ -312,6 +317,83 @@ static void test_sync_multi_consumer(void)
igt_assert_f(thread_ret == 0, "A sync thread reported failure.\n");
}
+#define MULTI_CONSUMER_PRODUCER_THREADS 8
+#define MULTI_CONSUMER_PRODUCER_ITERATIONS (1 << 14)
+static void * test_sync_multi_consumer_producer_thread(void *arg)
+{
+ data_t *data = arg;
+ int thread_id = data->thread_id;
+ int timeline = data->timeline;
+ int ret, i;
+
+ for (i = 0; i < MULTI_CONSUMER_PRODUCER_ITERATIONS; i++) {
+ int next_point = i * MULTI_CONSUMER_PRODUCER_THREADS + thread_id;
+ int fence = sw_sync_fence_create(timeline, next_point);
+
+ ret = sync_wait(fence, 1000);
+ if (ret == -1)
+ {
+ return (void *) 1;
+ }
+
+ if (*(data->counter) != next_point)
+ {
+ return (void *) 1;
+ }
+
+ (*data->counter)++;
+
+ /* Kick off the next thread. */
+ sw_sync_timeline_inc(timeline, 1);
+
+ close(fence);
+ }
+ return NULL;
+}
+
+static void test_sync_multi_consumer_producer(void)
+{
+ data_t data_arr[MULTI_CONSUMER_PRODUCER_THREADS];
+ pthread_t thread_arr[MULTI_CONSUMER_PRODUCER_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.counter = &counter;
+ data.timeline = timeline;
+
+ /* Start consumer threads. */
+ for (i = 0; i < MULTI_CONSUMER_PRODUCER_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 < MULTI_CONSUMER_PRODUCER_THREADS; i++)
+ {
+ uintptr_t local_thread_ret;
+ pthread_join(thread_arr[i], (void **)&local_thread_ret);
+ thread_ret |= local_thread_ret;
+ }
+
+ close(timeline);
+
+ igt_assert_f(counter == MULTI_CONSUMER_PRODUCER_THREADS *
+ MULTI_CONSUMER_PRODUCER_ITERATIONS,
+ "Counter has unexpected value.\n");
+
+ igt_assert_f(thread_ret == 0, "A sync thread reported failure.\n");
+}
+
igt_main
{
igt_subtest("alloc_timeline")
@@ -337,5 +419,8 @@ igt_main
igt_subtest("sync_multi_consumer")
test_sync_multi_consumer();
+
+ igt_subtest("sync_multi_consumer_producer")
+ test_sync_multi_consumer_producer();
}
--
2.11.0
_______________________________________________
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 i-g-t v10 11/21] tests/sw_sync: Add subtest test_sync_random_merge
2016-12-07 2:51 [PATCH i-g-t v10 00/21] Implement sw_sync test Robert Foss
` (9 preceding siblings ...)
2016-12-07 2:52 ` [PATCH i-g-t v10 10/21] tests/sw_sync: Add subtest test_sync_multi_consumer_producer Robert Foss
@ 2016-12-07 2:52 ` Robert Foss
2016-12-07 2:52 ` [PATCH i-g-t v10 12/21] tests/sw_sync: Add subtest test_sync_multi_timeline_wait Robert Foss
` (9 subsequent siblings)
20 siblings, 0 replies; 24+ messages in thread
From: Robert Foss @ 2016-12-07 2:52 UTC (permalink / raw)
To: intel-gfx, Gustavo Padovan, Daniel Stone, Daniel Vetter,
Marius Vlad, Eric Engestrom, Chris Wilson, Tomeu Vizoso
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>
Reviewed-by: Eric Engestrom <eric@engestrom.ch>
Reviewed-by: Tomeu Vizoso <tomeu.vizoso@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 f32dae5a..81e83fc8 100644
--- a/tests/sw_sync.c
+++ b/tests/sw_sync.c
@@ -394,6 +394,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();
+ fence_map[i] = -1;
+ }
+
+ 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 = sync_merge(tmpfence, fence);
+ close(tmpfence);
+ close(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 = sync_wait(fence, 0);
+ igt_assert_f(ret == -1 && errno == ETIME,
+ "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 = sync_wait(fence, 0);
+ igt_assert_f(ret == 0, "Failure triggering fence\n");
+
+ close(fence);
+ for (i = 0; i < nbr_timeline; i++)
+ close(timeline_arr[i]);
+}
+
igt_main
{
igt_subtest("alloc_timeline")
@@ -422,5 +492,8 @@ igt_main
igt_subtest("sync_multi_consumer_producer")
test_sync_multi_consumer_producer();
+
+ igt_subtest("sync_random_merge")
+ test_sync_random_merge();
}
--
2.11.0
_______________________________________________
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 i-g-t v10 12/21] tests/sw_sync: Add subtest test_sync_multi_timeline_wait
2016-12-07 2:51 [PATCH i-g-t v10 00/21] Implement sw_sync test Robert Foss
` (10 preceding siblings ...)
2016-12-07 2:52 ` [PATCH i-g-t v10 11/21] tests/sw_sync: Add subtest test_sync_random_merge Robert Foss
@ 2016-12-07 2:52 ` Robert Foss
2016-12-07 2:52 ` [PATCH i-g-t v10 13/21] tests/sw_sync: Add subtest test_sync_multi_producer_single_consumer Robert Foss
` (8 subsequent siblings)
20 siblings, 0 replies; 24+ messages in thread
From: Robert Foss @ 2016-12-07 2:52 UTC (permalink / raw)
To: intel-gfx, Gustavo Padovan, Daniel Stone, Daniel Vetter,
Marius Vlad, Eric Engestrom, Chris Wilson, Tomeu Vizoso
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>
Reviewed-by: Eric Engestrom <eric@engestrom.ch>
Reviewed-by: Tomeu Vizoso <tomeu.vizoso@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 81e83fc8..b0bd2ad4 100644
--- a/tests/sw_sync.c
+++ b/tests/sw_sync.c
@@ -231,6 +231,69 @@ static void test_sync_merge_same(void)
close(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 = sync_merge(in_fence[0], in_fence[1]);
+ fence_merge = sync_merge(in_fence[2], fence_merge);
+
+ /* Confirm fence isn't signaled */
+ active = sync_fence_count_status(fence_merge,
+ SW_SYNC_FENCE_STATUS_ACTIVE);
+ igt_assert_f(active == 3, "Fence signaled too early\n");
+
+ ret = sync_wait(fence_merge, 0);
+ igt_assert_f(ret == -1 && errno == ETIME, "Failure waiting on fence until timeout\n");
+
+ sw_sync_timeline_inc(timeline[0], 5);
+ active = sync_fence_count_status(fence_merge,
+ SW_SYNC_FENCE_STATUS_ACTIVE);
+ signaled = 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 = sync_fence_count_status(fence_merge,
+ SW_SYNC_FENCE_STATUS_ACTIVE);
+ signaled = 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 = sync_fence_count_status(fence_merge,
+ SW_SYNC_FENCE_STATUS_ACTIVE);
+ signaled = 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 = sync_wait(fence_merge, 100);
+ igt_assert_f(ret == 0, "Failure waiting on signaled fence\n");
+
+ close(in_fence[0]);
+ close(in_fence[1]);
+ close(in_fence[2]);
+ close(fence_merge);
+ close(timeline[0]);
+ close(timeline[1]);
+ close(timeline[2]);
+}
+
#define MULTI_CONSUMER_THREADS 8
#define MULTI_CONSUMER_ITERATIONS (1 << 14)
static void * test_sync_multi_consumer_thread(void *arg)
@@ -487,6 +550,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.11.0
_______________________________________________
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 i-g-t v10 13/21] tests/sw_sync: Add subtest test_sync_multi_producer_single_consumer
2016-12-07 2:51 [PATCH i-g-t v10 00/21] Implement sw_sync test Robert Foss
` (11 preceding siblings ...)
2016-12-07 2:52 ` [PATCH i-g-t v10 12/21] tests/sw_sync: Add subtest test_sync_multi_timeline_wait Robert Foss
@ 2016-12-07 2:52 ` Robert Foss
2016-12-07 2:52 ` [PATCH i-g-t v10 14/21] tests/sw_sync: Add subtest test_sync_expired_merge Robert Foss
` (7 subsequent siblings)
20 siblings, 0 replies; 24+ messages in thread
From: Robert Foss @ 2016-12-07 2:52 UTC (permalink / raw)
To: intel-gfx, Gustavo Padovan, Daniel Stone, Daniel Vetter,
Marius Vlad, Eric Engestrom, Chris Wilson, Tomeu Vizoso
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>
Reviewed-by: Eric Engestrom <eric@engestrom.ch>
Reviewed-by: Tomeu Vizoso <tomeu.vizoso@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 b0bd2ad4..13a9602f 100644
--- a/tests/sw_sync.c
+++ b/tests/sw_sync.c
@@ -457,6 +457,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 = sync_fence_count_status(fence,
+ SW_SYNC_FENCE_STATUS_ERROR);
+ igt_assert_f(error == 0, "Error occurred on fence\n");
+ active = 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(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);
+ close(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 = sync_merge(tmp, fence);
+ close(tmp);
+ close(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(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);
+ close(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;
@@ -559,6 +695,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.11.0
_______________________________________________
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 i-g-t v10 14/21] tests/sw_sync: Add subtest test_sync_expired_merge
2016-12-07 2:51 [PATCH i-g-t v10 00/21] Implement sw_sync test Robert Foss
` (12 preceding siblings ...)
2016-12-07 2:52 ` [PATCH i-g-t v10 13/21] tests/sw_sync: Add subtest test_sync_multi_producer_single_consumer Robert Foss
@ 2016-12-07 2:52 ` Robert Foss
2016-12-07 2:52 ` [PATCH i-g-t v10 15/21] tests/sw_sync: Add subtest test_timeline_closed Robert Foss
` (6 subsequent siblings)
20 siblings, 0 replies; 24+ messages in thread
From: Robert Foss @ 2016-12-07 2:52 UTC (permalink / raw)
To: intel-gfx, Gustavo Padovan, Daniel Stone, Daniel Vetter,
Marius Vlad, Eric Engestrom, Chris Wilson, Tomeu Vizoso
From: Rafael Antognolli <rafael.antognolli@intel.com>
This test creates an already expired fence, then creates a merged fence
out of that expired one (passed twice to the merge operation), and
finally closes the merged fence. It shows that if the refcounts are
wrong on the original expired fence, it might get freed while still in
use. Usually a kernel panick will follow.
Signed-off-by: Rafael Antognolli <rafael.antognolli@intel.com>
Signed-off-by: Robert Foss <robert.foss@collabora.com>
Reviewed-by: Tomeu Vizoso <tomeu.vizoso@collabora.com>
---
tests/sw_sync.c | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/tests/sw_sync.c b/tests/sw_sync.c
index 13a9602f..572efc3b 100644
--- a/tests/sw_sync.c
+++ b/tests/sw_sync.c
@@ -593,6 +593,34 @@ static void test_sync_multi_producer_single_consumer(void)
pthread_join(threads[i], NULL);
}
+static void test_sync_expired_merge(void)
+{
+ int iterations = 1 << 20;
+ int timeline;
+ int i;
+ int fence_expired, fence_merged;
+
+ timeline = sw_sync_timeline_create();
+
+ sw_sync_timeline_inc(timeline, 100);
+ fence_expired = sw_sync_fence_create(timeline, 1);
+ igt_assert_f(sync_wait(fence_expired, 0) == 0,
+ "Failure waiting for expired fence\n");
+
+ fence_merged = sync_merge(fence_expired, fence_expired);
+ close(fence_merged);
+
+ for (i = 0; i < iterations; i++) {
+ int fence = sync_merge(fence_expired, fence_expired);
+
+ igt_assert_f(sync_wait(fence, -1) == 0,
+ "Failure waiting on fence\n");
+ close(fence);
+ }
+
+ close(fence_expired);
+}
+
static void test_sync_random_merge(void)
{
int i, size, ret;
@@ -698,6 +726,9 @@ igt_main
igt_subtest("sync_multi_producer_single_consumer")
test_sync_multi_producer_single_consumer();
+ igt_subtest("sync_expired_merge")
+ test_sync_expired_merge();
+
igt_subtest("sync_random_merge")
test_sync_random_merge();
}
--
2.11.0
_______________________________________________
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 i-g-t v10 15/21] tests/sw_sync: Add subtest test_timeline_closed
2016-12-07 2:51 [PATCH i-g-t v10 00/21] Implement sw_sync test Robert Foss
` (13 preceding siblings ...)
2016-12-07 2:52 ` [PATCH i-g-t v10 14/21] tests/sw_sync: Add subtest test_sync_expired_merge Robert Foss
@ 2016-12-07 2:52 ` Robert Foss
2016-12-07 2:52 ` [PATCH i-g-t v10 16/21] tests/sw_sync: Add subtest test_timeline_closed_signaled Robert Foss
` (5 subsequent siblings)
20 siblings, 0 replies; 24+ messages in thread
From: Robert Foss @ 2016-12-07 2:52 UTC (permalink / raw)
To: intel-gfx, Gustavo Padovan, Daniel Stone, Daniel Vetter,
Marius Vlad, Eric Engestrom, Chris Wilson, Tomeu Vizoso
This subtest verifies that the fences of a timeline are not signalled when
a timelne is closed.
Signed-off-by: Robert Foss <robert.foss@collabora.com>
Reviewed-by: Tomeu Vizoso <tomeu.vizoso@collabora.com>
---
tests/sw_sync.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/tests/sw_sync.c b/tests/sw_sync.c
index 572efc3b..1de45277 100644
--- a/tests/sw_sync.c
+++ b/tests/sw_sync.c
@@ -71,6 +71,20 @@ static void test_alloc_fence_invalid_timeline(void)
"Did not fail to create fence on invalid timeline\n");
}
+static void test_timeline_closed(void)
+{
+ int fence, ret;
+ int timeline;
+
+ timeline = sw_sync_timeline_create();
+ fence = sw_sync_fence_create(timeline, 1);
+
+ close(timeline);
+ ret = sync_wait(fence, 0);
+ igt_assert_f(ret == -1 && errno == ETIME,
+ "Failure waiting on unsignaled fence on closed timeline\n");
+}
+
static void test_alloc_merge_fence(void)
{
int in_fence[2];
@@ -702,6 +716,9 @@ igt_main
igt_subtest("alloc_fence_invalid_timeline")
test_alloc_fence_invalid_timeline();
+ igt_subtest("timeline_closed")
+ test_timeline_closed();
+
igt_subtest("alloc_merge_fence")
test_alloc_merge_fence();
--
2.11.0
_______________________________________________
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 i-g-t v10 16/21] tests/sw_sync: Add subtest test_timeline_closed_signaled
2016-12-07 2:51 [PATCH i-g-t v10 00/21] Implement sw_sync test Robert Foss
` (14 preceding siblings ...)
2016-12-07 2:52 ` [PATCH i-g-t v10 15/21] tests/sw_sync: Add subtest test_timeline_closed Robert Foss
@ 2016-12-07 2:52 ` Robert Foss
2016-12-07 2:52 ` [PATCH i-g-t v10 17/21] lib/sw_sync: Add igt_require_sw_sync to enable skipping on no sw_sync support Robert Foss
` (4 subsequent siblings)
20 siblings, 0 replies; 24+ messages in thread
From: Robert Foss @ 2016-12-07 2:52 UTC (permalink / raw)
To: intel-gfx, Gustavo Padovan, Daniel Stone, Daniel Vetter,
Marius Vlad, Eric Engestrom, Chris Wilson, Tomeu Vizoso
Add subtest test_timeline_closed_signaled that verifies that a signaled fence
stays signaled after its timeline has been closed.
Signed-off-by: Robert Foss <robert.foss@collabora.com>
Reviewed-by: Tomeu Vizoso <tomeu.vizoso@collabora.com>
---
tests/sw_sync.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/tests/sw_sync.c b/tests/sw_sync.c
index 1de45277..f990818d 100644
--- a/tests/sw_sync.c
+++ b/tests/sw_sync.c
@@ -85,6 +85,21 @@ static void test_timeline_closed(void)
"Failure waiting on unsignaled fence on closed timeline\n");
}
+static void test_timeline_closed_signaled(void)
+{
+ int fence, ret;
+ int timeline;
+
+ timeline = sw_sync_timeline_create();
+ fence = sw_sync_fence_create(timeline, 1);
+
+ sw_sync_timeline_inc(timeline, 1);
+ close(timeline);
+ ret = sync_wait(fence, 0);
+ igt_assert_f(ret == 0,
+ "Failure waiting on signaled fence for closed timeline\n");
+}
+
static void test_alloc_merge_fence(void)
{
int in_fence[2];
@@ -719,6 +734,9 @@ igt_main
igt_subtest("timeline_closed")
test_timeline_closed();
+ igt_subtest("timeline_closed_signaled")
+ test_timeline_closed_signaled();
+
igt_subtest("alloc_merge_fence")
test_alloc_merge_fence();
--
2.11.0
_______________________________________________
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 i-g-t v10 17/21] lib/sw_sync: Add igt_require_sw_sync to enable skipping on no sw_sync support
2016-12-07 2:51 [PATCH i-g-t v10 00/21] Implement sw_sync test Robert Foss
` (15 preceding siblings ...)
2016-12-07 2:52 ` [PATCH i-g-t v10 16/21] tests/sw_sync: Add subtest test_timeline_closed_signaled Robert Foss
@ 2016-12-07 2:52 ` Robert Foss
2016-12-07 11:06 ` Petri Latvala
2016-12-07 2:52 ` [PATCH i-g-t v10 18/21] tests/sw_sync: Add igt_require check for sw_sync feature Robert Foss
` (3 subsequent siblings)
20 siblings, 1 reply; 24+ messages in thread
From: Robert Foss @ 2016-12-07 2:52 UTC (permalink / raw)
To: intel-gfx, Gustavo Padovan, Daniel Stone, Daniel Vetter,
Marius Vlad, Eric Engestrom, Chris Wilson, Tomeu Vizoso
Add igt_require_sw_sync to provide tests to skip if sw_sync support isn't
available on the host machine.
Signed-off-by: Robert Foss <robert.foss@collabora.com>
Reviewed-by: Tomeu Vizoso <tomeu.vizoso@collabora.com>
---
lib/sw_sync.c | 22 ++++++++++++++++++++++
lib/sw_sync.h | 1 +
2 files changed, 23 insertions(+)
diff --git a/lib/sw_sync.c b/lib/sw_sync.c
index a2168f78..d4ecc898 100644
--- a/lib/sw_sync.c
+++ b/lib/sw_sync.c
@@ -194,3 +194,25 @@ int sync_fence_count_status(int fd, int status)
igt_assert_f(count >= 0, "No fences with supplied status found");
return count;
}
+
+static bool kernel_has_sw_sync(void)
+{
+ bool err;
+
+ igt_ignore_warn(system("/sbin/modprobe -s r sw_sync"));
+
+ err = false;
+ if (access(DEVFS_SW_SYNC, R_OK | W_OK) < 0) {
+ char buf[128];
+
+ snprintf(buf, sizeof(buf), "%s/sw_sync", igt_debugfs_mount());
+ err = access(DEBUGFS_SW_SYNC, R_OK | W_OK) < 0;
+ }
+
+ return !err;
+}
+
+void igt_require_sw_sync(void)
+{
+ igt_require(kernel_has_sw_sync());
+}
diff --git a/lib/sw_sync.h b/lib/sw_sync.h
index cea5a603..82af3378 100644
--- a/lib/sw_sync.h
+++ b/lib/sw_sync.h
@@ -39,6 +39,7 @@ int sync_merge(int fd1, int fd2);
int sync_wait(int fence, int timeout);
int sync_fence_count(int fd);
int sync_fence_count_status(int fd, int status);
+void igt_require_sw_sync(void);
#endif
--
2.11.0
_______________________________________________
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: [PATCH i-g-t v10 17/21] lib/sw_sync: Add igt_require_sw_sync to enable skipping on no sw_sync support
2016-12-07 2:52 ` [PATCH i-g-t v10 17/21] lib/sw_sync: Add igt_require_sw_sync to enable skipping on no sw_sync support Robert Foss
@ 2016-12-07 11:06 ` Petri Latvala
2016-12-07 15:27 ` Robert Foss
0 siblings, 1 reply; 24+ messages in thread
From: Petri Latvala @ 2016-12-07 11:06 UTC (permalink / raw)
To: Robert Foss; +Cc: Daniel Stone, intel-gfx, Eric Engestrom, Gustavo Padovan
On Tue, Dec 06, 2016 at 09:52:09PM -0500, Robert Foss wrote:
> Add igt_require_sw_sync to provide tests to skip if sw_sync support isn't
> available on the host machine.
>
> Signed-off-by: Robert Foss <robert.foss@collabora.com>
> Reviewed-by: Tomeu Vizoso <tomeu.vizoso@collabora.com>
> ---
> lib/sw_sync.c | 22 ++++++++++++++++++++++
> lib/sw_sync.h | 1 +
> 2 files changed, 23 insertions(+)
>
> diff --git a/lib/sw_sync.c b/lib/sw_sync.c
> index a2168f78..d4ecc898 100644
> --- a/lib/sw_sync.c
> +++ b/lib/sw_sync.c
> @@ -194,3 +194,25 @@ int sync_fence_count_status(int fd, int status)
> igt_assert_f(count >= 0, "No fences with supplied status found");
> return count;
> }
> +
> +static bool kernel_has_sw_sync(void)
> +{
> + bool err;
> +
> + igt_ignore_warn(system("/sbin/modprobe -s r sw_sync"));
> +
> + err = false;
> + if (access(DEVFS_SW_SYNC, R_OK | W_OK) < 0) {
> + char buf[128];
> +
> + snprintf(buf, sizeof(buf), "%s/sw_sync", igt_debugfs_mount());
> + err = access(DEBUGFS_SW_SYNC, R_OK | W_OK) < 0;
> + }
Did you mean access(buf, R_OK | W_OK) here?
--
Petri Latvala
_______________________________________________
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 i-g-t v10 17/21] lib/sw_sync: Add igt_require_sw_sync to enable skipping on no sw_sync support
2016-12-07 11:06 ` Petri Latvala
@ 2016-12-07 15:27 ` Robert Foss
0 siblings, 0 replies; 24+ messages in thread
From: Robert Foss @ 2016-12-07 15:27 UTC (permalink / raw)
To: Petri Latvala; +Cc: Daniel Stone, intel-gfx, Eric Engestrom, Gustavo Padovan
On 2016-12-07 06:06 AM, Petri Latvala wrote:
> On Tue, Dec 06, 2016 at 09:52:09PM -0500, Robert Foss wrote:
>> Add igt_require_sw_sync to provide tests to skip if sw_sync support isn't
>> available on the host machine.
>>
>> Signed-off-by: Robert Foss <robert.foss@collabora.com>
>> Reviewed-by: Tomeu Vizoso <tomeu.vizoso@collabora.com>
>> ---
>> lib/sw_sync.c | 22 ++++++++++++++++++++++
>> lib/sw_sync.h | 1 +
>> 2 files changed, 23 insertions(+)
>>
>> diff --git a/lib/sw_sync.c b/lib/sw_sync.c
>> index a2168f78..d4ecc898 100644
>> --- a/lib/sw_sync.c
>> +++ b/lib/sw_sync.c
>> @@ -194,3 +194,25 @@ int sync_fence_count_status(int fd, int status)
>> igt_assert_f(count >= 0, "No fences with supplied status found");
>> return count;
>> }
>> +
>> +static bool kernel_has_sw_sync(void)
>> +{
>> + bool err;
>> +
>> + igt_ignore_warn(system("/sbin/modprobe -s r sw_sync"));
>> +
>> + err = false;
>> + if (access(DEVFS_SW_SYNC, R_OK | W_OK) < 0) {
>> + char buf[128];
>> +
>> + snprintf(buf, sizeof(buf), "%s/sw_sync", igt_debugfs_mount());
>> + err = access(DEBUGFS_SW_SYNC, R_OK | W_OK) < 0;
>> + }
>
>
> Did you mean access(buf, R_OK | W_OK) here?
Yes, fixing this in v11.
Thanks!
>
>
> --
> Petri Latvala
>
_______________________________________________
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 i-g-t v10 18/21] tests/sw_sync: Add igt_require check for sw_sync feature
2016-12-07 2:51 [PATCH i-g-t v10 00/21] Implement sw_sync test Robert Foss
` (16 preceding siblings ...)
2016-12-07 2:52 ` [PATCH i-g-t v10 17/21] lib/sw_sync: Add igt_require_sw_sync to enable skipping on no sw_sync support Robert Foss
@ 2016-12-07 2:52 ` Robert Foss
2016-12-07 2:52 ` [PATCH i-g-t v10 19/21] tests/sw_sync: Add subtest test_sync_merge_invalid Robert Foss
` (2 subsequent siblings)
20 siblings, 0 replies; 24+ messages in thread
From: Robert Foss @ 2016-12-07 2:52 UTC (permalink / raw)
To: intel-gfx, Gustavo Padovan, Daniel Stone, Daniel Vetter,
Marius Vlad, Eric Engestrom, Chris Wilson, Tomeu Vizoso
Make sure that this test is skipped if the sw_sync feature is missing from
the host system.
Signed-off-by: Robert Foss <robert.foss@collabora.com>
Reviewed-by: Tomeu Vizoso <tomeu.vizoso@collabora.com>
---
lib/sw_sync.c | 1 +
tests/sw_sync.c | 3 +++
2 files changed, 4 insertions(+)
diff --git a/lib/sw_sync.c b/lib/sw_sync.c
index d4ecc898..614554a6 100644
--- a/lib/sw_sync.c
+++ b/lib/sw_sync.c
@@ -36,6 +36,7 @@
#include <linux/sync_file.h>
#include <sys/ioctl.h>
+#include "igt_debugfs.h"
#include "sw_sync.h"
#include "drmtest.h"
#include "ioctl_wrappers.h"
diff --git a/tests/sw_sync.c b/tests/sw_sync.c
index f990818d..5bccb053 100644
--- a/tests/sw_sync.c
+++ b/tests/sw_sync.c
@@ -722,6 +722,9 @@ static void test_sync_random_merge(void)
igt_main
{
+ igt_fixture
+ igt_require_sw_sync();
+
igt_subtest("alloc_timeline")
test_alloc_timeline();
--
2.11.0
_______________________________________________
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 i-g-t v10 19/21] tests/sw_sync: Add subtest test_sync_merge_invalid
2016-12-07 2:51 [PATCH i-g-t v10 00/21] Implement sw_sync test Robert Foss
` (17 preceding siblings ...)
2016-12-07 2:52 ` [PATCH i-g-t v10 18/21] tests/sw_sync: Add igt_require check for sw_sync feature Robert Foss
@ 2016-12-07 2:52 ` Robert Foss
2016-12-07 2:52 ` [PATCH i-g-t v10 20/21] tests/sw_sync: Add subtest test_sync_busy_fork Robert Foss
2016-12-07 2:52 ` [PATCH i-g-t v10 21/21] tests/sw_sync: Add subtest test_sync_busy_unixsocket Robert Foss
20 siblings, 0 replies; 24+ messages in thread
From: Robert Foss @ 2016-12-07 2:52 UTC (permalink / raw)
To: intel-gfx, Gustavo Padovan, Daniel Stone, Daniel Vetter,
Marius Vlad, Eric Engestrom, Chris Wilson, Tomeu Vizoso
Add subtest test_sync_merge_invalid that tests merging invalid fences.
Signed-off-by: Robert Foss <robert.foss@collabora.com>
Reviewed-by: Tomeu Vizoso <tomeu.vizoso@collabora.com>
---
tests/sw_sync.c | 41 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+)
diff --git a/tests/sw_sync.c b/tests/sw_sync.c
index 5bccb053..3c876e03 100644
--- a/tests/sw_sync.c
+++ b/tests/sw_sync.c
@@ -172,6 +172,44 @@ static void test_sync_busy(void)
close(timeline);
}
+static void test_sync_merge_invalid(void)
+{
+ int in_fence;
+ int fence_invalid;
+ int fence_merge;
+ int timeline;
+ char tmppath[] = "/tmp/igt-XXXXXX";
+ int skip = 0;
+
+ timeline = sw_sync_timeline_create();
+ in_fence = sw_sync_fence_create(timeline, 1);
+
+ fence_invalid = -1;
+ fence_merge = sync_merge(in_fence, fence_invalid);
+ igt_assert_f(fence_merge < 0, "Verify invalid fd (-1) handling");
+
+ fence_invalid = drm_open_driver(DRIVER_ANY);
+ fence_merge = sync_merge(in_fence, fence_invalid);
+ igt_assert_f(fence_merge < 0, "Verify invalid fd (device fd) handling");
+
+ fence_invalid = mkstemp(tmppath);
+ if (fence_invalid == -1) {
+ skip = 1;
+ goto out;
+ }
+ unlink(tmppath);
+ fence_invalid = drm_open_driver(DRIVER_ANY);
+ fence_merge = sync_merge(in_fence, fence_invalid);
+ close(fence_invalid);
+ igt_assert_f(fence_merge < 0, "Verify invalid fd (file fd) handling");
+
+out:
+ close(in_fence);
+ close(fence_merge);
+ close(timeline);
+ igt_require(skip == 0);
+}
+
static void test_sync_merge(void)
{
int in_fence[3];
@@ -746,6 +784,9 @@ igt_main
igt_subtest("sync_busy")
test_sync_busy();
+ igt_subtest("sync_merge_invalid")
+ test_sync_merge_invalid();
+
igt_subtest("sync_merge")
test_sync_merge();
--
2.11.0
_______________________________________________
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 i-g-t v10 20/21] tests/sw_sync: Add subtest test_sync_busy_fork
2016-12-07 2:51 [PATCH i-g-t v10 00/21] Implement sw_sync test Robert Foss
` (18 preceding siblings ...)
2016-12-07 2:52 ` [PATCH i-g-t v10 19/21] tests/sw_sync: Add subtest test_sync_merge_invalid Robert Foss
@ 2016-12-07 2:52 ` Robert Foss
2016-12-07 2:52 ` [PATCH i-g-t v10 21/21] tests/sw_sync: Add subtest test_sync_busy_unixsocket Robert Foss
20 siblings, 0 replies; 24+ messages in thread
From: Robert Foss @ 2016-12-07 2:52 UTC (permalink / raw)
To: intel-gfx, Gustavo Padovan, Daniel Stone, Daniel Vetter,
Marius Vlad, Eric Engestrom, Chris Wilson, Tomeu Vizoso
Add subtest test_sync_busy_fork which increments the timeline in a forked child
process.
Signed-off-by: Robert Foss <robert.foss@collabora.com>
Reviewed-by: Tomeu Vizoso <tomeu.vizoso@collabora.com>
---
tests/sw_sync.c | 39 +++++++++++++++++++++++++++++++++++++++
1 file changed, 39 insertions(+)
diff --git a/tests/sw_sync.c b/tests/sw_sync.c
index 3c876e03..c64bb80e 100644
--- a/tests/sw_sync.c
+++ b/tests/sw_sync.c
@@ -172,6 +172,42 @@ static void test_sync_busy(void)
close(timeline);
}
+static void test_sync_busy_fork(void)
+{
+ int fence, ret;
+ int timeline;
+ int skip = 0;
+
+ timeline = sw_sync_timeline_create();
+ fence = sw_sync_fence_create(timeline, 1);
+
+ switch (fork()) {
+ case 0:
+ /* Child process */
+ usleep(1*1000*1000);
+ /* Advance timeline from 0 -> 1 */
+ sw_sync_timeline_inc(timeline, 1);
+ _Exit(0);
+ break;
+ case -1:
+ /* Failed fork */
+ skip = 1;
+ break;
+ default:
+ /* Parent process */
+ ret = sync_wait(fence, 0);
+ igt_assert_f(ret == -1 && errno == ETIME, "Fence signaled (it should not have been signalled yet)\n");
+
+ ret = sync_wait(fence, 2*1000);
+ igt_assert_f(ret == 0, "Fence not signaled (timeline value 1 fence seqno 1)\n");
+ break;
+ }
+
+ close(fence);
+ close(timeline);
+ igt_require(!skip);
+}
+
static void test_sync_merge_invalid(void)
{
int in_fence;
@@ -784,6 +820,9 @@ igt_main
igt_subtest("sync_busy")
test_sync_busy();
+ igt_subtest("sync_busy_fork")
+ test_sync_busy_fork();
+
igt_subtest("sync_merge_invalid")
test_sync_merge_invalid();
--
2.11.0
_______________________________________________
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 i-g-t v10 21/21] tests/sw_sync: Add subtest test_sync_busy_unixsocket
2016-12-07 2:51 [PATCH i-g-t v10 00/21] Implement sw_sync test Robert Foss
` (19 preceding siblings ...)
2016-12-07 2:52 ` [PATCH i-g-t v10 20/21] tests/sw_sync: Add subtest test_sync_busy_fork Robert Foss
@ 2016-12-07 2:52 ` Robert Foss
20 siblings, 0 replies; 24+ messages in thread
From: Robert Foss @ 2016-12-07 2:52 UTC (permalink / raw)
To: intel-gfx, Gustavo Padovan, Daniel Stone, Daniel Vetter,
Marius Vlad, Eric Engestrom, Chris Wilson, Tomeu Vizoso
Add subtest test_sync_busy_fork which increments the timeline in a forked child
process, where the timeline fd has been sent through a UNIX socket.
Signed-off-by: Robert Foss <robert.foss@collabora.com>
Reviewed-by: Tomeu Vizoso <tomeu.vizoso@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 c64bb80e..7a428c86 100644
--- a/tests/sw_sync.c
+++ b/tests/sw_sync.c
@@ -27,6 +27,8 @@
#include <pthread.h>
#include <semaphore.h>
#include <stdint.h>
+#include <sys/socket.h>
+#include <sys/types.h>
#include <unistd.h>
#include "igt.h"
@@ -172,6 +174,104 @@ static void test_sync_busy(void)
close(timeline);
}
+static void test_sync_busy_fork_unixsocket(void)
+{
+ int fence, ret;
+ int timeline;
+ int skip = 0;
+ int sv[2];
+
+
+ timeline = sw_sync_timeline_create();
+ fence = sw_sync_fence_create(timeline, 1);
+
+ if (socketpair(AF_UNIX, SOCK_DGRAM, 0, sv) != 0) {
+ skip = 1;
+ goto out;
+ }
+
+ switch (fork()) {
+ case 0:
+ {
+ /* Child process */
+ int socket = sv[1];
+ int socket_timeline;
+ struct msghdr msg = {0};
+ struct cmsghdr *cmsg;
+ unsigned char *data;
+ char m_buffer[256];
+ char c_buffer[256];
+ struct iovec io = { .iov_base = m_buffer, .iov_len = sizeof(m_buffer) };
+ close(sv[0]);
+
+ msg.msg_iov = &io;
+ msg.msg_iovlen = 1;
+ msg.msg_control = c_buffer;
+ msg.msg_controllen = sizeof(c_buffer);
+
+ if (recvmsg(socket, &msg, 0) < 0)
+ _Exit(1);
+
+ cmsg = CMSG_FIRSTHDR(&msg);
+ data = CMSG_DATA(cmsg);
+ socket_timeline = *((int *) data);
+
+ /* Advance timeline from 0 -> 1 */
+ sw_sync_timeline_inc(socket_timeline, 1);
+
+ _Exit(0);
+ break;
+ }
+ case -1:
+ {
+ /* Failed fork */
+ skip = 1;
+ break;
+ }
+ default:
+ {
+ /* Parent process */
+ int socket = sv[0];
+ struct cmsghdr *cmsg;
+ struct iovec io = { .iov_base = (char *)"ABC", .iov_len = 3 };
+ struct msghdr msg = { 0 };
+ char buf[CMSG_SPACE(sizeof(timeline))];
+ memset(buf, '\0', sizeof(buf));
+ close(sv[1]);
+
+ msg.msg_iov = &io;
+ msg.msg_iovlen = 1;
+ msg.msg_control = buf;
+ msg.msg_controllen = sizeof(buf);
+
+ cmsg = CMSG_FIRSTHDR(&msg);
+ cmsg->cmsg_level = SOL_SOCKET;
+ cmsg->cmsg_type = SCM_RIGHTS;
+ cmsg->cmsg_len = CMSG_LEN(sizeof(timeline));
+
+ *((int *) CMSG_DATA(cmsg)) = timeline;
+ msg.msg_controllen = cmsg->cmsg_len;
+
+ ret = sync_wait(fence, 0);
+ igt_assert_f(ret == -1 && errno == ETIME, "Fence signaled (it should not have been signalled yet)\n");
+
+ if (sendmsg(socket, &msg, 0) < 0) {
+ skip = 1;
+ goto out;
+ }
+
+ ret = sync_wait(fence, 2*1000);
+ igt_assert_f(ret == 0, "Fence not signaled (timeline value 1 fence seqno 1)\n");
+ break;
+ }
+ }
+
+out:
+ close(fence);
+ close(timeline);
+ igt_require(!skip);
+}
+
static void test_sync_busy_fork(void)
{
int fence, ret;
@@ -823,6 +923,9 @@ igt_main
igt_subtest("sync_busy_fork")
test_sync_busy_fork();
+ igt_subtest("sync_busy_fork_unixsocket")
+ test_sync_busy_fork_unixsocket();
+
igt_subtest("sync_merge_invalid")
test_sync_merge_invalid();
--
2.11.0
_______________________________________________
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