rtla-y += trace.o
rtla-y += utils.o
rtla-y += actions.o
+rtla-y += common.o
rtla-y += osnoise.o
rtla-y += osnoise_top.o
rtla-y += osnoise_hist.o
--- /dev/null
+// SPDX-License-Identifier: GPL-2.0
+#define _GNU_SOURCE
+
+#include <unistd.h>
+#include "common.h"
+
+/*
+ * common_apply_config - apply common configs to the initialized tool
+ */
+int
+common_apply_config(struct osnoise_tool *tool, struct common_params *params)
+{
+ int retval, i;
+
+ if (!params->sleep_time)
+ params->sleep_time = 1;
+
+ retval = osnoise_set_cpus(tool->context, params->cpus ? params->cpus : "all");
+ if (retval) {
+ err_msg("Failed to apply CPUs config\n");
+ goto out_err;
+ }
+
+ if (!params->cpus) {
+ for (i = 0; i < sysconf(_SC_NPROCESSORS_CONF); i++)
+ CPU_SET(i, ¶ms->monitored_cpus);
+ }
+
+ if (params->hk_cpus) {
+ retval = sched_setaffinity(getpid(), sizeof(params->hk_cpu_set),
+ ¶ms->hk_cpu_set);
+ if (retval == -1) {
+ err_msg("Failed to set rtla to the house keeping CPUs\n");
+ goto out_err;
+ }
+ } else if (params->cpus) {
+ /*
+ * Even if the user do not set a house-keeping CPU, try to
+ * move rtla to a CPU set different to the one where the user
+ * set the workload to run.
+ *
+ * No need to check results as this is an automatic attempt.
+ */
+ auto_house_keeping(¶ms->monitored_cpus);
+ }
+
+ /*
+ * Set workload according to type of thread if the kernel supports it.
+ * On kernels without support, user threads will have already failed
+ * on missing fd, and kernel threads do not need it.
+ */
+ retval = osnoise_set_workload(tool->context, params->kernel_workload);
+ if (retval < -1) {
+ err_msg("Failed to set OSNOISE_WORKLOAD option\n");
+ goto out_err;
+ }
+
+ return 0;
+
+out_err:
+ return -1;
+}
+
/* SPDX-License-Identifier: GPL-2.0 */
#pragma once
+#include "trace.h"
#include "utils.h"
+/*
+ * osnoise_context - read, store, write, restore osnoise configs.
+ */
+struct osnoise_context {
+ int flags;
+ int ref;
+
+ char *curr_cpus;
+ char *orig_cpus;
+
+ /* 0 as init value */
+ unsigned long long orig_runtime_us;
+ unsigned long long runtime_us;
+
+ /* 0 as init value */
+ unsigned long long orig_period_us;
+ unsigned long long period_us;
+
+ /* 0 as init value */
+ long long orig_timerlat_period_us;
+ long long timerlat_period_us;
+
+ /* 0 as init value */
+ long long orig_tracing_thresh;
+ long long tracing_thresh;
+
+ /* -1 as init value because 0 is disabled */
+ long long orig_stop_us;
+ long long stop_us;
+
+ /* -1 as init value because 0 is disabled */
+ long long orig_stop_total_us;
+ long long stop_total_us;
+
+ /* -1 as init value because 0 is disabled */
+ long long orig_print_stack;
+ long long print_stack;
+
+ /* -1 as init value because 0 is off */
+ int orig_opt_irq_disable;
+ int opt_irq_disable;
+
+ /* -1 as init value because 0 is off */
+ int orig_opt_workload;
+ int opt_workload;
+};
+
+/*
+ * osnoise_tool - osnoise based tool definition.
+ */
+struct osnoise_tool {
+ struct trace_instance trace;
+ struct osnoise_context *context;
+ void *data;
+ void *params;
+ time_t start_time;
+};
+
struct hist_params {
char no_irq;
char no_thread;
int output_divisor;
int pretty_output;
int quiet;
+ int kernel_workload;
};
+
+int osnoise_set_cpus(struct osnoise_context *context, char *cpus);
+void osnoise_restore_cpus(struct osnoise_context *context);
+
+int osnoise_set_workload(struct osnoise_context *context, bool onoff);
+
+int common_apply_config(struct osnoise_tool *tool, struct common_params *params);
}
/*
- * osnoise_apply_config - apply common configs to the initialized tool
+ * osnoise_apply_config - apply osnoise configs to the initialized tool
*/
int
osnoise_apply_config(struct osnoise_tool *tool, struct osnoise_params *params)
{
int retval;
- if (!params->common.sleep_time)
- params->common.sleep_time = 1;
-
- retval = osnoise_set_cpus(tool->context, params->common.cpus ? params->common.cpus : "all");
- if (retval) {
- err_msg("Failed to apply CPUs config\n");
- goto out_err;
- }
+ params->common.kernel_workload = true;
if (params->runtime || params->period) {
retval = osnoise_set_runtime_period(tool->context,
goto out_err;
}
- if (params->common.hk_cpus) {
- retval = sched_setaffinity(getpid(), sizeof(params->common.hk_cpu_set),
- ¶ms->common.hk_cpu_set);
- if (retval == -1) {
- err_msg("Failed to set rtla to the house keeping CPUs\n");
- goto out_err;
- }
- } else if (params->common.cpus) {
- /*
- * Even if the user do not set a house-keeping CPU, try to
- * move rtla to a CPU set different to the one where the user
- * set the workload to run.
- *
- * No need to check results as this is an automatic attempt.
- */
- auto_house_keeping(¶ms->common.monitored_cpus);
- }
-
- retval = osnoise_set_workload(tool->context, true);
- if (retval < -1) {
- err_msg("Failed to set OSNOISE_WORKLOAD option\n");
- goto out_err;
- }
-
- return 0;
+ return common_apply_config(tool, ¶ms->common);
out_err:
return -1;
#pragma once
#include "common.h"
-#include "trace.h"
enum osnoise_mode {
MODE_OSNOISE = 0,
enum osnoise_mode mode;
};
-/*
- * osnoise_context - read, store, write, restore osnoise configs.
- */
-struct osnoise_context {
- int flags;
- int ref;
-
- char *curr_cpus;
- char *orig_cpus;
-
- /* 0 as init value */
- unsigned long long orig_runtime_us;
- unsigned long long runtime_us;
-
- /* 0 as init value */
- unsigned long long orig_period_us;
- unsigned long long period_us;
-
- /* 0 as init value */
- long long orig_timerlat_period_us;
- long long timerlat_period_us;
-
- /* 0 as init value */
- long long orig_tracing_thresh;
- long long tracing_thresh;
-
- /* -1 as init value because 0 is disabled */
- long long orig_stop_us;
- long long stop_us;
-
- /* -1 as init value because 0 is disabled */
- long long orig_stop_total_us;
- long long stop_total_us;
-
- /* -1 as init value because 0 is disabled */
- long long orig_print_stack;
- long long print_stack;
-
- /* -1 as init value because 0 is off */
- int orig_opt_irq_disable;
- int opt_irq_disable;
-
- /* -1 as init value because 0 is off */
- int orig_opt_workload;
- int opt_workload;
-};
-
/*
* *_INIT_VALs are also invalid values, they are used to
* communicate errors.
int osnoise_get_context(struct osnoise_context *context);
void osnoise_put_context(struct osnoise_context *context);
-int osnoise_set_cpus(struct osnoise_context *context, char *cpus);
-void osnoise_restore_cpus(struct osnoise_context *context);
-
int osnoise_set_runtime_period(struct osnoise_context *context,
unsigned long long runtime,
unsigned long long period);
long long print_stack);
int osnoise_set_irq_disable(struct osnoise_context *context, bool onoff);
-int osnoise_set_workload(struct osnoise_context *context, bool onoff);
-
-/*
- * osnoise_tool - osnoise based tool definition.
- */
-struct osnoise_tool {
- struct trace_instance trace;
- struct osnoise_context *context;
- void *data;
- void *params;
- time_t start_time;
-};
-
void osnoise_destroy_tool(struct osnoise_tool *top);
struct osnoise_tool *osnoise_init_tool(char *tool_name);
struct osnoise_tool *osnoise_init_trace_tool(char *tracer);
int
timerlat_apply_config(struct osnoise_tool *tool, struct timerlat_params *params)
{
- int retval, i;
-
- if (!params->common.sleep_time)
- params->common.sleep_time = 1;
-
- retval = osnoise_set_cpus(tool->context, params->common.cpus ? params->common.cpus : "all");
- if (retval) {
- err_msg("Failed to apply CPUs config\n");
- goto out_err;
- }
-
- if (!params->common.cpus) {
- for (i = 0; i < sysconf(_SC_NPROCESSORS_CONF); i++)
- CPU_SET(i, ¶ms->common.monitored_cpus);
- }
+ int retval;
if (params->mode != TRACING_MODE_BPF) {
/*
goto out_err;
}
- if (params->common.hk_cpus) {
- retval = sched_setaffinity(getpid(), sizeof(params->common.hk_cpu_set),
- ¶ms->common.hk_cpu_set);
- if (retval == -1) {
- err_msg("Failed to set rtla to the house keeping CPUs\n");
- goto out_err;
- }
- } else if (params->common.cpus) {
- /*
- * Even if the user do not set a house-keeping CPU, try to
- * move rtla to a CPU set different to the one where the user
- * set the workload to run.
- *
- * No need to check results as this is an automatic attempt.
- */
- auto_house_keeping(¶ms->common.monitored_cpus);
- }
-
/*
* If the user did not specify a type of thread, try user-threads first.
* Fall back to kernel threads otherwise.
*/
- if (!params->kernel_workload && !params->user_data) {
+ if (!params->common.kernel_workload && !params->user_data) {
retval = tracefs_file_exists(NULL, "osnoise/per_cpu/cpu0/timerlat_fd");
if (retval) {
debug_msg("User-space interface detected, setting user-threads\n");
params->user_data = 1;
} else {
debug_msg("User-space interface not detected, setting kernel-threads\n");
- params->kernel_workload = 1;
+ params->common.kernel_workload = 1;
}
}
- /*
- * Set workload according to type of thread if the kernel supports it.
- * On kernels without support, user threads will have already failed
- * on missing timerlat_fd, and kernel threads do not need it.
- */
- retval = osnoise_set_workload(tool->context, params->kernel_workload);
- if (retval < -1) {
- err_msg("Failed to set OSNOISE_WORKLOAD option\n");
- goto out_err;
- }
-
- return 0;
+ return common_apply_config(tool, ¶ms->common);
out_err:
return -1;
int no_aa;
int dump_tasks;
int user_workload;
- int kernel_workload;
int user_data;
int deepest_idle_state;
int aa_only;
params->common.stop_us = get_llong_from_str(optarg);
break;
case 'k':
- params->kernel_workload = 1;
+ params->common.kernel_workload = 1;
break;
case 'n':
params->common.output_divisor = 1;
if (!params->common.stop_us && !params->common.stop_total_us)
params->no_aa = 1;
- if (params->kernel_workload && params->user_workload)
+ if (params->common.kernel_workload && params->user_workload)
timerlat_hist_usage("--kernel-threads and --user-threads are mutually exclusive!");
/*
params->common.stop_us = get_llong_from_str(optarg);
break;
case 'k':
- params->kernel_workload = true;
+ params->common.kernel_workload = true;
break;
case 'n':
params->common.output_divisor = 1;
if (params->no_aa && params->aa_only)
timerlat_top_usage("--no-aa and --aa-only are mutually exclusive!");
- if (params->kernel_workload && params->user_workload)
+ if (params->common.kernel_workload && params->user_workload)
timerlat_top_usage("--kernel-threads and --user-threads are mutually exclusive!");
/*