[Intel-gfx] [PATCH i-g-t 1/2] tools: Introduce intel_cgroup tool
Matt Roper
matthew.d.roper at intel.com
Tue Mar 6 23:49:09 UTC 2018
intel_cgroup is used to modify i915 cgroup parameters. At the moment only a
single parameter is supported (GPU priority offset). In the future the driver
may support additional parameters as well (e.g., limits on memory usage).
Signed-off-by: Matt Roper <matthew.d.roper at intel.com>
---
tools/Makefile.sources | 1 +
tools/intel_cgroup.c | 114 +++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 115 insertions(+)
create mode 100644 tools/intel_cgroup.c
diff --git a/tools/Makefile.sources b/tools/Makefile.sources
index abd23a0f..b30216c4 100644
--- a/tools/Makefile.sources
+++ b/tools/Makefile.sources
@@ -11,6 +11,7 @@ tools_prog_lists = \
intel_reg \
intel_backlight \
intel_bios_dumper \
+ intel_cgroup \
intel_display_crc \
intel_display_poller \
intel_forcewaked \
diff --git a/tools/intel_cgroup.c b/tools/intel_cgroup.c
new file mode 100644
index 00000000..88e9d391
--- /dev/null
+++ b/tools/intel_cgroup.c
@@ -0,0 +1,114 @@
+/*
+ * Copyright © 2018 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 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 <fcntl.h>
+#include <getopt.h>
+#include <i915_drm.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "igt.h"
+#include "xf86drm.h"
+#include "xf86drmMode.h"
+
+/* libdrm support is not yet upstream, so duplicate defs here for now */
+
+struct INTERNAL_drm_i915_cgroup_param {
+ __s32 cgroup_fd;
+ __u32 flags;
+ __u64 param;
+#define I915_CGROUP_PARAM_PRIORITY_OFFSET 0x1
+ __s64 value;
+};
+
+#define INTERNAL_IOCTL_I915_CGROUP_SETPARAM \
+ DRM_IOW(DRM_COMMAND_BASE + 0x39, struct INTERNAL_drm_i915_cgroup_param)
+
+char short_opts[] = "p:";
+struct option long_opts[] = {
+ { "set-prio", required_argument, NULL, 'p'},
+ { 0 },
+};
+
+static void usage(void)
+{
+ puts("Usage:");
+ printf(" intel_cgroup --set-prio=<val> <cgroup-v2>\n");
+}
+
+int main(int argc, char **argv)
+{
+ int drm_fd, cgrp_fd;
+ struct INTERNAL_drm_i915_cgroup_param req;
+ int opt, ret;
+ struct {
+ bool do_prio;
+ int prio_val;
+ } updates = { 0 };
+
+ while ((opt = getopt_long(argc, argv, short_opts, long_opts, NULL)) != -1) {
+ switch (opt) {
+ case 'p':
+ updates.do_prio = true;
+ updates.prio_val = atoi(optarg);
+ break;
+ default:
+ igt_assert(false);
+ }
+ }
+
+ if (argc - optind != 1) {
+ usage();
+ return 1;
+ }
+
+ drm_fd = drm_open_driver(DRIVER_INTEL);
+ if (drm_fd < 0) {
+ perror("Invalid DRM device");
+ return 1;
+ }
+
+ cgrp_fd = open(argv[optind], O_RDONLY|O_DIRECTORY, 0);
+ if (cgrp_fd < 0) {
+ perror("Invalid cgroup directory");
+ return 1;
+ }
+
+ req.cgroup_fd = cgrp_fd;
+ req.flags = 0;
+
+ if (updates.do_prio) {
+ req.param = I915_CGROUP_PARAM_PRIORITY_OFFSET;
+ req.value = updates.prio_val;
+
+ ret = drmIoctl(drm_fd, INTERNAL_IOCTL_I915_CGROUP_SETPARAM, &req);
+ if (ret)
+ perror("Failed to set cgroup parameter");
+ }
+
+ close(cgrp_fd);
+ close(drm_fd);
+
+ return ret;
+}
--
2.14.3
More information about the Intel-gfx
mailing list