From patchwork Thu Feb 1 19:53:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matt Roper X-Patchwork-Id: 10196117 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 727B260380 for ; Thu, 1 Feb 2018 22:19:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5672F2621B for ; Thu, 1 Feb 2018 22:19:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4BA7226E4A; Thu, 1 Feb 2018 22:19:40 +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 0F36A283C5 for ; Thu, 1 Feb 2018 22:19:39 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0CBBC6EF08; Thu, 1 Feb 2018 19:53:55 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by gabe.freedesktop.org (Postfix) with ESMTPS id 634246EF05; Thu, 1 Feb 2018 19:53:53 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 01 Feb 2018 11:53:53 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,444,1511856000"; d="scan'208";a="24211624" Received: from mdroper-desk.fm.intel.com ([10.1.134.220]) by FMSMGA003.fm.intel.com with ESMTP; 01 Feb 2018 11:53:53 -0800 From: Matt Roper To: dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, cgroups@vger.kernel.org Subject: [PATCH RFC v2 4/7] drm: Add helper to obtain cgroup of drm_file's owning process Date: Thu, 1 Feb 2018 11:53:12 -0800 Message-Id: <20180201195315.4956-5-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> 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: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Matt Roper --- include/drm/drm_file.h | 20 ++++++++++++++++++++ kernel/cgroup/cgroup_driver.c | 12 ++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/include/drm/drm_file.h b/include/drm/drm_file.h index 0e0c868451a5..72ac40530ad3 100644 --- a/include/drm/drm_file.h +++ b/include/drm/drm_file.h @@ -32,6 +32,7 @@ #include #include +#include #include @@ -378,4 +379,23 @@ void drm_event_cancel_free(struct drm_device *dev, void drm_send_event_locked(struct drm_device *dev, struct drm_pending_event *e); void drm_send_event(struct drm_device *dev, struct drm_pending_event *e); +#ifdef CONFIG_CGROUPS +/** + * drm_file_get_cgroup - obtain cgroup for drm_file's owning process + * @file_priv: DRM file + * + * Obtains the cgroup from a specific hierarchy that the drm_file's owning + * process belongs to. The cgroup may be used to set driver-specific + * policy (priority, vram usage, etc.). + */ +static inline struct cgroup * +drm_file_get_cgroup(struct drm_file *file_priv) +{ + return cgroup_for_driver_process(file_priv->pid); +} +#else +static inline struct cgroup * +drm_file_get_cgroup(struct drm_file *file_priv) { return NULL; } +#endif + #endif /* _DRM_FILE_H_ */ diff --git a/kernel/cgroup/cgroup_driver.c b/kernel/cgroup/cgroup_driver.c index 4f870cbb9212..db0e268b9546 100644 --- a/kernel/cgroup/cgroup_driver.c +++ b/kernel/cgroup/cgroup_driver.c @@ -4,6 +4,7 @@ #include #include +#include /* * General data structure returned by cgroup_driver_init() and used as a @@ -143,12 +144,19 @@ EXPORT_SYMBOL(cgroup_driver_get_data); struct cgroup * cgroup_for_driver_process(struct pid *pid) { - struct task_struct *task = pid_task(pid, PIDTYPE_PID); + struct task_struct *task; + struct cgroup *cgrp; + + read_lock(&tasklist_lock); + task = pid_task(pid, PIDTYPE_PID); + read_unlock(&tasklist_lock); mutex_lock(&cgroup_mutex); spin_lock_irq(&css_set_lock); - task_cgroup_from_root(task, &cgrp_dfl_root); + cgrp = task_cgroup_from_root(task, &cgrp_dfl_root); spin_unlock_irq(&css_set_lock); mutex_unlock(&cgroup_mutex); + + return cgrp; } EXPORT_SYMBOL(cgroup_for_driver_process);