From nobody Mon Feb 9 15:26:33 2026 Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 21040143C49 for ; Tue, 23 Apr 2024 21:33:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=46.235.227.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713908014; cv=none; b=YjG0yvc1VWl/2w8LAqbVbgZxt343Z+pkpBLO4/vHr6UDA8E1xvAQ1GRUfGJtAOKGGtVgFc+NtNasojvJk8exZIC2fXCOEbOd5rs6nSTcQFv/ck0x2KWPOGOLI4KVtqKiw0S7nIuGN1tkO5SB5keE4mUHkHE9o/H7l0Qq9kGj9wc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713908014; c=relaxed/simple; bh=i1eET/RjBYVCS/C3b09AiDsbznYgmcfJ403Ro9pzbh0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=JokVIW6313/mz3hvHLxhcS5ER/AwoyfPoUCaUmeIB9/3zYnGWIeEnJJ2s7xouzG6wAYnkKE63BBDEyWZYIkApwcS8+KDuq7TCuqFDqUnq8M8ONyazm1BN+wVZam5DFWWlmIayHzNQH+p6+Gz4638LWVLyqv66/wVBtmfu+jMxu4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=HgqFIt1e; arc=none smtp.client-ip=46.235.227.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="HgqFIt1e" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1713908009; bh=i1eET/RjBYVCS/C3b09AiDsbznYgmcfJ403Ro9pzbh0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HgqFIt1e59YlnlQPDsryRnwgSFZput2VSL58OUwKmAmV6v5S+Ytk3skMWRhSWTca/ Rdjv8Sx2ZU/e9FFxfXeyZebSkMHlv+WLVXIwgKwe1LqguGd+AbVM/ESr6+f32X+GnW WrL3g+WdJf6RhBYoywpXEHz/KmJagpwnTPGkIQwYNcmX5j3XbaY3efxVUcjjPS+lMM 6XM7Y8wbiYGiJ/NcS8QLvBkuXfuGcQuoXWZh68f+/VW5VSSsNwrA9ls0OU8lzHA0wG 8h4LTyy69R7jCVLu2ArLYXImiHkuujR56LfX48/NVCril3s3ZZRAPxFdEnJHMDa4d5 bRjOON1Rx7/sg== Received: from localhost.localdomain (cola.collaboradmins.com [195.201.22.229]) (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 madrid.collaboradmins.com (Postfix) with ESMTPSA id 58C4C3782141; Tue, 23 Apr 2024 21:33:29 +0000 (UTC) From: =?UTF-8?q?Adri=C3=A1n=20Larumbe?= To: Boris Brezillon , Steven Price , Liviu Dudau , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter Cc: kernel@collabora.com, Adrian Larumbe , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/3] drm/panthor: Add DRM fdinfo support Date: Tue, 23 Apr 2024 22:32:35 +0100 Message-ID: <20240423213240.91412-3-adrian.larumbe@collabora.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240423213240.91412-1-adrian.larumbe@collabora.com> References: <20240423213240.91412-1-adrian.larumbe@collabora.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Drawing from the FW-calculated values in the previous commit, we can increase the numbers for an open file by collecting them from finished jobs when updating their group synchronisation objects. Signed-off-by: Adri=C3=A1n Larumbe --- drivers/gpu/drm/panthor/panthor_devfreq.c | 10 +++++ drivers/gpu/drm/panthor/panthor_device.h | 11 ++++++ drivers/gpu/drm/panthor/panthor_drv.c | 31 +++++++++++++++ drivers/gpu/drm/panthor/panthor_sched.c | 46 +++++++++++++++++++++++ 4 files changed, 98 insertions(+) diff --git a/drivers/gpu/drm/panthor/panthor_devfreq.c b/drivers/gpu/drm/pa= nthor/panthor_devfreq.c index c6d3c327cc24..5eededaeade7 100644 --- a/drivers/gpu/drm/panthor/panthor_devfreq.c +++ b/drivers/gpu/drm/panthor/panthor_devfreq.c @@ -91,6 +91,7 @@ static int panthor_devfreq_get_dev_status(struct device *= dev, spin_lock_irqsave(&pdevfreq->lock, irqflags); =20 panthor_devfreq_update_utilization(pdevfreq); + ptdev->current_frequency =3D status->current_frequency; =20 status->total_time =3D ktime_to_ns(ktime_add(pdevfreq->busy_time, pdevfreq->idle_time)); @@ -130,6 +131,7 @@ int panthor_devfreq_init(struct panthor_device *ptdev) struct panthor_devfreq *pdevfreq; struct dev_pm_opp *opp; unsigned long cur_freq; + unsigned long freq =3D ULONG_MAX; int ret; =20 pdevfreq =3D drmm_kzalloc(&ptdev->base, sizeof(*ptdev->devfreq), GFP_KERN= EL); @@ -204,6 +206,14 @@ int panthor_devfreq_init(struct panthor_device *ptdev) =20 dev_pm_opp_put(opp); =20 + /* Find the fastest defined rate */ + opp =3D dev_pm_opp_find_freq_floor(dev, &freq); + if (IS_ERR(opp)) + return PTR_ERR(opp); + ptdev->fast_rate =3D freq; + + dev_pm_opp_put(opp); + /* * Setup default thresholds for the simple_ondemand governor. * The values are chosen based on experiments. diff --git a/drivers/gpu/drm/panthor/panthor_device.h b/drivers/gpu/drm/pan= thor/panthor_device.h index 2fdd671b38fd..b5b5dfe3cafe 100644 --- a/drivers/gpu/drm/panthor/panthor_device.h +++ b/drivers/gpu/drm/panthor/panthor_device.h @@ -162,6 +162,14 @@ struct panthor_device { */ struct page *dummy_latest_flush; } pm; + + unsigned long current_frequency; + unsigned long fast_rate; +}; + +struct panthor_gpu_usage { + u64 time; + u64 cycles; }; =20 /** @@ -176,6 +184,9 @@ struct panthor_file { =20 /** @groups: Scheduling group pool attached to this file. */ struct panthor_group_pool *groups; + + /** @stats: cycle and timestamp measures for job execution. */ + struct panthor_gpu_usage stats; }; =20 int panthor_device_init(struct panthor_device *ptdev); diff --git a/drivers/gpu/drm/panthor/panthor_drv.c b/drivers/gpu/drm/pantho= r/panthor_drv.c index b8a84f26b3ef..6d25385e02a1 100644 --- a/drivers/gpu/drm/panthor/panthor_drv.c +++ b/drivers/gpu/drm/panthor/panthor_drv.c @@ -3,12 +3,17 @@ /* Copyright 2019 Linaro, Ltd., Rob Herring */ /* Copyright 2019 Collabora ltd. */ =20 +#ifdef CONFIG_ARM_ARCH_TIMER +#include +#endif + #include #include #include #include #include #include +#include =20 #include #include @@ -1351,6 +1356,30 @@ static int panthor_mmap(struct file *filp, struct vm= _area_struct *vma) return ret; } =20 +static void panthor_gpu_show_fdinfo(struct panthor_device *ptdev, + struct panthor_file *pfile, + struct drm_printer *p) +{ +#ifdef CONFIG_ARM_ARCH_TIMER + drm_printf(p, "drm-engine-panthor:\t%llu ns\n", + DIV_ROUND_UP_ULL((pfile->stats.time * NSEC_PER_SEC), + arch_timer_get_cntfrq())); +#endif + drm_printf(p, "drm-cycles-panthor:\t%llu\n", pfile->stats.cycles); + drm_printf(p, "drm-maxfreq-panthor:\t%lu Hz\n", ptdev->fast_rate); + drm_printf(p, "drm-curfreq-panthor:\t%lu Hz\n", ptdev->current_frequency); +} + +static void panthor_show_fdinfo(struct drm_printer *p, struct drm_file *fi= le) +{ + struct drm_device *dev =3D file->minor->dev; + struct panthor_device *ptdev =3D container_of(dev, struct panthor_device,= base); + + panthor_gpu_show_fdinfo(ptdev, file->driver_priv, p); + + drm_show_memory_stats(p, file); +} + static const struct file_operations panthor_drm_driver_fops =3D { .open =3D drm_open, .release =3D drm_release, @@ -1360,6 +1389,7 @@ static const struct file_operations panthor_drm_drive= r_fops =3D { .read =3D drm_read, .llseek =3D noop_llseek, .mmap =3D panthor_mmap, + .show_fdinfo =3D drm_show_fdinfo, }; =20 #ifdef CONFIG_DEBUG_FS @@ -1378,6 +1408,7 @@ static const struct drm_driver panthor_drm_driver =3D= { DRIVER_SYNCOBJ_TIMELINE | DRIVER_GEM_GPUVA, .open =3D panthor_open, .postclose =3D panthor_postclose, + .show_fdinfo =3D panthor_show_fdinfo, .ioctls =3D panthor_drm_driver_ioctls, .num_ioctls =3D ARRAY_SIZE(panthor_drm_driver_ioctls), .fops =3D &panthor_drm_driver_fops, diff --git a/drivers/gpu/drm/panthor/panthor_sched.c b/drivers/gpu/drm/pant= hor/panthor_sched.c index 320dfa0388ba..9f1810f5cf4b 100644 --- a/drivers/gpu/drm/panthor/panthor_sched.c +++ b/drivers/gpu/drm/panthor/panthor_sched.c @@ -598,6 +598,18 @@ struct panthor_group { size_t times_offset; } syncobjs; =20 + /** @fdinfo: Per-file total cycle and timestamp values reference. */ + struct { + /** @data: Pointer to actual per-file sample data. */ + struct panthor_gpu_usage *data; + + /** + * @lock: Mutex to govern concurrent access from drm file's fdinfo callb= ack + * and job post-completion processing function + */ + struct mutex lock; + } fdinfo; + /** @state: Group state. */ enum panthor_group_state state; =20 @@ -859,6 +871,8 @@ static void group_release_work(struct work_struct *work) struct panthor_device *ptdev =3D group->ptdev; u32 i; =20 + mutex_destroy(&group->fdinfo.lock); + for (i =3D 0; i < group->queue_count; i++) group_free_queue(group, group->queues[i]); =20 @@ -2741,6 +2755,30 @@ void panthor_sched_post_reset(struct panthor_device = *ptdev) sched_queue_work(sched, sync_upd); } =20 +static void update_fdinfo_stats(struct panthor_job *job) +{ + struct panthor_group *group =3D job->group; + struct panthor_queue *queue =3D group->queues[job->queue_idx]; + struct panthor_device *ptdev =3D group->ptdev; + struct panthor_gpu_usage *fdinfo; + struct panthor_job_times *times; + + drm_WARN_ON(&ptdev->base, job->ringbuf_idx >=3D + panthor_kernel_bo_size(queue->ringbuf) / (SLOTSIZE)); + + times =3D (struct panthor_job_times *) + ((unsigned long)group->syncobjs.bo->kmap + queue->time_offset + + (job->ringbuf_idx * sizeof(struct panthor_job_times))); + + mutex_lock(&group->fdinfo.lock); + if ((group->fdinfo.data)) { + fdinfo =3D group->fdinfo.data; + fdinfo->cycles +=3D times->cycles.after - times->cycles.before; + fdinfo->time +=3D times->time.after - times->time.before; + } + mutex_unlock(&group->fdinfo.lock); +} + static void group_sync_upd_work(struct work_struct *work) { struct panthor_group *group =3D @@ -2776,6 +2814,7 @@ static void group_sync_upd_work(struct work_struct *w= ork) dma_fence_end_signalling(cookie); =20 list_for_each_entry_safe(job, job_tmp, &done_jobs, node) { + update_fdinfo_stats(job); list_del_init(&job->node); panthor_job_put(&job->base); } @@ -3240,6 +3279,9 @@ int panthor_group_create(struct panthor_file *pfile, } mutex_unlock(&sched->reset.lock); =20 + group->fdinfo.data =3D &pfile->stats; + mutex_init(&group->fdinfo.lock); + return gid; =20 err_put_group: @@ -3279,6 +3321,10 @@ int panthor_group_destroy(struct panthor_file *pfile= , u32 group_handle) mutex_unlock(&sched->lock); mutex_unlock(&sched->reset.lock); =20 + mutex_lock(&group->fdinfo.lock); + group->fdinfo.data =3D NULL; + mutex_unlock(&group->fdinfo.lock); + group_put(group); return 0; } --=20 2.44.0