All of lore.kernel.org
 help / color / mirror / Atom feed
From: Janusz Krzysztofik <janusz.krzysztofik@linux.intel.com>
To: igt-dev@lists.freedesktop.org
Cc: intel-gfx@lists.freedesktop.org
Subject: [RFC PATCH i-g-t v3 1/4] lib: Move redundant local helpers to lib/
Date: Mon, 28 Oct 2019 16:53:15 +0100	[thread overview]
Message-ID: <20191028155318.23416-2-janusz.krzysztofik@linux.intel.com> (raw)
In-Reply-To: <20191028155318.23416-1-janusz.krzysztofik@linux.intel.com>

Two tests - gem_exec_reloc and gem_softpin - define local helpers for
calculation of softpin offset canonical addresses.  As more users are
expected, replace those local instances with a single shared one under
lib/.

Signed-off-by: Janusz Krzysztofik <janusz.krzysztofik@linux.intel.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
---
 lib/igt_x86.c               | 13 +++++++++++++
 lib/igt_x86.h               |  5 +++++
 tests/i915/gem_exec_reloc.c | 16 +++-------------
 tests/i915/gem_softpin.c    | 13 +------------
 4 files changed, 22 insertions(+), 25 deletions(-)

diff --git a/lib/igt_x86.c b/lib/igt_x86.c
index 6ac700df..13d7c6e5 100644
--- a/lib/igt_x86.c
+++ b/lib/igt_x86.c
@@ -190,6 +190,19 @@ char *igt_x86_features_to_string(unsigned features, char *line)
 }
 #endif
 
+/**
+ * gen8_canonical_addr
+ * Used to convert any address into canonical form, i.e. [63:48] == [47].
+ * Based on kernel's sign_extend64 implementation.
+ * @address - a virtual address
+ */
+uint64_t gen8_canonical_addr(uint64_t address)
+{
+	int shift = 63 - GEN8_HIGH_ADDRESS_BIT;
+
+	return (int64_t)(address << shift) >> shift;
+}
+
 #if defined(__x86_64__) && !defined(__clang__)
 #pragma GCC push_options
 #pragma GCC target("sse4.1")
diff --git a/lib/igt_x86.h b/lib/igt_x86.h
index c7b84dec..8c7eb5e8 100644
--- a/lib/igt_x86.h
+++ b/lib/igt_x86.h
@@ -30,6 +30,8 @@
 #ifndef IGT_X86_H
 #define IGT_X86_H
 
+#include <stdint.h>
+
 #define MMX	0x1
 #define SSE	0x2
 #define SSE2	0x4
@@ -56,6 +58,9 @@ static inline char *igt_x86_features_to_string(unsigned features, char *line)
 }
 #endif
 
+#define GEN8_HIGH_ADDRESS_BIT 47
+uint64_t gen8_canonical_addr(uint64_t address);
+
 void igt_memcpy_from_wc(void *dst, const void *src, unsigned long len);
 
 #endif /* IGT_X86_H */
diff --git a/tests/i915/gem_exec_reloc.c b/tests/i915/gem_exec_reloc.c
index fdd9661d..61f8b755 100644
--- a/tests/i915/gem_exec_reloc.c
+++ b/tests/i915/gem_exec_reloc.c
@@ -23,6 +23,7 @@
 
 #include "igt.h"
 #include "igt_dummyload.h"
+#include "igt_x86.h"
 
 IGT_TEST_DESCRIPTION("Basic sanity check of execbuf-ioctl relocations.");
 
@@ -500,17 +501,6 @@ static void basic_reloc(int fd, unsigned before, unsigned after, unsigned flags)
 	gem_close(fd, obj.handle);
 }
 
