diff options
75 files changed, 1847 insertions, 3147 deletions
diff --git a/arch/sparc/kernel/perf_event.c b/arch/sparc/kernel/perf_event.c index 34ce49f80eac..0ec92c8861dd 100644 --- a/arch/sparc/kernel/perf_event.c +++ b/arch/sparc/kernel/perf_event.c | |||
@@ -92,6 +92,8 @@ struct cpu_hw_events { | |||
92 | 92 | ||
93 | /* Enabled/disable state. */ | 93 | /* Enabled/disable state. */ |
94 | int enabled; | 94 | int enabled; |
95 | |||
96 | unsigned int group_flag; | ||
95 | }; | 97 | }; |
96 | DEFINE_PER_CPU(struct cpu_hw_events, cpu_hw_events) = { .enabled = 1, }; | 98 | DEFINE_PER_CPU(struct cpu_hw_events, cpu_hw_events) = { .enabled = 1, }; |
97 | 99 | ||
@@ -981,53 +983,6 @@ static int collect_events(struct perf_event *group, int max_count, | |||
981 | return n; | 983 | return n; |
982 | } | 984 | } |
983 | 985 | ||
984 | static void event_sched_in(struct perf_event *event) | ||
985 | { | ||
986 | event->state = PERF_EVENT_STATE_ACTIVE; | ||
987 | event->oncpu = smp_processor_id(); | ||
988 | event->tstamp_running += event->ctx->time - event->tstamp_stopped; | ||
989 | if (is_software_event(event)) | ||
990 | event->pmu->enable(event); | ||
991 | } | ||
992 | |||
993 | int hw_perf_group_sched_in(struct perf_event *group_leader, | ||
994 | struct perf_cpu_context *cpuctx, | ||
995 | struct perf_event_context *ctx) | ||
996 | { | ||
997 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | ||
998 | struct perf_event *sub; | ||
999 | int n0, n; | ||
1000 | |||
1001 | if (!sparc_pmu) | ||
1002 | return 0; | ||
1003 | |||
1004 | n0 = cpuc->n_events; | ||
1005 | n = collect_events(group_leader, perf_max_events - n0, | ||
1006 | &cpuc->event[n0], &cpuc->events[n0], | ||
1007 | &cpuc->current_idx[n0]); | ||
1008 | if (n < 0) | ||
1009 | return -EAGAIN; | ||
1010 | if (check_excludes(cpuc->event, n0, n)) | ||
1011 | return -EINVAL; | ||
1012 | if (sparc_check_constraints(cpuc->event, cpuc->events, n + n0)) | ||
1013 | return -EAGAIN; | ||
1014 | cpuc->n_events = n0 + n; | ||
1015 | cpuc->n_added += n; | ||
1016 | |||
1017 | cpuctx->active_oncpu += n; | ||
1018 | n = 1; | ||
1019 | event_sched_in(group_leader); | ||
1020 | list_for_each_entry(sub, &group_leader->sibling_list, group_entry) { | ||
1021 | if (sub->state != PERF_EVENT_STATE_OFF) { | ||
1022 | event_sched_in(sub); | ||
1023 | n++; | ||
1024 | } | ||
1025 | } | ||
1026 | ctx->nr_active += n; | ||
1027 | |||
1028 | return 1; | ||
1029 | } | ||
1030 | |||
1031 | static int sparc_pmu_enable(struct perf_event *event) | 986 | static int sparc_pmu_enable(struct perf_event *event) |
1032 | { | 987 | { |
1033 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | 988 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); |
@@ -1045,11 +1000,20 @@ static int sparc_pmu_enable(struct perf_event *event) | |||
1045 | cpuc->events[n0] = event->hw.event_base; | 1000 | cpuc->events[n0] = event->hw.event_base; |
1046 | cpuc->current_idx[n0] = PIC_NO_INDEX; | 1001 | cpuc->current_idx[n0] = PIC_NO_INDEX; |
1047 | 1002 | ||
1003 | /* | ||
1004 | * If group events scheduling transaction was started, | ||
1005 | * skip the schedulability test here, it will be peformed | ||
1006 | * at commit time(->commit_txn) as a whole | ||
1007 | */ | ||
1008 | if (cpuc->group_flag & PERF_EVENT_TXN_STARTED) | ||
1009 | goto nocheck; | ||
1010 | |||
1048 | if (check_excludes(cpuc->event, n0, 1)) | 1011 | if (check_excludes(cpuc->event, n0, 1)) |
1049 | goto out; | 1012 | goto out; |
1050 | if (sparc_check_constraints(cpuc->event, cpuc->events, n0 + 1)) | 1013 | if (sparc_check_constraints(cpuc->event, cpuc->events, n0 + 1)) |
1051 | goto out; | 1014 | goto out; |
1052 | 1015 | ||
1016 | nocheck: | ||
1053 | cpuc->n_events++; | 1017 | cpuc->n_events++; |
1054 | cpuc->n_added++; | 1018 | cpuc->n_added++; |
1055 | 1019 | ||
@@ -1129,11 +1093,61 @@ static int __hw_perf_event_init(struct perf_event *event) | |||
1129 | return 0; | 1093 | return 0; |
1130 | } | 1094 | } |
1131 | 1095 | ||
1096 | /* | ||
1097 | * Start group events scheduling transaction | ||
1098 | * Set the flag to make pmu::enable() not perform the | ||
1099 | * schedulability test, it will be performed at commit time | ||
1100 | */ | ||
1101 | static void sparc_pmu_start_txn(const struct pmu *pmu) | ||
1102 | { | ||
1103 | struct cpu_hw_events *cpuhw = &__get_cpu_var(cpu_hw_events); | ||
1104 | |||
1105 | cpuhw->group_flag |= PERF_EVENT_TXN_STARTED; | ||
1106 | } | ||
1107 | |||
1108 | /* | ||
1109 | * Stop group events scheduling transaction | ||
1110 | * Clear the flag and pmu::enable() will perform the | ||
1111 | * schedulability test. | ||
1112 | */ | ||
1113 | static void sparc_pmu_cancel_txn(const struct pmu *pmu) | ||
1114 | { | ||
1115 | struct cpu_hw_events *cpuhw = &__get_cpu_var(cpu_hw_events); | ||
1116 | |||
1117 | cpuhw->group_flag &= ~PERF_EVENT_TXN_STARTED; | ||
1118 | } | ||
1119 | |||
1120 | /* | ||
1121 | * Commit group events scheduling transaction | ||
1122 | * Perform the group schedulability test as a whole | ||
1123 | * Return 0 if success | ||
1124 | */ | ||
1125 | static int sparc_pmu_commit_txn(const struct pmu *pmu) | ||
1126 | { | ||
1127 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | ||
1128 | int n; | ||
1129 | |||
1130 | if (!sparc_pmu) | ||
1131 | return -EINVAL; | ||
1132 | |||
1133 | cpuc = &__get_cpu_var(cpu_hw_events); | ||
1134 | n = cpuc->n_events; | ||
1135 | if (check_excludes(cpuc->event, 0, n)) | ||
1136 | return -EINVAL; | ||
1137 | if (sparc_check_constraints(cpuc->event, cpuc->events, n)) | ||
1138 | return -EAGAIN; | ||
1139 | |||
1140 | return 0; | ||
1141 | } | ||
1142 | |||
1132 | static const struct pmu pmu = { | 1143 | static const struct pmu pmu = { |
1133 | .enable = sparc_pmu_enable, | 1144 | .enable = sparc_pmu_enable, |
1134 | .disable = sparc_pmu_disable, | 1145 | .disable = sparc_pmu_disable, |
1135 | .read = sparc_pmu_read, | 1146 | .read = sparc_pmu_read, |
1136 | .unthrottle = sparc_pmu_unthrottle, | 1147 | .unthrottle = sparc_pmu_unthrottle, |
1148 | .start_txn = sparc_pmu_start_txn, | ||
1149 | .cancel_txn = sparc_pmu_cancel_txn, | ||
1150 | .commit_txn = sparc_pmu_commit_txn, | ||
1137 | }; | 1151 | }; |
1138 | 1152 | ||
1139 | const struct pmu *hw_perf_event_init(struct perf_event *event) | 1153 | const struct pmu *hw_perf_event_init(struct perf_event *event) |
diff --git a/arch/x86/include/asm/perf_event_p4.h b/arch/x86/include/asm/perf_event_p4.h index b05400a542ff..64a8ebff06fc 100644 --- a/arch/x86/include/asm/perf_event_p4.h +++ b/arch/x86/include/asm/perf_event_p4.h | |||
@@ -89,7 +89,8 @@ | |||
89 | P4_CCCR_ENABLE) | 89 | P4_CCCR_ENABLE) |
90 | 90 | ||
91 | /* HT mask */ | 91 | /* HT mask */ |
92 | #define P4_CCCR_MASK_HT (P4_CCCR_MASK | P4_CCCR_THREAD_ANY) | 92 | #define P4_CCCR_MASK_HT \ |
93 | (P4_CCCR_MASK | P4_CCCR_OVF_PMI_T1 | P4_CCCR_THREAD_ANY) | ||
93 | 94 | ||
94 | #define P4_GEN_ESCR_EMASK(class, name, bit) \ | 95 | #define P4_GEN_ESCR_EMASK(class, name, bit) \ |
95 | class##__##name = ((1 << bit) << P4_ESCR_EVENTMASK_SHIFT) | 96 | class##__##name = ((1 << bit) << P4_ESCR_EVENTMASK_SHIFT) |
diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c index fd4db0db3708..c77586061bcb 100644 --- a/arch/x86/kernel/cpu/perf_event.c +++ b/arch/x86/kernel/cpu/perf_event.c | |||
@@ -1717,7 +1717,11 @@ void perf_arch_fetch_caller_regs(struct pt_regs *regs, unsigned long ip, int ski | |||
1717 | */ | 1717 | */ |
1718 | regs->bp = rewind_frame_pointer(skip + 1); | 1718 | regs->bp = rewind_frame_pointer(skip + 1); |
1719 | regs->cs = __KERNEL_CS; | 1719 | regs->cs = __KERNEL_CS; |
1720 | local_save_flags(regs->flags); | 1720 | /* |
1721 | * We abuse bit 3 to pass exact information, see perf_misc_flags | ||
1722 | * and the comment with PERF_EFLAGS_EXACT. | ||
1723 | */ | ||
1724 | regs->flags = 0; | ||
1721 | } | 1725 | } |
1722 | 1726 | ||
1723 | unsigned long perf_instruction_pointer(struct pt_regs *regs) | 1727 | unsigned long perf_instruction_pointer(struct pt_regs *regs) |
diff --git a/arch/x86/kernel/cpu/perf_event_p4.c b/arch/x86/kernel/cpu/perf_event_p4.c index 424fc8de68e4..ae85d69644d1 100644 --- a/arch/x86/kernel/cpu/perf_event_p4.c +++ b/arch/x86/kernel/cpu/perf_event_p4.c | |||
@@ -465,15 +465,21 @@ out: | |||
465 | return rc; | 465 | return rc; |
466 | } | 466 | } |
467 | 467 | ||
468 | static inline void p4_pmu_clear_cccr_ovf(struct hw_perf_event *hwc) | 468 | static inline int p4_pmu_clear_cccr_ovf(struct hw_perf_event *hwc) |
469 | { | 469 | { |
470 | unsigned long dummy; | 470 | int overflow = 0; |
471 | u32 low, high; | ||
471 | 472 | ||
472 | rdmsrl(hwc->config_base + hwc->idx, dummy); | 473 | rdmsr(hwc->config_base + hwc->idx, low, high); |
473 | if (dummy & P4_CCCR_OVF) { | 474 | |
475 | /* we need to check high bit for unflagged overflows */ | ||
476 | if ((low & P4_CCCR_OVF) || !(high & (1 << 31))) { | ||
477 | overflow = 1; | ||
474 | (void)checking_wrmsrl(hwc->config_base + hwc->idx, | 478 | (void)checking_wrmsrl(hwc->config_base + hwc->idx, |
475 | ((u64)dummy) & ~P4_CCCR_OVF); | 479 | ((u64)low) & ~P4_CCCR_OVF); |
476 | } | 480 | } |
481 | |||
482 | return overflow; | ||
477 | } | 483 | } |
478 | 484 | ||
479 | static inline void p4_pmu_disable_event(struct perf_event *event) | 485 | static inline void p4_pmu_disable_event(struct perf_event *event) |
@@ -584,21 +590,15 @@ static int p4_pmu_handle_irq(struct pt_regs *regs) | |||
584 | 590 | ||
585 | WARN_ON_ONCE(hwc->idx != idx); | 591 | WARN_ON_ONCE(hwc->idx != idx); |
586 | 592 | ||
587 | /* | 593 | /* it might be unflagged overflow */ |
588 | * FIXME: Redundant call, actually not needed | 594 | handled = p4_pmu_clear_cccr_ovf(hwc); |
589 | * but just to check if we're screwed | ||
590 | */ | ||
591 | p4_pmu_clear_cccr_ovf(hwc); | ||
592 | 595 | ||
593 | val = x86_perf_event_update(event); | 596 | val = x86_perf_event_update(event); |
594 | if (val & (1ULL << (x86_pmu.cntval_bits - 1))) | 597 | if (!handled && (val & (1ULL << (x86_pmu.cntval_bits - 1)))) |
595 | continue; | 598 | continue; |
596 | 599 | ||
597 | /* | 600 | /* event overflow for sure */ |
598 | * event overflow | 601 | data.period = event->hw.last_period; |
599 | */ | ||
600 | handled = 1; | ||
601 | data.period = event->hw.last_period; | ||
602 | 602 | ||
603 | if (!x86_perf_event_set_period(event)) | 603 | if (!x86_perf_event_set_period(event)) |
604 | continue; | 604 | continue; |
@@ -670,7 +670,7 @@ static void p4_pmu_swap_config_ts(struct hw_perf_event *hwc, int cpu) | |||
670 | 670 | ||
671 | /* | 671 | /* |
672 | * ESCR address hashing is tricky, ESCRs are not sequential | 672 | * ESCR address hashing is tricky, ESCRs are not sequential |
673 | * in memory but all starts from MSR_P4_BSU_ESCR0 (0x03e0) and | 673 | * in memory but all starts from MSR_P4_BSU_ESCR0 (0x03a0) and |
674 | * the metric between any ESCRs is laid in range [0xa0,0xe1] | 674 | * the metric between any ESCRs is laid in range [0xa0,0xe1] |
675 | * | 675 | * |
676 | * so we make ~70% filled hashtable | 676 | * so we make ~70% filled hashtable |
@@ -735,8 +735,9 @@ static int p4_get_escr_idx(unsigned int addr) | |||
735 | { | 735 | { |
736 | unsigned int idx = P4_ESCR_MSR_IDX(addr); | 736 | unsigned int idx = P4_ESCR_MSR_IDX(addr); |
737 | 737 | ||
738 | if (unlikely(idx >= P4_ESCR_MSR_TABLE_SIZE || | 738 | if (unlikely(idx >= P4_ESCR_MSR_TABLE_SIZE || |
739 | !p4_escr_table[idx])) { | 739 | !p4_escr_table[idx] || |
740 | p4_escr_table[idx] != addr)) { | ||
740 | WARN_ONCE(1, "P4 PMU: Wrong address passed: %x\n", addr); | 741 | WARN_ONCE(1, "P4 PMU: Wrong address passed: %x\n", addr); |
741 | return -1; | 742 | return -1; |
742 | } | 743 | } |
@@ -762,7 +763,7 @@ static int p4_pmu_schedule_events(struct cpu_hw_events *cpuc, int n, int *assign | |||
762 | { | 763 | { |
763 | unsigned long used_mask[BITS_TO_LONGS(X86_PMC_IDX_MAX)]; | 764 | unsigned long used_mask[BITS_TO_LONGS(X86_PMC_IDX_MAX)]; |
764 | unsigned long escr_mask[BITS_TO_LONGS(P4_ESCR_MSR_TABLE_SIZE)]; | 765 | unsigned long escr_mask[BITS_TO_LONGS(P4_ESCR_MSR_TABLE_SIZE)]; |
765 | int cpu = raw_smp_processor_id(); | 766 | int cpu = smp_processor_id(); |
766 | struct hw_perf_event *hwc; | 767 | struct hw_perf_event *hwc; |
767 | struct p4_event_bind *bind; | 768 | struct p4_event_bind *bind; |
768 | unsigned int i, thread, num; | 769 | unsigned int i, thread, num; |
diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c index df3d5c861cda..308e32570d84 100644 --- a/arch/x86/mm/pf_in.c +++ b/arch/x86/mm/pf_in.c | |||
@@ -34,7 +34,7 @@ | |||
34 | /* IA32 Manual 3, 2-1 */ | 34 | /* IA32 Manual 3, 2-1 */ |
35 | static unsigned char prefix_codes[] = { | 35 | static unsigned char prefix_codes[] = { |
36 | 0xF0, 0xF2, 0xF3, 0x2E, 0x36, 0x3E, 0x26, 0x64, | 36 | 0xF0, 0xF2, 0xF3, 0x2E, 0x36, 0x3E, 0x26, 0x64, |
37 | 0x65, 0x2E, 0x3E, 0x66, 0x67 | 37 | 0x65, 0x66, 0x67 |
38 | }; | 38 | }; |
39 | /* IA32 Manual 3, 3-432*/ | 39 | /* IA32 Manual 3, 3-432*/ |
40 | static unsigned int reg_rop[] = { | 40 | static unsigned int reg_rop[] = { |
diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h index c082f223e2fe..3167f2df4126 100644 --- a/include/linux/ftrace_event.h +++ b/include/linux/ftrace_event.h | |||
@@ -73,18 +73,25 @@ struct trace_iterator { | |||
73 | }; | 73 | }; |
74 | 74 | ||
75 | 75 | ||
76 | struct trace_event; | ||
77 | |||
76 | typedef enum print_line_t (*trace_print_func)(struct trace_iterator *iter, | 78 | typedef enum print_line_t (*trace_print_func)(struct trace_iterator *iter, |
77 | int flags); | 79 | int flags, struct trace_event *event); |
78 | struct trace_event { | 80 | |
79 | struct hlist_node node; | 81 | struct trace_event_functions { |
80 | struct list_head list; | ||
81 | int type; | ||
82 | trace_print_func trace; | 82 | trace_print_func trace; |
83 | trace_print_func raw; | 83 | trace_print_func raw; |
84 | trace_print_func hex; | 84 | trace_print_func hex; |
85 | trace_print_func binary; | 85 | trace_print_func binary; |
86 | }; | 86 | }; |
87 | 87 | ||
88 | struct trace_event { | ||
89 | struct hlist_node node; | ||
90 | struct list_head list; | ||
91 | int type; | ||
92 | struct trace_event_functions *funcs; | ||
93 | }; | ||
94 | |||
88 | extern int register_ftrace_event(struct trace_event *event); | 95 | extern int register_ftrace_event(struct trace_event *event); |
89 | extern int unregister_ftrace_event(struct trace_event *event); | 96 | extern int unregister_ftrace_event(struct trace_event *event); |
90 | 97 | ||
@@ -116,28 +123,70 @@ void tracing_record_cmdline(struct task_struct *tsk); | |||
116 | 123 | ||
117 | struct event_filter; | 124 | struct event_filter; |
118 | 125 | ||
126 | enum trace_reg { | ||
127 | TRACE_REG_REGISTER, | ||
128 | TRACE_REG_UNREGISTER, | ||
129 | TRACE_REG_PERF_REGISTER, | ||
130 | TRACE_REG_PERF_UNREGISTER, | ||
131 | }; | ||
132 | |||
133 | struct ftrace_event_call; | ||
134 | |||
135 | struct ftrace_event_class { | ||
136 | char *system; | ||
137 | void *probe; | ||
138 | #ifdef CONFIG_PERF_EVENTS | ||
139 | void *perf_probe; | ||
140 | #endif | ||
141 | int (*reg)(struct ftrace_event_call *event, | ||
142 | enum trace_reg type); | ||
143 | int (*define_fields)(struct ftrace_event_call *); | ||
144 | struct list_head *(*get_fields)(struct ftrace_event_call *); | ||
145 | struct list_head fields; | ||
146 | int (*raw_init)(struct ftrace_event_call *); | ||
147 | }; | ||
148 | |||
149 | enum { | ||
150 | TRACE_EVENT_FL_ENABLED_BIT, | ||
151 | TRACE_EVENT_FL_FILTERED_BIT, | ||
152 | }; | ||
153 | |||
154 | enum { | ||
155 | TRACE_EVENT_FL_ENABLED = (1 << TRACE_EVENT_FL_ENABLED_BIT), | ||
156 | TRACE_EVENT_FL_FILTERED = (1 << TRACE_EVENT_FL_FILTERED_BIT), | ||
157 | }; | ||
158 | |||
119 | struct ftrace_event_call { | 159 | struct ftrace_event_call { |
120 | struct list_head list; | 160 | struct list_head list; |
161 | struct ftrace_event_class *class; | ||
121 | char *name; | 162 | char *name; |
122 | char *system; | ||
123 | struct dentry *dir; | 163 | struct dentry *dir; |
124 | struct trace_event *event; | 164 | struct trace_event event; |
125 | int enabled; | ||
126 | int (*regfunc)(struct ftrace_event_call *); | ||
127 | void (*unregfunc)(struct ftrace_event_call *); | ||
128 | int id; | ||
129 | const char *print_fmt; | 165 | const char *print_fmt; |
130 | int (*raw_init)(struct ftrace_event_call *); | ||
131 | int (*define_fields)(struct ftrace_event_call *); | ||
132 | struct list_head fields; | ||
133 | int filter_active; | ||
134 | struct event_filter *filter; | 166 | struct event_filter *filter; |
135 | void *mod; | 167 | void *mod; |
136 | void *data; | 168 | void *data; |
137 | 169 | ||
170 | /* | ||
171 | * 32 bit flags: | ||
172 | * bit 1: enabled | ||
173 | * bit 2: filter_active | ||
174 | * | ||
175 | * Changes to flags must hold the event_mutex. | ||
176 | * | ||
177 | * Note: Reads of flags do not hold the event_mutex since | ||
178 | * they occur in critical sections. But the way flags | ||
179 | * is currently used, these changes do no affect the code | ||
180 | * except that when a change is made, it may have a slight | ||
181 | * delay in propagating the changes to other CPUs due to | ||
182 | * caching and such. | ||
183 | */ | ||
184 | unsigned int flags; | ||
185 | |||
186 | #ifdef CONFIG_PERF_EVENTS | ||
138 | int perf_refcount; | 187 | int perf_refcount; |
139 | int (*perf_event_enable)(struct ftrace_event_call *); | 188 | struct hlist_head *perf_events; |
140 | void (*perf_event_disable)(struct ftrace_event_call *); | 189 | #endif |
141 | }; | 190 | }; |
142 | 191 | ||
143 | #define PERF_MAX_TRACE_SIZE 2048 | 192 | #define PERF_MAX_TRACE_SIZE 2048 |
@@ -194,24 +243,22 @@ struct perf_event; | |||
194 | 243 | ||
195 | DECLARE_PER_CPU(struct pt_regs, perf_trace_regs); | 244 | DECLARE_PER_CPU(struct pt_regs, perf_trace_regs); |
196 | 245 | ||
197 | extern int perf_trace_enable(int event_id); | 246 | extern int perf_trace_init(struct perf_event *event); |
198 | extern void perf_trace_disable(int event_id); | 247 | extern void perf_trace_destroy(struct perf_event *event); |
199 | extern int ftrace_profile_set_filter(struct perf_event *event, int event_id, | 248 | extern int perf_trace_enable(struct perf_event *event); |
249 | extern void perf_trace_disable(struct perf_event *event); | ||
250 | extern int ftrace_profile_set_filter(struct perf_event *event, int event_id, | ||
200 | char *filter_str); | 251 | char *filter_str); |
201 | extern void ftrace_profile_free_filter(struct perf_event *event); | 252 | extern void ftrace_profile_free_filter(struct perf_event *event); |
202 | extern void * | 253 | extern void *perf_trace_buf_prepare(int size, unsigned short type, |
203 | perf_trace_buf_prepare(int size, unsigned short type, int *rctxp, | 254 | struct pt_regs *regs, int *rctxp); |
204 | unsigned long *irq_flags); | ||
205 | 255 | ||
206 | static inline void | 256 | static inline void |
207 | perf_trace_buf_submit(void *raw_data, int size, int rctx, u64 addr, | 257 | perf_trace_buf_submit(void *raw_data, int size, int rctx, u64 addr, |
208 | u64 count, unsigned long irq_flags, struct pt_regs *regs) | 258 | u64 count, struct pt_regs *regs, void *head) |
209 | { | 259 | { |
210 | struct trace_entry *entry = raw_data; | 260 | perf_tp_event(addr, count, raw_data, size, regs, head); |
211 | |||
212 | perf_tp_event(entry->type, addr, count, raw_data, size, regs); | ||
213 | perf_swevent_put_recursion_context(rctx); | 261 | perf_swevent_put_recursion_context(rctx); |
214 | local_irq_restore(irq_flags); | ||
215 | } | 262 | } |
216 | #endif | 263 | #endif |
217 | 264 | ||
diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index 3fd5c82e0e18..fb6c91eac7e3 100644 --- a/include/linux/perf_event.h +++ b/include/linux/perf_event.h | |||
@@ -485,6 +485,7 @@ struct perf_guest_info_callbacks { | |||
485 | #include <linux/ftrace.h> | 485 | #include <linux/ftrace.h> |
486 | #include <linux/cpu.h> | 486 | #include <linux/cpu.h> |
487 | #include <asm/atomic.h> | 487 | #include <asm/atomic.h> |
488 | #include <asm/local.h> | ||
488 | 489 | ||
489 | #define PERF_MAX_STACK_DEPTH 255 | 490 | #define PERF_MAX_STACK_DEPTH 255 |
490 | 491 | ||
@@ -587,21 +588,19 @@ struct perf_mmap_data { | |||
587 | struct rcu_head rcu_head; | 588 | struct rcu_head rcu_head; |
588 | #ifdef CONFIG_PERF_USE_VMALLOC | 589 | #ifdef CONFIG_PERF_USE_VMALLOC |
589 | struct work_struct work; | 590 | struct work_struct work; |
591 | int page_order; /* allocation order */ | ||
590 | #endif | 592 | #endif |
591 | int data_order; | ||
592 | int nr_pages; /* nr of data pages */ | 593 | int nr_pages; /* nr of data pages */ |
593 | int writable; /* are we writable */ | 594 | int writable; /* are we writable */ |
594 | int nr_locked; /* nr pages mlocked */ | 595 | int nr_locked; /* nr pages mlocked */ |
595 | 596 | ||
596 | atomic_t poll; /* POLL_ for wakeups */ | 597 | atomic_t poll; /* POLL_ for wakeups */ |
597 | atomic_t events; /* event_id limit */ | ||
598 | 598 | ||
599 | atomic_long_t head; /* write position */ | 599 | local_t head; /* write position */ |
600 | atomic_long_t done_head; /* completed head */ | 600 | local_t nest; /* nested writers */ |
601 | 601 | local_t events; /* event limit */ | |
602 | atomic_t lock; /* concurrent writes */ | 602 | local_t wakeup; /* wakeup stamp */ |
603 | atomic_t wakeup; /* needs a wakeup */ | 603 | local_t lost; /* nr records lost */ |
604 | atomic_t lost; /* nr records lost */ | ||
605 | 604 | ||
606 | long watermark; /* wakeup watermark */ | 605 | long watermark; /* wakeup watermark */ |
607 | 606 | ||
@@ -728,6 +727,7 @@ struct perf_event { | |||
728 | perf_overflow_handler_t overflow_handler; | 727 | perf_overflow_handler_t overflow_handler; |
729 | 728 | ||
730 | #ifdef CONFIG_EVENT_TRACING | 729 | #ifdef CONFIG_EVENT_TRACING |
730 | struct ftrace_event_call *tp_event; | ||
731 | struct event_filter *filter; | 731 | struct event_filter *filter; |
732 | #endif | 732 | #endif |
733 | 733 | ||
@@ -803,11 +803,12 @@ struct perf_cpu_context { | |||
803 | struct perf_output_handle { | 803 | struct perf_output_handle { |
804 | struct perf_event *event; | 804 | struct perf_event *event; |
805 | struct perf_mmap_data *data; | 805 | struct perf_mmap_data *data; |
806 | unsigned long head; | 806 | unsigned long wakeup; |
807 | unsigned long offset; | 807 | unsigned long size; |
808 | void *addr; | ||
809 | int page; | ||
808 | int nmi; | 810 | int nmi; |
809 | int sample; | 811 | int sample; |
810 | int locked; | ||
811 | }; | 812 | }; |
812 | 813 | ||
813 | #ifdef CONFIG_PERF_EVENTS | 814 | #ifdef CONFIG_PERF_EVENTS |
@@ -993,8 +994,9 @@ static inline bool perf_paranoid_kernel(void) | |||
993 | } | 994 | } |
994 | 995 | ||
995 | extern void perf_event_init(void); | 996 | extern void perf_event_init(void); |
996 | extern void perf_tp_event(int event_id, u64 addr, u64 count, void *record, | 997 | extern void perf_tp_event(u64 addr, u64 count, void *record, |
997 | int entry_size, struct pt_regs *regs); | 998 | int entry_size, struct pt_regs *regs, |
999 | struct hlist_head *head); | ||
998 | extern void perf_bp_event(struct perf_event *event, void *data); | 1000 | extern void perf_bp_event(struct perf_event *event, void *data); |
999 | 1001 | ||
1000 | #ifndef perf_misc_flags | 1002 | #ifndef perf_misc_flags |
diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h index 057929b0a651..a1a86a53bc73 100644 --- a/include/linux/syscalls.h +++ b/include/linux/syscalls.h | |||
@@ -103,22 +103,6 @@ struct perf_event_attr; | |||
103 | #define __SC_TEST5(t5, a5, ...) __SC_TEST(t5); __SC_TEST4(__VA_ARGS__) | 103 | #define __SC_TEST5(t5, a5, ...) __SC_TEST(t5); __SC_TEST4(__VA_ARGS__) |
104 | #define __SC_TEST6(t6, a6, ...) __SC_TEST(t6); __SC_TEST5(__VA_ARGS__) | 104 | #define __SC_TEST6(t6, a6, ...) __SC_TEST(t6); __SC_TEST5(__VA_ARGS__) |
105 | 105 | ||
106 | #ifdef CONFIG_PERF_EVENTS | ||
107 | |||
108 | #define TRACE_SYS_ENTER_PERF_INIT(sname) \ | ||
109 | .perf_event_enable = perf_sysenter_enable, \ | ||
110 | .perf_event_disable = perf_sysenter_disable, | ||
111 | |||
112 | #define TRACE_SYS_EXIT_PERF_INIT(sname) \ | ||
113 | .perf_event_enable = perf_sysexit_enable, \ | ||
114 | .perf_event_disable = perf_sysexit_disable, | ||
115 | #else | ||
116 | #define TRACE_SYS_ENTER_PERF(sname) | ||
117 | #define TRACE_SYS_ENTER_PERF_INIT(sname) | ||
118 | #define TRACE_SYS_EXIT_PERF(sname) | ||
119 | #define TRACE_SYS_EXIT_PERF_INIT(sname) | ||
120 | #endif /* CONFIG_PERF_EVENTS */ | ||
121 | |||
122 | #ifdef CONFIG_FTRACE_SYSCALLS | 106 | #ifdef CONFIG_FTRACE_SYSCALLS |
123 | #define __SC_STR_ADECL1(t, a) #a | 107 | #define __SC_STR_ADECL1(t, a) #a |
124 | #define __SC_STR_ADECL2(t, a, ...) #a, __SC_STR_ADECL1(__VA_ARGS__) | 108 | #define __SC_STR_ADECL2(t, a, ...) #a, __SC_STR_ADECL1(__VA_ARGS__) |
@@ -134,54 +118,43 @@ struct perf_event_attr; | |||
134 | #define __SC_STR_TDECL5(t, a, ...) #t, __SC_STR_TDECL4(__VA_ARGS__) | 118 | #define __SC_STR_TDECL5(t, a, ...) #t, __SC_STR_TDECL4(__VA_ARGS__) |
135 | #define __SC_STR_TDECL6(t, a, ...) #t, __SC_STR_TDECL5(__VA_ARGS__) | 119 | #define __SC_STR_TDECL6(t, a, ...) #t, __SC_STR_TDECL5(__VA_ARGS__) |
136 | 120 | ||
121 | extern struct ftrace_event_class event_class_syscall_enter; | ||
122 | extern struct ftrace_event_class event_class_syscall_exit; | ||
123 | extern struct trace_event_functions enter_syscall_print_funcs; | ||
124 | extern struct trace_event_functions exit_syscall_print_funcs; | ||
125 | |||
137 | #define SYSCALL_TRACE_ENTER_EVENT(sname) \ | 126 | #define SYSCALL_TRACE_ENTER_EVENT(sname) \ |
138 | static const struct syscall_metadata __syscall_meta_##sname; \ | 127 | static struct syscall_metadata __syscall_meta_##sname; \ |
139 | static struct ftrace_event_call \ | 128 | static struct ftrace_event_call \ |
140 | __attribute__((__aligned__(4))) event_enter_##sname; \ | 129 | __attribute__((__aligned__(4))) event_enter_##sname; \ |
141 | static struct trace_event enter_syscall_print_##sname = { \ | ||
142 | .trace = print_syscall_enter, \ | ||
143 | }; \ | ||
144 | static struct ftrace_event_call __used \ | 130 | static struct ftrace_event_call __used \ |
145 | __attribute__((__aligned__(4))) \ | 131 | __attribute__((__aligned__(4))) \ |
146 | __attribute__((section("_ftrace_events"))) \ | 132 | __attribute__((section("_ftrace_events"))) \ |
147 | event_enter_##sname = { \ | 133 | event_enter_##sname = { \ |
148 | .name = "sys_enter"#sname, \ | 134 | .name = "sys_enter"#sname, \ |
149 | .system = "syscalls", \ | 135 | .class = &event_class_syscall_enter, \ |
150 | .event = &enter_syscall_print_##sname, \ | 136 | .event.funcs = &enter_syscall_print_funcs, \ |
151 | .raw_init = init_syscall_trace, \ | ||
152 | .define_fields = syscall_enter_define_fields, \ | ||
153 | .regfunc = reg_event_syscall_enter, \ | ||
154 | .unregfunc = unreg_event_syscall_enter, \ | ||
155 | .data = (void *)&__syscall_meta_##sname,\ | 137 | .data = (void *)&__syscall_meta_##sname,\ |
156 | TRACE_SYS_ENTER_PERF_INIT(sname) \ | ||
157 | } | 138 | } |
158 | 139 | ||
159 | #define SYSCALL_TRACE_EXIT_EVENT(sname) \ | 140 | #define SYSCALL_TRACE_EXIT_EVENT(sname) \ |
160 | static const struct syscall_metadata __syscall_meta_##sname; \ | 141 | static struct syscall_metadata __syscall_meta_##sname; \ |
161 | static struct ftrace_event_call \ | 142 | static struct ftrace_event_call \ |
162 | __attribute__((__aligned__(4))) event_exit_##sname; \ | 143 | __attribute__((__aligned__(4))) event_exit_##sname; \ |
163 | static struct trace_event exit_syscall_print_##sname = { \ | ||
164 | .trace = print_syscall_exit, \ | ||
165 | }; \ | ||
166 | static struct ftrace_event_call __used \ | 144 | static struct ftrace_event_call __used \ |
167 | __attribute__((__aligned__(4))) \ | 145 | __attribute__((__aligned__(4))) \ |
168 | __attribute__((section("_ftrace_events"))) \ | 146 | __attribute__((section("_ftrace_events"))) \ |
169 | event_exit_##sname = { \ | 147 | event_exit_##sname = { \ |
170 | .name = "sys_exit"#sname, \ | 148 | .name = "sys_exit"#sname, \ |
171 | .system = "syscalls", \ | 149 | .class = &event_class_syscall_exit, \ |
172 | .event = &exit_syscall_print_##sname, \ | 150 | .event.funcs = &exit_syscall_print_funcs, \ |
173 | .raw_init = init_syscall_trace, \ | ||
174 | .define_fields = syscall_exit_define_fields, \ | ||
175 | .regfunc = reg_event_syscall_exit, \ | ||
176 | .unregfunc = unreg_event_syscall_exit, \ | ||
177 | .data = (void *)&__syscall_meta_##sname,\ | 151 | .data = (void *)&__syscall_meta_##sname,\ |
178 | TRACE_SYS_EXIT_PERF_INIT(sname) \ | ||
179 | } | 152 | } |
180 | 153 | ||
181 | #define SYSCALL_METADATA(sname, nb) \ | 154 | #define SYSCALL_METADATA(sname, nb) \ |
182 | SYSCALL_TRACE_ENTER_EVENT(sname); \ | 155 | SYSCALL_TRACE_ENTER_EVENT(sname); \ |
183 | SYSCALL_TRACE_EXIT_EVENT(sname); \ | 156 | SYSCALL_TRACE_EXIT_EVENT(sname); \ |
184 | static const struct syscall_metadata __used \ | 157 | static struct syscall_metadata __used \ |
185 | __attribute__((__aligned__(4))) \ | 158 | __attribute__((__aligned__(4))) \ |
186 | __attribute__((section("__syscalls_metadata"))) \ | 159 | __attribute__((section("__syscalls_metadata"))) \ |
187 | __syscall_meta_##sname = { \ | 160 | __syscall_meta_##sname = { \ |
@@ -191,12 +164,14 @@ struct perf_event_attr; | |||
191 | .args = args_##sname, \ | 164 | .args = args_##sname, \ |
192 | .enter_event = &event_enter_##sname, \ | 165 | .enter_event = &event_enter_##sname, \ |
193 | .exit_event = &event_exit_##sname, \ | 166 | .exit_event = &event_exit_##sname, \ |
167 | .enter_fields = LIST_HEAD_INIT(__syscall_meta_##sname.enter_fields), \ | ||
168 | .exit_fields = LIST_HEAD_INIT(__syscall_meta_##sname.exit_fields), \ | ||
194 | }; | 169 | }; |
195 | 170 | ||
196 | #define SYSCALL_DEFINE0(sname) \ | 171 | #define SYSCALL_DEFINE0(sname) \ |
197 | SYSCALL_TRACE_ENTER_EVENT(_##sname); \ | 172 | SYSCALL_TRACE_ENTER_EVENT(_##sname); \ |
198 | SYSCALL_TRACE_EXIT_EVENT(_##sname); \ | 173 | SYSCALL_TRACE_EXIT_EVENT(_##sname); \ |
199 | static const struct syscall_metadata __used \ | 174 | static struct syscall_metadata __used \ |
200 | __attribute__((__aligned__(4))) \ | 175 | __attribute__((__aligned__(4))) \ |
201 | __attribute__((section("__syscalls_metadata"))) \ | 176 | __attribute__((section("__syscalls_metadata"))) \ |
202 | __syscall_meta__##sname = { \ | 177 | __syscall_meta__##sname = { \ |
@@ -204,6 +179,8 @@ struct perf_event_attr; | |||
204 | .nb_args = 0, \ | 179 | .nb_args = 0, \ |
205 | .enter_event = &event_enter__##sname, \ | 180 | .enter_event = &event_enter__##sname, \ |
206 | .exit_event = &event_exit__##sname, \ | 181 | .exit_event = &event_exit__##sname, \ |
182 | .enter_fields = LIST_HEAD_INIT(__syscall_meta__##sname.enter_fields), \ | ||
183 | .exit_fields = LIST_HEAD_INIT(__syscall_meta__##sname.exit_fields), \ | ||
207 | }; \ | 184 | }; \ |
208 | asmlinkage long sys_##sname(void) | 185 | asmlinkage long sys_##sname(void) |
209 | #else | 186 | #else |
diff --git a/include/linux/tracepoint.h b/include/linux/tracepoint.h index 1d85f9a6a199..9a59d1f98cd4 100644 --- a/include/linux/tracepoint.h +++ b/include/linux/tracepoint.h | |||
@@ -20,12 +20,17 @@ | |||
20 | struct module; | 20 | struct module; |
21 | struct tracepoint; | 21 | struct tracepoint; |
22 | 22 | ||
23 | struct tracepoint_func { | ||
24 | void *func; | ||
25 | void *data; | ||
26 | }; | ||
27 | |||
23 | struct tracepoint { | 28 | struct tracepoint { |
24 | const char *name; /* Tracepoint name */ | 29 | const char *name; /* Tracepoint name */ |
25 | int state; /* State. */ | 30 | int state; /* State. */ |
26 | void (*regfunc)(void); | 31 | void (*regfunc)(void); |
27 | void (*unregfunc)(void); | 32 | void (*unregfunc)(void); |
28 | void **funcs; | 33 | struct tracepoint_func *funcs; |
29 | } __attribute__((aligned(32))); /* | 34 | } __attribute__((aligned(32))); /* |
30 | * Aligned on 32 bytes because it is | 35 | * Aligned on 32 bytes because it is |
31 | * globally visible and gcc happily | 36 | * globally visible and gcc happily |
@@ -37,16 +42,19 @@ struct tracepoint { | |||
37 | * Connect a probe to a tracepoint. | 42 | * Connect a probe to a tracepoint. |
38 | * Internal API, should not be used directly. | 43 | * Internal API, should not be used directly. |
39 | */ | 44 | */ |
40 | extern int tracepoint_probe_register(const char *name, void *probe); | 45 | extern int tracepoint_probe_register(const char *name, void *probe, void *data); |
41 | 46 | ||
42 | /* | 47 | /* |
43 | * Disconnect a probe from a tracepoint. | 48 | * Disconnect a probe from a tracepoint. |
44 | * Internal API, should not be used directly. | 49 | * Internal API, should not be used directly. |
45 | */ | 50 | */ |
46 | extern int tracepoint_probe_unregister(const char *name, void *probe); | 51 | extern int |
52 | tracepoint_probe_unregister(const char *name, void *probe, void *data); | ||
47 | 53 | ||
48 | extern int tracepoint_probe_register_noupdate(const char *name, void *probe); | 54 | extern int tracepoint_probe_register_noupdate(const char *name, void *probe, |
49 | extern int tracepoint_probe_unregister_noupdate(const char *name, void *probe); | 55 | void *data); |
56 | extern int tracepoint_probe_unregister_noupdate(const char *name, void *probe, | ||
57 | void *data); | ||
50 | extern void tracepoint_probe_update_all(void); | 58 | extern void tracepoint_probe_update_all(void); |
51 | 59 | ||
52 | struct tracepoint_iter { | 60 | struct tracepoint_iter { |
@@ -102,17 +110,27 @@ static inline void tracepoint_update_probe_range(struct tracepoint *begin, | |||
102 | /* | 110 | /* |
103 | * it_func[0] is never NULL because there is at least one element in the array | 111 | * it_func[0] is never NULL because there is at least one element in the array |
104 | * when the array itself is non NULL. | 112 | * when the array itself is non NULL. |
113 | * | ||
114 | * Note, the proto and args passed in includes "__data" as the first parameter. | ||
115 | * The reason for this is to handle the "void" prototype. If a tracepoint | ||
116 | * has a "void" prototype, then it is invalid to declare a function | ||
117 | * as "(void *, void)". The DECLARE_TRACE_NOARGS() will pass in just | ||
118 | * "void *data", where as the DECLARE_TRACE() will pass in "void *data, proto". | ||
105 | */ | 119 | */ |
106 | #define __DO_TRACE(tp, proto, args) \ | 120 | #define __DO_TRACE(tp, proto, args) \ |
107 | do { \ | 121 | do { \ |
108 | void **it_func; \ | 122 | struct tracepoint_func *it_func_ptr; \ |
123 | void *it_func; \ | ||
124 | void *__data; \ | ||
109 | \ | 125 | \ |
110 | rcu_read_lock_sched_notrace(); \ | 126 | rcu_read_lock_sched_notrace(); \ |
111 | it_func = rcu_dereference_sched((tp)->funcs); \ | 127 | it_func_ptr = rcu_dereference_sched((tp)->funcs); \ |
112 | if (it_func) { \ | 128 | if (it_func_ptr) { \ |
113 | do { \ | 129 | do { \ |
114 | ((void(*)(proto))(*it_func))(args); \ | 130 | it_func = (it_func_ptr)->func; \ |
115 | } while (*(++it_func)); \ | 131 | __data = (it_func_ptr)->data; \ |
132 | ((void(*)(proto))(it_func))(args); \ | ||
133 | } while ((++it_func_ptr)->func); \ | ||
116 | } \ | 134 | } \ |
117 | rcu_read_unlock_sched_notrace(); \ | 135 | rcu_read_unlock_sched_notrace(); \ |
118 | } while (0) | 136 | } while (0) |
@@ -122,24 +140,32 @@ static inline void tracepoint_update_probe_range(struct tracepoint *begin, | |||
122 | * not add unwanted padding between the beginning of the section and the | 140 | * not add unwanted padding between the beginning of the section and the |
123 | * structure. Force alignment to the same alignment as the section start. | 141 | * structure. Force alignment to the same alignment as the section start. |
124 | */ | 142 | */ |
125 | #define DECLARE_TRACE(name, proto, args) \ | 143 | #define __DECLARE_TRACE(name, proto, args, data_proto, data_args) \ |
126 | extern struct tracepoint __tracepoint_##name; \ | 144 | extern struct tracepoint __tracepoint_##name; \ |
127 | static inline void trace_##name(proto) \ | 145 | static inline void trace_##name(proto) \ |
128 | { \ | 146 | { \ |
129 | if (unlikely(__tracepoint_##name.state)) \ | 147 | if (unlikely(__tracepoint_##name.state)) \ |
130 | __DO_TRACE(&__tracepoint_##name, \ | 148 | __DO_TRACE(&__tracepoint_##name, \ |
131 | TP_PROTO(proto), TP_ARGS(args)); \ | 149 | TP_PROTO(data_proto), \ |
150 | TP_ARGS(data_args)); \ | ||
151 | } \ | ||
152 | static inline int \ | ||
153 | register_trace_##name(void (*probe)(data_proto), void *data) \ | ||
154 | { \ | ||
155 | return tracepoint_probe_register(#name, (void *)probe, \ | ||
156 | data); \ | ||
132 | } \ | 157 | } \ |
133 | static inline int register_trace_##name(void (*probe)(proto)) \ | 158 | static inline int \ |
159 | unregister_trace_##name(void (*probe)(data_proto), void *data) \ | ||
134 | { \ | 160 | { \ |
135 | return tracepoint_probe_register(#name, (void *)probe); \ | 161 | return tracepoint_probe_unregister(#name, (void *)probe, \ |
162 | data); \ | ||
136 | } \ | 163 | } \ |
137 | static inline int unregister_trace_##name(void (*probe)(proto)) \ | 164 | static inline void \ |
165 | check_trace_callback_type_##name(void (*cb)(data_proto)) \ | ||
138 | { \ | 166 | { \ |
139 | return tracepoint_probe_unregister(#name, (void *)probe);\ | ||
140 | } | 167 | } |
141 | 168 | ||
142 | |||
143 | #define DEFINE_TRACE_FN(name, reg, unreg) \ | 169 | #define DEFINE_TRACE_FN(name, reg, unreg) \ |
144 | static const char __tpstrtab_##name[] \ | 170 | static const char __tpstrtab_##name[] \ |
145 | __attribute__((section("__tracepoints_strings"))) = #name; \ | 171 | __attribute__((section("__tracepoints_strings"))) = #name; \ |
@@ -156,18 +182,23 @@ static inline void tracepoint_update_probe_range(struct tracepoint *begin, | |||
156 | EXPORT_SYMBOL(__tracepoint_##name) | 182 | EXPORT_SYMBOL(__tracepoint_##name) |
157 | 183 | ||
158 | #else /* !CONFIG_TRACEPOINTS */ | 184 | #else /* !CONFIG_TRACEPOINTS */ |
159 | #define DECLARE_TRACE(name, proto, args) \ | 185 | #define __DECLARE_TRACE(name, proto, args, data_proto, data_args) \ |
160 | static inline void _do_trace_##name(struct tracepoint *tp, proto) \ | ||
161 | { } \ | ||
162 | static inline void trace_##name(proto) \ | 186 | static inline void trace_##name(proto) \ |
163 | { } \ | 187 | { } \ |
164 | static inline int register_trace_##name(void (*probe)(proto)) \ | 188 | static inline int \ |
189 | register_trace_##name(void (*probe)(data_proto), \ | ||
190 | void *data) \ | ||
165 | { \ | 191 | { \ |
166 | return -ENOSYS; \ | 192 | return -ENOSYS; \ |
167 | } \ | 193 | } \ |
168 | static inline int unregister_trace_##name(void (*probe)(proto)) \ | 194 | static inline int \ |
195 | unregister_trace_##name(void (*probe)(data_proto), \ | ||
196 | void *data) \ | ||
169 | { \ | 197 | { \ |
170 | return -ENOSYS; \ | 198 | return -ENOSYS; \ |
199 | } \ | ||
200 | static inline void check_trace_callback_type_##name(void (*cb)(data_proto)) \ | ||
201 | { \ | ||
171 | } | 202 | } |
172 | 203 | ||
173 | #define DEFINE_TRACE_FN(name, reg, unreg) | 204 | #define DEFINE_TRACE_FN(name, reg, unreg) |
@@ -176,6 +207,29 @@ static inline void tracepoint_update_probe_range(struct tracepoint *begin, | |||
176 | #define EXPORT_TRACEPOINT_SYMBOL(name) | 207 | #define EXPORT_TRACEPOINT_SYMBOL(name) |
177 | 208 | ||
178 | #endif /* CONFIG_TRACEPOINTS */ | 209 | #endif /* CONFIG_TRACEPOINTS */ |
210 | |||
211 | /* | ||
212 | * The need for the DECLARE_TRACE_NOARGS() is to handle the prototype | ||
213 | * (void). "void" is a special value in a function prototype and can | ||
214 | * not be combined with other arguments. Since the DECLARE_TRACE() | ||
215 | * macro adds a data element at the beginning of the prototype, | ||
216 | * we need a way to differentiate "(void *data, proto)" from | ||
217 | * "(void *data, void)". The second prototype is invalid. | ||
218 | * | ||
219 | * DECLARE_TRACE_NOARGS() passes "void" as the tracepoint prototype | ||
220 | * and "void *__data" as the callback prototype. | ||
221 | * | ||
222 | * DECLARE_TRACE() passes "proto" as the tracepoint protoype and | ||
223 | * "void *__data, proto" as the callback prototype. | ||
224 | */ | ||
225 | #define DECLARE_TRACE_NOARGS(name) \ | ||
226 | __DECLARE_TRACE(name, void, , void *__data, __data) | ||
227 | |||
228 | #define DECLARE_TRACE(name, proto, args) \ | ||
229 | __DECLARE_TRACE(name, PARAMS(proto), PARAMS(args), \ | ||
230 | PARAMS(void *__data, proto), \ | ||
231 | PARAMS(__data, args)) | ||
232 | |||
179 | #endif /* DECLARE_TRACE */ | 233 | #endif /* DECLARE_TRACE */ |
180 | 234 | ||
181 | #ifndef TRACE_EVENT | 235 | #ifndef TRACE_EVENT |
diff --git a/include/trace/ftrace.h b/include/trace/ftrace.h index 88c59c13ea7b..3d685d1f2a03 100644 --- a/include/trace/ftrace.h +++ b/include/trace/ftrace.h | |||
@@ -62,10 +62,13 @@ | |||
62 | struct trace_entry ent; \ | 62 | struct trace_entry ent; \ |
63 | tstruct \ | 63 | tstruct \ |
64 | char __data[0]; \ | 64 | char __data[0]; \ |
65 | }; | 65 | }; \ |
66 | \ | ||
67 | static struct ftrace_event_class event_class_##name; | ||
68 | |||
66 | #undef DEFINE_EVENT | 69 | #undef DEFINE_EVENT |
67 | #define DEFINE_EVENT(template, name, proto, args) \ | 70 | #define DEFINE_EVENT(template, name, proto, args) \ |
68 | static struct ftrace_event_call \ | 71 | static struct ftrace_event_call __used \ |
69 | __attribute__((__aligned__(4))) event_##name | 72 | __attribute__((__aligned__(4))) event_##name |
70 | 73 | ||
71 | #undef DEFINE_EVENT_PRINT | 74 | #undef DEFINE_EVENT_PRINT |
@@ -147,7 +150,7 @@ | |||
147 | * | 150 | * |
148 | * entry = iter->ent; | 151 | * entry = iter->ent; |
149 | * | 152 | * |
150 | * if (entry->type != event_<call>.id) { | 153 | * if (entry->type != event_<call>->event.type) { |
151 | * WARN_ON_ONCE(1); | 154 | * WARN_ON_ONCE(1); |
152 | * return TRACE_TYPE_UNHANDLED; | 155 | * return TRACE_TYPE_UNHANDLED; |
153 | * } | 156 | * } |
@@ -206,18 +209,22 @@ | |||
206 | #undef DECLARE_EVENT_CLASS | 209 | #undef DECLARE_EVENT_CLASS |
207 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ | 210 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ |
208 | static notrace enum print_line_t \ | 211 | static notrace enum print_line_t \ |
209 | ftrace_raw_output_id_##call(int event_id, const char *name, \ | 212 | ftrace_raw_output_##call(struct trace_iterator *iter, int flags, \ |
210 | struct trace_iterator *iter, int flags) \ | 213 | struct trace_event *trace_event) \ |
211 | { \ | 214 | { \ |
215 | struct ftrace_event_call *event; \ | ||
212 | struct trace_seq *s = &iter->seq; \ | 216 | struct trace_seq *s = &iter->seq; \ |
213 | struct ftrace_raw_##call *field; \ | 217 | struct ftrace_raw_##call *field; \ |
214 | struct trace_entry *entry; \ | 218 | struct trace_entry *entry; \ |
215 | struct trace_seq *p; \ | 219 | struct trace_seq *p; \ |
216 | int ret; \ | 220 | int ret; \ |
217 | \ | 221 | \ |
222 | event = container_of(trace_event, struct ftrace_event_call, \ | ||
223 | event); \ | ||
224 | \ | ||
218 | entry = iter->ent; \ | 225 | entry = iter->ent; \ |
219 | \ | 226 | \ |
220 | if (entry->type != event_id) { \ | 227 | if (entry->type != event->event.type) { \ |
221 | WARN_ON_ONCE(1); \ | 228 | WARN_ON_ONCE(1); \ |
222 | return TRACE_TYPE_UNHANDLED; \ | 229 | return TRACE_TYPE_UNHANDLED; \ |
223 | } \ | 230 | } \ |
@@ -226,7 +233,7 @@ ftrace_raw_output_id_##call(int event_id, const char *name, \ | |||
226 | \ | 233 | \ |
227 | p = &get_cpu_var(ftrace_event_seq); \ | 234 | p = &get_cpu_var(ftrace_event_seq); \ |
228 | trace_seq_init(p); \ | 235 | trace_seq_init(p); \ |
229 | ret = trace_seq_printf(s, "%s: ", name); \ | 236 | ret = trace_seq_printf(s, "%s: ", event->name); \ |
230 | if (ret) \ | 237 | if (ret) \ |
231 | ret = trace_seq_printf(s, print); \ | 238 | ret = trace_seq_printf(s, print); \ |
232 | put_cpu(); \ | 239 | put_cpu(); \ |
@@ -234,21 +241,16 @@ ftrace_raw_output_id_##call(int event_id, const char *name, \ | |||
234 | return TRACE_TYPE_PARTIAL_LINE; \ | 241 | return TRACE_TYPE_PARTIAL_LINE; \ |
235 | \ | 242 | \ |
236 | return TRACE_TYPE_HANDLED; \ | 243 | return TRACE_TYPE_HANDLED; \ |
237 | } | 244 | } \ |
238 | 245 | static struct trace_event_functions ftrace_event_type_funcs_##call = { \ | |
239 | #undef DEFINE_EVENT | 246 | .trace = ftrace_raw_output_##call, \ |
240 | #define DEFINE_EVENT(template, name, proto, args) \ | 247 | }; |
241 | static notrace enum print_line_t \ | ||
242 | ftrace_raw_output_##name(struct trace_iterator *iter, int flags) \ | ||
243 | { \ | ||
244 | return ftrace_raw_output_id_##template(event_##name.id, \ | ||
245 | #name, iter, flags); \ | ||
246 | } | ||
247 | 248 | ||
248 | #undef DEFINE_EVENT_PRINT | 249 | #undef DEFINE_EVENT_PRINT |
249 | #define DEFINE_EVENT_PRINT(template, call, proto, args, print) \ | 250 | #define DEFINE_EVENT_PRINT(template, call, proto, args, print) \ |
250 | static notrace enum print_line_t \ | 251 | static notrace enum print_line_t \ |
251 | ftrace_raw_output_##call(struct trace_iterator *iter, int flags) \ | 252 | ftrace_raw_output_##call(struct trace_iterator *iter, int flags, \ |
253 | struct trace_event *event) \ | ||
252 | { \ | 254 | { \ |
253 | struct trace_seq *s = &iter->seq; \ | 255 | struct trace_seq *s = &iter->seq; \ |
254 | struct ftrace_raw_##template *field; \ | 256 | struct ftrace_raw_##template *field; \ |
@@ -258,7 +260,7 @@ ftrace_raw_output_##call(struct trace_iterator *iter, int flags) \ | |||
258 | \ | 260 | \ |
259 | entry = iter->ent; \ | 261 | entry = iter->ent; \ |
260 | \ | 262 | \ |
261 | if (entry->type != event_##call.id) { \ | 263 | if (entry->type != event_##call.event.type) { \ |
262 | WARN_ON_ONCE(1); \ | 264 | WARN_ON_ONCE(1); \ |
263 | return TRACE_TYPE_UNHANDLED; \ | 265 | return TRACE_TYPE_UNHANDLED; \ |
264 | } \ | 266 | } \ |
@@ -275,7 +277,10 @@ ftrace_raw_output_##call(struct trace_iterator *iter, int flags) \ | |||
275 | return TRACE_TYPE_PARTIAL_LINE; \ | 277 | return TRACE_TYPE_PARTIAL_LINE; \ |
276 | \ | 278 | \ |
277 | return TRACE_TYPE_HANDLED; \ | 279 | return TRACE_TYPE_HANDLED; \ |
278 | } | 280 | } \ |
281 | static struct trace_event_functions ftrace_event_type_funcs_##call = { \ | ||
282 | .trace = ftrace_raw_output_##call, \ | ||
283 | }; | ||
279 | 284 | ||
280 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | 285 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
281 | 286 | ||
@@ -381,80 +386,18 @@ static inline notrace int ftrace_get_offsets_##call( \ | |||
381 | 386 | ||
382 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | 387 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
383 | 388 | ||
384 | #ifdef CONFIG_PERF_EVENTS | ||
385 | |||
386 | /* | ||
387 | * Generate the functions needed for tracepoint perf_event support. | ||
388 | * | ||
389 | * NOTE: The insertion profile callback (ftrace_profile_<call>) is defined later | ||
390 | * | ||
391 | * static int ftrace_profile_enable_<call>(void) | ||
392 | * { | ||
393 | * return register_trace_<call>(ftrace_profile_<call>); | ||
394 | * } | ||
395 | * | ||
396 | * static void ftrace_profile_disable_<call>(void) | ||
397 | * { | ||
398 | * unregister_trace_<call>(ftrace_profile_<call>); | ||
399 | * } | ||
400 | * | ||
401 | */ | ||
402 | |||
403 | #undef DECLARE_EVENT_CLASS | ||
404 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) | ||
405 | |||
406 | #undef DEFINE_EVENT | ||
407 | #define DEFINE_EVENT(template, name, proto, args) \ | ||
408 | \ | ||
409 | static void perf_trace_##name(proto); \ | ||
410 | \ | ||
411 | static notrace int \ | ||
412 | perf_trace_enable_##name(struct ftrace_event_call *unused) \ | ||
413 | { \ | ||
414 | return register_trace_##name(perf_trace_##name); \ | ||
415 | } \ | ||
416 | \ | ||
417 | static notrace void \ | ||
418 | perf_trace_disable_##name(struct ftrace_event_call *unused) \ | ||
419 | { \ | ||
420 | unregister_trace_##name(perf_trace_##name); \ | ||
421 | } | ||
422 | |||
423 | #undef DEFINE_EVENT_PRINT | ||
424 | #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \ | ||
425 | DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args)) | ||
426 | |||
427 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | ||
428 | |||
429 | #endif /* CONFIG_PERF_EVENTS */ | ||
430 | |||
431 | /* | 389 | /* |
432 | * Stage 4 of the trace events. | 390 | * Stage 4 of the trace events. |
433 | * | 391 | * |
434 | * Override the macros in <trace/trace_events.h> to include the following: | 392 | * Override the macros in <trace/trace_events.h> to include the following: |
435 | * | 393 | * |
436 | * static void ftrace_event_<call>(proto) | ||
437 | * { | ||
438 | * event_trace_printk(_RET_IP_, "<call>: " <fmt>); | ||
439 | * } | ||
440 | * | ||
441 | * static int ftrace_reg_event_<call>(struct ftrace_event_call *unused) | ||
442 | * { | ||
443 | * return register_trace_<call>(ftrace_event_<call>); | ||
444 | * } | ||
445 | * | ||
446 | * static void ftrace_unreg_event_<call>(struct ftrace_event_call *unused) | ||
447 | * { | ||
448 | * unregister_trace_<call>(ftrace_event_<call>); | ||
449 | * } | ||
450 | * | ||
451 | * | ||
452 | * For those macros defined with TRACE_EVENT: | 394 | * For those macros defined with TRACE_EVENT: |
453 | * | 395 | * |
454 | * static struct ftrace_event_call event_<call>; | 396 | * static struct ftrace_event_call event_<call>; |
455 | * | 397 | * |
456 | * static void ftrace_raw_event_<call>(proto) | 398 | * static void ftrace_raw_event_<call>(void *__data, proto) |
457 | * { | 399 | * { |
400 | * struct ftrace_event_call *event_call = __data; | ||
458 | * struct ftrace_data_offsets_<call> __maybe_unused __data_offsets; | 401 | * struct ftrace_data_offsets_<call> __maybe_unused __data_offsets; |
459 | * struct ring_buffer_event *event; | 402 | * struct ring_buffer_event *event; |
460 | * struct ftrace_raw_<call> *entry; <-- defined in stage 1 | 403 | * struct ftrace_raw_<call> *entry; <-- defined in stage 1 |
@@ -469,7 +412,7 @@ perf_trace_disable_##name(struct ftrace_event_call *unused) \ | |||
469 | * __data_size = ftrace_get_offsets_<call>(&__data_offsets, args); | 412 | * __data_size = ftrace_get_offsets_<call>(&__data_offsets, args); |
470 | * | 413 | * |
471 | * event = trace_current_buffer_lock_reserve(&buffer, | 414 | * event = trace_current_buffer_lock_reserve(&buffer, |
472 | * event_<call>.id, | 415 | * event_<call>->event.type, |
473 | * sizeof(*entry) + __data_size, | 416 | * sizeof(*entry) + __data_size, |
474 | * irq_flags, pc); | 417 | * irq_flags, pc); |
475 | * if (!event) | 418 | * if (!event) |
@@ -484,43 +427,42 @@ perf_trace_disable_##name(struct ftrace_event_call *unused) \ | |||
484 | * event, irq_flags, pc); | 427 | * event, irq_flags, pc); |
485 | * } | 428 | * } |
486 | * | 429 | * |
487 | * static int ftrace_raw_reg_event_<call>(struct ftrace_event_call *unused) | ||
488 | * { | ||
489 | * return register_trace_<call>(ftrace_raw_event_<call>); | ||
490 | * } | ||
491 | * | ||
492 | * static void ftrace_unreg_event_<call>(struct ftrace_event_call *unused) | ||
493 | * { | ||
494 | * unregister_trace_<call>(ftrace_raw_event_<call>); | ||
495 | * } | ||
496 | * | ||
497 | * static struct trace_event ftrace_event_type_<call> = { | 430 | * static struct trace_event ftrace_event_type_<call> = { |
498 | * .trace = ftrace_raw_output_<call>, <-- stage 2 | 431 | * .trace = ftrace_raw_output_<call>, <-- stage 2 |
499 | * }; | 432 | * }; |
500 | * | 433 | * |
501 | * static const char print_fmt_<call>[] = <TP_printk>; | 434 | * static const char print_fmt_<call>[] = <TP_printk>; |
502 | * | 435 | * |
436 | * static struct ftrace_event_class __used event_class_<template> = { | ||
437 | * .system = "<system>", | ||
438 | * .define_fields = ftrace_define_fields_<call>, | ||
439 | * .fields = LIST_HEAD_INIT(event_class_##call.fields), | ||
440 | * .raw_init = trace_event_raw_init, | ||
441 | * .probe = ftrace_raw_event_##call, | ||
442 | * }; | ||
443 | * | ||
503 | * static struct ftrace_event_call __used | 444 | * static struct ftrace_event_call __used |
504 | * __attribute__((__aligned__(4))) | 445 | * __attribute__((__aligned__(4))) |
505 | * __attribute__((section("_ftrace_events"))) event_<call> = { | 446 | * __attribute__((section("_ftrace_events"))) event_<call> = { |
506 | * .name = "<call>", | 447 | * .name = "<call>", |
507 | * .system = "<system>", | 448 | * .class = event_class_<template>, |
508 | * .raw_init = trace_event_raw_init, | 449 | * .event = &ftrace_event_type_<call>, |
509 | * .regfunc = ftrace_reg_event_<call>, | ||
510 | * .unregfunc = ftrace_unreg_event_<call>, | ||
511 | * .print_fmt = print_fmt_<call>, | 450 | * .print_fmt = print_fmt_<call>, |
512 | * .define_fields = ftrace_define_fields_<call>, | 451 | * }; |
513 | * } | ||
514 | * | 452 | * |
515 | */ | 453 | */ |
516 | 454 | ||
517 | #ifdef CONFIG_PERF_EVENTS | 455 | #ifdef CONFIG_PERF_EVENTS |
518 | 456 | ||
457 | #define _TRACE_PERF_PROTO(call, proto) \ | ||
458 | static notrace void \ | ||
459 | perf_trace_##call(void *__data, proto); | ||
460 | |||
519 | #define _TRACE_PERF_INIT(call) \ | 461 | #define _TRACE_PERF_INIT(call) \ |
520 | .perf_event_enable = perf_trace_enable_##call, \ | 462 | .perf_probe = perf_trace_##call, |
521 | .perf_event_disable = perf_trace_disable_##call, | ||
522 | 463 | ||
523 | #else | 464 | #else |
465 | #define _TRACE_PERF_PROTO(call, proto) | ||
524 | #define _TRACE_PERF_INIT(call) | 466 | #define _TRACE_PERF_INIT(call) |
525 | #endif /* CONFIG_PERF_EVENTS */ | 467 | #endif /* CONFIG_PERF_EVENTS */ |
526 | 468 | ||
@@ -554,9 +496,9 @@ perf_trace_disable_##name(struct ftrace_event_call *unused) \ | |||
554 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ | 496 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ |
555 | \ | 497 | \ |
556 | static notrace void \ | 498 | static notrace void \ |
557 | ftrace_raw_event_id_##call(struct ftrace_event_call *event_call, \ | 499 | ftrace_raw_event_##call(void *__data, proto) \ |
558 | proto) \ | ||
559 | { \ | 500 | { \ |
501 | struct ftrace_event_call *event_call = __data; \ | ||
560 | struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\ | 502 | struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\ |
561 | struct ring_buffer_event *event; \ | 503 | struct ring_buffer_event *event; \ |
562 | struct ftrace_raw_##call *entry; \ | 504 | struct ftrace_raw_##call *entry; \ |
@@ -571,7 +513,7 @@ ftrace_raw_event_id_##call(struct ftrace_event_call *event_call, \ | |||
571 | __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \ | 513 | __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \ |
572 | \ | 514 | \ |
573 | event = trace_current_buffer_lock_reserve(&buffer, \ | 515 | event = trace_current_buffer_lock_reserve(&buffer, \ |
574 | event_call->id, \ | 516 | event_call->event.type, \ |
575 | sizeof(*entry) + __data_size, \ | 517 | sizeof(*entry) + __data_size, \ |
576 | irq_flags, pc); \ | 518 | irq_flags, pc); \ |
577 | if (!event) \ | 519 | if (!event) \ |
@@ -586,34 +528,21 @@ ftrace_raw_event_id_##call(struct ftrace_event_call *event_call, \ | |||
586 | trace_nowake_buffer_unlock_commit(buffer, \ | 528 | trace_nowake_buffer_unlock_commit(buffer, \ |
587 | event, irq_flags, pc); \ | 529 | event, irq_flags, pc); \ |
588 | } | 530 | } |
531 | /* | ||
532 | * The ftrace_test_probe is compiled out, it is only here as a build time check | ||
533 | * to make sure that if the tracepoint handling changes, the ftrace probe will | ||
534 | * fail to compile unless it too is updated. | ||
535 | */ | ||
589 | 536 | ||
590 | #undef DEFINE_EVENT | 537 | #undef DEFINE_EVENT |
591 | #define DEFINE_EVENT(template, call, proto, args) \ | 538 | #define DEFINE_EVENT(template, call, proto, args) \ |
592 | \ | 539 | static inline void ftrace_test_probe_##call(void) \ |
593 | static notrace void ftrace_raw_event_##call(proto) \ | ||
594 | { \ | ||
595 | ftrace_raw_event_id_##template(&event_##call, args); \ | ||
596 | } \ | ||
597 | \ | ||
598 | static notrace int \ | ||
599 | ftrace_raw_reg_event_##call(struct ftrace_event_call *unused) \ | ||
600 | { \ | 540 | { \ |
601 | return register_trace_##call(ftrace_raw_event_##call); \ | 541 | check_trace_callback_type_##call(ftrace_raw_event_##template); \ |
602 | } \ | 542 | } |
603 | \ | ||
604 | static notrace void \ | ||
605 | ftrace_raw_unreg_event_##call(struct ftrace_event_call *unused) \ | ||
606 | { \ | ||
607 | unregister_trace_##call(ftrace_raw_event_##call); \ | ||
608 | } \ | ||
609 | \ | ||
610 | static struct trace_event ftrace_event_type_##call = { \ | ||
611 | .trace = ftrace_raw_output_##call, \ | ||
612 | }; | ||
613 | 543 | ||
614 | #undef DEFINE_EVENT_PRINT | 544 | #undef DEFINE_EVENT_PRINT |
615 | #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \ | 545 | #define DEFINE_EVENT_PRINT(template, name, proto, args, print) |
616 | DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args)) | ||
617 | 546 | ||
618 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | 547 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
619 | 548 | ||
@@ -630,7 +559,16 @@ static struct trace_event ftrace_event_type_##call = { \ | |||
630 | 559 | ||
631 | #undef DECLARE_EVENT_CLASS | 560 | #undef DECLARE_EVENT_CLASS |
632 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ | 561 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ |
633 | static const char print_fmt_##call[] = print; | 562 | _TRACE_PERF_PROTO(call, PARAMS(proto)); \ |
563 | static const char print_fmt_##call[] = print; \ | ||
564 | static struct ftrace_event_class __used event_class_##call = { \ | ||
565 | .system = __stringify(TRACE_SYSTEM), \ | ||
566 | .define_fields = ftrace_define_fields_##call, \ | ||
567 | .fields = LIST_HEAD_INIT(event_class_##call.fields),\ | ||
568 | .raw_init = trace_event_raw_init, \ | ||
569 | .probe = ftrace_raw_event_##call, \ | ||
570 | _TRACE_PERF_INIT(call) \ | ||
571 | }; | ||
634 | 572 | ||
635 | #undef DEFINE_EVENT | 573 | #undef DEFINE_EVENT |
636 | #define DEFINE_EVENT(template, call, proto, args) \ | 574 | #define DEFINE_EVENT(template, call, proto, args) \ |
@@ -639,15 +577,10 @@ static struct ftrace_event_call __used \ | |||
639 | __attribute__((__aligned__(4))) \ | 577 | __attribute__((__aligned__(4))) \ |
640 | __attribute__((section("_ftrace_events"))) event_##call = { \ | 578 | __attribute__((section("_ftrace_events"))) event_##call = { \ |
641 | .name = #call, \ | 579 | .name = #call, \ |
642 | .system = __stringify(TRACE_SYSTEM), \ | 580 | .class = &event_class_##template, \ |
643 | .event = &ftrace_event_type_##call, \ | 581 | .event.funcs = &ftrace_event_type_funcs_##template, \ |
644 | .raw_init = trace_event_raw_init, \ | ||
645 | .regfunc = ftrace_raw_reg_event_##call, \ | ||
646 | .unregfunc = ftrace_raw_unreg_event_##call, \ | ||
647 | .print_fmt = print_fmt_##template, \ | 582 | .print_fmt = print_fmt_##template, \ |
648 | .define_fields = ftrace_define_fields_##template, \ | 583 | }; |
649 | _TRACE_PERF_INIT(call) \ | ||
650 | } | ||
651 | 584 | ||
652 | #undef DEFINE_EVENT_PRINT | 585 | #undef DEFINE_EVENT_PRINT |
653 | #define DEFINE_EVENT_PRINT(template, call, proto, args, print) \ | 586 | #define DEFINE_EVENT_PRINT(template, call, proto, args, print) \ |
@@ -658,14 +591,9 @@ static struct ftrace_event_call __used \ | |||
658 | __attribute__((__aligned__(4))) \ | 591 | __attribute__((__aligned__(4))) \ |
659 | __attribute__((section("_ftrace_events"))) event_##call = { \ | 592 | __attribute__((section("_ftrace_events"))) event_##call = { \ |
660 | .name = #call, \ | 593 | .name = #call, \ |
661 | .system = __stringify(TRACE_SYSTEM), \ | 594 | .class = &event_class_##template, \ |
662 | .event = &ftrace_event_type_##call, \ | 595 | .event.funcs = &ftrace_event_type_funcs_##call, \ |
663 | .raw_init = trace_event_raw_init, \ | ||
664 | .regfunc = ftrace_raw_reg_event_##call, \ | ||
665 | .unregfunc = ftrace_raw_unreg_event_##call, \ | ||
666 | .print_fmt = print_fmt_##call, \ | 596 | .print_fmt = print_fmt_##call, \ |
667 | .define_fields = ftrace_define_fields_##template, \ | ||
668 | _TRACE_PERF_INIT(call) \ | ||
669 | } | 597 | } |
670 | 598 | ||
671 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | 599 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
@@ -765,17 +693,20 @@ __attribute__((section("_ftrace_events"))) event_##call = { \ | |||
765 | #undef DECLARE_EVENT_CLASS | 693 | #undef DECLARE_EVENT_CLASS |
766 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ | 694 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ |
767 | static notrace void \ | 695 | static notrace void \ |
768 | perf_trace_templ_##call(struct ftrace_event_call *event_call, \ | 696 | perf_trace_##call(void *__data, proto) \ |
769 | struct pt_regs *__regs, proto) \ | ||
770 | { \ | 697 | { \ |
698 | struct ftrace_event_call *event_call = __data; \ | ||
771 | struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\ | 699 | struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\ |
772 | struct ftrace_raw_##call *entry; \ | 700 | struct ftrace_raw_##call *entry; \ |
701 | struct pt_regs __regs; \ | ||
773 | u64 __addr = 0, __count = 1; \ | 702 | u64 __addr = 0, __count = 1; \ |
774 | unsigned long irq_flags; \ | 703 | struct hlist_head *head; \ |
775 | int __entry_size; \ | 704 | int __entry_size; \ |
776 | int __data_size; \ | 705 | int __data_size; \ |
777 | int rctx; \ | 706 | int rctx; \ |
778 | \ | 707 | \ |
708 | perf_fetch_caller_regs(&__regs, 1); \ | ||
709 | \ | ||
779 | __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \ | 710 | __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \ |
780 | __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),\ | 711 | __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),\ |
781 | sizeof(u64)); \ | 712 | sizeof(u64)); \ |
@@ -784,32 +715,34 @@ perf_trace_templ_##call(struct ftrace_event_call *event_call, \ | |||
784 | if (WARN_ONCE(__entry_size > PERF_MAX_TRACE_SIZE, \ | 715 | if (WARN_ONCE(__entry_size > PERF_MAX_TRACE_SIZE, \ |
785 | "profile buffer not large enough")) \ | 716 | "profile buffer not large enough")) \ |
786 | return; \ | 717 | return; \ |
718 | \ | ||
787 | entry = (struct ftrace_raw_##call *)perf_trace_buf_prepare( \ | 719 | entry = (struct ftrace_raw_##call *)perf_trace_buf_prepare( \ |
788 | __entry_size, event_call->id, &rctx, &irq_flags); \ | 720 | __entry_size, event_call->event.type, &__regs, &rctx); \ |
789 | if (!entry) \ | 721 | if (!entry) \ |
790 | return; \ | 722 | return; \ |
723 | \ | ||
791 | tstruct \ | 724 | tstruct \ |
792 | \ | 725 | \ |
793 | { assign; } \ | 726 | { assign; } \ |
794 | \ | 727 | \ |
728 | head = per_cpu_ptr(event_call->perf_events, smp_processor_id());\ | ||
795 | perf_trace_buf_submit(entry, __entry_size, rctx, __addr, \ | 729 | perf_trace_buf_submit(entry, __entry_size, rctx, __addr, \ |
796 | __count, irq_flags, __regs); \ | 730 | __count, &__regs, head); \ |
797 | } | 731 | } |
798 | 732 | ||
733 | /* | ||
734 | * This part is compiled out, it is only here as a build time check | ||
735 | * to make sure that if the tracepoint handling changes, the | ||
736 | * perf probe will fail to compile unless it too is updated. | ||
737 | */ | ||
799 | #undef DEFINE_EVENT | 738 | #undef DEFINE_EVENT |
800 | #define DEFINE_EVENT(template, call, proto, args) \ | 739 | #define DEFINE_EVENT(template, call, proto, args) \ |
801 | static notrace void perf_trace_##call(proto) \ | 740 | static inline void perf_test_probe_##call(void) \ |
802 | { \ | 741 | { \ |
803 | struct ftrace_event_call *event_call = &event_##call; \ | 742 | check_trace_callback_type_##call(perf_trace_##template); \ |
804 | struct pt_regs *__regs = &get_cpu_var(perf_trace_regs); \ | ||
805 | \ | ||
806 | perf_fetch_caller_regs(__regs, 1); \ | ||
807 | \ | ||
808 | perf_trace_templ_##template(event_call, __regs, args); \ | ||
809 | \ | ||
810 | put_cpu_var(perf_trace_regs); \ | ||
811 | } | 743 | } |
812 | 744 | ||
745 | |||
813 | #undef DEFINE_EVENT_PRINT | 746 | #undef DEFINE_EVENT_PRINT |
814 | #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \ | 747 | #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \ |
815 | DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args)) | 748 | DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args)) |
diff --git a/include/trace/syscall.h b/include/trace/syscall.h index e5e5f48dbfb3..257e08960d7b 100644 --- a/include/trace/syscall.h +++ b/include/trace/syscall.h | |||
@@ -25,6 +25,8 @@ struct syscall_metadata { | |||
25 | int nb_args; | 25 | int nb_args; |
26 | const char **types; | 26 | const char **types; |
27 | const char **args; | 27 | const char **args; |
28 | struct list_head enter_fields; | ||
29 | struct list_head exit_fields; | ||
28 | 30 | ||
29 | struct ftrace_event_call *enter_event; | 31 | struct ftrace_event_call *enter_event; |
30 | struct ftrace_event_call *exit_event; | 32 | struct ftrace_event_call *exit_event; |
@@ -34,16 +36,16 @@ struct syscall_metadata { | |||
34 | extern unsigned long arch_syscall_addr(int nr); | 36 | extern unsigned long arch_syscall_addr(int nr); |
35 | extern int init_syscall_trace(struct ftrace_event_call *call); | 37 | extern int init_syscall_trace(struct ftrace_event_call *call); |
36 | 38 | ||
37 | extern int syscall_enter_define_fields(struct ftrace_event_call *call); | ||
38 | extern int syscall_exit_define_fields(struct ftrace_event_call *call); | ||
39 | extern int reg_event_syscall_enter(struct ftrace_event_call *call); | 39 | extern int reg_event_syscall_enter(struct ftrace_event_call *call); |
40 | extern void unreg_event_syscall_enter(struct ftrace_event_call *call); | 40 | extern void unreg_event_syscall_enter(struct ftrace_event_call *call); |
41 | extern int reg_event_syscall_exit(struct ftrace_event_call *call); | 41 | extern int reg_event_syscall_exit(struct ftrace_event_call *call); |
42 | extern void unreg_event_syscall_exit(struct ftrace_event_call *call); | 42 | extern void unreg_event_syscall_exit(struct ftrace_event_call *call); |
43 | extern int | 43 | extern int |
44 | ftrace_format_syscall(struct ftrace_event_call *call, struct trace_seq *s); | 44 | ftrace_format_syscall(struct ftrace_event_call *call, struct trace_seq *s); |
45 | enum print_line_t print_syscall_enter(struct trace_iterator *iter, int flags); | 45 | enum print_line_t print_syscall_enter(struct trace_iterator *iter, int flags, |
46 | enum print_line_t print_syscall_exit(struct trace_iterator *iter, int flags); | 46 | struct trace_event *event); |
47 | enum print_line_t print_syscall_exit(struct trace_iterator *iter, int flags, | ||
48 | struct trace_event *event); | ||
47 | #endif | 49 | #endif |
48 | 50 | ||
49 | #ifdef CONFIG_PERF_EVENTS | 51 | #ifdef CONFIG_PERF_EVENTS |
diff --git a/kernel/perf_event.c b/kernel/perf_event.c index a4fa381db3c2..e099650cd249 100644 --- a/kernel/perf_event.c +++ b/kernel/perf_event.c | |||
@@ -2297,11 +2297,6 @@ unlock: | |||
2297 | rcu_read_unlock(); | 2297 | rcu_read_unlock(); |
2298 | } | 2298 | } |
2299 | 2299 | ||
2300 | static unsigned long perf_data_size(struct perf_mmap_data *data) | ||
2301 | { | ||
2302 | return data->nr_pages << (PAGE_SHIFT + data->data_order); | ||
2303 | } | ||
2304 | |||
2305 | #ifndef CONFIG_PERF_USE_VMALLOC | 2300 | #ifndef CONFIG_PERF_USE_VMALLOC |
2306 | 2301 | ||
2307 | /* | 2302 | /* |
@@ -2320,6 +2315,19 @@ perf_mmap_to_page(struct perf_mmap_data *data, unsigned long pgoff) | |||
2320 | return virt_to_page(data->data_pages[pgoff - 1]); | 2315 | return virt_to_page(data->data_pages[pgoff - 1]); |
2321 | } | 2316 | } |
2322 | 2317 | ||
2318 | static void *perf_mmap_alloc_page(int cpu) | ||
2319 | { | ||
2320 | struct page *page; | ||
2321 | int node; | ||
2322 | |||
2323 | node = (cpu == -1) ? cpu : cpu_to_node(cpu); | ||
2324 | page = alloc_pages_node(node, GFP_KERNEL | __GFP_ZERO, 0); | ||
2325 | if (!page) | ||
2326 | return NULL; | ||
2327 | |||
2328 | return page_address(page); | ||
2329 | } | ||
2330 | |||
2323 | static struct perf_mmap_data * | 2331 | static struct perf_mmap_data * |
2324 | perf_mmap_data_alloc(struct perf_event *event, int nr_pages) | 2332 | perf_mmap_data_alloc(struct perf_event *event, int nr_pages) |
2325 | { | 2333 | { |
@@ -2336,17 +2344,16 @@ perf_mmap_data_alloc(struct perf_event *event, int nr_pages) | |||
2336 | if (!data) | 2344 | if (!data) |
2337 | goto fail; | 2345 | goto fail; |
2338 | 2346 | ||
2339 | data->user_page = (void *)get_zeroed_page(GFP_KERNEL); | 2347 | data->user_page = perf_mmap_alloc_page(event->cpu); |
2340 | if (!data->user_page) | 2348 | if (!data->user_page) |
2341 | goto fail_user_page; | 2349 | goto fail_user_page; |
2342 | 2350 | ||
2343 | for (i = 0; i < nr_pages; i++) { | 2351 | for (i = 0; i < nr_pages; i++) { |
2344 | data->data_pages[i] = (void *)get_zeroed_page(GFP_KERNEL); | 2352 | data->data_pages[i] = perf_mmap_alloc_page(event->cpu); |
2345 | if (!data->data_pages[i]) | 2353 | if (!data->data_pages[i]) |
2346 | goto fail_data_pages; | 2354 | goto fail_data_pages; |
2347 | } | 2355 | } |
2348 | 2356 | ||
2349 | data->data_order = 0; | ||
2350 | data->nr_pages = nr_pages; | 2357 | data->nr_pages = nr_pages; |
2351 | 2358 | ||
2352 | return data; | 2359 | return data; |
@@ -2382,6 +2389,11 @@ static void perf_mmap_data_free(struct perf_mmap_data *data) | |||
2382 | kfree(data); | 2389 | kfree(data); |
2383 | } | 2390 | } |
2384 | 2391 | ||
2392 | static inline int page_order(struct perf_mmap_data *data) | ||
2393 | { | ||
2394 | return 0; | ||
2395 | } | ||
2396 | |||
2385 | #else | 2397 | #else |
2386 | 2398 | ||
2387 | /* | 2399 | /* |
@@ -2390,10 +2402,15 @@ static void perf_mmap_data_free(struct perf_mmap_data *data) | |||
2390 | * Required for architectures that have d-cache aliasing issues. | 2402 | * Required for architectures that have d-cache aliasing issues. |
2391 | */ | 2403 | */ |
2392 | 2404 | ||
2405 | static inline int page_order(struct perf_mmap_data *data) | ||
2406 | { | ||
2407 | return data->page_order; | ||
2408 | } | ||
2409 | |||
2393 | static struct page * | 2410 | static struct page * |
2394 | perf_mmap_to_page(struct perf_mmap_data *data, unsigned long pgoff) | 2411 | perf_mmap_to_page(struct perf_mmap_data *data, unsigned long pgoff) |
2395 | { | 2412 | { |
2396 | if (pgoff > (1UL << data->data_order)) | 2413 | if (pgoff > (1UL << page_order(data))) |
2397 | return NULL; | 2414 | return NULL; |
2398 | 2415 | ||
2399 | return vmalloc_to_page((void *)data->user_page + pgoff * PAGE_SIZE); | 2416 | return vmalloc_to_page((void *)data->user_page + pgoff * PAGE_SIZE); |
@@ -2413,7 +2430,7 @@ static void perf_mmap_data_free_work(struct work_struct *work) | |||
2413 | int i, nr; | 2430 | int i, nr; |
2414 | 2431 | ||
2415 | data = container_of(work, struct perf_mmap_data, work); | 2432 | data = container_of(work, struct perf_mmap_data, work); |
2416 | nr = 1 << data->data_order; | 2433 | nr = 1 << page_order(data); |
2417 | 2434 | ||
2418 | base = data->user_page; | 2435 | base = data->user_page; |
2419 | for (i = 0; i < nr + 1; i++) | 2436 | for (i = 0; i < nr + 1; i++) |
@@ -2452,7 +2469,7 @@ perf_mmap_data_alloc(struct perf_event *event, int nr_pages) | |||
2452 | 2469 | ||
2453 | data->user_page = all_buf; | 2470 | data->user_page = all_buf; |
2454 | data->data_pages[0] = all_buf + PAGE_SIZE; | 2471 | data->data_pages[0] = all_buf + PAGE_SIZE; |
2455 | data->data_order = ilog2(nr_pages); | 2472 | data->page_order = ilog2(nr_pages); |
2456 | data->nr_pages = 1; | 2473 | data->nr_pages = 1; |
2457 | 2474 | ||
2458 | return data; | 2475 | return data; |
@@ -2466,6 +2483,11 @@ fail: | |||
2466 | 2483 | ||
2467 | #endif | 2484 | #endif |
2468 | 2485 | ||
2486 | static unsigned long perf_data_size(struct perf_mmap_data *data) | ||
2487 | { | ||
2488 | return data->nr_pages << (PAGE_SHIFT + page_order(data)); | ||
2489 | } | ||
2490 | |||
2469 | static int perf_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf) | 2491 | static int perf_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf) |
2470 | { | 2492 | { |
2471 | struct perf_event *event = vma->vm_file->private_data; | 2493 | struct perf_event *event = vma->vm_file->private_data; |
@@ -2506,8 +2528,6 @@ perf_mmap_data_init(struct perf_event *event, struct perf_mmap_data *data) | |||
2506 | { | 2528 | { |
2507 | long max_size = perf_data_size(data); | 2529 | long max_size = perf_data_size(data); |
2508 | 2530 | ||
2509 | atomic_set(&data->lock, -1); | ||
2510 | |||
2511 | if (event->attr.watermark) { | 2531 | if (event->attr.watermark) { |
2512 | data->watermark = min_t(long, max_size, | 2532 | data->watermark = min_t(long, max_size, |
2513 | event->attr.wakeup_watermark); | 2533 | event->attr.wakeup_watermark); |
@@ -2580,6 +2600,14 @@ static int perf_mmap(struct file *file, struct vm_area_struct *vma) | |||
2580 | long user_extra, extra; | 2600 | long user_extra, extra; |
2581 | int ret = 0; | 2601 | int ret = 0; |
2582 | 2602 | ||
2603 | /* | ||
2604 | * Don't allow mmap() of inherited per-task counters. This would | ||
2605 | * create a performance issue due to all children writing to the | ||
2606 | * same buffer. | ||
2607 | */ | ||
2608 | if (event->cpu == -1 && event->attr.inherit) | ||
2609 | return -EINVAL; | ||
2610 | |||
2583 | if (!(vma->vm_flags & VM_SHARED)) | 2611 | if (!(vma->vm_flags & VM_SHARED)) |
2584 | return -EINVAL; | 2612 | return -EINVAL; |
2585 | 2613 | ||
@@ -2885,120 +2913,80 @@ static void perf_output_wakeup(struct perf_output_handle *handle) | |||
2885 | } | 2913 | } |
2886 | 2914 | ||
2887 | /* | 2915 | /* |
2888 | * Curious locking construct. | ||
2889 | * | ||
2890 | * We need to ensure a later event_id doesn't publish a head when a former | 2916 | * We need to ensure a later event_id doesn't publish a head when a former |
2891 | * event_id isn't done writing. However since we need to deal with NMIs we | 2917 | * event isn't done writing. However since we need to deal with NMIs we |
2892 | * cannot fully serialize things. | 2918 | * cannot fully serialize things. |
2893 | * | 2919 | * |
2894 | * What we do is serialize between CPUs so we only have to deal with NMI | ||
2895 | * nesting on a single CPU. | ||
2896 | * | ||
2897 | * We only publish the head (and generate a wakeup) when the outer-most | 2920 | * We only publish the head (and generate a wakeup) when the outer-most |
2898 | * event_id completes. | 2921 | * event completes. |
2899 | */ | 2922 | */ |
2900 | static void perf_output_lock(struct perf_output_handle *handle) | 2923 | static void perf_output_get_handle(struct perf_output_handle *handle) |
2901 | { | 2924 | { |
2902 | struct perf_mmap_data *data = handle->data; | 2925 | struct perf_mmap_data *data = handle->data; |
2903 | int cur, cpu = get_cpu(); | ||
2904 | |||
2905 | handle->locked = 0; | ||
2906 | |||
2907 | for (;;) { | ||
2908 | cur = atomic_cmpxchg(&data->lock, -1, cpu); | ||
2909 | if (cur == -1) { | ||
2910 | handle->locked = 1; | ||
2911 | break; | ||
2912 | } | ||
2913 | if (cur == cpu) | ||
2914 | break; | ||
2915 | 2926 | ||
2916 | cpu_relax(); | 2927 | preempt_disable(); |
2917 | } | 2928 | local_inc(&data->nest); |
2929 | handle->wakeup = local_read(&data->wakeup); | ||
2918 | } | 2930 | } |
2919 | 2931 | ||
2920 | static void perf_output_unlock(struct perf_output_handle *handle) | 2932 | static void perf_output_put_handle(struct perf_output_handle *handle) |
2921 | { | 2933 | { |
2922 | struct perf_mmap_data *data = handle->data; | 2934 | struct perf_mmap_data *data = handle->data; |
2923 | unsigned long head; | 2935 | unsigned long head; |
2924 | int cpu; | ||
2925 | |||
2926 | data->done_head = data->head; | ||
2927 | |||
2928 | if (!handle->locked) | ||
2929 | goto out; | ||
2930 | 2936 | ||
2931 | again: | 2937 | again: |
2932 | /* | 2938 | head = local_read(&data->head); |
2933 | * The xchg implies a full barrier that ensures all writes are done | ||
2934 | * before we publish the new head, matched by a rmb() in userspace when | ||
2935 | * reading this position. | ||
2936 | */ | ||
2937 | while ((head = atomic_long_xchg(&data->done_head, 0))) | ||
2938 | data->user_page->data_head = head; | ||
2939 | 2939 | ||
2940 | /* | 2940 | /* |
2941 | * NMI can happen here, which means we can miss a done_head update. | 2941 | * IRQ/NMI can happen here, which means we can miss a head update. |
2942 | */ | 2942 | */ |
2943 | 2943 | ||
2944 | cpu = atomic_xchg(&data->lock, -1); | 2944 | if (!local_dec_and_test(&data->nest)) |
2945 | WARN_ON_ONCE(cpu != smp_processor_id()); | 2945 | goto out; |
2946 | 2946 | ||
2947 | /* | 2947 | /* |
2948 | * Therefore we have to validate we did not indeed do so. | 2948 | * Publish the known good head. Rely on the full barrier implied |
2949 | * by atomic_dec_and_test() order the data->head read and this | ||
2950 | * write. | ||
2949 | */ | 2951 | */ |
2950 | if (unlikely(atomic_long_read(&data->done_head))) { | 2952 | data->user_page->data_head = head; |
2951 | /* | ||
2952 | * Since we had it locked, we can lock it again. | ||
2953 | */ | ||
2954 | while (atomic_cmpxchg(&data->lock, -1, cpu) != -1) | ||
2955 | cpu_relax(); | ||
2956 | 2953 | ||
2954 | /* | ||
2955 | * Now check if we missed an update, rely on the (compiler) | ||
2956 | * barrier in atomic_dec_and_test() to re-read data->head. | ||
2957 | */ | ||
2958 | if (unlikely(head != local_read(&data->head))) { | ||
2959 | local_inc(&data->nest); | ||
2957 | goto again; | 2960 | goto again; |
2958 | } | 2961 | } |
2959 | 2962 | ||
2960 | if (atomic_xchg(&data->wakeup, 0)) | 2963 | if (handle->wakeup != local_read(&data->wakeup)) |
2961 | perf_output_wakeup(handle); | 2964 | perf_output_wakeup(handle); |
2962 | out: | 2965 | |
2963 | put_cpu(); | 2966 | out: |
2967 | preempt_enable(); | ||
2964 | } | 2968 | } |
2965 | 2969 | ||
2966 | void perf_output_copy(struct perf_output_handle *handle, | 2970 | __always_inline void perf_output_copy(struct perf_output_handle *handle, |
2967 | const void *buf, unsigned int len) | 2971 | const void *buf, unsigned int len) |
2968 | { | 2972 | { |
2969 | unsigned int pages_mask; | ||
2970 | unsigned long offset; | ||
2971 | unsigned int size; | ||
2972 | void **pages; | ||
2973 | |||
2974 | offset = handle->offset; | ||
2975 | pages_mask = handle->data->nr_pages - 1; | ||
2976 | pages = handle->data->data_pages; | ||
2977 | |||
2978 | do { | 2973 | do { |
2979 | unsigned long page_offset; | 2974 | unsigned long size = min_t(unsigned long, handle->size, len); |
2980 | unsigned long page_size; | ||
2981 | int nr; | ||
2982 | 2975 | ||
2983 | nr = (offset >> PAGE_SHIFT) & pages_mask; | 2976 | memcpy(handle->addr, buf, size); |
2984 | page_size = 1UL << (handle->data->data_order + PAGE_SHIFT); | ||
2985 | page_offset = offset & (page_size - 1); | ||
2986 | size = min_t(unsigned int, page_size - page_offset, len); | ||
2987 | 2977 | ||
2988 | memcpy(pages[nr] + page_offset, buf, size); | 2978 | len -= size; |
2979 | handle->addr += size; | ||
2980 | handle->size -= size; | ||
2981 | if (!handle->size) { | ||
2982 | struct perf_mmap_data *data = handle->data; | ||
2989 | 2983 | ||
2990 | len -= size; | 2984 | handle->page++; |
2991 | buf += size; | 2985 | handle->page &= data->nr_pages - 1; |
2992 | offset += size; | 2986 | handle->addr = data->data_pages[handle->page]; |
2987 | handle->size = PAGE_SIZE << page_order(data); | ||
2988 | } | ||
2993 | } while (len); | 2989 | } while (len); |
2994 | |||
2995 | handle->offset = offset; | ||
2996 | |||
2997 | /* | ||
2998 | * Check we didn't copy past our reservation window, taking the | ||
2999 | * possible unsigned int wrap into account. | ||
3000 | */ | ||
3001 | WARN_ON_ONCE(((long)(handle->head - handle->offset)) < 0); | ||
3002 | } | 2990 | } |
3003 | 2991 | ||
3004 | int perf_output_begin(struct perf_output_handle *handle, | 2992 | int perf_output_begin(struct perf_output_handle *handle, |
@@ -3036,13 +3024,13 @@ int perf_output_begin(struct perf_output_handle *handle, | |||
3036 | handle->sample = sample; | 3024 | handle->sample = sample; |
3037 | 3025 | ||
3038 | if (!data->nr_pages) | 3026 | if (!data->nr_pages) |
3039 | goto fail; | 3027 | goto out; |
3040 | 3028 | ||
3041 | have_lost = atomic_read(&data->lost); | 3029 | have_lost = local_read(&data->lost); |
3042 | if (have_lost) | 3030 | if (have_lost) |
3043 | size += sizeof(lost_event); | 3031 | size += sizeof(lost_event); |
3044 | 3032 | ||
3045 | perf_output_lock(handle); | 3033 | perf_output_get_handle(handle); |
3046 | 3034 | ||
3047 | do { | 3035 | do { |
3048 | /* | 3036 | /* |
@@ -3052,24 +3040,28 @@ int perf_output_begin(struct perf_output_handle *handle, | |||
3052 | */ | 3040 | */ |
3053 | tail = ACCESS_ONCE(data->user_page->data_tail); | 3041 | tail = ACCESS_ONCE(data->user_page->data_tail); |
3054 | smp_rmb(); | 3042 | smp_rmb(); |
3055 | offset = head = atomic_long_read(&data->head); | 3043 | offset = head = local_read(&data->head); |
3056 | head += size; | 3044 | head += size; |
3057 | if (unlikely(!perf_output_space(data, tail, offset, head))) | 3045 | if (unlikely(!perf_output_space(data, tail, offset, head))) |
3058 | goto fail; | 3046 | goto fail; |
3059 | } while (atomic_long_cmpxchg(&data->head, offset, head) != offset); | 3047 | } while (local_cmpxchg(&data->head, offset, head) != offset); |
3060 | 3048 | ||
3061 | handle->offset = offset; | 3049 | if (head - local_read(&data->wakeup) > data->watermark) |
3062 | handle->head = head; | 3050 | local_add(data->watermark, &data->wakeup); |
3063 | 3051 | ||
3064 | if (head - tail > data->watermark) | 3052 | handle->page = offset >> (PAGE_SHIFT + page_order(data)); |
3065 | atomic_set(&data->wakeup, 1); | 3053 | handle->page &= data->nr_pages - 1; |
3054 | handle->size = offset & ((PAGE_SIZE << page_order(data)) - 1); | ||
3055 | handle->addr = data->data_pages[handle->page]; | ||
3056 | handle->addr += handle->size; | ||
3057 | handle->size = (PAGE_SIZE << page_order(data)) - handle->size; | ||
3066 | 3058 | ||
3067 | if (have_lost) { | 3059 | if (have_lost) { |
3068 | lost_event.header.type = PERF_RECORD_LOST; | 3060 | lost_event.header.type = PERF_RECORD_LOST; |
3069 | lost_event.header.misc = 0; | 3061 | lost_event.header.misc = 0; |
3070 | lost_event.header.size = sizeof(lost_event); | 3062 | lost_event.header.size = sizeof(lost_event); |
3071 | lost_event.id = event->id; | 3063 | lost_event.id = event->id; |
3072 | lost_event.lost = atomic_xchg(&data->lost, 0); | 3064 | lost_event.lost = local_xchg(&data->lost, 0); |
3073 | 3065 | ||
3074 | perf_output_put(handle, lost_event); | 3066 | perf_output_put(handle, lost_event); |
3075 | } | 3067 | } |
@@ -3077,8 +3069,8 @@ int perf_output_begin(struct perf_output_handle *handle, | |||
3077 | return 0; | 3069 | return 0; |
3078 | 3070 | ||
3079 | fail: | 3071 | fail: |
3080 | atomic_inc(&data->lost); | 3072 | local_inc(&data->lost); |
3081 | perf_output_unlock(handle); | 3073 | perf_output_put_handle(handle); |
3082 | out: | 3074 | out: |
3083 | rcu_read_unlock(); | 3075 | rcu_read_unlock(); |
3084 | 3076 | ||
@@ -3093,14 +3085,14 @@ void perf_output_end(struct perf_output_handle *handle) | |||
3093 | int wakeup_events = event->attr.wakeup_events; | 3085 | int wakeup_events = event->attr.wakeup_events; |
3094 | 3086 | ||
3095 | if (handle->sample && wakeup_events) { | 3087 | if (handle->sample && wakeup_events) { |
3096 | int events = atomic_inc_return(&data->events); | 3088 | int events = local_inc_return(&data->events); |
3097 | if (events >= wakeup_events) { | 3089 | if (events >= wakeup_events) { |
3098 | atomic_sub(wakeup_events, &data->events); | 3090 | local_sub(wakeup_events, &data->events); |
3099 | atomic_set(&data->wakeup, 1); | 3091 | local_inc(&data->wakeup); |
3100 | } | 3092 | } |
3101 | } | 3093 | } |
3102 | 3094 | ||
3103 | perf_output_unlock(handle); | 3095 | perf_output_put_handle(handle); |
3104 | rcu_read_unlock(); | 3096 | rcu_read_unlock(); |
3105 | } | 3097 | } |
3106 | 3098 | ||
@@ -3436,22 +3428,13 @@ static void perf_event_task_output(struct perf_event *event, | |||
3436 | { | 3428 | { |
3437 | struct perf_output_handle handle; | 3429 | struct perf_output_handle handle; |
3438 | struct task_struct *task = task_event->task; | 3430 | struct task_struct *task = task_event->task; |
3439 | unsigned long flags; | ||
3440 | int size, ret; | 3431 | int size, ret; |
3441 | 3432 | ||
3442 | /* | ||
3443 | * If this CPU attempts to acquire an rq lock held by a CPU spinning | ||
3444 | * in perf_output_lock() from interrupt context, it's game over. | ||
3445 | */ | ||
3446 | local_irq_save(flags); | ||
3447 | |||
3448 | size = task_event->event_id.header.size; | 3433 | size = task_event->event_id.header.size; |
3449 | ret = perf_output_begin(&handle, event, size, 0, 0); | 3434 | ret = perf_output_begin(&handle, event, size, 0, 0); |
3450 | 3435 | ||
3451 | if (ret) { | 3436 | if (ret) |
3452 | local_irq_restore(flags); | ||
3453 | return; | 3437 | return; |
3454 | } | ||
3455 | 3438 | ||
3456 | task_event->event_id.pid = perf_event_pid(event, task); | 3439 | task_event->event_id.pid = perf_event_pid(event, task); |
3457 | task_event->event_id.ppid = perf_event_pid(event, current); | 3440 | task_event->event_id.ppid = perf_event_pid(event, current); |
@@ -3462,7 +3445,6 @@ static void perf_event_task_output(struct perf_event *event, | |||
3462 | perf_output_put(&handle, task_event->event_id); | 3445 | perf_output_put(&handle, task_event->event_id); |
3463 | 3446 | ||
3464 | perf_output_end(&handle); | 3447 | perf_output_end(&handle); |
3465 | local_irq_restore(flags); | ||
3466 | } | 3448 | } |
3467 | 3449 | ||
3468 | static int perf_event_task_match(struct perf_event *event) | 3450 | static int perf_event_task_match(struct perf_event *event) |
@@ -4020,9 +4002,6 @@ static void perf_swevent_add(struct perf_event *event, u64 nr, | |||
4020 | perf_swevent_overflow(event, 0, nmi, data, regs); | 4002 | perf_swevent_overflow(event, 0, nmi, data, regs); |
4021 | } | 4003 | } |
4022 | 4004 | ||
4023 | static int perf_tp_event_match(struct perf_event *event, | ||
4024 | struct perf_sample_data *data); | ||
4025 | |||
4026 | static int perf_exclude_event(struct perf_event *event, | 4005 | static int perf_exclude_event(struct perf_event *event, |
4027 | struct pt_regs *regs) | 4006 | struct pt_regs *regs) |
4028 | { | 4007 | { |
@@ -4052,10 +4031,6 @@ static int perf_swevent_match(struct perf_event *event, | |||
4052 | if (perf_exclude_event(event, regs)) | 4031 | if (perf_exclude_event(event, regs)) |
4053 | return 0; | 4032 | return 0; |
4054 | 4033 | ||
4055 | if (event->attr.type == PERF_TYPE_TRACEPOINT && | ||
4056 | !perf_tp_event_match(event, data)) | ||
4057 | return 0; | ||
4058 | |||
4059 | return 1; | 4034 | return 1; |
4060 | } | 4035 | } |
4061 | 4036 | ||
@@ -4066,19 +4041,46 @@ static inline u64 swevent_hash(u64 type, u32 event_id) | |||
4066 | return hash_64(val, SWEVENT_HLIST_BITS); | 4041 | return hash_64(val, SWEVENT_HLIST_BITS); |
4067 | } | 4042 | } |
4068 | 4043 | ||
4069 | static struct hlist_head * | 4044 | static inline struct hlist_head * |
4070 | find_swevent_head(struct perf_cpu_context *ctx, u64 type, u32 event_id) | 4045 | __find_swevent_head(struct swevent_hlist *hlist, u64 type, u32 event_id) |
4071 | { | 4046 | { |
4072 | u64 hash; | 4047 | u64 hash = swevent_hash(type, event_id); |
4073 | struct swevent_hlist *hlist; | 4048 | |
4049 | return &hlist->heads[hash]; | ||
4050 | } | ||
4074 | 4051 | ||
4075 | hash = swevent_hash(type, event_id); | 4052 | /* For the read side: events when they trigger */ |
4053 | static inline struct hlist_head * | ||
4054 | find_swevent_head_rcu(struct perf_cpu_context *ctx, u64 type, u32 event_id) | ||
4055 | { | ||
4056 | struct swevent_hlist *hlist; | ||
4076 | 4057 | ||
4077 | hlist = rcu_dereference(ctx->swevent_hlist); | 4058 | hlist = rcu_dereference(ctx->swevent_hlist); |
4078 | if (!hlist) | 4059 | if (!hlist) |
4079 | return NULL; | 4060 | return NULL; |
4080 | 4061 | ||
4081 | return &hlist->heads[hash]; | 4062 | return __find_swevent_head(hlist, type, event_id); |
4063 | } | ||
4064 | |||
4065 | /* For the event head insertion and removal in the hlist */ | ||
4066 | static inline struct hlist_head * | ||
4067 | find_swevent_head(struct perf_cpu_context *ctx, struct perf_event *event) | ||
4068 | { | ||
4069 | struct swevent_hlist *hlist; | ||
4070 | u32 event_id = event->attr.config; | ||
4071 | u64 type = event->attr.type; | ||
4072 | |||
4073 | /* | ||
4074 | * Event scheduling is always serialized against hlist allocation | ||
4075 | * and release. Which makes the protected version suitable here. | ||
4076 | * The context lock guarantees that. | ||
4077 | */ | ||
4078 | hlist = rcu_dereference_protected(ctx->swevent_hlist, | ||
4079 | lockdep_is_held(&event->ctx->lock)); | ||
4080 | if (!hlist) | ||
4081 | return NULL; | ||
4082 | |||
4083 | return __find_swevent_head(hlist, type, event_id); | ||
4082 | } | 4084 | } |
4083 | 4085 | ||
4084 | static void do_perf_sw_event(enum perf_type_id type, u32 event_id, | 4086 | static void do_perf_sw_event(enum perf_type_id type, u32 event_id, |
@@ -4095,7 +4097,7 @@ static void do_perf_sw_event(enum perf_type_id type, u32 event_id, | |||
4095 | 4097 | ||
4096 | rcu_read_lock(); | 4098 | rcu_read_lock(); |
4097 | 4099 | ||
4098 | head = find_swevent_head(cpuctx, type, event_id); | 4100 | head = find_swevent_head_rcu(cpuctx, type, event_id); |
4099 | 4101 | ||
4100 | if (!head) | 4102 | if (!head) |
4101 | goto end; | 4103 | goto end; |
@@ -4110,7 +4112,7 @@ end: | |||
4110 | 4112 | ||
4111 | int perf_swevent_get_recursion_context(void) | 4113 | int perf_swevent_get_recursion_context(void) |
4112 | { | 4114 | { |
4113 | struct perf_cpu_context *cpuctx = &get_cpu_var(perf_cpu_context); | 4115 | struct perf_cpu_context *cpuctx = &__get_cpu_var(perf_cpu_context); |
4114 | int rctx; | 4116 | int rctx; |
4115 | 4117 | ||
4116 | if (in_nmi()) | 4118 | if (in_nmi()) |
@@ -4122,10 +4124,8 @@ int perf_swevent_get_recursion_context(void) | |||
4122 | else | 4124 | else |
4123 | rctx = 0; | 4125 | rctx = 0; |
4124 | 4126 | ||
4125 | if (cpuctx->recursion[rctx]) { | 4127 | if (cpuctx->recursion[rctx]) |
4126 | put_cpu_var(perf_cpu_context); | ||
4127 | return -1; | 4128 | return -1; |
4128 | } | ||
4129 | 4129 | ||
4130 | cpuctx->recursion[rctx]++; | 4130 | cpuctx->recursion[rctx]++; |
4131 | barrier(); | 4131 | barrier(); |
@@ -4139,7 +4139,6 @@ void perf_swevent_put_recursion_context(int rctx) | |||
4139 | struct perf_cpu_context *cpuctx = &__get_cpu_var(perf_cpu_context); | 4139 | struct perf_cpu_context *cpuctx = &__get_cpu_var(perf_cpu_context); |
4140 | barrier(); | 4140 | barrier(); |
4141 | cpuctx->recursion[rctx]--; | 4141 | cpuctx->recursion[rctx]--; |
4142 | put_cpu_var(perf_cpu_context); | ||
4143 | } | 4142 | } |
4144 | EXPORT_SYMBOL_GPL(perf_swevent_put_recursion_context); | 4143 | EXPORT_SYMBOL_GPL(perf_swevent_put_recursion_context); |
4145 | 4144 | ||
@@ -4150,6 +4149,7 @@ void __perf_sw_event(u32 event_id, u64 nr, int nmi, | |||
4150 | struct perf_sample_data data; | 4149 | struct perf_sample_data data; |
4151 | int rctx; | 4150 | int rctx; |
4152 | 4151 | ||
4152 | preempt_disable_notrace(); | ||
4153 | rctx = perf_swevent_get_recursion_context(); | 4153 | rctx = perf_swevent_get_recursion_context(); |
4154 | if (rctx < 0) | 4154 | if (rctx < 0) |
4155 | return; | 4155 | return; |
@@ -4159,6 +4159,7 @@ void __perf_sw_event(u32 event_id, u64 nr, int nmi, | |||
4159 | do_perf_sw_event(PERF_TYPE_SOFTWARE, event_id, nr, nmi, &data, regs); | 4159 | do_perf_sw_event(PERF_TYPE_SOFTWARE, event_id, nr, nmi, &data, regs); |
4160 | 4160 | ||
4161 | perf_swevent_put_recursion_context(rctx); | 4161 | perf_swevent_put_recursion_context(rctx); |
4162 | preempt_enable_notrace(); | ||
4162 | } | 4163 | } |
4163 | 4164 | ||
4164 | static void perf_swevent_read(struct perf_event *event) | 4165 | static void perf_swevent_read(struct perf_event *event) |
@@ -4178,7 +4179,7 @@ static int perf_swevent_enable(struct perf_event *event) | |||
4178 | perf_swevent_set_period(event); | 4179 | perf_swevent_set_period(event); |
4179 | } | 4180 | } |
4180 | 4181 | ||
4181 | head = find_swevent_head(cpuctx, event->attr.type, event->attr.config); | 4182 | head = find_swevent_head(cpuctx, event); |
4182 | if (WARN_ON_ONCE(!head)) | 4183 | if (WARN_ON_ONCE(!head)) |
4183 | return -EINVAL; | 4184 | return -EINVAL; |
4184 | 4185 | ||
@@ -4366,6 +4367,14 @@ static const struct pmu perf_ops_task_clock = { | |||
4366 | .read = task_clock_perf_event_read, | 4367 | .read = task_clock_perf_event_read, |
4367 | }; | 4368 | }; |
4368 | 4369 | ||
4370 | /* Deref the hlist from the update side */ | ||
4371 | static inline struct swevent_hlist * | ||
4372 | swevent_hlist_deref(struct perf_cpu_context *cpuctx) | ||
4373 | { | ||
4374 | return rcu_dereference_protected(cpuctx->swevent_hlist, | ||
4375 | lockdep_is_held(&cpuctx->hlist_mutex)); | ||
4376 | } | ||
4377 | |||
4369 | static void swevent_hlist_release_rcu(struct rcu_head *rcu_head) | 4378 | static void swevent_hlist_release_rcu(struct rcu_head *rcu_head) |
4370 | { | 4379 | { |
4371 | struct swevent_hlist *hlist; | 4380 | struct swevent_hlist *hlist; |
@@ -4376,12 +4385,11 @@ static void swevent_hlist_release_rcu(struct rcu_head *rcu_head) | |||
4376 | 4385 | ||
4377 | static void swevent_hlist_release(struct perf_cpu_context *cpuctx) | 4386 | static void swevent_hlist_release(struct perf_cpu_context *cpuctx) |
4378 | { | 4387 | { |
4379 | struct swevent_hlist *hlist; | 4388 | struct swevent_hlist *hlist = swevent_hlist_deref(cpuctx); |
4380 | 4389 | ||
4381 | if (!cpuctx->swevent_hlist) | 4390 | if (!hlist) |
4382 | return; | 4391 | return; |
4383 | 4392 | ||
4384 | hlist = cpuctx->swevent_hlist; | ||
4385 | rcu_assign_pointer(cpuctx->swevent_hlist, NULL); | 4393 | rcu_assign_pointer(cpuctx->swevent_hlist, NULL); |
4386 | call_rcu(&hlist->rcu_head, swevent_hlist_release_rcu); | 4394 | call_rcu(&hlist->rcu_head, swevent_hlist_release_rcu); |
4387 | } | 4395 | } |
@@ -4418,7 +4426,7 @@ static int swevent_hlist_get_cpu(struct perf_event *event, int cpu) | |||
4418 | 4426 | ||
4419 | mutex_lock(&cpuctx->hlist_mutex); | 4427 | mutex_lock(&cpuctx->hlist_mutex); |
4420 | 4428 | ||
4421 | if (!cpuctx->swevent_hlist && cpu_online(cpu)) { | 4429 | if (!swevent_hlist_deref(cpuctx) && cpu_online(cpu)) { |
4422 | struct swevent_hlist *hlist; | 4430 | struct swevent_hlist *hlist; |
4423 | 4431 | ||
4424 | hlist = kzalloc(sizeof(*hlist), GFP_KERNEL); | 4432 | hlist = kzalloc(sizeof(*hlist), GFP_KERNEL); |
@@ -4467,10 +4475,46 @@ static int swevent_hlist_get(struct perf_event *event) | |||
4467 | 4475 | ||
4468 | #ifdef CONFIG_EVENT_TRACING | 4476 | #ifdef CONFIG_EVENT_TRACING |
4469 | 4477 | ||
4470 | void perf_tp_event(int event_id, u64 addr, u64 count, void *record, | 4478 | static const struct pmu perf_ops_tracepoint = { |
4471 | int entry_size, struct pt_regs *regs) | 4479 | .enable = perf_trace_enable, |
4480 | .disable = perf_trace_disable, | ||
4481 | .read = perf_swevent_read, | ||
4482 | .unthrottle = perf_swevent_unthrottle, | ||
4483 | }; | ||
4484 | |||
4485 | static int perf_tp_filter_match(struct perf_event *event, | ||
4486 | struct perf_sample_data *data) | ||
4487 | { | ||
4488 | void *record = data->raw->data; | ||
4489 | |||
4490 | if (likely(!event->filter) || filter_match_preds(event->filter, record)) | ||
4491 | return 1; | ||
4492 | return 0; | ||
4493 | } | ||
4494 | |||
4495 | static int perf_tp_event_match(struct perf_event *event, | ||
4496 | struct perf_sample_data *data, | ||
4497 | struct pt_regs *regs) | ||
4498 | { | ||
4499 | /* | ||
4500 | * All tracepoints are from kernel-space. | ||
4501 | */ | ||
4502 | if (event->attr.exclude_kernel) | ||
4503 | return 0; | ||
4504 | |||
4505 | if (!perf_tp_filter_match(event, data)) | ||
4506 | return 0; | ||
4507 | |||
4508 | return 1; | ||
4509 | } | ||
4510 | |||
4511 | void perf_tp_event(u64 addr, u64 count, void *record, int entry_size, | ||
4512 | struct pt_regs *regs, struct hlist_head *head) | ||
4472 | { | 4513 | { |
4473 | struct perf_sample_data data; | 4514 | struct perf_sample_data data; |
4515 | struct perf_event *event; | ||
4516 | struct hlist_node *node; | ||
4517 | |||
4474 | struct perf_raw_record raw = { | 4518 | struct perf_raw_record raw = { |
4475 | .size = entry_size, | 4519 | .size = entry_size, |
4476 | .data = record, | 4520 | .data = record, |
@@ -4479,26 +4523,18 @@ void perf_tp_event(int event_id, u64 addr, u64 count, void *record, | |||
4479 | perf_sample_data_init(&data, addr); | 4523 | perf_sample_data_init(&data, addr); |
4480 | data.raw = &raw; | 4524 | data.raw = &raw; |
4481 | 4525 | ||
4482 | /* Trace events already protected against recursion */ | 4526 | rcu_read_lock(); |
4483 | do_perf_sw_event(PERF_TYPE_TRACEPOINT, event_id, count, 1, | 4527 | hlist_for_each_entry_rcu(event, node, head, hlist_entry) { |
4484 | &data, regs); | 4528 | if (perf_tp_event_match(event, &data, regs)) |
4529 | perf_swevent_add(event, count, 1, &data, regs); | ||
4530 | } | ||
4531 | rcu_read_unlock(); | ||
4485 | } | 4532 | } |
4486 | EXPORT_SYMBOL_GPL(perf_tp_event); | 4533 | EXPORT_SYMBOL_GPL(perf_tp_event); |
4487 | 4534 | ||
4488 | static int perf_tp_event_match(struct perf_event *event, | ||
4489 | struct perf_sample_data *data) | ||
4490 | { | ||
4491 | void *record = data->raw->data; | ||
4492 | |||
4493 | if (likely(!event->filter) || filter_match_preds(event->filter, record)) | ||
4494 | return 1; | ||
4495 | return 0; | ||
4496 | } | ||
4497 | |||
4498 | static void tp_perf_event_destroy(struct perf_event *event) | 4535 | static void tp_perf_event_destroy(struct perf_event *event) |
4499 | { | 4536 | { |
4500 | perf_trace_disable(event->attr.config); | 4537 | perf_trace_destroy(event); |
4501 | swevent_hlist_put(event); | ||
4502 | } | 4538 | } |
4503 | 4539 | ||
4504 | static const struct pmu *tp_perf_event_init(struct perf_event *event) | 4540 | static const struct pmu *tp_perf_event_init(struct perf_event *event) |
@@ -4514,17 +4550,13 @@ static const struct pmu *tp_perf_event_init(struct perf_event *event) | |||
4514 | !capable(CAP_SYS_ADMIN)) | 4550 | !capable(CAP_SYS_ADMIN)) |
4515 | return ERR_PTR(-EPERM); | 4551 | return ERR_PTR(-EPERM); |
4516 | 4552 | ||
4517 | if (perf_trace_enable(event->attr.config)) | 4553 | err = perf_trace_init(event); |
4554 | if (err) | ||
4518 | return NULL; | 4555 | return NULL; |
4519 | 4556 | ||
4520 | event->destroy = tp_perf_event_destroy; | 4557 | event->destroy = tp_perf_event_destroy; |
4521 | err = swevent_hlist_get(event); | ||
4522 | if (err) { | ||
4523 | perf_trace_disable(event->attr.config); | ||
4524 | return ERR_PTR(err); | ||
4525 | } | ||
4526 | 4558 | ||
4527 | return &perf_ops_generic; | 4559 | return &perf_ops_tracepoint; |
4528 | } | 4560 | } |
4529 | 4561 | ||
4530 | static int perf_event_set_filter(struct perf_event *event, void __user *arg) | 4562 | static int perf_event_set_filter(struct perf_event *event, void __user *arg) |
@@ -4552,12 +4584,6 @@ static void perf_event_free_filter(struct perf_event *event) | |||
4552 | 4584 | ||
4553 | #else | 4585 | #else |
4554 | 4586 | ||
4555 | static int perf_tp_event_match(struct perf_event *event, | ||
4556 | struct perf_sample_data *data) | ||
4557 | { | ||
4558 | return 1; | ||
4559 | } | ||
4560 | |||
4561 | static const struct pmu *tp_perf_event_init(struct perf_event *event) | 4587 | static const struct pmu *tp_perf_event_init(struct perf_event *event) |
4562 | { | 4588 | { |
4563 | return NULL; | 4589 | return NULL; |
@@ -4894,6 +4920,13 @@ static int perf_event_set_output(struct perf_event *event, int output_fd) | |||
4894 | int fput_needed = 0; | 4920 | int fput_needed = 0; |
4895 | int ret = -EINVAL; | 4921 | int ret = -EINVAL; |
4896 | 4922 | ||
4923 | /* | ||
4924 | * Don't allow output of inherited per-task events. This would | ||
4925 | * create performance issues due to cross cpu access. | ||
4926 | */ | ||
4927 | if (event->cpu == -1 && event->attr.inherit) | ||
4928 | return -EINVAL; | ||
4929 | |||
4897 | if (!output_fd) | 4930 | if (!output_fd) |
4898 | goto set; | 4931 | goto set; |
4899 | 4932 | ||
@@ -4914,6 +4947,18 @@ static int perf_event_set_output(struct perf_event *event, int output_fd) | |||
4914 | if (event->data) | 4947 | if (event->data) |
4915 | goto out; | 4948 | goto out; |
4916 | 4949 | ||
4950 | /* | ||
4951 | * Don't allow cross-cpu buffers | ||
4952 | */ | ||
4953 | if (output_event->cpu != event->cpu) | ||
4954 | goto out; | ||
4955 | |||
4956 | /* | ||
4957 | * If its not a per-cpu buffer, it must be the same task. | ||
4958 | */ | ||
4959 | if (output_event->cpu == -1 && output_event->ctx != event->ctx) | ||
4960 | goto out; | ||
4961 | |||
4917 | atomic_long_inc(&output_file->f_count); | 4962 | atomic_long_inc(&output_file->f_count); |
4918 | 4963 | ||
4919 | set: | 4964 | set: |
diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c index b3bc91a3f510..36ea2b65dcdc 100644 --- a/kernel/trace/blktrace.c +++ b/kernel/trace/blktrace.c | |||
@@ -675,28 +675,33 @@ static void blk_add_trace_rq(struct request_queue *q, struct request *rq, | |||
675 | } | 675 | } |
676 | } | 676 | } |
677 | 677 | ||
678 | static void blk_add_trace_rq_abort(struct request_queue *q, struct request *rq) | 678 | static void blk_add_trace_rq_abort(void *ignore, |
679 | struct request_queue *q, struct request *rq) | ||
679 | { | 680 | { |
680 | blk_add_trace_rq(q, rq, BLK_TA_ABORT); | 681 | blk_add_trace_rq(q, rq, BLK_TA_ABORT); |
681 | } | 682 | } |
682 | 683 | ||
683 | static void blk_add_trace_rq_insert(struct request_queue *q, struct request *rq) | 684 | static void blk_add_trace_rq_insert(void *ignore, |
685 | struct request_queue *q, struct request *rq) | ||
684 | { | 686 | { |
685 | blk_add_trace_rq(q, rq, BLK_TA_INSERT); | 687 | blk_add_trace_rq(q, rq, BLK_TA_INSERT); |
686 | } | 688 | } |
687 | 689 | ||
688 | static void blk_add_trace_rq_issue(struct request_queue *q, struct request *rq) | 690 | static void blk_add_trace_rq_issue(void *ignore, |
691 | struct request_queue *q, struct request *rq) | ||
689 | { | 692 | { |
690 | blk_add_trace_rq(q, rq, BLK_TA_ISSUE); | 693 | blk_add_trace_rq(q, rq, BLK_TA_ISSUE); |
691 | } | 694 | } |
692 | 695 | ||
693 | static void blk_add_trace_rq_requeue(struct request_queue *q, | 696 | static void blk_add_trace_rq_requeue(void *ignore, |
697 | struct request_queue *q, | ||
694 | struct request *rq) | 698 | struct request *rq) |
695 | { | 699 | { |
696 | blk_add_trace_rq(q, rq, BLK_TA_REQUEUE); | 700 | blk_add_trace_rq(q, rq, BLK_TA_REQUEUE); |
697 | } | 701 | } |
698 | 702 | ||
699 | static void blk_add_trace_rq_complete(struct request_queue *q, | 703 | static void blk_add_trace_rq_complete(void *ignore, |
704 | struct request_queue *q, | ||
700 | struct request *rq) | 705 | struct request *rq) |
701 | { | 706 | { |
702 | blk_add_trace_rq(q, rq, BLK_TA_COMPLETE); | 707 | blk_add_trace_rq(q, rq, BLK_TA_COMPLETE); |
@@ -724,34 +729,40 @@ static void blk_add_trace_bio(struct request_queue *q, struct bio *bio, | |||
724 | !bio_flagged(bio, BIO_UPTODATE), 0, NULL); | 729 | !bio_flagged(bio, BIO_UPTODATE), 0, NULL); |
725 | } | 730 | } |
726 | 731 | ||
727 | static void blk_add_trace_bio_bounce(struct request_queue *q, struct bio *bio) | 732 | static void blk_add_trace_bio_bounce(void *ignore, |
733 | struct request_queue *q, struct bio *bio) | ||
728 | { | 734 | { |
729 | blk_add_trace_bio(q, bio, BLK_TA_BOUNCE); | 735 | blk_add_trace_bio(q, bio, BLK_TA_BOUNCE); |
730 | } | 736 | } |
731 | 737 | ||
732 | static void blk_add_trace_bio_complete(struct request_queue *q, struct bio *bio) | 738 | static void blk_add_trace_bio_complete(void *ignore, |
739 | struct request_queue *q, struct bio *bio) | ||
733 | { | 740 | { |
734 | blk_add_trace_bio(q, bio, BLK_TA_COMPLETE); | 741 | blk_add_trace_bio(q, bio, BLK_TA_COMPLETE); |
735 | } | 742 | } |
736 | 743 | ||
737 | static void blk_add_trace_bio_backmerge(struct request_queue *q, | 744 | static void blk_add_trace_bio_backmerge(void *ignore, |
745 | struct request_queue *q, | ||
738 | struct bio *bio) | 746 | struct bio *bio) |
739 | { | 747 | { |
740 | blk_add_trace_bio(q, bio, BLK_TA_BACKMERGE); | 748 | blk_add_trace_bio(q, bio, BLK_TA_BACKMERGE); |
741 | } | 749 | } |
742 | 750 | ||
743 | static void blk_add_trace_bio_frontmerge(struct request_queue *q, | 751 | static void blk_add_trace_bio_frontmerge(void *ignore, |
752 | struct request_queue *q, | ||
744 | struct bio *bio) | 753 | struct bio *bio) |
745 | { | 754 | { |
746 | blk_add_trace_bio(q, bio, BLK_TA_FRONTMERGE); | 755 | blk_add_trace_bio(q, bio, BLK_TA_FRONTMERGE); |
747 | } | 756 | } |
748 | 757 | ||
749 | static void blk_add_trace_bio_queue(struct request_queue *q, struct bio *bio) | 758 | static void blk_add_trace_bio_queue(void *ignore, |
759 | struct request_queue *q, struct bio *bio) | ||
750 | { | 760 | { |
751 | blk_add_trace_bio(q, bio, BLK_TA_QUEUE); | 761 | blk_add_trace_bio(q, bio, BLK_TA_QUEUE); |
752 | } | 762 | } |
753 | 763 | ||
754 | static void blk_add_trace_getrq(struct request_queue *q, | 764 | static void blk_add_trace_getrq(void *ignore, |
765 | struct request_queue *q, | ||
755 | struct bio *bio, int rw) | 766 | struct bio *bio, int rw) |
756 | { | 767 | { |
757 | if (bio) | 768 | if (bio) |
@@ -765,7 +776,8 @@ static void blk_add_trace_getrq(struct request_queue *q, | |||
765 | } | 776 | } |
766 | 777 | ||
767 | 778 | ||
768 | static void blk_add_trace_sleeprq(struct request_queue *q, | 779 | static void blk_add_trace_sleeprq(void *ignore, |
780 | struct request_queue *q, | ||
769 | struct bio *bio, int rw) | 781 | struct bio *bio, int rw) |
770 | { | 782 | { |
771 | if (bio) | 783 | if (bio) |
@@ -779,7 +791,7 @@ static void blk_add_trace_sleeprq(struct request_queue *q, | |||
779 | } | 791 | } |
780 | } | 792 | } |
781 | 793 | ||
782 | static void blk_add_trace_plug(struct request_queue *q) | 794 | static void blk_add_trace_plug(void *ignore, struct request_queue *q) |
783 | { | 795 | { |
784 | struct blk_trace *bt = q->blk_trace; | 796 | struct blk_trace *bt = q->blk_trace; |
785 | 797 | ||
@@ -787,7 +799,7 @@ static void blk_add_trace_plug(struct request_queue *q) | |||
787 | __blk_add_trace(bt, 0, 0, 0, BLK_TA_PLUG, 0, 0, NULL); | 799 | __blk_add_trace(bt, 0, 0, 0, BLK_TA_PLUG, 0, 0, NULL); |
788 | } | 800 | } |
789 | 801 | ||
790 | static void blk_add_trace_unplug_io(struct request_queue *q) | 802 | static void blk_add_trace_unplug_io(void *ignore, struct request_queue *q) |
791 | { | 803 | { |
792 | struct blk_trace *bt = q->blk_trace; | 804 | struct blk_trace *bt = q->blk_trace; |
793 | 805 | ||
@@ -800,7 +812,7 @@ static void blk_add_trace_unplug_io(struct request_queue *q) | |||
800 | } | 812 | } |
801 | } | 813 | } |
802 | 814 | ||
803 | static void blk_add_trace_unplug_timer(struct request_queue *q) | 815 | static void blk_add_trace_unplug_timer(void *ignore, struct request_queue *q) |
804 | { | 816 | { |
805 | struct blk_trace *bt = q->blk_trace; | 817 | struct blk_trace *bt = q->blk_trace; |
806 | 818 | ||
@@ -813,7 +825,8 @@ static void blk_add_trace_unplug_timer(struct request_queue *q) | |||
813 | } | 825 | } |
814 | } | 826 | } |
815 | 827 | ||
816 | static void blk_add_trace_split(struct request_queue *q, struct bio *bio, | 828 | static void blk_add_trace_split(void *ignore, |
829 | struct request_queue *q, struct bio *bio, | ||
817 | unsigned int pdu) | 830 | unsigned int pdu) |
818 | { | 831 | { |
819 | struct blk_trace *bt = q->blk_trace; | 832 | struct blk_trace *bt = q->blk_trace; |
@@ -839,8 +852,9 @@ static void blk_add_trace_split(struct request_queue *q, struct bio *bio, | |||
839 | * it spans a stripe (or similar). Add a trace for that action. | 852 | * it spans a stripe (or similar). Add a trace for that action. |
840 | * | 853 | * |
841 | **/ | 854 | **/ |
842 | static void blk_add_trace_remap(struct request_queue *q, struct bio *bio, | 855 | static void blk_add_trace_remap(void *ignore, |
843 | dev_t dev, sector_t from) | 856 | struct request_queue *q, struct bio *bio, |
857 | dev_t dev, sector_t from) | ||
844 | { | 858 | { |
845 | struct blk_trace *bt = q->blk_trace; | 859 | struct blk_trace *bt = q->blk_trace; |
846 | struct blk_io_trace_remap r; | 860 | struct blk_io_trace_remap r; |
@@ -869,7 +883,8 @@ static void blk_add_trace_remap(struct request_queue *q, struct bio *bio, | |||
869 | * Add a trace for that action. | 883 | * Add a trace for that action. |
870 | * | 884 | * |
871 | **/ | 885 | **/ |
872 | static void blk_add_trace_rq_remap(struct request_queue *q, | 886 | static void blk_add_trace_rq_remap(void *ignore, |
887 | struct request_queue *q, | ||
873 | struct request *rq, dev_t dev, | 888 | struct request *rq, dev_t dev, |
874 | sector_t from) | 889 | sector_t from) |
875 | { | 890 | { |
@@ -921,64 +936,64 @@ static void blk_register_tracepoints(void) | |||
921 | { | 936 | { |
922 | int ret; | 937 | int ret; |
923 | 938 | ||
924 | ret = register_trace_block_rq_abort(blk_add_trace_rq_abort); | 939 | ret = register_trace_block_rq_abort(blk_add_trace_rq_abort, NULL); |
925 | WARN_ON(ret); | 940 | WARN_ON(ret); |
926 | ret = register_trace_block_rq_insert(blk_add_trace_rq_insert); | 941 | ret = register_trace_block_rq_insert(blk_add_trace_rq_insert, NULL); |
927 | WARN_ON(ret); | 942 | WARN_ON(ret); |
928 | ret = register_trace_block_rq_issue(blk_add_trace_rq_issue); | 943 | ret = register_trace_block_rq_issue(blk_add_trace_rq_issue, NULL); |
929 | WARN_ON(ret); | 944 | WARN_ON(ret); |
930 | ret = register_trace_block_rq_requeue(blk_add_trace_rq_requeue); | 945 | ret = register_trace_block_rq_requeue(blk_add_trace_rq_requeue, NULL); |
931 | WARN_ON(ret); | 946 | WARN_ON(ret); |
932 | ret = register_trace_block_rq_complete(blk_add_trace_rq_complete); | 947 | ret = register_trace_block_rq_complete(blk_add_trace_rq_complete, NULL); |
933 | WARN_ON(ret); | 948 | WARN_ON(ret); |
934 | ret = register_trace_block_bio_bounce(blk_add_trace_bio_bounce); | 949 | ret = register_trace_block_bio_bounce(blk_add_trace_bio_bounce, NULL); |
935 | WARN_ON(ret); | 950 | WARN_ON(ret); |
936 | ret = register_trace_block_bio_complete(blk_add_trace_bio_complete); | 951 | ret = register_trace_block_bio_complete(blk_add_trace_bio_complete, NULL); |
937 | WARN_ON(ret); | 952 | WARN_ON(ret); |
938 | ret = register_trace_block_bio_backmerge(blk_add_trace_bio_backmerge); | 953 | ret = register_trace_block_bio_backmerge(blk_add_trace_bio_backmerge, NULL); |
939 | WARN_ON(ret); | 954 | WARN_ON(ret); |
940 | ret = register_trace_block_bio_frontmerge(blk_add_trace_bio_frontmerge); | 955 | ret = register_trace_block_bio_frontmerge(blk_add_trace_bio_frontmerge, NULL); |
941 | WARN_ON(ret); | 956 | WARN_ON(ret); |
942 | ret = register_trace_block_bio_queue(blk_add_trace_bio_queue); | 957 | ret = register_trace_block_bio_queue(blk_add_trace_bio_queue, NULL); |
943 | WARN_ON(ret); | 958 | WARN_ON(ret); |
944 | ret = register_trace_block_getrq(blk_add_trace_getrq); | 959 | ret = register_trace_block_getrq(blk_add_trace_getrq, NULL); |
945 | WARN_ON(ret); | 960 | WARN_ON(ret); |
946 | ret = register_trace_block_sleeprq(blk_add_trace_sleeprq); | 961 | ret = register_trace_block_sleeprq(blk_add_trace_sleeprq, NULL); |
947 | WARN_ON(ret); | 962 | WARN_ON(ret); |
948 | ret = register_trace_block_plug(blk_add_trace_plug); | 963 | ret = register_trace_block_plug(blk_add_trace_plug, NULL); |
949 | WARN_ON(ret); | 964 | WARN_ON(ret); |
950 | ret = register_trace_block_unplug_timer(blk_add_trace_unplug_timer); | 965 | ret = register_trace_block_unplug_timer(blk_add_trace_unplug_timer, NULL); |
951 | WARN_ON(ret); | 966 | WARN_ON(ret); |
952 | ret = register_trace_block_unplug_io(blk_add_trace_unplug_io); | 967 | ret = register_trace_block_unplug_io(blk_add_trace_unplug_io, NULL); |
953 | WARN_ON(ret); | 968 | WARN_ON(ret); |
954 | ret = register_trace_block_split(blk_add_trace_split); | 969 | ret = register_trace_block_split(blk_add_trace_split, NULL); |
955 | WARN_ON(ret); | 970 | WARN_ON(ret); |
956 | ret = register_trace_block_remap(blk_add_trace_remap); | 971 | ret = register_trace_block_remap(blk_add_trace_remap, NULL); |
957 | WARN_ON(ret); | 972 | WARN_ON(ret); |
958 | ret = register_trace_block_rq_remap(blk_add_trace_rq_remap); | 973 | ret = register_trace_block_rq_remap(blk_add_trace_rq_remap, NULL); |
959 | WARN_ON(ret); | 974 | WARN_ON(ret); |
960 | } | 975 | } |
961 | 976 | ||
962 | static void blk_unregister_tracepoints(void) | 977 | static void blk_unregister_tracepoints(void) |
963 | { | 978 | { |
964 | unregister_trace_block_rq_remap(blk_add_trace_rq_remap); | 979 | unregister_trace_block_rq_remap(blk_add_trace_rq_remap, NULL); |
965 | unregister_trace_block_remap(blk_add_trace_remap); | 980 | unregister_trace_block_remap(blk_add_trace_remap, NULL); |
966 | unregister_trace_block_split(blk_add_trace_split); | 981 | unregister_trace_block_split(blk_add_trace_split, NULL); |
967 | unregister_trace_block_unplug_io(blk_add_trace_unplug_io); | 982 | unregister_trace_block_unplug_io(blk_add_trace_unplug_io, NULL); |
968 | unregister_trace_block_unplug_timer(blk_add_trace_unplug_timer); | 983 | unregister_trace_block_unplug_timer(blk_add_trace_unplug_timer, NULL); |
969 | unregister_trace_block_plug(blk_add_trace_plug); | 984 | unregister_trace_block_plug(blk_add_trace_plug, NULL); |
970 | unregister_trace_block_sleeprq(blk_add_trace_sleeprq); | 985 | unregister_trace_block_sleeprq(blk_add_trace_sleeprq, NULL); |
971 | unregister_trace_block_getrq(blk_add_trace_getrq); | 986 | unregister_trace_block_getrq(blk_add_trace_getrq, NULL); |
972 | unregister_trace_block_bio_queue(blk_add_trace_bio_queue); | 987 | unregister_trace_block_bio_queue(blk_add_trace_bio_queue, NULL); |
973 | unregister_trace_block_bio_frontmerge(blk_add_trace_bio_frontmerge); | 988 | unregister_trace_block_bio_frontmerge(blk_add_trace_bio_frontmerge, NULL); |
974 | unregister_trace_block_bio_backmerge(blk_add_trace_bio_backmerge); | 989 | unregister_trace_block_bio_backmerge(blk_add_trace_bio_backmerge, NULL); |
975 | unregister_trace_block_bio_complete(blk_add_trace_bio_complete); | 990 | unregister_trace_block_bio_complete(blk_add_trace_bio_complete, NULL); |
976 | unregister_trace_block_bio_bounce(blk_add_trace_bio_bounce); | 991 | unregister_trace_block_bio_bounce(blk_add_trace_bio_bounce, NULL); |
977 | unregister_trace_block_rq_complete(blk_add_trace_rq_complete); | 992 | unregister_trace_block_rq_complete(blk_add_trace_rq_complete, NULL); |
978 | unregister_trace_block_rq_requeue(blk_add_trace_rq_requeue); | 993 | unregister_trace_block_rq_requeue(blk_add_trace_rq_requeue, NULL); |
979 | unregister_trace_block_rq_issue(blk_add_trace_rq_issue); | 994 | unregister_trace_block_rq_issue(blk_add_trace_rq_issue, NULL); |
980 | unregister_trace_block_rq_insert(blk_add_trace_rq_insert); | 995 | unregister_trace_block_rq_insert(blk_add_trace_rq_insert, NULL); |
981 | unregister_trace_block_rq_abort(blk_add_trace_rq_abort); | 996 | unregister_trace_block_rq_abort(blk_add_trace_rq_abort, NULL); |
982 | 997 | ||
983 | tracepoint_synchronize_unregister(); | 998 | tracepoint_synchronize_unregister(); |
984 | } | 999 | } |
@@ -1321,7 +1336,7 @@ out: | |||
1321 | } | 1336 | } |
1322 | 1337 | ||
1323 | static enum print_line_t blk_trace_event_print(struct trace_iterator *iter, | 1338 | static enum print_line_t blk_trace_event_print(struct trace_iterator *iter, |
1324 | int flags) | 1339 | int flags, struct trace_event *event) |
1325 | { | 1340 | { |
1326 | return print_one_line(iter, false); | 1341 | return print_one_line(iter, false); |
1327 | } | 1342 | } |
@@ -1343,7 +1358,8 @@ static int blk_trace_synthesize_old_trace(struct trace_iterator *iter) | |||
1343 | } | 1358 | } |
1344 | 1359 | ||
1345 | static enum print_line_t | 1360 | static enum print_line_t |
1346 | blk_trace_event_print_binary(struct trace_iterator *iter, int flags) | 1361 | blk_trace_event_print_binary(struct trace_iterator *iter, int flags, |
1362 | struct trace_event *event) | ||
1347 | { | 1363 | { |
1348 | return blk_trace_synthesize_old_trace(iter) ? | 1364 | return blk_trace_synthesize_old_trace(iter) ? |
1349 | TRACE_TYPE_HANDLED : TRACE_TYPE_PARTIAL_LINE; | 1365 | TRACE_TYPE_HANDLED : TRACE_TYPE_PARTIAL_LINE; |
@@ -1381,12 +1397,16 @@ static struct tracer blk_tracer __read_mostly = { | |||
1381 | .set_flag = blk_tracer_set_flag, | 1397 | .set_flag = blk_tracer_set_flag, |
1382 | }; | 1398 | }; |
1383 | 1399 | ||
1384 | static struct trace_event trace_blk_event = { | 1400 | static struct trace_event_functions trace_blk_event_funcs = { |
1385 | .type = TRACE_BLK, | ||
1386 | .trace = blk_trace_event_print, | 1401 | .trace = blk_trace_event_print, |
1387 | .binary = blk_trace_event_print_binary, | 1402 | .binary = blk_trace_event_print_binary, |
1388 | }; | 1403 | }; |
1389 | 1404 | ||
1405 | static struct trace_event trace_blk_event = { | ||
1406 | .type = TRACE_BLK, | ||
1407 | .funcs = &trace_blk_event_funcs, | ||
1408 | }; | ||
1409 | |||
1390 | static int __init init_blk_tracer(void) | 1410 | static int __init init_blk_tracer(void) |
1391 | { | 1411 | { |
1392 | if (!register_ftrace_event(&trace_blk_event)) { | 1412 | if (!register_ftrace_event(&trace_blk_event)) { |
diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index 32837e19e3bd..6d2cb14f9449 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c | |||
@@ -3234,7 +3234,8 @@ free: | |||
3234 | } | 3234 | } |
3235 | 3235 | ||
3236 | static void | 3236 | static void |
3237 | ftrace_graph_probe_sched_switch(struct task_struct *prev, struct task_struct *next) | 3237 | ftrace_graph_probe_sched_switch(void *ignore, |
3238 | struct task_struct *prev, struct task_struct *next) | ||
3238 | { | 3239 | { |
3239 | unsigned long long timestamp; | 3240 | unsigned long long timestamp; |
3240 | int index; | 3241 | int index; |
@@ -3288,7 +3289,7 @@ static int start_graph_tracing(void) | |||
3288 | } while (ret == -EAGAIN); | 3289 | } while (ret == -EAGAIN); |
3289 | 3290 | ||
3290 | if (!ret) { | 3291 | if (!ret) { |
3291 | ret = register_trace_sched_switch(ftrace_graph_probe_sched_switch); | 3292 | ret = register_trace_sched_switch(ftrace_graph_probe_sched_switch, NULL); |
3292 | if (ret) | 3293 | if (ret) |
3293 | pr_info("ftrace_graph: Couldn't activate tracepoint" | 3294 | pr_info("ftrace_graph: Couldn't activate tracepoint" |
3294 | " probe to kernel_sched_switch\n"); | 3295 | " probe to kernel_sched_switch\n"); |
@@ -3364,7 +3365,7 @@ void unregister_ftrace_graph(void) | |||
3364 | ftrace_graph_entry = ftrace_graph_entry_stub; | 3365 | ftrace_graph_entry = ftrace_graph_entry_stub; |
3365 | ftrace_shutdown(FTRACE_STOP_FUNC_RET); | 3366 | ftrace_shutdown(FTRACE_STOP_FUNC_RET); |
3366 | unregister_pm_notifier(&ftrace_suspend_notifier); | 3367 | unregister_pm_notifier(&ftrace_suspend_notifier); |
3367 | unregister_trace_sched_switch(ftrace_graph_probe_sched_switch); | 3368 | unregister_trace_sched_switch(ftrace_graph_probe_sched_switch, NULL); |
3368 | 3369 | ||
3369 | out: | 3370 | out: |
3370 | mutex_unlock(&ftrace_lock); | 3371 | mutex_unlock(&ftrace_lock); |
diff --git a/kernel/trace/kmemtrace.c b/kernel/trace/kmemtrace.c index a91da69f153a..bbfc1bb1660b 100644 --- a/kernel/trace/kmemtrace.c +++ b/kernel/trace/kmemtrace.c | |||
@@ -95,7 +95,8 @@ static inline void kmemtrace_free(enum kmemtrace_type_id type_id, | |||
95 | trace_wake_up(); | 95 | trace_wake_up(); |
96 | } | 96 | } |
97 | 97 | ||
98 | static void kmemtrace_kmalloc(unsigned long call_site, | 98 | static void kmemtrace_kmalloc(void *ignore, |
99 | unsigned long call_site, | ||
99 | const void *ptr, | 100 | const void *ptr, |
100 | size_t bytes_req, | 101 | size_t bytes_req, |
101 | size_t bytes_alloc, | 102 | size_t bytes_alloc, |
@@ -105,7 +106,8 @@ static void kmemtrace_kmalloc(unsigned long call_site, | |||
105 | bytes_req, bytes_alloc, gfp_flags, -1); | 106 | bytes_req, bytes_alloc, gfp_flags, -1); |
106 | } | 107 | } |
107 | 108 | ||
108 | static void kmemtrace_kmem_cache_alloc(unsigned long call_site, | 109 | static void kmemtrace_kmem_cache_alloc(void *ignore, |
110 | unsigned long call_site, | ||
109 | const void *ptr, | 111 | const void *ptr, |
110 | size_t bytes_req, | 112 | size_t bytes_req, |
111 | size_t bytes_alloc, | 113 | size_t bytes_alloc, |
@@ -115,7 +117,8 @@ static void kmemtrace_kmem_cache_alloc(unsigned long call_site, | |||
115 | bytes_req, bytes_alloc, gfp_flags, -1); | 117 | bytes_req, bytes_alloc, gfp_flags, -1); |
116 | } | 118 | } |
117 | 119 | ||
118 | static void kmemtrace_kmalloc_node(unsigned long call_site, | 120 | static void kmemtrace_kmalloc_node(void *ignore, |
121 | unsigned long call_site, | ||
119 | const void *ptr, | 122 | const void *ptr, |
120 | size_t bytes_req, | 123 | size_t bytes_req, |
121 | size_t bytes_alloc, | 124 | size_t bytes_alloc, |
@@ -126,7 +129,8 @@ static void kmemtrace_kmalloc_node(unsigned long call_site, | |||
126 | bytes_req, bytes_alloc, gfp_flags, node); | 129 | bytes_req, bytes_alloc, gfp_flags, node); |
127 | } | 130 | } |
128 | 131 | ||
129 | static void kmemtrace_kmem_cache_alloc_node(unsigned long call_site, | 132 | static void kmemtrace_kmem_cache_alloc_node(void *ignore, |
133 | unsigned long call_site, | ||
130 | const void *ptr, | 134 | const void *ptr, |
131 | size_t bytes_req, | 135 | size_t bytes_req, |
132 | size_t bytes_alloc, | 136 | size_t bytes_alloc, |
@@ -137,12 +141,14 @@ static void kmemtrace_kmem_cache_alloc_node(unsigned long call_site, | |||
137 | bytes_req, bytes_alloc, gfp_flags, node); | 141 | bytes_req, bytes_alloc, gfp_flags, node); |
138 | } | 142 | } |
139 | 143 | ||
140 | static void kmemtrace_kfree(unsigned long call_site, const void *ptr) | 144 | static void |
145 | kmemtrace_kfree(void *ignore, unsigned long call_site, const void *ptr) | ||
141 | { | 146 | { |
142 | kmemtrace_free(KMEMTRACE_TYPE_KMALLOC, call_site, ptr); | 147 | kmemtrace_free(KMEMTRACE_TYPE_KMALLOC, call_site, ptr); |
143 | } | 148 | } |
144 | 149 | ||
145 | static void kmemtrace_kmem_cache_free(unsigned long call_site, const void *ptr) | 150 | static void kmemtrace_kmem_cache_free(void *ignore, |
151 | unsigned long call_site, const void *ptr) | ||
146 | { | 152 | { |
147 | kmemtrace_free(KMEMTRACE_TYPE_CACHE, call_site, ptr); | 153 | kmemtrace_free(KMEMTRACE_TYPE_CACHE, call_site, ptr); |
148 | } | 154 | } |
@@ -151,34 +157,34 @@ static int kmemtrace_start_probes(void) | |||
151 | { | 157 | { |
152 | int err; | 158 | int err; |
153 | 159 | ||
154 | err = register_trace_kmalloc(kmemtrace_kmalloc); | 160 | err = register_trace_kmalloc(kmemtrace_kmalloc, NULL); |
155 | if (err) | 161 | if (err) |
156 | return err; | 162 | return err; |
157 | err = register_trace_kmem_cache_alloc(kmemtrace_kmem_cache_alloc); | 163 | err = register_trace_kmem_cache_alloc(kmemtrace_kmem_cache_alloc, NULL); |
158 | if (err) | 164 | if (err) |
159 | return err; | 165 | return err; |
160 | err = register_trace_kmalloc_node(kmemtrace_kmalloc_node); | 166 | err = register_trace_kmalloc_node(kmemtrace_kmalloc_node, NULL); |
161 | if (err) | 167 | if (err) |
162 | return err; | 168 | return err; |
163 | err = register_trace_kmem_cache_alloc_node(kmemtrace_kmem_cache_alloc_node); | 169 | err = register_trace_kmem_cache_alloc_node(kmemtrace_kmem_cache_alloc_node, NULL); |
164 | if (err) | 170 | if (err) |
165 | return err; | 171 | return err; |
166 | err = register_trace_kfree(kmemtrace_kfree); | 172 | err = register_trace_kfree(kmemtrace_kfree, NULL); |
167 | if (err) | 173 | if (err) |
168 | return err; | 174 | return err; |
169 | err = register_trace_kmem_cache_free(kmemtrace_kmem_cache_free); | 175 | err = register_trace_kmem_cache_free(kmemtrace_kmem_cache_free, NULL); |
170 | 176 | ||
171 | return err; | 177 | return err; |
172 | } | 178 | } |
173 | 179 | ||
174 | static void kmemtrace_stop_probes(void) | 180 | static void kmemtrace_stop_probes(void) |
175 | { | 181 | { |
176 | unregister_trace_kmalloc(kmemtrace_kmalloc); | 182 | unregister_trace_kmalloc(kmemtrace_kmalloc, NULL); |
177 | unregister_trace_kmem_cache_alloc(kmemtrace_kmem_cache_alloc); | 183 | unregister_trace_kmem_cache_alloc(kmemtrace_kmem_cache_alloc, NULL); |
178 | unregister_trace_kmalloc_node(kmemtrace_kmalloc_node); | 184 | unregister_trace_kmalloc_node(kmemtrace_kmalloc_node, NULL); |
179 | unregister_trace_kmem_cache_alloc_node(kmemtrace_kmem_cache_alloc_node); | 185 | unregister_trace_kmem_cache_alloc_node(kmemtrace_kmem_cache_alloc_node, NULL); |
180 | unregister_trace_kfree(kmemtrace_kfree); | 186 | unregister_trace_kfree(kmemtrace_kfree, NULL); |
181 | unregister_trace_kmem_cache_free(kmemtrace_kmem_cache_free); | 187 | unregister_trace_kmem_cache_free(kmemtrace_kmem_cache_free, NULL); |
182 | } | 188 | } |
183 | 189 | ||
184 | static int kmem_trace_init(struct trace_array *tr) | 190 | static int kmem_trace_init(struct trace_array *tr) |
@@ -237,7 +243,8 @@ struct kmemtrace_user_event_alloc { | |||
237 | }; | 243 | }; |
238 | 244 | ||
239 | static enum print_line_t | 245 | static enum print_line_t |
240 | kmemtrace_print_alloc(struct trace_iterator *iter, int flags) | 246 | kmemtrace_print_alloc(struct trace_iterator *iter, int flags, |
247 | struct trace_event *event) | ||
241 | { | 248 | { |
242 | struct trace_seq *s = &iter->seq; | 249 | struct trace_seq *s = &iter->seq; |
243 | struct kmemtrace_alloc_entry *entry; | 250 | struct kmemtrace_alloc_entry *entry; |
@@ -257,7 +264,8 @@ kmemtrace_print_alloc(struct trace_iterator *iter, int flags) | |||
257 | } | 264 | } |
258 | 265 | ||
259 | static enum print_line_t | 266 | static enum print_line_t |
260 | kmemtrace_print_free(struct trace_iterator *iter, int flags) | 267 | kmemtrace_print_free(struct trace_iterator *iter, int flags, |
268 | struct trace_event *event) | ||
261 | { | 269 | { |
262 | struct trace_seq *s = &iter->seq; | 270 | struct trace_seq *s = &iter->seq; |
263 | struct kmemtrace_free_entry *entry; | 271 | struct kmemtrace_free_entry *entry; |
@@ -275,7 +283,8 @@ kmemtrace_print_free(struct trace_iterator *iter, int flags) | |||
275 | } | 283 | } |
276 | 284 | ||
277 | static enum print_line_t | 285 | static enum print_line_t |
278 | kmemtrace_print_alloc_user(struct trace_iterator *iter, int flags) | 286 | kmemtrace_print_alloc_user(struct trace_iterator *iter, int flags, |
287 | struct trace_event *event) | ||
279 | { | 288 | { |
280 | struct trace_seq *s = &iter->seq; | 289 | struct trace_seq *s = &iter->seq; |
281 | struct kmemtrace_alloc_entry *entry; | 290 | struct kmemtrace_alloc_entry *entry; |
@@ -309,7 +318,8 @@ kmemtrace_print_alloc_user(struct trace_iterator *iter, int flags) | |||
309 | } | 318 | } |
310 | 319 | ||
311 | static enum print_line_t | 320 | static enum print_line_t |
312 | kmemtrace_print_free_user(struct trace_iterator *iter, int flags) | 321 | kmemtrace_print_free_user(struct trace_iterator *iter, int flags, |
322 | struct trace_event *event) | ||
313 | { | 323 | { |
314 | struct trace_seq *s = &iter->seq; | 324 | struct trace_seq *s = &iter->seq; |
315 | struct kmemtrace_free_entry *entry; | 325 | struct kmemtrace_free_entry *entry; |
@@ -463,18 +473,26 @@ static enum print_line_t kmemtrace_print_line(struct trace_iterator *iter) | |||
463 | } | 473 | } |
464 | } | 474 | } |
465 | 475 | ||
466 | static struct trace_event kmem_trace_alloc = { | 476 | static struct trace_event_functions kmem_trace_alloc_funcs = { |
467 | .type = TRACE_KMEM_ALLOC, | ||
468 | .trace = kmemtrace_print_alloc, | 477 | .trace = kmemtrace_print_alloc, |
469 | .binary = kmemtrace_print_alloc_user, | 478 | .binary = kmemtrace_print_alloc_user, |
470 | }; | 479 | }; |
471 | 480 | ||
472 | static struct trace_event kmem_trace_free = { | 481 | static struct trace_event kmem_trace_alloc = { |
473 | .type = TRACE_KMEM_FREE, | 482 | .type = TRACE_KMEM_ALLOC, |
483 | .funcs = &kmem_trace_alloc_funcs, | ||
484 | }; | ||
485 | |||
486 | static struct trace_event_functions kmem_trace_free_funcs = { | ||
474 | .trace = kmemtrace_print_free, | 487 | .trace = kmemtrace_print_free, |
475 | .binary = kmemtrace_print_free_user, | 488 | .binary = kmemtrace_print_free_user, |
476 | }; | 489 | }; |
477 | 490 | ||
491 | static struct trace_event kmem_trace_free = { | ||
492 | .type = TRACE_KMEM_FREE, | ||
493 | .funcs = &kmem_trace_free_funcs, | ||
494 | }; | ||
495 | |||
478 | static struct tracer kmem_tracer __read_mostly = { | 496 | static struct tracer kmem_tracer __read_mostly = { |
479 | .name = "kmemtrace", | 497 | .name = "kmemtrace", |
480 | .init = kmem_trace_init, | 498 | .init = kmem_trace_init, |
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index 8a76339a9e65..55e48511d7c8 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c | |||
@@ -1936,7 +1936,7 @@ static enum print_line_t print_trace_fmt(struct trace_iterator *iter) | |||
1936 | } | 1936 | } |
1937 | 1937 | ||
1938 | if (event) | 1938 | if (event) |
1939 | return event->trace(iter, sym_flags); | 1939 | return event->funcs->trace(iter, sym_flags, event); |
1940 | 1940 | ||
1941 | if (!trace_seq_printf(s, "Unknown type %d\n", entry->type)) | 1941 | if (!trace_seq_printf(s, "Unknown type %d\n", entry->type)) |
1942 | goto partial; | 1942 | goto partial; |
@@ -1962,7 +1962,7 @@ static enum print_line_t print_raw_fmt(struct trace_iterator *iter) | |||
1962 | 1962 | ||
1963 | event = ftrace_find_event(entry->type); | 1963 | event = ftrace_find_event(entry->type); |
1964 | if (event) | 1964 | if (event) |
1965 | return event->raw(iter, 0); | 1965 | return event->funcs->raw(iter, 0, event); |
1966 | 1966 | ||
1967 | if (!trace_seq_printf(s, "%d ?\n", entry->type)) | 1967 | if (!trace_seq_printf(s, "%d ?\n", entry->type)) |
1968 | goto partial; | 1968 | goto partial; |
@@ -1989,7 +1989,7 @@ static enum print_line_t print_hex_fmt(struct trace_iterator *iter) | |||
1989 | 1989 | ||
1990 | event = ftrace_find_event(entry->type); | 1990 | event = ftrace_find_event(entry->type); |
1991 | if (event) { | 1991 | if (event) { |
1992 | enum print_line_t ret = event->hex(iter, 0); | 1992 | enum print_line_t ret = event->funcs->hex(iter, 0, event); |
1993 | if (ret != TRACE_TYPE_HANDLED) | 1993 | if (ret != TRACE_TYPE_HANDLED) |
1994 | return ret; | 1994 | return ret; |
1995 | } | 1995 | } |
@@ -2014,7 +2014,8 @@ static enum print_line_t print_bin_fmt(struct trace_iterator *iter) | |||
2014 | } | 2014 | } |
2015 | 2015 | ||
2016 | event = ftrace_find_event(entry->type); | 2016 | event = ftrace_find_event(entry->type); |
2017 | return event ? event->binary(iter, 0) : TRACE_TYPE_HANDLED; | 2017 | return event ? event->funcs->binary(iter, 0, event) : |
2018 | TRACE_TYPE_HANDLED; | ||
2018 | } | 2019 | } |
2019 | 2020 | ||
2020 | int trace_empty(struct trace_iterator *iter) | 2021 | int trace_empty(struct trace_iterator *iter) |
diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h index d1ce0bec1b3f..2cd96399463f 100644 --- a/kernel/trace/trace.h +++ b/kernel/trace/trace.h | |||
@@ -405,12 +405,12 @@ void ftrace_trace_userstack(struct ring_buffer *buffer, unsigned long flags, | |||
405 | void __trace_stack(struct trace_array *tr, unsigned long flags, int skip, | 405 | void __trace_stack(struct trace_array *tr, unsigned long flags, int skip, |
406 | int pc); | 406 | int pc); |
407 | #else | 407 | #else |
408 | static inline void ftrace_trace_stack(struct trace_array *tr, | 408 | static inline void ftrace_trace_stack(struct ring_buffer *buffer, |
409 | unsigned long flags, int skip, int pc) | 409 | unsigned long flags, int skip, int pc) |
410 | { | 410 | { |
411 | } | 411 | } |
412 | 412 | ||
413 | static inline void ftrace_trace_userstack(struct trace_array *tr, | 413 | static inline void ftrace_trace_userstack(struct ring_buffer *buffer, |
414 | unsigned long flags, int pc) | 414 | unsigned long flags, int pc) |
415 | { | 415 | { |
416 | } | 416 | } |
@@ -778,12 +778,15 @@ extern void print_subsystem_event_filter(struct event_subsystem *system, | |||
778 | struct trace_seq *s); | 778 | struct trace_seq *s); |
779 | extern int filter_assign_type(const char *type); | 779 | extern int filter_assign_type(const char *type); |
780 | 780 | ||
781 | struct list_head * | ||
782 | trace_get_fields(struct ftrace_event_call *event_call); | ||
783 | |||
781 | static inline int | 784 | static inline int |
782 | filter_check_discard(struct ftrace_event_call *call, void *rec, | 785 | filter_check_discard(struct ftrace_event_call *call, void *rec, |
783 | struct ring_buffer *buffer, | 786 | struct ring_buffer *buffer, |
784 | struct ring_buffer_event *event) | 787 | struct ring_buffer_event *event) |
785 | { | 788 | { |
786 | if (unlikely(call->filter_active) && | 789 | if (unlikely(call->flags & TRACE_EVENT_FL_FILTERED) && |
787 | !filter_match_preds(call->filter, rec)) { | 790 | !filter_match_preds(call->filter, rec)) { |
788 | ring_buffer_discard_commit(buffer, event); | 791 | ring_buffer_discard_commit(buffer, event); |
789 | return 1; | 792 | return 1; |
diff --git a/kernel/trace/trace_branch.c b/kernel/trace/trace_branch.c index b9bc4d470177..8d3538b4ea5f 100644 --- a/kernel/trace/trace_branch.c +++ b/kernel/trace/trace_branch.c | |||
@@ -143,7 +143,7 @@ static void branch_trace_reset(struct trace_array *tr) | |||
143 | } | 143 | } |
144 | 144 | ||
145 | static enum print_line_t trace_branch_print(struct trace_iterator *iter, | 145 | static enum print_line_t trace_branch_print(struct trace_iterator *iter, |
146 | int flags) | 146 | int flags, struct trace_event *event) |
147 | { | 147 | { |
148 | struct trace_branch *field; | 148 | struct trace_branch *field; |
149 | 149 | ||
@@ -167,9 +167,13 @@ static void branch_print_header(struct seq_file *s) | |||
167 | " |\n"); | 167 | " |\n"); |
168 | } | 168 | } |
169 | 169 | ||
170 | static struct trace_event_functions trace_branch_funcs = { | ||
171 | .trace = trace_branch_print, | ||
172 | }; | ||
173 | |||
170 | static struct trace_event trace_branch_event = { | 174 | static struct trace_event trace_branch_event = { |
171 | .type = TRACE_BRANCH, | 175 | .type = TRACE_BRANCH, |
172 | .trace = trace_branch_print, | 176 | .funcs = &trace_branch_funcs, |
173 | }; | 177 | }; |
174 | 178 | ||
175 | static struct tracer branch_trace __read_mostly = | 179 | static struct tracer branch_trace __read_mostly = |
diff --git a/kernel/trace/trace_event_perf.c b/kernel/trace/trace_event_perf.c index 0565bb42566f..cb6f365016e4 100644 --- a/kernel/trace/trace_event_perf.c +++ b/kernel/trace/trace_event_perf.c | |||
@@ -9,13 +9,9 @@ | |||
9 | #include <linux/kprobes.h> | 9 | #include <linux/kprobes.h> |
10 | #include "trace.h" | 10 | #include "trace.h" |
11 | 11 | ||
12 | DEFINE_PER_CPU(struct pt_regs, perf_trace_regs); | ||
13 | EXPORT_PER_CPU_SYMBOL_GPL(perf_trace_regs); | ||
14 | |||
15 | EXPORT_SYMBOL_GPL(perf_arch_fetch_caller_regs); | 12 | EXPORT_SYMBOL_GPL(perf_arch_fetch_caller_regs); |
16 | 13 | ||
17 | static char *perf_trace_buf; | 14 | static char *perf_trace_buf[4]; |
18 | static char *perf_trace_buf_nmi; | ||
19 | 15 | ||
20 | /* | 16 | /* |
21 | * Force it to be aligned to unsigned long to avoid misaligned accesses | 17 | * Force it to be aligned to unsigned long to avoid misaligned accesses |
@@ -27,57 +23,82 @@ typedef typeof(unsigned long [PERF_MAX_TRACE_SIZE / sizeof(unsigned long)]) | |||
27 | /* Count the events in use (per event id, not per instance) */ | 23 | /* Count the events in use (per event id, not per instance) */ |
28 | static int total_ref_count; | 24 | static int total_ref_count; |
29 | 25 | ||
30 | static int perf_trace_event_enable(struct ftrace_event_call *event) | 26 | static int perf_trace_event_init(struct ftrace_event_call *tp_event, |
27 | struct perf_event *p_event) | ||
31 | { | 28 | { |
32 | char *buf; | 29 | struct hlist_head *list; |
33 | int ret = -ENOMEM; | 30 | int ret = -ENOMEM; |
31 | int cpu; | ||
34 | 32 | ||
35 | if (event->perf_refcount++ > 0) | 33 | p_event->tp_event = tp_event; |
34 | if (tp_event->perf_refcount++ > 0) | ||
36 | return 0; | 35 | return 0; |
37 | 36 | ||
38 | if (!total_ref_count) { | 37 | list = alloc_percpu(struct hlist_head); |
39 | buf = (char *)alloc_percpu(perf_trace_t); | 38 | if (!list) |
40 | if (!buf) | 39 | goto fail; |
41 | goto fail_buf; | ||
42 | 40 | ||
43 | rcu_assign_pointer(perf_trace_buf, buf); | 41 | for_each_possible_cpu(cpu) |
42 | INIT_HLIST_HEAD(per_cpu_ptr(list, cpu)); | ||
44 | 43 | ||
45 | buf = (char *)alloc_percpu(perf_trace_t); | 44 | tp_event->perf_events = list; |
46 | if (!buf) | ||
47 | goto fail_buf_nmi; | ||
48 | 45 | ||
49 | rcu_assign_pointer(perf_trace_buf_nmi, buf); | 46 | if (!total_ref_count) { |
50 | } | 47 | char *buf; |
48 | int i; | ||
51 | 49 | ||
52 | ret = event->perf_event_enable(event); | 50 | for (i = 0; i < 4; i++) { |
53 | if (!ret) { | 51 | buf = (char *)alloc_percpu(perf_trace_t); |
54 | total_ref_count++; | 52 | if (!buf) |
55 | return 0; | 53 | goto fail; |
54 | |||
55 | perf_trace_buf[i] = buf; | ||
56 | } | ||
56 | } | 57 | } |
57 | 58 | ||
58 | fail_buf_nmi: | 59 | if (tp_event->class->reg) |
60 | ret = tp_event->class->reg(tp_event, TRACE_REG_PERF_REGISTER); | ||
61 | else | ||
62 | ret = tracepoint_probe_register(tp_event->name, | ||
63 | tp_event->class->perf_probe, | ||
64 | tp_event); | ||
65 | |||
66 | if (ret) | ||
67 | goto fail; | ||
68 | |||
69 | total_ref_count++; | ||
70 | return 0; | ||
71 | |||
72 | fail: | ||
59 | if (!total_ref_count) { | 73 | if (!total_ref_count) { |
60 | free_percpu(perf_trace_buf_nmi); | 74 | int i; |
61 | free_percpu(perf_trace_buf); | 75 | |
62 | perf_trace_buf_nmi = NULL; | 76 | for (i = 0; i < 4; i++) { |
63 | perf_trace_buf = NULL; | 77 | free_percpu(perf_trace_buf[i]); |
78 | perf_trace_buf[i] = NULL; | ||
79 | } | ||
80 | } | ||
81 | |||
82 | if (!--tp_event->perf_refcount) { | ||
83 | free_percpu(tp_event->perf_events); | ||
84 | tp_event->perf_events = NULL; | ||
64 | } | 85 | } |
65 | fail_buf: | ||
66 | event->perf_refcount--; | ||
67 | 86 | ||
68 | return ret; | 87 | return ret; |
69 | } | 88 | } |
70 | 89 | ||
71 | int perf_trace_enable(int event_id) | 90 | int perf_trace_init(struct perf_event *p_event) |
72 | { | 91 | { |
73 | struct ftrace_event_call *event; | 92 | struct ftrace_event_call *tp_event; |
93 | int event_id = p_event->attr.config; | ||
74 | int ret = -EINVAL; | 94 | int ret = -EINVAL; |
75 | 95 | ||
76 | mutex_lock(&event_mutex); | 96 | mutex_lock(&event_mutex); |
77 | list_for_each_entry(event, &ftrace_events, list) { | 97 | list_for_each_entry(tp_event, &ftrace_events, list) { |
78 | if (event->id == event_id && event->perf_event_enable && | 98 | if (tp_event->event.type == event_id && |
79 | try_module_get(event->mod)) { | 99 | tp_event->class && tp_event->class->perf_probe && |
80 | ret = perf_trace_event_enable(event); | 100 | try_module_get(tp_event->mod)) { |
101 | ret = perf_trace_event_init(tp_event, p_event); | ||
81 | break; | 102 | break; |
82 | } | 103 | } |
83 | } | 104 | } |
@@ -86,90 +107,78 @@ int perf_trace_enable(int event_id) | |||
86 | return ret; | 107 | return ret; |
87 | } | 108 | } |
88 | 109 | ||
89 | static void perf_trace_event_disable(struct ftrace_event_call *event) | 110 | int perf_trace_enable(struct perf_event *p_event) |
90 | { | 111 | { |
91 | char *buf, *nmi_buf; | 112 | struct ftrace_event_call *tp_event = p_event->tp_event; |
92 | 113 | struct hlist_head *list; | |
93 | if (--event->perf_refcount > 0) | ||
94 | return; | ||
95 | |||
96 | event->perf_event_disable(event); | ||
97 | 114 | ||
98 | if (!--total_ref_count) { | 115 | list = tp_event->perf_events; |
99 | buf = perf_trace_buf; | 116 | if (WARN_ON_ONCE(!list)) |
100 | rcu_assign_pointer(perf_trace_buf, NULL); | 117 | return -EINVAL; |
101 | 118 | ||
102 | nmi_buf = perf_trace_buf_nmi; | 119 | list = per_cpu_ptr(list, smp_processor_id()); |
103 | rcu_assign_pointer(perf_trace_buf_nmi, NULL); | 120 | hlist_add_head_rcu(&p_event->hlist_entry, list); |
104 | 121 | ||
105 | /* | 122 | return 0; |
106 | * Ensure every events in profiling have finished before | 123 | } |
107 | * releasing the buffers | ||
108 | */ | ||
109 | synchronize_sched(); | ||
110 | 124 | ||
111 | free_percpu(buf); | 125 | void perf_trace_disable(struct perf_event *p_event) |
112 | free_percpu(nmi_buf); | 126 | { |
113 | } | 127 | hlist_del_rcu(&p_event->hlist_entry); |
114 | } | 128 | } |
115 | 129 | ||
116 | void perf_trace_disable(int event_id) | 130 | void perf_trace_destroy(struct perf_event *p_event) |
117 | { | 131 | { |
118 | struct ftrace_event_call *event; | 132 | struct ftrace_event_call *tp_event = p_event->tp_event; |
133 | int i; | ||
119 | 134 | ||
120 | mutex_lock(&event_mutex); | 135 | if (--tp_event->perf_refcount > 0) |
121 | list_for_each_entry(event, &ftrace_events, list) { | 136 | return; |
122 | if (event->id == event_id) { | 137 | |
123 | perf_trace_event_disable(event); | 138 | if (tp_event->class->reg) |
124 | module_put(event->mod); | 139 | tp_event->class->reg(tp_event, TRACE_REG_PERF_UNREGISTER); |
125 | break; | 140 | else |
141 | tracepoint_probe_unregister(tp_event->name, | ||
142 | tp_event->class->perf_probe, | ||
143 | tp_event); | ||
144 | |||
145 | free_percpu(tp_event->perf_events); | ||
146 | tp_event->perf_events = NULL; | ||
147 | |||
148 | if (!--total_ref_count) { | ||
149 | for (i = 0; i < 4; i++) { | ||
150 | free_percpu(perf_trace_buf[i]); | ||
151 | perf_trace_buf[i] = NULL; | ||
126 | } | 152 | } |
127 | } | 153 | } |
128 | mutex_unlock(&event_mutex); | ||
129 | } | 154 | } |
130 | 155 | ||
131 | __kprobes void *perf_trace_buf_prepare(int size, unsigned short type, | 156 | __kprobes void *perf_trace_buf_prepare(int size, unsigned short type, |
132 | int *rctxp, unsigned long *irq_flags) | 157 | struct pt_regs *regs, int *rctxp) |
133 | { | 158 | { |
134 | struct trace_entry *entry; | 159 | struct trace_entry *entry; |
135 | char *trace_buf, *raw_data; | 160 | unsigned long flags; |
136 | int pc, cpu; | 161 | char *raw_data; |
162 | int pc; | ||
137 | 163 | ||
138 | BUILD_BUG_ON(PERF_MAX_TRACE_SIZE % sizeof(unsigned long)); | 164 | BUILD_BUG_ON(PERF_MAX_TRACE_SIZE % sizeof(unsigned long)); |
139 | 165 | ||
140 | pc = preempt_count(); | 166 | pc = preempt_count(); |
141 | 167 | ||
142 | /* Protect the per cpu buffer, begin the rcu read side */ | ||
143 | local_irq_save(*irq_flags); | ||
144 | |||
145 | *rctxp = perf_swevent_get_recursion_context(); | 168 | *rctxp = perf_swevent_get_recursion_context(); |
146 | if (*rctxp < 0) | 169 | if (*rctxp < 0) |
147 | goto err_recursion; | 170 | return NULL; |
148 | |||
149 | cpu = smp_processor_id(); | ||
150 | |||
151 | if (in_nmi()) | ||
152 | trace_buf = rcu_dereference_sched(perf_trace_buf_nmi); | ||
153 | else | ||
154 | trace_buf = rcu_dereference_sched(perf_trace_buf); | ||
155 | |||
156 | if (!trace_buf) | ||
157 | goto err; | ||
158 | 171 | ||
159 | raw_data = per_cpu_ptr(trace_buf, cpu); | 172 | raw_data = per_cpu_ptr(perf_trace_buf[*rctxp], smp_processor_id()); |
160 | 173 | ||
161 | /* zero the dead bytes from align to not leak stack to user */ | 174 | /* zero the dead bytes from align to not leak stack to user */ |
162 | memset(&raw_data[size - sizeof(u64)], 0, sizeof(u64)); | 175 | memset(&raw_data[size - sizeof(u64)], 0, sizeof(u64)); |
163 | 176 | ||
164 | entry = (struct trace_entry *)raw_data; | 177 | entry = (struct trace_entry *)raw_data; |
165 | tracing_generic_entry_update(entry, *irq_flags, pc); | 178 | local_save_flags(flags); |
179 | tracing_generic_entry_update(entry, flags, pc); | ||
166 | entry->type = type; | 180 | entry->type = type; |
167 | 181 | ||
168 | return raw_data; | 182 | return raw_data; |
169 | err: | ||
170 | perf_swevent_put_recursion_context(*rctxp); | ||
171 | err_recursion: | ||
172 | local_irq_restore(*irq_flags); | ||
173 | return NULL; | ||
174 | } | 183 | } |
175 | EXPORT_SYMBOL_GPL(perf_trace_buf_prepare); | 184 | EXPORT_SYMBOL_GPL(perf_trace_buf_prepare); |
diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c index c697c7043349..53cffc0b0801 100644 --- a/kernel/trace/trace_events.c +++ b/kernel/trace/trace_events.c | |||
@@ -29,11 +29,23 @@ DEFINE_MUTEX(event_mutex); | |||
29 | 29 | ||
30 | LIST_HEAD(ftrace_events); | 30 | LIST_HEAD(ftrace_events); |
31 | 31 | ||
32 | struct list_head * | ||
33 | trace_get_fields(struct ftrace_event_call *event_call) | ||
34 | { | ||
35 | if (!event_call->class->get_fields) | ||
36 | return &event_call->class->fields; | ||
37 | return event_call->class->get_fields(event_call); | ||
38 | } | ||
39 | |||
32 | int trace_define_field(struct ftrace_event_call *call, const char *type, | 40 | int trace_define_field(struct ftrace_event_call *call, const char *type, |
33 | const char *name, int offset, int size, int is_signed, | 41 | const char *name, int offset, int size, int is_signed, |
34 | int filter_type) | 42 | int filter_type) |
35 | { | 43 | { |
36 | struct ftrace_event_field *field; | 44 | struct ftrace_event_field *field; |
45 | struct list_head *head; | ||
46 | |||
47 | if (WARN_ON(!call->class)) | ||
48 | return 0; | ||
37 | 49 | ||
38 | field = kzalloc(sizeof(*field), GFP_KERNEL); | 50 | field = kzalloc(sizeof(*field), GFP_KERNEL); |
39 | if (!field) | 51 | if (!field) |
@@ -56,7 +68,8 @@ int trace_define_field(struct ftrace_event_call *call, const char *type, | |||
56 | field->size = size; | 68 | field->size = size; |
57 | field->is_signed = is_signed; | 69 | field->is_signed = is_signed; |
58 | 70 | ||
59 | list_add(&field->link, &call->fields); | 71 | head = trace_get_fields(call); |
72 | list_add(&field->link, head); | ||
60 | 73 | ||
61 | return 0; | 74 | return 0; |
62 | 75 | ||
@@ -94,8 +107,10 @@ static int trace_define_common_fields(struct ftrace_event_call *call) | |||
94 | void trace_destroy_fields(struct ftrace_event_call *call) | 107 | void trace_destroy_fields(struct ftrace_event_call *call) |
95 | { | 108 | { |
96 | struct ftrace_event_field *field, *next; | 109 | struct ftrace_event_field *field, *next; |
110 | struct list_head *head; | ||
97 | 111 | ||
98 | list_for_each_entry_safe(field, next, &call->fields, link) { | 112 | head = trace_get_fields(call); |
113 | list_for_each_entry_safe(field, next, head, link) { | ||
99 | list_del(&field->link); | 114 | list_del(&field->link); |
100 | kfree(field->type); | 115 | kfree(field->type); |
101 | kfree(field->name); | 116 | kfree(field->name); |
@@ -107,11 +122,9 @@ int trace_event_raw_init(struct ftrace_event_call *call) | |||
107 | { | 122 | { |
108 | int id; | 123 | int id; |
109 | 124 | ||
110 | id = register_ftrace_event(call->event); | 125 | id = register_ftrace_event(&call->event); |
111 | if (!id) | 126 | if (!id) |
112 | return -ENODEV; | 127 | return -ENODEV; |
113 | call->id = id; | ||
114 | INIT_LIST_HEAD(&call->fields); | ||
115 | 128 | ||
116 | return 0; | 129 | return 0; |
117 | } | 130 | } |
@@ -124,23 +137,33 @@ static int ftrace_event_enable_disable(struct ftrace_event_call *call, | |||
124 | 137 | ||
125 | switch (enable) { | 138 | switch (enable) { |
126 | case 0: | 139 | case 0: |
127 | if (call->enabled) { | 140 | if (call->flags & TRACE_EVENT_FL_ENABLED) { |
128 | call->enabled = 0; | 141 | call->flags &= ~TRACE_EVENT_FL_ENABLED; |
129 | tracing_stop_cmdline_record(); | 142 | tracing_stop_cmdline_record(); |
130 | call->unregfunc(call); | 143 | if (call->class->reg) |
144 | call->class->reg(call, TRACE_REG_UNREGISTER); | ||
145 | else | ||
146 | tracepoint_probe_unregister(call->name, | ||
147 | call->class->probe, | ||
148 | call); | ||
131 | } | 149 | } |
132 | break; | 150 | break; |
133 | case 1: | 151 | case 1: |
134 | if (!call->enabled) { | 152 | if (!(call->flags & TRACE_EVENT_FL_ENABLED)) { |
135 | tracing_start_cmdline_record(); | 153 | tracing_start_cmdline_record(); |
136 | ret = call->regfunc(call); | 154 | if (call->class->reg) |
155 | ret = call->class->reg(call, TRACE_REG_REGISTER); | ||
156 | else | ||
157 | ret = tracepoint_probe_register(call->name, | ||
158 | call->class->probe, | ||
159 | call); | ||
137 | if (ret) { | 160 | if (ret) { |
138 | tracing_stop_cmdline_record(); | 161 | tracing_stop_cmdline_record(); |
139 | pr_info("event trace: Could not enable event " | 162 | pr_info("event trace: Could not enable event " |
140 | "%s\n", call->name); | 163 | "%s\n", call->name); |
141 | break; | 164 | break; |
142 | } | 165 | } |
143 | call->enabled = 1; | 166 | call->flags |= TRACE_EVENT_FL_ENABLED; |
144 | } | 167 | } |
145 | break; | 168 | break; |
146 | } | 169 | } |
@@ -171,15 +194,16 @@ static int __ftrace_set_clr_event(const char *match, const char *sub, | |||
171 | mutex_lock(&event_mutex); | 194 | mutex_lock(&event_mutex); |
172 | list_for_each_entry(call, &ftrace_events, list) { | 195 | list_for_each_entry(call, &ftrace_events, list) { |
173 | 196 | ||
174 | if (!call->name || !call->regfunc) | 197 | if (!call->name || !call->class || |
198 | (!call->class->probe && !call->class->reg)) | ||
175 | continue; | 199 | continue; |
176 | 200 | ||
177 | if (match && | 201 | if (match && |
178 | strcmp(match, call->name) != 0 && | 202 | strcmp(match, call->name) != 0 && |
179 | strcmp(match, call->system) != 0) | 203 | strcmp(match, call->class->system) != 0) |
180 | continue; | 204 | continue; |
181 | 205 | ||
182 | if (sub && strcmp(sub, call->system) != 0) | 206 | if (sub && strcmp(sub, call->class->system) != 0) |
183 | continue; | 207 | continue; |
184 | 208 | ||
185 | if (event && strcmp(event, call->name) != 0) | 209 | if (event && strcmp(event, call->name) != 0) |
@@ -297,7 +321,7 @@ t_next(struct seq_file *m, void *v, loff_t *pos) | |||
297 | * The ftrace subsystem is for showing formats only. | 321 | * The ftrace subsystem is for showing formats only. |
298 | * They can not be enabled or disabled via the event files. | 322 | * They can not be enabled or disabled via the event files. |
299 | */ | 323 | */ |
300 | if (call->regfunc) | 324 | if (call->class && (call->class->probe || call->class->reg)) |
301 | return call; | 325 | return call; |
302 | } | 326 | } |
303 | 327 | ||
@@ -328,7 +352,7 @@ s_next(struct seq_file *m, void *v, loff_t *pos) | |||
328 | (*pos)++; | 352 | (*pos)++; |
329 | 353 | ||
330 | list_for_each_entry_continue(call, &ftrace_events, list) { | 354 | list_for_each_entry_continue(call, &ftrace_events, list) { |
331 | if (call->enabled) | 355 | if (call->flags & TRACE_EVENT_FL_ENABLED) |
332 | return call; | 356 | return call; |
333 | } | 357 | } |
334 | 358 | ||
@@ -355,8 +379,8 @@ static int t_show(struct seq_file *m, void *v) | |||
355 | { | 379 | { |
356 | struct ftrace_event_call *call = v; | 380 | struct ftrace_event_call *call = v; |
357 | 381 | ||
358 | if (strcmp(call->system, TRACE_SYSTEM) != 0) | 382 | if (strcmp(call->class->system, TRACE_SYSTEM) != 0) |
359 | seq_printf(m, "%s:", call->system); | 383 | seq_printf(m, "%s:", call->class->system); |
360 | seq_printf(m, "%s\n", call->name); | 384 | seq_printf(m, "%s\n", call->name); |
361 | 385 | ||
362 | return 0; | 386 | return 0; |
@@ -387,7 +411,7 @@ event_enable_read(struct file *filp, char __user *ubuf, size_t cnt, | |||
387 | struct ftrace_event_call *call = filp->private_data; | 411 | struct ftrace_event_call *call = filp->private_data; |
388 | char *buf; | 412 | char *buf; |
389 | 413 | ||
390 | if (call->enabled) | 414 | if (call->flags & TRACE_EVENT_FL_ENABLED) |
391 | buf = "1\n"; | 415 | buf = "1\n"; |
392 | else | 416 | else |
393 | buf = "0\n"; | 417 | buf = "0\n"; |
@@ -450,10 +474,11 @@ system_enable_read(struct file *filp, char __user *ubuf, size_t cnt, | |||
450 | 474 | ||
451 | mutex_lock(&event_mutex); | 475 | mutex_lock(&event_mutex); |
452 | list_for_each_entry(call, &ftrace_events, list) { | 476 | list_for_each_entry(call, &ftrace_events, list) { |
453 | if (!call->name || !call->regfunc) | 477 | if (!call->name || !call->class || |
478 | (!call->class->probe && !call->class->reg)) | ||
454 | continue; | 479 | continue; |
455 | 480 | ||
456 | if (system && strcmp(call->system, system) != 0) | 481 | if (system && strcmp(call->class->system, system) != 0) |
457 | continue; | 482 | continue; |
458 | 483 | ||
459 | /* | 484 | /* |
@@ -461,7 +486,7 @@ system_enable_read(struct file *filp, char __user *ubuf, size_t cnt, | |||
461 | * or if all events or cleared, or if we have | 486 | * or if all events or cleared, or if we have |
462 | * a mixture. | 487 | * a mixture. |
463 | */ | 488 | */ |
464 | set |= (1 << !!call->enabled); | 489 | set |= (1 << !!(call->flags & TRACE_EVENT_FL_ENABLED)); |
465 | 490 | ||
466 | /* | 491 | /* |
467 | * If we have a mixture, no need to look further. | 492 | * If we have a mixture, no need to look further. |
@@ -525,6 +550,7 @@ event_format_read(struct file *filp, char __user *ubuf, size_t cnt, | |||
525 | { | 550 | { |
526 | struct ftrace_event_call *call = filp->private_data; | 551 | struct ftrace_event_call *call = filp->private_data; |
527 | struct ftrace_event_field *field; | 552 | struct ftrace_event_field *field; |
553 | struct list_head *head; | ||
528 | struct trace_seq *s; | 554 | struct trace_seq *s; |
529 | int common_field_count = 5; | 555 | int common_field_count = 5; |
530 | char *buf; | 556 | char *buf; |
@@ -540,10 +566,11 @@ event_format_read(struct file *filp, char __user *ubuf, size_t cnt, | |||
540 | trace_seq_init(s); | 566 | trace_seq_init(s); |
541 | 567 | ||
542 | trace_seq_printf(s, "name: %s\n", call->name); | 568 | trace_seq_printf(s, "name: %s\n", call->name); |
543 | trace_seq_printf(s, "ID: %d\n", call->id); | 569 | trace_seq_printf(s, "ID: %d\n", call->event.type); |
544 | trace_seq_printf(s, "format:\n"); | 570 | trace_seq_printf(s, "format:\n"); |
545 | 571 | ||
546 | list_for_each_entry_reverse(field, &call->fields, link) { | 572 | head = trace_get_fields(call); |
573 | list_for_each_entry_reverse(field, head, link) { | ||
547 | /* | 574 | /* |
548 | * Smartly shows the array type(except dynamic array). | 575 | * Smartly shows the array type(except dynamic array). |
549 | * Normal: | 576 | * Normal: |
@@ -613,7 +640,7 @@ event_id_read(struct file *filp, char __user *ubuf, size_t cnt, loff_t *ppos) | |||
613 | return -ENOMEM; | 640 | return -ENOMEM; |
614 | 641 | ||
615 | trace_seq_init(s); | 642 | trace_seq_init(s); |
616 | trace_seq_printf(s, "%d\n", call->id); | 643 | trace_seq_printf(s, "%d\n", call->event.type); |
617 | 644 | ||
618 | r = simple_read_from_buffer(ubuf, cnt, ppos, | 645 | r = simple_read_from_buffer(ubuf, cnt, ppos, |
619 | s->buffer, s->len); | 646 | s->buffer, s->len); |
@@ -919,14 +946,15 @@ event_create_dir(struct ftrace_event_call *call, struct dentry *d_events, | |||
919 | const struct file_operations *filter, | 946 | const struct file_operations *filter, |
920 | const struct file_operations *format) | 947 | const struct file_operations *format) |
921 | { | 948 | { |
949 | struct list_head *head; | ||
922 | int ret; | 950 | int ret; |
923 | 951 | ||
924 | /* | 952 | /* |
925 | * If the trace point header did not define TRACE_SYSTEM | 953 | * If the trace point header did not define TRACE_SYSTEM |
926 | * then the system would be called "TRACE_SYSTEM". | 954 | * then the system would be called "TRACE_SYSTEM". |
927 | */ | 955 | */ |
928 | if (strcmp(call->system, TRACE_SYSTEM) != 0) | 956 | if (strcmp(call->class->system, TRACE_SYSTEM) != 0) |
929 | d_events = event_subsystem_dir(call->system, d_events); | 957 | d_events = event_subsystem_dir(call->class->system, d_events); |
930 | 958 | ||
931 | call->dir = debugfs_create_dir(call->name, d_events); | 959 | call->dir = debugfs_create_dir(call->name, d_events); |
932 | if (!call->dir) { | 960 | if (!call->dir) { |
@@ -935,22 +963,31 @@ event_create_dir(struct ftrace_event_call *call, struct dentry *d_events, | |||
935 | return -1; | 963 | return -1; |
936 | } | 964 | } |
937 | 965 | ||
938 | if (call->regfunc) | 966 | if (call->class->probe || call->class->reg) |
939 | trace_create_file("enable", 0644, call->dir, call, | 967 | trace_create_file("enable", 0644, call->dir, call, |
940 | enable); | 968 | enable); |
941 | 969 | ||
942 | if (call->id && call->perf_event_enable) | 970 | #ifdef CONFIG_PERF_EVENTS |
971 | if (call->event.type && (call->class->perf_probe || call->class->reg)) | ||
943 | trace_create_file("id", 0444, call->dir, call, | 972 | trace_create_file("id", 0444, call->dir, call, |
944 | id); | 973 | id); |
974 | #endif | ||
945 | 975 | ||
946 | if (call->define_fields) { | 976 | if (call->class->define_fields) { |
947 | ret = trace_define_common_fields(call); | 977 | /* |
948 | if (!ret) | 978 | * Other events may have the same class. Only update |
949 | ret = call->define_fields(call); | 979 | * the fields if they are not already defined. |
950 | if (ret < 0) { | 980 | */ |
951 | pr_warning("Could not initialize trace point" | 981 | head = trace_get_fields(call); |
952 | " events/%s\n", call->name); | 982 | if (list_empty(head)) { |
953 | return ret; | 983 | ret = trace_define_common_fields(call); |
984 | if (!ret) | ||
985 | ret = call->class->define_fields(call); | ||
986 | if (ret < 0) { | ||
987 | pr_warning("Could not initialize trace point" | ||
988 | " events/%s\n", call->name); | ||
989 | return ret; | ||
990 | } | ||
954 | } | 991 | } |
955 | trace_create_file("filter", 0644, call->dir, call, | 992 | trace_create_file("filter", 0644, call->dir, call, |
956 | filter); | 993 | filter); |
@@ -970,8 +1007,8 @@ static int __trace_add_event_call(struct ftrace_event_call *call) | |||
970 | if (!call->name) | 1007 | if (!call->name) |
971 | return -EINVAL; | 1008 | return -EINVAL; |
972 | 1009 | ||
973 | if (call->raw_init) { | 1010 | if (call->class->raw_init) { |
974 | ret = call->raw_init(call); | 1011 | ret = call->class->raw_init(call); |
975 | if (ret < 0) { | 1012 | if (ret < 0) { |
976 | if (ret != -ENOSYS) | 1013 | if (ret != -ENOSYS) |
977 | pr_warning("Could not initialize trace " | 1014 | pr_warning("Could not initialize trace " |
@@ -1035,13 +1072,13 @@ static void remove_subsystem_dir(const char *name) | |||
1035 | static void __trace_remove_event_call(struct ftrace_event_call *call) | 1072 | static void __trace_remove_event_call(struct ftrace_event_call *call) |
1036 | { | 1073 | { |
1037 | ftrace_event_enable_disable(call, 0); | 1074 | ftrace_event_enable_disable(call, 0); |
1038 | if (call->event) | 1075 | if (call->event.funcs) |
1039 | __unregister_ftrace_event(call->event); | 1076 | __unregister_ftrace_event(&call->event); |
1040 | debugfs_remove_recursive(call->dir); | 1077 | debugfs_remove_recursive(call->dir); |
1041 | list_del(&call->list); | 1078 | list_del(&call->list); |
1042 | trace_destroy_fields(call); | 1079 | trace_destroy_fields(call); |
1043 | destroy_preds(call); | 1080 | destroy_preds(call); |
1044 | remove_subsystem_dir(call->system); | 1081 | remove_subsystem_dir(call->class->system); |
1045 | } | 1082 | } |
1046 | 1083 | ||
1047 | /* Remove an event_call */ | 1084 | /* Remove an event_call */ |
@@ -1132,8 +1169,8 @@ static void trace_module_add_events(struct module *mod) | |||
1132 | /* The linker may leave blanks */ | 1169 | /* The linker may leave blanks */ |
1133 | if (!call->name) | 1170 | if (!call->name) |
1134 | continue; | 1171 | continue; |
1135 | if (call->raw_init) { | 1172 | if (call->class->raw_init) { |
1136 | ret = call->raw_init(call); | 1173 | ret = call->class->raw_init(call); |
1137 | if (ret < 0) { | 1174 | if (ret < 0) { |
1138 | if (ret != -ENOSYS) | 1175 | if (ret != -ENOSYS) |
1139 | pr_warning("Could not initialize trace " | 1176 | pr_warning("Could not initialize trace " |
@@ -1286,8 +1323,8 @@ static __init int event_trace_init(void) | |||
1286 | /* The linker may leave blanks */ | 1323 | /* The linker may leave blanks */ |
1287 | if (!call->name) | 1324 | if (!call->name) |
1288 | continue; | 1325 | continue; |
1289 | if (call->raw_init) { | 1326 | if (call->class->raw_init) { |
1290 | ret = call->raw_init(call); | 1327 | ret = call->class->raw_init(call); |
1291 | if (ret < 0) { | 1328 | if (ret < 0) { |
1292 | if (ret != -ENOSYS) | 1329 | if (ret != -ENOSYS) |
1293 | pr_warning("Could not initialize trace " | 1330 | pr_warning("Could not initialize trace " |
@@ -1388,8 +1425,8 @@ static __init void event_trace_self_tests(void) | |||
1388 | 1425 | ||
1389 | list_for_each_entry(call, &ftrace_events, list) { | 1426 | list_for_each_entry(call, &ftrace_events, list) { |
1390 | 1427 | ||
1391 | /* Only test those that have a regfunc */ | 1428 | /* Only test those that have a probe */ |
1392 | if (!call->regfunc) | 1429 | if (!call->class || !call->class->probe) |
1393 | continue; | 1430 | continue; |
1394 | 1431 | ||
1395 | /* | 1432 | /* |
@@ -1399,8 +1436,8 @@ static __init void event_trace_self_tests(void) | |||
1399 | * syscalls as we test. | 1436 | * syscalls as we test. |
1400 | */ | 1437 | */ |
1401 | #ifndef CONFIG_EVENT_TRACE_TEST_SYSCALLS | 1438 | #ifndef CONFIG_EVENT_TRACE_TEST_SYSCALLS |
1402 | if (call->system && | 1439 | if (call->class->system && |
1403 | strcmp(call->system, "syscalls") == 0) | 1440 | strcmp(call->class->system, "syscalls") == 0) |
1404 | continue; | 1441 | continue; |
1405 | #endif | 1442 | #endif |
1406 | 1443 | ||
@@ -1410,7 +1447,7 @@ static __init void event_trace_self_tests(void) | |||
1410 | * If an event is already enabled, someone is using | 1447 | * If an event is already enabled, someone is using |
1411 | * it and the self test should not be on. | 1448 | * it and the self test should not be on. |
1412 | */ | 1449 | */ |
1413 | if (call->enabled) { | 1450 | if (call->flags & TRACE_EVENT_FL_ENABLED) { |
1414 | pr_warning("Enabled event during self test!\n"); | 1451 | pr_warning("Enabled event during self test!\n"); |
1415 | WARN_ON_ONCE(1); | 1452 | WARN_ON_ONCE(1); |
1416 | continue; | 1453 | continue; |
diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events_filter.c index 58092d844a1f..57bb1bb32999 100644 --- a/kernel/trace/trace_events_filter.c +++ b/kernel/trace/trace_events_filter.c | |||
@@ -500,8 +500,10 @@ static struct ftrace_event_field * | |||
500 | find_event_field(struct ftrace_event_call *call, char *name) | 500 | find_event_field(struct ftrace_event_call *call, char *name) |
501 | { | 501 | { |
502 | struct ftrace_event_field *field; | 502 | struct ftrace_event_field *field; |
503 | struct list_head *head; | ||
503 | 504 | ||
504 | list_for_each_entry(field, &call->fields, link) { | 505 | head = trace_get_fields(call); |
506 | list_for_each_entry(field, head, link) { | ||
505 | if (!strcmp(field->name, name)) | 507 | if (!strcmp(field->name, name)) |
506 | return field; | 508 | return field; |
507 | } | 509 | } |
@@ -545,7 +547,7 @@ static void filter_disable_preds(struct ftrace_event_call *call) | |||
545 | struct event_filter *filter = call->filter; | 547 | struct event_filter *filter = call->filter; |
546 | int i; | 548 | int i; |
547 | 549 | ||
548 | call->filter_active = 0; | 550 | call->flags &= ~TRACE_EVENT_FL_FILTERED; |
549 | filter->n_preds = 0; | 551 | filter->n_preds = 0; |
550 | 552 | ||
551 | for (i = 0; i < MAX_FILTER_PRED; i++) | 553 | for (i = 0; i < MAX_FILTER_PRED; i++) |
@@ -572,7 +574,7 @@ void destroy_preds(struct ftrace_event_call *call) | |||
572 | { | 574 | { |
573 | __free_preds(call->filter); | 575 | __free_preds(call->filter); |
574 | call->filter = NULL; | 576 | call->filter = NULL; |
575 | call->filter_active = 0; | 577 | call->flags &= ~TRACE_EVENT_FL_FILTERED; |
576 | } | 578 | } |
577 | 579 | ||
578 | static struct event_filter *__alloc_preds(void) | 580 | static struct event_filter *__alloc_preds(void) |
@@ -611,7 +613,7 @@ static int init_preds(struct ftrace_event_call *call) | |||
611 | if (call->filter) | 613 | if (call->filter) |
612 | return 0; | 614 | return 0; |
613 | 615 | ||
614 | call->filter_active = 0; | 616 | call->flags &= ~TRACE_EVENT_FL_FILTERED; |
615 | call->filter = __alloc_preds(); | 617 | call->filter = __alloc_preds(); |
616 | if (IS_ERR(call->filter)) | 618 | if (IS_ERR(call->filter)) |
617 | return PTR_ERR(call->filter); | 619 | return PTR_ERR(call->filter); |
@@ -625,10 +627,10 @@ static int init_subsystem_preds(struct event_subsystem *system) | |||
625 | int err; | 627 | int err; |
626 | 628 | ||
627 | list_for_each_entry(call, &ftrace_events, list) { | 629 | list_for_each_entry(call, &ftrace_events, list) { |
628 | if (!call->define_fields) | 630 | if (!call->class || !call->class->define_fields) |
629 | continue; | 631 | continue; |
630 | 632 | ||
631 | if (strcmp(call->system, system->name) != 0) | 633 | if (strcmp(call->class->system, system->name) != 0) |
632 | continue; | 634 | continue; |
633 | 635 | ||
634 | err = init_preds(call); | 636 | err = init_preds(call); |
@@ -644,10 +646,10 @@ static void filter_free_subsystem_preds(struct event_subsystem *system) | |||
644 | struct ftrace_event_call *call; | 646 | struct ftrace_event_call *call; |
645 | 647 | ||
646 | list_for_each_entry(call, &ftrace_events, list) { | 648 | list_for_each_entry(call, &ftrace_events, list) { |
647 | if (!call->define_fields) | 649 | if (!call->class || !call->class->define_fields) |
648 | continue; | 650 | continue; |
649 | 651 | ||
650 | if (strcmp(call->system, system->name) != 0) | 652 | if (strcmp(call->class->system, system->name) != 0) |
651 | continue; | 653 | continue; |
652 | 654 | ||
653 | filter_disable_preds(call); | 655 | filter_disable_preds(call); |
@@ -1249,10 +1251,10 @@ static int replace_system_preds(struct event_subsystem *system, | |||
1249 | list_for_each_entry(call, &ftrace_events, list) { | 1251 | list_for_each_entry(call, &ftrace_events, list) { |
1250 | struct event_filter *filter = call->filter; | 1252 | struct event_filter *filter = call->filter; |
1251 | 1253 | ||
1252 | if (!call->define_fields) | 1254 | if (!call->class || !call->class->define_fields) |
1253 | continue; | 1255 | continue; |
1254 | 1256 | ||
1255 | if (strcmp(call->system, system->name) != 0) | 1257 | if (strcmp(call->class->system, system->name) != 0) |
1256 | continue; | 1258 | continue; |
1257 | 1259 | ||
1258 | /* try to see if the filter can be applied */ | 1260 | /* try to see if the filter can be applied */ |
@@ -1266,7 +1268,7 @@ static int replace_system_preds(struct event_subsystem *system, | |||
1266 | if (err) | 1268 | if (err) |
1267 | filter_disable_preds(call); | 1269 | filter_disable_preds(call); |
1268 | else { | 1270 | else { |
1269 | call->filter_active = 1; | 1271 | call->flags |= TRACE_EVENT_FL_FILTERED; |
1270 | replace_filter_string(filter, filter_string); | 1272 | replace_filter_string(filter, filter_string); |
1271 | } | 1273 | } |
1272 | fail = false; | 1274 | fail = false; |
@@ -1315,7 +1317,7 @@ int apply_event_filter(struct ftrace_event_call *call, char *filter_string) | |||
1315 | if (err) | 1317 | if (err) |
1316 | append_filter_err(ps, call->filter); | 1318 | append_filter_err(ps, call->filter); |
1317 | else | 1319 | else |
1318 | call->filter_active = 1; | 1320 | call->flags |= TRACE_EVENT_FL_FILTERED; |
1319 | out: | 1321 | out: |
1320 | filter_opstack_clear(ps); | 1322 | filter_opstack_clear(ps); |
1321 | postfix_clear(ps); | 1323 | postfix_clear(ps); |
@@ -1393,7 +1395,7 @@ int ftrace_profile_set_filter(struct perf_event *event, int event_id, | |||
1393 | mutex_lock(&event_mutex); | 1395 | mutex_lock(&event_mutex); |
1394 | 1396 | ||
1395 | list_for_each_entry(call, &ftrace_events, list) { | 1397 | list_for_each_entry(call, &ftrace_events, list) { |
1396 | if (call->id == event_id) | 1398 | if (call->event.type == event_id) |
1397 | break; | 1399 | break; |
1398 | } | 1400 | } |
1399 | 1401 | ||
diff --git a/kernel/trace/trace_export.c b/kernel/trace/trace_export.c index e091f64ba6ce..8536e2a65969 100644 --- a/kernel/trace/trace_export.c +++ b/kernel/trace/trace_export.c | |||
@@ -127,7 +127,7 @@ ftrace_define_fields_##name(struct ftrace_event_call *event_call) \ | |||
127 | 127 | ||
128 | static int ftrace_raw_init_event(struct ftrace_event_call *call) | 128 | static int ftrace_raw_init_event(struct ftrace_event_call *call) |
129 | { | 129 | { |
130 | INIT_LIST_HEAD(&call->fields); | 130 | INIT_LIST_HEAD(&call->class->fields); |
131 | return 0; | 131 | return 0; |
132 | } | 132 | } |
133 | 133 | ||
@@ -153,17 +153,21 @@ static int ftrace_raw_init_event(struct ftrace_event_call *call) | |||
153 | #define F_printk(fmt, args...) #fmt ", " __stringify(args) | 153 | #define F_printk(fmt, args...) #fmt ", " __stringify(args) |
154 | 154 | ||
155 | #undef FTRACE_ENTRY | 155 | #undef FTRACE_ENTRY |
156 | #define FTRACE_ENTRY(call, struct_name, type, tstruct, print) \ | 156 | #define FTRACE_ENTRY(call, struct_name, etype, tstruct, print) \ |
157 | \ | ||
158 | struct ftrace_event_class event_class_ftrace_##call = { \ | ||
159 | .system = __stringify(TRACE_SYSTEM), \ | ||
160 | .define_fields = ftrace_define_fields_##call, \ | ||
161 | .raw_init = ftrace_raw_init_event, \ | ||
162 | }; \ | ||
157 | \ | 163 | \ |
158 | struct ftrace_event_call __used \ | 164 | struct ftrace_event_call __used \ |
159 | __attribute__((__aligned__(4))) \ | 165 | __attribute__((__aligned__(4))) \ |
160 | __attribute__((section("_ftrace_events"))) event_##call = { \ | 166 | __attribute__((section("_ftrace_events"))) event_##call = { \ |
161 | .name = #call, \ | 167 | .name = #call, \ |
162 | .id = type, \ | 168 | .event.type = etype, \ |
163 | .system = __stringify(TRACE_SYSTEM), \ | 169 | .class = &event_class_ftrace_##call, \ |
164 | .raw_init = ftrace_raw_init_event, \ | ||
165 | .print_fmt = print, \ | 170 | .print_fmt = print, \ |
166 | .define_fields = ftrace_define_fields_##call, \ | ||
167 | }; \ | 171 | }; \ |
168 | 172 | ||
169 | #include "trace_entries.h" | 173 | #include "trace_entries.h" |
diff --git a/kernel/trace/trace_functions_graph.c b/kernel/trace/trace_functions_graph.c index dd11c830eb84..79f4bac99a94 100644 --- a/kernel/trace/trace_functions_graph.c +++ b/kernel/trace/trace_functions_graph.c | |||
@@ -1025,7 +1025,7 @@ print_graph_comment(struct trace_seq *s, struct trace_entry *ent, | |||
1025 | if (!event) | 1025 | if (!event) |
1026 | return TRACE_TYPE_UNHANDLED; | 1026 | return TRACE_TYPE_UNHANDLED; |
1027 | 1027 | ||
1028 | ret = event->trace(iter, sym_flags); | 1028 | ret = event->funcs->trace(iter, sym_flags, event); |
1029 | if (ret != TRACE_TYPE_HANDLED) | 1029 | if (ret != TRACE_TYPE_HANDLED) |
1030 | return ret; | 1030 | return ret; |
1031 | } | 1031 | } |
@@ -1112,7 +1112,8 @@ print_graph_function(struct trace_iterator *iter) | |||
1112 | } | 1112 | } |
1113 | 1113 | ||
1114 | static enum print_line_t | 1114 | static enum print_line_t |
1115 | print_graph_function_event(struct trace_iterator *iter, int flags) | 1115 | print_graph_function_event(struct trace_iterator *iter, int flags, |
1116 | struct trace_event *event) | ||
1116 | { | 1117 | { |
1117 | return print_graph_function(iter); | 1118 | return print_graph_function(iter); |
1118 | } | 1119 | } |
@@ -1225,14 +1226,18 @@ void graph_trace_close(struct trace_iterator *iter) | |||
1225 | } | 1226 | } |
1226 | } | 1227 | } |
1227 | 1228 | ||
1229 | static struct trace_event_functions graph_functions = { | ||
1230 | .trace = print_graph_function_event, | ||
1231 | }; | ||
1232 | |||
1228 | static struct trace_event graph_trace_entry_event = { | 1233 | static struct trace_event graph_trace_entry_event = { |
1229 | .type = TRACE_GRAPH_ENT, | 1234 | .type = TRACE_GRAPH_ENT, |
1230 | .trace = print_graph_function_event, | 1235 | .funcs = &graph_functions, |
1231 | }; | 1236 | }; |
1232 | 1237 | ||
1233 | static struct trace_event graph_trace_ret_event = { | 1238 | static struct trace_event graph_trace_ret_event = { |
1234 | .type = TRACE_GRAPH_RET, | 1239 | .type = TRACE_GRAPH_RET, |
1235 | .trace = print_graph_function_event, | 1240 | .funcs = &graph_functions |
1236 | }; | 1241 | }; |
1237 | 1242 | ||
1238 | static struct tracer graph_trace __read_mostly = { | 1243 | static struct tracer graph_trace __read_mostly = { |
diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c index a7514326052b..faf7cefd15da 100644 --- a/kernel/trace/trace_kprobe.c +++ b/kernel/trace/trace_kprobe.c | |||
@@ -324,8 +324,8 @@ struct trace_probe { | |||
324 | unsigned long nhit; | 324 | unsigned long nhit; |
325 | unsigned int flags; /* For TP_FLAG_* */ | 325 | unsigned int flags; /* For TP_FLAG_* */ |
326 | const char *symbol; /* symbol name */ | 326 | const char *symbol; /* symbol name */ |
327 | struct ftrace_event_class class; | ||
327 | struct ftrace_event_call call; | 328 | struct ftrace_event_call call; |
328 | struct trace_event event; | ||
329 | ssize_t size; /* trace entry size */ | 329 | ssize_t size; /* trace entry size */ |
330 | unsigned int nr_args; | 330 | unsigned int nr_args; |
331 | struct probe_arg args[]; | 331 | struct probe_arg args[]; |
@@ -404,6 +404,7 @@ static struct trace_probe *alloc_trace_probe(const char *group, | |||
404 | goto error; | 404 | goto error; |
405 | } | 405 | } |
406 | 406 | ||
407 | tp->call.class = &tp->class; | ||
407 | tp->call.name = kstrdup(event, GFP_KERNEL); | 408 | tp->call.name = kstrdup(event, GFP_KERNEL); |
408 | if (!tp->call.name) | 409 | if (!tp->call.name) |
409 | goto error; | 410 | goto error; |
@@ -413,8 +414,8 @@ static struct trace_probe *alloc_trace_probe(const char *group, | |||
413 | goto error; | 414 | goto error; |
414 | } | 415 | } |
415 | 416 | ||
416 | tp->call.system = kstrdup(group, GFP_KERNEL); | 417 | tp->class.system = kstrdup(group, GFP_KERNEL); |
417 | if (!tp->call.system) | 418 | if (!tp->class.system) |
418 | goto error; | 419 | goto error; |
419 | 420 | ||
420 | INIT_LIST_HEAD(&tp->list); | 421 | INIT_LIST_HEAD(&tp->list); |
@@ -443,7 +444,7 @@ static void free_trace_probe(struct trace_probe *tp) | |||
443 | for (i = 0; i < tp->nr_args; i++) | 444 | for (i = 0; i < tp->nr_args; i++) |
444 | free_probe_arg(&tp->args[i]); | 445 | free_probe_arg(&tp->args[i]); |
445 | 446 | ||
446 | kfree(tp->call.system); | 447 | kfree(tp->call.class->system); |
447 | kfree(tp->call.name); | 448 | kfree(tp->call.name); |
448 | kfree(tp->symbol); | 449 | kfree(tp->symbol); |
449 | kfree(tp); | 450 | kfree(tp); |
@@ -456,7 +457,7 @@ static struct trace_probe *find_probe_event(const char *event, | |||
456 | 457 | ||
457 | list_for_each_entry(tp, &probe_list, list) | 458 | list_for_each_entry(tp, &probe_list, list) |
458 | if (strcmp(tp->call.name, event) == 0 && | 459 | if (strcmp(tp->call.name, event) == 0 && |
459 | strcmp(tp->call.system, group) == 0) | 460 | strcmp(tp->call.class->system, group) == 0) |
460 | return tp; | 461 | return tp; |
461 | return NULL; | 462 | return NULL; |
462 | } | 463 | } |
@@ -481,7 +482,7 @@ static int register_trace_probe(struct trace_probe *tp) | |||
481 | mutex_lock(&probe_lock); | 482 | mutex_lock(&probe_lock); |
482 | 483 | ||
483 | /* register as an event */ | 484 | /* register as an event */ |
484 | old_tp = find_probe_event(tp->call.name, tp->call.system); | 485 | old_tp = find_probe_event(tp->call.name, tp->call.class->system); |
485 | if (old_tp) { | 486 | if (old_tp) { |
486 | /* delete old event */ | 487 | /* delete old event */ |
487 | unregister_trace_probe(old_tp); | 488 | unregister_trace_probe(old_tp); |
@@ -904,7 +905,7 @@ static int probes_seq_show(struct seq_file *m, void *v) | |||
904 | int i; | 905 | int i; |
905 | 906 | ||
906 | seq_printf(m, "%c", probe_is_return(tp) ? 'r' : 'p'); | 907 | seq_printf(m, "%c", probe_is_return(tp) ? 'r' : 'p'); |
907 | seq_printf(m, ":%s/%s", tp->call.system, tp->call.name); | 908 | seq_printf(m, ":%s/%s", tp->call.class->system, tp->call.name); |
908 | 909 | ||
909 | if (!tp->symbol) | 910 | if (!tp->symbol) |
910 | seq_printf(m, " 0x%p", tp->rp.kp.addr); | 911 | seq_printf(m, " 0x%p", tp->rp.kp.addr); |
@@ -1061,8 +1062,8 @@ static __kprobes void kprobe_trace_func(struct kprobe *kp, struct pt_regs *regs) | |||
1061 | 1062 | ||
1062 | size = sizeof(*entry) + tp->size; | 1063 | size = sizeof(*entry) + tp->size; |
1063 | 1064 | ||
1064 | event = trace_current_buffer_lock_reserve(&buffer, call->id, size, | 1065 | event = trace_current_buffer_lock_reserve(&buffer, call->event.type, |
1065 | irq_flags, pc); | 1066 | size, irq_flags, pc); |
1066 | if (!event) | 1067 | if (!event) |
1067 | return; | 1068 | return; |
1068 | 1069 | ||
@@ -1094,8 +1095,8 @@ static __kprobes void kretprobe_trace_func(struct kretprobe_instance *ri, | |||
1094 | 1095 | ||
1095 | size = sizeof(*entry) + tp->size; | 1096 | size = sizeof(*entry) + tp->size; |
1096 | 1097 | ||
1097 | event = trace_current_buffer_lock_reserve(&buffer, call->id, size, | 1098 | event = trace_current_buffer_lock_reserve(&buffer, call->event.type, |
1098 | irq_flags, pc); | 1099 | size, irq_flags, pc); |
1099 | if (!event) | 1100 | if (!event) |
1100 | return; | 1101 | return; |
1101 | 1102 | ||
@@ -1112,18 +1113,17 @@ static __kprobes void kretprobe_trace_func(struct kretprobe_instance *ri, | |||
1112 | 1113 | ||
1113 | /* Event entry printers */ | 1114 | /* Event entry printers */ |
1114 | enum print_line_t | 1115 | enum print_line_t |
1115 | print_kprobe_event(struct trace_iterator *iter, int flags) | 1116 | print_kprobe_event(struct trace_iterator *iter, int flags, |
1117 | struct trace_event *event) | ||
1116 | { | 1118 | { |
1117 | struct kprobe_trace_entry_head *field; | 1119 | struct kprobe_trace_entry_head *field; |
1118 | struct trace_seq *s = &iter->seq; | 1120 | struct trace_seq *s = &iter->seq; |
1119 | struct trace_event *event; | ||
1120 | struct trace_probe *tp; | 1121 | struct trace_probe *tp; |
1121 | u8 *data; | 1122 | u8 *data; |
1122 | int i; | 1123 | int i; |
1123 | 1124 | ||
1124 | field = (struct kprobe_trace_entry_head *)iter->ent; | 1125 | field = (struct kprobe_trace_entry_head *)iter->ent; |
1125 | event = ftrace_find_event(field->ent.type); | 1126 | tp = container_of(event, struct trace_probe, call.event); |
1126 | tp = container_of(event, struct trace_probe, event); | ||
1127 | 1127 | ||
1128 | if (!trace_seq_printf(s, "%s: (", tp->call.name)) | 1128 | if (!trace_seq_printf(s, "%s: (", tp->call.name)) |
1129 | goto partial; | 1129 | goto partial; |
@@ -1149,18 +1149,17 @@ partial: | |||
1149 | } | 1149 | } |
1150 | 1150 | ||
1151 | enum print_line_t | 1151 | enum print_line_t |
1152 | print_kretprobe_event(struct trace_iterator *iter, int flags) | 1152 | print_kretprobe_event(struct trace_iterator *iter, int flags, |
1153 | struct trace_event *event) | ||
1153 | { | 1154 | { |
1154 | struct kretprobe_trace_entry_head *field; | 1155 | struct kretprobe_trace_entry_head *field; |
1155 | struct trace_seq *s = &iter->seq; | 1156 | struct trace_seq *s = &iter->seq; |
1156 | struct trace_event *event; | ||
1157 | struct trace_probe *tp; | 1157 | struct trace_probe *tp; |
1158 | u8 *data; | 1158 | u8 *data; |
1159 | int i; | 1159 | int i; |
1160 | 1160 | ||
1161 | field = (struct kretprobe_trace_entry_head *)iter->ent; | 1161 | field = (struct kretprobe_trace_entry_head *)iter->ent; |
1162 | event = ftrace_find_event(field->ent.type); | 1162 | tp = container_of(event, struct trace_probe, call.event); |
1163 | tp = container_of(event, struct trace_probe, event); | ||
1164 | 1163 | ||
1165 | if (!trace_seq_printf(s, "%s: (", tp->call.name)) | 1164 | if (!trace_seq_printf(s, "%s: (", tp->call.name)) |
1166 | goto partial; | 1165 | goto partial; |
@@ -1217,8 +1216,6 @@ static void probe_event_disable(struct ftrace_event_call *call) | |||
1217 | 1216 | ||
1218 | static int probe_event_raw_init(struct ftrace_event_call *event_call) | 1217 | static int probe_event_raw_init(struct ftrace_event_call *event_call) |
1219 | { | 1218 | { |
1220 | INIT_LIST_HEAD(&event_call->fields); | ||
1221 | |||
1222 | return 0; | 1219 | return 0; |
1223 | } | 1220 | } |
1224 | 1221 | ||
@@ -1341,9 +1338,9 @@ static __kprobes void kprobe_perf_func(struct kprobe *kp, | |||
1341 | struct trace_probe *tp = container_of(kp, struct trace_probe, rp.kp); | 1338 | struct trace_probe *tp = container_of(kp, struct trace_probe, rp.kp); |
1342 | struct ftrace_event_call *call = &tp->call; | 1339 | struct ftrace_event_call *call = &tp->call; |
1343 | struct kprobe_trace_entry_head *entry; | 1340 | struct kprobe_trace_entry_head *entry; |
1341 | struct hlist_head *head; | ||
1344 | u8 *data; | 1342 | u8 *data; |
1345 | int size, __size, i; | 1343 | int size, __size, i; |
1346 | unsigned long irq_flags; | ||
1347 | int rctx; | 1344 | int rctx; |
1348 | 1345 | ||
1349 | __size = sizeof(*entry) + tp->size; | 1346 | __size = sizeof(*entry) + tp->size; |
@@ -1353,7 +1350,7 @@ static __kprobes void kprobe_perf_func(struct kprobe *kp, | |||
1353 | "profile buffer not large enough")) | 1350 | "profile buffer not large enough")) |
1354 | return; | 1351 | return; |
1355 | 1352 | ||
1356 | entry = perf_trace_buf_prepare(size, call->id, &rctx, &irq_flags); | 1353 | entry = perf_trace_buf_prepare(size, call->event.type, regs, &rctx); |
1357 | if (!entry) | 1354 | if (!entry) |
1358 | return; | 1355 | return; |
1359 | 1356 | ||
@@ -1362,7 +1359,8 @@ static __kprobes void kprobe_perf_func(struct kprobe *kp, | |||
1362 | for (i = 0; i < tp->nr_args; i++) | 1359 | for (i = 0; i < tp->nr_args; i++) |
1363 | call_fetch(&tp->args[i].fetch, regs, data + tp->args[i].offset); | 1360 | call_fetch(&tp->args[i].fetch, regs, data + tp->args[i].offset); |
1364 | 1361 | ||
1365 | perf_trace_buf_submit(entry, size, rctx, entry->ip, 1, irq_flags, regs); | 1362 | head = per_cpu_ptr(call->perf_events, smp_processor_id()); |
1363 | perf_trace_buf_submit(entry, size, rctx, entry->ip, 1, regs, head); | ||
1366 | } | 1364 | } |
1367 | 1365 | ||
1368 | /* Kretprobe profile handler */ | 1366 | /* Kretprobe profile handler */ |
@@ -1372,9 +1370,9 @@ static __kprobes void kretprobe_perf_func(struct kretprobe_instance *ri, | |||
1372 | struct trace_probe *tp = container_of(ri->rp, struct trace_probe, rp); | 1370 | struct trace_probe *tp = container_of(ri->rp, struct trace_probe, rp); |
1373 | struct ftrace_event_call *call = &tp->call; | 1371 | struct ftrace_event_call *call = &tp->call; |
1374 | struct kretprobe_trace_entry_head *entry; | 1372 | struct kretprobe_trace_entry_head *entry; |
1373 | struct hlist_head *head; | ||
1375 | u8 *data; | 1374 | u8 *data; |
1376 | int size, __size, i; | 1375 | int size, __size, i; |
1377 | unsigned long irq_flags; | ||
1378 | int rctx; | 1376 | int rctx; |
1379 | 1377 | ||
1380 | __size = sizeof(*entry) + tp->size; | 1378 | __size = sizeof(*entry) + tp->size; |
@@ -1384,7 +1382,7 @@ static __kprobes void kretprobe_perf_func(struct kretprobe_instance *ri, | |||
1384 | "profile buffer not large enough")) | 1382 | "profile buffer not large enough")) |
1385 | return; | 1383 | return; |
1386 | 1384 | ||
1387 | entry = perf_trace_buf_prepare(size, call->id, &rctx, &irq_flags); | 1385 | entry = perf_trace_buf_prepare(size, call->event.type, regs, &rctx); |
1388 | if (!entry) | 1386 | if (!entry) |
1389 | return; | 1387 | return; |
1390 | 1388 | ||
@@ -1394,8 +1392,8 @@ static __kprobes void kretprobe_perf_func(struct kretprobe_instance *ri, | |||
1394 | for (i = 0; i < tp->nr_args; i++) | 1392 | for (i = 0; i < tp->nr_args; i++) |
1395 | call_fetch(&tp->args[i].fetch, regs, data + tp->args[i].offset); | 1393 | call_fetch(&tp->args[i].fetch, regs, data + tp->args[i].offset); |
1396 | 1394 | ||
1397 | perf_trace_buf_submit(entry, size, rctx, entry->ret_ip, 1, | 1395 | head = per_cpu_ptr(call->perf_events, smp_processor_id()); |
1398 | irq_flags, regs); | 1396 | perf_trace_buf_submit(entry, size, rctx, entry->ret_ip, 1, regs, head); |
1399 | } | 1397 | } |
1400 | 1398 | ||
1401 | static int probe_perf_enable(struct ftrace_event_call *call) | 1399 | static int probe_perf_enable(struct ftrace_event_call *call) |
@@ -1425,6 +1423,26 @@ static void probe_perf_disable(struct ftrace_event_call *call) | |||
1425 | } | 1423 | } |
1426 | #endif /* CONFIG_PERF_EVENTS */ | 1424 | #endif /* CONFIG_PERF_EVENTS */ |
1427 | 1425 | ||
1426 | static __kprobes | ||
1427 | int kprobe_register(struct ftrace_event_call *event, enum trace_reg type) | ||
1428 | { | ||
1429 | switch (type) { | ||
1430 | case TRACE_REG_REGISTER: | ||
1431 | return probe_event_enable(event); | ||
1432 | case TRACE_REG_UNREGISTER: | ||
1433 | probe_event_disable(event); | ||
1434 | return 0; | ||
1435 | |||
1436 | #ifdef CONFIG_PERF_EVENTS | ||
1437 | case TRACE_REG_PERF_REGISTER: | ||
1438 | return probe_perf_enable(event); | ||
1439 | case TRACE_REG_PERF_UNREGISTER: | ||
1440 | probe_perf_disable(event); | ||
1441 | return 0; | ||
1442 | #endif | ||
1443 | } | ||
1444 | return 0; | ||
1445 | } | ||
1428 | 1446 | ||
1429 | static __kprobes | 1447 | static __kprobes |
1430 | int kprobe_dispatcher(struct kprobe *kp, struct pt_regs *regs) | 1448 | int kprobe_dispatcher(struct kprobe *kp, struct pt_regs *regs) |
@@ -1454,6 +1472,14 @@ int kretprobe_dispatcher(struct kretprobe_instance *ri, struct pt_regs *regs) | |||
1454 | return 0; /* We don't tweek kernel, so just return 0 */ | 1472 | return 0; /* We don't tweek kernel, so just return 0 */ |
1455 | } | 1473 | } |
1456 | 1474 | ||
1475 | static struct trace_event_functions kretprobe_funcs = { | ||
1476 | .trace = print_kretprobe_event | ||
1477 | }; | ||
1478 | |||
1479 | static struct trace_event_functions kprobe_funcs = { | ||
1480 | .trace = print_kprobe_event | ||
1481 | }; | ||
1482 | |||
1457 | static int register_probe_event(struct trace_probe *tp) | 1483 | static int register_probe_event(struct trace_probe *tp) |
1458 | { | 1484 | { |
1459 | struct ftrace_event_call *call = &tp->call; | 1485 | struct ftrace_event_call *call = &tp->call; |
@@ -1461,36 +1487,31 @@ static int register_probe_event(struct trace_probe *tp) | |||
1461 | 1487 | ||
1462 | /* Initialize ftrace_event_call */ | 1488 | /* Initialize ftrace_event_call */ |
1463 | if (probe_is_return(tp)) { | 1489 | if (probe_is_return(tp)) { |
1464 | tp->event.trace = print_kretprobe_event; | 1490 | INIT_LIST_HEAD(&call->class->fields); |
1465 | call->raw_init = probe_event_raw_init; | 1491 | call->event.funcs = &kretprobe_funcs; |
1466 | call->define_fields = kretprobe_event_define_fields; | 1492 | call->class->raw_init = probe_event_raw_init; |
1493 | call->class->define_fields = kretprobe_event_define_fields; | ||
1467 | } else { | 1494 | } else { |
1468 | tp->event.trace = print_kprobe_event; | 1495 | INIT_LIST_HEAD(&call->class->fields); |
1469 | call->raw_init = probe_event_raw_init; | 1496 | call->event.funcs = &kprobe_funcs; |
1470 | call->define_fields = kprobe_event_define_fields; | 1497 | call->class->raw_init = probe_event_raw_init; |
1498 | call->class->define_fields = kprobe_event_define_fields; | ||
1471 | } | 1499 | } |
1472 | if (set_print_fmt(tp) < 0) | 1500 | if (set_print_fmt(tp) < 0) |
1473 | return -ENOMEM; | 1501 | return -ENOMEM; |
1474 | call->event = &tp->event; | 1502 | ret = register_ftrace_event(&call->event); |
1475 | call->id = register_ftrace_event(&tp->event); | 1503 | if (!ret) { |
1476 | if (!call->id) { | ||
1477 | kfree(call->print_fmt); | 1504 | kfree(call->print_fmt); |
1478 | return -ENODEV; | 1505 | return -ENODEV; |
1479 | } | 1506 | } |
1480 | call->enabled = 0; | 1507 | call->flags = 0; |
1481 | call->regfunc = probe_event_enable; | 1508 | call->class->reg = kprobe_register; |
1482 | call->unregfunc = probe_event_disable; | ||
1483 | |||
1484 | #ifdef CONFIG_PERF_EVENTS | ||
1485 | call->perf_event_enable = probe_perf_enable; | ||
1486 | call->perf_event_disable = probe_perf_disable; | ||
1487 | #endif | ||
1488 | call->data = tp; | 1509 | call->data = tp; |
1489 | ret = trace_add_event_call(call); | 1510 | ret = trace_add_event_call(call); |
1490 | if (ret) { | 1511 | if (ret) { |
1491 | pr_info("Failed to register kprobe event: %s\n", call->name); | 1512 | pr_info("Failed to register kprobe event: %s\n", call->name); |
1492 | kfree(call->print_fmt); | 1513 | kfree(call->print_fmt); |
1493 | unregister_ftrace_event(&tp->event); | 1514 | unregister_ftrace_event(&call->event); |
1494 | } | 1515 | } |
1495 | return ret; | 1516 | return ret; |
1496 | } | 1517 | } |
diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c index ab13d7008061..57c1b4596470 100644 --- a/kernel/trace/trace_output.c +++ b/kernel/trace/trace_output.c | |||
@@ -742,6 +742,9 @@ int register_ftrace_event(struct trace_event *event) | |||
742 | if (WARN_ON(!event)) | 742 | if (WARN_ON(!event)) |
743 | goto out; | 743 | goto out; |
744 | 744 | ||
745 | if (WARN_ON(!event->funcs)) | ||
746 | goto out; | ||
747 | |||
745 | INIT_LIST_HEAD(&event->list); | 748 | INIT_LIST_HEAD(&event->list); |
746 | 749 | ||
747 | if (!event->type) { | 750 | if (!event->type) { |
@@ -774,14 +777,14 @@ int register_ftrace_event(struct trace_event *event) | |||
774 | goto out; | 777 | goto out; |
775 | } | 778 | } |
776 | 779 | ||
777 | if (event->trace == NULL) | 780 | if (event->funcs->trace == NULL) |
778 | event->trace = trace_nop_print; | 781 | event->funcs->trace = trace_nop_print; |
779 | if (event->raw == NULL) | 782 | if (event->funcs->raw == NULL) |
780 | event->raw = trace_nop_print; | 783 | event->funcs->raw = trace_nop_print; |
781 | if (event->hex == NULL) | 784 | if (event->funcs->hex == NULL) |
782 | event->hex = trace_nop_print; | 785 | event->funcs->hex = trace_nop_print; |
783 | if (event->binary == NULL) | 786 | if (event->funcs->binary == NULL) |
784 | event->binary = trace_nop_print; | 787 | event->funcs->binary = trace_nop_print; |
785 | 788 | ||
786 | key = event->type & (EVENT_HASHSIZE - 1); | 789 | key = event->type & (EVENT_HASHSIZE - 1); |
787 | 790 | ||
@@ -823,13 +826,15 @@ EXPORT_SYMBOL_GPL(unregister_ftrace_event); | |||
823 | * Standard events | 826 | * Standard events |
824 | */ | 827 | */ |
825 | 828 | ||
826 | enum print_line_t trace_nop_print(struct trace_iterator *iter, int flags) | 829 | enum print_line_t trace_nop_print(struct trace_iterator *iter, int flags, |
830 | struct trace_event *event) | ||
827 | { | 831 | { |
828 | return TRACE_TYPE_HANDLED; | 832 | return TRACE_TYPE_HANDLED; |
829 | } | 833 | } |
830 | 834 | ||
831 | /* TRACE_FN */ | 835 | /* TRACE_FN */ |
832 | static enum print_line_t trace_fn_trace(struct trace_iterator *iter, int flags) | 836 | static enum print_line_t trace_fn_trace(struct trace_iterator *iter, int flags, |
837 | struct trace_event *event) | ||
833 | { | 838 | { |
834 | struct ftrace_entry *field; | 839 | struct ftrace_entry *field; |
835 | struct trace_seq *s = &iter->seq; | 840 | struct trace_seq *s = &iter->seq; |
@@ -856,7 +861,8 @@ static enum print_line_t trace_fn_trace(struct trace_iterator *iter, int flags) | |||
856 | return TRACE_TYPE_PARTIAL_LINE; | 861 | return TRACE_TYPE_PARTIAL_LINE; |
857 | } | 862 | } |
858 | 863 | ||
859 | static enum print_line_t trace_fn_raw(struct trace_iterator *iter, int flags) | 864 | static enum print_line_t trace_fn_raw(struct trace_iterator *iter, int flags, |
865 | struct trace_event *event) | ||
860 | { | 866 | { |
861 | struct ftrace_entry *field; | 867 | struct ftrace_entry *field; |
862 | 868 | ||
@@ -870,7 +876,8 @@ static enum print_line_t trace_fn_raw(struct trace_iterator *iter, int flags) | |||
870 | return TRACE_TYPE_HANDLED; | 876 | return TRACE_TYPE_HANDLED; |
871 | } | 877 | } |
872 | 878 | ||
873 | static enum print_line_t trace_fn_hex(struct trace_iterator *iter, int flags) | 879 | static enum print_line_t trace_fn_hex(struct trace_iterator *iter, int flags, |
880 | struct trace_event *event) | ||
874 | { | 881 | { |
875 | struct ftrace_entry *field; | 882 | struct ftrace_entry *field; |
876 | struct trace_seq *s = &iter->seq; | 883 | struct trace_seq *s = &iter->seq; |
@@ -883,7 +890,8 @@ static enum print_line_t trace_fn_hex(struct trace_iterator *iter, int flags) | |||
883 | return TRACE_TYPE_HANDLED; | 890 | return TRACE_TYPE_HANDLED; |
884 | } | 891 | } |
885 | 892 | ||
886 | static enum print_line_t trace_fn_bin(struct trace_iterator *iter, int flags) | 893 | static enum print_line_t trace_fn_bin(struct trace_iterator *iter, int flags, |
894 | struct trace_event *event) | ||
887 | { | 895 | { |
888 | struct ftrace_entry *field; | 896 | struct ftrace_entry *field; |
889 | struct trace_seq *s = &iter->seq; | 897 | struct trace_seq *s = &iter->seq; |
@@ -896,14 +904,18 @@ static enum print_line_t trace_fn_bin(struct trace_iterator *iter, int flags) | |||
896 | return TRACE_TYPE_HANDLED; | 904 | return TRACE_TYPE_HANDLED; |
897 | } | 905 | } |
898 | 906 | ||
899 | static struct trace_event trace_fn_event = { | 907 | static struct trace_event_functions trace_fn_funcs = { |
900 | .type = TRACE_FN, | ||
901 | .trace = trace_fn_trace, | 908 | .trace = trace_fn_trace, |
902 | .raw = trace_fn_raw, | 909 | .raw = trace_fn_raw, |
903 | .hex = trace_fn_hex, | 910 | .hex = trace_fn_hex, |
904 | .binary = trace_fn_bin, | 911 | .binary = trace_fn_bin, |
905 | }; | 912 | }; |
906 | 913 | ||
914 | static struct trace_event trace_fn_event = { | ||
915 | .type = TRACE_FN, | ||
916 | .funcs = &trace_fn_funcs, | ||
917 | }; | ||
918 | |||
907 | /* TRACE_CTX an TRACE_WAKE */ | 919 | /* TRACE_CTX an TRACE_WAKE */ |
908 | static enum print_line_t trace_ctxwake_print(struct trace_iterator *iter, | 920 | static enum print_line_t trace_ctxwake_print(struct trace_iterator *iter, |
909 | char *delim) | 921 | char *delim) |
@@ -932,13 +944,14 @@ static enum print_line_t trace_ctxwake_print(struct trace_iterator *iter, | |||
932 | return TRACE_TYPE_HANDLED; | 944 | return TRACE_TYPE_HANDLED; |
933 | } | 945 | } |
934 | 946 | ||
935 | static enum print_line_t trace_ctx_print(struct trace_iterator *iter, int flags) | 947 | static enum print_line_t trace_ctx_print(struct trace_iterator *iter, int flags, |
948 | struct trace_event *event) | ||
936 | { | 949 | { |
937 | return trace_ctxwake_print(iter, "==>"); | 950 | return trace_ctxwake_print(iter, "==>"); |
938 | } | 951 | } |
939 | 952 | ||
940 | static enum print_line_t trace_wake_print(struct trace_iterator *iter, | 953 | static enum print_line_t trace_wake_print(struct trace_iterator *iter, |
941 | int flags) | 954 | int flags, struct trace_event *event) |
942 | { | 955 | { |
943 | return trace_ctxwake_print(iter, " +"); | 956 | return trace_ctxwake_print(iter, " +"); |
944 | } | 957 | } |
@@ -966,12 +979,14 @@ static int trace_ctxwake_raw(struct trace_iterator *iter, char S) | |||
966 | return TRACE_TYPE_HANDLED; | 979 | return TRACE_TYPE_HANDLED; |
967 | } | 980 | } |
968 | 981 | ||
969 | static enum print_line_t trace_ctx_raw(struct trace_iterator *iter, int flags) | 982 | static enum print_line_t trace_ctx_raw(struct trace_iterator *iter, int flags, |
983 | struct trace_event *event) | ||
970 | { | 984 | { |
971 | return trace_ctxwake_raw(iter, 0); | 985 | return trace_ctxwake_raw(iter, 0); |
972 | } | 986 | } |
973 | 987 | ||
974 | static enum print_line_t trace_wake_raw(struct trace_iterator *iter, int flags) | 988 | static enum print_line_t trace_wake_raw(struct trace_iterator *iter, int flags, |
989 | struct trace_event *event) | ||
975 | { | 990 | { |
976 | return trace_ctxwake_raw(iter, '+'); | 991 | return trace_ctxwake_raw(iter, '+'); |
977 | } | 992 | } |
@@ -1000,18 +1015,20 @@ static int trace_ctxwake_hex(struct trace_iterator *iter, char S) | |||
1000 | return TRACE_TYPE_HANDLED; | 1015 | return TRACE_TYPE_HANDLED; |
1001 | } | 1016 | } |
1002 | 1017 | ||
1003 | static enum print_line_t trace_ctx_hex(struct trace_iterator *iter, int flags) | 1018 | static enum print_line_t trace_ctx_hex(struct trace_iterator *iter, int flags, |
1019 | struct trace_event *event) | ||
1004 | { | 1020 | { |
1005 | return trace_ctxwake_hex(iter, 0); | 1021 | return trace_ctxwake_hex(iter, 0); |
1006 | } | 1022 | } |
1007 | 1023 | ||
1008 | static enum print_line_t trace_wake_hex(struct trace_iterator *iter, int flags) | 1024 | static enum print_line_t trace_wake_hex(struct trace_iterator *iter, int flags, |
1025 | struct trace_event *event) | ||
1009 | { | 1026 | { |
1010 | return trace_ctxwake_hex(iter, '+'); | 1027 | return trace_ctxwake_hex(iter, '+'); |
1011 | } | 1028 | } |
1012 | 1029 | ||
1013 | static enum print_line_t trace_ctxwake_bin(struct trace_iterator *iter, | 1030 | static enum print_line_t trace_ctxwake_bin(struct trace_iterator *iter, |
1014 | int flags) | 1031 | int flags, struct trace_event *event) |
1015 | { | 1032 | { |
1016 | struct ctx_switch_entry *field; | 1033 | struct ctx_switch_entry *field; |
1017 | struct trace_seq *s = &iter->seq; | 1034 | struct trace_seq *s = &iter->seq; |
@@ -1028,25 +1045,33 @@ static enum print_line_t trace_ctxwake_bin(struct trace_iterator *iter, | |||
1028 | return TRACE_TYPE_HANDLED; | 1045 | return TRACE_TYPE_HANDLED; |
1029 | } | 1046 | } |
1030 | 1047 | ||
1031 | static struct trace_event trace_ctx_event = { | 1048 | static struct trace_event_functions trace_ctx_funcs = { |
1032 | .type = TRACE_CTX, | ||
1033 | .trace = trace_ctx_print, | 1049 | .trace = trace_ctx_print, |
1034 | .raw = trace_ctx_raw, | 1050 | .raw = trace_ctx_raw, |
1035 | .hex = trace_ctx_hex, | 1051 | .hex = trace_ctx_hex, |
1036 | .binary = trace_ctxwake_bin, | 1052 | .binary = trace_ctxwake_bin, |
1037 | }; | 1053 | }; |
1038 | 1054 | ||
1039 | static struct trace_event trace_wake_event = { | 1055 | static struct trace_event trace_ctx_event = { |
1040 | .type = TRACE_WAKE, | 1056 | .type = TRACE_CTX, |
1057 | .funcs = &trace_ctx_funcs, | ||
1058 | }; | ||
1059 | |||
1060 | static struct trace_event_functions trace_wake_funcs = { | ||
1041 | .trace = trace_wake_print, | 1061 | .trace = trace_wake_print, |
1042 | .raw = trace_wake_raw, | 1062 | .raw = trace_wake_raw, |
1043 | .hex = trace_wake_hex, | 1063 | .hex = trace_wake_hex, |
1044 | .binary = trace_ctxwake_bin, | 1064 | .binary = trace_ctxwake_bin, |
1045 | }; | 1065 | }; |
1046 | 1066 | ||
1067 | static struct trace_event trace_wake_event = { | ||
1068 | .type = TRACE_WAKE, | ||
1069 | .funcs = &trace_wake_funcs, | ||
1070 | }; | ||
1071 | |||
1047 | /* TRACE_SPECIAL */ | 1072 | /* TRACE_SPECIAL */ |
1048 | static enum print_line_t trace_special_print(struct trace_iterator *iter, | 1073 | static enum print_line_t trace_special_print(struct trace_iterator *iter, |
1049 | int flags) | 1074 | int flags, struct trace_event *event) |
1050 | { | 1075 | { |
1051 | struct special_entry *field; | 1076 | struct special_entry *field; |
1052 | 1077 | ||
@@ -1062,7 +1087,7 @@ static enum print_line_t trace_special_print(struct trace_iterator *iter, | |||
1062 | } | 1087 | } |
1063 | 1088 | ||
1064 | static enum print_line_t trace_special_hex(struct trace_iterator *iter, | 1089 | static enum print_line_t trace_special_hex(struct trace_iterator *iter, |
1065 | int flags) | 1090 | int flags, struct trace_event *event) |
1066 | { | 1091 | { |
1067 | struct special_entry *field; | 1092 | struct special_entry *field; |
1068 | struct trace_seq *s = &iter->seq; | 1093 | struct trace_seq *s = &iter->seq; |
@@ -1077,7 +1102,7 @@ static enum print_line_t trace_special_hex(struct trace_iterator *iter, | |||
1077 | } | 1102 | } |
1078 | 1103 | ||
1079 | static enum print_line_t trace_special_bin(struct trace_iterator *iter, | 1104 | static enum print_line_t trace_special_bin(struct trace_iterator *iter, |
1080 | int flags) | 1105 | int flags, struct trace_event *event) |
1081 | { | 1106 | { |
1082 | struct special_entry *field; | 1107 | struct special_entry *field; |
1083 | struct trace_seq *s = &iter->seq; | 1108 | struct trace_seq *s = &iter->seq; |
@@ -1091,18 +1116,22 @@ static enum print_line_t trace_special_bin(struct trace_iterator *iter, | |||
1091 | return TRACE_TYPE_HANDLED; | 1116 | return TRACE_TYPE_HANDLED; |
1092 | } | 1117 | } |
1093 | 1118 | ||
1094 | static struct trace_event trace_special_event = { | 1119 | static struct trace_event_functions trace_special_funcs = { |
1095 | .type = TRACE_SPECIAL, | ||
1096 | .trace = trace_special_print, | 1120 | .trace = trace_special_print, |
1097 | .raw = trace_special_print, | 1121 | .raw = trace_special_print, |
1098 | .hex = trace_special_hex, | 1122 | .hex = trace_special_hex, |
1099 | .binary = trace_special_bin, | 1123 | .binary = trace_special_bin, |
1100 | }; | 1124 | }; |
1101 | 1125 | ||
1126 | static struct trace_event trace_special_event = { | ||
1127 | .type = TRACE_SPECIAL, | ||
1128 | .funcs = &trace_special_funcs, | ||
1129 | }; | ||
1130 | |||
1102 | /* TRACE_STACK */ | 1131 | /* TRACE_STACK */ |
1103 | 1132 | ||
1104 | static enum print_line_t trace_stack_print(struct trace_iterator *iter, | 1133 | static enum print_line_t trace_stack_print(struct trace_iterator *iter, |
1105 | int flags) | 1134 | int flags, struct trace_event *event) |
1106 | { | 1135 | { |
1107 | struct stack_entry *field; | 1136 | struct stack_entry *field; |
1108 | struct trace_seq *s = &iter->seq; | 1137 | struct trace_seq *s = &iter->seq; |
@@ -1130,17 +1159,21 @@ static enum print_line_t trace_stack_print(struct trace_iterator *iter, | |||
1130 | return TRACE_TYPE_PARTIAL_LINE; | 1159 | return TRACE_TYPE_PARTIAL_LINE; |
1131 | } | 1160 | } |
1132 | 1161 | ||
1133 | static struct trace_event trace_stack_event = { | 1162 | static struct trace_event_functions trace_stack_funcs = { |
1134 | .type = TRACE_STACK, | ||
1135 | .trace = trace_stack_print, | 1163 | .trace = trace_stack_print, |
1136 | .raw = trace_special_print, | 1164 | .raw = trace_special_print, |
1137 | .hex = trace_special_hex, | 1165 | .hex = trace_special_hex, |
1138 | .binary = trace_special_bin, | 1166 | .binary = trace_special_bin, |
1139 | }; | 1167 | }; |
1140 | 1168 | ||
1169 | static struct trace_event trace_stack_event = { | ||
1170 | .type = TRACE_STACK, | ||
1171 | .funcs = &trace_stack_funcs, | ||
1172 | }; | ||
1173 | |||
1141 | /* TRACE_USER_STACK */ | 1174 | /* TRACE_USER_STACK */ |
1142 | static enum print_line_t trace_user_stack_print(struct trace_iterator *iter, | 1175 | static enum print_line_t trace_user_stack_print(struct trace_iterator *iter, |
1143 | int flags) | 1176 | int flags, struct trace_event *event) |
1144 | { | 1177 | { |
1145 | struct userstack_entry *field; | 1178 | struct userstack_entry *field; |
1146 | struct trace_seq *s = &iter->seq; | 1179 | struct trace_seq *s = &iter->seq; |
@@ -1159,17 +1192,22 @@ static enum print_line_t trace_user_stack_print(struct trace_iterator *iter, | |||
1159 | return TRACE_TYPE_PARTIAL_LINE; | 1192 | return TRACE_TYPE_PARTIAL_LINE; |
1160 | } | 1193 | } |
1161 | 1194 | ||
1162 | static struct trace_event trace_user_stack_event = { | 1195 | static struct trace_event_functions trace_user_stack_funcs = { |
1163 | .type = TRACE_USER_STACK, | ||
1164 | .trace = trace_user_stack_print, | 1196 | .trace = trace_user_stack_print, |
1165 | .raw = trace_special_print, | 1197 | .raw = trace_special_print, |
1166 | .hex = trace_special_hex, | 1198 | .hex = trace_special_hex, |
1167 | .binary = trace_special_bin, | 1199 | .binary = trace_special_bin, |
1168 | }; | 1200 | }; |
1169 | 1201 | ||
1202 | static struct trace_event trace_user_stack_event = { | ||
1203 | .type = TRACE_USER_STACK, | ||
1204 | .funcs = &trace_user_stack_funcs, | ||
1205 | }; | ||
1206 | |||
1170 | /* TRACE_BPRINT */ | 1207 | /* TRACE_BPRINT */ |
1171 | static enum print_line_t | 1208 | static enum print_line_t |
1172 | trace_bprint_print(struct trace_iterator *iter, int flags) | 1209 | trace_bprint_print(struct trace_iterator *iter, int flags, |
1210 | struct trace_event *event) | ||
1173 | { | 1211 | { |
1174 | struct trace_entry *entry = iter->ent; | 1212 | struct trace_entry *entry = iter->ent; |
1175 | struct trace_seq *s = &iter->seq; | 1213 | struct trace_seq *s = &iter->seq; |
@@ -1194,7 +1232,8 @@ trace_bprint_print(struct trace_iterator *iter, int flags) | |||
1194 | 1232 | ||
1195 | 1233 | ||
1196 | static enum print_line_t | 1234 | static enum print_line_t |
1197 | trace_bprint_raw(struct trace_iterator *iter, int flags) | 1235 | trace_bprint_raw(struct trace_iterator *iter, int flags, |
1236 | struct trace_event *event) | ||
1198 | { | 1237 | { |
1199 | struct bprint_entry *field; | 1238 | struct bprint_entry *field; |
1200 | struct trace_seq *s = &iter->seq; | 1239 | struct trace_seq *s = &iter->seq; |
@@ -1213,16 +1252,19 @@ trace_bprint_raw(struct trace_iterator *iter, int flags) | |||
1213 | return TRACE_TYPE_PARTIAL_LINE; | 1252 | return TRACE_TYPE_PARTIAL_LINE; |
1214 | } | 1253 | } |
1215 | 1254 | ||
1255 | static struct trace_event_functions trace_bprint_funcs = { | ||
1256 | .trace = trace_bprint_print, | ||
1257 | .raw = trace_bprint_raw, | ||
1258 | }; | ||
1216 | 1259 | ||
1217 | static struct trace_event trace_bprint_event = { | 1260 | static struct trace_event trace_bprint_event = { |
1218 | .type = TRACE_BPRINT, | 1261 | .type = TRACE_BPRINT, |
1219 | .trace = trace_bprint_print, | 1262 | .funcs = &trace_bprint_funcs, |
1220 | .raw = trace_bprint_raw, | ||
1221 | }; | 1263 | }; |
1222 | 1264 | ||
1223 | /* TRACE_PRINT */ | 1265 | /* TRACE_PRINT */ |
1224 | static enum print_line_t trace_print_print(struct trace_iterator *iter, | 1266 | static enum print_line_t trace_print_print(struct trace_iterator *iter, |
1225 | int flags) | 1267 | int flags, struct trace_event *event) |
1226 | { | 1268 | { |
1227 | struct print_entry *field; | 1269 | struct print_entry *field; |
1228 | struct trace_seq *s = &iter->seq; | 1270 | struct trace_seq *s = &iter->seq; |
@@ -1241,7 +1283,8 @@ static enum print_line_t trace_print_print(struct trace_iterator *iter, | |||
1241 | return TRACE_TYPE_PARTIAL_LINE; | 1283 | return TRACE_TYPE_PARTIAL_LINE; |
1242 | } | 1284 | } |
1243 | 1285 | ||
1244 | static enum print_line_t trace_print_raw(struct trace_iterator *iter, int flags) | 1286 | static enum print_line_t trace_print_raw(struct trace_iterator *iter, int flags, |
1287 | struct trace_event *event) | ||
1245 | { | 1288 | { |
1246 | struct print_entry *field; | 1289 | struct print_entry *field; |
1247 | 1290 | ||
@@ -1256,12 +1299,16 @@ static enum print_line_t trace_print_raw(struct trace_iterator *iter, int flags) | |||
1256 | return TRACE_TYPE_PARTIAL_LINE; | 1299 | return TRACE_TYPE_PARTIAL_LINE; |
1257 | } | 1300 | } |
1258 | 1301 | ||
1259 | static struct trace_event trace_print_event = { | 1302 | static struct trace_event_functions trace_print_funcs = { |
1260 | .type = TRACE_PRINT, | ||
1261 | .trace = trace_print_print, | 1303 | .trace = trace_print_print, |
1262 | .raw = trace_print_raw, | 1304 | .raw = trace_print_raw, |
1263 | }; | 1305 | }; |
1264 | 1306 | ||
1307 | static struct trace_event trace_print_event = { | ||
1308 | .type = TRACE_PRINT, | ||
1309 | .funcs = &trace_print_funcs, | ||
1310 | }; | ||
1311 | |||
1265 | 1312 | ||
1266 | static struct trace_event *events[] __initdata = { | 1313 | static struct trace_event *events[] __initdata = { |
1267 | &trace_fn_event, | 1314 | &trace_fn_event, |
diff --git a/kernel/trace/trace_output.h b/kernel/trace/trace_output.h index 9d91c72ba38b..c038eba0492b 100644 --- a/kernel/trace/trace_output.h +++ b/kernel/trace/trace_output.h | |||
@@ -25,7 +25,7 @@ extern void trace_event_read_unlock(void); | |||
25 | extern struct trace_event *ftrace_find_event(int type); | 25 | extern struct trace_event *ftrace_find_event(int type); |
26 | 26 | ||
27 | extern enum print_line_t trace_nop_print(struct trace_iterator *iter, | 27 | extern enum print_line_t trace_nop_print(struct trace_iterator *iter, |
28 | int flags); | 28 | int flags, struct trace_event *event); |
29 | extern int | 29 | extern int |
30 | trace_print_lat_fmt(struct trace_seq *s, struct trace_entry *entry); | 30 | trace_print_lat_fmt(struct trace_seq *s, struct trace_entry *entry); |
31 | 31 | ||
diff --git a/kernel/trace/trace_sched_switch.c b/kernel/trace/trace_sched_switch.c index a55fccfede5d..8f758d070c43 100644 --- a/kernel/trace/trace_sched_switch.c +++ b/kernel/trace/trace_sched_switch.c | |||
@@ -50,7 +50,7 @@ tracing_sched_switch_trace(struct trace_array *tr, | |||
50 | } | 50 | } |
51 | 51 | ||
52 | static void | 52 | static void |
53 | probe_sched_switch(struct task_struct *prev, struct task_struct *next) | 53 | probe_sched_switch(void *ignore, struct task_struct *prev, struct task_struct *next) |
54 | { | 54 | { |
55 | struct trace_array_cpu *data; | 55 | struct trace_array_cpu *data; |
56 | unsigned long flags; | 56 | unsigned long flags; |
@@ -108,7 +108,7 @@ tracing_sched_wakeup_trace(struct trace_array *tr, | |||
108 | } | 108 | } |
109 | 109 | ||
110 | static void | 110 | static void |
111 | probe_sched_wakeup(struct task_struct *wakee, int success) | 111 | probe_sched_wakeup(void *ignore, struct task_struct *wakee, int success) |
112 | { | 112 | { |
113 | struct trace_array_cpu *data; | 113 | struct trace_array_cpu *data; |
114 | unsigned long flags; | 114 | unsigned long flags; |
@@ -138,21 +138,21 @@ static int tracing_sched_register(void) | |||
138 | { | 138 | { |
139 | int ret; | 139 | int ret; |
140 | 140 | ||
141 | ret = register_trace_sched_wakeup(probe_sched_wakeup); | 141 | ret = register_trace_sched_wakeup(probe_sched_wakeup, NULL); |
142 | if (ret) { | 142 | if (ret) { |
143 | pr_info("wakeup trace: Couldn't activate tracepoint" | 143 | pr_info("wakeup trace: Couldn't activate tracepoint" |
144 | " probe to kernel_sched_wakeup\n"); | 144 | " probe to kernel_sched_wakeup\n"); |
145 | return ret; | 145 | return ret; |
146 | } | 146 | } |
147 | 147 | ||
148 | ret = register_trace_sched_wakeup_new(probe_sched_wakeup); | 148 | ret = register_trace_sched_wakeup_new(probe_sched_wakeup, NULL); |
149 | if (ret) { | 149 | if (ret) { |
150 | pr_info("wakeup trace: Couldn't activate tracepoint" | 150 | pr_info("wakeup trace: Couldn't activate tracepoint" |
151 | " probe to kernel_sched_wakeup_new\n"); | 151 | " probe to kernel_sched_wakeup_new\n"); |
152 | goto fail_deprobe; | 152 | goto fail_deprobe; |
153 | } | 153 | } |
154 | 154 | ||
155 | ret = register_trace_sched_switch(probe_sched_switch); | 155 | ret = register_trace_sched_switch(probe_sched_switch, NULL); |
156 | if (ret) { | 156 | if (ret) { |
157 | pr_info("sched trace: Couldn't activate tracepoint" | 157 | pr_info("sched trace: Couldn't activate tracepoint" |
158 | " probe to kernel_sched_switch\n"); | 158 | " probe to kernel_sched_switch\n"); |
@@ -161,17 +161,17 @@ static int tracing_sched_register(void) | |||
161 | 161 | ||
162 | return ret; | 162 | return ret; |
163 | fail_deprobe_wake_new: | 163 | fail_deprobe_wake_new: |
164 | unregister_trace_sched_wakeup_new(probe_sched_wakeup); | 164 | unregister_trace_sched_wakeup_new(probe_sched_wakeup, NULL); |
165 | fail_deprobe: | 165 | fail_deprobe: |
166 | unregister_trace_sched_wakeup(probe_sched_wakeup); | 166 | unregister_trace_sched_wakeup(probe_sched_wakeup, NULL); |
167 | return ret; | 167 | return ret; |
168 | } | 168 | } |
169 | 169 | ||
170 | static void tracing_sched_unregister(void) | 170 | static void tracing_sched_unregister(void) |
171 | { | 171 | { |
172 | unregister_trace_sched_switch(probe_sched_switch); | 172 | unregister_trace_sched_switch(probe_sched_switch, NULL); |
173 | unregister_trace_sched_wakeup_new(probe_sched_wakeup); | 173 | unregister_trace_sched_wakeup_new(probe_sched_wakeup, NULL); |
174 | unregister_trace_sched_wakeup(probe_sched_wakeup); | 174 | unregister_trace_sched_wakeup(probe_sched_wakeup, NULL); |
175 | } | 175 | } |
176 | 176 | ||
177 | static void tracing_start_sched_switch(void) | 177 | static void tracing_start_sched_switch(void) |
diff --git a/kernel/trace/trace_sched_wakeup.c b/kernel/trace/trace_sched_wakeup.c index 8052446ceeaa..0e73bc2ef8c5 100644 --- a/kernel/trace/trace_sched_wakeup.c +++ b/kernel/trace/trace_sched_wakeup.c | |||
@@ -98,7 +98,8 @@ static int report_latency(cycle_t delta) | |||
98 | return 1; | 98 | return 1; |
99 | } | 99 | } |
100 | 100 | ||
101 | static void probe_wakeup_migrate_task(struct task_struct *task, int cpu) | 101 | static void |
102 | probe_wakeup_migrate_task(void *ignore, struct task_struct *task, int cpu) | ||
102 | { | 103 | { |
103 | if (task != wakeup_task) | 104 | if (task != wakeup_task) |
104 | return; | 105 | return; |
@@ -107,7 +108,8 @@ static void probe_wakeup_migrate_task(struct task_struct *task, int cpu) | |||
107 | } | 108 | } |
108 | 109 | ||
109 | static void notrace | 110 | static void notrace |
110 | probe_wakeup_sched_switch(struct task_struct *prev, struct task_struct *next) | 111 | probe_wakeup_sched_switch(void *ignore, |
112 | struct task_struct *prev, struct task_struct *next) | ||
111 | { | 113 | { |
112 | struct trace_array_cpu *data; | 114 | struct trace_array_cpu *data; |
113 | cycle_t T0, T1, delta; | 115 | cycle_t T0, T1, delta; |
@@ -199,7 +201,7 @@ static void wakeup_reset(struct trace_array *tr) | |||
199 | } | 201 | } |
200 | 202 | ||
201 | static void | 203 | static void |
202 | probe_wakeup(struct task_struct *p, int success) | 204 | probe_wakeup(void *ignore, struct task_struct *p, int success) |
203 | { | 205 | { |
204 | struct trace_array_cpu *data; | 206 | struct trace_array_cpu *data; |
205 | int cpu = smp_processor_id(); | 207 | int cpu = smp_processor_id(); |
@@ -263,28 +265,28 @@ static void start_wakeup_tracer(struct trace_array *tr) | |||
263 | { | 265 | { |
264 | int ret; | 266 | int ret; |
265 | 267 | ||
266 | ret = register_trace_sched_wakeup(probe_wakeup); | 268 | ret = register_trace_sched_wakeup(probe_wakeup, NULL); |
267 | if (ret) { | 269 | if (ret) { |
268 | pr_info("wakeup trace: Couldn't activate tracepoint" | 270 | pr_info("wakeup trace: Couldn't activate tracepoint" |
269 | " probe to kernel_sched_wakeup\n"); | 271 | " probe to kernel_sched_wakeup\n"); |
270 | return; | 272 | return; |
271 | } | 273 | } |
272 | 274 | ||
273 | ret = register_trace_sched_wakeup_new(probe_wakeup); | 275 | ret = register_trace_sched_wakeup_new(probe_wakeup, NULL); |
274 | if (ret) { | 276 | if (ret) { |
275 | pr_info("wakeup trace: Couldn't activate tracepoint" | 277 | pr_info("wakeup trace: Couldn't activate tracepoint" |
276 | " probe to kernel_sched_wakeup_new\n"); | 278 | " probe to kernel_sched_wakeup_new\n"); |
277 | goto fail_deprobe; | 279 | goto fail_deprobe; |
278 | } | 280 | } |
279 | 281 | ||
280 | ret = register_trace_sched_switch(probe_wakeup_sched_switch); | 282 | ret = register_trace_sched_switch(probe_wakeup_sched_switch, NULL); |
281 | if (ret) { | 283 | if (ret) { |
282 | pr_info("sched trace: Couldn't activate tracepoint" | 284 | pr_info("sched trace: Couldn't activate tracepoint" |
283 | " probe to kernel_sched_switch\n"); | 285 | " probe to kernel_sched_switch\n"); |
284 | goto fail_deprobe_wake_new; | 286 | goto fail_deprobe_wake_new; |
285 | } | 287 | } |
286 | 288 | ||
287 | ret = register_trace_sched_migrate_task(probe_wakeup_migrate_task); | 289 | ret = register_trace_sched_migrate_task(probe_wakeup_migrate_task, NULL); |
288 | if (ret) { | 290 | if (ret) { |
289 | pr_info("wakeup trace: Couldn't activate tracepoint" | 291 | pr_info("wakeup trace: Couldn't activate tracepoint" |
290 | " probe to kernel_sched_migrate_task\n"); | 292 | " probe to kernel_sched_migrate_task\n"); |
@@ -311,19 +313,19 @@ static void start_wakeup_tracer(struct trace_array *tr) | |||
311 | 313 | ||
312 | return; | 314 | return; |
313 | fail_deprobe_wake_new: | 315 | fail_deprobe_wake_new: |
314 | unregister_trace_sched_wakeup_new(probe_wakeup); | 316 | unregister_trace_sched_wakeup_new(probe_wakeup, NULL); |
315 | fail_deprobe: | 317 | fail_deprobe: |
316 | unregister_trace_sched_wakeup(probe_wakeup); | 318 | unregister_trace_sched_wakeup(probe_wakeup, NULL); |
317 | } | 319 | } |
318 | 320 | ||
319 | static void stop_wakeup_tracer(struct trace_array *tr) | 321 | static void stop_wakeup_tracer(struct trace_array *tr) |
320 | { | 322 | { |
321 | tracer_enabled = 0; | 323 | tracer_enabled = 0; |
322 | unregister_ftrace_function(&trace_ops); | 324 | unregister_ftrace_function(&trace_ops); |
323 | unregister_trace_sched_switch(probe_wakeup_sched_switch); | 325 | unregister_trace_sched_switch(probe_wakeup_sched_switch, NULL); |
324 | unregister_trace_sched_wakeup_new(probe_wakeup); | 326 | unregister_trace_sched_wakeup_new(probe_wakeup, NULL); |
325 | unregister_trace_sched_wakeup(probe_wakeup); | 327 | unregister_trace_sched_wakeup(probe_wakeup, NULL); |
326 | unregister_trace_sched_migrate_task(probe_wakeup_migrate_task); | 328 | unregister_trace_sched_migrate_task(probe_wakeup_migrate_task, NULL); |
327 | } | 329 | } |
328 | 330 | ||
329 | static int __wakeup_tracer_init(struct trace_array *tr) | 331 | static int __wakeup_tracer_init(struct trace_array *tr) |
diff --git a/kernel/trace/trace_syscalls.c b/kernel/trace/trace_syscalls.c index 4d6d711717f2..d2c859cec9ea 100644 --- a/kernel/trace/trace_syscalls.c +++ b/kernel/trace/trace_syscalls.c | |||
@@ -15,6 +15,54 @@ static int sys_refcount_exit; | |||
15 | static DECLARE_BITMAP(enabled_enter_syscalls, NR_syscalls); | 15 | static DECLARE_BITMAP(enabled_enter_syscalls, NR_syscalls); |
16 | static DECLARE_BITMAP(enabled_exit_syscalls, NR_syscalls); | 16 | static DECLARE_BITMAP(enabled_exit_syscalls, NR_syscalls); |
17 | 17 | ||
18 | static int syscall_enter_register(struct ftrace_event_call *event, | ||
19 | enum trace_reg type); | ||
20 | static int syscall_exit_register(struct ftrace_event_call *event, | ||
21 | enum trace_reg type); | ||
22 | |||
23 | static int syscall_enter_define_fields(struct ftrace_event_call *call); | ||
24 | static int syscall_exit_define_fields(struct ftrace_event_call *call); | ||
25 | |||
26 | static struct list_head * | ||
27 | syscall_get_enter_fields(struct ftrace_event_call *call) | ||
28 | { | ||
29 | struct syscall_metadata *entry = call->data; | ||
30 | |||
31 | return &entry->enter_fields; | ||
32 | } | ||
33 | |||
34 | static struct list_head * | ||
35 | syscall_get_exit_fields(struct ftrace_event_call *call) | ||
36 | { | ||
37 | struct syscall_metadata *entry = call->data; | ||
38 | |||
39 | return &entry->exit_fields; | ||
40 | } | ||
41 | |||
42 | struct trace_event_functions enter_syscall_print_funcs = { | ||
43 | .trace = print_syscall_enter, | ||
44 | }; | ||
45 | |||
46 | struct trace_event_functions exit_syscall_print_funcs = { | ||
47 | .trace = print_syscall_exit, | ||
48 | }; | ||
49 | |||
50 | struct ftrace_event_class event_class_syscall_enter = { | ||
51 | .system = "syscalls", | ||
52 | .reg = syscall_enter_register, | ||
53 | .define_fields = syscall_enter_define_fields, | ||
54 | .get_fields = syscall_get_enter_fields, | ||
55 | .raw_init = init_syscall_trace, | ||
56 | }; | ||
57 | |||
58 | struct ftrace_event_class event_class_syscall_exit = { | ||
59 | .system = "syscalls", | ||
60 | .reg = syscall_exit_register, | ||
61 | .define_fields = syscall_exit_define_fields, | ||
62 | .get_fields = syscall_get_exit_fields, | ||
63 | .raw_init = init_syscall_trace, | ||
64 | }; | ||
65 | |||
18 | extern unsigned long __start_syscalls_metadata[]; | 66 | extern unsigned long __start_syscalls_metadata[]; |
19 | extern unsigned long __stop_syscalls_metadata[]; | 67 | extern unsigned long __stop_syscalls_metadata[]; |
20 | 68 | ||
@@ -53,7 +101,8 @@ static struct syscall_metadata *syscall_nr_to_meta(int nr) | |||
53 | } | 101 | } |
54 | 102 | ||
55 | enum print_line_t | 103 | enum print_line_t |
56 | print_syscall_enter(struct trace_iterator *iter, int flags) | 104 | print_syscall_enter(struct trace_iterator *iter, int flags, |
105 | struct trace_event *event) | ||
57 | { | 106 | { |
58 | struct trace_seq *s = &iter->seq; | 107 | struct trace_seq *s = &iter->seq; |
59 | struct trace_entry *ent = iter->ent; | 108 | struct trace_entry *ent = iter->ent; |
@@ -68,7 +117,7 @@ print_syscall_enter(struct trace_iterator *iter, int flags) | |||
68 | if (!entry) | 117 | if (!entry) |
69 | goto end; | 118 | goto end; |
70 | 119 | ||
71 | if (entry->enter_event->id != ent->type) { | 120 | if (entry->enter_event->event.type != ent->type) { |
72 | WARN_ON_ONCE(1); | 121 | WARN_ON_ONCE(1); |
73 | goto end; | 122 | goto end; |
74 | } | 123 | } |
@@ -105,7 +154,8 @@ end: | |||
105 | } | 154 | } |
106 | 155 | ||
107 | enum print_line_t | 156 | enum print_line_t |
108 | print_syscall_exit(struct trace_iterator *iter, int flags) | 157 | print_syscall_exit(struct trace_iterator *iter, int flags, |
158 | struct trace_event *event) | ||
109 | { | 159 | { |
110 | struct trace_seq *s = &iter->seq; | 160 | struct trace_seq *s = &iter->seq; |
111 | struct trace_entry *ent = iter->ent; | 161 | struct trace_entry *ent = iter->ent; |
@@ -123,7 +173,7 @@ print_syscall_exit(struct trace_iterator *iter, int flags) | |||
123 | return TRACE_TYPE_HANDLED; | 173 | return TRACE_TYPE_HANDLED; |
124 | } | 174 | } |
125 | 175 | ||
126 | if (entry->exit_event->id != ent->type) { | 176 | if (entry->exit_event->event.type != ent->type) { |
127 | WARN_ON_ONCE(1); | 177 | WARN_ON_ONCE(1); |
128 | return TRACE_TYPE_UNHANDLED; | 178 | return TRACE_TYPE_UNHANDLED; |
129 | } | 179 | } |
@@ -205,7 +255,7 @@ static void free_syscall_print_fmt(struct ftrace_event_call *call) | |||
205 | kfree(call->print_fmt); | 255 | kfree(call->print_fmt); |
206 | } | 256 | } |
207 | 257 | ||
208 | int syscall_enter_define_fields(struct ftrace_event_call *call) | 258 | static int syscall_enter_define_fields(struct ftrace_event_call *call) |
209 | { | 259 | { |
210 | struct syscall_trace_enter trace; | 260 | struct syscall_trace_enter trace; |
211 | struct syscall_metadata *meta = call->data; | 261 | struct syscall_metadata *meta = call->data; |
@@ -228,7 +278,7 @@ int syscall_enter_define_fields(struct ftrace_event_call *call) | |||
228 | return ret; | 278 | return ret; |
229 | } | 279 | } |
230 | 280 | ||
231 | int syscall_exit_define_fields(struct ftrace_event_call *call) | 281 | static int syscall_exit_define_fields(struct ftrace_event_call *call) |
232 | { | 282 | { |
233 | struct syscall_trace_exit trace; | 283 | struct syscall_trace_exit trace; |
234 | int ret; | 284 | int ret; |
@@ -243,7 +293,7 @@ int syscall_exit_define_fields(struct ftrace_event_call *call) | |||
243 | return ret; | 293 | return ret; |
244 | } | 294 | } |
245 | 295 | ||
246 | void ftrace_syscall_enter(struct pt_regs *regs, long id) | 296 | void ftrace_syscall_enter(void *ignore, struct pt_regs *regs, long id) |
247 | { | 297 | { |
248 | struct syscall_trace_enter *entry; | 298 | struct syscall_trace_enter *entry; |
249 | struct syscall_metadata *sys_data; | 299 | struct syscall_metadata *sys_data; |
@@ -265,7 +315,7 @@ void ftrace_syscall_enter(struct pt_regs *regs, long id) | |||
265 | size = sizeof(*entry) + sizeof(unsigned long) * sys_data->nb_args; | 315 | size = sizeof(*entry) + sizeof(unsigned long) * sys_data->nb_args; |
266 | 316 | ||
267 | event = trace_current_buffer_lock_reserve(&buffer, | 317 | event = trace_current_buffer_lock_reserve(&buffer, |
268 | sys_data->enter_event->id, size, 0, 0); | 318 | sys_data->enter_event->event.type, size, 0, 0); |
269 | if (!event) | 319 | if (!event) |
270 | return; | 320 | return; |
271 | 321 | ||
@@ -278,7 +328,7 @@ void ftrace_syscall_enter(struct pt_regs *regs, long id) | |||
278 | trace_current_buffer_unlock_commit(buffer, event, 0, 0); | 328 | trace_current_buffer_unlock_commit(buffer, event, 0, 0); |
279 | } | 329 | } |
280 | 330 | ||
281 | void ftrace_syscall_exit(struct pt_regs *regs, long ret) | 331 | void ftrace_syscall_exit(void *ignore, struct pt_regs *regs, long ret) |
282 | { | 332 | { |
283 | struct syscall_trace_exit *entry; | 333 | struct syscall_trace_exit *entry; |
284 | struct syscall_metadata *sys_data; | 334 | struct syscall_metadata *sys_data; |
@@ -297,7 +347,7 @@ void ftrace_syscall_exit(struct pt_regs *regs, long ret) | |||
297 | return; | 347 | return; |
298 | 348 | ||
299 | event = trace_current_buffer_lock_reserve(&buffer, | 349 | event = trace_current_buffer_lock_reserve(&buffer, |
300 | sys_data->exit_event->id, sizeof(*entry), 0, 0); | 350 | sys_data->exit_event->event.type, sizeof(*entry), 0, 0); |
301 | if (!event) | 351 | if (!event) |
302 | return; | 352 | return; |
303 | 353 | ||
@@ -320,7 +370,7 @@ int reg_event_syscall_enter(struct ftrace_event_call *call) | |||
320 | return -ENOSYS; | 370 | return -ENOSYS; |
321 | mutex_lock(&syscall_trace_lock); | 371 | mutex_lock(&syscall_trace_lock); |
322 | if (!sys_refcount_enter) | 372 | if (!sys_refcount_enter) |
323 | ret = register_trace_sys_enter(ftrace_syscall_enter); | 373 | ret = register_trace_sys_enter(ftrace_syscall_enter, NULL); |
324 | if (!ret) { | 374 | if (!ret) { |
325 | set_bit(num, enabled_enter_syscalls); | 375 | set_bit(num, enabled_enter_syscalls); |
326 | sys_refcount_enter++; | 376 | sys_refcount_enter++; |
@@ -340,7 +390,7 @@ void unreg_event_syscall_enter(struct ftrace_event_call *call) | |||
340 | sys_refcount_enter--; | 390 | sys_refcount_enter--; |
341 | clear_bit(num, enabled_enter_syscalls); | 391 | clear_bit(num, enabled_enter_syscalls); |
342 | if (!sys_refcount_enter) | 392 | if (!sys_refcount_enter) |
343 | unregister_trace_sys_enter(ftrace_syscall_enter); | 393 | unregister_trace_sys_enter(ftrace_syscall_enter, NULL); |
344 | mutex_unlock(&syscall_trace_lock); | 394 | mutex_unlock(&syscall_trace_lock); |
345 | } | 395 | } |
346 | 396 | ||
@@ -354,7 +404,7 @@ int reg_event_syscall_exit(struct ftrace_event_call *call) | |||
354 | return -ENOSYS; | 404 | return -ENOSYS; |
355 | mutex_lock(&syscall_trace_lock); | 405 | mutex_lock(&syscall_trace_lock); |
356 | if (!sys_refcount_exit) | 406 | if (!sys_refcount_exit) |
357 | ret = register_trace_sys_exit(ftrace_syscall_exit); | 407 | ret = register_trace_sys_exit(ftrace_syscall_exit, NULL); |
358 | if (!ret) { | 408 | if (!ret) { |
359 | set_bit(num, enabled_exit_syscalls); | 409 | set_bit(num, enabled_exit_syscalls); |
360 | sys_refcount_exit++; | 410 | sys_refcount_exit++; |
@@ -374,7 +424,7 @@ void unreg_event_syscall_exit(struct ftrace_event_call *call) | |||
374 | sys_refcount_exit--; | 424 | sys_refcount_exit--; |
375 | clear_bit(num, enabled_exit_syscalls); | 425 | clear_bit(num, enabled_exit_syscalls); |
376 | if (!sys_refcount_exit) | 426 | if (!sys_refcount_exit) |
377 | unregister_trace_sys_exit(ftrace_syscall_exit); | 427 | unregister_trace_sys_exit(ftrace_syscall_exit, NULL); |
378 | mutex_unlock(&syscall_trace_lock); | 428 | mutex_unlock(&syscall_trace_lock); |
379 | } | 429 | } |
380 | 430 | ||
@@ -434,11 +484,11 @@ static DECLARE_BITMAP(enabled_perf_exit_syscalls, NR_syscalls); | |||
434 | static int sys_perf_refcount_enter; | 484 | static int sys_perf_refcount_enter; |
435 | static int sys_perf_refcount_exit; | 485 | static int sys_perf_refcount_exit; |
436 | 486 | ||
437 | static void perf_syscall_enter(struct pt_regs *regs, long id) | 487 | static void perf_syscall_enter(void *ignore, struct pt_regs *regs, long id) |
438 | { | 488 | { |
439 | struct syscall_metadata *sys_data; | 489 | struct syscall_metadata *sys_data; |
440 | struct syscall_trace_enter *rec; | 490 | struct syscall_trace_enter *rec; |
441 | unsigned long flags; | 491 | struct hlist_head *head; |
442 | int syscall_nr; | 492 | int syscall_nr; |
443 | int rctx; | 493 | int rctx; |
444 | int size; | 494 | int size; |
@@ -461,14 +511,16 @@ static void perf_syscall_enter(struct pt_regs *regs, long id) | |||
461 | return; | 511 | return; |
462 | 512 | ||
463 | rec = (struct syscall_trace_enter *)perf_trace_buf_prepare(size, | 513 | rec = (struct syscall_trace_enter *)perf_trace_buf_prepare(size, |
464 | sys_data->enter_event->id, &rctx, &flags); | 514 | sys_data->enter_event->event.type, regs, &rctx); |
465 | if (!rec) | 515 | if (!rec) |
466 | return; | 516 | return; |
467 | 517 | ||
468 | rec->nr = syscall_nr; | 518 | rec->nr = syscall_nr; |
469 | syscall_get_arguments(current, regs, 0, sys_data->nb_args, | 519 | syscall_get_arguments(current, regs, 0, sys_data->nb_args, |
470 | (unsigned long *)&rec->args); | 520 | (unsigned long *)&rec->args); |
471 | perf_trace_buf_submit(rec, size, rctx, 0, 1, flags, regs); | 521 | |
522 | head = per_cpu_ptr(sys_data->enter_event->perf_events, smp_processor_id()); | ||
523 | perf_trace_buf_submit(rec, size, rctx, 0, 1, regs, head); | ||
472 | } | 524 | } |
473 | 525 | ||
474 | int perf_sysenter_enable(struct ftrace_event_call *call) | 526 | int perf_sysenter_enable(struct ftrace_event_call *call) |
@@ -480,7 +532,7 @@ int perf_sysenter_enable(struct ftrace_event_call *call) | |||
480 | 532 | ||
481 | mutex_lock(&syscall_trace_lock); | 533 | mutex_lock(&syscall_trace_lock); |
482 | if (!sys_perf_refcount_enter) | 534 | if (!sys_perf_refcount_enter) |
483 | ret = register_trace_sys_enter(perf_syscall_enter); | 535 | ret = register_trace_sys_enter(perf_syscall_enter, NULL); |
484 | if (ret) { | 536 | if (ret) { |
485 | pr_info("event trace: Could not activate" | 537 | pr_info("event trace: Could not activate" |
486 | "syscall entry trace point"); | 538 | "syscall entry trace point"); |
@@ -502,15 +554,15 @@ void perf_sysenter_disable(struct ftrace_event_call *call) | |||
502 | sys_perf_refcount_enter--; | 554 | sys_perf_refcount_enter--; |
503 | clear_bit(num, enabled_perf_enter_syscalls); | 555 | clear_bit(num, enabled_perf_enter_syscalls); |
504 | if (!sys_perf_refcount_enter) | 556 | if (!sys_perf_refcount_enter) |
505 | unregister_trace_sys_enter(perf_syscall_enter); | 557 | unregister_trace_sys_enter(perf_syscall_enter, NULL); |
506 | mutex_unlock(&syscall_trace_lock); | 558 | mutex_unlock(&syscall_trace_lock); |
507 | } | 559 | } |
508 | 560 | ||
509 | static void perf_syscall_exit(struct pt_regs *regs, long ret) | 561 | static void perf_syscall_exit(void *ignore, struct pt_regs *regs, long ret) |
510 | { | 562 | { |
511 | struct syscall_metadata *sys_data; | 563 | struct syscall_metadata *sys_data; |
512 | struct syscall_trace_exit *rec; | 564 | struct syscall_trace_exit *rec; |
513 | unsigned long flags; | 565 | struct hlist_head *head; |
514 | int syscall_nr; | 566 | int syscall_nr; |
515 | int rctx; | 567 | int rctx; |
516 | int size; | 568 | int size; |
@@ -536,14 +588,15 @@ static void perf_syscall_exit(struct pt_regs *regs, long ret) | |||
536 | return; | 588 | return; |
537 | 589 | ||
538 | rec = (struct syscall_trace_exit *)perf_trace_buf_prepare(size, | 590 | rec = (struct syscall_trace_exit *)perf_trace_buf_prepare(size, |
539 | sys_data->exit_event->id, &rctx, &flags); | 591 | sys_data->exit_event->event.type, regs, &rctx); |
540 | if (!rec) | 592 | if (!rec) |
541 | return; | 593 | return; |
542 | 594 | ||
543 | rec->nr = syscall_nr; | 595 | rec->nr = syscall_nr; |
544 | rec->ret = syscall_get_return_value(current, regs); | 596 | rec->ret = syscall_get_return_value(current, regs); |
545 | 597 | ||
546 | perf_trace_buf_submit(rec, size, rctx, 0, 1, flags, regs); | 598 | head = per_cpu_ptr(sys_data->exit_event->perf_events, smp_processor_id()); |
599 | perf_trace_buf_submit(rec, size, rctx, 0, 1, regs, head); | ||
547 | } | 600 | } |
548 | 601 | ||
549 | int perf_sysexit_enable(struct ftrace_event_call *call) | 602 | int perf_sysexit_enable(struct ftrace_event_call *call) |
@@ -555,7 +608,7 @@ int perf_sysexit_enable(struct ftrace_event_call *call) | |||
555 | 608 | ||
556 | mutex_lock(&syscall_trace_lock); | 609 | mutex_lock(&syscall_trace_lock); |
557 | if (!sys_perf_refcount_exit) | 610 | if (!sys_perf_refcount_exit) |
558 | ret = register_trace_sys_exit(perf_syscall_exit); | 611 | ret = register_trace_sys_exit(perf_syscall_exit, NULL); |
559 | if (ret) { | 612 | if (ret) { |
560 | pr_info("event trace: Could not activate" | 613 | pr_info("event trace: Could not activate" |
561 | "syscall exit trace point"); | 614 | "syscall exit trace point"); |
@@ -577,9 +630,50 @@ void perf_sysexit_disable(struct ftrace_event_call *call) | |||
577 | sys_perf_refcount_exit--; | 630 | sys_perf_refcount_exit--; |
578 | clear_bit(num, enabled_perf_exit_syscalls); | 631 | clear_bit(num, enabled_perf_exit_syscalls); |
579 | if (!sys_perf_refcount_exit) | 632 | if (!sys_perf_refcount_exit) |
580 | unregister_trace_sys_exit(perf_syscall_exit); | 633 | unregister_trace_sys_exit(perf_syscall_exit, NULL); |
581 | mutex_unlock(&syscall_trace_lock); | 634 | mutex_unlock(&syscall_trace_lock); |
582 | } | 635 | } |
583 | 636 | ||
584 | #endif /* CONFIG_PERF_EVENTS */ | 637 | #endif /* CONFIG_PERF_EVENTS */ |
585 | 638 | ||
639 | static int syscall_enter_register(struct ftrace_event_call *event, | ||
640 | enum trace_reg type) | ||
641 | { | ||
642 | switch (type) { | ||
643 | case TRACE_REG_REGISTER: | ||
644 | return reg_event_syscall_enter(event); | ||
645 | case TRACE_REG_UNREGISTER: | ||
646 | unreg_event_syscall_enter(event); | ||
647 | return 0; | ||
648 | |||
649 | #ifdef CONFIG_PERF_EVENTS | ||
650 | case TRACE_REG_PERF_REGISTER: | ||
651 | return perf_sysenter_enable(event); | ||
652 | case TRACE_REG_PERF_UNREGISTER: | ||
653 | perf_sysenter_disable(event); | ||
654 | return 0; | ||
655 | #endif | ||
656 | } | ||
657 | return 0; | ||
658 | } | ||
659 | |||
660 | static int syscall_exit_register(struct ftrace_event_call *event, | ||
661 | enum trace_reg type) | ||
662 | { | ||
663 | switch (type) { | ||
664 | case TRACE_REG_REGISTER: | ||
665 | return reg_event_syscall_exit(event); | ||
666 | case TRACE_REG_UNREGISTER: | ||
667 | unreg_event_syscall_exit(event); | ||
668 | return 0; | ||
669 | |||
670 | #ifdef CONFIG_PERF_EVENTS | ||
671 | case TRACE_REG_PERF_REGISTER: | ||
672 | return perf_sysexit_enable(event); | ||
673 | case TRACE_REG_PERF_UNREGISTER: | ||
674 | perf_sysexit_disable(event); | ||
675 | return 0; | ||
676 | #endif | ||
677 | } | ||
678 | return 0; | ||
679 | } | ||
diff --git a/kernel/trace/trace_workqueue.c b/kernel/trace/trace_workqueue.c index cc2d2faa7d9e..a7cc3793baf6 100644 --- a/kernel/trace/trace_workqueue.c +++ b/kernel/trace/trace_workqueue.c | |||
@@ -49,7 +49,8 @@ static void cpu_workqueue_stat_free(struct kref *kref) | |||
49 | 49 | ||
50 | /* Insertion of a work */ | 50 | /* Insertion of a work */ |
51 | static void | 51 | static void |
52 | probe_workqueue_insertion(struct task_struct *wq_thread, | 52 | probe_workqueue_insertion(void *ignore, |
53 | struct task_struct *wq_thread, | ||
53 | struct work_struct *work) | 54 | struct work_struct *work) |
54 | { | 55 | { |
55 | int cpu = cpumask_first(&wq_thread->cpus_allowed); | 56 | int cpu = cpumask_first(&wq_thread->cpus_allowed); |
@@ -70,7 +71,8 @@ found: | |||
70 | 71 | ||
71 | /* Execution of a work */ | 72 | /* Execution of a work */ |
72 | static void | 73 | static void |
73 | probe_workqueue_execution(struct task_struct *wq_thread, | 74 | probe_workqueue_execution(void *ignore, |
75 | struct task_struct *wq_thread, | ||
74 | struct work_struct *work) | 76 | struct work_struct *work) |
75 | { | 77 | { |
76 | int cpu = cpumask_first(&wq_thread->cpus_allowed); | 78 | int cpu = cpumask_first(&wq_thread->cpus_allowed); |
@@ -90,7 +92,8 @@ found: | |||
90 | } | 92 | } |
91 | 93 | ||
92 | /* Creation of a cpu workqueue thread */ | 94 | /* Creation of a cpu workqueue thread */ |
93 | static void probe_workqueue_creation(struct task_struct *wq_thread, int cpu) | 95 | static void probe_workqueue_creation(void *ignore, |
96 | struct task_struct *wq_thread, int cpu) | ||
94 | { | 97 | { |
95 | struct cpu_workqueue_stats *cws; | 98 | struct cpu_workqueue_stats *cws; |
96 | unsigned long flags; | 99 | unsigned long flags; |
@@ -114,7 +117,8 @@ static void probe_workqueue_creation(struct task_struct *wq_thread, int cpu) | |||
114 | } | 117 | } |
115 | 118 | ||
116 | /* Destruction of a cpu workqueue thread */ | 119 | /* Destruction of a cpu workqueue thread */ |
117 | static void probe_workqueue_destruction(struct task_struct *wq_thread) | 120 | static void |
121 | probe_workqueue_destruction(void *ignore, struct task_struct *wq_thread) | ||
118 | { | 122 | { |
119 | /* Workqueue only execute on one cpu */ | 123 | /* Workqueue only execute on one cpu */ |
120 | int cpu = cpumask_first(&wq_thread->cpus_allowed); | 124 | int cpu = cpumask_first(&wq_thread->cpus_allowed); |
@@ -259,19 +263,19 @@ int __init trace_workqueue_early_init(void) | |||
259 | { | 263 | { |
260 | int ret, cpu; | 264 | int ret, cpu; |
261 | 265 | ||
262 | ret = register_trace_workqueue_insertion(probe_workqueue_insertion); | 266 | ret = register_trace_workqueue_insertion(probe_workqueue_insertion, NULL); |
263 | if (ret) | 267 | if (ret) |
264 | goto out; | 268 | goto out; |
265 | 269 | ||
266 | ret = register_trace_workqueue_execution(probe_workqueue_execution); | 270 | ret = register_trace_workqueue_execution(probe_workqueue_execution, NULL); |
267 | if (ret) | 271 | if (ret) |
268 | goto no_insertion; | 272 | goto no_insertion; |
269 | 273 | ||
270 | ret = register_trace_workqueue_creation(probe_workqueue_creation); | 274 | ret = register_trace_workqueue_creation(probe_workqueue_creation, NULL); |
271 | if (ret) | 275 | if (ret) |
272 | goto no_execution; | 276 | goto no_execution; |
273 | 277 | ||
274 | ret = register_trace_workqueue_destruction(probe_workqueue_destruction); | 278 | ret = register_trace_workqueue_destruction(probe_workqueue_destruction, NULL); |
275 | if (ret) | 279 | if (ret) |
276 | goto no_creation; | 280 | goto no_creation; |
277 | 281 | ||
@@ -283,11 +287,11 @@ int __init trace_workqueue_early_init(void) | |||
283 | return 0; | 287 | return 0; |
284 | 288 | ||
285 | no_creation: | 289 | no_creation: |
286 | unregister_trace_workqueue_creation(probe_workqueue_creation); | 290 | unregister_trace_workqueue_creation(probe_workqueue_creation, NULL); |
287 | no_execution: | 291 | no_execution: |
288 | unregister_trace_workqueue_execution(probe_workqueue_execution); | 292 | unregister_trace_workqueue_execution(probe_workqueue_execution, NULL); |
289 | no_insertion: | 293 | no_insertion: |
290 | unregister_trace_workqueue_insertion(probe_workqueue_insertion); | 294 | unregister_trace_workqueue_insertion(probe_workqueue_insertion, NULL); |
291 | out: | 295 | out: |
292 | pr_warning("trace_workqueue: unable to trace workqueues\n"); | 296 | pr_warning("trace_workqueue: unable to trace workqueues\n"); |
293 | 297 | ||
diff --git a/kernel/tracepoint.c b/kernel/tracepoint.c index cc89be5bc0f8..c77f3eceea25 100644 --- a/kernel/tracepoint.c +++ b/kernel/tracepoint.c | |||
@@ -54,7 +54,7 @@ static struct hlist_head tracepoint_table[TRACEPOINT_TABLE_SIZE]; | |||
54 | */ | 54 | */ |
55 | struct tracepoint_entry { | 55 | struct tracepoint_entry { |
56 | struct hlist_node hlist; | 56 | struct hlist_node hlist; |
57 | void **funcs; | 57 | struct tracepoint_func *funcs; |
58 | int refcount; /* Number of times armed. 0 if disarmed. */ | 58 | int refcount; /* Number of times armed. 0 if disarmed. */ |
59 | char name[0]; | 59 | char name[0]; |
60 | }; | 60 | }; |
@@ -64,12 +64,12 @@ struct tp_probes { | |||
64 | struct rcu_head rcu; | 64 | struct rcu_head rcu; |
65 | struct list_head list; | 65 | struct list_head list; |
66 | } u; | 66 | } u; |
67 | void *probes[0]; | 67 | struct tracepoint_func probes[0]; |
68 | }; | 68 | }; |
69 | 69 | ||
70 | static inline void *allocate_probes(int count) | 70 | static inline void *allocate_probes(int count) |
71 | { | 71 | { |
72 | struct tp_probes *p = kmalloc(count * sizeof(void *) | 72 | struct tp_probes *p = kmalloc(count * sizeof(struct tracepoint_func) |
73 | + sizeof(struct tp_probes), GFP_KERNEL); | 73 | + sizeof(struct tp_probes), GFP_KERNEL); |
74 | return p == NULL ? NULL : p->probes; | 74 | return p == NULL ? NULL : p->probes; |
75 | } | 75 | } |
@@ -79,7 +79,7 @@ static void rcu_free_old_probes(struct rcu_head *head) | |||
79 | kfree(container_of(head, struct tp_probes, u.rcu)); | 79 | kfree(container_of(head, struct tp_probes, u.rcu)); |
80 | } | 80 | } |
81 | 81 | ||
82 | static inline void release_probes(void *old) | 82 | static inline void release_probes(struct tracepoint_func *old) |
83 | { | 83 | { |
84 | if (old) { | 84 | if (old) { |
85 | struct tp_probes *tp_probes = container_of(old, | 85 | struct tp_probes *tp_probes = container_of(old, |
@@ -95,15 +95,16 @@ static void debug_print_probes(struct tracepoint_entry *entry) | |||
95 | if (!tracepoint_debug || !entry->funcs) | 95 | if (!tracepoint_debug || !entry->funcs) |
96 | return; | 96 | return; |
97 | 97 | ||
98 | for (i = 0; entry->funcs[i]; i++) | 98 | for (i = 0; entry->funcs[i].func; i++) |
99 | printk(KERN_DEBUG "Probe %d : %p\n", i, entry->funcs[i]); | 99 | printk(KERN_DEBUG "Probe %d : %p\n", i, entry->funcs[i].func); |
100 | } | 100 | } |
101 | 101 | ||
102 | static void * | 102 | static struct tracepoint_func * |
103 | tracepoint_entry_add_probe(struct tracepoint_entry *entry, void *probe) | 103 | tracepoint_entry_add_probe(struct tracepoint_entry *entry, |
104 | void *probe, void *data) | ||
104 | { | 105 | { |
105 | int nr_probes = 0; | 106 | int nr_probes = 0; |
106 | void **old, **new; | 107 | struct tracepoint_func *old, *new; |
107 | 108 | ||
108 | WARN_ON(!probe); | 109 | WARN_ON(!probe); |
109 | 110 | ||
@@ -111,8 +112,9 @@ tracepoint_entry_add_probe(struct tracepoint_entry *entry, void *probe) | |||
111 | old = entry->funcs; | 112 | old = entry->funcs; |
112 | if (old) { | 113 | if (old) { |
113 | /* (N -> N+1), (N != 0, 1) probes */ | 114 | /* (N -> N+1), (N != 0, 1) probes */ |
114 | for (nr_probes = 0; old[nr_probes]; nr_probes++) | 115 | for (nr_probes = 0; old[nr_probes].func; nr_probes++) |
115 | if (old[nr_probes] == probe) | 116 | if (old[nr_probes].func == probe && |
117 | old[nr_probes].data == data) | ||
116 | return ERR_PTR(-EEXIST); | 118 | return ERR_PTR(-EEXIST); |
117 | } | 119 | } |
118 | /* + 2 : one for new probe, one for NULL func */ | 120 | /* + 2 : one for new probe, one for NULL func */ |
@@ -120,9 +122,10 @@ tracepoint_entry_add_probe(struct tracepoint_entry *entry, void *probe) | |||
120 | if (new == NULL) | 122 | if (new == NULL) |
121 | return ERR_PTR(-ENOMEM); | 123 | return ERR_PTR(-ENOMEM); |
122 | if (old) | 124 | if (old) |
123 | memcpy(new, old, nr_probes * sizeof(void *)); | 125 | memcpy(new, old, nr_probes * sizeof(struct tracepoint_func)); |
124 | new[nr_probes] = probe; | 126 | new[nr_probes].func = probe; |
125 | new[nr_probes + 1] = NULL; | 127 | new[nr_probes].data = data; |
128 | new[nr_probes + 1].func = NULL; | ||
126 | entry->refcount = nr_probes + 1; | 129 | entry->refcount = nr_probes + 1; |
127 | entry->funcs = new; | 130 | entry->funcs = new; |
128 | debug_print_probes(entry); | 131 | debug_print_probes(entry); |
@@ -130,10 +133,11 @@ tracepoint_entry_add_probe(struct tracepoint_entry *entry, void *probe) | |||
130 | } | 133 | } |
131 | 134 | ||
132 | static void * | 135 | static void * |
133 | tracepoint_entry_remove_probe(struct tracepoint_entry *entry, void *probe) | 136 | tracepoint_entry_remove_probe(struct tracepoint_entry *entry, |
137 | void *probe, void *data) | ||
134 | { | 138 | { |
135 | int nr_probes = 0, nr_del = 0, i; | 139 | int nr_probes = 0, nr_del = 0, i; |
136 | void **old, **new; | 140 | struct tracepoint_func *old, *new; |
137 | 141 | ||
138 | old = entry->funcs; | 142 | old = entry->funcs; |
139 | 143 | ||
@@ -142,8 +146,10 @@ tracepoint_entry_remove_probe(struct tracepoint_entry *entry, void *probe) | |||
142 | 146 | ||
143 | debug_print_probes(entry); | 147 | debug_print_probes(entry); |
144 | /* (N -> M), (N > 1, M >= 0) probes */ | 148 | /* (N -> M), (N > 1, M >= 0) probes */ |
145 | for (nr_probes = 0; old[nr_probes]; nr_probes++) { | 149 | for (nr_probes = 0; old[nr_probes].func; nr_probes++) { |
146 | if ((!probe || old[nr_probes] == probe)) | 150 | if (!probe || |
151 | (old[nr_probes].func == probe && | ||
152 | old[nr_probes].data == data)) | ||
147 | nr_del++; | 153 | nr_del++; |
148 | } | 154 | } |
149 | 155 | ||
@@ -160,10 +166,11 @@ tracepoint_entry_remove_probe(struct tracepoint_entry *entry, void *probe) | |||
160 | new = allocate_probes(nr_probes - nr_del + 1); | 166 | new = allocate_probes(nr_probes - nr_del + 1); |
161 | if (new == NULL) | 167 | if (new == NULL) |
162 | return ERR_PTR(-ENOMEM); | 168 | return ERR_PTR(-ENOMEM); |
163 | for (i = 0; old[i]; i++) | 169 | for (i = 0; old[i].func; i++) |
164 | if ((probe && old[i] != probe)) | 170 | if (probe && |
171 | (old[i].func != probe || old[i].data != data)) | ||
165 | new[j++] = old[i]; | 172 | new[j++] = old[i]; |
166 | new[nr_probes - nr_del] = NULL; | 173 | new[nr_probes - nr_del].func = NULL; |
167 | entry->refcount = nr_probes - nr_del; | 174 | entry->refcount = nr_probes - nr_del; |
168 | entry->funcs = new; | 175 | entry->funcs = new; |
169 | } | 176 | } |
@@ -315,18 +322,19 @@ static void tracepoint_update_probes(void) | |||
315 | module_update_tracepoints(); | 322 | module_update_tracepoints(); |
316 | } | 323 | } |
317 | 324 | ||
318 | static void *tracepoint_add_probe(const char *name, void *probe) | 325 | static struct tracepoint_func * |
326 | tracepoint_add_probe(const char *name, void *probe, void *data) | ||
319 | { | 327 | { |
320 | struct tracepoint_entry *entry; | 328 | struct tracepoint_entry *entry; |
321 | void *old; | 329 | struct tracepoint_func *old; |
322 | 330 | ||
323 | entry = get_tracepoint(name); | 331 | entry = get_tracepoint(name); |
324 | if (!entry) { | 332 | if (!entry) { |
325 | entry = add_tracepoint(name); | 333 | entry = add_tracepoint(name); |
326 | if (IS_ERR(entry)) | 334 | if (IS_ERR(entry)) |
327 | return entry; | 335 | return (struct tracepoint_func *)entry; |
328 | } | 336 | } |
329 | old = tracepoint_entry_add_probe(entry, probe); | 337 | old = tracepoint_entry_add_probe(entry, probe, data); |
330 | if (IS_ERR(old) && !entry->refcount) | 338 | if (IS_ERR(old) && !entry->refcount) |
331 | remove_tracepoint(entry); | 339 | remove_tracepoint(entry); |
332 | return old; | 340 | return old; |
@@ -340,12 +348,12 @@ static void *tracepoint_add_probe(const char *name, void *probe) | |||
340 | * Returns 0 if ok, error value on error. | 348 | * Returns 0 if ok, error value on error. |
341 | * The probe address must at least be aligned on the architecture pointer size. | 349 | * The probe address must at least be aligned on the architecture pointer size. |
342 | */ | 350 | */ |
343 | int tracepoint_probe_register(const char *name, void *probe) | 351 | int tracepoint_probe_register(const char *name, void *probe, void *data) |
344 | { | 352 | { |
345 | void *old; | 353 | struct tracepoint_func *old; |
346 | 354 | ||
347 | mutex_lock(&tracepoints_mutex); | 355 | mutex_lock(&tracepoints_mutex); |
348 | old = tracepoint_add_probe(name, probe); | 356 | old = tracepoint_add_probe(name, probe, data); |
349 | mutex_unlock(&tracepoints_mutex); | 357 | mutex_unlock(&tracepoints_mutex); |
350 | if (IS_ERR(old)) | 358 | if (IS_ERR(old)) |
351 | return PTR_ERR(old); | 359 | return PTR_ERR(old); |
@@ -356,15 +364,16 @@ int tracepoint_probe_register(const char *name, void *probe) | |||
356 | } | 364 | } |
357 | EXPORT_SYMBOL_GPL(tracepoint_probe_register); | 365 | EXPORT_SYMBOL_GPL(tracepoint_probe_register); |
358 | 366 | ||
359 | static void *tracepoint_remove_probe(const char *name, void *probe) | 367 | static struct tracepoint_func * |
368 | tracepoint_remove_probe(const char *name, void *probe, void *data) | ||
360 | { | 369 | { |
361 | struct tracepoint_entry *entry; | 370 | struct tracepoint_entry *entry; |
362 | void *old; | 371 | struct tracepoint_func *old; |
363 | 372 | ||
364 | entry = get_tracepoint(name); | 373 | entry = get_tracepoint(name); |
365 | if (!entry) | 374 | if (!entry) |
366 | return ERR_PTR(-ENOENT); | 375 | return ERR_PTR(-ENOENT); |
367 | old = tracepoint_entry_remove_probe(entry, probe); | 376 | old = tracepoint_entry_remove_probe(entry, probe, data); |
368 | if (IS_ERR(old)) | 377 | if (IS_ERR(old)) |
369 | return old; | 378 | return old; |
370 | if (!entry->refcount) | 379 | if (!entry->refcount) |
@@ -382,12 +391,12 @@ static void *tracepoint_remove_probe(const char *name, void *probe) | |||
382 | * itself uses stop_machine(), which insures that every preempt disabled section | 391 | * itself uses stop_machine(), which insures that every preempt disabled section |
383 | * have finished. | 392 | * have finished. |
384 | */ | 393 | */ |
385 | int tracepoint_probe_unregister(const char *name, void *probe) | 394 | int tracepoint_probe_unregister(const char *name, void *probe, void *data) |
386 | { | 395 | { |
387 | void *old; | 396 | struct tracepoint_func *old; |
388 | 397 | ||
389 | mutex_lock(&tracepoints_mutex); | 398 | mutex_lock(&tracepoints_mutex); |
390 | old = tracepoint_remove_probe(name, probe); | 399 | old = tracepoint_remove_probe(name, probe, data); |
391 | mutex_unlock(&tracepoints_mutex); | 400 | mutex_unlock(&tracepoints_mutex); |
392 | if (IS_ERR(old)) | 401 | if (IS_ERR(old)) |
393 | return PTR_ERR(old); | 402 | return PTR_ERR(old); |
@@ -418,12 +427,13 @@ static void tracepoint_add_old_probes(void *old) | |||
418 | * | 427 | * |
419 | * caller must call tracepoint_probe_update_all() | 428 | * caller must call tracepoint_probe_update_all() |
420 | */ | 429 | */ |
421 | int tracepoint_probe_register_noupdate(const char *name, void *probe) | 430 | int tracepoint_probe_register_noupdate(const char *name, void *probe, |
431 | void *data) | ||
422 | { | 432 | { |
423 | void *old; | 433 | struct tracepoint_func *old; |
424 | 434 | ||
425 | mutex_lock(&tracepoints_mutex); | 435 | mutex_lock(&tracepoints_mutex); |
426 | old = tracepoint_add_probe(name, probe); | 436 | old = tracepoint_add_probe(name, probe, data); |
427 | if (IS_ERR(old)) { | 437 | if (IS_ERR(old)) { |
428 | mutex_unlock(&tracepoints_mutex); | 438 | mutex_unlock(&tracepoints_mutex); |
429 | return PTR_ERR(old); | 439 | return PTR_ERR(old); |
@@ -441,12 +451,13 @@ EXPORT_SYMBOL_GPL(tracepoint_probe_register_noupdate); | |||
441 | * | 451 | * |
442 | * caller must call tracepoint_probe_update_all() | 452 | * caller must call tracepoint_probe_update_all() |
443 | */ | 453 | */ |
444 | int tracepoint_probe_unregister_noupdate(const char *name, void *probe) | 454 | int tracepoint_probe_unregister_noupdate(const char *name, void *probe, |
455 | void *data) | ||
445 | { | 456 | { |
446 | void *old; | 457 | struct tracepoint_func *old; |
447 | 458 | ||
448 | mutex_lock(&tracepoints_mutex); | 459 | mutex_lock(&tracepoints_mutex); |
449 | old = tracepoint_remove_probe(name, probe); | 460 | old = tracepoint_remove_probe(name, probe, data); |
450 | if (IS_ERR(old)) { | 461 | if (IS_ERR(old)) { |
451 | mutex_unlock(&tracepoints_mutex); | 462 | mutex_unlock(&tracepoints_mutex); |
452 | return PTR_ERR(old); | 463 | return PTR_ERR(old); |
diff --git a/net/core/drop_monitor.c b/net/core/drop_monitor.c index cf208d8042b1..ad41529fb60f 100644 --- a/net/core/drop_monitor.c +++ b/net/core/drop_monitor.c | |||
@@ -172,12 +172,12 @@ out: | |||
172 | return; | 172 | return; |
173 | } | 173 | } |
174 | 174 | ||
175 | static void trace_kfree_skb_hit(struct sk_buff *skb, void *location) | 175 | static void trace_kfree_skb_hit(void *ignore, struct sk_buff *skb, void *location) |
176 | { | 176 | { |
177 | trace_drop_common(skb, location); | 177 | trace_drop_common(skb, location); |
178 | } | 178 | } |
179 | 179 | ||
180 | static void trace_napi_poll_hit(struct napi_struct *napi) | 180 | static void trace_napi_poll_hit(void *ignore, struct napi_struct *napi) |
181 | { | 181 | { |
182 | struct dm_hw_stat_delta *new_stat; | 182 | struct dm_hw_stat_delta *new_stat; |
183 | 183 | ||
@@ -225,12 +225,12 @@ static int set_all_monitor_traces(int state) | |||
225 | 225 | ||
226 | switch (state) { | 226 | switch (state) { |
227 | case TRACE_ON: | 227 | case TRACE_ON: |
228 | rc |= register_trace_kfree_skb(trace_kfree_skb_hit); | 228 | rc |= register_trace_kfree_skb(trace_kfree_skb_hit, NULL); |
229 | rc |= register_trace_napi_poll(trace_napi_poll_hit); | 229 | rc |= register_trace_napi_poll(trace_napi_poll_hit, NULL); |
230 | break; | 230 | break; |
231 | case TRACE_OFF: | 231 | case TRACE_OFF: |
232 | rc |= unregister_trace_kfree_skb(trace_kfree_skb_hit); | 232 | rc |= unregister_trace_kfree_skb(trace_kfree_skb_hit, NULL); |
233 | rc |= unregister_trace_napi_poll(trace_napi_poll_hit); | 233 | rc |= unregister_trace_napi_poll(trace_napi_poll_hit, NULL); |
234 | 234 | ||
235 | tracepoint_synchronize_unregister(); | 235 | tracepoint_synchronize_unregister(); |
236 | 236 | ||
diff --git a/samples/tracepoints/tp-samples-trace.h b/samples/tracepoints/tp-samples-trace.h index dffdc49878af..4d46be965961 100644 --- a/samples/tracepoints/tp-samples-trace.h +++ b/samples/tracepoints/tp-samples-trace.h | |||
@@ -7,7 +7,5 @@ | |||
7 | DECLARE_TRACE(subsys_event, | 7 | DECLARE_TRACE(subsys_event, |
8 | TP_PROTO(struct inode *inode, struct file *file), | 8 | TP_PROTO(struct inode *inode, struct file *file), |
9 | TP_ARGS(inode, file)); | 9 | TP_ARGS(inode, file)); |
10 | DECLARE_TRACE(subsys_eventb, | 10 | DECLARE_TRACE_NOARGS(subsys_eventb); |
11 | TP_PROTO(void), | ||
12 | TP_ARGS()); | ||
13 | #endif | 11 | #endif |
diff --git a/samples/tracepoints/tracepoint-probe-sample.c b/samples/tracepoints/tracepoint-probe-sample.c index 9e60eb6ca2d8..744c0b9652a7 100644 --- a/samples/tracepoints/tracepoint-probe-sample.c +++ b/samples/tracepoints/tracepoint-probe-sample.c | |||
@@ -13,7 +13,8 @@ | |||
13 | * Here the caller only guarantees locking for struct file and struct inode. | 13 | * Here the caller only guarantees locking for struct file and struct inode. |
14 | * Locking must therefore be done in the probe to use the dentry. | 14 | * Locking must therefore be done in the probe to use the dentry. |
15 | */ | 15 | */ |
16 | static void probe_subsys_event(struct inode *inode, struct file *file) | 16 | static void probe_subsys_event(void *ignore, |
17 | struct inode *inode, struct file *file) | ||
17 | { | 18 | { |
18 | path_get(&file->f_path); | 19 | path_get(&file->f_path); |
19 | dget(file->f_path.dentry); | 20 | dget(file->f_path.dentry); |
@@ -23,7 +24,7 @@ static void probe_subsys_event(struct inode *inode, struct file *file) | |||
23 | path_put(&file->f_path); | 24 | path_put(&file->f_path); |
24 | } | 25 | } |
25 | 26 | ||
26 | static void probe_subsys_eventb(void) | 27 | static void probe_subsys_eventb(void *ignore) |
27 | { | 28 | { |
28 | printk(KERN_INFO "Event B is encountered\n"); | 29 | printk(KERN_INFO "Event B is encountered\n"); |
29 | } | 30 | } |
@@ -32,9 +33,9 @@ static int __init tp_sample_trace_init(void) | |||
32 | { | 33 | { |
33 | int ret; | 34 | int ret; |
34 | 35 | ||
35 | ret = register_trace_subsys_event(probe_subsys_event); | 36 | ret = register_trace_subsys_event(probe_subsys_event, NULL); |
36 | WARN_ON(ret); | 37 | WARN_ON(ret); |
37 | ret = register_trace_subsys_eventb(probe_subsys_eventb); | 38 | ret = register_trace_subsys_eventb(probe_subsys_eventb, NULL); |
38 | WARN_ON(ret); | 39 | WARN_ON(ret); |
39 | 40 | ||
40 | return 0; | 41 | return 0; |
@@ -44,8 +45,8 @@ module_init(tp_sample_trace_init); | |||
44 | 45 | ||
45 | static void __exit tp_sample_trace_exit(void) | 46 | static void __exit tp_sample_trace_exit(void) |
46 | { | 47 | { |
47 | unregister_trace_subsys_eventb(probe_subsys_eventb); | 48 | unregister_trace_subsys_eventb(probe_subsys_eventb, NULL); |
48 | unregister_trace_subsys_event(probe_subsys_event); | 49 | unregister_trace_subsys_event(probe_subsys_event, NULL); |
49 | tracepoint_synchronize_unregister(); | 50 | tracepoint_synchronize_unregister(); |
50 | } | 51 | } |
51 | 52 | ||
diff --git a/samples/tracepoints/tracepoint-probe-sample2.c b/samples/tracepoints/tracepoint-probe-sample2.c index be2a960573f1..9fcf990e5d4b 100644 --- a/samples/tracepoints/tracepoint-probe-sample2.c +++ b/samples/tracepoints/tracepoint-probe-sample2.c | |||
@@ -12,7 +12,8 @@ | |||
12 | * Here the caller only guarantees locking for struct file and struct inode. | 12 | * Here the caller only guarantees locking for struct file and struct inode. |
13 | * Locking must therefore be done in the probe to use the dentry. | 13 | * Locking must therefore be done in the probe to use the dentry. |
14 | */ | 14 | */ |
15 | static void probe_subsys_event(struct inode *inode, struct file *file) | 15 | static void probe_subsys_event(void *ignore, |
16 | struct inode *inode, struct file *file) | ||
16 | { | 17 | { |
17 | printk(KERN_INFO "Event is encountered with inode number %lu\n", | 18 | printk(KERN_INFO "Event is encountered with inode number %lu\n", |
18 | inode->i_ino); | 19 | inode->i_ino); |
@@ -22,7 +23,7 @@ static int __init tp_sample_trace_init(void) | |||
22 | { | 23 | { |
23 | int ret; | 24 | int ret; |
24 | 25 | ||
25 | ret = register_trace_subsys_event(probe_subsys_event); | 26 | ret = register_trace_subsys_event(probe_subsys_event, NULL); |
26 | WARN_ON(ret); | 27 | WARN_ON(ret); |
27 | 28 | ||
28 | return 0; | 29 | return 0; |
@@ -32,7 +33,7 @@ module_init(tp_sample_trace_init); | |||
32 | 33 | ||
33 | static void __exit tp_sample_trace_exit(void) | 34 | static void __exit tp_sample_trace_exit(void) |
34 | { | 35 | { |
35 | unregister_trace_subsys_event(probe_subsys_event); | 36 | unregister_trace_subsys_event(probe_subsys_event, NULL); |
36 | tracepoint_synchronize_unregister(); | 37 | tracepoint_synchronize_unregister(); |
37 | } | 38 | } |
38 | 39 | ||
diff --git a/tools/perf/Documentation/perf-stat.txt b/tools/perf/Documentation/perf-stat.txt index 2cab8e8c33d0..909fa766fa1c 100644 --- a/tools/perf/Documentation/perf-stat.txt +++ b/tools/perf/Documentation/perf-stat.txt | |||
@@ -43,6 +43,9 @@ OPTIONS | |||
43 | -c:: | 43 | -c:: |
44 | scale counter values | 44 | scale counter values |
45 | 45 | ||
46 | -B:: | ||
47 | print large numbers with thousands' separators according to locale | ||
48 | |||
46 | EXAMPLES | 49 | EXAMPLES |
47 | -------- | 50 | -------- |
48 | 51 | ||
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c index 77bcc9b130f5..08278eda31a5 100644 --- a/tools/perf/builtin-annotate.c +++ b/tools/perf/builtin-annotate.c | |||
@@ -277,7 +277,7 @@ static void hist_entry__print_hits(struct hist_entry *self) | |||
277 | printf("%*s: %Lu\n", BITS_PER_LONG / 2, "h->sum", h->sum); | 277 | printf("%*s: %Lu\n", BITS_PER_LONG / 2, "h->sum", h->sum); |
278 | } | 278 | } |
279 | 279 | ||
280 | static void annotate_sym(struct hist_entry *he) | 280 | static int hist_entry__tty_annotate(struct hist_entry *he) |
281 | { | 281 | { |
282 | struct map *map = he->ms.map; | 282 | struct map *map = he->ms.map; |
283 | struct dso *dso = map->dso; | 283 | struct dso *dso = map->dso; |
@@ -288,7 +288,7 @@ static void annotate_sym(struct hist_entry *he) | |||
288 | struct objdump_line *pos, *n; | 288 | struct objdump_line *pos, *n; |
289 | 289 | ||
290 | if (hist_entry__annotate(he, &head) < 0) | 290 | if (hist_entry__annotate(he, &head) < 0) |
291 | return; | 291 | return -1; |
292 | 292 | ||
293 | if (full_paths) | 293 | if (full_paths) |
294 | d_filename = filename; | 294 | d_filename = filename; |
@@ -317,30 +317,59 @@ static void annotate_sym(struct hist_entry *he) | |||
317 | 317 | ||
318 | if (print_line) | 318 | if (print_line) |
319 | free_source_line(he, len); | 319 | free_source_line(he, len); |
320 | |||
321 | return 0; | ||
320 | } | 322 | } |
321 | 323 | ||
322 | static void hists__find_annotations(struct hists *self) | 324 | static void hists__find_annotations(struct hists *self) |
323 | { | 325 | { |
324 | struct rb_node *nd; | 326 | struct rb_node *first = rb_first(&self->entries), *nd = first; |
327 | int key = KEY_RIGHT; | ||
325 | 328 | ||
326 | for (nd = rb_first(&self->entries); nd; nd = rb_next(nd)) { | 329 | while (nd) { |
327 | struct hist_entry *he = rb_entry(nd, struct hist_entry, rb_node); | 330 | struct hist_entry *he = rb_entry(nd, struct hist_entry, rb_node); |
328 | struct sym_priv *priv; | 331 | struct sym_priv *priv; |
329 | 332 | ||
330 | if (he->ms.sym == NULL) | 333 | if (he->ms.sym == NULL || he->ms.map->dso->annotate_warned) |
331 | continue; | 334 | goto find_next; |
332 | 335 | ||
333 | priv = symbol__priv(he->ms.sym); | 336 | priv = symbol__priv(he->ms.sym); |
334 | if (priv->hist == NULL) | 337 | if (priv->hist == NULL) { |
338 | find_next: | ||
339 | if (key == KEY_LEFT) | ||
340 | nd = rb_prev(nd); | ||
341 | else | ||
342 | nd = rb_next(nd); | ||
335 | continue; | 343 | continue; |
344 | } | ||
336 | 345 | ||
337 | annotate_sym(he); | 346 | if (use_browser) { |
338 | /* | 347 | key = hist_entry__tui_annotate(he); |
339 | * Since we have a hist_entry per IP for the same symbol, free | 348 | if (is_exit_key(key)) |
340 | * he->ms.sym->hist to signal we already processed this symbol. | 349 | break; |
341 | */ | 350 | switch (key) { |
342 | free(priv->hist); | 351 | case KEY_RIGHT: |
343 | priv->hist = NULL; | 352 | case '\t': |
353 | nd = rb_next(nd); | ||
354 | break; | ||
355 | case KEY_LEFT: | ||
356 | if (nd == first) | ||
357 | continue; | ||
358 | nd = rb_prev(nd); | ||
359 | default: | ||
360 | break; | ||
361 | } | ||
362 | } else { | ||
363 | hist_entry__tty_annotate(he); | ||
364 | nd = rb_next(nd); | ||
365 | /* | ||
366 | * Since we have a hist_entry per IP for the same | ||
367 | * symbol, free he->ms.sym->hist to signal we already | ||
368 | * processed this symbol. | ||
369 | */ | ||
370 | free(priv->hist); | ||
371 | priv->hist = NULL; | ||
372 | } | ||
344 | } | 373 | } |
345 | } | 374 | } |
346 | 375 | ||
@@ -416,6 +445,8 @@ int cmd_annotate(int argc, const char **argv, const char *prefix __used) | |||
416 | { | 445 | { |
417 | argc = parse_options(argc, argv, options, annotate_usage, 0); | 446 | argc = parse_options(argc, argv, options, annotate_usage, 0); |
418 | 447 | ||
448 | setup_browser(); | ||
449 | |||
419 | symbol_conf.priv_size = sizeof(struct sym_priv); | 450 | symbol_conf.priv_size = sizeof(struct sym_priv); |
420 | symbol_conf.try_vmlinux_path = true; | 451 | symbol_conf.try_vmlinux_path = true; |
421 | 452 | ||
@@ -435,8 +466,6 @@ int cmd_annotate(int argc, const char **argv, const char *prefix __used) | |||
435 | sym_hist_filter = argv[0]; | 466 | sym_hist_filter = argv[0]; |
436 | } | 467 | } |
437 | 468 | ||
438 | setup_pager(); | ||
439 | |||
440 | if (field_sep && *field_sep == '.') { | 469 | if (field_sep && *field_sep == '.') { |
441 | pr_err("'.' is the only non valid --field-separator argument\n"); | 470 | pr_err("'.' is the only non valid --field-separator argument\n"); |
442 | return -1; | 471 | return -1; |
diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c index 61c6d70732c9..e4a4da32a568 100644 --- a/tools/perf/builtin-probe.c +++ b/tools/perf/builtin-probe.c | |||
@@ -65,8 +65,10 @@ static int parse_probe_event(const char *str) | |||
65 | int ret; | 65 | int ret; |
66 | 66 | ||
67 | pr_debug("probe-definition(%d): %s\n", params.nevents, str); | 67 | pr_debug("probe-definition(%d): %s\n", params.nevents, str); |
68 | if (++params.nevents == MAX_PROBES) | 68 | if (++params.nevents == MAX_PROBES) { |
69 | die("Too many probes (> %d) are specified.", MAX_PROBES); | 69 | pr_err("Too many probes (> %d) were specified.", MAX_PROBES); |
70 | return -1; | ||
71 | } | ||
70 | 72 | ||
71 | /* Parse a perf-probe command into event */ | 73 | /* Parse a perf-probe command into event */ |
72 | ret = parse_perf_probe_command(str, pev); | 74 | ret = parse_perf_probe_command(str, pev); |
@@ -84,7 +86,9 @@ static int parse_probe_event_argv(int argc, const char **argv) | |||
84 | len = 0; | 86 | len = 0; |
85 | for (i = 0; i < argc; i++) | 87 | for (i = 0; i < argc; i++) |
86 | len += strlen(argv[i]) + 1; | 88 | len += strlen(argv[i]) + 1; |
87 | buf = xzalloc(len + 1); | 89 | buf = zalloc(len + 1); |
90 | if (buf == NULL) | ||
91 | return -ENOMEM; | ||
88 | len = 0; | 92 | len = 0; |
89 | for (i = 0; i < argc; i++) | 93 | for (i = 0; i < argc; i++) |
90 | len += sprintf(&buf[len], "%s ", argv[i]); | 94 | len += sprintf(&buf[len], "%s ", argv[i]); |
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index cb46c7d0ea99..9bc89050e6f8 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c | |||
@@ -25,6 +25,7 @@ | |||
25 | 25 | ||
26 | #include <unistd.h> | 26 | #include <unistd.h> |
27 | #include <sched.h> | 27 | #include <sched.h> |
28 | #include <sys/mman.h> | ||
28 | 29 | ||
29 | enum write_mode_t { | 30 | enum write_mode_t { |
30 | WRITE_FORCE, | 31 | WRITE_FORCE, |
@@ -60,13 +61,8 @@ static bool call_graph = false; | |||
60 | static bool inherit_stat = false; | 61 | static bool inherit_stat = false; |
61 | static bool no_samples = false; | 62 | static bool no_samples = false; |
62 | static bool sample_address = false; | 63 | static bool sample_address = false; |
63 | static bool multiplex = false; | ||
64 | static int multiplex_fd = -1; | ||
65 | 64 | ||
66 | static long samples = 0; | 65 | static long samples = 0; |
67 | static struct timeval last_read; | ||
68 | static struct timeval this_read; | ||
69 | |||
70 | static u64 bytes_written = 0; | 66 | static u64 bytes_written = 0; |
71 | 67 | ||
72 | static struct pollfd *event_array; | 68 | static struct pollfd *event_array; |
@@ -86,7 +82,7 @@ struct mmap_data { | |||
86 | unsigned int prev; | 82 | unsigned int prev; |
87 | }; | 83 | }; |
88 | 84 | ||
89 | static struct mmap_data *mmap_array[MAX_NR_CPUS][MAX_COUNTERS]; | 85 | static struct mmap_data mmap_array[MAX_NR_CPUS]; |
90 | 86 | ||
91 | static unsigned long mmap_read_head(struct mmap_data *md) | 87 | static unsigned long mmap_read_head(struct mmap_data *md) |
92 | { | 88 | { |
@@ -146,8 +142,6 @@ static void mmap_read(struct mmap_data *md) | |||
146 | void *buf; | 142 | void *buf; |
147 | int diff; | 143 | int diff; |
148 | 144 | ||
149 | gettimeofday(&this_read, NULL); | ||
150 | |||
151 | /* | 145 | /* |
152 | * If we're further behind than half the buffer, there's a chance | 146 | * If we're further behind than half the buffer, there's a chance |
153 | * the writer will bite our tail and mess up the samples under us. | 147 | * the writer will bite our tail and mess up the samples under us. |
@@ -158,23 +152,13 @@ static void mmap_read(struct mmap_data *md) | |||
158 | */ | 152 | */ |
159 | diff = head - old; | 153 | diff = head - old; |
160 | if (diff < 0) { | 154 | if (diff < 0) { |
161 | struct timeval iv; | 155 | fprintf(stderr, "WARNING: failed to keep up with mmap data\n"); |
162 | unsigned long msecs; | ||
163 | |||
164 | timersub(&this_read, &last_read, &iv); | ||
165 | msecs = iv.tv_sec*1000 + iv.tv_usec/1000; | ||
166 | |||
167 | fprintf(stderr, "WARNING: failed to keep up with mmap data." | ||
168 | " Last read %lu msecs ago.\n", msecs); | ||
169 | |||
170 | /* | 156 | /* |
171 | * head points to a known good entry, start there. | 157 | * head points to a known good entry, start there. |
172 | */ | 158 | */ |
173 | old = head; | 159 | old = head; |
174 | } | 160 | } |
175 | 161 | ||
176 | last_read = this_read; | ||
177 | |||
178 | if (old != head) | 162 | if (old != head) |
179 | samples++; | 163 | samples++; |
180 | 164 | ||
@@ -380,27 +364,30 @@ try_again: | |||
380 | */ | 364 | */ |
381 | if (group && group_fd == -1) | 365 | if (group && group_fd == -1) |
382 | group_fd = fd[nr_cpu][counter][thread_index]; | 366 | group_fd = fd[nr_cpu][counter][thread_index]; |
383 | if (multiplex && multiplex_fd == -1) | ||
384 | multiplex_fd = fd[nr_cpu][counter][thread_index]; | ||
385 | 367 | ||
386 | if (multiplex && fd[nr_cpu][counter][thread_index] != multiplex_fd) { | 368 | if (counter || thread_index) { |
387 | 369 | ret = ioctl(fd[nr_cpu][counter][thread_index], | |
388 | ret = ioctl(fd[nr_cpu][counter][thread_index], PERF_EVENT_IOC_SET_OUTPUT, multiplex_fd); | 370 | PERF_EVENT_IOC_SET_OUTPUT, |
389 | assert(ret != -1); | 371 | fd[nr_cpu][0][0]); |
372 | if (ret) { | ||
373 | error("failed to set output: %d (%s)\n", errno, | ||
374 | strerror(errno)); | ||
375 | exit(-1); | ||
376 | } | ||
390 | } else { | 377 | } else { |
391 | event_array[nr_poll].fd = fd[nr_cpu][counter][thread_index]; | 378 | mmap_array[nr_cpu].counter = counter; |
392 | event_array[nr_poll].events = POLLIN; | 379 | mmap_array[nr_cpu].prev = 0; |
393 | nr_poll++; | 380 | mmap_array[nr_cpu].mask = mmap_pages*page_size - 1; |
394 | 381 | mmap_array[nr_cpu].base = mmap(NULL, (mmap_pages+1)*page_size, | |
395 | mmap_array[nr_cpu][counter][thread_index].counter = counter; | ||
396 | mmap_array[nr_cpu][counter][thread_index].prev = 0; | ||
397 | mmap_array[nr_cpu][counter][thread_index].mask = mmap_pages*page_size - 1; | ||
398 | mmap_array[nr_cpu][counter][thread_index].base = mmap(NULL, (mmap_pages+1)*page_size, | ||
399 | PROT_READ|PROT_WRITE, MAP_SHARED, fd[nr_cpu][counter][thread_index], 0); | 382 | PROT_READ|PROT_WRITE, MAP_SHARED, fd[nr_cpu][counter][thread_index], 0); |
400 | if (mmap_array[nr_cpu][counter][thread_index].base == MAP_FAILED) { | 383 | if (mmap_array[nr_cpu].base == MAP_FAILED) { |
401 | error("failed to mmap with %d (%s)\n", errno, strerror(errno)); | 384 | error("failed to mmap with %d (%s)\n", errno, strerror(errno)); |
402 | exit(-1); | 385 | exit(-1); |
403 | } | 386 | } |
387 | |||
388 | event_array[nr_poll].fd = fd[nr_cpu][counter][thread_index]; | ||
389 | event_array[nr_poll].events = POLLIN; | ||
390 | nr_poll++; | ||
404 | } | 391 | } |
405 | 392 | ||
406 | if (filter != NULL) { | 393 | if (filter != NULL) { |
@@ -501,16 +488,11 @@ static struct perf_event_header finished_round_event = { | |||
501 | 488 | ||
502 | static void mmap_read_all(void) | 489 | static void mmap_read_all(void) |
503 | { | 490 | { |
504 | int i, counter, thread; | 491 | int i; |
505 | 492 | ||
506 | for (i = 0; i < nr_cpu; i++) { | 493 | for (i = 0; i < nr_cpu; i++) { |
507 | for (counter = 0; counter < nr_counters; counter++) { | 494 | if (mmap_array[i].base) |
508 | for (thread = 0; thread < thread_num; thread++) { | 495 | mmap_read(&mmap_array[i]); |
509 | if (mmap_array[i][counter][thread].base) | ||
510 | mmap_read(&mmap_array[i][counter][thread]); | ||
511 | } | ||
512 | |||
513 | } | ||
514 | } | 496 | } |
515 | 497 | ||
516 | if (perf_header__has_feat(&session->header, HEADER_TRACE_INFO)) | 498 | if (perf_header__has_feat(&session->header, HEADER_TRACE_INFO)) |
@@ -834,8 +816,6 @@ static const struct option options[] = { | |||
834 | "Sample addresses"), | 816 | "Sample addresses"), |
835 | OPT_BOOLEAN('n', "no-samples", &no_samples, | 817 | OPT_BOOLEAN('n', "no-samples", &no_samples, |
836 | "don't sample"), | 818 | "don't sample"), |
837 | OPT_BOOLEAN('M', "multiplex", &multiplex, | ||
838 | "multiplex counter output in a single channel"), | ||
839 | OPT_END() | 819 | OPT_END() |
840 | }; | 820 | }; |
841 | 821 | ||
@@ -887,9 +867,7 @@ int cmd_record(int argc, const char **argv, const char *prefix __used) | |||
887 | for (i = 0; i < MAX_NR_CPUS; i++) { | 867 | for (i = 0; i < MAX_NR_CPUS; i++) { |
888 | for (j = 0; j < MAX_COUNTERS; j++) { | 868 | for (j = 0; j < MAX_COUNTERS; j++) { |
889 | fd[i][j] = malloc(sizeof(int)*thread_num); | 869 | fd[i][j] = malloc(sizeof(int)*thread_num); |
890 | mmap_array[i][j] = zalloc( | 870 | if (!fd[i][j]) |
891 | sizeof(struct mmap_data)*thread_num); | ||
892 | if (!fd[i][j] || !mmap_array[i][j]) | ||
893 | return -ENOMEM; | 871 | return -ENOMEM; |
894 | } | 872 | } |
895 | } | 873 | } |
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index 1d3c1003b43a..359205782964 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c | |||
@@ -116,7 +116,7 @@ static int perf_session__add_hist_entry(struct perf_session *self, | |||
116 | * so we don't allocated the extra space needed because the stdio | 116 | * so we don't allocated the extra space needed because the stdio |
117 | * code will not use it. | 117 | * code will not use it. |
118 | */ | 118 | */ |
119 | if (use_browser) | 119 | if (use_browser > 0) |
120 | err = hist_entry__inc_addr_samples(he, al->addr); | 120 | err = hist_entry__inc_addr_samples(he, al->addr); |
121 | out_free_syms: | 121 | out_free_syms: |
122 | free(syms); | 122 | free(syms); |
@@ -288,6 +288,38 @@ static size_t hists__fprintf_nr_sample_events(struct hists *self, | |||
288 | return ret + fprintf(fp, "\n#\n"); | 288 | return ret + fprintf(fp, "\n#\n"); |
289 | } | 289 | } |
290 | 290 | ||
291 | static int hists__tty_browse_tree(struct rb_root *tree, const char *help) | ||
292 | { | ||
293 | struct rb_node *next = rb_first(tree); | ||
294 | |||
295 | while (next) { | ||
296 | struct hists *hists = rb_entry(next, struct hists, rb_node); | ||
297 | const char *evname = NULL; | ||
298 | |||
299 | if (rb_first(&hists->entries) != rb_last(&hists->entries)) | ||
300 | evname = __event_name(hists->type, hists->config); | ||
301 | |||
302 | hists__fprintf_nr_sample_events(hists, evname, stdout); | ||
303 | hists__fprintf(hists, NULL, false, stdout); | ||
304 | fprintf(stdout, "\n\n"); | ||
305 | next = rb_next(&hists->rb_node); | ||
306 | } | ||
307 | |||
308 | if (sort_order == default_sort_order && | ||
309 | parent_pattern == default_parent_pattern) { | ||
310 | fprintf(stdout, "#\n# (%s)\n#\n", help); | ||
311 | |||
312 | if (show_threads) { | ||
313 | bool style = !strcmp(pretty_printing_style, "raw"); | ||
314 | perf_read_values_display(stdout, &show_threads_values, | ||
315 | style); | ||
316 | perf_read_values_destroy(&show_threads_values); | ||
317 | } | ||
318 | } | ||
319 | |||
320 | return 0; | ||
321 | } | ||
322 | |||
291 | static int __cmd_report(void) | 323 | static int __cmd_report(void) |
292 | { | 324 | { |
293 | int ret = -EINVAL; | 325 | int ret = -EINVAL; |
@@ -330,34 +362,14 @@ static int __cmd_report(void) | |||
330 | hists = rb_entry(next, struct hists, rb_node); | 362 | hists = rb_entry(next, struct hists, rb_node); |
331 | hists__collapse_resort(hists); | 363 | hists__collapse_resort(hists); |
332 | hists__output_resort(hists); | 364 | hists__output_resort(hists); |
333 | if (use_browser) | ||
334 | hists__browse(hists, help, input_name); | ||
335 | else { | ||
336 | const char *evname = NULL; | ||
337 | if (rb_first(&session->hists.entries) != | ||
338 | rb_last(&session->hists.entries)) | ||
339 | evname = __event_name(hists->type, hists->config); | ||
340 | |||
341 | hists__fprintf_nr_sample_events(hists, evname, stdout); | ||
342 | |||
343 | hists__fprintf(hists, NULL, false, stdout); | ||
344 | fprintf(stdout, "\n\n"); | ||
345 | } | ||
346 | |||
347 | next = rb_next(&hists->rb_node); | 365 | next = rb_next(&hists->rb_node); |
348 | } | 366 | } |
349 | 367 | ||
350 | if (!use_browser && sort_order == default_sort_order && | 368 | if (use_browser > 0) |
351 | parent_pattern == default_parent_pattern) { | 369 | hists__tui_browse_tree(&session->hists_tree, help); |
352 | fprintf(stdout, "#\n# (%s)\n#\n", help); | 370 | else |
371 | hists__tty_browse_tree(&session->hists_tree, help); | ||
353 | 372 | ||
354 | if (show_threads) { | ||
355 | bool style = !strcmp(pretty_printing_style, "raw"); | ||
356 | perf_read_values_display(stdout, &show_threads_values, | ||
357 | style); | ||
358 | perf_read_values_destroy(&show_threads_values); | ||
359 | } | ||
360 | } | ||
361 | out_delete: | 373 | out_delete: |
362 | perf_session__delete(session); | 374 | perf_session__delete(session); |
363 | return ret; | 375 | return ret; |
@@ -491,7 +503,7 @@ int cmd_report(int argc, const char **argv, const char *prefix __used) | |||
491 | * so don't allocate extra space that won't be used in the stdio | 503 | * so don't allocate extra space that won't be used in the stdio |
492 | * implementation. | 504 | * implementation. |
493 | */ | 505 | */ |
494 | if (use_browser) | 506 | if (use_browser > 0) |
495 | symbol_conf.priv_size = sizeof(struct sym_priv); | 507 | symbol_conf.priv_size = sizeof(struct sym_priv); |
496 | 508 | ||
497 | if (symbol__init() < 0) | 509 | if (symbol__init() < 0) |
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index ff8c413b7e73..9a39ca3c3ac4 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c | |||
@@ -50,6 +50,7 @@ | |||
50 | 50 | ||
51 | #include <sys/prctl.h> | 51 | #include <sys/prctl.h> |
52 | #include <math.h> | 52 | #include <math.h> |
53 | #include <locale.h> | ||
53 | 54 | ||
54 | static struct perf_event_attr default_attrs[] = { | 55 | static struct perf_event_attr default_attrs[] = { |
55 | 56 | ||
@@ -80,6 +81,8 @@ static pid_t *all_tids = NULL; | |||
80 | static int thread_num = 0; | 81 | static int thread_num = 0; |
81 | static pid_t child_pid = -1; | 82 | static pid_t child_pid = -1; |
82 | static bool null_run = false; | 83 | static bool null_run = false; |
84 | static bool big_num = false; | ||
85 | |||
83 | 86 | ||
84 | static int *fd[MAX_NR_CPUS][MAX_COUNTERS]; | 87 | static int *fd[MAX_NR_CPUS][MAX_COUNTERS]; |
85 | 88 | ||
@@ -377,7 +380,7 @@ static void nsec_printout(int counter, double avg) | |||
377 | { | 380 | { |
378 | double msecs = avg / 1e6; | 381 | double msecs = avg / 1e6; |
379 | 382 | ||
380 | fprintf(stderr, " %14.6f %-24s", msecs, event_name(counter)); | 383 | fprintf(stderr, " %18.6f %-24s", msecs, event_name(counter)); |
381 | 384 | ||
382 | if (MATCH_EVENT(SOFTWARE, SW_TASK_CLOCK, counter)) { | 385 | if (MATCH_EVENT(SOFTWARE, SW_TASK_CLOCK, counter)) { |
383 | fprintf(stderr, " # %10.3f CPUs ", | 386 | fprintf(stderr, " # %10.3f CPUs ", |
@@ -389,7 +392,10 @@ static void abs_printout(int counter, double avg) | |||
389 | { | 392 | { |
390 | double total, ratio = 0.0; | 393 | double total, ratio = 0.0; |
391 | 394 | ||
392 | fprintf(stderr, " %14.0f %-24s", avg, event_name(counter)); | 395 | if (big_num) |
396 | fprintf(stderr, " %'18.0f %-24s", avg, event_name(counter)); | ||
397 | else | ||
398 | fprintf(stderr, " %18.0f %-24s", avg, event_name(counter)); | ||
393 | 399 | ||
394 | if (MATCH_EVENT(HARDWARE, HW_INSTRUCTIONS, counter)) { | 400 | if (MATCH_EVENT(HARDWARE, HW_INSTRUCTIONS, counter)) { |
395 | total = avg_stats(&runtime_cycles_stats); | 401 | total = avg_stats(&runtime_cycles_stats); |
@@ -426,7 +432,7 @@ static void print_counter(int counter) | |||
426 | int scaled = event_scaled[counter]; | 432 | int scaled = event_scaled[counter]; |
427 | 433 | ||
428 | if (scaled == -1) { | 434 | if (scaled == -1) { |
429 | fprintf(stderr, " %14s %-24s\n", | 435 | fprintf(stderr, " %18s %-24s\n", |
430 | "<not counted>", event_name(counter)); | 436 | "<not counted>", event_name(counter)); |
431 | return; | 437 | return; |
432 | } | 438 | } |
@@ -477,7 +483,7 @@ static void print_stat(int argc, const char **argv) | |||
477 | print_counter(counter); | 483 | print_counter(counter); |
478 | 484 | ||
479 | fprintf(stderr, "\n"); | 485 | fprintf(stderr, "\n"); |
480 | fprintf(stderr, " %14.9f seconds time elapsed", | 486 | fprintf(stderr, " %18.9f seconds time elapsed", |
481 | avg_stats(&walltime_nsecs_stats)/1e9); | 487 | avg_stats(&walltime_nsecs_stats)/1e9); |
482 | if (run_count > 1) { | 488 | if (run_count > 1) { |
483 | fprintf(stderr, " ( +- %7.3f%% )", | 489 | fprintf(stderr, " ( +- %7.3f%% )", |
@@ -534,6 +540,8 @@ static const struct option options[] = { | |||
534 | "repeat command and print average + stddev (max: 100)"), | 540 | "repeat command and print average + stddev (max: 100)"), |
535 | OPT_BOOLEAN('n', "null", &null_run, | 541 | OPT_BOOLEAN('n', "null", &null_run, |
536 | "null run - dont start any counters"), | 542 | "null run - dont start any counters"), |
543 | OPT_BOOLEAN('B', "big-num", &big_num, | ||
544 | "print large numbers with thousands\' separators"), | ||
537 | OPT_END() | 545 | OPT_END() |
538 | }; | 546 | }; |
539 | 547 | ||
@@ -542,6 +550,8 @@ int cmd_stat(int argc, const char **argv, const char *prefix __used) | |||
542 | int status; | 550 | int status; |
543 | int i,j; | 551 | int i,j; |
544 | 552 | ||
553 | setlocale(LC_ALL, ""); | ||
554 | |||
545 | argc = parse_options(argc, argv, options, stat_usage, | 555 | argc = parse_options(argc, argv, options, stat_usage, |
546 | PARSE_OPT_STOP_AT_NON_OPTION); | 556 | PARSE_OPT_STOP_AT_NON_OPTION); |
547 | if (!argc && target_pid == -1 && target_tid == -1) | 557 | if (!argc && target_pid == -1 && target_tid == -1) |
diff --git a/tools/perf/perf.c b/tools/perf/perf.c index 08e0e5d2b50e..6e4871191138 100644 --- a/tools/perf/perf.c +++ b/tools/perf/perf.c | |||
@@ -15,15 +15,15 @@ | |||
15 | #include "util/parse-events.h" | 15 | #include "util/parse-events.h" |
16 | #include "util/debugfs.h" | 16 | #include "util/debugfs.h" |
17 | 17 | ||
18 | bool use_browser; | ||
19 | |||
20 | const char perf_usage_string[] = | 18 | const char perf_usage_string[] = |
21 | "perf [--version] [--help] COMMAND [ARGS]"; | 19 | "perf [--version] [--help] COMMAND [ARGS]"; |
22 | 20 | ||
23 | const char perf_more_info_string[] = | 21 | const char perf_more_info_string[] = |
24 | "See 'perf help COMMAND' for more information on a specific command."; | 22 | "See 'perf help COMMAND' for more information on a specific command."; |
25 | 23 | ||
24 | int use_browser = -1; | ||
26 | static int use_pager = -1; | 25 | static int use_pager = -1; |
26 | |||
27 | struct pager_config { | 27 | struct pager_config { |
28 | const char *cmd; | 28 | const char *cmd; |
29 | int val; | 29 | int val; |
@@ -49,6 +49,24 @@ int check_pager_config(const char *cmd) | |||
49 | return c.val; | 49 | return c.val; |
50 | } | 50 | } |
51 | 51 | ||
52 | static int tui_command_config(const char *var, const char *value, void *data) | ||
53 | { | ||
54 | struct pager_config *c = data; | ||
55 | if (!prefixcmp(var, "tui.") && !strcmp(var + 4, c->cmd)) | ||
56 | c->val = perf_config_bool(var, value); | ||
57 | return 0; | ||
58 | } | ||
59 | |||
60 | /* returns 0 for "no tui", 1 for "use tui", and -1 for "not specified" */ | ||
61 | static int check_tui_config(const char *cmd) | ||
62 | { | ||
63 | struct pager_config c; | ||
64 | c.cmd = cmd; | ||
65 | c.val = -1; | ||
66 | perf_config(tui_command_config, &c); | ||
67 | return c.val; | ||
68 | } | ||
69 | |||
52 | static void commit_pager_choice(void) | 70 | static void commit_pager_choice(void) |
53 | { | 71 | { |
54 | switch (use_pager) { | 72 | switch (use_pager) { |
@@ -255,6 +273,9 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv) | |||
255 | if (p->option & RUN_SETUP) | 273 | if (p->option & RUN_SETUP) |
256 | prefix = NULL; /* setup_perf_directory(); */ | 274 | prefix = NULL; /* setup_perf_directory(); */ |
257 | 275 | ||
276 | if (use_browser == -1) | ||
277 | use_browser = check_tui_config(p->cmd); | ||
278 | |||
258 | if (use_pager == -1 && p->option & RUN_SETUP) | 279 | if (use_pager == -1 && p->option & RUN_SETUP) |
259 | use_pager = check_pager_config(p->cmd); | 280 | use_pager = check_pager_config(p->cmd); |
260 | if (use_pager == -1 && p->option & USE_PAGER) | 281 | if (use_pager == -1 && p->option & USE_PAGER) |
diff --git a/tools/perf/util/abspath.c b/tools/perf/util/abspath.c index a791dd467261..0e76affe9c36 100644 --- a/tools/perf/util/abspath.c +++ b/tools/perf/util/abspath.c | |||
@@ -1,86 +1,5 @@ | |||
1 | #include "cache.h" | 1 | #include "cache.h" |
2 | 2 | ||
3 | /* | ||
4 | * Do not use this for inspecting *tracked* content. When path is a | ||
5 | * symlink to a directory, we do not want to say it is a directory when | ||
6 | * dealing with tracked content in the working tree. | ||
7 | */ | ||
8 | static int is_directory(const char *path) | ||
9 | { | ||
10 | struct stat st; | ||
11 | return (!stat(path, &st) && S_ISDIR(st.st_mode)); | ||
12 | } | ||
13 | |||
14 | /* We allow "recursive" symbolic links. Only within reason, though. */ | ||
15 | #define MAXDEPTH 5 | ||
16 | |||
17 | const char *make_absolute_path(const char *path) | ||
18 | { | ||
19 | static char bufs[2][PATH_MAX + 1], *buf = bufs[0], *next_buf = bufs[1]; | ||
20 | char cwd[1024] = ""; | ||
21 | int buf_index = 1, len; | ||
22 | |||
23 | int depth = MAXDEPTH; | ||
24 | char *last_elem = NULL; | ||
25 | struct stat st; | ||
26 | |||
27 | if (strlcpy(buf, path, PATH_MAX) >= PATH_MAX) | ||
28 | die ("Too long path: %.*s", 60, path); | ||
29 | |||
30 | while (depth--) { | ||
31 | if (!is_directory(buf)) { | ||
32 | char *last_slash = strrchr(buf, '/'); | ||
33 | if (last_slash) { | ||
34 | *last_slash = '\0'; | ||
35 | last_elem = xstrdup(last_slash + 1); | ||
36 | } else { | ||
37 | last_elem = xstrdup(buf); | ||
38 | *buf = '\0'; | ||
39 | } | ||
40 | } | ||
41 | |||
42 | if (*buf) { | ||
43 | if (!*cwd && !getcwd(cwd, sizeof(cwd))) | ||
44 | die ("Could not get current working directory"); | ||
45 | |||
46 | if (chdir(buf)) | ||
47 | die ("Could not switch to '%s'", buf); | ||
48 | } | ||
49 | if (!getcwd(buf, PATH_MAX)) | ||
50 | die ("Could not get current working directory"); | ||
51 | |||
52 | if (last_elem) { | ||
53 | len = strlen(buf); | ||
54 | |||
55 | if (len + strlen(last_elem) + 2 > PATH_MAX) | ||
56 | die ("Too long path name: '%s/%s'", | ||
57 | buf, last_elem); | ||
58 | buf[len] = '/'; | ||
59 | strcpy(buf + len + 1, last_elem); | ||
60 | free(last_elem); | ||
61 | last_elem = NULL; | ||
62 | } | ||
63 | |||
64 | if (!lstat(buf, &st) && S_ISLNK(st.st_mode)) { | ||
65 | len = readlink(buf, next_buf, PATH_MAX); | ||
66 | if (len < 0) | ||
67 | die ("Invalid symlink: %s", buf); | ||
68 | if (PATH_MAX <= len) | ||
69 | die("symbolic link too long: %s", buf); | ||
70 | next_buf[len] = '\0'; | ||
71 | buf = next_buf; | ||
72 | buf_index = 1 - buf_index; | ||
73 | next_buf = bufs[buf_index]; | ||
74 | } else | ||
75 | break; | ||
76 | } | ||
77 | |||
78 | if (*cwd && chdir(cwd)) | ||
79 | die ("Could not change back to '%s'", cwd); | ||
80 | |||
81 | return buf; | ||
82 | } | ||
83 | |||
84 | static const char *get_pwd_cwd(void) | 3 | static const char *get_pwd_cwd(void) |
85 | { | 4 | { |
86 | static char cwd[PATH_MAX + 1]; | 5 | static char cwd[PATH_MAX + 1]; |
diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c index 0f60a3906808..70c5cf87d020 100644 --- a/tools/perf/util/build-id.c +++ b/tools/perf/util/build-id.c | |||
@@ -6,6 +6,8 @@ | |||
6 | * Copyright (C) 2009, 2010 Red Hat Inc. | 6 | * Copyright (C) 2009, 2010 Red Hat Inc. |
7 | * Copyright (C) 2009, 2010 Arnaldo Carvalho de Melo <acme@redhat.com> | 7 | * Copyright (C) 2009, 2010 Arnaldo Carvalho de Melo <acme@redhat.com> |
8 | */ | 8 | */ |
9 | #include "util.h" | ||
10 | #include <stdio.h> | ||
9 | #include "build-id.h" | 11 | #include "build-id.h" |
10 | #include "event.h" | 12 | #include "event.h" |
11 | #include "symbol.h" | 13 | #include "symbol.h" |
@@ -37,3 +39,23 @@ struct perf_event_ops build_id__mark_dso_hit_ops = { | |||
37 | .mmap = event__process_mmap, | 39 | .mmap = event__process_mmap, |
38 | .fork = event__process_task, | 40 | .fork = event__process_task, |
39 | }; | 41 | }; |
42 | |||
43 | char *dso__build_id_filename(struct dso *self, char *bf, size_t size) | ||
44 | { | ||
45 | char build_id_hex[BUILD_ID_SIZE * 2 + 1]; | ||
46 | const char *home; | ||
47 | |||
48 | if (!self->has_build_id) | ||
49 | return NULL; | ||
50 | |||
51 | build_id__sprintf(self->build_id, sizeof(self->build_id), build_id_hex); | ||
52 | home = getenv("HOME"); | ||
53 | if (bf == NULL) { | ||
54 | if (asprintf(&bf, "%s/%s/.build-id/%.2s/%s", home, | ||
55 | DEBUG_CACHE_DIR, build_id_hex, build_id_hex + 2) < 0) | ||
56 | return NULL; | ||
57 | } else | ||
58 | snprintf(bf, size, "%s/%s/.build-id/%.2s/%s", home, | ||
59 | DEBUG_CACHE_DIR, build_id_hex, build_id_hex + 2); | ||
60 | return bf; | ||
61 | } | ||
diff --git a/tools/perf/util/build-id.h b/tools/perf/util/build-id.h index 1d981d63cf9a..5dafb00eaa06 100644 --- a/tools/perf/util/build-id.h +++ b/tools/perf/util/build-id.h | |||
@@ -5,4 +5,6 @@ | |||
5 | 5 | ||
6 | extern struct perf_event_ops build_id__mark_dso_hit_ops; | 6 | extern struct perf_event_ops build_id__mark_dso_hit_ops; |
7 | 7 | ||
8 | char *dso__build_id_filename(struct dso *self, char *bf, size_t size); | ||
9 | |||
8 | #endif | 10 | #endif |
diff --git a/tools/perf/util/cache.h b/tools/perf/util/cache.h index 4b9aab7f0405..65fe664fddf6 100644 --- a/tools/perf/util/cache.h +++ b/tools/perf/util/cache.h | |||
@@ -13,56 +13,16 @@ | |||
13 | 13 | ||
14 | #define PERF_DIR_ENVIRONMENT "PERF_DIR" | 14 | #define PERF_DIR_ENVIRONMENT "PERF_DIR" |
15 | #define PERF_WORK_TREE_ENVIRONMENT "PERF_WORK_TREE" | 15 | #define PERF_WORK_TREE_ENVIRONMENT "PERF_WORK_TREE" |
16 | #define DEFAULT_PERF_DIR_ENVIRONMENT ".perf" | ||
17 | #define DB_ENVIRONMENT "PERF_OBJECT_DIRECTORY" | ||
18 | #define INDEX_ENVIRONMENT "PERF_INDEX_FILE" | ||
19 | #define GRAFT_ENVIRONMENT "PERF_GRAFT_FILE" | ||
20 | #define TEMPLATE_DIR_ENVIRONMENT "PERF_TEMPLATE_DIR" | ||
21 | #define CONFIG_ENVIRONMENT "PERF_CONFIG" | ||
22 | #define EXEC_PATH_ENVIRONMENT "PERF_EXEC_PATH" | 16 | #define EXEC_PATH_ENVIRONMENT "PERF_EXEC_PATH" |
23 | #define CEILING_DIRECTORIES_ENVIRONMENT "PERF_CEILING_DIRECTORIES" | 17 | #define DEFAULT_PERF_DIR_ENVIRONMENT ".perf" |
24 | #define PERFATTRIBUTES_FILE ".perfattributes" | ||
25 | #define INFOATTRIBUTES_FILE "info/attributes" | ||
26 | #define ATTRIBUTE_MACRO_PREFIX "[attr]" | ||
27 | #define PERF_DEBUGFS_ENVIRONMENT "PERF_DEBUGFS_DIR" | 18 | #define PERF_DEBUGFS_ENVIRONMENT "PERF_DEBUGFS_DIR" |
28 | 19 | ||
29 | typedef int (*config_fn_t)(const char *, const char *, void *); | 20 | typedef int (*config_fn_t)(const char *, const char *, void *); |
30 | extern int perf_default_config(const char *, const char *, void *); | 21 | extern int perf_default_config(const char *, const char *, void *); |
31 | extern int perf_config_from_file(config_fn_t fn, const char *, void *); | ||
32 | extern int perf_config(config_fn_t fn, void *); | 22 | extern int perf_config(config_fn_t fn, void *); |
33 | extern int perf_parse_ulong(const char *, unsigned long *); | ||
34 | extern int perf_config_int(const char *, const char *); | 23 | extern int perf_config_int(const char *, const char *); |
35 | extern unsigned long perf_config_ulong(const char *, const char *); | ||
36 | extern int perf_config_bool_or_int(const char *, const char *, int *); | ||
37 | extern int perf_config_bool(const char *, const char *); | 24 | extern int perf_config_bool(const char *, const char *); |
38 | extern int perf_config_string(const char **, const char *, const char *); | ||
39 | extern int perf_config_set(const char *, const char *); | ||
40 | extern int perf_config_set_multivar(const char *, const char *, const char *, int); | ||
41 | extern int perf_config_rename_section(const char *, const char *); | ||
42 | extern const char *perf_etc_perfconfig(void); | ||
43 | extern int check_repository_format_version(const char *var, const char *value, void *cb); | ||
44 | extern int perf_config_system(void); | ||
45 | extern int perf_config_global(void); | ||
46 | extern int config_error_nonbool(const char *); | 25 | extern int config_error_nonbool(const char *); |
47 | extern const char *config_exclusive_filename; | ||
48 | |||
49 | #define MAX_PERFNAME (1000) | ||
50 | extern char perf_default_email[MAX_PERFNAME]; | ||
51 | extern char perf_default_name[MAX_PERFNAME]; | ||
52 | extern int user_ident_explicitly_given; | ||
53 | |||
54 | extern const char *perf_log_output_encoding; | ||
55 | extern const char *perf_mailmap_file; | ||
56 | |||
57 | /* IO helper functions */ | ||
58 | extern void maybe_flush_or_die(FILE *, const char *); | ||
59 | extern int copy_fd(int ifd, int ofd); | ||
60 | extern int copy_file(const char *dst, const char *src, int mode); | ||
61 | extern ssize_t write_in_full(int fd, const void *buf, size_t count); | ||
62 | extern void write_or_die(int fd, const void *buf, size_t count); | ||
63 | extern int write_or_whine(int fd, const void *buf, size_t count, const char *msg); | ||
64 | extern int write_or_whine_pipe(int fd, const void *buf, size_t count, const char *msg); | ||
65 | extern void fsync_or_die(int fd, const char *); | ||
66 | 26 | ||
67 | /* pager.c */ | 27 | /* pager.c */ |
68 | extern void setup_pager(void); | 28 | extern void setup_pager(void); |
@@ -70,7 +30,7 @@ extern const char *pager_program; | |||
70 | extern int pager_in_use(void); | 30 | extern int pager_in_use(void); |
71 | extern int pager_use_color; | 31 | extern int pager_use_color; |
72 | 32 | ||
73 | extern bool use_browser; | 33 | extern int use_browser; |
74 | 34 | ||
75 | #ifdef NO_NEWT_SUPPORT | 35 | #ifdef NO_NEWT_SUPPORT |
76 | static inline void setup_browser(void) | 36 | static inline void setup_browser(void) |
@@ -83,9 +43,6 @@ void setup_browser(void); | |||
83 | void exit_browser(bool wait_for_ok); | 43 | void exit_browser(bool wait_for_ok); |
84 | #endif | 44 | #endif |
85 | 45 | ||
86 | extern const char *editor_program; | ||
87 | extern const char *excludes_file; | ||
88 | |||
89 | char *alias_lookup(const char *alias); | 46 | char *alias_lookup(const char *alias); |
90 | int split_cmdline(char *cmdline, const char ***argv); | 47 | int split_cmdline(char *cmdline, const char ***argv); |
91 | 48 | ||
@@ -115,22 +72,12 @@ static inline int is_absolute_path(const char *path) | |||
115 | return path[0] == '/'; | 72 | return path[0] == '/'; |
116 | } | 73 | } |
117 | 74 | ||
118 | const char *make_absolute_path(const char *path); | ||
119 | const char *make_nonrelative_path(const char *path); | 75 | const char *make_nonrelative_path(const char *path); |
120 | const char *make_relative_path(const char *abs, const char *base); | ||
121 | int normalize_path_copy(char *dst, const char *src); | ||
122 | int longest_ancestor_length(const char *path, const char *prefix_list); | ||
123 | char *strip_path_suffix(const char *path, const char *suffix); | 76 | char *strip_path_suffix(const char *path, const char *suffix); |
124 | 77 | ||
125 | extern char *mkpath(const char *fmt, ...) __attribute__((format (printf, 1, 2))); | 78 | extern char *mkpath(const char *fmt, ...) __attribute__((format (printf, 1, 2))); |
126 | extern char *perf_path(const char *fmt, ...) __attribute__((format (printf, 1, 2))); | 79 | extern char *perf_path(const char *fmt, ...) __attribute__((format (printf, 1, 2))); |
127 | /* perf_mkstemp() - create tmp file honoring TMPDIR variable */ | ||
128 | extern int perf_mkstemp(char *path, size_t len, const char *template); | ||
129 | 80 | ||
130 | extern char *mksnpath(char *buf, size_t n, const char *fmt, ...) | ||
131 | __attribute__((format (printf, 3, 4))); | ||
132 | extern char *perf_snpath(char *buf, size_t n, const char *fmt, ...) | ||
133 | __attribute__((format (printf, 3, 4))); | ||
134 | extern char *perf_pathdup(const char *fmt, ...) | 81 | extern char *perf_pathdup(const char *fmt, ...) |
135 | __attribute__((format (printf, 1, 2))); | 82 | __attribute__((format (printf, 1, 2))); |
136 | 83 | ||
diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c index 21a52e0a4435..62b69ad4aa73 100644 --- a/tools/perf/util/callchain.c +++ b/tools/perf/util/callchain.c | |||
@@ -15,6 +15,7 @@ | |||
15 | #include <errno.h> | 15 | #include <errno.h> |
16 | #include <math.h> | 16 | #include <math.h> |
17 | 17 | ||
18 | #include "util.h" | ||
18 | #include "callchain.h" | 19 | #include "callchain.h" |
19 | 20 | ||
20 | bool ip_callchain__valid(struct ip_callchain *chain, event_t *event) | 21 | bool ip_callchain__valid(struct ip_callchain *chain, event_t *event) |
diff --git a/tools/perf/util/callchain.h b/tools/perf/util/callchain.h index 1cba1f5504e7..1ca73e4a2723 100644 --- a/tools/perf/util/callchain.h +++ b/tools/perf/util/callchain.h | |||
@@ -5,7 +5,6 @@ | |||
5 | #include <linux/list.h> | 5 | #include <linux/list.h> |
6 | #include <linux/rbtree.h> | 6 | #include <linux/rbtree.h> |
7 | #include "event.h" | 7 | #include "event.h" |
8 | #include "util.h" | ||
9 | #include "symbol.h" | 8 | #include "symbol.h" |
10 | 9 | ||
11 | enum chain_mode { | 10 | enum chain_mode { |
diff --git a/tools/perf/util/config.c b/tools/perf/util/config.c index 8784649109ce..dabe892d0e53 100644 --- a/tools/perf/util/config.c +++ b/tools/perf/util/config.c | |||
@@ -16,7 +16,7 @@ static const char *config_file_name; | |||
16 | static int config_linenr; | 16 | static int config_linenr; |
17 | static int config_file_eof; | 17 | static int config_file_eof; |
18 | 18 | ||
19 | const char *config_exclusive_filename = NULL; | 19 | static const char *config_exclusive_filename; |
20 | 20 | ||
21 | static int get_next_char(void) | 21 | static int get_next_char(void) |
22 | { | 22 | { |
@@ -291,19 +291,6 @@ static int perf_parse_long(const char *value, long *ret) | |||
291 | return 0; | 291 | return 0; |
292 | } | 292 | } |
293 | 293 | ||
294 | int perf_parse_ulong(const char *value, unsigned long *ret) | ||
295 | { | ||
296 | if (value && *value) { | ||
297 | char *end; | ||
298 | unsigned long val = strtoul(value, &end, 0); | ||
299 | if (!parse_unit_factor(end, &val)) | ||
300 | return 0; | ||
301 | *ret = val; | ||
302 | return 1; | ||
303 | } | ||
304 | return 0; | ||
305 | } | ||
306 | |||
307 | static void die_bad_config(const char *name) | 294 | static void die_bad_config(const char *name) |
308 | { | 295 | { |
309 | if (config_file_name) | 296 | if (config_file_name) |
@@ -319,15 +306,7 @@ int perf_config_int(const char *name, const char *value) | |||
319 | return ret; | 306 | return ret; |
320 | } | 307 | } |
321 | 308 | ||
322 | unsigned long perf_config_ulong(const char *name, const char *value) | 309 | static int perf_config_bool_or_int(const char *name, const char *value, int *is_bool) |
323 | { | ||
324 | unsigned long ret; | ||
325 | if (!perf_parse_ulong(value, &ret)) | ||
326 | die_bad_config(name); | ||
327 | return ret; | ||
328 | } | ||
329 | |||
330 | int perf_config_bool_or_int(const char *name, const char *value, int *is_bool) | ||
331 | { | 310 | { |
332 | *is_bool = 1; | 311 | *is_bool = 1; |
333 | if (!value) | 312 | if (!value) |
@@ -348,14 +327,6 @@ int perf_config_bool(const char *name, const char *value) | |||
348 | return !!perf_config_bool_or_int(name, value, &discard); | 327 | return !!perf_config_bool_or_int(name, value, &discard); |
349 | } | 328 | } |
350 | 329 | ||
351 | int perf_config_string(const char **dest, const char *var, const char *value) | ||
352 | { | ||
353 | if (!value) | ||
354 | return config_error_nonbool(var); | ||
355 | *dest = strdup(value); | ||
356 | return 0; | ||
357 | } | ||
358 | |||
359 | static int perf_default_core_config(const char *var __used, const char *value __used) | 330 | static int perf_default_core_config(const char *var __used, const char *value __used) |
360 | { | 331 | { |
361 | /* Add other config variables here and to Documentation/config.txt. */ | 332 | /* Add other config variables here and to Documentation/config.txt. */ |
@@ -371,7 +342,7 @@ int perf_default_config(const char *var, const char *value, void *dummy __used) | |||
371 | return 0; | 342 | return 0; |
372 | } | 343 | } |
373 | 344 | ||
374 | int perf_config_from_file(config_fn_t fn, const char *filename, void *data) | 345 | static int perf_config_from_file(config_fn_t fn, const char *filename, void *data) |
375 | { | 346 | { |
376 | int ret; | 347 | int ret; |
377 | FILE *f = fopen(filename, "r"); | 348 | FILE *f = fopen(filename, "r"); |
@@ -389,7 +360,7 @@ int perf_config_from_file(config_fn_t fn, const char *filename, void *data) | |||
389 | return ret; | 360 | return ret; |
390 | } | 361 | } |
391 | 362 | ||
392 | const char *perf_etc_perfconfig(void) | 363 | static const char *perf_etc_perfconfig(void) |
393 | { | 364 | { |
394 | static const char *system_wide; | 365 | static const char *system_wide; |
395 | if (!system_wide) | 366 | if (!system_wide) |
@@ -403,12 +374,12 @@ static int perf_env_bool(const char *k, int def) | |||
403 | return v ? perf_config_bool(k, v) : def; | 374 | return v ? perf_config_bool(k, v) : def; |
404 | } | 375 | } |
405 | 376 | ||
406 | int perf_config_system(void) | 377 | static int perf_config_system(void) |
407 | { | 378 | { |
408 | return !perf_env_bool("PERF_CONFIG_NOSYSTEM", 0); | 379 | return !perf_env_bool("PERF_CONFIG_NOSYSTEM", 0); |
409 | } | 380 | } |
410 | 381 | ||
411 | int perf_config_global(void) | 382 | static int perf_config_global(void) |
412 | { | 383 | { |
413 | return !perf_env_bool("PERF_CONFIG_NOGLOBAL", 0); | 384 | return !perf_env_bool("PERF_CONFIG_NOGLOBAL", 0); |
414 | } | 385 | } |
@@ -450,426 +421,6 @@ int perf_config(config_fn_t fn, void *data) | |||
450 | } | 421 | } |
451 | 422 | ||
452 | /* | 423 | /* |
453 | * Find all the stuff for perf_config_set() below. | ||
454 | */ | ||
455 | |||
456 | #define MAX_MATCHES 512 | ||
457 | |||
458 | static struct { | ||
459 | int baselen; | ||
460 | char* key; | ||
461 | int do_not_match; | ||
462 | regex_t* value_regex; | ||
463 | int multi_replace; | ||
464 | size_t offset[MAX_MATCHES]; | ||
465 | enum { START, SECTION_SEEN, SECTION_END_SEEN, KEY_SEEN } state; | ||
466 | int seen; | ||
467 | } store; | ||
468 | |||
469 | static int matches(const char* key, const char* value) | ||
470 | { | ||
471 | return !strcmp(key, store.key) && | ||
472 | (store.value_regex == NULL || | ||
473 | (store.do_not_match ^ | ||
474 | !regexec(store.value_regex, value, 0, NULL, 0))); | ||
475 | } | ||
476 | |||
477 | static int store_aux(const char* key, const char* value, void *cb __used) | ||
478 | { | ||
479 | int section_len; | ||
480 | const char *ep; | ||
481 | |||
482 | switch (store.state) { | ||
483 | case KEY_SEEN: | ||
484 | if (matches(key, value)) { | ||
485 | if (store.seen == 1 && store.multi_replace == 0) { | ||
486 | warning("%s has multiple values", key); | ||
487 | } else if (store.seen >= MAX_MATCHES) { | ||
488 | error("too many matches for %s", key); | ||
489 | return 1; | ||
490 | } | ||
491 | |||
492 | store.offset[store.seen] = ftell(config_file); | ||
493 | store.seen++; | ||
494 | } | ||
495 | break; | ||
496 | case SECTION_SEEN: | ||
497 | /* | ||
498 | * What we are looking for is in store.key (both | ||
499 | * section and var), and its section part is baselen | ||
500 | * long. We found key (again, both section and var). | ||
501 | * We would want to know if this key is in the same | ||
502 | * section as what we are looking for. We already | ||
503 | * know we are in the same section as what should | ||
504 | * hold store.key. | ||
505 | */ | ||
506 | ep = strrchr(key, '.'); | ||
507 | section_len = ep - key; | ||
508 | |||
509 | if ((section_len != store.baselen) || | ||
510 | memcmp(key, store.key, section_len+1)) { | ||
511 | store.state = SECTION_END_SEEN; | ||
512 | break; | ||
513 | } | ||
514 | |||
515 | /* | ||
516 | * Do not increment matches: this is no match, but we | ||
517 | * just made sure we are in the desired section. | ||
518 | */ | ||
519 | store.offset[store.seen] = ftell(config_file); | ||
520 | /* fallthru */ | ||
521 | case SECTION_END_SEEN: | ||
522 | case START: | ||
523 | if (matches(key, value)) { | ||
524 | store.offset[store.seen] = ftell(config_file); | ||
525 | store.state = KEY_SEEN; | ||
526 | store.seen++; | ||
527 | } else { | ||
528 | if (strrchr(key, '.') - key == store.baselen && | ||
529 | !strncmp(key, store.key, store.baselen)) { | ||
530 | store.state = SECTION_SEEN; | ||
531 | store.offset[store.seen] = ftell(config_file); | ||
532 | } | ||
533 | } | ||
534 | default: | ||
535 | break; | ||
536 | } | ||
537 | return 0; | ||
538 | } | ||
539 | |||
540 | static int store_write_section(int fd, const char* key) | ||
541 | { | ||
542 | const char *dot; | ||
543 | int i, success; | ||
544 | struct strbuf sb = STRBUF_INIT; | ||
545 | |||
546 | dot = memchr(key, '.', store.baselen); | ||
547 | if (dot) { | ||
548 | strbuf_addf(&sb, "[%.*s \"", (int)(dot - key), key); | ||
549 | for (i = dot - key + 1; i < store.baselen; i++) { | ||
550 | if (key[i] == '"' || key[i] == '\\') | ||
551 | strbuf_addch(&sb, '\\'); | ||
552 | strbuf_addch(&sb, key[i]); | ||
553 | } | ||
554 | strbuf_addstr(&sb, "\"]\n"); | ||
555 | } else { | ||
556 | strbuf_addf(&sb, "[%.*s]\n", store.baselen, key); | ||
557 | } | ||
558 | |||
559 | success = (write_in_full(fd, sb.buf, sb.len) == (ssize_t)sb.len); | ||
560 | strbuf_release(&sb); | ||
561 | |||
562 | return success; | ||
563 | } | ||
564 | |||
565 | static int store_write_pair(int fd, const char* key, const char* value) | ||
566 | { | ||
567 | int i, success; | ||
568 | int length = strlen(key + store.baselen + 1); | ||
569 | const char *quote = ""; | ||
570 | struct strbuf sb = STRBUF_INIT; | ||
571 | |||
572 | /* | ||
573 | * Check to see if the value needs to be surrounded with a dq pair. | ||
574 | * Note that problematic characters are always backslash-quoted; this | ||
575 | * check is about not losing leading or trailing SP and strings that | ||
576 | * follow beginning-of-comment characters (i.e. ';' and '#') by the | ||
577 | * configuration parser. | ||
578 | */ | ||
579 | if (value[0] == ' ') | ||
580 | quote = "\""; | ||
581 | for (i = 0; value[i]; i++) | ||
582 | if (value[i] == ';' || value[i] == '#') | ||
583 | quote = "\""; | ||
584 | if (i && value[i - 1] == ' ') | ||
585 | quote = "\""; | ||
586 | |||
587 | strbuf_addf(&sb, "\t%.*s = %s", | ||
588 | length, key + store.baselen + 1, quote); | ||
589 | |||
590 | for (i = 0; value[i]; i++) | ||
591 | switch (value[i]) { | ||
592 | case '\n': | ||
593 | strbuf_addstr(&sb, "\\n"); | ||
594 | break; | ||
595 | case '\t': | ||
596 | strbuf_addstr(&sb, "\\t"); | ||
597 | break; | ||
598 | case '"': | ||
599 | case '\\': | ||
600 | strbuf_addch(&sb, '\\'); | ||
601 | default: | ||
602 | strbuf_addch(&sb, value[i]); | ||
603 | break; | ||
604 | } | ||
605 | strbuf_addf(&sb, "%s\n", quote); | ||
606 | |||
607 | success = (write_in_full(fd, sb.buf, sb.len) == (ssize_t)sb.len); | ||
608 | strbuf_release(&sb); | ||
609 | |||
610 | return success; | ||
611 | } | ||
612 | |||
613 | static ssize_t find_beginning_of_line(const char* contents, size_t size, | ||
614 | size_t offset_, int* found_bracket) | ||
615 | { | ||
616 | size_t equal_offset = size, bracket_offset = size; | ||
617 | ssize_t offset; | ||
618 | |||
619 | contline: | ||
620 | for (offset = offset_-2; offset > 0 | ||
621 | && contents[offset] != '\n'; offset--) | ||
622 | switch (contents[offset]) { | ||
623 | case '=': equal_offset = offset; break; | ||
624 | case ']': bracket_offset = offset; break; | ||
625 | default: break; | ||
626 | } | ||
627 | if (offset > 0 && contents[offset-1] == '\\') { | ||
628 | offset_ = offset; | ||
629 | goto contline; | ||
630 | } | ||
631 | if (bracket_offset < equal_offset) { | ||
632 | *found_bracket = 1; | ||
633 | offset = bracket_offset+1; | ||
634 | } else | ||
635 | offset++; | ||
636 | |||
637 | return offset; | ||
638 | } | ||
639 | |||
640 | int perf_config_set(const char* key, const char* value) | ||
641 | { | ||
642 | return perf_config_set_multivar(key, value, NULL, 0); | ||
643 | } | ||
644 | |||
645 | /* | ||
646 | * If value==NULL, unset in (remove from) config, | ||
647 | * if value_regex!=NULL, disregard key/value pairs where value does not match. | ||
648 | * if multi_replace==0, nothing, or only one matching key/value is replaced, | ||
649 | * else all matching key/values (regardless how many) are removed, | ||
650 | * before the new pair is written. | ||
651 | * | ||
652 | * Returns 0 on success. | ||
653 | * | ||
654 | * This function does this: | ||
655 | * | ||
656 | * - it locks the config file by creating ".perf/config.lock" | ||
657 | * | ||
658 | * - it then parses the config using store_aux() as validator to find | ||
659 | * the position on the key/value pair to replace. If it is to be unset, | ||
660 | * it must be found exactly once. | ||
661 | * | ||
662 | * - the config file is mmap()ed and the part before the match (if any) is | ||
663 | * written to the lock file, then the changed part and the rest. | ||
664 | * | ||
665 | * - the config file is removed and the lock file rename()d to it. | ||
666 | * | ||
667 | */ | ||
668 | int perf_config_set_multivar(const char* key, const char* value, | ||
669 | const char* value_regex, int multi_replace) | ||
670 | { | ||
671 | int i, dot; | ||
672 | int fd = -1, in_fd; | ||
673 | int ret = 0; | ||
674 | char* config_filename; | ||
675 | const char* last_dot = strrchr(key, '.'); | ||
676 | |||
677 | if (config_exclusive_filename) | ||
678 | config_filename = strdup(config_exclusive_filename); | ||
679 | else | ||
680 | config_filename = perf_pathdup("config"); | ||
681 | |||
682 | /* | ||
683 | * Since "key" actually contains the section name and the real | ||
684 | * key name separated by a dot, we have to know where the dot is. | ||
685 | */ | ||
686 | |||
687 | if (last_dot == NULL) { | ||
688 | error("key does not contain a section: %s", key); | ||
689 | ret = 2; | ||
690 | goto out_free; | ||
691 | } | ||
692 | store.baselen = last_dot - key; | ||
693 | |||
694 | store.multi_replace = multi_replace; | ||
695 | |||
696 | /* | ||
697 | * Validate the key and while at it, lower case it for matching. | ||
698 | */ | ||
699 | store.key = malloc(strlen(key) + 1); | ||
700 | dot = 0; | ||
701 | for (i = 0; key[i]; i++) { | ||
702 | unsigned char c = key[i]; | ||
703 | if (c == '.') | ||
704 | dot = 1; | ||
705 | /* Leave the extended basename untouched.. */ | ||
706 | if (!dot || i > store.baselen) { | ||
707 | if (!iskeychar(c) || (i == store.baselen+1 && !isalpha(c))) { | ||
708 | error("invalid key: %s", key); | ||
709 | free(store.key); | ||
710 | ret = 1; | ||
711 | goto out_free; | ||
712 | } | ||
713 | c = tolower(c); | ||
714 | } else if (c == '\n') { | ||
715 | error("invalid key (newline): %s", key); | ||
716 | free(store.key); | ||
717 | ret = 1; | ||
718 | goto out_free; | ||
719 | } | ||
720 | store.key[i] = c; | ||
721 | } | ||
722 | store.key[i] = 0; | ||
723 | |||
724 | /* | ||
725 | * If .perf/config does not exist yet, write a minimal version. | ||
726 | */ | ||
727 | in_fd = open(config_filename, O_RDONLY); | ||
728 | if ( in_fd < 0 ) { | ||
729 | free(store.key); | ||
730 | |||
731 | if ( ENOENT != errno ) { | ||
732 | error("opening %s: %s", config_filename, | ||
733 | strerror(errno)); | ||
734 | ret = 3; /* same as "invalid config file" */ | ||
735 | goto out_free; | ||
736 | } | ||
737 | /* if nothing to unset, error out */ | ||
738 | if (value == NULL) { | ||
739 | ret = 5; | ||
740 | goto out_free; | ||
741 | } | ||
742 | |||
743 | store.key = (char*)key; | ||
744 | if (!store_write_section(fd, key) || | ||
745 | !store_write_pair(fd, key, value)) | ||
746 | goto write_err_out; | ||
747 | } else { | ||
748 | struct stat st; | ||
749 | char *contents; | ||
750 | ssize_t contents_sz, copy_begin, copy_end; | ||
751 | int new_line = 0; | ||
752 | |||
753 | if (value_regex == NULL) | ||
754 | store.value_regex = NULL; | ||
755 | else { | ||
756 | if (value_regex[0] == '!') { | ||
757 | store.do_not_match = 1; | ||
758 | value_regex++; | ||
759 | } else | ||
760 | store.do_not_match = 0; | ||
761 | |||
762 | store.value_regex = (regex_t*)malloc(sizeof(regex_t)); | ||
763 | if (regcomp(store.value_regex, value_regex, | ||
764 | REG_EXTENDED)) { | ||
765 | error("invalid pattern: %s", value_regex); | ||
766 | free(store.value_regex); | ||
767 | ret = 6; | ||
768 | goto out_free; | ||
769 | } | ||
770 | } | ||
771 | |||
772 | store.offset[0] = 0; | ||
773 | store.state = START; | ||
774 | store.seen = 0; | ||
775 | |||
776 | /* | ||
777 | * After this, store.offset will contain the *end* offset | ||
778 | * of the last match, or remain at 0 if no match was found. | ||
779 | * As a side effect, we make sure to transform only a valid | ||
780 | * existing config file. | ||
781 | */ | ||
782 | if (perf_config_from_file(store_aux, config_filename, NULL)) { | ||
783 | error("invalid config file %s", config_filename); | ||
784 | free(store.key); | ||
785 | if (store.value_regex != NULL) { | ||
786 | regfree(store.value_regex); | ||
787 | free(store.value_regex); | ||
788 | } | ||
789 | ret = 3; | ||
790 | goto out_free; | ||
791 | } | ||
792 | |||
793 | free(store.key); | ||
794 | if (store.value_regex != NULL) { | ||
795 | regfree(store.value_regex); | ||
796 | free(store.value_regex); | ||
797 | } | ||
798 | |||
799 | /* if nothing to unset, or too many matches, error out */ | ||
800 | if ((store.seen == 0 && value == NULL) || | ||
801 | (store.seen > 1 && multi_replace == 0)) { | ||
802 | ret = 5; | ||
803 | goto out_free; | ||
804 | } | ||
805 | |||
806 | fstat(in_fd, &st); | ||
807 | contents_sz = xsize_t(st.st_size); | ||
808 | contents = mmap(NULL, contents_sz, PROT_READ, | ||
809 | MAP_PRIVATE, in_fd, 0); | ||
810 | close(in_fd); | ||
811 | |||
812 | if (store.seen == 0) | ||
813 | store.seen = 1; | ||
814 | |||
815 | for (i = 0, copy_begin = 0; i < store.seen; i++) { | ||
816 | if (store.offset[i] == 0) { | ||
817 | store.offset[i] = copy_end = contents_sz; | ||
818 | } else if (store.state != KEY_SEEN) { | ||
819 | copy_end = store.offset[i]; | ||
820 | } else | ||
821 | copy_end = find_beginning_of_line( | ||
822 | contents, contents_sz, | ||
823 | store.offset[i]-2, &new_line); | ||
824 | |||
825 | if (copy_end > 0 && contents[copy_end-1] != '\n') | ||
826 | new_line = 1; | ||
827 | |||
828 | /* write the first part of the config */ | ||
829 | if (copy_end > copy_begin) { | ||
830 | if (write_in_full(fd, contents + copy_begin, | ||
831 | copy_end - copy_begin) < | ||
832 | copy_end - copy_begin) | ||
833 | goto write_err_out; | ||
834 | if (new_line && | ||
835 | write_in_full(fd, "\n", 1) != 1) | ||
836 | goto write_err_out; | ||
837 | } | ||
838 | copy_begin = store.offset[i]; | ||
839 | } | ||
840 | |||
841 | /* write the pair (value == NULL means unset) */ | ||
842 | if (value != NULL) { | ||
843 | if (store.state == START) { | ||
844 | if (!store_write_section(fd, key)) | ||
845 | goto write_err_out; | ||
846 | } | ||
847 | if (!store_write_pair(fd, key, value)) | ||
848 | goto write_err_out; | ||
849 | } | ||
850 | |||
851 | /* write the rest of the config */ | ||
852 | if (copy_begin < contents_sz) | ||
853 | if (write_in_full(fd, contents + copy_begin, | ||
854 | contents_sz - copy_begin) < | ||
855 | contents_sz - copy_begin) | ||
856 | goto write_err_out; | ||
857 | |||
858 | munmap(contents, contents_sz); | ||
859 | } | ||
860 | |||
861 | ret = 0; | ||
862 | |||
863 | out_free: | ||
864 | free(config_filename); | ||
865 | return ret; | ||
866 | |||
867 | write_err_out: | ||
868 | goto out_free; | ||
869 | |||
870 | } | ||
871 | |||
872 | /* | ||
873 | * Call this to report error for your variable that should not | 424 | * Call this to report error for your variable that should not |
874 | * get a boolean value (i.e. "[my] var" means "true"). | 425 | * get a boolean value (i.e. "[my] var" means "true"). |
875 | */ | 426 | */ |
diff --git a/tools/perf/util/exec_cmd.c b/tools/perf/util/exec_cmd.c index 2745605dba11..67eeff571568 100644 --- a/tools/perf/util/exec_cmd.c +++ b/tools/perf/util/exec_cmd.c | |||
@@ -53,8 +53,8 @@ const char *perf_extract_argv0_path(const char *argv0) | |||
53 | slash--; | 53 | slash--; |
54 | 54 | ||
55 | if (slash >= argv0) { | 55 | if (slash >= argv0) { |
56 | argv0_path = xstrndup(argv0, slash - argv0); | 56 | argv0_path = strndup(argv0, slash - argv0); |
57 | return slash + 1; | 57 | return argv0_path ? slash + 1 : NULL; |
58 | } | 58 | } |
59 | 59 | ||
60 | return argv0; | 60 | return argv0; |
@@ -116,7 +116,7 @@ void setup_path(void) | |||
116 | strbuf_release(&new_path); | 116 | strbuf_release(&new_path); |
117 | } | 117 | } |
118 | 118 | ||
119 | const char **prepare_perf_cmd(const char **argv) | 119 | static const char **prepare_perf_cmd(const char **argv) |
120 | { | 120 | { |
121 | int argc; | 121 | int argc; |
122 | const char **nargv; | 122 | const char **nargv; |
diff --git a/tools/perf/util/exec_cmd.h b/tools/perf/util/exec_cmd.h index 31647ac92ed1..bc4b915963f5 100644 --- a/tools/perf/util/exec_cmd.h +++ b/tools/perf/util/exec_cmd.h | |||
@@ -5,7 +5,6 @@ extern void perf_set_argv_exec_path(const char *exec_path); | |||
5 | extern const char *perf_extract_argv0_path(const char *path); | 5 | extern const char *perf_extract_argv0_path(const char *path); |
6 | extern const char *perf_exec_path(void); | 6 | extern const char *perf_exec_path(void); |
7 | extern void setup_path(void); | 7 | extern void setup_path(void); |
8 | extern const char **prepare_perf_cmd(const char **argv); | ||
9 | extern int execv_perf_cmd(const char **argv); /* NULL terminated */ | 8 | extern int execv_perf_cmd(const char **argv); /* NULL terminated */ |
10 | extern int execl_perf_cmd(const char *cmd, ...); | 9 | extern int execl_perf_cmd(const char *cmd, ...); |
11 | extern const char *system_path(const char *path); | 10 | extern const char *system_path(const char *path); |
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 8847bec64c54..1f62435f96c2 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c | |||
@@ -221,29 +221,38 @@ static int __dsos__write_buildid_table(struct list_head *head, pid_t pid, | |||
221 | return 0; | 221 | return 0; |
222 | } | 222 | } |
223 | 223 | ||
224 | static int machine__write_buildid_table(struct machine *self, int fd) | ||
225 | { | ||
226 | int err; | ||
227 | u16 kmisc = PERF_RECORD_MISC_KERNEL, | ||
228 | umisc = PERF_RECORD_MISC_USER; | ||
229 | |||
230 | if (!machine__is_host(self)) { | ||
231 | kmisc = PERF_RECORD_MISC_GUEST_KERNEL; | ||
232 | umisc = PERF_RECORD_MISC_GUEST_USER; | ||
233 | } | ||
234 | |||
235 | err = __dsos__write_buildid_table(&self->kernel_dsos, self->pid, | ||
236 | kmisc, fd); | ||
237 | if (err == 0) | ||
238 | err = __dsos__write_buildid_table(&self->user_dsos, | ||
239 | self->pid, umisc, fd); | ||
240 | return err; | ||
241 | } | ||
242 | |||
224 | static int dsos__write_buildid_table(struct perf_header *header, int fd) | 243 | static int dsos__write_buildid_table(struct perf_header *header, int fd) |
225 | { | 244 | { |
226 | struct perf_session *session = container_of(header, | 245 | struct perf_session *session = container_of(header, |
227 | struct perf_session, header); | 246 | struct perf_session, header); |
228 | struct rb_node *nd; | 247 | struct rb_node *nd; |
229 | int err = 0; | 248 | int err = machine__write_buildid_table(&session->host_machine, fd); |
230 | u16 kmisc, umisc; | 249 | |
250 | if (err) | ||
251 | return err; | ||
231 | 252 | ||
232 | for (nd = rb_first(&session->machines); nd; nd = rb_next(nd)) { | 253 | for (nd = rb_first(&session->machines); nd; nd = rb_next(nd)) { |
233 | struct machine *pos = rb_entry(nd, struct machine, rb_node); | 254 | struct machine *pos = rb_entry(nd, struct machine, rb_node); |
234 | if (machine__is_host(pos)) { | 255 | err = machine__write_buildid_table(pos, fd); |
235 | kmisc = PERF_RECORD_MISC_KERNEL; | ||
236 | umisc = PERF_RECORD_MISC_USER; | ||
237 | } else { | ||
238 | kmisc = PERF_RECORD_MISC_GUEST_KERNEL; | ||
239 | umisc = PERF_RECORD_MISC_GUEST_USER; | ||
240 | } | ||
241 | |||
242 | err = __dsos__write_buildid_table(&pos->kernel_dsos, pos->pid, | ||
243 | kmisc, fd); | ||
244 | if (err == 0) | ||
245 | err = __dsos__write_buildid_table(&pos->user_dsos, | ||
246 | pos->pid, umisc, fd); | ||
247 | if (err) | 256 | if (err) |
248 | break; | 257 | break; |
249 | } | 258 | } |
@@ -363,12 +372,17 @@ static int __dsos__cache_build_ids(struct list_head *head, const char *debugdir) | |||
363 | return err; | 372 | return err; |
364 | } | 373 | } |
365 | 374 | ||
366 | static int dsos__cache_build_ids(struct perf_header *self) | 375 | static int machine__cache_build_ids(struct machine *self, const char *debugdir) |
376 | { | ||
377 | int ret = __dsos__cache_build_ids(&self->kernel_dsos, debugdir); | ||
378 | ret |= __dsos__cache_build_ids(&self->user_dsos, debugdir); | ||
379 | return ret; | ||
380 | } | ||
381 | |||
382 | static int perf_session__cache_build_ids(struct perf_session *self) | ||
367 | { | 383 | { |
368 | struct perf_session *session = container_of(self, | ||
369 | struct perf_session, header); | ||
370 | struct rb_node *nd; | 384 | struct rb_node *nd; |
371 | int ret = 0; | 385 | int ret; |
372 | char debugdir[PATH_MAX]; | 386 | char debugdir[PATH_MAX]; |
373 | 387 | ||
374 | snprintf(debugdir, sizeof(debugdir), "%s/%s", getenv("HOME"), | 388 | snprintf(debugdir, sizeof(debugdir), "%s/%s", getenv("HOME"), |
@@ -377,25 +391,30 @@ static int dsos__cache_build_ids(struct perf_header *self) | |||
377 | if (mkdir(debugdir, 0755) != 0 && errno != EEXIST) | 391 | if (mkdir(debugdir, 0755) != 0 && errno != EEXIST) |
378 | return -1; | 392 | return -1; |
379 | 393 | ||
380 | for (nd = rb_first(&session->machines); nd; nd = rb_next(nd)) { | 394 | ret = machine__cache_build_ids(&self->host_machine, debugdir); |
395 | |||
396 | for (nd = rb_first(&self->machines); nd; nd = rb_next(nd)) { | ||
381 | struct machine *pos = rb_entry(nd, struct machine, rb_node); | 397 | struct machine *pos = rb_entry(nd, struct machine, rb_node); |
382 | ret |= __dsos__cache_build_ids(&pos->kernel_dsos, debugdir); | 398 | ret |= machine__cache_build_ids(pos, debugdir); |
383 | ret |= __dsos__cache_build_ids(&pos->user_dsos, debugdir); | ||
384 | } | 399 | } |
385 | return ret ? -1 : 0; | 400 | return ret ? -1 : 0; |
386 | } | 401 | } |
387 | 402 | ||
388 | static bool dsos__read_build_ids(struct perf_header *self, bool with_hits) | 403 | static bool machine__read_build_ids(struct machine *self, bool with_hits) |
404 | { | ||
405 | bool ret = __dsos__read_build_ids(&self->kernel_dsos, with_hits); | ||
406 | ret |= __dsos__read_build_ids(&self->user_dsos, with_hits); | ||
407 | return ret; | ||
408 | } | ||
409 | |||
410 | static bool perf_session__read_build_ids(struct perf_session *self, bool with_hits) | ||
389 | { | 411 | { |
390 | bool ret = false; | ||
391 | struct perf_session *session = container_of(self, | ||
392 | struct perf_session, header); | ||
393 | struct rb_node *nd; | 412 | struct rb_node *nd; |
413 | bool ret = machine__read_build_ids(&self->host_machine, with_hits); | ||
394 | 414 | ||
395 | for (nd = rb_first(&session->machines); nd; nd = rb_next(nd)) { | 415 | for (nd = rb_first(&self->machines); nd; nd = rb_next(nd)) { |
396 | struct machine *pos = rb_entry(nd, struct machine, rb_node); | 416 | struct machine *pos = rb_entry(nd, struct machine, rb_node); |
397 | ret |= __dsos__read_build_ids(&pos->kernel_dsos, with_hits); | 417 | ret |= machine__read_build_ids(pos, with_hits); |
398 | ret |= __dsos__read_build_ids(&pos->user_dsos, with_hits); | ||
399 | } | 418 | } |
400 | 419 | ||
401 | return ret; | 420 | return ret; |
@@ -404,12 +423,14 @@ static bool dsos__read_build_ids(struct perf_header *self, bool with_hits) | |||
404 | static int perf_header__adds_write(struct perf_header *self, int fd) | 423 | static int perf_header__adds_write(struct perf_header *self, int fd) |
405 | { | 424 | { |
406 | int nr_sections; | 425 | int nr_sections; |
426 | struct perf_session *session; | ||
407 | struct perf_file_section *feat_sec; | 427 | struct perf_file_section *feat_sec; |
408 | int sec_size; | 428 | int sec_size; |
409 | u64 sec_start; | 429 | u64 sec_start; |
410 | int idx = 0, err; | 430 | int idx = 0, err; |
411 | 431 | ||
412 | if (dsos__read_build_ids(self, true)) | 432 | session = container_of(self, struct perf_session, header); |
433 | if (perf_session__read_build_ids(session, true)) | ||
413 | perf_header__set_feat(self, HEADER_BUILD_ID); | 434 | perf_header__set_feat(self, HEADER_BUILD_ID); |
414 | 435 | ||
415 | nr_sections = bitmap_weight(self->adds_features, HEADER_FEAT_BITS); | 436 | nr_sections = bitmap_weight(self->adds_features, HEADER_FEAT_BITS); |
@@ -450,7 +471,7 @@ static int perf_header__adds_write(struct perf_header *self, int fd) | |||
450 | } | 471 | } |
451 | buildid_sec->size = lseek(fd, 0, SEEK_CUR) - | 472 | buildid_sec->size = lseek(fd, 0, SEEK_CUR) - |
452 | buildid_sec->offset; | 473 | buildid_sec->offset; |
453 | dsos__cache_build_ids(self); | 474 | perf_session__cache_build_ids(session); |
454 | } | 475 | } |
455 | 476 | ||
456 | lseek(fd, sec_start, SEEK_SET); | 477 | lseek(fd, sec_start, SEEK_SET); |
@@ -490,7 +511,6 @@ int perf_header__write(struct perf_header *self, int fd, bool at_exit) | |||
490 | 511 | ||
491 | lseek(fd, sizeof(f_header), SEEK_SET); | 512 | lseek(fd, sizeof(f_header), SEEK_SET); |
492 | 513 | ||
493 | |||
494 | for (i = 0; i < self->attrs; i++) { | 514 | for (i = 0; i < self->attrs; i++) { |
495 | attr = self->attr[i]; | 515 | attr = self->attr[i]; |
496 | 516 | ||
diff --git a/tools/perf/util/help.c b/tools/perf/util/help.c index fbb00978b2e2..6f2975a00358 100644 --- a/tools/perf/util/help.c +++ b/tools/perf/util/help.c | |||
@@ -4,28 +4,6 @@ | |||
4 | #include "levenshtein.h" | 4 | #include "levenshtein.h" |
5 | #include "help.h" | 5 | #include "help.h" |
6 | 6 | ||
7 | /* most GUI terminals set COLUMNS (although some don't export it) */ | ||
8 | static int term_columns(void) | ||
9 | { | ||
10 | char *col_string = getenv("COLUMNS"); | ||
11 | int n_cols; | ||
12 | |||
13 | if (col_string && (n_cols = atoi(col_string)) > 0) | ||
14 | return n_cols; | ||
15 | |||
16 | #ifdef TIOCGWINSZ | ||
17 | { | ||
18 | struct winsize ws; | ||
19 | if (!ioctl(1, TIOCGWINSZ, &ws)) { | ||
20 | if (ws.ws_col) | ||
21 | return ws.ws_col; | ||
22 | } | ||
23 | } | ||
24 | #endif | ||
25 | |||
26 | return 80; | ||
27 | } | ||
28 | |||
29 | void add_cmdname(struct cmdnames *cmds, const char *name, size_t len) | 7 | void add_cmdname(struct cmdnames *cmds, const char *name, size_t len) |
30 | { | 8 | { |
31 | struct cmdname *ent = malloc(sizeof(*ent) + len + 1); | 9 | struct cmdname *ent = malloc(sizeof(*ent) + len + 1); |
@@ -96,9 +74,13 @@ static void pretty_print_string_list(struct cmdnames *cmds, int longest) | |||
96 | { | 74 | { |
97 | int cols = 1, rows; | 75 | int cols = 1, rows; |
98 | int space = longest + 1; /* min 1 SP between words */ | 76 | int space = longest + 1; /* min 1 SP between words */ |
99 | int max_cols = term_columns() - 1; /* don't print *on* the edge */ | 77 | struct winsize win; |
78 | int max_cols; | ||
100 | int i, j; | 79 | int i, j; |
101 | 80 | ||
81 | get_term_dimensions(&win); | ||
82 | max_cols = win.ws_col - 1; /* don't print *on* the edge */ | ||
83 | |||
102 | if (space < max_cols) | 84 | if (space < max_cols) |
103 | cols = max_cols / space; | 85 | cols = max_cols / space; |
104 | rows = (cmds->cnt + cols - 1) / cols; | 86 | rows = (cmds->cnt + cols - 1) / cols; |
@@ -324,7 +306,7 @@ const char *help_unknown_cmd(const char *cmd) | |||
324 | 306 | ||
325 | main_cmds.names[0] = NULL; | 307 | main_cmds.names[0] = NULL; |
326 | clean_cmdnames(&main_cmds); | 308 | clean_cmdnames(&main_cmds); |
327 | fprintf(stderr, "WARNING: You called a Git program named '%s', " | 309 | fprintf(stderr, "WARNING: You called a perf program named '%s', " |
328 | "which does not exist.\n" | 310 | "which does not exist.\n" |
329 | "Continuing under the assumption that you meant '%s'\n", | 311 | "Continuing under the assumption that you meant '%s'\n", |
330 | cmd, assumed); | 312 | cmd, assumed); |
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c index 9a71c94f057a..cbf7eae2ce09 100644 --- a/tools/perf/util/hist.c +++ b/tools/perf/util/hist.c | |||
@@ -1,4 +1,5 @@ | |||
1 | #include "util.h" | 1 | #include "util.h" |
2 | #include "build-id.h" | ||
2 | #include "hist.h" | 3 | #include "hist.h" |
3 | #include "session.h" | 4 | #include "session.h" |
4 | #include "sort.h" | 5 | #include "sort.h" |
@@ -988,22 +989,42 @@ int hist_entry__annotate(struct hist_entry *self, struct list_head *head) | |||
988 | struct symbol *sym = self->ms.sym; | 989 | struct symbol *sym = self->ms.sym; |
989 | struct map *map = self->ms.map; | 990 | struct map *map = self->ms.map; |
990 | struct dso *dso = map->dso; | 991 | struct dso *dso = map->dso; |
991 | const char *filename = dso->long_name; | 992 | char *filename = dso__build_id_filename(dso, NULL, 0); |
993 | bool free_filename = true; | ||
992 | char command[PATH_MAX * 2]; | 994 | char command[PATH_MAX * 2]; |
993 | FILE *file; | 995 | FILE *file; |
996 | int err = 0; | ||
994 | u64 len; | 997 | u64 len; |
995 | 998 | ||
996 | if (!filename) | 999 | if (filename == NULL) { |
997 | return -1; | 1000 | if (dso->has_build_id) { |
1001 | pr_err("Can't annotate %s: not enough memory\n", | ||
1002 | sym->name); | ||
1003 | return -ENOMEM; | ||
1004 | } | ||
1005 | goto fallback; | ||
1006 | } else if (readlink(filename, command, sizeof(command)) < 0 || | ||
1007 | strstr(command, "[kernel.kallsyms]") || | ||
1008 | access(filename, R_OK)) { | ||
1009 | free(filename); | ||
1010 | fallback: | ||
1011 | /* | ||
1012 | * If we don't have build-ids or the build-id file isn't in the | ||
1013 | * cache, or is just a kallsyms file, well, lets hope that this | ||
1014 | * DSO is the same as when 'perf record' ran. | ||
1015 | */ | ||
1016 | filename = dso->long_name; | ||
1017 | free_filename = false; | ||
1018 | } | ||
998 | 1019 | ||
999 | if (dso->origin == DSO__ORIG_KERNEL) { | 1020 | if (dso->origin == DSO__ORIG_KERNEL) { |
1000 | if (dso->annotate_warned) | 1021 | if (dso->annotate_warned) |
1001 | return 0; | 1022 | goto out_free_filename; |
1023 | err = -ENOENT; | ||
1002 | dso->annotate_warned = 1; | 1024 | dso->annotate_warned = 1; |
1003 | pr_err("Can't annotate %s: No vmlinux file was found in the " | 1025 | pr_err("Can't annotate %s: No vmlinux file was found in the " |
1004 | "path:\n", sym->name); | 1026 | "path\n", sym->name); |
1005 | vmlinux_path__fprintf(stderr); | 1027 | goto out_free_filename; |
1006 | return -1; | ||
1007 | } | 1028 | } |
1008 | 1029 | ||
1009 | pr_debug("%s: filename=%s, sym=%s, start=%#Lx, end=%#Lx\n", __func__, | 1030 | pr_debug("%s: filename=%s, sym=%s, start=%#Lx, end=%#Lx\n", __func__, |
@@ -1025,14 +1046,17 @@ int hist_entry__annotate(struct hist_entry *self, struct list_head *head) | |||
1025 | 1046 | ||
1026 | file = popen(command, "r"); | 1047 | file = popen(command, "r"); |
1027 | if (!file) | 1048 | if (!file) |
1028 | return -1; | 1049 | goto out_free_filename; |
1029 | 1050 | ||
1030 | while (!feof(file)) | 1051 | while (!feof(file)) |
1031 | if (hist_entry__parse_objdump_line(self, file, head) < 0) | 1052 | if (hist_entry__parse_objdump_line(self, file, head) < 0) |
1032 | break; | 1053 | break; |
1033 | 1054 | ||
1034 | pclose(file); | 1055 | pclose(file); |
1035 | return 0; | 1056 | out_free_filename: |
1057 | if (free_filename) | ||
1058 | free(filename); | ||
1059 | return err; | ||
1036 | } | 1060 | } |
1037 | 1061 | ||
1038 | void hists__inc_nr_events(struct hists *self, u32 type) | 1062 | void hists__inc_nr_events(struct hists *self, u32 type) |
diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h index 6f17dcd8412c..83fa33a7b38b 100644 --- a/tools/perf/util/hist.h +++ b/tools/perf/util/hist.h | |||
@@ -98,12 +98,32 @@ void hists__filter_by_thread(struct hists *self, const struct thread *thread); | |||
98 | #ifdef NO_NEWT_SUPPORT | 98 | #ifdef NO_NEWT_SUPPORT |
99 | static inline int hists__browse(struct hists *self __used, | 99 | static inline int hists__browse(struct hists *self __used, |
100 | const char *helpline __used, | 100 | const char *helpline __used, |
101 | const char *input_name __used) | 101 | const char *ev_name __used) |
102 | { | 102 | { |
103 | return 0; | 103 | return 0; |
104 | } | 104 | } |
105 | |||
106 | static inline int hists__tui_browse_tree(struct rb_root *self __used, | ||
107 | const char *help __used) | ||
108 | { | ||
109 | return 0; | ||
110 | } | ||
111 | |||
112 | static inline int hist_entry__tui_annotate(struct hist_entry *self __used) | ||
113 | { | ||
114 | return 0; | ||
115 | } | ||
116 | #define KEY_LEFT -1 | ||
117 | #define KEY_RIGHT -2 | ||
105 | #else | 118 | #else |
119 | #include <newt.h> | ||
106 | int hists__browse(struct hists *self, const char *helpline, | 120 | int hists__browse(struct hists *self, const char *helpline, |
107 | const char *input_name); | 121 | const char *ev_name); |
122 | int hist_entry__tui_annotate(struct hist_entry *self); | ||
123 | |||
124 | #define KEY_LEFT NEWT_KEY_LEFT | ||
125 | #define KEY_RIGHT NEWT_KEY_RIGHT | ||
126 | |||
127 | int hists__tui_browse_tree(struct rb_root *self, const char *help); | ||
108 | #endif | 128 | #endif |
109 | #endif /* __PERF_HIST_H */ | 129 | #endif /* __PERF_HIST_H */ |
diff --git a/tools/perf/util/newt.c b/tools/perf/util/newt.c index ccb7c5bb269e..d54c540f49db 100644 --- a/tools/perf/util/newt.c +++ b/tools/perf/util/newt.c | |||
@@ -1,7 +1,15 @@ | |||
1 | #define _GNU_SOURCE | 1 | #define _GNU_SOURCE |
2 | #include <stdio.h> | 2 | #include <stdio.h> |
3 | #undef _GNU_SOURCE | 3 | #undef _GNU_SOURCE |
4 | 4 | /* | |
5 | * slang versions <= 2.0.6 have a "#if HAVE_LONG_LONG" that breaks | ||
6 | * the build if it isn't defined. Use the equivalent one that glibc | ||
7 | * has on features.h. | ||
8 | */ | ||
9 | #include <features.h> | ||
10 | #ifndef HAVE_LONG_LONG | ||
11 | #define HAVE_LONG_LONG __GLIBC_HAVE_LONG_LONG | ||
12 | #endif | ||
5 | #include <slang.h> | 13 | #include <slang.h> |
6 | #include <stdlib.h> | 14 | #include <stdlib.h> |
7 | #include <newt.h> | 15 | #include <newt.h> |
@@ -227,6 +235,15 @@ static bool dialog_yesno(const char *msg) | |||
227 | return newtWinChoice(NULL, yes, no, (char *)msg) == 1; | 235 | return newtWinChoice(NULL, yes, no, (char *)msg) == 1; |
228 | } | 236 | } |
229 | 237 | ||
238 | static void ui__error_window(const char *fmt, ...) | ||
239 | { | ||
240 | va_list ap; | ||
241 | |||
242 | va_start(ap, fmt); | ||
243 | newtWinMessagev((char *)"Error", (char *)"Ok", (char *)fmt, ap); | ||
244 | va_end(ap); | ||
245 | } | ||
246 | |||
230 | #define HE_COLORSET_TOP 50 | 247 | #define HE_COLORSET_TOP 50 |
231 | #define HE_COLORSET_MEDIUM 51 | 248 | #define HE_COLORSET_MEDIUM 51 |
232 | #define HE_COLORSET_NORMAL 52 | 249 | #define HE_COLORSET_NORMAL 52 |
@@ -375,8 +392,11 @@ static int ui_browser__run(struct ui_browser *self, const char *title, | |||
375 | newtFormAddHotKey(self->form, NEWT_KEY_DOWN); | 392 | newtFormAddHotKey(self->form, NEWT_KEY_DOWN); |
376 | newtFormAddHotKey(self->form, NEWT_KEY_PGUP); | 393 | newtFormAddHotKey(self->form, NEWT_KEY_PGUP); |
377 | newtFormAddHotKey(self->form, NEWT_KEY_PGDN); | 394 | newtFormAddHotKey(self->form, NEWT_KEY_PGDN); |
395 | newtFormAddHotKey(self->form, ' '); | ||
378 | newtFormAddHotKey(self->form, NEWT_KEY_HOME); | 396 | newtFormAddHotKey(self->form, NEWT_KEY_HOME); |
379 | newtFormAddHotKey(self->form, NEWT_KEY_END); | 397 | newtFormAddHotKey(self->form, NEWT_KEY_END); |
398 | newtFormAddHotKey(self->form, NEWT_KEY_TAB); | ||
399 | newtFormAddHotKey(self->form, NEWT_KEY_RIGHT); | ||
380 | 400 | ||
381 | if (ui_browser__refresh_entries(self) < 0) | 401 | if (ui_browser__refresh_entries(self) < 0) |
382 | return -1; | 402 | return -1; |
@@ -389,6 +409,8 @@ static int ui_browser__run(struct ui_browser *self, const char *title, | |||
389 | 409 | ||
390 | if (es->reason != NEWT_EXIT_HOTKEY) | 410 | if (es->reason != NEWT_EXIT_HOTKEY) |
391 | break; | 411 | break; |
412 | if (is_exit_key(es->u.key)) | ||
413 | return es->u.key; | ||
392 | switch (es->u.key) { | 414 | switch (es->u.key) { |
393 | case NEWT_KEY_DOWN: | 415 | case NEWT_KEY_DOWN: |
394 | if (self->index == self->nr_entries - 1) | 416 | if (self->index == self->nr_entries - 1) |
@@ -411,6 +433,7 @@ static int ui_browser__run(struct ui_browser *self, const char *title, | |||
411 | } | 433 | } |
412 | break; | 434 | break; |
413 | case NEWT_KEY_PGDN: | 435 | case NEWT_KEY_PGDN: |
436 | case ' ': | ||
414 | if (self->first_visible_entry_idx + self->height > self->nr_entries - 1) | 437 | if (self->first_visible_entry_idx + self->height > self->nr_entries - 1) |
415 | break; | 438 | break; |
416 | 439 | ||
@@ -461,12 +484,10 @@ static int ui_browser__run(struct ui_browser *self, const char *title, | |||
461 | } | 484 | } |
462 | } | 485 | } |
463 | break; | 486 | break; |
464 | case NEWT_KEY_ESCAPE: | 487 | case NEWT_KEY_RIGHT: |
465 | case NEWT_KEY_LEFT: | 488 | case NEWT_KEY_LEFT: |
466 | case CTRL('c'): | 489 | case NEWT_KEY_TAB: |
467 | case 'Q': | 490 | return es->u.key; |
468 | case 'q': | ||
469 | return 0; | ||
470 | default: | 491 | default: |
471 | continue; | 492 | continue; |
472 | } | 493 | } |
@@ -658,18 +679,24 @@ static size_t hist_entry__append_browser(struct hist_entry *self, | |||
658 | return ret; | 679 | return ret; |
659 | } | 680 | } |
660 | 681 | ||
661 | static void hist_entry__annotate_browser(struct hist_entry *self) | 682 | int hist_entry__tui_annotate(struct hist_entry *self) |
662 | { | 683 | { |
663 | struct ui_browser browser; | 684 | struct ui_browser browser; |
664 | struct newtExitStruct es; | 685 | struct newtExitStruct es; |
665 | struct objdump_line *pos, *n; | 686 | struct objdump_line *pos, *n; |
666 | LIST_HEAD(head); | 687 | LIST_HEAD(head); |
688 | int ret; | ||
667 | 689 | ||
668 | if (self->ms.sym == NULL) | 690 | if (self->ms.sym == NULL) |
669 | return; | 691 | return -1; |
670 | 692 | ||
671 | if (hist_entry__annotate(self, &head) < 0) | 693 | if (self->ms.map->dso->annotate_warned) |
672 | return; | 694 | return -1; |
695 | |||
696 | if (hist_entry__annotate(self, &head) < 0) { | ||
697 | ui__error_window(browser__last_msg); | ||
698 | return -1; | ||
699 | } | ||
673 | 700 | ||
674 | ui_helpline__push("Press <- or ESC to exit"); | 701 | ui_helpline__push("Press <- or ESC to exit"); |
675 | 702 | ||
@@ -684,7 +711,7 @@ static void hist_entry__annotate_browser(struct hist_entry *self) | |||
684 | } | 711 | } |
685 | 712 | ||
686 | browser.width += 18; /* Percentage */ | 713 | browser.width += 18; /* Percentage */ |
687 | ui_browser__run(&browser, self->ms.sym->name, &es); | 714 | ret = ui_browser__run(&browser, self->ms.sym->name, &es); |
688 | newtFormDestroy(browser.form); | 715 | newtFormDestroy(browser.form); |
689 | newtPopWindow(); | 716 | newtPopWindow(); |
690 | list_for_each_entry_safe(pos, n, &head, node) { | 717 | list_for_each_entry_safe(pos, n, &head, node) { |
@@ -692,6 +719,7 @@ static void hist_entry__annotate_browser(struct hist_entry *self) | |||
692 | objdump_line__free(pos); | 719 | objdump_line__free(pos); |
693 | } | 720 | } |
694 | ui_helpline__pop(); | 721 | ui_helpline__pop(); |
722 | return ret; | ||
695 | } | 723 | } |
696 | 724 | ||
697 | static const void *newt__symbol_tree_get_current(newtComponent self) | 725 | static const void *newt__symbol_tree_get_current(newtComponent self) |
@@ -814,6 +842,8 @@ static int hist_browser__populate(struct hist_browser *self, struct hists *hists | |||
814 | newtFormAddHotKey(self->form, 'h'); | 842 | newtFormAddHotKey(self->form, 'h'); |
815 | newtFormAddHotKey(self->form, NEWT_KEY_F1); | 843 | newtFormAddHotKey(self->form, NEWT_KEY_F1); |
816 | newtFormAddHotKey(self->form, NEWT_KEY_RIGHT); | 844 | newtFormAddHotKey(self->form, NEWT_KEY_RIGHT); |
845 | newtFormAddHotKey(self->form, NEWT_KEY_TAB); | ||
846 | newtFormAddHotKey(self->form, NEWT_KEY_UNTAB); | ||
817 | newtFormAddComponents(self->form, self->tree, NULL); | 847 | newtFormAddComponents(self->form, self->tree, NULL); |
818 | self->selection = newt__symbol_tree_get_current(self->tree); | 848 | self->selection = newt__symbol_tree_get_current(self->tree); |
819 | 849 | ||
@@ -845,7 +875,7 @@ static struct thread *hist_browser__selected_thread(struct hist_browser *self) | |||
845 | return he ? he->thread : NULL; | 875 | return he ? he->thread : NULL; |
846 | } | 876 | } |
847 | 877 | ||
848 | static int hist_browser__title(char *bf, size_t size, const char *input_name, | 878 | static int hist_browser__title(char *bf, size_t size, const char *ev_name, |
849 | const struct dso *dso, const struct thread *thread) | 879 | const struct dso *dso, const struct thread *thread) |
850 | { | 880 | { |
851 | int printed = 0; | 881 | int printed = 0; |
@@ -859,18 +889,18 @@ static int hist_browser__title(char *bf, size_t size, const char *input_name, | |||
859 | printed += snprintf(bf + printed, size - printed, | 889 | printed += snprintf(bf + printed, size - printed, |
860 | "%sDSO: %s", thread ? " " : "", | 890 | "%sDSO: %s", thread ? " " : "", |
861 | dso->short_name); | 891 | dso->short_name); |
862 | return printed ?: snprintf(bf, size, "Report: %s", input_name); | 892 | return printed ?: snprintf(bf, size, "Event: %s", ev_name); |
863 | } | 893 | } |
864 | 894 | ||
865 | int hists__browse(struct hists *self, const char *helpline, const char *input_name) | 895 | int hists__browse(struct hists *self, const char *helpline, const char *ev_name) |
866 | { | 896 | { |
867 | struct hist_browser *browser = hist_browser__new(); | 897 | struct hist_browser *browser = hist_browser__new(); |
868 | struct pstack *fstack = pstack__new(2); | 898 | struct pstack *fstack; |
869 | const struct thread *thread_filter = NULL; | 899 | const struct thread *thread_filter = NULL; |
870 | const struct dso *dso_filter = NULL; | 900 | const struct dso *dso_filter = NULL; |
871 | struct newtExitStruct es; | 901 | struct newtExitStruct es; |
872 | char msg[160]; | 902 | char msg[160]; |
873 | int err = -1; | 903 | int key = -1; |
874 | 904 | ||
875 | if (browser == NULL) | 905 | if (browser == NULL) |
876 | return -1; | 906 | return -1; |
@@ -881,7 +911,7 @@ int hists__browse(struct hists *self, const char *helpline, const char *input_na | |||
881 | 911 | ||
882 | ui_helpline__push(helpline); | 912 | ui_helpline__push(helpline); |
883 | 913 | ||
884 | hist_browser__title(msg, sizeof(msg), input_name, | 914 | hist_browser__title(msg, sizeof(msg), ev_name, |
885 | dso_filter, thread_filter); | 915 | dso_filter, thread_filter); |
886 | if (hist_browser__populate(browser, self, msg) < 0) | 916 | if (hist_browser__populate(browser, self, msg) < 0) |
887 | goto out_free_stack; | 917 | goto out_free_stack; |
@@ -899,11 +929,27 @@ int hists__browse(struct hists *self, const char *helpline, const char *input_na | |||
899 | dso = browser->selection->map ? browser->selection->map->dso : NULL; | 929 | dso = browser->selection->map ? browser->selection->map->dso : NULL; |
900 | 930 | ||
901 | if (es.reason == NEWT_EXIT_HOTKEY) { | 931 | if (es.reason == NEWT_EXIT_HOTKEY) { |
902 | if (es.u.key == NEWT_KEY_F1) | 932 | key = es.u.key; |
933 | |||
934 | switch (key) { | ||
935 | case NEWT_KEY_F1: | ||
903 | goto do_help; | 936 | goto do_help; |
937 | case NEWT_KEY_TAB: | ||
938 | case NEWT_KEY_UNTAB: | ||
939 | /* | ||
940 | * Exit the browser, let hists__browser_tree | ||
941 | * go to the next or previous | ||
942 | */ | ||
943 | goto out_free_stack; | ||
944 | default:; | ||
945 | } | ||
904 | 946 | ||
905 | switch (toupper(es.u.key)) { | 947 | key = toupper(key); |
948 | switch (key) { | ||
906 | case 'A': | 949 | case 'A': |
950 | if (browser->selection->map == NULL && | ||
951 | browser->selection->map->dso->annotate_warned) | ||
952 | continue; | ||
907 | goto do_annotate; | 953 | goto do_annotate; |
908 | case 'D': | 954 | case 'D': |
909 | goto zoom_dso; | 955 | goto zoom_dso; |
@@ -922,14 +968,14 @@ do_help: | |||
922 | continue; | 968 | continue; |
923 | default:; | 969 | default:; |
924 | } | 970 | } |
925 | if (toupper(es.u.key) == 'Q' || | 971 | if (is_exit_key(key)) { |
926 | es.u.key == CTRL('c')) | 972 | if (key == NEWT_KEY_ESCAPE) { |
927 | break; | 973 | if (dialog_yesno("Do you really want to exit?")) |
928 | if (es.u.key == NEWT_KEY_ESCAPE) { | 974 | break; |
929 | if (dialog_yesno("Do you really want to exit?")) | 975 | else |
976 | continue; | ||
977 | } else | ||
930 | break; | 978 | break; |
931 | else | ||
932 | continue; | ||
933 | } | 979 | } |
934 | 980 | ||
935 | if (es.u.key == NEWT_KEY_LEFT) { | 981 | if (es.u.key == NEWT_KEY_LEFT) { |
@@ -947,6 +993,7 @@ do_help: | |||
947 | } | 993 | } |
948 | 994 | ||
949 | if (browser->selection->sym != NULL && | 995 | if (browser->selection->sym != NULL && |
996 | !browser->selection->map->dso->annotate_warned && | ||
950 | asprintf(&options[nr_options], "Annotate %s", | 997 | asprintf(&options[nr_options], "Annotate %s", |
951 | browser->selection->sym->name) > 0) | 998 | browser->selection->sym->name) > 0) |
952 | annotate = nr_options++; | 999 | annotate = nr_options++; |
@@ -981,6 +1028,7 @@ do_help: | |||
981 | struct hist_entry *he; | 1028 | struct hist_entry *he; |
982 | do_annotate: | 1029 | do_annotate: |
983 | if (browser->selection->map->dso->origin == DSO__ORIG_KERNEL) { | 1030 | if (browser->selection->map->dso->origin == DSO__ORIG_KERNEL) { |
1031 | browser->selection->map->dso->annotate_warned = 1; | ||
984 | ui_helpline__puts("No vmlinux file found, can't " | 1032 | ui_helpline__puts("No vmlinux file found, can't " |
985 | "annotate with just a " | 1033 | "annotate with just a " |
986 | "kallsyms file"); | 1034 | "kallsyms file"); |
@@ -991,7 +1039,7 @@ do_annotate: | |||
991 | if (he == NULL) | 1039 | if (he == NULL) |
992 | continue; | 1040 | continue; |
993 | 1041 | ||
994 | hist_entry__annotate_browser(he); | 1042 | hist_entry__tui_annotate(he); |
995 | } else if (choice == zoom_dso) { | 1043 | } else if (choice == zoom_dso) { |
996 | zoom_dso: | 1044 | zoom_dso: |
997 | if (dso_filter) { | 1045 | if (dso_filter) { |
@@ -1008,7 +1056,7 @@ zoom_out_dso: | |||
1008 | pstack__push(fstack, &dso_filter); | 1056 | pstack__push(fstack, &dso_filter); |
1009 | } | 1057 | } |
1010 | hists__filter_by_dso(self, dso_filter); | 1058 | hists__filter_by_dso(self, dso_filter); |
1011 | hist_browser__title(msg, sizeof(msg), input_name, | 1059 | hist_browser__title(msg, sizeof(msg), ev_name, |
1012 | dso_filter, thread_filter); | 1060 | dso_filter, thread_filter); |
1013 | if (hist_browser__populate(browser, self, msg) < 0) | 1061 | if (hist_browser__populate(browser, self, msg) < 0) |
1014 | goto out; | 1062 | goto out; |
@@ -1027,18 +1075,49 @@ zoom_out_thread: | |||
1027 | pstack__push(fstack, &thread_filter); | 1075 | pstack__push(fstack, &thread_filter); |
1028 | } | 1076 | } |
1029 | hists__filter_by_thread(self, thread_filter); | 1077 | hists__filter_by_thread(self, thread_filter); |
1030 | hist_browser__title(msg, sizeof(msg), input_name, | 1078 | hist_browser__title(msg, sizeof(msg), ev_name, |
1031 | dso_filter, thread_filter); | 1079 | dso_filter, thread_filter); |
1032 | if (hist_browser__populate(browser, self, msg) < 0) | 1080 | if (hist_browser__populate(browser, self, msg) < 0) |
1033 | goto out; | 1081 | goto out; |
1034 | } | 1082 | } |
1035 | } | 1083 | } |
1036 | err = 0; | ||
1037 | out_free_stack: | 1084 | out_free_stack: |
1038 | pstack__delete(fstack); | 1085 | pstack__delete(fstack); |
1039 | out: | 1086 | out: |
1040 | hist_browser__delete(browser); | 1087 | hist_browser__delete(browser); |
1041 | return err; | 1088 | return key; |
1089 | } | ||
1090 | |||
1091 | int hists__tui_browse_tree(struct rb_root *self, const char *help) | ||
1092 | { | ||
1093 | struct rb_node *first = rb_first(self), *nd = first, *next; | ||
1094 | int key = 0; | ||
1095 | |||
1096 | while (nd) { | ||
1097 | struct hists *hists = rb_entry(nd, struct hists, rb_node); | ||
1098 | const char *ev_name = __event_name(hists->type, hists->config); | ||
1099 | |||
1100 | key = hists__browse(hists, help, ev_name); | ||
1101 | |||
1102 | if (is_exit_key(key)) | ||
1103 | break; | ||
1104 | |||
1105 | switch (key) { | ||
1106 | case NEWT_KEY_TAB: | ||
1107 | next = rb_next(nd); | ||
1108 | if (next) | ||
1109 | nd = next; | ||
1110 | break; | ||
1111 | case NEWT_KEY_UNTAB: | ||
1112 | if (nd == first) | ||
1113 | continue; | ||
1114 | nd = rb_prev(nd); | ||
1115 | default: | ||
1116 | break; | ||
1117 | } | ||
1118 | } | ||
1119 | |||
1120 | return key; | ||
1042 | } | 1121 | } |
1043 | 1122 | ||
1044 | static struct newtPercentTreeColors { | 1123 | static struct newtPercentTreeColors { |
@@ -1058,10 +1137,13 @@ static struct newtPercentTreeColors { | |||
1058 | void setup_browser(void) | 1137 | void setup_browser(void) |
1059 | { | 1138 | { |
1060 | struct newtPercentTreeColors *c = &defaultPercentTreeColors; | 1139 | struct newtPercentTreeColors *c = &defaultPercentTreeColors; |
1061 | if (!isatty(1)) | 1140 | |
1141 | if (!isatty(1) || !use_browser || dump_trace) { | ||
1142 | setup_pager(); | ||
1062 | return; | 1143 | return; |
1144 | } | ||
1063 | 1145 | ||
1064 | use_browser = true; | 1146 | use_browser = 1; |
1065 | newtInit(); | 1147 | newtInit(); |
1066 | newtCls(); | 1148 | newtCls(); |
1067 | ui_helpline__puts(" "); | 1149 | ui_helpline__puts(" "); |
@@ -1074,7 +1156,7 @@ void setup_browser(void) | |||
1074 | 1156 | ||
1075 | void exit_browser(bool wait_for_ok) | 1157 | void exit_browser(bool wait_for_ok) |
1076 | { | 1158 | { |
1077 | if (use_browser) { | 1159 | if (use_browser > 0) { |
1078 | if (wait_for_ok) { | 1160 | if (wait_for_ok) { |
1079 | char title[] = "Fatal Error", ok[] = "Ok"; | 1161 | char title[] = "Fatal Error", ok[] = "Ok"; |
1080 | newtWinMessage(title, ok, browser__last_msg); | 1162 | newtWinMessage(title, ok, browser__last_msg); |
diff --git a/tools/perf/util/path.c b/tools/perf/util/path.c index fd1f2faaade4..58a470d036dd 100644 --- a/tools/perf/util/path.c +++ b/tools/perf/util/path.c | |||
@@ -54,21 +54,6 @@ static char *cleanup_path(char *path) | |||
54 | return path; | 54 | return path; |
55 | } | 55 | } |
56 | 56 | ||
57 | char *mksnpath(char *buf, size_t n, const char *fmt, ...) | ||
58 | { | ||
59 | va_list args; | ||
60 | unsigned len; | ||
61 | |||
62 | va_start(args, fmt); | ||
63 | len = vsnprintf(buf, n, fmt, args); | ||
64 | va_end(args); | ||
65 | if (len >= n) { | ||
66 | strlcpy(buf, bad_path, n); | ||
67 | return buf; | ||
68 | } | ||
69 | return cleanup_path(buf); | ||
70 | } | ||
71 | |||
72 | static char *perf_vsnpath(char *buf, size_t n, const char *fmt, va_list args) | 57 | static char *perf_vsnpath(char *buf, size_t n, const char *fmt, va_list args) |
73 | { | 58 | { |
74 | const char *perf_dir = get_perf_dir(); | 59 | const char *perf_dir = get_perf_dir(); |
@@ -89,15 +74,6 @@ bad: | |||
89 | return buf; | 74 | return buf; |
90 | } | 75 | } |
91 | 76 | ||
92 | char *perf_snpath(char *buf, size_t n, const char *fmt, ...) | ||
93 | { | ||
94 | va_list args; | ||
95 | va_start(args, fmt); | ||
96 | (void)perf_vsnpath(buf, n, fmt, args); | ||
97 | va_end(args); | ||
98 | return buf; | ||
99 | } | ||
100 | |||
101 | char *perf_pathdup(const char *fmt, ...) | 77 | char *perf_pathdup(const char *fmt, ...) |
102 | { | 78 | { |
103 | char path[PATH_MAX]; | 79 | char path[PATH_MAX]; |
@@ -143,184 +119,6 @@ char *perf_path(const char *fmt, ...) | |||
143 | return cleanup_path(pathname); | 119 | return cleanup_path(pathname); |
144 | } | 120 | } |
145 | 121 | ||
146 | |||
147 | /* perf_mkstemp() - create tmp file honoring TMPDIR variable */ | ||
148 | int perf_mkstemp(char *path, size_t len, const char *template) | ||
149 | { | ||
150 | const char *tmp; | ||
151 | size_t n; | ||
152 | |||
153 | tmp = getenv("TMPDIR"); | ||
154 | if (!tmp) | ||
155 | tmp = "/tmp"; | ||
156 | n = snprintf(path, len, "%s/%s", tmp, template); | ||
157 | if (len <= n) { | ||
158 | errno = ENAMETOOLONG; | ||
159 | return -1; | ||
160 | } | ||
161 | return mkstemp(path); | ||
162 | } | ||
163 | |||
164 | |||
165 | const char *make_relative_path(const char *abs_path, const char *base) | ||
166 | { | ||
167 | static char buf[PATH_MAX + 1]; | ||
168 | int baselen; | ||
169 | |||
170 | if (!base) | ||
171 | return abs_path; | ||
172 | |||
173 | baselen = strlen(base); | ||
174 | if (prefixcmp(abs_path, base)) | ||
175 | return abs_path; | ||
176 | if (abs_path[baselen] == '/') | ||
177 | baselen++; | ||
178 | else if (base[baselen - 1] != '/') | ||
179 | return abs_path; | ||
180 | |||
181 | strcpy(buf, abs_path + baselen); | ||
182 | |||
183 | return buf; | ||
184 | } | ||
185 | |||
186 | /* | ||
187 | * It is okay if dst == src, but they should not overlap otherwise. | ||
188 | * | ||
189 | * Performs the following normalizations on src, storing the result in dst: | ||
190 | * - Ensures that components are separated by '/' (Windows only) | ||
191 | * - Squashes sequences of '/'. | ||
192 | * - Removes "." components. | ||
193 | * - Removes ".." components, and the components the precede them. | ||
194 | * Returns failure (non-zero) if a ".." component appears as first path | ||
195 | * component anytime during the normalization. Otherwise, returns success (0). | ||
196 | * | ||
197 | * Note that this function is purely textual. It does not follow symlinks, | ||
198 | * verify the existence of the path, or make any system calls. | ||
199 | */ | ||
200 | int normalize_path_copy(char *dst, const char *src) | ||
201 | { | ||
202 | char *dst0; | ||
203 | |||
204 | if (has_dos_drive_prefix(src)) { | ||
205 | *dst++ = *src++; | ||
206 | *dst++ = *src++; | ||
207 | } | ||
208 | dst0 = dst; | ||
209 | |||
210 | if (is_dir_sep(*src)) { | ||
211 | *dst++ = '/'; | ||
212 | while (is_dir_sep(*src)) | ||
213 | src++; | ||
214 | } | ||
215 | |||
216 | for (;;) { | ||
217 | char c = *src; | ||
218 | |||
219 | /* | ||
220 | * A path component that begins with . could be | ||
221 | * special: | ||
222 | * (1) "." and ends -- ignore and terminate. | ||
223 | * (2) "./" -- ignore them, eat slash and continue. | ||
224 | * (3) ".." and ends -- strip one and terminate. | ||
225 | * (4) "../" -- strip one, eat slash and continue. | ||
226 | */ | ||
227 | if (c == '.') { | ||
228 | if (!src[1]) { | ||
229 | /* (1) */ | ||
230 | src++; | ||
231 | } else if (is_dir_sep(src[1])) { | ||
232 | /* (2) */ | ||
233 | src += 2; | ||
234 | while (is_dir_sep(*src)) | ||
235 | src++; | ||
236 | continue; | ||
237 | } else if (src[1] == '.') { | ||
238 | if (!src[2]) { | ||
239 | /* (3) */ | ||
240 | src += 2; | ||
241 | goto up_one; | ||
242 | } else if (is_dir_sep(src[2])) { | ||
243 | /* (4) */ | ||
244 | src += 3; | ||
245 | while (is_dir_sep(*src)) | ||
246 | src++; | ||
247 | goto up_one; | ||
248 | } | ||
249 | } | ||
250 | } | ||
251 | |||
252 | /* copy up to the next '/', and eat all '/' */ | ||
253 | while ((c = *src++) != '\0' && !is_dir_sep(c)) | ||
254 | *dst++ = c; | ||
255 | if (is_dir_sep(c)) { | ||
256 | *dst++ = '/'; | ||
257 | while (is_dir_sep(c)) | ||
258 | c = *src++; | ||
259 | src--; | ||
260 | } else if (!c) | ||
261 | break; | ||
262 | continue; | ||
263 | |||
264 | up_one: | ||
265 | /* | ||
266 | * dst0..dst is prefix portion, and dst[-1] is '/'; | ||
267 | * go up one level. | ||
268 | */ | ||
269 | dst--; /* go to trailing '/' */ | ||
270 | if (dst <= dst0) | ||
271 | return -1; | ||
272 | /* Windows: dst[-1] cannot be backslash anymore */ | ||
273 | while (dst0 < dst && dst[-1] != '/') | ||
274 | dst--; | ||
275 | } | ||
276 | *dst = '\0'; | ||
277 | return 0; | ||
278 | } | ||
279 | |||
280 | /* | ||
281 | * path = Canonical absolute path | ||
282 | * prefix_list = Colon-separated list of absolute paths | ||
283 | * | ||
284 | * Determines, for each path in prefix_list, whether the "prefix" really | ||
285 | * is an ancestor directory of path. Returns the length of the longest | ||
286 | * ancestor directory, excluding any trailing slashes, or -1 if no prefix | ||
287 | * is an ancestor. (Note that this means 0 is returned if prefix_list is | ||
288 | * "/".) "/foo" is not considered an ancestor of "/foobar". Directories | ||
289 | * are not considered to be their own ancestors. path must be in a | ||
290 | * canonical form: empty components, or "." or ".." components are not | ||
291 | * allowed. prefix_list may be null, which is like "". | ||
292 | */ | ||
293 | int longest_ancestor_length(const char *path, const char *prefix_list) | ||
294 | { | ||
295 | char buf[PATH_MAX+1]; | ||
296 | const char *ceil, *colon; | ||
297 | int len, max_len = -1; | ||
298 | |||
299 | if (prefix_list == NULL || !strcmp(path, "/")) | ||
300 | return -1; | ||
301 | |||
302 | for (colon = ceil = prefix_list; *colon; ceil = colon+1) { | ||
303 | for (colon = ceil; *colon && *colon != PATH_SEP; colon++); | ||
304 | len = colon - ceil; | ||
305 | if (len == 0 || len > PATH_MAX || !is_absolute_path(ceil)) | ||
306 | continue; | ||
307 | strlcpy(buf, ceil, len+1); | ||
308 | if (normalize_path_copy(buf, buf) < 0) | ||
309 | continue; | ||
310 | len = strlen(buf); | ||
311 | if (len > 0 && buf[len-1] == '/') | ||
312 | buf[--len] = '\0'; | ||
313 | |||
314 | if (!strncmp(path, buf, len) && | ||
315 | path[len] == '/' && | ||
316 | len > max_len) { | ||
317 | max_len = len; | ||
318 | } | ||
319 | } | ||
320 | |||
321 | return max_len; | ||
322 | } | ||
323 | |||
324 | /* strip arbitrary amount of directory separators at end of path */ | 122 | /* strip arbitrary amount of directory separators at end of path */ |
325 | static inline int chomp_trailing_dir_sep(const char *path, int len) | 123 | static inline int chomp_trailing_dir_sep(const char *path, int len) |
326 | { | 124 | { |
@@ -354,5 +152,5 @@ char *strip_path_suffix(const char *path, const char *suffix) | |||
354 | 152 | ||
355 | if (path_len && !is_dir_sep(path[path_len - 1])) | 153 | if (path_len && !is_dir_sep(path[path_len - 1])) |
356 | return NULL; | 154 | return NULL; |
357 | return xstrndup(path, chomp_trailing_dir_sep(path, path_len)); | 155 | return strndup(path, chomp_trailing_dir_sep(path, path_len)); |
358 | } | 156 | } |
diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c index 562b1443e785..d964cb199c67 100644 --- a/tools/perf/util/probe-finder.c +++ b/tools/perf/util/probe-finder.c | |||
@@ -668,6 +668,7 @@ static int convert_probe_point(Dwarf_Die *sp_die, struct probe_finder *pf) | |||
668 | ret = dwarf_getlocation_addr(&fb_attr, pf->addr, &pf->fb_ops, &nops, 1); | 668 | ret = dwarf_getlocation_addr(&fb_attr, pf->addr, &pf->fb_ops, &nops, 1); |
669 | if (ret <= 0 || nops == 0) { | 669 | if (ret <= 0 || nops == 0) { |
670 | pf->fb_ops = NULL; | 670 | pf->fb_ops = NULL; |
671 | #if _ELFUTILS_PREREQ(0, 142) | ||
671 | } else if (nops == 1 && pf->fb_ops[0].atom == DW_OP_call_frame_cfa && | 672 | } else if (nops == 1 && pf->fb_ops[0].atom == DW_OP_call_frame_cfa && |
672 | pf->cfi != NULL) { | 673 | pf->cfi != NULL) { |
673 | Dwarf_Frame *frame; | 674 | Dwarf_Frame *frame; |
@@ -677,6 +678,7 @@ static int convert_probe_point(Dwarf_Die *sp_die, struct probe_finder *pf) | |||
677 | (uintmax_t)pf->addr); | 678 | (uintmax_t)pf->addr); |
678 | return -ENOENT; | 679 | return -ENOENT; |
679 | } | 680 | } |
681 | #endif | ||
680 | } | 682 | } |
681 | 683 | ||
682 | /* Find each argument */ | 684 | /* Find each argument */ |
@@ -741,32 +743,36 @@ static int find_lazy_match_lines(struct list_head *head, | |||
741 | const char *fname, const char *pat) | 743 | const char *fname, const char *pat) |
742 | { | 744 | { |
743 | char *fbuf, *p1, *p2; | 745 | char *fbuf, *p1, *p2; |
744 | int fd, ret, line, nlines = 0; | 746 | int fd, line, nlines = -1; |
745 | struct stat st; | 747 | struct stat st; |
746 | 748 | ||
747 | fd = open(fname, O_RDONLY); | 749 | fd = open(fname, O_RDONLY); |
748 | if (fd < 0) { | 750 | if (fd < 0) { |
749 | pr_warning("Failed to open %s: %s\n", fname, strerror(-fd)); | 751 | pr_warning("Failed to open %s: %s\n", fname, strerror(-fd)); |
750 | return fd; | 752 | return -errno; |
751 | } | 753 | } |
752 | 754 | ||
753 | ret = fstat(fd, &st); | 755 | if (fstat(fd, &st) < 0) { |
754 | if (ret < 0) { | ||
755 | pr_warning("Failed to get the size of %s: %s\n", | 756 | pr_warning("Failed to get the size of %s: %s\n", |
756 | fname, strerror(errno)); | 757 | fname, strerror(errno)); |
757 | return ret; | 758 | nlines = -errno; |
759 | goto out_close; | ||
758 | } | 760 | } |
759 | fbuf = xmalloc(st.st_size + 2); | 761 | |
760 | ret = read(fd, fbuf, st.st_size); | 762 | nlines = -ENOMEM; |
761 | if (ret < 0) { | 763 | fbuf = malloc(st.st_size + 2); |
764 | if (fbuf == NULL) | ||
765 | goto out_close; | ||
766 | if (read(fd, fbuf, st.st_size) < 0) { | ||
762 | pr_warning("Failed to read %s: %s\n", fname, strerror(errno)); | 767 | pr_warning("Failed to read %s: %s\n", fname, strerror(errno)); |
763 | return ret; | 768 | nlines = -errno; |
769 | goto out_free_fbuf; | ||
764 | } | 770 | } |
765 | close(fd); | ||
766 | fbuf[st.st_size] = '\n'; /* Dummy line */ | 771 | fbuf[st.st_size] = '\n'; /* Dummy line */ |
767 | fbuf[st.st_size + 1] = '\0'; | 772 | fbuf[st.st_size + 1] = '\0'; |
768 | p1 = fbuf; | 773 | p1 = fbuf; |
769 | line = 1; | 774 | line = 1; |
775 | nlines = 0; | ||
770 | while ((p2 = strchr(p1, '\n')) != NULL) { | 776 | while ((p2 = strchr(p1, '\n')) != NULL) { |
771 | *p2 = '\0'; | 777 | *p2 = '\0'; |
772 | if (strlazymatch(p1, pat)) { | 778 | if (strlazymatch(p1, pat)) { |
@@ -776,7 +782,10 @@ static int find_lazy_match_lines(struct list_head *head, | |||
776 | line++; | 782 | line++; |
777 | p1 = p2 + 1; | 783 | p1 = p2 + 1; |
778 | } | 784 | } |
785 | out_free_fbuf: | ||
779 | free(fbuf); | 786 | free(fbuf); |
787 | out_close: | ||
788 | close(fd); | ||
780 | return nlines; | 789 | return nlines; |
781 | } | 790 | } |
782 | 791 | ||
@@ -953,11 +962,15 @@ int find_kprobe_trace_events(int fd, struct perf_probe_event *pev, | |||
953 | if (!dbg) { | 962 | if (!dbg) { |
954 | pr_warning("No dwarf info found in the vmlinux - " | 963 | pr_warning("No dwarf info found in the vmlinux - " |
955 | "please rebuild with CONFIG_DEBUG_INFO=y.\n"); | 964 | "please rebuild with CONFIG_DEBUG_INFO=y.\n"); |
965 | free(pf.tevs); | ||
966 | *tevs = NULL; | ||
956 | return -EBADF; | 967 | return -EBADF; |
957 | } | 968 | } |
958 | 969 | ||
970 | #if _ELFUTILS_PREREQ(0, 142) | ||
959 | /* Get the call frame information from this dwarf */ | 971 | /* Get the call frame information from this dwarf */ |
960 | pf.cfi = dwarf_getcfi(dbg); | 972 | pf.cfi = dwarf_getcfi(dbg); |
973 | #endif | ||
961 | 974 | ||
962 | off = 0; | 975 | off = 0; |
963 | line_list__init(&pf.lcache); | 976 | line_list__init(&pf.lcache); |
diff --git a/tools/perf/util/probe-finder.h b/tools/perf/util/probe-finder.h index 66f1980e3855..e1f61dcd18ff 100644 --- a/tools/perf/util/probe-finder.h +++ b/tools/perf/util/probe-finder.h | |||
@@ -29,6 +29,7 @@ extern int find_line_range(int fd, struct line_range *lr); | |||
29 | 29 | ||
30 | #include <dwarf.h> | 30 | #include <dwarf.h> |
31 | #include <libdw.h> | 31 | #include <libdw.h> |
32 | #include <version.h> | ||
32 | 33 | ||
33 | struct probe_finder { | 34 | struct probe_finder { |
34 | struct perf_probe_event *pev; /* Target probe event */ | 35 | struct perf_probe_event *pev; /* Target probe event */ |
@@ -44,7 +45,9 @@ struct probe_finder { | |||
44 | struct list_head lcache; /* Line cache for lazy match */ | 45 | struct list_head lcache; /* Line cache for lazy match */ |
45 | 46 | ||
46 | /* For variable searching */ | 47 | /* For variable searching */ |
48 | #if _ELFUTILS_PREREQ(0, 142) | ||
47 | Dwarf_CFI *cfi; /* Call Frame Information */ | 49 | Dwarf_CFI *cfi; /* Call Frame Information */ |
50 | #endif | ||
48 | Dwarf_Op *fb_ops; /* Frame base attribute */ | 51 | Dwarf_Op *fb_ops; /* Frame base attribute */ |
49 | struct perf_probe_arg *pvar; /* Current target variable */ | 52 | struct perf_probe_arg *pvar; /* Current target variable */ |
50 | struct kprobe_trace_arg *tvar; /* Current result variable */ | 53 | struct kprobe_trace_arg *tvar; /* Current result variable */ |
diff --git a/tools/perf/util/quote.c b/tools/perf/util/quote.c index 2726fe40eb5d..01f03242b86a 100644 --- a/tools/perf/util/quote.c +++ b/tools/perf/util/quote.c | |||
@@ -1,8 +1,6 @@ | |||
1 | #include "cache.h" | 1 | #include "cache.h" |
2 | #include "quote.h" | 2 | #include "quote.h" |
3 | 3 | ||
4 | int quote_path_fully = 1; | ||
5 | |||
6 | /* Help to copy the thing properly quoted for the shell safety. | 4 | /* Help to copy the thing properly quoted for the shell safety. |
7 | * any single quote is replaced with '\'', any exclamation point | 5 | * any single quote is replaced with '\'', any exclamation point |
8 | * is replaced with '\!', and the whole thing is enclosed in a | 6 | * is replaced with '\!', and the whole thing is enclosed in a |
@@ -19,7 +17,7 @@ static inline int need_bs_quote(char c) | |||
19 | return (c == '\'' || c == '!'); | 17 | return (c == '\'' || c == '!'); |
20 | } | 18 | } |
21 | 19 | ||
22 | void sq_quote_buf(struct strbuf *dst, const char *src) | 20 | static void sq_quote_buf(struct strbuf *dst, const char *src) |
23 | { | 21 | { |
24 | char *to_free = NULL; | 22 | char *to_free = NULL; |
25 | 23 | ||
@@ -41,23 +39,6 @@ void sq_quote_buf(struct strbuf *dst, const char *src) | |||
41 | free(to_free); | 39 | free(to_free); |
42 | } | 40 | } |
43 | 41 | ||
44 | void sq_quote_print(FILE *stream, const char *src) | ||
45 | { | ||
46 | char c; | ||
47 | |||
48 | fputc('\'', stream); | ||
49 | while ((c = *src++)) { | ||
50 | if (need_bs_quote(c)) { | ||
51 | fputs("'\\", stream); | ||
52 | fputc(c, stream); | ||
53 | fputc('\'', stream); | ||
54 | } else { | ||
55 | fputc(c, stream); | ||
56 | } | ||
57 | } | ||
58 | fputc('\'', stream); | ||
59 | } | ||
60 | |||
61 | void sq_quote_argv(struct strbuf *dst, const char** argv, size_t maxlen) | 42 | void sq_quote_argv(struct strbuf *dst, const char** argv, size_t maxlen) |
62 | { | 43 | { |
63 | int i; | 44 | int i; |
@@ -71,415 +52,3 @@ void sq_quote_argv(struct strbuf *dst, const char** argv, size_t maxlen) | |||
71 | die("Too many or long arguments"); | 52 | die("Too many or long arguments"); |
72 | } | 53 | } |
73 | } | 54 | } |
74 | |||
75 | char *sq_dequote_step(char *arg, char **next) | ||
76 | { | ||
77 | char *dst = arg; | ||
78 | char *src = arg; | ||
79 | char c; | ||
80 | |||
81 | if (*src != '\'') | ||
82 | return NULL; | ||
83 | for (;;) { | ||
84 | c = *++src; | ||
85 | if (!c) | ||
86 | return NULL; | ||
87 | if (c != '\'') { | ||
88 | *dst++ = c; | ||
89 | continue; | ||
90 | } | ||
91 | /* We stepped out of sq */ | ||
92 | switch (*++src) { | ||
93 | case '\0': | ||
94 | *dst = 0; | ||
95 | if (next) | ||
96 | *next = NULL; | ||
97 | return arg; | ||
98 | case '\\': | ||
99 | c = *++src; | ||
100 | if (need_bs_quote(c) && *++src == '\'') { | ||
101 | *dst++ = c; | ||
102 | continue; | ||
103 | } | ||
104 | /* Fallthrough */ | ||
105 | default: | ||
106 | if (!next || !isspace(*src)) | ||
107 | return NULL; | ||
108 | do { | ||
109 | c = *++src; | ||
110 | } while (isspace(c)); | ||
111 | *dst = 0; | ||
112 | *next = src; | ||
113 | return arg; | ||
114 | } | ||
115 | } | ||
116 | } | ||
117 | |||
118 | char *sq_dequote(char *arg) | ||
119 | { | ||
120 | return sq_dequote_step(arg, NULL); | ||
121 | } | ||
122 | |||
123 | int sq_dequote_to_argv(char *arg, const char ***argv, int *nr, int *alloc) | ||
124 | { | ||
125 | char *next = arg; | ||
126 | |||
127 | if (!*arg) | ||
128 | return 0; | ||
129 | do { | ||
130 | char *dequoted = sq_dequote_step(next, &next); | ||
131 | if (!dequoted) | ||
132 | return -1; | ||
133 | ALLOC_GROW(*argv, *nr + 1, *alloc); | ||
134 | (*argv)[(*nr)++] = dequoted; | ||
135 | } while (next); | ||
136 | |||
137 | return 0; | ||
138 | } | ||
139 | |||
140 | /* 1 means: quote as octal | ||
141 | * 0 means: quote as octal if (quote_path_fully) | ||
142 | * -1 means: never quote | ||
143 | * c: quote as "\\c" | ||
144 | */ | ||
145 | #define X8(x) x, x, x, x, x, x, x, x | ||
146 | #define X16(x) X8(x), X8(x) | ||
147 | static signed char const sq_lookup[256] = { | ||
148 | /* 0 1 2 3 4 5 6 7 */ | ||
149 | /* 0x00 */ 1, 1, 1, 1, 1, 1, 1, 'a', | ||
150 | /* 0x08 */ 'b', 't', 'n', 'v', 'f', 'r', 1, 1, | ||
151 | /* 0x10 */ X16(1), | ||
152 | /* 0x20 */ -1, -1, '"', -1, -1, -1, -1, -1, | ||
153 | /* 0x28 */ X16(-1), X16(-1), X16(-1), | ||
154 | /* 0x58 */ -1, -1, -1, -1,'\\', -1, -1, -1, | ||
155 | /* 0x60 */ X16(-1), X8(-1), | ||
156 | /* 0x78 */ -1, -1, -1, -1, -1, -1, -1, 1, | ||
157 | /* 0x80 */ /* set to 0 */ | ||
158 | }; | ||
159 | |||
160 | static inline int sq_must_quote(char c) | ||
161 | { | ||
162 | return sq_lookup[(unsigned char)c] + quote_path_fully > 0; | ||
163 | } | ||
164 | |||
165 | /* | ||
166 | * Returns the longest prefix not needing a quote up to maxlen if | ||
167 | * positive. | ||
168 | * This stops at the first \0 because it's marked as a character | ||
169 | * needing an escape. | ||
170 | */ | ||
171 | static ssize_t next_quote_pos(const char *s, ssize_t maxlen) | ||
172 | { | ||
173 | ssize_t len; | ||
174 | |||
175 | if (maxlen < 0) { | ||
176 | for (len = 0; !sq_must_quote(s[len]); len++); | ||
177 | } else { | ||
178 | for (len = 0; len < maxlen && !sq_must_quote(s[len]); len++); | ||
179 | } | ||
180 | return len; | ||
181 | } | ||
182 | |||
183 | /* | ||
184 | * C-style name quoting. | ||
185 | * | ||
186 | * (1) if sb and fp are both NULL, inspect the input name and counts the | ||
187 | * number of bytes that are needed to hold c_style quoted version of name, | ||
188 | * counting the double quotes around it but not terminating NUL, and | ||
189 | * returns it. | ||
190 | * However, if name does not need c_style quoting, it returns 0. | ||
191 | * | ||
192 | * (2) if sb or fp are not NULL, it emits the c_style quoted version | ||
193 | * of name, enclosed with double quotes if asked and needed only. | ||
194 | * Return value is the same as in (1). | ||
195 | */ | ||
196 | static size_t quote_c_style_counted(const char *name, ssize_t maxlen, | ||
197 | struct strbuf *sb, FILE *fp, int no_dq) | ||
198 | { | ||
199 | #define EMIT(c) \ | ||
200 | do { \ | ||
201 | if (sb) strbuf_addch(sb, (c)); \ | ||
202 | if (fp) fputc((c), fp); \ | ||
203 | count++; \ | ||
204 | } while (0) | ||
205 | |||
206 | #define EMITBUF(s, l) \ | ||
207 | do { \ | ||
208 | int __ret; \ | ||
209 | if (sb) strbuf_add(sb, (s), (l)); \ | ||
210 | if (fp) __ret = fwrite((s), (l), 1, fp); \ | ||
211 | count += (l); \ | ||
212 | } while (0) | ||
213 | |||
214 | ssize_t len, count = 0; | ||
215 | const char *p = name; | ||
216 | |||
217 | for (;;) { | ||
218 | int ch; | ||
219 | |||
220 | len = next_quote_pos(p, maxlen); | ||
221 | if (len == maxlen || !p[len]) | ||
222 | break; | ||
223 | |||
224 | if (!no_dq && p == name) | ||
225 | EMIT('"'); | ||
226 | |||
227 | EMITBUF(p, len); | ||
228 | EMIT('\\'); | ||
229 | p += len; | ||
230 | ch = (unsigned char)*p++; | ||
231 | if (sq_lookup[ch] >= ' ') { | ||
232 | EMIT(sq_lookup[ch]); | ||
233 | } else { | ||
234 | EMIT(((ch >> 6) & 03) + '0'); | ||
235 | EMIT(((ch >> 3) & 07) + '0'); | ||
236 | EMIT(((ch >> 0) & 07) + '0'); | ||
237 | } | ||
238 | } | ||
239 | |||
240 | EMITBUF(p, len); | ||
241 | if (p == name) /* no ending quote needed */ | ||
242 | return 0; | ||
243 | |||
244 | if (!no_dq) | ||
245 | EMIT('"'); | ||
246 | return count; | ||
247 | } | ||
248 | |||
249 | size_t quote_c_style(const char *name, struct strbuf *sb, FILE *fp, int nodq) | ||
250 | { | ||
251 | return quote_c_style_counted(name, -1, sb, fp, nodq); | ||
252 | } | ||
253 | |||
254 | void quote_two_c_style(struct strbuf *sb, const char *prefix, const char *path, int nodq) | ||
255 | { | ||
256 | if (quote_c_style(prefix, NULL, NULL, 0) || | ||
257 | quote_c_style(path, NULL, NULL, 0)) { | ||
258 | if (!nodq) | ||
259 | strbuf_addch(sb, '"'); | ||
260 | quote_c_style(prefix, sb, NULL, 1); | ||
261 | quote_c_style(path, sb, NULL, 1); | ||
262 | if (!nodq) | ||
263 | strbuf_addch(sb, '"'); | ||
264 | } else { | ||
265 | strbuf_addstr(sb, prefix); | ||
266 | strbuf_addstr(sb, path); | ||
267 | } | ||
268 | } | ||
269 | |||
270 | void write_name_quoted(const char *name, FILE *fp, int terminator) | ||
271 | { | ||
272 | if (terminator) { | ||
273 | quote_c_style(name, NULL, fp, 0); | ||
274 | } else { | ||
275 | fputs(name, fp); | ||
276 | } | ||
277 | fputc(terminator, fp); | ||
278 | } | ||
279 | |||
280 | void write_name_quotedpfx(const char *pfx, ssize_t pfxlen, | ||
281 | const char *name, FILE *fp, int terminator) | ||
282 | { | ||
283 | int needquote = 0; | ||
284 | |||
285 | if (terminator) { | ||
286 | needquote = next_quote_pos(pfx, pfxlen) < pfxlen | ||
287 | || name[next_quote_pos(name, -1)]; | ||
288 | } | ||
289 | if (needquote) { | ||
290 | fputc('"', fp); | ||
291 | quote_c_style_counted(pfx, pfxlen, NULL, fp, 1); | ||
292 | quote_c_style(name, NULL, fp, 1); | ||
293 | fputc('"', fp); | ||
294 | } else { | ||
295 | int ret; | ||
296 | |||
297 | ret = fwrite(pfx, pfxlen, 1, fp); | ||
298 | fputs(name, fp); | ||
299 | } | ||
300 | fputc(terminator, fp); | ||
301 | } | ||
302 | |||
303 | /* quote path as relative to the given prefix */ | ||
304 | char *quote_path_relative(const char *in, int len, | ||
305 | struct strbuf *out, const char *prefix) | ||
306 | { | ||
307 | int needquote; | ||
308 | |||
309 | if (len < 0) | ||
310 | len = strlen(in); | ||
311 | |||
312 | /* "../" prefix itself does not need quoting, but "in" might. */ | ||
313 | needquote = (next_quote_pos(in, len) < len); | ||
314 | strbuf_setlen(out, 0); | ||
315 | strbuf_grow(out, len); | ||
316 | |||
317 | if (needquote) | ||
318 | strbuf_addch(out, '"'); | ||
319 | if (prefix) { | ||
320 | int off = 0; | ||
321 | while (off < len && prefix[off] && prefix[off] == in[off]) | ||
322 | if (prefix[off] == '/') { | ||
323 | prefix += off + 1; | ||
324 | in += off + 1; | ||
325 | len -= off + 1; | ||
326 | off = 0; | ||
327 | } else | ||
328 | off++; | ||
329 | |||
330 | for (; *prefix; prefix++) | ||
331 | if (*prefix == '/') | ||
332 | strbuf_addstr(out, "../"); | ||
333 | } | ||
334 | |||
335 | quote_c_style_counted (in, len, out, NULL, 1); | ||
336 | |||
337 | if (needquote) | ||
338 | strbuf_addch(out, '"'); | ||
339 | if (!out->len) | ||
340 | strbuf_addstr(out, "./"); | ||
341 | |||
342 | return out->buf; | ||
343 | } | ||
344 | |||
345 | /* | ||
346 | * C-style name unquoting. | ||
347 | * | ||
348 | * Quoted should point at the opening double quote. | ||
349 | * + Returns 0 if it was able to unquote the string properly, and appends the | ||
350 | * result in the strbuf `sb'. | ||
351 | * + Returns -1 in case of error, and doesn't touch the strbuf. Though note | ||
352 | * that this function will allocate memory in the strbuf, so calling | ||
353 | * strbuf_release is mandatory whichever result unquote_c_style returns. | ||
354 | * | ||
355 | * Updates endp pointer to point at one past the ending double quote if given. | ||
356 | */ | ||
357 | int unquote_c_style(struct strbuf *sb, const char *quoted, const char **endp) | ||
358 | { | ||
359 | size_t oldlen = sb->len, len; | ||
360 | int ch, ac; | ||
361 | |||
362 | if (*quoted++ != '"') | ||
363 | return -1; | ||
364 | |||
365 | for (;;) { | ||
366 | len = strcspn(quoted, "\"\\"); | ||
367 | strbuf_add(sb, quoted, len); | ||
368 | quoted += len; | ||
369 | |||
370 | switch (*quoted++) { | ||
371 | case '"': | ||
372 | if (endp) | ||
373 | *endp = quoted; | ||
374 | return 0; | ||
375 | case '\\': | ||
376 | break; | ||
377 | default: | ||
378 | goto error; | ||
379 | } | ||
380 | |||
381 | switch ((ch = *quoted++)) { | ||
382 | case 'a': ch = '\a'; break; | ||
383 | case 'b': ch = '\b'; break; | ||
384 | case 'f': ch = '\f'; break; | ||
385 | case 'n': ch = '\n'; break; | ||
386 | case 'r': ch = '\r'; break; | ||
387 | case 't': ch = '\t'; break; | ||
388 | case 'v': ch = '\v'; break; | ||
389 | |||
390 | case '\\': case '"': | ||
391 | break; /* verbatim */ | ||
392 | |||
393 | /* octal values with first digit over 4 overflow */ | ||
394 | case '0': case '1': case '2': case '3': | ||
395 | ac = ((ch - '0') << 6); | ||
396 | if ((ch = *quoted++) < '0' || '7' < ch) | ||
397 | goto error; | ||
398 | ac |= ((ch - '0') << 3); | ||
399 | if ((ch = *quoted++) < '0' || '7' < ch) | ||
400 | goto error; | ||
401 | ac |= (ch - '0'); | ||
402 | ch = ac; | ||
403 | break; | ||
404 | default: | ||
405 | goto error; | ||
406 | } | ||
407 | strbuf_addch(sb, ch); | ||
408 | } | ||
409 | |||
410 | error: | ||
411 | strbuf_setlen(sb, oldlen); | ||
412 | return -1; | ||
413 | } | ||
414 | |||
415 | /* quoting as a string literal for other languages */ | ||
416 | |||
417 | void perl_quote_print(FILE *stream, const char *src) | ||
418 | { | ||
419 | const char sq = '\''; | ||
420 | const char bq = '\\'; | ||
421 | char c; | ||
422 | |||
423 | fputc(sq, stream); | ||
424 | while ((c = *src++)) { | ||
425 | if (c == sq || c == bq) | ||
426 | fputc(bq, stream); | ||
427 | fputc(c, stream); | ||
428 | } | ||
429 | fputc(sq, stream); | ||
430 | } | ||
431 | |||
432 | void python_quote_print(FILE *stream, const char *src) | ||
433 | { | ||
434 | const char sq = '\''; | ||
435 | const char bq = '\\'; | ||
436 | const char nl = '\n'; | ||
437 | char c; | ||
438 | |||
439 | fputc(sq, stream); | ||
440 | while ((c = *src++)) { | ||
441 | if (c == nl) { | ||
442 | fputc(bq, stream); | ||
443 | fputc('n', stream); | ||
444 | continue; | ||
445 | } | ||
446 | if (c == sq || c == bq) | ||
447 | fputc(bq, stream); | ||
448 | fputc(c, stream); | ||
449 | } | ||
450 | fputc(sq, stream); | ||
451 | } | ||
452 | |||
453 | void tcl_quote_print(FILE *stream, const char *src) | ||
454 | { | ||
455 | char c; | ||
456 | |||
457 | fputc('"', stream); | ||
458 | while ((c = *src++)) { | ||
459 | switch (c) { | ||
460 | case '[': case ']': | ||
461 | case '{': case '}': | ||
462 | case '$': case '\\': case '"': | ||
463 | fputc('\\', stream); | ||
464 | default: | ||
465 | fputc(c, stream); | ||
466 | break; | ||
467 | case '\f': | ||
468 | fputs("\\f", stream); | ||
469 | break; | ||
470 | case '\r': | ||
471 | fputs("\\r", stream); | ||
472 | break; | ||
473 | case '\n': | ||
474 | fputs("\\n", stream); | ||
475 | break; | ||
476 | case '\t': | ||
477 | fputs("\\t", stream); | ||
478 | break; | ||
479 | case '\v': | ||
480 | fputs("\\v", stream); | ||
481 | break; | ||
482 | } | ||
483 | } | ||
484 | fputc('"', stream); | ||
485 | } | ||
diff --git a/tools/perf/util/quote.h b/tools/perf/util/quote.h index b6a019733919..172889ea234f 100644 --- a/tools/perf/util/quote.h +++ b/tools/perf/util/quote.h | |||
@@ -22,47 +22,8 @@ | |||
22 | * | 22 | * |
23 | * Note that the above examples leak memory! Remember to free result from | 23 | * Note that the above examples leak memory! Remember to free result from |
24 | * sq_quote() in a real application. | 24 | * sq_quote() in a real application. |
25 | * | ||
26 | * sq_quote_buf() writes to an existing buffer of specified size; it | ||
27 | * will return the number of characters that would have been written | ||
28 | * excluding the final null regardless of the buffer size. | ||
29 | */ | 25 | */ |
30 | 26 | ||
31 | extern void sq_quote_print(FILE *stream, const char *src); | ||
32 | |||
33 | extern void sq_quote_buf(struct strbuf *, const char *src); | ||
34 | extern void sq_quote_argv(struct strbuf *, const char **argv, size_t maxlen); | 27 | extern void sq_quote_argv(struct strbuf *, const char **argv, size_t maxlen); |
35 | 28 | ||
36 | /* This unwraps what sq_quote() produces in place, but returns | ||
37 | * NULL if the input does not look like what sq_quote would have | ||
38 | * produced. | ||
39 | */ | ||
40 | extern char *sq_dequote(char *); | ||
41 | |||
42 | /* | ||
43 | * Same as the above, but can be used to unwrap many arguments in the | ||
44 | * same string separated by space. "next" is changed to point to the | ||
45 | * next argument that should be passed as first parameter. When there | ||
46 | * is no more argument to be dequoted, "next" is updated to point to NULL. | ||
47 | */ | ||
48 | extern char *sq_dequote_step(char *arg, char **next); | ||
49 | extern int sq_dequote_to_argv(char *arg, const char ***argv, int *nr, int *alloc); | ||
50 | |||
51 | extern int unquote_c_style(struct strbuf *, const char *quoted, const char **endp); | ||
52 | extern size_t quote_c_style(const char *name, struct strbuf *, FILE *, int no_dq); | ||
53 | extern void quote_two_c_style(struct strbuf *, const char *, const char *, int); | ||
54 | |||
55 | extern void write_name_quoted(const char *name, FILE *, int terminator); | ||
56 | extern void write_name_quotedpfx(const char *pfx, ssize_t pfxlen, | ||
57 | const char *name, FILE *, int terminator); | ||
58 | |||
59 | /* quote path as relative to the given prefix */ | ||
60 | char *quote_path_relative(const char *in, int len, | ||
61 | struct strbuf *out, const char *prefix); | ||
62 | |||
63 | /* quoting as a string literal for other languages */ | ||
64 | extern void perl_quote_print(FILE *stream, const char *src); | ||
65 | extern void python_quote_print(FILE *stream, const char *src); | ||
66 | extern void tcl_quote_print(FILE *stream, const char *src); | ||
67 | |||
68 | #endif /* __PERF_QUOTE_H */ | 29 | #endif /* __PERF_QUOTE_H */ |
diff --git a/tools/perf/util/run-command.c b/tools/perf/util/run-command.c index 2b615acf94d7..da8e9b285f51 100644 --- a/tools/perf/util/run-command.c +++ b/tools/perf/util/run-command.c | |||
@@ -212,93 +212,3 @@ int run_command_v_opt(const char **argv, int opt) | |||
212 | prepare_run_command_v_opt(&cmd, argv, opt); | 212 | prepare_run_command_v_opt(&cmd, argv, opt); |
213 | return run_command(&cmd); | 213 | return run_command(&cmd); |
214 | } | 214 | } |
215 | |||
216 | int run_command_v_opt_cd_env(const char **argv, int opt, const char *dir, const char *const *env) | ||
217 | { | ||
218 | struct child_process cmd; | ||
219 | prepare_run_command_v_opt(&cmd, argv, opt); | ||
220 | cmd.dir = dir; | ||
221 | cmd.env = env; | ||
222 | return run_command(&cmd); | ||
223 | } | ||
224 | |||
225 | int start_async(struct async *async) | ||
226 | { | ||
227 | int pipe_out[2]; | ||
228 | |||
229 | if (pipe(pipe_out) < 0) | ||
230 | return error("cannot create pipe: %s", strerror(errno)); | ||
231 | async->out = pipe_out[0]; | ||
232 | |||
233 | /* Flush stdio before fork() to avoid cloning buffers */ | ||
234 | fflush(NULL); | ||
235 | |||
236 | async->pid = fork(); | ||
237 | if (async->pid < 0) { | ||
238 | error("fork (async) failed: %s", strerror(errno)); | ||
239 | close_pair(pipe_out); | ||
240 | return -1; | ||
241 | } | ||
242 | if (!async->pid) { | ||
243 | close(pipe_out[0]); | ||
244 | exit(!!async->proc(pipe_out[1], async->data)); | ||
245 | } | ||
246 | close(pipe_out[1]); | ||
247 | |||
248 | return 0; | ||
249 | } | ||
250 | |||
251 | int finish_async(struct async *async) | ||
252 | { | ||
253 | int ret = 0; | ||
254 | |||
255 | if (wait_or_whine(async->pid)) | ||
256 | ret = error("waitpid (async) failed"); | ||
257 | |||
258 | return ret; | ||
259 | } | ||
260 | |||
261 | int run_hook(const char *index_file, const char *name, ...) | ||
262 | { | ||
263 | struct child_process hook; | ||
264 | const char **argv = NULL, *env[2]; | ||
265 | char idx[PATH_MAX]; | ||
266 | va_list args; | ||
267 | int ret; | ||
268 | size_t i = 0, alloc = 0; | ||
269 | |||
270 | if (access(perf_path("hooks/%s", name), X_OK) < 0) | ||
271 | return 0; | ||
272 | |||
273 | va_start(args, name); | ||
274 | ALLOC_GROW(argv, i + 1, alloc); | ||
275 | argv[i++] = perf_path("hooks/%s", name); | ||
276 | while (argv[i-1]) { | ||
277 | ALLOC_GROW(argv, i + 1, alloc); | ||
278 | argv[i++] = va_arg(args, const char *); | ||
279 | } | ||
280 | va_end(args); | ||
281 | |||
282 | memset(&hook, 0, sizeof(hook)); | ||
283 | hook.argv = argv; | ||
284 | hook.no_stdin = 1; | ||
285 | hook.stdout_to_stderr = 1; | ||
286 | if (index_file) { | ||
287 | snprintf(idx, sizeof(idx), "PERF_INDEX_FILE=%s", index_file); | ||
288 | env[0] = idx; | ||
289 | env[1] = NULL; | ||
290 | hook.env = env; | ||
291 | } | ||
292 | |||
293 | ret = start_command(&hook); | ||
294 | free(argv); | ||
295 | if (ret) { | ||
296 | warning("Could not spawn %s", argv[0]); | ||
297 | return ret; | ||
298 | } | ||
299 | ret = finish_command(&hook); | ||
300 | if (ret == -ERR_RUN_COMMAND_WAITPID_SIGNAL) | ||
301 | warning("%s exited due to uncaught signal", argv[0]); | ||
302 | |||
303 | return ret; | ||
304 | } | ||
diff --git a/tools/perf/util/run-command.h b/tools/perf/util/run-command.h index d79028727ce2..1ef264d5069c 100644 --- a/tools/perf/util/run-command.h +++ b/tools/perf/util/run-command.h | |||
@@ -50,39 +50,9 @@ int start_command(struct child_process *); | |||
50 | int finish_command(struct child_process *); | 50 | int finish_command(struct child_process *); |
51 | int run_command(struct child_process *); | 51 | int run_command(struct child_process *); |
52 | 52 | ||
53 | extern int run_hook(const char *index_file, const char *name, ...); | ||
54 | |||
55 | #define RUN_COMMAND_NO_STDIN 1 | 53 | #define RUN_COMMAND_NO_STDIN 1 |
56 | #define RUN_PERF_CMD 2 /*If this is to be perf sub-command */ | 54 | #define RUN_PERF_CMD 2 /*If this is to be perf sub-command */ |
57 | #define RUN_COMMAND_STDOUT_TO_STDERR 4 | 55 | #define RUN_COMMAND_STDOUT_TO_STDERR 4 |
58 | int run_command_v_opt(const char **argv, int opt); | 56 | int run_command_v_opt(const char **argv, int opt); |
59 | 57 | ||
60 | /* | ||
61 | * env (the environment) is to be formatted like environ: "VAR=VALUE". | ||
62 | * To unset an environment variable use just "VAR". | ||
63 | */ | ||
64 | int run_command_v_opt_cd_env(const char **argv, int opt, const char *dir, const char *const *env); | ||
65 | |||
66 | /* | ||
67 | * The purpose of the following functions is to feed a pipe by running | ||
68 | * a function asynchronously and providing output that the caller reads. | ||
69 | * | ||
70 | * It is expected that no synchronization and mutual exclusion between | ||
71 | * the caller and the feed function is necessary so that the function | ||
72 | * can run in a thread without interfering with the caller. | ||
73 | */ | ||
74 | struct async { | ||
75 | /* | ||
76 | * proc writes to fd and closes it; | ||
77 | * returns 0 on success, non-zero on failure | ||
78 | */ | ||
79 | int (*proc)(int fd, void *data); | ||
80 | void *data; | ||
81 | int out; /* caller reads from here and closes it */ | ||
82 | pid_t pid; | ||
83 | }; | ||
84 | |||
85 | int start_async(struct async *async); | ||
86 | int finish_async(struct async *async); | ||
87 | |||
88 | #endif /* __PERF_RUN_COMMAND_H */ | 58 | #endif /* __PERF_RUN_COMMAND_H */ |
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 25bfca4f10f0..8f83a1835766 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c | |||
@@ -5,6 +5,7 @@ | |||
5 | #include <byteswap.h> | 5 | #include <byteswap.h> |
6 | #include <unistd.h> | 6 | #include <unistd.h> |
7 | #include <sys/types.h> | 7 | #include <sys/types.h> |
8 | #include <sys/mman.h> | ||
8 | 9 | ||
9 | #include "session.h" | 10 | #include "session.h" |
10 | #include "sort.h" | 11 | #include "sort.h" |
@@ -894,3 +895,10 @@ size_t perf_session__fprintf_dsos(struct perf_session *self, FILE *fp) | |||
894 | __dsos__fprintf(&self->host_machine.user_dsos, fp) + | 895 | __dsos__fprintf(&self->host_machine.user_dsos, fp) + |
895 | machines__fprintf_dsos(&self->machines, fp); | 896 | machines__fprintf_dsos(&self->machines, fp); |
896 | } | 897 | } |
898 | |||
899 | size_t perf_session__fprintf_dsos_buildid(struct perf_session *self, FILE *fp, | ||
900 | bool with_hits) | ||
901 | { | ||
902 | size_t ret = machine__fprintf_dsos_buildid(&self->host_machine, fp, with_hits); | ||
903 | return ret + machines__fprintf_dsos_buildid(&self->machines, fp, with_hits); | ||
904 | } | ||
diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h index e7fce486ebe2..55c6881b218d 100644 --- a/tools/perf/util/session.h +++ b/tools/perf/util/session.h | |||
@@ -132,12 +132,8 @@ void perf_session__process_machines(struct perf_session *self, | |||
132 | 132 | ||
133 | size_t perf_session__fprintf_dsos(struct perf_session *self, FILE *fp); | 133 | size_t perf_session__fprintf_dsos(struct perf_session *self, FILE *fp); |
134 | 134 | ||
135 | static inline | 135 | size_t perf_session__fprintf_dsos_buildid(struct perf_session *self, |
136 | size_t perf_session__fprintf_dsos_buildid(struct perf_session *self, FILE *fp, | 136 | FILE *fp, bool with_hits); |
137 | bool with_hits) | ||
138 | { | ||
139 | return machines__fprintf_dsos_buildid(&self->machines, fp, with_hits); | ||
140 | } | ||
141 | 137 | ||
142 | static inline | 138 | static inline |
143 | size_t perf_session__fprintf_nr_events(struct perf_session *self, FILE *fp) | 139 | size_t perf_session__fprintf_nr_events(struct perf_session *self, FILE *fp) |
diff --git a/tools/perf/util/sigchain.c b/tools/perf/util/sigchain.c index 1118b99e57d3..ba785e9b1841 100644 --- a/tools/perf/util/sigchain.c +++ b/tools/perf/util/sigchain.c | |||
@@ -16,7 +16,7 @@ static void check_signum(int sig) | |||
16 | die("BUG: signal out of range: %d", sig); | 16 | die("BUG: signal out of range: %d", sig); |
17 | } | 17 | } |
18 | 18 | ||
19 | int sigchain_push(int sig, sigchain_fun f) | 19 | static int sigchain_push(int sig, sigchain_fun f) |
20 | { | 20 | { |
21 | struct sigchain_signal *s = signals + sig; | 21 | struct sigchain_signal *s = signals + sig; |
22 | check_signum(sig); | 22 | check_signum(sig); |
diff --git a/tools/perf/util/sigchain.h b/tools/perf/util/sigchain.h index 1a53c11265fd..959d64eb5557 100644 --- a/tools/perf/util/sigchain.h +++ b/tools/perf/util/sigchain.h | |||
@@ -3,7 +3,6 @@ | |||
3 | 3 | ||
4 | typedef void (*sigchain_fun)(int); | 4 | typedef void (*sigchain_fun)(int); |
5 | 5 | ||
6 | int sigchain_push(int sig, sigchain_fun f); | ||
7 | int sigchain_pop(int sig); | 6 | int sigchain_pop(int sig); |
8 | 7 | ||
9 | void sigchain_push_common(sigchain_fun f); | 8 | void sigchain_push_common(sigchain_fun f); |
diff --git a/tools/perf/util/strbuf.c b/tools/perf/util/strbuf.c index 5249d5a1b0c2..92e068517c1a 100644 --- a/tools/perf/util/strbuf.c +++ b/tools/perf/util/strbuf.c | |||
@@ -41,16 +41,6 @@ char *strbuf_detach(struct strbuf *sb, size_t *sz) | |||
41 | return res; | 41 | return res; |
42 | } | 42 | } |
43 | 43 | ||
44 | void strbuf_attach(struct strbuf *sb, void *buf, size_t len, size_t alloc) | ||
45 | { | ||
46 | strbuf_release(sb); | ||
47 | sb->buf = buf; | ||
48 | sb->len = len; | ||
49 | sb->alloc = alloc; | ||
50 | strbuf_grow(sb, 0); | ||
51 | sb->buf[sb->len] = '\0'; | ||
52 | } | ||
53 | |||
54 | void strbuf_grow(struct strbuf *sb, size_t extra) | 44 | void strbuf_grow(struct strbuf *sb, size_t extra) |
55 | { | 45 | { |
56 | if (sb->len + extra + 1 <= sb->len) | 46 | if (sb->len + extra + 1 <= sb->len) |
@@ -60,94 +50,7 @@ void strbuf_grow(struct strbuf *sb, size_t extra) | |||
60 | ALLOC_GROW(sb->buf, sb->len + extra + 1, sb->alloc); | 50 | ALLOC_GROW(sb->buf, sb->len + extra + 1, sb->alloc); |
61 | } | 51 | } |
62 | 52 | ||
63 | void strbuf_trim(struct strbuf *sb) | 53 | static void strbuf_splice(struct strbuf *sb, size_t pos, size_t len, |
64 | { | ||
65 | char *b = sb->buf; | ||
66 | while (sb->len > 0 && isspace((unsigned char)sb->buf[sb->len - 1])) | ||
67 | sb->len--; | ||
68 | while (sb->len > 0 && isspace(*b)) { | ||
69 | b++; | ||
70 | sb->len--; | ||
71 | } | ||
72 | memmove(sb->buf, b, sb->len); | ||
73 | sb->buf[sb->len] = '\0'; | ||
74 | } | ||
75 | void strbuf_rtrim(struct strbuf *sb) | ||
76 | { | ||
77 | while (sb->len > 0 && isspace((unsigned char)sb->buf[sb->len - 1])) | ||
78 | sb->len--; | ||
79 | sb->buf[sb->len] = '\0'; | ||
80 | } | ||
81 | |||
82 | void strbuf_ltrim(struct strbuf *sb) | ||
83 | { | ||
84 | char *b = sb->buf; | ||
85 | while (sb->len > 0 && isspace(*b)) { | ||
86 | b++; | ||
87 | sb->len--; | ||
88 | } | ||
89 | memmove(sb->buf, b, sb->len); | ||
90 | sb->buf[sb->len] = '\0'; | ||
91 | } | ||
92 | |||
93 | void strbuf_tolower(struct strbuf *sb) | ||
94 | { | ||
95 | unsigned int i; | ||
96 | |||
97 | for (i = 0; i < sb->len; i++) | ||
98 | sb->buf[i] = tolower(sb->buf[i]); | ||
99 | } | ||
100 | |||
101 | struct strbuf **strbuf_split(const struct strbuf *sb, int delim) | ||
102 | { | ||
103 | int alloc = 2, pos = 0; | ||
104 | char *n, *p; | ||
105 | struct strbuf **ret; | ||
106 | struct strbuf *t; | ||
107 | |||
108 | ret = calloc(alloc, sizeof(struct strbuf *)); | ||
109 | p = n = sb->buf; | ||
110 | while (n < sb->buf + sb->len) { | ||
111 | int len; | ||
112 | n = memchr(n, delim, sb->len - (n - sb->buf)); | ||
113 | if (pos + 1 >= alloc) { | ||
114 | alloc = alloc * 2; | ||
115 | ret = realloc(ret, sizeof(struct strbuf *) * alloc); | ||
116 | } | ||
117 | if (!n) | ||
118 | n = sb->buf + sb->len - 1; | ||
119 | len = n - p + 1; | ||
120 | t = malloc(sizeof(struct strbuf)); | ||
121 | strbuf_init(t, len); | ||
122 | strbuf_add(t, p, len); | ||
123 | ret[pos] = t; | ||
124 | ret[++pos] = NULL; | ||
125 | p = ++n; | ||
126 | } | ||
127 | return ret; | ||
128 | } | ||
129 | |||
130 | void strbuf_list_free(struct strbuf **sbs) | ||
131 | { | ||
132 | struct strbuf **s = sbs; | ||
133 | |||
134 | while (*s) { | ||
135 | strbuf_release(*s); | ||
136 | free(*s++); | ||
137 | } | ||
138 | free(sbs); | ||
139 | } | ||
140 | |||
141 | int strbuf_cmp(const struct strbuf *a, const struct strbuf *b) | ||
142 | { | ||
143 | int len = a->len < b->len ? a->len: b->len; | ||
144 | int cmp = memcmp(a->buf, b->buf, len); | ||
145 | if (cmp) | ||
146 | return cmp; | ||
147 | return a->len < b->len ? -1: a->len != b->len; | ||
148 | } | ||
149 | |||
150 | void strbuf_splice(struct strbuf *sb, size_t pos, size_t len, | ||
151 | const void *data, size_t dlen) | 54 | const void *data, size_t dlen) |
152 | { | 55 | { |
153 | if (pos + len < pos) | 56 | if (pos + len < pos) |
@@ -166,11 +69,6 @@ void strbuf_splice(struct strbuf *sb, size_t pos, size_t len, | |||
166 | strbuf_setlen(sb, sb->len + dlen - len); | 69 | strbuf_setlen(sb, sb->len + dlen - len); |
167 | } | 70 | } |
168 | 71 | ||
169 | void strbuf_insert(struct strbuf *sb, size_t pos, const void *data, size_t len) | ||
170 | { | ||
171 | strbuf_splice(sb, pos, 0, data, len); | ||
172 | } | ||
173 | |||
174 | void strbuf_remove(struct strbuf *sb, size_t pos, size_t len) | 72 | void strbuf_remove(struct strbuf *sb, size_t pos, size_t len) |
175 | { | 73 | { |
176 | strbuf_splice(sb, pos, len, NULL, 0); | 74 | strbuf_splice(sb, pos, len, NULL, 0); |
@@ -183,13 +81,6 @@ void strbuf_add(struct strbuf *sb, const void *data, size_t len) | |||
183 | strbuf_setlen(sb, sb->len + len); | 81 | strbuf_setlen(sb, sb->len + len); |
184 | } | 82 | } |
185 | 83 | ||
186 | void strbuf_adddup(struct strbuf *sb, size_t pos, size_t len) | ||
187 | { | ||
188 | strbuf_grow(sb, len); | ||
189 | memcpy(sb->buf + sb->len, sb->buf + pos, len); | ||
190 | strbuf_setlen(sb, sb->len + len); | ||
191 | } | ||
192 | |||
193 | void strbuf_addf(struct strbuf *sb, const char *fmt, ...) | 84 | void strbuf_addf(struct strbuf *sb, const char *fmt, ...) |
194 | { | 85 | { |
195 | int len; | 86 | int len; |
@@ -214,57 +105,6 @@ void strbuf_addf(struct strbuf *sb, const char *fmt, ...) | |||
214 | strbuf_setlen(sb, sb->len + len); | 105 | strbuf_setlen(sb, sb->len + len); |
215 | } | 106 | } |
216 | 107 | ||
217 | void strbuf_expand(struct strbuf *sb, const char *format, expand_fn_t fn, | ||
218 | void *context) | ||
219 | { | ||
220 | for (;;) { | ||
221 | const char *percent; | ||
222 | size_t consumed; | ||
223 | |||
224 | percent = strchrnul(format, '%'); | ||
225 | strbuf_add(sb, format, percent - format); | ||
226 | if (!*percent) | ||
227 | break; | ||
228 | format = percent + 1; | ||
229 | |||
230 | consumed = fn(sb, format, context); | ||
231 | if (consumed) | ||
232 | format += consumed; | ||
233 | else | ||
234 | strbuf_addch(sb, '%'); | ||
235 | } | ||
236 | } | ||
237 | |||
238 | size_t strbuf_expand_dict_cb(struct strbuf *sb, const char *placeholder, | ||
239 | void *context) | ||
240 | { | ||
241 | struct strbuf_expand_dict_entry *e = context; | ||
242 | size_t len; | ||
243 | |||
244 | for (; e->placeholder && (len = strlen(e->placeholder)); e++) { | ||
245 | if (!strncmp(placeholder, e->placeholder, len)) { | ||
246 | if (e->value) | ||
247 | strbuf_addstr(sb, e->value); | ||
248 | return len; | ||
249 | } | ||
250 | } | ||
251 | return 0; | ||
252 | } | ||
253 | |||
254 | size_t strbuf_fread(struct strbuf *sb, size_t size, FILE *f) | ||
255 | { | ||
256 | size_t res; | ||
257 | size_t oldalloc = sb->alloc; | ||
258 | |||
259 | strbuf_grow(sb, size); | ||
260 | res = fread(sb->buf + sb->len, 1, size, f); | ||
261 | if (res > 0) | ||
262 | strbuf_setlen(sb, sb->len + res); | ||
263 | else if (oldalloc == 0) | ||
264 | strbuf_release(sb); | ||
265 | return res; | ||
266 | } | ||
267 | |||
268 | ssize_t strbuf_read(struct strbuf *sb, int fd, ssize_t hint) | 108 | ssize_t strbuf_read(struct strbuf *sb, int fd, ssize_t hint) |
269 | { | 109 | { |
270 | size_t oldlen = sb->len; | 110 | size_t oldlen = sb->len; |
@@ -291,70 +131,3 @@ ssize_t strbuf_read(struct strbuf *sb, int fd, ssize_t hint) | |||
291 | sb->buf[sb->len] = '\0'; | 131 | sb->buf[sb->len] = '\0'; |
292 | return sb->len - oldlen; | 132 | return sb->len - oldlen; |
293 | } | 133 | } |
294 | |||
295 | #define STRBUF_MAXLINK (2*PATH_MAX) | ||
296 | |||
297 | int strbuf_readlink(struct strbuf *sb, const char *path, ssize_t hint) | ||
298 | { | ||
299 | size_t oldalloc = sb->alloc; | ||
300 | |||
301 | if (hint < 32) | ||
302 | hint = 32; | ||
303 | |||
304 | while (hint < STRBUF_MAXLINK) { | ||
305 | ssize_t len; | ||
306 | |||
307 | strbuf_grow(sb, hint); | ||
308 | len = readlink(path, sb->buf, hint); | ||
309 | if (len < 0) { | ||
310 | if (errno != ERANGE) | ||
311 | break; | ||
312 | } else if (len < hint) { | ||
313 | strbuf_setlen(sb, len); | ||
314 | return 0; | ||
315 | } | ||
316 | |||
317 | /* .. the buffer was too small - try again */ | ||
318 | hint *= 2; | ||
319 | } | ||
320 | if (oldalloc == 0) | ||
321 | strbuf_release(sb); | ||
322 | return -1; | ||
323 | } | ||
324 | |||
325 | int strbuf_getline(struct strbuf *sb, FILE *fp, int term) | ||
326 | { | ||
327 | int ch; | ||
328 | |||
329 | strbuf_grow(sb, 0); | ||
330 | if (feof(fp)) | ||
331 | return EOF; | ||
332 | |||
333 | strbuf_reset(sb); | ||
334 | while ((ch = fgetc(fp)) != EOF) { | ||
335 | if (ch == term) | ||
336 | break; | ||
337 | strbuf_grow(sb, 1); | ||
338 | sb->buf[sb->len++] = ch; | ||
339 | } | ||
340 | if (ch == EOF && sb->len == 0) | ||
341 | return EOF; | ||
342 | |||
343 | sb->buf[sb->len] = '\0'; | ||
344 | return 0; | ||
345 | } | ||
346 | |||
347 | int strbuf_read_file(struct strbuf *sb, const char *path, ssize_t hint) | ||
348 | { | ||
349 | int fd, len; | ||
350 | |||
351 | fd = open(path, O_RDONLY); | ||
352 | if (fd < 0) | ||
353 | return -1; | ||
354 | len = strbuf_read(sb, fd, hint); | ||
355 | close(fd); | ||
356 | if (len < 0) | ||
357 | return -1; | ||
358 | |||
359 | return len; | ||
360 | } | ||
diff --git a/tools/perf/util/strbuf.h b/tools/perf/util/strbuf.h index a3d121d6c83e..436ac319f6c7 100644 --- a/tools/perf/util/strbuf.h +++ b/tools/perf/util/strbuf.h | |||
@@ -53,12 +53,6 @@ struct strbuf { | |||
53 | extern void strbuf_init(struct strbuf *buf, ssize_t hint); | 53 | extern void strbuf_init(struct strbuf *buf, ssize_t hint); |
54 | extern void strbuf_release(struct strbuf *); | 54 | extern void strbuf_release(struct strbuf *); |
55 | extern char *strbuf_detach(struct strbuf *, size_t *); | 55 | extern char *strbuf_detach(struct strbuf *, size_t *); |
56 | extern void strbuf_attach(struct strbuf *, void *, size_t, size_t); | ||
57 | static inline void strbuf_swap(struct strbuf *a, struct strbuf *b) { | ||
58 | struct strbuf tmp = *a; | ||
59 | *a = *b; | ||
60 | *b = tmp; | ||
61 | } | ||
62 | 56 | ||
63 | /*----- strbuf size related -----*/ | 57 | /*----- strbuf size related -----*/ |
64 | static inline ssize_t strbuf_avail(const struct strbuf *sb) { | 58 | static inline ssize_t strbuf_avail(const struct strbuf *sb) { |
@@ -74,17 +68,6 @@ static inline void strbuf_setlen(struct strbuf *sb, size_t len) { | |||
74 | sb->len = len; | 68 | sb->len = len; |
75 | sb->buf[len] = '\0'; | 69 | sb->buf[len] = '\0'; |
76 | } | 70 | } |
77 | #define strbuf_reset(sb) strbuf_setlen(sb, 0) | ||
78 | |||
79 | /*----- content related -----*/ | ||
80 | extern void strbuf_trim(struct strbuf *); | ||
81 | extern void strbuf_rtrim(struct strbuf *); | ||
82 | extern void strbuf_ltrim(struct strbuf *); | ||
83 | extern int strbuf_cmp(const struct strbuf *, const struct strbuf *); | ||
84 | extern void strbuf_tolower(struct strbuf *); | ||
85 | |||
86 | extern struct strbuf **strbuf_split(const struct strbuf *, int delim); | ||
87 | extern void strbuf_list_free(struct strbuf **); | ||
88 | 71 | ||
89 | /*----- add data in your buffer -----*/ | 72 | /*----- add data in your buffer -----*/ |
90 | static inline void strbuf_addch(struct strbuf *sb, int c) { | 73 | static inline void strbuf_addch(struct strbuf *sb, int c) { |
@@ -93,45 +76,17 @@ static inline void strbuf_addch(struct strbuf *sb, int c) { | |||
93 | sb->buf[sb->len] = '\0'; | 76 | sb->buf[sb->len] = '\0'; |
94 | } | 77 | } |
95 | 78 | ||
96 | extern void strbuf_insert(struct strbuf *, size_t pos, const void *, size_t); | ||
97 | extern void strbuf_remove(struct strbuf *, size_t pos, size_t len); | 79 | extern void strbuf_remove(struct strbuf *, size_t pos, size_t len); |
98 | 80 | ||
99 | /* splice pos..pos+len with given data */ | ||
100 | extern void strbuf_splice(struct strbuf *, size_t pos, size_t len, | ||
101 | const void *, size_t); | ||
102 | |||
103 | extern void strbuf_add(struct strbuf *, const void *, size_t); | 81 | extern void strbuf_add(struct strbuf *, const void *, size_t); |
104 | static inline void strbuf_addstr(struct strbuf *sb, const char *s) { | 82 | static inline void strbuf_addstr(struct strbuf *sb, const char *s) { |
105 | strbuf_add(sb, s, strlen(s)); | 83 | strbuf_add(sb, s, strlen(s)); |
106 | } | 84 | } |
107 | static inline void strbuf_addbuf(struct strbuf *sb, const struct strbuf *sb2) { | ||
108 | strbuf_add(sb, sb2->buf, sb2->len); | ||
109 | } | ||
110 | extern void strbuf_adddup(struct strbuf *sb, size_t pos, size_t len); | ||
111 | |||
112 | typedef size_t (*expand_fn_t) (struct strbuf *sb, const char *placeholder, void *context); | ||
113 | extern void strbuf_expand(struct strbuf *sb, const char *format, expand_fn_t fn, void *context); | ||
114 | struct strbuf_expand_dict_entry { | ||
115 | const char *placeholder; | ||
116 | const char *value; | ||
117 | }; | ||
118 | extern size_t strbuf_expand_dict_cb(struct strbuf *sb, const char *placeholder, void *context); | ||
119 | 85 | ||
120 | __attribute__((format(printf,2,3))) | 86 | __attribute__((format(printf,2,3))) |
121 | extern void strbuf_addf(struct strbuf *sb, const char *fmt, ...); | 87 | extern void strbuf_addf(struct strbuf *sb, const char *fmt, ...); |
122 | 88 | ||
123 | extern size_t strbuf_fread(struct strbuf *, size_t, FILE *); | ||
124 | /* XXX: if read fails, any partial read is undone */ | 89 | /* XXX: if read fails, any partial read is undone */ |
125 | extern ssize_t strbuf_read(struct strbuf *, int fd, ssize_t hint); | 90 | extern ssize_t strbuf_read(struct strbuf *, int fd, ssize_t hint); |
126 | extern int strbuf_read_file(struct strbuf *sb, const char *path, ssize_t hint); | ||
127 | extern int strbuf_readlink(struct strbuf *sb, const char *path, ssize_t hint); | ||
128 | |||
129 | extern int strbuf_getline(struct strbuf *, FILE *, int); | ||
130 | |||
131 | extern void stripspace(struct strbuf *buf, int skip_comments); | ||
132 | extern int launch_editor(const char *path, struct strbuf *buffer, const char *const *env); | ||
133 | |||
134 | extern int strbuf_branchname(struct strbuf *sb, const char *name); | ||
135 | extern int strbuf_check_branch_ref(struct strbuf *sb, const char *name); | ||
136 | 91 | ||
137 | #endif /* __PERF_STRBUF_H */ | 92 | #endif /* __PERF_STRBUF_H */ |
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c index a06131f6259a..aaa51ba147df 100644 --- a/tools/perf/util/symbol.c +++ b/tools/perf/util/symbol.c | |||
@@ -11,6 +11,7 @@ | |||
11 | #include <sys/param.h> | 11 | #include <sys/param.h> |
12 | #include <fcntl.h> | 12 | #include <fcntl.h> |
13 | #include <unistd.h> | 13 | #include <unistd.h> |
14 | #include "build-id.h" | ||
14 | #include "symbol.h" | 15 | #include "symbol.h" |
15 | #include "strlist.h" | 16 | #include "strlist.h" |
16 | 17 | ||
@@ -1131,6 +1132,10 @@ bool __dsos__read_build_ids(struct list_head *head, bool with_hits) | |||
1131 | list_for_each_entry(pos, head, node) { | 1132 | list_for_each_entry(pos, head, node) { |
1132 | if (with_hits && !pos->hit) | 1133 | if (with_hits && !pos->hit) |
1133 | continue; | 1134 | continue; |
1135 | if (pos->has_build_id) { | ||
1136 | have_build_id = true; | ||
1137 | continue; | ||
1138 | } | ||
1134 | if (filename__read_build_id(pos->long_name, pos->build_id, | 1139 | if (filename__read_build_id(pos->long_name, pos->build_id, |
1135 | sizeof(pos->build_id)) > 0) { | 1140 | sizeof(pos->build_id)) > 0) { |
1136 | have_build_id = true; | 1141 | have_build_id = true; |
@@ -1289,7 +1294,6 @@ int dso__load(struct dso *self, struct map *map, symbol_filter_t filter) | |||
1289 | int size = PATH_MAX; | 1294 | int size = PATH_MAX; |
1290 | char *name; | 1295 | char *name; |
1291 | u8 build_id[BUILD_ID_SIZE]; | 1296 | u8 build_id[BUILD_ID_SIZE]; |
1292 | char build_id_hex[BUILD_ID_SIZE * 2 + 1]; | ||
1293 | int ret = -1; | 1297 | int ret = -1; |
1294 | int fd; | 1298 | int fd; |
1295 | struct machine *machine; | 1299 | struct machine *machine; |
@@ -1321,15 +1325,8 @@ int dso__load(struct dso *self, struct map *map, symbol_filter_t filter) | |||
1321 | } | 1325 | } |
1322 | 1326 | ||
1323 | self->origin = DSO__ORIG_BUILD_ID_CACHE; | 1327 | self->origin = DSO__ORIG_BUILD_ID_CACHE; |
1324 | 1328 | if (dso__build_id_filename(self, name, size) != NULL) | |
1325 | if (self->has_build_id) { | ||
1326 | build_id__sprintf(self->build_id, sizeof(self->build_id), | ||
1327 | build_id_hex); | ||
1328 | snprintf(name, size, "%s/%s/.build-id/%.2s/%s", | ||
1329 | getenv("HOME"), DEBUG_CACHE_DIR, | ||
1330 | build_id_hex, build_id_hex + 2); | ||
1331 | goto open_file; | 1329 | goto open_file; |
1332 | } | ||
1333 | more: | 1330 | more: |
1334 | do { | 1331 | do { |
1335 | self->origin++; | 1332 | self->origin++; |
@@ -1345,6 +1342,7 @@ more: | |||
1345 | case DSO__ORIG_BUILDID: | 1342 | case DSO__ORIG_BUILDID: |
1346 | if (filename__read_build_id(self->long_name, build_id, | 1343 | if (filename__read_build_id(self->long_name, build_id, |
1347 | sizeof(build_id))) { | 1344 | sizeof(build_id))) { |
1345 | char build_id_hex[BUILD_ID_SIZE * 2 + 1]; | ||
1348 | build_id__sprintf(build_id, sizeof(build_id), | 1346 | build_id__sprintf(build_id, sizeof(build_id), |
1349 | build_id_hex); | 1347 | build_id_hex); |
1350 | snprintf(name, size, | 1348 | snprintf(name, size, |
@@ -1933,6 +1931,12 @@ static size_t __dsos__fprintf_buildid(struct list_head *head, FILE *fp, | |||
1933 | return ret; | 1931 | return ret; |
1934 | } | 1932 | } |
1935 | 1933 | ||
1934 | size_t machine__fprintf_dsos_buildid(struct machine *self, FILE *fp, bool with_hits) | ||
1935 | { | ||
1936 | return __dsos__fprintf_buildid(&self->kernel_dsos, fp, with_hits) + | ||
1937 | __dsos__fprintf_buildid(&self->user_dsos, fp, with_hits); | ||
1938 | } | ||
1939 | |||
1936 | size_t machines__fprintf_dsos_buildid(struct rb_root *self, FILE *fp, bool with_hits) | 1940 | size_t machines__fprintf_dsos_buildid(struct rb_root *self, FILE *fp, bool with_hits) |
1937 | { | 1941 | { |
1938 | struct rb_node *nd; | 1942 | struct rb_node *nd; |
@@ -1940,8 +1944,7 @@ size_t machines__fprintf_dsos_buildid(struct rb_root *self, FILE *fp, bool with_ | |||
1940 | 1944 | ||
1941 | for (nd = rb_first(self); nd; nd = rb_next(nd)) { | 1945 | for (nd = rb_first(self); nd; nd = rb_next(nd)) { |
1942 | struct machine *pos = rb_entry(nd, struct machine, rb_node); | 1946 | struct machine *pos = rb_entry(nd, struct machine, rb_node); |
1943 | ret += __dsos__fprintf_buildid(&pos->kernel_dsos, fp, with_hits); | 1947 | ret += machine__fprintf_dsos_buildid(pos, fp, with_hits); |
1944 | ret += __dsos__fprintf_buildid(&pos->user_dsos, fp, with_hits); | ||
1945 | } | 1948 | } |
1946 | return ret; | 1949 | return ret; |
1947 | } | 1950 | } |
diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h index 032469e41876..5d25b5eb1456 100644 --- a/tools/perf/util/symbol.h +++ b/tools/perf/util/symbol.h | |||
@@ -170,6 +170,7 @@ int machine__load_vmlinux_path(struct machine *self, enum map_type type, | |||
170 | 170 | ||
171 | size_t __dsos__fprintf(struct list_head *head, FILE *fp); | 171 | size_t __dsos__fprintf(struct list_head *head, FILE *fp); |
172 | 172 | ||
173 | size_t machine__fprintf_dsos_buildid(struct machine *self, FILE *fp, bool with_hits); | ||
173 | size_t machines__fprintf_dsos(struct rb_root *self, FILE *fp); | 174 | size_t machines__fprintf_dsos(struct rb_root *self, FILE *fp); |
174 | size_t machines__fprintf_dsos_buildid(struct rb_root *self, FILE *fp, bool with_hits); | 175 | size_t machines__fprintf_dsos_buildid(struct rb_root *self, FILE *fp, bool with_hits); |
175 | 176 | ||
diff --git a/tools/perf/util/trace-event-read.c b/tools/perf/util/trace-event-read.c index cb54cd002f49..f55cc3a765a1 100644 --- a/tools/perf/util/trace-event-read.c +++ b/tools/perf/util/trace-event-read.c | |||
@@ -53,12 +53,6 @@ static unsigned long page_size; | |||
53 | static ssize_t calc_data_size; | 53 | static ssize_t calc_data_size; |
54 | static bool repipe; | 54 | static bool repipe; |
55 | 55 | ||
56 | /* If it fails, the next read will report it */ | ||
57 | static void skip(int size) | ||
58 | { | ||
59 | lseek(input_fd, size, SEEK_CUR); | ||
60 | } | ||
61 | |||
62 | static int do_read(int fd, void *buf, int size) | 56 | static int do_read(int fd, void *buf, int size) |
63 | { | 57 | { |
64 | int rsize = size; | 58 | int rsize = size; |
@@ -98,6 +92,19 @@ static int read_or_die(void *data, int size) | |||
98 | return r; | 92 | return r; |
99 | } | 93 | } |
100 | 94 | ||
95 | /* If it fails, the next read will report it */ | ||
96 | static void skip(int size) | ||
97 | { | ||
98 | char buf[BUFSIZ]; | ||
99 | int r; | ||
100 | |||
101 | while (size) { | ||
102 | r = size > BUFSIZ ? BUFSIZ : size; | ||
103 | read_or_die(buf, r); | ||
104 | size -= r; | ||
105 | }; | ||
106 | } | ||
107 | |||
101 | static unsigned int read4(void) | 108 | static unsigned int read4(void) |
102 | { | 109 | { |
103 | unsigned int data; | 110 | unsigned int data; |
diff --git a/tools/perf/util/trace-event.h b/tools/perf/util/trace-event.h index 406d452956db..b3e86b1e4444 100644 --- a/tools/perf/util/trace-event.h +++ b/tools/perf/util/trace-event.h | |||
@@ -233,7 +233,12 @@ static inline unsigned long long __data2host8(unsigned long long data) | |||
233 | 233 | ||
234 | #define data2host2(ptr) __data2host2(*(unsigned short *)ptr) | 234 | #define data2host2(ptr) __data2host2(*(unsigned short *)ptr) |
235 | #define data2host4(ptr) __data2host4(*(unsigned int *)ptr) | 235 | #define data2host4(ptr) __data2host4(*(unsigned int *)ptr) |
236 | #define data2host8(ptr) __data2host8(*(unsigned long long *)ptr) | 236 | #define data2host8(ptr) ({ \ |
237 | unsigned long long __val; \ | ||
238 | \ | ||
239 | memcpy(&__val, (ptr), sizeof(unsigned long long)); \ | ||
240 | __data2host8(__val); \ | ||
241 | }) | ||
237 | 242 | ||
238 | extern int header_page_ts_offset; | 243 | extern int header_page_ts_offset; |
239 | extern int header_page_ts_size; | 244 | extern int header_page_ts_size; |
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h index 0795bf304b19..4e8b6b0c551c 100644 --- a/tools/perf/util/util.h +++ b/tools/perf/util/util.h | |||
@@ -81,7 +81,7 @@ | |||
81 | #include <inttypes.h> | 81 | #include <inttypes.h> |
82 | #include "../../../include/linux/magic.h" | 82 | #include "../../../include/linux/magic.h" |
83 | #include "types.h" | 83 | #include "types.h" |
84 | 84 | #include <sys/ttydefaults.h> | |
85 | 85 | ||
86 | #ifndef NO_ICONV | 86 | #ifndef NO_ICONV |
87 | #include <iconv.h> | 87 | #include <iconv.h> |
@@ -152,7 +152,6 @@ extern void warning(const char *err, ...) __attribute__((format (printf, 1, 2))) | |||
152 | extern void set_die_routine(void (*routine)(const char *err, va_list params) NORETURN); | 152 | extern void set_die_routine(void (*routine)(const char *err, va_list params) NORETURN); |
153 | 153 | ||
154 | extern int prefixcmp(const char *str, const char *prefix); | 154 | extern int prefixcmp(const char *str, const char *prefix); |
155 | extern time_t tm_to_time_t(const struct tm *tm); | ||
156 | 155 | ||
157 | static inline const char *skip_prefix(const char *str, const char *prefix) | 156 | static inline const char *skip_prefix(const char *str, const char *prefix) |
158 | { | 157 | { |
@@ -160,119 +159,6 @@ static inline const char *skip_prefix(const char *str, const char *prefix) | |||
160 | return strncmp(str, prefix, len) ? NULL : str + len; | 159 | return strncmp(str, prefix, len) ? NULL : str + len; |
161 | } | 160 | } |
162 | 161 | ||
163 | #if defined(NO_MMAP) || defined(USE_WIN32_MMAP) | ||
164 | |||
165 | #ifndef PROT_READ | ||
166 | #define PROT_READ 1 | ||
167 | #define PROT_WRITE 2 | ||
168 | #define MAP_PRIVATE 1 | ||
169 | #define MAP_FAILED ((void*)-1) | ||
170 | #endif | ||
171 | |||
172 | #define mmap git_mmap | ||
173 | #define munmap git_munmap | ||
174 | extern void *git_mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset); | ||
175 | extern int git_munmap(void *start, size_t length); | ||
176 | |||
177 | #else /* NO_MMAP || USE_WIN32_MMAP */ | ||
178 | |||
179 | #include <sys/mman.h> | ||
180 | |||
181 | #endif /* NO_MMAP || USE_WIN32_MMAP */ | ||
182 | |||
183 | #ifdef NO_MMAP | ||
184 | |||
185 | /* This value must be multiple of (pagesize * 2) */ | ||
186 | #define DEFAULT_PACKED_GIT_WINDOW_SIZE (1 * 1024 * 1024) | ||
187 | |||
188 | #else /* NO_MMAP */ | ||
189 | |||
190 | /* This value must be multiple of (pagesize * 2) */ | ||
191 | #define DEFAULT_PACKED_GIT_WINDOW_SIZE \ | ||
192 | (sizeof(void*) >= 8 \ | ||
193 | ? 1 * 1024 * 1024 * 1024 \ | ||
194 | : 32 * 1024 * 1024) | ||
195 | |||
196 | #endif /* NO_MMAP */ | ||
197 | |||
198 | #ifdef NO_ST_BLOCKS_IN_STRUCT_STAT | ||
199 | #define on_disk_bytes(st) ((st).st_size) | ||
200 | #else | ||
201 | #define on_disk_bytes(st) ((st).st_blocks * 512) | ||
202 | #endif | ||
203 | |||
204 | #define DEFAULT_PACKED_GIT_LIMIT \ | ||
205 | ((1024L * 1024L) * (sizeof(void*) >= 8 ? 8192 : 256)) | ||
206 | |||
207 | #ifdef NO_PREAD | ||
208 | #define pread git_pread | ||
209 | extern ssize_t git_pread(int fd, void *buf, size_t count, off_t offset); | ||
210 | #endif | ||
211 | /* | ||
212 | * Forward decl that will remind us if its twin in cache.h changes. | ||
213 | * This function is used in compat/pread.c. But we can't include | ||
214 | * cache.h there. | ||
215 | */ | ||
216 | extern ssize_t read_in_full(int fd, void *buf, size_t count); | ||
217 | |||
218 | #ifdef NO_SETENV | ||
219 | #define setenv gitsetenv | ||
220 | extern int gitsetenv(const char *, const char *, int); | ||
221 | #endif | ||
222 | |||
223 | #ifdef NO_MKDTEMP | ||
224 | #define mkdtemp gitmkdtemp | ||
225 | extern char *gitmkdtemp(char *); | ||
226 | #endif | ||
227 | |||
228 | #ifdef NO_UNSETENV | ||
229 | #define unsetenv gitunsetenv | ||
230 | extern void gitunsetenv(const char *); | ||
231 | #endif | ||
232 | |||
233 | #ifdef NO_STRCASESTR | ||
234 | #define strcasestr gitstrcasestr | ||
235 | extern char *gitstrcasestr(const char *haystack, const char *needle); | ||
236 | #endif | ||
237 | |||
238 | #ifdef NO_STRLCPY | ||
239 | #define strlcpy gitstrlcpy | ||
240 | extern size_t gitstrlcpy(char *, const char *, size_t); | ||
241 | #endif | ||
242 | |||
243 | #ifdef NO_STRTOUMAX | ||
244 | #define strtoumax gitstrtoumax | ||
245 | extern uintmax_t gitstrtoumax(const char *, char **, int); | ||
246 | #endif | ||
247 | |||
248 | #ifdef NO_HSTRERROR | ||
249 | #define hstrerror githstrerror | ||
250 | extern const char *githstrerror(int herror); | ||
251 | #endif | ||
252 | |||
253 | #ifdef NO_MEMMEM | ||
254 | #define memmem gitmemmem | ||
255 | void *gitmemmem(const void *haystack, size_t haystacklen, | ||
256 | const void *needle, size_t needlelen); | ||
257 | #endif | ||
258 | |||
259 | #ifdef FREAD_READS_DIRECTORIES | ||
260 | #ifdef fopen | ||
261 | #undef fopen | ||
262 | #endif | ||
263 | #define fopen(a,b) git_fopen(a,b) | ||
264 | extern FILE *git_fopen(const char*, const char*); | ||
265 | #endif | ||
266 | |||
267 | #ifdef SNPRINTF_RETURNS_BOGUS | ||
268 | #define snprintf git_snprintf | ||
269 | extern int git_snprintf(char *str, size_t maxsize, | ||
270 | const char *format, ...); | ||
271 | #define vsnprintf git_vsnprintf | ||
272 | extern int git_vsnprintf(char *str, size_t maxsize, | ||
273 | const char *format, va_list ap); | ||
274 | #endif | ||
275 | |||
276 | #ifdef __GLIBC_PREREQ | 162 | #ifdef __GLIBC_PREREQ |
277 | #if __GLIBC_PREREQ(2, 1) | 163 | #if __GLIBC_PREREQ(2, 1) |
278 | #define HAVE_STRCHRNUL | 164 | #define HAVE_STRCHRNUL |
@@ -293,28 +179,14 @@ static inline char *gitstrchrnul(const char *s, int c) | |||
293 | * Wrappers: | 179 | * Wrappers: |
294 | */ | 180 | */ |
295 | extern char *xstrdup(const char *str); | 181 | extern char *xstrdup(const char *str); |
296 | extern void *xmalloc(size_t size) __attribute__((weak)); | ||
297 | extern void *xmemdupz(const void *data, size_t len); | ||
298 | extern char *xstrndup(const char *str, size_t len); | ||
299 | extern void *xrealloc(void *ptr, size_t size) __attribute__((weak)); | 182 | extern void *xrealloc(void *ptr, size_t size) __attribute__((weak)); |
300 | 183 | ||
301 | static inline void *xzalloc(size_t size) | ||
302 | { | ||
303 | void *buf = xmalloc(size); | ||
304 | |||
305 | return memset(buf, 0, size); | ||
306 | } | ||
307 | 184 | ||
308 | static inline void *zalloc(size_t size) | 185 | static inline void *zalloc(size_t size) |
309 | { | 186 | { |
310 | return calloc(1, size); | 187 | return calloc(1, size); |
311 | } | 188 | } |
312 | 189 | ||
313 | static inline size_t xsize_t(off_t len) | ||
314 | { | ||
315 | return (size_t)len; | ||
316 | } | ||
317 | |||
318 | static inline int has_extension(const char *filename, const char *ext) | 190 | static inline int has_extension(const char *filename, const char *ext) |
319 | { | 191 | { |
320 | size_t len = strlen(filename); | 192 | size_t len = strlen(filename); |
@@ -351,8 +223,6 @@ extern unsigned char sane_ctype[256]; | |||
351 | #define isalpha(x) sane_istest(x,GIT_ALPHA) | 223 | #define isalpha(x) sane_istest(x,GIT_ALPHA) |
352 | #define isalnum(x) sane_istest(x,GIT_ALPHA | GIT_DIGIT) | 224 | #define isalnum(x) sane_istest(x,GIT_ALPHA | GIT_DIGIT) |
353 | #define isprint(x) sane_istest(x,GIT_PRINT) | 225 | #define isprint(x) sane_istest(x,GIT_PRINT) |
354 | #define is_glob_special(x) sane_istest(x,GIT_GLOB_SPECIAL) | ||
355 | #define is_regex_special(x) sane_istest(x,GIT_GLOB_SPECIAL | GIT_REGEX_SPECIAL) | ||
356 | #define tolower(x) sane_case((unsigned char)(x), 0x20) | 226 | #define tolower(x) sane_case((unsigned char)(x), 0x20) |
357 | #define toupper(x) sane_case((unsigned char)(x), 0) | 227 | #define toupper(x) sane_case((unsigned char)(x), 0) |
358 | 228 | ||
@@ -363,38 +233,6 @@ static inline int sane_case(int x, int high) | |||
363 | return x; | 233 | return x; |
364 | } | 234 | } |
365 | 235 | ||
366 | static inline int strtoul_ui(char const *s, int base, unsigned int *result) | ||
367 | { | ||
368 | unsigned long ul; | ||
369 | char *p; | ||
370 | |||
371 | errno = 0; | ||
372 | ul = strtoul(s, &p, base); | ||
373 | if (errno || *p || p == s || (unsigned int) ul != ul) | ||
374 | return -1; | ||
375 | *result = ul; | ||
376 | return 0; | ||
377 | } | ||
378 | |||
379 | static inline int strtol_i(char const *s, int base, int *result) | ||
380 | { | ||
381 | long ul; | ||
382 | char *p; | ||
383 | |||
384 | errno = 0; | ||
385 | ul = strtol(s, &p, base); | ||
386 | if (errno || *p || p == s || (int) ul != ul) | ||
387 | return -1; | ||
388 | *result = ul; | ||
389 | return 0; | ||
390 | } | ||
391 | |||
392 | #ifdef INTERNAL_QSORT | ||
393 | void git_qsort(void *base, size_t nmemb, size_t size, | ||
394 | int(*compar)(const void *, const void *)); | ||
395 | #define qsort git_qsort | ||
396 | #endif | ||
397 | |||
398 | #ifndef DIR_HAS_BSD_GROUP_SEMANTICS | 236 | #ifndef DIR_HAS_BSD_GROUP_SEMANTICS |
399 | # define FORCE_DIR_SET_GID S_ISGID | 237 | # define FORCE_DIR_SET_GID S_ISGID |
400 | #else | 238 | #else |
@@ -425,6 +263,19 @@ bool strglobmatch(const char *str, const char *pat); | |||
425 | bool strlazymatch(const char *str, const char *pat); | 263 | bool strlazymatch(const char *str, const char *pat); |
426 | unsigned long convert_unit(unsigned long value, char *unit); | 264 | unsigned long convert_unit(unsigned long value, char *unit); |
427 | 265 | ||
266 | #ifndef ESC | ||
267 | #define ESC 27 | ||
268 | #endif | ||
269 | |||
270 | static inline bool is_exit_key(int key) | ||
271 | { | ||
272 | char up; | ||
273 | if (key == CTRL('c') || key == ESC) | ||
274 | return true; | ||
275 | up = toupper(key); | ||
276 | return up == 'Q'; | ||
277 | } | ||
278 | |||
428 | #define _STR(x) #x | 279 | #define _STR(x) #x |
429 | #define STR(x) _STR(x) | 280 | #define STR(x) _STR(x) |
430 | 281 | ||
diff --git a/tools/perf/util/wrapper.c b/tools/perf/util/wrapper.c index bf44ca85d23b..73e900edb5a2 100644 --- a/tools/perf/util/wrapper.c +++ b/tools/perf/util/wrapper.c | |||
@@ -23,46 +23,6 @@ char *xstrdup(const char *str) | |||
23 | return ret; | 23 | return ret; |
24 | } | 24 | } |
25 | 25 | ||
26 | void *xmalloc(size_t size) | ||
27 | { | ||
28 | void *ret = malloc(size); | ||
29 | if (!ret && !size) | ||
30 | ret = malloc(1); | ||
31 | if (!ret) { | ||
32 | release_pack_memory(size, -1); | ||
33 | ret = malloc(size); | ||
34 | if (!ret && !size) | ||
35 | ret = malloc(1); | ||
36 | if (!ret) | ||
37 | die("Out of memory, malloc failed"); | ||
38 | } | ||
39 | #ifdef XMALLOC_POISON | ||
40 | memset(ret, 0xA5, size); | ||
41 | #endif | ||
42 | return ret; | ||
43 | } | ||
44 | |||
45 | /* | ||
46 | * xmemdupz() allocates (len + 1) bytes of memory, duplicates "len" bytes of | ||
47 | * "data" to the allocated memory, zero terminates the allocated memory, | ||
48 | * and returns a pointer to the allocated memory. If the allocation fails, | ||
49 | * the program dies. | ||
50 | */ | ||
51 | void *xmemdupz(const void *data, size_t len) | ||
52 | { | ||
53 | char *p = xmalloc(len + 1); | ||
54 | memcpy(p, data, len); | ||
55 | p[len] = '\0'; | ||
56 | return p; | ||
57 | } | ||
58 | |||
59 | char *xstrndup(const char *str, size_t len) | ||
60 | { | ||
61 | char *p = memchr(str, '\0', len); | ||
62 | |||
63 | return xmemdupz(str, p ? (size_t)(p - str) : len); | ||
64 | } | ||
65 | |||
66 | void *xrealloc(void *ptr, size_t size) | 26 | void *xrealloc(void *ptr, size_t size) |
67 | { | 27 | { |
68 | void *ret = realloc(ptr, size); | 28 | void *ret = realloc(ptr, size); |
@@ -78,73 +38,3 @@ void *xrealloc(void *ptr, size_t size) | |||
78 | } | 38 | } |
79 | return ret; | 39 | return ret; |
80 | } | 40 | } |
81 | |||
82 | /* | ||
83 | * xread() is the same a read(), but it automatically restarts read() | ||
84 | * operations with a recoverable error (EAGAIN and EINTR). xread() | ||
85 | * DOES NOT GUARANTEE that "len" bytes is read even if the data is available. | ||
86 | */ | ||
87 | static ssize_t xread(int fd, void *buf, size_t len) | ||
88 | { | ||
89 | ssize_t nr; | ||
90 | while (1) { | ||
91 | nr = read(fd, buf, len); | ||
92 | if ((nr < 0) && (errno == EAGAIN || errno == EINTR)) | ||
93 | continue; | ||
94 | return nr; | ||
95 | } | ||
96 | } | ||
97 | |||
98 | /* | ||
99 | * xwrite() is the same a write(), but it automatically restarts write() | ||
100 | * operations with a recoverable error (EAGAIN and EINTR). xwrite() DOES NOT | ||
101 | * GUARANTEE that "len" bytes is written even if the operation is successful. | ||
102 | */ | ||
103 | static ssize_t xwrite(int fd, const void *buf, size_t len) | ||
104 | { | ||
105 | ssize_t nr; | ||
106 | while (1) { | ||
107 | nr = write(fd, buf, len); | ||
108 | if ((nr < 0) && (errno == EAGAIN || errno == EINTR)) | ||
109 | continue; | ||
110 | return nr; | ||
111 | } | ||
112 | } | ||
113 | |||
114 | ssize_t read_in_full(int fd, void *buf, size_t count) | ||
115 | { | ||
116 | char *p = buf; | ||
117 | ssize_t total = 0; | ||
118 | |||
119 | while (count > 0) { | ||
120 | ssize_t loaded = xread(fd, p, count); | ||
121 | if (loaded <= 0) | ||
122 | return total ? total : loaded; | ||
123 | count -= loaded; | ||
124 | p += loaded; | ||
125 | total += loaded; | ||
126 | } | ||
127 | |||
128 | return total; | ||
129 | } | ||
130 | |||
131 | ssize_t write_in_full(int fd, const void *buf, size_t count) | ||
132 | { | ||
133 | const char *p = buf; | ||
134 | ssize_t total = 0; | ||
135 | |||
136 | while (count > 0) { | ||
137 | ssize_t written = xwrite(fd, p, count); | ||
138 | if (written < 0) | ||
139 | return -1; | ||
140 | if (!written) { | ||
141 | errno = ENOSPC; | ||
142 | return -1; | ||
143 | } | ||
144 | count -= written; | ||
145 | p += written; | ||
146 | total += written; | ||
147 | } | ||
148 | |||
149 | return total; | ||
150 | } | ||