From patchwork Tue Aug 8 22:22:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Adri=C3=A1n_Larumbe?= X-Patchwork-Id: 13347094 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 8076FC001DB for ; Tue, 8 Aug 2023 22:23:01 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id AF68110E19D; Tue, 8 Aug 2023 22:22:54 +0000 (UTC) Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5C7A010E116 for ; Tue, 8 Aug 2023 22:22:50 +0000 (UTC) Received: from localhost.localdomain (unknown [IPv6:2a02:8010:65b5:0:1ac0:4dff:feee:236a]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: alarumbe) by madras.collabora.co.uk (Postfix) with ESMTPSA id 0032266071EF; Tue, 8 Aug 2023 23:22:48 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1691533369; bh=V+UHC/f4Z5437d2s+qeZfNk0n0XPSuDIfTrta5KSWQg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ss2K4UtKaSfC7DWP5xWNlq2YiQ6T+2XuKYnpPJ7HAbbXifZ2eyWVIAG8Jo8JrMzRf agiygiOaaXM/O9ej8/g04M2zv9KO7pEMXLcEnOLyFVLosKqO5WvuYBaz16iQqfU97P F6V7nJfBUJxZQhDLA3oVdj+xWus2xZBvrQG/Uxwpq3AwCfYdINLWLovcmEs/UAfG96 67TZ3pzJ/xQshwHB0VC5expf0X7MFff8uWjENf948gv66CV1uNyxo7yFSK9ebKy82r JDJFAYoUlHpc8mHi0cN714Oy8hTjVcrfcY26fOkC62FERgHOIk+RDKBfwXn0I3HAIN ZozHBhkeb3urw== From: =?utf-8?q?Adri=C3=A1n_Larumbe?= To: robh@kernel.org, steven.price@arm.com, airlied@gmail.com, daniel@ffwll.ch Subject: [PATCH 1/2] drm/panfrost: Add fdinfo support to Panfrost Date: Tue, 8 Aug 2023 23:22:38 +0100 Message-ID: <20230808222240.1016623-2-adrian.larumbe@collabora.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230808222240.1016623-1-adrian.larumbe@collabora.com> References: <20230808222240.1016623-1-adrian.larumbe@collabora.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: adrian.larumbe@collabora.com, kernel@collabora.com, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" We calculate the amount of time the GPU spends on a job with ktime samples, and then add it to the cumulative total for the open DRM file, which is what will be eventually exposed through the 'fdinfo' DRM file descriptor. Signed-off-by: Adrián Larumbe --- drivers/gpu/drm/panfrost/panfrost_device.c | 12 ++++++++ drivers/gpu/drm/panfrost/panfrost_device.h | 10 +++++++ drivers/gpu/drm/panfrost/panfrost_drv.c | 32 +++++++++++++++++++++- drivers/gpu/drm/panfrost/panfrost_job.c | 6 ++++ drivers/gpu/drm/panfrost/panfrost_job.h | 3 ++ 5 files changed, 62 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/panfrost/panfrost_device.c b/drivers/gpu/drm/panfrost/panfrost_device.c index fa1a086a862b..67a5e894d037 100644 --- a/drivers/gpu/drm/panfrost/panfrost_device.c +++ b/drivers/gpu/drm/panfrost/panfrost_device.c @@ -401,6 +401,18 @@ void panfrost_device_reset(struct panfrost_device *pfdev) panfrost_job_enable_interrupts(pfdev); } +struct drm_info_gpu panfrost_device_get_counters(struct panfrost_device *pfdev, + struct panfrost_file_priv *panfrost_priv) +{ + struct drm_info_gpu gpu_info; + + gpu_info.engine = panfrost_priv->elapsed_ns; + gpu_info.cycles = panfrost_priv->elapsed_ns * clk_get_rate(pfdev->clock); + gpu_info.maxfreq = clk_get_rate(pfdev->clock); + + return gpu_info; +} + static int panfrost_device_resume(struct device *dev) { struct panfrost_device *pfdev = dev_get_drvdata(dev); diff --git a/drivers/gpu/drm/panfrost/panfrost_device.h b/drivers/gpu/drm/panfrost/panfrost_device.h index b0126b9fbadc..4621a2ece1bb 100644 --- a/drivers/gpu/drm/panfrost/panfrost_device.h +++ b/drivers/gpu/drm/panfrost/panfrost_device.h @@ -141,6 +141,14 @@ struct panfrost_file_priv { struct drm_sched_entity sched_entity[NUM_JOB_SLOTS]; struct panfrost_mmu *mmu; + + uint64_t elapsed_ns; +}; + +struct drm_info_gpu { + unsigned long long engine; + unsigned long long cycles; + unsigned int maxfreq; }; static inline struct panfrost_device *to_panfrost_device(struct drm_device *ddev) @@ -172,6 +180,8 @@ int panfrost_unstable_ioctl_check(void); int panfrost_device_init(struct panfrost_device *pfdev); void panfrost_device_fini(struct panfrost_device *pfdev); void panfrost_device_reset(struct panfrost_device *pfdev); +struct drm_info_gpu panfrost_device_get_counters(struct panfrost_device *pfdev, + struct panfrost_file_priv *panfrost_priv); extern const struct dev_pm_ops panfrost_pm_ops; diff --git a/drivers/gpu/drm/panfrost/panfrost_drv.c b/drivers/gpu/drm/panfrost/panfrost_drv.c index a2ab99698ca8..65fdc0e4c7cb 100644 --- a/drivers/gpu/drm/panfrost/panfrost_drv.c +++ b/drivers/gpu/drm/panfrost/panfrost_drv.c @@ -3,6 +3,7 @@ /* Copyright 2019 Linaro, Ltd., Rob Herring */ /* Copyright 2019 Collabora ltd. */ +#include "drm/drm_file.h" #include #include #include @@ -267,6 +268,7 @@ static int panfrost_ioctl_submit(struct drm_device *dev, void *data, job->requirements = args->requirements; job->flush_id = panfrost_gpu_get_latest_flush_id(pfdev); job->mmu = file_priv->mmu; + job->priv = file_priv; slot = panfrost_job_get_slot(job); @@ -523,7 +525,34 @@ static const struct drm_ioctl_desc panfrost_drm_driver_ioctls[] = { PANFROST_IOCTL(MADVISE, madvise, DRM_RENDER_ALLOW), }; -DEFINE_DRM_GEM_FOPS(panfrost_drm_driver_fops); + +static void panfrost_gpu_show_fdinfo(struct panfrost_device *pfdev, + struct panfrost_file_priv *panfrost_priv, + struct drm_printer *p) +{ + struct drm_info_gpu gpu_info; + + gpu_info = panfrost_device_get_counters(pfdev, panfrost_priv); + + drm_printf(p, "drm-engine-gpu:\t%llu ns\n", gpu_info.engine); + drm_printf(p, "drm-cycles-gpu:\t%llu\n", gpu_info.cycles); + drm_printf(p, "drm-maxfreq-gpu:\t%u Hz\n", gpu_info.maxfreq); +} + +static void panfrost_show_fdinfo(struct drm_printer *p, struct drm_file *file) +{ + struct drm_device *dev = file->minor->dev; + struct panfrost_device *pfdev = dev->dev_private; + + panfrost_gpu_show_fdinfo(pfdev, file->driver_priv, p); + +} + +static const struct file_operations panfrost_drm_driver_fops = { + .owner = THIS_MODULE, + DRM_GEM_FOPS, + .show_fdinfo = drm_show_fdinfo, +}; /* * Panfrost driver version: @@ -535,6 +564,7 @@ static const struct drm_driver panfrost_drm_driver = { .driver_features = DRIVER_RENDER | DRIVER_GEM | DRIVER_SYNCOBJ, .open = panfrost_open, .postclose = panfrost_postclose, + .show_fdinfo = panfrost_show_fdinfo, .ioctls = panfrost_drm_driver_ioctls, .num_ioctls = ARRAY_SIZE(panfrost_drm_driver_ioctls), .fops = &panfrost_drm_driver_fops, diff --git a/drivers/gpu/drm/panfrost/panfrost_job.c b/drivers/gpu/drm/panfrost/panfrost_job.c index dbc597ab46fb..d0063cac9f72 100644 --- a/drivers/gpu/drm/panfrost/panfrost_job.c +++ b/drivers/gpu/drm/panfrost/panfrost_job.c @@ -157,6 +157,11 @@ static struct panfrost_job * panfrost_dequeue_job(struct panfrost_device *pfdev, int slot) { struct panfrost_job *job = pfdev->jobs[slot][0]; + job->priv->elapsed_ns += + ktime_to_ns(ktime_sub(ktime_get(), job->start_time)); + + /* Reset in case the job has to be requeued */ + job->start_time = 0; WARN_ON(!job); pfdev->jobs[slot][0] = pfdev->jobs[slot][1]; @@ -233,6 +238,7 @@ static void panfrost_job_hw_submit(struct panfrost_job *job, int js) subslot = panfrost_enqueue_job(pfdev, js, job); /* Don't queue the job if a reset is in progress */ if (!atomic_read(&pfdev->reset.pending)) { + job->start_time = ktime_get(); job_write(pfdev, JS_COMMAND_NEXT(js), JS_COMMAND_START); dev_dbg(pfdev->dev, "JS: Submitting atom %p to js[%d][%d] with head=0x%llx AS %d", diff --git a/drivers/gpu/drm/panfrost/panfrost_job.h b/drivers/gpu/drm/panfrost/panfrost_job.h index 8becc1ba0eb9..b4318e476694 100644 --- a/drivers/gpu/drm/panfrost/panfrost_job.h +++ b/drivers/gpu/drm/panfrost/panfrost_job.h @@ -32,6 +32,9 @@ struct panfrost_job { /* Fence to be signaled by drm-sched once its done with the job */ struct dma_fence *render_done_fence; + + struct panfrost_file_priv *priv; + ktime_t start_time; }; int panfrost_job_init(struct panfrost_device *pfdev); From patchwork Tue Aug 8 22:22:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Adri=C3=A1n_Larumbe?= X-Patchwork-Id: 13347093 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 57E39C04A94 for ; Tue, 8 Aug 2023 22:22:58 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 17D9A10E116; Tue, 8 Aug 2023 22:22:54 +0000 (UTC) Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9913B10E115 for ; Tue, 8 Aug 2023 22:22:50 +0000 (UTC) Received: from localhost.localdomain (unknown [IPv6:2a02:8010:65b5:0:1ac0:4dff:feee:236a]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: alarumbe) by madras.collabora.co.uk (Postfix) with ESMTPSA id 30CF166071F7; Tue, 8 Aug 2023 23:22:49 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1691533369; bh=VWCWv3TF6qDjaauYLhA34kcdzVSNugilzQyUxtVWXX4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UH/RXcUK9/pOVCvakVoSWzoFiqvKMUQ/pMFDjWja3BohYJ9v5p1kXFwIuqS+fzfeo jXu5RjCk3H3HdmpMY5/yhGE6vB4pY2lBNnSpNM+bUBSCZwexsk0rPJFQUTREEeosOt PYD08tEceRK5GIBT0GahnidF5hG9cwGyXxaZvtlXzhHnHsBazb4R2uCzPz6cfVCKtZ 4sfV+UMTUkukz2lYNdlajzF33F9OKGbTF3w5biiF3nGNWPBKyQkMc3xtrql6agY3Rw Org3I/QO0aXsA7gxPdBuoR/VcjhhfYTYVKxl2b/XzG7x+LASPMNbnrIkiLLYm6oAmu 4Efj3q7HBC1Bw== From: =?utf-8?q?Adri=C3=A1n_Larumbe?= To: robh@kernel.org, steven.price@arm.com, airlied@gmail.com, daniel@ffwll.ch Subject: [PATCH 2/2] drm/panfrost: Add drm memory stats display through fdinfo Date: Tue, 8 Aug 2023 23:22:39 +0100 Message-ID: <20230808222240.1016623-3-adrian.larumbe@collabora.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230808222240.1016623-1-adrian.larumbe@collabora.com> References: <20230808222240.1016623-1-adrian.larumbe@collabora.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: adrian.larumbe@collabora.com, kernel@collabora.com, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" For drm_show_memory_stats to produce a more accurate report, provide a new Panfrost DRM object callback that decides whether an object is resident in memory or eligible for purging. Signed-off-by: Adrián Larumbe --- drivers/gpu/drm/panfrost/panfrost_drv.c | 8 ++++++-- drivers/gpu/drm/panfrost/panfrost_gem.c | 16 ++++++++++++++++ drivers/gpu/drm/panfrost/panfrost_gem.h | 1 + 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/panfrost/panfrost_drv.c b/drivers/gpu/drm/panfrost/panfrost_drv.c index 65fdc0e4c7cb..46e8e69479c0 100644 --- a/drivers/gpu/drm/panfrost/panfrost_drv.c +++ b/drivers/gpu/drm/panfrost/panfrost_drv.c @@ -441,11 +441,14 @@ static int panfrost_ioctl_madvise(struct drm_device *dev, void *data, args->retained = drm_gem_shmem_madvise(&bo->base, args->madv); if (args->retained) { - if (args->madv == PANFROST_MADV_DONTNEED) + if (args->madv == PANFROST_MADV_DONTNEED) { list_move_tail(&bo->base.madv_list, &pfdev->shrinker_list); - else if (args->madv == PANFROST_MADV_WILLNEED) + bo->is_purgable = true; + } else if (args->madv == PANFROST_MADV_WILLNEED) { list_del_init(&bo->base.madv_list); + bo->is_purgable = false; + } } out_unlock_mappings: @@ -546,6 +549,7 @@ static void panfrost_show_fdinfo(struct drm_printer *p, struct drm_file *file) panfrost_gpu_show_fdinfo(pfdev, file->driver_priv, p); + drm_show_memory_stats(p, file); } static const struct file_operations panfrost_drm_driver_fops = { diff --git a/drivers/gpu/drm/panfrost/panfrost_gem.c b/drivers/gpu/drm/panfrost/panfrost_gem.c index 3c812fbd126f..80ab1521a14e 100644 --- a/drivers/gpu/drm/panfrost/panfrost_gem.c +++ b/drivers/gpu/drm/panfrost/panfrost_gem.c @@ -195,6 +195,21 @@ static int panfrost_gem_pin(struct drm_gem_object *obj) return drm_gem_shmem_pin(&bo->base); } +static enum drm_gem_object_status panfrost_gem_status(struct drm_gem_object *obj) +{ + struct panfrost_gem_object *bo = to_panfrost_bo(obj); + struct panfrost_device *pfdev = obj->dev->dev_private; + unsigned int res = 0; + + mutex_lock(&pfdev->shrinker_lock); + res |= (bo->is_purgable) ? DRM_GEM_OBJECT_PURGEABLE : 0; + mutex_unlock(&pfdev->shrinker_lock); + + res |= (bo->base.pages) ? DRM_GEM_OBJECT_RESIDENT : 0; + + return res; +} + static const struct drm_gem_object_funcs panfrost_gem_funcs = { .free = panfrost_gem_free_object, .open = panfrost_gem_open, @@ -206,6 +221,7 @@ static const struct drm_gem_object_funcs panfrost_gem_funcs = { .vmap = drm_gem_shmem_object_vmap, .vunmap = drm_gem_shmem_object_vunmap, .mmap = drm_gem_shmem_object_mmap, + .status = panfrost_gem_status, .vm_ops = &drm_gem_shmem_vm_ops, }; diff --git a/drivers/gpu/drm/panfrost/panfrost_gem.h b/drivers/gpu/drm/panfrost/panfrost_gem.h index ad2877eeeccd..e06f7ceb8f73 100644 --- a/drivers/gpu/drm/panfrost/panfrost_gem.h +++ b/drivers/gpu/drm/panfrost/panfrost_gem.h @@ -38,6 +38,7 @@ struct panfrost_gem_object { bool noexec :1; bool is_heap :1; + bool is_purgable :1; }; struct panfrost_gem_mapping {