diff options
Diffstat (limited to 'kernel/trace/ring_buffer.c')
| -rw-r--r-- | kernel/trace/ring_buffer.c | 118 |
1 files changed, 116 insertions, 2 deletions
diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c index 3f3380638646..f780e9552f91 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; |
| @@ -576,6 +617,7 @@ int ring_buffer_resize(struct ring_buffer *buffer, unsigned long size) | |||
| 576 | list_del_init(&page->list); | 617 | list_del_init(&page->list); |
| 577 | free_buffer_page(page); | 618 | free_buffer_page(page); |
| 578 | } | 619 | } |
| 620 | mutex_unlock(&buffer->mutex); | ||
| 579 | return -ENOMEM; | 621 | return -ENOMEM; |
| 580 | } | 622 | } |
| 581 | 623 | ||
| @@ -1060,7 +1102,7 @@ rb_reserve_next_event(struct ring_buffer_per_cpu *cpu_buffer, | |||
| 1060 | 1102 | ||
| 1061 | /* Did the write stamp get updated already? */ | 1103 | /* Did the write stamp get updated already? */ |
| 1062 | if (unlikely(ts < cpu_buffer->write_stamp)) | 1104 | if (unlikely(ts < cpu_buffer->write_stamp)) |
| 1063 | goto again; | 1105 | delta = 0; |
| 1064 | 1106 | ||
| 1065 | if (test_time_stamp(delta)) { | 1107 | if (test_time_stamp(delta)) { |
| 1066 | 1108 | ||
| @@ -1133,6 +1175,9 @@ ring_buffer_lock_reserve(struct ring_buffer *buffer, | |||
| 1133 | struct ring_buffer_event *event; | 1175 | struct ring_buffer_event *event; |
| 1134 | int cpu, resched; | 1176 | int cpu, resched; |
| 1135 | 1177 | ||
| 1178 | if (ring_buffers_off) | ||
| 1179 | return NULL; | ||
| 1180 | |||
| 1136 | if (atomic_read(&buffer->record_disabled)) | 1181 | if (atomic_read(&buffer->record_disabled)) |
| 1137 | return NULL; | 1182 | return NULL; |
| 1138 | 1183 | ||
| @@ -1249,6 +1294,9 @@ int ring_buffer_write(struct ring_buffer *buffer, | |||
| 1249 | int ret = -EBUSY; | 1294 | int ret = -EBUSY; |
| 1250 | int cpu, resched; | 1295 | int cpu, resched; |
| 1251 | 1296 | ||
| 1297 | if (ring_buffers_off) | ||
| 1298 | return -EBUSY; | ||
| 1299 | |||
| 1252 | if (atomic_read(&buffer->record_disabled)) | 1300 | if (atomic_read(&buffer->record_disabled)) |
| 1253 | return -EBUSY; | 1301 | return -EBUSY; |
| 1254 | 1302 | ||
| @@ -2070,3 +2118,69 @@ int ring_buffer_swap_cpu(struct ring_buffer *buffer_a, | |||
| 2070 | return 0; | 2118 | return 0; |
| 2071 | } | 2119 | } |
| 2072 | 2120 | ||
| 2121 | static ssize_t | ||
| 2122 | rb_simple_read(struct file *filp, char __user *ubuf, | ||
| 2123 | size_t cnt, loff_t *ppos) | ||
| 2124 | { | ||
| 2125 | int *p = filp->private_data; | ||
| 2126 | char buf[64]; | ||
| 2127 | int r; | ||
| 2128 | |||
| 2129 | /* !ring_buffers_off == tracing_on */ | ||
| 2130 | r = sprintf(buf, "%d\n", !*p); | ||
| 2131 | |||
| 2132 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); | ||
| 2133 | } | ||
| 2134 | |||
| 2135 | static ssize_t | ||
| 2136 | rb_simple_write(struct file *filp, const char __user *ubuf, | ||
| 2137 | size_t cnt, loff_t *ppos) | ||
| 2138 | { | ||
| 2139 | int *p = filp->private_data; | ||
| 2140 | char buf[64]; | ||
| 2141 | long val; | ||
| 2142 | int ret; | ||
| 2143 | |||
| 2144 | if (cnt >= sizeof(buf)) | ||
| 2145 | return -EINVAL; | ||
| 2146 | |||
| 2147 | if (copy_from_user(&buf, ubuf, cnt)) | ||
| 2148 | return -EFAULT; | ||
| 2149 | |||
| 2150 | buf[cnt] = 0; | ||
| 2151 | |||
| 2152 | ret = strict_strtoul(buf, 10, &val); | ||
| 2153 | if (ret < 0) | ||
| 2154 | return ret; | ||
| 2155 | |||
| 2156 | /* !ring_buffers_off == tracing_on */ | ||
| 2157 | *p = !val; | ||
| 2158 | |||
| 2159 | (*ppos)++; | ||
| 2160 | |||
| 2161 | return cnt; | ||
| 2162 | } | ||
| 2163 | |||
| 2164 | static struct file_operations rb_simple_fops = { | ||
| 2165 | .open = tracing_open_generic, | ||
| 2166 | .read = rb_simple_read, | ||
| 2167 | .write = rb_simple_write, | ||
| 2168 | }; | ||
| 2169 | |||
| 2170 | |||
| 2171 | static __init int rb_init_debugfs(void) | ||
| 2172 | { | ||
| 2173 | struct dentry *d_tracer; | ||
| 2174 | struct dentry *entry; | ||
| 2175 | |||
| 2176 | d_tracer = tracing_init_dentry(); | ||
| 2177 | |||
| 2178 | entry = debugfs_create_file("tracing_on", 0644, d_tracer, | ||
| 2179 | &ring_buffers_off, &rb_simple_fops); | ||
| 2180 | if (!entry) | ||
| 2181 | pr_warning("Could not create debugfs 'tracing_on' entry\n"); | ||
| 2182 | |||
| 2183 | return 0; | ||
| 2184 | } | ||
| 2185 | |||
| 2186 | fs_initcall(rb_init_debugfs); | ||
