Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp811831rwb; Wed, 9 Nov 2022 08:55:27 -0800 (PST) X-Google-Smtp-Source: AMsMyM5HTvxtLKbO2as1TgNYBGyE/0WyM9rxPf/Jsfk6qYUOcRAZkQNE2tZk0bPD9J0AAMXH9GmL X-Received: by 2002:a17:906:3197:b0:73d:5e1a:44ac with SMTP id 23-20020a170906319700b0073d5e1a44acmr56905407ejy.512.1668012927213; Wed, 09 Nov 2022 08:55:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668012927; cv=none; d=google.com; s=arc-20160816; b=Sk2uV7XzHcjTXqLaKgmW9JDPngu/Pis/2exwuDO8U+QcvcOpSe/95DzehEEJwda6rt EzXFDwu2WKRNyMhRJS6nsMF3BSqJ9DBJqy7aA4RPvBSdhhviM2DXjZmu+cFeEajDK3WV DpqDvfuhoAIR5lHInnA1oj4kkdDyVljkI2gEXd6JDueAr0U7bKni+UmNnK0SAdvb88Ou s5P1raHcLm6E1vxTZoSJVErz1TCKav4y2Ud1Dpez4BXUJCwFNO+/kC8WCTUc2hTACO4x iSQlKfoBQZ1VH1geQjoPxR8KLwC2yXdQogVeD6nWOwjx/zSyinjQBNJHYTh7qsaHWYB1 Yw/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=YkKPPCbEBRE/kWEWtguueBKH+6EdPgrWKN1qODyjCmo=; b=aeoCxgRVLBw7vjMLItwI0LptKEY2imb+58+KngDeuB1OHclC66qG6QVR9HPcLZN/2r /r15JHUBuvKbZ0NnZh9gutGrwpzflfT/JmKJX7h3kTdxEEKQCV030Jw+Lfx+DDYGrT4k 0w1MXOzm6u4+FeoMR8WCyEeLjQDRlhav32g7mkJQ47zZcKl6SiLlv1E6EgakumBaoS60 lpHdp+UNbbNIHs8d1Z6FuvPvE5gCt0ne5BHC4kbyRmCmOcaoxfVerW+3rq8Hs76w24Cn 4YSPwsKSsk+yz7VK6kgakbZrHLV3fBB1NgkkSH3usB9vWsGziTGI70Hw0tkDRho2nN7B OFsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Nur0QNLk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u9-20020a170906124900b007ae4717bf0fsi12278672eja.158.2022.11.09.08.55.05; Wed, 09 Nov 2022 08:55:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Nur0QNLk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231273AbiKIQNK (ORCPT + 92 others); Wed, 9 Nov 2022 11:13:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232157AbiKIQMt (ORCPT ); Wed, 9 Nov 2022 11:12:49 -0500 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF3C823BFF; Wed, 9 Nov 2022 08:12:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1668010354; x=1699546354; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=xsH6SUJPl/aECTQLLwvLwzjjo/OdVfq3yYbEuLbpcjc=; b=Nur0QNLkADbBaix9OP9OgUxgd+zYPTvU/f9Kjk3FVRu7+1+udWPDCgFI PQ3D/h6jPpVCADRoq6w71mpWo49Re1qMzc4TU3k72KpNva1ga1YxtX6sy y49caY8V2ujcmuJv7ZV2RSp1om9UtNyAt7TK8dJSV1ZQ+0sDHrNKOBDeJ o+XC1j8bKRk/5lxvsRR5iJbqahEXncF4vAvQqwQAh9Z1vIMC26uKNlsXW l9ZVzp1B6tvqZTFbvwOD4nxbAO4vCBWJp4IIPoiXPL+VV1yN4I7tH8Vlw o0Xy2ONGkfz+e4A8VZfyM5NVJrr+3OgoCurHcgJ2ooUJXcxZipRNeaQin w==; X-IronPort-AV: E=McAfee;i="6500,9779,10526"; a="312181445" X-IronPort-AV: E=Sophos;i="5.96,151,1665471600"; d="scan'208";a="312181445" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Nov 2022 08:12:34 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10526"; a="811684585" X-IronPort-AV: E=Sophos;i="5.96,151,1665471600"; d="scan'208";a="811684585" Received: from smurnane-mobl.ger.corp.intel.com (HELO localhost.localdomain) ([10.213.196.238]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Nov 2022 08:12:31 -0800 From: Tvrtko Ursulin To: Intel-gfx@lists.freedesktop.org Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Tejun Heo , Johannes Weiner , Zefan Li , Dave Airlie , Daniel Vetter , Rob Clark , =?UTF-8?q?St=C3=A9phane=20Marchesin?= , "T . J . Mercier" , Kenny.Ho@amd.com, =?UTF-8?q?Christian=20K=C3=B6nig?= , Brian Welty , Tvrtko Ursulin Subject: [RFC 10/13] cgroup/drm: Client exit hook Date: Wed, 9 Nov 2022 16:11:38 +0000 Message-Id: <20221109161141.2987173-11-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221109161141.2987173-1-tvrtko.ursulin@linux.intel.com> References: <20221109161141.2987173-1-tvrtko.ursulin@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,HK_RANDOM_ENVFROM,HK_RANDOM_FROM, RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tvrtko Ursulin We need the ability for DRM core to inform the cgroup controller when a client has closed a DRM file descriptor. This will allow us not needing to keep state relating to GPU time usage by tasks sets in the cgroup controller itself. Signed-off-by: Tvrtko Ursulin --- drivers/gpu/drm/drm_cgroup.c | 8 ++++++++ include/linux/cgroup_drm.h | 4 ++++ kernel/cgroup/drm.c | 13 +++++++++++++ 3 files changed, 25 insertions(+) diff --git a/drivers/gpu/drm/drm_cgroup.c b/drivers/gpu/drm/drm_cgroup.c index d3050c744e3e..31a1bf3c8a43 100644 --- a/drivers/gpu/drm/drm_cgroup.c +++ b/drivers/gpu/drm/drm_cgroup.c @@ -5,6 +5,7 @@ #include #include +#include static DEFINE_XARRAY(drm_pid_clients); @@ -31,6 +32,7 @@ void drm_clients_close(struct drm_file *file_priv) { struct drm_device *dev = file_priv->minor->dev; struct drm_pid_clients *clients; + struct task_struct *task; struct pid *pid; lockdep_assert_held(&dev->filelist_mutex); @@ -43,6 +45,12 @@ void drm_clients_close(struct drm_file *file_priv) if (WARN_ON_ONCE(!clients)) return; + task = get_pid_task(pid, PIDTYPE_PID); + if (task) { + drmcgroup_client_exited(task); + put_task_struct(task); + } + __del_clients(clients, file_priv, (unsigned long)pid); } diff --git a/include/linux/cgroup_drm.h b/include/linux/cgroup_drm.h index bf8abc6b8ebf..2f755b896136 100644 --- a/include/linux/cgroup_drm.h +++ b/include/linux/cgroup_drm.h @@ -6,4 +6,8 @@ #ifndef _CGROUP_DRM_H #define _CGROUP_DRM_H +struct task_struct; + +void drmcgroup_client_exited(struct task_struct *task); + #endif /* _CGROUP_DRM_H */ diff --git a/kernel/cgroup/drm.c b/kernel/cgroup/drm.c index b88c93661df3..e165d8f542cc 100644 --- a/kernel/cgroup/drm.c +++ b/kernel/cgroup/drm.c @@ -18,11 +18,24 @@ css_to_drmcs(struct cgroup_subsys_state *css) return container_of(css, struct drm_cgroup_state, css); } +static inline struct drm_cgroup_state *get_task_drmcs(struct task_struct *task) +{ + return css_to_drmcs(task_get_css(task, drm_cgrp_id)); +} + static void drmcs_free(struct cgroup_subsys_state *css) { kfree(css_to_drmcs(css)); } +void drmcgroup_client_exited(struct task_struct *task) +{ + struct drm_cgroup_state *drmcs = get_task_drmcs(task); + + css_put(&drmcs->css); +} +EXPORT_SYMBOL_GPL(drmcgroup_client_exited); + static struct drm_cgroup_state root_drmcs = { }; -- 2.34.1