Debian Codegraph @

tools/tracing/rtla/src/common.h

raw
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #pragma once
3
4 #include <getopt.h>
5 #include "actions.h"
6 #include "timerlat_u.h"
7 #include "trace.h"
8 #include "utils.h"
9
10 /*
11 * osnoise_context - read, store, write, restore osnoise configs.
12 */
13 struct osnoise_context {
14 int flags;
15 int ref;
16
17 char *curr_cpus;
18 char *orig_cpus;
19
20 /* 0 as init value */
21 unsigned long long orig_runtime_us;
22 unsigned long long runtime_us;
23
24 /* 0 as init value */
25 unsigned long long orig_period_us;
26 unsigned long long period_us;
27
28 /* 0 as init value */
29 long long orig_timerlat_period_us;
30 long long timerlat_period_us;
31
32 /* 0 as init value */
33 long long orig_tracing_thresh;
34 long long tracing_thresh;
35
36 /* -1 as init value because 0 is disabled */
37 long long orig_stop_us;
38 long long stop_us;
39
40 /* -1 as init value because 0 is disabled */
41 long long orig_stop_total_us;
42 long long stop_total_us;
43
44 /* -1 as init value because 0 is disabled */
45 long long orig_print_stack;
46 long long print_stack;
47
48 /* -1 as init value because 0 is off */
49 int orig_opt_irq_disable;
50 int opt_irq_disable;
51
52 /* -1 as init value because 0 is off */
53 int orig_opt_workload;
54 int opt_workload;
55 };
56
57 extern struct trace_instance *trace_inst;
58 extern volatile int stop_tracing;
59
60 struct hist_params {
61 char no_irq;
62 char no_thread;
63 char no_header;
64 char no_summary;
65 char no_index;
66 char with_zeros;
67 int bucket_size;
68 int entries;
69 };
70
71 /*
72 * common_params - Parameters shared between timerlat_params and osnoise_params
73 */
74 struct common_params {
75 /* trace configuration */
76 char *cpus;
77 cpu_set_t monitored_cpus;
78 struct trace_events *events;
79 int buffer_size;
80
81 /* Timing parameters */
82 int warmup;
83 long long stop_us;
84 long long stop_total_us;
85 int sleep_time;
86 int duration;
87
88 /* Scheduling parameters */
89 int set_sched;
90 struct sched_attr sched_param;
91 int cgroup;
92 char *cgroup_name;
93 int hk_cpus;
94 cpu_set_t hk_cpu_set;
95
96 /* Other parameters */
97 struct hist_params hist;
98 int output_divisor;
99 int pretty_output;
100 int quiet;
101 int user_workload;
102 int kernel_workload;
103 int user_data;
104 int aa_only;
105
106 struct actions threshold_actions;
107 struct actions end_actions;
108 struct timerlat_u_params user;
109 };
110
111 #define for_each_monitored_cpu(cpu, nr_cpus, common) \
112 for (cpu = 0; cpu < nr_cpus; cpu++) \
113 if (!(common)->cpus || CPU_ISSET(cpu, &(common)->monitored_cpus))
114
115 struct tool_ops;
116
117 /*
118 * osnoise_tool - osnoise based tool definition.
119 *
120 * Only the "trace" and "context" fields are used for
121 * the additional trace instances (record and aa).
122 */
123 struct osnoise_tool {
124 struct tool_ops *ops;
125 struct trace_instance trace;
126 struct osnoise_context *context;
127 void *data;
128 struct common_params *params;
129 time_t start_time;
130 struct osnoise_tool *record;
131 struct osnoise_tool *aa;
132 };
133
134 struct tool_ops {
135 const char *tracer;
136 const char *comm_prefix;
137 struct common_params *(*parse_args)(int argc, char *argv[]);
138 struct osnoise_tool *(*init_tool)(struct common_params *params);
139 int (*apply_config)(struct osnoise_tool *tool);
140 int (*enable)(struct osnoise_tool *tool);
141 int (*main)(struct osnoise_tool *tool);
142 void (*print_stats)(struct osnoise_tool *tool);
143 void (*analyze)(struct osnoise_tool *tool, bool stopped);
144 void (*free)(struct osnoise_tool *tool);
145 };
146
147 int osnoise_set_cpus(struct osnoise_context *context, char *cpus);
148 void osnoise_restore_cpus(struct osnoise_context *context);
149
150 int osnoise_set_workload(struct osnoise_context *context, bool onoff);
151
152 void osnoise_destroy_tool(struct osnoise_tool *top);
153 struct osnoise_tool *osnoise_init_tool(char *tool_name);
154 struct osnoise_tool *osnoise_init_trace_tool(const char *tracer);
155 bool osnoise_trace_is_off(struct osnoise_tool *tool, struct osnoise_tool *record);
156 int osnoise_set_stop_us(struct osnoise_context *context, long long stop_us);
157 int osnoise_set_stop_total_us(struct osnoise_context *context,
158 long long stop_total_us);
159
160 int getopt_auto(int argc, char **argv, const struct option *long_opts);
161 int common_parse_options(int argc, char **argv, struct common_params *common);
162 int common_apply_config(struct osnoise_tool *tool, struct common_params *params);
163 int top_main_loop(struct osnoise_tool *tool);
164 int hist_main_loop(struct osnoise_tool *tool);
165 int osn_set_stop(struct osnoise_tool *tool);
166
167 void common_usage(const char *tool, const char *mode,
168 const char *desc, const char * const *start_msgs, const char * const *opt_msgs);