Skip to content

Commit 3a161d9

Browse files
committed
tracing: Create seq_buf layer in trace_seq
Create a seq_buf layer that trace_seq sits on. The seq_buf will not be limited to page size. This will allow other usages of seq_buf instead of a hard set PAGE_SIZE one that trace_seq has. Link: http://lkml.kernel.org/r/20141104160221.864997179@goodmis.org Link: http://lkml.kernel.org/r/20141114011412.170377300@goodmis.org Tested-by: Jiri Kosina <jkosina@suse.cz> Acked-by: Jiri Kosina <jkosina@suse.cz> Reviewed-by: Petr Mladek <pmladek@suse.cz> Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
1 parent 16a8ef2 commit 3a161d9

8 files changed

Lines changed: 538 additions & 126 deletions

File tree

‎include/linux/seq_buf.h‎

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#ifndef _LINUX_SEQ_BUF_H
2+
#define _LINUX_SEQ_BUF_H
3+
4+
#include <linux/fs.h>
5+
6+
/*
7+
* Trace sequences are used to allow a function to call several other functions
8+
* to create a string of data to use.
9+
*/
10+
11+
/**
12+
* seq_buf - seq buffer structure
13+
* @buffer: pointer to the buffer
14+
* @size: size of the buffer
15+
* @len: the amount of data inside the buffer
16+
* @readpos: The next position to read in the buffer.
17+
*/
18+
struct seq_buf {
19+
unsigned char *buffer;
20+
unsigned int size;
21+
unsigned int len;
22+
unsigned int readpos;
23+
};
24+
25+
static inline void
26+
seq_buf_init(struct seq_buf *s, unsigned char *buf, unsigned int size)
27+
{
28+
s->buffer = buf;
29+
s->size = size;
30+
s->len = 0;
31+
s->readpos = 0;
32+
}
33+
34+
/*
35+
* seq_buf have a buffer that might overflow. When this happens
36+
* the len and size are set to be equal.
37+
*/
38+
static inline bool
39+
seq_buf_has_overflowed(struct seq_buf *s)
40+
{
41+
return s->len == s->size;
42+
}
43+
44+
static inline void
45+
seq_buf_set_overflow(struct seq_buf *s)
46+
{
47+
s->len = s->size;
48+
}
49+
50+
/*
51+
* How much buffer is left on the seq_buf?
52+
*/
53+
static inline unsigned int
54+
seq_buf_buffer_left(struct seq_buf *s)
55+
{
56+
if (seq_buf_has_overflowed(s))
57+
return 0;
58+
59+
return (s->size - 1) - s->len;
60+
}
61+
62+
extern __printf(2, 3)
63+
int seq_buf_printf(struct seq_buf *s, const char *fmt, ...);
64+
extern __printf(2, 0)
65+
int seq_buf_vprintf(struct seq_buf *s, const char *fmt, va_list args);
66+
extern int
67+
seq_buf_bprintf(struct seq_buf *s, const char *fmt, const u32 *binary);
68+
extern int seq_buf_print_seq(struct seq_file *m, struct seq_buf *s);
69+
extern int seq_buf_to_user(struct seq_buf *s, char __user *ubuf,
70+
int cnt);
71+
extern int seq_buf_puts(struct seq_buf *s, const char *str);
72+
extern int seq_buf_putc(struct seq_buf *s, unsigned char c);
73+
extern int seq_buf_putmem(struct seq_buf *s, const void *mem, unsigned int len);
74+
extern int seq_buf_putmem_hex(struct seq_buf *s, const void *mem,
75+
unsigned int len);
76+
extern int seq_buf_path(struct seq_buf *s, const struct path *path);
77+
78+
extern int seq_buf_bitmask(struct seq_buf *s, const unsigned long *maskp,
79+
int nmaskbits);
80+
81+
#endif /* _LINUX_SEQ_BUF_H */

‎include/linux/trace_seq.h‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef _LINUX_TRACE_SEQ_H
22
#define _LINUX_TRACE_SEQ_H
33

4-
#include <linux/fs.h>
4+
#include <linux/seq_buf.h>
55

66
#include <asm/page.h>
77

@@ -12,16 +12,14 @@
1212

1313
struct trace_seq {
1414
unsigned char buffer[PAGE_SIZE];
15-
unsigned int len;
16-
unsigned int readpos;
15+
struct seq_buf seq;
1716
int full;
1817
};
1918

2019
static inline void
2120
trace_seq_init(struct trace_seq *s)
2221
{
23-
s->len = 0;
24-
s->readpos = 0;
22+
seq_buf_init(&s->seq, s->buffer, PAGE_SIZE);
2523
s->full = 0;
2624
}
2725

@@ -37,7 +35,7 @@ trace_seq_init(struct trace_seq *s)
3735
static inline unsigned char *
3836
trace_seq_buffer_ptr(struct trace_seq *s)
3937
{
40-
return s->buffer + s->len;
38+
return s->buffer + s->seq.len;
4139
}
4240

4341
/**
@@ -49,7 +47,7 @@ trace_seq_buffer_ptr(struct trace_seq *s)
4947
*/
5048
static inline bool trace_seq_has_overflowed(struct trace_seq *s)
5149
{
52-
return s->full || s->len > PAGE_SIZE - 1;
50+
return s->full || seq_buf_has_overflowed(&s->seq);
5351
}
5452

5553
/*

‎kernel/trace/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ obj-$(CONFIG_RING_BUFFER_BENCHMARK) += ring_buffer_benchmark.o
2929
obj-$(CONFIG_TRACING) += trace.o
3030
obj-$(CONFIG_TRACING) += trace_output.o
3131
obj-$(CONFIG_TRACING) += trace_seq.o
32+
obj-$(CONFIG_TRACING) += seq_buf.o
3233
obj-$(CONFIG_TRACING) += trace_stat.o
3334
obj-$(CONFIG_TRACING) += trace_printk.o
3435
obj-$(CONFIG_CONTEXT_SWITCH_TRACER) += trace_sched_switch.o

0 commit comments

Comments
 (0)