From patchwork Tue Jan 26 21:46:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Welty, Brian" X-Patchwork-Id: 12048409 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BBEDCC433E9 for ; Tue, 26 Jan 2021 21:45:13 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 84F8F20656 for ; Tue, 26 Jan 2021 21:45:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 84F8F20656 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 03FD16E4C1; Tue, 26 Jan 2021 21:44:42 +0000 (UTC) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by gabe.freedesktop.org (Postfix) with ESMTPS id DBFB66E455; Tue, 26 Jan 2021 21:44:38 +0000 (UTC) IronPort-SDR: C5eR9fq5lAHjmNH4Hhk0/VNlefwZB6fD3Yd83bdZVt6dElo/q4lbe+VHyaJjeh9OJdgc08utPw d6Hnzd38byZA== X-IronPort-AV: E=McAfee;i="6000,8403,9876"; a="198770833" X-IronPort-AV: E=Sophos;i="5.79,377,1602572400"; d="scan'208";a="198770833" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jan 2021 13:44:37 -0800 IronPort-SDR: 5gXBtpv/bdceklTZYWdFrkeFvdqPkHTvqOWtCrbOr1mtMjc+Wz1YWJEHoMl1+Kit9uYn5G06dz ksz3Gj04BC5g== X-IronPort-AV: E=Sophos;i="5.79,377,1602572400"; d="scan'208";a="362139902" Received: from nvishwa1-desk.sc.intel.com ([172.25.29.76]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-SHA; 26 Jan 2021 13:44:37 -0800 From: Brian Welty To: Brian Welty , cgroups@vger.kernel.org, Tejun Heo , dri-devel@lists.freedesktop.org, David Airlie , Daniel Vetter , =?utf-8?q?Christian_K=C3=B6nig?= , Kenny Ho , amd-gfx@lists.freedesktop.org, Chris Wilson , Tvrtko Ursulin , intel-gfx@lists.freedesktop.org, Joonas Lahtinen , Eero Tamminen Date: Tue, 26 Jan 2021 13:46:24 -0800 Message-Id: <20210126214626.16260-8-brian.welty@intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210126214626.16260-1-brian.welty@intel.com> References: <20210126214626.16260-1-brian.welty@intel.com> MIME-Version: 1.0 Subject: [Intel-gfx] [RFC PATCH 7/9] drmcg: Add initial support for tracking gpu time usage X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Single control below is added to DRM cgroup controller in order to track user execution time for GPU devices. It is up to device drivers to charge execution time to the cgroup via drm_cgroup_try_charge(). sched.runtime Read-only value, displays current user execution time for each DRM device. The expectation is that this is incremented by DRM device driver's scheduler upon user context completion or context switch. Units of time are in microseconds for consistency with cpu.stats. Signed-off-by: Brian Welty --- Documentation/admin-guide/cgroup-v2.rst | 9 +++++++++ include/drm/drm_cgroup.h | 2 ++ include/linux/cgroup_drm.h | 2 ++ kernel/cgroup/drm.c | 20 ++++++++++++++++++++ 4 files changed, 33 insertions(+) diff --git a/Documentation/admin-guide/cgroup-v2.rst b/Documentation/admin-guide/cgroup-v2.rst index ccc25f03a898..f1d0f333a49e 100644 --- a/Documentation/admin-guide/cgroup-v2.rst +++ b/Documentation/admin-guide/cgroup-v2.rst @@ -2205,6 +2205,15 @@ thresholds are hit, this would then allow the DRM device driver to invoke some equivalent to OOM-killer or forced memory eviction for the device backed memory in order to attempt to free additional space. +The below set of control files are for time accounting of DRM devices. Units +of time are in microseconds. + + sched.runtime + Read-only value, displays current user execution time for each DRM + device. The expectation is that this is incremented by DRM device + driver's scheduler upon user context completion or context switch. + + Misc ---- diff --git a/include/drm/drm_cgroup.h b/include/drm/drm_cgroup.h index 9ba0e372eeee..315dab8a93b8 100644 --- a/include/drm/drm_cgroup.h +++ b/include/drm/drm_cgroup.h @@ -22,6 +22,7 @@ enum drmcg_res_type { DRMCG_TYPE_MEM_CURRENT, DRMCG_TYPE_MEM_MAX, DRMCG_TYPE_MEM_TOTAL, + DRMCG_TYPE_SCHED_RUNTIME, __DRMCG_TYPE_LAST, }; @@ -79,5 +80,6 @@ void drm_cgroup_uncharge(struct drmcg *drmcg,struct drm_device *dev, enum drmcg_res_type type, u64 usage) { } + #endif /* CONFIG_CGROUP_DRM */ #endif /* __DRM_CGROUP_H__ */ diff --git a/include/linux/cgroup_drm.h b/include/linux/cgroup_drm.h index 3570636473cf..0fafa663321e 100644 --- a/include/linux/cgroup_drm.h +++ b/include/linux/cgroup_drm.h @@ -19,6 +19,8 @@ */ struct drmcg_device_resource { struct page_counter memory; + seqlock_t sched_lock; + u64 exec_runtime; }; /** diff --git a/kernel/cgroup/drm.c b/kernel/cgroup/drm.c index 08e75eb67593..64e9d0dbe8c8 100644 --- a/kernel/cgroup/drm.c +++ b/kernel/cgroup/drm.c @@ -81,6 +81,7 @@ static inline int init_drmcg_single(struct drmcg *drmcg, struct drm_device *dev) /* set defaults here */ page_counter_init(&ddr->memory, parent_ddr ? &parent_ddr->memory : NULL); + seqlock_init(&ddr->sched_lock); drmcg->dev_resources[minor] = ddr; return 0; @@ -287,6 +288,10 @@ static int drmcg_seq_show_fn(int id, void *ptr, void *data) seq_printf(sf, "%d:%d %llu\n", DRM_MAJOR, minor->index, minor->dev->drmcg_props.memory_total); break; + case DRMCG_TYPE_SCHED_RUNTIME: + seq_printf(sf, "%d:%d %llu\n", DRM_MAJOR, minor->index, + ktime_to_us(ddr->exec_runtime)); + break; default: seq_printf(sf, "%d:%d\n", DRM_MAJOR, minor->index); break; @@ -384,6 +389,12 @@ struct cftype files[] = { .private = DRMCG_TYPE_MEM_TOTAL, .flags = CFTYPE_ONLY_ON_ROOT, }, + { + .name = "sched.runtime", + .seq_show = drmcg_seq_show, + .private = DRMCG_TYPE_SCHED_RUNTIME, + .flags = CFTYPE_NOT_ON_ROOT, + }, { } /* terminate */ }; @@ -440,6 +451,10 @@ EXPORT_SYMBOL(drmcg_device_early_init); * choose to enact some form of memory reclaim, but the exact behavior is left * to the DRM device driver to define. * + * For @res type of DRMCG_TYPE_SCHED_RUNTIME: + * For GPU time accounting, add @usage amount of GPU time to @drmcg for + * the given device. + * * Returns 0 on success. Otherwise, an error code is returned. */ int drm_cgroup_try_charge(struct drmcg *drmcg, struct drm_device *dev, @@ -466,6 +481,11 @@ int drm_cgroup_try_charge(struct drmcg *drmcg, struct drm_device *dev, err = 0; } break; + case DRMCG_TYPE_SCHED_RUNTIME: + write_seqlock(&res->sched_lock); + res->exec_runtime = ktime_add(res->exec_runtime, usage); + write_sequnlock(&res->sched_lock); + break; default: err = -EINVAL; break;