Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp1997208rda; Tue, 24 Oct 2023 09:12:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGhFp69RuHLyjdnhO4uyFq+L6iwN1Y9UzRQge+z1xpwU0sL6AsyirXUxg6j0hu4/1D/DoXt X-Received: by 2002:a05:6359:2c4d:b0:168:e7c3:bff1 with SMTP id qv13-20020a0563592c4d00b00168e7c3bff1mr3473178rwb.20.1698163976662; Tue, 24 Oct 2023 09:12:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698163976; cv=none; d=google.com; s=arc-20160816; b=gdCugtD4h+E7RXZAA+iyPcewE5+DjGX2163C8RW5hbLf8qxV6wKPdBuriTdtYI2xAJ vfZafDRbByuAvd8ZyXkD9DPCzUUUhaVlY1anaWuLAxHNP6VcUsRQIynWiC/6tED1dw8N uAjt6OWSbUK6mXYjeYANa+OrWGcpkTNOjBJhuHTVO2ssx2CIOqDkIbqvfZDSnVj4NmBw JhoIfzEtM4+nP/IbZS+2WGbpN+v2zJr60Nmm/2HlNCn1E0QA8X5s8jdrljEszSkdHYKN F36NuXf+ZkCkbyJjUTC73nNlaHX2rcwt29k6/xR5OlnpZ04ljA624UR4qQncC+w4wjeL qt5Q== 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=W1jE99eR8w+afvNf8U5HyfHD0gPYx7/ikY0uf4AllM4=; fh=/ZOxcqSPQ7ZmK2g/PdD6BIXwjY9ZzHLj4uU6aqnGgsw=; b=gULLEQFSfmxJnNPzB2bJ77mmP/sVB/zyTyHdvT7RGS7X+G1Ne3p2LUS4uaPbHmfUTn Ss5tfs5eDLSfHBCoWqhXkSj3U8NNCeZT3pxHCUqY7g1EbXCUnQ6wgCTBjWRJup5GjRFl MMwx4TJgWm7wJ69rGMIemujBX+I0QB5HagQd63W0IDSO782BWISkOVyd3RDLjoZ4ZcK+ zPQV7jE3i/E19LSWRn3DZMHTdmZ2Zf7pMwqVYc6wEsglfH4jz1f5AK1XIDlRrqpuOhcJ Hge+kpxij9UFJRxaSUi/ndZIg1FuhUxRrnwpKtxLUMUlsxIhmbyVbvHTdeYDyEhG6Lsf lp0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Bpn7LqE5; 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 Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id by35-20020a056a0205a300b005b11ce9c97esi9209831pgb.353.2023.10.24.09.12.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 09:12:56 -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=Bpn7LqE5; 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 5DF978046F0D; Tue, 24 Oct 2023 09:12:47 -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 S234954AbjJXQMX (ORCPT + 99 others); Tue, 24 Oct 2023 12:12:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50548 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344087AbjJXQMG (ORCPT ); Tue, 24 Oct 2023 12:12:06 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 587AEA6; Tue, 24 Oct 2023 09:12:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698163924; x=1729699924; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=cx4m6Re1t0koStp5FqrNlsfdb8zARqyFqR2+8EFxmrM=; b=Bpn7LqE5OAMG0zJnhs/VDCRxkCuXgcC/bvCush47c4Q3l+bU+Bqb9bo7 Czeo24Mema3Z1DzZk+C3AS7bU0gMaELXP0a7EqLfwjRSCmKFXyiilqa7c knycnn0mkSMcKjIW0t5k72Q+utu5weYqIXJ2CYnogPEwAqqY7Q3GlNUbi VjfMjt7z5vRkgPuGU6I5CuTG/MUELtcueWiiyvhHRQnCRxt0Sf1S09dCO DErioRU03k2PoUZLEzZbymQ4XAwPG2xydeYHWWvOeC5uVPj58Ds6yN5o6 z/cFXCvbUdmdWSBf3wsUTE46eP1JVd/mPqQHPHJD4kw5CW7+kapz745xe Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10873"; a="451328206" X-IronPort-AV: E=Sophos;i="6.03,248,1694761200"; d="scan'208";a="451328206" 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:08:06 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10873"; a="902237358" X-IronPort-AV: E=Sophos;i="6.03,248,1694761200"; d="scan'208";a="902237358" 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:41 -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 , Eero Tamminen Subject: [RFC 8/8] cgroup/drm: Expose GPU utilisation Date: Tue, 24 Oct 2023 17:07:27 +0100 Message-Id: <20231024160727.282960-9-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 Content-Transfer-Encoding: 8bit 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:47 -0700 (PDT) From: Tvrtko Ursulin To support container use cases where external orchestrators want to make deployment and migration decisions based on GPU load and capacity, we can expose the GPU load as seen by the controller in a new drm.active_us field. This field contains a monotonic cumulative time cgroup has spent executing GPU loads, as reported by the DRM drivers being used by group members. Signed-off-by: Tvrtko Ursulin Cc: Tejun Heo Cc: Eero Tamminen --- Documentation/admin-guide/cgroup-v2.rst | 8 +++++++ kernel/cgroup/drm.c | 29 ++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/Documentation/admin-guide/cgroup-v2.rst b/Documentation/admin-guide/cgroup-v2.rst index 841533527b7b..9ac8ab65161c 100644 --- a/Documentation/admin-guide/cgroup-v2.rst +++ b/Documentation/admin-guide/cgroup-v2.rst @@ -2445,6 +2445,14 @@ respected. DRM weight based time control interface files ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + drm.stat + A read-only flat-keyed file. + + Contains these fields: + + - usage_usec - GPU time used by the group, recursively including all + child groups. + drm.weight Standard cgroup weight based control [1, 10000] used to configure the relative distributing of GPU time between the sibling groups. diff --git a/kernel/cgroup/drm.c b/kernel/cgroup/drm.c index 1d1570bf3e90..127730990301 100644 --- a/kernel/cgroup/drm.c +++ b/kernel/cgroup/drm.c @@ -25,6 +25,8 @@ struct drm_cgroup_state { bool over; bool over_budget; + u64 total_us; + u64 per_s_budget_us; u64 prev_active_us; u64 active_us; @@ -117,6 +119,24 @@ drmcs_write_weight(struct cgroup_subsys_state *css, struct cftype *cftype, return 0; } +static int drmcs_show_stat(struct seq_file *sf, void *v) +{ + struct drm_cgroup_state *drmcs = css_to_drmcs(seq_css(sf)); + u64 val; + +#ifndef CONFIG_64BIT + mutex_lock(&drmcg_mutex); +#endif + val = drmcs->total_us; +#ifndef CONFIG_64BIT + mutex_unlock(&drmcg_mutex); +#endif + + seq_printf(sf, "usage_usec %llu\n", val); + + return 0; +} + static bool __start_scanning(unsigned int period_us) { struct drm_cgroup_state *root = &root_drmcs.drmcs; @@ -169,11 +189,14 @@ static bool __start_scanning(unsigned int period_us) parent = css_to_drmcs(node->parent); active = drmcs_get_active_time_us(drmcs); - if (period_us && active > drmcs->prev_active_us) + if (period_us && active > drmcs->prev_active_us) { drmcs->active_us += active - drmcs->prev_active_us; + drmcs->total_us += drmcs->active_us; + } drmcs->prev_active_us = active; parent->active_us += drmcs->active_us; + parent->total_us += drmcs->active_us; parent->sum_children_weights += drmcs->weight; css_put(node); @@ -564,6 +587,10 @@ struct cftype files[] = { .read_u64 = drmcs_read_weight, .write_u64 = drmcs_write_weight, }, + { + .name = "stat", + .seq_show = drmcs_show_stat, + }, { } /* Zero entry terminates. */ }; -- 2.39.2