From e905bfe81bd404bca00dcaa0f6b9fc56d46cfe95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Roberto=20de=20Souza?= Date: Fri, 22 Dec 2023 09:49:36 -0800 Subject: [PATCH] intel/common: Add functions to handle async vm bind MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Roberto de Souza Reviewed-by: Lionel Landwerlin Part-of: --- src/intel/common/intel_bind_timeline.c | 79 ++++++++++++++++++++++++++ src/intel/common/intel_bind_timeline.h | 25 ++++++++ src/intel/common/meson.build | 2 + 3 files changed, 106 insertions(+) create mode 100644 src/intel/common/intel_bind_timeline.c create mode 100644 src/intel/common/intel_bind_timeline.h diff --git a/src/intel/common/intel_bind_timeline.c b/src/intel/common/intel_bind_timeline.c new file mode 100644 index 00000000000..f96158339a5 --- /dev/null +++ b/src/intel/common/intel_bind_timeline.c @@ -0,0 +1,79 @@ +/* + * Copyright 2023 Intel Corporation + * SPDX-License-Identifier: MIT + */ + +#include "intel_bind_timeline.h" + +#include "drm-uapi/drm.h" +#include "intel_gem.h" + +bool intel_bind_timeline_init(struct intel_bind_timeline *bind_timeline, int fd) +{ + struct drm_syncobj_create syncobj_create = { .flags = DRM_SYNCOBJ_CREATE_SIGNALED }; + + if (intel_ioctl(fd, DRM_IOCTL_SYNCOBJ_CREATE, &syncobj_create)) + return false; + + simple_mtx_init(&bind_timeline->mutex, mtx_plain); + bind_timeline->syncobj = syncobj_create.handle; + bind_timeline->point = 0; + + return true; +} + +void intel_bind_timeline_finish(struct intel_bind_timeline *bind_timeline, int fd) +{ + if (bind_timeline->syncobj == 0) + return; + + uint64_t point = intel_bind_timeline_get_last_point(bind_timeline); + struct drm_syncobj_timeline_wait syncobj_wait = { + .timeout_nsec = INT64_MAX, + .handles = (uintptr_t)&bind_timeline->syncobj, + .count_handles = 1, + .points = (uintptr_t)&point, + }; + struct drm_syncobj_destroy syncobj_destroy = { + .handle = bind_timeline->syncobj, + }; + + /* Makes sure last unbind was signaled otherwise it can trigger job + * timeouts in KMD + */ + intel_ioctl(fd, DRM_IOCTL_SYNCOBJ_TIMELINE_WAIT, &syncobj_wait); + intel_ioctl(fd, DRM_IOCTL_SYNCOBJ_DESTROY, &syncobj_destroy); + + simple_mtx_destroy(&bind_timeline->mutex); +} + +uint32_t intel_bind_timeline_get_syncobj(struct intel_bind_timeline *bind_timeline) +{ + return bind_timeline->syncobj; +} + +uint64_t intel_bind_timeline_bind_begin(struct intel_bind_timeline *bind_timeline) +{ + simple_mtx_lock(&bind_timeline->mutex); + return ++bind_timeline->point; +} + +void intel_bind_timeline_bind_end(struct intel_bind_timeline *bind_timeline) +{ + simple_mtx_unlock(&bind_timeline->mutex); +} + +/* + * Returns the timeline point that should be waited on before execute any + * batch buffers. + */ +uint64_t intel_bind_timeline_get_last_point(struct intel_bind_timeline *bind_timeline) +{ + uint64_t ret; + + simple_mtx_lock(&bind_timeline->mutex); + ret = bind_timeline->point; + simple_mtx_unlock(&bind_timeline->mutex); + + return ret; +} diff --git a/src/intel/common/intel_bind_timeline.h b/src/intel/common/intel_bind_timeline.h new file mode 100644 index 00000000000..faeb73e52fd --- /dev/null +++ b/src/intel/common/intel_bind_timeline.h @@ -0,0 +1,25 @@ +/* + * Copyright 2023 Intel Corporation + * SPDX-License-Identifier: MIT + */ + +#pragma once + +#include +#include + +#include "util/simple_mtx.h" + +struct intel_bind_timeline { + simple_mtx_t mutex; + uint32_t syncobj; + uint64_t point; +}; + +bool intel_bind_timeline_init(struct intel_bind_timeline *intel_bind_timeline, int fd); +void intel_bind_timeline_finish(struct intel_bind_timeline *bind_timeline, int fd); + +uint64_t intel_bind_timeline_bind_begin(struct intel_bind_timeline *bind_timeline); +void intel_bind_timeline_bind_end(struct intel_bind_timeline *bind_timeline); +uint32_t intel_bind_timeline_get_syncobj(struct intel_bind_timeline *bind_timeline); +uint64_t intel_bind_timeline_get_last_point(struct intel_bind_timeline *bind_timeline); diff --git a/src/intel/common/meson.build b/src/intel/common/meson.build index 979ca09cb82..491ed159c01 100644 --- a/src/intel/common/meson.build +++ b/src/intel/common/meson.build @@ -33,6 +33,8 @@ files_libintel_common = files( 'xe/intel_gem.h', 'intel_aux_map.c', 'intel_aux_map.h', + 'intel_bind_timeline.c', + 'intel_bind_timeline.h', 'intel_buffer_alloc.h', 'intel_decoder.h', 'intel_disasm.c',