Skip to content

Commit

Permalink
rtla/osnoise: Unify params struct
Browse files Browse the repository at this point in the history
Instead of having separate structs osnoise_top_params and
osnoise_hist_params, use one struct osnoise_params for both.

This allows code using the structs to be shared between osnoise-top and
osnoise-hist.

Cc: Luis Goncalves <lgoncalv@redhat.com>
Link: https://lore.kernel.org/20250320092500.101385-2-tglozar@redhat.com
Signed-off-by: Tomas Glozar <tglozar@redhat.com>
Reviewed-by: John Kacur <jkacur@redhat.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
  • Loading branch information
Tomas Glozar authored and Steven Rostedt (Google) committed Mar 26, 2025
1 parent c57c58a commit 025b217
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 87 deletions.
1 change: 0 additions & 1 deletion tools/tracing/rtla/src/osnoise.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include <stdio.h>

#include "osnoise.h"
#include "utils.h"

/*
* osnoise_get_cpus - return the original "osnoise/cpus" content
Expand Down
47 changes: 47 additions & 0 deletions tools/tracing/rtla/src/osnoise.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,55 @@
// SPDX-License-Identifier: GPL-2.0
#pragma once

#include "utils.h"
#include "trace.h"

enum osnoise_mode {
MODE_OSNOISE = 0,
MODE_HWNOISE
};

struct osnoise_params {
/* Common params */
char *cpus;
cpu_set_t monitored_cpus;
char *trace_output;
char *cgroup_name;
unsigned long long runtime;
unsigned long long period;
long long threshold;
long long stop_us;
long long stop_total_us;
int sleep_time;
int duration;
int set_sched;
int cgroup;
int hk_cpus;
cpu_set_t hk_cpu_set;
struct sched_attr sched_param;
struct trace_events *events;
int warmup;
int buffer_size;
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.
*/
Expand Down
52 changes: 11 additions & 41 deletions tools/tracing/rtla/src/osnoise_hist.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,38 +14,8 @@
#include <time.h>
#include <sched.h>

#include "utils.h"
#include "osnoise.h"

struct osnoise_hist_params {
char *cpus;
cpu_set_t monitored_cpus;
char *trace_output;
char *cgroup_name;
unsigned long long runtime;
unsigned long long period;
long long threshold;
long long stop_us;
long long stop_total_us;
int sleep_time;
int duration;
int set_sched;
int output_divisor;
int cgroup;
int hk_cpus;
cpu_set_t hk_cpu_set;
struct sched_attr sched_param;
struct trace_events *events;
char no_header;
char no_summary;
char no_index;
char with_zeros;
int bucket_size;
int entries;
int warmup;
int buffer_size;
};

