diff options
| -rw-r--r-- | arch/Kconfig | 2 | ||||
| -rw-r--r-- | arch/x86/oprofile/op_model_amd.c | 89 | ||||
| -rw-r--r-- | drivers/oprofile/buffer_sync.c | 117 | ||||
| -rw-r--r-- | drivers/oprofile/cpu_buffer.c | 197 | ||||
| -rw-r--r-- | drivers/oprofile/cpu_buffer.h | 69 | ||||
| -rw-r--r-- | drivers/oprofile/oprofile_files.c | 15 | ||||
| -rw-r--r-- | include/linux/oprofile.h | 3 | ||||
| -rw-r--r-- | include/linux/ring_buffer.h | 2 | ||||
| -rw-r--r-- | kernel/trace/ring_buffer.c | 36 | ||||
| -rw-r--r-- | kernel/trace/trace.c | 4 |
10 files changed, 306 insertions, 228 deletions
diff --git a/arch/Kconfig b/arch/Kconfig index 471e72dbaf8b..2e13aa261929 100644 --- a/arch/Kconfig +++ b/arch/Kconfig | |||
| @@ -6,6 +6,8 @@ config OPROFILE | |||
| 6 | tristate "OProfile system profiling (EXPERIMENTAL)" | 6 | tristate "OProfile system profiling (EXPERIMENTAL)" |
| 7 | depends on PROFILING | 7 | depends on PROFILING |
| 8 | depends on HAVE_OPROFILE | 8 | depends on HAVE_OPROFILE |
| 9 | select TRACING | ||
| 10 | select RING_BUFFER | ||
| 9 | help | 11 | help |
| 10 | OProfile is a profiling system capable of profiling the | 12 | OProfile is a profiling system capable of profiling the |
| 11 | whole system, include the kernel, kernel modules, libraries, | 13 | whole system, include the kernel, kernel modules, libraries, |
diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c index 509513760a6e..98658f25f542 100644 --- a/arch/x86/oprofile/op_model_amd.c +++ b/arch/x86/oprofile/op_model_amd.c | |||
| @@ -65,11 +65,13 @@ static unsigned long reset_value[NUM_COUNTERS]; | |||
| 65 | #define IBS_FETCH_BEGIN 3 | 65 | #define IBS_FETCH_BEGIN 3 |
| 66 | #define IBS_OP_BEGIN 4 | 66 | #define IBS_OP_BEGIN 4 |
| 67 | 67 | ||
| 68 | /* The function interface needs to be fixed, something like add | 68 | /* |
| 69 | data. Should then be added to linux/oprofile.h. */ | 69 | * The function interface needs to be fixed, something like add |
| 70 | * data. Should then be added to linux/oprofile.h. | ||
| 71 | */ | ||
| 70 | extern void | 72 | extern void |
| 71 | oprofile_add_ibs_sample(struct pt_regs *const regs, | 73 | oprofile_add_ibs_sample(struct pt_regs * const regs, |
| 72 | unsigned int *const ibs_sample, int ibs_code); | 74 | unsigned int * const ibs_sample, int ibs_code); |
| 73 | 75 | ||
| 74 | struct ibs_fetch_sample { | 76 | struct ibs_fetch_sample { |
| 75 | /* MSRC001_1031 IBS Fetch Linear Address Register */ | 77 | /* MSRC001_1031 IBS Fetch Linear Address Register */ |
| @@ -104,11 +106,6 @@ struct ibs_op_sample { | |||
| 104 | unsigned int ibs_dc_phys_high; | 106 | unsigned int ibs_dc_phys_high; |
| 105 | }; | 107 | }; |
| 106 | 108 | ||
| 107 | /* | ||
| 108 | * unitialize the APIC for the IBS interrupts if needed on AMD Family10h+ | ||
| 109 | */ | ||
| 110 | static void clear_ibs_nmi(void); | ||
| 111 | |||
| 112 | static int ibs_allowed; /* AMD Family10h and later */ | 109 | static int ibs_allowed; /* AMD Family10h and later */ |
| 113 | 110 | ||
| 114 | struct op_ibs_config { | 111 | struct op_ibs_config { |
| @@ -223,7 +220,7 @@ op_amd_handle_ibs(struct pt_regs * const regs, | |||
| 223 | (unsigned int *)&ibs_fetch, | 220 | (unsigned int *)&ibs_fetch, |
| 224 | IBS_FETCH_BEGIN); | 221 | IBS_FETCH_BEGIN); |
| 225 | 222 | ||
| 226 | /*reenable the IRQ */ | 223 | /* reenable the IRQ */ |
| 227 | rdmsr(MSR_AMD64_IBSFETCHCTL, low, high); | 224 | rdmsr(MSR_AMD64_IBSFETCHCTL, low, high); |
| 228 | high &= ~IBS_FETCH_HIGH_VALID_BIT; | 225 | high &= ~IBS_FETCH_HIGH_VALID_BIT; |
| 229 | high |= IBS_FETCH_HIGH_ENABLE; | 226 | high |= IBS_FETCH_HIGH_ENABLE; |
| @@ -331,8 +328,10 @@ static void op_amd_stop(struct op_msrs const * const msrs) | |||
| 331 | unsigned int low, high; | 328 | unsigned int low, high; |
| 332 | int i; | 329 | int i; |
| 333 | 330 | ||
| 334 | /* Subtle: stop on all counters to avoid race with | 331 | /* |
| 335 | * setting our pm callback */ | 332 | * Subtle: stop on all counters to avoid race with setting our |
| 333 | * pm callback | ||
| 334 | */ | ||
| 336 | for (i = 0 ; i < NUM_COUNTERS ; ++i) { | 335 | for (i = 0 ; i < NUM_COUNTERS ; ++i) { |
| 337 | if (!reset_value[i]) | 336 | if (!reset_value[i]) |
| 338 | continue; | 337 | continue; |
| @@ -343,13 +342,15 @@ static void op_amd_stop(struct op_msrs const * const msrs) | |||
| 343 | 342 | ||
| 344 | #ifdef CONFIG_OPROFILE_IBS | 343 | #ifdef CONFIG_OPROFILE_IBS |
| 345 | if (ibs_allowed && ibs_config.fetch_enabled) { | 344 | if (ibs_allowed && ibs_config.fetch_enabled) { |
| 346 | low = 0; /* clear max count and enable */ | 345 | /* clear max count and enable */ |
| 346 | low = 0; | ||
| 347 | high = 0; | 347 | high = 0; |
| 348 | wrmsr(MSR_AMD64_IBSFETCHCTL, low, high); | 348 | wrmsr(MSR_AMD64_IBSFETCHCTL, low, high); |
| 349 | } | 349 | } |
| 350 | 350 | ||
| 351 | if (ibs_allowed && ibs_config.op_enabled) { | 351 | if (ibs_allowed && ibs_config.op_enabled) { |
| 352 | low = 0; /* clear max count and enable */ | 352 | /* clear max count and enable */ |
| 353 | low = 0; | ||
| 353 | high = 0; | 354 | high = 0; |
| 354 | wrmsr(MSR_AMD64_IBSOPCTL, low, high); | 355 | wrmsr(MSR_AMD64_IBSOPCTL, low, high); |
| 355 | } | 356 | } |
| @@ -370,18 +371,7 @@ static void op_amd_shutdown(struct op_msrs const * const msrs) | |||
| 370 | } | 371 | } |
| 371 | } | 372 | } |
| 372 | 373 | ||
| 373 | #ifndef CONFIG_OPROFILE_IBS | 374 | #ifdef CONFIG_OPROFILE_IBS |
| 374 | |||
| 375 | /* no IBS support */ | ||
| 376 | |||
| 377 | static int op_amd_init(struct oprofile_operations *ops) | ||
| 378 | { | ||
| 379 | return 0; | ||
| 380 | } | ||
| 381 | |||
| 382 | static void op_amd_exit(void) {} | ||
| 383 | |||
| 384 | #else | ||
| 385 | 375 | ||
| 386 | static u8 ibs_eilvt_off; | 376 | static u8 ibs_eilvt_off; |
| 387 | 377 | ||
| @@ -395,7 +385,7 @@ static inline void apic_clear_ibs_nmi_per_cpu(void *arg) | |||
| 395 | setup_APIC_eilvt_ibs(0, APIC_EILVT_MSG_FIX, 1); | 385 | setup_APIC_eilvt_ibs(0, APIC_EILVT_MSG_FIX, 1); |
| 396 | } | 386 | } |
| 397 | 387 | ||
| 398 | static int pfm_amd64_setup_eilvt(void) | 388 | static int init_ibs_nmi(void) |
| 399 | { | 389 | { |
| 400 | #define IBSCTL_LVTOFFSETVAL (1 << 8) | 390 | #define IBSCTL_LVTOFFSETVAL (1 << 8) |
| 401 | #define IBSCTL 0x1cc | 391 | #define IBSCTL 0x1cc |
| @@ -443,18 +433,22 @@ static int pfm_amd64_setup_eilvt(void) | |||
| 443 | return 0; | 433 | return 0; |
| 444 | } | 434 | } |
| 445 | 435 | ||
| 446 | /* | 436 | /* uninitialize the APIC for the IBS interrupts if needed */ |
| 447 | * initialize the APIC for the IBS interrupts | 437 | static void clear_ibs_nmi(void) |
| 448 | * if available (AMD Family10h rev B0 and later) | 438 | { |
| 449 | */ | 439 | if (ibs_allowed) |
| 450 | static void setup_ibs(void) | 440 | on_each_cpu(apic_clear_ibs_nmi_per_cpu, NULL, 1); |
| 441 | } | ||
| 442 | |||
| 443 | /* initialize the APIC for the IBS interrupts if available */ | ||
| 444 | static void ibs_init(void) | ||
| 451 | { | 445 | { |
| 452 | ibs_allowed = boot_cpu_has(X86_FEATURE_IBS); | 446 | ibs_allowed = boot_cpu_has(X86_FEATURE_IBS); |
| 453 | 447 | ||
| 454 | if (!ibs_allowed) | 448 | if (!ibs_allowed) |
| 455 | return; | 449 | return; |
| 456 | 450 | ||
| 457 | if (pfm_amd64_setup_eilvt()) { | 451 | if (init_ibs_nmi()) { |
| 458 | ibs_allowed = 0; | 452 | ibs_allowed = 0; |
| 459 | return; | 453 | return; |
| 460 | } | 454 | } |
| @@ -462,14 +456,12 @@ static void setup_ibs(void) | |||
| 462 | printk(KERN_INFO "oprofile: AMD IBS detected\n"); | 456 | printk(KERN_INFO "oprofile: AMD IBS detected\n"); |
| 463 | } | 457 | } |
| 464 | 458 | ||
| 465 | 459 | static void ibs_exit(void) | |
| 466 | /* | ||
| 467 | * unitialize the APIC for the IBS interrupts if needed on AMD Family10h | ||
| 468 | * rev B0 and later */ | ||
| 469 | static void clear_ibs_nmi(void) | ||
| 470 | { | 460 | { |
| 471 | if (ibs_allowed) | 461 | if (!ibs_allowed) |
| 472 | on_each_cpu(apic_clear_ibs_nmi_per_cpu, NULL, 1); | 462 | return; |
| 463 | |||
| 464 | clear_ibs_nmi(); | ||
| 473 | } | 465 | } |
| 474 | 466 | ||
| 475 | static int (*create_arch_files)(struct super_block *sb, struct dentry *root); | 467 | static int (*create_arch_files)(struct super_block *sb, struct dentry *root); |
| @@ -519,7 +511,7 @@ static int setup_ibs_files(struct super_block *sb, struct dentry *root) | |||
| 519 | 511 | ||
| 520 | static int op_amd_init(struct oprofile_operations *ops) | 512 | static int op_amd_init(struct oprofile_operations *ops) |
| 521 | { | 513 | { |
| 522 | setup_ibs(); | 514 | ibs_init(); |
| 523 | create_arch_files = ops->create_files; | 515 | create_arch_files = ops->create_files; |
| 524 | ops->create_files = setup_ibs_files; | 516 | ops->create_files = setup_ibs_files; |
| 525 | return 0; | 517 | return 0; |
| @@ -527,10 +519,21 @@ static int op_amd_init(struct oprofile_operations *ops) | |||
| 527 | 519 | ||
| 528 | static void op_amd_exit(void) | 520 | static void op_amd_exit(void) |
| 529 | { | 521 | { |
| 530 | clear_ibs_nmi(); | 522 | ibs_exit(); |
| 531 | } | 523 | } |
| 532 | 524 | ||
| 533 | #endif | 525 | #else |
| 526 | |||
| 527 | /* no IBS support */ | ||
| 528 | |||
| 529 | static int op_amd_init(struct oprofile_operations *ops) | ||
| 530 | { | ||
| 531 | return 0; | ||
| 532 | } | ||
| 533 | |||
| 534 | static void op_amd_exit(void) {} | ||
| 535 | |||
| 536 | #endif /* CONFIG_OPROFILE_IBS */ | ||
| 534 | 537 | ||
| 535 | struct op_x86_model_spec const op_amd_spec = { | 538 | struct op_x86_model_spec const op_amd_spec = { |
| 536 | .init = op_amd_init, | 539 | .init = op_amd_init, |
diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c index b55cd23ffdef..737bd9484822 100644 --- a/drivers/oprofile/buffer_sync.c +++ b/drivers/oprofile/buffer_sync.c | |||
| @@ -268,18 +268,6 @@ lookup_dcookie(struct mm_struct *mm, unsigned long addr, off_t *offset) | |||
| 268 | return cookie; | 268 | return cookie; |
| 269 | } | 269 | } |
| 270 | 270 | ||
| 271 | static void increment_tail(struct oprofile_cpu_buffer *b) | ||
| 272 | { | ||
| 273 | unsigned long new_tail = b->tail_pos + 1; | ||
| 274 | |||
| 275 | rmb(); /* be sure fifo pointers are synchromized */ | ||
| 276 | |||
| 277 | if (new_tail < b->buffer_size) | ||
| 278 | b->tail_pos = new_tail; | ||
| 279 | else | ||
| 280 | b->tail_pos = 0; | ||
| 281 | } | ||
| 282 | |||
| 283 | static unsigned long last_cookie = INVALID_COOKIE; | 271 | static unsigned long last_cookie = INVALID_COOKIE; |
| 284 | 272 | ||
| 285 | static void add_cpu_switch(int i) | 273 | static void add_cpu_switch(int i) |
| @@ -331,28 +319,25 @@ static void add_trace_begin(void) | |||
| 331 | 319 | ||
| 332 | #define IBS_FETCH_CODE_SIZE 2 | 320 | #define IBS_FETCH_CODE_SIZE 2 |
| 333 | #define IBS_OP_CODE_SIZE 5 | 321 | #define IBS_OP_CODE_SIZE 5 |
| 334 | #define IBS_EIP(offset) \ | ||
| 335 | (((struct op_sample *)&cpu_buf->buffer[(offset)])->eip) | ||
| 336 | #define IBS_EVENT(offset) \ | ||
| 337 | (((struct op_sample *)&cpu_buf->buffer[(offset)])->event) | ||
| 338 | 322 | ||
| 339 | /* | 323 | /* |
| 340 | * Add IBS fetch and op entries to event buffer | 324 | * Add IBS fetch and op entries to event buffer |
| 341 | */ | 325 | */ |
| 342 | static void add_ibs_begin(struct oprofile_cpu_buffer *cpu_buf, int code, | 326 | static void add_ibs_begin(int cpu, int code, struct mm_struct *mm) |
| 343 | struct mm_struct *mm) | ||
| 344 | { | 327 | { |
| 345 | unsigned long rip; | 328 | unsigned long rip; |
| 346 | int i, count; | 329 | int i, count; |
| 347 | unsigned long ibs_cookie = 0; | 330 | unsigned long ibs_cookie = 0; |
| 348 | off_t offset; | 331 | off_t offset; |
| 332 | struct op_sample *sample; | ||
| 349 | 333 | ||
| 350 | increment_tail(cpu_buf); /* move to RIP entry */ | 334 | sample = cpu_buffer_read_entry(cpu); |
| 351 | 335 | if (!sample) | |
| 352 | rip = IBS_EIP(cpu_buf->tail_pos); | 336 | goto Error; |
| 337 | rip = sample->eip; | ||
| 353 | 338 | ||
| 354 | #ifdef __LP64__ | 339 | #ifdef __LP64__ |
| 355 | rip += IBS_EVENT(cpu_buf->tail_pos) << 32; | 340 | rip += sample->event << 32; |
| 356 | #endif | 341 | #endif |
| 357 | 342 | ||
| 358 | if (mm) { | 343 | if (mm) { |
| @@ -376,8 +361,8 @@ static void add_ibs_begin(struct oprofile_cpu_buffer *cpu_buf, int code, | |||
| 376 | add_event_entry(offset); /* Offset from Dcookie */ | 361 | add_event_entry(offset); /* Offset from Dcookie */ |
| 377 | 362 | ||
| 378 | /* we send the Dcookie offset, but send the raw Linear Add also*/ | 363 | /* we send the Dcookie offset, but send the raw Linear Add also*/ |
| 379 | add_event_entry(IBS_EIP(cpu_buf->tail_pos)); | 364 | add_event_entry(sample->eip); |
| 380 | add_event_entry(IBS_EVENT(cpu_buf->tail_pos)); | 365 | add_event_entry(sample->event); |
| 381 | 366 | ||
| 382 | if (code == IBS_FETCH_CODE) | 367 | if (code == IBS_FETCH_CODE) |
| 383 | count = IBS_FETCH_CODE_SIZE; /*IBS FETCH is 2 int64s*/ | 368 | count = IBS_FETCH_CODE_SIZE; /*IBS FETCH is 2 int64s*/ |
| @@ -385,10 +370,17 @@ static void add_ibs_begin(struct oprofile_cpu_buffer *cpu_buf, int code, | |||
| 385 | count = IBS_OP_CODE_SIZE; /*IBS OP is 5 int64s*/ | 370 | count = IBS_OP_CODE_SIZE; /*IBS OP is 5 int64s*/ |
| 386 | 371 | ||
| 387 | for (i = 0; i < count; i++) { | 372 | for (i = 0; i < count; i++) { |
| 388 | increment_tail(cpu_buf); | 373 | sample = cpu_buffer_read_entry(cpu); |
| 389 | add_event_entry(IBS_EIP(cpu_buf->tail_pos)); | 374 | if (!sample) |
| 390 | add_event_entry(IBS_EVENT(cpu_buf->tail_pos)); | 375 | goto Error; |
| 376 | add_event_entry(sample->eip); | ||
| 377 | add_event_entry(sample->event); | ||
| 391 | } | 378 | } |
| 379 | |||
| 380 | return; | ||
| 381 | |||
| 382 | Error: | ||
| 383 | return; | ||
| 392 | } | 384 | } |
| 393 | 385 | ||
| 394 | #endif | 386 | #endif |
| @@ -466,33 +458,6 @@ static inline int is_code(unsigned long val) | |||
| 466 | } | 458 | } |
| 467 | 459 | ||
| 468 | 460 | ||
| 469 | /* "acquire" as many cpu buffer slots as we can */ | ||
| 470 | static unsigned long get_slots(struct oprofile_cpu_buffer *b) | ||
| 471 | { | ||
| 472 | unsigned long head = b->head_pos; | ||
| 473 | unsigned long tail = b->tail_pos; | ||
| 474 | |||
| 475 | /* | ||
| 476 | * Subtle. This resets the persistent last_task | ||
| 477 | * and in_kernel values used for switching notes. | ||
| 478 | * BUT, there is a small window between reading | ||
| 479 | * head_pos, and this call, that means samples | ||
| 480 | * can appear at the new head position, but not | ||
| 481 | * be prefixed with the notes for switching | ||
| 482 | * kernel mode or a task switch. This small hole | ||
| 483 | * can lead to mis-attribution or samples where | ||
| 484 | * we don't know if it's in the kernel or not, | ||
| 485 | * at the start of an event buffer. | ||
| 486 | */ | ||
| 487 | cpu_buffer_reset(b); | ||
| 488 | |||
| 489 | if (head >= tail) | ||
| 490 | return head - tail; | ||
| 491 | |||
| 492 | return head + (b->buffer_size - tail); | ||
| 493 | } | ||
| 494 | |||
| 495 | |||
| 496 | /* Move tasks along towards death. Any tasks on dead_tasks | 461 | /* Move tasks along towards death. Any tasks on dead_tasks |
| 497 | * will definitely have no remaining references in any | 462 | * will definitely have no remaining references in any |
| 498 | * CPU buffers at this point, because we use two lists, | 463 | * CPU buffers at this point, because we use two lists, |
| @@ -559,61 +524,61 @@ typedef enum { | |||
| 559 | */ | 524 | */ |
| 560 | void sync_buffer(int cpu) | 525 | void sync_buffer(int cpu) |
| 561 | { | 526 | { |
| 562 | struct oprofile_cpu_buffer *cpu_buf = &per_cpu(cpu_buffer, cpu); | ||
| 563 | struct mm_struct *mm = NULL; | 527 | struct mm_struct *mm = NULL; |
| 528 | struct mm_struct *oldmm; | ||
| 564 | struct task_struct *new; | 529 | struct task_struct *new; |
| 565 | unsigned long cookie = 0; | 530 | unsigned long cookie = 0; |
| 566 | int in_kernel = 1; | 531 | int in_kernel = 1; |
| 567 | sync_buffer_state state = sb_buffer_start; | 532 | sync_buffer_state state = sb_buffer_start; |
| 568 | #ifndef CONFIG_OPROFILE_IBS | ||
| 569 | unsigned int i; | 533 | unsigned int i; |
| 570 | unsigned long available; | 534 | unsigned long available; |
| 571 | #endif | ||
| 572 | 535 | ||
| 573 | mutex_lock(&buffer_mutex); | 536 | mutex_lock(&buffer_mutex); |
| 574 | 537 | ||
| 575 | add_cpu_switch(cpu); | 538 | add_cpu_switch(cpu); |
| 576 | 539 | ||
| 577 | /* Remember, only we can modify tail_pos */ | 540 | cpu_buffer_reset(cpu); |
| 578 | 541 | available = cpu_buffer_entries(cpu); | |
| 579 | #ifndef CONFIG_OPROFILE_IBS | ||
| 580 | available = get_slots(cpu_buf); | ||
| 581 | 542 | ||
| 582 | for (i = 0; i < available; ++i) { | 543 | for (i = 0; i < available; ++i) { |
| 583 | #else | 544 | struct op_sample *s = cpu_buffer_read_entry(cpu); |
| 584 | while (get_slots(cpu_buf)) { | 545 | if (!s) |
| 585 | #endif | 546 | break; |
| 586 | struct op_sample *s = &cpu_buf->buffer[cpu_buf->tail_pos]; | ||
| 587 | 547 | ||
| 588 | if (is_code(s->eip)) { | 548 | if (is_code(s->eip)) { |
| 589 | if (s->event <= CPU_IS_KERNEL) { | 549 | switch (s->event) { |
| 550 | case 0: | ||
| 551 | case CPU_IS_KERNEL: | ||
| 590 | /* kernel/userspace switch */ | 552 | /* kernel/userspace switch */ |
| 591 | in_kernel = s->event; | 553 | in_kernel = s->event; |
| 592 | if (state == sb_buffer_start) | 554 | if (state == sb_buffer_start) |
| 593 | state = sb_sample_start; | 555 | state = sb_sample_start; |
| 594 | add_kernel_ctx_switch(s->event); | 556 | add_kernel_ctx_switch(s->event); |
| 595 | } else if (s->event == CPU_TRACE_BEGIN) { | 557 | break; |
| 558 | case CPU_TRACE_BEGIN: | ||
| 596 | state = sb_bt_start; | 559 | state = sb_bt_start; |
| 597 | add_trace_begin(); | 560 | add_trace_begin(); |
| 561 | break; | ||
| 598 | #ifdef CONFIG_OPROFILE_IBS | 562 | #ifdef CONFIG_OPROFILE_IBS |
| 599 | } else if (s->event == IBS_FETCH_BEGIN) { | 563 | case IBS_FETCH_BEGIN: |
| 600 | state = sb_bt_start; | 564 | state = sb_bt_start; |
| 601 | add_ibs_begin(cpu_buf, IBS_FETCH_CODE, mm); | 565 | add_ibs_begin(cpu, IBS_FETCH_CODE, mm); |
| 602 | } else if (s->event == IBS_OP_BEGIN) { | 566 | break; |
| 567 | case IBS_OP_BEGIN: | ||
| 603 | state = sb_bt_start; | 568 | state = sb_bt_start; |
| 604 | add_ibs_begin(cpu_buf, IBS_OP_CODE, mm); | 569 | add_ibs_begin(cpu, IBS_OP_CODE, mm); |
| 570 | break; | ||
| 605 | #endif | 571 | #endif |
| 606 | } else { | 572 | default: |
| 607 | struct mm_struct *oldmm = mm; | ||
| 608 | |||
| 609 | /* userspace context switch */ | 573 | /* userspace context switch */ |
| 574 | oldmm = mm; | ||
| 610 | new = (struct task_struct *)s->event; | 575 | new = (struct task_struct *)s->event; |
| 611 | |||
| 612 | release_mm(oldmm); | 576 | release_mm(oldmm); |
| 613 | mm = take_tasks_mm(new); | 577 | mm = take_tasks_mm(new); |
| 614 | if (mm != oldmm) | 578 | if (mm != oldmm) |
| 615 | cookie = get_exec_dcookie(mm); | 579 | cookie = get_exec_dcookie(mm); |
| 616 | add_user_ctx_switch(new, cookie); | 580 | add_user_ctx_switch(new, cookie); |
| 581 | break; | ||
| 617 | } | 582 | } |
| 618 | } else if (state >= sb_bt_start && | 583 | } else if (state >= sb_bt_start && |
| 619 | !add_sample(mm, s, in_kernel)) { | 584 | !add_sample(mm, s, in_kernel)) { |
| @@ -622,8 +587,6 @@ void sync_buffer(int cpu) | |||
| 622 | atomic_inc(&oprofile_stats.bt_lost_no_mapping); | 587 | atomic_inc(&oprofile_stats.bt_lost_no_mapping); |
| 623 | } | 588 | } |
| 624 | } | 589 | } |
| 625 | |||
| 626 | increment_tail(cpu_buf); | ||
| 627 | } | 590 | } |
| 628 | release_mm(mm); | 591 | release_mm(mm); |
| 629 | 592 | ||
diff --git a/drivers/oprofile/cpu_buffer.c b/drivers/oprofile/cpu_buffer.c index 01d38e78cde1..61090969158f 100644 --- a/drivers/oprofile/cpu_buffer.c +++ b/drivers/oprofile/cpu_buffer.c | |||
| @@ -28,6 +28,25 @@ | |||
| 28 | #include "buffer_sync.h" | 28 | #include "buffer_sync.h" |
| 29 | #include "oprof.h" | 29 | #include "oprof.h" |
| 30 | 30 | ||
| 31 | #define OP_BUFFER_FLAGS 0 | ||
| 32 | |||
| 33 | /* | ||
| 34 | * Read and write access is using spin locking. Thus, writing to the | ||
| 35 | * buffer by NMI handler (x86) could occur also during critical | ||
| 36 | * sections when reading the buffer. To avoid this, there are 2 | ||
| 37 | * buffers for independent read and write access. Read access is in | ||
| 38 | * process context only, write access only in the NMI handler. If the | ||
| 39 | * read buffer runs empty, both buffers are swapped atomically. There | ||
| 40 | * is potentially a small window during swapping where the buffers are | ||
| 41 | * disabled and samples could be lost. | ||
| 42 | * | ||
| 43 | * Using 2 buffers is a little bit overhead, but the solution is clear | ||
| 44 | * and does not require changes in the ring buffer implementation. It | ||
| 45 | * can be changed to a single buffer solution when the ring buffer | ||
| 46 | * access is implemented as non-locking atomic code. | ||
| 47 | */ | ||
| 48 | struct ring_buffer *op_ring_buffer_read; | ||
| 49 | struct ring_buffer *op_ring_buffer_write; | ||
| 31 | DEFINE_PER_CPU(struct oprofile_cpu_buffer, cpu_buffer); | 50 | DEFINE_PER_CPU(struct oprofile_cpu_buffer, cpu_buffer); |
| 32 | 51 | ||
| 33 | static void wq_sync_buffer(struct work_struct *work); | 52 | static void wq_sync_buffer(struct work_struct *work); |
| @@ -37,12 +56,12 @@ static int work_enabled; | |||
| 37 | 56 | ||
| 38 | void free_cpu_buffers(void) | 57 | void free_cpu_buffers(void) |
| 39 | { | 58 | { |
| 40 | int i; | 59 | if (op_ring_buffer_read) |
| 41 | 60 | ring_buffer_free(op_ring_buffer_read); | |
| 42 | for_each_possible_cpu(i) { | 61 | op_ring_buffer_read = NULL; |
| 43 | vfree(per_cpu(cpu_buffer, i).buffer); | 62 | if (op_ring_buffer_write) |
| 44 | per_cpu(cpu_buffer, i).buffer = NULL; | 63 | ring_buffer_free(op_ring_buffer_write); |
| 45 | } | 64 | op_ring_buffer_write = NULL; |
| 46 | } | 65 | } |
| 47 | 66 | ||
| 48 | unsigned long oprofile_get_cpu_buffer_size(void) | 67 | unsigned long oprofile_get_cpu_buffer_size(void) |
| @@ -64,14 +83,16 @@ int alloc_cpu_buffers(void) | |||
| 64 | 83 | ||
| 65 | unsigned long buffer_size = fs_cpu_buffer_size; | 84 | unsigned long buffer_size = fs_cpu_buffer_size; |
| 66 | 85 | ||
| 86 | op_ring_buffer_read = ring_buffer_alloc(buffer_size, OP_BUFFER_FLAGS); | ||
| 87 | if (!op_ring_buffer_read) | ||
| 88 | goto fail; | ||
| 89 | op_ring_buffer_write = ring_buffer_alloc(buffer_size, OP_BUFFER_FLAGS); | ||
| 90 | if (!op_ring_buffer_write) | ||
| 91 | goto fail; | ||
| 92 | |||
| 67 | for_each_possible_cpu(i) { | 93 | for_each_possible_cpu(i) { |
| 68 | struct oprofile_cpu_buffer *b = &per_cpu(cpu_buffer, i); | 94 | struct oprofile_cpu_buffer *b = &per_cpu(cpu_buffer, i); |
| 69 | 95 | ||
| 70 | b->buffer = vmalloc_node(sizeof(struct op_sample) * buffer_size, | ||
| 71 | cpu_to_node(i)); | ||
| 72 | if (!b->buffer) | ||
| 73 | goto fail; | ||
| 74 | |||
| 75 | b->last_task = NULL; | 96 | b->last_task = NULL; |
| 76 | b->last_is_kernel = -1; | 97 | b->last_is_kernel = -1; |
| 77 | b->tracing = 0; | 98 | b->tracing = 0; |
| @@ -124,57 +145,31 @@ void end_cpu_work(void) | |||
| 124 | flush_scheduled_work(); | 145 | flush_scheduled_work(); |
| 125 | } | 146 | } |
| 126 | 147 | ||
| 127 | /* Resets the cpu buffer to a sane state. */ | 148 | static inline int |
| 128 | void cpu_buffer_reset(struct oprofile_cpu_buffer *cpu_buf) | 149 | add_sample(struct oprofile_cpu_buffer *cpu_buf, |
| 129 | { | 150 | unsigned long pc, unsigned long event) |
| 130 | /* reset these to invalid values; the next sample | ||
| 131 | * collected will populate the buffer with proper | ||
| 132 | * values to initialize the buffer | ||
| 133 | */ | ||
| 134 | cpu_buf->last_is_kernel = -1; | ||
| 135 | cpu_buf->last_task = NULL; | ||
| 136 | } | ||
| 137 | |||
| 138 | /* compute number of available slots in cpu_buffer queue */ | ||
| 139 | static unsigned long nr_available_slots(struct oprofile_cpu_buffer const *b) | ||
| 140 | { | 151 | { |
| 141 | unsigned long head = b->head_pos; | 152 | struct op_entry entry; |
| 142 | unsigned long tail = b->tail_pos; | 153 | int ret; |
| 143 | 154 | ||
| 144 | if (tail > head) | 155 | ret = cpu_buffer_write_entry(&entry); |
| 145 | return (tail - head) - 1; | 156 | if (ret) |
| 157 | return ret; | ||
| 146 | 158 | ||
| 147 | return tail + (b->buffer_size - head) - 1; | 159 | entry.sample->eip = pc; |
| 148 | } | 160 | entry.sample->event = event; |
| 149 | 161 | ||
| 150 | static void increment_head(struct oprofile_cpu_buffer *b) | 162 | ret = cpu_buffer_write_commit(&entry); |
| 151 | { | 163 | if (ret) |
| 152 | unsigned long new_head = b->head_pos + 1; | 164 | return ret; |
| 153 | |||
| 154 | /* Ensure anything written to the slot before we | ||
| 155 | * increment is visible */ | ||
| 156 | wmb(); | ||
| 157 | |||
| 158 | if (new_head < b->buffer_size) | ||
| 159 | b->head_pos = new_head; | ||
| 160 | else | ||
| 161 | b->head_pos = 0; | ||
| 162 | } | ||
| 163 | 165 | ||
| 164 | static inline void | 166 | return 0; |
| 165 | add_sample(struct oprofile_cpu_buffer *cpu_buf, | ||
| 166 | unsigned long pc, unsigned long event) | ||
| 167 | { | ||
| 168 | struct op_sample *entry = &cpu_buf->buffer[cpu_buf->head_pos]; | ||
| 169 | entry->eip = pc; | ||
| 170 | entry->event = event; | ||
| 171 | increment_head(cpu_buf); | ||
| 172 | } | 167 | } |
| 173 | 168 | ||
| 174 | static inline void | 169 | static inline int |
| 175 | add_code(struct oprofile_cpu_buffer *buffer, unsigned long value) | 170 | add_code(struct oprofile_cpu_buffer *buffer, unsigned long value) |
| 176 | { | 171 | { |
| 177 | add_sample(buffer, ESCAPE_CODE, value); | 172 | return add_sample(buffer, ESCAPE_CODE, value); |
| 178 | } | 173 | } |
| 179 | 174 | ||
| 180 | /* This must be safe from any context. It's safe writing here | 175 | /* This must be safe from any context. It's safe writing here |
| @@ -198,11 +193,6 @@ static int log_sample(struct oprofile_cpu_buffer *cpu_buf, unsigned long pc, | |||
| 198 | return 0; | 193 | return 0; |
| 199 | } | 194 | } |
| 200 | 195 | ||
| 201 | if (nr_available_slots(cpu_buf) < 3) { | ||
| 202 | cpu_buf->sample_lost_overflow++; | ||
| 203 | return 0; | ||
| 204 | } | ||
| 205 | |||
| 206 | is_kernel = !!is_kernel; | 196 | is_kernel = !!is_kernel; |
| 207 | 197 | ||
| 208 | task = current; | 198 | task = current; |
| @@ -210,26 +200,29 @@ static int log_sample(struct oprofile_cpu_buffer *cpu_buf, unsigned long pc, | |||
| 210 | /* notice a switch from user->kernel or vice versa */ | 200 | /* notice a switch from user->kernel or vice versa */ |
| 211 | if (cpu_buf->last_is_kernel != is_kernel) { | 201 | if (cpu_buf->last_is_kernel != is_kernel) { |
| 212 | cpu_buf->last_is_kernel = is_kernel; | 202 | cpu_buf->last_is_kernel = is_kernel; |
| 213 | add_code(cpu_buf, is_kernel); | 203 | if (add_code(cpu_buf, is_kernel)) |
| 204 | goto fail; | ||
| 214 | } | 205 | } |
| 215 | 206 | ||
| 216 | /* notice a task switch */ | 207 | /* notice a task switch */ |
| 217 | if (cpu_buf->last_task != task) { | 208 | if (cpu_buf->last_task != task) { |
| 218 | cpu_buf->last_task = task; | 209 | cpu_buf->last_task = task; |
| 219 | add_code(cpu_buf, (unsigned long)task); | 210 | if (add_code(cpu_buf, (unsigned long)task)) |
| 211 | goto fail; | ||
| 220 | } | 212 | } |
| 221 | 213 | ||
| 222 | add_sample(cpu_buf, pc, event); | 214 | if (add_sample(cpu_buf, pc, event)) |
| 215 | goto fail; | ||
| 216 | |||
| 223 | return 1; | 217 | return 1; |
| 218 | |||
| 219 | fail: | ||
| 220 | cpu_buf->sample_lost_overflow++; | ||
| 221 | return 0; | ||
| 224 | } | 222 | } |
| 225 | 223 | ||
| 226 | static int oprofile_begin_trace(struct oprofile_cpu_buffer *cpu_buf) | 224 | static int oprofile_begin_trace(struct oprofile_cpu_buffer *cpu_buf) |
| 227 | { | 225 | { |
| 228 | if (nr_available_slots(cpu_buf) < 4) { | ||
| 229 | cpu_buf->sample_lost_overflow++; | ||
| 230 | return 0; | ||
| 231 | } | ||
| 232 | |||
| 233 | add_code(cpu_buf, CPU_TRACE_BEGIN); | 226 | add_code(cpu_buf, CPU_TRACE_BEGIN); |
| 234 | cpu_buf->tracing = 1; | 227 | cpu_buf->tracing = 1; |
| 235 | return 1; | 228 | return 1; |
| @@ -253,8 +246,10 @@ void oprofile_add_ext_sample(unsigned long pc, struct pt_regs * const regs, | |||
| 253 | if (!oprofile_begin_trace(cpu_buf)) | 246 | if (!oprofile_begin_trace(cpu_buf)) |
| 254 | return; | 247 | return; |
| 255 | 248 | ||
| 256 | /* if log_sample() fail we can't backtrace since we lost the source | 249 | /* |
| 257 | * of this event */ | 250 | * if log_sample() fail we can't backtrace since we lost the |
| 251 | * source of this event | ||
| 252 | */ | ||
| 258 | if (log_sample(cpu_buf, pc, is_kernel, event)) | 253 | if (log_sample(cpu_buf, pc, is_kernel, event)) |
| 259 | oprofile_ops.backtrace(regs, backtrace_depth); | 254 | oprofile_ops.backtrace(regs, backtrace_depth); |
| 260 | oprofile_end_trace(cpu_buf); | 255 | oprofile_end_trace(cpu_buf); |
| @@ -272,49 +267,55 @@ void oprofile_add_sample(struct pt_regs * const regs, unsigned long event) | |||
| 272 | 267 | ||
| 273 | #define MAX_IBS_SAMPLE_SIZE 14 | 268 | #define MAX_IBS_SAMPLE_SIZE 14 |
| 274 | 269 | ||
| 275 | void oprofile_add_ibs_sample(struct pt_regs *const regs, | 270 | void oprofile_add_ibs_sample(struct pt_regs * const regs, |
| 276 | unsigned int *const ibs_sample, int ibs_code) | 271 | unsigned int * const ibs_sample, int ibs_code) |
| 277 | { | 272 | { |
| 278 | int is_kernel = !user_mode(regs); | 273 | int is_kernel = !user_mode(regs); |
| 279 | struct oprofile_cpu_buffer *cpu_buf = &__get_cpu_var(cpu_buffer); | 274 | struct oprofile_cpu_buffer *cpu_buf = &__get_cpu_var(cpu_buffer); |
| 280 | struct task_struct *task; | 275 | struct task_struct *task; |
| 276 | int fail = 0; | ||
| 281 | 277 | ||
| 282 | cpu_buf->sample_received++; | 278 | cpu_buf->sample_received++; |
| 283 | 279 | ||
| 284 | if (nr_available_slots(cpu_buf) < MAX_IBS_SAMPLE_SIZE) { | ||
| 285 | /* we can't backtrace since we lost the source of this event */ | ||
| 286 | cpu_buf->sample_lost_overflow++; | ||
| 287 | return; | ||
| 288 | } | ||
| 289 | |||
| 290 | /* notice a switch from user->kernel or vice versa */ | 280 | /* notice a switch from user->kernel or vice versa */ |
| 291 | if (cpu_buf->last_is_kernel != is_kernel) { | 281 | if (cpu_buf->last_is_kernel != is_kernel) { |
| 282 | if (add_code(cpu_buf, is_kernel)) | ||
| 283 | goto fail; | ||
| 292 | cpu_buf->last_is_kernel = is_kernel; | 284 | cpu_buf->last_is_kernel = is_kernel; |
| 293 | add_code(cpu_buf, is_kernel); | ||
| 294 | } | 285 | } |
| 295 | 286 | ||
| 296 | /* notice a task switch */ | 287 | /* notice a task switch */ |
| 297 | if (!is_kernel) { | 288 | if (!is_kernel) { |
| 298 | task = current; | 289 | task = current; |
| 299 | if (cpu_buf->last_task != task) { | 290 | if (cpu_buf->last_task != task) { |
| 291 | if (add_code(cpu_buf, (unsigned long)task)) | ||
| 292 | goto fail; | ||
| 300 | cpu_buf->last_task = task; | 293 | cpu_buf->last_task = task; |
| 301 | add_code(cpu_buf, (unsigned long)task); | ||
| 302 | } | 294 | } |
| 303 | } | 295 | } |
| 304 | 296 | ||
| 305 | add_code(cpu_buf, ibs_code); | 297 | fail = fail || add_code(cpu_buf, ibs_code); |
| 306 | add_sample(cpu_buf, ibs_sample[0], ibs_sample[1]); | 298 | fail = fail || add_sample(cpu_buf, ibs_sample[0], ibs_sample[1]); |
| 307 | add_sample(cpu_buf, ibs_sample[2], ibs_sample[3]); | 299 | fail = fail || add_sample(cpu_buf, ibs_sample[2], ibs_sample[3]); |
| 308 | add_sample(cpu_buf, ibs_sample[4], ibs_sample[5]); | 300 | fail = fail || add_sample(cpu_buf, ibs_sample[4], ibs_sample[5]); |
| 309 | 301 | ||
| 310 | if (ibs_code == IBS_OP_BEGIN) { | 302 | if (ibs_code == IBS_OP_BEGIN) { |
| 311 | add_sample(cpu_buf, ibs_sample[6], ibs_sample[7]); | 303 | fail = fail || add_sample(cpu_buf, ibs_sample[6], ibs_sample[7]); |
| 312 | add_sample(cpu_buf, ibs_sample[8], ibs_sample[9]); | 304 | fail = fail || add_sample(cpu_buf, ibs_sample[8], ibs_sample[9]); |
| 313 | add_sample(cpu_buf, ibs_sample[10], ibs_sample[11]); | 305 | fail = fail || add_sample(cpu_buf, ibs_sample[10], ibs_sample[11]); |
| 314 | } | 306 | } |
| 315 | 307 | ||
| 308 | if (fail) | ||
| 309 | goto fail; | ||
| 310 | |||
| 316 | if (backtrace_depth) | 311 | if (backtrace_depth) |
| 317 | oprofile_ops.backtrace(regs, backtrace_depth); | 312 | oprofile_ops.backtrace(regs, backtrace_depth); |
| 313 | |||
| 314 | return; | ||
| 315 | |||
| 316 | fail: | ||
| 317 | cpu_buf->sample_lost_overflow++; | ||
| 318 | return; | ||
| 318 | } | 319 | } |
| 319 | 320 | ||
| 320 | #endif | 321 | #endif |
| @@ -332,21 +333,21 @@ void oprofile_add_trace(unsigned long pc) | |||
| 332 | if (!cpu_buf->tracing) | 333 | if (!cpu_buf->tracing) |
| 333 | return; | 334 | return; |
| 334 | 335 | ||
| 335 | if (nr_available_slots(cpu_buf) < 1) { | 336 | /* |
| 336 | cpu_buf->tracing = 0; | 337 | * broken frame can give an eip with the same value as an |
| 337 | cpu_buf->sample_lost_overflow++; | 338 | * escape code, abort the trace if we get it |
| 338 | return; | 339 | */ |
| 339 | } | 340 | if (pc == ESCAPE_CODE) |
| 341 | goto fail; | ||
| 340 | 342 | ||
| 341 | /* broken frame can give an eip with the same value as an escape code, | 343 | if (add_sample(cpu_buf, pc, 0)) |
| 342 | * abort the trace if we get it */ | 344 | goto fail; |
| 343 | if (pc == ESCAPE_CODE) { | ||
| 344 | cpu_buf->tracing = 0; | ||
| 345 | cpu_buf->backtrace_aborted++; | ||
| 346 | return; | ||
| 347 | } | ||
| 348 | 345 | ||
| 349 | add_sample(cpu_buf, pc, 0); | 346 | return; |
| 347 | fail: | ||
| 348 | cpu_buf->tracing = 0; | ||
| 349 | cpu_buf->backtrace_aborted++; | ||
| 350 | return; | ||
| 350 | } | 351 | } |
| 351 | 352 | ||
| 352 | /* | 353 | /* |
diff --git a/drivers/oprofile/cpu_buffer.h b/drivers/oprofile/cpu_buffer.h index d3cc26264db5..aacb0f0bc566 100644 --- a/drivers/oprofile/cpu_buffer.h +++ b/drivers/oprofile/cpu_buffer.h | |||
| @@ -15,6 +15,7 @@ | |||
| 15 | #include <linux/workqueue.h> | 15 | #include <linux/workqueue.h> |
| 16 | #include <linux/cache.h> | 16 | #include <linux/cache.h> |
| 17 | #include <linux/sched.h> | 17 | #include <linux/sched.h> |
| 18 | #include <linux/ring_buffer.h> | ||
| 18 | 19 | ||
| 19 | struct task_struct; | 20 | struct task_struct; |
| 20 | 21 | ||
| @@ -32,6 +33,12 @@ struct op_sample { | |||
| 32 | unsigned long event; | 33 | unsigned long event; |
| 33 | }; | 34 | }; |
| 34 | 35 | ||
| 36 | struct op_entry { | ||
| 37 | struct ring_buffer_event *event; | ||
| 38 | struct op_sample *sample; | ||
| 39 | unsigned long irq_flags; | ||
| 40 | }; | ||
| 41 | |||
| 35 | struct oprofile_cpu_buffer { | 42 | struct oprofile_cpu_buffer { |
| 36 | volatile unsigned long head_pos; | 43 | volatile unsigned long head_pos; |
| 37 | volatile unsigned long tail_pos; | 44 | volatile unsigned long tail_pos; |
| @@ -39,7 +46,6 @@ struct oprofile_cpu_buffer { | |||
| 39 | struct task_struct *last_task; | 46 | struct task_struct *last_task; |
| 40 | int last_is_kernel; | 47 | int last_is_kernel; |
| 41 | int tracing; | 48 | int tracing; |
| 42 | struct op_sample *buffer; | ||
| 43 | unsigned long sample_received; | 49 | unsigned long sample_received; |
| 44 | unsigned long sample_lost_overflow; | 50 | unsigned long sample_lost_overflow; |
| 45 | unsigned long backtrace_aborted; | 51 | unsigned long backtrace_aborted; |
| @@ -48,9 +54,68 @@ struct oprofile_cpu_buffer { | |||
| 48 | struct delayed_work work; | 54 | struct delayed_work work; |
| 49 | }; | 55 | }; |
| 50 | 56 | ||
| 57 | extern struct ring_buffer *op_ring_buffer_read; | ||
| 58 | extern struct ring_buffer *op_ring_buffer_write; | ||
| 51 | DECLARE_PER_CPU(struct oprofile_cpu_buffer, cpu_buffer); | 59 | DECLARE_PER_CPU(struct oprofile_cpu_buffer, cpu_buffer); |
| 52 | 60 | ||
| 53 | void cpu_buffer_reset(struct oprofile_cpu_buffer *cpu_buf); | 61 | /* |
| 62 | * Resets the cpu buffer to a sane state. | ||
| 63 | * | ||
| 64 | * reset these to invalid values; the next sample collected will | ||
| 65 | * populate the buffer with proper values to initialize the buffer | ||
| 66 | */ | ||
| 67 | static inline void cpu_buffer_reset(int cpu) | ||
| 68 | { | ||
| 69 | struct oprofile_cpu_buffer *cpu_buf = &per_cpu(cpu_buffer, cpu); | ||
| 70 | |||
| 71 | cpu_buf->last_is_kernel = -1; | ||
| 72 | cpu_buf->last_task = NULL; | ||
| 73 | } | ||
| 74 | |||
| 75 | static inline int cpu_buffer_write_entry(struct op_entry *entry) | ||
| 76 | { | ||
| 77 | entry->event = ring_buffer_lock_reserve(op_ring_buffer_write, | ||
| 78 | sizeof(struct op_sample), | ||
| 79 | &entry->irq_flags); | ||
| 80 | if (entry->event) | ||
| 81 | entry->sample = ring_buffer_event_data(entry->event); | ||
| 82 | else | ||
| 83 | entry->sample = NULL; | ||
| 84 | |||
| 85 | if (!entry->sample) | ||
| 86 | return -ENOMEM; | ||
| 87 | |||
| 88 | return 0; | ||
| 89 | } | ||
| 90 | |||
| 91 | static inline int cpu_buffer_write_commit(struct op_entry *entry) | ||
| 92 | { | ||
| 93 | return ring_buffer_unlock_commit(op_ring_buffer_write, entry->event, | ||
| 94 | entry->irq_flags); | ||
| 95 | } | ||
| 96 | |||
| 97 | static inline struct op_sample *cpu_buffer_read_entry(int cpu) | ||
| 98 | { | ||
| 99 | struct ring_buffer_event *e; | ||
| 100 | e = ring_buffer_consume(op_ring_buffer_read, cpu, NULL); | ||
| 101 | if (e) | ||
| 102 | return ring_buffer_event_data(e); | ||
| 103 | if (ring_buffer_swap_cpu(op_ring_buffer_read, | ||
| 104 | op_ring_buffer_write, | ||
| 105 | cpu)) | ||
| 106 | return NULL; | ||
| 107 | e = ring_buffer_consume(op_ring_buffer_read, cpu, NULL); | ||
| 108 | if (e) | ||
| 109 | return ring_buffer_event_data(e); | ||
| 110 | return NULL; | ||
| 111 | } | ||
| 112 | |||
| 113 | /* "acquire" as many cpu buffer slots as we can */ | ||
| 114 | static inline unsigned long cpu_buffer_entries(int cpu) | ||
| 115 | { | ||
| 116 | return ring_buffer_entries_cpu(op_ring_buffer_read, cpu) | ||
| 117 | + ring_buffer_entries_cpu(op_ring_buffer_write, cpu); | ||
| 118 | } | ||
| 54 | 119 | ||
| 55 | /* transient events for the CPU buffer -> event buffer */ | 120 | /* transient events for the CPU buffer -> event buffer */ |
| 56 | #define CPU_IS_KERNEL 1 | 121 | #define CPU_IS_KERNEL 1 |
diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c index cc106d503ace..d8201998b0b7 100644 --- a/drivers/oprofile/oprofile_files.c +++ b/drivers/oprofile/oprofile_files.c | |||
| @@ -14,9 +14,13 @@ | |||
| 14 | #include "oprofile_stats.h" | 14 | #include "oprofile_stats.h" |
| 15 | #include "oprof.h" | 15 | #include "oprof.h" |
| 16 | 16 | ||
| 17 | unsigned long fs_buffer_size = 131072; | 17 | #define FS_BUFFER_SIZE_DEFAULT 131072 |
| 18 | unsigned long fs_cpu_buffer_size = 8192; | 18 | #define FS_CPU_BUFFER_SIZE_DEFAULT 8192 |
| 19 | unsigned long fs_buffer_watershed = 32768; /* FIXME: tune */ | 19 | #define FS_BUFFER_WATERSHED_DEFAULT 32768 /* FIXME: tune */ |
| 20 | |||
| 21 | unsigned long fs_buffer_size; | ||
| 22 | unsigned long fs_cpu_buffer_size; | ||
| 23 | unsigned long fs_buffer_watershed; | ||
| 20 | 24 | ||
| 21 | static ssize_t depth_read(struct file *file, char __user *buf, size_t count, loff_t *offset) | 25 | static ssize_t depth_read(struct file *file, char __user *buf, size_t count, loff_t *offset) |
| 22 | { | 26 | { |
| @@ -120,6 +124,11 @@ static const struct file_operations dump_fops = { | |||
| 120 | 124 | ||
| 121 | void oprofile_create_files(struct super_block *sb, struct dentry *root) | 125 | void oprofile_create_files(struct super_block *sb, struct dentry *root) |
| 122 | { | 126 | { |
| 127 | /* reinitialize default values */ | ||
| 128 | fs_buffer_size = FS_BUFFER_SIZE_DEFAULT; | ||
| 129 | fs_cpu_buffer_size = FS_CPU_BUFFER_SIZE_DEFAULT; | ||
| 130 | fs_buffer_watershed = FS_BUFFER_WATERSHED_DEFAULT; | ||
| 131 | |||
| 123 | oprofilefs_create_file(sb, root, "enable", &enable_fops); | 132 | oprofilefs_create_file(sb, root, "enable", &enable_fops); |
| 124 | oprofilefs_create_file_perm(sb, root, "dump", &dump_fops, 0666); | 133 | oprofilefs_create_file_perm(sb, root, "dump", &dump_fops, 0666); |
| 125 | oprofilefs_create_file(sb, root, "buffer", &event_buffer_fops); | 134 | oprofilefs_create_file(sb, root, "buffer", &event_buffer_fops); |
diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h index 5231861f357d..1ce9fe572e51 100644 --- a/include/linux/oprofile.h +++ b/include/linux/oprofile.h | |||
| @@ -86,8 +86,7 @@ int oprofile_arch_init(struct oprofile_operations * ops); | |||
| 86 | void oprofile_arch_exit(void); | 86 | void oprofile_arch_exit(void); |
| 87 | 87 | ||
| 88 | /** | 88 | /** |
| 89 | * Add a sample. This may be called from any context. Pass | 89 | * Add a sample. This may be called from any context. |
| 90 | * smp_processor_id() as cpu. | ||
| 91 | */ | 90 | */ |
| 92 | void oprofile_add_sample(struct pt_regs * const regs, unsigned long event); | 91 | void oprofile_add_sample(struct pt_regs * const regs, unsigned long event); |
| 93 | 92 | ||
diff --git a/include/linux/ring_buffer.h b/include/linux/ring_buffer.h index d363467c8f13..b3b359660082 100644 --- a/include/linux/ring_buffer.h +++ b/include/linux/ring_buffer.h | |||
| @@ -118,6 +118,8 @@ void ring_buffer_record_enable_cpu(struct ring_buffer *buffer, int cpu); | |||
| 118 | 118 | ||
| 119 | unsigned long ring_buffer_entries(struct ring_buffer *buffer); | 119 | unsigned long ring_buffer_entries(struct ring_buffer *buffer); |
| 120 | unsigned long ring_buffer_overruns(struct ring_buffer *buffer); | 120 | unsigned long ring_buffer_overruns(struct ring_buffer *buffer); |
| 121 | unsigned long ring_buffer_entries_cpu(struct ring_buffer *buffer, int cpu); | ||
| 122 | unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu); | ||
| 121 | 123 | ||
| 122 | u64 ring_buffer_time_stamp(int cpu); | 124 | u64 ring_buffer_time_stamp(int cpu); |
| 123 | void ring_buffer_normalize_time_stamp(int cpu, u64 *ts); | 125 | void ring_buffer_normalize_time_stamp(int cpu, u64 *ts); |
diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c index 76f34c0ef29c..1d601a7c4587 100644 --- a/kernel/trace/ring_buffer.c +++ b/kernel/trace/ring_buffer.c | |||
| @@ -69,6 +69,7 @@ void tracing_on(void) | |||
| 69 | { | 69 | { |
| 70 | set_bit(RB_BUFFERS_ON_BIT, &ring_buffer_flags); | 70 | set_bit(RB_BUFFERS_ON_BIT, &ring_buffer_flags); |
| 71 | } | 71 | } |
| 72 | EXPORT_SYMBOL_GPL(tracing_on); | ||
| 72 | 73 | ||
| 73 | /** | 74 | /** |
| 74 | * tracing_off - turn off all tracing buffers | 75 | * tracing_off - turn off all tracing buffers |
| @@ -82,6 +83,7 @@ void tracing_off(void) | |||
| 82 | { | 83 | { |
| 83 | clear_bit(RB_BUFFERS_ON_BIT, &ring_buffer_flags); | 84 | clear_bit(RB_BUFFERS_ON_BIT, &ring_buffer_flags); |
| 84 | } | 85 | } |
| 86 | EXPORT_SYMBOL_GPL(tracing_off); | ||
| 85 | 87 | ||
| 86 | /** | 88 | /** |
| 87 | * tracing_off_permanent - permanently disable ring buffers | 89 | * tracing_off_permanent - permanently disable ring buffers |
| @@ -111,12 +113,14 @@ u64 ring_buffer_time_stamp(int cpu) | |||
| 111 | 113 | ||
| 112 | return time; | 114 | return time; |
| 113 | } | 115 | } |
| 116 | EXPORT_SYMBOL_GPL(ring_buffer_time_stamp); | ||
| 114 | 117 | ||
| 115 | void ring_buffer_normalize_time_stamp(int cpu, u64 *ts) | 118 | void ring_buffer_normalize_time_stamp(int cpu, u64 *ts) |
| 116 | { | 119 | { |
| 117 | /* Just stupid testing the normalize function and deltas */ | 120 | /* Just stupid testing the normalize function and deltas */ |
| 118 | *ts >>= DEBUG_SHIFT; | 121 | *ts >>= DEBUG_SHIFT; |
| 119 | } | 122 | } |
| 123 | EXPORT_SYMBOL_GPL(ring_buffer_normalize_time_stamp); | ||
| 120 | 124 | ||
| 121 | #define RB_EVNT_HDR_SIZE (sizeof(struct ring_buffer_event)) | 125 | #define RB_EVNT_HDR_SIZE (sizeof(struct ring_buffer_event)) |
| 122 | #define RB_ALIGNMENT_SHIFT 2 | 126 | #define RB_ALIGNMENT_SHIFT 2 |
| @@ -166,6 +170,7 @@ unsigned ring_buffer_event_length(struct ring_buffer_event *event) | |||
| 166 | { | 170 | { |
| 167 | return rb_event_length(event); | 171 | return rb_event_length(event); |
| 168 | } | 172 | } |
| 173 | EXPORT_SYMBOL_GPL(ring_buffer_event_length); | ||
| 169 | 174 | ||
| 170 | /* inline for ring buffer fast paths */ | 175 | /* inline for ring buffer fast paths */ |
| 171 | static inline void * | 176 | static inline void * |
| @@ -187,6 +192,7 @@ void *ring_buffer_event_data(struct ring_buffer_event *event) | |||
| 187 | { | 192 | { |
| 188 | return rb_event_data(event); | 193 | return rb_event_data(event); |
| 189 | } | 194 | } |
| 195 | EXPORT_SYMBOL_GPL(ring_buffer_event_data); | ||
| 190 | 196 | ||
| 191 | #define for_each_buffer_cpu(buffer, cpu) \ | 197 | #define for_each_buffer_cpu(buffer, cpu) \ |
| 192 | for_each_cpu_mask(cpu, buffer->cpumask) | 198 | for_each_cpu_mask(cpu, buffer->cpumask) |
| @@ -427,7 +433,7 @@ extern int ring_buffer_page_too_big(void); | |||
| 427 | 433 | ||
| 428 | /** | 434 | /** |
| 429 | * ring_buffer_alloc - allocate a new ring_buffer | 435 | * ring_buffer_alloc - allocate a new ring_buffer |
| 430 | * @size: the size in bytes that is needed. | 436 | * @size: the size in bytes per cpu that is needed. |
| 431 | * @flags: attributes to set for the ring buffer. | 437 | * @flags: attributes to set for the ring buffer. |
| 432 | * | 438 | * |
| 433 | * Currently the only flag that is available is the RB_FL_OVERWRITE | 439 | * Currently the only flag that is available is the RB_FL_OVERWRITE |
| @@ -490,6 +496,7 @@ struct ring_buffer *ring_buffer_alloc(unsigned long size, unsigned flags) | |||
| 490 | kfree(buffer); | 496 | kfree(buffer); |
| 491 | return NULL; | 497 | return NULL; |
| 492 | } | 498 | } |
| 499 | EXPORT_SYMBOL_GPL(ring_buffer_alloc); | ||
| 493 | 500 | ||
| 494 | /** | 501 | /** |
| 495 | * ring_buffer_free - free a ring buffer. | 502 | * ring_buffer_free - free a ring buffer. |
| @@ -505,6 +512,7 @@ ring_buffer_free(struct ring_buffer *buffer) | |||
| 505 | 512 | ||
| 506 | kfree(buffer); | 513 | kfree(buffer); |
| 507 | } | 514 | } |
| 515 | EXPORT_SYMBOL_GPL(ring_buffer_free); | ||
| 508 | 516 | ||
| 509 | static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer); | 517 | static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer); |
| 510 | 518 | ||
| @@ -680,6 +688,7 @@ int ring_buffer_resize(struct ring_buffer *buffer, unsigned long size) | |||
| 680 | mutex_unlock(&buffer->mutex); | 688 | mutex_unlock(&buffer->mutex); |
| 681 | return -ENOMEM; | 689 | return -ENOMEM; |
| 682 | } | 690 | } |
| 691 | EXPORT_SYMBOL_GPL(ring_buffer_resize); | ||
| 683 | 692 | ||
| 684 | static inline int rb_null_event(struct ring_buffer_event *event) | 693 | static inline int rb_null_event(struct ring_buffer_event *event) |
| 685 | { | 694 | { |
| @@ -1304,6 +1313,7 @@ ring_buffer_lock_reserve(struct ring_buffer *buffer, | |||
| 1304 | ftrace_preempt_enable(resched); | 1313 | ftrace_preempt_enable(resched); |
| 1305 | return NULL; | 1314 | return NULL; |
| 1306 | } | 1315 | } |
| 1316 | EXPORT_SYMBOL_GPL(ring_buffer_lock_reserve); | ||
| 1307 | 1317 | ||
| 1308 | static void rb_commit(struct ring_buffer_per_cpu *cpu_buffer, | 1318 | static void rb_commit(struct ring_buffer_per_cpu *cpu_buffer, |
| 1309 | struct ring_buffer_event *event) | 1319 | struct ring_buffer_event *event) |
| @@ -1350,6 +1360,7 @@ int ring_buffer_unlock_commit(struct ring_buffer *buffer, | |||
| 1350 | 1360 | ||
| 1351 | return 0; | 1361 | return 0; |
| 1352 | } | 1362 | } |
| 1363 | EXPORT_SYMBOL_GPL(ring_buffer_unlock_commit); | ||
| 1353 | 1364 | ||
| 1354 | /** | 1365 | /** |
| 1355 | * ring_buffer_write - write data to the buffer without reserving | 1366 | * ring_buffer_write - write data to the buffer without reserving |
| @@ -1411,6 +1422,7 @@ int ring_buffer_write(struct ring_buffer *buffer, | |||
| 1411 | 1422 | ||
| 1412 | return ret; | 1423 | return ret; |
| 1413 | } | 1424 | } |
| 1425 | EXPORT_SYMBOL_GPL(ring_buffer_write); | ||
| 1414 | 1426 | ||
| 1415 | static inline int rb_per_cpu_empty(struct ring_buffer_per_cpu *cpu_buffer) | 1427 | static inline int rb_per_cpu_empty(struct ring_buffer_per_cpu *cpu_buffer) |
| 1416 | { | 1428 | { |
| @@ -1437,6 +1449,7 @@ void ring_buffer_record_disable(struct ring_buffer *buffer) | |||
| 1437 | { | 1449 | { |
| 1438 | atomic_inc(&buffer->record_disabled); | 1450 | atomic_inc(&buffer->record_disabled); |
| 1439 | } | 1451 | } |
| 1452 | EXPORT_SYMBOL_GPL(ring_buffer_record_disable); | ||
| 1440 | 1453 | ||
| 1441 | /** | 1454 | /** |
| 1442 | * ring_buffer_record_enable - enable writes to the buffer | 1455 | * ring_buffer_record_enable - enable writes to the buffer |
| @@ -1449,6 +1462,7 @@ void ring_buffer_record_enable(struct ring_buffer *buffer) | |||
| 1449 | { | 1462 | { |
| 1450 | atomic_dec(&buffer->record_disabled); | 1463 | atomic_dec(&buffer->record_disabled); |
| 1451 | } | 1464 | } |
| 1465 | EXPORT_SYMBOL_GPL(ring_buffer_record_enable); | ||
| 1452 | 1466 | ||
| 1453 | /** | 1467 | /** |
| 1454 | * ring_buffer_record_disable_cpu - stop all writes into the cpu_buffer | 1468 | * ring_buffer_record_disable_cpu - stop all writes into the cpu_buffer |
| @@ -1470,6 +1484,7 @@ void ring_buffer_record_disable_cpu(struct ring_buffer *buffer, int cpu) | |||
| 1470 | cpu_buffer = buffer->buffers[cpu]; | 1484 | cpu_buffer = buffer->buffers[cpu]; |
| 1471 | atomic_inc(&cpu_buffer->record_disabled); | 1485 | atomic_inc(&cpu_buffer->record_disabled); |
| 1472 | } | 1486 | } |
| 1487 | EXPORT_SYMBOL_GPL(ring_buffer_record_disable_cpu); | ||
| 1473 | 1488 | ||
| 1474 | /** | 1489 | /** |
| 1475 | * ring_buffer_record_enable_cpu - enable writes to the buffer | 1490 | * ring_buffer_record_enable_cpu - enable writes to the buffer |
| @@ -1489,6 +1504,7 @@ void ring_buffer_record_enable_cpu(struct ring_buffer *buffer, int cpu) | |||
| 1489 | cpu_buffer = buffer->buffers[cpu]; | 1504 | cpu_buffer = buffer->buffers[cpu]; |
| 1490 | atomic_dec(&cpu_buffer->record_disabled); | 1505 | atomic_dec(&cpu_buffer->record_disabled); |
| 1491 | } | 1506 | } |
| 1507 | EXPORT_SYMBOL_GPL(ring_buffer_record_enable_cpu); | ||
| 1492 | 1508 | ||
| 1493 | /** | 1509 | /** |
| 1494 | * ring_buffer_entries_cpu - get the number of entries in a cpu buffer | 1510 | * ring_buffer_entries_cpu - get the number of entries in a cpu buffer |
| @@ -1505,6 +1521,7 @@ unsigned long ring_buffer_entries_cpu(struct ring_buffer *buffer, int cpu) | |||
| 1505 | cpu_buffer = buffer->buffers[cpu]; | 1521 | cpu_buffer = buffer->buffers[cpu]; |
| 1506 | return cpu_buffer->entries; | 1522 | return cpu_buffer->entries; |
| 1507 | } | 1523 | } |
| 1524 | EXPORT_SYMBOL_GPL(ring_buffer_entries_cpu); | ||
| 1508 | 1525 | ||
| 1509 | /** | 1526 | /** |
| 1510 | * ring_buffer_overrun_cpu - get the number of overruns in a cpu_buffer | 1527 | * ring_buffer_overrun_cpu - get the number of overruns in a cpu_buffer |
| @@ -1521,6 +1538,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu) | |||
| 1521 | cpu_buffer = buffer->buffers[cpu]; | 1538 | cpu_buffer = buffer->buffers[cpu]; |
| 1522 | return cpu_buffer->overrun; | 1539 | return cpu_buffer->overrun; |
| 1523 | } | 1540 | } |
| 1541 | EXPORT_SYMBOL_GPL(ring_buffer_overrun_cpu); | ||
| 1524 | 1542 | ||
| 1525 | /** | 1543 | /** |
| 1526 | * ring_buffer_entries - get the number of entries in a buffer | 1544 | * ring_buffer_entries - get the number of entries in a buffer |
| @@ -1543,6 +1561,7 @@ unsigned long ring_buffer_entries(struct ring_buffer *buffer) | |||
| 1543 | 1561 | ||
| 1544 | return entries; | 1562 | return entries; |
| 1545 | } | 1563 | } |
| 1564 | EXPORT_SYMBOL_GPL(ring_buffer_entries); | ||
| 1546 | 1565 | ||
| 1547 | /** | 1566 | /** |
| 1548 | * ring_buffer_overrun_cpu - get the number of overruns in buffer | 1567 | * ring_buffer_overrun_cpu - get the number of overruns in buffer |
| @@ -1565,6 +1584,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer) | |||
| 1565 | 1584 | ||
| 1566 | return overruns; | 1585 | return overruns; |
| 1567 | } | 1586 | } |
| 1587 | EXPORT_SYMBOL_GPL(ring_buffer_overruns); | ||
| 1568 | 1588 | ||
| 1569 | static void rb_iter_reset(struct ring_buffer_iter *iter) | 1589 | static void rb_iter_reset(struct ring_buffer_iter *iter) |
| 1570 | { | 1590 | { |
| @@ -1600,6 +1620,7 @@ void ring_buffer_iter_reset(struct ring_buffer_iter *iter) | |||
| 1600 | rb_iter_reset(iter); | 1620 | rb_iter_reset(iter); |
| 1601 | spin_unlock_irqrestore(&cpu_buffer->reader_lock, flags); | 1621 | spin_unlock_irqrestore(&cpu_buffer->reader_lock, flags); |
| 1602 | } | 1622 | } |
| 1623 | EXPORT_SYMBOL_GPL(ring_buffer_iter_reset); | ||
| 1603 | 1624 | ||
| 1604 | /** | 1625 | /** |
| 1605 | * ring_buffer_iter_empty - check if an iterator has no more to read | 1626 | * ring_buffer_iter_empty - check if an iterator has no more to read |
| @@ -1614,6 +1635,7 @@ int ring_buffer_iter_empty(struct ring_buffer_iter *iter) | |||
| 1614 | return iter->head_page == cpu_buffer->commit_page && | 1635 | return iter->head_page == cpu_buffer->commit_page && |
| 1615 | iter->head == rb_commit_index(cpu_buffer); | 1636 | iter->head == rb_commit_index(cpu_buffer); |
| 1616 | } | 1637 | } |
| 1638 | EXPORT_SYMBOL_GPL(ring_buffer_iter_empty); | ||
| 1617 | 1639 | ||
| 1618 | static void | 1640 | static void |
| 1619 | rb_update_read_stamp(struct ring_buffer_per_cpu *cpu_buffer, | 1641 | rb_update_read_stamp(struct ring_buffer_per_cpu *cpu_buffer, |
| @@ -1880,6 +1902,7 @@ rb_buffer_peek(struct ring_buffer *buffer, int cpu, u64 *ts) | |||
| 1880 | 1902 | ||
| 1881 | return NULL; | 1903 | return NULL; |
| 1882 | } | 1904 | } |
| 1905 | EXPORT_SYMBOL_GPL(ring_buffer_peek); | ||
| 1883 | 1906 | ||
| 1884 | static struct ring_buffer_event * | 1907 | static struct ring_buffer_event * |
| 1885 | rb_iter_peek(struct ring_buffer_iter *iter, u64 *ts) | 1908 | rb_iter_peek(struct ring_buffer_iter *iter, u64 *ts) |
| @@ -1940,6 +1963,7 @@ rb_iter_peek(struct ring_buffer_iter *iter, u64 *ts) | |||
| 1940 | 1963 | ||
| 1941 | return NULL; | 1964 | return NULL; |
| 1942 | } | 1965 | } |
| 1966 | EXPORT_SYMBOL_GPL(ring_buffer_iter_peek); | ||
| 1943 | 1967 | ||
| 1944 | /** | 1968 | /** |
| 1945 | * ring_buffer_peek - peek at the next event to be read | 1969 | * ring_buffer_peek - peek at the next event to be read |
| @@ -2017,6 +2041,7 @@ ring_buffer_consume(struct ring_buffer *buffer, int cpu, u64 *ts) | |||
| 2017 | 2041 | ||
| 2018 | return event; | 2042 | return event; |
| 2019 | } | 2043 | } |
| 2044 | EXPORT_SYMBOL_GPL(ring_buffer_consume); | ||
| 2020 | 2045 | ||
| 2021 | /** | 2046 | /** |
| 2022 | * ring_buffer_read_start - start a non consuming read of the buffer | 2047 | * ring_buffer_read_start - start a non consuming read of the buffer |
| @@ -2059,6 +2084,7 @@ ring_buffer_read_start(struct ring_buffer *buffer, int cpu) | |||
| 2059 | 2084 | ||
| 2060 | return iter; | 2085 | return iter; |
| 2061 | } | 2086 | } |
| 2087 | EXPORT_SYMBOL_GPL(ring_buffer_read_start); | ||
| 2062 | 2088 | ||
| 2063 | /** | 2089 | /** |
| 2064 | * ring_buffer_finish - finish reading the iterator of the buffer | 2090 | * ring_buffer_finish - finish reading the iterator of the buffer |
| @@ -2075,6 +2101,7 @@ ring_buffer_read_finish(struct ring_buffer_iter *iter) | |||
| 2075 | atomic_dec(&cpu_buffer->record_disabled); | 2101 | atomic_dec(&cpu_buffer->record_disabled); |
| 2076 | kfree(iter); | 2102 | kfree(iter); |
| 2077 | } | 2103 | } |
| 2104 | EXPORT_SYMBOL_GPL(ring_buffer_read_finish); | ||
| 2078 | 2105 | ||
| 2079 | /** | 2106 | /** |
| 2080 | * ring_buffer_read - read the next item in the ring buffer by the iterator | 2107 | * ring_buffer_read - read the next item in the ring buffer by the iterator |
| @@ -2101,6 +2128,7 @@ ring_buffer_read(struct ring_buffer_iter *iter, u64 *ts) | |||
| 2101 | 2128 | ||
| 2102 | return event; | 2129 | return event; |
| 2103 | } | 2130 | } |
| 2131 | EXPORT_SYMBOL_GPL(ring_buffer_read); | ||
| 2104 | 2132 | ||
| 2105 | /** | 2133 | /** |
| 2106 | * ring_buffer_size - return the size of the ring buffer (in bytes) | 2134 | * ring_buffer_size - return the size of the ring buffer (in bytes) |
| @@ -2110,6 +2138,7 @@ unsigned long ring_buffer_size(struct ring_buffer *buffer) | |||
| 2110 | { | 2138 | { |
| 2111 | return BUF_PAGE_SIZE * buffer->pages; | 2139 | return BUF_PAGE_SIZE * buffer->pages; |
| 2112 | } | 2140 | } |
| 2141 | EXPORT_SYMBOL_GPL(ring_buffer_size); | ||
| 2113 | 2142 | ||
| 2114 | static void | 2143 | static void |
| 2115 | rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer) | 2144 | rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer) |
| @@ -2156,6 +2185,7 @@ void ring_buffer_reset_cpu(struct ring_buffer *buffer, int cpu) | |||
| 2156 | 2185 | ||
| 2157 | spin_unlock_irqrestore(&cpu_buffer->reader_lock, flags); | 2186 | spin_unlock_irqrestore(&cpu_buffer->reader_lock, flags); |
| 2158 | } | 2187 | } |
| 2188 | EXPORT_SYMBOL_GPL(ring_buffer_reset_cpu); | ||
| 2159 | 2189 | ||
| 2160 | /** | 2190 | /** |
| 2161 | * ring_buffer_reset - reset a ring buffer | 2191 | * ring_buffer_reset - reset a ring buffer |
| @@ -2168,6 +2198,7 @@ void ring_buffer_reset(struct ring_buffer *buffer) | |||
| 2168 | for_each_buffer_cpu(buffer, cpu) | 2198 | for_each_buffer_cpu(buffer, cpu) |
| 2169 | ring_buffer_reset_cpu(buffer, cpu); | 2199 | ring_buffer_reset_cpu(buffer, cpu); |
| 2170 | } | 2200 | } |
| 2201 | EXPORT_SYMBOL_GPL(ring_buffer_reset); | ||
| 2171 | 2202 | ||
| 2172 | /** | 2203 | /** |
| 2173 | * rind_buffer_empty - is the ring buffer empty? | 2204 | * rind_buffer_empty - is the ring buffer empty? |
| @@ -2186,6 +2217,7 @@ int ring_buffer_empty(struct ring_buffer *buffer) | |||
| 2186 | } | 2217 | } |
| 2187 | return 1; | 2218 | return 1; |
| 2188 | } | 2219 | } |
| 2220 | EXPORT_SYMBOL_GPL(ring_buffer_empty); | ||
| 2189 | 2221 | ||
| 2190 | /** | 2222 | /** |
| 2191 | * ring_buffer_empty_cpu - is a cpu buffer of a ring buffer empty? | 2223 | * ring_buffer_empty_cpu - is a cpu buffer of a ring buffer empty? |
| @@ -2202,6 +2234,7 @@ int ring_buffer_empty_cpu(struct ring_buffer *buffer, int cpu) | |||
| 2202 | cpu_buffer = buffer->buffers[cpu]; | 2234 | cpu_buffer = buffer->buffers[cpu]; |
| 2203 | return rb_per_cpu_empty(cpu_buffer); | 2235 | return rb_per_cpu_empty(cpu_buffer); |
| 2204 | } | 2236 | } |
| 2237 | EXPORT_SYMBOL_GPL(ring_buffer_empty_cpu); | ||
| 2205 | 2238 | ||
| 2206 | /** | 2239 | /** |
| 2207 | * ring_buffer_swap_cpu - swap a CPU buffer between two ring buffers | 2240 | * ring_buffer_swap_cpu - swap a CPU buffer between two ring buffers |
| @@ -2250,6 +2283,7 @@ int ring_buffer_swap_cpu(struct ring_buffer *buffer_a, | |||
| 2250 | 2283 | ||
| 2251 | return 0; | 2284 | return 0; |
| 2252 | } | 2285 | } |
| 2286 | EXPORT_SYMBOL_GPL(ring_buffer_swap_cpu); | ||
| 2253 | 2287 | ||
| 2254 | static void rb_remove_entries(struct ring_buffer_per_cpu *cpu_buffer, | 2288 | static void rb_remove_entries(struct ring_buffer_per_cpu *cpu_buffer, |
| 2255 | struct buffer_data_page *bpage) | 2289 | struct buffer_data_page *bpage) |
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index f4bb3800318b..3608f6cb2f7a 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c | |||
| @@ -1310,7 +1310,7 @@ enum trace_file_type { | |||
| 1310 | TRACE_FILE_ANNOTATE = 2, | 1310 | TRACE_FILE_ANNOTATE = 2, |
| 1311 | }; | 1311 | }; |
| 1312 | 1312 | ||
| 1313 | static void trace_iterator_increment(struct trace_iterator *iter, int cpu) | 1313 | static void trace_iterator_increment(struct trace_iterator *iter) |
| 1314 | { | 1314 | { |
| 1315 | /* Don't allow ftrace to trace into the ring buffers */ | 1315 | /* Don't allow ftrace to trace into the ring buffers */ |
| 1316 | ftrace_disable_cpu(); | 1316 | ftrace_disable_cpu(); |
| @@ -1389,7 +1389,7 @@ static void *find_next_entry_inc(struct trace_iterator *iter) | |||
| 1389 | iter->ent = __find_next_entry(iter, &iter->cpu, &iter->ts); | 1389 | iter->ent = __find_next_entry(iter, &iter->cpu, &iter->ts); |
| 1390 | 1390 | ||
| 1391 | if (iter->ent) | 1391 | if (iter->ent) |
| 1392 | trace_iterator_increment(iter, iter->cpu); | 1392 | trace_iterator_increment(iter); |
| 1393 | 1393 | ||
| 1394 | return iter->ent ? iter : NULL; | 1394 | return iter->ent ? iter : NULL; |
| 1395 | } | 1395 | } |
