Skip to contentSkip to conversation

gem_ctx_param: Update for context priorities

PATCH In review Tvrtko Ursulin 4 participants 5 messages Nov 8, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gem_ctx_param: Update for context priorities

From: Tvrtko Ursulin <[email protected]>

Update the test to check for context priority get and set and at the same time bump the invalid flag tests.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=103107
Cc: Daniel Vetter <[email protected]>
Cc: Chris Wilson <[email protected]>
Cc: Joonas Lahtinen <[email protected]>

---
 lib/i915/gem_context.c | 25 ++++++++++++++++++++++---
 lib/i915/gem_context.h |  2 ++
 tests/gem_ctx_param.c  | 20 +++++++++++++++++++-
 3 files changed, 43 insertions(+), 4 deletions(-)
lib/i915/gem_context.c +22 -3
index 6d9edf5e3263..778dc6ca76e3 100644
@@ -198,8 +198,6 @@ void gem_context_require_bannable(int fd)
 	igt_require(has_ban_period || has_bannable);
 }
 
-#define LOCAL_I915_CONTEXT_PARAM_PRIORITY 0x6
-
 /**
  * __gem_context_set_priority:
  * @fd: open i915 drm file descriptor
@@ -219,7 +217,7 @@ int __gem_context_set_priority(int fd, uint32_t ctx_id, int prio)
 	memset(&p, 0, sizeof(p));
 	p.context = ctx_id;
 	p.size = 0;
-	p.param = LOCAL_I915_CONTEXT_PARAM_PRIORITY;
+	p.param = LOCAL_CONTEXT_PARAM_PRIORITY;
 	p.value = prio;
 
 	return __gem_context_set_param(fd, &p);
@@ -237,3 +235,24 @@ void gem_context_set_priority(int fd, uint32_t ctx_id, int prio)
 {
 	igt_assert(__gem_context_set_priority(fd, ctx_id, prio) == 0);
 }
+
+/**
+ * gem_context_get_priority:
+ * @fd: open i915 drm file descriptor
+ * @ctx_id: i915 context id
+ *
+ * Returns the current context priority.
+ */
+int gem_context_get_priority(int fd, uint32_t ctx_id)
+{
+	struct local_i915_gem_context_param p;
+
+	memset(&p, 0, sizeof(p));
+	p.context = ctx_id;
+	p.size = 0;
+	p.param = LOCAL_CONTEXT_PARAM_PRIORITY;
+
+	igt_assert_eq(__gem_context_get_param(fd, &p), 0);
+
+	return p.value;
+}
lib/i915/gem_context.h +2 -0
index a2339c4b6da2..ac89512225e5 100644
@@ -36,6 +36,7 @@ struct local_i915_gem_context_param {
 #define LOCAL_CONTEXT_PARAM_GTT_SIZE	0x3
 #define LOCAL_CONTEXT_PARAM_NO_ERROR_CAPTURE	0x4
 #define LOCAL_CONTEXT_PARAM_BANNABLE	0x5
+#define LOCAL_CONTEXT_PARAM_PRIORITY	0x6
 	uint64_t value;
 };
 void gem_context_require_bannable(int fd);
@@ -50,5 +51,6 @@ int __gem_context_get_param(int fd, struct local_i915_gem_context_param *p);
 #define LOCAL_I915_CONTEXT_MIN_USER_PRIORITY	-1023
 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_get_priority(int fd, uint32_t ctx);
 
 #endif /* GEM_CONTEXT_H */
tests/gem_ctx_param.c +19 -1
index efdaf191a1ed..43f6f96e0857 100644
@@ -136,11 +136,29 @@ igt_main
 		gem_context_set_param(fd, &arg);
 	}
 
+	igt_subtest_group {
+		igt_fixture {
+			igt_require(gem_scheduler_enabled(fd));
+			igt_require(gem_scheduler_has_ctx_priority(fd));
+		}
+
+		igt_subtest("priority-get") {
+			igt_assert_eq(gem_context_get_priority(fd, ctx), 0);
+		}
+
+		igt_subtest("priority-set") {
+			int prio = LOCAL_I915_CONTEXT_DEFAULT_PRIORITY - 1;
+
+			gem_context_set_priority(fd, ctx, prio);
+			igt_assert_eq(gem_context_get_priority(fd, ctx), prio);
+		}
+	}
+
 	/* NOTE: This testcase intentionally tests for the next free parameter
 	 * to catch ABI extensions. Don't "fix" this testcase without adding all
 	 * the tests for the new param first.
 	 */
