diff options
author | Rusty Russell <rusty@rustcorp.com.au> | 2008-12-31 18:42:22 -0500 |
---|---|---|
committer | Rusty Russell <rusty@rustcorp.com.au> | 2008-12-31 18:42:22 -0500 |
commit | 9e01c1b74c9531e301c900edaa92a99fcb7738f2 (patch) | |
tree | f71425ecfecf32046bd6aecb5ca6e504e9258b30 /kernel/trace/ring_buffer.c | |
parent | 333af15341b2f6cd813c054e1b441d7b6d8e9318 (diff) |
cpumask: convert kernel trace functions
Impact: Reduce future memory usage, use new cpumask API.
(Eventually, cpumask_var_t will be allocated based on nr_cpu_ids, not NR_CPUS).
Convert kernel trace functions to use struct cpumask API:
1) Use cpumask_copy/cpumask_test_cpu/for_each_cpu.
2) Use cpumask_var_t and alloc_cpumask_var/free_cpumask_var everywhere.
3) Use on_each_cpu instead of playing with current->cpus_allowed.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: Mike Travis <travis@sgi.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Diffstat (limited to 'kernel/trace/ring_buffer.c')
-rw-r--r-- | kernel/trace/ring_buffer.c | 42 |
1 files changed, 25 insertions, 17 deletions
diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c index 1d601a7c4587..a9d9760dc7b6 100644 --- a/kernel/trace/ring_buffer.c +++ b/kernel/trace/ring_buffer.c | |||
@@ -195,7 +195,7 @@ void *ring_buffer_event_data(struct ring_buffer_event *event) | |||
195 | EXPORT_SYMBOL_GPL(ring_buffer_event_data); | 195 | EXPORT_SYMBOL_GPL(ring_buffer_event_data); |
196 | 196 | ||
197 | #define for_each_buffer_cpu(buffer, cpu) \ | 197 | #define for_each_buffer_cpu(buffer, cpu) \ |
198 | for_each_cpu_mask(cpu, buffer->cpumask) | 198 | for_each_cpu(cpu, buffer->cpumask) |
199 | 199 | ||
200 | #define TS_SHIFT 27 | 200 | #define TS_SHIFT 27 |
201 | #define TS_MASK ((1ULL << TS_SHIFT) - 1) | 201 | #define TS_MASK ((1ULL << TS_SHIFT) - 1) |
@@ -267,7 +267,7 @@ struct ring_buffer { | |||
267 | unsigned pages; | 267 | unsigned pages; |
268 | unsigned flags; | 268 | unsigned flags; |
269 | int cpus; | 269 | int cpus; |
270 | cpumask_t cpumask; | 270 | cpumask_var_t cpumask; |
271 | atomic_t record_disabled; | 271 | atomic_t record_disabled; |
272 | 272 | ||
273 | struct mutex mutex; | 273 | struct mutex mutex; |
@@ -458,6 +458,9 @@ struct ring_buffer *ring_buffer_alloc(unsigned long size, unsigned flags) | |||
458 | if (!buffer) | 458 | if (!buffer) |
459 | return NULL; | 459 | return NULL; |
460 | 460 | ||
461 | if (!alloc_cpumask_var(&buffer->cpumask, GFP_KERNEL)) | ||
462 | goto fail_free_buffer; | ||
463 | |||
461 | buffer->pages = DIV_ROUND_UP(size, BUF_PAGE_SIZE); | 464 | buffer->pages = DIV_ROUND_UP(size, BUF_PAGE_SIZE); |
462 | buffer->flags = flags; | 465 | buffer->flags = flags; |
463 | 466 | ||
@@ -465,14 +468,14 @@ struct ring_buffer *ring_buffer_alloc(unsigned long size, unsigned flags) | |||
465 | if (buffer->pages == 1) | 468 | if (buffer->pages == 1) |
466 | buffer->pages++; | 469 | buffer->pages++; |
467 | 470 | ||
468 | buffer->cpumask = cpu_possible_map; | 471 | cpumask_copy(buffer->cpumask, cpu_possible_mask); |
469 | buffer->cpus = nr_cpu_ids; | 472 | buffer->cpus = nr_cpu_ids; |
470 | 473 | ||
471 | bsize = sizeof(void *) * nr_cpu_ids; | 474 | bsize = sizeof(void *) * nr_cpu_ids; |
472 | buffer->buffers = kzalloc(ALIGN(bsize, cache_line_size()), | 475 | buffer->buffers = kzalloc(ALIGN(bsize, cache_line_size()), |
473 | GFP_KERNEL); | 476 | GFP_KERNEL); |
474 | if (!buffer->buffers) | 477 | if (!buffer->buffers) |
475 | goto fail_free_buffer; | 478 | goto fail_free_cpumask; |
476 | 479 | ||
477 | for_each_buffer_cpu(buffer, cpu) { | 480 | for_each_buffer_cpu(buffer, cpu) { |
478 | buffer->buffers[cpu] = | 481 | buffer->buffers[cpu] = |
@@ -492,6 +495,9 @@ struct ring_buffer *ring_buffer_alloc(unsigned long size, unsigned flags) | |||
492 | } | 495 | } |
493 | kfree(buffer->buffers); | 496 | kfree(buffer->buffers); |
494 | 497 | ||
498 | fail_free_cpumask: | ||
499 | free_cpumask_var(buffer->cpumask); | ||
500 | |||
495 | fail_free_buffer: | 501 | fail_free_buffer: |
496 | kfree(buffer); | 502 | kfree(buffer); |
497 | return NULL; | 503 | return NULL; |
@@ -510,6 +516,8 @@ ring_buffer_free(struct ring_buffer *buffer) | |||
510 | for_each_buffer_cpu(buffer, cpu) | 516 | for_each_buffer_cpu(buffer, cpu) |
511 | rb_free_cpu_buffer(buffer->buffers[cpu]); | 517 | rb_free_cpu_buffer(buffer->buffers[cpu]); |
512 | 518 | ||
519 | free_cpumask_var(buffer->cpumask); | ||
520 | |||
513 | kfree(buffer); | 521 | kfree(buffer); |
514 | } | 522 | } |
515 | EXPORT_SYMBOL_GPL(ring_buffer_free); | 523 | EXPORT_SYMBOL_GPL(ring_buffer_free); |
@@ -1283,7 +1291,7 @@ ring_buffer_lock_reserve(struct ring_buffer *buffer, | |||
1283 | 1291 | ||
1284 | cpu = raw_smp_processor_id(); | 1292 | cpu = raw_smp_processor_id(); |
1285 | 1293 | ||
1286 | if (!cpu_isset(cpu, buffer->cpumask)) | 1294 | if (!cpumask_test_cpu(cpu, buffer->cpumask)) |
1287 | goto out; | 1295 | goto out; |
1288 | 1296 | ||
1289 | cpu_buffer = buffer->buffers[cpu]; | 1297 | cpu_buffer = buffer->buffers[cpu]; |
@@ -1396,7 +1404,7 @@ int ring_buffer_write(struct ring_buffer *buffer, | |||
1396 | 1404 | ||
1397 | cpu = raw_smp_processor_id(); | 1405 | cpu = raw_smp_processor_id(); |
1398 | 1406 | ||
1399 | if (!cpu_isset(cpu, buffer->cpumask)) | 1407 | if (!cpumask_test_cpu(cpu, buffer->cpumask)) |
1400 | goto out; | 1408 | goto out; |
1401 | 1409 | ||
1402 | cpu_buffer = buffer->buffers[cpu]; | 1410 | cpu_buffer = buffer->buffers[cpu]; |
@@ -1478,7 +1486,7 @@ void ring_buffer_record_disable_cpu(struct ring_buffer *buffer, int cpu) | |||
1478 | { | 1486 | { |
1479 | struct ring_buffer_per_cpu *cpu_buffer; | 1487 | struct ring_buffer_per_cpu *cpu_buffer; |
1480 | 1488 | ||
1481 | if (!cpu_isset(cpu, buffer->cpumask)) | 1489 | if (!cpumask_test_cpu(cpu, buffer->cpumask)) |
1482 | return; | 1490 | return; |
1483 | 1491 | ||
1484 | cpu_buffer = buffer->buffers[cpu]; | 1492 | cpu_buffer = buffer->buffers[cpu]; |
@@ -1498,7 +1506,7 @@ void ring_buffer_record_enable_cpu(struct ring_buffer *buffer, int cpu) | |||
1498 | { | 1506 | { |
1499 | struct ring_buffer_per_cpu *cpu_buffer; | 1507 | struct ring_buffer_per_cpu *cpu_buffer; |
1500 | 1508 | ||
1501 | if (!cpu_isset(cpu, buffer->cpumask)) | 1509 | if (!cpumask_test_cpu(cpu, buffer->cpumask)) |
1502 | return; | 1510 | return; |
1503 | 1511 | ||
1504 | cpu_buffer = buffer->buffers[cpu]; | 1512 | cpu_buffer = buffer->buffers[cpu]; |
@@ -1515,7 +1523,7 @@ unsigned long ring_buffer_entries_cpu(struct ring_buffer *buffer, int cpu) | |||
1515 | { | 1523 | { |
1516 | struct ring_buffer_per_cpu *cpu_buffer; | 1524 | struct ring_buffer_per_cpu *cpu_buffer; |
1517 | 1525 | ||
1518 | if (!cpu_isset(cpu, buffer->cpumask)) | 1526 | if (!cpumask_test_cpu(cpu, buffer->cpumask)) |
1519 | return 0; | 1527 | return 0; |
1520 | 1528 | ||
1521 | cpu_buffer = buffer->buffers[cpu]; | 1529 | cpu_buffer = buffer->buffers[cpu]; |
@@ -1532,7 +1540,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu) | |||
1532 | { | 1540 | { |
1533 | struct ring_buffer_per_cpu *cpu_buffer; | 1541 | struct ring_buffer_per_cpu *cpu_buffer; |
1534 | 1542 | ||
1535 | if (!cpu_isset(cpu, buffer->cpumask)) | 1543 | if (!cpumask_test_cpu(cpu, buffer->cpumask)) |
1536 | return 0; | 1544 | return 0; |
1537 | 1545 | ||
1538 | cpu_buffer = buffer->buffers[cpu]; | 1546 | cpu_buffer = buffer->buffers[cpu]; |
@@ -1850,7 +1858,7 @@ rb_buffer_peek(struct ring_buffer *buffer, int cpu, u64 *ts) | |||
1850 | struct buffer_page *reader; | 1858 | struct buffer_page *reader; |
1851 | int nr_loops = 0; | 1859 | int nr_loops = 0; |
1852 | 1860 | ||
1853 | if (!cpu_isset(cpu, buffer->cpumask)) | 1861 | if (!cpumask_test_cpu(cpu, buffer->cpumask)) |
1854 | return NULL; | 1862 | return NULL; |
1855 | 1863 | ||
1856 | cpu_buffer = buffer->buffers[cpu]; | 1864 | cpu_buffer = buffer->buffers[cpu]; |
@@ -2025,7 +2033,7 @@ ring_buffer_consume(struct ring_buffer *buffer, int cpu, u64 *ts) | |||
2025 | struct ring_buffer_event *event; | 2033 | struct ring_buffer_event *event; |
2026 | unsigned long flags; | 2034 | unsigned long flags; |
2027 | 2035 | ||
2028 | if (!cpu_isset(cpu, buffer->cpumask)) | 2036 | if (!cpumask_test_cpu(cpu, buffer->cpumask)) |
2029 | return NULL; | 2037 | return NULL; |
2030 | 2038 | ||
2031 | spin_lock_irqsave(&cpu_buffer->reader_lock, flags); | 2039 | spin_lock_irqsave(&cpu_buffer->reader_lock, flags); |
@@ -2062,7 +2070,7 @@ ring_buffer_read_start(struct ring_buffer *buffer, int cpu) | |||
2062 | struct ring_buffer_iter *iter; | 2070 | struct ring_buffer_iter *iter; |
2063 | unsigned long flags; | 2071 | unsigned long flags; |
2064 | 2072 | ||
2065 | if (!cpu_isset(cpu, buffer->cpumask)) | 2073 | if (!cpumask_test_cpu(cpu, buffer->cpumask)) |
2066 | return NULL; | 2074 | return NULL; |
2067 | 2075 | ||
2068 | iter = kmalloc(sizeof(*iter), GFP_KERNEL); | 2076 | iter = kmalloc(sizeof(*iter), GFP_KERNEL); |
@@ -2172,7 +2180,7 @@ void ring_buffer_reset_cpu(struct ring_buffer *buffer, int cpu) | |||
2172 | struct ring_buffer_per_cpu *cpu_buffer = buffer->buffers[cpu]; | 2180 | struct ring_buffer_per_cpu *cpu_buffer = buffer->buffers[cpu]; |
2173 | unsigned long flags; | 2181 | unsigned long flags; |
2174 | 2182 | ||
2175 | if (!cpu_isset(cpu, buffer->cpumask)) | 2183 | if (!cpumask_test_cpu(cpu, buffer->cpumask)) |
2176 | return; | 2184 | return; |
2177 | 2185 | ||
2178 | spin_lock_irqsave(&cpu_buffer->reader_lock, flags); | 2186 | spin_lock_irqsave(&cpu_buffer->reader_lock, flags); |
@@ -2228,7 +2236,7 @@ int ring_buffer_empty_cpu(struct ring_buffer *buffer, int cpu) | |||
2228 | { | 2236 | { |
2229 | struct ring_buffer_per_cpu *cpu_buffer; | 2237 | struct ring_buffer_per_cpu *cpu_buffer; |
2230 | 2238 | ||
2231 | if (!cpu_isset(cpu, buffer->cpumask)) | 2239 | if (!cpumask_test_cpu(cpu, buffer->cpumask)) |
2232 | return 1; | 2240 | return 1; |
2233 | 2241 | ||
2234 | cpu_buffer = buffer->buffers[cpu]; | 2242 | cpu_buffer = buffer->buffers[cpu]; |
@@ -2252,8 +2260,8 @@ int ring_buffer_swap_cpu(struct ring_buffer *buffer_a, | |||
2252 | struct ring_buffer_per_cpu *cpu_buffer_a; | 2260 | struct ring_buffer_per_cpu *cpu_buffer_a; |
2253 | struct ring_buffer_per_cpu *cpu_buffer_b; | 2261 | struct ring_buffer_per_cpu *cpu_buffer_b; |
2254 | 2262 | ||
2255 | if (!cpu_isset(cpu, buffer_a->cpumask) || | 2263 | if (!cpumask_test_cpu(cpu, buffer_a->cpumask) || |
2256 | !cpu_isset(cpu, buffer_b->cpumask)) | 2264 | !cpumask_test_cpu(cpu, buffer_b->cpumask)) |
2257 | return -EINVAL; | 2265 | return -EINVAL; |
2258 | 2266 | ||
2259 | /* At least make sure the two buffers are somewhat the same */ | 2267 | /* At least make sure the two buffers are somewhat the same */ |