From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F10E43F2109 for ; Tue, 14 Jul 2026 21:16:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.52 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784063793; cv=none; b=D7WH9mHRwdBTrZ0bUb1fUMusnJVEtT0amSrgkKwClXPo9gP9cX81l0QZr3ACNhCW15NdX27oKNly6l+8QoIFHLNiltwpeya984pgxgkUFDguq/Yxns2JIQE+4Xf5spZaIm2VzT7mMsvpyDbURkSzQtGn7fywb+VhE+jOpqlhFaU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784063793; c=relaxed/simple; bh=3jUreGkyhrV477FYQIahdQE8YW50gzqKB02n2ANMxFA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=riiMueuBHbsiSFBz92uYloorga1Ju49oJM3zjWi2lBfNbJ9S4RNwiAOvgj6hAmcWi/LW+fKH4iWty3uxP1+5CItfQ/+Oo5f1OaWjQ7qZ5gMmibhrAaXN/jpO5db4nGK4ocVVfSpaw7jNyvTIWnHqQRDWO5zLzw5UJMlDYIL97Po= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=gDhHre6w; arc=none smtp.client-ip=209.85.128.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gDhHre6w" Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-493c52cde9eso40857385e9.3 for ; Tue, 14 Jul 2026 14:16:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784063790; x=1784668590; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=/0bDbsUAsCNrKRVFeKWSEZSKWRta+w0G44odHsje0xU=; b=gDhHre6wjCuvY/6ErjFSNJtv2lWNkQlhCYrPaSaO8j4m6ukwdTqcCtURvIlvW1P64R 2s972RSiE5eEk9+Co793t3A5nAZCM82wzD4boynNCfKhj9qtH31z8MI/FxxK9ySf0E5H G5DTNefz9UJgM0oqlM7Qz20BO1NQEJGJo5agrohr41eGC9zguYoAZSGznaz630CrI4Jb 7TPdGTvcZaNEc5YPIl3bX5TkE10FS2FAWQOvs9M7BXlLoZ4zG6bTIaguig8zo4zW9xub mqSp7gWOmlgXAz0PmKM3V7+1gKtkThNphQuBvTYymvFzh4J1vMJwDHX/4bD/8+9Eg05+ pJ4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784063790; x=1784668590; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=/0bDbsUAsCNrKRVFeKWSEZSKWRta+w0G44odHsje0xU=; b=WmkAdXZRrnxZzInoC6S++vUnJeO6cg4AOn/UvOKJTFZtP2nsJAYu+zQZNPqYS/i31u wWujBbkqxDB+NhRmlUQmeEwGksMMxD3WIYUcnb8idE4mXU7W3GR7uDZgtSNjJ0Cumsw2 XkgbLOPAl8kcUvmT3Px4l6296ytYelqSXl0uH3guGWBgLjENfil13zay9576xfxHViRv Hizfs6WHvFvpn6+hPxgQzgxPM86qtNKtJ+FQPXJS3IxaRrvBadifKosDZgvUvZUZ6CZ1 2HPZmAulU3lgSz2XmHjAxAQIXa4fXLYGdBrn0ryNvnAlJ6uDKumlIZDxbchkOqFSAYjt oGnA== X-Gm-Message-State: AOJu0YxzWNYapSehpKnV7htbE1bpNqL4LLTelnSpDgogfFCxHk89Ygal +FIqzIZCMu+2+FnWBpzFLUzOW7gB162qwfeLODFtXnWYl8L0nifu1XYiV2N9W6zh X-Gm-Gg: AfdE7cl2Z7MQtCS2g5owiW7jWQmbphHbPUJPPwCgJKo8ZgRQA0rq20CODrahYa/HfOn nmD8XJRAgK52ALTohtT0SbWqJIfaSJVe4q4lfoIZRcCLUvUuYvKr/dhybDHGYM+jmO629yPvpMd OAtPdeVuYG8pjl21tyWeYAiuZafRDF1btaAv3EIKf1jo1IBNtBSXoGzflSOSWZoOwzJnPDN7Cto SFxzy4a+kDYo19A8nRxXrUX+Mh2Zbm74l1g75IzSfBWchUM964sRSOmCj+391e6UskHXOuwC/mb FNb5Kc1Su/QPYyRWoRKEyTwjjYU4f7jT0OAbqdZWzR7wBXlPLzW7STW6grj/CrZ4VPd0SzAQODs BoxtDq1V8PTzed/+hgh9/HLL0yqYBBtHrdmIsaaZA98/TlE6rSqDkOrIIe3MBoCMLsuLU+ht653 POBpPmJDL/mMBCA4i6PgiMhD53H7viMh4= X-Received: by 2002:a05:600c:c84:b0:493:ece1:86b9 with SMTP id 5b1f17b1804b1-495389cdfbdmr41072165e9.8.1784063790070; Tue, 14 Jul 2026 14:16:30 -0700 (PDT) Received: from fedora ([94.205.182.68]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4950a32a2casm149843875e9.12.2026.07.14.14.16.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jul 2026 14:16:28 -0700 (PDT) From: Mohamed Ahmed To: linux-kernel@vger.kernel.org Cc: dri-devel@lists.freedesktop.org, Lyude Paul , Danilo Krummrich , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Mary Guillemard , Milos Tijanic , nouveau@lists.freedesktop.org, Mohamed Ahmed Subject: [PATCH 5/6] drm/nouveau: expose global VRAM size and usage via sysfs Date: Wed, 15 Jul 2026 01:14:28 +0400 Message-ID: <20260714211429.238355-6-mohamedahmedegypt2001@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260714211429.238355-1-mohamedahmedegypt2001@gmail.com> References: <20260714211429.238355-1-mohamedahmedegypt2001@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Monitoring tools want a device-wide VRAM total and current usage, but nouveau exposed neither outside of NOUVEAU_GETPARAM ioctls, which are awkward to use for some tools as they rely on pulling libdrm. Add two read-only files in a device attribute group: mem_info_vram_total user-accessible VRAM, i.e. NOUVEAU_GETPARAM_FB_SIZE mem_info_vram_used bytes currently allocated from the VRAM TTM manager Both read nouveau's own framebuffer and TTM accounting, the exact source behind the FB_SIZE/VRAM_USED getparams, so they need no GSP and are present on every board, unlike the GSP-only RUSD group. total is the size of the pool used draws from, so used never exceeds total. used counts only memory nouveau itself allocated and can read below firmware-reserved usage. Signed-off-by: Mohamed Ahmed --- .../ABI/testing/sysfs-driver-nouveau | 17 +++++- drivers/gpu/drm/nouveau/nouveau_drv.h | 1 + drivers/gpu/drm/nouveau/nouveau_sysfs.c | 61 +++++++++++++++++++ 3 files changed, 78 insertions(+), 1 deletion(-) diff --git a/Documentation/ABI/testing/sysfs-driver-nouveau b/Documentation/ABI/testing/sysfs-driver-nouveau index 947474b9955d..968c3ac0c464 100644 --- a/Documentation/ABI/testing/sysfs-driver-nouveau +++ b/Documentation/ABI/testing/sysfs-driver-nouveau @@ -149,4 +149,19 @@ Date: June 2026 Contact: nouveau Description: PCIe link telemetry. pcie_gen is a packed gen/width bitfield; - the remaining files are link error and event counters. \ No newline at end of file + the remaining files are link error and event counters. + +What: /sys/class/drm/card/device/mem_info_vram_total +What: /sys/class/drm/card/device/mem_info_vram_used +Date: June 2026 +Contact: nouveau +Description: + The amount of VRAM usable for allocations and the amount currently + in use, in bytes, world-readable and read-only. mem_info_vram_total + is the installed VRAM minus the region firmware reserves. This is the + same value as NOUVEAU_GETPARAM_FB_SIZE, so it can read slightly below + the card's marketed size, and it is the size of the pool that + mem_info_vram_used draws from (so used never exceeds total). Both + come from nouveau's own framebuffer and TTM accounting (the same + source as the FB_SIZE/VRAM_USED ioctls) and are present on every + nouveau board, independent of GSP-RM. \ No newline at end of file diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h index a3e343085cc1..a8ca86556e2f 100644 --- a/drivers/gpu/drm/nouveau/nouveau_drv.h +++ b/drivers/gpu/drm/nouveau/nouveau_drv.h @@ -297,6 +297,7 @@ struct nouveau_drm { struct nouveau_hwmon *hwmon; struct nouveau_debugfs *debugfs; bool rusd_sysfs; + bool mem_sysfs; /* led management */ struct nouveau_led *led; diff --git a/drivers/gpu/drm/nouveau/nouveau_sysfs.c b/drivers/gpu/drm/nouveau/nouveau_sysfs.c index f3d9462deaba..789b3781bedc 100644 --- a/drivers/gpu/drm/nouveau/nouveau_sysfs.c +++ b/drivers/gpu/drm/nouveau/nouveau_sysfs.c @@ -7,11 +7,18 @@ * file is one decoded value; nvkm owns the units and conversions. A section * that is not supported on this board, or has not been polled yet, reads * -ENODATA. See Documentation/ABI/testing/sysfs-driver-nouveau for units. + * + * Also exposes global VRAM size and usage (mem_info_vram_total/used, bytes) + * from nouveau's own FB/TTM accounting. Unlike RUSD these do not need GSP and + * are present on every board. */ #include #include #include +#include +#include + #include "nouveau_drv.h" #include "nouveau_sysfs.h" @@ -214,11 +221,60 @@ static const struct attribute_group rusd_group = { .attrs = rusd_attrs, }; +/* + * Global VRAM size and current usage, in bytes. These use the same source as the + * NOUVEAU_GETPARAM_FB_SIZE/VRAM_USED ioctls, and are exposed here as a more + * convenient way for monitoring tools to access the data. + * + * Unlike the RUSD group these need no GSP and are present on every board. + */ +static ssize_t +mem_info_vram_total_show(struct device *dev, struct device_attribute *attr, char *buf) +{ + struct nouveau_drm *drm = dev_get_drvdata(dev); + + return sysfs_emit(buf, "%llu\n", drm->client.device.info.ram_user); +} +static DEVICE_ATTR_RO(mem_info_vram_total); + +static ssize_t +mem_info_vram_used_show(struct device *dev, struct device_attribute *attr, char *buf) +{ + struct nouveau_drm *drm = dev_get_drvdata(dev); + struct ttm_resource_manager *vram = ttm_manager_type(&drm->ttm.bdev, TTM_PL_VRAM); + + return sysfs_emit(buf, "%llu\n", ttm_resource_manager_usage(vram)); +} +static DEVICE_ATTR_RO(mem_info_vram_used); + +static struct attribute *nouveau_mem_attrs[] = { + &dev_attr_mem_info_vram_total.attr, + &dev_attr_mem_info_vram_used.attr, + NULL, +}; + +static const struct attribute_group nouveau_mem_group = { + .attrs = nouveau_mem_attrs, +}; + int nouveau_sysfs_init(struct nouveau_drm *drm) { int ret; + /* + * VRAM size/usage comes from nouveau's own accounting, so this group is + * present on every board (GSP or legacy). + * + * The group is NOT devm-managed on drm->dev->dev: that device's devres + * outlives nouveau's remove path (which frees the drm objects the files + * read), so it is torn down explicitly in nouveau_sysfs_fini() before that. + */ + ret = device_add_group(drm->dev->dev, &nouveau_mem_group); + if (ret) + return ret; + drm->mem_sysfs = true; + /* * Only GPUs running GSP with RUSD registered (r570+) get the group. On * everything else there is nothing to expose. All files appear when RUSD @@ -247,4 +303,9 @@ nouveau_sysfs_fini(struct nouveau_drm *drm) device_remove_group(drm->dev->dev, &rusd_group); drm->rusd_sysfs = false; } + + if (drm->mem_sysfs) { + device_remove_group(drm->dev->dev, &nouveau_mem_group); + drm->mem_sysfs = false; + } } -- 2.55.0