Skip to content

Commit 20d6b07

Browse files
lenticularis39rostedt
authored andcommitted
rtla: Unify apply_config between top and hist
The functions osnoise_top_apply_config and osnoise_hist_apply_config, as well as timerlat_top_apply_config and timerlat_hist_apply_config, are mostly the same. Move common part from them into separate functions osnoise_apply_config and timerlat_apply_config. For rtla-timerlat, also unify params->user_hist and params->user_top into one field called params->user_data, and move several fields used only by timerlat-top into the top-only section of struct timerlat_params. Cc: Luis Goncalves <lgoncalv@redhat.com> Link: https://lore.kernel.org/20250320092500.101385-3-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>
1 parent 025b217 commit 20d6b07

File tree

8 files changed

+227
-334
lines changed

8 files changed

+227
-334
lines changed

tools/tracing/rtla/src/osnoise.c

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright (C) 2021 Red Hat Inc, Daniel Bristot de Oliveira <bristot@kernel.org>
44
*/
55

6+
#define _GNU_SOURCE
67
#include <sys/types.h>
78
#include <sys/stat.h>
89
#include <pthread.h>
@@ -12,6 +13,7 @@
1213
#include <errno.h>
1314
#include <fcntl.h>
1415
#include <stdio.h>
16+
#include <sched.h>
1517

1618
#include "osnoise.h"
1719

@@ -1114,6 +1116,83 @@ osnoise_report_missed_events(struct osnoise_tool *tool)
11141116
}
11151117
}
11161118

