From patchwork Tue Mar 14 14:18:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 69669 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1802367wrd; Tue, 14 Mar 2023 07:49:22 -0700 (PDT) X-Google-Smtp-Source: AK7set9HiB3KuTBG5IRLpogdubrxRIAqnGUtud5Rmve7Cix3R2+4EQlR90a37AMTkzG8CIqQWLC5 X-Received: by 2002:aa7:9833:0:b0:624:b772:7822 with SMTP id q19-20020aa79833000000b00624b7727822mr4892906pfl.12.1678805362241; Tue, 14 Mar 2023 07:49:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678805362; cv=none; d=google.com; s=arc-20160816; b=UMjhPQjqX3pq0TiAt/JM+8CemUkkAxMmoRSiwslXJT8U8n9LUq+2nYSRI1Z+UTbHaI EWXZ4L3Fs6x4oZwWmzd/jZKQsHdjMI/wwxd1ramhOZqmldOVkizzspqJ2Tbm0dOufveN AAu1EXSsTO/CDmJfM7bLMRy5N2AdMcScVK8Y46hKJOYF1oTigyjlgmFcJ8y7VS8EKRNE nrj8IuU9UwxmzqJpVN1wrWPhcxI5u512jif4qORUdleTF5V2hO2s/LqO9Lhhhn1ynXQF mwVuhDjkwl6kM5ZWSpmNHgD5p4exFqu6BXZeVVQPI93j1UnAOVo4H1efPjcP7y/Vy+aE O0lw== 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=mBMAYow7bQtQ6GdpYRiiqObtq5gyANuVTDDpd3P13ko=; b=X5z77gLfXPL2uRLZPoAlO3nH9KKAcFC1L5Xxpdj+wHrK3N5aRaE7gC5ixeOkDUbsrI IX4TX3PgXt8r9W85YtVwCIkxjOhMwtt6Y8uqd/9N8hAT4EvOdsYGL67in4vDFOkXAo41 YYggBxVAFCIg9SIhe+7SlcPaHjgetPEqd0Qli32hmYswbrAustswnnnG1Iy+zo6NLvB2 ZyxKduHQHSunCfXFMGWpoSVqt3PbAkgjslQ+/jdb3ELyVYZ0giYMbX47hzTXTBQ5rIyC 5L/6SxSn4ReEDq3VIOxt9r3+g7ngFNs3jPTd3TZiAvaDzJhQ+PSQQ7G9AR1XGbhFwW91 2VvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="H+/QS/Fq"; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j11-20020a634a4b000000b005091ced8a0csi2249717pgl.775.2023.03.14.07.49.08; Tue, 14 Mar 2023 07:49:22 -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="H+/QS/Fq"; 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 S230341AbjCNOUb (ORCPT + 99 others); Tue, 14 Mar 2023 10:20:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231175AbjCNOTz (ORCPT ); Tue, 14 Mar 2023 10:19:55 -0400 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA91B23137; Tue, 14 Mar 2023 07:19:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1678803581; x=1710339581; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=YOLueewwuDNMLLryD+HA+AYOg+k/XFD1PEr0h2uYLdE=; b=H+/QS/FqWU7eF8AE9qMGRWyqfr1Q7qgHXJyZTD/X+1C9oO2iaVMaT9k0 clmzkEnpLMebKQSyPt/Xbu1E2XVii7HzKmHJJMHpGTyx5YRjYCU9MWvQd kV/I4ZlyFrweIiaMmSN5Zjtf7FiJ36zWRi+bZRQ4octJ1EM6ciZqJ6tUU kPgp0lQq9/OnqK404KkchWZCUz5HlenxgBiEvJgqYZLZ6Pf/vulavITNJ GMdlNTMobNLSl4jk2WSEuVv/Ls1bDNOjRBRwqzNM/HHkrARou4zT+Im0q AczhDSXaMG3QIlgtEYxq1f/6f9kfqW+xoS35+0mf7qMOJWDy1CFfH45Ut w==; X-IronPort-AV: E=McAfee;i="6500,9779,10649"; a="321284768" X-IronPort-AV: E=Sophos;i="5.98,260,1673942400"; d="scan'208";a="321284768" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Mar 2023 07:19:37 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10649"; a="656363256" X-IronPort-AV: E=Sophos;i="5.98,260,1673942400"; d="scan'208";a="656363256" Received: from mjtillin-mobl.ger.corp.intel.com (HELO localhost.localdomain) ([10.213.236.227]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Mar 2023 07:19:33 -0700 From: Tvrtko Ursulin To: Intel-gfx@lists.freedesktop.org, dri-devel@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_Marchesin?= , "T . J . Mercier" , Kenny.Ho@amd.com, =?utf-8?q?Chris?= =?utf-8?q?tian_K=C3=B6nig?= , Brian Welty , Tvrtko Ursulin Subject: [RFC 05/10] drm/cgroup: Add ability to query drm cgroup GPU time Date: Tue, 14 Mar 2023 14:18:59 +0000 Message-Id: <20230314141904.1210824-6-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230314141904.1210824-1-tvrtko.ursulin@linux.intel.com> References: <20230314141904.1210824-1-tvrtko.ursulin@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=0.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,HK_RANDOM_ENVFROM,HK_RANDOM_FROM, SPF_HELO_NONE,SPF_NONE,URIBL_BLOCKED autolearn=no 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760355011882402673?= X-GMAIL-MSGID: =?utf-8?q?1760355011882402673?= From: Tvrtko Ursulin Add a driver callback and core helper which allow querying the time spent on GPUs for processes belonging to a group. Signed-off-by: Tvrtko Ursulin --- include/drm/drm_drv.h | 28 ++++++++++++++++++++++++++++ kernel/cgroup/drm.c | 20 ++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/include/drm/drm_drv.h b/include/drm/drm_drv.h index 5b86bb7603e7..01953d6b98d6 100644 --- a/include/drm/drm_drv.h +++ b/include/drm/drm_drv.h @@ -151,6 +151,24 @@ enum drm_driver_feature { DRIVER_HAVE_IRQ = BIT(30), }; +/** + * struct drm_cgroup_ops + * + * This structure contains a number of callbacks that drivers can provide if + * they are able to support one or more of the functionalities implemented by + * the DRM cgroup controller. + */ +struct drm_cgroup_ops { + /** + * @active_time_us: + * + * Optional callback for reporting the GPU time consumed by this client. + * + * Used by the DRM core when queried by the DRM cgroup controller. + */ + u64 (*active_time_us) (struct drm_file *); +}; + /** * struct drm_driver - DRM driver structure * @@ -443,6 +461,16 @@ struct drm_driver { */ const struct file_operations *fops; +#ifdef CONFIG_CGROUP_DRM + /** + * @cg_ops: + * + * Optional pointer to driver callbacks facilitating integration with + * the DRM cgroup controller. + */ + const struct drm_cgroup_ops *cg_ops; +#endif + #ifdef CONFIG_DRM_LEGACY /* Everything below here is for legacy driver, never use! */ /* private: */ diff --git a/kernel/cgroup/drm.c b/kernel/cgroup/drm.c index d702be1b441f..acdb76635b60 100644 --- a/kernel/cgroup/drm.c +++ b/kernel/cgroup/drm.c @@ -9,6 +9,8 @@ #include #include +#include + struct drm_cgroup_state { struct cgroup_subsys_state css; @@ -31,6 +33,24 @@ css_to_drmcs(struct cgroup_subsys_state *css) return container_of(css, struct drm_cgroup_state, css); } +static u64 drmcs_get_active_time_us(struct drm_cgroup_state *drmcs) +{ + struct drm_file *fpriv; + u64 total = 0; + + lockdep_assert_held(&drmcg_mutex); + + list_for_each_entry(fpriv, &drmcs->clients, clink) { + const struct drm_cgroup_ops *cg_ops = + fpriv->minor->dev->driver->cg_ops; + + if (cg_ops && cg_ops->active_time_us) + total += cg_ops->active_time_us(fpriv); + } + + return total; +} + static void drmcs_free(struct cgroup_subsys_state *css) { struct drm_cgroup_state *drmcs = css_to_drmcs(css);