1 #ifndef PERF_UTIL_KWORK_H
2 #define PERF_UTIL_KWORK_H
7 #include "util/event.h"
8 #include "util/evlist.h"
9 #include "util/session.h"
10 #include "util/time-utils.h"
12 #include <linux/list.h>
13 #include <linux/bitmap.h>
15 enum kwork_class_type {
18 KWORK_CLASS_WORKQUEUE,
22 enum kwork_report_type {
25 KWORK_REPORT_TIMEHIST,
28 enum kwork_trace_type {
38 * +==================+ +============+ +======================+
39 * | class | | work | | atom |
40 * +==================+ +============+ +======================+
41 * +------------+ | +-----+ | | +------+ | | +-------+ +-----+ |
42 * | perf_kwork | +-> | irq | --------|+-> | eth0 | --+-> | raise | - | ... | --+ +-----------+
43 * +-----+------+ || +-----+ ||| +------+ ||| +-------+ +-----+ | | | |
44 * | || ||| ||| | +-> | atom_page |
45 * | || ||| ||| +-------+ +-----+ | | |
46 * | class_list ||| |+-> | entry | - | ... | ----> | |
47 * | || ||| ||| +-------+ +-----+ | | |
48 * | || ||| ||| | +-> | |
49 * | || ||| ||| +-------+ +-----+ | | | |
50 * | || ||| |+-> | exit | - | ... | --+ +-----+-----+
51 * | || ||| | | +-------+ +-----+ | |
53 * | || ||| +-----+ | | | |
54 * | || |+-> | ... | | | | |
55 * | || | | +-----+ | | | |
57 * | || +---------+ | | +-----+ | | +-------+ +-----+ | |
58 * | +-> | softirq | -------> | RCU | ---+-> | raise | - | ... | --+ +-----+-----+
59 * | || +---------+ | | +-----+ ||| +-------+ +-----+ | | | |
60 * | || | | ||| | +-> | atom_page |
61 * | || | | ||| +-------+ +-----+ | | |
62 * | || | | |+-> | entry | - | ... | ----> | |
63 * | || | | ||| +-------+ +-----+ | | |
64 * | || | | ||| | +-> | |
65 * | || | | ||| +-------+ +-----+ | | | |
66 * | || | | |+-> | exit | - | ... | --+ +-----+-----+
67 * | || | | | | +-------+ +-----+ | |
69 * | || +-----------+ | | +-----+ | | | |
70 * | +-> | workqueue | -----> | ... | | | | |
71 * | | +-----------+ | | +-----+ | | | |
72 * | +==================+ +============+ +======================+ |
74 * +----> atom_page_list ---------------------------------------------------------+
79 struct list_head list;
81 struct kwork_atom *prev;
84 unsigned long bit_inpage;
87 #define NR_ATOM_PER_PAGE 128
88 struct kwork_atom_page {
89 struct list_head list;
90 struct kwork_atom atoms[NR_ATOM_PER_PAGE];
91 DECLARE_BITMAP(bitmap, NR_ATOM_PER_PAGE);
100 struct kwork_class *class;
113 struct list_head atom_list[KWORK_TRACE_MAX];
119 u64 max_runtime_start;
127 u64 max_latency_start;
133 struct list_head list;
135 enum kwork_class_type type;
137 unsigned int nr_tracepoints;
138 const struct evsel_str_handler *tp_handlers;
140 struct rb_root_cached work_root;
142 int (*class_init)(struct kwork_class *class,
143 struct perf_session *session);
145 void (*work_init)(struct kwork_class *class,
146 struct kwork_work *work,
148 struct perf_sample *sample,
149 struct machine *machine);
151 void (*work_name)(struct kwork_work *work,
156 struct trace_kwork_handler {
157 int (*raise_event)(struct perf_kwork *kwork,
158 struct kwork_class *class, struct evsel *evsel,
159 struct perf_sample *sample, struct machine *machine);
161 int (*entry_event)(struct perf_kwork *kwork,
162 struct kwork_class *class, struct evsel *evsel,
163 struct perf_sample *sample, struct machine *machine);
165 int (*exit_event)(struct perf_kwork *kwork,
166 struct kwork_class *class, struct evsel *evsel,
167 struct perf_sample *sample, struct machine *machine);
174 struct perf_tool tool;
175 struct list_head class_list;
176 struct list_head atom_page_list;
177 struct list_head sort_list, cmp_id;
178 struct rb_root_cached sorted_work_root;
179 const struct trace_kwork_handler *tp_handler;
184 const char *profile_name;
186 const char *cpu_list;
187 DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);
189 const char *time_str;
190 struct perf_time_interval ptime;
193 * options for command
196 const char *event_list_str;
197 enum kwork_report_type report;
200 * options for subcommand
203 const char *sort_order;
205 unsigned int max_stack;
214 unsigned long nr_events;
215 unsigned long nr_lost_chunks;
216 unsigned long nr_lost_events;
220 u64 nr_skipped_events[KWORK_TRACE_MAX + 1];
223 struct kwork_work *perf_kwork_add_work(struct perf_kwork *kwork,
224 struct kwork_class *class,
225 struct kwork_work *key);
229 int perf_kwork__trace_prepare_bpf(struct perf_kwork *kwork);
230 int perf_kwork__report_read_bpf(struct perf_kwork *kwork);
231 void perf_kwork__report_cleanup_bpf(void);
233 void perf_kwork__trace_start(void);
234 void perf_kwork__trace_finish(void);
236 #else /* !HAVE_BPF_SKEL */
239 perf_kwork__trace_prepare_bpf(struct perf_kwork *kwork __maybe_unused)
245 perf_kwork__report_read_bpf(struct perf_kwork *kwork __maybe_unused)
250 static inline void perf_kwork__report_cleanup_bpf(void) {}
252 static inline void perf_kwork__trace_start(void) {}
253 static inline void perf_kwork__trace_finish(void) {}
255 #endif /* HAVE_BPF_SKEL */
257 #endif /* PERF_UTIL_KWORK_H */