struct osnoise_hist_cpu {
int *samples;
int count;
Expand Down Expand Up @@ -126,7 +96,7 @@ static struct osnoise_hist_data
static void osnoise_hist_update_multiple(struct osnoise_tool *tool, int cpu,
unsigned long long duration, int count)
{
struct osnoise_hist_params *params = tool->params;
struct osnoise_params *params = tool->params;
struct osnoise_hist_data *data = tool->data;
unsigned long long total_duration;
int entries = data->entries;
Expand Down Expand Up @@ -168,7 +138,7 @@ static void osnoise_destroy_trace_hist(struct osnoise_tool *tool)
*/
static int osnoise_init_trace_hist(struct osnoise_tool *tool)
{
struct osnoise_hist_params *params = tool->params;
struct osnoise_params *params = tool->params;
struct osnoise_hist_data *data = tool->data;
int bucket_size;
char buff[128];
Expand Down Expand Up @@ -253,7 +223,7 @@ static void osnoise_read_trace_hist(struct osnoise_tool *tool)
*/
static void osnoise_hist_header(struct osnoise_tool *tool)
{
struct osnoise_hist_params *params = tool->params;
struct osnoise_params *params = tool->params;
struct osnoise_hist_data *data = tool->data;
struct trace_seq *s = tool->trace.seq;
char duration[26];
Expand Down Expand Up @@ -292,7 +262,7 @@ static void osnoise_hist_header(struct osnoise_tool *tool)
* osnoise_print_summary - print the summary of the hist data to the output
*/
static void
osnoise_print_summary(struct osnoise_hist_params *params,
osnoise_print_summary(struct osnoise_params *params,
struct trace_instance *trace,
struct osnoise_hist_data *data)
{
Expand Down Expand Up @@ -370,7 +340,7 @@ osnoise_print_summary(struct osnoise_hist_params *params,
* osnoise_print_stats - print data for all CPUs
*/
static void
osnoise_print_stats(struct osnoise_hist_params *params, struct osnoise_tool *tool)
osnoise_print_stats(struct osnoise_params *params, struct osnoise_tool *tool)
{
struct osnoise_hist_data *data = tool->data;
struct trace_instance *trace = &tool->trace;
Expand Down Expand Up @@ -508,10 +478,10 @@ static void osnoise_hist_usage(char *usage)
/*
* osnoise_hist_parse_args - allocs, parse and fill the cmd line parameters
*/
static struct osnoise_hist_params
static struct osnoise_params
*osnoise_hist_parse_args(int argc, char *argv[])
{
struct osnoise_hist_params *params;
struct osnoise_params *params;
struct trace_events *tevent;
int retval;
int c;
Expand Down Expand Up @@ -731,7 +701,7 @@ static struct osnoise_hist_params
* osnoise_hist_apply_config - apply the hist configs to the initialized tool
*/
static int
osnoise_hist_apply_config(struct osnoise_tool *tool, struct osnoise_hist_params *params)
osnoise_hist_apply_config(struct osnoise_tool *tool, struct osnoise_params *params)
{
int retval;

Expand Down Expand Up @@ -808,7 +778,7 @@ osnoise_hist_apply_config(struct osnoise_tool *tool, struct osnoise_hist_params
* osnoise_init_hist - initialize a osnoise hist tool with parameters
*/
static struct osnoise_tool
*osnoise_init_hist(struct osnoise_hist_params *params)
*osnoise_init_hist(struct osnoise_params *params)
{
struct osnoise_tool *tool;
int nr_cpus;
Expand Down Expand Up @@ -842,7 +812,7 @@ static void stop_hist(int sig)
* osnoise_hist_set_signals - handles the signal to stop the tool
*/
static void
osnoise_hist_set_signals(struct osnoise_hist_params *params)
osnoise_hist_set_signals(struct osnoise_params *params)
{
signal(SIGINT, stop_hist);
if (params->duration) {
Expand All @@ -853,7 +823,7 @@ osnoise_hist_set_signals(struct osnoise_hist_params *params)

int osnoise_hist_main(int argc, char *argv[])
{
struct osnoise_hist_params *params;
struct osnoise_params *params;
struct osnoise_tool *record = NULL;
struct osnoise_tool *tool = NULL;
struct trace_instance *trace;
Expand Down
54 changes: 10 additions & 44 deletions tools/tracing/rtla/src/osnoise_top.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,40 +14,6 @@
#include <sched.h>

#include "osnoise.h"
#include "utils.h"

enum osnoise_mode {
MODE_OSNOISE = 0,
MODE_HWNOISE
};

/*
* osnoise top parameters
*/
struct osnoise_top_params {
char *cpus;
cpu_set_t monitored_cpus;
char *trace_output;
char *cgroup_name;
unsigned long long runtime;
unsigned long long period;
long long threshold;
long long stop_us;
long long stop_total_us;
int sleep_time;
int duration;
int quiet;
int set_sched;
int cgroup;
int hk_cpus;
int warmup;
int buffer_size;
int pretty_output;
cpu_set_t hk_cpu_set;
struct sched_attr sched_param;
struct trace_events *events;
enum osnoise_mode mode;
};

struct osnoise_top_cpu {
unsigned long long sum_runtime;
Expand Down Expand Up @@ -158,7 +124,7 @@ osnoise_top_handler(struct trace_seq *s, struct tep_record *record,
*/
static void osnoise_top_header(struct osnoise_tool *top)
{
struct osnoise_top_params *params = top->params;
struct osnoise_params *params = top->params;
struct trace_seq *s = top->trace.seq;
char duration[26];

Expand Down Expand Up @@ -218,7 +184,7 @@ static void clear_terminal(struct trace_seq *seq)
*/
static void osnoise_top_print(struct osnoise_tool *tool, int cpu)
{
struct osnoise_top_params *params = tool->params;
struct osnoise_params *params = tool->params;
struct trace_seq *s = tool->trace.seq;
struct osnoise_top_cpu *cpu_data;
struct osnoise_top_data *data;
Expand Down Expand Up @@ -258,7 +224,7 @@ static void osnoise_top_print(struct osnoise_tool *tool, int cpu)
* osnoise_print_stats - print data for all cpus
*/
static void
osnoise_print_stats(struct osnoise_top_params *params, struct osnoise_tool *top)
osnoise_print_stats(struct osnoise_params *params, struct osnoise_tool *top)
{
struct trace_instance *trace = &top->trace;
static int nr_cpus = -1;
Expand Down Expand Up @@ -286,7 +252,7 @@ osnoise_print_stats(struct osnoise_top_params *params, struct osnoise_tool *top)
/*
* osnoise_top_usage - prints osnoise top usage message
*/
static void osnoise_top_usage(struct osnoise_top_params *params, char *usage)
static void osnoise_top_usage(struct osnoise_params *params, char *usage)
{
int i;

Expand Down Expand Up @@ -354,9 +320,9 @@ static void osnoise_top_usage(struct osnoise_top_params *params, char *usage)
/*
* osnoise_top_parse_args - allocs, parse and fill the cmd line parameters
*/
struct osnoise_top_params *osnoise_top_parse_args(int argc, char **argv)
struct osnoise_params *osnoise_top_parse_args(int argc, char **argv)
{
struct osnoise_top_params *params;
struct osnoise_params *params;
struct trace_events *tevent;
int retval;
int c;
Expand Down Expand Up @@ -553,7 +519,7 @@ struct osnoise_top_params *osnoise_top_parse_args(int argc, char **argv)
* osnoise_top_apply_config - apply the top configs to the initialized tool
*/
static int
osnoise_top_apply_config(struct osnoise_tool *tool, struct osnoise_top_params *params)
osnoise_top_apply_config(struct osnoise_tool *tool, struct osnoise_params *params)
{
int retval;

Expand Down Expand Up @@ -640,7 +606,7 @@ osnoise_top_apply_config(struct osnoise_tool *tool, struct osnoise_top_params *p
/*
* osnoise_init_top - initialize a osnoise top tool with parameters
*/
struct osnoise_tool *osnoise_init_top(struct osnoise_top_params *params)
struct osnoise_tool *osnoise_init_top(struct osnoise_params *params)
{
struct osnoise_tool *tool;
int nr_cpus;
Expand Down Expand Up @@ -674,7 +640,7 @@ static void stop_top(int sig)
/*
* osnoise_top_set_signals - handles the signal to stop the tool
*/
static void osnoise_top_set_signals(struct osnoise_top_params *params)
static void osnoise_top_set_signals(struct osnoise_params *params)
{
signal(SIGINT, stop_top);
if (params->duration) {
Expand All @@ -685,7 +651,7 @@ static void osnoise_top_set_signals(struct osnoise_top_params *params)

int osnoise_top_main(int argc, char **argv)
{
struct osnoise_top_params *params;
struct osnoise_params *params;
struct osnoise_tool *record = NULL;
struct osnoise_tool *tool = NULL;
struct trace_instance *trace;
Expand Down
1 change: 0 additions & 1 deletion tools/tracing/rtla/src/timerlat.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// SPDX-License-Identifier: GPL-2.0
#include "utils.h"
#include "osnoise.h"

struct timerlat_params {
Expand Down

0 comments on commit 025b217

Please sign in to comment.