From nobody Thu Dec 18 19:43:32 2025 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 75EE5C77B73 for ; Mon, 1 May 2023 18:45:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232577AbjEASpR (ORCPT ); Mon, 1 May 2023 14:45:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232419AbjEASpL (ORCPT ); Mon, 1 May 2023 14:45:11 -0400 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1DA8ECD; Mon, 1 May 2023 11:45:10 -0700 (PDT) Received: by mail-pj1-x102c.google.com with SMTP id 98e67ed59e1d1-24ddf274039so1469453a91.1; Mon, 01 May 2023 11:45:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682966709; x=1685558709; 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=xlQgRgGnpnzTcnGyVtUcqaEHfPcu6dc+i5pcShGQrxo=; b=kRsbc8tlfk/H/cv097InCtoRduh0Q2peT/+ICEGVsdCySxLpPGs6lZFcQW1isxOIYv DpToN+aOtwZamMBWgLnntS32ZADvrFqAyvGYF81UPuDErrqXkAno9sehM9HAx5baUPUf AOT+20t3+OTA5Ac/yr1GPsSGcAY0J0l++i6HzhDW5ddBC8m5v07Lz0GY/p1WDHBuf37Q +BvoNNvuotTtkrvhp2v3sFlXUjuvmHW76vC7FYpyNoETJzENXbXPVSQJDOyX6py19UdS RkeJ0wQ3O139P4qNytKjJJ0zFi1AKI2RO5bdE6ukPAaPgZEBOFJ/VTvmTeGd/WygQPwG k1Zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682966709; x=1685558709; 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=xlQgRgGnpnzTcnGyVtUcqaEHfPcu6dc+i5pcShGQrxo=; b=gROfrvEcBdRvUDX8E5EhVGQKoBsX0J/KTRp/ceQSGscoNMe6iBOH+Gzm35bZQC8lGp dD7T8mcvIdBVWBj2QOeLas6SCusiSboM52EAkw241FKrHp+PSwYz1PjE+tsWRzM7MMjG lleeVSchNT+t1qrNOQy9Qf3ddZihinncNZs78p+8yDl3S/j8ApsiZLwQ0IUsLm4LviP4 jbpsqw2lDJBrghcVRex9uSn2aQj9Pd5X8u4KGi/UdTnUz3ojfP5jjzFP5dlgHZIwPEeS CFzjuNCM30jpcgk/dVRLfnKzg93dlCucjsjAYGO7Dih0K1CPRgx8lFQ0MiCa+8WuY7I4 dWGQ== X-Gm-Message-State: AC+VfDx7Eer27mXdQ4by2m2jYDhQ86AZU9jwrAHBoV+CyHkU/2YGK5U8 O7qaRoBa9fzpofXogAFSddA= X-Google-Smtp-Source: ACHHUZ4b+PxnvHuPTzQ0/tFd2w6+1Uyn0n4UKDVf+1oB8hgnSSkutccemZUA4kOfxhR3khAf5A59ew== X-Received: by 2002:a17:90b:954:b0:24d:fb2c:1ae0 with SMTP id dw20-20020a17090b095400b0024dfb2c1ae0mr4322102pjb.17.1682966709532; Mon, 01 May 2023 11:45:09 -0700 (PDT) Received: from localhost ([2a00:79e1:abd:4a00:61b:48ed:72ab:435b]) by smtp.gmail.com with ESMTPSA id hg4-20020a17090b300400b0024decfb1ec2sm3032473pjb.30.2023.05.01.11.45.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 May 2023 11:45:09 -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 v3 1/9] drm/docs: Fix usage stats typos Date: Mon, 1 May 2023 11:44:47 -0700 Message-Id: <20230501184502.1620335-2-robdclark@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230501184502.1620335-1-robdclark@gmail.com> References: <20230501184502.1620335-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 --- 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 @@ -98,33 +98,33 @@ is not allowed. 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. =20 Value shall reflect the amount of storage currently consumed by the buffer object belong to this client, in the respective memory region. =20 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 engine. =20 Values are not required to be constantly monotonic if it makes the driver implementation easier, but are required to catch up with the previously re= ported 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 engine. Taken together with drm-cycles-, this can be used to calcula= te percentage utilization of the engine, whereas drm-engine- only reflec= ts time active without considering what frequency the engine is operating as a percentage of it's maximum frequency. =20 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 2.39.2 From nobody Thu Dec 18 19:43:32 2025 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 47F6EC77B7C for ; Mon, 1 May 2023 18:45:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231356AbjEASpV (ORCPT ); Mon, 1 May 2023 14:45:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58312 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232540AbjEASpP (ORCPT ); Mon, 1 May 2023 14:45:15 -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 1594FC6; Mon, 1 May 2023 11:45:12 -0700 (PDT) Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-63b70f0b320so3289207b3a.1; Mon, 01 May 2023 11:45:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682966711; x=1685558711; 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=MkOiaACJUwTSaZnAMg3Z1LNgb8tXwVgSyta4ro1Te6g=; b=ehnGoMuxRDRH5aLlU2tF306g+ZD38d9HHlxR5A50he032bRpcy/KZBQXNoCjrUVhg+ OsvU/3cuqKQDxPGYbHqci2oy3KilnhpuhiklCFsV9L11Vm1TEejJPleCQkqyD05Ukhgm aXAoeeCa6atrhbjBEFUAJFgnhRY17guz4D5K5Niv8QazAuzS5zI57U9yEScBkOh58Gvk yNZi0P/5BGSy5H3Vi3LAAQNZXBUTpgQT1WsEgCaMCrrNSWt3zlnHNz3+auAGT7b5IG+9 sgbCoo4PdZsrkFCSw/YGMgFQX9Wc0XGd6aLUma5ZB3WjYtF4TInVwUODGneX3ry+/cyl CHFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682966711; x=1685558711; 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=MkOiaACJUwTSaZnAMg3Z1LNgb8tXwVgSyta4ro1Te6g=; b=hEA+kkLvQ2WMJiAkS8dW+f24JwqvT/BRYTpjG3nMMmoEEQ+ckOpAQJVKjxaU1CbEcI /Z2I9/hFrPUSjqpVDYZfZFbhkqr3EI5IDTF0k9a9WxV2CWJ6vMutYaGAm8Ee/Kq1aeAB EXkCKMgjyZjNb4bdXV69xZ6XN8+fAoO7Quz9oAuCUarC9aL/xruL8Kcp3gZPkLyObBxd E21EIiGwHqLjGLd4g8980mjEaOJnMVQ++MzEZ4q3sxTUCYSOHpSPpc2+dE/E/hMmOg/y q93e/mpBeAxs/qlvbAL4BMkSeuEXCfuwtzUrJbfaDU7Mks5oOUaiCqFvXgr3S0iLLUMh mqEQ== X-Gm-Message-State: AC+VfDz+Rug1oWO4JoB8z8U+E52our8vGPDleM29zQvB4OpVz9YaUCkP N94WHrffC0Lg/sekA/bVDgU= X-Google-Smtp-Source: ACHHUZ7mhldmS4hPvySjRFhjN5zTE63qGlJYrr/wJcWFWwtgMblzXR1skb/7nyqzI3zdZZnLfsmGNw== X-Received: by 2002:a05:6a20:7d95:b0:f4:98d2:591d with SMTP id v21-20020a056a207d9500b000f498d2591dmr19290919pzj.5.1682966711341; Mon, 01 May 2023 11:45:11 -0700 (PDT) Received: from localhost ([2a00:79e1:abd:4a00:61b:48ed:72ab:435b]) by smtp.gmail.com with ESMTPSA id gb9-20020a17090b060900b0024dee500736sm2994401pjb.57.2023.05.01.11.45.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 May 2023 11:45: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 , 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 v3 2/9] drm: Add common fdinfo helper Date: Mon, 1 May 2023 11:44:48 -0700 Message-Id: <20230501184502.1620335-3-robdclark@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230501184502.1620335-1-robdclark@gmail.com> References: <20230501184502.1620335-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 @@ -119,14 +119,22 @@ value until a monotonic update is seen. =20 - 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 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 @@ -141,28 +141,31 @@ bool drm_dev_needs_global_mutex(struct drm_device *de= v) * * This allocates a new DRM file context. It is not linked into any contex= t and * can be used by the caller freely. Note that the context keeps a pointer= to * @minor, so it must be freed before @minor is. * * RETURNS: * Pointer to newly allocated context, ERR_PTR on failure. */ 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; =20 file =3D kzalloc(sizeof(*file), GFP_KERNEL); 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 /* for compatibility root is always authenticated */ file->authenticated =3D capable(CAP_SYS_ADMIN); =20 INIT_LIST_HEAD(&file->lhead); INIT_LIST_HEAD(&file->fbs); mutex_init(&file->fbs_lock); INIT_LIST_HEAD(&file->blobs); @@ -861,20 +864,52 @@ EXPORT_SYMBOL(drm_send_event_locked); void drm_send_event(struct drm_device *dev, struct drm_pending_event *e) { unsigned long irqflags; =20 spin_lock_irqsave(&dev->event_lock, irqflags); drm_send_event_helper(dev, e, 0); spin_unlock_irqrestore(&dev->event_lock, irqflags); } 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) * @flags: file creation mode (O_RDWR etc) * * This create a new struct file that wraps a DRM file context around a * DRM minor. This mimicks userspace opening e.g. /dev/dri/card0, but with= out * invoking userspace. The struct file may be operated on using its f_op * (the drm_device.driver.fops) to mimick userspace operations, or be supp= lied * to userspace facing functions as an internal/anonymous client. 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 @@ -394,20 +394,27 @@ struct drm_driver { * Called by the user via ioctl. * * Returns: * * Zero on success, negative errno on failure. */ int (*dumb_map_offset)(struct drm_file *file_priv, 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 */ int minor; /** @patchlevel: driver patch level */ int patchlevel; /** @name: driver name */ char *name; /** @desc: driver description */ char *desc; 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 @@ -251,20 +251,23 @@ struct drm_file { * primary nodes and authentication `. */ struct drm_master *master; =20 /** @master_lookup_lock: Serializes @master. */ spinlock_t master_lookup_lock; =20 /** @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 /** * @lhead: * * List of all open files of a DRM device, linked into * &drm_device.filelist. Protected by &drm_device.filelist_mutex. */ struct list_head lhead; @@ -430,14 +433,15 @@ int drm_event_reserve_init(struct drm_device *dev, struct drm_file *file_priv, struct drm_pending_event *p, struct drm_event *e); void drm_event_cancel_free(struct drm_device *dev, struct drm_pending_event *p); void drm_send_event_locked(struct drm_device *dev, struct drm_pending_even= t *e); 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 #endif /* _DRM_FILE_H_ */ --=20 2.39.2 From nobody Thu Dec 18 19:43:32 2025 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 A3859C77B7F for ; Mon, 1 May 2023 18:45:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232540AbjEASpY (ORCPT ); Mon, 1 May 2023 14:45:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58316 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232556AbjEASpQ (ORCPT ); Mon, 1 May 2023 14:45:16 -0400 Received: from mail-pg1-x52d.google.com (mail-pg1-x52d.google.com [IPv6:2607:f8b0:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0F58CD; Mon, 1 May 2023 11:45:13 -0700 (PDT) Received: by mail-pg1-x52d.google.com with SMTP id 41be03b00d2f7-51f1b6e8179so1834173a12.3; Mon, 01 May 2023 11:45:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682966713; x=1685558713; 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=9TduxMlN6FHewLrO+zh81TjJ8J6pSF1/l3zfTKBuCoA=; b=pbDCxE0gxpMORIzDv5ufSDD4Cwhb6fG38OM/mI8pUhoP2nHMH/BuM8h40pXoXWfD2B 2HSm7znuwK0F9YqpXYk+smBFsD2w5Qn6HQI4y7jBnbOfrzUjE5kvLluxpe6iIzbRheF8 vz1kGmJppucdox89cT8qG8Pn3bE5AzNDR50aY/iIIwXyJW5YQoBCcrv3Z4LYdB/K+LMK xUDdHvndgdWehotplHMVODbOuUhh5PrrIjomi3bB3QFPFda+X6cB8D2VHI6HzfKuESGE YKz92jPLomNOevc3fYN2uLeCyUZKagiNDCGq74aFZjQhGldGTnCdfTkcYzhQ5AX0TrC+ NSAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682966713; x=1685558713; 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=9TduxMlN6FHewLrO+zh81TjJ8J6pSF1/l3zfTKBuCoA=; b=LYwz9Kcgo3vqGTcrZ2cgQNpj/eu1BlY67oURk1P+BYZ4R6mZoAu250JOxkIVWfPkfY JbBtOOxTaIAEngdrty4wh9YfkCSPHFjDHNQUCa2wJEtI1RVJ4Pr+C3g2an3LGfAbAANt tknc0uCUMOyBcYhs3OTkjh7moIjDilybSCFlLRB1SqIOlS1S8oaq9cgUIRpbPQp1Wwd4 VygOvNgIq0vr41YORTf4uDxy/ijvcr7sKLWaWT7JTDjMFhk7ljEdx44GkSAj5skjOGOl BqJo/ubWkxaYHkbdAZzJOVYhdNWr0iKTBqb5BFygGrVngwgo9xp38j3df/63465FhvPU Quig== X-Gm-Message-State: AC+VfDyQg7rHOwOcVv1C2vvazmiTw+5x6qXoFBf3aqYFwEv87RQjz4Qo DUp94PtTq7Jzr+cMHwCCSe4= X-Google-Smtp-Source: ACHHUZ5PXdAU5V8zv7AbOm6OW63czG63yjlCOeZwJReqrF8100LfyQPQ8YRzmHo0eqCEjFIf2vdQwQ== X-Received: by 2002:a17:90b:4f82:b0:23f:582d:f45f with SMTP id qe2-20020a17090b4f8200b0023f582df45fmr14866590pjb.1.1682966713106; Mon, 01 May 2023 11:45:13 -0700 (PDT) Received: from localhost ([2a00:79e1:abd:4a00:61b:48ed:72ab:435b]) by smtp.gmail.com with ESMTPSA id r23-20020a17090a941700b00247bdd05fe5sm6090019pjo.29.2023.05.01.11.45.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 May 2023 11:45:12 -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 v3 3/9] drm/msm: Switch to fdinfo helper Date: Mon, 1 May 2023 11:44:49 -0700 Message-Id: <20230501184502.1620335-4-robdclark@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230501184502.1620335-1-robdclark@gmail.com> References: <20230501184502.1620335-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 @@ -1036,57 +1036,56 @@ static const struct drm_ioctl_desc msm_ioctls[] =3D= { DRM_IOCTL_DEF_DRV(MSM_GEM_CPU_PREP, msm_ioctl_gem_cpu_prep, DRM_RENDER_AL= LOW), DRM_IOCTL_DEF_DRV(MSM_GEM_CPU_FINI, msm_ioctl_gem_cpu_fini, DRM_RENDER_AL= LOW), DRM_IOCTL_DEF_DRV(MSM_GEM_SUBMIT, msm_ioctl_gem_submit, DRM_RENDER_AL= LOW), DRM_IOCTL_DEF_DRV(MSM_WAIT_FENCE, msm_ioctl_wait_fence, DRM_RENDER_AL= LOW), DRM_IOCTL_DEF_DRV(MSM_GEM_MADVISE, msm_ioctl_gem_madvise, DRM_RENDER_AL= LOW), DRM_IOCTL_DEF_DRV(MSM_SUBMITQUEUE_NEW, msm_ioctl_submitqueue_new, DRM= _RENDER_ALLOW), DRM_IOCTL_DEF_DRV(MSM_SUBMITQUEUE_CLOSE, msm_ioctl_submitqueue_close, DRM= _RENDER_ALLOW), 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 { .driver_features =3D DRIVER_GEM | DRIVER_RENDER | DRIVER_ATOMIC | 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, .prime_handle_to_fd =3D drm_gem_prime_handle_to_fd, .prime_fd_to_handle =3D drm_gem_prime_fd_to_handle, .gem_prime_import_sg_table =3D msm_gem_prime_import_sg_table, .gem_prime_mmap =3D msm_gem_prime_mmap, #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, .name =3D "msm", .desc =3D "MSM Snapdragon DRM", .date =3D "20130625", .major =3D MSM_VERSION_MAJOR, .minor =3D MSM_VERSION_MINOR, .patchlevel =3D MSM_VERSION_PATCHLEVEL, }; 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 @@ -144,22 +144,20 @@ int msm_gpu_pm_suspend(struct msm_gpu *gpu) return ret; =20 gpu->suspend_count++; =20 return 0; } =20 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 int msm_gpu_hw_init(struct msm_gpu *gpu) { int ret; =20 WARN_ON(!mutex_is_locked(&gpu->lock)); --=20 2.39.2 From nobody Thu Dec 18 19:43:32 2025 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 DBC81C7EE25 for ; Mon, 1 May 2023 18:45:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232645AbjEASp2 (ORCPT ); Mon, 1 May 2023 14:45:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232590AbjEASpV (ORCPT ); Mon, 1 May 2023 14:45:21 -0400 Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 581C8C6 for ; Mon, 1 May 2023 11:45:18 -0700 (PDT) Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-63b8b19901fso3327013b3a.3 for ; Mon, 01 May 2023 11:45:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682966718; x=1685558718; 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=BrobCNYvIO66ZrJzqOwGa4WzVcqoiyRGGqDniTZ33q0=; b=nQZi0sQq4ckcKQAakrJrAYwM2qpWTzMOGY25ybF5XoFHveOEdeFrrvUPSbHI2Xlx7R cHon4s8hkO1Elfp2amnk1wO0PbuNGbIqKM+5rhvQOSasvEBp49O95vSOohPzR5GEUgIM cYWa3fgUPvzPfxvCtbdKg2R6eElfkNG7WudgFBpVnfs2P/z9rZim0tQI+UOYZ2aMK69v Ze95OQB+63Vr/RwmUPYBjumlzPKi7MtQWrhHGGwdlo/L4ruC0F5MohJxQnNnpYZfj0z9 huAhyjHaGComSFCZEEQzFyrWIa1Z0gw2o7oB/bVrLrerqIuAkgLG3jVf9x3HCGkRRlcZ g7JQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682966718; x=1685558718; 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=BrobCNYvIO66ZrJzqOwGa4WzVcqoiyRGGqDniTZ33q0=; b=UJVM7stmIlgW5Qk1lPxqPxV02DJq4kKBHZ3N1l9YFBrgvlxQsVxjdRtBkqdTFkh/Z3 VNrsIekkyspa2DgxZu8nsLdSlTo9iUyji3MDGbbGsPmnrZ6NDGM7Xz6zPkDwg9dPH9+C AdpPAwKZrq1RbjnjCiaIkqqSpboYtsim7Gqt1CBnpe8/QRvf+wDVtvG7NnDyoFWgyjYB +LxThXC3BltILlRi4Zg3IrHsxfbyyDmKLfFZHxfd4sdh9o1pjn4Uo7zLkR0XWj+9mjSJ gWgkrtzMrgg+L96QpMCyEHBtw7VS3G/y4rHecl3JNjhUAQiFJtZzTbODA2vRquGXuQrK LEYg== X-Gm-Message-State: AC+VfDzlMdbYc4dEfgtkVna1KUsKpC42HlJs1M+oKPHK2CRjozh/CVpU RoHPbolWS9ZZfbKLB+PuJgI= X-Google-Smtp-Source: ACHHUZ6KzprDSNgtc3hzYbQlNEU1SkXSMh9IsDMZaL+sTIK4sFcA7pRERG3li0Q83kYu+AZNFaCJVw== X-Received: by 2002:a05:6a00:15c5:b0:636:f899:46a0 with SMTP id o5-20020a056a0015c500b00636f89946a0mr21949327pfu.15.1682966717801; Mon, 01 May 2023 11:45:17 -0700 (PDT) Received: from localhost ([2a00:79e1:abd:4a00:61b:48ed:72ab:435b]) by smtp.gmail.com with ESMTPSA id m30-20020a62a21e000000b0063aa1763146sm20735822pff.17.2023.05.01.11.45.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 May 2023 11:45:17 -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 , =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= , Guchun Chen , YiPeng Chai , =?UTF-8?q?Michel=20D=C3=A4nzer?= , Jim Cromie , 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 v3 4/9] drm/amdgpu: Switch to fdinfo helper Date: Mon, 1 May 2023 11:44:50 -0700 Message-Id: <20230501184502.1620335-5-robdclark@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230501184502.1620335-1-robdclark@gmail.com> References: <20230501184502.1620335-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 @@ -2745,21 +2745,21 @@ static const struct file_operations amdgpu_driver_k= ms_fops =3D { .flush =3D amdgpu_flush, .release =3D drm_release, .unlocked_ioctl =3D amdgpu_drm_ioctl, .mmap =3D drm_gem_mmap, .poll =3D drm_poll, .read =3D drm_read, #ifdef CONFIG_COMPAT .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 int amdgpu_file_to_fpriv(struct file *filp, struct amdgpu_fpriv **fpriv) { struct drm_file *file; =20 if (!filp) return -EINVAL; =20 @@ -2800,20 +2800,21 @@ static const struct drm_driver amdgpu_kms_driver = =3D { DRIVER_SYNCOBJ_TIMELINE, .open =3D amdgpu_driver_open_kms, .postclose =3D amdgpu_driver_postclose_kms, .lastclose =3D amdgpu_driver_lastclose_kms, .ioctls =3D amdgpu_ioctls_kms, .num_ioctls =3D ARRAY_SIZE(amdgpu_ioctls_kms), .dumb_create =3D amdgpu_mode_dumb_create, .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, .gem_prime_import =3D amdgpu_gem_prime_import, .gem_prime_mmap =3D drm_gem_prime_mmap, =20 .name =3D DRIVER_NAME, .desc =3D DRIVER_DESC, .date =3D DRIVER_DATE, .major =3D KMS_DRIVER_MAJOR, 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 @@ -46,23 +46,22 @@ static const char *amdgpu_ip_name[AMDGPU_HW_IP_NUM] =3D= { [AMDGPU_HW_IP_COMPUTE] =3D "compute", [AMDGPU_HW_IP_DMA] =3D "dma", [AMDGPU_HW_IP_UVD] =3D "dec", [AMDGPU_HW_IP_VCE] =3D "enc", [AMDGPU_HW_IP_UVD_ENC] =3D "enc_1", [AMDGPU_HW_IP_VCN_DEC] =3D "dec", [AMDGPU_HW_IP_VCN_ENC] =3D "enc", [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; =20 uint64_t vram_mem =3D 0, gtt_mem =3D 0, cpu_mem =3D 0; ktime_t usage[AMDGPU_HW_IP_NUM]; uint32_t bus, dev, fn, domain; unsigned int hw_ip; int ret; =20 @@ -79,25 +78,22 @@ void amdgpu_show_fdinfo(struct seq_file *m, struct file= *f) amdgpu_bo_unreserve(vm->root.bo); =20 amdgpu_ctx_mgr_usage(&fpriv->ctx_mgr, usage); =20 /* * ****************************************************************** * For text output format description please see drm-usage-stats.rst! * ****************************************************************** */ =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 @@ -30,13 +30,13 @@ #include #include #include #include =20 #include "amdgpu_sync.h" #include "amdgpu_ring.h" #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 Thu Dec 18 19:43:32 2025 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 ABFEBC7EE26 for ; Mon, 1 May 2023 18:45:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231816AbjEASpi (ORCPT ); Mon, 1 May 2023 14:45:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232641AbjEASp2 (ORCPT ); Mon, 1 May 2023 14:45:28 -0400 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7927E2688; Mon, 1 May 2023 11:45:20 -0700 (PDT) Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-64115e652eeso28734558b3a.0; Mon, 01 May 2023 11:45:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682966720; x=1685558720; 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=KQp9gfJGG+Y0BWztBSmHSY/g3i1wrswRgdK7Ptk4ajw=; b=FP6GBCvERuFY2QFLk/vIqLKI9YJo8uJVwdL5P0YYFhSqyU2xwr1+AGZ8G0cU1HtYBP UIw8uFkQ/3jHNgZp5OhNjz2+FCWh/WzH7239GzAloVRSIr02/PTnpJO8DXY9Et2eZRck Cke2ivICuEg3hsdv7ZcbaqZfy97rdEcYWZ7fgsv0amE05QpuIapGDv3V8fUhmkO2eQ4h CFRFxjT7VKaSya1oM2q4vXKWd7gfOrTnwqeWPh9rGw3XStcsM4zzLAr8jHVV0WHASRZT xjFxH1Dw3BnmTCngRq+lF+aUhEKNnumk8n9rbdp/OrzFj+QTohMmhZGGKK2EAuaR8m3j rCRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682966720; x=1685558720; 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=KQp9gfJGG+Y0BWztBSmHSY/g3i1wrswRgdK7Ptk4ajw=; b=RtSfUx55tpTFI1m+v87tN+Me7xQDAJWkrm/765VAI2kelGrYqvMabEIZ3EXHkZrBFg 8owB1u/yoYEkXVV8UWDNjOuqivkGjlKbtZiCZXUSCNVTYlimaQVOP6A0D6VvfcMGVAV6 9w8u3S/r76GbFLkD2NRPPdVOe6b/IaLBgIZv96rNyI1J9rLXoEkXNtmjTfhtqLVf9B0M RJMquBkpHj1dv+8ezVhDTWwn7pJcdTLUQKslob7J1FXO7+DYYKbsJz5BKHIStILD7xLp n63qbMEhSwhzxbDM1J913gaQv/JWAlu3CjGkLAbLFN7SeCTO8cq68GQfkNQmT6GQjM2g Pbdg== X-Gm-Message-State: AC+VfDyQk1YIhb7PO1qbmlyBfljxhwTfMMgvUMSfnkqzGLY06TFvR6XT 0J9cvz8DfUMVubiInMe7KUc= X-Google-Smtp-Source: ACHHUZ7u+VuFSbDRFoeugmom6ZLBj75QfayFTw/3tPOB6o1QVmKKagB/TrcSwWuCSK3GHmBUlKMQig== X-Received: by 2002:a17:90a:3189:b0:24d:f0e9:907f with SMTP id j9-20020a17090a318900b0024df0e9907fmr6472197pjb.6.1682966719804; Mon, 01 May 2023 11:45:19 -0700 (PDT) Received: from localhost ([2a00:79e1:abd:4a00:61b:48ed:72ab:435b]) by smtp.gmail.com with ESMTPSA id b13-20020a17090a8c8d00b0024deb445265sm3169189pjo.47.2023.05.01.11.45.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 May 2023 11:45:19 -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 v3 5/9] drm: Add fdinfo memory stats Date: Mon, 1 May 2023 11:44:51 -0700 Message-Id: <20230501184502.1620335-6-robdclark@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230501184502.1620335-1-robdclark@gmail.com> References: <20230501184502.1620335-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 v5: doc fixes 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 | 28 ++++++++ include/drm/drm_gem.h | 30 ++++++++ 4 files changed, 198 insertions(+), 13 deletions(-) diff --git a/Documentation/gpu/drm-usage-stats.rst b/Documentation/gpu/drm-= usage-stats.rst index 552195fb1ea3..d012eb56885e 100644 --- a/Documentation/gpu/drm-usage-stats.rst +++ b/Documentation/gpu/drm-usage-stats.rst @@ -45,37 +45,43 @@ Mandatory fully standardised keys --------------------------------- =20 - drm-driver: =20 String shall contain the name this driver registered as via the respective `struct drm_driver` data structure. =20 Optional fully standardised keys -------------------------------- =20 +Identification +^^^^^^^^^^^^^^ + - drm-pdev: =20 For PCI devices this should contain the PCI slot address of the device in question. =20 - drm-client-id: =20 Unique value relating to the open DRM file descriptor used to distinguish duplicated and shared file descriptors. Conceptually the value should map = 1:1 to the in kernel representation of `struct drm_file` instances. =20 Uniqueness of the value shall be either globally unique, or unique within = the scope of each device, in which case `drm-pdev` shall be present as well. =20 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 and unique name (str), with possible values documented in the driver speci= fic documentation. =20 Value shall be in specified time units which the respective GPU engine spe= nt busy executing workloads belonging to this client. =20 Values are not required to be constantly monotonic if it makes the driver @@ -86,32 +92,20 @@ value until a monotonic update is seen. =20 - 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 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-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 drm-engine- tag and shall contain the number of busy cycles for the g= iven engine. =20 Values are not required to be constantly monotonic if it makes the driver implementation easier, but are required to catch up with the previously re= ported 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 @@ -119,20 +113,56 @@ value until a monotonic update is seen. =20 - 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 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 +objects 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-total-: [KiB|MiB] + +The total size of buffers that including shared and private memory. + +- drm-resident-: [KiB|MiB] + +The total size of buffers that are resident in the specified region. + +- 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 engines. + 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 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. =20 Driver specific implementations ------------------------------- 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 @@ -35,20 +35,21 @@ #include #include #include #include #include #include =20 #include #include #include +#include #include =20 #include "drm_crtc_internal.h" #include "drm_internal.h" #include "drm_legacy.h" =20 /* from BKL pushdown */ DEFINE_MUTEX(drm_global_mutex); =20 bool drm_dev_needs_global_mutex(struct drm_device *dev) @@ -864,23 +865,119 @@ EXPORT_SYMBOL(drm_send_event_locked); void drm_send_event(struct drm_device *dev, struct drm_pending_event *e) { unsigned long irqflags; =20 spin_lock_irqsave(&dev->event_lock, irqflags); drm_send_event_helper(dev, e, 0); spin_unlock_irqrestore(&dev->event_lock, irqflags); } 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 * 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; diff --git a/include/drm/drm_file.h b/include/drm/drm_file.h index 6de6d0e9c634..f77540b97cd0 100644 --- a/include/drm/drm_file.h +++ b/include/drm/drm_file.h @@ -34,20 +34,21 @@ #include #include =20 #include =20 #include =20 struct dma_fence; struct drm_file; struct drm_device; +struct drm_printer; struct device; struct file; =20 /* * FIXME: Not sure we want to have drm_minor here in the end, but to avoid * header include loops we need it here for now. */ =20 /* Note that the order of this enum is ABI (it determines * /dev/dri/renderD* numbers). @@ -433,15 +434,42 @@ int drm_event_reserve_init(struct drm_device *dev, struct drm_file *file_priv, struct drm_pending_event *p, struct drm_event *e); void drm_event_cancel_free(struct drm_device *dev, struct drm_pending_event *p); void drm_send_event_locked(struct drm_device *dev, struct drm_pending_even= t *e); 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 - GEM object stats associated + * @shared: Total size of GEM objects shared between processes + * @private: Total size of GEM objects + * @resident: Total size of GEM objects backing pages + * @purgeable: Total size of GEM objects that can be purged (resident and = not active) + * @active: Total size of GEM objects active on one or more engines + * + * Used by drm_print_memory_stats() + */ +struct drm_memory_stats { + u32 shared; + u32 private; + u32 resident; + u32 purgeable; + u32 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); =20 #endif /* _DRM_FILE_H_ */ 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 @@ -35,20 +35,39 @@ */ =20 #include #include =20 #include =20 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 */ struct drm_gem_object_funcs { /** * @free: * * Deconstructor for drm_gem_objects. * * This callback is mandatory. @@ -167,20 +186,31 @@ struct drm_gem_object_funcs { /** * @evict: * * Evicts gem object out from memory. Used by the drm_gem_object_evict() * helper. Returns 0 on success, -errno otherwise. * * This callback is optional. */ 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: * * Virtual memory operations used with mmap. * * This is optional but necessary for mmap support. */ const struct vm_operations_struct *vm_ops; }; =20 --=20 2.39.2 From nobody Thu Dec 18 19:43:32 2025 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 24909C77B73 for ; Mon, 1 May 2023 18:45:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232680AbjEASpk (ORCPT ); Mon, 1 May 2023 14:45:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232650AbjEASpd (ORCPT ); Mon, 1 May 2023 14:45:33 -0400 Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60572212D; Mon, 1 May 2023 11:45:22 -0700 (PDT) Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-642f5394651so387386b3a.3; Mon, 01 May 2023 11:45:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682966721; x=1685558721; 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=txqLAX2ZeHUuYfn7+/gjt1ln/mVXpEI+QLx8SJDIN6g=; b=f4LGwvAuK/XoawhvaLRsbVd1xHVXJgaE/ouTNYpKVg8zlmvLXVogFG4Yovwb42Qd57 ujUvo6+nHg//g4U/jxpAh6eSa/qUfyQwZzjNDXTq1XKnvYCLKc4TKA079BDU7kMxPicO yzSk78ao4uAY7b2Xh4rY9awJtE0qXX5TRTvzjc0DEbheXcUVEgpKMmZ4xvdUTPkMepwm kBKUG8/qE28kz6tSUv/M/IgDPCZ63kD0OOhfgOdkEbjqaGO1b4joKsXE7mxC9PzZMBXv LT9v+hEzfTtEN5JKmvtXRG0KdmICx+5h+4MiaZ9vPFPH19dG91BOf7wK/32zlYVlwWNu UWTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682966721; x=1685558721; 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=txqLAX2ZeHUuYfn7+/gjt1ln/mVXpEI+QLx8SJDIN6g=; b=Cx8PDxhyQ55beLTOzw8OH2axydnZpHizIDgHRYPDoGg0SXk5f6W4RQaetG0LRopylm rAQfVPPdlebMN2bdwhRDZq4N3DNZPS9a5uK2v9+HqgD6y7S1FFDi8f1b/+qYL3dwWwI3 9fRhxW2hSsl0/CqNwRZrR/trXWTVdvxU5lVzxK3mK3KYwkCsiXo0a6CRbOT0YTTE9hwp oxL3U5iHJoPNLLOK5Qis7ocFq4/k4k5HryaCk6zFOSKEGwBntCEi2NKbrTanLWfqjKZn P+DOBXMusPjiEyClcc1ri1OeDeybMKPh5APkzWOArsyrZSBgGKT4uSiae/HhPZTmIZZm TQIQ== X-Gm-Message-State: AC+VfDxr+yj6nEtpiE1SFoZnN8AnMxDRw53/fl2pud1w63mTTFOAB5Kc uEbKW6FSnyrFlXSkJq942O0= X-Google-Smtp-Source: ACHHUZ5ufftVV8BZl4Vx8rWA4zRjQDkDsiNR5Pk+vNtG9t2sDNjTIzPdswaBLma6goGyfFkSJ5n99w== X-Received: by 2002:a05:6a00:2485:b0:641:4d30:7922 with SMTP id c5-20020a056a00248500b006414d307922mr10351853pfv.4.1682966721437; Mon, 01 May 2023 11:45:21 -0700 (PDT) Received: from localhost ([2a00:79e1:abd:4a00:61b:48ed:72ab:435b]) by smtp.gmail.com with ESMTPSA id c192-20020a621cc9000000b0063d44634d8csm20199690pfc.71.2023.05.01.11.45.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 May 2023 11:45:21 -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 v3 6/9] drm/msm: Add memory stats to fdinfo Date: Mon, 1 May 2023 11:44:52 -0700 Message-Id: <20230501184502.1620335-7-robdclark@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230501184502.1620335-1-robdclark@gmail.com> References: <20230501184502.1620335-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 @@ -1045,20 +1045,22 @@ static const struct drm_ioctl_desc msm_ioctls[] =3D= { =20 static void msm_show_fdinfo(struct drm_printer *p, struct drm_file *file) { struct drm_device *dev =3D file->minor->dev; struct msm_drm_private *priv =3D dev->dev_private; =20 if (!priv->gpu) 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 { .owner =3D THIS_MODULE, DRM_GEM_FOPS, .show_fdinfo =3D drm_show_fdinfo, }; =20 static const struct drm_driver msm_driver =3D { .driver_features =3D DRIVER_GEM | 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 @@ -1083,34 +1083,49 @@ int msm_gem_new_handle(struct drm_device *dev, stru= ct drm_file *file, msm_gem_object_set_name(obj, "%s", name); =20 ret =3D drm_gem_handle_create(file, obj, handle); =20 /* drop reference from allocate - handle holds it now */ drm_gem_object_put(obj); =20 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, .close =3D drm_gem_vm_close, }; =20 static const struct drm_gem_object_funcs msm_gem_object_funcs =3D { .free =3D msm_gem_free_object, .pin =3D msm_gem_prime_pin, .unpin =3D msm_gem_prime_unpin, .get_sg_table =3D msm_gem_prime_get_sg_table, .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 static int msm_gem_new_impl(struct drm_device *dev, uint32_t size, uint32_t flags, struct drm_gem_object **obj) { struct msm_drm_private *priv =3D dev->dev_private; struct msm_gem_object *msm_obj; =20 --=20 2.39.2 From nobody Thu Dec 18 19:43:32 2025 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 45F27C77B73 for ; Mon, 1 May 2023 18:45:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232727AbjEASpp (ORCPT ); Mon, 1 May 2023 14:45:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232627AbjEASpe (ORCPT ); Mon, 1 May 2023 14:45:34 -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 C04072710; Mon, 1 May 2023 11:45:24 -0700 (PDT) Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-63b5465fb99so2209776b3a.1; Mon, 01 May 2023 11:45:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682966723; x=1685558723; 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=OPMqzx0tM4YAjR4KEyZrtVllL0FOx+3j3GjXG2bjHSo=; b=m0yeF5XDnoSNCwWz8zb/15XvdP85Wq9Wty2g5oK1tWp5bpWl6MJt8GhEaD0cX25F2Q 3Gv7A//1uVPQKKu7iWp7bPWX61K+M8YbK5pvQ0pg6Ob3cSw7XYdxYhlIVfJDHRmLqdt0 /J5UV81E9BNJUaJd3HxTFbZTBn4GxMw3zLsWaEqt3uq9dPR4awpWlaH1Q1lSFa539lWT msGRv/uFpr9s1XT8zRwVdIAlMSQsbHtogIwLIEdQnhF8j26m2KvK9vKRiA/lUrVWujQt L4S0z5C3av2GWfYb2zS8bmVHtoPDPY8vsluNOZltL4W1BQxZxjaUlq545p/UzpUjSOgb PcvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682966723; x=1685558723; 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=OPMqzx0tM4YAjR4KEyZrtVllL0FOx+3j3GjXG2bjHSo=; b=HGs6D+f8NG6BbXLd1p/ynZKofk9tmXsn1SCDYttU/Gd7ukOvUoNPCApx4uJTP/Jpab L+XHTPiEAFKsxDXAh6BTCVX/QkWmUR1BdxFHdg0KbUljHjpbDG4SzWTcnGDhORCKPkAR nxE0bQ3Pi30wi5OQPPQMmYPU5YGxa6mvrjQLuwLQPSo4+AL4Tr6Ln283z5TUGaAzr9Sa FLR1xplaiDCaemWAeMNmwpdWnnKuP+6Z9HKE21OOltaGJNWvYX0n+7Ac+Mp0arGatKG4 jhZDixpjBspNlspPtQPp4iyqOXtqacVPa8FMKBSFxsS34OpYjRWEca/Yx+O/7zmHZ+Je yM7A== X-Gm-Message-State: AC+VfDx+z8PnlEuML8AV8/XDb1MDv11ZTK/+UWgW+jg+DbV0/rBf5UEK BvWdDa9Iry1Dec7p+e+q6fs= X-Google-Smtp-Source: ACHHUZ5kWDPbyXZ8IAVsgL324BEDoAigBDLexRlapPgQoDaPBV8uSYJRoanU3EsEU9ZHORHXg+btAA== X-Received: by 2002:a05:6a00:2d24:b0:63b:2102:a1d4 with SMTP id fa36-20020a056a002d2400b0063b2102a1d4mr22975654pfb.13.1682966723259; Mon, 01 May 2023 11:45:23 -0700 (PDT) Received: from localhost ([2a00:79e1:abd:4a00:61b:48ed:72ab:435b]) by smtp.gmail.com with ESMTPSA id y72-20020a62644b000000b006372791d708sm20201846pfb.104.2023.05.01.11.45.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 May 2023 11:45:22 -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 , 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 v3 7/9] drm/doc: Relax fdinfo string constraints Date: Mon, 1 May 2023 11:44:53 -0700 Message-Id: <20230501184502.1620335-8-robdclark@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230501184502.1620335-1-robdclark@gmail.com> References: <20230501184502.1620335-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 d012eb56885e..fe35a291ff3e 100644 --- a/Documentation/gpu/drm-usage-stats.rst +++ b/Documentation/gpu/drm-usage-stats.rst @@ -17,41 +17,42 @@ wherever possible effort should still be made to standa= rdise as much as possible. =20 File format specification =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 - 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-`. - 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 Key types --------- =20 1. Mandatory, fully standardised. 2. Optional, fully standardised. 3. Driver specific. =20 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. =20 Optional fully standardised keys -------------------------------- =20 Identification ^^^^^^^^^^^^^^ =20 @@ -68,62 +69,62 @@ to the in kernel representation of `struct drm_file` in= stances. =20 Uniqueness of the value shall be either globally unique, or unique within = the scope of each device, in which case `drm-pdev` shall be present as well. =20 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 ^^^^^^^^^^^ =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 busy executing workloads belonging to this client. =20 Values are not required to be constantly monotonic if it makes the driver implementation easier, but are required to catch up with the previously re= ported 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 implementation easier, but are required to catch up with the previously re= ported 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 -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 Memory ^^^^^^ =20 - drm-memory-: [KiB|MiB] =20 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 --=20 2.39.2 From nobody Thu Dec 18 19:43:32 2025 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 E6A1BC77B73 for ; Mon, 1 May 2023 18:45:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232144AbjEASpu (ORCPT ); Mon, 1 May 2023 14:45:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231978AbjEASpf (ORCPT ); Mon, 1 May 2023 14:45:35 -0400 Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 208561BFF; Mon, 1 May 2023 11:45:25 -0700 (PDT) Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-63b620188aeso3326309b3a.0; Mon, 01 May 2023 11:45:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682966725; x=1685558725; 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=vyZZbvnIPcy9SJ2XHAqwKtaGibd+YeoRhfLb959XYfs=; b=AQH/TI8t31awy2pNsHOH16n6UDJzt4czgCXQW5e0/RrlrTD75C8c76TW+NXjXFVVf5 WmLnyOdEkSa0rU1pTCP/m/TDFEq2o957jWHrTYajYnDnC3kn8a1EE4F4E2FR3C2d4Y06 /Ne835duRBqqUoHdtisXWhwnvIfrXmTUrhzjQb+OYko7VL+L5SuWbDXRegQ/eA6WX2kp GPm18LUJmf5c+9VpiYEco78gVPDvBLxwNfUFPZ9Vs3QfJ687fmXiYrdPQBuWGWmTFdjF l/qVfcRtBR0ZCkmTXRMouDoW5XRZcb7vGCfOrlxYSUCOukb8o/phFMSI2Xnt5BVC2wHD tfMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682966725; x=1685558725; 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=vyZZbvnIPcy9SJ2XHAqwKtaGibd+YeoRhfLb959XYfs=; b=LPiB1OSnzVK0iZf9QEkbPxU110Y06cBC+jUXKvMJLL9m2n0Ac4uFZHxsbDgfwWFV69 obcENgIr0aoPOsYqhSeiy3TWP9/KEm30opBdBpOcCZw9TwNeIOKHZHT6w8A71xXJcw0T PH6S7EIqWO4cf/3VthG0oYVTyDhQZcw2f7Aqzv9fstslYl5A7nSA72BNJgDn4EeDRcM6 EjZEnX55V2kVQEZBQ2kektpvtTrxkeK5STsAkUhUFIFKOqWrqqgvQfY1NSmr+2W8j0bG TzRN++tvcXWOSSE97LtlSbDVCXHt/fDSZE3epACjZaymdxPfi5k7AIBz8X/nR5F9VcAq hMpQ== X-Gm-Message-State: AC+VfDzYc35sDg1Daw3MNOR0P4Ow0F0g1U4vXr2wFedj7Lqoms5gcied UKA2hS2We94a6YhYjSbT8Vo= X-Google-Smtp-Source: ACHHUZ67nRjak7J+u1L+vpuJQkSKVUTLHbv+8U0s5j3YKPvyWJCEaua7jxtf8bLS0fBFzFvEGGRLFg== X-Received: by 2002:a05:6a20:938e:b0:f4:d4a8:9c82 with SMTP id x14-20020a056a20938e00b000f4d4a89c82mr18999826pzh.47.1682966725083; Mon, 01 May 2023 11:45:25 -0700 (PDT) Received: from localhost ([2a00:79e1:abd:4a00:61b:48ed:72ab:435b]) by smtp.gmail.com with ESMTPSA id q7-20020a63cc47000000b0051ba4d6fe4fsm17719136pgi.56.2023.05.01.11.45.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 May 2023 11:45:24 -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 v3 8/9] drm/fdinfo: Add comm/cmdline override fields Date: Mon, 1 May 2023 11:44:54 -0700 Message-Id: <20230501184502.1620335-9-robdclark@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230501184502.1620335-1-robdclark@gmail.com> References: <20230501184502.1620335-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. v2: doc cleanups Signed-off-by: Rob Clark --- Documentation/gpu/drm-usage-stats.rst | 10 ++++++++++ drivers/gpu/drm/drm_file.c | 15 +++++++++++++++ include/drm/drm_file.h | 19 +++++++++++++++++++ 3 files changed, 44 insertions(+) diff --git a/Documentation/gpu/drm-usage-stats.rst b/Documentation/gpu/drm-= usage-stats.rst index fe35a291ff3e..03bd92b9125a 100644 --- a/Documentation/gpu/drm-usage-stats.rst +++ b/Documentation/gpu/drm-usage-stats.rst @@ -66,20 +66,30 @@ question. Unique value relating to the open DRM file descriptor used to distinguish duplicated and shared file descriptors. Conceptually the value should map = 1:1 to the in kernel representation of `struct drm_file` instances. =20 Uniqueness of the value shall be either globally unique, or unique within = the scope of each device, in which case `drm-pdev` shall be present as well. =20 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: +- drm-cmdline-override: + +Returns the client comm (executable) or cmdline override strings. Some dr= ivers +support letting userspace override this in cases where the userspace is si= mply a +"proxy". Such as is the case with virglrenderer drm native context, where= the +host process is just forwarding command submission, etc, from guest usersp= ace. +This allows the proxy to make visible the cmdline of the actual app in the= VM +guest. + Utilization ^^^^^^^^^^^ =20 - drm-engine-: ns =20 GPUs usually contain multiple execution engines. Each shall be given a sta= ble 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 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 @@ -171,20 +171,22 @@ struct drm_file *drm_file_alloc(struct drm_minor *min= or) mutex_init(&file->fbs_lock); INIT_LIST_HEAD(&file->blobs); INIT_LIST_HEAD(&file->pending_event_list); INIT_LIST_HEAD(&file->event_list); init_waitqueue_head(&file->event_wait); file->event_space =3D 4096; /* set aside 4k for event buffer */ =20 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 if (drm_core_check_feature(dev, DRIVER_SYNCOBJ)) drm_syncobj_open(file); =20 drm_prime_init_file_private(&file->prime); =20 if (dev->driver->open) { ret =3D dev->driver->open(dev, file); @@ -285,20 +287,22 @@ void drm_file_free(struct drm_file *file) drm_master_release(file); =20 if (dev->driver->postclose) dev->driver->postclose(dev, file); =20 drm_prime_destroy_file_private(&file->prime); =20 WARN_ON(!list_empty(&file->event_list)); =20 put_pid(file->pid); + kfree(file->override_comm); + kfree(file->override_cmdline); kfree(file); } =20 static void drm_close_helper(struct file *filp) { struct drm_file *file_priv =3D filp->private_data; struct drm_device *dev =3D file_priv->minor->dev; =20 mutex_lock(&dev->filelist_mutex); list_del(&file_priv->lhead); @@ -988,20 +992,31 @@ void drm_show_fdinfo(struct seq_file *m, struct file = *f) drm_printf(&p, "drm-client-id:\t%llu\n", file->client_id); =20 if (dev_is_pci(dev->dev)) { struct pci_dev *pdev =3D to_pci_dev(dev->dev); =20 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)); } =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); } EXPORT_SYMBOL(drm_show_fdinfo); =20 /** * mock_drm_getfile - Create a new struct file for the drm device * @minor: drm minor to wrap (e.g. #drm_device.primary) * @flags: file creation mode (O_RDWR etc) * diff --git a/include/drm/drm_file.h b/include/drm/drm_file.h index f77540b97cd0..233de3d252a8 100644 --- a/include/drm/drm_file.h +++ b/include/drm/drm_file.h @@ -363,20 +363,39 @@ struct drm_file { /** @event_read_lock: Serializes drm_read(). */ struct mutex event_read_lock; =20 /** * @prime: * * Per-file buffer caches used by the PRIME buffer sharing code. */ 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 */ #endif }; =20 /** * drm_is_primary_client - is this an open file of the primary node * @file_priv: DRM file * --=20 2.39.2 From nobody Thu Dec 18 19:43:32 2025 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 E9036C77B73 for ; Mon, 1 May 2023 18:46:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231482AbjEASqH (ORCPT ); Mon, 1 May 2023 14:46:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232684AbjEASpk (ORCPT ); Mon, 1 May 2023 14:45:40 -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 6D8822D5E; Mon, 1 May 2023 11:45:28 -0700 (PDT) Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-63b5c830d5eso1970884b3a.2; Mon, 01 May 2023 11:45:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682966728; x=1685558728; 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=Ej3O8h3ZWoAQLcK8hFb5Wz4fSCAI1uIdFPtS/Ymi5AQ=; b=JfC97d9J/pcL5yhiMnjDyNh4CwgNnz5usEsDqGGVxix+juBHtF7xvL/gwq/cTnbIq+ QL1g8DGEL7BO3qNCQTgUHgzjNol8Pm4CN5SZpCeCdzCU4bIP1upsUloPENQI95r+3M+q vEw4GkunXAKMpq+iI781Qo5SNea6fmQgYx5lWlT1MSHXPw++AOPbxGiI1kylS31CmEPz haJ0ZSx4Evqiphrz1VMJBtR4e1Inkb9UHPUnwCmxCyqITmudcW+APDDX59qQp0R3R7Ud m+T75jT5Iy7xGr0lRffMTckGgdUb3b4Hn3Rh5R42SZkfW++4bM80lnob3bjEVumZtrCk Kthw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682966728; x=1685558728; 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=Ej3O8h3ZWoAQLcK8hFb5Wz4fSCAI1uIdFPtS/Ymi5AQ=; b=cNdzEeHRp2iZWgt7u/J4oGdR6+BYKk5L3K/4bKkVUbZhf/Yp0RhXDUU3e9DwbLwXz2 /EZpUiJ4ZhisBK11JxtWm2Kd/3h2bIsRNCY0RRCpp3YDC7JZsHWMMicAGEtLCDhxRD/5 8N+gn75FcbosCMX1OBJ9T/caMTjgGc+ECl6iDUFPuLPqbScSfsj1WvHfd/fDHDYK+uj5 NfqJOk9F0GMqaoTweO4CcLjqaaFyGSFDrvTNQ+uumpGuKa/yxseH37u8V2eByEOBAYhJ ZV0XfmdzD9Z+Y8iZi4/HJtY3lrlvKoDCyAIZcyiiQcLkbbMKgJnrR9gVHSohR5FMwV05 dgNw== X-Gm-Message-State: AC+VfDwawWPLgFbWm8KhGxAqWbWZtf/NtXvTNVQWcKIt/0e21yuaPJTF /FX/SIT5PUcDqYmZQM7WyvQ= X-Google-Smtp-Source: ACHHUZ6xjC+IXT/sFRGOEvj/MjCi4WpmFr5TYXENVRy6LJGbRoVdL674AZUJCcS7wUsvtrDT8RZ94A== X-Received: by 2002:a17:902:d505:b0:1a9:9c5d:9fac with SMTP id b5-20020a170902d50500b001a99c5d9facmr18578911plg.33.1682966727756; Mon, 01 May 2023 11:45:27 -0700 (PDT) Received: from localhost ([2a00:79e1:abd:4a00:61b:48ed:72ab:435b]) by smtp.gmail.com with ESMTPSA id c24-20020a170902d91800b001ab05828797sm416775plz.179.2023.05.01.11.45.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 May 2023 11:45:27 -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 , Elliot Berman , Maximilian Luz , Konrad Dybcio , linux-arm-msm@vger.kernel.org (open list:DRM DRIVER FOR MSM ADRENO GPU), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v3 9/9] drm/msm: Wire up comm/cmdline override for fdinfo Date: Mon, 1 May 2023 11:44:55 -0700 Message-Id: <20230501184502.1620335-10-robdclark@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230501184502.1620335-1-robdclark@gmail.com> References: <20230501184502.1620335-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 @@ -9,20 +9,21 @@ #include #include #include #include #include #include #include #include #include #include +#include #include "adreno_gpu.h" #include "a6xx_gpu.h" #include "msm_gem.h" #include "msm_mmu.h" =20 static u64 address_space_size =3D 0; MODULE_PARM_DESC(address_space_size, "Override for size of processes priva= te GPU address space"); module_param(address_space_size, ullong, 0600); =20 static bool zap_available =3D true; @@ -391,47 +392,68 @@ int adreno_set_param(struct msm_gpu *gpu, struct msm_= file_private *ctx, return -EINVAL; break; default: if (len !=3D 0) return -EINVAL; } =20 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) return -ENOMEM; =20 if (copy_from_user(str, u64_to_user_ptr(value), len)) { kfree(str); return -EFAULT; } =20 /* 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) { paramp =3D &ctx->comm; } else { paramp =3D &ctx->cmdline; } =20 kfree(*paramp); *paramp =3D str; =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: if (!capable(CAP_SYS_ADMIN)) return -EPERM; return msm_file_private_set_sysprof(ctx, gpu, value); default: DBG("%s: invalid param: %u", gpu->name, param); return -EINVAL; } 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 @@ -574,20 +574,21 @@ static int context_init(struct drm_device *dev, struc= t drm_file *file) struct msm_file_private *ctx; =20 ctx =3D kzalloc(sizeof(*ctx), GFP_KERNEL); if (!ctx) return -ENOMEM; =20 INIT_LIST_HEAD(&ctx->submitqueues); 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); file->driver_priv =3D ctx; =20 ctx->seqno =3D atomic_inc_return(&ident); =20 return 0; } =20 @@ -596,20 +597,21 @@ static int msm_open(struct drm_device *dev, struct dr= m_file *file) /* For now, load gpu on open.. to avoid the requirement of having * firmware in the initrd. */ load_gpu(dev); =20 return context_init(dev, file); } =20 static void context_close(struct msm_file_private *ctx) { + ctx->file =3D NULL; msm_submitqueue_close(ctx); msm_file_private_put(ctx); } =20 static void msm_postclose(struct drm_device *dev, struct drm_file *file) { struct msm_drm_private *priv =3D dev->dev_private; struct msm_file_private *ctx =3D file->driver_priv; =20 /* 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 @@ -352,20 +352,30 @@ struct msm_gpu_perfcntr { * @seqno: unique per process seqno */ struct msm_file_private { rwlock_t queuelock; struct list_head submitqueues; int queueid; struct msm_gem_address_space *aspace; 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: * * The value of MSM_PARAM_SYSPROF set by userspace. This is * intended to be used by system profiling tools like Mesa's * pps-producer (perfetto), and restricted to CAP_SYS_ADMIN. * * Setting a value of 1 will preserve performance counters across * context switches. Setting a value of 2 will in addition * suppress suspend. (Performance counters lose state across --=20 2.39.2