From d2b5e1e2d6371dcff1b48423abbf4af2295f4f0f Mon Sep 17 00:00:00 2001 From: Thomas Richter Date: Tue, 7 Nov 2023 09:51:55 +0100 Subject: [PATCH] cpumf/pai: Add command line option for realtime scheduling Pai collects data from per CPU ring buffers and stores them in the memory mapped output file. When data is collected from many CPUs at the same time, writing data to output file can be slow. Improve this and allow the pai recording to run with higher real time priority. This is the same approach as done by the perf tool. Signed-off-by: Thomas Richter Acked-by: Sumanth Korikkar Signed-off-by: Steffen Eiden --- cpumf/man/pai.8 | 12 ++++++++++++ cpumf/pai.c | 21 +++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/cpumf/man/pai.8 b/cpumf/man/pai.8 index 6107f280..204b8df0 100644 --- a/cpumf/man/pai.8 +++ b/cpumf/man/pai.8 @@ -18,6 +18,8 @@ .IR size ] .RB [ \-i | \-\-interval .IR ms ] +.RB [ \-R | \-\-realtime +.IR prio ] .BR \-c | \-\-crypto [ \fIcpulist ][: \fIdata\fR "] [" \fIloops\fP ] .br \*c @@ -25,6 +27,8 @@ .IR size ] .RB [ \-i | \-\-interval .IR ms ] +.RB [ \-R | \-\-realtime +.IR prio ] .BR \-n | \-\-nnpa [ \fIcpulist ][: \fIdata\fR "] [" \fIloops\fP ] .br \*c @@ -191,6 +195,14 @@ The ring buffer is created with the .IR mmap (2) system call. . +.TP +.BR \-R ", " \-\-realtime "\ prio" +Collect data using the RT SCHED_FIFO priority specified by +.BR prio . +Valid values are integers in the range 1 (low) to 99 (high). +Use this option when gathering data from multiple CPUs +to prevent data loss. +. .SH ARGUMENT The command line options determine how command line arguments are interpreted. diff --git a/cpumf/pai.c b/cpumf/pai.c index 6c06f9e8..68bdebfa 100644 --- a/cpumf/pai.c +++ b/cpumf/pai.c @@ -944,6 +944,11 @@ static struct util_opt opt_vec[] = { .option = { "report", no_argument, NULL, 'r' }, .desc = "Report file contents" }, + { + .option = { "realtime", required_argument, NULL, 'R' }, + .argument = "PRIO", + .desc = "Collect data with this RT SCHED_FIFO priority" + }, { .option = { "interval", required_argument, NULL, 'i' }, .argument = "NUMBER", @@ -1007,6 +1012,19 @@ static unsigned long check_mapsize(unsigned long n) return cnt == 1 ? n : 0; } +static void setprio(const char *prio) +{ + struct sched_param param; + char *endstr; + + memset(¶m, 0, sizeof(param)); + param.sched_priority = strtoul(prio, &endstr, 0); + if (*endstr) + errno = EINVAL; + if (*endstr || sched_setscheduler(0, SCHED_FIFO, ¶m)) + err(EXIT_FAILURE, "Could not set realtime priority"); +} + int main(int argc, char **argv) { bool crypto_record = false, report = false; @@ -1061,6 +1079,9 @@ int main(int argc, char **argv) record_cpus_nnpa(optarg); nnpa_record = true; break; + case 'R': + setprio(optarg); + break; case 'r': report = true; break;