From patchwork Thu Feb 1 19:56:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Matt Roper X-Patchwork-Id: 10196109 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BD8B660380 for ; Thu, 1 Feb 2018 22:19:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A2E9828396 for ; Thu, 1 Feb 2018 22:19:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 93BF826E78; Thu, 1 Feb 2018 22:19:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id CD3DD27165 for ; Thu, 1 Feb 2018 22:19:38 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B56CA6EEFA; Thu, 1 Feb 2018 19:56:18 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by gabe.freedesktop.org (Postfix) with ESMTPS id C8B816E0EE; Thu, 1 Feb 2018 19:56:16 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 01 Feb 2018 11:56:16 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,444,1511856000"; d="scan'208";a="27347091" Received: from mdroper-desk.fm.intel.com ([10.1.134.220]) by fmsmga001.fm.intel.com with ESMTP; 01 Feb 2018 11:56:16 -0800 From: Matt Roper To: dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org Subject: [IGT PATCH RFC] tools: Introduce intel_cgroup tool Date: Thu, 1 Feb 2018 11:56:15 -0800 Message-Id: <20180201195615.5124-1-matthew.d.roper@intel.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180201195315.4956-1-matthew.d.roper@intel.com> References: <20180201195315.4956-1-matthew.d.roper@intel.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 --- tools/Makefile.sources | 1 + tools/intel_cgroup.c | 103 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 104 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..ce781b08 --- /dev/null +++ b/tools/intel_cgroup.c @@ -0,0 +1,103 @@ +/* + * 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 +#include +#include +#include +#include +#include + +#include "igt.h" +#include "xf86drm.h" +#include "xf86drmMode.h" + +#define I915_CGROUP_PARAM_PRIORITY_OFFSET 0x1 + +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= \n"); +} + +int main(int argc, char **argv) +{ + int drm_fd, cgrp_fd; + struct 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, DRM_IOCTL_I915_CGROUP_SETPARAM, &req); + if (ret) + perror("Failed to set cgroup parameter"); + } + + close(cgrp_fd); + close(drm_fd); + + return ret; +}