From patchwork Tue Oct 24 16:07:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 157622 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp2051753vqx; Tue, 24 Oct 2023 09:12:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFAh6lc/I+ci7ZEJpRi2MIgALGO8Vf9j5Wd2Aik6grk/OhHjBqliSSfXqfqYrLg8gfQ2U/s X-Received: by 2002:a05:6a20:3d08:b0:174:373b:4381 with SMTP id y8-20020a056a203d0800b00174373b4381mr4022891pzi.49.1698163958008; Tue, 24 Oct 2023 09:12:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698163957; cv=none; d=google.com; s=arc-20160816; b=JXA+piB3/E+HSFX6EP4dXt8cRAYw2TVGwU/dRoU5AZxCygSX5gNLgL5NWGvJNJ952p KTe9cnPIFp+hybaZuOFVmhr9IlkGJUKGcSiabisxbJklKdQhGAqDdTiTEJ6g2puP8sOR sQGQREamB5LuHbo0XqQdEf9tSlV91jcDg2GWTMQTLLdXOqVUym0qg4nzhON2QRn8qTft +0xxBNXcxgWbH4S9lKgGXRQn5iZHiKU3iqiRxiyfaz/596S3DRxgrHuYRzj9ZfGXlg2w 1MB+g+RLMzTFYpuYr7XodvlDtU4rUeGe+dOy4kCQdyJ4DGdaFamLU2X8cOnqQL5uwzqi ojWA== 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=9lA5xFJy2CUv/7Zo2HS8VdowRzDsCtqFTOu4vI7GDXU=; fh=2HBAlzlAa9r6oEay2NbkpJS0xF7sQwPTpkwcUWUf5js=; b=k8A6QXo1RLonqZqlJUTtzkAdp9zodtAw0Py2qZP92MiFUJur5q44Qx0yD4C7jL+fix bQ9RzPtpbVs6e7jDpNQnBOflaiyVCW1qzGkN5JZbUmWiREqIcGrsYJaRe0i31xqXZ7c+ /tG2BOhrQKqSWqmOsrNJj2g9QNgxb37w5uEmqfTcKlgIEZqB5J0iQ5+ojt00fJfjSOhK No9AcwoRJoaYQL8sTm/U36o/3ATbcBwG4386SrQ9TdvpuynDSq4EzKW9nI62YWdRZYU2 vfv7xxA+DHxQIr58jE/9UcRrSGSJA4ZGxsnFxnjCgPu/516UWWp646+dbevFanMpWpuG 6fuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=g6zBbTMi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id o10-20020a056a0015ca00b006bd27e41c15si8836026pfu.291.2023.10.24.09.12.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 09:12:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=g6zBbTMi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id E19E58046F0A; Tue, 24 Oct 2023 09:12:29 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344113AbjJXQML (ORCPT + 27 others); Tue, 24 Oct 2023 12:12:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230304AbjJXQMC (ORCPT ); Tue, 24 Oct 2023 12:12:02 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B8F1010C3; Tue, 24 Oct 2023 09:12:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698163920; x=1729699920; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=grMzeSHRyi5Hbnx2+6Q3kkMweOiaep23+j//w7Ao1+s=; b=g6zBbTMiaV27U4S6kWIC5HC+6VIreX6P4E/OM3KE9RSJ6wbGa3BnqzgJ 2VA4X+QvTlHTzkMvx7f8SUi7pBR7SZKGXxLYu0TzC3cXGMb4m0s90cR1Q oEoCvlffOFReQFQyvr/I5CF4QrpJzQVFFyD431O0SS3c7l2LvVhnHzBkc eBMbosRJ37IWq8ufAFJmVDT8AllXIYDuG8LQtaP53HNcxetvPacOtoX6J hgx+SBxF0uxKBby5Dbufl4qgkVQWACnC9FpPMK7FULXmxyMbaeNHGYFdk JseAICbvw2kQj63CFAj3FdUjXkTQ6Se7/vaCny1wgYK4nZdrpFgHMzWwM g==; X-IronPort-AV: E=McAfee;i="6600,9927,10873"; a="451328134" X-IronPort-AV: E=Sophos;i="6.03,248,1694761200"; d="scan'208";a="451328134" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2023 09:07:47 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10873"; a="902237205" X-IronPort-AV: E=Sophos;i="6.03,248,1694761200"; d="scan'208";a="902237205" Received: from aidenbar-mobl.ger.corp.intel.com (HELO localhost.localdomain) ([10.213.219.125]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2023 09:05:23 -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 3/8] drm/cgroup: Add ability to query drm cgroup GPU time Date: Tue, 24 Oct 2023 17:07:22 +0100 Message-Id: <20231024160727.282960-4-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231024160727.282960-1-tvrtko.ursulin@linux.intel.com> References: <20231024160727.282960-1-tvrtko.ursulin@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=0.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,HK_RANDOM_FROM, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Tue, 24 Oct 2023 09:12:30 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780653970454363292 X-GMAIL-MSGID: 1780653970454363292 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 e2640dc64e08..d1cee5899cde 100644 --- a/include/drm/drm_drv.h +++ b/include/drm/drm_drv.h @@ -157,6 +157,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 * @@ -434,6 +452,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);