From patchwork Mon May 15 14:30:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 13241592 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BC2E3C7EE23 for ; Mon, 15 May 2023 14:30:55 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6ACCB10E1F4; Mon, 15 May 2023 14:30:51 +0000 (UTC) Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9726E10E1F4; Mon, 15 May 2023 14:30:49 +0000 (UTC) Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-1aad5245571so88071495ad.1; Mon, 15 May 2023 07:30:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684161048; x=1686753048; 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=pKiFi7cchV1/CNWFldN1e7tKyJWR1+z9tt8oV8Nq+So=; b=U7v8btQ5/QYmSL94U2iZQqrHenblyfkJ8OvgC5n+sjZ3Yta/A/713ZWWd8pOxSGWgm hkW4A6Mqqszo8a7liLUH4loXS6zDTc5SGqD08T8ai5OvB6dpEpWOI+15JII8cSgX2gin Q7HBknzSE2y1ohrsHJaj5tvtoCPDpx4nCyqIVVYyKJAPzJBGKcWR7Bezgz1+IBk35Uny OR6bCaqsF7szeXVgcJNCZQYU0Oeu977lzX6PidABEwVAPaKNvSvR5yMVrxQQLf9S2tE3 DzBLIxUaRY/UoBZ/KLEELQQCumpVBy//COL1zL1x/rJ83RYi/aA+6ELUZ10zhChOCogd dsdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684161048; x=1686753048; 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=pKiFi7cchV1/CNWFldN1e7tKyJWR1+z9tt8oV8Nq+So=; b=flP36lXZkHyFTUaPxSdJmRGzMdKq0eEgQ5EJ9R0dM9fWNzWc2oGWiL2rVfMO7XllMO bob+Y06mr8+AjXA9rCuIyI+hWuceYJpuFkxyGOq/YqqvAaFe1ozbuWOvuyHi2LNcOFL1 kk35eSz3tlw/cxqNUDnLAJQCpixP6ch548lx+3LdWuUwnZN5WQ9Bz3OQU9o84gBIkq7N NHr9pm3fw5K7+M2Z32WB90lP59N+oSDue/yNpZ7VYP9Fcd7y9x/KZWoqDFme29F/xxHh vL7s5KajW3bWRGcPf6MR/7mNTR/KM565TdLkarJp0bZpC0j8ukmSP49UFwEd5ojHYCmU Iw7w== X-Gm-Message-State: AC+VfDzf7jkDoogI0jWPHjn9a8hanQR8QuweXwdRJbvZ6WQsegIEN9Cw VLDEh86NA0BHhJQw42f8ma6YDLww57A= X-Google-Smtp-Source: ACHHUZ4Zknr855Fx+2gL1S41HQi7R9Q/SvWwDE1oi+z6Z/cwmI2uo6gUDx0idW2j3FpMiK58ZLMCjQ== X-Received: by 2002:a17:902:7481:b0:1a9:7e26:d72 with SMTP id h1-20020a170902748100b001a97e260d72mr33925292pll.9.1684161048587; Mon, 15 May 2023 07:30:48 -0700 (PDT) Received: from localhost ([2a00:79e1:abd:4a00:61b:48ed:72ab:435b]) by smtp.gmail.com with ESMTPSA id h4-20020a170902704400b001aaf370b1c7sm13552475plt.278.2023.05.15.07.30.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 May 2023 07:30:48 -0700 (PDT) From: Rob Clark To: dri-devel@lists.freedesktop.org Subject: [PATCH v4 1/9] drm/docs: Fix usage stats typos Date: Mon, 15 May 2023 07:30:08 -0700 Message-Id: <20230515143023.801167-2-robdclark@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230515143023.801167-1-robdclark@gmail.com> References: <20230515143023.801167-1-robdclark@gmail.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Rob Clark , Tvrtko Ursulin , Thomas Zimmermann , Jonathan Corbet , "open list:DOCUMENTATION" , Emil Velikov , Christopher Healy , open list , Boris Brezillon , Rodrigo Vivi , freedreno@lists.freedesktop.org, =?utf-8?q?Christian_K=C3=B6nig?= Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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. 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- +- drm-cycles-: 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 given engine. Values are not required to be constantly monotonic if it makes the driver implementation easier, but are required to catch up with the previously reported larger value within a reasonable period. Upon observing a value lower than what was previously read, userspace is expected to stay with that larger previous value until a monotonic update is seen. -- drm-maxfreq- [Hz|MHz|KHz] +- drm-maxfreq-: [Hz|MHz|KHz] 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 calculate percentage utilization of the engine, whereas drm-engine- only reflects time active without considering what frequency the engine is operating as a percentage of it's maximum frequency. Driver specific implementations =============================== From patchwork Mon May 15 14:30:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 13241594 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 26254C77B75 for ; Mon, 15 May 2023 14:31:03 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1D48710E201; Mon, 15 May 2023 14:30:59 +0000 (UTC) Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0F42010E1F8; Mon, 15 May 2023 14:30:51 +0000 (UTC) Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1aad5245632so91351995ad.3; Mon, 15 May 2023 07:30:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684161051; x=1686753051; 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=8Iod2HA8RXIaY6bEo4iIsHcjoOi8lEUL6tKacYY2zxQ=; b=Du3SrjPlot9vra7vbm15yFa+93msV8VwbrGyqpMGM1cd4yp2vF8DMR4WF/5//MtR4a tfH27KhLeXo5IkusOkoa5qcwAMEFJujYdk5jpqE6lYYS27eSO/4JJb/JomSJ75syzh/T SVdeViCXi6VHGAYauuFRDpd1Xw9VcWA5SBKYRvljB3wt0rAHQOXk2sEpQJmpRDQJK7R7 fXmCkn3Pq3U2OEVZS84AbNjdDNDEaufXb0byGfqk4qIslZV3TEdWzujNR6RLN43FTq36 /N/15875d+hjrGfSRb8xHAThnqJd70tSoSUqp0IidUEYaIYVzd36SmrnKWZShzEUJtlN MPow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684161051; x=1686753051; 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=8Iod2HA8RXIaY6bEo4iIsHcjoOi8lEUL6tKacYY2zxQ=; b=HCvPAlB+Ftywvl9mo8KOUSyZO+SpCfTBnkUd+J45iK0HclHVuPe7LhWeEH3C6SK5n8 OEG1C09yXpsHk9YLkiLzwZk3ajhIjRJQjE4fPdjmoenVyFSZwRPpjX9+wXwZDnV53WeP g+8l2Lx9ZCUBuVvY7ORxX4Qxk+JgP2MBRAYdRJzWXwNJPkzraHbCpR97hmYZ4ceJasvh doFFqWOFV9zaGAcTATapIw6c1ZOMMUGagQgAwJGUIe9hsfxArRHEpHuVmWJUy5IXYiwU JRnqQwR7McwgQJxUC9iHkpXicn/4SxgHI0YPrABbLnEOurCmYu93v9e9AY2Ld5afhlku s2Hw== X-Gm-Message-State: AC+VfDzvdERSJbehudYIfL16sevEyzuUHX/z/Wqnc3Dsnrxf852Y3Zt/ Y+vV/N68rHOJpVfm3u+uQFaOsBf55BM= X-Google-Smtp-Source: ACHHUZ4vFqF6P3tMA+yr/XvkAuwzFZ1n/my0C/J6X12mO1Rl1F99uQYMriijeaUTHNs1fDNQrEcC4g== X-Received: by 2002:a17:902:d483:b0:1ac:896f:f655 with SMTP id c3-20020a170902d48300b001ac896ff655mr31761178plg.50.1684161050822; Mon, 15 May 2023 07:30:50 -0700 (PDT) Received: from localhost ([2a00:79e1:abd:4a00:61b:48ed:72ab:435b]) by smtp.gmail.com with ESMTPSA id z2-20020a170903018200b001ae12378732sm3171573plg.300.2023.05.15.07.30.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 May 2023 07:30:50 -0700 (PDT) From: Rob Clark To: dri-devel@lists.freedesktop.org Subject: [PATCH v4 2/9] drm: Add common fdinfo helper Date: Mon, 15 May 2023 07:30:09 -0700 Message-Id: <20230515143023.801167-3-robdclark@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230515143023.801167-1-robdclark@gmail.com> References: <20230515143023.801167-1-robdclark@gmail.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Rob Clark , Tvrtko Ursulin , Thomas Zimmermann , Jonathan Corbet , Daniel Vetter , "open list:DOCUMENTATION" , Emil Velikov , Christopher Healy , open list , Boris Brezillon , freedreno@lists.freedesktop.org, =?utf-8?q?Christian_K=C3=B6nig?= Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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. - drm-maxfreq-: [Hz|MHz|KHz] 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 calculate percentage utilization of the engine, whereas drm-engine- only reflects time active without considering what frequency the engine is operating as a percentage of it's maximum frequency. +Implementation Details +====================== + +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 should +be documented above and where possible, aligned with other drivers. + Driver specific implementations -=============================== +------------------------------- :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 *dev) * * This allocates a new DRM file context. It is not linked into any context 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 = ATOMIC_INIT(0); struct drm_device *dev = minor->dev; struct drm_file *file; int ret; file = kzalloc(sizeof(*file), GFP_KERNEL); if (!file) return ERR_PTR(-ENOMEM); + /* Get a unique identifier for fdinfo: */ + file->client_id = atomic64_inc_return(&ident); file->pid = get_pid(task_pid(current)); file->minor = minor; /* for compatibility root is always authenticated */ file->authenticated = capable(CAP_SYS_ADMIN); 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; 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); +/** + * 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-usage-stats.rst + */ +void drm_show_fdinfo(struct seq_file *m, struct file *f) +{ + struct drm_file *file = f->private_data; + struct drm_device *dev = file->minor->dev; + struct drm_printer p = 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 = 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 without * invoking userspace. The struct file may be operated on using its f_op * (the drm_device.driver.fops) to mimick userspace operations, or be supplied * 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); + /** + * @show_fdinfo: + * + * Print device specific fdinfo. See Documentation/gpu/drm-usage-stats.rst. + */ + 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; /** @master_lookup_lock: Serializes @master. */ spinlock_t master_lookup_lock; /** @pid: Process that opened this file. */ struct pid *pid; + /** @client_id: A unique id for fdinfo */ + u64 client_id; + /** @magic: Authentication magic, see @authenticated. */ drm_magic_t magic; /** * @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_event *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); struct file *mock_drm_getfile(struct drm_minor *minor, unsigned int flags); #endif /* _DRM_FILE_H_ */ From patchwork Mon May 15 14:30:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 13241593 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 08DE9C77B75 for ; Mon, 15 May 2023 14:31:00 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id BCB4510E1FC; Mon, 15 May 2023 14:30:55 +0000 (UTC) Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by gabe.freedesktop.org (Postfix) with ESMTPS id 82DEB10E1F8; Mon, 15 May 2023 14:30:53 +0000 (UTC) Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-643bb9cdd6eso10656137b3a.1; Mon, 15 May 2023 07:30:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684161052; x=1686753052; 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=IPtbgHx5pvKBNpqMIwwso4Kz83kyTXBOXbUJsvgFKio=; b=h7IgYrEFwajKVJ586ZDDv70DkO3URA7qqNdbXJOx6+Hy4RCSrL2yPbZXywpq5w6+y4 OcoXUxVoAoSkDrQ4pUVNlZHW4Q+gOGshZ0pzsm/pRn0m2/+qqVnYLEyj/nmVo+E2PCjA oAGUhjP5fB/ZEu8VEDM0iixekXob7I7Fkmh0xnZtD1ZyNM3EiaCW3nvDp88RklNt1ahl rPCpSkv8Z61oCgLpUUVqiqyvDpj/s4bkH1xNGTtZ0P6ZSczXe3gnr7vQXr1H0zdmRRY5 vS65EHnMET4ad642Ra39vqN01oJqPOMw3McMQGgdAt+e0OTKBK1sme3h5tYjYJ6vjw7h /vKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684161052; x=1686753052; 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=IPtbgHx5pvKBNpqMIwwso4Kz83kyTXBOXbUJsvgFKio=; b=URpT5RMjC4D7ObTQaNAqS10GeiTRvDt6dYThz3tehWlW3EdlKbeaUTCHWXxON1GAa9 aMoSbYdeLttYT2cnGr4Bmka91m91GA1RYlXyca1fXb0JaCg9Y+BGZlR5B0eZutoR7F1y HyI3aiUiu8VFztwY2vZ9E+4sz9XjaxCaNkrSG9iuCtdeDih7O/cqxAipsAQ7LCWeKMFc ZrcGN4DxZiquI+gdGYGvlx+S5+cr1lTGnY0+wgRPWBgz8UjzUmHH0kkuSrXllX+wSa7G CgR53K2AZ2JDmOy0StZuc9MfHq9zg5zreJezfCnV5RmEbhkSF1UjG0GW0Rmj1Cj1Lkxl fe2w== X-Gm-Message-State: AC+VfDwtQfhx9h/Kkf3THsqOqc+yz10CbWDBdgFgkrcrpYF1hxirtRWp TQbzbOGtEkJSu6L0NciVs52TM0+U1Q4= X-Google-Smtp-Source: ACHHUZ5W5LyVqcEpb0f8ngjuy8aCj0jQZi+Th7CZErNuBgiTOji2SVBxyRpp2T43jz8bd0rNaKk8Mg== X-Received: by 2002:a05:6a21:9988:b0:100:3964:6cb with SMTP id ve8-20020a056a21998800b00100396406cbmr36102198pzb.40.1684161052599; Mon, 15 May 2023 07:30:52 -0700 (PDT) Received: from localhost ([2a00:79e1:abd:4a00:61b:48ed:72ab:435b]) by smtp.gmail.com with ESMTPSA id s145-20020a632c97000000b0050bc4ca9024sm11564000pgs.65.2023.05.15.07.30.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 May 2023 07:30:52 -0700 (PDT) From: Rob Clark To: dri-devel@lists.freedesktop.org Subject: [PATCH v4 3/9] drm/msm: Switch to fdinfo helper Date: Mon, 15 May 2023 07:30:10 -0700 Message-Id: <20230515143023.801167-4-robdclark@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230515143023.801167-1-robdclark@gmail.com> References: <20230515143023.801167-1-robdclark@gmail.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Rob Clark , Tvrtko Ursulin , Sean Paul , Emil Velikov , Christopher Healy , Abhinav Kumar , Boris Brezillon , "open list:DRM DRIVER FOR MSM ADRENO GPU" , Dmitry Baryshkov , freedreno@lists.freedesktop.org, =?utf-8?q?Christian_K=C3=B6nig?= , open list Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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 2f2f9e42c519..467c689a95f2 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[] = { DRM_IOCTL_DEF_DRV(MSM_GEM_CPU_PREP, msm_ioctl_gem_cpu_prep, DRM_RENDER_ALLOW), DRM_IOCTL_DEF_DRV(MSM_GEM_CPU_FINI, msm_ioctl_gem_cpu_fini, DRM_RENDER_ALLOW), DRM_IOCTL_DEF_DRV(MSM_GEM_SUBMIT, msm_ioctl_gem_submit, DRM_RENDER_ALLOW), DRM_IOCTL_DEF_DRV(MSM_WAIT_FENCE, msm_ioctl_wait_fence, DRM_RENDER_ALLOW), DRM_IOCTL_DEF_DRV(MSM_GEM_MADVISE, msm_ioctl_gem_madvise, DRM_RENDER_ALLOW), 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), }; -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 = f->private_data; struct drm_device *dev = file->minor->dev; struct msm_drm_private *priv = dev->dev_private; - struct drm_printer p = drm_seq_file_printer(m); if (!priv->gpu) return; - msm_gpu_show_fdinfo(priv->gpu, file->driver_priv, &p); + msm_gpu_show_fdinfo(priv->gpu, file->driver_priv, p); } static const struct file_operations fops = { .owner = THIS_MODULE, DRM_GEM_FOPS, - .show_fdinfo = msm_fop_show_fdinfo, + .show_fdinfo = drm_show_fdinfo, }; static const struct drm_driver msm_driver = { .driver_features = DRIVER_GEM | DRIVER_RENDER | DRIVER_ATOMIC | DRIVER_MODESET | DRIVER_SYNCOBJ, .open = msm_open, - .postclose = msm_postclose, + .postclose = msm_postclose, .lastclose = drm_fb_helper_lastclose, .dumb_create = msm_gem_dumb_create, .dumb_map_offset = msm_gem_dumb_map_offset, .prime_handle_to_fd = drm_gem_prime_handle_to_fd, .prime_fd_to_handle = drm_gem_prime_fd_to_handle, .gem_prime_import_sg_table = msm_gem_prime_import_sg_table, .gem_prime_mmap = msm_gem_prime_mmap, #ifdef CONFIG_DEBUG_FS .debugfs_init = msm_debugfs_init, #endif + .show_fdinfo = msm_show_fdinfo, .ioctls = msm_ioctls, .num_ioctls = ARRAY_SIZE(msm_ioctls), .fops = &fops, .name = "msm", .desc = "MSM Snapdragon DRM", .date = "20130625", .major = MSM_VERSION_MAJOR, .minor = MSM_VERSION_MINOR, .patchlevel = 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; gpu->suspend_count++; return 0; } 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); } int msm_gpu_hw_init(struct msm_gpu *gpu) { int ret; WARN_ON(!mutex_is_locked(&gpu->lock)); From patchwork Mon May 15 14:30:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 13241596 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A7D52C7EE23 for ; Mon, 15 May 2023 14:31:09 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 05FDC10E202; Mon, 15 May 2023 14:31:03 +0000 (UTC) Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by gabe.freedesktop.org (Postfix) with ESMTPS id C551610E1F5; Mon, 15 May 2023 14:30:57 +0000 (UTC) Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1aaea3909d1so120036815ad.2; Mon, 15 May 2023 07:30:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684161057; x=1686753057; 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=J+eFaAuv5DwnuMYT4MLpA+IW5y413fK5e+lMgmHpaqM=; b=bLYk0iTRvozgHkHd57YIP5u30BVW3qkKKsSYng6dMI2zSNSuvZ0hd5Z7GmUhqUzfYc 6sqINwqp8IQkBjx0HU4Iwve9ZRKyu+7rAchvR48XmE9OS/sp3Rz5yUcZ0/bbsymk3Ju1 y37nZ35DM3V8U2+uGGCk4itjv/wHKGRxj/nJjyJz1dEZv/K0sAmH5Ry/KGN/ATCDJBu9 kjuvxlSQtOJ+mzWV2rvAXPDUfbcxtrjrWoifs1r/tw8FpihTuJ3aK5rf8YlSvj5dGVPv BZ6oqv/3wDLmiBMojFiyZAZdZz6e7LzHy6MI8OvHwKWzs18rTEe4nHmFlSLF1AQwLzNv 4jZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684161057; x=1686753057; 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=J+eFaAuv5DwnuMYT4MLpA+IW5y413fK5e+lMgmHpaqM=; b=CfCAGcIEwcWBPDV6ybcvQyAP/Uo6w7kyU7j/H1W8WZiqsIeiBktpW6MlQhBflhOOcI UPWN4FmHC3sYW0m/MJU3ru0hAlxTZb54rAzan4wlxg4tJPULM1FnS1ZyYTmhZMhXS2LG qDvCc8gILhHgEqH7F/1HcO23/vopMWXep3LwVGgFrUGuGu5aJlN0CVgoYRYrKJNYyQXZ ie3PdZ9cyB1UDdKfeTotYpP7/8flJ2aUf9WGngv0ckViq5BdOjlRsEfkXXjnwvl5FKH/ sr9Z7nKR8Ytv1ulVAJPt1H2vIv6DZ+R83F/XIiU23KsZqPdKnFZtbeP917tv+dPpiEF9 ZSsw== X-Gm-Message-State: AC+VfDwvGd3pGs98QnXKMng0OAgfSIjSURh9hVZekDW872U4LTEtiYAc eQDH8yPZEeFiqB00VY8xG/Tq4Ijdr0k= X-Google-Smtp-Source: ACHHUZ5sGvx/oOWoGm1MaSZQQVu5CXoA43XI4IbEIKFtFr/c2N29+/r/jC2CaUXLxPqmI4mMDtAAIg== X-Received: by 2002:a17:902:da88:b0:1a6:d9de:1887 with SMTP id j8-20020a170902da8800b001a6d9de1887mr44100368plx.53.1684161057060; Mon, 15 May 2023 07:30:57 -0700 (PDT) Received: from localhost ([2a00:79e1:abd:4a00:61b:48ed:72ab:435b]) by smtp.gmail.com with ESMTPSA id m2-20020a1709026bc200b001a045f45d49sm13541803plt.281.2023.05.15.07.30.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 May 2023 07:30:56 -0700 (PDT) From: Rob Clark To: dri-devel@lists.freedesktop.org Subject: [PATCH v4 4/9] drm/amdgpu: Switch to fdinfo helper Date: Mon, 15 May 2023 07:30:11 -0700 Message-Id: <20230515143023.801167-5-robdclark@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230515143023.801167-1-robdclark@gmail.com> References: <20230515143023.801167-1-robdclark@gmail.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Pan, Xinhui" , open list , =?utf-8?q?Michel_D=C3=A4nzer?= , YiPeng Chai , Mario Limonciello , Rob Clark , Guchun Chen , Shashank Sharma , "open list:RADEON and AMDGPU DRM DRIVERS" , Arunpravin Paneer Selvam , =?utf-8?b?TWFy?= =?utf-8?b?ZWsgT2zFocOhaw==?= , Tvrtko Ursulin , Tvrtko Ursulin , Peter Maucher , Emil Velikov , Christopher Healy , Boris Brezillon , Alex Deucher , freedreno@lists.freedesktop.org, =?utf-8?q?Christian_K=C3=B6nig?= Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Rob Clark Signed-off-by: Rob Clark Reviewed-by: Christian König --- 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_kms_fops = { .flush = amdgpu_flush, .release = drm_release, .unlocked_ioctl = amdgpu_drm_ioctl, .mmap = drm_gem_mmap, .poll = drm_poll, .read = drm_read, #ifdef CONFIG_COMPAT .compat_ioctl = amdgpu_kms_compat_ioctl, #endif #ifdef CONFIG_PROC_FS - .show_fdinfo = amdgpu_show_fdinfo + .show_fdinfo = drm_show_fdinfo, #endif }; int amdgpu_file_to_fpriv(struct file *filp, struct amdgpu_fpriv **fpriv) { struct drm_file *file; if (!filp) return -EINVAL; @@ -2800,20 +2800,21 @@ static const struct drm_driver amdgpu_kms_driver = { DRIVER_SYNCOBJ_TIMELINE, .open = amdgpu_driver_open_kms, .postclose = amdgpu_driver_postclose_kms, .lastclose = amdgpu_driver_lastclose_kms, .ioctls = amdgpu_ioctls_kms, .num_ioctls = ARRAY_SIZE(amdgpu_ioctls_kms), .dumb_create = amdgpu_mode_dumb_create, .dumb_map_offset = amdgpu_mode_dumb_mmap, .fops = &amdgpu_driver_kms_fops, .release = &amdgpu_driver_release_kms, + .show_fdinfo = amdgpu_show_fdinfo, .prime_handle_to_fd = drm_gem_prime_handle_to_fd, .prime_fd_to_handle = drm_gem_prime_fd_to_handle, .gem_prime_import = amdgpu_gem_prime_import, .gem_prime_mmap = drm_gem_prime_mmap, .name = DRIVER_NAME, .desc = DRIVER_DESC, .date = DRIVER_DATE, .major = KMS_DRIVER_MAJOR, diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_fdinfo.c b/drivers/gpu/drm/amd/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] = { [AMDGPU_HW_IP_COMPUTE] = "compute", [AMDGPU_HW_IP_DMA] = "dma", [AMDGPU_HW_IP_UVD] = "dec", [AMDGPU_HW_IP_VCE] = "enc", [AMDGPU_HW_IP_UVD_ENC] = "enc_1", [AMDGPU_HW_IP_VCN_DEC] = "dec", [AMDGPU_HW_IP_VCN_ENC] = "enc", [AMDGPU_HW_IP_VCN_JPEG] = "jpeg", }; -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 = f->private_data; struct amdgpu_device *adev = drm_to_adev(file->minor->dev); struct amdgpu_fpriv *fpriv = file->driver_priv; struct amdgpu_vm *vm = &fpriv->vm; uint64_t vram_mem = 0, gtt_mem = 0, cpu_mem = 0; ktime_t usage[AMDGPU_HW_IP_NUM]; uint32_t bus, dev, fn, domain; unsigned int hw_ip; int ret; @@ -79,25 +78,22 @@ void amdgpu_show_fdinfo(struct seq_file *m, struct file *f) amdgpu_bo_unreserve(vm->root.bo); amdgpu_ctx_mgr_usage(&fpriv->ctx_mgr, usage); /* * ****************************************************************** * For text output format description please see drm-usage-stats.rst! * ****************************************************************** */ - 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 = 0; hw_ip < AMDGPU_HW_IP_NUM; ++hw_ip) { if (!usage[hw_ip]) continue; - 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/amd/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 #include "amdgpu_sync.h" #include "amdgpu_ring.h" #include "amdgpu_ids.h" 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); #endif From patchwork Mon May 15 14:30:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 13241595 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1999EC77B75 for ; Mon, 15 May 2023 14:31:07 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id F26E710E203; Mon, 15 May 2023 14:31:01 +0000 (UTC) Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3077510E203; Mon, 15 May 2023 14:31:00 +0000 (UTC) Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-1aaf21bb427so91423975ad.1; Mon, 15 May 2023 07:31:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684161059; x=1686753059; 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=I9CjL0Fz9cdjrYojcQZBZLwYXaiNihqTcbd8qG9seGA=; b=dgtUxZeVXB995aTs+oGdCgBpO+sm9tG5yeOT96p+XwYDxLx2/bbDv/Lp4pxSQ6yZuo F6eUBWuS3ktsKAPcm+61eILC7m/P09QJSdHY8XB4SCKcmoy5GBfDPF4jReACnoF22cJj 4FOMf1pjQurmq/eEGa9aKe6jPvWpbbpuUaTyLlBaDpoqnHwe9JzVn5uKz/V6K6was21H kWiqTTGqgLPzrB+bLxcspYw9QvhAdhj4uLtoPjf2dNNY7qGpjcMSWjDmtewdZR9sXf52 K57sodEWgPPCYnc3Co6sE4lq+o/BI/bm8EYtgRVPKAr5GABRu4G1k8DlwJVPPABPiF2a icbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684161059; x=1686753059; 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=I9CjL0Fz9cdjrYojcQZBZLwYXaiNihqTcbd8qG9seGA=; b=IAzxf48/No0m99mnYN9SvM0Mvcwpy3FEliIOCVNp2z8fmR8M2rK13BW3dzpnxPWlsv KcA+y65KuwyFZ+7lg9ghpV4IcN75kQi2AKFm8V8rBm38vwMKzuhWg6leTaPTvUMnTv2f OyXtx8Y5blwi1WQ+IBaRivVF2dyN4INQoDRu0Ix4x/aFkaSyISQjdMgTmCAhAbbURrMd aOX62FhTwjQ/fnRDWvbyzTeI4kg9w+3aXiic3zZKwVyX+/E/v9n3gIelIzYWK6loUDhT 9eW3y9RlEy8Fc1YxzeWq51SrmmwQO4pesbpRj2Os27rjWihueFjPgr5f+ebNb5cRwzv6 19dA== X-Gm-Message-State: AC+VfDxpYHq36DGDc1cvqa4A8oEmuUSndhbSylXEqhUJXQvmgibQHbin /n1N8n+zFW0yocUo2xBc4f8FJ9/2qmU= X-Google-Smtp-Source: ACHHUZ6FzYOsMsVGCB45TdZ+LSnw5dZKVjNgPSdXbnfw7jIRmFN4CK/sFLfySLGXFSHX/uzPyHSbqA== X-Received: by 2002:a17:902:a516:b0:1ab:1355:1a45 with SMTP id s22-20020a170902a51600b001ab13551a45mr32077289plq.30.1684161058891; Mon, 15 May 2023 07:30:58 -0700 (PDT) Received: from localhost ([2a00:79e1:abd:4a00:61b:48ed:72ab:435b]) by smtp.gmail.com with ESMTPSA id d23-20020a170902729700b001a216d44440sm13607640pll.200.2023.05.15.07.30.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 May 2023 07:30:58 -0700 (PDT) From: Rob Clark To: dri-devel@lists.freedesktop.org Subject: [PATCH v4 5/9] drm: Add fdinfo memory stats Date: Mon, 15 May 2023 07:30:12 -0700 Message-Id: <20230515143023.801167-6-robdclark@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230515143023.801167-1-robdclark@gmail.com> References: <20230515143023.801167-1-robdclark@gmail.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Rob Clark , Tvrtko Ursulin , Thomas Zimmermann , Tvrtko Ursulin , Daniel Vetter , Jonathan Corbet , Emil Velikov , Christopher Healy , "open list:DOCUMENTATION" , Boris Brezillon , freedreno@lists.freedesktop.org, =?utf-8?q?Christian_K=C3=B6nig?= , open list Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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 --- 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 --------------------------------- - drm-driver: String shall contain the name this driver registered as via the respective `struct drm_driver` data structure. Optional fully standardised keys -------------------------------- +Identification +^^^^^^^^^^^^^^ + - drm-pdev: For PCI devices this should contain the PCI slot address of the device in question. - drm-client-id: 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. 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. Userspace should make sure to not double account any usage statistics by using the above described criteria in order to associate data to individual clients. +Utilization +^^^^^^^^^^^ + - drm-engine-: ns GPUs usually contain multiple execution engines. Each shall be given a stable and unique name (str), with possible values documented in the driver specific documentation. Value shall be in specified time units which the respective GPU engine spent busy executing workloads belonging to this client. Values are not required to be constantly monotonic if it makes the driver @@ -86,32 +92,20 @@ value until a monotonic update is seen. - drm-engine-capacity-: 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. In the absence of this tag parser shall assume capacity of one. Zero capacity is not allowed. -- 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-: 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 given engine. Values are not required to be constantly monotonic if it makes the driver implementation easier, but are required to catch up with the previously reported larger value within a reasonable period. Upon observing a value lower than what was previously read, userspace is expected to stay with that larger previous @@ -119,20 +113,56 @@ value until a monotonic update is seen. - drm-maxfreq-: [Hz|MHz|KHz] 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 calculate percentage utilization of the engine, whereas drm-engine- only reflects time active without considering what frequency the engine is operating as a percentage of it's maximum frequency. +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 memory. + +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 ====================== 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 should be documented above and where possible, aligned with other drivers. Driver specific implementations ------------------------------- diff --git a/drivers/gpu/drm/drm_file.c b/drivers/gpu/drm/drm_file.c index 6d5bdd684ae2..739d9b7ab9ec 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 #include #include #include +#include #include #include "drm_crtc_internal.h" #include "drm_internal.h" #include "drm_legacy.h" /* from BKL pushdown */ DEFINE_MUTEX(drm_global_mutex); 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; 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); +static void print_size(struct drm_printer *p, const char *stat, + const char *region, u64 sz) +{ + const char *units[] = {"", " KiB", " MiB"}; + unsigned u; + + for (u = 0; u < ARRAY_SIZE(units) - 1; u++) { + if (sz < SZ_1K) + break; + sz = 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 memory stats + * @p: the printer to print output to + * @file: the DRM file + * + * Helper to iterate over GEM objects with a handle allocated in the specified + * file. + */ +void drm_show_memory_stats(struct drm_printer *p, struct drm_file *file) +{ + struct drm_gem_object *obj; + struct drm_memory_stats status = {}; + 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 = 0; + + if (obj->funcs && obj->funcs->status) { + s = obj->funcs->status(obj); + supported_status = DRM_GEM_OBJECT_RESIDENT | + DRM_GEM_OBJECT_PURGEABLE; + } + + if (obj->handle_count > 1) { + status.shared += obj->size; + } else { + status.private += obj->size; + } + + if (s & DRM_GEM_OBJECT_RESIDENT) { + status.resident += obj->size; + } else { + /* If already purged or not yet backed by pages, don't + * count it as purgeable: + */ + s &= ~DRM_GEM_OBJECT_PURGEABLE; + } + + if (!dma_resv_test_signaled(obj->resv, dma_resv_usage_rw(true))) { + status.active += obj->size; + + /* If still active, don't count as purgeable: */ + s &= ~DRM_GEM_OBJECT_PURGEABLE; + } + + if (s & DRM_GEM_OBJECT_PURGEABLE) + status.purgeable += 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-usage-stats.rst */ void drm_show_fdinfo(struct seq_file *m, struct file *f) { struct drm_file *file = f->private_data; diff --git a/include/drm/drm_file.h b/include/drm/drm_file.h index 6de6d0e9c634..5f5c156903d2 100644 --- a/include/drm/drm_file.h +++ b/include/drm/drm_file.h @@ -34,20 +34,21 @@ #include #include #include #include struct dma_fence; struct drm_file; struct drm_device; +struct drm_printer; struct device; struct file; /* * 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. */ /* 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_event *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); struct file *mock_drm_getfile(struct drm_minor *minor, unsigned int flags); #endif /* _DRM_FILE_H_ */ diff --git a/include/drm/drm_gem.h b/include/drm/drm_gem.h index 189fd618ca65..1df035ae7981 100644 --- a/include/drm/drm_gem.h +++ b/include/drm/drm_gem.h @@ -35,20 +35,39 @@ */ #include #include #include struct iosys_map; struct drm_gem_object; +/** + * enum drm_gem_object_status - bitmask of object state for fdinfo reporting + * @DRM_GEM_OBJECT_RESIDENT: object is resident in memory (ie. not unpinned) + * @DRM_GEM_OBJECT_PURGEABLE: object marked as purgeable by userspace + * + * Bitmask of status used for fdinfo memory stats, see &drm_gem_object_funcs.status + * and drm_show_fdinfo(). Note that an object can DRM_GEM_OBJECT_PURGEABLE if + * it still active or not resident, in which case drm_show_fdinfo() will not + * account for it as purgeable. So drivers do not need to check if the buffer + * is idle and resident to return this bit. (Ie. userspace can mark a buffer + * as purgeable even while it is still busy on the GPU.. it does not _actually_ + * become puregeable until it becomes idle. The status gem object func does + * not need to consider this.) + */ +enum drm_gem_object_status { + DRM_GEM_OBJECT_RESIDENT = BIT(0), + DRM_GEM_OBJECT_PURGEABLE = 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); + /** + * @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; }; From patchwork Mon May 15 14:30:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 13241597 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A76BCC77B75 for ; Mon, 15 May 2023 14:31:12 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D480B10E207; Mon, 15 May 2023 14:31:05 +0000 (UTC) Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by gabe.freedesktop.org (Postfix) with ESMTPS id 54AA210E203; Mon, 15 May 2023 14:31:01 +0000 (UTC) Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-1aafa03f541so124355385ad.0; Mon, 15 May 2023 07:31:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684161060; x=1686753060; 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=3L1H5A/AgNdZq2KMqprQZztlGdFsDSiLstadTyfsWps=; b=eCRMUe9GcCej4DZn0o5scm14epytTxlq5SKShRg5NCvxZfpyg0sZ9Sl/rB+3TLrnjW s7+4/FXsCbKSOTfS9q8e0PGpu6T2VfNwGBkf8dJhzC8RwZZhKAhzywnit04Doft9V0qp opsWuRAf6zsqCll2HTwlXoHpthYiZEN7bGnCg2aGMl1kmxVskL+1GnGHsgmbYCHhic0s VmNa7CFqFEVuHk0AkesRR1+kmS2hHB04LP1Ky3hw3GlkkgZWFjZvG4syg12T3qZzWNP+ tBrXZmeupszD9NIkMbZwaRJe7ItV5YqzI/u1qG2P21uLKQ81ZM4OkRwO2qssdCLgl5Jg bm7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684161060; x=1686753060; 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=3L1H5A/AgNdZq2KMqprQZztlGdFsDSiLstadTyfsWps=; b=NO6ySpyJyqqlYQpvHKUmviY9Dt8ewjUycC+cEzZevXtDv7CmcoU0iT369PK7squFRH nv3WQjwZCah5h5QejfoKCRpjR+sz0VLo0jyFKUphh+nnPWjz+fONZAFIDXl/r6aJ54Nu xrFVoJSmvxrE3Z0a+us5wsHgzPupHraNx0YjELWUgQV0aqLhHPVMBtNk5TIZesi9R5aa 45E7AkVwLie1nzUZpVOc4qxQUivIo0D7LcUj/vHfhxbiEWHXIn8Ik2adCEcVvB6/9Z8y SoyRkdNWALKAS9m+4ZikvxvoKLAVtRYRo2YHITqRT132squTRy8jPH7/ekC1oGF2iQ2o 3Srg== X-Gm-Message-State: AC+VfDx7gwwFjs7QTKJR1xaG+XR3VtE3/7R9FhcdxRQeaT1xj/ehMArY dDvFwWCXbOuGhA7oXOWZKC3AQKOH6BM= X-Google-Smtp-Source: ACHHUZ6pvVnfptzAGB3VhyoJFkfiSRpU+DqPKt/RNYDksPRe5O/02m95S5dnueIYFETpJ/RpAzfMGw== X-Received: by 2002:a17:903:185:b0:1a1:e237:5f0 with SMTP id z5-20020a170903018500b001a1e23705f0mr46730970plg.58.1684161060586; Mon, 15 May 2023 07:31:00 -0700 (PDT) Received: from localhost ([2a00:79e1:abd:4a00:61b:48ed:72ab:435b]) by smtp.gmail.com with ESMTPSA id j12-20020a170902c3cc00b0019f3cc463absm13665435plj.0.2023.05.15.07.30.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 May 2023 07:31:00 -0700 (PDT) From: Rob Clark To: dri-devel@lists.freedesktop.org Subject: [PATCH v4 6/9] drm/msm: Add memory stats to fdinfo Date: Mon, 15 May 2023 07:30:13 -0700 Message-Id: <20230515143023.801167-7-robdclark@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230515143023.801167-1-robdclark@gmail.com> References: <20230515143023.801167-1-robdclark@gmail.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Rob Clark , Tvrtko Ursulin , Sean Paul , Emil Velikov , Christopher Healy , Abhinav Kumar , Boris Brezillon , "open list:DRM DRIVER FOR MSM ADRENO GPU" , Dmitry Baryshkov , freedreno@lists.freedesktop.org, =?utf-8?q?Christian_K=C3=B6nig?= , open list Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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 467c689a95f2..a403aebe7f5a 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[] = { static void msm_show_fdinfo(struct drm_printer *p, struct drm_file *file) { struct drm_device *dev = file->minor->dev; struct msm_drm_private *priv = dev->dev_private; if (!priv->gpu) return; msm_gpu_show_fdinfo(priv->gpu, file->driver_priv, p); + + drm_show_memory_stats(p, file); } static const struct file_operations fops = { .owner = THIS_MODULE, DRM_GEM_FOPS, .show_fdinfo = drm_show_fdinfo, }; static const struct drm_driver msm_driver = { .driver_features = 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, struct drm_file *file, msm_gem_object_set_name(obj, "%s", name); ret = drm_gem_handle_create(file, obj, handle); /* drop reference from allocate - handle holds it now */ drm_gem_object_put(obj); return ret; } +static enum drm_gem_object_status msm_gem_status(struct drm_gem_object *obj) +{ + struct msm_gem_object *msm_obj = to_msm_bo(obj); + enum drm_gem_object_status status = 0; + + if (msm_obj->pages) + status |= DRM_GEM_OBJECT_RESIDENT; + + if (msm_obj->madv == MSM_MADV_DONTNEED) + status |= DRM_GEM_OBJECT_PURGEABLE; + + return status; +} + static const struct vm_operations_struct vm_ops = { .fault = msm_gem_fault, .open = drm_gem_vm_open, .close = drm_gem_vm_close, }; static const struct drm_gem_object_funcs msm_gem_object_funcs = { .free = msm_gem_free_object, .pin = msm_gem_prime_pin, .unpin = msm_gem_prime_unpin, .get_sg_table = msm_gem_prime_get_sg_table, .vmap = msm_gem_prime_vmap, .vunmap = msm_gem_prime_vunmap, .mmap = msm_gem_object_mmap, + .status = msm_gem_status, .vm_ops = &vm_ops, }; 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 = dev->dev_private; struct msm_gem_object *msm_obj; From patchwork Mon May 15 14:30:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 13241599 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CF560C77B7D for ; Mon, 15 May 2023 14:31:16 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7425210E20F; Mon, 15 May 2023 14:31:10 +0000 (UTC) Received: from mail-pg1-x529.google.com (mail-pg1-x529.google.com [IPv6:2607:f8b0:4864:20::529]) by gabe.freedesktop.org (Postfix) with ESMTPS id 581D810E205; Mon, 15 May 2023 14:31:03 +0000 (UTC) Received: by mail-pg1-x529.google.com with SMTP id 41be03b00d2f7-528dd896165so9200599a12.2; Mon, 15 May 2023 07:31:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684161062; x=1686753062; 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=QVq/kpJ/70Wv68RjMJaNqydvleLpT2XbW0a2c5YuHeA=; b=bW2MaVBFgRr7231m/l4hHFIy4hGb46iF869j3WLa15qqsNJTd3j/N258uPhokNlg0Z rrmWgnxqqLtNEnWfgdkGTiUcTqo3Awy2ruCYzoEDs6A45fHEwgw/rrM9udtBi3Hn4ka4 FT/fNwayPHyYJ9sjXpy11xlpQl65r2fXoxHH4xt9d3DLEIW/dpzcu6SEAOyzDN4qM3Qo xCkWzGocLjM0ZlVPxAzk5umC6Jhms1ajOXEXTwvKFWmBTkKXE8GzlFZCwskWcix0m6DQ B1myHlr1KIP9Sf4r07RPDdTfBNRWi6fv77waWOaTzDmIyfy/6EEaXA8I/02tSBHMORxK WSWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684161062; x=1686753062; 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=QVq/kpJ/70Wv68RjMJaNqydvleLpT2XbW0a2c5YuHeA=; b=IXL8iTgL2XHxM/iavf4PdXspi9tHTWOUX4blsNlhZz6S9riNUIRBt8qD4pBMk7yVSA FsI9/FEzYy5exBc4Myq10xh3MD3FDMFoDEcxIRPba/gcc2V/hMldsLJLQkLXZEYyeng9 JL7Ao+zl+oMV1JN/AqA8VzB+60j/g9F24cdA3wZlYfkCIgxBssEdXXJX9gNh4NFgpiNN s/gb5CcGERnr527u8RdG0uqPFhAGxxpjp521/hmzoRIQ5Y+7OVlTaSqJiHRRzbvktiTi G9yDaVgSb1w/3ySTwM4+8y7jugFmM13qeT8Ydxc3KoScSsRZzd7KiqTqbTnAjxkiUFLg wNCw== X-Gm-Message-State: AC+VfDx2wdbTgd3xDRIW1L+Mz68OC00TGi7Nt34HqL2fbzmmMVqNHefT FvA89fnjm4tb/kXK+cjBor5kplilkNQ= X-Google-Smtp-Source: ACHHUZ71l41Y3wgpKhvpJKf0oM96ttVQjDila4pNl6cUuMG11fTboomzRXCM+U5ceRWquu8RZWWeuw== X-Received: by 2002:a17:90a:8004:b0:24e:5245:6383 with SMTP id b4-20020a17090a800400b0024e52456383mr33282021pjn.23.1684161062193; Mon, 15 May 2023 07:31:02 -0700 (PDT) Received: from localhost ([2a00:79e1:abd:4a00:61b:48ed:72ab:435b]) by smtp.gmail.com with ESMTPSA id g22-20020a17090adb1600b00250bf8495b3sm10747609pjv.39.2023.05.15.07.31.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 May 2023 07:31:01 -0700 (PDT) From: Rob Clark To: dri-devel@lists.freedesktop.org Subject: [PATCH v4 7/9] drm/doc: Relax fdinfo string constraints Date: Mon, 15 May 2023 07:30:14 -0700 Message-Id: <20230515143023.801167-8-robdclark@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230515143023.801167-1-robdclark@gmail.com> References: <20230515143023.801167-1-robdclark@gmail.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Rob Clark , Tvrtko Ursulin , Thomas Zimmermann , Tvrtko Ursulin , Jonathan Corbet , Emil Velikov , Christopher Healy , "open list:DOCUMENTATION" , Boris Brezillon , freedreno@lists.freedesktop.org, =?utf-8?q?Christian_K=C3=B6nig?= , open list Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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 standardise as much as possible. File format specification ========================= - File shall contain one key value pair per one line of text. - Colon character (`:`) must be used to delimit keys and values. - All keys shall be prefixed with `drm-`. - Whitespace between the delimiter and first non-whitespace character shall 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. Key types --------- 1. Mandatory, fully standardised. 2. Optional, fully standardised. 3. Driver specific. Data types ---------- - - Unsigned integer without defining the maximum value. -- - String excluding any above defined reserved characters or whitespace. +- - String excluding any above defined reserved characters or whitespace. +- - String. Mandatory fully standardised keys --------------------------------- -- drm-driver: +- drm-driver: String shall contain the name this driver registered as via the respective `struct drm_driver` data structure. Optional fully standardised keys -------------------------------- Identification ^^^^^^^^^^^^^^ @@ -68,62 +69,62 @@ to the in kernel representation of `struct drm_file` instances. 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. Userspace should make sure to not double account any usage statistics by using the above described criteria in order to associate data to individual clients. Utilization ^^^^^^^^^^^ -- drm-engine-: ns +- drm-engine-: ns GPUs usually contain multiple execution engines. Each shall be given a stable -and unique name (str), with possible values documented in the driver specific +and unique name (keystr), with possible values documented in the driver specific documentation. Value shall be in specified time units which the respective GPU engine spent busy executing workloads belonging to this client. Values are not required to be constantly monotonic if it makes the driver implementation easier, but are required to catch up with the previously reported larger value within a reasonable period. Upon observing a value lower than what was previously read, userspace is expected to stay with that larger previous value until a monotonic update is seen. -- drm-engine-capacity-: +- drm-engine-capacity-: 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 case the exported engine corresponds to a group of identical hardware engines. In the absence of this tag parser shall assume capacity of one. Zero capacity is not allowed. -- drm-cycles-: +- drm-cycles-: 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 given +drm-engine- tag and shall contain the number of busy cycles for the given engine. Values are not required to be constantly monotonic if it makes the driver implementation easier, but are required to catch up with the previously reported larger value within a reasonable period. Upon observing a value lower than what was previously read, userspace is expected to stay with that larger previous value until a monotonic update is seen. -- drm-maxfreq-: [Hz|MHz|KHz] +- drm-maxfreq-: [Hz|MHz|KHz] 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 calculate -percentage utilization of the engine, whereas drm-engine- only reflects +drm-engine- tag and shall contain the maximum frequency for the given +engine. Taken together with drm-cycles-, this can be used to calculate +percentage utilization of the engine, whereas drm-engine- only reflects time active without considering what frequency the engine is operating as a percentage of it's maximum frequency. 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 From patchwork Mon May 15 14:30:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 13241598 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B44DEC7EE26 for ; Mon, 15 May 2023 14:31:14 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A5D0310E20E; Mon, 15 May 2023 14:31:08 +0000 (UTC) Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2135710E207; Mon, 15 May 2023 14:31:05 +0000 (UTC) Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-6436e075166so9583748b3a.0; Mon, 15 May 2023 07:31:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684161064; x=1686753064; 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=+ALq25/GYGH1zBk6Bxp4nZpXzMg5fERkeTFcF2Sc5VQ=; b=rObvimGJrFK2A8lzFbnXDUzo+N+GHtHZxseJ0knzMtMqtfIou+p1+b/gJAnOQr7Tug g14TqF12i3WogQ2yshrldLo4we4vKJv7pMlBBKn+h1RheZ2bvIeIFVRwmJoXh5iiiCc2 cfLRMefKYsBGfy+wY2jtzgJHkbms95Kk1PZyRXhwyJz8dKOS/Pm00fPPLR2PY9o6K7KF UFXy1gWIuNJLFWLZaRGfUGOCJg1cjJWhflRUt2UBOkoIXDtTT6oAJfDKpmV2BVCyUtLZ i73eCt+MQqGRfZDSOLBD77U1CRi8XUQrENwO9ex5Ku0PD0hAa5CESfb40DrLKGcRRsWg MtFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684161064; x=1686753064; 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=+ALq25/GYGH1zBk6Bxp4nZpXzMg5fERkeTFcF2Sc5VQ=; b=TNJAgAIOCsWM9999aKTe5CgCfIOWN4ceYASRWDkzZSEM8dZ33zEYZ9383sf/JAo+yI 9YKWFicyNbTZkYpJ5ikBM26COVzaW74hdawyeqTij+8hzaGavda2dwYtF1lOxY3sXbOw CfklT5SZZ9N8DXchVuT10BjJGcDRRAx6hAZfsFUYCknDQ33FjkRjewx3xEElUeFHSOkN GYnaJkgXUnT7qhV1SD2wyYWHaJ+Nyi6y5lh06GJUPZHCCmQmA1ydLypoTPP76ogmrBLm Ox0FxV3AaYseL2VvOex3GJVem0B6LFdpEvzlR/3efuRU8lZx/ez4OVM5q7cL2Y1odk9z +QKw== X-Gm-Message-State: AC+VfDx8FDAnEbwSgoK2CzuwAjNezdaVdoiOLrCI4P0N9aJszdf7WzOs P3JiNQDCnK6/W5/xX/5iY2I1S5Mi1zg= X-Google-Smtp-Source: ACHHUZ4R3D/gaKOk7QkT8FMcc9BtENuYixxz4Hv1MjvFhVsW4kdm9Xr25qLw7//hiieQaz81R+IUPw== X-Received: by 2002:a05:6a00:218a:b0:640:defd:a6d5 with SMTP id h10-20020a056a00218a00b00640defda6d5mr40180183pfi.12.1684161063962; Mon, 15 May 2023 07:31:03 -0700 (PDT) Received: from localhost ([2a00:79e1:abd:4a00:61b:48ed:72ab:435b]) by smtp.gmail.com with ESMTPSA id j18-20020aa78dd2000000b0064c9c80617csm2666690pfr.214.2023.05.15.07.31.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 May 2023 07:31:03 -0700 (PDT) From: Rob Clark To: dri-devel@lists.freedesktop.org Subject: [PATCH v4 8/9] drm/fdinfo: Add comm/cmdline override fields Date: Mon, 15 May 2023 07:30:15 -0700 Message-Id: <20230515143023.801167-9-robdclark@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230515143023.801167-1-robdclark@gmail.com> References: <20230515143023.801167-1-robdclark@gmail.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Rob Clark , Tvrtko Ursulin , Thomas Zimmermann , Jonathan Corbet , "open list:DOCUMENTATION" , Emil Velikov , Christopher Healy , open list , Boris Brezillon , freedreno@lists.freedesktop.org, =?utf-8?q?Christian_K=C3=B6nig?= Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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. 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. Userspace should make sure to not double account any usage statistics by using the above described criteria in order to associate data to individual clients. +- drm-comm-override: +- drm-cmdline-override: + +Returns the client comm (executable) or cmdline override strings. Some drivers +support letting userspace override this in cases where the userspace is simply a +"proxy". Such as is the case with virglrenderer drm native context, where the +host process is just forwarding command submission, etc, from guest userspace. +This allows the proxy to make visible the cmdline of the actual app in the VM +guest. + Utilization ^^^^^^^^^^^ - drm-engine-: ns GPUs usually contain multiple execution engines. Each shall be given a stable and unique name (keystr), with possible values documented in the driver specific documentation. Value shall be in specified time units which the respective GPU engine spent diff --git a/drivers/gpu/drm/drm_file.c b/drivers/gpu/drm/drm_file.c index 739d9b7ab9ec..a0684c4a021d 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 *minor) 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 = 4096; /* set aside 4k for event buffer */ spin_lock_init(&file->master_lookup_lock); mutex_init(&file->event_read_lock); + mutex_init(&file->override_lock); + if (drm_core_check_feature(dev, DRIVER_GEM)) drm_gem_open(dev, file); if (drm_core_check_feature(dev, DRIVER_SYNCOBJ)) drm_syncobj_open(file); drm_prime_init_file_private(&file->prime); if (dev->driver->open) { ret = dev->driver->open(dev, file); @@ -285,20 +287,22 @@ void drm_file_free(struct drm_file *file) drm_master_release(file); if (dev->driver->postclose) dev->driver->postclose(dev, file); drm_prime_destroy_file_private(&file->prime); WARN_ON(!list_empty(&file->event_list)); put_pid(file->pid); + kfree(file->override_comm); + kfree(file->override_cmdline); kfree(file); } static void drm_close_helper(struct file *filp) { struct drm_file *file_priv = filp->private_data; struct drm_device *dev = file_priv->minor->dev; 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); if (dev_is_pci(dev->dev)) { struct pci_dev *pdev = 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)); } + 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); /** * 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 5f5c156903d2..25384edd1e91 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; /** * @prime: * * Per-file buffer caches used by the PRIME buffer sharing code. */ struct drm_prime_file_private prime; + /** + * @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 }; /** * drm_is_primary_client - is this an open file of the primary node * @file_priv: DRM file * From patchwork Mon May 15 14:30:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 13241600 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D7ABBC7EE23 for ; Mon, 15 May 2023 14:31:18 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 00FE410E205; Mon, 15 May 2023 14:31:16 +0000 (UTC) Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9C0A910E204; Mon, 15 May 2023 14:31:07 +0000 (UTC) Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-1aaf91ae451so120213285ad.1; Mon, 15 May 2023 07:31:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684161067; x=1686753067; 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=qqnNhChLNbHWp6ove8p/hsKGE1errQugomyUMPMw9ls=; b=fH6QFLL+CYHRn+8pGwUhAoac0FbnvAZdJFesFc5r8vV/i196TOHCIInwyzzyYauNDq acsj5AK5T1CZRbpHYwsfuCkTfEN+oIgpxQ8RdewnHOZUIJ+r3yHmsajrya34xy0OX06e l+8w4DjDnnOBvWQSgYKhpLRTQYpaEd4eHayyR311Sc9vdPoexzdKBDGWXCtuJN6AlBCQ HYGRx4Vjk94ROq8FDS5u5TiFpmmJtI84qYwe/0flN5XGuSKkPFyCXBQYGHQeSkYwRBj6 xfYGtyRQiZh9Ca/C1AWbjcK4HYqCbmkLZSUXqst/o1nRQJ6ji5MICuEQ0c6x3S3h/eQJ 5FaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684161067; x=1686753067; 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=qqnNhChLNbHWp6ove8p/hsKGE1errQugomyUMPMw9ls=; b=gCfFGcLE20oOaTqxBTld6mnEeTJ0c6kRk+jmDPl2oPjYvCaFhNzRhPXIPBbx1JALeH LJ7FrE3TKRr+KSEbMsRsubkH+9nJR0ew5bb6mDA72KdbIiu6AN9UI4g++sHPFiRhenrH t3PPD0sCN/ND/4WrwnlYtPsxj/hCdTLUc1gmKBiiliSXkiVt1opYIEkEigCdCluDD1k9 wAfvNu6wE/L1CuJjkbHPE52bmYep4BqxmG1fdzqx++PicnF38ZIY0roqWA86kChsaCq7 Yx9tDNDaQ0nlcmIWlvt+H3wmz34GjRNWh5aS2FbsvFLzMOXaa6KQMb4noiIGlcZya4bT TIfA== X-Gm-Message-State: AC+VfDy0cJ5o+T0g9y/lhzdmrAAAYrWAPUXOUHR6StbkEDAKfbx5WydY 2fxgSg7Fwn/j5mDRPu7QY8TDNiqDpXA= X-Google-Smtp-Source: ACHHUZ45CjBOIkWOM6gt+Z5UDMQMYRnAACMza7WWCWB+vaTsz6VCtYycaRj+NUuppqX4mM9Nwmj5jA== X-Received: by 2002:a17:902:be03:b0:1ab:797:afbe with SMTP id r3-20020a170902be0300b001ab0797afbemr32952864pls.8.1684161066640; Mon, 15 May 2023 07:31:06 -0700 (PDT) Received: from localhost ([2a00:79e1:abd:4a00:61b:48ed:72ab:435b]) by smtp.gmail.com with ESMTPSA id p10-20020a1709026b8a00b001acaf7e22bdsm11708482plk.14.2023.05.15.07.31.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 May 2023 07:31:06 -0700 (PDT) From: Rob Clark To: dri-devel@lists.freedesktop.org Subject: [PATCH v4 9/9] drm/msm: Wire up comm/cmdline override for fdinfo Date: Mon, 15 May 2023 07:30:16 -0700 Message-Id: <20230515143023.801167-10-robdclark@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230515143023.801167-1-robdclark@gmail.com> References: <20230515143023.801167-1-robdclark@gmail.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Rob Clark , Tvrtko Ursulin , Elliot Berman , Akhil P Oommen , Sean Paul , Emil Velikov , Christopher Healy , Abhinav Kumar , Konrad Dybcio , Maximilian Luz , Boris Brezillon , "open list:DRM DRIVER FOR MSM ADRENO GPU" , Dmitry Baryshkov , freedreno@lists.freedesktop.org, =?utf-8?q?Christian_K=C3=B6nig?= , open list Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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 Reviewed-by: Dmitry Baryshkov --- 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" static u64 address_space_size = 0; MODULE_PARM_DESC(address_space_size, "Override for size of processes private GPU address space"); module_param(address_space_size, ullong, 0600); static bool zap_available = true; @@ -391,47 +392,68 @@ int adreno_set_param(struct msm_gpu *gpu, struct msm_file_private *ctx, return -EINVAL; break; default: if (len != 0) return -EINVAL; } switch (param) { case MSM_PARAM_COMM: case MSM_PARAM_CMDLINE: { - char *str, **paramp; + char *str, *str2, **paramp; + struct drm_file *file = ctx->file; str = kmalloc(len + 1, GFP_KERNEL); if (!str) return -ENOMEM; if (copy_from_user(str, u64_to_user_ptr(value), len)) { kfree(str); return -EFAULT; } /* Ensure string is null terminated: */ str[len] = '\0'; + /* + * 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 = kstrdup(str, GFP_KERNEL); + mutex_lock(&gpu->lock); if (param == MSM_PARAM_COMM) { paramp = &ctx->comm; } else { paramp = &ctx->cmdline; } kfree(*paramp); *paramp = str; mutex_unlock(&gpu->lock); + mutex_lock(&file->override_lock); + + if (param == MSM_PARAM_COMM) { + paramp = &file->override_comm; + } else { + paramp = &file->override_cmdline; + } + + kfree(*paramp); + *paramp = 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 a403aebe7f5a..6dec1a3534f2 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, struct drm_file *file) struct msm_file_private *ctx; ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); if (!ctx) return -ENOMEM; INIT_LIST_HEAD(&ctx->submitqueues); rwlock_init(&ctx->queuelock); kref_init(&ctx->ref); + ctx->file = file; msm_submitqueue_init(dev, ctx); ctx->aspace = msm_gpu_create_private_address_space(priv->gpu, current); file->driver_priv = ctx; ctx->seqno = atomic_inc_return(&ident); return 0; } @@ -596,20 +597,21 @@ static int msm_open(struct drm_device *dev, struct drm_file *file) /* For now, load gpu on open.. to avoid the requirement of having * firmware in the initrd. */ load_gpu(dev); return context_init(dev, file); } static void context_close(struct msm_file_private *ctx) { + ctx->file = NULL; msm_submitqueue_close(ctx); msm_file_private_put(ctx); } static void msm_postclose(struct drm_device *dev, struct drm_file *file) { struct msm_drm_private *priv = dev->dev_private; struct msm_file_private *ctx = file->driver_priv; /* 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; + /** + * @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