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;