| 1 |
|
| 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 |
|
| 20 | unsigned long long orig_runtime_us;
|
| 21 | unsigned long long runtime_us;
|
| 22 |
|
| 23 |
|
| 24 | unsigned long long orig_period_us;
|
| 25 | unsigned long long period_us;
|
| 26 |
|
| 27 |
|
| 28 | long long orig_timerlat_period_us;
|
| 29 | long long timerlat_period_us;
|
| 30 |
|
| 31 |
|
| 32 | long long orig_tracing_thresh;
|
| 33 | long long tracing_thresh;
|
| 34 |
|
| 35 |
|
| 36 | long long orig_stop_us;
|
| 37 | long long stop_us;
|
| 38 |
|
| 39 |
|
| 40 | long long orig_stop_total_us;
|
| 41 | long long stop_total_us;
|
| 42 |
|
| 43 |
|
| 44 | long long orig_print_stack;
|
| 45 | long long print_stack;
|
| 46 |
|
| 47 |
|
| 48 | int orig_opt_irq_disable;
|
| 49 | int opt_irq_disable;
|
| 50 |
|
| 51 |
|
| 52 | int orig_opt_workload;
|
| 53 | int opt_workload;
|
| 54 |
|
| 55 |
|
| 56 | int orig_opt_timerlat_align;
|
| 57 | int opt_timerlat_align;
|
| 58 |
|
| 59 |
|
| 60 | unsigned long long orig_timerlat_align_us;
|
| 61 | unsigned long long timerlat_align_us;
|
| 62 | };
|
| 63 |
|
| 64 | extern volatile int stop_tracing;
|
| 65 |
|
| 66 | struct hist_params {
|
| 67 | bool no_irq;
|
| 68 | bool no_thread;
|
| 69 | bool no_header;
|
| 70 | bool no_summary;
|
| 71 | bool no_index;
|
| 72 | bool with_zeros;
|
| 73 | int bucket_size;
|
| 74 | int entries;
|
| 75 | };
|
| 76 |
|
| 77 | |
| 78 | * common_params - Parameters shared between timerlat_params and osnoise_params
|
| 79 |
|
| 80 | struct common_params {
|
| 81 |
|
| 82 | char *cpus;
|
| 83 | cpu_set_t monitored_cpus;
|
| 84 | struct trace_events *events;
|
| 85 | int buffer_size;
|
| 86 |
|
| 87 |
|
| 88 | int warmup;
|
| 89 | long long stop_us;
|
| 90 | long long stop_total_us;
|
| 91 | int sleep_time;
|
| 92 | int duration;
|
| 93 |
|
| 94 |
|
| 95 | int set_sched;
|
| 96 | struct sched_attr sched_param;
|
| 97 | int cgroup;
|
| 98 | char *cgroup_name;
|
| 99 | int hk_cpus;
|
| 100 | cpu_set_t hk_cpu_set;
|
| 101 |
|
| 102 |
|
| 103 | struct hist_params hist;
|
| 104 | int output_divisor;
|
| 105 | bool pretty_output;
|
| 106 | bool quiet;
|
| 107 | bool user_workload;
|
| 108 | bool kernel_workload;
|
| 109 | bool user_data;
|
| 110 | bool aa_only;
|
| 111 |
|
| 112 | struct actions threshold_actions;
|
| 113 | struct actions end_actions;
|
| 114 | struct timerlat_u_params user;
|
| 115 | };
|
| 116 |
|
| 117 | extern int nr_cpus;
|
| 118 |
|
| 119 | #define for_each_monitored_cpu(cpu, common) \
|
| 120 | for (cpu = 0; cpu < nr_cpus; cpu++) \
|
| 121 | if (!(common)->cpus || CPU_ISSET(cpu, &(common)->monitored_cpus))
|
| 122 |
|
| 123 | struct tool_ops;
|
| 124 |
|
| 125 | |
| 126 | * osnoise_tool - osnoise based tool definition.
|
| 127 | *
|
| 128 | * Only the "trace" and "context" fields are used for
|
| 129 | * the additional trace instances (record and aa).
|
| 130 |
|
| 131 | struct osnoise_tool {
|
| 132 | struct tool_ops *ops;
|
| 133 | struct trace_instance trace;
|
| 134 | struct osnoise_context *context;
|
| 135 | void *data;
|
| 136 | struct common_params *params;
|
| 137 | time_t start_time;
|
| 138 | struct osnoise_tool *record;
|
| 139 | struct osnoise_tool *aa;
|
| 140 | };
|
| 141 |
|
| 142 | struct tool_ops {
|
| 143 | const char *tracer;
|
| 144 | const char *comm_prefix;
|
| 145 | struct common_params *(*parse_args)(int argc, char *argv[]);
|
| 146 | struct osnoise_tool *(*init_tool)(struct common_params *params);
|
| 147 | int (*apply_config)(struct osnoise_tool *tool);
|
| 148 | int (*enable)(struct osnoise_tool *tool);
|
| 149 | int (*main)(struct osnoise_tool *tool);
|
| 150 | void (*print_stats)(struct osnoise_tool *tool);
|
| 151 | void (*analyze)(struct osnoise_tool *tool, bool stopped);
|
| 152 | void (*free)(struct osnoise_tool *tool);
|
| 153 | };
|
| 154 |
|
| 155 | |
| 156 | * should_continue_tracing - check if tracing should continue after threshold
|
| 157 | * @params: pointer to the common parameters structure
|
| 158 | *
|
| 159 | * Returns true if the continue action was configured (--on-threshold continue),
|
| 160 | * indicating that tracing should be restarted after handling the threshold event.
|
| 161 | *
|
| 162 | * Return: 1 if tracing should continue, 0 otherwise.
|
| 163 |
|
| 164 | static inline int
|
| 165 | should_continue_tracing(const struct common_params *params)
|
| 166 | {
|
| 167 | return params->threshold_actions.continue_flag;
|
| 168 | }
|
| 169 |
|
| 170 | int
|
| 171 | common_threshold_handler(const struct osnoise_tool *tool);
|
| 172 |
|
| 173 | int osnoise_set_cpus(struct osnoise_context *context, char *cpus);
|
| 174 | void osnoise_restore_cpus(struct osnoise_context *context);
|
| 175 |
|
| 176 | int osnoise_set_workload(struct osnoise_context *context, bool onoff);
|
| 177 |
|
| 178 | void osnoise_destroy_tool(struct osnoise_tool *top);
|
| 179 | struct osnoise_tool *osnoise_init_tool(char *tool_name);
|
| 180 | struct osnoise_tool *osnoise_init_trace_tool(const char *tracer);
|
| 181 | bool osnoise_trace_is_off(struct osnoise_tool *tool, struct osnoise_tool *record);
|
| 182 | int osnoise_set_stop_us(struct osnoise_context *context, long long stop_us);
|
| 183 | int osnoise_set_stop_total_us(struct osnoise_context *context,
|
| 184 | long long stop_total_us);
|
| 185 |
|
| 186 | int common_apply_config(struct osnoise_tool *tool, struct common_params *params);
|
| 187 | int top_main_loop(struct osnoise_tool *tool);
|
| 188 | int hist_main_loop(struct osnoise_tool *tool);
|
| 189 | int osn_set_stop(struct osnoise_tool *tool);
|
| 190 |
|
| 191 | void common_usage(const char *tool, const char *mode,
|
| 192 | const char *desc, const char * const *start_msgs, const char * const *opt_msgs);
|