xref: /linux/tools/tracing/rtla/src/osnoise.h (revision 4fa118e5b79fcc537dcb1a860ed319a6106935eb)
1 // SPDX-License-Identifier: GPL-2.0
2 #pragma once
3 
4 #include "utils.h"
5 #include "trace.h"
6 
7 enum osnoise_mode {
8 	MODE_OSNOISE = 0,
9 	MODE_HWNOISE
10 };
11 
12 struct osnoise_params {
13 	/* Common params */
14 	char			*cpus;
15 	cpu_set_t		monitored_cpus;
16 	char			*trace_output;
17 	char			*cgroup_name;
18 	unsigned long long	runtime;
19 	unsigned long long	period;
20 	long long		threshold;
21 	long long		stop_us;
22 	long long		stop_total_us;
23 	int			sleep_time;
24 	int			duration;
25 	int			set_sched;
26 	int			cgroup;
27 	int			hk_cpus;
28 	cpu_set_t		hk_cpu_set;
29 	struct sched_attr	sched_param;
30 	struct trace_events	*events;
31 	int			warmup;
32 	int			buffer_size;
33 	union {
34 		struct {
35 			/* top only */
36 			int			quiet;
37 			int			pretty_output;
38 			enum osnoise_mode	mode;
39 		};
40 		struct {
41 			/* hist only */
42 			int			output_divisor;
43 			char			no_header;
44 			char			no_summary;
45 			char			no_index;
46 			char			with_zeros;
47 			int			bucket_size;
48 			int			entries;
49 		};
50 	};
51 };
52 
53 /*
54  * osnoise_context - read, store, write, restore osnoise configs.
55  */
56 struct osnoise_context {
57 	int			flags;
58 	int			ref;
59 
60 	char			*curr_cpus;
61 	char			*orig_cpus;
62 
63 	/* 0 as init value */
64 	unsigned long long	orig_runtime_us;
65 	unsigned long long	runtime_us;
66 
67 	/* 0 as init value */
68 	unsigned long long	orig_period_us;
69 	unsigned long long	period_us;
70 
71 	/* 0 as init value */
72 	long long		orig_timerlat_period_us;
73 	long long		timerlat_period_us;
74 
75 	/* 0 as init value */
76 	long long		orig_tracing_thresh;
77 	long long		tracing_thresh;
78 
79 	/* -1 as init value because 0 is disabled */
80 	long long		orig_stop_us;
81 	long long		stop_us;
82 
83 	/* -1 as init value because 0 is disabled */
84 	long long		orig_stop_total_us;
85 	long long		stop_total_us;
86 
87 	/* -1 as init value because 0 is disabled */
88 	long long		orig_print_stack;
89 	long long		print_stack;
90 
91 	/* -1 as init value because 0 is off */
92 	int			orig_opt_irq_disable;
93 	int			opt_irq_disable;
94 
95 	/* -1 as init value because 0 is off */
96 	int			orig_opt_workload;
97 	int			opt_workload;
98 };
99 
100 /*
101  * *_INIT_VALs are also invalid values, they are used to
102  * communicate errors.
103  */
104 #define OSNOISE_OPTION_INIT_VAL	(-1)
105 #define OSNOISE_TIME_INIT_VAL	(0)
106 
107 struct osnoise_context *osnoise_context_alloc(void);
108 int osnoise_get_context(struct osnoise_context *context);
109 void osnoise_put_context(struct osnoise_context *context);
110 
111 int osnoise_set_cpus(struct osnoise_context *context, char *cpus);
112 void osnoise_restore_cpus(struct osnoise_context *context);
113 
114 int osnoise_set_runtime_period(struct osnoise_context *context,
115 			       unsigned long long runtime,
116 			       unsigned long long period);
117 void osnoise_restore_runtime_period(struct osnoise_context *context);
118 
119 int osnoise_set_stop_us(struct osnoise_context *context,
120 			long long stop_us);
121 void osnoise_restore_stop_us(struct osnoise_context *context);
122 
123 int osnoise_set_stop_total_us(struct osnoise_context *context,
124 			      long long stop_total_us);
125 void osnoise_restore_stop_total_us(struct osnoise_context *context);
126 
127 int osnoise_set_timerlat_period_us(struct osnoise_context *context,
128 				   long long timerlat_period_us);
129 void osnoise_restore_timerlat_period_us(struct osnoise_context *context);
130 
131 int osnoise_set_tracing_thresh(struct osnoise_context *context,
132 			       long long tracing_thresh);
133 void osnoise_restore_tracing_thresh(struct osnoise_context *context);
134 
135 void osnoise_restore_print_stack(struct osnoise_context *context);
136 int osnoise_set_print_stack(struct osnoise_context *context,
137 			    long long print_stack);
138 
139 int osnoise_set_irq_disable(struct osnoise_context *context, bool onoff);
140 int osnoise_set_workload(struct osnoise_context *context, bool onoff);
141 
142 /*
143  * osnoise_tool -  osnoise based tool definition.
144  */
145 struct osnoise_tool {
146 	struct trace_instance		trace;
147 	struct osnoise_context		*context;
148 	void				*data;
149 	void				*params;
150 	time_t				start_time;
151 };
152 
153 void osnoise_destroy_tool(struct osnoise_tool *top);
154 struct osnoise_tool *osnoise_init_tool(char *tool_name);
155 struct osnoise_tool *osnoise_init_trace_tool(char *tracer);
156 void osnoise_report_missed_events(struct osnoise_tool *tool);
157 bool osnoise_trace_is_off(struct osnoise_tool *tool, struct osnoise_tool *record);
158 int osnoise_apply_config(struct osnoise_tool *tool, struct osnoise_params *params);
159 
160 int osnoise_hist_main(int argc, char *argv[]);
161 int osnoise_top_main(int argc, char **argv);
162 int osnoise_main(int argc, char **argv);
163 int hwnoise_main(int argc, char **argv);
164