From: Matt Roper <matthew.d.roper@intel.com>
To: dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org
Subject: [PATCH libdrm] tests: Add drm_set_cgrp_param
Date: Mon, 22 Jan 2018 07:44:35 -0800 [thread overview]
Message-ID: <20180122154435.18146-1-matthew.d.roper@intel.com> (raw)
In-Reply-To: <20180120015141.10118-1-matthew.d.roper@intel.com>
drm_set_cgrp_param is a simple tool to set DRM parameters associated with a
cgroup. It is intended to be called at system initialization time (e.g., from
a sysv-init script or systemd service) to configure graphics policy and
resource management according to the wishes of the system integrator.
Signed-off-by: Matt Roper <matthew.d.roper@intel.com>
---
configure.ac | 1 +
tests/Makefile.am | 2 +-
tests/drm_set_cgrp_param/Makefile.am | 18 ++++++
tests/drm_set_cgrp_param/drm_set_cgrp_param.c | 80 +++++++++++++++++++++++++++
4 files changed, 100 insertions(+), 1 deletion(-)
create mode 100644 tests/drm_set_cgrp_param/Makefile.am
create mode 100644 tests/drm_set_cgrp_param/drm_set_cgrp_param.c
diff --git a/configure.ac b/configure.ac
index 35378b3384..9b5f340e2a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -567,6 +567,7 @@ AC_CONFIG_FILES([
tests/nouveau/Makefile
tests/etnaviv/Makefile
tests/util/Makefile
+ tests/drm_set_cgrp_param/Makefile
man/Makefile
libdrm.pc])
AC_OUTPUT
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 0355a9255f..d77a8639c8 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,4 +1,4 @@
-SUBDIRS = util kms modeprint proptest modetest vbltest
+SUBDIRS = util kms modeprint proptest modetest vbltest drm_set_cgrp_param
if HAVE_LIBKMS
SUBDIRS += kmstest
diff --git a/tests/drm_set_cgrp_param/Makefile.am b/tests/drm_set_cgrp_param/Makefile.am
new file mode 100644
index 0000000000..c32ec1c440
--- /dev/null
+++ b/tests/drm_set_cgrp_param/Makefile.am
@@ -0,0 +1,18 @@
+AM_CFLAGS = \
+ $(WARN_CFLAGS)\
+ -I$(top_srcdir)/include/drm \
+ -I$(top_srcdir)/tests \
+ -I$(top_srcdir)
+
+if HAVE_INSTALL_TESTS
+bin_PROGRAMS = \
+ drm_set_cgrp_param
+else
+noinst_PROGRAMS = \
+ drm_set_cgrp_param
+endif
+
+drm_set_cgrp_param_SOURCES = \
+ drm_set_cgrp_param.c
+drm_set_cgrp_param_LDADD = \
+ $(top_builddir)/libdrm.la
diff --git a/tests/drm_set_cgrp_param/drm_set_cgrp_param.c b/tests/drm_set_cgrp_param/drm_set_cgrp_param.c
new file mode 100644
index 0000000000..987bd18e88
--- /dev/null
+++ b/tests/drm_set_cgrp_param/drm_set_cgrp_param.c
@@ -0,0 +1,80 @@
+/*
+ * \file drm_set_cgrp_prop.c
+ * Simple tool to set a DRM property for a cgroup. Intended for use in
+ * system-specific initialization handling (e.g., sysv init, systemd, etc.).
+ */
+
+/*
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "xf86drm.h"
+#include "xf86drmMode.h"
+
+#include "util/common.h"
+
+int main(int argc, char **argv)
+{
+ int drm_fd, cgrp_fd;
+ struct drm_cgroup_setparam req;
+ int ret;
+
+ if (argc != 5) {
+ puts("Usage:");
+ printf(" %s <drm device> <cgroup-v2> <prop> <val>\n\n", argv[0]);
+ puts("Example:");
+ printf(" %s /dev/dri/card0 /sys/fs/cgroup-2/highprio 1 10\n",
+ argv[0]);
+ return 1;
+ }
+
+ drm_fd = open(argv[1], O_RDWR, 0);
+ if (drm_fd < 0) {
+ perror("Invalid DRM device");
+ return 1;
+ }
+
+ cgrp_fd = open(argv[2], O_RDONLY|O_DIRECTORY, 0);
+ if (cgrp_fd < 0) {
+ perror("Invalid cgroup directory");
+ return 1;
+ }
+
+ req.cgroup_fd = cgrp_fd;
+ req.reserved = 0;
+ req.param = (uint64_t)strtoul(argv[3], NULL, 0);
+ req.value = (int64_t)strtol(argv[4], NULL, 0);
+
+ ret = drmIoctl(drm_fd, DRM_IOCTL_CGROUP_SETPARAM, &req);
+ if (ret)
+ perror("Failed to set cgroup parameter");
+
+ close(cgrp_fd);
+ close(drm_fd);
+
+ return ret;
+}
--
2.14.3
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
next prev parent reply other threads:[~2018-01-22 15:44 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-20 1:51 [PATCH RFC 0/9] DRM management via cgroups Matt Roper
2018-01-20 1:51 ` [PATCH RFC 2/9] cgroup: Add notifier call chain for cgroup destruction Matt Roper
2018-01-20 1:51 ` [PATCH RFC 4/9] cgroup: Export task_cgroup_from_root() and cgroup_mutex for drivers Matt Roper
2018-01-20 1:51 ` [PATCH RFC 5/9] drm: Introduce DRM_IOCTL_CGROUP_SETPARAM Matt Roper
[not found] ` <20180120015141.10118-1-matthew.d.roper-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2018-01-20 1:51 ` [PATCH RFC 1/9] kernfs: Export kernfs_get_inode Matt Roper
2018-01-20 1:51 ` [PATCH RFC 3/9] cgroup: Export cgroup_on_dfl() to drivers Matt Roper
2018-01-20 1:51 ` [PATCH RFC 6/9] drm: Add cgroup helper library Matt Roper
2018-01-22 16:24 ` Tejun Heo
2018-01-20 1:51 ` [PATCH RFC 7/9] drm: Add helper to obtain cgroup of drm_file's owning process Matt Roper
2018-01-20 1:51 ` [PATCH RFC 8/9] drm/i915: Allow default context priority to be set via cgroup parameter Matt Roper
[not found] ` <20180120015141.10118-9-matthew.d.roper-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2018-01-20 9:36 ` Chris Wilson
[not found] ` <151644097064.13504.16277692057900569412-M6iVdVfohj6unts5RBS2dVaTQe2KTcn/@public.gmane.org>
2018-01-20 10:40 ` Chris Wilson
2018-01-22 9:50 ` Michel Dänzer
2018-01-22 9:56 ` Chris Wilson
2018-01-22 15:57 ` Matt Roper
2018-01-20 1:51 ` [PATCH RFC 9/9] drm/i915: Add context priority to debugfs Matt Roper
2018-01-22 15:44 ` Matt Roper [this message]
2018-01-26 17:08 ` [PATCH libdrm] tests: Add drm_set_cgrp_param Emil Velikov
2018-01-26 17:27 ` [Intel-gfx] " Matt Roper
2018-01-26 17:57 ` Emil Velikov
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=20180122154435.18146-1-matthew.d.roper@intel.com \
--to=matthew.d.roper@intel.com \
--cc=dri-devel@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox