Re: [Intel-gfx] [PATCH i-g-t 2/2] Add i915/gem_ctx_persistence
Hi Chris, On Thu, Oct 10, 2019 at 08:32:58AM +0100, Chris Wilson wrote: > Sanity test existing persistence and new exciting non-persistent context > behaviour. > > Signed-off-by: Chris Wilson > Cc: Joonas Lahtinen > Cc: Michał Winiarski > Cc: Jon Bloomfield > Cc: Tvrtko Ursulin > Cc: Andi Shyti > --- > lib/i915/gem_context.c | 37 +++ > lib/i915/gem_context.h | 8 + > lib/igt_dummyload.c | 3 +- > lib/ioctl_wrappers.c | 1 + > tests/Makefile.sources | 3 + > tests/i915/gem_ctx_persistence.c | 407 +++ > tests/meson.build| 1 + > 7 files changed, 459 insertions(+), 1 deletion(-) > create mode 100644 tests/i915/gem_ctx_persistence.c I think this patch should be split as ioctl_wrappers, igt_dummyload have changes that are not related to "Sanity test existing persistence and new exciting non-persistent context behaviour" I think they don't affect the test itself. Without those changes: Reviewed-by: Andi Shyti Still one question. > +static bool enable_hangcheck(int i915) how about adding here a boolean and use this function also for the test_nohangcheck_hostile() case? > +{ > + int enabled = -1; > + int dir; > + > + dir = igt_sysfs_open_parameters(i915); > + if (dir < 0) /* no parameters, must be default! */ > + return enabled; > + > + /* If i915.hangcheck is removed, assume the default is good */ > + igt_sysfs_set(dir, "enable_hangcheck", "1"); > + igt_sysfs_scanf(dir, "enable_hangcheck", "%d", ); > + > + close(dir); > + > + return enabled; > +} > + > +static void test_idempotent(int i915) > +{ > + struct drm_i915_gem_context_param p = { > + .param = I915_CONTEXT_PARAM_PERSISTENCE, > + }; > + int expected; > + > + /* > + * Simple test to verify that we are able to read back the same boolean > + * value as we set. > + * > + * Each time we invert the current value so that at the end of the test, > + * if successful, we leave the context in the original state. > + */ > + > + gem_context_get_param(i915, ); > + expected = !!p.value; > + > + expected = !expected; mmhhh... looks familiar :) Andi ___ Intel-gfx mailing list Intel-gfx@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/intel-gfx
[Intel-gfx] [PATCH i-g-t 2/2] Add i915/gem_ctx_persistence
Sanity test existing persistence and new exciting non-persistent context behaviour. Signed-off-by: Chris Wilson Cc: Joonas Lahtinen Cc: Michał Winiarski Cc: Jon Bloomfield Cc: Tvrtko Ursulin Cc: Andi Shyti --- lib/i915/gem_context.c | 37 +++ lib/i915/gem_context.h | 8 + lib/igt_dummyload.c | 3 +- lib/ioctl_wrappers.c | 1 + tests/Makefile.sources | 3 + tests/i915/gem_ctx_persistence.c | 407 +++ tests/meson.build| 1 + 7 files changed, 459 insertions(+), 1 deletion(-) create mode 100644 tests/i915/gem_ctx_persistence.c diff --git a/lib/i915/gem_context.c b/lib/i915/gem_context.c index 83c5df961..1fae5191f 100644 --- a/lib/i915/gem_context.c +++ b/lib/i915/gem_context.c @@ -272,6 +272,43 @@ void gem_context_set_priority(int fd, uint32_t ctx_id, int prio) igt_assert_eq(__gem_context_set_priority(fd, ctx_id, prio), 0); } +/** + * __gem_context_set_persistence: + * @i915: open i915 drm file descriptor + * @ctx: i915 context id + * @state: desired persistence + * + * Declare whether this context is allowed to persist after closing until + * its requests are complete (persistent=true) or if it should be + * immediately reaped on closing and its requests cancelled + * (persistent=false). + * + * Returns: An integer equal to zero for success and negative for failure + */ +int __gem_context_set_persistence(int i915, uint32_t ctx, bool state) +{ + struct drm_i915_gem_context_param p = { + .ctx_id = ctx, + .param = I915_CONTEXT_PARAM_PERSISTENCE, + .value = state, + }; + + return __gem_context_set_param(i915, ); +} + +/** + * __gem_context_set_persistence: + * @i915: open i915 drm file descriptor + * @ctx: i915 context id + * @state: desired persistence + * + * Like __gem_context_set_persistence(), except we assert on failure. + */ +void gem_context_set_persistence(int i915, uint32_t ctx, bool state) +{ + igt_assert_eq(__gem_context_set_persistence(i915, ctx, state), 0); +} + int __gem_context_clone(int i915, uint32_t src, unsigned int share, diff --git a/lib/i915/gem_context.h b/lib/i915/gem_context.h index 8043c3401..c0d4c9615 100644 --- a/lib/i915/gem_context.h +++ b/lib/i915/gem_context.h @@ -24,6 +24,11 @@ #ifndef GEM_CONTEXT_H #define GEM_CONTEXT_H +#include +#include + +struct drm_i915_gem_context_param; + uint32_t gem_context_create(int fd); int __gem_context_create(int fd, uint32_t *ctx_id); void gem_context_destroy(int fd, uint32_t ctx_id); @@ -58,6 +63,9 @@ int __gem_context_get_param(int fd, struct drm_i915_gem_context_param *p); int __gem_context_set_priority(int fd, uint32_t ctx, int prio); void gem_context_set_priority(int fd, uint32_t ctx, int prio); +int __gem_context_set_persistence(int i915, uint32_t ctx, bool state); +void gem_context_set_persistence(int i915, uint32_t ctx, bool state); + bool gem_context_has_engine(int fd, uint32_t ctx, uint64_t engine); #endif /* GEM_CONTEXT_H */ diff --git a/lib/igt_dummyload.c b/lib/igt_dummyload.c index 65b5cc927..6060878dd 100644 --- a/lib/igt_dummyload.c +++ b/lib/igt_dummyload.c @@ -450,7 +450,8 @@ void igt_spin_free(int fd, igt_spin_t *spin) gem_close(fd, spin->poll_handle); } - gem_close(fd, spin->handle); + if (spin->handle) + gem_close(fd, spin->handle); if (spin->out_fence >= 0) close(spin->out_fence); diff --git a/lib/ioctl_wrappers.c b/lib/ioctl_wrappers.c index 280fdd624..628f8b830 100644 --- a/lib/ioctl_wrappers.c +++ b/lib/ioctl_wrappers.c @@ -445,6 +445,7 @@ int gem_wait(int fd, uint32_t handle, int64_t *timeout_ns) ret = 0; if (igt_ioctl(fd, DRM_IOCTL_I915_GEM_WAIT, )) ret = -errno; + errno = 0; if (timeout_ns) *timeout_ns = wait.timeout_ns; diff --git a/tests/Makefile.sources b/tests/Makefile.sources index 343be0500..093eb57f3 100644 --- a/tests/Makefile.sources +++ b/tests/Makefile.sources @@ -154,6 +154,9 @@ gem_ctx_isolation_SOURCES = i915/gem_ctx_isolation.c TESTS_progs += gem_ctx_param gem_ctx_param_SOURCES = i915/gem_ctx_param.c +TESTS_progs += gem_ctx_persistence +gem_ctx_persistence_SOURCES = i915/gem_ctx_persistence.c + TESTS_progs += gem_ctx_shared gem_ctx_shared_SOURCES = i915/gem_ctx_shared.c diff --git a/tests/i915/gem_ctx_persistence.c b/tests/i915/gem_ctx_persistence.c new file mode 100644 index 0..854c146ec --- /dev/null +++ b/tests/i915/gem_ctx_persistence.c @@ -0,0 +1,407 @@ +/* + * Copyright © 2019 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + *
[Intel-gfx] [PATCH i-g-t 2/2] Add i915/gem_ctx_persistence
Sanity test existing persistence and new exciting non-persistent context behaviour. Signed-off-by: Chris Wilson Cc: Joonas Lahtinen Cc: Michał Winiarski Cc: Jon Bloomfield --- lib/i915/gem_context.c | 37 lib/i915/gem_context.h | 8 + lib/igt_dummyload.c | 3 +- lib/ioctl_wrappers.c | 1 + tests/Makefile.sources | 3 + tests/i915/gem_ctx_persistence.c | 353 +++ tests/meson.build| 1 + 7 files changed, 405 insertions(+), 1 deletion(-) create mode 100644 tests/i915/gem_ctx_persistence.c diff --git a/lib/i915/gem_context.c b/lib/i915/gem_context.c index 83c5df961..1fae5191f 100644 --- a/lib/i915/gem_context.c +++ b/lib/i915/gem_context.c @@ -272,6 +272,43 @@ void gem_context_set_priority(int fd, uint32_t ctx_id, int prio) igt_assert_eq(__gem_context_set_priority(fd, ctx_id, prio), 0); } +/** + * __gem_context_set_persistence: + * @i915: open i915 drm file descriptor + * @ctx: i915 context id + * @state: desired persistence + * + * Declare whether this context is allowed to persist after closing until + * its requests are complete (persistent=true) or if it should be + * immediately reaped on closing and its requests cancelled + * (persistent=false). + * + * Returns: An integer equal to zero for success and negative for failure + */ +int __gem_context_set_persistence(int i915, uint32_t ctx, bool state) +{ + struct drm_i915_gem_context_param p = { + .ctx_id = ctx, + .param = I915_CONTEXT_PARAM_PERSISTENCE, + .value = state, + }; + + return __gem_context_set_param(i915, ); +} + +/** + * __gem_context_set_persistence: + * @i915: open i915 drm file descriptor + * @ctx: i915 context id + * @state: desired persistence + * + * Like __gem_context_set_persistence(), except we assert on failure. + */ +void gem_context_set_persistence(int i915, uint32_t ctx, bool state) +{ + igt_assert_eq(__gem_context_set_persistence(i915, ctx, state), 0); +} + int __gem_context_clone(int i915, uint32_t src, unsigned int share, diff --git a/lib/i915/gem_context.h b/lib/i915/gem_context.h index 8043c3401..c0d4c9615 100644 --- a/lib/i915/gem_context.h +++ b/lib/i915/gem_context.h @@ -24,6 +24,11 @@ #ifndef GEM_CONTEXT_H #define GEM_CONTEXT_H +#include +#include + +struct drm_i915_gem_context_param; + uint32_t gem_context_create(int fd); int __gem_context_create(int fd, uint32_t *ctx_id); void gem_context_destroy(int fd, uint32_t ctx_id); @@ -58,6 +63,9 @@ int __gem_context_get_param(int fd, struct drm_i915_gem_context_param *p); int __gem_context_set_priority(int fd, uint32_t ctx, int prio); void gem_context_set_priority(int fd, uint32_t ctx, int prio); +int __gem_context_set_persistence(int i915, uint32_t ctx, bool state); +void gem_context_set_persistence(int i915, uint32_t ctx, bool state); + bool gem_context_has_engine(int fd, uint32_t ctx, uint64_t engine); #endif /* GEM_CONTEXT_H */ diff --git a/lib/igt_dummyload.c b/lib/igt_dummyload.c index 65b5cc927..6060878dd 100644 --- a/lib/igt_dummyload.c +++ b/lib/igt_dummyload.c @@ -450,7 +450,8 @@ void igt_spin_free(int fd, igt_spin_t *spin) gem_close(fd, spin->poll_handle); } - gem_close(fd, spin->handle); + if (spin->handle) + gem_close(fd, spin->handle); if (spin->out_fence >= 0) close(spin->out_fence); diff --git a/lib/ioctl_wrappers.c b/lib/ioctl_wrappers.c index 280fdd624..628f8b830 100644 --- a/lib/ioctl_wrappers.c +++ b/lib/ioctl_wrappers.c @@ -445,6 +445,7 @@ int gem_wait(int fd, uint32_t handle, int64_t *timeout_ns) ret = 0; if (igt_ioctl(fd, DRM_IOCTL_I915_GEM_WAIT, )) ret = -errno; + errno = 0; if (timeout_ns) *timeout_ns = wait.timeout_ns; diff --git a/tests/Makefile.sources b/tests/Makefile.sources index 343be0500..093eb57f3 100644 --- a/tests/Makefile.sources +++ b/tests/Makefile.sources @@ -154,6 +154,9 @@ gem_ctx_isolation_SOURCES = i915/gem_ctx_isolation.c TESTS_progs += gem_ctx_param gem_ctx_param_SOURCES = i915/gem_ctx_param.c +TESTS_progs += gem_ctx_persistence +gem_ctx_persistence_SOURCES = i915/gem_ctx_persistence.c + TESTS_progs += gem_ctx_shared gem_ctx_shared_SOURCES = i915/gem_ctx_shared.c diff --git a/tests/i915/gem_ctx_persistence.c b/tests/i915/gem_ctx_persistence.c new file mode 100644 index 0..d6ef6b900 --- /dev/null +++ b/tests/i915/gem_ctx_persistence.c @@ -0,0 +1,353 @@ +/* + * Copyright © 2019 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software,