Commit 5742bf62 authored by Crystal Wood's avatar Crystal Wood Committed by Steven Rostedt (Google)
Browse files

tools/rtla: Move top/hist params into common struct

The hist members were very similar between timerlat and top, so
just use one common hist struct.

output_divisor, quiet, and pretty printing are pretty generic
concepts that can go in the main struct even if not every
specific tool (currently) uses them.

Cc: John Kacur <jkacur@redhat.com>
Cc: Costa Shulyupin <costa.shul@redhat.com>
Link: https://lore.kernel.org/20250907022325.243930-3-crwood@redhat.com


Reviewed-by: default avatarTomas Glozar <tglozar@redhat.com>
Signed-off-by: default avatarCrystal Wood <crwood@redhat.com>
Signed-off-by: default avatarSteven Rostedt (Google) <rostedt@goodmis.org>
parent 34482388
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -3,6 +3,17 @@

#include "utils.h"

struct hist_params {
	char			no_irq;
	char			no_thread;
	char			no_header;
	char			no_summary;
	char			no_index;
	char			with_zeros;
	int			bucket_size;
	int			entries;
};

/*
 * common_params - Parameters shared between timerlat_params and osnoise_params
 */
@@ -27,4 +38,10 @@ struct common_params {
	char			*cgroup_name;
	int			hk_cpus;
	cpu_set_t		hk_cpu_set;

	/* Other parameters */
	struct hist_params	hist;
	int			output_divisor;
	int			pretty_output;
	int			quiet;
};
+1 −18
Original line number Diff line number Diff line
@@ -15,25 +15,8 @@ struct osnoise_params {
	unsigned long long	runtime;
	unsigned long long	period;
	long long		threshold;
	union {
		struct {
			/* top only */
			int			quiet;
			int			pretty_output;
	enum osnoise_mode	mode;
};
		struct {
			/* hist only */
			int			output_divisor;
			char			no_header;
			char			no_summary;
			char			no_index;
			char			with_zeros;
			int			bucket_size;
			int			entries;
		};
	};
};

