public inbox for igt-dev@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Arkadiusz Hiler <arkadiusz.hiler@intel.com>
To: igt-dev@lists.freedesktop.org
Subject: [igt-dev] [PATCH i-g-t v2] tests/gem_exec_balancer: Manually calculate VLA struct sizes
Date: Tue,  4 Jun 2019 16:15:55 +0300	[thread overview]
Message-ID: <20190604131555.1717-1-arkadiusz.hiler@intel.com> (raw)
In-Reply-To: <20190604125955.28806-1-arkadiusz.hiler@intel.com>

VLA in structs (struct { int array[count] }) is a GCC extension, so
let's avoid using it.

v2: don't be overzealous in converting static-size structs

Cc: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Simon Ser <simon.ser@intel.com>
Signed-off-by: Arkadiusz Hiler <arkadiusz.hiler@intel.com>
---
 tests/i915/gem_exec_balancer.c | 64 ++++++++++++++++++++++------------
 1 file changed, 42 insertions(+), 22 deletions(-)

diff --git a/tests/i915/gem_exec_balancer.c b/tests/i915/gem_exec_balancer.c
index 33b17fc5..29438381 100644
--- a/tests/i915/gem_exec_balancer.c
+++ b/tests/i915/gem_exec_balancer.c
@@ -32,6 +32,26 @@ IGT_TEST_DESCRIPTION("Exercise in-kernel load-balancing");
 
 #define INSTANCE_COUNT (1 << I915_PMU_SAMPLE_INSTANCE_BITS)
 
