sync_debug.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Sync File validation framework and debug information
  4. *
  5. * Copyright (C) 2012 Google, Inc.
  6. */
  7. #include <linux/debugfs.h>
  8. #include "sync_debug.h"
  9. static struct dentry *dbgfs;
  10. static LIST_HEAD(sync_timeline_list_head);
  11. static DEFINE_SPINLOCK(sync_timeline_list_lock);
  12. void sync_timeline_debug_add(struct sync_timeline *obj)
  13. {
  14. unsigned long flags;
  15. spin_lock_irqsave(&sync_timeline_list_lock, flags);
  16. list_add_tail(&obj->sync_timeline_list, &sync_timeline_list_head);
  17. spin_unlock_irqrestore(&sync_timeline_list_lock, flags);
  18. }
  19. void sync_timeline_debug_remove(struct sync_timeline *obj)
  20. {
  21. unsigned long flags;
  22. spin_lock_irqsave(&sync_timeline_list_lock, flags);
  23. list_del(&obj->sync_timeline_list);
  24. spin_unlock_irqrestore(&sync_timeline_list_lock, flags);
  25. }
  26. static const char *sync_status_str(int status)
  27. {
  28. if (status < 0)
  29. return "error";
  30. if (status > 0)
  31. return "signaled";
  32. return "active";
  33. }
  34. static void sync_print_fence(struct seq_file *s,
  35. struct dma_fence *fence, bool show)
  36. {
  37. struct sync_timeline *parent = dma_fence_parent(fence);
  38. int status;
  39. status = dma_fence_get_status_locked(fence);
  40. seq_printf(s, " %s%sfence %s",
  41. show ? parent->name : "",
  42. show ? "_" : "",
  43. sync_status_str(status));
  44. if (test_bit(DMA_FENCE_FLAG_TIMESTAMP_BIT, &fence->flags)) {
  45. struct timespec64 ts64 =
  46. ktime_to_timespec64(fence->timestamp);
  47. seq_printf(s, "@%ptSp", &ts64);
  48. }
  49. seq_printf(s, ": %lld", fence->seqno);
  50. seq_printf(s, " / %d", parent->value);
  51. seq_putc(s, '\n');
  52. }
  53. static void sync_print_obj(struct seq_file *s, struct sync_timeline *obj)
  54. {
  55. struct list_head *pos;
  56. seq_printf(s, "%s: %d\n", obj->name, obj->value);
  57. spin_lock(&obj->lock); /* Caller already disabled IRQ. */
  58. list_for_each(pos, &obj->pt_list) {
  59. struct sync_pt *pt = container_of(pos, struct sync_pt, link);
  60. sync_print_fence(s, &pt->base, false);
  61. }
  62. spin_unlock(&obj->lock);
  63. }
  64. static int sync_info_debugfs_show(struct seq_file *s, void *unused)
  65. {
  66. struct list_head *pos;
  67. seq_puts(s, "objs:\n--------------\n");
  68. spin_lock_irq(&sync_timeline_list_lock);
  69. list_for_each(pos, &sync_timeline_list_head) {
  70. struct sync_timeline *obj =
  71. container_of(pos, struct sync_timeline,
  72. sync_timeline_list);
  73. sync_print_obj(s, obj);
  74. seq_putc(s, '\n');
  75. }
  76. spin_unlock_irq(&sync_timeline_list_lock);
  77. seq_puts(s, "fences:\n--------------\n");
  78. return 0;
  79. }
  80. DEFINE_SHOW_ATTRIBUTE(sync_info_debugfs);
  81. static __init int sync_debugfs_init(void)
  82. {
  83. dbgfs = debugfs_create_dir("sync", NULL);
  84. /*
  85. * The debugfs files won't ever get removed and thus, there is
  86. * no need to protect it against removal races. The use of
  87. * debugfs_create_file_unsafe() is actually safe here.
  88. */
  89. debugfs_create_file_unsafe("info", 0444, dbgfs, NULL,
  90. &sync_info_debugfs_fops);
  91. debugfs_create_file_unsafe("sw_sync", 0644, dbgfs, NULL,
  92. &sw_sync_debugfs_fops);
  93. return 0;
  94. }
  95. late_initcall(sync_debugfs_init);