blob: 07eda413dfcf750ea5971c89d241de446f31baed [file] [log] [blame]
Steven Rostedt95045042009-04-11 12:59:57 -04001#ifndef _LINUX_TRACE_SEQ_H
2#define _LINUX_TRACE_SEQ_H
3
Steven Rostedt6d723732009-04-10 14:53:50 -04004#include <linux/fs.h>
5
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];
15 unsigned int len;
16 unsigned int readpos;
Johannes Bergd184b312009-11-25 16:10:14 +010017 int full;
Steven Rostedt95045042009-04-11 12:59:57 -040018};
19
20static inline void
21trace_seq_init(struct trace_seq *s)
22{
23 s->len = 0;
24 s->readpos = 0;
Johannes Bergd184b312009-11-25 16:10:14 +010025 s->full = 0;
Steven Rostedt95045042009-04-11 12:59:57 -040026}
27
Steven Rostedt (Red Hat)7b039cb2014-06-26 09:42:41 -040028/**
29 * trace_seq_buffer_ptr - return pointer to next location in buffer
30 * @s: trace sequence descriptor
31 *
32 * Returns the pointer to the buffer where the next write to
33 * the buffer will happen. This is useful to save the location
34 * that is about to be written to and then return the result
35 * of that write.
36 */
37static inline unsigned char *
38trace_seq_buffer_ptr(struct trace_seq *s)
39{
40 return s->buffer + s->len;
41}
42
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -050043/**
44 * trace_seq_has_overflowed - return true if the trace_seq took too much
45 * @s: trace sequence descriptor
46 *
47 * Returns true if too much data was added to the trace_seq and it is
48 * now full and will not take anymore.
49 */
50static inline bool trace_seq_has_overflowed(struct trace_seq *s)
51{
52 return s->full || s->len > PAGE_SIZE - 1;
53}
54
Steven Rostedt95045042009-04-11 12:59:57 -040055/*
56 * Currently only defined when tracing is enabled.
57 */
58#ifdef CONFIG_TRACING
Joe Perchesb9075fa2011-10-31 17:11:33 -070059extern __printf(2, 3)
60int trace_seq_printf(struct trace_seq *s, const char *fmt, ...);
61extern __printf(2, 0)
62int trace_seq_vprintf(struct trace_seq *s, const char *fmt, va_list args);
Steven Rostedt95045042009-04-11 12:59:57 -040063extern int
64trace_seq_bprintf(struct trace_seq *s, const char *fmt, const u32 *binary);
Steven Rostedta63ce5b2009-12-07 09:11:39 -050065extern int trace_print_seq(struct seq_file *m, struct trace_seq *s);
Steven Rostedt (Red Hat)36aabff2014-06-20 17:38:01 -040066extern int trace_seq_to_user(struct trace_seq *s, char __user *ubuf,
67 int cnt);
Steven Rostedt95045042009-04-11 12:59:57 -040068extern int trace_seq_puts(struct trace_seq *s, const char *str);
69extern int trace_seq_putc(struct trace_seq *s, unsigned char c);
Steven Rostedt (Red Hat)36aabff2014-06-20 17:38:01 -040070extern int trace_seq_putmem(struct trace_seq *s, const void *mem, unsigned int len);
Steven Rostedt95045042009-04-11 12:59:57 -040071extern int trace_seq_putmem_hex(struct trace_seq *s, const void *mem,
Steven Rostedt (Red Hat)36aabff2014-06-20 17:38:01 -040072 unsigned int len);
Al Viro38eff282012-03-14 21:51:10 -040073extern int trace_seq_path(struct trace_seq *s, const struct path *path);
Steven Rostedt95045042009-04-11 12:59:57 -040074
Steven Rostedt (Red Hat)4449bf92014-05-06 13:10:24 -040075extern int trace_seq_bitmask(struct trace_seq *s, const unsigned long *maskp,
76 int nmaskbits);
77
Steven Rostedt95045042009-04-11 12:59:57 -040078#else /* CONFIG_TRACING */
79static inline int trace_seq_printf(struct trace_seq *s, const char *fmt, ...)
Steven Rostedt95045042009-04-11 12:59:57 -040080{
81 return 0;
82}
83static inline int
84trace_seq_bprintf(struct trace_seq *s, const char *fmt, const u32 *binary)
85{
86 return 0;
87}
88
Steven Rostedt (Red Hat)4449bf92014-05-06 13:10:24 -040089static inline int
90trace_seq_bitmask(struct trace_seq *s, const unsigned long *maskp,
91 int nmaskbits)
92{
93 return 0;
94}
95
Steven Rostedta63ce5b2009-12-07 09:11:39 -050096static inline int trace_print_seq(struct seq_file *m, struct trace_seq *s)
Steven Rostedt95045042009-04-11 12:59:57 -040097{
Steven Rostedta63ce5b2009-12-07 09:11:39 -050098 return 0;
Steven Rostedt95045042009-04-11 12:59:57 -040099}
Steven Rostedt (Red Hat)36aabff2014-06-20 17:38:01 -0400100static inline int trace_seq_to_user(struct trace_seq *s, char __user *ubuf,
101 int cnt)
Steven Rostedt95045042009-04-11 12:59:57 -0400102{
103 return 0;
104}
105static inline int trace_seq_puts(struct trace_seq *s, const char *str)
106{
107 return 0;
108}
Steven Rostedt23de29d2009-04-20 12:59:29 -0400109static inline int trace_seq_putc(struct trace_seq *s, unsigned char c)
Steven Rostedt95045042009-04-11 12:59:57 -0400110{
111 return 0;
112}
113static inline int
Steven Rostedt (Red Hat)36aabff2014-06-20 17:38:01 -0400114trace_seq_putmem(struct trace_seq *s, const void *mem, unsigned int len)
Steven Rostedt95045042009-04-11 12:59:57 -0400115{
116 return 0;
117}
118static inline int trace_seq_putmem_hex(struct trace_seq *s, const void *mem,
Steven Rostedt (Red Hat)36aabff2014-06-20 17:38:01 -0400119 unsigned int len)
Steven Rostedt95045042009-04-11 12:59:57 -0400120{
121 return 0;
122}
Al Viro38eff282012-03-14 21:51:10 -0400123static inline int trace_seq_path(struct trace_seq *s, const struct path *path)
Steven Rostedt95045042009-04-11 12:59:57 -0400124{
125 return 0;
126}
127#endif /* CONFIG_TRACING */
128
129#endif /* _LINUX_TRACE_SEQ_H */