1 #ifndef PERF_UTIL_KWORK_H
2 #define PERF_UTIL_KWORK_H
5 #include "util/time-utils.h"
7 #include <linux/bitmap.h>
8 #include <linux/list.h>
9 #include <linux/rbtree.h>
10 #include <linux/types.h>
15 enum kwork_class_type {
18 KWORK_CLASS_WORKQUEUE,
23 enum kwork_report_type {
26 KWORK_REPORT_TIMEHIST,
30 enum kwork_trace_type {
40 * +==================+ +============+ +======================+
41 * | class | | work | | atom |
42 * +==================+ +============+ +======================+
43 * +------------+ | +-----+ | | +------+ | | +-------+ +-----+ |
44 * | perf_kwork | +-> | irq | --------|+-> | eth0 | --+-> | raise | - | ... | --+ +-----------+
45 * +-----+------+ || +-----+ ||| +------+ ||| +-------+ +-----+ | | | |
46 * | || ||| ||| | +-> | atom_page |
47 * | || ||| ||| +-------+ +-----+ | | |
48 * | class_list ||| |+-> | entry | - | ... | ----> | |
49 * | || ||| ||| +-------+ +-----+ | | |
50 * | || ||| ||| | +-> | |
51 * | || ||| ||| +-------+ +-----+ | | | |
52 * | || ||| |+-> | exit | - | ... | --+ +-----+-----+
53 * | || ||| | | +-------+ +-----+ | |
55 * | || ||| +-----+ | | | |
56 * | || |+-> | ... | | | | |
57 * | || | | +-----+ | | | |
59 * | || +---------+ | | +-----+ | | +-------+ +-----+ | |
60 * | +-> | softirq | -------> | RCU | ---+-> | raise | - | ... | --+ +-----+-----+
61 * | || +---------+ | | +-----+ ||| +-------+ +-----+ | | | |
62 * | || | | ||| | +-> | atom_page |
63 * | || | | ||| +-------+ +-----+ | | |
64 * | || | | |+-> | entry | - | ... | ----> | |
65 * | || | | ||| +-------+ +-----+ | | |
66 * | || | | ||| | +-> | |
67 * | || | | ||| +-------+ +-----+ | | | |
68 * | || | | |+-> | exit | - | ... | --+ +-----+-----+
69 * | || | | | | +-------+ +-----+ | |
71 * | || +-----------+ | | +-----+ | | | |
72 * | +-> | workqueue | -----> | ... | | | | |
73 * | | +-----------+ | | +-----+ | | | |
74 * | +==================+ +============+ +======================+ |
76 * +----> atom_page_list ---------------------------------------------------------+
81 struct list_head list;
83 struct kwork_atom *prev;
86 unsigned long bit_inpage;
89 #define NR_ATOM_PER_PAGE 128
90 struct kwork_atom_page {
91 struct list_head list;
92 struct kwork_atom atoms[NR_ATOM_PER_PAGE];
93 DECLARE_BITMAP(bitmap, NR_ATOM_PER_PAGE);
103 struct kwork_class *class;
116 struct list_head atom_list[KWORK_TRACE_MAX];
122 u64 max_runtime_start;
130 u64 max_latency_start;
143 struct list_head list;
145 enum kwork_class_type type;
147 unsigned int nr_tracepoints;
148 const struct evsel_str_handler *tp_handlers;
150 struct rb_root_cached work_root;
152 int (*class_init)(struct kwork_class *class,
153 struct perf_session *session);
155 void (*work_init)(struct perf_kwork *kwork,
156 struct kwork_class *class,
157 struct kwork_work *work,
158 enum kwork_trace_type src_type,
160 struct perf_sample *sample,
161 struct machine *machine);
163 void (*work_name)(struct kwork_work *work,
167 struct trace_kwork_handler {
168 int (*raise_event)(struct perf_kwork *kwork,
169 struct kwork_class *class, struct evsel *evsel,
170 struct perf_sample *sample, struct machine *machine);
172 int (*entry_event)(struct perf_kwork *kwork,
173 struct kwork_class *class, struct evsel *evsel,
174 struct perf_sample *sample, struct machine *machine);
176 int (*exit_event)(struct perf_kwork *kwork,
177 struct kwork_class *class, struct evsel *evsel,
178 struct perf_sample *sample, struct machine *machine);
180 int (*sched_switch_event)(struct perf_kwork *kwork,
181 struct kwork_class *class, struct evsel *evsel,
182 struct perf_sample *sample, struct machine *machine);
185 struct __top_cpus_runtime {
193 struct kwork_top_stat {
194 DECLARE_BITMAP(all_cpus_bitmap, MAX_NR_CPUS);
195 struct __top_cpus_runtime *cpus_runtime;
202 struct perf_tool tool;
203 struct list_head class_list;
204 struct list_head atom_page_list;
205 struct list_head sort_list, cmp_id;
206 struct rb_root_cached sorted_work_root;
207 const struct trace_kwork_handler *tp_handler;
212 const char *profile_name;
214 const char *cpu_list;
215 DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);
217 const char *time_str;
218 struct perf_time_interval ptime;
221 * options for command
224 const char *event_list_str;
225 enum kwork_report_type report;
228 * options for subcommand
231 const char *sort_order;
233 unsigned int max_stack;
242 unsigned long nr_events;
243 unsigned long nr_lost_chunks;
244 unsigned long nr_lost_events;
248 u64 nr_skipped_events[KWORK_TRACE_MAX + 1];
251 * perf kwork top data
253 struct kwork_top_stat top_stat;
256 struct kwork_work *perf_kwork_add_work(struct perf_kwork *kwork,
257 struct kwork_class *class,
258 struct kwork_work *key);
262 int perf_kwork__trace_prepare_bpf(struct perf_kwork *kwork);
263 int perf_kwork__report_read_bpf(struct perf_kwork *kwork);
264 void perf_kwork__report_cleanup_bpf(void);
266 void perf_kwork__trace_start(void);
267 void perf_kwork__trace_finish(void);
269 int perf_kwork__top_prepare_bpf(struct perf_kwork *kwork);
270 int perf_kwork__top_read_bpf(struct perf_kwork *kwork);
271 void perf_kwork__top_cleanup_bpf(void);
273 void perf_kwork__top_start(void);
274 void perf_kwork__top_finish(void);
276 #else /* !HAVE_BPF_SKEL */
279 perf_kwork__trace_prepare_bpf(struct perf_kwork *kwork __maybe_unused)
285 perf_kwork__report_read_bpf(struct perf_kwork *kwork __maybe_unused)
290 static inline void perf_kwork__report_cleanup_bpf(void) {}
292 static inline void perf_kwork__trace_start(void) {}
293 static inline void perf_kwork__trace_finish(void) {}
296 perf_kwork__top_prepare_bpf(struct perf_kwork *kwork __maybe_unused)
302 perf_kwork__top_read_bpf(struct perf_kwork *kwork __maybe_unused)
307 static inline void perf_kwork__top_cleanup_bpf(void) {}
309 static inline void perf_kwork__top_start(void) {}
310 static inline void perf_kwork__top_finish(void) {}
312 #endif /* HAVE_BPF_SKEL */
314 #endif /* PERF_UTIL_KWORK_H */