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