From: Ramalingam C <ramalingam.c@intel.com>
To: igt-dev <igt-dev@lists.freedesktop.org>
Subject: [igt-dev] [RFC 1/2] lib/i915/intel_memory_region: wrappers for memory regions ops
Date: Sat, 4 Jan 2020 15:38:25 +0530 [thread overview]
Message-ID: <20200104100826.21067-1-ramalingam.c@intel.com> (raw)
As of now lmem details are exposed from kernel through debugfs.
Wrappers for detecting the lmem and reading it's details are written.
Signed-off-by: Ramalingam C <ramalingam.c@intel.com>
cc: Zbigniew Kempczy_ski <zbigniew.kempczynski@intel.com>
cc: Vinay Belgaumkar <vinay.belgaumkar@intel.com>
---
lib/Makefile.sources | 2 +
lib/i915/intel_memory_region.c | 105 +++++++++++++++++++++++++++++++++
lib/i915/intel_memory_region.h | 30 ++++++++++
lib/meson.build | 1 +
4 files changed, 138 insertions(+)
create mode 100644 lib/i915/intel_memory_region.c
create mode 100644 lib/i915/intel_memory_region.h
diff --git a/lib/Makefile.sources b/lib/Makefile.sources
index 5dd3962ee019..9f1a457825f4 100644
--- a/lib/Makefile.sources
+++ b/lib/Makefile.sources
@@ -17,6 +17,8 @@ lib_source_list = \
i915/gem_mman.h \
i915/gem_vm.c \
i915/gem_vm.h \
+ i915/intel_memory_region.c \
+ i915/intel_memory_region.h \
i915_3d.h \
i915_reg.h \
i915_pciids.h \
diff --git a/lib/i915/intel_memory_region.c b/lib/i915/intel_memory_region.c
new file mode 100644
index 000000000000..95d0646c3863
--- /dev/null
+++ b/lib/i915/intel_memory_region.c
@@ -0,0 +1,105 @@
+/*
+ * Copyright © 2020 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, 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.
+ */
+
+#include <signal.h>
+#include <sys/ioctl.h>
+#include <sys/time.h>
+
+#include "intel_reg.h"
+#include "drmtest.h"
+#include "ioctl_wrappers.h"
+#include "igt_dummyload.h"
+#include "igt_gt.h"
+#include "intel_chipset.h"
+
+#include "i915/intel_memory_region.h"
+
+static void __debugfs_read(int fd, const char *param, char *buf, int len)
+{
+ len = igt_debugfs_simple_read(fd, param, buf, len);
+ if (len < 0)
+ igt_assert_eq(len, -ENODEV);
+}
+
+#define debugfs_read(fd, p, arr) __debugfs_read(fd, p, arr, sizeof(arr))
+
+#define MAX_i915_GEM_OBJ_BUF_LEN 5000
+
+static int get_i915_gem_objects_str(int drm_fd, char *buf)
+{
+ int fd;
+
+ fd = igt_debugfs_dir(drm_fd);
+ if (fd < 0)
+ return -ENODEV;
+
+ debugfs_read(fd, "i915_gem_objects", buf);
+ close(fd);
+
+ return 0;
+}
+/**
+ * gem_has_lmem:
+ * @fd: open i915 drm file descriptor
+ *
+ * Helper function to check if lmem is available on device.
+ *
+ * Returns: True if at least one lmem region was found.
+ */
+bool gem_has_lmem(int fd)
+{
+ char buf[MAX_i915_GEM_OBJ_BUF_LEN];
+
+ if (get_i915_gem_objects_str(fd, buf) < 0)
+ return false;
+
+ return strstr(buf, "local");
+}
+
+/**
+ * gem_lmem_total_size:
+ * @drm_fd: open i915 drm file descriptor
+ *
+ * Helper function to get the lmem size on device.
+ *
+ * Returns: returns lmem size if it is found else 0.
+ */
+uint64_t gem_lmem_total_size(int fd)
+{
+ char buf[MAX_i915_GEM_OBJ_BUF_LEN];
+ char *str;
+ int ret;
+
+ ret = get_i915_gem_objects_str(fd, buf);
+ if (ret < 0)
+ return 0;
+
+ str = strstr(buf, "local");
+ if (str) {
+ str = strstr(str, "total: ");
+ igt_assert_f(str, "expected string not found");
+ return strtoul(str + strlen("total: "), NULL, 16);
+ }
+
+ return 0;
+}
diff --git a/lib/i915/intel_memory_region.h b/lib/i915/intel_memory_region.h
new file mode 100644
index 000000000000..bbcaef6a19fb
--- /dev/null
+++ b/lib/i915/intel_memory_region.h
@@ -0,0 +1,30 @@
+/*
+ * Copyright © 2020 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, 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.
+ */
+
+#ifndef INTEL_MEMORY_REGION_H
+#define INTEL_MEMORY_REGION_H
+
+bool gem_has_lmem(int fd);
+uint64_t gem_lmem_total_size(int fd);
+
+#endif /* INTEL_MEMORY_REGION_H */
diff --git a/lib/meson.build b/lib/meson.build
index 57eb7d938639..25a9960a57e2 100644
--- a/lib/meson.build
+++ b/lib/meson.build
@@ -7,6 +7,7 @@ lib_sources = [
'i915/gem_ring.c',
'i915/gem_mman.c',
'i915/gem_vm.c',
+ 'i915/intel_memory_region.c',
'igt_color_encoding.c',
'igt_debugfs.c',
'igt_device.c',
--
2.20.1
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev
next reply other threads:[~2020-01-04 10:09 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-04 10:08 Ramalingam C [this message]
2020-01-04 10:08 ` [igt-dev] [RFC 2/2] tests/dumb_duffer: extending for lmem coverage Ramalingam C
2020-01-04 11:07 ` Chris Wilson
2020-01-06 6:43 ` Ramalingam C
2020-01-06 12:00 ` Chris Wilson
2020-01-04 10:42 ` [igt-dev] ✗ Fi.CI.BAT: failure for series starting with [RFC,1/2] lib/i915/intel_memory_region: wrappers for memory regions ops 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=20200104100826.21067-1-ramalingam.c@intel.com \
--to=ramalingam.c@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