-	arg.param = LOCAL_CONTEXT_PARAM_BANNABLE + 1;
+	arg.param = LOCAL_CONTEXT_PARAM_PRIORITY + 1;
 
 	igt_subtest("invalid-param-get") {
 		arg.context = ctx;
Signature · 6 lines
2.14.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#1 lore raw

On Wed, Nov 08, 2017 at 09:47:20AM +0000, Tvrtko Ursulin wrote:

Subject: [Intel-gfx] [PATCH] gem_ctx_param: Update for context priorities

Can you resend with PATCH i-g-t so this gets to the correct patchwork?

Signature · 5 lines
Petri Latvala
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#2 lore raw
In reply to Tvrtko Ursulin
Quoted 96 lines · Tvrtko Ursulin

From: Tvrtko Ursulin <[email protected]>

Update the test to check for context priority get and set and at the same time bump the invalid flag tests.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=103107
Cc: Daniel Vetter <[email protected]>
Cc: Chris Wilson <[email protected]>
Cc: Joonas Lahtinen <[email protected]>

---
 lib/i915/gem_context.c | 25 ++++++++++++++++++++++---
 lib/i915/gem_context.h |  2 ++
 tests/gem_ctx_param.c  | 20 +++++++++++++++++++-
 3 files changed, 43 insertions(+), 4 deletions(-)
lib/i915/gem_context.c +22 -3
index 6d9edf5e3263..778dc6ca76e3 100644
@@ -198,8 +198,6 @@ void gem_context_require_bannable(int fd)
 	igt_require(has_ban_period || has_bannable);
 }
 
-#define LOCAL_I915_CONTEXT_PARAM_PRIORITY 0x6
-
 /**
  * __gem_context_set_priority:
  * @fd: open i915 drm file descriptor
@@ -219,7 +217,7 @@ int __gem_context_set_priority(int fd, uint32_t ctx_id, int prio)
 	memset(&p, 0, sizeof(p));
 	p.context = ctx_id;
 	p.size = 0;
-	p.param = LOCAL_I915_CONTEXT_PARAM_PRIORITY;
+	p.param = LOCAL_CONTEXT_PARAM_PRIORITY;
 	p.value = prio;
 
 	return __gem_context_set_param(fd, &p);
@@ -237,3 +235,24 @@ void gem_context_set_priority(int fd, uint32_t ctx_id, int prio)
 {
 	igt_assert(__gem_context_set_priority(fd, ctx_id, prio) == 0);
 }
+
+/**
+ * gem_context_get_priority:
+ * @fd: open i915 drm file descriptor
+ * @ctx_id: i915 context id
+ *
+ * Returns the current context priority.
+ */
+int gem_context_get_priority(int fd, uint32_t ctx_id)
+{
+	struct local_i915_gem_context_param p;
+
+	memset(&p, 0, sizeof(p));
+	p.context = ctx_id;
+	p.size = 0;
+	p.param = LOCAL_CONTEXT_PARAM_PRIORITY;
+
+	igt_assert_eq(__gem_context_get_param(fd, &p), 0);
+
+	return p.value;
+}
lib/i915/gem_context.h +2 -0
index a2339c4b6da2..ac89512225e5 100644
@@ -36,6 +36,7 @@ struct local_i915_gem_context_param {
 #define LOCAL_CONTEXT_PARAM_GTT_SIZE	0x3
 #define LOCAL_CONTEXT_PARAM_NO_ERROR_CAPTURE	0x4
 #define LOCAL_CONTEXT_PARAM_BANNABLE	0x5
+#define LOCAL_CONTEXT_PARAM_PRIORITY	0x6
 	uint64_t value;
 };
 void gem_context_require_bannable(int fd);
@@ -50,5 +51,6 @@ int __gem_context_get_param(int fd, struct local_i915_gem_context_param *p);
 #define LOCAL_I915_CONTEXT_MIN_USER_PRIORITY	-1023
 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_get_priority(int fd, uint32_t ctx);
 
 #endif /* GEM_CONTEXT_H */
tests/gem_ctx_param.c +6 -0
index efdaf191a1ed..43f6f96e0857 100644
@@ -136,11 +136,29 @@ igt_main
 		gem_context_set_param(fd, &arg);
 	}
 
