-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Thomas, Got a couple of requests for mlockall() in cyclictest, so I added an --mlockall option to cyclictest, signaltest and pi_stress. Patches attached. Clark -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org iEYEARECAAYFAkgknisACgkQqA4JVb61b9e+5wCgkfnFdvymSXLsxQ9AwhVU9te+ J9YAniZv12Xj1r6epjft/L/CLv3P1Yl4 =ismw -----END PGP SIGNATURE-----
From c4a44c163df791ec3f42075e587685fa7e5b031d Mon Sep 17 00:00:00 2001 From: Clark Williams <williams@xxxxxxxxxx> Date: Fri, 9 May 2008 13:28:50 -0500 Subject: [PATCH] added mlockall option Signed-off-by: Clark Williams <williams@xxxxxxxxxx> --- .gitignore | 4 ++++ src/cyclictest/cyclictest.c | 18 +++++++++++++++++- src/pi_tests/pi_stress.c | 18 ++++++++++++++++++ src/signaltest/signaltest.c | 16 +++++++++++++++- 4 files changed, 54 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index fd84086..f09d8dc 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,7 @@ releases BUILD RPMS SRPMS +classic_pi +pi_stress +cyclictest +signaltest diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c index 9223549..cf9b7c6 100644 --- a/src/cyclictest/cyclictest.c +++ b/src/cyclictest/cyclictest.c @@ -30,6 +30,7 @@ #include <sys/types.h> #include <sys/time.h> #include <sys/utsname.h> +#include <sys/mman.h> #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) @@ -119,6 +120,7 @@ static int ftrace = 0; static int kernelversion; static int verbose = 0; static int oscope_reduction = 1; +static int lockall = 0; /* Backup of kernel variables that we modify */ static struct kvars { @@ -478,6 +480,7 @@ static void display_help(void) "-s --system use sys_nanosleep and sys_setitimer\n" "-t --threads one thread per available processor\n" "-t NUM --threads=NUM number of threads: without -t default=1\n" + "-m --mlockall lock current and future memory allocations\n" "-v --verbose output values on stdout for statistics\n" " format: n:c:v n=tasknum c=count v=value in us\n"); exit(0); @@ -531,11 +534,12 @@ static void process_options (int argc, char *argv[]) {"relative", no_argument, NULL, 'r'}, {"system", no_argument, NULL, 's'}, {"threads", optional_argument, NULL, 't'}, + {"mlockall", no_argument, NULL, 'm' }, {"verbose", no_argument, NULL, 'v'}, {"help", no_argument, NULL, '?'}, {NULL, 0, NULL, 0} }; - int c = getopt_long (argc, argv, "a::b:c:d:fi:l:no:p:qrst::v", + int c = getopt_long (argc, argv, "a::b:c:d:fi:l:no:p:qrsmt::v", long_options, &option_index); if (c == -1) break; @@ -566,6 +570,7 @@ static void process_options (int argc, char *argv[]) num_threads = max_cpus; break; case 'v': verbose = 1; break; + case 'm': lockall = 1; break; case '?': error = 1; break; } } @@ -696,6 +701,13 @@ int main(int argc, char **argv) process_options(argc, argv); + /* lock all memory (prevent paging) */ + if (lockall) + if (mlockall(MCL_CURRENT|MCL_FUTURE) == -1) { + perror("mlockall"); + goto out; + } + kernelversion = check_kernel(); if (kernelversion == KV_NOT_26) @@ -809,6 +821,10 @@ int main(int argc, char **argv) free(par); out: + /* unlock everything */ + if (lockall) + munlockall(); + /* Be a nice program, cleanup */ if (kernelversion != KV_26_CURR) restorekernvars(); diff --git a/src/pi_tests/pi_stress.c b/src/pi_tests/pi_stress.c index a0599ad..052c476 100644 --- a/src/pi_tests/pi_stress.c +++ b/src/pi_tests/pi_stress.c @@ -51,6 +51,7 @@ #include <signal.h> #include <getopt.h> #include <sys/types.h> +#include <sys/mman.h> #include <sys/wait.h> #include <termios.h> @@ -128,6 +129,9 @@ int have_errors = 0; // force running on one cpu int uniprocessor = 0; +// lock all memory +int lockall = 0; + // command line options struct option options [] = { { "duration", required_argument, NULL, 't' }, @@ -141,6 +145,7 @@ struct option options [] = { { "prompt", no_argument, NULL, 'p'}, { "debug", no_argument, NULL, 'd'}, { "version", no_argument, NULL, 'V'}, + { "mlockall", no_argument, NULL, 'm'}, { "help", no_argument, NULL, 'h'}, { NULL, 0, NULL, 0}, }; @@ -234,6 +239,13 @@ main (int argc, char **argv) /* process command line arguments */ process_command_line(argc, argv); + /* lock memory */ + if (lockall) + if (mlockall(MCL_CURRENT|MCL_FUTURE) == -1) { + error("mlockall failed\n"); + return FAILURE; + } + // boost main's priority (so we keep running) :) prio_min = sched_get_priority_min(policy); thread_param.sched_priority = MAIN_PRIO(); @@ -328,6 +340,8 @@ main (int argc, char **argv) } finish = time(NULL); summary(); + if (lockall) + munlockall(); exit(retval); } @@ -852,6 +866,7 @@ usage(void) printf("\t--rr\t\t- use SCHED_RR for test threads [SCHED_FIFO]\n"); printf("\t--prompt\t- prompt before starting the test\n"); printf("\t--uniprocessor\t- force all threads to run on one processor\n"); + printf("\t--mlockall\t- lock current and future memory\n"); printf("\t--debug\t\t- turn on debug prints\n"); printf("\t--version\t- print version number on output\n"); printf("\t--help\t\t- print this message\n"); @@ -1083,6 +1098,9 @@ process_command_line(int argc, char **argv) case 'u': uniprocessor = 1; break; + case 'm': + lockall = 1; + break; } } } diff --git a/src/signaltest/signaltest.c b/src/signaltest/signaltest.c index 963cc38..eef7d6e 100644 --- a/src/signaltest/signaltest.c +++ b/src/signaltest/signaltest.c @@ -25,6 +25,7 @@ #include <sys/stat.h> #include <sys/types.h> #include <sys/time.h> +#include <sys/mman.h> #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) @@ -207,6 +208,7 @@ static void display_help(void) "-p PRIO --prio=PRIO priority of highest prio thread\n" "-q --quiet print only a summary on exit\n" "-t NUM --threads=NUM number of threads: default=2\n" + "-m --mlockall lock current and future memory allocations\n" "-v --verbose output values on stdout for statistics\n" " format: n:c:v n=tasknum c=count v=value in us\n"); exit(0); @@ -217,6 +219,7 @@ static int num_threads = 2; static int max_cycles; static int verbose; static int quiet; +static int lockall = 0; /* Process commandline options */ static void process_options (int argc, char *argv[]) @@ -235,7 +238,7 @@ static void process_options (int argc, char *argv[]) {"help", no_argument, NULL, '?'}, {NULL, 0, NULL, 0} }; - int c = getopt_long (argc, argv, "b:c:d:i:l:np:qrst:v", + int c = getopt_long (argc, argv, "b:c:d:i:l:np:qrsmt:v", long_options, &option_index); if (c == -1) break; @@ -245,6 +248,7 @@ static void process_options (int argc, char *argv[]) case 'p': priority = atoi(optarg); break; case 'q': quiet = 1; break; case 't': num_threads = atoi(optarg); break; + case 'm': lockall = 1; break; case 'v': verbose = 1; break; case '?': error = 1; break; } @@ -317,6 +321,13 @@ int main(int argc, char **argv) process_options(argc, argv); + /* lock all memory (prevent paging) */ + if (lockall) + if (mlockall(MCL_CURRENT|MCL_FUTURE) == -1) { + perror("mlockall"); + goto out; + } + check_kernel(); sigemptyset(&sigset); @@ -417,5 +428,8 @@ int main(int argc, char **argv) outpar: free(par); out: + if (lockall) + munlockall(); + exit(ret); } -- 1.5.4.5
From f6db792ba42908b78f31d3a16cf5c170c29085b7 Mon Sep 17 00:00:00 2001 From: Clark Williams <williams@xxxxxxxxxx> Date: Fri, 9 May 2008 13:40:08 -0500 Subject: [PATCH] updated man pages for --mlockall option Signed-off-by: Clark Williams <williams@xxxxxxxxxx> --- src/cyclictest/cyclictest.8 | 3 +++ src/pi_tests/pi_stress.8 | 6 +++++- 2 files changed, 8 insertions(+), 1 deletions(-) diff --git a/src/cyclictest/cyclictest.8 b/src/cyclictest/cyclictest.8 index 29a232f..71cca33 100644 --- a/src/cyclictest/cyclictest.8 +++ b/src/cyclictest/cyclictest.8 @@ -86,6 +86,9 @@ Use sys_nanosleep and sys_setitimer instead of posix timers. Note, that -s can o Set the number of test threads (default is 1). Create NUM test threads. If NUM is not specifed, NUM is set to the number of available CPUs. See -d, -i and -p for further information. .TP +.B \-m, \-\-mlockall +Lock current an future memory allocations to prevent being paged out +.TP .B \-v, \-\-verbose Output values on stdout for statistics. This option is used to gather statistical information about the latency distribution. The output is sent to stdout. The output format is: diff --git a/src/pi_tests/pi_stress.8 b/src/pi_tests/pi_stress.8 index 059ee52..3723671 100644 --- a/src/pi_tests/pi_stress.8 +++ b/src/pi_tests/pi_stress.8 @@ -10,7 +10,7 @@ pi_stress \- a stress test for POSIX Priority Inheritance mutexes .\"}}} .\"{{{ Synopsis -.\" Usage: pi_stress [-i n ] [-g n] [-v] [-d] [-s] [-r] [-p] [-u] +.\" Usage: pi_stress [-i n ] [-g n] [-v] [-d] [-s] [-r] [-p] [-u] [-m] .SH SYNOPSIS .B pi_stress .RB [ \-i|--inversions @@ -24,6 +24,7 @@ pi_stress \- a stress test for POSIX Priority Inheritance mutexes .RB [ \-s|--signal ] .RB [ \-r|--rr ] .RB [ \-p|--prompt ] +.RB [ \-m|--mlockall ] .RB [ \-u|--uniprocessor ] .br .\" help @@ -70,6 +71,9 @@ Prompt before actually starting the stress test Run all threads on one processor. The default is to run all inversion group threads on one processor and the admin threads (reporting thread, keyboard reader, etc.) on a different processor. +.IP \m|--mlockall +Call mlockall to lock currnet and future memory allocations and +prevent being paged out .IP -h|--help Display a short help message and options. .SH CAVEATS -- 1.5.4.5
From 5587d442ee5eba79325e842f5ecc70ce6fe74817 Mon Sep 17 00:00:00 2001 From: Clark Williams <williams@xxxxxxxxxx> Date: Fri, 9 May 2008 13:43:55 -0500 Subject: [PATCH] fixed formating damage Signed-off-by: Clark Williams <williams@xxxxxxxxxx> --- src/cyclictest/cyclictest.8 | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/src/cyclictest/cyclictest.8 b/src/cyclictest/cyclictest.8 index 71cca33..91bf2a8 100644 --- a/src/cyclictest/cyclictest.8 +++ b/src/cyclictest/cyclictest.8 @@ -16,7 +16,7 @@ cyclictest \- High resolution test program .SH SYNOPSIS .B cyclictest -.RI "[ -hnqrsv ] [\-a " proc " ] [\-b " usec " ] [\-c " clock " ] [\-d " dist " ] [\-i " intv " ] [\-l " loop " ] [\-o " red " ] [\-p " prio " ] [\-t " num " ] " +.RI "[ -hnqrsv ] [\-a " proc " ] [\-b " usec " ] [\-c " clock " ] [\-d " dist " ] [\-i " intv " ] [\-l " loop " ] [\-o " red " ] [\-p " prio " ] [\-t " num " ] [\-m]" .\" .SH DESCRIPTION .\" This manual page documents briefly the .\" .B cyclictest commands. -- 1.5.4.5