drm/exec: Pass in initial # of objects

In cases where the # is known ahead of time, it is silly to do the table
resize dance.

Signed-off-by: Rob Clark <robdclark@chromium.org>
Reviewed-by: Christian König <christian.koenig@amd.com>
Patchwork: https://patchwork.freedesktop.org/patch/568338/
This commit is contained in:
Rob Clark
2023-11-20 16:38:50 -08:00
parent 3a48a40387
commit 05d249352f
13 changed files with 37 additions and 30 deletions

View File

@@ -69,16 +69,23 @@ static void drm_exec_unlock_all(struct drm_exec *exec)
* drm_exec_init - initialize a drm_exec object
* @exec: the drm_exec object to initialize
* @flags: controls locking behavior, see DRM_EXEC_* defines
* @nr: the initial # of objects
*
* Initialize the object and make sure that we can track locked objects.
*
* If nr is non-zero then it is used as the initial objects table size.
* In either case, the table will grow (be re-allocated) on demand.
*/
void drm_exec_init(struct drm_exec *exec, uint32_t flags)
void drm_exec_init(struct drm_exec *exec, uint32_t flags, unsigned nr)
{
if (!nr)
nr = PAGE_SIZE / sizeof(void *);
exec->flags = flags;
exec->objects = kmalloc(PAGE_SIZE, GFP_KERNEL);
exec->objects = kvmalloc_array(nr, sizeof(void *), GFP_KERNEL);
/* If allocation here fails, just delay that till the first use */
exec->max_objects = exec->objects ? PAGE_SIZE / sizeof(void *) : 0;
exec->max_objects = exec->objects ? nr : 0;
exec->num_objects = 0;
exec->contended = DRM_EXEC_DUMMY;
exec->prelocked = NULL;