-static inline uint64_t sign_extend(uint64_t x, int index)
-{
-	int shift = 63 - index;
-	return (int64_t)(x << shift) >> shift;
-}
-
-static uint64_t gen8_canonical_address(uint64_t address)
-{
-	return sign_extend(address, 47);
-}
-
 static void basic_range(int fd, unsigned flags)
 {
 	struct drm_i915_gem_relocation_entry reloc[128];
@@ -537,7 +527,7 @@ static void basic_range(int fd, unsigned flags)
 	for (int i = 0; i <= count; i++) {
 		obj[n].handle = gem_create(fd, 4096);
 		obj[n].offset = (1ull << (i + 12)) - 4096;
-		obj[n].offset = gen8_canonical_address(obj[n].offset);
+		obj[n].offset = gen8_canonical_addr(obj[n].offset);
 		obj[n].flags = EXEC_OBJECT_PINNED | EXEC_OBJECT_SUPPORTS_48B_ADDRESS;
 		gem_write(fd, obj[n].handle, 0, &bbe, sizeof(bbe));
 		execbuf.buffers_ptr = to_user_pointer(&obj[n]);
@@ -557,7 +547,7 @@ static void basic_range(int fd, unsigned flags)
 	for (int i = 1; i < count; i++) {
 		obj[n].handle = gem_create(fd, 4096);
 		obj[n].offset = 1ull << (i + 12);
-		obj[n].offset = gen8_canonical_address(obj[n].offset);
+		obj[n].offset = gen8_canonical_addr(obj[n].offset);
 		obj[n].flags = EXEC_OBJECT_PINNED | EXEC_OBJECT_SUPPORTS_48B_ADDRESS;
 		gem_write(fd, obj[n].handle, 0, &bbe, sizeof(bbe));
 		execbuf.buffers_ptr = to_user_pointer(&obj[n]);
diff --git a/tests/i915/gem_softpin.c b/tests/i915/gem_softpin.c
index b9ff532e..17bd40a4 100644
--- a/tests/i915/gem_softpin.c
+++ b/tests/i915/gem_softpin.c
@@ -27,22 +27,11 @@
  */
 
 #include "igt.h"
+#include "igt_x86.h"
 
 #define EXEC_OBJECT_PINNED	(1<<4)
 #define EXEC_OBJECT_SUPPORTS_48B_ADDRESS (1<<3)
 
-/* gen8_canonical_addr
- * Used to convert any address into canonical form, i.e. [63:48] == [47].
- * Based on kernel's sign_extend64 implementation.
- * @address - a virtual address
-*/
-#define GEN8_HIGH_ADDRESS_BIT 47
-static uint64_t gen8_canonical_addr(uint64_t address)
-{
-	__u8 shift = 63 - GEN8_HIGH_ADDRESS_BIT;
-	return (__s64)(address << shift) >> shift;
-}
-
 static void test_invalid(int fd)
 {
 	const uint32_t bbe = MI_BATCH_BUFFER_END;
-- 
2.21.0

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

WARNING: multiple messages have this Message-ID (diff)
From: Janusz Krzysztofik <janusz.krzysztofik@linux.intel.com>
To: igt-dev@lists.freedesktop.org
Cc: intel-gfx@lists.freedesktop.org
Subject: [Intel-gfx] [RFC PATCH i-g-t v3 1/4] lib: Move redundant local helpers to lib/
Date: Mon, 28 Oct 2019 16:53:15 +0100	[thread overview]
Message-ID: <20191028155318.23416-2-janusz.krzysztofik@linux.intel.com> (raw)
Message-ID: <20191028155315.lEmrMOhAH5nMLFiKpZw8OLn1HLr7AVO109eT4cLh3-w@z> (raw)
In-Reply-To: <20191028155318.23416-1-janusz.krzysztofik@linux.intel.com>

Two tests - gem_exec_reloc and gem_softpin - define local helpers for
calculation of softpin offset canonical addresses.  As more users are
expected, replace those local instances with a single shared one under
lib/.

Signed-off-by: Janusz Krzysztofik <janusz.krzysztofik@linux.intel.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
---
 lib/igt_x86.c               | 13 +++++++++++++
 lib/igt_x86.h               |  5 +++++
 tests/i915/gem_exec_reloc.c | 16 +++-------------
 tests/i915/gem_softpin.c    | 13 +------------
 4 files changed, 22 insertions(+), 25 deletions(-)

diff --git a/lib/igt_x86.c b/lib/igt_x86.c
index 6ac700df..13d7c6e5 100644
--- a/lib/igt_x86.c
+++ b/lib/igt_x86.c
@@ -190,6 +190,19 @@ char *igt_x86_features_to_string(unsigned features, char *line)
 }
 #endif
 
+/**
+ * gen8_canonical_addr
+ * Used to convert any address into canonical form, i.e. [63:48] == [47].
+ * Based on kernel's sign_extend64 implementation.
+ * @address - a virtual address
+ */
+uint64_t gen8_canonical_addr(uint64_t address)
+{
+	int shift = 63 - GEN8_HIGH_ADDRESS_BIT;
+
+	return (int64_t)(address << shift) >> shift;
+}
+
 #if defined(__x86_64__) && !defined(__clang__)
 #pragma GCC push_options
 #pragma GCC target("sse4.1")
diff --git a/lib/igt_x86.h b/lib/igt_x86.h
index c7b84dec..8c7eb5e8 100644
--- a/lib/igt_x86.h
+++ b/lib/igt_x86.h
@@ -30,6 +30,8 @@
 #ifndef IGT_X86_H
 #define IGT_X86_H
 
+#include <stdint.h>
+
 #define MMX	0x1
 #define SSE	0x2
 #define SSE2	0x4
@@ -56,6 +58,9 @@ static inline char *igt_x86_features_to_string(unsigned features, char *line)
 }
 #endif
 
+#define GEN8_HIGH_ADDRESS_BIT 47
+uint64_t gen8_canonical_addr(uint64_t address);
+
 void igt_memcpy_from_wc(void *dst, const void *src, unsigned long len);
 
 #endif /* IGT_X86_H */
diff --git a/tests/i915/gem_exec_reloc.c b/tests/i915/gem_exec_reloc.c
index fdd9661d..61f8b755 100644
--- a/tests/i915/gem_exec_reloc.c
+++ b/tests/i915/gem_exec_reloc.c
@@ -23,6 +23,7 @@
 
 #include "igt.h"
 #include "igt_dummyload.h"
+#include "igt_x86.h"
 
 IGT_TEST_DESCRIPTION("Basic sanity check of execbuf-ioctl relocations.");
 
@@ -500,17 +501,6 @@ static void basic_reloc(int fd, unsigned before, unsigned after, unsigned flags)
 	gem_close(fd, obj.handle);
 }
 
-static inline uint64_t sign_extend(uint64_t x, int index)
-{
-	int shift = 63 - index;
-	return (int64_t)(x << shift) >> shift;
-}
-
-static uint64_t gen8_canonical_address(uint64_t address)
-{
-	return sign_extend(address, 47);
-}
-
 static void basic_range(int fd, unsigned flags)
 {
 	struct drm_i915_gem_relocation_entry reloc[128];
@@ -537,7 +527,7 @@ static void basic_range(int fd, unsigned flags)
 	for (int i = 0; i <= count; i++) {
 		obj[n].handle = gem_create(fd, 4096);
 		obj[n].offset = (1ull << (i + 12)) - 4096;
-		obj[n].offset = gen8_canonical_address(obj[n].offset);
+		obj[n].offset = gen8_canonical_addr(obj[n].offset);
 		obj[n].flags = EXEC_OBJECT_PINNED | EXEC_OBJECT_SUPPORTS_48B_ADDRESS;
 		gem_write(fd, obj[n].handle, 0, &bbe, sizeof(bbe));
 		execbuf.buffers_ptr = to_user_pointer(&obj[n]);
@@ -557,7 +547,7 @@ static void basic_range(int fd, unsigned flags)
 	for (int i = 1; i < count; i++) {
 		obj[n].handle = gem_create(fd, 4096);
 		obj[n].offset = 1ull << (i + 12);
-		obj[n].offset = gen8_canonical_address(obj[n].offset);
+		obj[n].offset = gen8_canonical_addr(obj[n].offset);
 		obj[n].flags = EXEC_OBJECT_PINNED | EXEC_OBJECT_SUPPORTS_48B_ADDRESS;
 		gem_write(fd, obj[n].handle, 0, &bbe, sizeof(bbe));
 		execbuf.buffers_ptr = to_user_pointer(&obj[n]);
diff --git a/tests/i915/gem_softpin.c b/tests/i915/gem_softpin.c
index b9ff532e..17bd40a4 100644
--- a/tests/i915/gem_softpin.c
+++ b/tests/i915/gem_softpin.c
@@ -27,22 +27,11 @@
  */
 
 #include "igt.h"
+#include "igt_x86.h"
 
 #define EXEC_OBJECT_PINNED	(1<<4)
 #define EXEC_OBJECT_SUPPORTS_48B_ADDRESS (1<<3)
 
-/* gen8_canonical_addr
- * Used to convert any address into canonical form, i.e. [63:48] == [47].
- * Based on kernel's sign_extend64 implementation.
- * @address - a virtual address
-*/
-#define GEN8_HIGH_ADDRESS_BIT 47
-static uint64_t gen8_canonical_addr(uint64_t address)
-{
-	__u8 shift = 63 - GEN8_HIGH_ADDRESS_BIT;
-	return (__s64)(address << shift) >> shift;
-}
-
 static void test_invalid(int fd)
 {
 	const uint32_t bbe = MI_BATCH_BUFFER_END;
-- 
2.21.0

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

  reply	other threads:[~2019-10-28 15:53 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-28 15:53 [RFC PATCH i-g-t v3 0/4] Calculate softpin offsets from actual page size Janusz Krzysztofik
2019-10-28 15:53 ` [Intel-gfx] " Janusz Krzysztofik
2019-10-28 15:53 ` Janusz Krzysztofik [this message]
2019-10-28 15:53   ` [Intel-gfx] [RFC PATCH i-g-t v3 1/4] lib: Move redundant local helpers to lib/ Janusz Krzysztofik
2019-10-28 15:53 ` [RFC PATCH i-g-t v3 2/4] lib: Add GEM minimum page size helper Janusz Krzysztofik
2019-10-28 15:53   ` [Intel-gfx] " Janusz Krzysztofik
2019-10-28 15:53 ` [RFC PATCH i-g-t v3 3/4] tests/gem_exec_reloc: Calculate softpin offsets from actual page size Janusz Krzysztofik
2019-10-28 15:53   ` [Intel-gfx] " Janusz Krzysztofik
2019-10-28 15:53 ` [RFC PATCH i-g-t v3 4/4] tests/gem_ctx_shared: Calculate object attributs " Janusz Krzysztofik
2019-10-28 15:53   ` [Intel-gfx] " Janusz Krzysztofik
2019-10-28 17:20 ` [igt-dev] ✗ Fi.CI.BAT: failure for Calculate softpin offsets " 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=20191028155318.23416-2-janusz.krzysztofik@linux.intel.com \
    --to=janusz.krzysztofik@linux.intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=intel-gfx@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.