From patchwork Thu Apr 27 17:53:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 13225676 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 13621C7EE25 for ; Thu, 27 Apr 2023 17:54:02 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 121BB10E2E3; Thu, 27 Apr 2023 17:54:01 +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 C7DDF10E0C7; Thu, 27 Apr 2023 17:53:55 +0000 (UTC) Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-63b62d2f729so6871507b3a.1; Thu, 27 Apr 2023 10:53:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682618034; x=1685210034; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=sGjGxmlouVGhi3M6MRZkXvcAVwGS3ye2TGK3XrM7dRI=; b=DskqNrsRREOOo5+tJopmLlCj6+GWPbnQOa2+AYvaPYS7fcpG66CcxTCQrmwYXBL3WQ +BkdoMC1ullgLuxY+Ds8+4wtsgzFGje4bjzDVek19jcDHjSS1Iwi3kiHP/PPZLRehB5a Zp9LmrhckNG6ETFh/+OolV51Jh7+GIC9C2SO6R5FS8jYo9CNKgW9yAbalvrpaQyX2EPq eWT+EyJF3gEjxMScpTDYWjmkLghh0ytfAuhZhmGQIQODAZandBUchj8+1gQFeECBQGq8 REtNK/WAXbsVAO/yv/vqGiymb8vtB7zd/Ta6RHuHWOSSGCwY+wkETaKIIS/jwqU+/MpU 8Qkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682618034; x=1685210034; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sGjGxmlouVGhi3M6MRZkXvcAVwGS3ye2TGK3XrM7dRI=; b=hxOJTTOGzs0nmWFhxGd1h2SgQwA/zuT1Cs7nj0tRZyUny5ZJwdNbcG1gPuemzmr+DN ynQf6JgBcXSNDLhorf20Y8ziZf24Un3pY9ZQEC5jfyS2wI6VkkDY/Hr+n4oeNCEb0ISY Tt7eajyWAJhh9V98OjwKpJ2VFAO8woZlHIxHhTSiiU8ivlRG6DwqLVSM+vjhsf3b0iVX cJlDrVIUgOKu2Ki0VI73VcyOTtVRBEHOB7A6TctE1Z7mO2DVl2p4/+9ddcvv1k7f9PLg DANqb4ttnng80yuZNQSMyrIi5gYrfacJ9SFmcDjgUIp5QVNmu/SiMU8SJp21jinYEqA0 RYFw== X-Gm-Message-State: AC+VfDxmrnZjtNCZtvakMqzvUgWNQzoUHNECsgdNV9Ujrb9Sa/2Uopm8 ZsDcdg8KgtuY8eQSU7f9TrHnB9CFlqs= X-Google-Smtp-Source: ACHHUZ6B+aak2ZkUYsB+1ZMUHj9b32Ns03yuVkuacD2JU5/1vQBVbzhVWx7Q599OyF6uLhjfXVdnNQ== X-Received: by 2002:a05:6a20:7f97:b0:f3:67da:9db5 with SMTP id d23-20020a056a207f9700b000f367da9db5mr3076695pzj.38.1682618034603; Thu, 27 Apr 2023 10:53:54 -0700 (PDT) Received: from localhost ([2a00:79e1:abd:4a00:61b:48ed:72ab:435b]) by smtp.gmail.com with ESMTPSA id e27-20020a630f1b000000b00502e7115cbdsm3662034pgl.51.2023.04.27.10.53.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Apr 2023 10:53:54 -0700 (PDT) From: Rob Clark To: dri-devel@lists.freedesktop.org Subject: [PATCH v2 1/9] drm/docs: Fix usage stats typos Date: Thu, 27 Apr 2023 10:53:25 -0700 Message-Id: <20230427175340.1280952-2-robdclark@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230427175340.1280952-1-robdclark@gmail.com> References: <20230427175340.1280952-1-robdclark@gmail.com> MIME-Version: 1.0 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 Reviewed-by: Christian König --- Documentation/gpu/drm-usage-stats.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Documentation/gpu/drm-usage-stats.rst b/Documentation/gpu/drm-usage-stats.rst index b46327356e80..72d069e5dacb 100644 --- a/Documentation/gpu/drm-usage-stats.rst +++ b/Documentation/gpu/drm-usage-stats.rst @@ -105,7 +105,7 @@ object belong to this client, in the respective memory region. Default unit shall be bytes with optional unit specifiers of 'KiB' or 'MiB' indicating kibi- or mebi-bytes. -- 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 @@ -117,7 +117,7 @@ larger value within a reasonable period. Upon observing a value lower than what was previously read, userspace is expected to stay with that larger 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 From patchwork Thu Apr 27 17:53:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 13225677 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 89B23C77B61 for ; Thu, 27 Apr 2023 17:54:05 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E696C10E0E0; Thu, 27 Apr 2023 17:54:04 +0000 (UTC) Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by gabe.freedesktop.org (Postfix) with ESMTPS id 8994F10E24D; Thu, 27 Apr 2023 17:53:57 +0000 (UTC) Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-1a686260adcso91125005ad.0; Thu, 27 Apr 2023 10:53:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682618036; x=1685210036; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=UBhM8EV3rKHhycxSOd95UiYteeNU/7m/WGXxS7jGTSE=; b=Ls4jFb+IpHVK6hd4oTgRZh1XNrm/GGsmbM1MTz2AZcdHdxzQ+tGALfErG4zqPfYALQ 4suMa75vWaO0JTm3RbPgJqDt15bxo2c8F+HfHRiPjEinqB8/NGkGbAyi7kokD/bWzTdH ofTixZ4kDUIr0YC1Q3BCsUPog3gZkjn+nev3RlOo3nHDuxR3S0K91wDdfGxU8thZgQkM DtKNgMs7XHbeRNM7d5v6f0GOCq/CGIPB1zc8DJsG4Sl5kGC4R38T0zddl6DYUwiT9nkA OstnBQtiQGDqTITIUpIvI35QbHJd4DaGJn+rCa0cTHbipCNf+wxE4A6pTqzHLkGz/fEE A7Ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682618036; x=1685210036; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UBhM8EV3rKHhycxSOd95UiYteeNU/7m/WGXxS7jGTSE=; b=eY4cu4a3hlCLeI1BQLaGDW5XRUnNEKPLqxCfSbrVD2MKCkZpihSUcwQxFpESneVCoP anl3RTgW1GU3Nv55WtXtTL828RMYwm8xQTdj0UQUAc1hmtqFUvn4JSx8+lR7oip03Mqm PWciQw6n4JUs/PjoVY1RclV9GVXpuSF/v5ot/oPFPt4dyI40EBZs1Bx87VzaAlhXV9jg h2kjcEBEQAUXYjxy66ne/GeS1V8oVfMKA7susCJak6V9YCZNrKtp3Kkm1FCDBAjslUBv SwjhC9dKUN4k9sYGxpjj+w55tWHscaC053mZAyo58KEQ4/UTcrnK+/K6I4ZUzTrm+uNj M3KQ== X-Gm-Message-State: AC+VfDy3RS+Dsn7BfLGnYa0K8qJeqAKF5t2Ht2txoeWkDYOCku+z77kI OSFZ7O9USadH1W6jWFC3SvzH37AZPhY= X-Google-Smtp-Source: ACHHUZ6IFGCsK9vNT8DizUsnkKluwvUlgTje+Wo9ShQhw/TLfGLD127nu2oMIGujHdFfqPrdp8xeeg== X-Received: by 2002:a17:902:da90:b0:19f:188c:3e34 with SMTP id j16-20020a170902da9000b0019f188c3e34mr2843715plx.53.1682618036600; Thu, 27 Apr 2023 10:53:56 -0700 (PDT) Received: from localhost ([2a00:79e1:abd:4a00:61b:48ed:72ab:435b]) by smtp.gmail.com with ESMTPSA id jl14-20020a170903134e00b001a2104d706fsm11903101plb.225.2023.04.27.10.53.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Apr 2023 10:53:56 -0700 (PDT) From: Rob Clark To: dri-devel@lists.freedesktop.org Subject: [PATCH v2 2/9] drm: Add common fdinfo helper Date: Thu, 27 Apr 2023 10:53:26 -0700 Message-Id: <20230427175340.1280952-3-robdclark@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230427175340.1280952-1-robdclark@gmail.com> References: <20230427175340.1280952-1-robdclark@gmail.com> MIME-Version: 1.0 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 @@ -126,7 +126,15 @@ 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 @@ -148,6 +148,7 @@ bool drm_dev_needs_global_mutex(struct drm_device *dev) */ struct drm_file *drm_file_alloc(struct drm_minor *minor) { + static atomic64_t ident = ATOMIC_INIT(0); struct drm_device *dev = minor->dev; struct drm_file *file; int ret; @@ -156,6 +157,8 @@ struct drm_file *drm_file_alloc(struct drm_minor *minor) if (!file) return ERR_PTR(-ENOMEM); + /* Get a unique identifier for fdinfo: */ + file->client_id = atomic64_inc_return(&ident); file->pid = get_pid(task_pid(current)); file->minor = minor; @@ -868,6 +871,38 @@ void drm_send_event(struct drm_device *dev, struct drm_pending_event *e) } 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) diff --git a/include/drm/drm_drv.h b/include/drm/drm_drv.h index 5b86bb7603e7..5edf2a13733b 100644 --- a/include/drm/drm_drv.h +++ b/include/drm/drm_drv.h @@ -401,6 +401,13 @@ struct drm_driver { struct drm_device *dev, uint32_t handle, uint64_t *offset); + /** + * @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 */ diff --git a/include/drm/drm_file.h b/include/drm/drm_file.h index 0d1f853092ab..6de6d0e9c634 100644 --- a/include/drm/drm_file.h +++ b/include/drm/drm_file.h @@ -258,6 +258,9 @@ struct drm_file { /** @pid: Process that opened this file. */ struct pid *pid; + /** @client_id: A unique id for fdinfo */ + u64 client_id; + /** @magic: Authentication magic, see @authenticated. */ drm_magic_t magic; @@ -437,6 +440,7 @@ void drm_send_event(struct drm_device *dev, struct drm_pending_event *e); void drm_send_event_timestamp_locked(struct drm_device *dev, struct drm_pending_event *e, ktime_t timestamp); +void drm_show_fdinfo(struct seq_file *m, struct file *f); struct file *mock_drm_getfile(struct drm_minor *minor, unsigned int flags); From patchwork Thu Apr 27 17:53:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 13225678 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 D295EC77B7E for ; Thu, 27 Apr 2023 17:54:10 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 74A6D10E360; Thu, 27 Apr 2023 17:54:09 +0000 (UTC) Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by gabe.freedesktop.org (Postfix) with ESMTPS id 79D1B10E24D; Thu, 27 Apr 2023 17:53:59 +0000 (UTC) Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-64115eef620so6795971b3a.1; Thu, 27 Apr 2023 10:53:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682618038; x=1685210038; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=oBfxB8yEA4WhI7T5i4/ckAUY1Fu23yRgn7oYj27vnCU=; b=L1nF7BCZaBP86QA8Op3mSkjT2UtT+S15flbFR0f0eOTvMVCmfniMiX5dID5EGdz61P ieBXt1NAw2rxJgHrdwYLvYF8ntYs4uwj/nCjpgEGDfTseJ92qQ5SGsYki0aaWcyh2fyK G8prdb/NM5zCZStwSZi/WFKVIIR3AGA9eVpOdScXgRqb3uSpdJLJxSSElMl7cbPBDeAH Y1Y0nlker1Z8x5URSZwMVkAevF7c3TIg3usf5LEI/IxnihLFUOeJBclUBbdpOjzhgFsp lTvKPPaqKjwWiBCGAuNgFYnPNzSurCA4dhFw+DIsH2gG0WZx4gYezqrHFX7eHOlkgZzU zwbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682618038; x=1685210038; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oBfxB8yEA4WhI7T5i4/ckAUY1Fu23yRgn7oYj27vnCU=; b=bksb4YI/+yIW1GUmCutnfpz5YNz/d9CF4SViXqX9uYfm3Q/RJwoaUDJqQGjTK5jLsJ 1S4gek/T9uNR0KFkf/CJTGQhn7ZgRlLUD9R6uVLCVmtE/UYRyDi+3Ys28khvIhzYMLEI VKtrh/mQdvyvZRbbc71W8ZfKoX+FyOwbyNseTjiC1qmoDE3Pc/eEPFXLlhxSQh9ht22j hRR1DlzomMqllpzoe9+Nee/21NXt08BWgX6opuH2ctaGtETCbSty5i8CsxuGtFvt4bMJ hzTP9Lr/GQ8gsVyvIIRtbaAkPMtlrjPlmIa0Cl0PZZ9sSz5kADVLo/1YM4paDRrPcaPt mSmA== X-Gm-Message-State: AC+VfDxCiejESf7Lx0JOvA8oYJ02LZ43mBJr9+wjke89EWv7xCt2KI1U 9ACCVeCCbJeQd8xuHvz9USlL5Im6/68= X-Google-Smtp-Source: ACHHUZ4RY8lUy/Z4Ld9c0UFYaaSoWErxG6HLfP2eNZlkE1GaZYLb1I87VbW+l/YJFqATDwzqwkRTig== X-Received: by 2002:a17:902:d484:b0:1a9:68d2:e4ae with SMTP id c4-20020a170902d48400b001a968d2e4aemr8298243plg.2.1682618038445; Thu, 27 Apr 2023 10:53:58 -0700 (PDT) Received: from localhost ([2a00:79e1:abd:4a00:61b:48ed:72ab:435b]) by smtp.gmail.com with ESMTPSA id u13-20020a170902e80d00b0019719f752c5sm1638484plg.59.2023.04.27.10.53.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Apr 2023 10:53:58 -0700 (PDT) From: Rob Clark To: dri-devel@lists.freedesktop.org Subject: [PATCH v2 3/9] drm/msm: Switch to fdinfo helper Date: Thu, 27 Apr 2023 10:53:27 -0700 Message-Id: <20230427175340.1280952-4-robdclark@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230427175340.1280952-1-robdclark@gmail.com> References: <20230427175340.1280952-1-robdclark@gmail.com> MIME-Version: 1.0 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 9b6f17b1261f..1e941aa77609 100644 --- a/drivers/gpu/drm/msm/msm_drv.c +++ b/drivers/gpu/drm/msm/msm_drv.c @@ -1043,23 +1043,21 @@ static const struct drm_ioctl_desc msm_ioctls[] = { 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 = { @@ -1069,7 +1067,7 @@ static const struct drm_driver msm_driver = { 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, @@ -1080,6 +1078,7 @@ static const struct drm_driver msm_driver = { #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, diff --git a/drivers/gpu/drm/msm/msm_gpu.c b/drivers/gpu/drm/msm/msm_gpu.c index b1647b851018..52db90e34ead 100644 --- a/drivers/gpu/drm/msm/msm_gpu.c +++ b/drivers/gpu/drm/msm/msm_gpu.c @@ -151,8 +151,6 @@ int msm_gpu_pm_suspend(struct msm_gpu *gpu) void msm_gpu_show_fdinfo(struct msm_gpu *gpu, struct msm_file_private *ctx, struct drm_printer *p) { - drm_printf(p, "drm-driver:\t%s\n", gpu->dev->driver->name); - drm_printf(p, "drm-client-id:\t%u\n", ctx->seqno); drm_printf(p, "drm-engine-gpu:\t%llu ns\n", ctx->elapsed_ns); drm_printf(p, "drm-cycles-gpu:\t%llu\n", ctx->cycles); drm_printf(p, "drm-maxfreq-gpu:\t%u Hz\n", gpu->fast_rate); From patchwork Thu Apr 27 17:53:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 13225680 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 EB0B8C77B7E for ; Thu, 27 Apr 2023 17:54:13 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8929F10EBAA; Thu, 27 Apr 2023 17:54:10 +0000 (UTC) Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by gabe.freedesktop.org (Postfix) with ESMTPS id BFE8610E0E0; Thu, 27 Apr 2023 17:54:03 +0000 (UTC) Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-64115eef620so6796613b3a.1; Thu, 27 Apr 2023 10:54:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682618043; x=1685210043; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kTwA5Igpbrlnqx2MFioiqClnnk3fWCd7F6gKiXvsizg=; b=F02JosDYSh6gH8BbBVyLQpfSS+7jFCWgel+AjYaRMDX6D8xc/HdFGNUw/LP4VfuhKO FBGI+ypyvSemxnMhgbXmZhIj0XAsFs578Ow2DPZX6tr0p6k0r7tRA0tkDLWNgoI66t14 ChadQMBb4p5jszCF567xmG+p0QDKicYptfWnC10WXOjeNrcro5Kl4r0qSGiZ7igOJ9yw ur+tS0pDFIXAvtNgVWdz84HVxOS7GQZpK/ZRRCoMAELIQdgaEAUBJ8h113jxpNcWYFbz 1Qb9YqiCSLdpHjJTq8V4AyQXpEjLA0vl/xdhw7dWvJ6JZymB4bWO37FZtlgp47OJClNi NuJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682618043; x=1685210043; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kTwA5Igpbrlnqx2MFioiqClnnk3fWCd7F6gKiXvsizg=; b=f1fP1LBhsUWSgT5qeaWHrBfS8VxNER7I+Ii8pN0sN4HORSsWlJarX3d34jkIVt5alP L/CqPozrCAxRaNqg0XIuAntA3ipQO8WDgXQyeYHSvikYqM9BNnCfG6KuIZeApfOBO0qx 1uXNOeMJKvoh4L7uuNEsKvewyPuJEIQKy1mCs65T6d7KRQ+JX+knsv0Er67t33Qc/RUe k0mIZKEP83viXRutm8VaBF0i+MYxIIfS/hihf/5gbVsXvCIXrA1LyIO0vckmUEWeQlUb d1v4dYFukn4gViBynI6nYcrB7O6vDJr2yg6+0hBuGhIyw8UuVJv8HqT5TV0bwiie4a2K T+6A== X-Gm-Message-State: AC+VfDxAPYWzYlk+B2Gxqd8GQ4gB/8vU2L+9Ykctk1ZpzLmcBFE6PBnY zdFryToI+7q26SlsGJBvOlkmPIy6iLY= X-Google-Smtp-Source: ACHHUZ6LNNj8gqJAFOABkk08xjTsf/iTgKG8pNsMVfNLhyxs19frA15VFo4R4M5e8URgVw6J5vEgMw== X-Received: by 2002:a17:90a:cb81:b0:249:7ad3:e843 with SMTP id a1-20020a17090acb8100b002497ad3e843mr3282208pju.16.1682618043189; Thu, 27 Apr 2023 10:54:03 -0700 (PDT) Received: from localhost ([2a00:79e1:abd:4a00:61b:48ed:72ab:435b]) by smtp.gmail.com with ESMTPSA id ls17-20020a17090b351100b0023a9564763bsm13396089pjb.29.2023.04.27.10.54.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Apr 2023 10:54:02 -0700 (PDT) From: Rob Clark To: dri-devel@lists.freedesktop.org Subject: [PATCH v2 4/9] drm/amdgpu: Switch to fdinfo helper Date: Thu, 27 Apr 2023 10:53:28 -0700 Message-Id: <20230427175340.1280952-5-robdclark@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230427175340.1280952-1-robdclark@gmail.com> References: <20230427175340.1280952-1-robdclark@gmail.com> MIME-Version: 1.0 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: Lijo Lazar , 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 , Tvrtko Ursulin , Tvrtko Ursulin , "Pan, Xinhui" , Emil Velikov , Christopher Healy , Boris Brezillon , Alex Deucher , freedreno@lists.freedesktop.org, =?utf-8?q?Christian_K=C3=B6nig?= , Hawking Zhang 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 @@ -2752,7 +2752,7 @@ static const struct file_operations amdgpu_driver_kms_fops = { .compat_ioctl = amdgpu_kms_compat_ioctl, #endif #ifdef CONFIG_PROC_FS - .show_fdinfo = amdgpu_show_fdinfo + .show_fdinfo = drm_show_fdinfo, #endif }; @@ -2807,6 +2807,7 @@ static const struct drm_driver amdgpu_kms_driver = { .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, 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 @@ -53,9 +53,8 @@ static const char *amdgpu_ip_name[AMDGPU_HW_IP_NUM] = { [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; @@ -86,18 +85,15 @@ void amdgpu_show_fdinfo(struct seq_file *m, struct file *f) * ****************************************************************** */ - 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 @@ -37,6 +37,6 @@ #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 Thu Apr 27 17:53:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 13225681 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 E6DF9C77B61 for ; Thu, 27 Apr 2023 17:54:15 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id EF3B010E03D; Thu, 27 Apr 2023 17:54:09 +0000 (UTC) Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2043E10E32B; Thu, 27 Apr 2023 17:54:06 +0000 (UTC) Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-63b78b344d5so6923703b3a.1; Thu, 27 Apr 2023 10:54:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682618045; x=1685210045; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=p73C15js764dzQJEgbWBx+7QNMsWovIoyzGPpjczgNY=; b=kCxBda4dX0v9+KBOw3q745gxPj6sZv6R2ayxpdDPKEgoo5SEdRuB63GjusADcmhym3 dwk+FD/2zxoUdKFhPkBpIioo3kSpRwziJ8SHPBqIkUsAp/Aww4Km6iE/ZF+/qKjwEIcP BZopZG6XHUscKCfj2SOJU9rO73+xOjUa4shfwY6YA36QbWcERYDtEkxMvnTm4QQ0RX+y 9z8HZFFAewmbZFIFYwKq/VpgRdjxEMdN4xNBZ64SNcxr42LqMzR2uzrhw6R3hk9tqXu8 b2ym0VtpRaZVr8+BhPc72xSXoGQCq0NUfMo+A9mfF0wUD8z3XpW1OQg5HcbJTgvnSuuk hBHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682618045; x=1685210045; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=p73C15js764dzQJEgbWBx+7QNMsWovIoyzGPpjczgNY=; b=B1fWmht1jj+fCCz8lQy3RC3FdY4V35XckzouJN9PBM3Ke0fOjpfLp4nWgcAK/F9Wxp v2oODT4tIJ0kxybq7MzoYCT2XaVAQi0aD+Al8ZIAZmJ7Qk2voAGJQMov9Svw9eLg8sIm oB2tmlGEZSrYP9wawujeAq3mSlmiz9RecrjhcMm0TxIXURCeheDTM22bWAY2oBnSp63h bD//t+9rFuIFk3Vx7Y/cGfOt9tku3kpT+hmvFRmK4Sme+Z+ZyeJme4+AO2oaZNMBd6Qp Ha+6hF3z/r+szH0XcmoO7NiLVic/Grq2pY7J/e1HbRoBY/YN4NUD21Frr8GG3Zrh0PLW qf6g== X-Gm-Message-State: AC+VfDzF/Bf6vFpFXWORhumHHYzh5I2yWWn95xDm7mqUpK7x28e77OsO uJYg24YC7ZSVoUOrGq9IgtkpNSIFKik= X-Google-Smtp-Source: ACHHUZ53SdbC+GkAvFXw8H5V9YJK9MOfeVPqmP/O5m4zpTSne+FvC+0QNJsFZFXd++qOvmCi+EqtEw== X-Received: by 2002:a05:6a00:b52:b0:634:4dea:81c6 with SMTP id p18-20020a056a000b5200b006344dea81c6mr4015210pfo.0.1682618045198; Thu, 27 Apr 2023 10:54:05 -0700 (PDT) Received: from localhost ([2a00:79e1:abd:4a00:61b:48ed:72ab:435b]) by smtp.gmail.com with ESMTPSA id o76-20020a62cd4f000000b0063d6666ee4csm13514749pfg.34.2023.04.27.10.54.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Apr 2023 10:54:04 -0700 (PDT) From: Rob Clark To: dri-devel@lists.freedesktop.org Subject: [PATCH v2 5/9] drm: Add fdinfo memory stats Date: Thu, 27 Apr 2023 10:53:29 -0700 Message-Id: <20230427175340.1280952-6-robdclark@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230427175340.1280952-1-robdclark@gmail.com> References: <20230427175340.1280952-1-robdclark@gmail.com> MIME-Version: 1.0 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 Add support to dump GEM stats to fdinfo. v2: Fix typos, change size units to match docs, use div_u64 v3: Do it in core v4: more kerneldoc Signed-off-by: Rob Clark Reviewed-by: Emil Velikov Reviewed-by: Daniel Vetter --- Documentation/gpu/drm-usage-stats.rst | 54 +++++++++++---- drivers/gpu/drm/drm_file.c | 99 ++++++++++++++++++++++++++- include/drm/drm_file.h | 19 +++++ include/drm/drm_gem.h | 30 ++++++++ 4 files changed, 189 insertions(+), 13 deletions(-) diff --git a/Documentation/gpu/drm-usage-stats.rst b/Documentation/gpu/drm-usage-stats.rst index 552195fb1ea3..bfc14150452c 100644 --- a/Documentation/gpu/drm-usage-stats.rst +++ b/Documentation/gpu/drm-usage-stats.rst @@ -52,6 +52,9 @@ String shall contain the name this driver registered as via the respective Optional fully standardised keys -------------------------------- +Identification +^^^^^^^^^^^^^^ + - drm-pdev: For PCI devices this should contain the PCI slot address of the device in @@ -69,6 +72,9 @@ scope of each device, in which case `drm-pdev` shall be 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 @@ -93,18 +99,6 @@ 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 @@ -126,6 +120,42 @@ 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 +object belong to this client, in the respective memory region. + +Default unit shall be bytes with optional unit specifiers of 'KiB' or 'MiB' +indicating kibi- or mebi-bytes. + +- drm-shared-: [KiB|MiB] + +The total size of buffers that are shared with another file (ie. have more +than a single handle). + +- drm-private-: [KiB|MiB] + +The total size of buffers that are not shared with another file. + +- drm-resident-: [KiB|MiB] + +The total size of buffers that are resident in system memory. + +- drm-purgeable-: [KiB|MiB] + +The total size of buffers that are purgeable. + +- drm-active-: [KiB|MiB] + +The total size of buffers that are active on one or more rings. + Implementation Details ====================== diff --git a/drivers/gpu/drm/drm_file.c b/drivers/gpu/drm/drm_file.c index 6d5bdd684ae2..9321eb0bf020 100644 --- a/drivers/gpu/drm/drm_file.c +++ b/drivers/gpu/drm/drm_file.c @@ -42,6 +42,7 @@ #include #include #include +#include #include #include "drm_crtc_internal.h" @@ -871,9 +872,105 @@ void drm_send_event(struct drm_device *dev, struct drm_pending_event *e) } EXPORT_SYMBOL(drm_send_event); +static void print_size(struct drm_printer *p, const char *stat, + const char *region, size_t 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%zu%s\n", stat, region, sz, units[u]); +} + +/** + * drm_print_memory_stats - A helper to print memory stats + * @p: The printer to print output to + * @stats: The collected memory stats + * @supported_status: Bitmask of optional stats which are available + * @region: The memory region + * + */ +void drm_print_memory_stats(struct drm_printer *p, + const struct drm_memory_stats *stats, + enum drm_gem_object_status supported_status, + const char *region) +{ + print_size(p, "total", region, stats->private + stats->shared); + print_size(p, "shared", region, stats->shared); + print_size(p, "active", region, stats->active); + + if (supported_status & DRM_GEM_OBJECT_RESIDENT) + print_size(p, "resident", region, stats->resident); + + if (supported_status & DRM_GEM_OBJECT_PURGEABLE) + print_size(p, "purgeable", region, stats->purgeable); +} +EXPORT_SYMBOL(drm_print_memory_stats); + +/** + * drm_show_memory_stats - Helper to collect and show standard fdinfo 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 diff --git a/include/drm/drm_file.h b/include/drm/drm_file.h index 6de6d0e9c634..1339e925af52 100644 --- a/include/drm/drm_file.h +++ b/include/drm/drm_file.h @@ -41,6 +41,7 @@ struct dma_fence; struct drm_file; struct drm_device; +struct drm_printer; struct device; struct file; @@ -440,6 +441,24 @@ void drm_send_event(struct drm_device *dev, struct drm_pending_event *e); void drm_send_event_timestamp_locked(struct drm_device *dev, struct drm_pending_event *e, ktime_t timestamp); + + +struct drm_memory_stats { + size_t shared; + size_t private; + size_t resident; + size_t purgeable; + size_t active; +}; + +enum drm_gem_object_status; + +void drm_print_memory_stats(struct drm_printer *p, + const struct drm_memory_stats *stats, + enum drm_gem_object_status supported_status, + const char *region); + +void drm_show_memory_stats(struct drm_printer *p, struct drm_file *file); void drm_show_fdinfo(struct seq_file *m, struct file *f); struct file *mock_drm_getfile(struct drm_minor *minor, unsigned int flags); diff --git a/include/drm/drm_gem.h b/include/drm/drm_gem.h index 189fd618ca65..9ebd2820ad1f 100644 --- a/include/drm/drm_gem.h +++ b/include/drm/drm_gem.h @@ -42,6 +42,25 @@ struct iosys_map; struct drm_gem_object; +/** + * 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 */ @@ -174,6 +193,17 @@ struct drm_gem_object_funcs { */ 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. + */ + enum drm_gem_object_status (*status)(struct drm_gem_object *obj); + /** * @vm_ops: * From patchwork Thu Apr 27 17:53:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 13225679 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 04BB0C77B73 for ; Thu, 27 Apr 2023 17:54:12 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7E21010EBA0; Thu, 27 Apr 2023 17:54:09 +0000 (UTC) Received: from mail-pg1-x533.google.com (mail-pg1-x533.google.com [IPv6:2607:f8b0:4864:20::533]) by gabe.freedesktop.org (Postfix) with ESMTPS id 10D6E10E360; Thu, 27 Apr 2023 17:54:07 +0000 (UTC) Received: by mail-pg1-x533.google.com with SMTP id 41be03b00d2f7-524b02cc166so5089051a12.0; Thu, 27 Apr 2023 10:54:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682618047; x=1685210047; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=tk36LHgT7Zd3DnVnkUrHTABb/+wFJaIJC2KssqoMtiA=; b=eLrWdp6G4Kchqv4Qdaauo7bSYHMHL3SgbOabiyKhti17zyGH3h7Fn5HV8Rjz/7qIUT u7lM4YrdTNZ9IYLVHRBiOuF2MFueaj6VxzcGfAm1y2HXpLywUb0Yr5/HwDnmmnahA8yY gkPqgz/HtXC50zqptgdfI/DyIlOj/WpKZssQISqmRNJ3dL8peof2/aLv2sMbKyyrTpiu JO3IMj1mhKLtQshAka98lVJX7Od8yfJiwNScAxYZ26Fbs4k8k6mOWaBHNe+P5BqTxET6 gE40PvRGCjMy/SpZLKboyq710VewPdBfOVhTqamRYrUMYAC6Ni6wHczYFR24EHIFxaXE pmxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682618047; x=1685210047; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tk36LHgT7Zd3DnVnkUrHTABb/+wFJaIJC2KssqoMtiA=; b=hYQV9XHYL7mZEFi0yKnJ4yjCqBVxzN0ws102ypBdIOEVvD75tMdKzQ8RDV1XrLJaVx 9CGpfCsfoOxOkW1defMEMNNvF3zkPY/111igkuUSCvmVpaPBV0KegGfojWBnxjvJG/xX pmE5EAMRyGozmdRrcKM4BsV9EBNY25ZI0xyVrLMtVu8CYFZkbXCu/RDz0Rl2xPu5alRb dqQsT2CpiUE2eU8+fhIfSz4mmN9fmqMdFb79Tu0tJ6rFylac4JzplDmyLIbpyHnniGcI goyVimYpUCt5GeKjbpTPxqKc/2rf2AIykSfa8bHwjDqw8aBfWDZGNFz3saIABAiqEBsz 0O0A== X-Gm-Message-State: AC+VfDxSmT5VJKkgtt/tvguM/IlK8LBTprT1cmH3+t9uhYvhaJheXVPi d1nU60khN7RoApbcxRDo1weOuF2TpUY= X-Google-Smtp-Source: ACHHUZ60SORnik/eSAifUwaYbsYC/Ea5qlWfZS6XAVfSHEgeUf/F/4TBA83gnvjAxC1qtMElfaHudw== X-Received: by 2002:a17:90b:4f4b:b0:23d:31c3:c98d with SMTP id pj11-20020a17090b4f4b00b0023d31c3c98dmr2686481pjb.15.1682618046972; Thu, 27 Apr 2023 10:54:06 -0700 (PDT) Received: from localhost ([2a00:79e1:abd:4a00:61b:48ed:72ab:435b]) by smtp.gmail.com with ESMTPSA id r78-20020a632b51000000b00520f316ebe3sm11614239pgr.62.2023.04.27.10.54.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Apr 2023 10:54:06 -0700 (PDT) From: Rob Clark To: dri-devel@lists.freedesktop.org Subject: [PATCH v2 6/9] drm/msm: Add memory stats to fdinfo Date: Thu, 27 Apr 2023 10:53:30 -0700 Message-Id: <20230427175340.1280952-7-robdclark@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230427175340.1280952-1-robdclark@gmail.com> References: <20230427175340.1280952-1-robdclark@gmail.com> MIME-Version: 1.0 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 1e941aa77609..81a1371c0307 100644 --- a/drivers/gpu/drm/msm/msm_drv.c +++ b/drivers/gpu/drm/msm/msm_drv.c @@ -1052,6 +1052,8 @@ static void msm_show_fdinfo(struct drm_printer *p, struct drm_file *file) return; msm_gpu_show_fdinfo(priv->gpu, file->driver_priv, p); + + drm_show_memory_stats(p, file); } static const struct file_operations fops = { diff --git a/drivers/gpu/drm/msm/msm_gem.c b/drivers/gpu/drm/msm/msm_gem.c index cd39b9d8abdb..20cfd86d2b32 100644 --- a/drivers/gpu/drm/msm/msm_gem.c +++ b/drivers/gpu/drm/msm/msm_gem.c @@ -1090,6 +1090,20 @@ int msm_gem_new_handle(struct drm_device *dev, struct drm_file *file, 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, @@ -1104,6 +1118,7 @@ static const struct drm_gem_object_funcs msm_gem_object_funcs = { .vmap = msm_gem_prime_vmap, .vunmap = msm_gem_prime_vunmap, .mmap = msm_gem_object_mmap, + .status = msm_gem_status, .vm_ops = &vm_ops, }; From patchwork Thu Apr 27 17:53:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 13225683 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 D02BEC77B61 for ; Thu, 27 Apr 2023 17:54:31 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1085910EBA6; Thu, 27 Apr 2023 17:54:31 +0000 (UTC) Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by gabe.freedesktop.org (Postfix) with ESMTPS id 061B410EBA6; Thu, 27 Apr 2023 17:54:09 +0000 (UTC) Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-63b67a26069so10979573b3a.0; Thu, 27 Apr 2023 10:54:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682618049; x=1685210049; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5X8ws8C9Uya1bH1qvM3ByEZiUSzSNNSQCvKC0+MH6tc=; b=FJmULW49+UMYCVzDkpdb7BszKylFpQ8Go8QKjSNPi9p1Epfy9Abj+ptulI1LZsNXYO Drur1lnhr+2tDX7fQ5TKZA6bWEIgZuH6kNGI3k3r76j0lFiQ2B3/ufbtNACKCxcYD3PD 2oiXG504lUTQJI8Ol1FBvV0twNshzJFLFJNj5v2Y/ze2zM7gaXKXVrQkJDZKFLRqg1HA aQ8ArDm80oS8vDG+z7RNtaF5HamxWhVFBKj8cE/bG2KcuxlKFD0q6pBs2kxDH/FJBDIS 9mMTob0B48PC8gzJcc/I4A2EMUcHUJj0GYAPsFe5i6yUQQGY7w7y8ITx7QFUaSsqOMRy rQlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682618049; x=1685210049; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5X8ws8C9Uya1bH1qvM3ByEZiUSzSNNSQCvKC0+MH6tc=; b=PszJBpdaCAGX6FCJDrSehW3cE4NVXIsRhciWQGDBbcobotwj2j82fsZFvvWFFm55JP EPBlSweJ16UbBeEHIXG0d7357yc8v6cwoN6N+qoiDB3WaaJx/DEHxIC3Ojskb9yipXOz wLzVq8fBRq0YLSusV1RRWF/SpqYKDNSjntXyghsU//jRTwZh+TykKCqrmLRJLtrHDr7+ ElFOlUy0FAf6O9GOvBRR4o0uXL6khc9xhRsBJIVvkkrBluTDyQhJjpnVwFJe49KmDzrp 7sa41uHtCzY3vlOYErmp5/UE7bSnl1dWgYnU8bkv/g3Veu5pkP5J/SMcFZzJIfW1YVeV orJQ== X-Gm-Message-State: AC+VfDz7cCm2uvMGvheHBG2jE4hGh8DGXkGyzfGhZBGGIRjGKXCPJgYo 2nMNKDmaryreViPS2mABi66Opi4aXic= X-Google-Smtp-Source: ACHHUZ4MKuwKrDINV0TTla8lJWfaf+1NN+A7s4Fg1UjvkclS6fQTdlIEtFpva4hScU7H2HtK4HrNrQ== X-Received: by 2002:a05:6a00:807:b0:63f:244d:cd07 with SMTP id m7-20020a056a00080700b0063f244dcd07mr3256742pfk.31.1682618048750; Thu, 27 Apr 2023 10:54:08 -0700 (PDT) Received: from localhost ([2a00:79e1:abd:4a00:61b:48ed:72ab:435b]) by smtp.gmail.com with ESMTPSA id s9-20020a63e809000000b00476d1385265sm11680207pgh.25.2023.04.27.10.54.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Apr 2023 10:54:08 -0700 (PDT) From: Rob Clark To: dri-devel@lists.freedesktop.org Subject: [PATCH v2 7/9] drm/doc: Relax fdinfo string constraints Date: Thu, 27 Apr 2023 10:53:31 -0700 Message-Id: <20230427175340.1280952-8-robdclark@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230427175340.1280952-1-robdclark@gmail.com> References: <20230427175340.1280952-1-robdclark@gmail.com> MIME-Version: 1.0 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 bfc14150452c..58dc0d3f8c58 100644 --- a/Documentation/gpu/drm-usage-stats.rst +++ b/Documentation/gpu/drm-usage-stats.rst @@ -24,7 +24,7 @@ File format specification - All keys shall be prefixed with `drm-`. - Whitespace between the delimiter and first non-whitespace character 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. @@ -39,12 +39,13 @@ 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. @@ -75,10 +76,10 @@ 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 @@ -90,19 +91,19 @@ larger value within a reasonable period. Upon observing a value lower than what was previously read, userspace is expected to stay with that larger 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 @@ -111,12 +112,12 @@ 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. From patchwork Thu Apr 27 17:53:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 13225682 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 E8948C77B61 for ; Thu, 27 Apr 2023 17:54:19 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4978710EBC1; Thu, 27 Apr 2023 17:54:19 +0000 (UTC) Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by gabe.freedesktop.org (Postfix) with ESMTPS id 8A27210EBA6; Thu, 27 Apr 2023 17:54:11 +0000 (UTC) Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-64115eef620so6797437b3a.1; Thu, 27 Apr 2023 10:54:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682618051; x=1685210051; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=sGLJmibW87WAJcS5t0uIh72jCVPBIb7Gj0WXUx1P9zU=; b=QMXQRPIdXA5q5Km0eEBU7rKyuFO/cgMrtoDCMJdyNqAiJII2NpWeJLh5tHe70Cy232 Sm5bFKWRn1oSSzIdYYglEqg8J6RUhcSkcWnMH7d4qgcvGCmFinBCuh81eI4k4yWHVpvx ZGSfIBbB+9WYYIJU6QL3JOedPPhjgrhrXsvSGBPHyj1zrMv0q578RG/AT6Ue8xSs2fL3 VqFTs5aUbk2lfTToiCebxdTsxyY8QfQ8af5msEFx2/6VxM7sz1Mj6jn3ZRQ6NcpfhnBz smFVLkXfhebsJulsoQqEEQZQriQbsmux38e2ELM+/aEBKnk7Y2f+FUt5q8Q7P6pfwUeA 1fdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682618051; x=1685210051; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sGLJmibW87WAJcS5t0uIh72jCVPBIb7Gj0WXUx1P9zU=; b=kVdLKSX9rinbJ5+VJYrohR/1CP0U35hyOXe3ygUdIgD7wb92wOpzd3cZ6dqXM5dtjX 1FWB9QW2JFIFWaRInISH7Mw7nU4u1YMoDnhFMCsmoXdCU6cvNAoPP066E4hXV2ONHbdM edYWcHl+ddrufJ5JHtuu0xkzd9qAC8TarGZ7Fhjca/hmCoq48XPnog1wiFqAkSi0nfEt b/lumOJeoX++L1hMA66Qw+cnRXhSM9zXDeztpjZDIHxdH+SGO3CeOfZAqdKKHCEROoT/ JznVU7DWj+hoXTm/eaD/SHpgqHnt2vOZa8uL2/eqrCa1PdwKXskVE9aGKq0TWIBn4zF+ bQkA== X-Gm-Message-State: AC+VfDwTVW1Uf9Sw1N2X/e+vrsZu70+EQSphFow2zI+Qr9pnC7Uf2ijK mYi9QJ8f2Pjv7zPl4Fy5peHjLlUgs6w= X-Google-Smtp-Source: ACHHUZ6Nn15Zn+c1Wo6Qo1HTjwDdKmVdH9HihAreo97OXBbuOLvs3ki9YVei3t6pb2Epm77vQyXY1g== X-Received: by 2002:a05:6a20:918f:b0:f0:3fc4:744f with SMTP id v15-20020a056a20918f00b000f03fc4744fmr3333199pzd.8.1682618050907; Thu, 27 Apr 2023 10:54:10 -0700 (PDT) Received: from localhost ([2a00:79e1:abd:4a00:61b:48ed:72ab:435b]) by smtp.gmail.com with ESMTPSA id y189-20020a62cec6000000b00640defda6d2sm6860749pfg.207.2023.04.27.10.54.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Apr 2023 10:54:10 -0700 (PDT) From: Rob Clark To: dri-devel@lists.freedesktop.org Subject: [PATCH v2 8/9] drm/fdinfo: Add comm/cmdline override fields Date: Thu, 27 Apr 2023 10:53:32 -0700 Message-Id: <20230427175340.1280952-9-robdclark@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230427175340.1280952-1-robdclark@gmail.com> References: <20230427175340.1280952-1-robdclark@gmail.com> MIME-Version: 1.0 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. Signed-off-by: Rob Clark Reviewed-by: Tvrtko Ursulin --- Documentation/gpu/drm-usage-stats.rst | 18 ++++++++++++++++++ drivers/gpu/drm/drm_file.c | 15 +++++++++++++++ include/drm/drm_file.h | 19 +++++++++++++++++++ 3 files changed, 52 insertions(+) diff --git a/Documentation/gpu/drm-usage-stats.rst b/Documentation/gpu/drm-usage-stats.rst index 58dc0d3f8c58..e4877cf8089c 100644 --- a/Documentation/gpu/drm-usage-stats.rst +++ b/Documentation/gpu/drm-usage-stats.rst @@ -73,6 +73,24 @@ scope of each device, in which case `drm-pdev` shall be present as well. Userspace should make sure to not double account any usage statistics by using the above described criteria in order to associate data to individual clients. +- drm-comm-override: + +Returns the client executable override string. Some drivers support letting +userspace override this in cases where the userspace is simply a "proxy". +Such as is the case with virglrenderer drm native context, where the host +process is just forwarding command submission, etc, from guest userspace. +This allows the proxy to make visible the executable name of the actual +app in the VM guest. + +- drm-cmdline-override: + +Returns the client cmdline override string. Some drivers support letting +userspace override this in cases where the userspace is simply a "proxy". +Such as is the case with virglrenderer drm native context, where the host +process is just forwarding command submission, etc, from guest userspace. +This allows the proxy to make visible the cmdline of the actual app in the +VM guest. + Utilization ^^^^^^^^^^^ diff --git a/drivers/gpu/drm/drm_file.c b/drivers/gpu/drm/drm_file.c index 9321eb0bf020..d7514c313af1 100644 --- a/drivers/gpu/drm/drm_file.c +++ b/drivers/gpu/drm/drm_file.c @@ -178,6 +178,8 @@ struct drm_file *drm_file_alloc(struct drm_minor *minor) spin_lock_init(&file->master_lookup_lock); mutex_init(&file->event_read_lock); + mutex_init(&file->override_lock); + if (drm_core_check_feature(dev, DRIVER_GEM)) drm_gem_open(dev, file); @@ -292,6 +294,8 @@ void drm_file_free(struct drm_file *file) WARN_ON(!list_empty(&file->event_list)); put_pid(file->pid); + kfree(file->override_comm); + kfree(file->override_cmdline); kfree(file); } @@ -995,6 +999,17 @@ void drm_show_fdinfo(struct seq_file *m, struct file *f) 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); } diff --git a/include/drm/drm_file.h b/include/drm/drm_file.h index 1339e925af52..604d05fa6f0c 100644 --- a/include/drm/drm_file.h +++ b/include/drm/drm_file.h @@ -370,6 +370,25 @@ struct drm_file { */ struct drm_prime_file_private prime; + /** + * @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 */ From patchwork Thu Apr 27 17:53:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 13225684 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 B08E8C77B73 for ; Thu, 27 Apr 2023 17:54:33 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 953DF10EBBC; Thu, 27 Apr 2023 17:54:32 +0000 (UTC) Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by gabe.freedesktop.org (Postfix) with ESMTPS id 1EFF310EBB5; Thu, 27 Apr 2023 17:54:15 +0000 (UTC) Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1a9253d4551so68669335ad.0; Thu, 27 Apr 2023 10:54:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682618054; x=1685210054; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3ok26iuO88WTdiTh3yqSvF0njUaJd/G7EVrYrB/tlNM=; b=NGkm71aOJ/s2qjTeR/gaLYWgyuhDv8G+me2tBr6PxbRaq548LAyp+ofSB/dnvdlG4R I0wgCM/25DaIqgEo3jPIP843OCkPqhy0nXXYCOS+CS1MurrPlIwbHuYOk/q+Z88c+IO0 P6wg134IWILVVK6Br15IsyK1zVeHw7oqYdaMNk5qyypE++AIRlcPyHqgxZEQi2AqM6ks ylyb/vau7BR6OElUXcPm0NUbGJsAOUhzbqc3fv7+Ek4GhRxkujAVLcjGcNgB1cgZVi9g CWzq92oioySI+k78Up20FrrLdXQHF1kGfIuEF7/Uo1Vbs43oc8ko4IPQqQhI/FALmL32 leFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682618054; x=1685210054; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3ok26iuO88WTdiTh3yqSvF0njUaJd/G7EVrYrB/tlNM=; b=VH5R1RfPQMaiYtLTRwe09CN6FNDEXZZnNDfp3RnzDwYAHgOLggBUIxXLZTNW0tc/9r noH9FCX6VWlcJXE/PEwM8oZRGrFeANEuX5uWIahGMZf4NP47ddZDczOB0ShbCFqwcAvR +IOsOogIhpOn7DfWIQyhypyLmtldZCDE4oSs6zXzR6V3+Lwxpc56kYo8oYycrRLD+lG/ 1+2WaBW44BlybFqkfGFs1DtkdqyeJPwv1yq58o0Y4iRDWLE75yTNsgqlscqdZXzsUW/1 Y1s+ZKjCweE01kEH8sBgJOnDjIX2TPegVIOxXw2E0L8F8HxELvrqtptl6SdvVlloEvw4 INYg== X-Gm-Message-State: AC+VfDz0t7QHWNsIR74JvPFkXGjFBnkYHwr1MlGPtByshjie0ZeFcFOB TZMwhEzrgHvtKLpIUOp+3A6ImTxv2YQ= X-Google-Smtp-Source: ACHHUZ7NYzhki84oqM5sC/T0ASeC0x8KLgCKVbwvSy/vX3s9gdhOdDf04XFw8HA41JD89ghsoCr/qw== X-Received: by 2002:a17:902:868a:b0:1a6:9f09:866d with SMTP id g10-20020a170902868a00b001a69f09866dmr2347865plo.61.1682618054077; Thu, 27 Apr 2023 10:54:14 -0700 (PDT) Received: from localhost ([2a00:79e1:abd:4a00:61b:48ed:72ab:435b]) by smtp.gmail.com with ESMTPSA id ja14-20020a170902efce00b001a69dfd918dsm4852762plb.187.2023.04.27.10.54.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Apr 2023 10:54:13 -0700 (PDT) From: Rob Clark To: dri-devel@lists.freedesktop.org Subject: [PATCH v2 9/9] drm/msm: Wire up comm/cmdline override for fdinfo Date: Thu, 27 Apr 2023 10:53:33 -0700 Message-Id: <20230427175340.1280952-10-robdclark@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230427175340.1280952-1-robdclark@gmail.com> References: <20230427175340.1280952-1-robdclark@gmail.com> MIME-Version: 1.0 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 , Konrad Dybcio , Akhil P Oommen , Sean Paul , Emil Velikov , Christopher Healy , Abhinav Kumar , Luca Weiss , 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 --- drivers/gpu/drm/msm/adreno/adreno_gpu.c | 24 +++++++++++++++++++++++- drivers/gpu/drm/msm/msm_drv.c | 2 ++ drivers/gpu/drm/msm/msm_gpu.h | 10 ++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/msm/adreno/adreno_gpu.c b/drivers/gpu/drm/msm/adreno/adreno_gpu.c index bb38e728864d..a20c2622a61f 100644 --- a/drivers/gpu/drm/msm/adreno/adreno_gpu.c +++ b/drivers/gpu/drm/msm/adreno/adreno_gpu.c @@ -16,6 +16,7 @@ #include #include #include +#include #include "adreno_gpu.h" #include "a6xx_gpu.h" #include "msm_gem.h" @@ -398,7 +399,8 @@ int adreno_set_param(struct msm_gpu *gpu, struct msm_file_private *ctx, 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) @@ -412,6 +414,13 @@ int adreno_set_param(struct msm_gpu *gpu, struct msm_file_private *ctx, /* 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) { @@ -425,6 +434,19 @@ int adreno_set_param(struct msm_gpu *gpu, struct msm_file_private *ctx, 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: diff --git a/drivers/gpu/drm/msm/msm_drv.c b/drivers/gpu/drm/msm/msm_drv.c index 81a1371c0307..3a74b5653e96 100644 --- a/drivers/gpu/drm/msm/msm_drv.c +++ b/drivers/gpu/drm/msm/msm_drv.c @@ -581,6 +581,7 @@ static int context_init(struct drm_device *dev, struct drm_file *file) rwlock_init(&ctx->queuelock); kref_init(&ctx->ref); + ctx->file = file; msm_submitqueue_init(dev, ctx); ctx->aspace = msm_gpu_create_private_address_space(priv->gpu, current); @@ -603,6 +604,7 @@ static int msm_open(struct drm_device *dev, struct drm_file *file) static void context_close(struct msm_file_private *ctx) { + ctx->file = NULL; msm_submitqueue_close(ctx); msm_file_private_put(ctx); } diff --git a/drivers/gpu/drm/msm/msm_gpu.h b/drivers/gpu/drm/msm/msm_gpu.h index 7a4fa1b8655b..671ce89e61b0 100644 --- a/drivers/gpu/drm/msm/msm_gpu.h +++ b/drivers/gpu/drm/msm/msm_gpu.h @@ -359,6 +359,16 @@ struct msm_file_private { struct kref ref; int seqno; + /** + * @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: *