1119+
/*
1120+
* osnoise_apply_config - apply common configs to the initialized tool
1121+
*/
1122+
int
1123+
osnoise_apply_config(struct osnoise_tool *tool, struct osnoise_params *params)
1124+
{
1125+
int retval;
1126+
1127+
if (!params->sleep_time)
1128+
params->sleep_time = 1;
1129+
1130+
if (params->cpus) {
1131+
retval = osnoise_set_cpus(tool->context, params->cpus);
1132+
if (retval) {
1133+
err_msg("Failed to apply CPUs config\n");
1134+
goto out_err;
1135+
}
1136+
}
1137+
1138+
if (params->runtime || params->period) {
1139+
retval = osnoise_set_runtime_period(tool->context,
1140+
params->runtime,
1141+
params->period);
1142+
if (retval) {
1143+
err_msg("Failed to set runtime and/or period\n");
1144+
goto out_err;
1145+
}
1146+
}
1147+
1148+
if (params->stop_us) {
1149+
retval = osnoise_set_stop_us(tool->context, params->stop_us);
1150+
if (retval) {
1151+
err_msg("Failed to set stop us\n");
1152+
goto out_err;
1153+
}
1154+
}
1155+
1156+
if (params->stop_total_us) {
1157+
retval = osnoise_set_stop_total_us(tool->context, params->stop_total_us);
1158+
if (retval) {
1159+
err_msg("Failed to set stop total us\n");
1160+
goto out_err;
1161+
}
1162+
}
1163+
1164+
if (params->threshold) {
1165+
retval = osnoise_set_tracing_thresh(tool->context, params->threshold);
1166+
if (retval) {
1167+
err_msg("Failed to set tracing_thresh\n");
1168+
goto out_err;
1169+
}
1170+
}
1171+
1172+
if (params->hk_cpus) {
1173+
retval = sched_setaffinity(getpid(), sizeof(params->hk_cpu_set),
1174+
&params->hk_cpu_set);
1175+
if (retval == -1) {
1176+
err_msg("Failed to set rtla to the house keeping CPUs\n");
1177+
goto out_err;
1178+
}
1179+
} else if (params->cpus) {
1180+
/*
1181+
* Even if the user do not set a house-keeping CPU, try to
1182+
* move rtla to a CPU set different to the one where the user
1183+
* set the workload to run.
1184+
*
1185+
* No need to check results as this is an automatic attempt.
1186+
*/
1187+
auto_house_keeping(&params->monitored_cpus);
1188+
}
1189+
1190+
return 0;
1191+
1192+
out_err:
1193+
return -1;
1194+
}
1195+
11171196
static void osnoise_usage(int err)
11181197
{
11191198
int i;

tools/tracing/rtla/src/osnoise.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ struct osnoise_tool *osnoise_init_tool(char *tool_name);
155155
struct osnoise_tool *osnoise_init_trace_tool(char *tracer);
156156
void osnoise_report_missed_events(struct osnoise_tool *tool);
157157
bool osnoise_trace_is_off(struct osnoise_tool *tool, struct osnoise_tool *record);
158+
int osnoise_apply_config(struct osnoise_tool *tool, struct osnoise_params *params);
158159

159160
int osnoise_hist_main(int argc, char *argv[]);
160161
int osnoise_top_main(int argc, char **argv);

tools/tracing/rtla/src/osnoise_hist.c

Lines changed: 3 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include <errno.h>
1313
#include <stdio.h>
1414
#include <time.h>
15-
#include <sched.h>
1615

1716
#include "osnoise.h"
1817

@@ -705,68 +704,9 @@ osnoise_hist_apply_config(struct osnoise_tool *tool, struct osnoise_params *para
705704
{
706705
int retval;
707706

708-
if (!params->sleep_time)
709-
params->sleep_time = 1;
710-
711-
if (params->cpus) {
712-
retval = osnoise_set_cpus(tool->context, params->cpus);
713-
if (retval) {
714-
err_msg("Failed to apply CPUs config\n");
715-
goto out_err;
716-
}
717-
}
718-
719-
if (params->runtime || params->period) {
720-
retval = osnoise_set_runtime_period(tool->context,
721-
params->runtime,
722-
params->period);
723-
if (retval) {
724-
err_msg("Failed to set runtime and/or period\n");
725-
goto out_err;
726-
}
727-
}
728-
729-
if (params->stop_us) {
730-
retval = osnoise_set_stop_us(tool->context, params->stop_us);
731-
if (retval) {
732-
err_msg("Failed to set stop us\n");
733-
goto out_err;
734-
}
735-
}
736-
737-
if (params->stop_total_us) {
738-
retval = osnoise_set_stop_total_us(tool->context, params->stop_total_us);
739-
if (retval) {
740-
err_msg("Failed to set stop total us\n");
741-
goto out_err;
742-
}
743-
}
744-
745-
if (params->threshold) {
746-
retval = osnoise_set_tracing_thresh(tool->context, params->threshold);
747-
if (retval) {
748-
err_msg("Failed to set tracing_thresh\n");
749-
goto out_err;
750-
}
751-
}
752-
753-
if (params->hk_cpus) {
754-
retval = sched_setaffinity(getpid(), sizeof(params->hk_cpu_set),
755-
&params->hk_cpu_set);
756-
if (retval == -1) {
757-
err_msg("Failed to set rtla to the house keeping CPUs\n");
758-
goto out_err;
759-
}
760-
} else if (params->cpus) {
761-
/*
762-
* Even if the user do not set a house-keeping CPU, try to
763-
* move rtla to a CPU set different to the one where the user
764-
* set the workload to run.
765-
*
766-
* No need to check results as this is an automatic attempt.
767-
*/
768-
auto_house_keeping(&params->monitored_cpus);
769-
}
707+
retval = osnoise_apply_config(tool, params);
708+
if (retval)
709+
goto out_err;
770710

771711
return 0;
772712

tools/tracing/rtla/src/osnoise_top.c

Lines changed: 3 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include <unistd.h>
1212
#include <stdio.h>
1313
#include <time.h>
14-
#include <sched.h>
1514

1615
#include "osnoise.h"
1716

@@ -523,50 +522,9 @@ osnoise_top_apply_config(struct osnoise_tool *tool, struct osnoise_params *param
523522
{
524523
int retval;
525524

526-
if (!params->sleep_time)
527-
params->sleep_time = 1;
528-
529-
if (params->cpus) {
530-
retval = osnoise_set_cpus(tool->context, params->cpus);
531-
if (retval) {
532-
err_msg("Failed to apply CPUs config\n");
533-
goto out_err;
534-
}
535-
}
536-
537-
if (params->runtime || params->period) {
538-
retval = osnoise_set_runtime_period(tool->context,
539-
params->runtime,
540-
params->period);
541-
if (retval) {
542-
err_msg("Failed to set runtime and/or period\n");
543-
goto out_err;
544-
}
545-
}
546-
547-
if (params->stop_us) {
548-
retval = osnoise_set_stop_us(tool->context, params->stop_us);
549-
if (retval) {
550-
err_msg("Failed to set stop us\n");
551-
goto out_err;
552-
}
553-
}
554-
555-
if (params->stop_total_us) {
556-
retval = osnoise_set_stop_total_us(tool->context, params->stop_total_us);
557-
if (retval) {
558-
err_msg("Failed to set stop total us\n");
559-
goto out_err;
560-
}
561-
}
562-
563-
if (params->threshold) {
564-
retval = osnoise_set_tracing_thresh(tool->context, params->threshold);
565-
if (retval) {
566-
err_msg("Failed to set tracing_thresh\n");
567-
goto out_err;
568-
}
569-
}
525+
retval = osnoise_apply_config(tool, params);
526+
if (retval)
527+
goto out_err;
570528

571529
if (params->mode == MODE_HWNOISE) {
572530
retval = osnoise_set_irq_disable(tool->context, 1);
@@ -576,24 +534,6 @@ osnoise_top_apply_config(struct osnoise_tool *tool, struct osnoise_params *param
576534
}
577535
}
578536

579-
if (params->hk_cpus) {
580-
retval = sched_setaffinity(getpid(), sizeof(params->hk_cpu_set),
581-
&params->hk_cpu_set);
582-
if (retval == -1) {
583-
err_msg("Failed to set rtla to the house keeping CPUs\n");
584-
goto out_err;
585-
}
586-
} else if (params->cpus) {
587-
/*
588-
* Even if the user do not set a house-keeping CPU, try to
589-
* move rtla to a CPU set different to the one where the user
590-
* set the workload to run.
591-
*
592-
* No need to check results as this is an automatic attempt.
593-
*/
594-
auto_house_keeping(&params->monitored_cpus);
595-
}
596-
597537
if (isatty(STDOUT_FILENO) && !params->quiet)
598538
params->pretty_output = 1;
599539

0 commit comments

Comments
 (0)