From nobody Thu Dec 18 13:14:08 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 ED2EDC77B7C for ; Wed, 24 May 2023 16:01:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232084AbjEXQBW (ORCPT ); Wed, 24 May 2023 12:01:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238173AbjEXQAw (ORCPT ); Wed, 24 May 2023 12:00:52 -0400 Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B9BB10C8; Wed, 24 May 2023 09:00:12 -0700 (PDT) Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-64d41d8bc63so880298b3a.0; Wed, 24 May 2023 09:00:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684944011; x=1687536011; 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=eSswnMLwwEGQnN2xlrnUru6iM+0TXo2/wbtbw8wTOo0=; b=B+Bsw1NUnpKejAiuRxs86EcWG/xC9B2nB98H9nqq+mvMU2qeXTEIzfpT40bDW4kzZI u3GG4tS+dL+RvZBM46eFDEu6To+siU2UEFVnq9Bujpx92iJe+n+uA/IY45jlFjMtjE6H UJsf9+3XGmpuM4rFzC8REjnC2Umj4okDLEFBYelLZObja7FuoIUCEpkvIz2DAppfXZa3 68gdUsJhcWKUZ30KLvw5you3T0dIt93E+bVv2hac/q3ga0plJP1eEcYYuBHzwl5Ag3/q kSZZCx3wv+YvGhO+3p/S8wzKUK9RlU8Io1cwT+nP3Ss7IGdLZjNCXIQi5Tb+hoOk5u9P 7mBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684944011; x=1687536011; 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=eSswnMLwwEGQnN2xlrnUru6iM+0TXo2/wbtbw8wTOo0=; b=LcxNfvS02mYDDK1Lo7dg5+z4BbCz0jk50xpMHja8Xjyia9eexofgyfAuab3A9WrmUp iCxM7/WyXi5yFAdnFgNBvIxt49i9axS9hHs5GIeFnzQjG1/nGaw2bbkVozSTZfsZeo4C 4llFAeaqE6W+tkT+cGYGGdvC56CDWbi3Ocf56hWejXiHcX5RY60Sxe9SYGd8zDcZWeun SogMjz/Q/4BmvGJluZZau0xpVHyelC92hqErgmus3t0NwRdq02nl2L5OCYNNyjvoOx+L BYeseqs054aEvyThHcLtroIJQHw9GrTWnA3w9Y8HrzaYo5+oj0aNq5Ao3TPhjO03ABNK qHAg== X-Gm-Message-State: AC+VfDxZ1+8hfUfEl1+vW6I+m6olUC4qT/UG1s/Uj0/VRbN7dfNM+l0o SjZiQ25+KNiHbfInD4d/eP8= X-Google-Smtp-Source: ACHHUZ4B7uPtJ7sN4k/tvRDpTXNjWvoZAnRI7XqCVYOuMgRJiNLAZbt9+ZqdTUOnaHPAUA2M6EXipQ== X-Received: by 2002:a17:902:c402:b0:1ac:b259:87ea with SMTP id k2-20020a170902c40200b001acb25987eamr25487162plk.0.1684944011561; Wed, 24 May 2023 09:00:11 -0700 (PDT) Received: from localhost ([2a00:79e1:abd:4a00:61b:48ed:72ab:435b]) by smtp.gmail.com with ESMTPSA id jk17-20020a170903331100b001ab1d23c44bsm8979421plb.181.2023.05.24.09.00.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 May 2023 09:00:11 -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 , Dave Airlie , 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 v5 1/7] drm/docs: Fix usage stats typos Date: Wed, 24 May 2023 08:59:31 -0700 Message-Id: <20230524155956.382440-2-robdclark@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230524155956.382440-1-robdclark@gmail.com> References: <20230524155956.382440-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 Acked-by: Dave Airlie --- 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.40.1 From nobody Thu Dec 18 13:14:08 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 E7EB3C77B7A for ; Wed, 24 May 2023 16:01:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236359AbjEXQBZ (ORCPT ); Wed, 24 May 2023 12:01:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238267AbjEXQAz (ORCPT ); Wed, 24 May 2023 12:00:55 -0400 Received: from mail-pg1-x52a.google.com (mail-pg1-x52a.google.com [IPv6:2607:f8b0:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A709910CF; Wed, 24 May 2023 09:00:15 -0700 (PDT) Received: by mail-pg1-x52a.google.com with SMTP id 41be03b00d2f7-51b0f9d7d70so438097a12.1; Wed, 24 May 2023 09:00:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684944015; x=1687536015; 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=7/m5y9DMBAGNOMht9FaF2vJN36JyHjRD9qCEwtOdPVI=; b=L8hNGSICE/y/nRGAQSHMJZxKPdKQY4FYCJuUBDFNI+lBh9XwgJXWj1MTK261vpT2/K jtkGpVeK2J8cN8NpfKHIcmaDuURs1mPLgUztOiDhp3ShT4g23biQjG6LVnCoh4Y5ufug 5g4/r35PXOttozl/FpTusNYuR9X/LmpiRX/z4tKuF9Uk2DHKZtJg2MPwo11nr1ErQFOn aCk7xWcaFff7yKrZY9K5IsPYZLoucw2Gd8pGycY8/c/T7fuBdkImH58/PuVAJBNEL6Qg 6eUMjLayFAICkxsxSWnQul10VkazeTO9UIrOzZLqRN83OYlB2OUAjjVwThbgv5ghAi8H q0JA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684944015; x=1687536015; 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=7/m5y9DMBAGNOMht9FaF2vJN36JyHjRD9qCEwtOdPVI=; b=ZFLXtV35t2reBXiAixDoEyHXk09fazNzvr/xg0NbrzdMf/h2Y6VQLB16xALg4ymgew 2ibiDCtu38pMb3PGwUJwysOGPU/9zkR0vRgMRrHrfCwj8IN5klo364XHkR2xGry4swXx tYz9eD0G3+mRiZ8g5m4mT+6lTW8SSxPygpi0A8pxYPhZI2chxyHphgdyPP5v74IAqWtf i/qENx2P2u/HXP35fVjrPT1id0IAC+F2lSpy46+pU9oB9sa1RMpiuoSetpD5a2XQkLp3 lX4puJ7B6S5i1iYCyb8QvEnmYD90fnA6JUHXQ5EchIR+BQRwWuDt32o7rR0sGuVZiPr5 SVWQ== X-Gm-Message-State: AC+VfDx1jhdiUqG1uPcnLkTF94/Cr6YIt9nh0ZgbVH3n2qyR8Juq78OW VjA+W2igaql9foIhJ+Ql9HtUBa1FDro= X-Google-Smtp-Source: ACHHUZ5YU5N8QTK4ZBBBpjdCK9cdIFp3zFxCoHqfb2M0Eo2l5hXrUlfHUARcaMsKKWFPJi/3lOzliw== X-Received: by 2002:a17:902:f681:b0:1af:e295:ad68 with SMTP id l1-20020a170902f68100b001afe295ad68mr2278321plg.30.1684944014575; Wed, 24 May 2023 09:00:14 -0700 (PDT) Received: from localhost ([2a00:79e1:abd:4a00:61b:48ed:72ab:435b]) by smtp.gmail.com with ESMTPSA id t22-20020a1709028c9600b001afebec96basm264091plo.148.2023.05.24.09.00.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 May 2023 09:00:14 -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 , Dave Airlie , 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 v5 2/7] drm: Add common fdinfo helper Date: Wed, 24 May 2023 08:59:32 -0700 Message-Id: <20230524155956.382440-3-robdclark@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230524155956.382440-1-robdclark@gmail.com> References: <20230524155956.382440-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 v3: Rebase on drm-misc-next Reviewed-by: Daniel Vetter Signed-off-by: Rob Clark Acked-by: Dave Airlie --- 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 c1018c470047..37b4f76a5191 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_tgid(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 b419c59c4bef..89e2706cac56 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 ecffe24e2b1b..7d9b3c65cbc1 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; @@ -431,14 +434,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.40.1 From nobody Thu Dec 18 13:14:08 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 8E380C7EE23 for ; Wed, 24 May 2023 16:01:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238365AbjEXQB1 (ORCPT ); Wed, 24 May 2023 12:01:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238290AbjEXQA5 (ORCPT ); Wed, 24 May 2023 12:00:57 -0400 Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5A2B10D5; Wed, 24 May 2023 09:00:17 -0700 (PDT) Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1ae52ce3250so4166285ad.2; Wed, 24 May 2023 09:00:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684944017; x=1687536017; 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=qZdffD1rbmzqNwR9ysIIe02HLLzxNGaBoHLlHROGv/g=; b=Lr/1jT6n8l1wbPqAqWhMiQRhI6C6gqZlwmYElMzq3VCGGrIBhTCYH1fkG+SFK/cALY lG59mSrbKE+CTFADfy8folwN8YsbdrvBSxsNt+0qu0JBkta70l5Xdzc+drKUHNVErqLF Zz4bxqw6wRlNxkG09h1w4oD4iZo25Hd7O/38LHooqpDz0LOE+35F5v4G0GZcNa4+6ksL rDPWVW5Td9Dkyw5Fhza9RHZvyhEiv2qwwfeHFVLUO0l1MqcpjB9diguzsduFp9oDX0/5 XkPXI6C1tEy3U/WYiw4NgpfRyowtvRjjH8Mp6GguV/WUfzAy+nibovNX2vJnMWrtD+v9 6SGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684944017; x=1687536017; 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=qZdffD1rbmzqNwR9ysIIe02HLLzxNGaBoHLlHROGv/g=; b=b/Lu0LUA6CJkOIlBYXaLPhndbXrW4veadGMrlMlnzW3ZJXwVYKy9eKEMMBC38bqDhJ ovlQJ8FneCGFt5JUM6kLhgH+tA5z1IgObCoomU9hV5au3a7yi1ilm49oqUCDcpUJhDR+ YDe5mpz/5pz54CFo+k5BN/8iXb8rfL9KSh3YdRvvVvXWNlPEp5TYWwGnwGg8fw1fAWdV r0x6eIufTbPUJWWlzvFHPOXtqqLgOrCobe10IlCk91P5G41+sQELUXIt3ZqqXtLlOPnO jnfoQZQkGmi1fmlSLDNnflDCtaP4cJKWK7n8ZJ1S0+Cb2vtck4n4WdetRO7xQtylSLJ1 beZQ== X-Gm-Message-State: AC+VfDwJh8AKf2BQQc1nCpkw1es4RHX/p31cpW2LX1aBSDnu7Ag9BcVI 4ex/qSX4bx1ERj5KTFzED/Y= X-Google-Smtp-Source: ACHHUZ5b/PXeIbi81JP2M0rufyrxO74igPjls7nP2EP/NzkiZARbH215dXzrWXuI4QDdzWnY7iSH/Q== X-Received: by 2002:a17:902:e74f:b0:1af:ccc9:ce4a with SMTP id p15-20020a170902e74f00b001afccc9ce4amr6603942plf.25.1684944017044; Wed, 24 May 2023 09:00:17 -0700 (PDT) Received: from localhost ([2a00:79e1:abd:4a00:61b:48ed:72ab:435b]) by smtp.gmail.com with ESMTPSA id 19-20020a170902c21300b001ae626afed4sm8933758pll.220.2023.05.24.09.00.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 May 2023 09:00:16 -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 , Dave Airlie , 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 v5 3/7] drm/msm: Switch to fdinfo helper Date: Wed, 24 May 2023 08:59:33 -0700 Message-Id: <20230524155956.382440-4-robdclark@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230524155956.382440-1-robdclark@gmail.com> References: <20230524155956.382440-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. v2: Rebase on drm-misc-next Signed-off-by: Rob Clark Reviewed-by: Dmitry Baryshkov Acked-by: Dave Airlie --- 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 060c7689a739..02fd6093f9b0 100644 --- a/drivers/gpu/drm/msm/msm_drv.c +++ b/drivers/gpu/drm/msm/msm_drv.c @@ -1050,56 +1050,55 @@ 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, .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 26ebda40be4f..c403912d13ab 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.40.1 From nobody Thu Dec 18 13:14:08 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 7B57EC7EE2D for ; Wed, 24 May 2023 16:01:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238152AbjEXQBs (ORCPT ); Wed, 24 May 2023 12:01:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238004AbjEXQBM (ORCPT ); Wed, 24 May 2023 12:01:12 -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 5E4B01730 for ; Wed, 24 May 2023 09:00:31 -0700 (PDT) Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-64d2467d640so1214470b3a.1 for ; Wed, 24 May 2023 09:00:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684944030; x=1687536030; 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=fgPqvCuDomCcpddhPDuK2cRaX+7yovp8gvIn/0ROM8o=; b=RWgC+TkHkjKHT+CRTZboyOkJAe0MhVmLlogkcVtrAP5M9V4/3hVzOnHCwy30ZsQ6qW 3F/kk34xKaTJllzDMw/89vq7P3ud/ugGD6xq93Kqnr4s6to/vbTGBQ4SbW3YfYjJ0lgC trdADqdmQWIX58ByAYBJ8gbJUsd+t44HUS1ljf0WXyreJcdN37oNiCdSz2fkw+KjzA/B JMAetRMqJQdmfbNH98iEwu8FCnaoy4EABiyzkc6e0oglk4KbVQWXRlPubMJyeg7XaVhA tcSMxJhtse24tUVk2ITvFpXRciAb7zsVg1H/sKCmg4edZhFIF+yMFNVpUF78+9HniOoQ 9AHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684944030; x=1687536030; 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=fgPqvCuDomCcpddhPDuK2cRaX+7yovp8gvIn/0ROM8o=; b=TZURJ9nvcw0AgpfyLUdBsV/qAS2dTvSYx6032IQndS99aaAzE6jsLL+u25YLiwU53N 5ImC4T44Psk/yFWIC9eqFUR29zbTLpyXu11CqxvCf4Xu4uUA7FzcUzK6usImLxoDh+7F VyYXZufyosyOG4YTfzB0JVhwmdtVXXE418ZehQ5jEais0po9DfWwuHJv57F7KvzYom3z CM/sSxjoOWErCt8h2UArRRUI4SEXSR75FG2ZKbDVJADcjVS0KY0ndw37io+uYQP4DvjH xgBMhJdHZKttn36XnasF3VrI/80qKPkWETzdbFH4feQaCg0utBShdmvxIxhkA/UBcMD8 ZHcw== X-Gm-Message-State: AC+VfDxn33OsLQidi2CQ4bJ70p9dzPSVMOTcn80wBqbAbQLQ69kUuBv1 lK6ysiEuxUt44lQYYqeWEUM= X-Google-Smtp-Source: ACHHUZ7nmLnzIpMDtOUnPkTfQof/nxgZRpx7CECCrwNmb2fR4ergpfoLMNL7O5fM+bih4y3CQJTGAw== X-Received: by 2002:a05:6a00:14c2:b0:643:59cd:6cad with SMTP id w2-20020a056a0014c200b0064359cd6cadmr4023754pfu.24.1684944030032; Wed, 24 May 2023 09:00:30 -0700 (PDT) Received: from localhost ([2a00:79e1:abd:4a00:61b:48ed:72ab:435b]) by smtp.gmail.com with ESMTPSA id b1-20020aa78101000000b0063b85893633sm7542046pfi.197.2023.05.24.09.00.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 May 2023 09:00:29 -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 , Dave Airlie , Alex Deucher , "Pan, Xinhui" , David Airlie , =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= , Guchun Chen , Mario Limonciello , YiPeng Chai , =?UTF-8?q?Michel=20D=C3=A4nzer?= , Jim Cromie , Srinivasan Shanmugam , 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 v5 4/7] drm/amdgpu: Switch to fdinfo helper Date: Wed, 24 May 2023 08:59:34 -0700 Message-Id: <20230524155956.382440-5-robdclark@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230524155956.382440-1-robdclark@gmail.com> References: <20230524155956.382440-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 v2: Rebase on drm-misc-next Signed-off-by: Rob Clark Reviewed-by: Christian K=C3=B6nig Acked-by: Dave Airlie --- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 3 +- drivers/gpu/drm/amd/amdgpu/amdgpu_fdinfo.c | 32 ++++++++++------------ drivers/gpu/drm/amd/amdgpu/amdgpu_fdinfo.h | 2 +- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/= amdgpu/amdgpu_drv.c index b1ca1ab6d6ad..1b46e7ac7cb0 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c @@ -2740,21 +2740,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 @@ -2795,20 +2795,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 c57252f004e8..13d7413d4ca3 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 struct amdgpu_mem_stats stats; ktime_t usage[AMDGPU_HW_IP_NUM]; uint32_t bus, dev, fn, domain; unsigned int hw_ip; int ret; =20 @@ -80,38 +79,37 @@ 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", stats.vram/1024UL); - seq_printf(m, "drm-memory-gtt: \t%llu KiB\n", stats.gtt/1024UL); - seq_printf(m, "drm-memory-cpu: \t%llu KiB\n", stats.cpu/1024UL); - seq_printf(m, "amd-memory-visible-vram:\t%llu KiB\n", + drm_printf(p, "pasid:\t%u\n", fpriv->vm.pasid); + drm_printf(p, "drm-driver:\t%s\n", file->minor->dev->driver->name); + drm_printf(p, "drm-pdev:\t%04x:%02x:%02x.%d\n", domain, bus, dev, fn); + drm_printf(p, "drm-client-id:\t%Lu\n", vm->immediate.fence_context); + drm_printf(p, "drm-memory-vram:\t%llu KiB\n", stats.vram/1024UL); + drm_printf(p, "drm-memory-gtt: \t%llu KiB\n", stats.gtt/1024UL); + drm_printf(p, "drm-memory-cpu: \t%llu KiB\n", stats.cpu/1024UL); + drm_printf(p, "amd-memory-visible-vram:\t%llu KiB\n", stats.visible_vram/1024UL); - seq_printf(m, "amd-evicted-vram:\t%llu KiB\n", + drm_printf(p, "amd-evicted-vram:\t%llu KiB\n", stats.evicted_vram/1024UL); - seq_printf(m, "amd-evicted-visible-vram:\t%llu KiB\n", + drm_printf(p, "amd-evicted-visible-vram:\t%llu KiB\n", stats.evicted_visible_vram/1024UL); - seq_printf(m, "amd-requested-vram:\t%llu KiB\n", + drm_printf(p, "amd-requested-vram:\t%llu KiB\n", stats.requested_vram/1024UL); - seq_printf(m, "amd-requested-visible-vram:\t%llu KiB\n", + drm_printf(p, "amd-requested-visible-vram:\t%llu KiB\n", stats.requested_visible_vram/1024UL); - seq_printf(m, "amd-requested-gtt:\t%llu KiB\n", + drm_printf(p, "amd-requested-gtt:\t%llu KiB\n", stats.requested_gtt/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.40.1 From nobody Thu Dec 18 13:14:08 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 EBA7EC7EE23 for ; Wed, 24 May 2023 16:01:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237275AbjEXQBv (ORCPT ); Wed, 24 May 2023 12:01:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238221AbjEXQBP (ORCPT ); Wed, 24 May 2023 12:01:15 -0400 Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46D0C173F; Wed, 24 May 2023 09:00:37 -0700 (PDT) Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1ae851f2a7dso3547295ad.0; Wed, 24 May 2023 09:00:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684944035; x=1687536035; 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=mSsQ3aGvmnPAex9q1f35gfIysAp2jDmPNa2ojXepp/s=; b=daZaE0EeAHwkdRv2C6j9IV3QCFFXw9Wh5HyGxmD4X6nO6OMMHj+iZ7Dip1JNUN5nI1 O0K9zqNhvrWWur2nKL1lF4VbYU2yQTpb9Ajy5uJvXEewQjcOpCWoB38CLE178W2pL1Cn aaQUiGcFKz4+W8A+ut9TO5H9ySXlv+pzSnefk1RoPC47mZrGb2wclTKU7eGzyVSXgGKk EfIF/22EABy6uvgsTmi4m0RipfYboNaG7efpvxhZywiET9SqnjFzYsCHEp9fQiFL9m5l ciH7Uh2jUzzz++TrlgZLai0ZyXGOWLAwvCbRlh/w0WvhZ42rbcrGMOUUDFCmsINKwzT2 1Few== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684944035; x=1687536035; 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=mSsQ3aGvmnPAex9q1f35gfIysAp2jDmPNa2ojXepp/s=; b=b58vAR6XlX+z/0je69QYaJW8ukDK6dOTiZhVzLEDqC1ywMCOyRK5sDSKeyTRLmLYNF SNAAQEa3PpQxRstjqJnz9BC6oHQB1GEVkxSTor2AjexYjHFnmDa54ElGRandM4ZoWmq0 MqveQvxE24N0wjb31b5a9OLEiWMIgxTQHFukZNN5z9AynKFzVfP4u0EgfG18bI8JpOgZ Y3o6AFKhuYHeytpIID7mGe9Vy19h8PAsCoNcpRnh/bRiIAydO43jpVfN0UL1EejCKXjd RRrhX5CAaSGKYhaMIVsAESfwpvxB44dJUenUcrL4Jn9RFTGb/DVV1D3hDDi0neajWmGf aorA== X-Gm-Message-State: AC+VfDzoHOtPI6GfUJKXNQdehH7KPQRgjpEoY3EGsQNg5Wc3vLfwzOf6 /+X/yTYUgPHRean9Z514LJ4= X-Google-Smtp-Source: ACHHUZ7geA+6WGmVWjO9aZlyK6YbXch4LoyqXgsv1ysgMkQF2FWLqTSSwww3g7YRaHTpyefs2NRP6w== X-Received: by 2002:a17:903:8c4:b0:1ac:b03c:a58e with SMTP id lk4-20020a17090308c400b001acb03ca58emr22930072plb.25.1684944033892; Wed, 24 May 2023 09:00:33 -0700 (PDT) Received: from localhost ([2a00:79e1:abd:4a00:61b:48ed:72ab:435b]) by smtp.gmail.com with ESMTPSA id g7-20020a1709029f8700b001ac4d3d3f72sm8841588plq.296.2023.05.24.09.00.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 May 2023 09:00:33 -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 , Tvrtko Ursulin , Dave Airlie , 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 v5 5/7] drm: Add fdinfo memory stats Date: Wed, 24 May 2023 08:59:35 -0700 Message-Id: <20230524155956.382440-6-robdclark@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230524155956.382440-1-robdclark@gmail.com> References: <20230524155956.382440-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 v6: Actually use u64, bit more comment docs Signed-off-by: Rob Clark Reviewed-by: Emil Velikov Reviewed-by: Daniel Vetter Acked-by: Tvrtko Ursulin Acked-by: Dave Airlie --- 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 | 32 +++++++++ 4 files changed, 200 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 37b4f76a5191..883d83bc0e3d 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, u64 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%llu%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 7d9b3c65cbc1..966912053cb0 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). @@ -434,15 +435,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 { + u64 shared; + u64 private; + u64 resident; + u64 purgeable; + u64 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 b8efd836edef..bbc721870c13 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,33 @@ 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. + * + * Called by drm_show_memory_stats(). + */ + 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.40.1 From nobody Thu Dec 18 13:14:08 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 A3C6BC7EE23 for ; Wed, 24 May 2023 16:01:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238449AbjEXQB4 (ORCPT ); Wed, 24 May 2023 12:01:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238426AbjEXQBS (ORCPT ); Wed, 24 May 2023 12:01:18 -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 30AEC13A; Wed, 24 May 2023 09:00:44 -0700 (PDT) Received: by mail-pg1-x534.google.com with SMTP id 41be03b00d2f7-53482b44007so346235a12.2; Wed, 24 May 2023 09:00:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684944037; x=1687536037; 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=Jm+2eVuJ9R4bEqEphmNY+ONsUg1tV+e6toSMo5kMY6k=; b=q1VpPZyD+nYPnYezdhRT00RybGny9C4lNkC4miOFMe4161KJ43bBPpVu95XgkMlmxL mX4VNz2KWsGQyqERKRIyjzfl/4ZaXfv1/GdTv8+Qk8Xa2Ir0qqa6HUJ0uBtP7ymnAlBs ioz7ArkMdhtQdnfnGmwU40avtqQzPNgU5GhZMKPlUfPLkY8Wcd9fqL793zMPh9XfceZi zPFkwlGVMNCRsRRsWGwK/RIs1QKX/AImVQ85WSwxdwJgG0eyDUTCt2MGkKQhcl8Z7byP sKaZmP/NMt7yyRT8guvwS3r7Cig36TA393sasu1tae77JZ6e+RFnrtSh8Dc8b1GRQuG2 VGsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684944037; x=1687536037; 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=Jm+2eVuJ9R4bEqEphmNY+ONsUg1tV+e6toSMo5kMY6k=; b=kFF/looAYSS8jrgrmSH+HNoYjcbp9GN6MKw6ZhIz+qnIQSekgZcnF1tcoPg7IAUrMc 8qIpvtkAFgeA5UYlejhZGZ5FBmtOAXeWQ3QtdKhqxe3JA94YLSZFlzYwKmqbuubzBgJw LK1/vfEfqtpsQSxm0KN+GA1PzKsPD6uHi3Ify7d69ZcU5QdU7zaImpdRpjywHwlvMr4c p4rQEptUIYEvC+Ml05/7nWDsH8mqpq1oAMKoE1DMjSUZE3cDYwAMA0OwZ5/Zh7G2akwo Mco6tKymaEUfcPM1e94Szhvtmc04zhUcKt0fJ4EMHUPRanTmOrD4MYwhoAkNgaAjXNi8 7QIQ== X-Gm-Message-State: AC+VfDzllAhSVw5W3DbQuwyMcwFJjybK39qAyfAZ3UuHf4hVTTASX17q tMkKEsecdk/7GQ8IYhffwYM= X-Google-Smtp-Source: ACHHUZ5/AKM5rkM7PzF/QTY24ajzauhpViEEpLlFzZy/a838vAMr/lNMwq5NczwDPFVd7bvqBTk5yQ== X-Received: by 2002:a17:902:a989:b0:1af:e63f:5bb1 with SMTP id bh9-20020a170902a98900b001afe63f5bb1mr1739595plb.7.1684944036844; Wed, 24 May 2023 09:00:36 -0700 (PDT) Received: from localhost ([2a00:79e1:abd:4a00:61b:48ed:72ab:435b]) by smtp.gmail.com with ESMTPSA id x1-20020a170902a38100b001ae6b4b28adsm9041318pla.130.2023.05.24.09.00.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 May 2023 09:00:36 -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 , Dave Airlie , 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 v5 6/7] drm/msm: Add memory stats to fdinfo Date: Wed, 24 May 2023 08:59:36 -0700 Message-Id: <20230524155956.382440-7-robdclark@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230524155956.382440-1-robdclark@gmail.com> References: <20230524155956.382440-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 Acked-by: Dave Airlie --- 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 02fd6093f9b0..58264ff2c4b1 100644 --- a/drivers/gpu/drm/msm/msm_drv.c +++ b/drivers/gpu/drm/msm/msm_drv.c @@ -1059,20 +1059,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 db6c4e281d75..c32264234ea1 100644 --- a/drivers/gpu/drm/msm/msm_gem.c +++ b/drivers/gpu/drm/msm/msm_gem.c @@ -1089,34 +1089,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.40.1 From nobody Thu Dec 18 13:14:08 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 4830DC77B7A for ; Wed, 24 May 2023 16:02:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229592AbjEXQB7 (ORCPT ); Wed, 24 May 2023 12:01:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238427AbjEXQBS (ORCPT ); Wed, 24 May 2023 12:01:18 -0400 Received: from mail-pg1-x52f.google.com (mail-pg1-x52f.google.com [IPv6:2607:f8b0:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E45C186; Wed, 24 May 2023 09:00:44 -0700 (PDT) Received: by mail-pg1-x52f.google.com with SMTP id 41be03b00d2f7-53eee18a192so426895a12.3; Wed, 24 May 2023 09:00:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684944039; x=1687536039; 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=ex5RgcOGAy76xADxIoHPP5AhCcNedegsTMiHxYneYvA=; b=AESaB1MjaCZtF0RCoh9e77N5vnrWapnBypJL1aCtjHEnEZb14XPLFFeEJGplihdCB9 xcEovBnrNPwzC7actG2PNYtsxUMNUvPyjKjRRUrpLAdhSU5qs/L1njJWvayRfHp6l+gz DqdY/B8iS7/N4Cz3Mh8phN8N4jdj1+hGp50cUv08D3FxbcIRaj092Fo6DNoRQFZ2kjEG FdlR6Vkl83wdnxOKU0/1vIWWJhcfMA+VF0M9QMBpwhVsYaADIYuYWXvuGLJxUk/v3JW0 4nYEjVSCl7hMOEonBURtneMlQ5nePBIVU79XIPcNi5N5riSozrlNxKYUZdorCfnJ7/CW cgpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684944039; x=1687536039; 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=ex5RgcOGAy76xADxIoHPP5AhCcNedegsTMiHxYneYvA=; b=O4ZkO9fo0HPxLE0x6WK4gELXFwuhQ/lwwb9tCxR+96tyMFMTw/WzJWZZYPizfebulr v0EfS8cqlV8kjRKBcVcTeNUKYXHl4qqJ5JbcGkNHxjD85bf0dPi4dXVO7hv5ifGyp6A6 lA7E7umWcuB77x2zGsgSj6z9R7TjpKD0ByXUHLJGxowcI+yMRne/o1vAIxGeF+TXw+lt TeYobUjLkZdLvHjilrGSXU4w4kxSNl26vqDMQb+mnnPvtBUM4q6FPiUIcdizxjz7fG2z lmHPyJAn/OKX3BB9uLs6E2BddvaAGK297z4UpWGJWe5cshRt4nB5HspI4xMyGLBwyftq FZnw== X-Gm-Message-State: AC+VfDxaKO+lgZPfBBmPvd5lXgQlHXY8+VP4TbVJlyOY5q7QedrpNkjp kCk9J75ZD8xAQdEMzXcuJdQ= X-Google-Smtp-Source: ACHHUZ7onA/29uMKwZvh+T+iC1Z1taVKK6Wncz/arA/4C9WyRm6daOgouT46veHHvrkbpt6hDF5Vwg== X-Received: by 2002:a17:902:748c:b0:1a9:21bc:65f8 with SMTP id h12-20020a170902748c00b001a921bc65f8mr16308136pll.11.1684944039060; Wed, 24 May 2023 09:00:39 -0700 (PDT) Received: from localhost ([2a00:79e1:abd:4a00:61b:48ed:72ab:435b]) by smtp.gmail.com with ESMTPSA id e16-20020a17090301d000b001afccb29d69sm3698533plh.303.2023.05.24.09.00.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 May 2023 09:00:38 -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 , Dave Airlie , 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 v5 7/7] drm/doc: Relax fdinfo string constraints Date: Wed, 24 May 2023 08:59:37 -0700 Message-Id: <20230524155956.382440-8-robdclark@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230524155956.382440-1-robdclark@gmail.com> References: <20230524155956.382440-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 Acked-by: Dave Airlie --- 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.40.1