/*
 * osnoise_context - read, store, write, restore osnoise configs.
+31 −28
Original line number Diff line number Diff line
@@ -102,8 +102,8 @@ static void osnoise_hist_update_multiple(struct osnoise_tool *tool, int cpu,
	int bucket;
	int *hist;

	if (params->output_divisor)
		duration = duration / params->output_divisor;
	if (params->common.output_divisor)
		duration = duration / params->common.output_divisor;

	bucket = duration / data->bucket_size;

@@ -146,7 +146,7 @@ static int osnoise_init_trace_hist(struct osnoise_tool *tool)
	/*
	 * Set the size of the bucket.
	 */
	bucket_size = params->output_divisor * params->bucket_size;
	bucket_size = params->common.output_divisor * params->common.hist.bucket_size;
	snprintf(buff, sizeof(buff), "duration.buckets=%d", bucket_size);

	data->trace_hist = tracefs_hist_alloc(tool->trace.tep, "osnoise", "sample_threshold",
@@ -228,18 +228,18 @@ static void osnoise_hist_header(struct osnoise_tool *tool)
	char duration[26];
	int cpu;

	if (params->no_header)
	if (params->common.hist.no_header)
		return;

	get_duration(tool->start_time, duration, sizeof(duration));
	trace_seq_printf(s, "# RTLA osnoise histogram\n");
	trace_seq_printf(s, "# Time unit is %s (%s)\n",
			params->output_divisor == 1 ? "nanoseconds" : "microseconds",
			params->output_divisor == 1 ? "ns" : "us");
			params->common.output_divisor == 1 ? "nanoseconds" : "microseconds",
			params->common.output_divisor == 1 ? "ns" : "us");

	trace_seq_printf(s, "# Duration: %s\n", duration);

	if (!params->no_index)
	if (!params->common.hist.no_index)
		trace_seq_printf(s, "Index");

	for (cpu = 0; cpu < data->nr_cpus; cpu++) {
@@ -267,10 +267,10 @@ osnoise_print_summary(struct osnoise_params *params,
{
	int cpu;

	if (params->no_summary)
	if (params->common.hist.no_summary)
		return;

	if (!params->no_index)
	if (!params->common.hist.no_index)
		trace_seq_printf(trace->seq, "count:");

	for (cpu = 0; cpu < data->nr_cpus; cpu++) {
@@ -284,7 +284,7 @@ osnoise_print_summary(struct osnoise_params *params,
	}
	trace_seq_printf(trace->seq, "\n");

	if (!params->no_index)
	if (!params->common.hist.no_index)
		trace_seq_printf(trace->seq, "min:  ");

	for (cpu = 0; cpu < data->nr_cpus; cpu++) {
@@ -299,7 +299,7 @@ osnoise_print_summary(struct osnoise_params *params,
	}
	trace_seq_printf(trace->seq, "\n");

	if (!params->no_index)
	if (!params->common.hist.no_index)
		trace_seq_printf(trace->seq, "avg:  ");

	for (cpu = 0; cpu < data->nr_cpus; cpu++) {
@@ -317,7 +317,7 @@ osnoise_print_summary(struct osnoise_params *params,
	}
	trace_seq_printf(trace->seq, "\n");

	if (!params->no_index)
	if (!params->common.hist.no_index)
		trace_seq_printf(trace->seq, "max:  ");

	for (cpu = 0; cpu < data->nr_cpus; cpu++) {
@@ -352,7 +352,7 @@ osnoise_print_stats(struct osnoise_params *params, struct osnoise_tool *tool)
	for (bucket = 0; bucket < data->entries; bucket++) {
		total = 0;

		if (!params->no_index)
		if (!params->common.hist.no_index)
			trace_seq_printf(trace->seq, "%-6d",
					 bucket * data->bucket_size);

@@ -367,7 +367,7 @@ osnoise_print_stats(struct osnoise_params *params, struct osnoise_tool *tool)
			trace_seq_printf(trace->seq, "%9d ", data->hist[cpu].samples[bucket]);
		}

		if (total == 0 && !params->with_zeros) {
		if (total == 0 && !params->common.hist.with_zeros) {
			trace_seq_reset(trace->seq);
			continue;
		}
@@ -391,7 +391,7 @@ osnoise_print_stats(struct osnoise_params *params, struct osnoise_tool *tool)
		return;
	}

	if (!params->no_index)
	if (!params->common.hist.no_index)
		trace_seq_printf(trace->seq, "over: ");

	for (cpu = 0; cpu < data->nr_cpus; cpu++) {
@@ -490,9 +490,9 @@ static struct osnoise_params
		exit(1);

	/* display data in microseconds */
	params->output_divisor = 1000;
	params->bucket_size = 1;
	params->entries = 256;
	params->common.output_divisor = 1000;
	params->common.hist.bucket_size = 1;
	params->common.hist.entries = 256;

	while (1) {
		static struct option long_options[] = {
@@ -547,8 +547,9 @@ static struct osnoise_params

			break;
		case 'b':
			params->bucket_size = get_llong_from_str(optarg);
			if ((params->bucket_size == 0) || (params->bucket_size >= 1000000))
			params->common.hist.bucket_size = get_llong_from_str(optarg);
			if (params->common.hist.bucket_size == 0 ||
			    params->common.hist.bucket_size >= 1000000)
				osnoise_hist_usage("Bucket size needs to be > 0 and <= 1000000\n");
			break;
		case 'c':
@@ -588,8 +589,9 @@ static struct osnoise_params
			params->common.events = tevent;
			break;
		case 'E':
			params->entries = get_llong_from_str(optarg);
			if ((params->entries < 10) || (params->entries > 9999999))
			params->common.hist.entries = get_llong_from_str(optarg);
			if (params->common.hist.entries < 10 ||
			    params->common.hist.entries > 9999999)
				osnoise_hist_usage("Entries must be > 10 and < 9999999\n");
			break;
		case 'h':
@@ -641,16 +643,16 @@ static struct osnoise_params
				params->trace_output = "osnoise_trace.txt";
			break;
		case '0': /* no header */
			params->no_header = 1;
			params->common.hist.no_header = 1;
			break;
		case '1': /* no summary */
			params->no_summary = 1;
			params->common.hist.no_summary = 1;
			break;
		case '2': /* no index */
			params->no_index = 1;
			params->common.hist.no_index = 1;
			break;
		case '3': /* with zeros */
			params->with_zeros = 1;
			params->common.hist.with_zeros = 1;
			break;
		case '4': /* trigger */
			if (params->common.events) {
@@ -690,7 +692,7 @@ static struct osnoise_params
		exit(EXIT_FAILURE);
	}

	if (params->no_index && !params->with_zeros)
	if (params->common.hist.no_index && !params->common.hist.with_zeros)
		osnoise_hist_usage("no-index set and with-zeros not set - it does not make sense");

	return params;
@@ -729,7 +731,8 @@ static struct osnoise_tool
	if (!tool)
		return NULL;

	tool->data = osnoise_alloc_histogram(nr_cpus, params->entries, params->bucket_size);
	tool->data = osnoise_alloc_histogram(nr_cpus, params->common.hist.entries,
					     params->common.hist.bucket_size);
	if (!tool->data)
		goto out_err;

+10 −9
Original line number Diff line number Diff line
@@ -125,11 +125,12 @@ static void osnoise_top_header(struct osnoise_tool *top)
{
	struct osnoise_params *params = top->params;
	struct trace_seq *s = top->trace.seq;
	bool pretty = params->common.pretty_output;
	char duration[26];

	get_duration(top->start_time, duration, sizeof(duration));

	if (params->pretty_output)
	if (pretty)
		trace_seq_printf(s, "\033[2;37;40m");

	trace_seq_printf(s, "                                          ");
@@ -143,13 +144,13 @@ static void osnoise_top_header(struct osnoise_tool *top)

	trace_seq_printf(s, "                                   ");

	if (params->pretty_output)
	if (pretty)
		trace_seq_printf(s, "\033[0;0;0m");
	trace_seq_printf(s, "\n");

	trace_seq_printf(s, "duration: %9s | time is in us\n", duration);

	if (params->pretty_output)
	if (pretty)
		trace_seq_printf(s, "\033[2;30;47m");

	trace_seq_printf(s, "CPU Period       Runtime ");
@@ -164,7 +165,7 @@ static void osnoise_top_header(struct osnoise_tool *top)
	trace_seq_printf(s, "          IRQ      Softirq       Thread");

eol:
	if (params->pretty_output)
	if (pretty)
		trace_seq_printf(s, "\033[0;0;0m");
	trace_seq_printf(s, "\n");
}
@@ -232,7 +233,7 @@ osnoise_print_stats(struct osnoise_params *params, struct osnoise_tool *top)
	if (nr_cpus == -1)
		nr_cpus = sysconf(_SC_NPROCESSORS_CONF);

	if (!params->quiet)
	if (!params->common.quiet)
		clear_terminal(trace->seq);

	osnoise_top_header(top);
@@ -446,7 +447,7 @@ struct osnoise_params *osnoise_top_parse_args(int argc, char **argv)
			params->common.set_sched = 1;
			break;
		case 'q':
			params->quiet = 1;
			params->common.quiet = 1;
			break;
		case 'r':
			params->runtime = get_llong_from_str(optarg);
@@ -534,8 +535,8 @@ osnoise_top_apply_config(struct osnoise_tool *tool, struct osnoise_params *param
		}
	}

	if (isatty(STDOUT_FILENO) && !params->quiet)
		params->pretty_output = 1;
	if (isatty(STDOUT_FILENO) && !params->common.quiet)
		params->common.pretty_output = 1;

	return 0;

@@ -705,7 +706,7 @@ int osnoise_top_main(int argc, char **argv)
			goto out_top;
		}

		if (!params->quiet)
		if (!params->common.quiet)
			osnoise_print_stats(params, tool);

		if (osnoise_trace_is_off(tool, record))
+1 −21
Original line number Diff line number Diff line
@@ -23,7 +23,6 @@ struct timerlat_params {
	struct common_params	common;
	long long		timerlat_period_us;
	long long		print_stack;
	int			output_divisor;
	int			dma_latency;
	int			no_aa;
	int			dump_tasks;
@@ -31,30 +30,11 @@ struct timerlat_params {
	int			kernel_workload;
	int			user_data;
	int			deepest_idle_state;
	int			aa_only;
	enum timerlat_tracing_mode mode;

	struct actions threshold_actions;
	struct actions end_actions;

	union {
		struct {
			/* top only */
			int			quiet;
			int			aa_only;
			int			pretty_output;
		};
		struct {
			/* hist only */
			char			no_irq;
			char			no_thread;
			char			no_header;
			char			no_summary;
			char			no_index;
			char			with_zeros;
			int			bucket_size;
			int			entries;
		};
	};
};

int timerlat_apply_config(struct osnoise_tool *tool, struct timerlat_params *params);
Loading