From patchwork Sat Jan 20 01:51:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matt Roper X-Patchwork-Id: 10176207 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 7109360386 for ; Sat, 20 Jan 2018 01:52:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 62FDB28762 for ; Sat, 20 Jan 2018 01:52:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 578BA2880C; Sat, 20 Jan 2018 01:52:30 +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 E4D0E28762 for ; Sat, 20 Jan 2018 01:52:29 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A5CDB6EBD4; Sat, 20 Jan 2018 01:52:08 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by gabe.freedesktop.org (Postfix) with ESMTPS id D7BAB6EBCF; Sat, 20 Jan 2018 01:52:07 +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 orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Jan 2018 17:52:07 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,383,1511856000"; d="scan'208";a="23895510" Received: from mdroper-desk.fm.intel.com ([10.1.134.220]) by fmsmga001.fm.intel.com with ESMTP; 19 Jan 2018 17:52:07 -0800 From: Matt Roper To: dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, cgroups@vger.kernel.org Subject: [PATCH RFC 7/9] drm: Add helper to obtain cgroup of drm_file's owning process Date: Fri, 19 Jan 2018 17:51:39 -0800 Message-Id: <20180120015141.10118-8-matthew.d.roper@intel.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180120015141.10118-1-matthew.d.roper@intel.com> References: <20180120015141.10118-1-matthew.d.roper@intel.com> Cc: Tejun Heo X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 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 Cc: Tejun Heo Cc: cgroups@vger.kernel.org Signed-off-by: Matt Roper --- include/drm/drm_file.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/include/drm/drm_file.h b/include/drm/drm_file.h index 0e0c868451a5..08855a99069c 100644 --- a/include/drm/drm_file.h +++ b/include/drm/drm_file.h @@ -32,6 +32,7 @@ #include #include +#include #include @@ -378,4 +379,31 @@ 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 + * @root: cgroup hierarchy to search for process in + * + * 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, struct cgroup_root *root) +{ + struct task_struct *task = pid_task(file_priv->pid, PIDTYPE_PID); + struct cgroup *cgrp; + + mutex_lock(&cgroup_mutex); + cgrp = task_cgroup_from_root(task, root); + mutex_unlock(&cgroup_mutex); + + return cgrp; +} +#else +static inline struct cgroup * +drm_file_get_cgroup(struct drm_file *file_priv) { return NULL; } +#endif + #endif /* _DRM_FILE_H_ */