Skip to content

Commit

Permalink
drm/v3d: Create a CPU job extension for the reset timestamp job
Browse files Browse the repository at this point in the history
A CPU job is a type of job that performs operations that requires CPU
intervention. A reset timestamp job is a job that resets the timestamp
queries based on the value offset of the first query. As V3D doesn't
provide any mechanism to obtain a timestamp from the GPU, it is a job
that needs CPU intervention.

So, create a user extension for the CPU job that enables the creation
of a reset timestamp job. This user extension will allow the creation of
a CPU job that resets the timestamp value in the timestamp BO and resets
the availability syncobj.

Signed-off-by: Maíra Canal <mcanal@igalia.com>
Reviewed-by: Iago Toral Quiroga <itoral@igalia.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20231130164420.932823-16-mcanal@igalia.com
  • Loading branch information
Maíra Canal committed Dec 1, 2023
1 parent 9ba0ff3 commit 34a101e
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 0 deletions.
1 change: 1 addition & 0 deletions drivers/gpu/drm/v3d/v3d_drv.h
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ struct v3d_csd_job {
enum v3d_cpu_job_type {
V3D_CPU_JOB_TYPE_INDIRECT_CSD = 1,
V3D_CPU_JOB_TYPE_TIMESTAMP_QUERY,
V3D_CPU_JOB_TYPE_RESET_TIMESTAMP_QUERY,
};

struct v3d_timestamp_query {
Expand Down
21 changes: 21 additions & 0 deletions drivers/gpu/drm/v3d/v3d_sched.c
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,30 @@ v3d_timestamp_query(struct v3d_cpu_job *job)
v3d_put_bo_vaddr(bo);
}

static void
v3d_reset_timestamp_queries(struct v3d_cpu_job *job)
{
struct v3d_timestamp_query_info *timestamp_query = &job->timestamp_query;
struct v3d_timestamp_query *queries = timestamp_query->queries;
struct v3d_bo *bo = to_v3d_bo(job->base.bo[0]);
u8 *value_addr;

v3d_get_bo_vaddr(bo);

for (int i = 0; i < timestamp_query->count; i++) {
value_addr = ((u8 *)bo->vaddr) + queries[i].offset;
*((u64 *)value_addr) = 0;

drm_syncobj_replace_fence(queries[i].syncobj, NULL);
}

v3d_put_bo_vaddr(bo);
}

static const v3d_cpu_job_fn cpu_job_function[] = {
[V3D_CPU_JOB_TYPE_INDIRECT_CSD] = v3d_rewrite_csd_job_wg_counts_from_indirect,
[V3D_CPU_JOB_TYPE_TIMESTAMP_QUERY] = v3d_timestamp_query,
[V3D_CPU_JOB_TYPE_RESET_TIMESTAMP_QUERY] = v3d_reset_timestamp_queries,
};

static struct dma_fence *
Expand Down
52 changes: 52 additions & 0 deletions drivers/gpu/drm/v3d/v3d_submit.c
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,54 @@ v3d_get_cpu_timestamp_query_params(struct drm_file *file_priv,
return 0;
}

static int
v3d_get_cpu_reset_timestamp_params(struct drm_file *file_priv,
struct drm_v3d_extension __user *ext,
struct v3d_cpu_job *job)
{
u32 __user *syncs;
struct drm_v3d_reset_timestamp_query reset;

if (!job) {
DRM_DEBUG("CPU job extension was attached to a GPU job.\n");
return -EINVAL;
}

if (job->job_type) {
DRM_DEBUG("Two CPU job extensions were added to the same CPU job.\n");
return -EINVAL;
}

if (copy_from_user(&reset, ext, sizeof(reset)))
return -EFAULT;

job->job_type = V3D_CPU_JOB_TYPE_RESET_TIMESTAMP_QUERY;

job->timestamp_query.queries = kvmalloc_array(reset.count,
sizeof(struct v3d_timestamp_query),
GFP_KERNEL);
if (!job->timestamp_query.queries)
return -ENOMEM;

syncs = u64_to_user_ptr(reset.syncs);

for (int i = 0; i < reset.count; i++) {
u32 sync;

job->timestamp_query.queries[i].offset = reset.offset + 8 * i;

if (copy_from_user(&sync, syncs++, sizeof(sync))) {
kvfree(job->timestamp_query.queries);
return -EFAULT;
}

job->timestamp_query.queries[i].syncobj = drm_syncobj_find(file_priv, sync);
}
job->timestamp_query.count = reset.count;

return 0;
}

/* Whenever userspace sets ioctl extensions, v3d_get_extensions parses data
* according to the extension id (name).
*/
Expand Down Expand Up @@ -522,6 +570,9 @@ v3d_get_extensions(struct drm_file *file_priv,
case DRM_V3D_EXT_ID_CPU_TIMESTAMP_QUERY:
ret = v3d_get_cpu_timestamp_query_params(file_priv, user_ext, job);
break;
case DRM_V3D_EXT_ID_CPU_RESET_TIMESTAMP_QUERY:
ret = v3d_get_cpu_reset_timestamp_params(file_priv, user_ext, job);
break;
default:
DRM_DEBUG_DRIVER("Unknown extension id: %d\n", ext.id);
return -EINVAL;
Expand Down Expand Up @@ -899,6 +950,7 @@ v3d_submit_csd_ioctl(struct drm_device *dev, void *data,
static const unsigned int cpu_job_bo_handle_count[] = {
[V3D_CPU_JOB_TYPE_INDIRECT_CSD] = 1,
[V3D_CPU_JOB_TYPE_TIMESTAMP_QUERY] = 1,
[V3D_CPU_JOB_TYPE_RESET_TIMESTAMP_QUERY] = 1,
};

/**
Expand Down
27 changes: 27 additions & 0 deletions include/uapi/drm/v3d_drm.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ struct drm_v3d_extension {
#define DRM_V3D_EXT_ID_MULTI_SYNC 0x01
#define DRM_V3D_EXT_ID_CPU_INDIRECT_CSD 0x02
#define DRM_V3D_EXT_ID_CPU_TIMESTAMP_QUERY 0x03
#define DRM_V3D_EXT_ID_CPU_RESET_TIMESTAMP_QUERY 0x04
__u32 flags; /* mbz */
};

Expand Down Expand Up @@ -427,6 +428,29 @@ struct drm_v3d_timestamp_query {
__u32 pad;
};

/**
* struct drm_v3d_reset_timestamp_query - ioctl extension for the CPU job to
* reset timestamp queries
*
* When an extension DRM_V3D_EXT_ID_CPU_RESET_TIMESTAMP_QUERY is defined, it
* points to this extension to define a reset timestamp submission. This CPU
* job will reset the timestamp queries based on value offset of the first
* query. Moreover, it will reset the timestamp syncobj to reset query
* availability.
*/
struct drm_v3d_reset_timestamp_query {
struct drm_v3d_extension base;

/* Array of timestamp's syncobjs to indicate its availability */
__u64 syncs;

/* Offset of the first query within the timestamp BO for its value */
__u32 offset;

/* Number of queries */
__u32 count;
};

struct drm_v3d_submit_cpu {
/* Pointer to a u32 array of the BOs that are referenced by the job.
*
Expand All @@ -435,6 +459,9 @@ struct drm_v3d_submit_cpu {
*
* For DRM_V3D_EXT_ID_TIMESTAMP_QUERY, it must contain only one BO,
* that will contain the timestamp.
*
* For DRM_V3D_EXT_ID_CPU_RESET_TIMESTAMP_QUERY, it must contain only
* one BO, that contains the timestamp.
*/
__u64 bo_handles;

Expand Down

0 comments on commit 34a101e

Please sign in to comment.