i915_gem_debug.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /*
  2. * Copyright © 2008 Intel Corporation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice (including the next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. * IN THE SOFTWARE.
  22. *
  23. * Authors:
  24. * Keith Packard <keithp@keithp.com>
  25. *
  26. */
  27. #include "drmP.h"
  28. #include "drm.h"
  29. #include "i915_drm.h"
  30. #include "i915_drv.h"
  31. #if WATCH_INACTIVE
  32. void
  33. i915_verify_inactive(struct drm_device *dev, char *file, int line)
  34. {
  35. drm_i915_private_t *dev_priv = dev->dev_private;
  36. struct drm_gem_object *obj;
  37. struct drm_i915_gem_object *obj_priv;
  38. list_for_each_entry(obj_priv, &dev_priv->mm.inactive_list, list) {
  39. obj = obj_priv->obj;
  40. if (obj_priv->pin_count || obj_priv->active ||
  41. (obj->write_domain & ~(I915_GEM_DOMAIN_CPU |
  42. I915_GEM_DOMAIN_GTT)))
  43. DRM_ERROR("inactive %p (p %d a %d w %x) %s:%d\n",
  44. obj,
  45. obj_priv->pin_count, obj_priv->active,
  46. obj->write_domain, file, line);
  47. }
  48. }
  49. #endif /* WATCH_INACTIVE */
  50. #if WATCH_BUF | WATCH_EXEC | WATCH_PWRITE
  51. static void
  52. i915_gem_dump_page(struct page *page, uint32_t start, uint32_t end,
  53. uint32_t bias, uint32_t mark)
  54. {
  55. uint32_t *mem = kmap_atomic(page, KM_USER0);
  56. int i;
  57. for (i = start; i < end; i += 4)
  58. DRM_INFO("%08x: %08x%s\n",
  59. (int) (bias + i), mem[i / 4],
  60. (bias + i == mark) ? " ********" : "");
  61. kunmap_atomic(mem, KM_USER0);
  62. /* give syslog time to catch up */
  63. msleep(1);
  64. }
  65. void
  66. i915_gem_dump_object(struct drm_gem_object *obj, int len,
  67. const char *where, uint32_t mark)
  68. {
  69. struct drm_i915_gem_object *obj_priv = obj->driver_private;
  70. int page;
  71. DRM_INFO("%s: object at offset %08x\n", where, obj_priv->gtt_offset);
  72. for (page = 0; page < (len + PAGE_SIZE-1) / PAGE_SIZE; page++) {
  73. int page_len, chunk, chunk_len;
  74. page_len = len - page * PAGE_SIZE;
  75. if (page_len > PAGE_SIZE)
  76. page_len = PAGE_SIZE;
  77. for (chunk = 0; chunk < page_len; chunk += 128) {
  78. chunk_len = page_len - chunk;
  79. if (chunk_len > 128)
  80. chunk_len = 128;
  81. i915_gem_dump_page(obj_priv->page_list[page],
  82. chunk, chunk + chunk_len,
  83. obj_priv->gtt_offset +
  84. page * PAGE_SIZE,
  85. mark);
  86. }
  87. }
  88. }
  89. #endif
  90. #if WATCH_LRU
  91. void
  92. i915_dump_lru(struct drm_device *dev, const char *where)
  93. {
  94. drm_i915_private_t *dev_priv = dev->dev_private;
  95. struct drm_i915_gem_object *obj_priv;
  96. DRM_INFO("active list %s {\n", where);
  97. list_for_each_entry(obj_priv, &dev_priv->mm.active_list,
  98. list)
  99. {
  100. DRM_INFO(" %p: %08x\n", obj_priv,
  101. obj_priv->last_rendering_seqno);
  102. }
  103. DRM_INFO("}\n");
  104. DRM_INFO("flushing list %s {\n", where);
  105. list_for_each_entry(obj_priv, &dev_priv->mm.flushing_list,
  106. list)
  107. {
  108. DRM_INFO(" %p: %08x\n", obj_priv,
  109. obj_priv->last_rendering_seqno);
  110. }
  111. DRM_INFO("}\n");
  112. DRM_INFO("inactive %s {\n", where);
  113. list_for_each_entry(obj_priv, &dev_priv->mm.inactive_list, list) {
  114. DRM_INFO(" %p: %08x\n", obj_priv,
  115. obj_priv->last_rendering_seqno);
  116. }
  117. DRM_INFO("}\n");
  118. }
  119. #endif
  120. #if WATCH_COHERENCY
  121. void
  122. i915_gem_object_check_coherency(struct drm_gem_object *obj, int handle)
  123. {
  124. struct drm_device *dev = obj->dev;
  125. struct drm_i915_gem_object *obj_priv = obj->driver_private;
  126. int page;
  127. uint32_t *gtt_mapping;
  128. uint32_t *backing_map = NULL;
  129. int bad_count = 0;
  130. DRM_INFO("%s: checking coherency of object %p@0x%08x (%d, %dkb):\n",
  131. __func__, obj, obj_priv->gtt_offset, handle,
  132. obj->size / 1024);
  133. gtt_mapping = ioremap(dev->agp->base + obj_priv->gtt_offset,
  134. obj->size);
  135. if (gtt_mapping == NULL) {
  136. DRM_ERROR("failed to map GTT space\n");
  137. return;
  138. }
  139. for (page = 0; page < obj->size / PAGE_SIZE; page++) {
  140. int i;
  141. backing_map = kmap_atomic(obj_priv->page_list[page], KM_USER0);
  142. if (backing_map == NULL) {
  143. DRM_ERROR("failed to map backing page\n");
  144. goto out;
  145. }
  146. for (i = 0; i < PAGE_SIZE / 4; i++) {
  147. uint32_t cpuval = backing_map[i];
  148. uint32_t gttval = readl(gtt_mapping +
  149. page * 1024 + i);
  150. if (cpuval != gttval) {
  151. DRM_INFO("incoherent CPU vs GPU at 0x%08x: "
  152. "0x%08x vs 0x%08x\n",
  153. (int)(obj_priv->gtt_offset +
  154. page * PAGE_SIZE + i * 4),
  155. cpuval, gttval);
  156. if (bad_count++ >= 8) {
  157. DRM_INFO("...\n");
  158. goto out;
  159. }
  160. }
  161. }
  162. kunmap_atomic(backing_map, KM_USER0);
  163. backing_map = NULL;
  164. }
  165. out:
  166. if (backing_map != NULL)
  167. kunmap_atomic(backing_map, KM_USER0);
  168. iounmap(gtt_mapping);
  169. /* give syslog time to catch up */
  170. msleep(1);
  171. /* Directly flush the object, since we just loaded values with the CPU
  172. * from the backing pages and we don't want to disturb the cache
  173. * management that we're trying to observe.
  174. */
  175. i915_gem_clflush_object(obj);
  176. }
  177. #endif