1 /* arch/arm/mach-msm/qdsp5/evlog.h
3 * simple event log debugging facility
5 * Copyright (C) 2008 Google, Inc.
7 * This software is licensed under the terms of the GNU General Public
8 * License version 2, as published by the Free Software Foundation, and
9 * may be copied, distributed, and modified under those terms.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
19 #include <linux/hrtimer.h>
20 #include <linux/debugfs.h>
22 #define EV_LOG_ENTRY_NAME(n) n##_entry
24 #define DECLARE_LOG(_name, _size, _str) \
25 static struct ev_entry EV_LOG_ENTRY_NAME(_name)[_size]; \
26 static struct ev_log _name = { \
29 .num_strings = ARRAY_SIZE(_str), \
30 .entry = EV_LOG_ENTRY_NAME(_name), \
31 .max = ARRAY_SIZE(EV_LOG_ENTRY_NAME(_name)), \
41 struct ev_entry
*entry
;
50 static char ev_buf
[4096];
52 static ssize_t
ev_log_read(struct file
*file
, char __user
*buf
,
53 size_t count
, loff_t
*ppos
)
55 struct ev_log
*log
= file
->private_data
;
56 struct ev_entry
*entry
;
64 local_irq_save(flags
);
65 n
= (log
->next
- 1) & (max
- 1);
67 while (n
!= log
->next
) {
68 t
= ktime_sub(now
, entry
[n
].when
);
72 if (id
< log
->num_strings
)
73 str
= log
->strings
[id
];
76 size
+= scnprintf(ev_buf
+ size
, 4096 - size
,
78 t
.tv
.sec
, t
.tv
.nsec
/ 1000000,
81 n
= (n
- 1) & (max
- 1);
84 local_irq_restore(flags
);
85 return simple_read_from_buffer(buf
, count
, ppos
, ev_buf
, size
);
88 static void ev_log_write(struct ev_log
*log
, unsigned id
, unsigned arg
)
90 struct ev_entry
*entry
;
92 local_irq_save(flags
);
100 entry
= log
->entry
+ log
->next
;
101 entry
->when
= ktime_get();
104 log
->next
= (log
->next
+ 1) & (log
->max
- 1);
106 local_irq_restore(flags
);
109 static void ev_log_freeze(struct ev_log
*log
, unsigned count
)
112 local_irq_save(flags
);
114 local_irq_restore(flags
);
117 static int ev_log_open(struct inode
*inode
, struct file
*file
)
119 file
->private_data
= inode
->i_private
;
123 static const struct file_operations ev_log_ops
= {
128 static int ev_log_init(struct ev_log
*log
)
130 debugfs_create_file(log
->name
, 0444, 0, log
, &ev_log_ops
);