+	igt_subtest_group {
+		igt_fixture {
+			igt_require(gem_scheduler_enabled(fd));
+			igt_require(gem_scheduler_has_ctx_priority(fd));
+		}
+

tests/gem_ctx_param.c igt_main · line 154

Quoted 10 lines
tests/gem_ctx_param.c +10 -0
+		igt_subtest("priority-get") {
+			igt_assert_eq(gem_context_get_priority(fd, ctx), 0);
+		}
+
+		igt_subtest("priority-set") {
+			int prio = LOCAL_I915_CONTEXT_DEFAULT_PRIORITY - 1;
+
+			gem_context_set_priority(fd, ctx, prio);
+			igt_assert_eq(gem_context_get_priority(fd, ctx), prio);
+		}

Not sure this is really a useful test. This I would like to see tested would be:
- invalid priorities, i.e. above and below the max
- invalid priorities for non CAP_SYS_NICE, especially checking that the fd-passing (which X does) works in a reasonable way: root opens fd, passes to non-root (just change uid), do we reject higher priorities?

This is the kind of stuff that I think is worth checking when adding new uapi, to catch potential security issues where the kernel code doesn't properly validate&reject invalid input.

If all this test ends up doing is busywork every time a new flag is added I'll concur with Chris and it's probably best to just throw it all out.

But that's my own stance, I'm not really involved in gem deeply at all, so what exactly you end up going with is up to you and Chris and Jooans and everyone.

Thanks, Daniel

Quoted 18 lines
tests/gem_ctx_param.c +3 -1
+	}
+
 	/* NOTE: This testcase intentionally tests for the next free parameter
 	 * to catch ABI extensions. Don't "fix" this testcase without adding all
 	 * the tests for the new param first.
 	 */
-	arg.param = LOCAL_CONTEXT_PARAM_BANNABLE + 1;
+	arg.param = LOCAL_CONTEXT_PARAM_PRIORITY + 1;
 
 	igt_subtest("invalid-param-get") {
 		arg.context = ctx;
Signature · 6 lines
2.14.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#3 lore raw
Quoted 101 lines · Daniel Vetter
Quoted 100 lines · Tvrtko Ursulin

From: Tvrtko Ursulin <[email protected]>

Update the test to check for context priority get and set and at the same time bump the invalid flag tests.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=103107
Cc: Daniel Vetter <[email protected]>
Cc: Chris Wilson <[email protected]>
Cc: Joonas Lahtinen <[email protected]>

---
  lib/i915/gem_context.c | 25 ++++++++++++++++++++++---
  lib/i915/gem_context.h |  2 ++
  tests/gem_ctx_param.c  | 20 +++++++++++++++++++-
  3 files changed, 43 insertions(+), 4 deletions(-)
lib/i915/gem_context.c +22 -3
index 6d9edf5e3263..778dc6ca76e3 100644
@@ -198,8 +198,6 @@ void gem_context_require_bannable(int fd)
  	igt_require(has_ban_period || has_bannable);
  }
 
-#define LOCAL_I915_CONTEXT_PARAM_PRIORITY 0x6
-
  /**
   * __gem_context_set_priority:
   * @fd: open i915 drm file descriptor
@@ -219,7 +217,7 @@ int __gem_context_set_priority(int fd, uint32_t ctx_id, int prio)
  	memset(&p, 0, sizeof(p));
  	p.context = ctx_id;
  	p.size = 0;
-	p.param = LOCAL_I915_CONTEXT_PARAM_PRIORITY;
+	p.param = LOCAL_CONTEXT_PARAM_PRIORITY;
  	p.value = prio;
 
  	return __gem_context_set_param(fd, &p);
@@ -237,3 +235,24 @@ void gem_context_set_priority(int fd, uint32_t ctx_id, int prio)
  {
  	igt_assert(__gem_context_set_priority(fd, ctx_id, prio) == 0);
  }
+
+/**
+ * gem_context_get_priority:
+ * @fd: open i915 drm file descriptor
+ * @ctx_id: i915 context id
+ *
+ * Returns the current context priority.
+ */
+int gem_context_get_priority(int fd, uint32_t ctx_id)
+{
+	struct local_i915_gem_context_param p;
+
+	memset(&p, 0, sizeof(p));
+	p.context = ctx_id;
+	p.size = 0;
+	p.param = LOCAL_CONTEXT_PARAM_PRIORITY;
+
+	igt_assert_eq(__gem_context_get_param(fd, &p), 0);
+
+	return p.value;
+}
lib/i915/gem_context.h +2 -0
index a2339c4b6da2..ac89512225e5 100644
@@ -36,6 +36,7 @@ struct local_i915_gem_context_param {
  #define LOCAL_CONTEXT_PARAM_GTT_SIZE	0x3
  #define LOCAL_CONTEXT_PARAM_NO_ERROR_CAPTURE	0x4
  #define LOCAL_CONTEXT_PARAM_BANNABLE	0x5
+#define LOCAL_CONTEXT_PARAM_PRIORITY	0x6
  	uint64_t value;
  };
  void gem_context_require_bannable(int fd);