+static size_t sizeof_load_balance(int count)
+{
+	return offsetof(struct i915_context_engines_load_balance,
+			engines[count]);
+}
+
+static size_t sizeof_param_engines(int count)
+{
+	return offsetof(struct i915_context_param_engines,
+			engines[count]);
+}
+
+static size_t sizeof_engines_bond(int count)
+{
+	return offsetof(struct i915_context_engines_bond,
+			engines[count]);
+}
+
+#define alloca0(sz) ({ size_t sz__ = (sz); memset(alloca(sz__), 0, sz__); })
+
 static bool has_class_instance(int i915, uint16_t class, uint16_t instance)
 {
 	int fd;
@@ -93,16 +113,17 @@ static int __set_engines(int i915, uint32_t ctx,
 			 const struct i915_engine_class_instance *ci,
 			 unsigned int count)
 {
-	I915_DEFINE_CONTEXT_PARAM_ENGINES(engines, count);
+	struct i915_context_param_engines *engines =
+		alloca0(sizeof_param_engines(count));
 	struct drm_i915_gem_context_param p = {
 		.ctx_id = ctx,
 		.param = I915_CONTEXT_PARAM_ENGINES,
-		.size = sizeof(engines),
-		.value = to_user_pointer(&engines)
+		.size = sizeof_param_engines(count),
+		.value = to_user_pointer(engines)
 	};
 
-	engines.extensions = 0;
-	memcpy(engines.engines, ci, sizeof(engines.engines));
+	engines->extensions = 0;
+	memcpy(engines->engines, ci, sizeof(engines->engines));
 
 	return __gem_context_set_param(i915, &p);
 }
@@ -119,30 +140,30 @@ static int __set_load_balancer(int i915, uint32_t ctx,
 			       unsigned int count,
 			       void *ext)
 {
-	I915_DEFINE_CONTEXT_ENGINES_LOAD_BALANCE(balancer, count);
-	I915_DEFINE_CONTEXT_PARAM_ENGINES(engines, 1 + count);
+	struct i915_context_engines_load_balance *balancer =
+		alloca0(sizeof_load_balance(count));
+	struct i915_context_param_engines *engines =
+		alloca0(sizeof_param_engines(count + 1));
 	struct drm_i915_gem_context_param p = {
 		.ctx_id = ctx,
 		.param = I915_CONTEXT_PARAM_ENGINES,
-		.size = sizeof(engines),
-		.value = to_user_pointer(&engines)
+		.size = sizeof_param_engines(count + 1),
+		.value = to_user_pointer(engines)
 	};
 
-	memset(&balancer, 0, sizeof(balancer));
-	balancer.base.name = I915_CONTEXT_ENGINES_EXT_LOAD_BALANCE;
-	balancer.base.next_extension = to_user_pointer(ext);
+	balancer->base.name = I915_CONTEXT_ENGINES_EXT_LOAD_BALANCE;
+	balancer->base.next_extension = to_user_pointer(ext);
 
 	igt_assert(count);
-	balancer.num_siblings = count;
-	memcpy(balancer.engines, ci, count * sizeof(*ci));
+	balancer->num_siblings = count;
+	memcpy(balancer->engines, ci, count * sizeof(*ci));
 
-	memset(&engines, 0, sizeof(engines));
-	engines.extensions = to_user_pointer(&balancer);
-	engines.engines[0].engine_class =
+	engines->extensions = to_user_pointer(balancer);
+	engines->engines[0].engine_class =
 		I915_ENGINE_CLASS_INVALID;
-	engines.engines[0].engine_instance =
+	engines->engines[0].engine_instance =
 		I915_ENGINE_CLASS_INVALID_NONE;
-	memcpy(engines.engines + 1, ci, count * sizeof(*ci));
+	memcpy(engines->engines + 1, ci, count * sizeof(*ci));
 
 	return __gem_context_set_param(i915, &p);
 }
@@ -709,15 +730,14 @@ static void indices(int i915)
 			continue;
 
 		for (int n = 0; n < count; n++) {
-			I915_DEFINE_CONTEXT_ENGINES_LOAD_BALANCE(*balancer,
-								 count);
+			struct i915_context_engines_load_balance *balancer;
 
 			engines.engines[nengines].engine_class =
 				I915_ENGINE_CLASS_INVALID;
 			engines.engines[nengines].engine_instance =
 				I915_ENGINE_CLASS_INVALID_NONE;
 
-			balancer = calloc(sizeof(*balancer), 1);
+			balancer = calloc(sizeof_load_balance(1), 1);
 			igt_assert(balancer);
 
 			balancer->base.name =
-- 
2.21.0

_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

  parent reply	other threads:[~2019-06-04 13:16 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-04 12:59 [igt-dev] [PATCH i-g-t 1/4] tests/gem_exec_balancer: Manually calculate VLA struct sizes Arkadiusz Hiler
2019-06-04 12:59 ` [igt-dev] [PATCH i-g-t 2/4] Makefile: Do not nest new gem tests in i915 directory Arkadiusz Hiler
2019-06-04 13:02   ` Chris Wilson
2019-06-04 13:18     ` Arkadiusz Hiler
2019-06-05  9:28   ` Petri Latvala
2019-06-04 12:59 ` [igt-dev] [PATCH i-g-t 3/4] meson: Add gem_exec_balancer to test-list.txt Arkadiusz Hiler
2019-06-05  9:11   ` Petri Latvala
2019-06-04 12:59 ` [igt-dev] [PATCH i-g-t 4/4] tools/meson: Build igt_stats Arkadiusz Hiler
2019-06-05  9:10   ` Petri Latvala
2019-06-04 13:03 ` [igt-dev] [PATCH i-g-t 1/4] tests/gem_exec_balancer: Manually calculate VLA struct sizes Chris Wilson
2019-06-04 13:15 ` Arkadiusz Hiler [this message]
2019-06-04 13:23   ` [igt-dev] [PATCH i-g-t v2] " Chris Wilson
2019-06-04 15:14 ` [igt-dev] ✓ Fi.CI.BAT: success for series starting with [i-g-t,v2] tests/gem_exec_balancer: Manually calculate VLA struct sizes (rev2) Patchwork
2019-06-05  7:32 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190604131555.1717-1-arkadiusz.hiler@intel.com \
    --to=arkadiusz.hiler@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox