blob: b76022623d8ab0b3c42f61877f99b26b6c816f67 [file] [log] [blame]
Maarten Lankhorst0f0d8402014-07-01 12:57:31 +02001/*
2 * drivers/base/sync.c
3 *
4 * Copyright (C) 2012 Google, Inc.
5 *
6 * This software is licensed under the terms of the GNU General Public
7 * License version 2, as published by the Free Software Foundation, and
8 * may be copied, distributed, and modified under those terms.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 */
16
17#include <linux/debugfs.h>
Gustavo Padovan1fe82e22016-05-31 16:59:12 -030018#include "sync_debug.h"
Maarten Lankhorst0f0d8402014-07-01 12:57:31 +020019
20#ifdef CONFIG_DEBUG_FS
21
Gustavo Padovan8a004482016-01-21 10:49:17 -020022static struct dentry *dbgfs;
23
Maarten Lankhorst0f0d8402014-07-01 12:57:31 +020024static LIST_HEAD(sync_timeline_list_head);
25static DEFINE_SPINLOCK(sync_timeline_list_lock);
Gustavo Padovand7fdb0a2016-01-21 10:49:19 -020026static LIST_HEAD(sync_file_list_head);
27static DEFINE_SPINLOCK(sync_file_list_lock);
Maarten Lankhorst0f0d8402014-07-01 12:57:31 +020028
29void sync_timeline_debug_add(struct sync_timeline *obj)
30{
31 unsigned long flags;
32
33 spin_lock_irqsave(&sync_timeline_list_lock, flags);
34 list_add_tail(&obj->sync_timeline_list, &sync_timeline_list_head);
35 spin_unlock_irqrestore(&sync_timeline_list_lock, flags);
36}
37
38void sync_timeline_debug_remove(struct sync_timeline *obj)
39{
40 unsigned long flags;
41
42 spin_lock_irqsave(&sync_timeline_list_lock, flags);
43 list_del(&obj->sync_timeline_list);
44 spin_unlock_irqrestore(&sync_timeline_list_lock, flags);
45}
46
Gustavo Padovand7fdb0a2016-01-21 10:49:19 -020047void sync_file_debug_add(struct sync_file *sync_file)
Maarten Lankhorst0f0d8402014-07-01 12:57:31 +020048{
49 unsigned long flags;
50
Gustavo Padovand7fdb0a2016-01-21 10:49:19 -020051 spin_lock_irqsave(&sync_file_list_lock, flags);
52 list_add_tail(&sync_file->sync_file_list, &sync_file_list_head);
53 spin_unlock_irqrestore(&sync_file_list_lock, flags);
Maarten Lankhorst0f0d8402014-07-01 12:57:31 +020054}
55
Gustavo Padovand7fdb0a2016-01-21 10:49:19 -020056void sync_file_debug_remove(struct sync_file *sync_file)
Maarten Lankhorst0f0d8402014-07-01 12:57:31 +020057{
58 unsigned long flags;
59
Gustavo Padovand7fdb0a2016-01-21 10:49:19 -020060 spin_lock_irqsave(&sync_file_list_lock, flags);
61 list_del(&sync_file->sync_file_list);
62 spin_unlock_irqrestore(&sync_file_list_lock, flags);
Maarten Lankhorst0f0d8402014-07-01 12:57:31 +020063}
64
65static const char *sync_status_str(int status)
66{
67 if (status == 0)
68 return "signaled";
Peter Senna Tschudin95451352014-07-12 21:55:56 +020069
70 if (status > 0)
Maarten Lankhorst0f0d8402014-07-01 12:57:31 +020071 return "active";
Peter Senna Tschudin95451352014-07-12 21:55:56 +020072
73 return "error";
Maarten Lankhorst0f0d8402014-07-01 12:57:31 +020074}
75
Gustavo Padovanb55b54b2016-01-21 10:49:21 -020076static void sync_print_fence(struct seq_file *s, struct fence *fence, bool show)
Maarten Lankhorst0f0d8402014-07-01 12:57:31 +020077{
78 int status = 1;
Gustavo Padovanb55b54b2016-01-21 10:49:21 -020079 struct sync_timeline *parent = fence_parent(fence);
Maarten Lankhorst0f0d8402014-07-01 12:57:31 +020080
Gustavo Padovanb55b54b2016-01-21 10:49:21 -020081 if (fence_is_signaled_locked(fence))
82 status = fence->status;
Maarten Lankhorst0f0d8402014-07-01 12:57:31 +020083
Gustavo Padovanb55b54b2016-01-21 10:49:21 -020084 seq_printf(s, " %s%sfence %s",
85 show ? parent->name : "",
86 show ? "_" : "",
Maarten Lankhorst0f0d8402014-07-01 12:57:31 +020087 sync_status_str(status));
88
89 if (status <= 0) {
Steve Pennington0541cdf2014-12-24 09:33:02 -060090 struct timespec64 ts64 =
Gustavo Padovanb55b54b2016-01-21 10:49:21 -020091 ktime_to_timespec64(fence->timestamp);
Peter Senna Tschudin95451352014-07-12 21:55:56 +020092
Tapasweni Pathak353fdf12014-10-26 19:20:16 +053093 seq_printf(s, "@%lld.%09ld", (s64)ts64.tv_sec, ts64.tv_nsec);
Maarten Lankhorst0f0d8402014-07-01 12:57:31 +020094 }
95
Gustavo Padovan724812d2016-05-31 16:59:02 -030096 if (fence->ops->timeline_value_str &&
Gustavo Padovanb55b54b2016-01-21 10:49:21 -020097 fence->ops->fence_value_str) {
Maarten Lankhorst0f0d8402014-07-01 12:57:31 +020098 char value[64];
Maarten Lankhorst73465f12015-12-11 13:11:49 +000099 bool success;
Peter Senna Tschudin95451352014-07-12 21:55:56 +0200100
Gustavo Padovanb55b54b2016-01-21 10:49:21 -0200101 fence->ops->fence_value_str(fence, value, sizeof(value));
Maarten Lankhorst73465f12015-12-11 13:11:49 +0000102 success = strlen(value);
103
Gustavo Padovan724812d2016-05-31 16:59:02 -0300104 if (success) {
Maarten Lankhorst73465f12015-12-11 13:11:49 +0000105 seq_printf(s, ": %s", value);
106
Gustavo Padovanb55b54b2016-01-21 10:49:21 -0200107 fence->ops->timeline_value_str(fence, value,
108 sizeof(value));
Maarten Lankhorst73465f12015-12-11 13:11:49 +0000109
110 if (strlen(value))
111 seq_printf(s, " / %s", value);
Maarten Lankhorst0f0d8402014-07-01 12:57:31 +0200112 }
113 }
114
115 seq_puts(s, "\n");
116}
117
118static void sync_print_obj(struct seq_file *s, struct sync_timeline *obj)
119{
120 struct list_head *pos;
121 unsigned long flags;
122
Gustavo Padovanb9bc2b72016-05-31 16:59:11 -0300123 seq_printf(s, "%s: %d\n", obj->name, obj->value);
Maarten Lankhorst0f0d8402014-07-01 12:57:31 +0200124
125 spin_lock_irqsave(&obj->child_list_lock, flags);
126 list_for_each(pos, &obj->child_list_head) {
Gustavo Padovan0431b902016-05-31 16:59:04 -0300127 struct sync_pt *pt =
128 container_of(pos, struct sync_pt, child_list);
129 sync_print_fence(s, &pt->base, false);
Maarten Lankhorst0f0d8402014-07-01 12:57:31 +0200130 }
131 spin_unlock_irqrestore(&obj->child_list_lock, flags);
132}
133
Gustavo Padovand7fdb0a2016-01-21 10:49:19 -0200134static void sync_print_sync_file(struct seq_file *s,
135 struct sync_file *sync_file)
Gustavo Padovanb55b54b2016-01-21 10:49:21 -0200136{
Maarten Lankhorst0f0d8402014-07-01 12:57:31 +0200137 int i;
138
Gustavo Padovand7fdb0a2016-01-21 10:49:19 -0200139 seq_printf(s, "[%p] %s: %s\n", sync_file, sync_file->name,
140 sync_status_str(atomic_read(&sync_file->status)));
Maarten Lankhorst0f0d8402014-07-01 12:57:31 +0200141
Gustavo Padovand7fdb0a2016-01-21 10:49:19 -0200142 for (i = 0; i < sync_file->num_fences; ++i)
Gustavo Padovanb55b54b2016-01-21 10:49:21 -0200143 sync_print_fence(s, sync_file->cbs[i].fence, true);
144}
145
Maarten Lankhorst0f0d8402014-07-01 12:57:31 +0200146static int sync_debugfs_show(struct seq_file *s, void *unused)
147{
148 unsigned long flags;
149 struct list_head *pos;
150
151 seq_puts(s, "objs:\n--------------\n");
152
153 spin_lock_irqsave(&sync_timeline_list_lock, flags);
154 list_for_each(pos, &sync_timeline_list_head) {
155 struct sync_timeline *obj =
156 container_of(pos, struct sync_timeline,
157 sync_timeline_list);
158
159 sync_print_obj(s, obj);
160 seq_puts(s, "\n");
161 }
162 spin_unlock_irqrestore(&sync_timeline_list_lock, flags);
163
164 seq_puts(s, "fences:\n--------------\n");
165
Gustavo Padovand7fdb0a2016-01-21 10:49:19 -0200166 spin_lock_irqsave(&sync_file_list_lock, flags);
167 list_for_each(pos, &sync_file_list_head) {
168 struct sync_file *sync_file =
169 container_of(pos, struct sync_file, sync_file_list);
Maarten Lankhorst0f0d8402014-07-01 12:57:31 +0200170
Gustavo Padovand7fdb0a2016-01-21 10:49:19 -0200171 sync_print_sync_file(s, sync_file);
Maarten Lankhorst0f0d8402014-07-01 12:57:31 +0200172 seq_puts(s, "\n");
173 }
Gustavo Padovand7fdb0a2016-01-21 10:49:19 -0200174 spin_unlock_irqrestore(&sync_file_list_lock, flags);
Maarten Lankhorst0f0d8402014-07-01 12:57:31 +0200175 return 0;
176}
177
Gustavo Padovan8a004482016-01-21 10:49:17 -0200178static int sync_info_debugfs_open(struct inode *inode, struct file *file)
Maarten Lankhorst0f0d8402014-07-01 12:57:31 +0200179{
180 return single_open(file, sync_debugfs_show, inode->i_private);
181}
182
Gustavo Padovan8a004482016-01-21 10:49:17 -0200183static const struct file_operations sync_info_debugfs_fops = {
184 .open = sync_info_debugfs_open,
Maarten Lankhorst0f0d8402014-07-01 12:57:31 +0200185 .read = seq_read,
186 .llseek = seq_lseek,
187 .release = single_release,
188};
189
190static __init int sync_debugfs_init(void)
191{
Gustavo Padovan8a004482016-01-21 10:49:17 -0200192 dbgfs = debugfs_create_dir("sync", NULL);
193
194 debugfs_create_file("info", 0444, dbgfs, NULL, &sync_info_debugfs_fops);
Gustavo Padovand21858f2016-05-31 16:59:00 -0300195
Gustavo Padovana44eb742016-01-21 10:49:18 -0200196 debugfs_create_file("sw_sync", 0644, dbgfs, NULL,
197 &sw_sync_debugfs_fops);
Gustavo Padovan8a004482016-01-21 10:49:17 -0200198
Maarten Lankhorst0f0d8402014-07-01 12:57:31 +0200199 return 0;
200}
201late_initcall(sync_debugfs_init);
202
203#define DUMP_CHUNK 256
204static char sync_dump_buf[64 * 1024];
205void sync_dump(void)
206{
207 struct seq_file s = {
208 .buf = sync_dump_buf,
209 .size = sizeof(sync_dump_buf) - 1,
210 };
211 int i;
212
213 sync_debugfs_show(&s, NULL);
214
215 for (i = 0; i < s.count; i += DUMP_CHUNK) {
216 if ((s.count - i) > DUMP_CHUNK) {
217 char c = s.buf[i + DUMP_CHUNK];
Peter Senna Tschudin95451352014-07-12 21:55:56 +0200218
Maarten Lankhorst0f0d8402014-07-01 12:57:31 +0200219 s.buf[i + DUMP_CHUNK] = 0;
220 pr_cont("%s", s.buf + i);
221 s.buf[i + DUMP_CHUNK] = c;
222 } else {
223 s.buf[s.count] = 0;
224 pr_cont("%s", s.buf + i);
225 }
226 }
227}
228
229#endif