diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2008-12-28 15:21:10 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-12-28 15:21:10 -0500 |
commit | b0f4b285d7ed174804658539129a834270f4829a (patch) | |
tree | be7f8dca58075aba2c6a137fcfd4d44c5c333efc /block/blktrace.c | |
parent | be9c5ae4eeec2e85527e95647348b8ea4eb25128 (diff) | |
parent | 5250d329e38cdf7580faeb9c53c17d3588d7d19c (diff) |
Merge branch 'tracing-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip
* 'tracing-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip: (241 commits)
sched, trace: update trace_sched_wakeup()
tracing/ftrace: don't trace on early stage of a secondary cpu boot, v3
Revert "x86: disable X86_PTRACE_BTS"
ring-buffer: prevent false positive warning
ring-buffer: fix dangling commit race
ftrace: enable format arguments checking
x86, bts: memory accounting
x86, bts: add fork and exit handling
ftrace: introduce tracing_reset_online_cpus() helper
tracing: fix warnings in kernel/trace/trace_sched_switch.c
tracing: fix warning in kernel/trace/trace.c
tracing/ring-buffer: remove unused ring_buffer size
trace: fix task state printout
ftrace: add not to regex on filtering functions
trace: better use of stack_trace_enabled for boot up code
trace: add a way to enable or disable the stack tracer
x86: entry_64 - introduce FTRACE_ frame macro v2
tracing/ftrace: add the printk-msg-only option
tracing/ftrace: use preempt_enable_no_resched_notrace in ring_buffer_time_stamp()
x86, bts: correctly report invalid bts records
...
Fixed up trivial conflict in scripts/recordmcount.pl due to SH bits
being already partly merged by the SH merge.
Diffstat (limited to 'block/blktrace.c')
-rw-r--r-- | block/blktrace.c | 332 |
1 files changed, 329 insertions, 3 deletions
diff --git a/block/blktrace.c b/block/blktrace.c index 85049a7e7a17..b0a2cae886db 100644 --- a/block/blktrace.c +++ b/block/blktrace.c | |||
@@ -23,10 +23,18 @@ | |||
23 | #include <linux/mutex.h> | 23 | #include <linux/mutex.h> |
24 | #include <linux/debugfs.h> | 24 | #include <linux/debugfs.h> |
25 | #include <linux/time.h> | 25 | #include <linux/time.h> |
26 | #include <trace/block.h> | ||
26 | #include <asm/uaccess.h> | 27 | #include <asm/uaccess.h> |
27 | 28 | ||
28 | static unsigned int blktrace_seq __read_mostly = 1; | 29 | static unsigned int blktrace_seq __read_mostly = 1; |
29 | 30 | ||
31 | /* Global reference count of probes */ | ||
32 | static DEFINE_MUTEX(blk_probe_mutex); | ||
33 | static atomic_t blk_probes_ref = ATOMIC_INIT(0); | ||
34 | |||
35 | static int blk_register_tracepoints(void); | ||
36 | static void blk_unregister_tracepoints(void); | ||
37 | |||
30 | /* | 38 | /* |
31 | * Send out a notify message. | 39 | * Send out a notify message. |
32 | */ | 40 | */ |
@@ -119,7 +127,7 @@ static u32 ddir_act[2] __read_mostly = { BLK_TC_ACT(BLK_TC_READ), BLK_TC_ACT(BLK | |||
119 | * The worker for the various blk_add_trace*() types. Fills out a | 127 | * The worker for the various blk_add_trace*() types. Fills out a |
120 | * blk_io_trace structure and places it in a per-cpu subbuffer. | 128 | * blk_io_trace structure and places it in a per-cpu subbuffer. |
121 | */ | 129 | */ |
122 | void __blk_add_trace(struct blk_trace *bt, sector_t sector, int bytes, | 130 | static void __blk_add_trace(struct blk_trace *bt, sector_t sector, int bytes, |
123 | int rw, u32 what, int error, int pdu_len, void *pdu_data) | 131 | int rw, u32 what, int error, int pdu_len, void *pdu_data) |
124 | { | 132 | { |
125 | struct task_struct *tsk = current; | 133 | struct task_struct *tsk = current; |
@@ -177,8 +185,6 @@ void __blk_add_trace(struct blk_trace *bt, sector_t sector, int bytes, | |||
177 | local_irq_restore(flags); | 185 | local_irq_restore(flags); |
178 | } | 186 | } |
179 | 187 | ||
180 | EXPORT_SYMBOL_GPL(__blk_add_trace); | ||
181 | |||
182 | static struct dentry *blk_tree_root; | 188 | static struct dentry *blk_tree_root; |
183 | static DEFINE_MUTEX(blk_tree_mutex); | 189 | static DEFINE_MUTEX(blk_tree_mutex); |
184 | static unsigned int root_users; | 190 | static unsigned int root_users; |
@@ -237,6 +243,10 @@ static void blk_trace_cleanup(struct blk_trace *bt) | |||
237 | free_percpu(bt->sequence); | 243 | free_percpu(bt->sequence); |
238 | free_percpu(bt->msg_data); | 244 | free_percpu(bt->msg_data); |
239 | kfree(bt); | 245 | kfree(bt); |
246 | mutex_lock(&blk_probe_mutex); | ||
247 | if (atomic_dec_and_test(&blk_probes_ref)) | ||
248 | blk_unregister_tracepoints(); | ||
249 | mutex_unlock(&blk_probe_mutex); | ||
240 | } | 250 | } |
241 | 251 | ||
242 | int blk_trace_remove(struct request_queue *q) | 252 | int blk_trace_remove(struct request_queue *q) |
@@ -428,6 +438,14 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev, | |||
428 | bt->pid = buts->pid; | 438 | bt->pid = buts->pid; |
429 | bt->trace_state = Blktrace_setup; | 439 | bt->trace_state = Blktrace_setup; |
430 | 440 | ||
441 | mutex_lock(&blk_probe_mutex); | ||
442 | if (atomic_add_return(1, &blk_probes_ref) == 1) { | ||
443 | ret = blk_register_tracepoints(); | ||
444 | if (ret) | ||
445 | goto probe_err; | ||
446 | } | ||
447 | mutex_unlock(&blk_probe_mutex); | ||
448 | |||
431 | ret = -EBUSY; | 449 | ret = -EBUSY; |
432 | old_bt = xchg(&q->blk_trace, bt); | 450 | old_bt = xchg(&q->blk_trace, bt); |
433 | if (old_bt) { | 451 | if (old_bt) { |
@@ -436,6 +454,9 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev, | |||
436 | } | 454 | } |
437 | 455 | ||
438 | return 0; | 456 | return 0; |
457 | probe_err: | ||
458 | atomic_dec(&blk_probes_ref); | ||
459 | mutex_unlock(&blk_probe_mutex); | ||
439 | err: | 460 | err: |
440 | if (dir) | 461 | if (dir) |
441 | blk_remove_tree(dir); | 462 | blk_remove_tree(dir); |
@@ -562,3 +583,308 @@ void blk_trace_shutdown(struct request_queue *q) | |||
562 | blk_trace_remove(q); | 583 | blk_trace_remove(q); |
563 | } | 584 | } |
564 | } | 585 | } |
586 | |||
587 | /* | ||
588 | * blktrace probes | ||
589 | */ | ||
590 | |||
591 | /** | ||
592 | * blk_add_trace_rq - Add a trace for a request oriented action | ||
593 | * @q: queue the io is for | ||
594 | * @rq: the source request | ||
595 | * @what: the action | ||
596 | * | ||
597 | * Description: | ||
598 | * Records an action against a request. Will log the bio offset + size. | ||
599 | * | ||
600 | **/ | ||
601 | static void blk_add_trace_rq(struct request_queue *q, struct request *rq, | ||
602 | u32 what) | ||
603 | { | ||
604 | struct blk_trace *bt = q->blk_trace; | ||
605 | int rw = rq->cmd_flags & 0x03; | ||
606 | |||
607 | if (likely(!bt)) | ||
608 | return; | ||
609 | |||
610 | if (blk_discard_rq(rq)) | ||
611 | rw |= (1 << BIO_RW_DISCARD); | ||
612 | |||
613 | if (blk_pc_request(rq)) { | ||
614 | what |= BLK_TC_ACT(BLK_TC_PC); | ||
615 | __blk_add_trace(bt, 0, rq->data_len, rw, what, rq->errors, | ||
616 | sizeof(rq->cmd), rq->cmd); | ||
617 | } else { | ||
618 | what |= BLK_TC_ACT(BLK_TC_FS); | ||
619 | __blk_add_trace(bt, rq->hard_sector, rq->hard_nr_sectors << 9, | ||
620 | rw, what, rq->errors, 0, NULL); | ||
621 | } | ||
622 | } | ||
623 | |||
624 | static void blk_add_trace_rq_abort(struct request_queue *q, struct request *rq) | ||
625 | { | ||
626 | blk_add_trace_rq(q, rq, BLK_TA_ABORT); | ||
627 | } | ||
628 | |||
629 | static void blk_add_trace_rq_insert(struct request_queue *q, struct request *rq) | ||
630 | { | ||
631 | blk_add_trace_rq(q, rq, BLK_TA_INSERT); | ||
632 | } | ||
633 | |||
634 | static void blk_add_trace_rq_issue(struct request_queue *q, struct request *rq) | ||
635 | { | ||
636 | blk_add_trace_rq(q, rq, BLK_TA_ISSUE); | ||
637 | } | ||
638 | |||
639 | static void blk_add_trace_rq_requeue(struct request_queue *q, struct request *rq) | ||
640 | { | ||
641 | blk_add_trace_rq(q, rq, BLK_TA_REQUEUE); | ||
642 | } | ||
643 | |||
644 | static void blk_add_trace_rq_complete(struct request_queue *q, struct request *rq) | ||
645 | { | ||
646 | blk_add_trace_rq(q, rq, BLK_TA_COMPLETE); | ||
647 | } | ||
648 | |||
649 | /** | ||
650 | * blk_add_trace_bio - Add a trace for a bio oriented action | ||
651 | * @q: queue the io is for | ||
652 | * @bio: the source bio | ||
653 | * @what: the action | ||
654 | * | ||
655 | * Description: | ||
656 | * Records an action against a bio. Will log the bio offset + size. | ||
657 | * | ||
658 | **/ | ||
659 | static void blk_add_trace_bio(struct request_queue *q, struct bio *bio, | ||
660 | u32 what) | ||
661 | { | ||
662 | struct blk_trace *bt = q->blk_trace; | ||
663 | |||
664 | if (likely(!bt)) | ||
665 | return; | ||
666 | |||
667 | __blk_add_trace(bt, bio->bi_sector, bio->bi_size, bio->bi_rw, what, | ||
668 | !bio_flagged(bio, BIO_UPTODATE), 0, NULL); | ||
669 | } | ||
670 | |||
671 | static void blk_add_trace_bio_bounce(struct request_queue *q, struct bio *bio) | ||
672 | { | ||
673 | blk_add_trace_bio(q, bio, BLK_TA_BOUNCE); | ||
674 | } | ||
675 | |||
676 | static void blk_add_trace_bio_complete(struct request_queue *q, struct bio *bio) | ||
677 | { | ||
678 | blk_add_trace_bio(q, bio, BLK_TA_COMPLETE); | ||
679 | } | ||
680 | |||
681 | static void blk_add_trace_bio_backmerge(struct request_queue *q, struct bio *bio) | ||
682 | { | ||
683 | blk_add_trace_bio(q, bio, BLK_TA_BACKMERGE); | ||
684 | } | ||
685 | |||
686 | static void blk_add_trace_bio_frontmerge(struct request_queue *q, struct bio *bio) | ||
687 | { | ||
688 | blk_add_trace_bio(q, bio, BLK_TA_FRONTMERGE); | ||
689 | } | ||
690 | |||
691 | static void blk_add_trace_bio_queue(struct request_queue *q, struct bio *bio) | ||
692 | { | ||
693 | blk_add_trace_bio(q, bio, BLK_TA_QUEUE); | ||
694 | } | ||
695 | |||
696 | static void blk_add_trace_getrq(struct request_queue *q, struct bio *bio, int rw) | ||
697 | { | ||
698 | if (bio) | ||
699 | blk_add_trace_bio(q, bio, BLK_TA_GETRQ); | ||
700 | else { | ||
701 | struct blk_trace *bt = q->blk_trace; | ||
702 | |||
703 | if (bt) | ||
704 | __blk_add_trace(bt, 0, 0, rw, BLK_TA_GETRQ, 0, 0, NULL); | ||
705 | } | ||
706 | } | ||
707 | |||
708 | |||
709 | static void blk_add_trace_sleeprq(struct request_queue *q, struct bio *bio, int rw) | ||
710 | { | ||
711 | if (bio) | ||
712 | blk_add_trace_bio(q, bio, BLK_TA_SLEEPRQ); | ||
713 | else { | ||
714 | struct blk_trace *bt = q->blk_trace; | ||
715 | |||
716 | if (bt) | ||
717 | __blk_add_trace(bt, 0, 0, rw, BLK_TA_SLEEPRQ, 0, 0, NULL); | ||
718 | } | ||
719 | } | ||
720 | |||
721 | static void blk_add_trace_plug(struct request_queue *q) | ||
722 | { | ||
723 | struct blk_trace *bt = q->blk_trace; | ||
724 | |||
725 | if (bt) | ||
726 | __blk_add_trace(bt, 0, 0, 0, BLK_TA_PLUG, 0, 0, NULL); | ||
727 | } | ||
728 | |||
729 | static void blk_add_trace_unplug_io(struct request_queue *q) | ||
730 | { | ||
731 | struct blk_trace *bt = q->blk_trace; | ||
732 | |||
733 | if (bt) { | ||
734 | unsigned int pdu = q->rq.count[READ] + q->rq.count[WRITE]; | ||
735 | __be64 rpdu = cpu_to_be64(pdu); | ||
736 | |||
737 | __blk_add_trace(bt, 0, 0, 0, BLK_TA_UNPLUG_IO, 0, | ||
738 | sizeof(rpdu), &rpdu); | ||
739 | } | ||
740 | } | ||
741 | |||
742 | static void blk_add_trace_unplug_timer(struct request_queue *q) | ||
743 | { | ||
744 | struct blk_trace *bt = q->blk_trace; | ||
745 | |||
746 | if (bt) { | ||
747 | unsigned int pdu = q->rq.count[READ] + q->rq.count[WRITE]; | ||
748 | __be64 rpdu = cpu_to_be64(pdu); | ||
749 | |||
750 | __blk_add_trace(bt, 0, 0, 0, BLK_TA_UNPLUG_TIMER, 0, | ||
751 | sizeof(rpdu), &rpdu); | ||
752 | } | ||
753 | } | ||
754 | |||
755 | static void blk_add_trace_split(struct request_queue *q, struct bio *bio, | ||
756 | unsigned int pdu) | ||
757 | { | ||
758 | struct blk_trace *bt = q->blk_trace; | ||
759 | |||
760 | if (bt) { | ||
761 | __be64 rpdu = cpu_to_be64(pdu); | ||
762 | |||
763 | __blk_add_trace(bt, bio->bi_sector, bio->bi_size, bio->bi_rw, | ||
764 | BLK_TA_SPLIT, !bio_flagged(bio, BIO_UPTODATE), | ||
765 | sizeof(rpdu), &rpdu); | ||
766 | } | ||
767 | } | ||
768 | |||
769 | /** | ||
770 | * blk_add_trace_remap - Add a trace for a remap operation | ||
771 | * @q: queue the io is for | ||
772 | * @bio: the source bio | ||
773 | * @dev: target device | ||
774 | * @from: source sector | ||
775 | * @to: target sector | ||
776 | * | ||
777 | * Description: | ||
778 | * Device mapper or raid target sometimes need to split a bio because | ||
779 | * it spans a stripe (or similar). Add a trace for that action. | ||
780 | * | ||
781 | **/ | ||
782 | static void blk_add_trace_remap(struct request_queue *q, struct bio *bio, | ||
783 | dev_t dev, sector_t from, sector_t to) | ||
784 | { | ||
785 | struct blk_trace *bt = q->blk_trace; | ||
786 | struct blk_io_trace_remap r; | ||
787 | |||
788 | if (likely(!bt)) | ||
789 | return; | ||
790 | |||
791 | r.device = cpu_to_be32(dev); | ||
792 | r.device_from = cpu_to_be32(bio->bi_bdev->bd_dev); | ||
793 | r.sector = cpu_to_be64(to); | ||
794 | |||
795 | __blk_add_trace(bt, from, bio->bi_size, bio->bi_rw, BLK_TA_REMAP, | ||
796 | !bio_flagged(bio, BIO_UPTODATE), sizeof(r), &r); | ||
797 | } | ||
798 | |||
799 | /** | ||
800 | * blk_add_driver_data - Add binary message with driver-specific data | ||
801 | * @q: queue the io is for | ||
802 | * @rq: io request | ||
803 | * @data: driver-specific data | ||
804 | * @len: length of driver-specific data | ||
805 | * | ||
806 | * Description: | ||
807 | * Some drivers might want to write driver-specific data per request. | ||
808 | * | ||
809 | **/ | ||
810 | void blk_add_driver_data(struct request_queue *q, | ||
811 | struct request *rq, | ||
812 | void *data, size_t len) | ||
813 | { | ||
814 | struct blk_trace *bt = q->blk_trace; | ||
815 | |||
816 | if (likely(!bt)) | ||
817 | return; | ||
818 | |||
819 | if (blk_pc_request(rq)) | ||
820 | __blk_add_trace(bt, 0, rq->data_len, 0, BLK_TA_DRV_DATA, | ||
821 | rq->errors, len, data); | ||
822 | else | ||
823 | __blk_add_trace(bt, rq->hard_sector, rq->hard_nr_sectors << 9, | ||
824 | 0, BLK_TA_DRV_DATA, rq->errors, len, data); | ||
825 | } | ||
826 | EXPORT_SYMBOL_GPL(blk_add_driver_data); | ||
827 | |||
828 | static int blk_register_tracepoints(void) | ||
829 | { | ||
830 | int ret; | ||
831 | |||
832 | ret = register_trace_block_rq_abort(blk_add_trace_rq_abort); | ||
833 | WARN_ON(ret); | ||
834 | ret = register_trace_block_rq_insert(blk_add_trace_rq_insert); | ||
835 | WARN_ON(ret); | ||
836 | ret = register_trace_block_rq_issue(blk_add_trace_rq_issue); | ||
837 | WARN_ON(ret); | ||
838 | ret = register_trace_block_rq_requeue(blk_add_trace_rq_requeue); | ||
839 | WARN_ON(ret); | ||
840 | ret = register_trace_block_rq_complete(blk_add_trace_rq_complete); | ||
841 | WARN_ON(ret); | ||
842 | ret = register_trace_block_bio_bounce(blk_add_trace_bio_bounce); | ||
843 | WARN_ON(ret); | ||
844 | ret = register_trace_block_bio_complete(blk_add_trace_bio_complete); | ||
845 | WARN_ON(ret); | ||
846 | ret = register_trace_block_bio_backmerge(blk_add_trace_bio_backmerge); | ||
847 | WARN_ON(ret); | ||
848 | ret = register_trace_block_bio_frontmerge(blk_add_trace_bio_frontmerge); | ||
849 | WARN_ON(ret); | ||
850 | ret = register_trace_block_bio_queue(blk_add_trace_bio_queue); | ||
851 | WARN_ON(ret); | ||
852 | ret = register_trace_block_getrq(blk_add_trace_getrq); | ||
853 | WARN_ON(ret); | ||
854 | ret = register_trace_block_sleeprq(blk_add_trace_sleeprq); | ||
855 | WARN_ON(ret); | ||
856 | ret = register_trace_block_plug(blk_add_trace_plug); | ||
857 | WARN_ON(ret); | ||
858 | ret = register_trace_block_unplug_timer(blk_add_trace_unplug_timer); | ||
859 | WARN_ON(ret); | ||
860 | ret = register_trace_block_unplug_io(blk_add_trace_unplug_io); | ||
861 | WARN_ON(ret); | ||
862 | ret = register_trace_block_split(blk_add_trace_split); | ||
863 | WARN_ON(ret); | ||
864 | ret = register_trace_block_remap(blk_add_trace_remap); | ||
865 | WARN_ON(ret); | ||
866 | return 0; | ||
867 | } | ||
868 | |||
869 | static void blk_unregister_tracepoints(void) | ||
870 | { | ||
871 | unregister_trace_block_remap(blk_add_trace_remap); | ||
872 | unregister_trace_block_split(blk_add_trace_split); | ||
873 | unregister_trace_block_unplug_io(blk_add_trace_unplug_io); | ||
874 | unregister_trace_block_unplug_timer(blk_add_trace_unplug_timer); | ||
875 | unregister_trace_block_plug(blk_add_trace_plug); | ||
876 | unregister_trace_block_sleeprq(blk_add_trace_sleeprq); | ||
877 | unregister_trace_block_getrq(blk_add_trace_getrq); | ||
878 | unregister_trace_block_bio_queue(blk_add_trace_bio_queue); | ||
879 | unregister_trace_block_bio_frontmerge(blk_add_trace_bio_frontmerge); | ||
880 | unregister_trace_block_bio_backmerge(blk_add_trace_bio_backmerge); | ||
881 | unregister_trace_block_bio_complete(blk_add_trace_bio_complete); | ||
882 | unregister_trace_block_bio_bounce(blk_add_trace_bio_bounce); | ||
883 | unregister_trace_block_rq_complete(blk_add_trace_rq_complete); | ||
884 | unregister_trace_block_rq_requeue(blk_add_trace_rq_requeue); | ||
885 | unregister_trace_block_rq_issue(blk_add_trace_rq_issue); | ||
886 | unregister_trace_block_rq_insert(blk_add_trace_rq_insert); | ||
887 | unregister_trace_block_rq_abort(blk_add_trace_rq_abort); | ||
888 | |||
889 | tracepoint_synchronize_unregister(); | ||
890 | } | ||