anv: Add helpers for setting/checking device lost
authorJason Ekstrand <jason.ekstrand@intel.com>
Tue, 13 Mar 2018 18:50:33 +0000 (11:50 -0700)
committerJason Ekstrand <jason.ekstrand@intel.com>
Fri, 26 Oct 2018 13:40:21 +0000 (08:40 -0500)
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Reviewed-by: Eric Engestrom <eric.engestrom@intel.com>
src/intel/vulkan/anv_device.c
src/intel/vulkan/anv_private.h
src/intel/vulkan/anv_queue.c
src/intel/vulkan/genX_query.c

index 87fe5e4dbbf753f50a6f2afa346013be6f83931f..b4034145a555d445a917cc10aa8382131c399789 100644 (file)
@@ -1711,7 +1711,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;
@@ -2048,6 +2048,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)
 {
@@ -2055,24 +2061,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");
    }
@@ -2092,7 +2098,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");
    }
@@ -2115,7 +2121,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");
    }
@@ -2132,7 +2138,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;
@@ -2806,7 +2812,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);
@@ -2864,7 +2870,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) {
@@ -3094,7 +3100,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");
          }
index a3a041ab3227db6d001065cdf7e883d09a283ae0..a3ab971b6fd8b2355933f70b691a955bf8f0f29b 100644 (file)
@@ -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);
index cf063701b8d0bf71af2c77a4f7a801f8179efcd5..8e9f743fcb7a953a1f8fc97c5d766f265246331f 100644 (file)
@@ -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");
       }
@@ -670,7 +670,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;
@@ -760,7 +760,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)) {
index 7533ec050953ba21ab1e363186db9c305fbddbd5..7dd9112d296228f1c7d53253569681014af96d34 100644 (file)
@@ -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)