From patchwork Wed Jan 8 21:02:38 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Adri=C3=A1n_Larumbe?= X-Patchwork-Id: 13931546 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 73288E77199 for ; Wed, 8 Jan 2025 21:03:40 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4677010E93F; Wed, 8 Jan 2025 21:03:39 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=collabora.com header.i=adrian.larumbe@collabora.com header.b="FAUc4oeB"; dkim-atps=neutral Received: from sender4-pp-f112.zoho.com (sender4-pp-f112.zoho.com [136.143.188.112]) by gabe.freedesktop.org (Postfix) with ESMTPS id E04E510E94B for ; Wed, 8 Jan 2025 21:03:38 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; t=1736370207; cv=none; d=zohomail.com; s=zohoarc; b=H8Jb2K4zs+88UpB5qz00vGVfFUbzy45RkhhnXTZjrXOuRmlDxBFqMcjnPhw/64stUUnqoL0strMRAOhKcA6/kTWgJOQqqqQmm8ILu5388pYFzT5Li18gnwSdmWVU4P4a3cU0TfiysYl14g3By+ealgt8w3mCR6nZz5INHIwfEVY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1736370207; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=j02AXCvuCHibfUnBxBkuO49rQkRYm6/Ti75LjkepN2U=; b=PcbLB+W4T40G4tIFW3FXIlXpBvRR/RkYlW1C1GuwO+IwkKdPPhDajgT6XmSFoYaZy0DWbxw2jhcsfb0fURAttL5D+kuOAtc4P3WJktFHCtYH8QceYRnnsU4eINShPa/pilD+o3dXDc+rs99Y5/SXWtmM3kSWRCb8oOn1BHRLqsg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=collabora.com; spf=pass smtp.mailfrom=adrian.larumbe@collabora.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1736370207; s=zohomail; d=collabora.com; i=adrian.larumbe@collabora.com; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-ID:In-Reply-To:References:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Reply-To; bh=j02AXCvuCHibfUnBxBkuO49rQkRYm6/Ti75LjkepN2U=; b=FAUc4oeBHp8DPo7bLj2RB423IhAgkROH3gUL8hPeJvR4fSLvaBgvDONXDJr46SlQ 92QDrzCGOwb7L3RSmkOSyOKtJsjeVKsiXQtBVI0bSkHSQFOmVM8dECxEn1fPIgtZ2rF /8aL+Pl2UqR8u1TsJR+gejmJwR8SUaG67pEEN+vo= Received: by mx.zohomail.com with SMTPS id 1736370206747493.3339975056514; Wed, 8 Jan 2025 13:03:26 -0800 (PST) From: =?utf-8?q?Adri=C3=A1n_Larumbe?= To: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Jonathan Corbet Cc: kernel@collabora.com, =?utf-8?q?Adri=C3=A1n_Larumbe?= , Tvrtko Ursulin , dri-devel@lists.freedesktop.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v7 1/4] Documentation/gpu: Clarify format of driver-specific fidnfo keys Date: Wed, 8 Jan 2025 21:02:38 +0000 Message-ID: <20250108210259.647030-2-adrian.larumbe@collabora.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250108210259.647030-1-adrian.larumbe@collabora.com> References: <20250108210259.647030-1-adrian.larumbe@collabora.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" This change reflects de facto usage by amdgpu, as exemplified by commit d6530c33a978 ("drm/amdgpu: expose more memory stats in fdinfo"). Signed-off-by: Adrián Larumbe Cc: Tvrtko Ursulin Acked-by: Tvrtko Ursulin --- Documentation/gpu/drm-usage-stats.rst | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Documentation/gpu/drm-usage-stats.rst b/Documentation/gpu/drm-usage-stats.rst index 2717cb2a597e..2b5393ed7692 100644 --- a/Documentation/gpu/drm-usage-stats.rst +++ b/Documentation/gpu/drm-usage-stats.rst @@ -21,7 +21,10 @@ File format specification - File shall contain one key value pair per one line of text. - Colon character (`:`) must be used to delimit keys and values. -- All keys shall be prefixed with `drm-`. +- All standardised keys shall be prefixed with `drm-`. +- Driver-specific keys shall be prefixed with `driver_name-`, where + driver_name should ideally be the same as the `name` field in + `struct drm_driver`, although this is not mandatory. - Whitespace between the delimiter and first non-whitespace character shall be ignored when parsing. - Keys are not allowed to contain whitespace characters. From patchwork Wed Jan 8 21:02:39 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Adri=C3=A1n_Larumbe?= X-Patchwork-Id: 13931547 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id D19F3E77188 for ; Wed, 8 Jan 2025 21:03:44 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5128810EC84; Wed, 8 Jan 2025 21:03:44 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=collabora.com header.i=adrian.larumbe@collabora.com header.b="XEbvqacW"; dkim-atps=neutral Received: from sender4-pp-f112.zoho.com (sender4-pp-f112.zoho.com [136.143.188.112]) by gabe.freedesktop.org (Postfix) with ESMTPS id DF07110E94B for ; Wed, 8 Jan 2025 21:03:42 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; t=1736370211; cv=none; d=zohomail.com; s=zohoarc; b=mbMYkKrgulUJO/cMu9wZhHnYi9GjRfqnG3EUtH5+qd//koB3GpsmSDylqdSPEgybsm07nTt8aPXCYxfL5u31nx3q4IY5F9RwTRGoxeWGJt7LGpFPUpnoYUhoXOttE7dqxKzb8CPE7r/Kj1Q5xH6ETds/rrpyStsZbXXkrPWlMRE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1736370211; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=IeOb8w72JN8I9izYPyP3tyjwcOsCNYfWtXN1cZKj9x4=; b=fDUfzlcq1k+Dgz2G6dAGdzz/dZI2Auwnukxxwlfbqdn7kYj0uihxwAEAp6w8xzImsvF04okkZ4j57NH/jT8kaFIlTVuIz01A2DnhKABph6jxiXaSfQmbrJ+a28Tu5YVeD7vv6VrIEVWUI984PamFrzZVkTG69bdLBibbme9E9wk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=collabora.com; spf=pass smtp.mailfrom=adrian.larumbe@collabora.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1736370211; s=zohomail; d=collabora.com; i=adrian.larumbe@collabora.com; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-ID:In-Reply-To:References:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Reply-To; bh=IeOb8w72JN8I9izYPyP3tyjwcOsCNYfWtXN1cZKj9x4=; b=XEbvqacWWUaJEH4XEL7rMq4HwVL3wdTyI+bPg0PNOhLXuUQF2VKfWIV0lc3/ssUj cHw+i8gqpYnlpbiSCUELleYyRPXuQWlxz1YWWtq8aS9VYaSbZpAJWA2yO1R3nogfvo1 LfapPp6/c+ndrs3DaUx6zMbKOvUUkSwwxvpJi7ro= Received: by mx.zohomail.com with SMTPS id 1736370209212598.6316543311995; Wed, 8 Jan 2025 13:03:29 -0800 (PST) From: =?utf-8?q?Adri=C3=A1n_Larumbe?= To: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Jonathan Corbet Cc: kernel@collabora.com, =?utf-8?q?Adri=C3=A1n_Larumbe?= , Tvrtko Ursulin , dri-devel@lists.freedesktop.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v7 2/4] drm/file: Add driver-specific memory region key printing helper Date: Wed, 8 Jan 2025 21:02:39 +0000 Message-ID: <20250108210259.647030-3-adrian.larumbe@collabora.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250108210259.647030-1-adrian.larumbe@collabora.com> References: <20250108210259.647030-1-adrian.larumbe@collabora.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" This is motivated by the desire of some dirvers (eg. Panthor) to print the size of internal memory regions with a prefix that reflects the driver name, as suggested in the previous documentation commit. That means a minor refactoring of print_size() was needed so as to make it more generic in the format of key strings it takes as input. Signed-off-by: Adrián Larumbe Cc: Tvrtko Ursulin --- drivers/gpu/drm/drm_file.c | 60 +++++++++++++++++++++++++++++++++----- include/drm/drm_file.h | 2 ++ 2 files changed, 54 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/drm_file.c b/drivers/gpu/drm/drm_file.c index cb5f22f5bbb6..5deae4cffa79 100644 --- a/drivers/gpu/drm/drm_file.c +++ b/drivers/gpu/drm/drm_file.c @@ -830,8 +830,7 @@ void drm_send_event(struct drm_device *dev, struct drm_pending_event *e) } EXPORT_SYMBOL(drm_send_event); -static void print_size(struct drm_printer *p, const char *stat, - const char *region, u64 sz) +static void print_size(struct drm_printer *p, const char *key, u64 sz) { const char *units[] = {"", " KiB", " MiB"}; unsigned u; @@ -842,9 +841,54 @@ static void print_size(struct drm_printer *p, const char *stat, sz = div_u64(sz, SZ_1K); } - drm_printf(p, "drm-%s-%s:\t%llu%s\n", stat, region, sz, units[u]); + drm_printf(p, "%s:\t%llu%s\n", key, sz, units[u]); } +#define KEY_LEN 1024 +#define DRM_PREFIX "drm" + +static void +print_size_region(struct drm_printer *p, const char *stat, + const char *region, u64 sz) +{ + char key[KEY_LEN+1] = {0}; + + if (strnlen(stat, KEY_LEN) + strnlen(region, KEY_LEN) + + strlen(DRM_PREFIX) + 2 > KEY_LEN) + return; + + snprintf(key, sizeof(key), "%s-%s-%s", DRM_PREFIX, stat, region); + print_size(p, key, sz); +} + +/** + * drm_driver_print_size - A helper to print driver-specific k:v pairs + * @p: The printer to print output to + * @file: DRM file private data + * @subkey: Name of the key minus the driver name + * @sz: Size value expressed in bytes + * + * Helper to display key:value pairs where the value is a numerical + * size expressed in bytes. It's useful for driver-internal memory + * whose objects aren't exposed to UM through a DRM handle. + */ +void drm_driver_print_size(struct drm_printer *p, struct drm_file *file, + const char *subkey, u64 sz) +{ + char key[KEY_LEN+1] = {0}; + char *drv_name = file->minor->dev->driver->name; + + if (strnlen(subkey, KEY_LEN) + strlen(drv_name) + 1 > KEY_LEN) + return; + + snprintf(key, sizeof(key), "%s-%s", drv_name, subkey); + print_size(p, key, sz); +} +EXPORT_SYMBOL(drm_driver_print_size); + +#undef DRM_PREFIX +#undef KEY_LEN + /** * drm_print_memory_stats - A helper to print memory stats * @p: The printer to print output to @@ -858,15 +902,15 @@ void drm_print_memory_stats(struct drm_printer *p, enum drm_gem_object_status supported_status, const char *region) { - print_size(p, "total", region, stats->private + stats->shared); - print_size(p, "shared", region, stats->shared); - print_size(p, "active", region, stats->active); + print_size_region(p, "total", region, stats->private + stats->shared); + print_size_region(p, "shared", region, stats->shared); + print_size_region(p, "active", region, stats->active); if (supported_status & DRM_GEM_OBJECT_RESIDENT) - print_size(p, "resident", region, stats->resident); + print_size_region(p, "resident", region, stats->resident); if (supported_status & DRM_GEM_OBJECT_PURGEABLE) - print_size(p, "purgeable", region, stats->purgeable); + print_size_region(p, "purgeable", region, stats->purgeable); } EXPORT_SYMBOL(drm_print_memory_stats); diff --git a/include/drm/drm_file.h b/include/drm/drm_file.h index f0ef32e9fa5e..07da14859289 100644 --- a/include/drm/drm_file.h +++ b/include/drm/drm_file.h @@ -494,6 +494,8 @@ struct drm_memory_stats { enum drm_gem_object_status; +void drm_driver_print_size(struct drm_printer *p, struct drm_file *file, + const char *subkey, u64 sz); void drm_print_memory_stats(struct drm_printer *p, const struct drm_memory_stats *stats, enum drm_gem_object_status supported_status, From patchwork Wed Jan 8 21:02:40 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Adri=C3=A1n_Larumbe?= X-Patchwork-Id: 13931548 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 26E59E77199 for ; Wed, 8 Jan 2025 21:03:47 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9B77110E94B; Wed, 8 Jan 2025 21:03:46 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=collabora.com header.i=adrian.larumbe@collabora.com header.b="IecZ82zw"; dkim-atps=neutral Received: from sender4-pp-f112.zoho.com (sender4-pp-f112.zoho.com [136.143.188.112]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5F8CA10EC90 for ; Wed, 8 Jan 2025 21:03:45 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; t=1736370213; cv=none; d=zohomail.com; s=zohoarc; b=YFb9bBztpmCpoAfIenDvu8Z+ZXe+mtv+cHm1Rbywf2zGwv9CRm7pyL01yKOpKqMuD/Q64VF8mtf3IVgh7FkOFIpPIRrTu2ah8Cljw0kNuxCqYBm0r0JFvqpqms0u5TVdTXlWtjPrEfHg1KRWxEOHJ1hWl+5Y/UfvwWToMR2AJOk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1736370213; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=cf+3pKc/11P3IOsbq6dyyYgjHTUbb9LNF+LWZ2Ywi2w=; b=ZcWqgocG3l+XN6G9dwTQaMlc8MsR7PONaiOlBdYYh0YYot4xlXSBG5uE8N33VnHW4SFTuVXX2324jWlvgmR25Wy1PfAgv4pTNz2mKg9wuZuUPzRJs2bdRIRWdqntfCohOokGiv6tUbUyCtnXjhMvrDcsAtWccbsFjdy5KkOHdys= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=collabora.com; spf=pass smtp.mailfrom=adrian.larumbe@collabora.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1736370213; s=zohomail; d=collabora.com; i=adrian.larumbe@collabora.com; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-ID:In-Reply-To:References:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Reply-To; bh=cf+3pKc/11P3IOsbq6dyyYgjHTUbb9LNF+LWZ2Ywi2w=; b=IecZ82zwxogdRO9RCGKSZCE/HUm5QUe83AptZOi6YuQf9YmlCqkeP2rGjGeo2Wk8 qcHLHmAP666oUF0VR4uEuzaNRqfkgjAXoBwxbCdQbT0x0rqFF7XOaiYaQ4T9ofApeRl UNYFHRXk2BtsL7xVjB8NzD/YVTvD/OCwRYc/aJMQ= Received: by mx.zohomail.com with SMTPS id 1736370212026522.9519763070799; Wed, 8 Jan 2025 13:03:32 -0800 (PST) From: =?utf-8?q?Adri=C3=A1n_Larumbe?= To: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Jonathan Corbet Cc: kernel@collabora.com, =?utf-8?q?Adri=C3=A1n_Larumbe?= , Tvrtko Ursulin , dri-devel@lists.freedesktop.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Liviu Dudau , Mihail Atanassov , Steven Price Subject: [PATCH v7 3/4] drm/panthor: Expose size of driver internal BO's over fdinfo Date: Wed, 8 Jan 2025 21:02:40 +0000 Message-ID: <20250108210259.647030-4-adrian.larumbe@collabora.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250108210259.647030-1-adrian.larumbe@collabora.com> References: <20250108210259.647030-1-adrian.larumbe@collabora.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" This will display the sizes of kenrel BO's bound to an open file, which are otherwise not exposed to UM through a handle. The sizes recorded are as follows: - Per group: suspend buffer, protm-suspend buffer, syncobjcs - Per queue: ringbuffer, profiling slots, firmware interface - For all heaps in all heap pools across all VM's bound to an open file, record size of all heap chuks, and for each pool the gpu_context BO too. This does not record the size of FW regions, as these aren't bound to a specific open file and remain active through the whole life of the driver. Reviewed-by: Liviu Dudau Reviewed-by: Mihail Atanassov Reviewed-by: Steven Price Signed-off-by: Adrián Larumbe --- drivers/gpu/drm/panthor/panthor_drv.c | 13 +++++++ drivers/gpu/drm/panthor/panthor_heap.c | 26 +++++++++++++ drivers/gpu/drm/panthor/panthor_heap.h | 2 + drivers/gpu/drm/panthor/panthor_mmu.c | 34 +++++++++++++++++ drivers/gpu/drm/panthor/panthor_mmu.h | 3 ++ drivers/gpu/drm/panthor/panthor_sched.c | 51 ++++++++++++++++++++++++- drivers/gpu/drm/panthor/panthor_sched.h | 2 + 7 files changed, 130 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/panthor/panthor_drv.c b/drivers/gpu/drm/panthor/panthor_drv.c index ac7e53f6e3f0..c41136af27d2 100644 --- a/drivers/gpu/drm/panthor/panthor_drv.c +++ b/drivers/gpu/drm/panthor/panthor_drv.c @@ -1457,12 +1457,25 @@ static void panthor_gpu_show_fdinfo(struct panthor_device *ptdev, drm_printf(p, "drm-curfreq-panthor:\t%lu Hz\n", ptdev->current_frequency); } +static void panthor_show_internal_memory_stats(struct drm_printer *p, struct drm_file *file) +{ + struct panthor_file *pfile = file->driver_priv; + struct drm_memory_stats status = {0}; + + panthor_group_kbo_sizes(pfile, &status); + panthor_vm_heaps_sizes(pfile, &status); + + drm_driver_print_size(p, file, "resident-memory", status.resident); + drm_driver_print_size(p, file, "active-memory", status.active); +} + static void panthor_show_fdinfo(struct drm_printer *p, struct drm_file *file) { struct drm_device *dev = file->minor->dev; struct panthor_device *ptdev = container_of(dev, struct panthor_device, base); panthor_gpu_show_fdinfo(ptdev, file->driver_priv, p); + panthor_show_internal_memory_stats(p, file); drm_show_memory_stats(p, file); } diff --git a/drivers/gpu/drm/panthor/panthor_heap.c b/drivers/gpu/drm/panthor/panthor_heap.c index 3796a9eb22af..db0285ce5812 100644 --- a/drivers/gpu/drm/panthor/panthor_heap.c +++ b/drivers/gpu/drm/panthor/panthor_heap.c @@ -603,3 +603,29 @@ void panthor_heap_pool_destroy(struct panthor_heap_pool *pool) panthor_heap_pool_put(pool); } + +/** + * panthor_heap_pool_size() - Calculate size of all chunks across all heaps in a pool + * @pool: Pool whose total chunk size to calculate. + * + * This function adds the size of all heap chunks across all heaps in the + * argument pool. It also adds the size of the gpu contexts kernel bo. + * It is meant to be used by fdinfo for displaying the size of internal + * driver BO's that aren't exposed to userspace through a GEM handle. + * + */ +size_t panthor_heap_pool_size(struct panthor_heap_pool *pool) +{ + struct panthor_heap *heap; + unsigned long i; + size_t size = 0; + + down_read(&pool->lock); + xa_for_each(&pool->xa, i, heap) + size += heap->chunk_size * heap->chunk_count; + up_read(&pool->lock); + + size += pool->gpu_contexts->obj->size; + + return size; +} diff --git a/drivers/gpu/drm/panthor/panthor_heap.h b/drivers/gpu/drm/panthor/panthor_heap.h index 25a5f2bba445..e3358d4e8edb 100644 --- a/drivers/gpu/drm/panthor/panthor_heap.h +++ b/drivers/gpu/drm/panthor/panthor_heap.h @@ -27,6 +27,8 @@ struct panthor_heap_pool * panthor_heap_pool_get(struct panthor_heap_pool *pool); void panthor_heap_pool_put(struct panthor_heap_pool *pool); +size_t panthor_heap_pool_size(struct panthor_heap_pool *pool); + int panthor_heap_grow(struct panthor_heap_pool *pool, u64 heap_gpu_va, u32 renderpasses_in_flight, diff --git a/drivers/gpu/drm/panthor/panthor_mmu.c b/drivers/gpu/drm/panthor/panthor_mmu.c index c3f0b0225cf9..32cc0f8b8e23 100644 --- a/drivers/gpu/drm/panthor/panthor_mmu.c +++ b/drivers/gpu/drm/panthor/panthor_mmu.c @@ -1941,6 +1941,40 @@ struct panthor_heap_pool *panthor_vm_get_heap_pool(struct panthor_vm *vm, bool c return pool; } +/** + * panthor_vm_heaps_sizes() - Calculate size of all heap chunks across all + * heaps over all the heap pools in a VM + * @pfile: File. + * @status: Memory status to be updated. + * + * Calculate all heap chunk sizes in all heap pools bound to a VM. If the VM + * is active, record the size as active as well. + */ +void panthor_vm_heaps_sizes(struct panthor_file *pfile, struct drm_memory_stats *status) +{ + struct panthor_vm *vm; + unsigned long i; + + if (!pfile->vms) + return; + + xa_for_each(&pfile->vms->xa, i, vm) { + size_t size; + + mutex_lock(&vm->heaps.lock); + if (!vm->heaps.pool) { + mutex_unlock(&vm->heaps.lock); + continue; + } + size = panthor_heap_pool_size(vm->heaps.pool); + mutex_unlock(&vm->heaps.lock); + + status->resident += size; + if (vm->as.id >= 0) + status->active += size; + } +} + static u64 mair_to_memattr(u64 mair, bool coherent) { u64 memattr = 0; diff --git a/drivers/gpu/drm/panthor/panthor_mmu.h b/drivers/gpu/drm/panthor/panthor_mmu.h index 8d21e83d8aba..494c36d732b4 100644 --- a/drivers/gpu/drm/panthor/panthor_mmu.h +++ b/drivers/gpu/drm/panthor/panthor_mmu.h @@ -9,6 +9,7 @@ struct drm_exec; struct drm_sched_job; +struct drm_memory_stats; struct panthor_gem_object; struct panthor_heap_pool; struct panthor_vm; @@ -37,6 +38,8 @@ int panthor_vm_flush_all(struct panthor_vm *vm); struct panthor_heap_pool * panthor_vm_get_heap_pool(struct panthor_vm *vm, bool create); +void panthor_vm_heaps_sizes(struct panthor_file *pfile, struct drm_memory_stats *status); + struct panthor_vm *panthor_vm_get(struct panthor_vm *vm); void panthor_vm_put(struct panthor_vm *vm); struct panthor_vm *panthor_vm_create(struct panthor_device *ptdev, bool for_mcu, diff --git a/drivers/gpu/drm/panthor/panthor_sched.c b/drivers/gpu/drm/panthor/panthor_sched.c index ef4bec7ff9c7..e4acf6a0a9b1 100644 --- a/drivers/gpu/drm/panthor/panthor_sched.c +++ b/drivers/gpu/drm/panthor/panthor_sched.c @@ -618,7 +618,7 @@ struct panthor_group { */ struct panthor_kernel_bo *syncobjs; - /** @fdinfo: Per-file total cycle and timestamp values reference. */ + /** @fdinfo: Per-group total cycle and timestamp values and kernel BO sizes. */ struct { /** @data: Total sampled values for jobs in queues from this group. */ struct panthor_gpu_usage data; @@ -628,6 +628,9 @@ struct panthor_group { * and job post-completion processing function */ struct mutex lock; + + /** @kbo_sizes: Aggregate size of private kernel BO's held by the group. */ + size_t kbo_sizes; } fdinfo; /** @state: Group state. */ @@ -3365,6 +3368,29 @@ group_create_queue(struct panthor_group *group, return ERR_PTR(ret); } +static void add_group_kbo_sizes(struct panthor_device *ptdev, + struct panthor_group *group) +{ + struct panthor_queue *queue; + int i; + + if (drm_WARN_ON(&ptdev->base, IS_ERR_OR_NULL(group))) + return; + if (drm_WARN_ON(&ptdev->base, ptdev != group->ptdev)) + return; + + group->fdinfo.kbo_sizes += group->suspend_buf->obj->size; + group->fdinfo.kbo_sizes += group->protm_suspend_buf->obj->size; + group->fdinfo.kbo_sizes += group->syncobjs->obj->size; + + for (i = 0; i < group->queue_count; i++) { + queue = group->queues[i]; + group->fdinfo.kbo_sizes += queue->ringbuf->obj->size; + group->fdinfo.kbo_sizes += queue->iface.mem->obj->size; + group->fdinfo.kbo_sizes += queue->profiling.slots->obj->size; + } +} + #define MAX_GROUPS_PER_POOL 128 int panthor_group_create(struct panthor_file *pfile, @@ -3489,6 +3515,7 @@ int panthor_group_create(struct panthor_file *pfile, } mutex_unlock(&sched->reset.lock); + add_group_kbo_sizes(group->ptdev, group); mutex_init(&group->fdinfo.lock); return gid; @@ -3606,6 +3633,28 @@ void panthor_group_pool_destroy(struct panthor_file *pfile) pfile->groups = NULL; } +/** + * panthor_group_kbo_sizes() - Retrieve aggregate size of all private kernel BO's + * belonging to all the groups owned by an open Panthor file + * @pfile: File. + * @status: Memory status to be updated. + * + */ +void panthor_group_kbo_sizes(struct panthor_file *pfile, struct drm_memory_stats *status) +{ + struct panthor_group_pool *gpool = pfile->groups; + struct panthor_group *group; + unsigned long i; + + if (IS_ERR_OR_NULL(gpool)) + return; + xa_for_each(&gpool->xa, i, group) { + status->resident += group->fdinfo.kbo_sizes; + if (group->csg_id >= 0) + status->active += group->fdinfo.kbo_sizes; + } +} + static void job_release(struct kref *ref) { struct panthor_job *job = container_of(ref, struct panthor_job, refcount); diff --git a/drivers/gpu/drm/panthor/panthor_sched.h b/drivers/gpu/drm/panthor/panthor_sched.h index 5ae6b4bde7c5..2327d441ceb1 100644 --- a/drivers/gpu/drm/panthor/panthor_sched.h +++ b/drivers/gpu/drm/panthor/panthor_sched.h @@ -9,6 +9,7 @@ struct dma_fence; struct drm_file; struct drm_gem_object; struct drm_sched_job; +struct drm_memory_stats; struct drm_panthor_group_create; struct drm_panthor_queue_create; struct drm_panthor_group_get_state; @@ -36,6 +37,7 @@ void panthor_job_update_resvs(struct drm_exec *exec, struct drm_sched_job *job); int panthor_group_pool_create(struct panthor_file *pfile); void panthor_group_pool_destroy(struct panthor_file *pfile); +void panthor_group_kbo_sizes(struct panthor_file *pfile, struct drm_memory_stats *status); int panthor_sched_init(struct panthor_device *ptdev); void panthor_sched_unplug(struct panthor_device *ptdev); From patchwork Wed Jan 8 21:02:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Adri=C3=A1n_Larumbe?= X-Patchwork-Id: 13931549 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 853A5E77188 for ; Wed, 8 Jan 2025 21:03:48 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 077D810E947; Wed, 8 Jan 2025 21:03:48 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=collabora.com header.i=adrian.larumbe@collabora.com header.b="EzgMR0GV"; dkim-atps=neutral Received: from sender4-pp-f112.zoho.com (sender4-pp-f112.zoho.com [136.143.188.112]) by gabe.freedesktop.org (Postfix) with ESMTPS id DB43610EC90 for ; Wed, 8 Jan 2025 21:03:46 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; t=1736370215; cv=none; d=zohomail.com; s=zohoarc; b=cVl+ryPb2apeWILXP0Uc8S5mznBHqwUSSNQhfLlPZh4RAzNlyvogUagFHELaY4QlakJX4EBZ41dxyL1uoGTEL2ZHYiTb7fbne7g4qfq85CruZHXUTCrYQZl2q7pRGYiR6YtQX9LD6bUyvIoY5eSs1Losv8nAT7gQBQuwKiqtgx4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1736370215; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=wNaB1y8CPCW4MU5KNXHb/rWezDgTcc6rjkhqAnOZx4E=; b=CLPfkRWC37FQjt2mMsed7zGGFutQszyTPIVG/Mjdmi2OX2I3NeEwVnH39tTh7n4ONEIUsJNRYK78FVjePP8BhVzBqKZeg46jP4G8ru1Lo9ncAumDfv4y14uU/MrtpBn92cgysJCW9CB2azikTpLjauATplxfrNeLfeX3+iElNiQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=collabora.com; spf=pass smtp.mailfrom=adrian.larumbe@collabora.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1736370215; s=zohomail; d=collabora.com; i=adrian.larumbe@collabora.com; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-ID:In-Reply-To:References:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Reply-To; bh=wNaB1y8CPCW4MU5KNXHb/rWezDgTcc6rjkhqAnOZx4E=; b=EzgMR0GV9Ok58NME2JbKWG+Um1JXJf/EIhNJeKkEdC/aHaO4K8rF/mDa2tX/wOX/ WVQ+3HoAEzR2iGdwgQZWHE7iqKxQ2zsZYxoPG5n4MGoCGSsI53Oqilz/uU01ID2eOFz +TkdDyWIcociL3WqLRPSkM4k11LMtyMy1yHKaz0I= Received: by mx.zohomail.com with SMTPS id 1736370214840680.0859912850773; Wed, 8 Jan 2025 13:03:34 -0800 (PST) From: =?utf-8?q?Adri=C3=A1n_Larumbe?= To: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Jonathan Corbet Cc: kernel@collabora.com, =?utf-8?q?Adri=C3=A1n_Larumbe?= , Tvrtko Ursulin , dri-devel@lists.freedesktop.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Mihail Atanassov , Liviu Dudau , Steven Price Subject: [PATCH v7 4/4] Documentation/gpu: Add fdinfo meanings of drm-*-internal memory tags Date: Wed, 8 Jan 2025 21:02:41 +0000 Message-ID: <20250108210259.647030-5-adrian.larumbe@collabora.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250108210259.647030-1-adrian.larumbe@collabora.com> References: <20250108210259.647030-1-adrian.larumbe@collabora.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" A previous commit enabled display of driver-internal kernel BO sizes through the device file's fdinfo interface. Expand the description of the relevant driver-specific key:value pairs with the definitions of the new panthor-*-memory ones. Reviewed-by: Mihail Atanassov Reviewed-by: Liviu Dudau Reviewed-by: Steven Price Signed-off-by: Adrián Larumbe --- Documentation/gpu/panthor.rst | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Documentation/gpu/panthor.rst b/Documentation/gpu/panthor.rst index 3f8979fa2b86..76e03304fe7a 100644 --- a/Documentation/gpu/panthor.rst +++ b/Documentation/gpu/panthor.rst @@ -26,6 +26,8 @@ the currently possible format options: drm-cycles-panthor: 94439687187 drm-maxfreq-panthor: 1000000000 Hz drm-curfreq-panthor: 1000000000 Hz + panthor-resident-memory: 10396 KiB + panthor-active-memory: 10396 KiB drm-total-memory: 16480 KiB drm-shared-memory: 0 drm-active-memory: 16200 KiB @@ -44,3 +46,11 @@ driver by writing into the appropriate sysfs node:: Where `N` is a bit mask where cycle and timestamp sampling are respectively enabled by the first and second bits. + +Possible `panthor-*-memory` keys are: `active` and `resident`. +These values convey the sizes of the internal driver-owned shmem BO's that +aren't exposed to user-space through a DRM handle, like queue ring buffers, +sync object arrays and heap chunks. Because they are all allocated and pinned +at creation time, only `panthor-resident-memory` is necessary to tell us their +size. `panthor-resident-active` shows the size of kernel BO's associated with +VM's and groups currently being scheduled for execution by the GPU.