[Mesa-dev] [PATCH 2/3] anv: Add helpers for setting/checking device lost
Lionel Landwerlin
lionel.g.landwerlin at intel.com
Thu Oct 25 17:16:15 UTC 2018
I would put the vk_errorf within the anv_device_set_lost and make it
return VkResult so that you can cull a bunch of lines, but that can be
done in another commit.
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin at intel.com>
On 25/10/2018 17:46, Jason Ekstrand wrote:
> ---
> src/intel/vulkan/anv_device.c | 28 +++++++++++++++++-----------
> src/intel/vulkan/anv_private.h | 11 ++++++++++-
> src/intel/vulkan/anv_queue.c | 14 +++++++-------
> src/intel/vulkan/genX_query.c | 4 ++--
> 4 files changed, 36 insertions(+), 21 deletions(-)
>
> diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c
> index 8e4436ec960..79d3f052113 100644
> --- a/src/intel/vulkan/anv_device.c
> +++ b/src/intel/vulkan/anv_device.c
> @@ -1712,7 +1712,7 @@ VkResult anv_CreateDevice(
> device->instance = physical_device->instance;
> device->chipset_id = physical_device->chipset_id;
> device->no_hw = physical_device->no_hw;
> - device->lost = false;
> + device->_lost = false;
>
> if (pAllocator)
> device->alloc = *pAllocator;
> @@ -2049,6 +2049,12 @@ void anv_GetDeviceQueue2(
> *pQueue = NULL;
> }
>
> +void
> +anv_device_set_lost(struct anv_device *device, const char *msg, ...)
> +{
> + device->_lost = true;
> +}
> +
> VkResult
> anv_device_query_status(struct anv_device *device)
> {
> @@ -2056,24 +2062,24 @@ anv_device_query_status(struct anv_device *device)
> * for it. However, it doesn't hurt to check and it potentially lets us
> * avoid an ioctl.
> */
> - if (unlikely(device->lost))
> + if (anv_device_is_lost(device))
> return VK_ERROR_DEVICE_LOST;
>
> uint32_t active, pending;
> int ret = anv_gem_gpu_get_reset_stats(device, &active, &pending);
> if (ret == -1) {
> /* We don't know the real error. */
> - device->lost = true;
> + anv_device_set_lost(device, "get_reset_stats failed: %m");
> return vk_errorf(device->instance, device, VK_ERROR_DEVICE_LOST,
> "get_reset_stats failed: %m");
> }
>
> if (active) {
> - device->lost = true;
> + anv_device_set_lost(device, "GPU hung on one of our command buffers");
> return vk_errorf(device->instance, device, VK_ERROR_DEVICE_LOST,
> "GPU hung on one of our command buffers");
> } else if (pending) {
> - device->lost = true;
> + anv_device_set_lost(device, "GPU hung with commands in-flight");
> return vk_errorf(device->instance, device, VK_ERROR_DEVICE_LOST,
> "GPU hung with commands in-flight");
> }
> @@ -2093,7 +2099,7 @@ anv_device_bo_busy(struct anv_device *device, struct anv_bo *bo)
> return VK_NOT_READY;
> } else if (ret == -1) {
> /* We don't know the real error. */
> - device->lost = true;
> + anv_device_set_lost(device, "gem wait failed: %m");
> return vk_errorf(device->instance, device, VK_ERROR_DEVICE_LOST,
> "gem wait failed: %m");
> }
> @@ -2116,7 +2122,7 @@ anv_device_wait(struct anv_device *device, struct anv_bo *bo,
> return VK_TIMEOUT;
> } else if (ret == -1) {
> /* We don't know the real error. */
> - device->lost = true;
> + anv_device_set_lost(device, "gem wait failed: %m");
> return vk_errorf(device->instance, device, VK_ERROR_DEVICE_LOST,
> "gem wait failed: %m");
> }
> @@ -2133,7 +2139,7 @@ VkResult anv_DeviceWaitIdle(
> VkDevice _device)
> {
> ANV_FROM_HANDLE(anv_device, device, _device);
> - if (unlikely(device->lost))
> + if (anv_device_is_lost(device))
> return VK_ERROR_DEVICE_LOST;
>
> struct anv_batch batch;
> @@ -2807,7 +2813,7 @@ VkResult anv_QueueBindSparse(
> VkFence fence)
> {
> ANV_FROM_HANDLE(anv_queue, queue, _queue);
> - if (unlikely(queue->device->lost))
> + if (anv_device_is_lost(queue->device))
> return VK_ERROR_DEVICE_LOST;
>
> return vk_error(VK_ERROR_FEATURE_NOT_PRESENT);
> @@ -2865,7 +2871,7 @@ VkResult anv_GetEventStatus(
> ANV_FROM_HANDLE(anv_device, device, _device);
> ANV_FROM_HANDLE(anv_event, event, _event);
>
> - if (unlikely(device->lost))
> + if (anv_device_is_lost(device))
> return VK_ERROR_DEVICE_LOST;
>
> if (!device->info.has_llc) {
> @@ -3095,7 +3101,7 @@ VkResult anv_GetCalibratedTimestampsEXT(
> &pTimestamps[d]);
>
> if (ret != 0) {
> - device->lost = TRUE;
> + anv_device_set_lost(device, "Failed to get a timestamp");
> return vk_errorf(device->instance, device, VK_ERROR_DEVICE_LOST,
> "Failed to read the TIMESTAMP register: %m");
> }
> diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h
> index 0f957fae69b..a9fada56dd3 100644
> --- a/src/intel/vulkan/anv_private.h
> +++ b/src/intel/vulkan/anv_private.h
> @@ -1028,7 +1028,7 @@ struct anv_device {
>
> pthread_mutex_t mutex;
> pthread_cond_t queue_submit;
> - bool lost;
> + bool _lost;
> };
>
> static inline struct anv_state_pool *
> @@ -1075,6 +1075,15 @@ anv_state_flush(struct anv_device *device, struct anv_state state)
> void anv_device_init_blorp(struct anv_device *device);
> void anv_device_finish_blorp(struct anv_device *device);
>
> +void anv_device_set_lost(struct anv_device *device,
> + const char *msg, ...);
> +
> +static inline bool
> +anv_device_is_lost(struct anv_device *device)
> +{
> + return unlikely(device->_lost);
> +}
> +
> VkResult anv_device_execbuf(struct anv_device *device,
> struct drm_i915_gem_execbuffer2 *execbuf,
> struct anv_bo **execbuf_bos);
> diff --git a/src/intel/vulkan/anv_queue.c b/src/intel/vulkan/anv_queue.c
> index e0c0a42069f..e07c37f4942 100644
> --- a/src/intel/vulkan/anv_queue.c
> +++ b/src/intel/vulkan/anv_queue.c
> @@ -42,7 +42,7 @@ anv_device_execbuf(struct anv_device *device,
> int ret = device->no_hw ? 0 : anv_gem_execbuffer(device, execbuf);
> if (ret != 0) {
> /* We don't know the real error. */
> - device->lost = true;
> + anv_device_set_lost(device, "execbuf2 failed: %m");
> return vk_errorf(device->instance, device, VK_ERROR_DEVICE_LOST,
> "execbuf2 failed: %m");
> }
> @@ -245,7 +245,7 @@ out:
> */
> result = vk_errorf(device->instance, device, VK_ERROR_DEVICE_LOST,
> "vkQueueSubmit() failed");
> - device->lost = true;
> + anv_device_set_lost(device, "vkQueueSubmit() failed");
> }
>
> pthread_mutex_unlock(&device->mutex);
> @@ -398,7 +398,7 @@ VkResult anv_GetFenceStatus(
> ANV_FROM_HANDLE(anv_device, device, _device);
> ANV_FROM_HANDLE(anv_fence, fence, _fence);
>
> - if (unlikely(device->lost))
> + if (anv_device_is_lost(device))
> return VK_ERROR_DEVICE_LOST;
>
> struct anv_fence_impl *impl =
> @@ -438,7 +438,7 @@ VkResult anv_GetFenceStatus(
> return VK_NOT_READY;
> } else {
> /* We don't know the real error. */
> - device->lost = true;
> + anv_device_set_lost(device, "drm_syncobj_wait failed: %m");
> return vk_errorf(device->instance, device, VK_ERROR_DEVICE_LOST,
> "drm_syncobj_wait failed: %m");
> }
> @@ -526,7 +526,7 @@ anv_wait_for_syncobj_fences(struct anv_device *device,
> return VK_TIMEOUT;
> } else {
> /* We don't know the real error. */
> - device->lost = true;
> + anv_device_set_lost(device, "drm_syncobj_wait failed: %m");
> return vk_errorf(device->instance, device, VK_ERROR_DEVICE_LOST,
> "drm_syncobj_wait failed: %m");
> }
> @@ -671,7 +671,7 @@ anv_wait_for_bo_fences(struct anv_device *device,
> }
>
> done:
> - if (unlikely(device->lost))
> + if (anv_device_is_lost(device))
> return VK_ERROR_DEVICE_LOST;
>
> return result;
> @@ -761,7 +761,7 @@ VkResult anv_WaitForFences(
> {
> ANV_FROM_HANDLE(anv_device, device, _device);
>
> - if (unlikely(device->lost))
> + if (anv_device_is_lost(device))
> return VK_ERROR_DEVICE_LOST;
>
> if (anv_all_fences_syncobj(fenceCount, pFences)) {
> diff --git a/src/intel/vulkan/genX_query.c b/src/intel/vulkan/genX_query.c
> index 7533ec05095..7dd9112d296 100644
> --- a/src/intel/vulkan/genX_query.c
> +++ b/src/intel/vulkan/genX_query.c
> @@ -181,7 +181,7 @@ wait_for_available(struct anv_device *device,
> continue;
> } else if (ret == -1) {
> /* We don't know the real error. */
> - device->lost = true;
> + anv_device_set_lost(device, "gem wait failed: %m");
> return vk_errorf(device->instance, device, VK_ERROR_DEVICE_LOST,
> "gem wait failed: %m");
> } else {
> @@ -224,7 +224,7 @@ VkResult genX(GetQueryPoolResults)(
> pool->type == VK_QUERY_TYPE_PIPELINE_STATISTICS ||
> pool->type == VK_QUERY_TYPE_TIMESTAMP);
>
> - if (unlikely(device->lost))
> + if (anv_device_is_lost(device))
> return VK_ERROR_DEVICE_LOST;
>
> if (pData == NULL)
More information about the mesa-dev
mailing list