Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp38243844rwd; Wed, 12 Jul 2023 05:16:46 -0700 (PDT) X-Google-Smtp-Source: APBJJlEbBmJGrYYu8cs62Y1btaHV/cztKNwgw8FLLiZGRVBC1mHh1XMuPoKKYcjqInbgQ+9HyGe6 X-Received: by 2002:a05:6a00:3994:b0:674:a3be:2766 with SMTP id fi20-20020a056a00399400b00674a3be2766mr16539656pfb.14.1689164205739; Wed, 12 Jul 2023 05:16:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689164205; cv=none; d=google.com; s=arc-20160816; b=HmX2EQFTmSuREhrfcJbYNninoO0Bet4DB0o3UEjfVoQdOUnujfn7wvnrZezpeoQrUo ssM08mwCn76ZvwsY4Mjt7/QLnTO/FhEUU+zBPeIyTDvoRt4ACIIh/lQqwUM87Lo17jBN C0+GmM79VWF8a80FRQIuq9chA9MGPrQZKJeb/nTdPZLpNZd04bl5Lv1qxinLmu4gC2VH xY1BahXql0xgbzmcJ8qiKrAMBLqzRJH1Z+sS66Wi7O3ftI41BfEKtO4n2SK2R9fgbbBy V6+/ZRcvgpO0B3aqSPx2d007sjNj8npr2RPbCa8vGn3N4/KiVa+Bhp0+XTLADnVevh4J H0hw== 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=P7LBxQM4iNjAqXpgW+DGSSz6GKf5BucoOAVdC0KQK/8=; fh=AB6ahJ7aRRWBRwaRRWg5ebNaiYUkpi/4N4/J23sBvbI=; b=EJRP7ncFHlmaKckVk+0pR1qPPKSvF33RkHLlEK8Gf81hxczJZ5ap8M10qyiOoXuUfx AUPEOoZ9iH3CDiTZ6yj7bVPflORMPcksyXsq4mrHml5F+NXgodF48m7+WR6IQ+lAbZ7O eN3O1XBawsZXvvuWMG4WrxEQhBnUfNgi+7DnshXmBGMcxs4zcjka/b5d9aMcQQstHs6U wa/o557HwVrahHgW3Rz32vhNYon5kq7NWR2uVIDzUHLIQBH6U7BcAfmkQSkBnGXkm3uh PyUFqbbefCEfAg0oYbhQaBUuKJ4ZvBd6rGvWAupT9XJhC1GT3fHMEfGHrxe3zxdWJCsn 2Hvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=MyjGoJDF; 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 be4-20020a056a001f0400b00668750818ffsi3192464pfb.174.2023.07.12.05.16.33; Wed, 12 Jul 2023 05:16:45 -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=MyjGoJDF; 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 S233367AbjGLLui (ORCPT + 99 others); Wed, 12 Jul 2023 07:50:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233460AbjGLLuS (ORCPT ); Wed, 12 Jul 2023 07:50:18 -0400 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 24A6A2D51; Wed, 12 Jul 2023 04:48:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689162534; x=1720698534; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=uQ4I98L+peLkvtgsNHxAtBxt8A95MI6az8TimZ/zwAk=; b=MyjGoJDFIOovEC4ELX32m+PFPo5vELdpTycJFY91b6aGUsTbNDDj17pn G+/eBi9ireMurd3oP8xO+oqr7COwple/Fnsn8tgXNZDTUHYqUISF4bHfA 1TTwFM0YKRal8baMPYC6NZbOD8qW6++tU12WNAY3ZRxL0xh2Fu0+PTuVx fPCx2T9N4MIXaI6EucoVm8o3h7zOEkmCGVPLlhPDdAdebm9sjsaGNLa5Z /m2b4cfWAjDiiDo8and2Vq0O2GQVQxSTJ+G1PhOtxYBG+GJHQ3PnrOd4K isiqVZryWkzdkqn1blQQsKHUQ34Qa7dVctb7wRY+WeiN20qw0SeEeMhkX g==; X-IronPort-AV: E=McAfee;i="6600,9927,10768"; a="344469247" X-IronPort-AV: E=Sophos;i="6.01,199,1684825200"; d="scan'208";a="344469247" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jul 2023 04:46:51 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10768"; a="866094117" X-IronPort-AV: E=Sophos;i="6.01,199,1684825200"; d="scan'208";a="866094117" Received: from eamonnob-mobl1.ger.corp.intel.com (HELO localhost.localdomain) ([10.213.237.202]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jul 2023 04:46:47 -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=20Marchesin?= , "T . J . Mercier" , Kenny.Ho@amd.com, =?UTF-8?q?Christian=20K=C3=B6nig?= , Brian Welty , Tvrtko Ursulin Subject: [PATCH 09/17] drm/cgroup: Add ability to query drm cgroup GPU time Date: Wed, 12 Jul 2023 12:45:57 +0100 Message-Id: <20230712114605.519432-10-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230712114605.519432-1-tvrtko.ursulin@linux.intel.com> References: <20230712114605.519432-1-tvrtko.ursulin@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 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_BLOCKED,SPF_HELO_PASS,SPF_NONE,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED 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 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 b77f2c7275b7..3116fa4dbc48 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 * @@ -428,6 +446,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); -- 2.39.2