@@ -50,5 +51,6 @@ int __gem_context_get_param(int fd, struct local_i915_gem_context_param *p);
  #define LOCAL_I915_CONTEXT_MIN_USER_PRIORITY	-1023
  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_get_priority(int fd, uint32_t ctx);
 
  #endif /* GEM_CONTEXT_H */
tests/gem_ctx_param.c +10 -0
index efdaf191a1ed..43f6f96e0857 100644
@@ -136,11 +136,29 @@ igt_main
  		gem_context_set_param(fd, &arg);
  	}
 
+	igt_subtest_group {
+		igt_fixture {
+			igt_require(gem_scheduler_enabled(fd));
+			igt_require(gem_scheduler_has_ctx_priority(fd));
+		}
+
+		igt_subtest("priority-get") {
+			igt_assert_eq(gem_context_get_priority(fd, ctx), 0);
+		}
+
Quoted 8 lines

tests/gem_ctx_param.c igt_main · line 154

Quoted 6 lines
tests/gem_ctx_param.c +6 -0
+		igt_subtest("priority-set") {
+			int prio = LOCAL_I915_CONTEXT_DEFAULT_PRIORITY - 1;
+
+			gem_context_set_priority(fd, ctx, prio);
+			igt_assert_eq(gem_context_get_priority(fd, ctx), prio);
+		}

Not sure this is really a useful test. This I would like to see tested

"Better than nothing" and better than a broken one, just that. My re-action to this morning's bickering.

Quoted 9 lines

would be:
- invalid priorities, i.e. above and below the max
- invalid priorities for non CAP_SYS_NICE, especially checking that the fd-passing (which X does) works in a reasonable way: root opens fd, passes to non-root (just change uid), do we reject higher priorities?

This is the kind of stuff that I think is worth checking when adding new uapi, to catch potential security issues where the kernel code doesn't properly validate&reject invalid input.

Agreed, the more context params the less sense it makes to have it in gem_ctx_param and more sense to handle those details in dedicated tests for each feature.

Quoted 6 lines

If all this test ends up doing is busywork every time a new flag is added I'll concur with Chris and it's probably best to just throw it all out.

But that's my own stance, I'm not really involved in gem deeply at all, so what exactly you end up going with is up to you and Chris and Jooans and everyone.

No complaints from me to remove it, but it needs to go on the big GEM IGT TODO list to look at what's missing elsewhere, fill it in, and then remove. In the meantime, the sole contribution of this patch was that it stops an always failing test in a less aggressive manner than removing it completely before first doing the above.

Regards,

Tvrtko
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#4 lore raw
Quoted 132 lines · Tvrtko Ursulin
Quoted 97 lines · Daniel Vetter
Quoted 96 lines · Tvrtko Ursulin

From: Tvrtko Ursulin <[email protected]>

Update the test to check for context priority get and set and at the same time bump the invalid flag tests.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=103107
Cc: Daniel Vetter <[email protected]>
Cc: Chris Wilson <[email protected]>
Cc: Joonas Lahtinen <[email protected]>

---
  lib/i915/gem_context.c | 25 ++++++++++++++++++++++---
  lib/i915/gem_context.h |  2 ++
  tests/gem_ctx_param.c  | 20 +++++++++++++++++++-
  3 files changed, 43 insertions(+), 4 deletions(-)
lib/i915/gem_context.c +22 -3
index 6d9edf5e3263..778dc6ca76e3 100644
@@ -198,8 +198,6 @@ void gem_context_require_bannable(int fd)
  	igt_require(has_ban_period || has_bannable);
  }
