From nobody Sat Feb 7 18:26:18 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B6E2AC77B61 for ; Thu, 27 Apr 2023 17:54:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244477AbjD0RyG (ORCPT ); Thu, 27 Apr 2023 13:54:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244319AbjD0Rx7 (ORCPT ); Thu, 27 Apr 2023 13:53:59 -0400 Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 324AABE; Thu, 27 Apr 2023 10:53:55 -0700 (PDT) Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-63d2ba63dddso6861875b3a.2; Thu, 27 Apr 2023 10:53:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682618034; x=1685210034; 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; bh=sGjGxmlouVGhi3M6MRZkXvcAVwGS3ye2TGK3XrM7dRI=; b=DskqNrsRREOOo5+tJopmLlCj6+GWPbnQOa2+AYvaPYS7fcpG66CcxTCQrmwYXBL3WQ +BkdoMC1ullgLuxY+Ds8+4wtsgzFGje4bjzDVek19jcDHjSS1Iwi3kiHP/PPZLRehB5a Zp9LmrhckNG6ETFh/+OolV51Jh7+GIC9C2SO6R5FS8jYo9CNKgW9yAbalvrpaQyX2EPq eWT+EyJF3gEjxMScpTDYWjmkLghh0ytfAuhZhmGQIQODAZandBUchj8+1gQFeECBQGq8 REtNK/WAXbsVAO/yv/vqGiymb8vtB7zd/Ta6RHuHWOSSGCwY+wkETaKIIS/jwqU+/MpU 8Qkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682618034; x=1685210034; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sGjGxmlouVGhi3M6MRZkXvcAVwGS3ye2TGK3XrM7dRI=; b=h9ctLnr5RJneK4oujbfcCVOLGU7kN4A8IZ6a0nV02exHsLVe+6g1Dfvw14PO6Lyrl3 /Ne120KCmTv8P/gBfl32IHEGvSijbb/bx/5BHemAxoHL75pPEmkm5EtU56gUVtzu1WuD OfzWoH5bHNVf0xASCSPCSCxpARqAyEEdzIYNWlgbMNlrTwTH3ucWRSF51Q8tablo+StP xic2YHWTmtvIOdCDPG4T+66DMovAJaEOE5/gum/dKe17Qsav05KdChCWF3XowmAvHUfr kITqhirCVrGYBFGfljgml526LYIUaP6OnT9j8AODoY0ZRqfwNCDxznWF5FF/Y0Zw23r/ CIwg== X-Gm-Message-State: AC+VfDwUW3f8tBsLOr6pXZUjqEXZfNQwM/V3THFjz7BB9IQcYDSqtt/Y FDN8jKtbS2vu7me7WI0LEBA= X-Google-Smtp-Source: ACHHUZ6B+aak2ZkUYsB+1ZMUHj9b32Ns03yuVkuacD2JU5/1vQBVbzhVWx7Q599OyF6uLhjfXVdnNQ== X-Received: by 2002:a05:6a20:7f97:b0:f3:67da:9db5 with SMTP id d23-20020a056a207f9700b000f367da9db5mr3076695pzj.38.1682618034603; Thu, 27 Apr 2023 10:53:54 -0700 (PDT) Received: from localhost ([2a00:79e1:abd:4a00:61b:48ed:72ab:435b]) by smtp.gmail.com with ESMTPSA id e27-20020a630f1b000000b00502e7115cbdsm3662034pgl.51.2023.04.27.10.53.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Apr 2023 10:53:54 -0700 (PDT) From: Rob Clark To: dri-devel@lists.freedesktop.org Cc: freedreno@lists.freedesktop.org, Daniel Vetter , Tvrtko Ursulin , Boris Brezillon , Christopher Healy , Emil Velikov , =?UTF-8?q?Christian=20K=C3=B6nig?= , Rob Clark , Rodrigo Vivi , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Jonathan Corbet , linux-doc@vger.kernel.org (open list:DOCUMENTATION), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v2 1/9] drm/docs: Fix usage stats typos Date: Thu, 27 Apr 2023 10:53:25 -0700 Message-Id: <20230427175340.1280952-2-robdclark@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230427175340.1280952-1-robdclark@gmail.com> References: <20230427175340.1280952-1-robdclark@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Rob Clark Fix a couple missing ':'s. Signed-off-by: Rob Clark Reviewed-by: Rodrigo Vivi Reviewed-by: Christian K=C3=B6nig --- Documentation/gpu/drm-usage-stats.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Documentation/gpu/drm-usage-stats.rst b/Documentation/gpu/drm-= usage-stats.rst index b46327356e80..72d069e5dacb 100644 --- a/Documentation/gpu/drm-usage-stats.rst +++ b/Documentation/gpu/drm-usage-stats.rst @@ -105,7 +105,7 @@ object belong to this client, in the respective memory = region. Default unit shall be bytes with optional unit specifiers of 'KiB' or 'MiB' indicating kibi- or mebi-bytes. =20 -- drm-cycles- +- drm-cycles-: =20 Engine identifier string must be the same as the one specified in the drm-engine- tag and shall contain the number of busy cycles for the g= iven @@ -117,7 +117,7 @@ larger value within a reasonable period. Upon observing= a value lower than what was previously read, userspace is expected to stay with that larger previo= us value until a monotonic update is seen. =20 -- drm-maxfreq- [Hz|MHz|KHz] +- drm-maxfreq-: [Hz|MHz|KHz] =20 Engine identifier string must be the same as the one specified in the drm-engine- tag and shall contain the maximum frequency for the given --=20 2.39.2 From nobody Sat Feb 7 18:26:18 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB874C7EE21 for ; Thu, 27 Apr 2023 17:54:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244478AbjD0RyK (ORCPT ); Thu, 27 Apr 2023 13:54:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33488 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244423AbjD0RyA (ORCPT ); Thu, 27 Apr 2023 13:54:00 -0400 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31780420A; Thu, 27 Apr 2023 10:53:57 -0700 (PDT) Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-1a686260adcso91124975ad.0; Thu, 27 Apr 2023 10:53:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682618036; x=1685210036; 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; bh=UBhM8EV3rKHhycxSOd95UiYteeNU/7m/WGXxS7jGTSE=; b=Ls4jFb+IpHVK6hd4oTgRZh1XNrm/GGsmbM1MTz2AZcdHdxzQ+tGALfErG4zqPfYALQ 4suMa75vWaO0JTm3RbPgJqDt15bxo2c8F+HfHRiPjEinqB8/NGkGbAyi7kokD/bWzTdH ofTixZ4kDUIr0YC1Q3BCsUPog3gZkjn+nev3RlOo3nHDuxR3S0K91wDdfGxU8thZgQkM DtKNgMs7XHbeRNM7d5v6f0GOCq/CGIPB1zc8DJsG4Sl5kGC4R38T0zddl6DYUwiT9nkA OstnBQtiQGDqTITIUpIvI35QbHJd4DaGJn+rCa0cTHbipCNf+wxE4A6pTqzHLkGz/fEE A7Ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682618036; x=1685210036; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UBhM8EV3rKHhycxSOd95UiYteeNU/7m/WGXxS7jGTSE=; b=YXCb3TmegPJrB7sU+QmvbTfS/A7yRfO01dIReKkkRLg5ER2FC3usUWc3MrRftT2BiX /SrDAtelROYykB8vUy18uAlJWt9iv0zeGiU6me4lJj1DCkEPTvxWM/mZ15rtaCima2SH ofQGhqRLj9Y+f27mMLqtTu1H1y9wIBed0F79frJ67oQzmDzWmX8X5QV4dOLbSjrftiSb I4VVLjQCRBDNJu9lAX28KTClMr1vfSTMMQphqkd0/sIA1CuXZhrGybU/WmAmagdYAzcM 9AWYKdwMLxwArNzVjhWlYMOx4YnWXbAiP4ELkWiHCFk42qB0VnuWbrhpNybX5rCtEUPP rsbA== X-Gm-Message-State: AC+VfDzRDHKcK2CvjBrHXB0bKToOOjZkPQpAy1eCW+g/vPYNfsC47jFS aCMqr8IiVJcDhSgkJZbWqhE= X-Google-Smtp-Source: ACHHUZ6IFGCsK9vNT8DizUsnkKluwvUlgTje+Wo9ShQhw/TLfGLD127nu2oMIGujHdFfqPrdp8xeeg== X-Received: by 2002:a17:902:da90:b0:19f:188c:3e34 with SMTP id j16-20020a170902da9000b0019f188c3e34mr2843715plx.53.1682618036600; Thu, 27 Apr 2023 10:53:56 -0700 (PDT) Received: from localhost ([2a00:79e1:abd:4a00:61b:48ed:72ab:435b]) by smtp.gmail.com with ESMTPSA id jl14-20020a170903134e00b001a2104d706fsm11903101plb.225.2023.04.27.10.53.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Apr 2023 10:53:56 -0700 (PDT) From: Rob Clark To: dri-devel@lists.freedesktop.org Cc: freedreno@lists.freedesktop.org, Daniel Vetter , Tvrtko Ursulin , Boris Brezillon , Christopher Healy , Emil Velikov , =?UTF-8?q?Christian=20K=C3=B6nig?= , Rob Clark , Daniel Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Jonathan Corbet , linux-doc@vger.kernel.org (open list:DOCUMENTATION), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v2 2/9] drm: Add common fdinfo helper Date: Thu, 27 Apr 2023 10:53:26 -0700 Message-Id: <20230427175340.1280952-3-robdclark@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230427175340.1280952-1-robdclark@gmail.com> References: <20230427175340.1280952-1-robdclark@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Rob Clark Handle a bit of the boiler-plate in a single case, and make it easier to add some core tracked stats. This also ensures consistent behavior across drivers for standardised fields. v2: Update drm-usage-stats.rst, 64b client-id, rename drm_show_fdinfo Reviewed-by: Daniel Vetter Signed-off-by: Rob Clark --- Documentation/gpu/drm-usage-stats.rst | 10 +++++++- drivers/gpu/drm/drm_file.c | 35 +++++++++++++++++++++++++++ include/drm/drm_drv.h | 7 ++++++ include/drm/drm_file.h | 4 +++ 4 files changed, 55 insertions(+), 1 deletion(-) diff --git a/Documentation/gpu/drm-usage-stats.rst b/Documentation/gpu/drm-= usage-stats.rst index 72d069e5dacb..552195fb1ea3 100644 --- a/Documentation/gpu/drm-usage-stats.rst +++ b/Documentation/gpu/drm-usage-stats.rst @@ -126,7 +126,15 @@ percentage utilization of the engine, whereas drm-engi= ne- only reflects time active without considering what frequency the engine is operating as a percentage of it's maximum frequency. =20 +Implementation Details +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +Drivers should use drm_show_fdinfo() in their `struct file_operations`, and +implement &drm_driver.show_fdinfo if they wish to provide any stats which +are not provided by drm_show_fdinfo(). But even driver specific stats sho= uld +be documented above and where possible, aligned with other drivers. + Driver specific implementations -=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D +------------------------------- =20 :ref:`i915-usage-stats` diff --git a/drivers/gpu/drm/drm_file.c b/drivers/gpu/drm/drm_file.c index a51ff8cee049..6d5bdd684ae2 100644 --- a/drivers/gpu/drm/drm_file.c +++ b/drivers/gpu/drm/drm_file.c @@ -148,6 +148,7 @@ bool drm_dev_needs_global_mutex(struct drm_device *dev) */ struct drm_file *drm_file_alloc(struct drm_minor *minor) { + static atomic64_t ident =3D ATOMIC_INIT(0); struct drm_device *dev =3D minor->dev; struct drm_file *file; int ret; @@ -156,6 +157,8 @@ struct drm_file *drm_file_alloc(struct drm_minor *minor) if (!file) return ERR_PTR(-ENOMEM); =20 + /* Get a unique identifier for fdinfo: */ + file->client_id =3D atomic64_inc_return(&ident); file->pid =3D get_pid(task_pid(current)); file->minor =3D minor; =20 @@ -868,6 +871,38 @@ void drm_send_event(struct drm_device *dev, struct drm= _pending_event *e) } EXPORT_SYMBOL(drm_send_event); =20 +/** + * drm_show_fdinfo - helper for drm file fops + * @seq_file: output stream + * @f: the device file instance + * + * Helper to implement fdinfo, for userspace to query usage stats, etc, of= a + * process using the GPU. See also &drm_driver.show_fdinfo. + * + * For text output format description please see Documentation/gpu/drm-usa= ge-stats.rst + */ +void drm_show_fdinfo(struct seq_file *m, struct file *f) +{ + struct drm_file *file =3D f->private_data; + struct drm_device *dev =3D file->minor->dev; + struct drm_printer p =3D drm_seq_file_printer(m); + + drm_printf(&p, "drm-driver:\t%s\n", dev->driver->name); + drm_printf(&p, "drm-client-id:\t%llu\n", file->client_id); + + if (dev_is_pci(dev->dev)) { + struct pci_dev *pdev =3D to_pci_dev(dev->dev); + + drm_printf(&p, "drm-pdev:\t%04x:%02x:%02x.%d\n", + pci_domain_nr(pdev->bus), pdev->bus->number, + PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn)); + } + + if (dev->driver->show_fdinfo) + dev->driver->show_fdinfo(&p, file); +} +EXPORT_SYMBOL(drm_show_fdinfo); + /** * mock_drm_getfile - Create a new struct file for the drm device * @minor: drm minor to wrap (e.g. #drm_device.primary) diff --git a/include/drm/drm_drv.h b/include/drm/drm_drv.h index 5b86bb7603e7..5edf2a13733b 100644 --- a/include/drm/drm_drv.h +++ b/include/drm/drm_drv.h @@ -401,6 +401,13 @@ struct drm_driver { struct drm_device *dev, uint32_t handle, uint64_t *offset); =20 + /** + * @show_fdinfo: + * + * Print device specific fdinfo. See Documentation/gpu/drm-usage-stats.r= st. + */ + void (*show_fdinfo)(struct drm_printer *p, struct drm_file *f); + /** @major: driver major number */ int major; /** @minor: driver minor number */ diff --git a/include/drm/drm_file.h b/include/drm/drm_file.h index 0d1f853092ab..6de6d0e9c634 100644 --- a/include/drm/drm_file.h +++ b/include/drm/drm_file.h @@ -258,6 +258,9 @@ struct drm_file { /** @pid: Process that opened this file. */ struct pid *pid; =20 + /** @client_id: A unique id for fdinfo */ + u64 client_id; + /** @magic: Authentication magic, see @authenticated. */ drm_magic_t magic; =20 @@ -437,6 +440,7 @@ void drm_send_event(struct drm_device *dev, struct drm_= pending_event *e); void drm_send_event_timestamp_locked(struct drm_device *dev, struct drm_pending_event *e, ktime_t timestamp); +void drm_show_fdinfo(struct seq_file *m, struct file *f); =20 struct file *mock_drm_getfile(struct drm_minor *minor, unsigned int flags); =20 --=20 2.39.2 From nobody Sat Feb 7 18:26:18 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 66010C7EE21 for ; Thu, 27 Apr 2023 17:54:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244174AbjD0RyN (ORCPT ); Thu, 27 Apr 2023 13:54:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244020AbjD0RyB (ORCPT ); Thu, 27 Apr 2023 13:54:01 -0400 Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09F413C15; Thu, 27 Apr 2023 10:53:59 -0700 (PDT) Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-64115eef620so6795950b3a.1; Thu, 27 Apr 2023 10:53:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682618038; x=1685210038; 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; bh=oBfxB8yEA4WhI7T5i4/ckAUY1Fu23yRgn7oYj27vnCU=; b=L1nF7BCZaBP86QA8Op3mSkjT2UtT+S15flbFR0f0eOTvMVCmfniMiX5dID5EGdz61P ieBXt1NAw2rxJgHrdwYLvYF8ntYs4uwj/nCjpgEGDfTseJ92qQ5SGsYki0aaWcyh2fyK G8prdb/NM5zCZStwSZi/WFKVIIR3AGA9eVpOdScXgRqb3uSpdJLJxSSElMl7cbPBDeAH Y1Y0nlker1Z8x5URSZwMVkAevF7c3TIg3usf5LEI/IxnihLFUOeJBclUBbdpOjzhgFsp lTvKPPaqKjwWiBCGAuNgFYnPNzSurCA4dhFw+DIsH2gG0WZx4gYezqrHFX7eHOlkgZzU zwbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682618038; x=1685210038; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oBfxB8yEA4WhI7T5i4/ckAUY1Fu23yRgn7oYj27vnCU=; b=P/LphTy/PUlhFGe3RSQh8KHEdJf8Agxxr4n1hopFpKJXSA04ZGN3PQ7ZaIXeEACr/d 5GHJSUHGWp+fgQidaZMCBhBNjjF04hyjCSPhq7qmstBCpPVR88FaH7jB4dnSmQnNaBMT FpN1MW57SfNn55+E2Gz5zfhpm/pcAp4LCnhW/Pva7bO0lySPFMbaaJsp9SxFg5tyLB5J rnnFFGrCk41/cHWvOIgmVTyTEjvjEEluJV5WT7d2po7TcazqjfFCDsrdvcMMcQ8GQAKi unkD+/bHLJDsArehfmLgkMhITQyrpnWuhkD3ux3LkzsLPc0ZfnXoJZ1j0zdp3g9o8JXO 7GQQ== X-Gm-Message-State: AC+VfDyKHltmDGhJ/yxsdDte0Zq1zn2mDKvTP5n6vfiue/IJGz4XW35+ mcgMhHdgsK09NEpdtMTrc/o= X-Google-Smtp-Source: ACHHUZ4RY8lUy/Z4Ld9c0UFYaaSoWErxG6HLfP2eNZlkE1GaZYLb1I87VbW+l/YJFqATDwzqwkRTig== X-Received: by 2002:a17:902:d484:b0:1a9:68d2:e4ae with SMTP id c4-20020a170902d48400b001a968d2e4aemr8298243plg.2.1682618038445; Thu, 27 Apr 2023 10:53:58 -0700 (PDT) Received: from localhost ([2a00:79e1:abd:4a00:61b:48ed:72ab:435b]) by smtp.gmail.com with ESMTPSA id u13-20020a170902e80d00b0019719f752c5sm1638484plg.59.2023.04.27.10.53.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Apr 2023 10:53:58 -0700 (PDT) From: Rob Clark To: dri-devel@lists.freedesktop.org Cc: freedreno@lists.freedesktop.org, Daniel Vetter , Tvrtko Ursulin , Boris Brezillon , Christopher Healy , Emil Velikov , =?UTF-8?q?Christian=20K=C3=B6nig?= , Rob Clark , Dmitry Baryshkov , Rob Clark , Abhinav Kumar , Sean Paul , David Airlie , linux-arm-msm@vger.kernel.org (open list:DRM DRIVER FOR MSM ADRENO GPU), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v2 3/9] drm/msm: Switch to fdinfo helper Date: Thu, 27 Apr 2023 10:53:27 -0700 Message-Id: <20230427175340.1280952-4-robdclark@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230427175340.1280952-1-robdclark@gmail.com> References: <20230427175340.1280952-1-robdclark@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Rob Clark Now that we have a common helper, use it. Signed-off-by: Rob Clark Reviewed-by: Dmitry Baryshkov --- drivers/gpu/drm/msm/msm_drv.c | 11 +++++------ drivers/gpu/drm/msm/msm_gpu.c | 2 -- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/msm/msm_drv.c b/drivers/gpu/drm/msm/msm_drv.c index 9b6f17b1261f..1e941aa77609 100644 --- a/drivers/gpu/drm/msm/msm_drv.c +++ b/drivers/gpu/drm/msm/msm_drv.c @@ -1043,23 +1043,21 @@ static const struct drm_ioctl_desc msm_ioctls[] =3D= { DRM_IOCTL_DEF_DRV(MSM_SUBMITQUEUE_QUERY, msm_ioctl_submitqueue_query, DRM= _RENDER_ALLOW), }; =20 -static void msm_fop_show_fdinfo(struct seq_file *m, struct file *f) +static void msm_show_fdinfo(struct drm_printer *p, struct drm_file *file) { - struct drm_file *file =3D f->private_data; struct drm_device *dev =3D file->minor->dev; struct msm_drm_private *priv =3D dev->dev_private; - struct drm_printer p =3D drm_seq_file_printer(m); =20 if (!priv->gpu) return; =20 - msm_gpu_show_fdinfo(priv->gpu, file->driver_priv, &p); + msm_gpu_show_fdinfo(priv->gpu, file->driver_priv, p); } =20 static const struct file_operations fops =3D { .owner =3D THIS_MODULE, DRM_GEM_FOPS, - .show_fdinfo =3D msm_fop_show_fdinfo, + .show_fdinfo =3D drm_show_fdinfo, }; =20 static const struct drm_driver msm_driver =3D { @@ -1069,7 +1067,7 @@ static const struct drm_driver msm_driver =3D { DRIVER_MODESET | DRIVER_SYNCOBJ, .open =3D msm_open, - .postclose =3D msm_postclose, + .postclose =3D msm_postclose, .lastclose =3D drm_fb_helper_lastclose, .dumb_create =3D msm_gem_dumb_create, .dumb_map_offset =3D msm_gem_dumb_map_offset, @@ -1080,6 +1078,7 @@ static const struct drm_driver msm_driver =3D { #ifdef CONFIG_DEBUG_FS .debugfs_init =3D msm_debugfs_init, #endif + .show_fdinfo =3D msm_show_fdinfo, .ioctls =3D msm_ioctls, .num_ioctls =3D ARRAY_SIZE(msm_ioctls), .fops =3D &fops, diff --git a/drivers/gpu/drm/msm/msm_gpu.c b/drivers/gpu/drm/msm/msm_gpu.c index b1647b851018..52db90e34ead 100644 --- a/drivers/gpu/drm/msm/msm_gpu.c +++ b/drivers/gpu/drm/msm/msm_gpu.c @@ -151,8 +151,6 @@ int msm_gpu_pm_suspend(struct msm_gpu *gpu) void msm_gpu_show_fdinfo(struct msm_gpu *gpu, struct msm_file_private *ctx, struct drm_printer *p) { - drm_printf(p, "drm-driver:\t%s\n", gpu->dev->driver->name); - drm_printf(p, "drm-client-id:\t%u\n", ctx->seqno); drm_printf(p, "drm-engine-gpu:\t%llu ns\n", ctx->elapsed_ns); drm_printf(p, "drm-cycles-gpu:\t%llu\n", ctx->cycles); drm_printf(p, "drm-maxfreq-gpu:\t%u Hz\n", gpu->fast_rate); --=20 2.39.2 From nobody Sat Feb 7 18:26:18 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 35300C77B73 for ; Thu, 27 Apr 2023 17:54:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244409AbjD0RyZ (ORCPT ); Thu, 27 Apr 2023 13:54:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244472AbjD0RyV (ORCPT ); Thu, 27 Apr 2023 13:54:21 -0400 Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DF2F63A92 for ; Thu, 27 Apr 2023 10:54:03 -0700 (PDT) Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-64115e652eeso6806633b3a.0 for ; Thu, 27 Apr 2023 10:54:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682618043; x=1685210043; 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; bh=kTwA5Igpbrlnqx2MFioiqClnnk3fWCd7F6gKiXvsizg=; b=F02JosDYSh6gH8BbBVyLQpfSS+7jFCWgel+AjYaRMDX6D8xc/HdFGNUw/LP4VfuhKO FBGI+ypyvSemxnMhgbXmZhIj0XAsFs578Ow2DPZX6tr0p6k0r7tRA0tkDLWNgoI66t14 ChadQMBb4p5jszCF567xmG+p0QDKicYptfWnC10WXOjeNrcro5Kl4r0qSGiZ7igOJ9yw ur+tS0pDFIXAvtNgVWdz84HVxOS7GQZpK/ZRRCoMAELIQdgaEAUBJ8h113jxpNcWYFbz 1Qb9YqiCSLdpHjJTq8V4AyQXpEjLA0vl/xdhw7dWvJ6JZymB4bWO37FZtlgp47OJClNi NuJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682618043; x=1685210043; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kTwA5Igpbrlnqx2MFioiqClnnk3fWCd7F6gKiXvsizg=; b=ZJ2Tl9cGEQRnwhb5ls7iqrpI8mGx4ikXjs1fH9YI3reiq6+rcRJF2lYK6zW7YOdT+i 3yPK2FCzmYh/LRCwkg+558fcTGPHZewC838/okmYDIEKJCWlbg4sX6UJuNCIyuToYOZ5 eD3VOcrB8kJJYhbRckPKRG29L+K2ct49r8EUtWxXlzR0cE1tkgIZDbigtbciTURBNq64 QdK62SlkL1XqjX3cnpUdIcQ1o+2OWEHztOS02rtD1arSNUE/JZwVz9xSVQlRssLNmKLe dZ9DyQKUD4F0ZPwU+CtDkRB6f2xsQtJ0SYfa52s2gKd4jLyelnvaS5CtH+qAjmPAO95z eimA== X-Gm-Message-State: AC+VfDyEYoMGvDUazRyXI48dD9xmtKtS3xpbs7ZOAaSs2oLQdpYvJhn+ grZCZNuBQWs44EAdUdl4ReU= X-Google-Smtp-Source: ACHHUZ6LNNj8gqJAFOABkk08xjTsf/iTgKG8pNsMVfNLhyxs19frA15VFo4R4M5e8URgVw6J5vEgMw== X-Received: by 2002:a17:90a:cb81:b0:249:7ad3:e843 with SMTP id a1-20020a17090acb8100b002497ad3e843mr3282208pju.16.1682618043189; Thu, 27 Apr 2023 10:54:03 -0700 (PDT) Received: from localhost ([2a00:79e1:abd:4a00:61b:48ed:72ab:435b]) by smtp.gmail.com with ESMTPSA id ls17-20020a17090b351100b0023a9564763bsm13396089pjb.29.2023.04.27.10.54.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Apr 2023 10:54:02 -0700 (PDT) From: Rob Clark To: dri-devel@lists.freedesktop.org Cc: freedreno@lists.freedesktop.org, Daniel Vetter , Tvrtko Ursulin , Boris Brezillon , Christopher Healy , Emil Velikov , =?UTF-8?q?Christian=20K=C3=B6nig?= , Rob Clark , Alex Deucher , "Pan, Xinhui" , David Airlie , Mario Limonciello , Hawking Zhang , Lijo Lazar , YiPeng Chai , Guchun Chen , =?UTF-8?q?Michel=20D=C3=A4nzer?= , Shashank Sharma , Tvrtko Ursulin , Arunpravin Paneer Selvam , amd-gfx@lists.freedesktop.org (open list:RADEON and AMDGPU DRM DRIVERS), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v2 4/9] drm/amdgpu: Switch to fdinfo helper Date: Thu, 27 Apr 2023 10:53:28 -0700 Message-Id: <20230427175340.1280952-5-robdclark@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230427175340.1280952-1-robdclark@gmail.com> References: <20230427175340.1280952-1-robdclark@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Rob Clark Signed-off-by: Rob Clark Reviewed-by: Christian K=C3=B6nig --- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 3 ++- drivers/gpu/drm/amd/amdgpu/amdgpu_fdinfo.c | 16 ++++++---------- drivers/gpu/drm/amd/amdgpu/amdgpu_fdinfo.h | 2 +- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/= amdgpu/amdgpu_drv.c index f5ffca24def4..6c0e0c614b94 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c @@ -2752,7 +2752,7 @@ static const struct file_operations amdgpu_driver_kms= _fops =3D { .compat_ioctl =3D amdgpu_kms_compat_ioctl, #endif #ifdef CONFIG_PROC_FS - .show_fdinfo =3D amdgpu_show_fdinfo + .show_fdinfo =3D drm_show_fdinfo, #endif }; =20 @@ -2807,6 +2807,7 @@ static const struct drm_driver amdgpu_kms_driver =3D { .dumb_map_offset =3D amdgpu_mode_dumb_mmap, .fops =3D &amdgpu_driver_kms_fops, .release =3D &amdgpu_driver_release_kms, + .show_fdinfo =3D amdgpu_show_fdinfo, =20 .prime_handle_to_fd =3D drm_gem_prime_handle_to_fd, .prime_fd_to_handle =3D drm_gem_prime_fd_to_handle, diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_fdinfo.c b/drivers/gpu/drm/a= md/amdgpu/amdgpu_fdinfo.c index 99a7855ab1bc..c2fdd5e448d1 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_fdinfo.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_fdinfo.c @@ -53,9 +53,8 @@ static const char *amdgpu_ip_name[AMDGPU_HW_IP_NUM] =3D { [AMDGPU_HW_IP_VCN_JPEG] =3D "jpeg", }; =20 -void amdgpu_show_fdinfo(struct seq_file *m, struct file *f) +void amdgpu_show_fdinfo(struct drm_printer *p, struct drm_file *file) { - struct drm_file *file =3D f->private_data; struct amdgpu_device *adev =3D drm_to_adev(file->minor->dev); struct amdgpu_fpriv *fpriv =3D file->driver_priv; struct amdgpu_vm *vm =3D &fpriv->vm; @@ -86,18 +85,15 @@ void amdgpu_show_fdinfo(struct seq_file *m, struct file= *f) * ****************************************************************** */ =20 - seq_printf(m, "pasid:\t%u\n", fpriv->vm.pasid); - seq_printf(m, "drm-driver:\t%s\n", file->minor->dev->driver->name); - seq_printf(m, "drm-pdev:\t%04x:%02x:%02x.%d\n", domain, bus, dev, fn); - seq_printf(m, "drm-client-id:\t%Lu\n", vm->immediate.fence_context); - seq_printf(m, "drm-memory-vram:\t%llu KiB\n", vram_mem/1024UL); - seq_printf(m, "drm-memory-gtt: \t%llu KiB\n", gtt_mem/1024UL); - seq_printf(m, "drm-memory-cpu: \t%llu KiB\n", cpu_mem/1024UL); + drm_printf(p, "pasid:\t%u\n", fpriv->vm.pasid); + drm_printf(p, "drm-memory-vram:\t%llu KiB\n", vram_mem/1024UL); + drm_printf(p, "drm-memory-gtt: \t%llu KiB\n", gtt_mem/1024UL); + drm_printf(p, "drm-memory-cpu: \t%llu KiB\n", cpu_mem/1024UL); for (hw_ip =3D 0; hw_ip < AMDGPU_HW_IP_NUM; ++hw_ip) { if (!usage[hw_ip]) continue; =20 - seq_printf(m, "drm-engine-%s:\t%Ld ns\n", amdgpu_ip_name[hw_ip], + drm_printf(p, "drm-engine-%s:\t%Ld ns\n", amdgpu_ip_name[hw_ip], ktime_to_ns(usage[hw_ip])); } } diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_fdinfo.h b/drivers/gpu/drm/a= md/amdgpu/amdgpu_fdinfo.h index e86834bfea1d..0398f5a159ef 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_fdinfo.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_fdinfo.h @@ -37,6 +37,6 @@ #include "amdgpu_ids.h" =20 uint32_t amdgpu_get_ip_count(struct amdgpu_device *adev, int id); -void amdgpu_show_fdinfo(struct seq_file *m, struct file *f); +void amdgpu_show_fdinfo(struct drm_printer *p, struct drm_file *file); =20 #endif --=20 2.39.2 From nobody Sat Feb 7 18:26:18 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E43BBC77B73 for ; Thu, 27 Apr 2023 17:54:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244453AbjD0Ry3 (ORCPT ); Thu, 27 Apr 2023 13:54:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244509AbjD0RyW (ORCPT ); Thu, 27 Apr 2023 13:54:22 -0400 Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E4CE49E1; Thu, 27 Apr 2023 10:54:06 -0700 (PDT) Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-63b5c830d5eso6923911b3a.2; Thu, 27 Apr 2023 10:54:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682618045; x=1685210045; 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; bh=p73C15js764dzQJEgbWBx+7QNMsWovIoyzGPpjczgNY=; b=kCxBda4dX0v9+KBOw3q745gxPj6sZv6R2ayxpdDPKEgoo5SEdRuB63GjusADcmhym3 dwk+FD/2zxoUdKFhPkBpIioo3kSpRwziJ8SHPBqIkUsAp/Aww4Km6iE/ZF+/qKjwEIcP BZopZG6XHUscKCfj2SOJU9rO73+xOjUa4shfwY6YA36QbWcERYDtEkxMvnTm4QQ0RX+y 9z8HZFFAewmbZFIFYwKq/VpgRdjxEMdN4xNBZ64SNcxr42LqMzR2uzrhw6R3hk9tqXu8 b2ym0VtpRaZVr8+BhPc72xSXoGQCq0NUfMo+A9mfF0wUD8z3XpW1OQg5HcbJTgvnSuuk hBHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682618045; x=1685210045; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=p73C15js764dzQJEgbWBx+7QNMsWovIoyzGPpjczgNY=; b=Q6ZfWTBv+Wj7Bo1BCwA2bm7gUPC6Cai+oQ08g9nn1smA9U3GE9+Z3pFAsJxgQvMbgW NmMh1BKl7wY9G3eUmXQJyzy3lNTCk9TfRIGn1W2Z6ooOQOWeKl/MPAltKOGwVhwqBGG1 WhQT1p7E/pQOq8LGjwsUD6OxaE6OLuk6poftnqrJrJzakCQwgEBqO/dAXRwRiXiIPVCY Bt/5bagL/VXAtZHp879KXqt2tUZXbaADeVugVjhJc3Kx6ypxxiwVacBVPrT495SFKQY1 Fi4C0bHU1cZAqlLLmXS59RSkdbTOwW/iWcVk3mRWe4rzCc4o4I7rKiT9TqdctKsMWHMd sYxw== X-Gm-Message-State: AC+VfDwXkbmXZRnkvfoyFfpByymtTrr8edbrdu+26tKNXU6q0kyWB7Tk JGXwIHcHredoOldHlGm0X5g= X-Google-Smtp-Source: ACHHUZ53SdbC+GkAvFXw8H5V9YJK9MOfeVPqmP/O5m4zpTSne+FvC+0QNJsFZFXd++qOvmCi+EqtEw== X-Received: by 2002:a05:6a00:b52:b0:634:4dea:81c6 with SMTP id p18-20020a056a000b5200b006344dea81c6mr4015210pfo.0.1682618045198; Thu, 27 Apr 2023 10:54:05 -0700 (PDT) Received: from localhost ([2a00:79e1:abd:4a00:61b:48ed:72ab:435b]) by smtp.gmail.com with ESMTPSA id o76-20020a62cd4f000000b0063d6666ee4csm13514749pfg.34.2023.04.27.10.54.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Apr 2023 10:54:04 -0700 (PDT) From: Rob Clark To: dri-devel@lists.freedesktop.org Cc: freedreno@lists.freedesktop.org, Daniel Vetter , Tvrtko Ursulin , Boris Brezillon , Christopher Healy , Emil Velikov , =?UTF-8?q?Christian=20K=C3=B6nig?= , Rob Clark , Daniel Vetter , David Airlie , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Jonathan Corbet , linux-doc@vger.kernel.org (open list:DOCUMENTATION), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v2 5/9] drm: Add fdinfo memory stats Date: Thu, 27 Apr 2023 10:53:29 -0700 Message-Id: <20230427175340.1280952-6-robdclark@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230427175340.1280952-1-robdclark@gmail.com> References: <20230427175340.1280952-1-robdclark@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Rob Clark Add support to dump GEM stats to fdinfo. v2: Fix typos, change size units to match docs, use div_u64 v3: Do it in core v4: more kerneldoc Signed-off-by: Rob Clark Reviewed-by: Emil Velikov Reviewed-by: Daniel Vetter --- Documentation/gpu/drm-usage-stats.rst | 54 +++++++++++---- drivers/gpu/drm/drm_file.c | 99 ++++++++++++++++++++++++++- include/drm/drm_file.h | 19 +++++ include/drm/drm_gem.h | 30 ++++++++ 4 files changed, 189 insertions(+), 13 deletions(-) diff --git a/Documentation/gpu/drm-usage-stats.rst b/Documentation/gpu/drm-= usage-stats.rst index 552195fb1ea3..bfc14150452c 100644 --- a/Documentation/gpu/drm-usage-stats.rst +++ b/Documentation/gpu/drm-usage-stats.rst @@ -52,6 +52,9 @@ String shall contain the name this driver registered as v= ia the respective Optional fully standardised keys -------------------------------- =20 +Identification +^^^^^^^^^^^^^^ + - drm-pdev: =20 For PCI devices this should contain the PCI slot address of the device in @@ -69,6 +72,9 @@ scope of each device, in which case `drm-pdev` shall be p= resent as well. Userspace should make sure to not double account any usage statistics by u= sing the above described criteria in order to associate data to individual clie= nts. =20 +Utilization +^^^^^^^^^^^ + - drm-engine-: ns =20 GPUs usually contain multiple execution engines. Each shall be given a sta= ble @@ -93,18 +99,6 @@ exported engine corresponds to a group of identical hard= ware engines. In the absence of this tag parser shall assume capacity of one. Zero capac= ity is not allowed. =20 -- drm-memory-: [KiB|MiB] - -Each possible memory type which can be used to store buffer objects by the -GPU in question shall be given a stable and unique name to be returned as = the -string here. - -Value shall reflect the amount of storage currently consumed by the buffer -object belong to this client, in the respective memory region. - -Default unit shall be bytes with optional unit specifiers of 'KiB' or 'MiB' -indicating kibi- or mebi-bytes. - - drm-cycles-: =20 Engine identifier string must be the same as the one specified in the @@ -126,6 +120,42 @@ percentage utilization of the engine, whereas drm-engi= ne- only reflects time active without considering what frequency the engine is operating as a percentage of it's maximum frequency. =20 +Memory +^^^^^^ + +- drm-memory-: [KiB|MiB] + +Each possible memory type which can be used to store buffer objects by the +GPU in question shall be given a stable and unique name to be returned as = the +string here. The name "memory" is reserved to refer to normal system memo= ry. + +Value shall reflect the amount of storage currently consumed by the buffer +object belong to this client, in the respective memory region. + +Default unit shall be bytes with optional unit specifiers of 'KiB' or 'MiB' +indicating kibi- or mebi-bytes. + +- drm-shared-: [KiB|MiB] + +The total size of buffers that are shared with another file (ie. have more +than a single handle). + +- drm-private-: [KiB|MiB] + +The total size of buffers that are not shared with another file. + +- drm-resident-: [KiB|MiB] + +The total size of buffers that are resident in system memory. + +- drm-purgeable-: [KiB|MiB] + +The total size of buffers that are purgeable. + +- drm-active-: [KiB|MiB] + +The total size of buffers that are active on one or more rings. + Implementation Details =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 diff --git a/drivers/gpu/drm/drm_file.c b/drivers/gpu/drm/drm_file.c index 6d5bdd684ae2..9321eb0bf020 100644 --- a/drivers/gpu/drm/drm_file.c +++ b/drivers/gpu/drm/drm_file.c @@ -42,6 +42,7 @@ #include #include #include +#include #include =20 #include "drm_crtc_internal.h" @@ -871,9 +872,105 @@ void drm_send_event(struct drm_device *dev, struct dr= m_pending_event *e) } EXPORT_SYMBOL(drm_send_event); =20 +static void print_size(struct drm_printer *p, const char *stat, + const char *region, size_t sz) +{ + const char *units[] =3D {"", " KiB", " MiB"}; + unsigned u; + + for (u =3D 0; u < ARRAY_SIZE(units) - 1; u++) { + if (sz < SZ_1K) + break; + sz =3D div_u64(sz, SZ_1K); + } + + drm_printf(p, "drm-%s-%s:\t%zu%s\n", stat, region, sz, units[u]); +} + +/** + * drm_print_memory_stats - A helper to print memory stats + * @p: The printer to print output to + * @stats: The collected memory stats + * @supported_status: Bitmask of optional stats which are available + * @region: The memory region + * + */ +void drm_print_memory_stats(struct drm_printer *p, + const struct drm_memory_stats *stats, + 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); + + if (supported_status & DRM_GEM_OBJECT_RESIDENT) + print_size(p, "resident", region, stats->resident); + + if (supported_status & DRM_GEM_OBJECT_PURGEABLE) + print_size(p, "purgeable", region, stats->purgeable); +} +EXPORT_SYMBOL(drm_print_memory_stats); + +/** + * drm_show_memory_stats - Helper to collect and show standard fdinfo memo= ry stats + * @p: the printer to print output to + * @file: the DRM file + * + * Helper to iterate over GEM objects with a handle allocated in the speci= fied + * file. + */ +void drm_show_memory_stats(struct drm_printer *p, struct drm_file *file) +{ + struct drm_gem_object *obj; + struct drm_memory_stats status =3D {}; + enum drm_gem_object_status supported_status; + int id; + + spin_lock(&file->table_lock); + idr_for_each_entry (&file->object_idr, obj, id) { + enum drm_gem_object_status s =3D 0; + + if (obj->funcs && obj->funcs->status) { + s =3D obj->funcs->status(obj); + supported_status =3D DRM_GEM_OBJECT_RESIDENT | + DRM_GEM_OBJECT_PURGEABLE; + } + + if (obj->handle_count > 1) { + status.shared +=3D obj->size; + } else { + status.private +=3D obj->size; + } + + if (s & DRM_GEM_OBJECT_RESIDENT) { + status.resident +=3D obj->size; + } else { + /* If already purged or not yet backed by pages, don't + * count it as purgeable: + */ + s &=3D ~DRM_GEM_OBJECT_PURGEABLE; + } + + if (!dma_resv_test_signaled(obj->resv, dma_resv_usage_rw(true))) { + status.active +=3D obj->size; + + /* If still active, don't count as purgeable: */ + s &=3D ~DRM_GEM_OBJECT_PURGEABLE; + } + + if (s & DRM_GEM_OBJECT_PURGEABLE) + status.purgeable +=3D obj->size; + } + spin_unlock(&file->table_lock); + + drm_print_memory_stats(p, &status, supported_status, "memory"); +} +EXPORT_SYMBOL(drm_show_memory_stats); + /** * drm_show_fdinfo - helper for drm file fops - * @seq_file: output stream + * @m: output stream * @f: the device file instance * * Helper to implement fdinfo, for userspace to query usage stats, etc, of= a diff --git a/include/drm/drm_file.h b/include/drm/drm_file.h index 6de6d0e9c634..1339e925af52 100644 --- a/include/drm/drm_file.h +++ b/include/drm/drm_file.h @@ -41,6 +41,7 @@ struct dma_fence; struct drm_file; struct drm_device; +struct drm_printer; struct device; struct file; =20 @@ -440,6 +441,24 @@ void drm_send_event(struct drm_device *dev, struct drm= _pending_event *e); void drm_send_event_timestamp_locked(struct drm_device *dev, struct drm_pending_event *e, ktime_t timestamp); + + +struct drm_memory_stats { + size_t shared; + size_t private; + size_t resident; + size_t purgeable; + size_t active; +}; + +enum drm_gem_object_status; + +void drm_print_memory_stats(struct drm_printer *p, + const struct drm_memory_stats *stats, + enum drm_gem_object_status supported_status, + const char *region); + +void drm_show_memory_stats(struct drm_printer *p, struct drm_file *file); void drm_show_fdinfo(struct seq_file *m, struct file *f); =20 struct file *mock_drm_getfile(struct drm_minor *minor, unsigned int flags); diff --git a/include/drm/drm_gem.h b/include/drm/drm_gem.h index 189fd618ca65..9ebd2820ad1f 100644 --- a/include/drm/drm_gem.h +++ b/include/drm/drm_gem.h @@ -42,6 +42,25 @@ struct iosys_map; struct drm_gem_object; =20 +/** + * enum drm_gem_object_status - bitmask of object state for fdinfo reporti= ng + * @DRM_GEM_OBJECT_RESIDENT: object is resident in memory (ie. not unpinne= d) + * @DRM_GEM_OBJECT_PURGEABLE: object marked as purgeable by userspace + * + * Bitmask of status used for fdinfo memory stats, see &drm_gem_object_fun= cs.status + * and drm_show_fdinfo(). Note that an object can DRM_GEM_OBJECT_PURGEABL= E if + * it still active or not resident, in which case drm_show_fdinfo() will n= ot + * account for it as purgeable. So drivers do not need to check if the bu= ffer + * is idle and resident to return this bit. (Ie. userspace can mark a buf= fer + * as purgeable even while it is still busy on the GPU.. it does not _actu= ally_ + * become puregeable until it becomes idle. The status gem object func do= es + * not need to consider this.) + */ +enum drm_gem_object_status { + DRM_GEM_OBJECT_RESIDENT =3D BIT(0), + DRM_GEM_OBJECT_PURGEABLE =3D BIT(1), +}; + /** * struct drm_gem_object_funcs - GEM object functions */ @@ -174,6 +193,17 @@ struct drm_gem_object_funcs { */ int (*evict)(struct drm_gem_object *obj); =20 + /** + * @status: + * + * The optional status callback can return additional object state + * which determines which stats the object is counted against. The + * callback is called under table_lock. Racing against object status + * change is "harmless", and the callback can expect to not race + * against object destruction. + */ + enum drm_gem_object_status (*status)(struct drm_gem_object *obj); + /** * @vm_ops: * --=20 2.39.2 From nobody Sat Feb 7 18:26:18 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A2445C77B61 for ; Thu, 27 Apr 2023 17:54:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244509AbjD0Ryd (ORCPT ); Thu, 27 Apr 2023 13:54:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244353AbjD0RyX (ORCPT ); Thu, 27 Apr 2023 13:54:23 -0400 Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A79033A8D; Thu, 27 Apr 2023 10:54:07 -0700 (PDT) Received: by mail-pg1-x534.google.com with SMTP id 41be03b00d2f7-517bdc9e81dso5194682a12.1; Thu, 27 Apr 2023 10:54:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682618047; x=1685210047; 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; bh=tk36LHgT7Zd3DnVnkUrHTABb/+wFJaIJC2KssqoMtiA=; b=eLrWdp6G4Kchqv4Qdaauo7bSYHMHL3SgbOabiyKhti17zyGH3h7Fn5HV8Rjz/7qIUT u7lM4YrdTNZ9IYLVHRBiOuF2MFueaj6VxzcGfAm1y2HXpLywUb0Yr5/HwDnmmnahA8yY gkPqgz/HtXC50zqptgdfI/DyIlOj/WpKZssQISqmRNJ3dL8peof2/aLv2sMbKyyrTpiu JO3IMj1mhKLtQshAka98lVJX7Od8yfJiwNScAxYZ26Fbs4k8k6mOWaBHNe+P5BqTxET6 gE40PvRGCjMy/SpZLKboyq710VewPdBfOVhTqamRYrUMYAC6Ni6wHczYFR24EHIFxaXE pmxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682618047; x=1685210047; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tk36LHgT7Zd3DnVnkUrHTABb/+wFJaIJC2KssqoMtiA=; b=FP7BzbowclOj8d8hV2C2/Mb9OV7+9pGLX2EXkD/KGUywHgcD7tnM/J5G+W2yqRucJs J3AIpAeIPXlBb7tNv15Ur7Gp5OaPkRmL/WUC5467wdhAM0LLaJB53ZMy/DMDwFuCwFXW RqgcA4pjgwBSq2/85oD+DyS8z4VOovEv99VVt/G3GJawkysLef6FdXo7OWJm3DD30MwO 06awaCzyUqwNTL91K7RuyqhOMT5ABQ6Dip767qJK3SUxwUhsb0QiMog++4eCcqAf3uIm gst61E+LCniYAm+vQZOm1JiRgLRcNpBht9Bt6n3df0te1pJtsifMrHg02dfZGsubXxWO GoGQ== X-Gm-Message-State: AC+VfDxvKJ9YOCXrD9XBs19ruN4S8wa1OKBK33FqC/O22ZiHYvSNMra/ f46nZWXpjhbokPTI0xvCdPo= X-Google-Smtp-Source: ACHHUZ60SORnik/eSAifUwaYbsYC/Ea5qlWfZS6XAVfSHEgeUf/F/4TBA83gnvjAxC1qtMElfaHudw== X-Received: by 2002:a17:90b:4f4b:b0:23d:31c3:c98d with SMTP id pj11-20020a17090b4f4b00b0023d31c3c98dmr2686481pjb.15.1682618046972; Thu, 27 Apr 2023 10:54:06 -0700 (PDT) Received: from localhost ([2a00:79e1:abd:4a00:61b:48ed:72ab:435b]) by smtp.gmail.com with ESMTPSA id r78-20020a632b51000000b00520f316ebe3sm11614239pgr.62.2023.04.27.10.54.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Apr 2023 10:54:06 -0700 (PDT) From: Rob Clark To: dri-devel@lists.freedesktop.org Cc: freedreno@lists.freedesktop.org, Daniel Vetter , Tvrtko Ursulin , Boris Brezillon , Christopher Healy , Emil Velikov , =?UTF-8?q?Christian=20K=C3=B6nig?= , Rob Clark , Rob Clark , Abhinav Kumar , Dmitry Baryshkov , Sean Paul , David Airlie , linux-arm-msm@vger.kernel.org (open list:DRM DRIVER FOR MSM ADRENO GPU), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v2 6/9] drm/msm: Add memory stats to fdinfo Date: Thu, 27 Apr 2023 10:53:30 -0700 Message-Id: <20230427175340.1280952-7-robdclark@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230427175340.1280952-1-robdclark@gmail.com> References: <20230427175340.1280952-1-robdclark@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Rob Clark Use the new helper to export stats about memory usage. v2: Drop unintended hunk v3: Rebase Signed-off-by: Rob Clark Reviewed-by: Emil Velikov --- drivers/gpu/drm/msm/msm_drv.c | 2 ++ drivers/gpu/drm/msm/msm_gem.c | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/drivers/gpu/drm/msm/msm_drv.c b/drivers/gpu/drm/msm/msm_drv.c index 1e941aa77609..81a1371c0307 100644 --- a/drivers/gpu/drm/msm/msm_drv.c +++ b/drivers/gpu/drm/msm/msm_drv.c @@ -1052,6 +1052,8 @@ static void msm_show_fdinfo(struct drm_printer *p, st= ruct drm_file *file) return; =20 msm_gpu_show_fdinfo(priv->gpu, file->driver_priv, p); + + drm_show_memory_stats(p, file); } =20 static const struct file_operations fops =3D { diff --git a/drivers/gpu/drm/msm/msm_gem.c b/drivers/gpu/drm/msm/msm_gem.c index cd39b9d8abdb..20cfd86d2b32 100644 --- a/drivers/gpu/drm/msm/msm_gem.c +++ b/drivers/gpu/drm/msm/msm_gem.c @@ -1090,6 +1090,20 @@ int msm_gem_new_handle(struct drm_device *dev, struc= t drm_file *file, return ret; } =20 +static enum drm_gem_object_status msm_gem_status(struct drm_gem_object *ob= j) +{ + struct msm_gem_object *msm_obj =3D to_msm_bo(obj); + enum drm_gem_object_status status =3D 0; + + if (msm_obj->pages) + status |=3D DRM_GEM_OBJECT_RESIDENT; + + if (msm_obj->madv =3D=3D MSM_MADV_DONTNEED) + status |=3D DRM_GEM_OBJECT_PURGEABLE; + + return status; +} + static const struct vm_operations_struct vm_ops =3D { .fault =3D msm_gem_fault, .open =3D drm_gem_vm_open, @@ -1104,6 +1118,7 @@ static const struct drm_gem_object_funcs msm_gem_obje= ct_funcs =3D { .vmap =3D msm_gem_prime_vmap, .vunmap =3D msm_gem_prime_vunmap, .mmap =3D msm_gem_object_mmap, + .status =3D msm_gem_status, .vm_ops =3D &vm_ops, }; =20 --=20 2.39.2 From nobody Sat Feb 7 18:26:18 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6C45DC77B61 for ; Thu, 27 Apr 2023 17:54:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244629AbjD0Ryo (ORCPT ); Thu, 27 Apr 2023 13:54:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34380 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244474AbjD0RyY (ORCPT ); Thu, 27 Apr 2023 13:54:24 -0400 Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9436355BB; Thu, 27 Apr 2023 10:54:09 -0700 (PDT) Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-63b5c4c769aso10949306b3a.3; Thu, 27 Apr 2023 10:54:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682618049; x=1685210049; 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; bh=5X8ws8C9Uya1bH1qvM3ByEZiUSzSNNSQCvKC0+MH6tc=; b=FJmULW49+UMYCVzDkpdb7BszKylFpQ8Go8QKjSNPi9p1Epfy9Abj+ptulI1LZsNXYO Drur1lnhr+2tDX7fQ5TKZA6bWEIgZuH6kNGI3k3r76j0lFiQ2B3/ufbtNACKCxcYD3PD 2oiXG504lUTQJI8Ol1FBvV0twNshzJFLFJNj5v2Y/ze2zM7gaXKXVrQkJDZKFLRqg1HA aQ8ArDm80oS8vDG+z7RNtaF5HamxWhVFBKj8cE/bG2KcuxlKFD0q6pBs2kxDH/FJBDIS 9mMTob0B48PC8gzJcc/I4A2EMUcHUJj0GYAPsFe5i6yUQQGY7w7y8ITx7QFUaSsqOMRy rQlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682618049; x=1685210049; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5X8ws8C9Uya1bH1qvM3ByEZiUSzSNNSQCvKC0+MH6tc=; b=kpcvvfcxWg/RMimHMjzLMb1S3yv11WdC24rp034vO/oRDl8JWOcV7sJqznZ5K0VBv6 KqksEVSFVbFJcJgRAeKxqIA1/WEtHlCOLC7NMPIP1ZddBoNkJPyCV1jnoObUy7NPfnMH PBOJzQstPyJ5LYDBRIbAAsU1/GzGPOFULF8aWrfAibnvGpQ/OFa/s2XhgseCMUOAH3zE AXPJCuFfu004wkl9OiUkQcvpxX8ehIRSzrm+R/emLFnRTvz3XXTxvKCf84FNAKjVvV2d 7MgtR/09Dq9YMAzVqTHl7euTwRodcTJoJQE9TKmuXumPr8x/mWK0H0zzZ8ksEZusXP7d Xs9Q== X-Gm-Message-State: AC+VfDwMVbY/E3mZ8ezO4hEZkbrulbTd5LfvkrgJSg7sK5Oq48WEARJm zADJkbCkwqsSvwfD/QIvnI5Jv6AEUbk= X-Google-Smtp-Source: ACHHUZ4MKuwKrDINV0TTla8lJWfaf+1NN+A7s4Fg1UjvkclS6fQTdlIEtFpva4hScU7H2HtK4HrNrQ== X-Received: by 2002:a05:6a00:807:b0:63f:244d:cd07 with SMTP id m7-20020a056a00080700b0063f244dcd07mr3256742pfk.31.1682618048750; Thu, 27 Apr 2023 10:54:08 -0700 (PDT) Received: from localhost ([2a00:79e1:abd:4a00:61b:48ed:72ab:435b]) by smtp.gmail.com with ESMTPSA id s9-20020a63e809000000b00476d1385265sm11680207pgh.25.2023.04.27.10.54.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Apr 2023 10:54:08 -0700 (PDT) From: Rob Clark To: dri-devel@lists.freedesktop.org Cc: freedreno@lists.freedesktop.org, Daniel Vetter , Tvrtko Ursulin , Boris Brezillon , Christopher Healy , Emil Velikov , =?UTF-8?q?Christian=20K=C3=B6nig?= , Rob Clark , Tvrtko Ursulin , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Jonathan Corbet , linux-doc@vger.kernel.org (open list:DOCUMENTATION), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v2 7/9] drm/doc: Relax fdinfo string constraints Date: Thu, 27 Apr 2023 10:53:31 -0700 Message-Id: <20230427175340.1280952-8-robdclark@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230427175340.1280952-1-robdclark@gmail.com> References: <20230427175340.1280952-1-robdclark@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Rob Clark The restriction about no whitespace, etc, really only applies to the usage of strings in keys. Values can contain anything (other than newline). Signed-off-by: Rob Clark Acked-by: Tvrtko Ursulin --- Documentation/gpu/drm-usage-stats.rst | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/Documentation/gpu/drm-usage-stats.rst b/Documentation/gpu/drm-= usage-stats.rst index bfc14150452c..58dc0d3f8c58 100644 --- a/Documentation/gpu/drm-usage-stats.rst +++ b/Documentation/gpu/drm-usage-stats.rst @@ -24,7 +24,7 @@ File format specification - All keys shall be prefixed with `drm-`. - Whitespace between the delimiter and first non-whitespace character shal= l be ignored when parsing. -- Neither keys or values are allowed to contain whitespace characters. +- Keys are not allowed to contain whitespace characters. - Numerical key value pairs can end with optional unit string. - Data type of the value is fixed as defined in the specification. =20 @@ -39,12 +39,13 @@ Data types ---------- =20 - - Unsigned integer without defining the maximum value. -- - String excluding any above defined reserved characters or whites= pace. +- - String excluding any above defined reserved characters or whi= tespace. +- - String. =20 Mandatory fully standardised keys --------------------------------- =20 -- drm-driver: +- drm-driver: =20 String shall contain the name this driver registered as via the respective `struct drm_driver` data structure. @@ -75,10 +76,10 @@ the above described criteria in order to associate data= to individual clients. Utilization ^^^^^^^^^^^ =20 -- drm-engine-: ns +- drm-engine-: ns =20 GPUs usually contain multiple execution engines. Each shall be given a sta= ble -and unique name (str), with possible values documented in the driver speci= fic +and unique name (keystr), with possible values documented in the driver sp= ecific documentation. =20 Value shall be in specified time units which the respective GPU engine spe= nt @@ -90,19 +91,19 @@ larger value within a reasonable period. Upon observing= a value lower than what was previously read, userspace is expected to stay with that larger previo= us value until a monotonic update is seen. =20 -- drm-engine-capacity-: +- drm-engine-capacity-: =20 Engine identifier string must be the same as the one specified in the -drm-engine- tag and shall contain a greater than zero number in case = the +drm-engine- tag and shall contain a greater than zero number in ca= se the exported engine corresponds to a group of identical hardware engines. =20 In the absence of this tag parser shall assume capacity of one. Zero capac= ity is not allowed. =20 -- drm-cycles-: +- drm-cycles-: =20 Engine identifier string must be the same as the one specified in the -drm-engine- tag and shall contain the number of busy cycles for the g= iven +drm-engine- tag and shall contain the number of busy cycles for th= e given engine. =20 Values are not required to be constantly monotonic if it makes the driver @@ -111,12 +112,12 @@ larger value within a reasonable period. Upon observi= ng a value lower than what was previously read, userspace is expected to stay with that larger previo= us value until a monotonic update is seen. =20 -- drm-maxfreq-: [Hz|MHz|KHz] +- drm-maxfreq-: [Hz|MHz|KHz] =20 Engine identifier string must be the same as the one specified in the -drm-engine- tag and shall contain the maximum frequency for the given -engine. Taken together with drm-cycles-, this can be used to calcula= te -percentage utilization of the engine, whereas drm-engine- only reflec= ts +drm-engine- tag and shall contain the maximum frequency for the gi= ven +engine. Taken together with drm-cycles-, this can be used to calc= ulate +percentage utilization of the engine, whereas drm-engine- only ref= lects time active without considering what frequency the engine is operating as a percentage of it's maximum frequency. =20 --=20 2.39.2 From nobody Sat Feb 7 18:26:18 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9F74AC77B73 for ; Thu, 27 Apr 2023 17:55:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244394AbjD0RzA (ORCPT ); Thu, 27 Apr 2023 13:55:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244535AbjD0RyZ (ORCPT ); Thu, 27 Apr 2023 13:54:25 -0400 Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A41A3C15; Thu, 27 Apr 2023 10:54:11 -0700 (PDT) Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-64115eef620so6797419b3a.1; Thu, 27 Apr 2023 10:54:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682618051; x=1685210051; 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; bh=sGLJmibW87WAJcS5t0uIh72jCVPBIb7Gj0WXUx1P9zU=; b=QMXQRPIdXA5q5Km0eEBU7rKyuFO/cgMrtoDCMJdyNqAiJII2NpWeJLh5tHe70Cy232 Sm5bFKWRn1oSSzIdYYglEqg8J6RUhcSkcWnMH7d4qgcvGCmFinBCuh81eI4k4yWHVpvx ZGSfIBbB+9WYYIJU6QL3JOedPPhjgrhrXsvSGBPHyj1zrMv0q578RG/AT6Ue8xSs2fL3 VqFTs5aUbk2lfTToiCebxdTsxyY8QfQ8af5msEFx2/6VxM7sz1Mj6jn3ZRQ6NcpfhnBz smFVLkXfhebsJulsoQqEEQZQriQbsmux38e2ELM+/aEBKnk7Y2f+FUt5q8Q7P6pfwUeA 1fdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682618051; x=1685210051; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sGLJmibW87WAJcS5t0uIh72jCVPBIb7Gj0WXUx1P9zU=; b=cBhd0hWS4Ys++9yltsjwGNJMNB03d1QShIL5r+kwcpuVyECHY7/Jl/WWkcWoXnejoK djev7l/IunKyQK6Dy0Es9ZWI9Qc/POP0nTbA5gdO9WYcZqPK+I4ZcrETDGq/zmoonqon l//UNBv1M+LfLXVoW3ubh26ck0ENhAzyEgvbLqkzSbQWHAKGoCBSd5yfnlKWXWgIUQMD 0k1OQ0a1H3eYyRmVaLnnhmZj9NZdP05xgs5kyK3ZFnSPF17q3NokT78QLtFwGckBxnaD tn9bgYfGRIcTCawR6G57s+R6unKo02+PX2LrQyPNB97froZ3kL3yBfAssbtjRpGMtOrS LykQ== X-Gm-Message-State: AC+VfDxs1g5B3LSbxALWkO57THUhN9NKfsbsCw5uEL5uRmH+QfgKWD7E cPl7/4wtIRrII8CHfTxqhFA= X-Google-Smtp-Source: ACHHUZ6Nn15Zn+c1Wo6Qo1HTjwDdKmVdH9HihAreo97OXBbuOLvs3ki9YVei3t6pb2Epm77vQyXY1g== X-Received: by 2002:a05:6a20:918f:b0:f0:3fc4:744f with SMTP id v15-20020a056a20918f00b000f03fc4744fmr3333199pzd.8.1682618050907; Thu, 27 Apr 2023 10:54:10 -0700 (PDT) Received: from localhost ([2a00:79e1:abd:4a00:61b:48ed:72ab:435b]) by smtp.gmail.com with ESMTPSA id y189-20020a62cec6000000b00640defda6d2sm6860749pfg.207.2023.04.27.10.54.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Apr 2023 10:54:10 -0700 (PDT) From: Rob Clark To: dri-devel@lists.freedesktop.org Cc: freedreno@lists.freedesktop.org, Daniel Vetter , Tvrtko Ursulin , Boris Brezillon , Christopher Healy , Emil Velikov , =?UTF-8?q?Christian=20K=C3=B6nig?= , Rob Clark , David Airlie , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Jonathan Corbet , linux-doc@vger.kernel.org (open list:DOCUMENTATION), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v2 8/9] drm/fdinfo: Add comm/cmdline override fields Date: Thu, 27 Apr 2023 10:53:32 -0700 Message-Id: <20230427175340.1280952-9-robdclark@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230427175340.1280952-1-robdclark@gmail.com> References: <20230427175340.1280952-1-robdclark@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Rob Clark These are useful in particular for VM scenarios where the process which has opened to drm device file is just a proxy for the real user in a VM guest. Signed-off-by: Rob Clark Reviewed-by: Tvrtko Ursulin --- Documentation/gpu/drm-usage-stats.rst | 18 ++++++++++++++++++ drivers/gpu/drm/drm_file.c | 15 +++++++++++++++ include/drm/drm_file.h | 19 +++++++++++++++++++ 3 files changed, 52 insertions(+) diff --git a/Documentation/gpu/drm-usage-stats.rst b/Documentation/gpu/drm-= usage-stats.rst index 58dc0d3f8c58..e4877cf8089c 100644 --- a/Documentation/gpu/drm-usage-stats.rst +++ b/Documentation/gpu/drm-usage-stats.rst @@ -73,6 +73,24 @@ scope of each device, in which case `drm-pdev` shall be = present as well. Userspace should make sure to not double account any usage statistics by u= sing the above described criteria in order to associate data to individual clie= nts. =20 +- drm-comm-override: + +Returns the client executable override string. Some drivers support letti= ng +userspace override this in cases where the userspace is simply a "proxy". +Such as is the case with virglrenderer drm native context, where the host +process is just forwarding command submission, etc, from guest userspace. +This allows the proxy to make visible the executable name of the actual +app in the VM guest. + +- drm-cmdline-override: + +Returns the client cmdline override string. Some drivers support letting +userspace override this in cases where the userspace is simply a "proxy". +Such as is the case with virglrenderer drm native context, where the host +process is just forwarding command submission, etc, from guest userspace. +This allows the proxy to make visible the cmdline of the actual app in the +VM guest. + Utilization ^^^^^^^^^^^ =20 diff --git a/drivers/gpu/drm/drm_file.c b/drivers/gpu/drm/drm_file.c index 9321eb0bf020..d7514c313af1 100644 --- a/drivers/gpu/drm/drm_file.c +++ b/drivers/gpu/drm/drm_file.c @@ -178,6 +178,8 @@ struct drm_file *drm_file_alloc(struct drm_minor *minor) spin_lock_init(&file->master_lookup_lock); mutex_init(&file->event_read_lock); =20 + mutex_init(&file->override_lock); + if (drm_core_check_feature(dev, DRIVER_GEM)) drm_gem_open(dev, file); =20 @@ -292,6 +294,8 @@ void drm_file_free(struct drm_file *file) WARN_ON(!list_empty(&file->event_list)); =20 put_pid(file->pid); + kfree(file->override_comm); + kfree(file->override_cmdline); kfree(file); } =20 @@ -995,6 +999,17 @@ void drm_show_fdinfo(struct seq_file *m, struct file *= f) PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn)); } =20 + mutex_lock(&file->override_lock); + if (file->override_comm) { + drm_printf(&p, "drm-comm-override:\t%s\n", + file->override_comm); + } + if (file->override_cmdline) { + drm_printf(&p, "drm-cmdline-override:\t%s\n", + file->override_cmdline); + } + mutex_unlock(&file->override_lock); + if (dev->driver->show_fdinfo) dev->driver->show_fdinfo(&p, file); } diff --git a/include/drm/drm_file.h b/include/drm/drm_file.h index 1339e925af52..604d05fa6f0c 100644 --- a/include/drm/drm_file.h +++ b/include/drm/drm_file.h @@ -370,6 +370,25 @@ struct drm_file { */ struct drm_prime_file_private prime; =20 + /** + * @comm: Overridden task comm + * + * Accessed under override_lock + */ + char *override_comm; + + /** + * @cmdline: Overridden task cmdline + * + * Accessed under override_lock + */ + char *override_cmdline; + + /** + * @override_lock: Serialize access to override_comm and override_cmdline + */ + struct mutex override_lock; + /* private: */ #if IS_ENABLED(CONFIG_DRM_LEGACY) unsigned long lock_count; /* DRI1 legacy lock count */ --=20 2.39.2 From nobody Sat Feb 7 18:26:18 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B2BF7C77B73 for ; Thu, 27 Apr 2023 17:55:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244399AbjD0RzD (ORCPT ); Thu, 27 Apr 2023 13:55:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34344 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244559AbjD0Ry1 (ORCPT ); Thu, 27 Apr 2023 13:54:27 -0400 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD5635FC0; Thu, 27 Apr 2023 10:54:14 -0700 (PDT) Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1a66888cb89so68369745ad.3; Thu, 27 Apr 2023 10:54:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682618054; x=1685210054; 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; bh=3ok26iuO88WTdiTh3yqSvF0njUaJd/G7EVrYrB/tlNM=; b=NGkm71aOJ/s2qjTeR/gaLYWgyuhDv8G+me2tBr6PxbRaq548LAyp+ofSB/dnvdlG4R I0wgCM/25DaIqgEo3jPIP843OCkPqhy0nXXYCOS+CS1MurrPlIwbHuYOk/q+Z88c+IO0 P6wg134IWILVVK6Br15IsyK1zVeHw7oqYdaMNk5qyypE++AIRlcPyHqgxZEQi2AqM6ks ylyb/vau7BR6OElUXcPm0NUbGJsAOUhzbqc3fv7+Ek4GhRxkujAVLcjGcNgB1cgZVi9g CWzq92oioySI+k78Up20FrrLdXQHF1kGfIuEF7/Uo1Vbs43oc8ko4IPQqQhI/FALmL32 leFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682618054; x=1685210054; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3ok26iuO88WTdiTh3yqSvF0njUaJd/G7EVrYrB/tlNM=; b=MrxZ0u9IOzmG8gvvWYHsK0xJIT1nuG2VANwuUzjGn/v9SRaoErmbrNuGzbWbLjS1Rh qJB8FAkpO8swLvsJaduR6xBb+NTjpE32dvc+nnqro07Sl6CyFLbmR40VMJO4zi+dh0ie b5P1UQMXGbeXnPpmknocMefJ+mY9ecP88+eXkY0IeL4wsSFDmtIMKVagdtXZcfGmGfD2 td325jE6Xpbtbx7/63mkJsCgU6ggRIVILF8m0oHGwHtblPq62N4/butlwBk83Wl/aPMB kvra4lfmVY0HbD2OVMMWuuiEkrjDEqQDwi4wrlKw6UWdJUJ6DfK7gy1lAE8bYcXoFojs z7ng== X-Gm-Message-State: AC+VfDxLumcfMEnEG/GgMkNeEAe0eKzvhL8qcx4FBXKvosc1fcJnbssy CJoArExOjGYWbeaYIbWdUPw= X-Google-Smtp-Source: ACHHUZ7NYzhki84oqM5sC/T0ASeC0x8KLgCKVbwvSy/vX3s9gdhOdDf04XFw8HA41JD89ghsoCr/qw== X-Received: by 2002:a17:902:868a:b0:1a6:9f09:866d with SMTP id g10-20020a170902868a00b001a69f09866dmr2347865plo.61.1682618054077; Thu, 27 Apr 2023 10:54:14 -0700 (PDT) Received: from localhost ([2a00:79e1:abd:4a00:61b:48ed:72ab:435b]) by smtp.gmail.com with ESMTPSA id ja14-20020a170902efce00b001a69dfd918dsm4852762plb.187.2023.04.27.10.54.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Apr 2023 10:54:13 -0700 (PDT) From: Rob Clark To: dri-devel@lists.freedesktop.org Cc: freedreno@lists.freedesktop.org, Daniel Vetter , Tvrtko Ursulin , Boris Brezillon , Christopher Healy , Emil Velikov , =?UTF-8?q?Christian=20K=C3=B6nig?= , Rob Clark , Rob Clark , Abhinav Kumar , Dmitry Baryshkov , Sean Paul , David Airlie , Chia-I Wu , Akhil P Oommen , Luca Weiss , Maximilian Luz , Konrad Dybcio , Elliot Berman , linux-arm-msm@vger.kernel.org (open list:DRM DRIVER FOR MSM ADRENO GPU), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v2 9/9] drm/msm: Wire up comm/cmdline override for fdinfo Date: Thu, 27 Apr 2023 10:53:33 -0700 Message-Id: <20230427175340.1280952-10-robdclark@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230427175340.1280952-1-robdclark@gmail.com> References: <20230427175340.1280952-1-robdclark@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Rob Clark Also store the override strings in drm_file so that fdinfo can display them. We still need to keep our original copy as we could need these override strings after the device file has been closed and drm_file freed. Signed-off-by: Rob Clark --- drivers/gpu/drm/msm/adreno/adreno_gpu.c | 24 +++++++++++++++++++++++- drivers/gpu/drm/msm/msm_drv.c | 2 ++ drivers/gpu/drm/msm/msm_gpu.h | 10 ++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/msm/adreno/adreno_gpu.c b/drivers/gpu/drm/msm/= adreno/adreno_gpu.c index bb38e728864d..a20c2622a61f 100644 --- a/drivers/gpu/drm/msm/adreno/adreno_gpu.c +++ b/drivers/gpu/drm/msm/adreno/adreno_gpu.c @@ -16,6 +16,7 @@ #include #include #include +#include #include "adreno_gpu.h" #include "a6xx_gpu.h" #include "msm_gem.h" @@ -398,7 +399,8 @@ int adreno_set_param(struct msm_gpu *gpu, struct msm_fi= le_private *ctx, switch (param) { case MSM_PARAM_COMM: case MSM_PARAM_CMDLINE: { - char *str, **paramp; + char *str, *str2, **paramp; + struct drm_file *file =3D ctx->file; =20 str =3D kmalloc(len + 1, GFP_KERNEL); if (!str) @@ -412,6 +414,13 @@ int adreno_set_param(struct msm_gpu *gpu, struct msm_f= ile_private *ctx, /* Ensure string is null terminated: */ str[len] =3D '\0'; =20 + /* + * We need a 2nd copy for drm_file.. this copy can't replace + * our internal copy in the ctx, because we may need it for + * recovery/devcoredump after the file is already closed. + */ + str2 =3D kstrdup(str, GFP_KERNEL); + mutex_lock(&gpu->lock); =20 if (param =3D=3D MSM_PARAM_COMM) { @@ -425,6 +434,19 @@ int adreno_set_param(struct msm_gpu *gpu, struct msm_f= ile_private *ctx, =20 mutex_unlock(&gpu->lock); =20 + mutex_lock(&file->override_lock); + + if (param =3D=3D MSM_PARAM_COMM) { + paramp =3D &file->override_comm; + } else { + paramp =3D &file->override_cmdline; + } + + kfree(*paramp); + *paramp =3D str2; + + mutex_unlock(&file->override_lock); + return 0; } case MSM_PARAM_SYSPROF: diff --git a/drivers/gpu/drm/msm/msm_drv.c b/drivers/gpu/drm/msm/msm_drv.c index 81a1371c0307..3a74b5653e96 100644 --- a/drivers/gpu/drm/msm/msm_drv.c +++ b/drivers/gpu/drm/msm/msm_drv.c @@ -581,6 +581,7 @@ static int context_init(struct drm_device *dev, struct = drm_file *file) rwlock_init(&ctx->queuelock); =20 kref_init(&ctx->ref); + ctx->file =3D file; msm_submitqueue_init(dev, ctx); =20 ctx->aspace =3D msm_gpu_create_private_address_space(priv->gpu, current); @@ -603,6 +604,7 @@ static int msm_open(struct drm_device *dev, struct drm_= file *file) =20 static void context_close(struct msm_file_private *ctx) { + ctx->file =3D NULL; msm_submitqueue_close(ctx); msm_file_private_put(ctx); } diff --git a/drivers/gpu/drm/msm/msm_gpu.h b/drivers/gpu/drm/msm/msm_gpu.h index 7a4fa1b8655b..671ce89e61b0 100644 --- a/drivers/gpu/drm/msm/msm_gpu.h +++ b/drivers/gpu/drm/msm/msm_gpu.h @@ -359,6 +359,16 @@ struct msm_file_private { struct kref ref; int seqno; =20 + /** + * @file: link back to the associated drm_file + * + * Note that msm_file_private can outlive the drm_file, ie. + * after the drm_file is closed but before jobs submitted have + * been cleaned up. After the drm_file is closed this will be + * NULL. + */ + struct drm_file *file; + /** * sysprof: * --=20 2.39.2