diff options
| author | Linus Torvalds <torvalds@linux-foundation.org> | 2008-11-18 11:06:35 -0500 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-11-18 11:06:35 -0500 |
| commit | 72b51a6b4d803381f16d819df392dd1efd1c7181 (patch) | |
| tree | 7e27a03c10cb2f5e6593dd599b3c8b0bcd0f9ee9 /kernel/trace/ring_buffer.c | |
| parent | 8c60bfb0666952728b3be73ef9bc133d686aebba (diff) | |
| parent | e270219f4372b58bd3eeac12bd9f7edc592b8f6b (diff) | |
Merge branch 'tracing-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip
* 'tracing-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip:
kernel/profile.c: fix section mismatch warning
function tracing: fix wrong pos computing when read buffer has been fulfilled
tracing: fix mmiotrace resizing crash
ring-buffer: no preempt for sched_clock()
ring-buffer: buffer record on/off switch
Diffstat (limited to 'kernel/trace/ring_buffer.c')
| -rw-r--r-- | kernel/trace/ring_buffer.c | 115 |
1 files changed, 114 insertions, 1 deletions
diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c index 2f76193c3489..036456cbb4f7 100644 --- a/kernel/trace/ring_buffer.c +++ b/kernel/trace/ring_buffer.c | |||
| @@ -16,14 +16,49 @@ | |||
| 16 | #include <linux/list.h> | 16 | #include <linux/list.h> |
| 17 | #include <linux/fs.h> | 17 | #include <linux/fs.h> |
| 18 | 18 | ||
| 19 | #include "trace.h" | ||
| 20 | |||
| 21 | /* Global flag to disable all recording to ring buffers */ | ||
| 22 | static int ring_buffers_off __read_mostly; | ||
| 23 | |||
| 24 | /** | ||
| 25 | * tracing_on - enable all tracing buffers | ||
| 26 | * | ||
| 27 | * This function enables all tracing buffers that may have been | ||
| 28 | * disabled with tracing_off. | ||
| 29 | */ | ||
| 30 | void tracing_on(void) | ||
| 31 | { | ||
| 32 | ring_buffers_off = 0; | ||
| 33 | } | ||
| 34 | |||
| 35 | /** | ||
| 36 | * tracing_off - turn off all tracing buffers | ||
| 37 | * | ||
| 38 | * This function stops all tracing buffers from recording data. | ||
| 39 | * It does not disable any overhead the tracers themselves may | ||
| 40 | * be causing. This function simply causes all recording to | ||
| 41 | * the ring buffers to fail. | ||
| 42 | */ | ||
| 43 | void tracing_off(void) | ||
| 44 | { | ||
| 45 | ring_buffers_off = 1; | ||
| 46 | } | ||
| 47 | |||
| 19 | /* Up this if you want to test the TIME_EXTENTS and normalization */ | 48 | /* Up this if you want to test the TIME_EXTENTS and normalization */ |
| 20 | #define DEBUG_SHIFT 0 | 49 | #define DEBUG_SHIFT 0 |
| 21 | 50 | ||
| 22 | /* FIXME!!! */ | 51 | /* FIXME!!! */ |
| 23 | u64 ring_buffer_time_stamp(int cpu) | 52 | u64 ring_buffer_time_stamp(int cpu) |
| 24 | { | 53 | { |
| 54 | u64 time; | ||
| 55 | |||
| 56 | preempt_disable_notrace(); | ||
| 25 | /* shift to debug/test normalization and TIME_EXTENTS */ | 57 | /* shift to debug/test normalization and TIME_EXTENTS */ |
| 26 | return sched_clock() << DEBUG_SHIFT; | 58 | time = sched_clock() << DEBUG_SHIFT; |
| 59 | preempt_enable_notrace(); | ||
| 60 | |||
| 61 | return time; | ||
| 27 | } | 62 | } |
| 28 | 63 | ||
| 29 | void ring_buffer_normalize_time_stamp(int cpu, u64 *ts) | 64 | void ring_buffer_normalize_time_stamp(int cpu, u64 *ts) |
| @@ -503,6 +538,12 @@ int ring_buffer_resize(struct ring_buffer *buffer, unsigned long size) | |||
| 503 | LIST_HEAD(pages); | 538 | LIST_HEAD(pages); |
| 504 | int i, cpu; | 539 | int i, cpu; |
| 505 | 540 | ||
| 541 | /* | ||
| 542 | * Always succeed at resizing a non-existent buffer: | ||
| 543 | */ | ||
| 544 | if (!buffer) | ||
| 545 | return size; | ||
| 546 | |||
| 506 | size = DIV_ROUND_UP(size, BUF_PAGE_SIZE); | 547 | size = DIV_ROUND_UP(size, BUF_PAGE_SIZE); |
| 507 | size *= BUF_PAGE_SIZE; | 548 | size *= BUF_PAGE_SIZE; |
| 508 | buffer_size = buffer->pages * BUF_PAGE_SIZE; | 549 | buffer_size = buffer->pages * BUF_PAGE_SIZE; |
| @@ -1133,6 +1174,9 @@ ring_buffer_lock_reserve(struct ring_buffer *buffer, | |||
| 1133 | struct ring_buffer_event *event; | 1174 | struct ring_buffer_event *event; |
| 1134 | int cpu, resched; | 1175 | int cpu, resched; |
| 1135 | 1176 | ||
| 1177 | if (ring_buffers_off) | ||
| 1178 | return NULL; | ||
| 1179 | |||
| 1136 | if (atomic_read(&buffer->record_disabled)) | 1180 | if (atomic_read(&buffer->record_disabled)) |
| 1137 | return NULL; | 1181 | return NULL; |
| 1138 | 1182 | ||
| @@ -1249,6 +1293,9 @@ int ring_buffer_write(struct ring_buffer *buffer, | |||
| 1249 | int ret = -EBUSY; | 1293 | int ret = -EBUSY; |
| 1250 | int cpu, resched; | 1294 | int cpu, resched; |
| 1251 | 1295 | ||
| 1296 | if (ring_buffers_off) | ||
| 1297 | return -EBUSY; | ||
| 1298 | |||
| 1252 | if (atomic_read(&buffer->record_disabled)) | 1299 | if (atomic_read(&buffer->record_disabled)) |
| 1253 | return -EBUSY; | 1300 | return -EBUSY; |
| 1254 | 1301 | ||
| @@ -2070,3 +2117,69 @@ int ring_buffer_swap_cpu(struct ring_buffer *buffer_a, | |||
| 2070 | return 0; | 2117 | return 0; |
| 2071 | } | 2118 | } |
| 2072 | 2119 | ||
| 2120 | static ssize_t | ||
| 2121 | rb_simple_read(struct file *filp, char __user *ubuf, | ||
| 2122 | size_t cnt, loff_t *ppos) | ||
| 2123 | { | ||
| 2124 | int *p = filp->private_data; | ||
| 2125 | char buf[64]; | ||
| 2126 | int r; | ||
| 2127 | |||
| 2128 | /* !ring_buffers_off == tracing_on */ | ||
| 2129 | r = sprintf(buf, "%d\n", !*p); | ||
| 2130 | |||
| 2131 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); | ||
| 2132 | } | ||
| 2133 | |||
| 2134 | static ssize_t | ||
| 2135 | rb_simple_write(struct file *filp, const char __user *ubuf, | ||
| 2136 | size_t cnt, loff_t *ppos) | ||
| 2137 | { | ||
| 2138 | int *p = filp->private_data; | ||
| 2139 | char buf[64]; | ||
| 2140 | long val; | ||
| 2141 | int ret; | ||
| 2142 | |||
| 2143 | if (cnt >= sizeof(buf)) | ||
| 2144 | return -EINVAL; | ||
| 2145 | |||
| 2146 | if (copy_from_user(&buf, ubuf, cnt)) | ||
| 2147 | return -EFAULT; | ||
| 2148 | |||
| 2149 | buf[cnt] = 0; | ||
| 2150 | |||
| 2151 | ret = strict_strtoul(buf, 10, &val); | ||
| 2152 | if (ret < 0) | ||
| 2153 | return ret; | ||
| 2154 | |||
| 2155 | /* !ring_buffers_off == tracing_on */ | ||
| 2156 | *p = !val; | ||
| 2157 | |||
| 2158 | (*ppos)++; | ||
| 2159 | |||
| 2160 | return cnt; | ||
| 2161 | } | ||
| 2162 | |||
| 2163 | static struct file_operations rb_simple_fops = { | ||
| 2164 | .open = tracing_open_generic, | ||
| 2165 | .read = rb_simple_read, | ||
| 2166 | .write = rb_simple_write, | ||
| 2167 | }; | ||
| 2168 | |||
| 2169 | |||
| 2170 | static __init int rb_init_debugfs(void) | ||
| 2171 | { | ||
| 2172 | struct dentry *d_tracer; | ||
| 2173 | struct dentry *entry; | ||
| 2174 | |||
| 2175 | d_tracer = tracing_init_dentry(); | ||
| 2176 | |||
| 2177 | entry = debugfs_create_file("tracing_on", 0644, d_tracer, | ||
| 2178 | &ring_buffers_off, &rb_simple_fops); | ||
| 2179 | if (!entry) | ||
| 2180 | pr_warning("Could not create debugfs 'tracing_on' entry\n"); | ||
| 2181 | |||
| 2182 | return 0; | ||
| 2183 | } | ||
| 2184 | |||
| 2185 | fs_initcall(rb_init_debugfs); | ||
