Thomas Gleixner | 9c92ab6 | 2019-05-29 07:17:56 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Maarten Lankhorst | 0f0d840 | 2014-07-01 12:57:31 +0200 | [diff] [blame] | 2 | /* |
Gustavo Padovan | e912c88 | 2016-08-11 12:26:42 -0300 | [diff] [blame] | 3 | * Sync File validation framework and debug information |
Maarten Lankhorst | 0f0d840 | 2014-07-01 12:57:31 +0200 | [diff] [blame] | 4 | * |
| 5 | * Copyright (C) 2012 Google, Inc. |
Maarten Lankhorst | 0f0d840 | 2014-07-01 12:57:31 +0200 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <linux/debugfs.h> |
Gustavo Padovan | 1fe82e2 | 2016-05-31 16:59:12 -0300 | [diff] [blame] | 9 | #include "sync_debug.h" |
Maarten Lankhorst | 0f0d840 | 2014-07-01 12:57:31 +0200 | [diff] [blame] | 10 | |
Gustavo Padovan | 8a00448 | 2016-01-21 10:49:17 -0200 | [diff] [blame] | 11 | static struct dentry *dbgfs; |
| 12 | |
Maarten Lankhorst | 0f0d840 | 2014-07-01 12:57:31 +0200 | [diff] [blame] | 13 | static LIST_HEAD(sync_timeline_list_head); |
| 14 | static DEFINE_SPINLOCK(sync_timeline_list_lock); |
Gustavo Padovan | d7fdb0a | 2016-01-21 10:49:19 -0200 | [diff] [blame] | 15 | static LIST_HEAD(sync_file_list_head); |
| 16 | static DEFINE_SPINLOCK(sync_file_list_lock); |
Maarten Lankhorst | 0f0d840 | 2014-07-01 12:57:31 +0200 | [diff] [blame] | 17 | |
| 18 | void sync_timeline_debug_add(struct sync_timeline *obj) |
| 19 | { |
| 20 | unsigned long flags; |
| 21 | |
| 22 | spin_lock_irqsave(&sync_timeline_list_lock, flags); |
| 23 | list_add_tail(&obj->sync_timeline_list, &sync_timeline_list_head); |
| 24 | spin_unlock_irqrestore(&sync_timeline_list_lock, flags); |
| 25 | } |
| 26 | |
| 27 | void sync_timeline_debug_remove(struct sync_timeline *obj) |
| 28 | { |
| 29 | unsigned long flags; |
| 30 | |
| 31 | spin_lock_irqsave(&sync_timeline_list_lock, flags); |
| 32 | list_del(&obj->sync_timeline_list); |
| 33 | spin_unlock_irqrestore(&sync_timeline_list_lock, flags); |
| 34 | } |
| 35 | |
Gustavo Padovan | d7fdb0a | 2016-01-21 10:49:19 -0200 | [diff] [blame] | 36 | void sync_file_debug_add(struct sync_file *sync_file) |
Maarten Lankhorst | 0f0d840 | 2014-07-01 12:57:31 +0200 | [diff] [blame] | 37 | { |
| 38 | unsigned long flags; |
| 39 | |
Gustavo Padovan | d7fdb0a | 2016-01-21 10:49:19 -0200 | [diff] [blame] | 40 | spin_lock_irqsave(&sync_file_list_lock, flags); |
| 41 | list_add_tail(&sync_file->sync_file_list, &sync_file_list_head); |
| 42 | spin_unlock_irqrestore(&sync_file_list_lock, flags); |
Maarten Lankhorst | 0f0d840 | 2014-07-01 12:57:31 +0200 | [diff] [blame] | 43 | } |
| 44 | |
Gustavo Padovan | d7fdb0a | 2016-01-21 10:49:19 -0200 | [diff] [blame] | 45 | void sync_file_debug_remove(struct sync_file *sync_file) |
Maarten Lankhorst | 0f0d840 | 2014-07-01 12:57:31 +0200 | [diff] [blame] | 46 | { |
| 47 | unsigned long flags; |
| 48 | |
Gustavo Padovan | d7fdb0a | 2016-01-21 10:49:19 -0200 | [diff] [blame] | 49 | spin_lock_irqsave(&sync_file_list_lock, flags); |
| 50 | list_del(&sync_file->sync_file_list); |
| 51 | spin_unlock_irqrestore(&sync_file_list_lock, flags); |
Maarten Lankhorst | 0f0d840 | 2014-07-01 12:57:31 +0200 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | static const char *sync_status_str(int status) |
| 55 | { |
Chris Wilson | d6c99f4 | 2017-01-04 14:12:21 +0000 | [diff] [blame] | 56 | if (status < 0) |
| 57 | return "error"; |
Peter Senna Tschudin | 9545135 | 2014-07-12 21:55:56 +0200 | [diff] [blame] | 58 | |
| 59 | if (status > 0) |
Chris Wilson | d6c99f4 | 2017-01-04 14:12:21 +0000 | [diff] [blame] | 60 | return "signaled"; |
Peter Senna Tschudin | 9545135 | 2014-07-12 21:55:56 +0200 | [diff] [blame] | 61 | |
Chris Wilson | d6c99f4 | 2017-01-04 14:12:21 +0000 | [diff] [blame] | 62 | return "active"; |
Maarten Lankhorst | 0f0d840 | 2014-07-01 12:57:31 +0200 | [diff] [blame] | 63 | } |
| 64 | |
Chris Wilson | f54d186 | 2016-10-25 13:00:45 +0100 | [diff] [blame] | 65 | static void sync_print_fence(struct seq_file *s, |
| 66 | struct dma_fence *fence, bool show) |
Maarten Lankhorst | 0f0d840 | 2014-07-01 12:57:31 +0200 | [diff] [blame] | 67 | { |
Chris Wilson | f54d186 | 2016-10-25 13:00:45 +0100 | [diff] [blame] | 68 | struct sync_timeline *parent = dma_fence_parent(fence); |
Chris Wilson | d6c99f4 | 2017-01-04 14:12:21 +0000 | [diff] [blame] | 69 | int status; |
Maarten Lankhorst | 0f0d840 | 2014-07-01 12:57:31 +0200 | [diff] [blame] | 70 | |
Chris Wilson | d6c99f4 | 2017-01-04 14:12:21 +0000 | [diff] [blame] | 71 | status = dma_fence_get_status_locked(fence); |
Maarten Lankhorst | 0f0d840 | 2014-07-01 12:57:31 +0200 | [diff] [blame] | 72 | |
Gustavo Padovan | b55b54b | 2016-01-21 10:49:21 -0200 | [diff] [blame] | 73 | seq_printf(s, " %s%sfence %s", |
| 74 | show ? parent->name : "", |
| 75 | show ? "_" : "", |
Maarten Lankhorst | 0f0d840 | 2014-07-01 12:57:31 +0200 | [diff] [blame] | 76 | sync_status_str(status)); |
| 77 | |
Chris Wilson | 76250f2 | 2017-02-14 12:40:01 +0000 | [diff] [blame] | 78 | if (test_bit(DMA_FENCE_FLAG_TIMESTAMP_BIT, &fence->flags)) { |
Steve Pennington | 0541cdf | 2014-12-24 09:33:02 -0600 | [diff] [blame] | 79 | struct timespec64 ts64 = |
Gustavo Padovan | b55b54b | 2016-01-21 10:49:21 -0200 | [diff] [blame] | 80 | ktime_to_timespec64(fence->timestamp); |
Peter Senna Tschudin | 9545135 | 2014-07-12 21:55:56 +0200 | [diff] [blame] | 81 | |
Tapasweni Pathak | 353fdf1 | 2014-10-26 19:20:16 +0530 | [diff] [blame] | 82 | seq_printf(s, "@%lld.%09ld", (s64)ts64.tv_sec, ts64.tv_nsec); |
Maarten Lankhorst | 0f0d840 | 2014-07-01 12:57:31 +0200 | [diff] [blame] | 83 | } |
| 84 | |
Gustavo Padovan | 724812d6 | 2016-05-31 16:59:02 -0300 | [diff] [blame] | 85 | if (fence->ops->timeline_value_str && |
Gustavo Padovan | b55b54b | 2016-01-21 10:49:21 -0200 | [diff] [blame] | 86 | fence->ops->fence_value_str) { |
Maarten Lankhorst | 0f0d840 | 2014-07-01 12:57:31 +0200 | [diff] [blame] | 87 | char value[64]; |
Maarten Lankhorst | 73465f1 | 2015-12-11 13:11:49 +0000 | [diff] [blame] | 88 | bool success; |
Peter Senna Tschudin | 9545135 | 2014-07-12 21:55:56 +0200 | [diff] [blame] | 89 | |
Gustavo Padovan | b55b54b | 2016-01-21 10:49:21 -0200 | [diff] [blame] | 90 | fence->ops->fence_value_str(fence, value, sizeof(value)); |
Maarten Lankhorst | 73465f1 | 2015-12-11 13:11:49 +0000 | [diff] [blame] | 91 | success = strlen(value); |
| 92 | |
Gustavo Padovan | 724812d6 | 2016-05-31 16:59:02 -0300 | [diff] [blame] | 93 | if (success) { |
Maarten Lankhorst | 73465f1 | 2015-12-11 13:11:49 +0000 | [diff] [blame] | 94 | seq_printf(s, ": %s", value); |
| 95 | |
Gustavo Padovan | b55b54b | 2016-01-21 10:49:21 -0200 | [diff] [blame] | 96 | fence->ops->timeline_value_str(fence, value, |
| 97 | sizeof(value)); |
Maarten Lankhorst | 73465f1 | 2015-12-11 13:11:49 +0000 | [diff] [blame] | 98 | |
| 99 | if (strlen(value)) |
| 100 | seq_printf(s, " / %s", value); |
Maarten Lankhorst | 0f0d840 | 2014-07-01 12:57:31 +0200 | [diff] [blame] | 101 | } |
| 102 | } |
| 103 | |
Markus Elfring | 47a369d | 2017-05-08 10:55:42 +0200 | [diff] [blame] | 104 | seq_putc(s, '\n'); |
Maarten Lankhorst | 0f0d840 | 2014-07-01 12:57:31 +0200 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | static void sync_print_obj(struct seq_file *s, struct sync_timeline *obj) |
| 108 | { |
| 109 | struct list_head *pos; |
Maarten Lankhorst | 0f0d840 | 2014-07-01 12:57:31 +0200 | [diff] [blame] | 110 | |
Gustavo Padovan | b9bc2b7 | 2016-05-31 16:59:11 -0300 | [diff] [blame] | 111 | seq_printf(s, "%s: %d\n", obj->name, obj->value); |
Maarten Lankhorst | 0f0d840 | 2014-07-01 12:57:31 +0200 | [diff] [blame] | 112 | |
Chris Wilson | d3862e4 | 2017-06-29 22:05:32 +0100 | [diff] [blame] | 113 | spin_lock_irq(&obj->lock); |
| 114 | list_for_each(pos, &obj->pt_list) { |
| 115 | struct sync_pt *pt = container_of(pos, struct sync_pt, link); |
Gustavo Padovan | 0431b90 | 2016-05-31 16:59:04 -0300 | [diff] [blame] | 116 | sync_print_fence(s, &pt->base, false); |
Maarten Lankhorst | 0f0d840 | 2014-07-01 12:57:31 +0200 | [diff] [blame] | 117 | } |
Chris Wilson | d3862e4 | 2017-06-29 22:05:32 +0100 | [diff] [blame] | 118 | spin_unlock_irq(&obj->lock); |
Maarten Lankhorst | 0f0d840 | 2014-07-01 12:57:31 +0200 | [diff] [blame] | 119 | } |
| 120 | |
Gustavo Padovan | d7fdb0a | 2016-01-21 10:49:19 -0200 | [diff] [blame] | 121 | static void sync_print_sync_file(struct seq_file *s, |
| 122 | struct sync_file *sync_file) |
Gustavo Padovan | b55b54b | 2016-01-21 10:49:21 -0200 | [diff] [blame] | 123 | { |
Chris Wilson | 71ebc9a | 2017-05-16 12:10:42 +0100 | [diff] [blame] | 124 | char buf[128]; |
Maarten Lankhorst | 0f0d840 | 2014-07-01 12:57:31 +0200 | [diff] [blame] | 125 | int i; |
| 126 | |
Chris Wilson | 71ebc9a | 2017-05-16 12:10:42 +0100 | [diff] [blame] | 127 | seq_printf(s, "[%p] %s: %s\n", sync_file, |
| 128 | sync_file_get_name(sync_file, buf, sizeof(buf)), |
Chris Wilson | d6c99f4 | 2017-01-04 14:12:21 +0000 | [diff] [blame] | 129 | sync_status_str(dma_fence_get_status(sync_file->fence))); |
Maarten Lankhorst | 0f0d840 | 2014-07-01 12:57:31 +0200 | [diff] [blame] | 130 | |
Chris Wilson | f54d186 | 2016-10-25 13:00:45 +0100 | [diff] [blame] | 131 | if (dma_fence_is_array(sync_file->fence)) { |
| 132 | struct dma_fence_array *array = to_dma_fence_array(sync_file->fence); |
Linus Torvalds | 6b25e21 | 2016-10-11 18:12:22 -0700 | [diff] [blame] | 133 | |
| 134 | for (i = 0; i < array->num_fences; ++i) |
| 135 | sync_print_fence(s, array->fences[i], true); |
| 136 | } else { |
| 137 | sync_print_fence(s, sync_file->fence, true); |
| 138 | } |
Gustavo Padovan | b55b54b | 2016-01-21 10:49:21 -0200 | [diff] [blame] | 139 | } |
| 140 | |
Yangtao Li | 2674305 | 2018-11-30 11:11:01 -0500 | [diff] [blame] | 141 | static int sync_info_debugfs_show(struct seq_file *s, void *unused) |
Maarten Lankhorst | 0f0d840 | 2014-07-01 12:57:31 +0200 | [diff] [blame] | 142 | { |
Maarten Lankhorst | 0f0d840 | 2014-07-01 12:57:31 +0200 | [diff] [blame] | 143 | struct list_head *pos; |
| 144 | |
| 145 | seq_puts(s, "objs:\n--------------\n"); |
| 146 | |
Chris Wilson | a6aa8fc | 2017-06-29 13:59:27 +0100 | [diff] [blame] | 147 | spin_lock_irq(&sync_timeline_list_lock); |
Maarten Lankhorst | 0f0d840 | 2014-07-01 12:57:31 +0200 | [diff] [blame] | 148 | list_for_each(pos, &sync_timeline_list_head) { |
| 149 | struct sync_timeline *obj = |
| 150 | container_of(pos, struct sync_timeline, |
| 151 | sync_timeline_list); |
| 152 | |
| 153 | sync_print_obj(s, obj); |
Markus Elfring | 47a369d | 2017-05-08 10:55:42 +0200 | [diff] [blame] | 154 | seq_putc(s, '\n'); |
Maarten Lankhorst | 0f0d840 | 2014-07-01 12:57:31 +0200 | [diff] [blame] | 155 | } |
Chris Wilson | a6aa8fc | 2017-06-29 13:59:27 +0100 | [diff] [blame] | 156 | spin_unlock_irq(&sync_timeline_list_lock); |
Maarten Lankhorst | 0f0d840 | 2014-07-01 12:57:31 +0200 | [diff] [blame] | 157 | |
| 158 | seq_puts(s, "fences:\n--------------\n"); |
| 159 | |
Chris Wilson | a6aa8fc | 2017-06-29 13:59:27 +0100 | [diff] [blame] | 160 | spin_lock_irq(&sync_file_list_lock); |
Gustavo Padovan | d7fdb0a | 2016-01-21 10:49:19 -0200 | [diff] [blame] | 161 | list_for_each(pos, &sync_file_list_head) { |
| 162 | struct sync_file *sync_file = |
| 163 | container_of(pos, struct sync_file, sync_file_list); |
Maarten Lankhorst | 0f0d840 | 2014-07-01 12:57:31 +0200 | [diff] [blame] | 164 | |
Gustavo Padovan | d7fdb0a | 2016-01-21 10:49:19 -0200 | [diff] [blame] | 165 | sync_print_sync_file(s, sync_file); |
Markus Elfring | 47a369d | 2017-05-08 10:55:42 +0200 | [diff] [blame] | 166 | seq_putc(s, '\n'); |
Maarten Lankhorst | 0f0d840 | 2014-07-01 12:57:31 +0200 | [diff] [blame] | 167 | } |
Chris Wilson | a6aa8fc | 2017-06-29 13:59:27 +0100 | [diff] [blame] | 168 | spin_unlock_irq(&sync_file_list_lock); |
Maarten Lankhorst | 0f0d840 | 2014-07-01 12:57:31 +0200 | [diff] [blame] | 169 | return 0; |
| 170 | } |
| 171 | |
Yangtao Li | 2674305 | 2018-11-30 11:11:01 -0500 | [diff] [blame] | 172 | DEFINE_SHOW_ATTRIBUTE(sync_info_debugfs); |
Maarten Lankhorst | 0f0d840 | 2014-07-01 12:57:31 +0200 | [diff] [blame] | 173 | |
| 174 | static __init int sync_debugfs_init(void) |
| 175 | { |
Gustavo Padovan | 8a00448 | 2016-01-21 10:49:17 -0200 | [diff] [blame] | 176 | dbgfs = debugfs_create_dir("sync", NULL); |
| 177 | |
Nicolai Stange | 0fd9da9 | 2016-05-27 20:03:54 +0200 | [diff] [blame] | 178 | /* |
| 179 | * The debugfs files won't ever get removed and thus, there is |
| 180 | * no need to protect it against removal races. The use of |
| 181 | * debugfs_create_file_unsafe() is actually safe here. |
| 182 | */ |
| 183 | debugfs_create_file_unsafe("info", 0444, dbgfs, NULL, |
| 184 | &sync_info_debugfs_fops); |
| 185 | debugfs_create_file_unsafe("sw_sync", 0644, dbgfs, NULL, |
| 186 | &sw_sync_debugfs_fops); |
Gustavo Padovan | 8a00448 | 2016-01-21 10:49:17 -0200 | [diff] [blame] | 187 | |
Maarten Lankhorst | 0f0d840 | 2014-07-01 12:57:31 +0200 | [diff] [blame] | 188 | return 0; |
| 189 | } |
| 190 | late_initcall(sync_debugfs_init); |