diff options
Diffstat (limited to 'tools/tracing/rtla/src/osnoise.c')
-rw-r--r-- | tools/tracing/rtla/src/osnoise.c | 86 |
1 files changed, 85 insertions, 1 deletions
diff --git a/tools/tracing/rtla/src/osnoise.c b/tools/tracing/rtla/src/osnoise.c index 85f398b89597..2dc3e4539e99 100644 --- a/tools/tracing/rtla/src/osnoise.c +++ b/tools/tracing/rtla/src/osnoise.c @@ -3,6 +3,7 @@ * Copyright (C) 2021 Red Hat Inc, Daniel Bristot de Oliveira <bristot@kernel.org> */ +#define _GNU_SOURCE #include <sys/types.h> #include <sys/stat.h> #include <pthread.h> @@ -12,9 +13,12 @@ #include <errno.h> #include <fcntl.h> #include <stdio.h> +#include <sched.h> #include "osnoise.h" -#include "utils.h" + +#define DEFAULT_SAMPLE_PERIOD 1000000 /* 1s */ +#define DEFAULT_SAMPLE_RUNTIME 1000000 /* 1s */ /* * osnoise_get_cpus - return the original "osnoise/cpus" content @@ -1115,6 +1119,86 @@ osnoise_report_missed_events(struct osnoise_tool *tool) } } +/* + * osnoise_apply_config - apply common configs to the initialized tool + */ +int +osnoise_apply_config(struct osnoise_tool *tool, struct osnoise_params *params) +{ + int retval; + + 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->runtime || params->period) { + retval = osnoise_set_runtime_period(tool->context, + params->runtime, + params->period); + } else { + retval = osnoise_set_runtime_period(tool->context, + DEFAULT_SAMPLE_PERIOD, + DEFAULT_SAMPLE_RUNTIME); + } + + if (retval) { + err_msg("Failed to set runtime and/or period\n"); + goto out_err; + } + + retval = osnoise_set_stop_us(tool->context, params->stop_us); + if (retval) { + err_msg("Failed to set stop us\n"); + goto out_err; + } + + retval = osnoise_set_stop_total_us(tool->context, params->stop_total_us); + if (retval) { + err_msg("Failed to set stop total us\n"); + goto out_err; + } + + retval = osnoise_set_tracing_thresh(tool->context, params->threshold); + if (retval) { + err_msg("Failed to set tracing_thresh\n"); + goto out_err; + } + + 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); + } + + retval = osnoise_set_workload(tool->context, true); + if (retval < -1) { + err_msg("Failed to set OSNOISE_WORKLOAD option\n"); + goto out_err; + } + + return 0; + +out_err: + return -1; +} + static void osnoise_usage(int err) { int i; |