Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp1447387rwi; Wed, 19 Oct 2022 10:39:49 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6W0dj+s9gPVHEfdviP3J8UsAC3sBN+3xFOWhUfxu3sIvWVn9exC4MJE6YNVHmNwA+x1Wod X-Received: by 2002:a17:906:eec9:b0:73d:c369:690f with SMTP id wu9-20020a170906eec900b0073dc369690fmr7787816ejb.767.1666201178783; Wed, 19 Oct 2022 10:39:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666201178; cv=none; d=google.com; s=arc-20160816; b=1KqnUUScl3XqiBuXxNt58lb8EMeP4jpY519IttNjrgQnEXEbrGbx4xvGBwD6r2c+iA J14XIyXn4oiYU3SyK1bOc/gYW9Bk5xiHWxUyST84BppAWMgBM08jidIR6J3mHUtUubBK iAlUJ1QFV8+Wx1SGAjuKMhqQc9cFwKdKIodFZ7TLWQZtTgLAIYx6al1hNFSPAOzG+ipu cycGtyAfs+01lbSbIQtBcFaUiIW1cAG2xMMQ10JT3stGT9ziS95EPaMLKhcYXmWjI7GD ciD3xzMgqFb81Dwy8J396xG13t3w5S+bMgrC4XIyxgxvkYEU4CERqRNgkYnxomJQHnoE 7Idg== 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=NSkS7M8YosxLuSsHaOOSZY7WYyRcJmNMMsHK5yXz4RA=; b=GiL953LuU80/W/6uP7vdWfiojUFB+Ce386bs2AWtcJbxDlW+ornS1CBgsMqBZmKB+b r/ailIc3buuTGkhosrnPEZ3aS63F6hXPyKOluHHAps1fE/sgbfGbozzKfgEbr5K1x3id x7I3BZuJDAD6iK6JEbnNgFuo7IkZsM21o+DOm+sw2DQrOD+KnAxzsvQP/5QJ+Sqrn1Qg LgQizhzfn6wO5CysOUX7B3ePIvX2zUfC18jQY8A4q0znJ2OoEnejMs1BsJ3a9+JN5I1D YqYVRG9zesO/wG/5gg7dMPyL32WJOEhxgW382HTV/RzxWyUhUTPbyurl9wnqoUQ2G7+7 mzog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=UZDN5ecu; 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 j11-20020a05640211cb00b0045f802c0b98si2826708edw.443.2022.10.19.10.39.12; Wed, 19 Oct 2022 10:39:38 -0700 (PDT) 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=UZDN5ecu; 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 S231441AbiJSRfB (ORCPT + 99 others); Wed, 19 Oct 2022 13:35:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230243AbiJSReR (ORCPT ); Wed, 19 Oct 2022 13:34:17 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A54A1C20A8; Wed, 19 Oct 2022 10:34:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1666200852; x=1697736852; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=2SjnzP/RjutkVE2GWCovZkYcvG7xuDDB28V5+LUt3bM=; b=UZDN5ecuQzQMwOX56Ll2FRO2VGAm7ii9b8WiAyLfnIZPtdVuqWvI+8uh xC0g7YzBZH34qUDvvR4TSwnqUcyHjEHfy0PfdSEENpUIXd2fs9RCID3Xw QUvYhXIuoMtsmQW3K+XxpR3bCgs1XcJvBnHKmL3vXaM1NFb2dslugUcU8 BWLbpmlqK6amndbYgDJx12UKGNMwM2JT7yQOjcW46mXLG3bcjSc8WiLoH 2ZPwbJdUnVXqg20iVaq9WdibSi/Cu35zt6noEmyrJ5MOyDXyx34Fq57Tc sFxInBtg5eBRkLq1DTPLvBXkoF7l8QxBEpHGWuKUC/y96bX5/NY2lBkVt w==; X-IronPort-AV: E=McAfee;i="6500,9779,10505"; a="306474544" X-IronPort-AV: E=Sophos;i="5.95,196,1661842800"; d="scan'208";a="306474544" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Oct 2022 10:34:00 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10505"; a="607204833" X-IronPort-AV: E=Sophos;i="5.95,196,1661842800"; d="scan'208";a="607204833" Received: from mjmcener-mobl1.amr.corp.intel.com (HELO localhost.localdomain) ([10.213.233.40]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Oct 2022 10:33:56 -0700 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 12/17] cgroup/drm: Client exit hook Date: Wed, 19 Oct 2022 18:32:49 +0100 Message-Id: <20221019173254.3361334-13-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221019173254.3361334-1-tvrtko.ursulin@linux.intel.com> References: <20221019173254.3361334-1-tvrtko.ursulin@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-5.5 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_HI,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 | 1 + kernel/cgroup/drm.c | 8 ++++++++ 3 files changed, 17 insertions(+) diff --git a/drivers/gpu/drm/drm_cgroup.c b/drivers/gpu/drm/drm_cgroup.c index e36bc4333924..ff99d1f4f1d4 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); @@ -25,6 +26,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; lockdep_assert_held(&dev->filelist_mutex); @@ -35,6 +37,12 @@ void drm_clients_close(struct drm_file *file_priv) if (WARN_ON_ONCE(!clients)) return; + task = get_pid_task(file_priv->cpid, PIDTYPE_PID); + if (task) { + drmcgroup_client_exited(task); + put_task_struct(task); + } + __del_clients(clients, file_priv); /* diff --git a/include/linux/cgroup_drm.h b/include/linux/cgroup_drm.h index 66063b4708e8..c84516d3e50a 100644 --- a/include/linux/cgroup_drm.h +++ b/include/linux/cgroup_drm.h @@ -13,5 +13,6 @@ struct task_struct; #define DRM_CGROUP_PRIORITY_MAX (10000) int drmcgroup_lookup_effective_priority(struct task_struct *task); +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 4b6f88d8236e..48f1eaaa1c07 100644 --- a/kernel/cgroup/drm.c +++ b/kernel/cgroup/drm.c @@ -221,6 +221,14 @@ static void drmcs_attach(struct cgroup_taskset *tset) css_to_drmcs(css)->effective_priority); } +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 = { .priority = DRM_CGROUP_PRIORITY_DEF, .effective_priority = DRM_CGROUP_PRIORITY_DEF, -- 2.34.1