-#define LOCAL_I915_CONTEXT_PARAM_PRIORITY 0x6
-
  /**
   * __gem_context_set_priority:
   * @fd: open i915 drm file descriptor
@@ -219,7 +217,7 @@ int __gem_context_set_priority(int fd, uint32_t ctx_id, int prio)
  	memset(&p, 0, sizeof(p));
  	p.context = ctx_id;
  	p.size = 0;
-	p.param = LOCAL_I915_CONTEXT_PARAM_PRIORITY;
+	p.param = LOCAL_CONTEXT_PARAM_PRIORITY;
  	p.value = prio;
  	return __gem_context_set_param(fd, &p);
@@ -237,3 +235,24 @@ void gem_context_set_priority(int fd, uint32_t ctx_id, int prio)
  {
  	igt_assert(__gem_context_set_priority(fd, ctx_id, prio) == 0);
  }
+
+/**
+ * gem_context_get_priority:
+ * @fd: open i915 drm file descriptor
+ * @ctx_id: i915 context id
+ *
+ * Returns the current context priority.
+ */
+int gem_context_get_priority(int fd, uint32_t ctx_id)
+{
+	struct local_i915_gem_context_param p;
+
+	memset(&p, 0, sizeof(p));
+	p.context = ctx_id;
+	p.size = 0;
+	p.param = LOCAL_CONTEXT_PARAM_PRIORITY;
+
+	igt_assert_eq(__gem_context_get_param(fd, &p), 0);
+
+	return p.value;
+}
lib/i915/gem_context.h +2 -0
index a2339c4b6da2..ac89512225e5 100644
@@ -36,6 +36,7 @@ struct local_i915_gem_context_param {
  #define LOCAL_CONTEXT_PARAM_GTT_SIZE	0x3
  #define LOCAL_CONTEXT_PARAM_NO_ERROR_CAPTURE	0x4
  #define LOCAL_CONTEXT_PARAM_BANNABLE	0x5
+#define LOCAL_CONTEXT_PARAM_PRIORITY	0x6
  	uint64_t value;
  };
  void gem_context_require_bannable(int fd);
@@ -50,5 +51,6 @@ int __gem_context_get_param(int fd, struct local_i915_gem_context_param *p);
  #define LOCAL_I915_CONTEXT_MIN_USER_PRIORITY	-1023
  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_get_priority(int fd, uint32_t ctx);
  #endif /* GEM_CONTEXT_H */
tests/gem_ctx_param.c +10 -0
index efdaf191a1ed..43f6f96e0857 100644
@@ -136,11 +136,29 @@ igt_main
  		gem_context_set_param(fd, &arg);
  	}
+	igt_subtest_group {
+		igt_fixture {
+			igt_require(gem_scheduler_enabled(fd));
+			igt_require(gem_scheduler_has_ctx_priority(fd));
+		}
+
+		igt_subtest("priority-get") {
+			igt_assert_eq(gem_context_get_priority(fd, ctx), 0);
+		}
+
Quoted 8 lines

tests/gem_ctx_param.c igt_main · line 154

Quoted 6 lines
tests/gem_ctx_param.c +6 -0
+		igt_subtest("priority-set") {
+			int prio = LOCAL_I915_CONTEXT_DEFAULT_PRIORITY - 1;
+
+			gem_context_set_priority(fd, ctx, prio);
+			igt_assert_eq(gem_context_get_priority(fd, ctx), prio);
+		}

Not sure this is really a useful test. This I would like to see tested

"Better than nothing" and better than a broken one, just that. My re-action to this morning's bickering.

Quoted 9 lines

would be:
- invalid priorities, i.e. above and below the max
- invalid priorities for non CAP_SYS_NICE, especially checking that the fd-passing (which X does) works in a reasonable way: root opens fd, passes to non-root (just change uid), do we reject higher priorities?

This is the kind of stuff that I think is worth checking when adding new uapi, to catch potential security issues where the kernel code doesn't properly validate&reject invalid input.

Agreed, the more context params the less sense it makes to have it in gem_ctx_param and more sense to handle those details in dedicated tests for each feature.

Quoted 6 lines

If all this test ends up doing is busywork every time a new flag is added I'll concur with Chris and it's probably best to just throw it all out.

But that's my own stance, I'm not really involved in gem deeply at all, so what exactly you end up going with is up to you and Chris and Jooans and everyone.

Quoted 5 lines

No complaints from me to remove it, but it needs to go on the big GEM IGT TODO list to look at what's missing elsewhere, fill it in, and then remove. In the meantime, the sole contribution of this patch was that it stops an always failing test in a less aggressive manner than removing it completely before first doing the above.

If all you want is not forget about the possible gaps, then remove the subtest Chris Wilson doesn't like and add it to the gem igt todo list.

I'm simply fed up bickering with Chris every time this comes up, it's not worth it, hence why I prefer to just nuke it and it's gone. We can also let it keep failing, CI has it greylisted ever since the regression was merged anyway.
-Daniel

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx