Skip to content

Commit c58a3f8

Browse files
Daniel Bristot de Oliveirarostedt
authored andcommitted
rtla: Automatically move rtla to a house-keeping cpu
When the user sets -c <cpu-list> try to move rtla out of the <cpu-list>, even without an -H option. This is useful to avoid having rtla interfering with the workload. This works by removing <cpu-list> from rtla's current affinity. If rtla fails to move itself away it is not that of a problem as this is an automatic measure. Link: https://lkml.kernel.org/r/c54304d90c777310fb85a3e658d1449173759aab.1686066600.git.bristot@kernel.org Cc: William White <chwhite@redhat.com> Cc: Jonathan Corbet <corbet@lwn.net> Tested-by: Juri Lelli <juri.lelli@redhat.com> Signed-off-by: Daniel Bristot de Oliveira <bristot@kernel.org> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 parent 894c29c commit c58a3f8

6 files changed

Lines changed: 87 additions & 0 deletions

File tree

tools/tracing/rtla/src/osnoise_hist.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,15 @@ osnoise_hist_apply_config(struct osnoise_tool *tool, struct osnoise_hist_params
753753
err_msg("Failed to set rtla to the house keeping CPUs\n");
754754
goto out_err;
755755
}
756+
} else if (params->cpus) {
757+
/*
758+
* Even if the user do not set a house-keeping CPU, try to
759+
* move rtla to a CPU set different to the one where the user
760+
* set the workload to run.
761+
*
762+
* No need to check results as this is an automatic attempt.
763+
*/
764+
auto_house_keeping(&params->monitored_cpus);
756765
}
757766

758767
return 0;

tools/tracing/rtla/src/osnoise_top.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,15 @@ osnoise_top_apply_config(struct osnoise_tool *tool, struct osnoise_top_params *p
582582
err_msg("Failed to set rtla to the house keeping CPUs\n");
583583
goto out_err;
584584
}
585+
} else if (params->cpus) {
586+
/*
587+
* Even if the user do not set a house-keeping CPU, try to
588+
* move rtla to a CPU set different to the one where the user
589+
* set the workload to run.
590+
*
591+
* No need to check results as this is an automatic attempt.
592+
*/
593+
auto_house_keeping(&params->monitored_cpus);
585594
}
586595

587596
return 0;

tools/tracing/rtla/src/timerlat_hist.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,15 @@ timerlat_hist_apply_config(struct osnoise_tool *tool, struct timerlat_hist_param
776776
err_msg("Failed to set rtla to the house keeping CPUs\n");
777777
goto out_err;
778778
}
779+
} else if (params->cpus) {
780+
/*
781+
* Even if the user do not set a house-keeping CPU, try to
782+
* move rtla to a CPU set different to the one where the user
783+
* set the workload to run.
784+
*
785+
* No need to check results as this is an automatic attempt.
786+
*/
787+
auto_house_keeping(&params->monitored_cpus);
779788
}
780789

781790
return 0;

tools/tracing/rtla/src/timerlat_top.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,15 @@ timerlat_top_apply_config(struct osnoise_tool *top, struct timerlat_top_params *
619619
err_msg("Failed to set rtla to the house keeping CPUs\n");
620620
goto out_err;
621621
}
622+
} else if (params->cpus) {
623+
/*
624+
* Even if the user do not set a house-keeping CPU, try to
625+
* move rtla to a CPU set different to the one where the user
626+
* set the workload to run.
627+
*
628+
* No need to check results as this is an automatic attempt.
629+
*/
630+
auto_house_keeping(&params->monitored_cpus);
622631
}
623632

624633
return 0;

tools/tracing/rtla/src/utils.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,3 +709,53 @@ int set_comm_cgroup(const char *comm_prefix, const char *cgroup)
709709
close(cg_fd);
710710
return 0;
711711
}
712+
713+
/**
714+
* auto_house_keeping - Automatically move rtla out of measurement threads
715+
*
716+
* Try to move rtla away from the tracer, if possible.
717+
*
718+
* Returns 1 on success, 0 otherwise.
719+
*/
720+
int auto_house_keeping(cpu_set_t *monitored_cpus)
721+
{
722+
cpu_set_t rtla_cpus, house_keeping_cpus;
723+
int retval;
724+
725+
/* first get the CPUs in which rtla can actually run. */
726+
retval = sched_getaffinity(getpid(), sizeof(rtla_cpus), &rtla_cpus);
727+
if (retval == -1) {
728+
debug_msg("Could not get rtla affinity, rtla might run with the threads!\n");
729+
return 0;
730+
}
731+
732+
/* then check if the existing setup is already good. */
733+
CPU_AND(&house_keeping_cpus, &rtla_cpus, monitored_cpus);
734+
if (!CPU_COUNT(&house_keeping_cpus)) {
735+
debug_msg("rtla and the monitored CPUs do not share CPUs.");
736+
debug_msg("Skipping auto house-keeping\n");
737+
return 1;
738+
}
739+
740+
/* remove the intersection */
741+
CPU_XOR(&house_keeping_cpus, &rtla_cpus, monitored_cpus);
742+
743+
/* get only those that rtla can run */
744+
CPU_AND(&house_keeping_cpus, &house_keeping_cpus, &rtla_cpus);
745+
746+
/* is there any cpu left? */
747+
if (!CPU_COUNT(&house_keeping_cpus)) {
748+
debug_msg("Could not find any CPU for auto house-keeping\n");
749+
return 0;
750+
}
751+
752+
retval = sched_setaffinity(getpid(), sizeof(house_keeping_cpus), &house_keeping_cpus);
753+
if (retval == -1) {
754+
debug_msg("Could not set affinity for auto house-keeping\n");
755+
return 0;
756+
}
757+
758+
debug_msg("rtla automatically moved to an auto house-keeping cpu set\n");
759+
760+
return 1;
761+
}

tools/tracing/rtla/src/utils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ int parse_cpu_set(char *cpu_list, cpu_set_t *set);
6060
int set_comm_sched_attr(const char *comm_prefix, struct sched_attr *attr);
6161
int set_comm_cgroup(const char *comm_prefix, const char *cgroup);
6262
int set_cpu_dma_latency(int32_t latency);
63+
int auto_house_keeping(cpu_set_t *monitored_cpus);
6364

6465
#define ns_to_usf(x) (((double)x/1000))
6566
#define ns_to_per(total, part) ((part * 100) / (double)total)

0 commit comments

Comments
 (0)