From nobody Mon Feb 9 21:37:23 2026 Received: from sender4-pp-f112.zoho.com (sender4-pp-f112.zoho.com [136.143.188.112]) (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 B001B1442F7 for ; Wed, 14 Aug 2024 11:24:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.112 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723634680; cv=pass; b=CqRUKh7UpI4LKK7KV4QvhpAhGEFSWShkOZogsBp2nLlQqnlJEB7E3HgKOp0pTki41TsUU0jcW/R+R1mXOTpRpQq+LDwclbmFMmgUqBIFqoZ9LVe50QynaspGTBfdO0MQ+cDy7YRt8pvilsweJL5gLAJYw+iTS/lQqhkMiuwE2X8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723634680; c=relaxed/simple; bh=E8lVpgB07KR0a4u2yL4Ji7KOoojA3Ood86lUIU/JGlY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AGvWtDtimQW5Cb6cN71I71rwZGPhWDgimcQo5a5vTQ6PwRLq1dDtQZI/Lbn53t++S+/u0/yZO2CdETkHll/VJCQ2fj1uS3zshDzQSS2bx4QxpboDL7FPYUkmyMpooZYqdKRO9PFFWprJGu+FDij/DbZW/+iajkPhvp4ukvmCjgQ= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (1024-bit key) header.d=collabora.com header.i=mary.guillemard@collabora.com header.b=BEJC3ehC; arc=pass smtp.client-ip=136.143.188.112 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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 (1024-bit key) header.d=collabora.com header.i=mary.guillemard@collabora.com header.b="BEJC3ehC" ARC-Seal: i=1; a=rsa-sha256; t=1723634664; cv=none; d=zohomail.com; s=zohoarc; b=XXBWEihLQFZqFfntEC50XZl8XpZQU8QFerZ9BjItdMxuYdS2lnXggRCFS5Z/GZ5ywVjl9mu8vITs/fj2QD6uZbvcD78RqDWdzmf761MJ//6zkq/TyrXfSryUC7T6U0R56lc96vgZMLUKtfHtYEi4PptBjP1PqJK66hT39vXRmnI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1723634664; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=dqiFKqE0gbXnM9IqXYHKQzJjNYy7JMZYaPUwduwL4og=; b=BhMVy6Q49E1VQgC1dARgEciokL2UT/W4sQ/vdtUc6mw4M/EHgOuMVPszgzjZBOv6hkpSIemefP8/dQsnnggkTwVBn3bxkjp/CF34NsKv5jCDCr+USa9xgeTl7IpD2BnQu30B3zYFh+CPIDTJLQ6vPTybPc42bPLZvfFelAiDTM0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=collabora.com; spf=pass smtp.mailfrom=mary.guillemard@collabora.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1723634664; s=zohomail; d=collabora.com; i=mary.guillemard@collabora.com; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-ID:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Message-Id:Reply-To; bh=dqiFKqE0gbXnM9IqXYHKQzJjNYy7JMZYaPUwduwL4og=; b=BEJC3ehCP1ATW7omm0jSp+2JPxqRwBaKgZyjJZpfWuDCpRHYtacDlMoLUDVvgUyA SSmsLMeExSLKH68DwN9UoGmUb+e3JD9iwwUrf6yxWBcEApOG2vBIvITNF4YVEbG0JFC 80yvJU+P/neJi7IuIu/G9R6JgxjhxGFuYreP8Ybo= Received: by mx.zohomail.com with SMTPS id 1723634663431628.3090562709767; Wed, 14 Aug 2024 04:24:23 -0700 (PDT) From: Mary Guillemard To: linux-kernel@vger.kernel.org Cc: dri-devel@lists.freedesktop.org, kernel@collabora.com, Mary Guillemard , Boris Brezillon , Rob Herring , Steven Price , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter Subject: [PATCH v2 2/2] drm/panfrost: Add cycle counter job requirement Date: Wed, 14 Aug 2024 13:21:22 +0200 Message-ID: <20240814112121.61137-4-mary.guillemard@collabora.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240814112121.61137-2-mary.guillemard@collabora.com> References: <20240814112121.61137-2-mary.guillemard@collabora.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMailClient: External Content-Type: text/plain; charset="utf-8" Extend the uAPI with a new job requirement flag for cycle counters. This requirement is used by userland to indicate that a job requires cycle counters or system timestamp to be propagated. (for use with write value timestamp jobs) We cannot enable cycle counters unconditionally as this would result in an increase of GPU power consumption. As a result, they should be left off unless required by the application. If a job requires cycle counters or system timestamps propagation, we must enable cycle counting before issuing a job and disable it right after the job completes. Since this extends the uAPI and because userland needs a way to advertise features like VK_KHR_shader_clock conditionally, we bumps the driver minor version. v2: - Rework commit message - Squash uAPI changes and implementation in this commit - Simplify changes based on Steven Price comments Signed-off-by: Mary Guillemard Reviewed-by: Steven Price --- drivers/gpu/drm/panfrost/panfrost_drv.c | 8 +++++-- drivers/gpu/drm/panfrost/panfrost_job.c | 28 +++++++++++++++---------- include/uapi/drm/panfrost_drm.h | 1 + 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/drivers/gpu/drm/panfrost/panfrost_drv.c b/drivers/gpu/drm/panf= rost/panfrost_drv.c index 83696d06d697..07a09f32c32e 100644 --- a/drivers/gpu/drm/panfrost/panfrost_drv.c +++ b/drivers/gpu/drm/panfrost/panfrost_drv.c @@ -25,6 +25,8 @@ #include "panfrost_gpu.h" #include "panfrost_perfcnt.h" =20 +#define JOB_REQUIREMENTS (PANFROST_JD_REQ_FS | PANFROST_JD_REQ_CYCLE_COUNT) + static bool unstable_ioctls; module_param_unsafe(unstable_ioctls, bool, 0600); =20 @@ -280,7 +282,7 @@ static int panfrost_ioctl_submit(struct drm_device *dev= , void *data, if (!args->jc) return -EINVAL; =20 - if (args->requirements && args->requirements !=3D PANFROST_JD_REQ_FS) + if (args->requirements & ~JOB_REQUIREMENTS) return -EINVAL; =20 if (args->out_sync > 0) { @@ -619,6 +621,8 @@ static const struct file_operations panfrost_drm_driver= _fops =3D { * - 1.0 - initial interface * - 1.1 - adds HEAP and NOEXEC flags for CREATE_BO * - 1.2 - adds AFBC_FEATURES query + * - 1.3 - adds JD_REQ_CYCLE_COUNT job requirement for SUBMIT + * - adds SYSTEM_TIMESTAMP and SYSTEM_TIMESTAMP_FREQUENCY queries */ static const struct drm_driver panfrost_drm_driver =3D { .driver_features =3D DRIVER_RENDER | DRIVER_GEM | DRIVER_SYNCOBJ, @@ -632,7 +636,7 @@ static const struct drm_driver panfrost_drm_driver =3D { .desc =3D "panfrost DRM", .date =3D "20180908", .major =3D 1, - .minor =3D 2, + .minor =3D 3, =20 .gem_create_object =3D panfrost_gem_create_object, .gem_prime_import_sg_table =3D panfrost_gem_prime_import_sg_table, diff --git a/drivers/gpu/drm/panfrost/panfrost_job.c b/drivers/gpu/drm/panf= rost/panfrost_job.c index df49d37d0e7e..e5e62ee356ef 100644 --- a/drivers/gpu/drm/panfrost/panfrost_job.c +++ b/drivers/gpu/drm/panfrost/panfrost_job.c @@ -159,16 +159,17 @@ panfrost_dequeue_job(struct panfrost_device *pfdev, i= nt slot) struct panfrost_job *job =3D pfdev->jobs[slot][0]; =20 WARN_ON(!job); - if (job->is_profiled) { - if (job->engine_usage) { - job->engine_usage->elapsed_ns[slot] +=3D - ktime_to_ns(ktime_sub(ktime_get(), job->start_time)); - job->engine_usage->cycles[slot] +=3D - panfrost_cycle_counter_read(pfdev) - job->start_cycles; - } - panfrost_cycle_counter_put(job->pfdev); + + if (job->is_profiled && job->engine_usage) { + job->engine_usage->elapsed_ns[slot] +=3D + ktime_to_ns(ktime_sub(ktime_get(), job->start_time)); + job->engine_usage->cycles[slot] +=3D + panfrost_cycle_counter_read(pfdev) - job->start_cycles; } =20 + if (job->requirements & PANFROST_JD_REQ_CYCLE_COUNT || job->is_profiled) + panfrost_cycle_counter_put(pfdev); + pfdev->jobs[slot][0] =3D pfdev->jobs[slot][1]; pfdev->jobs[slot][1] =3D NULL; =20 @@ -243,9 +244,13 @@ static void panfrost_job_hw_submit(struct panfrost_job= *job, int js) subslot =3D panfrost_enqueue_job(pfdev, js, job); /* Don't queue the job if a reset is in progress */ if (!atomic_read(&pfdev->reset.pending)) { - if (pfdev->profile_mode) { + job->is_profiled =3D pfdev->profile_mode; + + if (job->requirements & PANFROST_JD_REQ_CYCLE_COUNT || + job->is_profiled) panfrost_cycle_counter_get(pfdev); - job->is_profiled =3D true; + + if (job->is_profiled) { job->start_time =3D ktime_get(); job->start_cycles =3D panfrost_cycle_counter_read(pfdev); } @@ -693,7 +698,8 @@ panfrost_reset(struct panfrost_device *pfdev, spin_lock(&pfdev->js->job_lock); for (i =3D 0; i < NUM_JOB_SLOTS; i++) { for (j =3D 0; j < ARRAY_SIZE(pfdev->jobs[0]) && pfdev->jobs[i][j]; j++) { - if (pfdev->jobs[i][j]->is_profiled) + if (pfdev->jobs[i][j]->requirements & PANFROST_JD_REQ_CYCLE_COUNT || + pfdev->jobs[i][j]->is_profiled) panfrost_cycle_counter_put(pfdev->jobs[i][j]->pfdev); pm_runtime_put_noidle(pfdev->dev); panfrost_devfreq_record_idle(&pfdev->pfdevfreq); diff --git a/include/uapi/drm/panfrost_drm.h b/include/uapi/drm/panfrost_dr= m.h index 52b050e2b660..568724be6628 100644 --- a/include/uapi/drm/panfrost_drm.h +++ b/include/uapi/drm/panfrost_drm.h @@ -40,6 +40,7 @@ extern "C" { #define DRM_IOCTL_PANFROST_PERFCNT_DUMP DRM_IOW(DRM_COMMAND_BASE + DRM_PA= NFROST_PERFCNT_DUMP, struct drm_panfrost_perfcnt_dump) =20 #define PANFROST_JD_REQ_FS (1 << 0) +#define PANFROST_JD_REQ_CYCLE_COUNT (1 << 1) /** * struct drm_panfrost_submit - ioctl argument for submitting commands to = the 3D * engine. --=20 2.45.2