Message ID | 20240710134130.17292-8-tursulin@igalia.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | v3d: Perfmon cleanup | expand |
On 7/10/24 10:41, Tvrtko Ursulin wrote: > From: Tvrtko Ursulin <tvrtko.ursulin@igalia.com> > > Instead of statically reserving pessimistic space for the kperfmon_ids > array, make the userspace extension code allocate the exactly required > amount of space. > > Apart from saving some memory at runtime, this also removes the need for > the V3D_MAX_PERFMONS macro whose removal will benefit further driver > cleanup. > > Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@igalia.com> Reviewed-by: Maíra Canal <mcanal@igalia.com> Best Regards, - Maíra > --- > drivers/gpu/drm/v3d/v3d_drv.h | 6 +----- > drivers/gpu/drm/v3d/v3d_sched.c | 4 +++- > drivers/gpu/drm/v3d/v3d_submit.c | 17 +++++++++++------ > 3 files changed, 15 insertions(+), 12 deletions(-) > > diff --git a/drivers/gpu/drm/v3d/v3d_drv.h b/drivers/gpu/drm/v3d/v3d_drv.h > index 38c80168da51..00fe5d993175 100644 > --- a/drivers/gpu/drm/v3d/v3d_drv.h > +++ b/drivers/gpu/drm/v3d/v3d_drv.h > @@ -351,13 +351,9 @@ struct v3d_timestamp_query { > struct drm_syncobj *syncobj; > }; > > -/* Number of perfmons required to handle all supported performance counters */ > -#define V3D_MAX_PERFMONS DIV_ROUND_UP(V3D_MAX_COUNTERS, \ > - DRM_V3D_MAX_PERF_COUNTERS) > - > struct v3d_performance_query { > /* Performance monitor IDs for this query */ > - u32 kperfmon_ids[V3D_MAX_PERFMONS]; > + u32 *kperfmon_ids; > > /* Syncobj that indicates the query availability */ > struct drm_syncobj *syncobj; > diff --git a/drivers/gpu/drm/v3d/v3d_sched.c b/drivers/gpu/drm/v3d/v3d_sched.c > index 173801aa54ee..fc8730264386 100644 > --- a/drivers/gpu/drm/v3d/v3d_sched.c > +++ b/drivers/gpu/drm/v3d/v3d_sched.c > @@ -94,8 +94,10 @@ __v3d_performance_query_info_free(struct v3d_performance_query_info *qinfo, > if (qinfo->queries) { > unsigned int i; > > - for (i = 0; i < count; i++) > + for (i = 0; i < count; i++) { > drm_syncobj_put(qinfo->queries[i].syncobj); > + kvfree(qinfo->queries[i].kperfmon_ids); > + } > > kvfree(qinfo->queries); > } > diff --git a/drivers/gpu/drm/v3d/v3d_submit.c b/drivers/gpu/drm/v3d/v3d_submit.c > index 35682433f75b..8dae3ab5f936 100644 > --- a/drivers/gpu/drm/v3d/v3d_submit.c > +++ b/drivers/gpu/drm/v3d/v3d_submit.c > @@ -668,10 +668,20 @@ copy_query_info(struct v3d_performance_query_info *qinfo, > goto error; > } > > + query->kperfmon_ids = > + kvmalloc_array(nperfmons, > + sizeof(struct v3d_performance_query *), > + GFP_KERNEL); > + if (!query->kperfmon_ids) { > + err = -ENOMEM; > + goto error; > + } > + > ids_pointer = u64_to_user_ptr(ids); > > for (j = 0; j < nperfmons; j++) { > if (get_user(id, ids_pointer++)) { > + kvfree(query->kperfmon_ids); > err = -EFAULT; > goto error; > } > @@ -681,6 +691,7 @@ copy_query_info(struct v3d_performance_query_info *qinfo, > > query->syncobj = drm_syncobj_find(fpriv, sync); > if (!query->syncobj) { > + kvfree(query->kperfmon_ids); > err = -ENOENT; > goto error; > } > @@ -714,9 +725,6 @@ v3d_get_cpu_reset_performance_params(struct drm_file *file_priv, > if (copy_from_user(&reset, ext, sizeof(reset))) > return -EFAULT; > > - if (reset.nperfmons > V3D_MAX_PERFMONS) > - return -EINVAL; > - > job->job_type = V3D_CPU_JOB_TYPE_RESET_PERFORMANCE_QUERY; > > job->performance_query.queries = kvmalloc_array(reset.count, > @@ -762,9 +770,6 @@ v3d_get_cpu_copy_performance_query_params(struct drm_file *file_priv, > if (copy.pad) > return -EINVAL; > > - if (copy.nperfmons > V3D_MAX_PERFMONS) > - return -EINVAL; > - > job->job_type = V3D_CPU_JOB_TYPE_COPY_PERFORMANCE_QUERY; > > job->performance_query.queries = kvmalloc_array(copy.count,
diff --git a/drivers/gpu/drm/v3d/v3d_drv.h b/drivers/gpu/drm/v3d/v3d_drv.h index 38c80168da51..00fe5d993175 100644 --- a/drivers/gpu/drm/v3d/v3d_drv.h +++ b/drivers/gpu/drm/v3d/v3d_drv.h @@ -351,13 +351,9 @@ struct v3d_timestamp_query { struct drm_syncobj *syncobj; }; -/* Number of perfmons required to handle all supported performance counters */ -#define V3D_MAX_PERFMONS DIV_ROUND_UP(V3D_MAX_COUNTERS, \ - DRM_V3D_MAX_PERF_COUNTERS) - struct v3d_performance_query { /* Performance monitor IDs for this query */ - u32 kperfmon_ids[V3D_MAX_PERFMONS]; + u32 *kperfmon_ids; /* Syncobj that indicates the query availability */ struct drm_syncobj *syncobj; diff --git a/drivers/gpu/drm/v3d/v3d_sched.c b/drivers/gpu/drm/v3d/v3d_sched.c index 173801aa54ee..fc8730264386 100644 --- a/drivers/gpu/drm/v3d/v3d_sched.c +++ b/drivers/gpu/drm/v3d/v3d_sched.c @@ -94,8 +94,10 @@ __v3d_performance_query_info_free(struct v3d_performance_query_info *qinfo, if (qinfo->queries) { unsigned int i; - for (i = 0; i < count; i++) + for (i = 0; i < count; i++) { drm_syncobj_put(qinfo->queries[i].syncobj); + kvfree(qinfo->queries[i].kperfmon_ids); + } kvfree(qinfo->queries); } diff --git a/drivers/gpu/drm/v3d/v3d_submit.c b/drivers/gpu/drm/v3d/v3d_submit.c index 35682433f75b..8dae3ab5f936 100644 --- a/drivers/gpu/drm/v3d/v3d_submit.c +++ b/drivers/gpu/drm/v3d/v3d_submit.c @@ -668,10 +668,20 @@ copy_query_info(struct v3d_performance_query_info *qinfo, goto error; } + query->kperfmon_ids = + kvmalloc_array(nperfmons, + sizeof(struct v3d_performance_query *), + GFP_KERNEL); + if (!query->kperfmon_ids) { + err = -ENOMEM; + goto error; + } + ids_pointer = u64_to_user_ptr(ids); for (j = 0; j < nperfmons; j++) { if (get_user(id, ids_pointer++)) { + kvfree(query->kperfmon_ids); err = -EFAULT; goto error; } @@ -681,6 +691,7 @@ copy_query_info(struct v3d_performance_query_info *qinfo, query->syncobj = drm_syncobj_find(fpriv, sync); if (!query->syncobj) { + kvfree(query->kperfmon_ids); err = -ENOENT; goto error; } @@ -714,9 +725,6 @@ v3d_get_cpu_reset_performance_params(struct drm_file *file_priv, if (copy_from_user(&reset, ext, sizeof(reset))) return -EFAULT; - if (reset.nperfmons > V3D_MAX_PERFMONS) - return -EINVAL; - job->job_type = V3D_CPU_JOB_TYPE_RESET_PERFORMANCE_QUERY; job->performance_query.queries = kvmalloc_array(reset.count, @@ -762,9 +770,6 @@ v3d_get_cpu_copy_performance_query_params(struct drm_file *file_priv, if (copy.pad) return -EINVAL; - if (copy.nperfmons > V3D_MAX_PERFMONS) - return -EINVAL; - job->job_type = V3D_CPU_JOB_TYPE_COPY_PERFORMANCE_QUERY; job->performance_query.queries = kvmalloc_array(copy.count,