blob: cfaf5a1d4bad77cac2f76b41c9bc0fe4f7746ff2 [file] [log] [blame]
Steven Rostedt95045042009-04-11 12:59:57 -04001#ifndef _LINUX_TRACE_SEQ_H
2#define _LINUX_TRACE_SEQ_H
3
Steven Rostedt (Red Hat)3a161d92014-06-25 15:54:42 -04004#include <linux/seq_buf.h>
Steven Rostedt6d723732009-04-10 14:53:50 -04005
Wu Zhangjin78be6912009-06-14 14:52:30 +08006#include <asm/page.h>
7
Steven Rostedt95045042009-04-11 12:59:57 -04008/*
9 * Trace sequences are used to allow a function to call several other functions
Jiri Olsa6d3f1e12009-10-23 19:36:19 -040010 * to create a string of data to use (up to a max of PAGE_SIZE).
Steven Rostedt95045042009-04-11 12:59:57 -040011 */
12
13struct trace_seq {
14 unsigned char buffer[PAGE_SIZE];
Steven Rostedt (Red Hat)3a161d92014-06-25 15:54:42 -040015 struct seq_buf seq;
Johannes Bergd184b312009-11-25 16:10:14 +010016 int full;
Steven Rostedt95045042009-04-11 12:59:57 -040017};
18
19static inline void
20trace_seq_init(struct trace_seq *s)
21{
Steven Rostedt (Red Hat)3a161d92014-06-25 15:54:42 -040022 seq_buf_init(&s->seq, s->buffer, PAGE_SIZE);
Johannes Bergd184b312009-11-25 16:10:14 +010023 s->full = 0;
Steven Rostedt95045042009-04-11 12:59:57 -040024}
25
Steven Rostedt (Red Hat)7b039cb2014-06-26 09:42:41 -040026/**
Steven Rostedt (Red Hat)5ac483782014-11-14 15:49:41 -050027 * trace_seq_used - amount of actual data written to buffer
28 * @s: trace sequence descriptor
29 *
30 * Returns the amount of data written to the buffer.
31 *
32 * IMPORTANT!
33 *
34 * Use this instead of @s->seq.len if you need to pass the amount
35 * of data from the buffer to another buffer (userspace, or what not).
36 * The @s->seq.len on overflow is bigger than the buffer size and
37 * using it can cause access to undefined memory.
38 */
39static inline int trace_seq_used(struct trace_seq *s)
40{
41 return seq_buf_used(&s->seq);
42}
43
44/**
Steven Rostedt (Red Hat)7b039cb2014-06-26 09:42:41 -040045 * trace_seq_buffer_ptr - return pointer to next location in buffer
46 * @s: trace sequence descriptor
47 *
48 * Returns the pointer to the buffer where the next write to
49 * the buffer will happen. This is useful to save the location
50 * that is about to be written to and then return the result
51 * of that write.
52 */
53static inline unsigned char *
54trace_seq_buffer_ptr(struct trace_seq *s)
55{
Steven Rostedt (Red Hat)5ac483782014-11-14 15:49:41 -050056 return s->buffer + seq_buf_used(&s->seq);
Steven Rostedt (Red Hat)7b039cb2014-06-26 09:42:41 -040057}
58
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -050059/**
60 * trace_seq_has_overflowed - return true if the trace_seq took too much
61 * @s: trace sequence descriptor
62 *
63 * Returns true if too much data was added to the trace_seq and it is
64 * now full and will not take anymore.
65 */
66static inline bool trace_seq_has_overflowed(struct trace_seq *s)
67{
Steven Rostedt (Red Hat)3a161d92014-06-25 15:54:42 -040068 return s->full || seq_buf_has_overflowed(&s->seq);
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -050069}
70
Steven Rostedt95045042009-04-11 12:59:57 -040071/*
72 * Currently only defined when tracing is enabled.
73 */
74#ifdef CONFIG_TRACING
Joe Perchesb9075fa2011-10-31 17:11:33 -070075extern __printf(2, 3)
Steven Rostedt (Red Hat)dba39442014-11-12 18:07:22 -050076void trace_seq_printf(struct trace_seq *s, const char *fmt, ...);
Joe Perchesb9075fa2011-10-31 17:11:33 -070077extern __printf(2, 0)
Steven Rostedt (Red Hat)dba39442014-11-12 18:07:22 -050078void trace_seq_vprintf(struct trace_seq *s, const char *fmt, va_list args);
79extern void
Steven Rostedt95045042009-04-11 12:59:57 -040080trace_seq_bprintf(struct trace_seq *s, const char *fmt, const u32 *binary);
Steven Rostedta63ce5b2009-12-07 09:11:39 -050081extern int trace_print_seq(struct seq_file *m, struct trace_seq *s);
Steven Rostedt (Red Hat)36aabff2014-06-20 17:38:01 -040082extern int trace_seq_to_user(struct trace_seq *s, char __user *ubuf,
83 int cnt);
Steven Rostedt (Red Hat)dba39442014-11-12 18:07:22 -050084extern void trace_seq_puts(struct trace_seq *s, const char *str);
85extern void trace_seq_putc(struct trace_seq *s, unsigned char c);
86extern void trace_seq_putmem(struct trace_seq *s, const void *mem, unsigned int len);
87extern void trace_seq_putmem_hex(struct trace_seq *s, const void *mem,
Steven Rostedt (Red Hat)36aabff2014-06-20 17:38:01 -040088 unsigned int len);
Al Viro38eff282012-03-14 21:51:10 -040089extern int trace_seq_path(struct trace_seq *s, const struct path *path);
Steven Rostedt95045042009-04-11 12:59:57 -040090
Steven Rostedt (Red Hat)dba39442014-11-12 18:07:22 -050091extern void trace_seq_bitmask(struct trace_seq *s, const unsigned long *maskp,
Steven Rostedt (Red Hat)4449bf92014-05-06 13:10:24 -040092 int nmaskbits);
93
Steven Rostedt95045042009-04-11 12:59:57 -040094#else /* CONFIG_TRACING */
Steven Rostedt (Red Hat)dba39442014-11-12 18:07:22 -050095static inline void trace_seq_printf(struct trace_seq *s, const char *fmt, ...)
Steven Rostedt95045042009-04-11 12:59:57 -040096{
Steven Rostedt95045042009-04-11 12:59:57 -040097}
Steven Rostedt (Red Hat)dba39442014-11-12 18:07:22 -050098static inline void
Steven Rostedt95045042009-04-11 12:59:57 -040099trace_seq_bprintf(struct trace_seq *s, const char *fmt, const u32 *binary)
100{
Steven Rostedt95045042009-04-11 12:59:57 -0400101}
102
Steven Rostedt (Red Hat)dba39442014-11-12 18:07:22 -0500103static inline void
Steven Rostedt (Red Hat)4449bf92014-05-06 13:10:24 -0400104trace_seq_bitmask(struct trace_seq *s, const unsigned long *maskp,
105 int nmaskbits)
106{
Steven Rostedt (Red Hat)4449bf92014-05-06 13:10:24 -0400107}
108
Steven Rostedta63ce5b2009-12-07 09:11:39 -0500109static inline int trace_print_seq(struct seq_file *m, struct trace_seq *s)
Steven Rostedt95045042009-04-11 12:59:57 -0400110{
Steven Rostedta63ce5b2009-12-07 09:11:39 -0500111 return 0;
Steven Rostedt95045042009-04-11 12:59:57 -0400112}
Steven Rostedt (Red Hat)36aabff2014-06-20 17:38:01 -0400113static inline int trace_seq_to_user(struct trace_seq *s, char __user *ubuf,
114 int cnt)
Steven Rostedt95045042009-04-11 12:59:57 -0400115{
116 return 0;
117}
Steven Rostedt (Red Hat)dba39442014-11-12 18:07:22 -0500118static inline void trace_seq_puts(struct trace_seq *s, const char *str)
Steven Rostedt95045042009-04-11 12:59:57 -0400119{
Steven Rostedt95045042009-04-11 12:59:57 -0400120}
Steven Rostedt (Red Hat)dba39442014-11-12 18:07:22 -0500121static inline void trace_seq_putc(struct trace_seq *s, unsigned char c)
Steven Rostedt95045042009-04-11 12:59:57 -0400122{
Steven Rostedt95045042009-04-11 12:59:57 -0400123}
Steven Rostedt (Red Hat)dba39442014-11-12 18:07:22 -0500124static inline void
Steven Rostedt (Red Hat)36aabff2014-06-20 17:38:01 -0400125trace_seq_putmem(struct trace_seq *s, const void *mem, unsigned int len)
Steven Rostedt95045042009-04-11 12:59:57 -0400126{
Steven Rostedt95045042009-04-11 12:59:57 -0400127}
Steven Rostedt (Red Hat)dba39442014-11-12 18:07:22 -0500128static inline void trace_seq_putmem_hex(struct trace_seq *s, const void *mem,
Steven Rostedt (Red Hat)36aabff2014-06-20 17:38:01 -0400129 unsigned int len)
Steven Rostedt95045042009-04-11 12:59:57 -0400130{
Steven Rostedt95045042009-04-11 12:59:57 -0400131}
Al Viro38eff282012-03-14 21:51:10 -0400132static inline int trace_seq_path(struct trace_seq *s, const struct path *path)
Steven Rostedt95045042009-04-11 12:59:57 -0400133{
134 return 0;
135}
136#endif /* CONFIG_TRACING */
137
138#endif /* _LINUX_TRACE_SEQ_H */